1/* 2 * Copyright (C) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16#include "satellite_test.h" 17 18#define private public 19#define protected public 20#include "cellular_call_config.h" 21#include "cellular_call_handler.h" 22#include "cellular_call_proxy.h" 23#include "cellular_call_register.h" 24#include "cellular_call_service.h" 25#include "tel_ril_call_parcel.h" 26#include "satellite_call_client.h" 27#include "securec.h" 28 29namespace OHOS { 30namespace Telephony { 31using namespace testing::ext; 32const int32_t SIM1_SLOTID = 0; 33const int32_t SIM2_SLOTID = 1; 34const int32_t INVALID_SLOTID = 10; 35const std::string PHONE_NUMBER = "0000000"; 36 37void SatelliteTest::SetUpTestCase(void) 38{ 39 // step 3: Set Up Test Case 40} 41 42void SatelliteTest::TearDownTestCase(void) 43{ 44 // step 3: Tear Down Test Case 45} 46 47void SatelliteTest::SetUp(void) 48{ 49 // step 3: input testcase setup step 50} 51 52void SatelliteTest::TearDown(void) 53{ 54 // step 3: input testcase teardown step 55} 56 57/** 58 * @tc.number Satellite_call_test_001 59 * @tc.name Test the corresponding functions by entering commands, such as 300 -- SetCallPreferenceMode, 301 -- 60 * GetCallPreferenceMode, etc 61 * @tc.desc Function test 62 */ 63HWTEST_F(SatelliteTest, Satellite_call_test_001, Function | MediumTest | Level0) 64{ 65 std::cout << "HWTEST_F Satellite_call_test_001"; 66 AccessToken token; 67 auto systemAbilityMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); 68 ASSERT_TRUE(systemAbilityMgr != nullptr); 69 auto remote = systemAbilityMgr->CheckSystemAbility(TELEPHONY_CELLULAR_CALL_SYS_ABILITY_ID); 70 ASSERT_TRUE(remote != nullptr); 71 auto telephonyService = iface_cast<CellularCallInterface>(remote); 72 ASSERT_TRUE(telephonyService != nullptr); 73} 74 75/** 76 * @tc.number Satellite_call_test_002 77 * @tc.name Test the corresponding functions by entering commands, such as 300 -- SetCallPreferenceMode, 301 -- 78 * GetCallPreferenceMode, etc 79 * @tc.desc Function test 80 */ 81HWTEST_F(SatelliteTest, Satellite_call_test_002, Function | MediumTest | Level1) 82{ 83 std::cout << "HWTEST_F Satellite_call_test_002"; 84 AccessToken token; 85 auto systemAbilityMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); 86 ASSERT_TRUE(systemAbilityMgr != nullptr); 87 auto remote = systemAbilityMgr->CheckSystemAbility(TELEPHONY_CELLULAR_CALL_SYS_ABILITY_ID); 88 ASSERT_TRUE(remote != nullptr); 89 auto telephonyService = iface_cast<CellularCallInterface>(remote); 90 ASSERT_TRUE(telephonyService != nullptr); 91} 92 93/** 94 * @tc.number Satellite_call_DialCall_0001 95 * @tc.name Test for SetClip function by Satellite 96 * @tc.desc Function test 97 */ 98HWTEST_F(SatelliteTest, Satellite_call_DialCall_0001, Function | MediumTest | Level2) 99{ 100 AccessToken token; 101 TELEPHONY_LOGI("Satellite_call_DialCall_0001 entry"); 102 auto systemAbilityMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); 103 ASSERT_TRUE(systemAbilityMgr != nullptr); 104 auto hangUpCallRemote = systemAbilityMgr->CheckSystemAbility(TELEPHONY_CELLULAR_CALL_SYS_ABILITY_ID); 105 ASSERT_TRUE(hangUpCallRemote != nullptr); 106 auto telephonyService = iface_cast<CellularCallInterface>(hangUpCallRemote); 107 ASSERT_TRUE(telephonyService != nullptr); 108 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) { 109 return; 110 } 111 if (HasSimCard(SIM1_SLOTID)) { 112 int32_t ret = TestDialCallBySatellite(SIM1_SLOTID, PHONE_NUMBER); 113 EXPECT_EQ(ret, TELEPHONY_SUCCESS); 114 ret = TestDialCallBySatellite(INVALID_SLOTID, PHONE_NUMBER); 115 EXPECT_EQ(ret, CALL_ERR_INVALID_SLOT_ID); 116 } 117 if (HasSimCard(SIM2_SLOTID)) { 118 int32_t ret = TestDialCallBySatellite(SIM2_SLOTID, PHONE_NUMBER); 119 EXPECT_EQ(ret, TELEPHONY_SUCCESS); 120 ret = TestDialCallBySatellite(INVALID_SLOTID, PHONE_NUMBER); 121 EXPECT_EQ(ret, CALL_ERR_INVALID_SLOT_ID); 122 } 123} 124 125/** 126 * @tc.number Satellite_call_HangUpCall_0001 127 * @tc.name Test for HangUp function by Satellite 128 * @tc.desc Function test 129 */ 130HWTEST_F(SatelliteTest, Satellite_call_HangUpCall_0001, Function | MediumTest | Level2) 131{ 132 AccessToken token; 133 TELEPHONY_LOGI("Satellite_call_HangUpCall_0001 entry"); 134 auto systemAbilityMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); 135 ASSERT_TRUE(systemAbilityMgr != nullptr); 136 auto hangUpCallRemote = systemAbilityMgr->CheckSystemAbility(TELEPHONY_CELLULAR_CALL_SYS_ABILITY_ID); 137 ASSERT_TRUE(hangUpCallRemote != nullptr); 138 auto telephonyService = iface_cast<CellularCallInterface>(hangUpCallRemote); 139 ASSERT_TRUE(telephonyService != nullptr); 140 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) { 141 return; 142 } 143 if (HasSimCard(SIM1_SLOTID)) { 144 CellularCallInfo callInfo; 145 int32_t ret = InitCellularCallInfo(SIM1_SLOTID, PHONE_NUMBER, callInfo); 146 EXPECT_EQ(ret, TELEPHONY_SUCCESS); 147 ret = telephonyService->HangUp(callInfo, CallSupplementType::TYPE_DEFAULT); 148 EXPECT_GE(ret, TELEPHONY_SUCCESS); 149 } 150 if (HasSimCard(SIM2_SLOTID)) { 151 CellularCallInfo callInfo; 152 int32_t ret = InitCellularCallInfo(SIM2_SLOTID, PHONE_NUMBER, callInfo); 153 EXPECT_EQ(ret, TELEPHONY_SUCCESS); 154 ret = telephonyService->HangUp(callInfo, CallSupplementType::TYPE_DEFAULT); 155 EXPECT_GE(ret, TELEPHONY_SUCCESS); 156 } 157} 158 159/** 160 * @tc.number Satellite_call_AnswerCall_0001 161 * @tc.name Test for answer function by Satellite 162 * @tc.desc Function test 163 */ 164HWTEST_F(SatelliteTest, Satellite_call_AnswerCall_0001, Function | MediumTest | Level2) 165{ 166 AccessToken token; 167 TELEPHONY_LOGI("Satellite_call_AnswerCall_0001 entry"); 168 auto systemAbilityMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); 169 ASSERT_TRUE(systemAbilityMgr != nullptr); 170 auto answerCallRemote = systemAbilityMgr->CheckSystemAbility(TELEPHONY_CELLULAR_CALL_SYS_ABILITY_ID); 171 ASSERT_TRUE(answerCallRemote != nullptr); 172 auto telephonyService = iface_cast<CellularCallInterface>(answerCallRemote); 173 ASSERT_TRUE(telephonyService != nullptr); 174 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) { 175 return; 176 } 177 if (HasSimCard(SIM1_SLOTID)) { 178 CellularCallInfo callInfo; 179 int32_t ret = InitCellularCallInfo(SIM1_SLOTID, PHONE_NUMBER, callInfo); 180 EXPECT_EQ(ret, TELEPHONY_SUCCESS); 181 ret = telephonyService->Answer(callInfo); 182 EXPECT_GE(ret, TELEPHONY_SUCCESS); 183 } 184 if (HasSimCard(SIM2_SLOTID)) { 185 CellularCallInfo callInfo; 186 int32_t ret = InitCellularCallInfo(SIM2_SLOTID, PHONE_NUMBER, callInfo); 187 EXPECT_EQ(ret, TELEPHONY_SUCCESS); 188 ret = telephonyService->Answer(callInfo); 189 EXPECT_GE(ret, TELEPHONY_SUCCESS); 190 } 191} 192 193/** 194 * @tc.number Satellite_call_RejectCall_0001 195 * @tc.name Test for reject function by tatellite 196 * @tc.desc Function test 197 */ 198HWTEST_F(SatelliteTest, Satellite_call_RejectCall_0001, Function | MediumTest | Level2) 199{ 200 AccessToken token; 201 TELEPHONY_LOGI("Satellite_call_RejectCall_0001 entry"); 202 auto systemAbilityMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); 203 ASSERT_TRUE(systemAbilityMgr != nullptr); 204 auto rejectCallRemote = systemAbilityMgr->CheckSystemAbility(TELEPHONY_CELLULAR_CALL_SYS_ABILITY_ID); 205 ASSERT_TRUE(rejectCallRemote != nullptr); 206 auto telephonyService = iface_cast<CellularCallInterface>(rejectCallRemote); 207 ASSERT_TRUE(telephonyService != nullptr); 208 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) { 209 return; 210 } 211 if (HasSimCard(SIM1_SLOTID)) { 212 CellularCallInfo callInfo; 213 int32_t ret = InitCellularCallInfo(SIM1_SLOTID, PHONE_NUMBER, callInfo); 214 EXPECT_EQ(ret, TELEPHONY_SUCCESS); 215 ret = telephonyService->Reject(callInfo); 216 EXPECT_GE(ret, TELEPHONY_SUCCESS); 217 } 218 if (HasSimCard(SIM2_SLOTID)) { 219 CellularCallInfo callInfo; 220 int32_t ret = InitCellularCallInfo(SIM2_SLOTID, PHONE_NUMBER, callInfo); 221 EXPECT_EQ(ret, TELEPHONY_SUCCESS); 222 ret = telephonyService->Reject(callInfo); 223 EXPECT_GE(ret, TELEPHONY_SUCCESS); 224 } 225} 226/** 227 * @tc.number Satellite_call_StartDtmf_0001 228 * @tc.name Test for startDtmf function by satellite 229 * @tc.desc Function test 230 */ 231HWTEST_F(SatelliteTest, Satellite_call_StartDtmf_0001, Function | MediumTest | Level2) 232{ 233 AccessToken token; 234 auto systemAbilityMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); 235 ASSERT_TRUE(systemAbilityMgr != nullptr); 236 auto startDtmfRemote = systemAbilityMgr->CheckSystemAbility(TELEPHONY_CELLULAR_CALL_SYS_ABILITY_ID); 237 ASSERT_TRUE(startDtmfRemote != nullptr); 238 auto telephonyService = iface_cast<CellularCallInterface>(startDtmfRemote); 239 ASSERT_TRUE(telephonyService != nullptr); 240 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) { 241 return; 242 } 243 if (HasSimCard(SIM1_SLOTID)) { 244 CellularCallInfo callInfo; 245 int32_t ret = InitCellularCallInfo(SIM1_SLOTID, PHONE_NUMBER, callInfo); 246 EXPECT_EQ(ret, TELEPHONY_SUCCESS); 247 char code = '1'; 248 ret = telephonyService->StartDtmf(code, callInfo); 249 EXPECT_EQ(ret, CALL_ERR_CALL_CONNECTION_NOT_EXIST); 250 } 251 if (HasSimCard(SIM2_SLOTID)) { 252 CellularCallInfo callInfo; 253 int32_t ret = InitCellularCallInfo(SIM2_SLOTID, PHONE_NUMBER, callInfo); 254 EXPECT_EQ(ret, TELEPHONY_SUCCESS); 255 char code = '1'; 256 ret = telephonyService->StartDtmf(code, callInfo); 257 EXPECT_EQ(ret, CALL_ERR_CALL_CONNECTION_NOT_EXIST); 258 } 259} 260 261/** 262 * @tc.number Satellite_call_StartDtmf_0002 263 * @tc.name Test for startDtmf function with invalid slot by satellite 264 * @tc.desc Function test 265 */ 266HWTEST_F(SatelliteTest, Satellite_call_StartDtmf_0002, Function | MediumTest | Level2) 267{ 268 AccessToken token; 269 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) { 270 return; 271 } 272 auto systemAbilityMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); 273 ASSERT_TRUE(systemAbilityMgr != nullptr); 274 auto startDtmfRemote = systemAbilityMgr->CheckSystemAbility(TELEPHONY_CELLULAR_CALL_SYS_ABILITY_ID); 275 ASSERT_TRUE(startDtmfRemote != nullptr); 276 auto telephonyService = iface_cast<CellularCallInterface>(startDtmfRemote); 277 ASSERT_TRUE(telephonyService != nullptr); 278 CellularCallInfo callInfo; 279 if (HasSimCard(SIM1_SLOTID)) { 280 int32_t ret = InitCellularCallInfo(INVALID_SLOTID, PHONE_NUMBER, callInfo); 281 EXPECT_EQ(ret, TELEPHONY_SUCCESS); 282 char code = '1'; 283 ret = telephonyService->StartDtmf(code, callInfo); 284 EXPECT_EQ(ret, CALL_ERR_INVALID_SLOT_ID); 285 } 286 if (HasSimCard(SIM2_SLOTID)) { 287 int32_t ret = InitCellularCallInfo(INVALID_SLOTID, PHONE_NUMBER, callInfo); 288 EXPECT_EQ(ret, TELEPHONY_SUCCESS); 289 char code = '1'; 290 ret = telephonyService->StartDtmf(code, callInfo); 291 EXPECT_EQ(ret, CALL_ERR_INVALID_SLOT_ID); 292 } 293} 294 295/** 296 * @tc.number Satellite_call_StopDtmf_0001 297 * @tc.name Test for stopDtmf function by satellite 298 * @tc.desc Function test 299 */ 300HWTEST_F(SatelliteTest, Satellite_call_StopDtmf_0001, Function | MediumTest | Level2) 301{ 302 AccessToken token; 303 auto systemAbilityMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); 304 ASSERT_TRUE(systemAbilityMgr != nullptr); 305 auto stopDtmfRemote = systemAbilityMgr->CheckSystemAbility(TELEPHONY_CELLULAR_CALL_SYS_ABILITY_ID); 306 ASSERT_TRUE(stopDtmfRemote != nullptr); 307 auto telephonyService = iface_cast<CellularCallInterface>(stopDtmfRemote); 308 ASSERT_TRUE(telephonyService != nullptr); 309 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) { 310 return; 311 } 312 if (HasSimCard(SIM1_SLOTID)) { 313 CellularCallInfo callInfo; 314 int32_t ret = InitCellularCallInfo(SIM1_SLOTID, PHONE_NUMBER, callInfo); 315 EXPECT_EQ(ret, TELEPHONY_SUCCESS); 316 ret = telephonyService->StopDtmf(callInfo); 317 EXPECT_EQ(ret, CALL_ERR_CALL_CONNECTION_NOT_EXIST); 318 } 319 if (HasSimCard(SIM2_SLOTID)) { 320 CellularCallInfo callInfo; 321 int32_t ret = InitCellularCallInfo(SIM2_SLOTID, PHONE_NUMBER, callInfo); 322 EXPECT_EQ(ret, TELEPHONY_SUCCESS); 323 ret = telephonyService->StopDtmf(callInfo); 324 EXPECT_EQ(ret, CALL_ERR_CALL_CONNECTION_NOT_EXIST); 325 } 326} 327 328/** 329 * @tc.number Satellite_call_StopDtmf_0002 330 * @tc.name Test for stopDtmf function with invalid slot by satellite 331 * @tc.desc Function test 332 */ 333HWTEST_F(SatelliteTest, Satellite_call_StopDtmf_0002, Function | MediumTest | Level2) 334{ 335 AccessToken token; 336 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) { 337 return; 338 } 339 auto systemAbilityMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); 340 ASSERT_TRUE(systemAbilityMgr != nullptr); 341 auto stopDtmfRemote = systemAbilityMgr->CheckSystemAbility(TELEPHONY_CELLULAR_CALL_SYS_ABILITY_ID); 342 ASSERT_TRUE(stopDtmfRemote != nullptr); 343 auto telephonyService = iface_cast<CellularCallInterface>(stopDtmfRemote); 344 ASSERT_TRUE(telephonyService != nullptr); 345 if (HasSimCard(SIM1_SLOTID)) { 346 CellularCallInfo stopDtmfCallInfo; 347 int32_t ret = InitCellularCallInfo(INVALID_SLOTID, PHONE_NUMBER, stopDtmfCallInfo); 348 EXPECT_EQ(ret, TELEPHONY_SUCCESS); 349 ret = telephonyService->StopDtmf(stopDtmfCallInfo); 350 EXPECT_EQ(ret, CALL_ERR_INVALID_SLOT_ID); 351 } 352 if (HasSimCard(SIM2_SLOTID)) { 353 CellularCallInfo stopDtmfCallInfo; 354 int32_t ret = InitCellularCallInfo(INVALID_SLOTID, PHONE_NUMBER, stopDtmfCallInfo); 355 EXPECT_EQ(ret, TELEPHONY_SUCCESS); 356 ret = telephonyService->StopDtmf(stopDtmfCallInfo); 357 EXPECT_EQ(ret, CALL_ERR_INVALID_SLOT_ID); 358 } 359} 360 361/** 362 * @tc.number Satellite_call_SendDtmf_0001 363 * @tc.name Test for sendDtmf function by satellite 364 * @tc.desc Function test 365 */ 366HWTEST_F(SatelliteTest, Satellite_call_SendDtmf_0001, Function | MediumTest | Level2) 367{ 368 AccessToken token; 369 auto systemAbilityMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); 370 ASSERT_TRUE(systemAbilityMgr != nullptr); 371 auto sendDtmfRemote = systemAbilityMgr->CheckSystemAbility(TELEPHONY_CELLULAR_CALL_SYS_ABILITY_ID); 372 ASSERT_TRUE(sendDtmfRemote != nullptr); 373 auto telephonyService = iface_cast<CellularCallInterface>(sendDtmfRemote); 374 ASSERT_TRUE(telephonyService != nullptr); 375 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) { 376 return; 377 } 378 if (HasSimCard(SIM1_SLOTID)) { 379 CellularCallInfo sendDtmfCallInfo; 380 int32_t ret = InitCellularCallInfo(SIM1_SLOTID, PHONE_NUMBER, sendDtmfCallInfo); 381 EXPECT_EQ(ret, TELEPHONY_SUCCESS); 382 char code = '1'; 383 ret = telephonyService->SendDtmf(code, sendDtmfCallInfo); 384 EXPECT_EQ(ret, CALL_ERR_CALL_CONNECTION_NOT_EXIST); 385 } 386 if (HasSimCard(SIM2_SLOTID)) { 387 CellularCallInfo sendDtmfCallInfo; 388 int32_t ret = InitCellularCallInfo(SIM2_SLOTID, PHONE_NUMBER, sendDtmfCallInfo); 389 EXPECT_EQ(ret, TELEPHONY_SUCCESS); 390 char code = '1'; 391 ret = telephonyService->SendDtmf(code, sendDtmfCallInfo); 392 EXPECT_EQ(ret, CALL_ERR_CALL_CONNECTION_NOT_EXIST); 393 } 394} 395 396/** 397 * @tc.number Satellite_call_SendDtmf_0002 398 * @tc.name Test for sendDtmf function with invalid slot by satellite 399 * @tc.desc Function test 400 */ 401HWTEST_F(SatelliteTest, Satellite_call_SendDtmf_0002, Function | MediumTest | Level2) 402{ 403 AccessToken token; 404 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) { 405 return; 406 } 407 auto systemAbilityMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); 408 ASSERT_TRUE(systemAbilityMgr != nullptr); 409 auto sendDtmfRemote = systemAbilityMgr->CheckSystemAbility(TELEPHONY_CELLULAR_CALL_SYS_ABILITY_ID); 410 ASSERT_TRUE(sendDtmfRemote != nullptr); 411 auto telephonyService = iface_cast<CellularCallInterface>(sendDtmfRemote); 412 ASSERT_TRUE(telephonyService != nullptr); 413 if (HasSimCard(SIM1_SLOTID)) { 414 CellularCallInfo sendDtmfCallInfo; 415 int32_t ret = InitCellularCallInfo(INVALID_SLOTID, PHONE_NUMBER, sendDtmfCallInfo); 416 EXPECT_EQ(ret, TELEPHONY_SUCCESS); 417 char code = '1'; 418 ret = telephonyService->SendDtmf(code, sendDtmfCallInfo); 419 EXPECT_EQ(ret, CALL_ERR_INVALID_SLOT_ID); 420 } 421 if (HasSimCard(SIM2_SLOTID)) { 422 CellularCallInfo sendDtmfCallInfo; 423 int32_t ret = InitCellularCallInfo(INVALID_SLOTID, PHONE_NUMBER, sendDtmfCallInfo); 424 EXPECT_EQ(ret, TELEPHONY_SUCCESS); 425 char code = '1'; 426 ret = telephonyService->SendDtmf(code, sendDtmfCallInfo); 427 EXPECT_EQ(ret, CALL_ERR_INVALID_SLOT_ID); 428 } 429} 430} // namespace Telephony 431} // namespace OHOS 432