/* * Copyright (C) 2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "gtest/gtest.h" #define PRIVATE public #define PROTECTED public #include "cellular_call_callback.h" #include "cellular_call_handler.h" #include "cellular_call_proxy.h" #include "cellular_call_register.h" #include "cellular_call_service.h" #include "cellular_call_supplement.h" #include "config_request.h" #include "core_service_client.h" #include "cs_control.h" #include "tel_ril_call_parcel.h" #include "operator_config_types.h" #include "radio_event.h" #include "securec.h" #include "sim_state_type.h" #include "system_ability_definition.h" #include "token.h" namespace OHOS { namespace Telephony { using namespace testing::ext; const int32_t SIM1_SLOTID = 0; const int32_t SIM2_SLOTID = 1; class CsCallOperationTest : public testing::Test { public: static void SetUpTestCase(); static void TearDownTestCase(); void SetUp(); void TearDown(); int32_t TestDialCallByCs(int32_t slotId, std::string code); bool HasSimCard(int32_t slotId) { bool hasSimCard = false; DelayedRefSingleton::GetInstance().HasSimCard(slotId, hasSimCard); return hasSimCard; } int32_t InitCellularCallInfo(int32_t accountId, std::string phonenumber, CellularCallInfo &callInfo); }; int32_t CsCallOperationTest::TestDialCallByCs(int32_t slotId, std::string code) { AccessToken token; auto systemAbilityMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); if (systemAbilityMgr == nullptr) { return TELEPHONY_ERR_FAIL; } auto remote = systemAbilityMgr->CheckSystemAbility(TELEPHONY_CELLULAR_CALL_SYS_ABILITY_ID); if (remote == nullptr) { return TELEPHONY_ERR_FAIL; } auto telephonyService = iface_cast(remote); if (telephonyService == nullptr) { return TELEPHONY_ERR_FAIL; } CellularCallInfo callInfo; int32_t ret = TELEPHONY_SUCCESS; ret = InitCellularCallInfo(slotId, code, callInfo); if (ret != TELEPHONY_SUCCESS) { return ret; } // close ims, make this time use cs to test ret = telephonyService->SetImsSwitchStatus(slotId, false); if (ret != TELEPHONY_SUCCESS) { return ret; } ret = telephonyService->Dial(callInfo); return ret; }; int32_t CsCallOperationTest::InitCellularCallInfo(int32_t accountId, std::string phonenumber, CellularCallInfo &callInfo) { callInfo.accountId = accountId; callInfo.slotId = accountId; callInfo.index = accountId; callInfo.callType = CallType::TYPE_CS; callInfo.videoState = 0; // 0 means audio if (memset_s(callInfo.phoneNum, kMaxNumberLen, 0, kMaxNumberLen) != EOK) { return TELEPHONY_ERR_MEMSET_FAIL; } if (phonenumber.length() > static_cast(kMaxNumberLen)) { return CALL_ERR_NUMBER_OUT_OF_RANGE; } if (memcpy_s(callInfo.phoneNum, kMaxNumberLen, phonenumber.c_str(), phonenumber.length()) != EOK) { return TELEPHONY_ERR_MEMCPY_FAIL; } return TELEPHONY_SUCCESS; }; void CsCallOperationTest::SetUpTestCase(void) { // step 3: Set Up Test Case } void CsCallOperationTest::TearDownTestCase(void) { // step 3: Tear Down Test Case } void CsCallOperationTest::SetUp(void) { // step 3: input testcase setup step } void CsCallOperationTest::TearDown(void) { // step 3: input testcase teardown step } /** * @tc.number cellular_call_HangUpAllConnection_0001 * @tc.name Test for hangup all connection function by cs * @tc.desc Function test */ HWTEST_F(CsCallOperationTest, cellular_call_HangUpAllConnection_0001, Function | MediumTest | Level2) { AccessToken token; auto systemAbilityMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); ASSERT_TRUE(systemAbilityMgr != nullptr); auto hangUpAllConRemote = systemAbilityMgr->CheckSystemAbility(TELEPHONY_CELLULAR_CALL_SYS_ABILITY_ID); ASSERT_TRUE(hangUpAllConRemote != nullptr); auto telephonyService = iface_cast(hangUpAllConRemote); ASSERT_TRUE(telephonyService != nullptr); if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) { return; } if (HasSimCard(SIM1_SLOTID)) { int32_t ret = telephonyService->HangUpAllConnection(); EXPECT_EQ(ret, TELEPHONY_SUCCESS); } if (HasSimCard(SIM2_SLOTID)) { int32_t ret = telephonyService->HangUpAllConnection(); EXPECT_EQ(ret, TELEPHONY_SUCCESS); } } } // namespace Telephony } // namespace OHOS