1d95e75fdSopenharmony_ci/*
2d95e75fdSopenharmony_ci * Copyright (C) 2023 Huawei Device Co., Ltd.
3d95e75fdSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4d95e75fdSopenharmony_ci * you may not use this file except in compliance with the License.
5d95e75fdSopenharmony_ci * You may obtain a copy of the License at
6d95e75fdSopenharmony_ci *
7d95e75fdSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8d95e75fdSopenharmony_ci *
9d95e75fdSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10d95e75fdSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11d95e75fdSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12d95e75fdSopenharmony_ci * See the License for the specific language governing permissions and
13d95e75fdSopenharmony_ci * limitations under the License.
14d95e75fdSopenharmony_ci */
15d95e75fdSopenharmony_ci#define private public
16d95e75fdSopenharmony_ci#define protected public
17d95e75fdSopenharmony_ci
18d95e75fdSopenharmony_ci#include "cellular_call_config.h"
19d95e75fdSopenharmony_ci#include "cellular_call_connection_satellite.h"
20d95e75fdSopenharmony_ci#include "cellular_call_handler.h"
21d95e75fdSopenharmony_ci#include "cellular_call_proxy.h"
22d95e75fdSopenharmony_ci#include "cellular_call_register.h"
23d95e75fdSopenharmony_ci#include "cellular_call_service.h"
24d95e75fdSopenharmony_ci#include "gtest/gtest.h"
25d95e75fdSopenharmony_ci#include "tel_ril_call_parcel.h"
26d95e75fdSopenharmony_ci#include "satellite_call_client.h"
27d95e75fdSopenharmony_ci#include "satellite_control.h"
28d95e75fdSopenharmony_ci#include "satellite_test.h"
29d95e75fdSopenharmony_ci#include "securec.h"
30d95e75fdSopenharmony_ci#include "standardize_utils.h"
31d95e75fdSopenharmony_ci
32d95e75fdSopenharmony_cinamespace OHOS {
33d95e75fdSopenharmony_cinamespace Telephony {
34d95e75fdSopenharmony_ciusing namespace testing::ext;
35d95e75fdSopenharmony_ci
36d95e75fdSopenharmony_cinamespace {
37d95e75fdSopenharmony_ciconst int32_t SIM1_SLOTID = 0;
38d95e75fdSopenharmony_ciconst int32_t SIM2_SLOTID = 1;
39d95e75fdSopenharmony_ciconst std::string PHONE_NUMBER = "00000000";
40d95e75fdSopenharmony_ci} // namespace
41d95e75fdSopenharmony_ci
42d95e75fdSopenharmony_ciclass BranchTest : public testing::Test {
43d95e75fdSopenharmony_cipublic:
44d95e75fdSopenharmony_ci    static void SetUpTestCase();
45d95e75fdSopenharmony_ci    static void TearDownTestCase();
46d95e75fdSopenharmony_ci    void SetUp();
47d95e75fdSopenharmony_ci    void TearDown();
48d95e75fdSopenharmony_ci    int32_t InitCellularCallInfo(int32_t accountId, std::string phonenumber, CellularCallInfo &callInfo);
49d95e75fdSopenharmony_ci};
50d95e75fdSopenharmony_ci
51d95e75fdSopenharmony_civoid BranchTest::SetUpTestCase()
52d95e75fdSopenharmony_ci{
53d95e75fdSopenharmony_ci    std::cout << "---------- CellularCallService start ------------" << std::endl;
54d95e75fdSopenharmony_ci}
55d95e75fdSopenharmony_ci
56d95e75fdSopenharmony_civoid BranchTest::TearDownTestCase() {}
57d95e75fdSopenharmony_ci
58d95e75fdSopenharmony_civoid BranchTest::SetUp() {}
59d95e75fdSopenharmony_ci
60d95e75fdSopenharmony_civoid BranchTest::TearDown() {}
61d95e75fdSopenharmony_ci
62d95e75fdSopenharmony_ciint32_t BranchTest::InitCellularCallInfo(int32_t accountId, std::string phonenumber, CellularCallInfo &callInfo)
63d95e75fdSopenharmony_ci{
64d95e75fdSopenharmony_ci    callInfo.accountId = accountId;
65d95e75fdSopenharmony_ci    callInfo.slotId = accountId;
66d95e75fdSopenharmony_ci    callInfo.index = accountId;
67d95e75fdSopenharmony_ci    callInfo.callType = CallType::TYPE_SATELLITE;
68d95e75fdSopenharmony_ci    callInfo.videoState = 0; // 0 means audio
69d95e75fdSopenharmony_ci    if (memset_s(callInfo.phoneNum, kMaxNumberLen, 0, kMaxNumberLen) != EOK) {
70d95e75fdSopenharmony_ci        return TELEPHONY_ERR_MEMSET_FAIL;
71d95e75fdSopenharmony_ci    }
72d95e75fdSopenharmony_ci    if (phonenumber.length() > static_cast<size_t>(kMaxNumberLen)) {
73d95e75fdSopenharmony_ci        return CALL_ERR_NUMBER_OUT_OF_RANGE;
74d95e75fdSopenharmony_ci    }
75d95e75fdSopenharmony_ci    if (memcpy_s(callInfo.phoneNum, kMaxNumberLen, phonenumber.c_str(), phonenumber.length()) != EOK) {
76d95e75fdSopenharmony_ci        return TELEPHONY_ERR_MEMCPY_FAIL;
77d95e75fdSopenharmony_ci    }
78d95e75fdSopenharmony_ci    return TELEPHONY_SUCCESS;
79d95e75fdSopenharmony_ci}
80d95e75fdSopenharmony_ci
81d95e75fdSopenharmony_ci/**
82d95e75fdSopenharmony_ci * @tc.number   Telephony_CellularCallSatelliteControl_001
83d95e75fdSopenharmony_ci * @tc.name     Test error branch
84d95e75fdSopenharmony_ci * @tc.desc     Function test
85d95e75fdSopenharmony_ci */
86d95e75fdSopenharmony_ciHWTEST_F(BranchTest, Telephony_CellularCallSatelliteControl_001, Function | MediumTest | Level3)
87d95e75fdSopenharmony_ci{
88d95e75fdSopenharmony_ci    AccessToken token;
89d95e75fdSopenharmony_ci    SatelliteControl satelliteControl;
90d95e75fdSopenharmony_ci    CellularCallInfo cellularCallInfo;
91d95e75fdSopenharmony_ci    std::vector<CellularCallInfo> infos;
92d95e75fdSopenharmony_ci    infos.emplace_back(cellularCallInfo);
93d95e75fdSopenharmony_ci    CellularCallInfo cellularCallInfo_new;
94d95e75fdSopenharmony_ci    int32_t invalidSupType = -1;
95d95e75fdSopenharmony_ci    InitCellularCallInfo(SIM1_SLOTID, PHONE_NUMBER, cellularCallInfo);
96d95e75fdSopenharmony_ci
97d95e75fdSopenharmony_ci    satelliteControl.Dial(cellularCallInfo, true);
98d95e75fdSopenharmony_ci    cellularCallInfo_new.slotId = 1;
99d95e75fdSopenharmony_ci    satelliteControl.Dial(cellularCallInfo_new, true);
100d95e75fdSopenharmony_ci    cellularCallInfo_new.callType = CallType::TYPE_SATELLITE;
101d95e75fdSopenharmony_ci    infos.emplace_back(cellularCallInfo_new);
102d95e75fdSopenharmony_ci    satelliteControl.HangUp(cellularCallInfo, CallSupplementType::TYPE_DEFAULT);
103d95e75fdSopenharmony_ci    satelliteControl.HangUp(cellularCallInfo, CallSupplementType::TYPE_HANG_UP_HOLD_WAIT);
104d95e75fdSopenharmony_ci    satelliteControl.HangUp(cellularCallInfo, CallSupplementType::TYPE_HANG_UP_ACTIVE);
105d95e75fdSopenharmony_ci    satelliteControl.HangUp(cellularCallInfo, CallSupplementType::TYPE_HANG_UP_ALL);
106d95e75fdSopenharmony_ci    satelliteControl.HangUp(cellularCallInfo, static_cast<CallSupplementType>(invalidSupType));
107d95e75fdSopenharmony_ci    satelliteControl.Answer(cellularCallInfo);
108d95e75fdSopenharmony_ci    satelliteControl.Reject(cellularCallInfo);
109d95e75fdSopenharmony_ci    satelliteControl.ReportHangUp(infos, SIM2_SLOTID);
110d95e75fdSopenharmony_ci    satelliteControl.HoldCall(SIM1_SLOTID);
111d95e75fdSopenharmony_ci    satelliteControl.UnHoldCall(SIM1_SLOTID);
112d95e75fdSopenharmony_ci    satelliteControl.SwitchCall(SIM1_SLOTID);
113d95e75fdSopenharmony_ci    satelliteControl.CombineConference(SIM1_SLOTID);
114d95e75fdSopenharmony_ci    CallInfoList callInfoList;
115d95e75fdSopenharmony_ci    satelliteControl.ReportCallsData(SIM1_SLOTID, callInfoList);
116d95e75fdSopenharmony_ci    SatelliteCurrentCallList satellitecallInfoList;
117d95e75fdSopenharmony_ci    satelliteControl.ReportHangUpInfo(SIM1_SLOTID);
118d95e75fdSopenharmony_ci    satelliteControl.ReportIncomingInfo(SIM1_SLOTID, satellitecallInfoList);
119d95e75fdSopenharmony_ci    satelliteControl.ReportUpdateInfo(SIM1_SLOTID, satellitecallInfoList);
120d95e75fdSopenharmony_ci    SatelliteCurrentCall CallInfo;
121d95e75fdSopenharmony_ci    satelliteControl.EncapsulationCallReportInfo(SIM1_SLOTID, CallInfo);
122d95e75fdSopenharmony_ci    CallsReportInfo callsReportInfo;
123d95e75fdSopenharmony_ci    satelliteControl.DeleteConnection(callsReportInfo, satellitecallInfoList);
124d95e75fdSopenharmony_ci    satelliteControl.HangUpAllConnection(SIM1_SLOTID);
125d95e75fdSopenharmony_ci    CLIRMode mode = DEFAULT;
126d95e75fdSopenharmony_ci    satelliteControl.EncapsulateDialCommon(SIM1_SLOTID, PHONE_NUMBER, mode);
127d95e75fdSopenharmony_ci    ASSERT_EQ(satelliteControl.ReportSatelliteCallsData(SIM1_SLOTID, satellitecallInfoList), TELEPHONY_SUCCESS);
128d95e75fdSopenharmony_ci}
129d95e75fdSopenharmony_ci
130d95e75fdSopenharmony_ci/**
131d95e75fdSopenharmony_ci * @tc.number   Telephony_CellularCallSatelliteControl_002
132d95e75fdSopenharmony_ci * @tc.name     Test error branch
133d95e75fdSopenharmony_ci * @tc.desc     Function test
134d95e75fdSopenharmony_ci */
135d95e75fdSopenharmony_ciHWTEST_F(BranchTest, Telephony_CellularCallSatelliteControl_002, Function | MediumTest | Level3)
136d95e75fdSopenharmony_ci{
137d95e75fdSopenharmony_ci    AccessToken token;
138d95e75fdSopenharmony_ci    SatelliteControl satelliteControl;
139d95e75fdSopenharmony_ci    CellularCallInfo cellularCallInfo;
140d95e75fdSopenharmony_ci    std::vector<CellularCallInfo> infos;
141d95e75fdSopenharmony_ci    infos.emplace_back(cellularCallInfo);
142d95e75fdSopenharmony_ci    SatelliteCurrentCallList satellitecallInfoList;
143d95e75fdSopenharmony_ci    satellitecallInfoList.callSize = 2;
144d95e75fdSopenharmony_ci    CallsReportInfo callsReportInfo;
145d95e75fdSopenharmony_ci    auto connectionMap = satelliteControl.GetConnectionMap();
146d95e75fdSopenharmony_ci    satelliteControl.connectionMap_.insert(std::make_pair(1, CellularCallConnectionSatellite()));
147d95e75fdSopenharmony_ci    satelliteControl.ReportHangUpInfo(SIM1_SLOTID);
148d95e75fdSopenharmony_ci    satelliteControl.DeleteConnection(callsReportInfo, satellitecallInfoList);
149d95e75fdSopenharmony_ci    satelliteControl.ExecutePostDial(SIM1_SLOTID, 0);
150d95e75fdSopenharmony_ci    ASSERT_NE(satelliteControl.PostDialProceed(cellularCallInfo, true), TELEPHONY_SUCCESS);
151d95e75fdSopenharmony_ci}
152d95e75fdSopenharmony_ci
153d95e75fdSopenharmony_ci/**
154d95e75fdSopenharmony_ci * @tc.number   Telephony_ControlBase_001
155d95e75fdSopenharmony_ci * @tc.name     Test error branch
156d95e75fdSopenharmony_ci * @tc.desc     Function test
157d95e75fdSopenharmony_ci */
158d95e75fdSopenharmony_ciHWTEST_F(BranchTest, Telephony_ControlBase_001, Function | MediumTest | Level3)
159d95e75fdSopenharmony_ci{
160d95e75fdSopenharmony_ci    SatelliteControl satelliteControl;
161d95e75fdSopenharmony_ci    CellularCallInfo callInfo;
162d95e75fdSopenharmony_ci    bool isEcc = true;
163d95e75fdSopenharmony_ci    bool isAirplaneModeOn = true;
164d95e75fdSopenharmony_ci    bool isActivateSim = false;
165d95e75fdSopenharmony_ci    satelliteControl.HandleEcc(callInfo, isEcc, isAirplaneModeOn, isActivateSim);
166d95e75fdSopenharmony_ci    ASSERT_EQ(satelliteControl.SetReadyToCall(SIM1_SLOTID, true), TELEPHONY_SUCCESS);
167d95e75fdSopenharmony_ci}
168d95e75fdSopenharmony_ci
169d95e75fdSopenharmony_ci/**
170d95e75fdSopenharmony_ci * @tc.number   Telephony_CellularCallConnectionSatellite_001
171d95e75fdSopenharmony_ci * @tc.name     Test error branch
172d95e75fdSopenharmony_ci * @tc.desc     Function test
173d95e75fdSopenharmony_ci */
174d95e75fdSopenharmony_ciHWTEST_F(BranchTest, Telephony_CellularCallConnectionSatellite_001, Function | MediumTest | Level3)
175d95e75fdSopenharmony_ci{
176d95e75fdSopenharmony_ci    AccessToken token;
177d95e75fdSopenharmony_ci    CellularCallConnectionSatellite callConn;
178d95e75fdSopenharmony_ci    DialRequestStruct dialRequest;
179d95e75fdSopenharmony_ci    callConn.DialRequest(SIM1_SLOTID, dialRequest);
180d95e75fdSopenharmony_ci    callConn.HangUpRequest(SIM1_SLOTID);
181d95e75fdSopenharmony_ci    callConn.AnswerRequest(SIM1_SLOTID);
182d95e75fdSopenharmony_ci    callConn.RejectRequest(SIM1_SLOTID);
183d95e75fdSopenharmony_ci    callConn.GetSatelliteCallsDataRequest(SIM1_SLOTID, 0);
184d95e75fdSopenharmony_ci    ASSERT_NE(callConn.GetCallFailReasonRequest(SIM1_SLOTID), TELEPHONY_SUCCESS);
185d95e75fdSopenharmony_ci}
186d95e75fdSopenharmony_ci
187d95e75fdSopenharmony_ci/**
188d95e75fdSopenharmony_ci * @tc.number   Telephony_CellularCallService_001
189d95e75fdSopenharmony_ci * @tc.name     Test error branch
190d95e75fdSopenharmony_ci * @tc.desc     Function test
191d95e75fdSopenharmony_ci */
192d95e75fdSopenharmony_ciHWTEST_F(BranchTest, Telephony_CellularCallService_001, Function | MediumTest | Level3)
193d95e75fdSopenharmony_ci{
194d95e75fdSopenharmony_ci    CellularCallService callService;
195d95e75fdSopenharmony_ci    CellularCallInfo satelliteCallInfo = { .callType = CallType::TYPE_SATELLITE };
196d95e75fdSopenharmony_ci    callService.Dial(satelliteCallInfo);
197d95e75fdSopenharmony_ci    callService.HangUp(satelliteCallInfo, CallSupplementType::TYPE_HANG_UP_HOLD_WAIT);
198d95e75fdSopenharmony_ci    callService.Reject(satelliteCallInfo);
199d95e75fdSopenharmony_ci    callService.Answer(satelliteCallInfo);
200d95e75fdSopenharmony_ci    callService.HoldCall(satelliteCallInfo);
201d95e75fdSopenharmony_ci    callService.UnHoldCall(satelliteCallInfo);
202d95e75fdSopenharmony_ci
203d95e75fdSopenharmony_ci    callService.GetSatelliteControl(SIM1_SLOTID);
204d95e75fdSopenharmony_ci
205d95e75fdSopenharmony_ci    std::shared_ptr<SatelliteControl> satelliteControl;
206d95e75fdSopenharmony_ci    callService.SetSatelliteControl(SIM1_SLOTID, satelliteControl);
207d95e75fdSopenharmony_ci    ASSERT_NE(callService.SwitchCall(satelliteCallInfo), TELEPHONY_SUCCESS);
208d95e75fdSopenharmony_ci}
209d95e75fdSopenharmony_ci} // namespace Telephony
210d95e75fdSopenharmony_ci} // namespace OHOS
211