1 /*
2 * Copyright (C) 2021-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 #define private public
17 #define protected public
18 #include "call_manager_gtest.h"
19
20 #include <gtest/gtest.h>
21 #include <cstring>
22 #include <string>
23
24 #include "bluetooth_hfp_ag.h"
25 #include "call_manager_connect.h"
26 #include "call_manager_service.h"
27 #include "surface_utils.h"
28 #include "telephony_types.h"
29 #include "voip_call.h"
30
31 using namespace OHOS::Bluetooth;
32 namespace OHOS {
33 namespace Telephony {
34 using namespace testing::ext;
35 constexpr int16_t SIM2_SLOTID = 1;
36 constexpr int16_t SIM1_SLOTID_NO_CARD = 0;
37 constexpr int16_t RETURN_VALUE_IS_ZERO = 0;
38 constexpr int16_t INVALID_NEGATIVE_ID = -100;
39 constexpr int16_t INVALID_POSITIVE_ID = 100;
40 constexpr int INVALID_DIAL_TYPE = 3;
41 constexpr int WAIT_TIME = 3;
42 constexpr int16_t CAMERA_ROTATION_90 = 90;
43 constexpr int16_t CAMERA_ROTATION_ERROR = 50;
44 constexpr int16_t SLEEP_1000_MS = 1000;
45 constexpr int BASE_TIME_MS = 1000;
46 constexpr int SLEEP_TIME_MS = 50;
47 constexpr int MAX_LIMIT_TIME = 18000;
48 constexpr int16_t SIM1_SLOTID = 0;
49 const std::string PHONE_NUMBER = "0000000000";
50
51 std::unordered_map<int32_t, std::unordered_set<int32_t>> g_callStateMap;
52 int32_t g_newCallId = -1;
53 std::mutex CallInfoManager::mutex_;
54 int16_t CallInfoManager::newCallState_;
55 CallAttributeInfo CallInfoManager::updateCallInfo_;
56 std::unordered_set<int32_t> CallInfoManager::callIdSet_;
57
CallDetailsChange(const CallAttributeInfo & info)58 int32_t CallInfoManager::CallDetailsChange(const CallAttributeInfo &info)
59 {
60 TELEPHONY_LOGI("CallDetailsChange Start");
61 std::lock_guard<std::mutex> lock(mutex_);
62 updateCallInfo_ = info;
63 if (callIdSet_.find(updateCallInfo_.callId) == callIdSet_.end()) {
64 TELEPHONY_LOGI("CallDetailsChange new call");
65 callIdSet_.insert(updateCallInfo_.callId);
66 g_newCallId = updateCallInfo_.callId;
67 newCallState_ = (int32_t)updateCallInfo_.callState;
68 std::unordered_set<int32_t> newSet;
69 newSet.clear();
70 g_callStateMap.insert(std::pair<int32_t, std::unordered_set<int32_t>>(g_newCallId, newSet));
71 }
72 g_callStateMap[updateCallInfo_.callId].insert((int32_t)updateCallInfo_.callState);
73 return TELEPHONY_SUCCESS;
74 }
75
MeeTimeDetailsChange(const CallAttributeInfo & info)76 int32_t CallInfoManager::MeeTimeDetailsChange(const CallAttributeInfo &info)
77 {
78 TELEPHONY_LOGI("MeeTimeDetailsChange Start");
79 std::lock_guard<std::mutex> lock(mutex_);
80 updateCallInfo_ = info;
81 if (callIdSet_.find(updateCallInfo_.callId) == callIdSet_.end()) {
82 TELEPHONY_LOGI("MeeTimeDetailsChange new call");
83 callIdSet_.insert(updateCallInfo_.callId);
84 g_newCallId = updateCallInfo_.callId;
85 newCallState_ = (int32_t)updateCallInfo_.callState;
86 std::unordered_set<int32_t> newSet;
87 newSet.clear();
88 g_callStateMap.insert(std::pair<int32_t, std::unordered_set<int32_t>>(g_newCallId, newSet));
89 }
90 g_callStateMap[updateCallInfo_.callId].insert((int32_t)updateCallInfo_.callState);
91 return TELEPHONY_SUCCESS;
92 }
93
HasActiveStatus()94 bool CallInfoManager::HasActiveStatus()
95 {
96 TELEPHONY_LOGI("Waiting for activation !");
97 int sumUseTime = 0;
98 int slipMs = SLEEP_TIME_MS;
99 do {
100 if (!(HasState(g_newCallId, static_cast<int32_t>(TelCallState::CALL_STATUS_ACTIVE)))) {
101 usleep(slipMs * BASE_TIME_MS);
102 sumUseTime += slipMs;
103 } else {
104 TELEPHONY_LOGI("===========wait %d ms callStatus:%d==============", sumUseTime, newCallState_);
105 return true;
106 }
107 } while (sumUseTime < MAX_LIMIT_TIME);
108 TELEPHONY_LOGI("===========wait %d ms callStatus:%d=====not active=========", sumUseTime, newCallState_);
109 return false;
110 }
111
HasState(int callId,int32_t callState)112 bool CallInfoManager::HasState(int callId, int32_t callState)
113 {
114 if (g_callStateMap.find(callId) == g_callStateMap.end()) {
115 return false;
116 }
117 if (g_callStateMap[callId].find(callState) == g_callStateMap[callId].end()) {
118 return false;
119 }
120 return true;
121 }
122
CallEventChange(const CallEventInfo & info)123 int32_t CallInfoManager::CallEventChange(const CallEventInfo &info)
124 {
125 return TELEPHONY_SUCCESS;
126 }
127
Init()128 void CallInfoManager::Init()
129 {
130 g_newCallId = -1;
131 updateCallInfo_.speakerphoneOn = -1;
132 updateCallInfo_.startTime = -1;
133 updateCallInfo_.isEcc = -1;
134 updateCallInfo_.accountId = -1;
135 updateCallInfo_.callType = CallType::TYPE_CS;
136 updateCallInfo_.callId = -1;
137 updateCallInfo_.callState = TelCallState::CALL_STATUS_IDLE;
138 updateCallInfo_.videoState = VideoStateType::TYPE_VOICE;
139 }
140
LockCallId(bool eq,int32_t targetId,int32_t slipMs,int32_t timeoutMs)141 void CallInfoManager::LockCallId(bool eq, int32_t targetId, int32_t slipMs, int32_t timeoutMs)
142 {
143 int32_t useTimeMs = 0;
144 std::cout << "wait for a few seconds......" << std::endl;
145 while ((updateCallInfo_.callId != targetId) && (useTimeMs < timeoutMs)) {
146 usleep(slipMs * SLEEP_1000_MS);
147 useTimeMs += slipMs;
148 }
149 std::cout << "\n===========wait " << useTimeMs << " ms target:" << updateCallInfo_.callId << std::endl;
150 if (eq) {
151 EXPECT_EQ(updateCallInfo_.callId, targetId);
152 } else {
153 EXPECT_NE(updateCallInfo_.callId, targetId);
154 }
155 }
156
LockCallState(bool eq,int32_t targetState,int32_t slipMs,int32_t timeoutMs)157 void CallInfoManager::LockCallState(bool eq, int32_t targetState, int32_t slipMs, int32_t timeoutMs)
158 {
159 if (CallManagerGtest::clientPtr_->GetCallState() == targetState) {
160 return;
161 }
162 int32_t usedTimeMs = 0;
163 std::cout << "wait for a few seconds......" << std::endl;
164 while ((CallManagerGtest::clientPtr_->GetCallState() != targetState) && (usedTimeMs < timeoutMs)) {
165 usleep(slipMs * SLEEP_1000_MS);
166 usedTimeMs += slipMs;
167 }
168 int32_t callState = CallManagerGtest::clientPtr_->GetCallState();
169 std::cout << "waited " << usedTimeMs << " seconds" << std::endl;
170 std::cout << "target call state:" << targetState << std::endl;
171 if (eq) {
172 EXPECT_EQ(callState, targetState);
173 } else {
174 EXPECT_NE(callState, targetState);
175 }
176 }
177
HangUpCall()178 void CallManagerGtest::HangUpCall()
179 {
180 clientPtr_->HangUpCall(INVALID_CALLID);
181 }
182
183 class ClientErrorBranchTest : public testing::Test {
184 public:
SetUpTestCase()185 static void SetUpTestCase() {};
TearDownTestCase()186 static void TearDownTestCase() {};
SetUp()187 void SetUp() {};
TearDown()188 void TearDown() {};
189 };
190
191 /******************************************* Test SetCameraZoom() *********************************************/
192 /**
193 * @tc.number Telephony_CallManager_SetCameraZoom_0100
194 * @tc.name input zoomRatio 5.0, Test SetCameraZoom
195 * @tc.desc Function test
196 */
197 HWTEST_F(CallManagerGtest, Telephony_CallManager_SetCameraZoom_0100, Function | MediumTest | Level2)
198 {
199 AccessToken token;
200 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
201 return;
202 }
203 float zoomRatio = 5.0;
204 EXPECT_EQ(CallManagerGtest::clientPtr_->SetCameraZoom(zoomRatio), RETURN_VALUE_IS_ZERO);
205 }
206
207 /**
208 * @tc.number Telephony_CallManager_SetCameraZoom_0200
209 * @tc.name input zoomRatio 0.1, Test SetCameraZoom
210 * @tc.desc Function test
211 */
212 HWTEST_F(CallManagerGtest, Telephony_CallManager_SetCameraZoom_0200, Function | MediumTest | Level2)
213 {
214 AccessToken token;
215 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
216 return;
217 }
218 float zoomRatio = 0.1;
219 EXPECT_EQ(CallManagerGtest::clientPtr_->SetCameraZoom(zoomRatio), RETURN_VALUE_IS_ZERO);
220 }
221
222 /**
223 * @tc.number Telephony_CallManager_SetCameraZoom_0300
224 * @tc.name input zoomRatio 10.0, Test SetCameraZoom
225 * @tc.desc Function test
226 */
227 HWTEST_F(CallManagerGtest, Telephony_CallManager_SetCameraZoom_0300, Function | MediumTest | Level2)
228 {
229 AccessToken token;
230 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
231 return;
232 }
233 float zoomRatio = 10.0;
234 EXPECT_EQ(CallManagerGtest::clientPtr_->SetCameraZoom(zoomRatio), RETURN_VALUE_IS_ZERO);
235 }
236
237 /**
238 * @tc.number Telephony_CallManager_SetCameraZoom_0400
239 * @tc.name input invalid para zoomRatio 15.0, Test SetCameraZoom, return error code if failed
240 * @tc.desc Function test
241 */
242 HWTEST_F(CallManagerGtest, Telephony_CallManager_SetCameraZoom_0400, Function | MediumTest | Level2)
243 {
244 AccessToken token;
245 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
246 return;
247 }
248 float zoomRatio = 15.0;
249 EXPECT_EQ(CallManagerGtest::clientPtr_->SetCameraZoom(zoomRatio), RETURN_VALUE_IS_ZERO);
250 }
251
252 /**
253 * @tc.number Telephony_CallManager_SetCameraZoom_0500
254 * @tc.name input invalid para zoomRatio 0.0, Test SetCameraZoom, return error code if failed
255 * @tc.desc Function test
256 */
257 HWTEST_F(CallManagerGtest, Telephony_CallManager_SetCameraZoom_0500, Function | MediumTest | Level2)
258 {
259 AccessToken token;
260 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
261 return;
262 }
263 float zoomRatio = 0.0;
264 EXPECT_EQ(CallManagerGtest::clientPtr_->SetCameraZoom(zoomRatio), RETURN_VALUE_IS_ZERO);
265 }
266
267 /**
268 * @tc.number Telephony_CallManager_SetCameraZoom_0600
269 * @tc.name input invalid para zoomRatio -1.0, Test SetCameraZoom, return error code if failed
270 * @tc.desc Function test
271 */
272 HWTEST_F(CallManagerGtest, Telephony_CallManager_SetCameraZoom_0600, Function | MediumTest | Level2)
273 {
274 AccessToken token;
275 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
276 return;
277 }
278 float zoomRatio = -1.0;
279 EXPECT_EQ(CallManagerGtest::clientPtr_->SetCameraZoom(zoomRatio), RETURN_VALUE_IS_ZERO);
280 }
281
282 /**
283 * @tc.number Telephony_CallManager_SetCameraZoom_0700
284 * @tc.name input invalid para zoomRatio 10.1, Test SetCameraZoom, return error code if failed
285 * @tc.desc Function test
286 */
287 HWTEST_F(CallManagerGtest, Telephony_CallManager_SetCameraZoom_0700, Function | MediumTest | Level2)
288 {
289 AccessToken token;
290 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
291 return;
292 }
293 float zoomRatio = 10.1;
294 EXPECT_EQ(CallManagerGtest::clientPtr_->SetCameraZoom(zoomRatio), RETURN_VALUE_IS_ZERO);
295 }
296 /******************************************* Test SetPausePicture() *********************************************/
297 /**
298 * @tc.number Telephony_CallManager_SetPausePicture_0100
299 * @tc.name input locale picture path /system/bin/test.png that does not exist, Test SetPausePicture,
300 * return error code if failed
301 * @tc.desc Function test
302 */
303 HWTEST_F(CallManagerGtest, Telephony_CallManager_SetPausePicture_0100, Function | MediumTest | Level2)
304 {
305 AccessToken token;
306 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
307 return;
308 }
309 int32_t callId = 1;
310 std::string pathTemp = "/system/bin/test.png";
311 std::u16string path = Str8ToStr16(pathTemp);
312 EXPECT_NE(CallManagerGtest::clientPtr_->SetPausePicture(callId, path), RETURN_VALUE_IS_ZERO);
313 }
314
315 /**
316 * @tc.number Telephony_CallManager_SetPausePicture_0200
317 * @tc.name input an invalid image format file path, Test SetPausePicture, return error code if failed
318 * @tc.desc Function test
319 */
320 HWTEST_F(CallManagerGtest, Telephony_CallManager_SetPausePicture_0200, Function | MediumTest | Level2)
321 {
322 AccessToken token;
323 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
324 return;
325 }
326 int32_t callId = 1;
327 std::string pathTemp = "/system/bin/test.jpg";
328 std::u16string path = Str8ToStr16(pathTemp);
329 EXPECT_NE(CallManagerGtest::clientPtr_->SetPausePicture(callId, path), RETURN_VALUE_IS_ZERO);
330 }
331
332 /**
333 * @tc.number Telephony_CallManager_SetPausePicture_0300
334 * @tc.name input an invalid image format file path, Test SetPausePicture, return error code if failed
335 * @tc.desc Function test
336 */
337 HWTEST_F(CallManagerGtest, Telephony_CallManager_SetPausePicture_0300, Function | MediumTest | Level2)
338 {
339 AccessToken token;
340 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
341 return;
342 }
343 int32_t callId = 1;
344 std::string pathTemp = "/system/bin/test.bmp";
345 std::u16string path = Str8ToStr16(pathTemp);
346 EXPECT_NE(CallManagerGtest::clientPtr_->SetPausePicture(callId, path), RETURN_VALUE_IS_ZERO);
347 }
348
349 /**
350 * @tc.number Telephony_CallManager_SetPausePicture_0400
351 * @tc.name input an invalid image format file path, Test SetPausePicture, return error code if failed
352 * @tc.desc Function test
353 */
354 HWTEST_F(CallManagerGtest, Telephony_CallManager_SetPausePicture_0400, Function | MediumTest | Level2)
355 {
356 AccessToken token;
357 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
358 return;
359 }
360 int32_t callId = 1;
361 std::string pathTemp = "/system/bin/test.webp";
362 std::u16string path = Str8ToStr16(pathTemp);
363 EXPECT_NE(CallManagerGtest::clientPtr_->SetPausePicture(callId, path), RETURN_VALUE_IS_ZERO);
364 }
365
366 /**
367 * @tc.number Telephony_CallManager_SetPausePicture_0500
368 * @tc.name input remote picture path http://callManager.jpg that does not exist, Test SetPausePicture,
369 * return error code if failed
370 * @tc.desc Function test
371 */
372 HWTEST_F(CallManagerGtest, Telephony_CallManager_SetPausePicture_0500, Function | MediumTest | Level2)
373 {
374 AccessToken token;
375 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
376 return;
377 }
378 int32_t callId = 1;
379 std::string pathTemp = "http://callManager.jpg";
380 std::u16string path = Str8ToStr16(pathTemp);
381 EXPECT_NE(CallManagerGtest::clientPtr_->SetPausePicture(callId, path), RETURN_VALUE_IS_ZERO);
382 }
383
384 /**
385 * @tc.number Telephony_CallManager_SetPausePicture_0600
386 * @tc.name input empty picture path, Test SetPausePicture, return error code if failed
387 * @tc.desc Function test
388 */
389 HWTEST_F(CallManagerGtest, Telephony_CallManager_SetPausePicture_0600, Function | MediumTest | Level2)
390 {
391 AccessToken token;
392 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
393 return;
394 }
395 int32_t callId = 1;
396 std::string pathTemp = "";
397 std::u16string path = Str8ToStr16(pathTemp);
398 EXPECT_NE(CallManagerGtest::clientPtr_->SetPausePicture(callId, path), RETURN_VALUE_IS_ZERO);
399 }
400
401 /**
402 * @tc.number Telephony_CallManager_CancelCallUpgrade_0100
403 * @tc.name input callId:1, Test CancelCallUpgrade, return error code if failed
404 * @tc.desc Function test
405 */
406 HWTEST_F(CallManagerGtest, Telephony_CallManager_CancelCallUpgrade_0100, Function | MediumTest | Level2)
407 {
408 AccessToken token;
409 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
410 return;
411 }
412 int32_t callId = 1;
413 EXPECT_NE(CallManagerGtest::clientPtr_->CancelCallUpgrade(callId), RETURN_VALUE_IS_ZERO);
414 }
415
416 /**
417 * @tc.number Telephony_CallManager_RequestCameraCapabilities_0100
418 * @tc.name input callId:1, Test RequestCameraCapabilities, return error code if failed
419 * @tc.desc Function test
420 */
421 HWTEST_F(CallManagerGtest, Telephony_CallManager_RequestCameraCapabilities_0100, Function | MediumTest | Level2)
422 {
423 AccessToken token;
424 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
425 return;
426 }
427 int32_t callId = 1;
428 EXPECT_NE(CallManagerGtest::clientPtr_->RequestCameraCapabilities(callId), RETURN_VALUE_IS_ZERO);
429 }
430
431 /********************************************* Test GetImsConfig() ************************************************/
432 /**
433 * @tc.number Telephony_CallManager_GetImsConfig_0100
434 * @tc.name test get ims config item video quality
435 * @tc.desc Function test
436 */
437 HWTEST_F(CallManagerGtest, Telephony_CallManager_GetImsConfig_0100, TestSize.Level0)
438 {
439 AccessToken token;
440 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
441 return;
442 }
443
444 if (HasSimCard(SIM1_SLOTID)) {
445 EXPECT_NE(CallManagerGtest::clientPtr_->GetImsConfig(SIM1_SLOTID, ITEM_VIDEO_QUALITY), RETURN_VALUE_IS_ZERO);
446 }
447 if (HasSimCard(SIM2_SLOTID)) {
448 EXPECT_NE(CallManagerGtest::clientPtr_->GetImsConfig(SIM2_SLOTID, ITEM_VIDEO_QUALITY), RETURN_VALUE_IS_ZERO);
449 }
450 }
451
452 /**
453 * @tc.number Telephony_CallManager_GetImsConfig_0200
454 * @tc.name test get ims config item ims switch status
455 * @tc.desc Function test
456 */
457 HWTEST_F(CallManagerGtest, Telephony_CallManager_GetImsConfig_0200, TestSize.Level0)
458 {
459 AccessToken token;
460 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
461 return;
462 }
463
464 if (HasSimCard(SIM1_SLOTID)) {
465 EXPECT_NE(
466 CallManagerGtest::clientPtr_->GetImsConfig(SIM1_SLOTID, ITEM_IMS_SWITCH_STATUS), RETURN_VALUE_IS_ZERO);
467 }
468 if (HasSimCard(SIM2_SLOTID)) {
469 EXPECT_NE(
470 CallManagerGtest::clientPtr_->GetImsConfig(SIM2_SLOTID, ITEM_IMS_SWITCH_STATUS), RETURN_VALUE_IS_ZERO);
471 }
472 }
473
474 /**
475 * @tc.number Telephony_CallManager_GetImsConfig_0300
476 * @tc.name test get ims config item with invalid item
477 * @tc.desc Function test
478 */
479 HWTEST_F(CallManagerGtest, Telephony_CallManager_GetImsConfig_0300, TestSize.Level1)
480 {
481 AccessToken token;
482 ImsConfigItem item = static_cast<ImsConfigItem>(2);
483 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
484 return;
485 }
486
487 if (HasSimCard(SIM1_SLOTID)) {
488 EXPECT_NE(CallManagerGtest::clientPtr_->GetImsConfig(SIM1_SLOTID, item), RETURN_VALUE_IS_ZERO);
489 }
490 if (HasSimCard(SIM2_SLOTID)) {
491 EXPECT_NE(CallManagerGtest::clientPtr_->GetImsConfig(SIM2_SLOTID, item), RETURN_VALUE_IS_ZERO);
492 }
493 }
494
495 /********************************************* Test SetImsConfig() ************************************************/
496 /**
497 * @tc.number Telephony_CallManager_SetImsConfig_0100
498 * @tc.name test set ims config item video quality
499 * @tc.desc Function test
500 */
501 HWTEST_F(CallManagerGtest, Telephony_CallManager_SetImsConfig_0100, TestSize.Level0)
502 {
503 AccessToken token;
504 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
505 return;
506 }
507
508 std::u16string value = u"123";
509 if (HasSimCard(SIM1_SLOTID)) {
510 EXPECT_NE(
511 CallManagerGtest::clientPtr_->SetImsConfig(SIM1_SLOTID, ITEM_VIDEO_QUALITY, value), RETURN_VALUE_IS_ZERO);
512 }
513 if (HasSimCard(SIM2_SLOTID)) {
514 EXPECT_NE(
515 CallManagerGtest::clientPtr_->SetImsConfig(SIM2_SLOTID, ITEM_VIDEO_QUALITY, value), RETURN_VALUE_IS_ZERO);
516 }
517 }
518
519 /**
520 * @tc.number Telephony_CallManager_SetImsConfig_0200
521 * @tc.name test set ims config item ims switch status
522 * @tc.desc Function test
523 */
524 HWTEST_F(CallManagerGtest, Telephony_CallManager_SetImsConfig_0200, TestSize.Level0)
525 {
526 AccessToken token;
527 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
528 return;
529 }
530
531 std::u16string value = u"123";
532 if (HasSimCard(SIM1_SLOTID)) {
533 EXPECT_NE(CallManagerGtest::clientPtr_->SetImsConfig(SIM1_SLOTID, ITEM_IMS_SWITCH_STATUS, value),
534 RETURN_VALUE_IS_ZERO);
535 }
536 if (HasSimCard(SIM2_SLOTID)) {
537 EXPECT_NE(CallManagerGtest::clientPtr_->SetImsConfig(SIM2_SLOTID, ITEM_IMS_SWITCH_STATUS, value),
538 RETURN_VALUE_IS_ZERO);
539 }
540 }
541
542 /**
543 * @tc.number Telephony_CallManager_SetImsConfig_0300
544 * @tc.name test set ims config item with invalid item
545 * @tc.desc Function test
546 */
547 HWTEST_F(CallManagerGtest, Telephony_CallManager_SetImsConfig_0300, TestSize.Level0)
548 {
549 AccessToken token;
550 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
551 return;
552 }
553
554 std::u16string value = u"123";
555 ImsConfigItem item = static_cast<ImsConfigItem>(2);
556 if (HasSimCard(SIM1_SLOTID)) {
557 EXPECT_NE(CallManagerGtest::clientPtr_->SetImsConfig(SIM1_SLOTID, item, value), RETURN_VALUE_IS_ZERO);
558 }
559 if (HasSimCard(SIM2_SLOTID)) {
560 EXPECT_NE(CallManagerGtest::clientPtr_->SetImsConfig(SIM2_SLOTID, item, value), RETURN_VALUE_IS_ZERO);
561 }
562 }
563
564 /*********************************** Test GetImsFeatureValue() ****************************************/
565 /**
566 * @tc.number Telephony_CallManager_GetImsFeatureValue_0100
567 * @tc.name test get ims feature value type voice over lte
568 * @tc.desc Function test
569 */
570 HWTEST_F(CallManagerGtest, Telephony_CallManager_GetImsFeatureValue_0100, TestSize.Level0)
571 {
572 AccessToken token;
573 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
574 return;
575 }
576
577 if (HasSimCard(SIM1_SLOTID)) {
578 EXPECT_NE(
579 CallManagerGtest::clientPtr_->GetImsFeatureValue(SIM1_SLOTID, TYPE_VOICE_OVER_LTE), RETURN_VALUE_IS_ZERO);
580 }
581 if (HasSimCard(SIM2_SLOTID)) {
582 EXPECT_NE(
583 CallManagerGtest::clientPtr_->GetImsFeatureValue(SIM2_SLOTID, TYPE_VOICE_OVER_LTE), RETURN_VALUE_IS_ZERO);
584 }
585 }
586
587 /**
588 * @tc.number Telephony_CallManager_GetImsFeatureValue_0200
589 * @tc.name test get ims feature value type video over lte
590 * @tc.desc Function test
591 */
592 HWTEST_F(CallManagerGtest, Telephony_CallManager_GetImsFeatureValue_0200, TestSize.Level0)
593 {
594 AccessToken token;
595 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
596 return;
597 }
598
599 if (HasSimCard(SIM1_SLOTID)) {
600 EXPECT_NE(
601 CallManagerGtest::clientPtr_->GetImsFeatureValue(SIM1_SLOTID, TYPE_VIDEO_OVER_LTE), RETURN_VALUE_IS_ZERO);
602 }
603 if (HasSimCard(SIM2_SLOTID)) {
604 EXPECT_NE(
605 CallManagerGtest::clientPtr_->GetImsFeatureValue(SIM2_SLOTID, TYPE_VIDEO_OVER_LTE), RETURN_VALUE_IS_ZERO);
606 }
607 }
608
609 /**
610 * @tc.number Telephony_CallManager_GetImsFeatureValue_0300
611 * @tc.name test get ims feature value type ss over ut
612 * @tc.desc Function test
613 */
614 HWTEST_F(CallManagerGtest, Telephony_CallManager_GetImsFeatureValue_0300, TestSize.Level0)
615 {
616 AccessToken token;
617 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
618 return;
619 }
620
621 if (HasSimCard(SIM1_SLOTID)) {
622 EXPECT_NE(CallManagerGtest::clientPtr_->GetImsFeatureValue(SIM1_SLOTID, TYPE_SS_OVER_UT),
623 RETURN_VALUE_IS_ZERO);
624 }
625 if (HasSimCard(SIM2_SLOTID)) {
626 EXPECT_NE(CallManagerGtest::clientPtr_->GetImsFeatureValue(SIM2_SLOTID, TYPE_SS_OVER_UT),
627 RETURN_VALUE_IS_ZERO);
628 }
629 }
630
631 /**
632 * @tc.number Telephony_CallManager_GetImsFeatureValue_0400
633 * @tc.name test get ims feature value with invalid type
634 * @tc.desc Function test
635 */
636 HWTEST_F(CallManagerGtest, Telephony_CallManager_GetImsFeatureValue_0400, TestSize.Level0)
637 {
638 AccessToken token;
639 FeatureType type = static_cast<FeatureType>(3);
640 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
641 return;
642 }
643
644 if (HasSimCard(SIM1_SLOTID)) {
645 EXPECT_NE(CallManagerGtest::clientPtr_->GetImsFeatureValue(SIM1_SLOTID, type), RETURN_VALUE_IS_ZERO);
646 }
647 if (HasSimCard(SIM2_SLOTID)) {
648 EXPECT_NE(CallManagerGtest::clientPtr_->GetImsFeatureValue(SIM2_SLOTID, type), RETURN_VALUE_IS_ZERO);
649 }
650 }
651
652 /***************************************** Test SetImsFeatureValue() ***************************************/
653 /**
654 * @tc.number Telephony_CallManager_SetImsFeatureValue_0100
655 * @tc.name test set ims feature value type voice over lte
656 * @tc.desc Function test
657 */
658 HWTEST_F(CallManagerGtest, Telephony_CallManager_SetImsFeatureValue_0100, TestSize.Level0)
659 {
660 AccessToken token;
661 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
662 return;
663 }
664
665 int32_t value = 1;
666 if (HasSimCard(SIM1_SLOTID)) {
667 EXPECT_NE(CallManagerGtest::clientPtr_->SetImsFeatureValue(SIM1_SLOTID, TYPE_VOICE_OVER_LTE, value),
668 RETURN_VALUE_IS_ZERO);
669 }
670 if (HasSimCard(SIM2_SLOTID)) {
671 EXPECT_NE(CallManagerGtest::clientPtr_->SetImsFeatureValue(SIM2_SLOTID, TYPE_VOICE_OVER_LTE, value),
672 RETURN_VALUE_IS_ZERO);
673 }
674 }
675
676 /**
677 * @tc.number Telephony_CallManager_SetImsFeatureValue_0200
678 * @tc.name test set ims feature value type video over lte
679 * @tc.desc Function test
680 */
681 HWTEST_F(CallManagerGtest, Telephony_CallManager_SetImsFeatureValue_0200, TestSize.Level0)
682 {
683 AccessToken token;
684 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
685 return;
686 }
687
688 int32_t value = 1;
689 if (HasSimCard(SIM1_SLOTID)) {
690 EXPECT_NE(CallManagerGtest::clientPtr_->SetImsFeatureValue(SIM1_SLOTID, TYPE_VIDEO_OVER_LTE, value),
691 RETURN_VALUE_IS_ZERO);
692 }
693 if (HasSimCard(SIM2_SLOTID)) {
694 EXPECT_NE(CallManagerGtest::clientPtr_->SetImsFeatureValue(SIM2_SLOTID, TYPE_VIDEO_OVER_LTE, value),
695 RETURN_VALUE_IS_ZERO);
696 }
697 }
698
699 /**
700 * @tc.number Telephony_CallManager_SetImsFeatureValue_0300
701 * @tc.name test set ims feature value type ss over ut
702 * @tc.desc Function test
703 */
704 HWTEST_F(CallManagerGtest, Telephony_CallManager_SetImsFeatureValue_0300, TestSize.Level0)
705 {
706 AccessToken token;
707 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
708 return;
709 }
710
711 int32_t value = 1;
712 if (HasSimCard(SIM1_SLOTID)) {
713 EXPECT_NE(CallManagerGtest::clientPtr_->SetImsFeatureValue(SIM1_SLOTID, TYPE_SS_OVER_UT, value),
714 RETURN_VALUE_IS_ZERO);
715 }
716 if (HasSimCard(SIM2_SLOTID)) {
717 EXPECT_NE(CallManagerGtest::clientPtr_->SetImsFeatureValue(SIM2_SLOTID, TYPE_SS_OVER_UT, value),
718 RETURN_VALUE_IS_ZERO);
719 }
720 }
721
722 /**
723 * @tc.number Telephony_CallManager_SetImsFeatureValue_0400
724 * @tc.name test set ims feature value with invalid type
725 * @tc.desc Function test
726 */
727 HWTEST_F(CallManagerGtest, Telephony_CallManager_SetImsFeatureValue_0400, TestSize.Level0)
728 {
729 AccessToken token;
730 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
731 return;
732 }
733
734 int32_t value = 1;
735 FeatureType type = static_cast<FeatureType>(3);
736 if (HasSimCard(SIM1_SLOTID)) {
737 EXPECT_NE(CallManagerGtest::clientPtr_->SetImsFeatureValue(SIM1_SLOTID, type, value), RETURN_VALUE_IS_ZERO);
738 }
739 if (HasSimCard(SIM2_SLOTID)) {
740 EXPECT_NE(CallManagerGtest::clientPtr_->SetImsFeatureValue(SIM2_SLOTID, type, value), RETURN_VALUE_IS_ZERO);
741 }
742 }
743
744 /************************************** Test UpdateImsCallMode() ****************************************/
745 /**
746 * @tc.number Telephony_CallManager_UpdateImsCallMode_0100
747 * @tc.name test update ims call mode audio only
748 * @tc.desc Function test
749 */
750 HWTEST_F(CallManagerGtest, Telephony_CallManager_UpdateImsCallMode_0100, TestSize.Level0)
751 {
752 AccessToken token;
753 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
754 return;
755 }
756
757 int32_t callId = 1;
758 EXPECT_NE(CallManagerGtest::clientPtr_->UpdateImsCallMode(callId, CALL_MODE_AUDIO_ONLY), RETURN_VALUE_IS_ZERO);
759 }
760
761 /**
762 * @tc.number Telephony_CallManager_UpdateImsCallMode_0200
763 * @tc.name test update ims call mode send only
764 * @tc.desc Function test
765 */
766 HWTEST_F(CallManagerGtest, Telephony_CallManager_UpdateImsCallMode_0200, TestSize.Level0)
767 {
768 AccessToken token;
769 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
770 return;
771 }
772
773 int32_t callId = 1;
774 EXPECT_NE(CallManagerGtest::clientPtr_->UpdateImsCallMode(callId, CALL_MODE_SEND_ONLY), RETURN_VALUE_IS_ZERO);
775 }
776
777 /**
778 * @tc.number Telephony_CallManager_UpdateImsCallMode_0300
779 * @tc.name test update ims call mode recerve only
780 * @tc.desc Function test
781 */
782 HWTEST_F(CallManagerGtest, Telephony_CallManager_UpdateImsCallMode_0300, TestSize.Level0)
783 {
784 AccessToken token;
785 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
786 return;
787 }
788
789 int32_t callId = 1;
790 EXPECT_NE(CallManagerGtest::clientPtr_->UpdateImsCallMode(callId, CALL_MODE_RECEIVE_ONLY), RETURN_VALUE_IS_ZERO);
791 }
792
793 /**
794 * @tc.number Telephony_CallManager_UpdateImsCallMode_0400
795 * @tc.name test update ims call mode send receive
796 * @tc.desc Function test
797 */
798 HWTEST_F(CallManagerGtest, Telephony_CallManager_UpdateImsCallMode_0400, TestSize.Level0)
799 {
800 AccessToken token;
801 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
802 return;
803 }
804
805 int32_t callId = 1;
806 EXPECT_NE(CallManagerGtest::clientPtr_->UpdateImsCallMode(callId, CALL_MODE_SEND_RECEIVE), RETURN_VALUE_IS_ZERO);
807 }
808
809 /**
810 * @tc.number Telephony_CallManager_UpdateImsCallMode_0500
811 * @tc.name test update ims call mode video paused
812 * @tc.desc Function test
813 */
814 HWTEST_F(CallManagerGtest, Telephony_CallManager_UpdateImsCallMode_0500, TestSize.Level0)
815 {
816 AccessToken token;
817 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
818 return;
819 }
820
821 int32_t callId = 1;
822 EXPECT_NE(CallManagerGtest::clientPtr_->UpdateImsCallMode(callId, CALL_MODE_VIDEO_PAUSED), RETURN_VALUE_IS_ZERO);
823 }
824
825 /**
826 * @tc.number Telephony_CallManager_UpdateImsCallMode_0600
827 * @tc.name test update ims call with invalid mode
828 * @tc.desc Function test
829 */
830 HWTEST_F(CallManagerGtest, Telephony_CallManager_UpdateImsCallMode_0600, TestSize.Level0)
831 {
832 AccessToken token;
833 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
834 return;
835 }
836
837 int32_t callId = 1;
838 ImsCallMode mode = static_cast<ImsCallMode>(5);
839 EXPECT_NE(CallManagerGtest::clientPtr_->UpdateImsCallMode(callId, mode), RETURN_VALUE_IS_ZERO);
840 }
841
842 /********************************************* Test StartRtt() ************************************************/
843 /**
844 * @tc.number Telephony_CallManager_StartRtt_0100
845 * @tc.name test start rtt
846 * @tc.desc Function test
847 */
848 HWTEST_F(CallManagerGtest, Telephony_CallManager_StartRtt_0100, TestSize.Level0)
849 {
850 AccessToken token;
851 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
852 return;
853 }
854
855 std::u16string msg = u"123";
856 int32_t callId = 1;
857 EXPECT_NE(CallManagerGtest::clientPtr_->StartRtt(callId, msg), RETURN_VALUE_IS_ZERO);
858 }
859
860 /********************************************* Test StopRtt() ************************************************/
861 /**
862 * @tc.number Telephony_CallManager_StopRtt_0100
863 * @tc.name test stop rtt
864 * @tc.desc Function test
865 */
866 HWTEST_F(CallManagerGtest, Telephony_CallManager_StopRtt_0100, TestSize.Level0)
867 {
868 AccessToken token;
869 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
870 return;
871 }
872 int32_t callId = 1;
873 EXPECT_NE(CallManagerGtest::clientPtr_->StopRtt(callId), RETURN_VALUE_IS_ZERO);
874 }
875
876 /**************************************** Test CanSetCallTransferTime() ******************************************/
877 /**
878 * @tc.number Telephony_CallManager_CanSetCallTransferTime_0100
879 * @tc.name input invalid slotId, test CanSetCallTransferTime() return failed
880 * @tc.desc Function test
881 */
882 HWTEST_F(CallManagerGtest, Telephony_CallManager_CanSetCallTransferTime_0100, TestSize.Level0)
883 {
884 AccessToken token;
885 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
886 return;
887 }
888
889 bool result;
890 EXPECT_EQ(CallManagerGtest::clientPtr_->CanSetCallTransferTime(INVALID_SLOT_ID, result), CALL_ERR_INVALID_SLOT_ID);
891 }
892
893 /**
894 * @tc.number Telephony_CallManager_CanSetCallTransferTime_0200
895 * @tc.name input slotId was out of count
896 * test CanSetCallTransferTime() return failed
897 * @tc.desc Function test
898 */
899 HWTEST_F(CallManagerGtest, Telephony_CallManager_CanSetCallTransferTime_0200, TestSize.Level0)
900 {
901 AccessToken token;
902 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
903 return;
904 }
905
906 bool result;
907 int32_t slotId = SIM_SLOT_COUNT; // out of the count
908 EXPECT_EQ(CallManagerGtest::clientPtr_->CanSetCallTransferTime(slotId, result), CALL_ERR_INVALID_SLOT_ID);
909 }
910
911 /**
912 * @tc.number Telephony_CallManager_CanSetCallTransferTime_0300
913 * @tc.name test CanSetCallTransferTime() without permission
914 * @tc.desc Function test
915 */
916 HWTEST_F(CallManagerGtest, Telephony_CallManager_CanSetCallTransferTime_0300, TestSize.Level0)
917 {
918 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
919 return;
920 }
921
922 bool result;
923 if (HasSimCard(SIM1_SLOTID)) {
924 EXPECT_EQ(
925 CallManagerGtest::clientPtr_->CanSetCallTransferTime(SIM1_SLOTID, result), TELEPHONY_ERR_PERMISSION_ERR);
926 }
927 if (HasSimCard(SIM2_SLOTID)) {
928 EXPECT_EQ(
929 CallManagerGtest::clientPtr_->CanSetCallTransferTime(SIM2_SLOTID, result), TELEPHONY_ERR_PERMISSION_ERR);
930 }
931 }
932
933 /**
934 * @tc.number Telephony_CallManager_CanSetCallTransferTime_0400
935 * @tc.name test CanSetCallTransferTime() with normal situation
936 * @tc.desc Function test
937 */
938 HWTEST_F(CallManagerGtest, Telephony_CallManager_CanSetCallTransferTime_0400, TestSize.Level0)
939 {
940 AccessToken token;
941 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
942 return;
943 }
944
945 bool result;
946 if (HasSimCard(SIM1_SLOTID)) {
947 EXPECT_NE(CallManagerGtest::clientPtr_->CanSetCallTransferTime(SIM1_SLOTID, result), RETURN_VALUE_IS_ZERO);
948 }
949 if (HasSimCard(SIM2_SLOTID)) {
950 EXPECT_NE(CallManagerGtest::clientPtr_->CanSetCallTransferTime(SIM2_SLOTID, result), RETURN_VALUE_IS_ZERO);
951 }
952 }
953
954 /********************************************* Test SetAudioDevice()***********************************************/
955 /**
956 * @tc.number Telephony_CallManager_SetAudioDevice_0100
957 * @tc.name make a normal buletoothAddress, set active bluetooth device
958 * @tc.desc Function test
959 * @tc.require: issueI5JUAQ
960 */
961 HWTEST_F(CallManagerGtest, Telephony_CallManager_SetAudioDevice_0100, Function | MediumTest | Level2)
962 {
963 AccessToken token;
964 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
965 return;
966 }
967 std::string phoneNumber = "66666666666";
968 EXPECT_EQ(CallManagerGtest::IsServiceConnected(), true);
969 if (clientPtr_->GetCallState() == static_cast<int>(CallStateToApp::CALL_STATE_OFFHOOK)) {
970 HangUpCall();
971 }
972 int32_t ret = CallManagerGtest::clientPtr_->DialCall(Str8ToStr16(phoneNumber), dialInfo_);
973 EXPECT_GE(ret, RETURN_VALUE_IS_ZERO);
974
975 HandsFreeAudioGateway *profile = HandsFreeAudioGateway::GetProfile();
976 vector<BluetoothRemoteDevice> devices = profile->GetConnectedDevices();
977 int deviceNum = devices.size();
978 std::string address = "";
979 const int32_t zeroDevice = 0;
980 if (deviceNum > zeroDevice) {
981 address = devices[0].GetDeviceAddr();
982 }
983
984 AudioDevice audioDevice;
985 if (memset_s(&audioDevice, sizeof(AudioDevice), 0, sizeof(AudioDevice)) != EOK) {
986 TELEPHONY_LOGE("memset_s fail");
987 return;
988 }
989 audioDevice.deviceType = AudioDeviceType::DEVICE_BLUETOOTH_SCO;
990 if (address.length() > kMaxAddressLen) {
991 TELEPHONY_LOGE("address is not too long");
992 return;
993 }
994 if (memcpy_s(audioDevice.address, kMaxAddressLen, address.c_str(), address.length()) != EOK) {
995 TELEPHONY_LOGE("memcpy_s address fail");
996 return;
997 }
998 EXPECT_NE(clientPtr_->SetAudioDevice(audioDevice), RETURN_VALUE_IS_ZERO);
999 }
1000
1001 /**
1002 * @tc.number Telephony_CallManager_Telephony_CallManager_SendUssdResponse_0100SetAudioDevice_0100
1003 * @tc.name input slotId:0, content:1, Test SendUssdResponse, return error code if failed
1004 * @tc.desc Function test
1005 * @tc.require: issueI5JUAQ
1006 */
1007 HWTEST_F(CallManagerGtest, Telephony_CallManager_SendUssdResponse_0100, Function | MediumTest | Level2)
1008 {
1009 AccessToken token;
1010 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
1011 return;
1012 }
1013 std::string content = "1";
1014 if (HasSimCard(SIM1_SLOTID)) {
1015 EXPECT_EQ(CallManagerGtest::clientPtr_->SendUssdResponse(SIM1_SLOTID, content), RETURN_VALUE_IS_ZERO);
1016 return;
1017 }
1018 if (HasSimCard(SIM2_SLOTID)) {
1019 EXPECT_EQ(CallManagerGtest::clientPtr_->SendUssdResponse(SIM2_SLOTID, content), RETURN_VALUE_IS_ZERO);
1020 return;
1021 }
1022 }
1023
1024 /**
1025 * @tc.number Telephony_CallManager_Telephony_CallManager_SetCallPolicyInfo_0100
1026 * @tc.name input slotId:0, content:1, Test SetCallPolicyInfo, return error code if failed
1027 * @tc.desc Function test
1028 * @tc.require: issueI5JUAQ
1029 */
1030 HWTEST_F(CallManagerGtest, Telephony_CallManager_SetCallPolicyInfo_0100, Function | MediumTest | Level2)
1031 {
1032 std::vector<std::string> dialingList;
1033 std::vector<std::string> incomingList;
1034 EXPECT_EQ(CallManagerGtest::clientPtr_->SetCallPolicyInfo(false, dialingList, false, incomingList),
1035 TELEPHONY_ERR_PERMISSION_ERR);
1036 }
1037 } // namespace Telephony
1038 } // namespace OHOS
1039