1 /*
2 * Copyright (C) 2022-2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "ims_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_[ImsCallInterfaceCode::IMS_DIAL] = &ImsUnitTest::Dial;
59 requestCallFuncMap_[ImsCallInterfaceCode::IMS_HANG_UP] = &ImsUnitTest::HangUp;
60 requestCallFuncMap_[ImsCallInterfaceCode::IMS_REJECT_WITH_REASON] = &ImsUnitTest::RejectWithReason;
61 requestCallFuncMap_[ImsCallInterfaceCode::IMS_ANSWER] = &ImsUnitTest::Answer;
62 requestCallFuncMap_[ImsCallInterfaceCode::IMS_HOLD] = &ImsUnitTest::HoldCall;
63 requestCallFuncMap_[ImsCallInterfaceCode::IMS_UN_HOLD] = &ImsUnitTest::UnHoldCall;
64 requestCallFuncMap_[ImsCallInterfaceCode::IMS_SWITCH] = &ImsUnitTest::SwitchCall;
65 requestCallFuncMap_[ImsCallInterfaceCode::IMS_COMBINE_CONFERENCE] = &ImsUnitTest::CombineConference;
66 requestCallFuncMap_[ImsCallInterfaceCode::IMS_INVITE_TO_CONFERENCE] = &ImsUnitTest::InviteToConference;
67 requestCallFuncMap_[ImsCallInterfaceCode::IMS_KICK_OUT_CONFERENCE] = &ImsUnitTest::KickOutFromConference;
68 requestCallFuncMap_[ImsCallInterfaceCode::IMS_UPDATE_CALL_MEDIA_MODE] = &ImsUnitTest::UpdateImsCallMode;
69 requestCallFuncMap_[ImsCallInterfaceCode::IMS_GET_CALL_DATA] = &ImsUnitTest::GetImsCallsDataRequest;
70 requestCallFuncMap_[ImsCallInterfaceCode::IMS_GET_LAST_CALL_FAIL_REASON] = &ImsUnitTest::GetLastCallFailReason;
71 requestCallFuncMap_[ImsCallInterfaceCode::IMS_START_DTMF] = &ImsUnitTest::StartDtmf;
72 requestCallFuncMap_[ImsCallInterfaceCode::IMS_SEND_DTMF] = &ImsUnitTest::SendDtmf;
73 requestCallFuncMap_[ImsCallInterfaceCode::IMS_STOP_DTMF] = &ImsUnitTest::StopDtmf;
74 requestCallFuncMap_[ImsCallInterfaceCode::IMS_START_RTT] = &ImsUnitTest::StartRtt;
75 requestCallFuncMap_[ImsCallInterfaceCode::IMS_STOP_RTT] = &ImsUnitTest::StopRtt;
76 }
77
InitConfigFuncMap(void)78 void ImsUnitTest::InitConfigFuncMap(void)
79 {
80 requestCallFuncMap_[ImsCallInterfaceCode::IMS_SET_DOMAIN_PREFERENCE_MODE] = &ImsUnitTest::SetDomainPreferenceMode;
81 requestCallFuncMap_[ImsCallInterfaceCode::IMS_GET_DOMAIN_PREFERENCE_MODE] = &ImsUnitTest::GetDomainPreferenceMode;
82 requestCallFuncMap_[ImsCallInterfaceCode::IMS_SET_SWITCH_STATUS] = &ImsUnitTest::SetImsSwitchStatus;
83 requestCallFuncMap_[ImsCallInterfaceCode::IMS_GET_SWITCH_STATUS] = &ImsUnitTest::GetImsSwitchStatus;
84 requestCallFuncMap_[ImsCallInterfaceCode::IMS_SET_IMS_CONFIG_STRING] = &ImsUnitTest::SetImsConfigString;
85 requestCallFuncMap_[ImsCallInterfaceCode::IMS_SET_IMS_CONFIG_INT] = &ImsUnitTest::SetImsConfigInt;
86 requestCallFuncMap_[ImsCallInterfaceCode::IMS_GET_IMS_CONFIG] = &ImsUnitTest::GetImsConfig;
87 requestCallFuncMap_[ImsCallInterfaceCode::IMS_SET_IMS_FEATURE] = &ImsUnitTest::SetImsFeatureValue;
88 requestCallFuncMap_[ImsCallInterfaceCode::IMS_GET_IMS_FEATURE] = &ImsUnitTest::GetImsFeatureValue;
89 requestCallFuncMap_[ImsCallInterfaceCode::IMS_SET_MUTE] = &ImsUnitTest::SetMute;
90 requestCallFuncMap_[ImsCallInterfaceCode::IMS_GET_MUTE] = &ImsUnitTest::GetMute;
91 }
92
InitVideoCallFuncMap(void)93 void ImsUnitTest::InitVideoCallFuncMap(void)
94 {
95 requestCallFuncMap_[ImsCallInterfaceCode::IMS_CTRL_CAMERA] = &ImsUnitTest::CtrlCamera;
96 requestCallFuncMap_[ImsCallInterfaceCode::IMS_SET_PREVIEW_WINDOW] = &ImsUnitTest::SetPreviewWindow;
97 requestCallFuncMap_[ImsCallInterfaceCode::IMS_SET_DISPLAY_WINDOW] = &ImsUnitTest::SetDisplayWindow;
98 requestCallFuncMap_[ImsCallInterfaceCode::IMS_SET_CAMERA_ZOOM] = &ImsUnitTest::SetCameraZoom;
99 requestCallFuncMap_[ImsCallInterfaceCode::IMS_SET_PAUSE_IMAGE] = &ImsUnitTest::SetPauseImage;
100 requestCallFuncMap_[ImsCallInterfaceCode::IMS_SET_DEVICE_DIRECTION] = &ImsUnitTest::SetDeviceDirection;
101 }
102
InitSupplementFuncMap(void)103 void ImsUnitTest::InitSupplementFuncMap(void)
104 {
105 requestCallFuncMap_[ImsCallInterfaceCode::IMS_GET_CLIP] = &ImsUnitTest::GetClip;
106 requestCallFuncMap_[ImsCallInterfaceCode::IMS_SET_CLIR] = &ImsUnitTest::SetClir;
107 requestCallFuncMap_[ImsCallInterfaceCode::IMS_GET_CLIR] = &ImsUnitTest::GetClir;
108 requestCallFuncMap_[ImsCallInterfaceCode::IMS_SET_CALL_TRANSFER] = &ImsUnitTest::SetCallTransfer;
109 requestCallFuncMap_[ImsCallInterfaceCode::IMS_GET_CALL_TRANSFER] = &ImsUnitTest::GetCallTransfer;
110 requestCallFuncMap_[ImsCallInterfaceCode::IMS_SET_CALL_RESTRICTION] = &ImsUnitTest::SetCallRestriction;
111 requestCallFuncMap_[ImsCallInterfaceCode::IMS_GET_CALL_RESTRICTION] = &ImsUnitTest::GetCallRestriction;
112 requestCallFuncMap_[ImsCallInterfaceCode::IMS_SET_CALL_WAITING] = &ImsUnitTest::SetCallWaiting;
113 requestCallFuncMap_[ImsCallInterfaceCode::IMS_GET_CALL_WAITING] = &ImsUnitTest::GetCallWaiting;
114 }
115
InitSmsFuncMap(void)116 void ImsUnitTest::InitSmsFuncMap(void)
117 {
118 requestSmsFuncMap_[ImsSmsInterfaceCode::IMS_SET_SMS_CONFIG] = &ImsUnitTest::SetSmsConfig;
119 requestSmsFuncMap_[ImsSmsInterfaceCode::IMS_GET_SMS_CONFIG] = &ImsUnitTest::GetSmsConfig;
120 requestSmsFuncMap_[ImsSmsInterfaceCode::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<ImsCallInterfaceCode> & imsCallPtr) const134 int32_t ImsUnitTest::Dial(const sptr<ImsCallInterfaceCode> &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<ImsCallInterfaceCode> & imsCallPtr) const151 int32_t ImsUnitTest::HangUp(const sptr<ImsCallInterfaceCode> &imsCallPtr) const
152 {
153 std::cout << "test HangUp entry." << std::endl;
154 ImsCallInfo hangUpCallInfo;
155 if (memset_s(&hangUpCallInfo, sizeof(hangUpCallInfo), 0, sizeof(hangUpCallInfo)) != 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 >> hangUpCallInfo.phoneNum;
161 hangUpCallInfo.videoState = 1;
162 hangUpCallInfo.slotId = 0;
163 std::cout << "please enter the connect index:";
164 std::cin >> hangUpCallInfo.index;
165 imsCallPtr->HangUp(hangUpCallInfo);
166 return IMS_TEST_SUCCESS;
167 }
168
RejectWithReason(const sptr<ImsCallInterfaceCode> & imsCallPtr) const169 int32_t ImsUnitTest::RejectWithReason(const sptr<ImsCallInterfaceCode> &imsCallPtr) const
170 {
171 std::cout << "test RejectWithReason entry." << std::endl;
172 ImsCallInfo rejectCallInfo;
173 if (memset_s(&rejectCallInfo, sizeof(rejectCallInfo), 0, sizeof(rejectCallInfo)) != 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 >> rejectCallInfo.phoneNum;
179 rejectCallInfo.videoState = 1;
180 rejectCallInfo.slotId = 0;
181 std::cout << "please enter the connect index:";
182 std::cin >> rejectCallInfo.index;
183 imsCallPtr->RejectWithReason(rejectCallInfo, ImsRejectReason::USER_DECLINE);
184 return IMS_TEST_SUCCESS;
185 }
186
Answer(const sptr<ImsCallInterfaceCode> & imsCallPtr) const187 int32_t ImsUnitTest::Answer(const sptr<ImsCallInterfaceCode> &imsCallPtr) const
188 {
189 std::cout << "test Answer entry." << std::endl;
190 ImsCallInfo answerCallInfo;
191 if (memset_s(&answerCallInfo, sizeof(answerCallInfo), 0, sizeof(answerCallInfo)) != 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 >> answerCallInfo.phoneNum;
197 answerCallInfo.videoState = 1;
198 answerCallInfo.slotId = 0;
199 std::cout << "please enter the connect index:";
200 std::cin >> answerCallInfo.index;
201 imsCallPtr->Answer(answerCallInfo);
202 return IMS_TEST_SUCCESS;
203 }
204
HoldCall(const sptr<ImsCallInterfaceCode> & imsCallPtr) const205 int32_t ImsUnitTest::HoldCall(const sptr<ImsCallInterfaceCode> &imsCallPtr) const
206 {
207 std::cout << "test HoldCall entry." << std::endl;
208 int32_t slotId;
209 int32_t holdCallType;
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 >> holdCallType;
214 imsCallPtr->HoldCall(slotId, holdCallType);
215 return IMS_TEST_SUCCESS;
216 }
217
UnHoldCall(const sptr<ImsCallInterfaceCode> & imsCallPtr) const218 int32_t ImsUnitTest::UnHoldCall(const sptr<ImsCallInterfaceCode> &imsCallPtr) const
219 {
220 std::cout << "test UnHoldCall entry." << std::endl;
221 int32_t slotId;
222 int32_t unHoldCallType;
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 >> unHoldCallType;
227 imsCallPtr->UnHoldCall(slotId, unHoldCallType);
228 return IMS_TEST_SUCCESS;
229 }
230
SwitchCall(const sptr<ImsCallInterfaceCode> & imsCallPtr) const231 int32_t ImsUnitTest::SwitchCall(const sptr<ImsCallInterfaceCode> &imsCallPtr) const
232 {
233 std::cout << "test SwitchCall entry." << std::endl;
234 int32_t slotId;
235 int32_t switchCallType;
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 >> switchCallType;
240 imsCallPtr->SwitchCall(slotId, switchCallType);
241 return IMS_TEST_SUCCESS;
242 }
243
CombineConference(const sptr<ImsCallInterfaceCode> & imsCallPtr) const244 int32_t ImsUnitTest::CombineConference(const sptr<ImsCallInterfaceCode> &imsCallPtr) const
245 {
246 std::cout << "test CombineConference entry." << std::endl;
247 int32_t slotId;
248 std::cout << "please enter the slotId:";
249 std::cin >> slotId;
250 imsCallPtr->CombineConference(slotId);
251 return IMS_TEST_SUCCESS;
252 }
253
InviteToConference(const sptr<ImsCallInterfaceCode> & imsCallPtr) const254 int32_t ImsUnitTest::InviteToConference(const sptr<ImsCallInterfaceCode> &imsCallPtr) const
255 {
256 std::cout << "test InviteToConference entry." << std::endl;
257 std::vector<std::string> numberList;
258 std::cout << "please enter the invite phone number:";
259 std::string phoneNumber;
260 std::cin >> phoneNumber;
261 numberList.push_back(phoneNumber);
262 int32_t slotId;
263 std::cout << "please enter the slotId:";
264 std::cin >> slotId;
265 imsCallPtr->InviteToConference(slotId, numberList);
266 return IMS_TEST_SUCCESS;
267 }
268
KickOutFromConference(const sptr<ImsCallInterfaceCode> & imsCallPtr) const269 int32_t ImsUnitTest::KickOutFromConference(const sptr<ImsCallInterfaceCode> &imsCallPtr) const
270 {
271 std::cout << "test KickOutFromConference entry." << std::endl;
272 int32_t kickOutIndex;
273 std::cout << "please enter the kick out phone index:";
274 std::cin >> kickOutIndex;
275 int32_t slotId;
276 std::cout << "please enter the slotId:";
277 std::cin >> slotId;
278 imsCallPtr->KickOutFromConference(slotId, kickOutIndex);
279 return IMS_TEST_SUCCESS;
280 }
281
UpdateImsCallMode(const sptr<ImsCallInterfaceCode> & imsCallPtr) const282 int32_t ImsUnitTest::UpdateImsCallMode(const sptr<ImsCallInterfaceCode> &imsCallPtr) const
283 {
284 std::cout << "test UpdateImsCallMode entry." << std::endl;
285 ImsCallInfo updateImsCallInfo;
286 if (memset_s(&updateImsCallInfo, sizeof(updateImsCallInfo), 0, sizeof(updateImsCallInfo)) != EOK) {
287 std::cout << "UpdateImsCallMode return, memset_s failed." << std::endl;
288 return IMS_TEST_ERROR;
289 }
290 std::cout << "please enter the phone number:";
291 std::cin >> updateImsCallInfo.phoneNum;
292 updateImsCallInfo.videoState = 1;
293 updateImsCallInfo.slotId = 0;
294 std::cout << "please enter the connect index:";
295 std::cin >> updateImsCallInfo.index;
296 std::cout << "please enter the update call mode():";
297 int32_t mode = 0;
298 std::cin >> mode;
299 imsCallPtr->UpdateImsCallMode(updateImsCallInfo, static_cast<ImsCallMode>(mode));
300 return IMS_TEST_SUCCESS;
301 }
302
GetImsCallsDataRequest(const sptr<ImsCallInterfaceCode> & imsCallPtr) const303 int32_t ImsUnitTest::GetImsCallsDataRequest(const sptr<ImsCallInterfaceCode> &imsCallPtr) const
304 {
305 std::cout << "please enter the slot id:";
306 int32_t slotId = 0;
307 std::cin >> slotId;
308 std::cout << "please enter the last calls data flag:";
309 int64_t flag = 0;
310 std::cin >> flag;
311 imsCallPtr->GetImsCallsDataRequest(slotId, flag);
312 return IMS_TEST_SUCCESS;
313 }
314
GetLastCallFailReason(const sptr<ImsCallInterfaceCode> & imsCallPtr) const315 int32_t ImsUnitTest::GetLastCallFailReason(const sptr<ImsCallInterfaceCode> &imsCallPtr) const
316 {
317 std::cout << "please enter the slot id:";
318 int32_t slotId = 0;
319 std::cin >> slotId;
320 imsCallPtr->GetLastCallFailReason(slotId);
321 return IMS_TEST_SUCCESS;
322 }
323
StartDtmf(const sptr<ImsCallInterfaceCode> & imsCallPtr) const324 int32_t ImsUnitTest::StartDtmf(const sptr<ImsCallInterfaceCode> &imsCallPtr) const
325 {
326 std::cout << "test StartDtmf entry." << std::endl;
327 std::cout << "please enter the dtmf code(0-9,#,*,A,D):";
328 char startDtmfCode;
329 std::cin >> startDtmfCode;
330 std::cout << "please enter the index:";
331 int32_t index = 0;
332 std::cin >> index;
333 std::cout << "please enter the slot id:";
334 int32_t slotId = 0;
335 std::cin >> slotId;
336 imsCallPtr->StartDtmf(slotId, startDtmfCode, index);
337 return IMS_TEST_SUCCESS;
338 }
339
SendDtmf(const sptr<ImsCallInterfaceCode> & imsCallPtr) const340 int32_t ImsUnitTest::SendDtmf(const sptr<ImsCallInterfaceCode> &imsCallPtr) const
341 {
342 std::cout << "test SendDtmf entry." << std::endl;
343 std::cout << "please enter the dtmf code(0-9,#,*,A,D):";
344 char sendDtmfCode;
345 std::cin >> sendDtmfCode;
346 std::cout << "please enter the index:";
347 int32_t index = 0;
348 std::cin >> index;
349 std::cout << "please enter the slot id:";
350 int32_t slotId = 0;
351 std::cin >> slotId;
352 imsCallPtr->SendDtmf(slotId, sendDtmfCode, index);
353 return IMS_TEST_SUCCESS;
354 }
355
StopDtmf(const sptr<ImsCallInterfaceCode> & imsCallPtr) const356 int32_t ImsUnitTest::StopDtmf(const sptr<ImsCallInterfaceCode> &imsCallPtr) const
357 {
358 std::cout << "test StopDtmf entry." << std::endl;
359 std::cout << "please enter the index:";
360 int32_t stopDtmfIndex = 0;
361 std::cin >> stopDtmfIndex;
362 std::cout << "please enter the slot id:";
363 int32_t slotId = 0;
364 std::cin >> slotId;
365 imsCallPtr->StopDtmf(slotId, stopDtmfIndex);
366 return IMS_TEST_SUCCESS;
367 }
368
StartRtt(const sptr<ImsCallInterfaceCode> & imsCallPtr) const369 int32_t ImsUnitTest::StartRtt(const sptr<ImsCallInterfaceCode> &imsCallPtr) const
370 {
371 std::cout << "test StartRtt entry." << std::endl;
372 std::cout << "please enter the send msg:";
373 std::string startRttMsg;
374 std::cin >> startRttMsg;
375 std::cout << "please enter the slot id:";
376 int32_t slotId = 0;
377 std::cin >> slotId;
378 imsCallPtr->StartRtt(slotId, startRttMsg);
379 return IMS_TEST_SUCCESS;
380 }
381
StopRtt(const sptr<ImsCallInterfaceCode> & imsCallPtr) const382 int32_t ImsUnitTest::StopRtt(const sptr<ImsCallInterfaceCode> &imsCallPtr) const
383 {
384 std::cout << "test StopRtt entry." << std::endl;
385 std::cout << "please enter the slot id:";
386 int32_t slotId = 0;
387 std::cin >> slotId;
388 imsCallPtr->StopRtt(slotId);
389 return IMS_TEST_SUCCESS;
390 }
391
SetDomainPreferenceMode(const sptr<ImsCallInterfaceCode> & imsCallPtr) const392 int32_t ImsUnitTest::SetDomainPreferenceMode(const sptr<ImsCallInterfaceCode> &imsCallPtr) const
393 {
394 std::cout << "test SetDomainPreferenceMode entry." << std::endl;
395 std::cout << "please enter the need mode:(1 - 4)";
396 int32_t domainPrefMode;
397 std::cin >> domainPrefMode;
398 std::cout << "please enter the slot id:";
399 int32_t slotId = 0;
400 std::cin >> slotId;
401 imsCallPtr->SetDomainPreferenceMode(slotId, domainPrefMode);
402 return IMS_TEST_SUCCESS;
403 }
404
GetDomainPreferenceMode(const sptr<ImsCallInterfaceCode> & imsCallPtr) const405 int32_t ImsUnitTest::GetDomainPreferenceMode(const sptr<ImsCallInterfaceCode> &imsCallPtr) const
406 {
407 std::cout << "test GetDomainPreferenceMode entry." << std::endl;
408 std::cout << "please enter the slot id:";
409 int32_t slotId = 0;
410 std::cin >> slotId;
411 imsCallPtr->GetDomainPreferenceMode(slotId);
412 return IMS_TEST_SUCCESS;
413 }
414
SetImsSwitchStatus(const sptr<ImsCallInterfaceCode> & imsCallPtr) const415 int32_t ImsUnitTest::SetImsSwitchStatus(const sptr<ImsCallInterfaceCode> &imsCallPtr) const
416 {
417 std::cout << "test SetImsSwitchStatus entry." << std::endl;
418 std::cout << "please enter the switch state:";
419 bool switchStatus;
420 std::cin >> switchStatus;
421 std::cout << "please enter the slot id:";
422 int32_t slotId = 0;
423 std::cin >> slotId;
424 imsCallPtr->SetImsSwitchStatus(slotId, switchStatus);
425 return IMS_TEST_SUCCESS;
426 }
427
GetImsSwitchStatus(const sptr<ImsCallInterfaceCode> & imsCallPtr) const428 int32_t ImsUnitTest::GetImsSwitchStatus(const sptr<ImsCallInterfaceCode> &imsCallPtr) const
429 {
430 std::cout << "test GetImsSwitchStatus entry." << std::endl;
431 std::cout << "please enter the slot id:";
432 int32_t slotId = 0;
433 std::cin >> slotId;
434 imsCallPtr->GetImsSwitchStatus(slotId);
435 return IMS_TEST_SUCCESS;
436 }
437
SetImsConfigString(const sptr<ImsCallInterfaceCode> & imsCallPtr) const438 int32_t ImsUnitTest::SetImsConfigString(const sptr<ImsCallInterfaceCode> &imsCallPtr) const
439 {
440 std::cout << "test SetImsConfigString entry." << std::endl;
441 std::cout << "please enter the item id:";
442 int32_t imsConfigItem = 0;
443 std::cin >> imsConfigItem;
444 std::cout << "please enter the item value:";
445 std::string value;
446 std::cin >> value;
447 imsCallPtr->SetImsConfig(static_cast<ImsConfigItem>(imsConfigItem), value);
448 return IMS_TEST_SUCCESS;
449 }
450
SetImsConfigInt(const sptr<ImsCallInterfaceCode> & imsCallPtr) const451 int32_t ImsUnitTest::SetImsConfigInt(const sptr<ImsCallInterfaceCode> &imsCallPtr) const
452 {
453 std::cout << "test SetImsConfigInt entry." << std::endl;
454 std::cout << "please enter the item id:";
455 int32_t imsConfigItem = 0;
456 std::cin >> imsConfigItem;
457 std::cout << "please enter the item value:";
458 int32_t value = 0;
459 std::cin >> value;
460 imsCallPtr->SetImsConfig(static_cast<ImsConfigItem>(imsConfigItem), value);
461 return IMS_TEST_SUCCESS;
462 }
463
GetImsConfig(const sptr<ImsCallInterfaceCode> & imsCallPtr) const464 int32_t ImsUnitTest::GetImsConfig(const sptr<ImsCallInterfaceCode> &imsCallPtr) const
465 {
466 std::cout << "test GetImsConfig entry." << std::endl;
467 std::cout << "please enter the item id:";
468 int32_t item = 0;
469 std::cin >> item;
470 imsCallPtr->GetImsConfig(static_cast<ImsConfigItem>(item));
471 return IMS_TEST_SUCCESS;
472 }
473
SetImsFeatureValue(const sptr<ImsCallInterfaceCode> & imsCallPtr) const474 int32_t ImsUnitTest::SetImsFeatureValue(const sptr<ImsCallInterfaceCode> &imsCallPtr) const
475 {
476 std::cout << "test SetImsFeatureValue entry." << std::endl;
477 std::cout << "please enter the feature type:";
478 int32_t imsFeatureType = 0;
479 std::cin >> imsFeatureType;
480 std::cout << "please enter the feature value:";
481 int32_t value = 0;
482 std::cin >> value;
483 imsCallPtr->SetImsFeatureValue(static_cast<FeatureType>(type), value);
484 return IMS_TEST_SUCCESS;
485 }
486
GetImsFeatureValue(const sptr<ImsCallInterfaceCode> & imsCallPtr) const487 int32_t ImsUnitTest::GetImsFeatureValue(const sptr<ImsCallInterfaceCode> &imsCallPtr) const
488 {
489 std::cout << "test GetImsFeatureValue entry." << std::endl;
490 std::cout << "please enter the feature type:";
491 int32_t imsFeatureType = 0;
492 std::cin >> imsFeatureType;
493 int32_t value;
494 imsCallPtr->GetImsFeatureValue(static_cast<FeatureType>(type), value);
495 std::cout << "test GetImsFeatureValue value:" << value;
496 return IMS_TEST_SUCCESS;
497 }
498
SetMute(const sptr<ImsCallInterfaceCode> & imsCallPtr) const499 int32_t ImsUnitTest::SetMute(const sptr<ImsCallInterfaceCode> &imsCallPtr) const
500 {
501 std::cout << "test SetMute entry.\n";
502 int32_t slotId = 0;
503 std::cout << "please enter the mute(0 - 1):";
504 int32_t mute = -1;
505 std::cin >> mute;
506 return imsCallPtr->SetMute(slotId, mute);
507 }
508
GetMute(const sptr<ImsCallInterfaceCode> & imsCallPtr) const509 int32_t ImsUnitTest::GetMute(const sptr<ImsCallInterfaceCode> &imsCallPtr) const
510 {
511 std::cout << "test GetMute entry.\n";
512 int32_t slotId = 0;
513 return imsCallPtr->GetMute(slotId);
514 }
515
CtrlCamera(const sptr<ImsCallInterfaceCode> & imsCallPtr) const516 int32_t ImsUnitTest::CtrlCamera(const sptr<ImsCallInterfaceCode> &imsCallPtr) const
517 {
518 std::cout << "test CtrlCamera entry." << std::endl;
519 std::u16string cameraId = u"cameraId";
520 int32_t callingUid = 0;
521 int32_t callingPid = 0;
522 imsCallPtr->CtrlCamera(cameraId, callingUid, callingPid);
523 return IMS_TEST_SUCCESS;
524 }
525
SetPreviewWindow(const sptr<ImsCallInterfaceCode> & imsCallPtr) const526 int32_t ImsUnitTest::SetPreviewWindow(const sptr<ImsCallInterfaceCode> &imsCallPtr) const
527 {
528 std::cout << "test SetPreviewWindow entry." << std::endl;
529 int32_t previewWindowX = 0;
530 int32_t previewWindowY = 0;
531 int32_t previewWindowZ = 0;
532 int32_t width = 0;
533 int32_t height = 0;
534 imsCallPtr->SetPreviewWindow(previewWindowX, previewWindowY, previewWindowZ, width, height);
535 return IMS_TEST_SUCCESS;
536 }
537
SetDisplayWindow(const sptr<ImsCallInterfaceCode> & imsCallPtr) const538 int32_t ImsUnitTest::SetDisplayWindow(const sptr<ImsCallInterfaceCode> &imsCallPtr) const
539 {
540 std::cout << "test SetDisplayWindow entry." << std::endl;
541 int32_t displayWindowX = 0;
542 int32_t displayWindowY = 0;
543 int32_t displayWindowZ = 0;
544 int32_t width = 0;
545 int32_t height = 0;
546 imsCallPtr->SetDisplayWindow(displayWindowX, displayWindowY, displayWindowZ, width, height);
547 return IMS_TEST_SUCCESS;
548 }
549
SetCameraZoom(const sptr<ImsCallInterfaceCode> & imsCallPtr) const550 int32_t ImsUnitTest::SetCameraZoom(const sptr<ImsCallInterfaceCode> &imsCallPtr) const
551 {
552 std::cout << "test SetCameraZoom entry." << std::endl;
553 float zoomRatio = 1.0;
554 imsCallPtr->SetCameraZoom(zoomRatio);
555 return IMS_TEST_SUCCESS;
556 }
557
SetPauseImage(const sptr<ImsCallInterfaceCode> & imsCallPtr) const558 int32_t ImsUnitTest::SetPauseImage(const sptr<ImsCallInterfaceCode> &imsCallPtr) const
559 {
560 std::cout << "test SetPauseImage entry." << std::endl;
561 std::u16string path = u"path";
562 imsCallPtr->SetPauseImage(path);
563 return IMS_TEST_SUCCESS;
564 }
565
SetDeviceDirection(const sptr<ImsCallInterfaceCode> & imsCallPtr) const566 int32_t ImsUnitTest::SetDeviceDirection(const sptr<ImsCallInterfaceCode> &imsCallPtr) const
567 {
568 std::cout << "test SetDeviceDirection entry." << std::endl;
569 int32_t rotation = 0;
570 imsCallPtr->SetDeviceDirection(rotation);
571 return IMS_TEST_SUCCESS;
572 }
573
GetClip(const sptr<ImsCallInterfaceCode> & imsCallPtr) const574 int32_t ImsUnitTest::GetClip(const sptr<ImsCallInterfaceCode> &imsCallPtr) const
575 {
576 std::cout << "please enter the slot id:";
577 int32_t slotId = 0;
578 std::cin >> slotId;
579 imsCallPtr->GetClip(slotId);
580 return IMS_TEST_SUCCESS;
581 }
582
SetClir(const sptr<ImsCallInterfaceCode> & imsCallPtr) const583 int32_t ImsUnitTest::SetClir(const sptr<ImsCallInterfaceCode> &imsCallPtr) const
584 {
585 std::cout << "please enter the slot id:";
586 int32_t slotId = 0;
587 std::cin >> slotId;
588 std::cout << "please enter the action:";
589 int32_t action = 0;
590 std::cin >> action;
591 imsCallPtr->SetClir(slotId, action);
592 return IMS_TEST_SUCCESS;
593 }
594
GetClir(const sptr<ImsCallInterfaceCode> & imsCallPtr) const595 int32_t ImsUnitTest::GetClir(const sptr<ImsCallInterfaceCode> &imsCallPtr) const
596 {
597 std::cout << "please enter the slot id:";
598 int32_t slotId = 0;
599 std::cin >> slotId;
600 imsCallPtr->GetClir(slotId);
601 return IMS_TEST_SUCCESS;
602 }
603
SetCallTransfer(const sptr<ImsCallInterfaceCode> & imsCallPtr) const604 int32_t ImsUnitTest::SetCallTransfer(const sptr<ImsCallInterfaceCode> &imsCallPtr) const
605 {
606 std::cout << "test SetCallTransfer entry.\n";
607 int32_t slotId = 0;
608 std::cout << "please enter the transfer type(0 - 5):";
609 int32_t callTransferType = 0;
610 std::cin >> callTransferType;
611 std::cout << "please enter the transfer mode(0 - 4):";
612 int32_t mode = 0;
613 std::cin >> mode;
614 std::cout << "please enter the phone number:";
615 std::string transferNum;
616 std::cin >> transferNum;
617 int32_t classType = 1;
618 return imsCallPtr->SetCallTransfer(slotId, callTransferType, mode, transferNum, classType);
619 }
620
GetCallTransfer(const sptr<ImsCallInterfaceCode> & imsCallPtr) const621 int32_t ImsUnitTest::GetCallTransfer(const sptr<ImsCallInterfaceCode> &imsCallPtr) const
622 {
623 std::cout << "test GetCallTransfer entry.\n";
624 int32_t slotId = 0;
625 std::cout << "please enter the transfer type(0 - 5):";
626 int32_t type = 0;
627 std::cin >> type;
628 return imsCallPtr->GetCallTransfer(slotId, type);
629 }
630
SetCallRestriction(const sptr<ImsCallInterfaceCode> & imsCallPtr) const631 int32_t ImsUnitTest::SetCallRestriction(const sptr<ImsCallInterfaceCode> &imsCallPtr) const
632 {
633 std::cout << "test SetCallRestriction entry.\n";
634 int32_t slotId = 0;
635 std::cout << "please enter the fac:";
636 std::string fac = "AO";
637 std::cout << "please enter the call restriction password:";
638 char crRassword[IMS_TEST_MAX_PASSWORD] = { 0 };
639 std::cin >> crRassword;
640 std::cout << "please enter the mode:";
641 int32_t crMode = 0;
642 std::cin >> crMode;
643 int32_t ret = imsCallPtr->SetCallRestriction(slotId, fac, crMode, crRassword);
644 memset_s(crRassword, sizeof(crRassword), 0, sizeof(crRassword));
645 return ret;
646 }
647
GetCallRestriction(const sptr<ImsCallInterfaceCode> & imsCallPtr) const648 int32_t ImsUnitTest::GetCallRestriction(const sptr<ImsCallInterfaceCode> &imsCallPtr) const
649 {
650 std::cout << "test GetCallRestriction entry.\n";
651 int32_t slotId = 0;
652 std::cout << "please enter the fac:";
653 std::string facType = "AO";
654 return imsCallPtr->GetCallRestriction(slotId, facType);
655 }
656
SetCallWaiting(const sptr<ImsCallInterfaceCode> & imsCallPtr) const657 int32_t ImsUnitTest::SetCallWaiting(const sptr<ImsCallInterfaceCode> &imsCallPtr) const
658 {
659 std::cout << "test SetCallWaiting entry.\n";
660 bool activate = true;
661 int32_t slotId = 0;
662 return imsCallPtr->SetCallWaiting(slotId, activate, ServiceClassType::VOICE);
663 }
664
GetCallWaiting(const sptr<ImsCallInterfaceCode> & imsCallPtr) const665 int32_t ImsUnitTest::GetCallWaiting(const sptr<ImsCallInterfaceCode> &imsCallPtr) const
666 {
667 std::cout << "test GetCallWaiting entry.\n";
668 int32_t slotId = 0;
669 return imsCallPtr->GetCallWaiting(slotId);
670 }
671
SetSmsConfig(const sptr<ImsSmsInterface> & imsSmsPtr) const672 int32_t ImsUnitTest::SetSmsConfig(const sptr<ImsSmsInterface> &imsSmsPtr) const
673 {
674 std::cout << "test SetSmsConfig entry.\n";
675 int32_t imsSmsConfig = 1;
676 int32_t slotId = 0;
677 return imsSmsPtr->ImsSetSmsConfig(slotId, imsSmsConfig);
678 }
679
GetSmsConfig(const sptr<ImsSmsInterface> & imsSmsPtr) const680 int32_t ImsUnitTest::GetSmsConfig(const sptr<ImsSmsInterface> &imsSmsPtr) const
681 {
682 std::cout << "test GetSmsConfig entry.\n";
683 int32_t slotId = 0;
684 return imsSmsPtr->ImsGetSmsConfig(slotId);
685 }
686
SendMessage(const sptr<ImsSmsInterface> & imsSmsPtr) const687 int32_t ImsUnitTest::SendMessage(const sptr<ImsSmsInterface> &imsSmsPtr) const
688 {
689 std::cout << "test SendMessage entry.\n";
690 ImsMessageInfo imsMessageInfo;
691 int32_t slotId = 0;
692 imsMessageInfo.refId = 1;
693 return imsSmsPtr->ImsSendMessage(slotId, imsMessageInfo);
694 }
695
GetImsRegistrationStatus(const sptr<ImsCoreServiceInterface> & imsCoreSerivcePtr) const696 int32_t ImsUnitTest::GetImsRegistrationStatus(const sptr<ImsCoreServiceInterface> &imsCoreSerivcePtr) const
697 {
698 std::cout << "test GetImsRegistrationStatus entry.\n";
699 int32_t slotId = 0;
700 return imsCoreSerivcePtr->GetImsRegistrationStatus(slotId);
701 }
702
ImsCallTest() const703 int32_t ImsUnitTest::ImsCallTest() const
704 {
705 auto imsCallPtr = DelayedSingleton<ImsCallClient>::GetInstance()->GetImsCallProxy();
706 if (imsCallPtr == nullptr) {
707 std::cout << "\nimsCallPtr is nullptr, Init ImsCall Failed!\n";
708 return IMS_TEST_ERROR;
709 }
710 std::shared_ptr<ImsTestHandler> handler = std::make_shared<ImsTestHandler>();
711 handler->RegisterImsCall();
712 int32_t ret = -1;
713 int32_t inputNum = 0;
714 int32_t returnNum = 1000; // end loop variable value
715 bool loopFlag = true;
716 while (loopFlag) {
717 std::cout << "\n**********Unit Test Start**********\n"
718 "Usage: please input a cmd num:\n"
719 "1:Dial\n2:HangUp\n3:RejectWithReason\n4:Answer\n5:HoldCall\n6:UnHoldCall\n7:SwitchCall\n"
720 "8:CombineConference\n9:InviteToConference\n10:KickOutFromConference\n11:UpdateImsCallMode\n"
721 "13:GetImsCallsDataRequest\n14:GetLastCallFailReason\n100:StartDtmf\n101:SendDtmf\n102:StopDtmf\n"
722 "103:StartRtt\n104:StopRtt\n200:SetCallPreferenceMode\n201:GetCallPreferenceMode\n202:"
723 "SetImsSwitchStatus\n203:GetImsSwitchStatus\n204:SetImsConfigString\n205:SetImsConfigInt\n"
724 "206:GetImsConfig\n207:SetImsFeatureValue\n208:GetImsFeatureValue\n"
725 "209:SetMute\n210:GetMute\n300:CtrlCamera\n301:SetPreviewWindow\n"
726 "302:SetDisplayWindow\n303:SetCameraZoom\n304:SetPauseImage\n305:SetDeviceDirection\n"
727 "400:GetClip\n401:SetClir\n402:GetClir\n"
728 "403:SetCallTransfer\n404:GetCallTransfer\n405:SetCallRestriction\n406:GetCallRestriction\n"
729 "407:SetCallWaiting\n408:GetCallWaiting\n"
730 "500:RegisterCellularCallBack\n501:IsCallBackExists\n"
731 "1000:Exit\n"
732 "***********************************\n"
733 "Your choice: ";
734 std::cin >> inputNumber;
735 if (inputNumber == returnNum) {
736 std::cout << "exiting...\n";
737 break;
738 }
739 auto itFunc = requestCallFuncMap_.find(inputNumber);
740 if (itFunc != requestCallFuncMap_.end()) {
741 auto requestFunction = itFunc->second;
742 if (requestFunction != nullptr) {
743 ret = (this->*requestFunction)(imsCallPtr);
744 }
745 }
746 if (ret != IMS_TEST_SUCCESS) {
747 std::cout << "this execution did not return a successful value, please check.\n";
748 return ret;
749 }
750 }
751 return IMS_TEST_SUCCESS;
752 }
753
ImsSmsTest() const754 int32_t ImsUnitTest::ImsSmsTest() const
755 {
756 auto imsSmsPtr = DelayedSingleton<ImsSmsClient>::GetInstance()->GetImsSmsProxy();
757 if (imsSmsPtr == nullptr) {
758 std::cout << "\nimsSmsPtr is nullptr, Init ImsSms Failed!\n";
759 return IMS_TEST_ERROR;
760 }
761 std::shared_ptr<ImsTestHandler> handler = std::make_shared<ImsTestHandler>();
762 handler->RegisterImsSms();
763 int32_t ret = -1;
764 int32_t inputNum = 0;
765 int32_t returnNum = 1000; // end loop variable value
766 bool loopFlag = true;
767 while (loopFlag) {
768 std::cout << "\n**********Unit Test Start**********\n"
769 "Usage: please input a cmd num:\n"
770 "0:SendMessage\n"
771 "100:SetSmsConfig\n"
772 "101:GetSmsConfig\n"
773 "1000:Exit\n"
774 "***********************************\n"
775 "Your choice: ";
776 std::cin >> inputNum;
777 if (inputNum == returnNum) {
778 std::cout << "exiting...\n";
779 break;
780 }
781 auto itFunc = requestSmsFuncMap_.find(inputNum);
782 if (itFunc != requestSmsFuncMap_.end()) {
783 auto requestFunc = itFunc->second;
784 if (requestFunc != nullptr) {
785 ret = (this->*requestFunc)(imsSmsPtr);
786 }
787 }
788 if (ret != IMS_TEST_SUCCESS) {
789 std::cout << "this execution did not return a successful value, please check.\n";
790 return ret;
791 }
792 }
793 return IMS_TEST_SUCCESS;
794 }
795
ImsCoreServiceTest() const796 int32_t ImsUnitTest::ImsCoreServiceTest() const
797 {
798 auto imsCoreSerivcePtr = DelayedSingleton<ImsCoreServiceClient>::GetInstance()->GetImsCoreServiceProxy();
799 if (imsCoreSerivcePtr == nullptr) {
800 std::cout << "\nimsCoreSerivcePtr is nullptr, Init ImsCoreService Failed!\n";
801 return IMS_TEST_ERROR;
802 }
803 std::shared_ptr<ImsTestHandler> handler = std::make_shared<ImsTestHandler>();
804 handler->RegisterImsCoreService();
805 int32_t ret = -1;
806 int32_t inputNumber = 0;
807 int32_t returnNum = 1000; // end loop variable value
808 bool loopFlag = true;
809 while (loopFlag) {
810 std::cout << "\n**********Unit Test Start**********\n"
811 "Usage: please input a cmd num:\n"
812 "0:GetImsRegistrationStatus\n"
813 "1000:Exit\n"
814 "***********************************\n"
815 "Your choice: ";
816 std::cin >> inputNumber;
817 if (inputNumber == returnNum) {
818 std::cout << "exiting...\n";
819 break;
820 }
821 auto itFunc = requestCoreServiceFuncMap_.find(inputNumber);
822 if (itFunc != requestCoreServiceFuncMap_.end()) {
823 auto requestFunction = itFunc->second;
824 if (requestFunction != nullptr) {
825 ret = (this->*requestFunction)(imsCoreSerivcePtr);
826 }
827 }
828 if (ret != IMS_TEST_SUCCESS) {
829 std::cout << "this execution did not return a successful value, please check.\n";
830 return ret;
831 }
832 }
833 return IMS_TEST_SUCCESS;
834 }
835 } // namespace Telephony
836 } // namespace OHOS
837
838 using namespace OHOS::Telephony;
main()839 int32_t main()
840 {
841 std::unique_ptr<ImsUnitTest> test = std::make_unique<ImsUnitTest>();
842 const int32_t callTest = 1;
843 const int32_t smsTest = 2;
844 const int32_t coreServiceTest = 3;
845 const int32_t codeExit = 1000;
846 int32_t code;
847 test->SetUp();
848 std::cout << "Please select interface type...." << std::endl;
849 while (true) {
850 std::cout << "\n1:ims call interface\n"
851 "2:ims sms interface\n"
852 "3:ims core service interface\n"
853 "1000:exit\n";
854 std::cin >> code;
855 switch (code) {
856 case callTest:
857 test->ImsCallTest();
858 break;
859 case smsTest:
860 test->ImsSmsTest();
861 break;
862 case coreServiceTest:
863 test->ImsCoreServiceTest();
864 break;
865 case codeExit:
866 break;
867 default:
868 std::cout << "invalid input" << std::endl;
869 break;
870 }
871 if (code == codeExit) {
872 break;
873 }
874 }
875 return OHOS::Telephony::TELEPHONY_SUCCESS;
876 }
877