• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "gtest/gtest.h"
17 
18 #define PRIVATE public
19 #define PROTECTED public
20 #include "cellular_call_callback.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 "cellular_call_supplement.h"
26 #include "config_request.h"
27 #include "core_service_client.h"
28 #include "cs_control.h"
29 #include "tel_ril_call_parcel.h"
30 #include "operator_config_types.h"
31 #include "radio_event.h"
32 #include "securec.h"
33 #include "sim_state_type.h"
34 #include "system_ability_definition.h"
35 #include "token.h"
36 
37 namespace OHOS {
38 namespace Telephony {
39 using namespace testing::ext;
40 const int32_t SIM1_SLOTID = 0;
41 const int32_t SIM2_SLOTID = 1;
42 
43 class CsCallOperationTest : public testing::Test {
44 public:
45     static void SetUpTestCase();
46     static void TearDownTestCase();
47     void SetUp();
48     void TearDown();
49     int32_t TestDialCallByCs(int32_t slotId, std::string code);
HasSimCard(int32_t slotId)50     bool HasSimCard(int32_t slotId)
51     {
52         bool hasSimCard = false;
53         DelayedRefSingleton<CoreServiceClient>::GetInstance().HasSimCard(slotId, hasSimCard);
54         return hasSimCard;
55     }
56     int32_t InitCellularCallInfo(int32_t accountId, std::string phonenumber, CellularCallInfo &callInfo);
57 };
58 
TestDialCallByCs(int32_t slotId,std::string code)59 int32_t CsCallOperationTest::TestDialCallByCs(int32_t slotId, std::string code)
60     {
61         AccessToken token;
62         auto systemAbilityMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
63         if (systemAbilityMgr == nullptr) {
64             return TELEPHONY_ERR_FAIL;
65         }
66         auto remote = systemAbilityMgr->CheckSystemAbility(TELEPHONY_CELLULAR_CALL_SYS_ABILITY_ID);
67         if (remote == nullptr) {
68             return TELEPHONY_ERR_FAIL;
69         }
70         auto telephonyService = iface_cast<CellularCallInterface>(remote);
71         if (telephonyService == nullptr) {
72             return TELEPHONY_ERR_FAIL;
73         }
74         CellularCallInfo callInfo;
75         int32_t ret = TELEPHONY_SUCCESS;
76         ret = InitCellularCallInfo(slotId, code, callInfo);
77         if (ret != TELEPHONY_SUCCESS) {
78             return ret;
79         }
80         // close ims, make this time use cs to test
81         ret = telephonyService->SetImsSwitchStatus(slotId, false);
82         if (ret != TELEPHONY_SUCCESS) {
83             return ret;
84         }
85         ret = telephonyService->Dial(callInfo);
86         return ret;
87     };
88 
InitCellularCallInfo(int32_t accountId,std::string phonenumber,CellularCallInfo & callInfo)89 int32_t CsCallOperationTest::InitCellularCallInfo(int32_t accountId, std::string phonenumber,
90     CellularCallInfo &callInfo)
91 {
92     callInfo.accountId = accountId;
93     callInfo.slotId = accountId;
94     callInfo.index = accountId;
95     callInfo.callType = CallType::TYPE_CS;
96     callInfo.videoState = 0; // 0 means audio
97     if (memset_s(callInfo.phoneNum, kMaxNumberLen, 0, kMaxNumberLen) != EOK) {
98         return TELEPHONY_ERR_MEMSET_FAIL;
99     }
100     if (phonenumber.length() > static_cast<size_t>(kMaxNumberLen)) {
101         return CALL_ERR_NUMBER_OUT_OF_RANGE;
102     }
103     if (memcpy_s(callInfo.phoneNum, kMaxNumberLen, phonenumber.c_str(), phonenumber.length()) != EOK) {
104         return TELEPHONY_ERR_MEMCPY_FAIL;
105     }
106     return TELEPHONY_SUCCESS;
107 };
108 
SetUpTestCase(void)109 void CsCallOperationTest::SetUpTestCase(void)
110 {
111     // step 3: Set Up Test Case
112 }
113 
TearDownTestCase(void)114 void CsCallOperationTest::TearDownTestCase(void)
115 {
116     // step 3: Tear Down Test Case
117 }
118 
SetUp(void)119 void CsCallOperationTest::SetUp(void)
120 {
121     // step 3: input testcase setup step
122 }
123 
TearDown(void)124 void CsCallOperationTest::TearDown(void)
125 {
126     // step 3: input testcase teardown step
127 }
128 
129 /**
130  * @tc.number   cellular_call_HangUpAllConnection_0001
131  * @tc.name     Test for hangup all connection function by cs
132  * @tc.desc     Function test
133  */
134 HWTEST_F(CsCallOperationTest, cellular_call_HangUpAllConnection_0001, Function | MediumTest | Level2)
135 {
136     AccessToken token;
137     auto systemAbilityMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
138     ASSERT_TRUE(systemAbilityMgr != nullptr);
139     auto hangUpAllConRemote = systemAbilityMgr->CheckSystemAbility(TELEPHONY_CELLULAR_CALL_SYS_ABILITY_ID);
140     ASSERT_TRUE(hangUpAllConRemote != nullptr);
141     auto telephonyService = iface_cast<CellularCallInterface>(hangUpAllConRemote);
142     ASSERT_TRUE(telephonyService != nullptr);
143     if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
144         return;
145     }
146     if (HasSimCard(SIM1_SLOTID)) {
147         int32_t ret = telephonyService->HangUpAllConnection();
148         EXPECT_EQ(ret, TELEPHONY_SUCCESS);
149     }
150     if (HasSimCard(SIM2_SLOTID)) {
151         int32_t ret = telephonyService->HangUpAllConnection();
152         EXPECT_EQ(ret, TELEPHONY_SUCCESS);
153     }
154 }
155 } // namespace Telephony
156 } // namespace OHOS
157