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
16d95e75fdSopenharmony_ci#define private public
17d95e75fdSopenharmony_ci#define protected public
18d95e75fdSopenharmony_ci#include "cellular_call_config.h"
19d95e75fdSopenharmony_ci#include "cellular_call_handler.h"
20d95e75fdSopenharmony_ci#include "cellular_call_proxy.h"
21d95e75fdSopenharmony_ci#include "cellular_call_register.h"
22d95e75fdSopenharmony_ci#include "cellular_call_service.h"
23d95e75fdSopenharmony_ci#include "tel_ril_call_parcel.h"
24d95e75fdSopenharmony_ci#include "satellite_call_callback_proxy.h"
25d95e75fdSopenharmony_ci#include "satellite_call_callback_stub.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
31d95e75fdSopenharmony_cinamespace OHOS {
32d95e75fdSopenharmony_cinamespace Telephony {
33d95e75fdSopenharmony_ciusing namespace testing::ext;
34d95e75fdSopenharmony_ciconst int32_t SIM1_SLOTID = 0;
35d95e75fdSopenharmony_ciconst int32_t SIM2_SLOTID = 1;
36d95e75fdSopenharmony_ciconst int32_t SLOT_COUNT = 2;
37d95e75fdSopenharmony_ciconst std::string PHONE_NUMBER = "0000000";
38d95e75fdSopenharmony_ci
39d95e75fdSopenharmony_civoid SatelliteTest::SetUpTestCase(void)
40d95e75fdSopenharmony_ci{
41d95e75fdSopenharmony_ci    // step 3: Set Up Test Case
42d95e75fdSopenharmony_ci}
43d95e75fdSopenharmony_ci
44d95e75fdSopenharmony_civoid SatelliteTest::TearDownTestCase(void)
45d95e75fdSopenharmony_ci{
46d95e75fdSopenharmony_ci    // step 3: Tear Down Test Case
47d95e75fdSopenharmony_ci}
48d95e75fdSopenharmony_ci
49d95e75fdSopenharmony_civoid SatelliteTest::SetUp(void)
50d95e75fdSopenharmony_ci{
51d95e75fdSopenharmony_ci    // step 3: input testcase setup step
52d95e75fdSopenharmony_ci}
53d95e75fdSopenharmony_ci
54d95e75fdSopenharmony_civoid SatelliteTest::TearDown(void)
55d95e75fdSopenharmony_ci{
56d95e75fdSopenharmony_ci    // step 3: input testcase teardown step
57d95e75fdSopenharmony_ci}
58d95e75fdSopenharmony_ci
59d95e75fdSopenharmony_ci/**
60d95e75fdSopenharmony_ci * @tc.number   cellular_call_SatelliteCallCallbackProxy_0001
61d95e75fdSopenharmony_ci * @tc.name     Test for SatelliteCallCallbackProxy
62d95e75fdSopenharmony_ci * @tc.desc     Function test
63d95e75fdSopenharmony_ci */
64d95e75fdSopenharmony_ciHWTEST_F(SatelliteTest, cellular_call_SatelliteCallCallbackProxy_0001, Function | MediumTest | Level3)
65d95e75fdSopenharmony_ci{
66d95e75fdSopenharmony_ci    const sptr<SatelliteCallCallbackInterface> satelliteCallCallback_ =
67d95e75fdSopenharmony_ci        (std::make_unique<SatelliteCallCallbackStub>()).release();
68d95e75fdSopenharmony_ci    auto callCallbackProxy =
69d95e75fdSopenharmony_ci        (std::make_unique<SatelliteCallCallbackProxy>(satelliteCallCallback_->AsObject().GetRefPtr())).release();
70d95e75fdSopenharmony_ci    ASSERT_TRUE(callCallbackProxy != nullptr);
71d95e75fdSopenharmony_ci    for (int32_t slotId = 0; slotId < SIM_SLOT_COUNT; slotId++) {
72d95e75fdSopenharmony_ci        if (!HasSimCard(slotId)) {
73d95e75fdSopenharmony_ci            continue;
74d95e75fdSopenharmony_ci        }
75d95e75fdSopenharmony_ci        EventFwk::MatchingSkills matchingSkills;
76d95e75fdSopenharmony_ci        matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_OPERATOR_CONFIG_CHANGED);
77d95e75fdSopenharmony_ci        EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills);
78d95e75fdSopenharmony_ci        auto handler = std::make_shared<CellularCallHandler>(subscriberInfo);
79d95e75fdSopenharmony_ci        auto callClient = DelayedSingleton<SatelliteCallClient>::GetInstance();
80d95e75fdSopenharmony_ci        callClient->RegisterSatelliteCallCallbackHandler(slotId, handler);
81d95e75fdSopenharmony_ci        RadioResponseInfo rilRadioResponse;
82d95e75fdSopenharmony_ci        rilRadioResponse.error = ErrType::ERR_GENERIC_FAILURE;
83d95e75fdSopenharmony_ci
84d95e75fdSopenharmony_ci        ASSERT_EQ(callCallbackProxy->DialSatelliteResponse(slotId, rilRadioResponse), TELEPHONY_SUCCESS);
85d95e75fdSopenharmony_ci        ASSERT_EQ(callCallbackProxy->HangUpSatelliteResponse(slotId, rilRadioResponse), TELEPHONY_SUCCESS);
86d95e75fdSopenharmony_ci        ASSERT_EQ(callCallbackProxy->AnswerSatelliteResponse(slotId, rilRadioResponse), TELEPHONY_SUCCESS);
87d95e75fdSopenharmony_ci        ASSERT_EQ(callCallbackProxy->RejectSatelliteResponse(slotId, rilRadioResponse), TELEPHONY_SUCCESS);
88d95e75fdSopenharmony_ci        ASSERT_EQ(callCallbackProxy->GetSatelliteCallsDataResponse(slotId, rilRadioResponse), TELEPHONY_SUCCESS);
89d95e75fdSopenharmony_ci        ASSERT_EQ(callCallbackProxy->CallStateChangeReport(slotId), TELEPHONY_SUCCESS);
90d95e75fdSopenharmony_ci        SatelliteCurrentCallList satelliteCallList;
91d95e75fdSopenharmony_ci        satelliteCallList.callSize = 0;
92d95e75fdSopenharmony_ci        ASSERT_EQ(callCallbackProxy->GetSatelliteCallsDataResponse(slotId, satelliteCallList), TELEPHONY_SUCCESS);
93d95e75fdSopenharmony_ci    }
94d95e75fdSopenharmony_ci    DelayedSingleton<SatelliteCallClient>::GetInstance()->UnInit();
95d95e75fdSopenharmony_ci    DelayedSingleton<SatelliteCallClient>::DestroyInstance();
96d95e75fdSopenharmony_ci}
97d95e75fdSopenharmony_ci
98d95e75fdSopenharmony_ci/**
99d95e75fdSopenharmony_ci * @tc.number   cellular_call_SatelliteCallCallbackProxy_0002
100d95e75fdSopenharmony_ci * @tc.name     Test for SatelliteCallCallbackProxy
101d95e75fdSopenharmony_ci * @tc.desc     Function test
102d95e75fdSopenharmony_ci */
103d95e75fdSopenharmony_ciHWTEST_F(SatelliteTest, cellular_call_SatelliteCallCallbackProxy_0002, Function | MediumTest | Level3)
104d95e75fdSopenharmony_ci{
105d95e75fdSopenharmony_ci    const sptr<SatelliteCallCallbackInterface> satelliteCallCallback_ =
106d95e75fdSopenharmony_ci        (std::make_unique<SatelliteCallCallbackStub>()).release();
107d95e75fdSopenharmony_ci    auto callCallbackProxy =
108d95e75fdSopenharmony_ci        (std::make_unique<SatelliteCallCallbackProxy>(satelliteCallCallback_->AsObject().GetRefPtr())).release();
109d95e75fdSopenharmony_ci    ASSERT_TRUE(callCallbackProxy != nullptr);
110d95e75fdSopenharmony_ci    for (int32_t slotId = 0; slotId < SLOT_COUNT; slotId++) {
111d95e75fdSopenharmony_ci        EventFwk::MatchingSkills matchingSkills;
112d95e75fdSopenharmony_ci        matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_OPERATOR_CONFIG_CHANGED);
113d95e75fdSopenharmony_ci        EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills);
114d95e75fdSopenharmony_ci        auto handler = std::make_shared<CellularCallHandler>(subscriberInfo);
115d95e75fdSopenharmony_ci        auto callClient = DelayedSingleton<SatelliteCallClient>::GetInstance();
116d95e75fdSopenharmony_ci        callClient->RegisterSatelliteCallCallbackHandler(slotId, handler);
117d95e75fdSopenharmony_ci        RadioResponseInfo rilRadioResponse;
118d95e75fdSopenharmony_ci        rilRadioResponse.error = ErrType::ERR_GENERIC_FAILURE;
119d95e75fdSopenharmony_ci
120d95e75fdSopenharmony_ci        ASSERT_EQ(callCallbackProxy->DialSatelliteResponse(slotId, rilRadioResponse), TELEPHONY_SUCCESS);
121d95e75fdSopenharmony_ci        ASSERT_EQ(callCallbackProxy->HangUpSatelliteResponse(slotId, rilRadioResponse), TELEPHONY_SUCCESS);
122d95e75fdSopenharmony_ci        ASSERT_EQ(callCallbackProxy->AnswerSatelliteResponse(slotId, rilRadioResponse), TELEPHONY_SUCCESS);
123d95e75fdSopenharmony_ci        ASSERT_EQ(callCallbackProxy->RejectSatelliteResponse(slotId, rilRadioResponse), TELEPHONY_SUCCESS);
124d95e75fdSopenharmony_ci        ASSERT_EQ(callCallbackProxy->GetSatelliteCallsDataResponse(slotId, rilRadioResponse), TELEPHONY_SUCCESS);
125d95e75fdSopenharmony_ci        ASSERT_EQ(callCallbackProxy->CallStateChangeReport(slotId), TELEPHONY_SUCCESS);
126d95e75fdSopenharmony_ci        SatelliteCurrentCallList satelliteCallList;
127d95e75fdSopenharmony_ci        satelliteCallList.callSize = 0;
128d95e75fdSopenharmony_ci        ASSERT_EQ(callCallbackProxy->GetSatelliteCallsDataResponse(slotId, satelliteCallList), TELEPHONY_SUCCESS);
129d95e75fdSopenharmony_ci    }
130d95e75fdSopenharmony_ci    DelayedSingleton<SatelliteCallClient>::GetInstance()->UnInit();
131d95e75fdSopenharmony_ci    DelayedSingleton<SatelliteCallClient>::DestroyInstance();
132d95e75fdSopenharmony_ci}
133d95e75fdSopenharmony_ci
134d95e75fdSopenharmony_ci/**
135d95e75fdSopenharmony_ci * @tc.number   cellular_call_SatelliteCallCallbackStub_0001
136d95e75fdSopenharmony_ci * @tc.name     Test for SatelliteCallCallbackStub
137d95e75fdSopenharmony_ci * @tc.desc     Function test
138d95e75fdSopenharmony_ci */
139d95e75fdSopenharmony_ciHWTEST_F(SatelliteTest, cellular_call_SatelliteCallCallbackStub_0001, Function | MediumTest | Level3)
140d95e75fdSopenharmony_ci{
141d95e75fdSopenharmony_ci    sptr<SatelliteCallCallbackStub> stub = (std::make_unique<SatelliteCallCallbackStub>()).release();
142d95e75fdSopenharmony_ci    ASSERT_TRUE(stub != nullptr);
143d95e75fdSopenharmony_ci    if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
144d95e75fdSopenharmony_ci        return;
145d95e75fdSopenharmony_ci    }
146d95e75fdSopenharmony_ci    for (int32_t slotId = 0; slotId < SIM_SLOT_COUNT; slotId++) {
147d95e75fdSopenharmony_ci        if (!HasSimCard(slotId)) {
148d95e75fdSopenharmony_ci            continue;
149d95e75fdSopenharmony_ci        }
150d95e75fdSopenharmony_ci        RadioResponseInfo rilRadioResponse;
151d95e75fdSopenharmony_ci        rilRadioResponse.error = ErrType::ERR_GENERIC_FAILURE;
152d95e75fdSopenharmony_ci        MessageParcel answerData;
153d95e75fdSopenharmony_ci        MessageParcel answerReply;
154d95e75fdSopenharmony_ci        ASSERT_TRUE(answerData.WriteInt32(slotId));
155d95e75fdSopenharmony_ci        ASSERT_TRUE(answerData.WriteRawData((const void *)&rilRadioResponse, sizeof(RadioResponseInfo)));
156d95e75fdSopenharmony_ci        ASSERT_EQ(stub->OnAnswerResponseInner(answerData, answerReply), TELEPHONY_SUCCESS);
157d95e75fdSopenharmony_ci
158d95e75fdSopenharmony_ci        MessageParcel dialData;
159d95e75fdSopenharmony_ci        MessageParcel dialReply;
160d95e75fdSopenharmony_ci        ASSERT_TRUE(dialData.WriteInt32(slotId));
161d95e75fdSopenharmony_ci        ASSERT_TRUE(dialData.WriteRawData((const void *)&rilRadioResponse, sizeof(RadioResponseInfo)));
162d95e75fdSopenharmony_ci        ASSERT_EQ(stub->OnDialResponseInner(dialData, dialReply), TELEPHONY_SUCCESS);
163d95e75fdSopenharmony_ci
164d95e75fdSopenharmony_ci        MessageParcel CallsData;
165d95e75fdSopenharmony_ci        MessageParcel CallsReply;
166d95e75fdSopenharmony_ci        ASSERT_TRUE(CallsData.WriteInt32(slotId));
167d95e75fdSopenharmony_ci        ASSERT_TRUE(CallsData.WriteRawData((const void *)&rilRadioResponse, sizeof(RadioResponseInfo)));
168d95e75fdSopenharmony_ci        ASSERT_EQ(stub->OnGetSatelliteCallsDataResponseInner(CallsData, CallsReply), TELEPHONY_SUCCESS);
169d95e75fdSopenharmony_ci
170d95e75fdSopenharmony_ci        MessageParcel hangupData;
171d95e75fdSopenharmony_ci        MessageParcel hangupReply;
172d95e75fdSopenharmony_ci        ASSERT_TRUE(hangupData.WriteInt32(slotId));
173d95e75fdSopenharmony_ci        ASSERT_TRUE(hangupData.WriteRawData((const void *)&rilRadioResponse, sizeof(RadioResponseInfo)));
174d95e75fdSopenharmony_ci        ASSERT_EQ(stub->OnHangUpResponseInner(hangupData, hangupReply), TELEPHONY_SUCCESS);
175d95e75fdSopenharmony_ci
176d95e75fdSopenharmony_ci        MessageParcel rejectData;
177d95e75fdSopenharmony_ci        MessageParcel rejectReply;
178d95e75fdSopenharmony_ci        ASSERT_TRUE(rejectData.WriteInt32(slotId));
179d95e75fdSopenharmony_ci        ASSERT_TRUE(rejectData.WriteRawData((const void *)&rilRadioResponse, sizeof(RadioResponseInfo)));
180d95e75fdSopenharmony_ci        ASSERT_EQ(stub->OnRejectResponseInner(rejectData, rejectReply), TELEPHONY_SUCCESS);
181d95e75fdSopenharmony_ci
182d95e75fdSopenharmony_ci        MessageParcel statechangeData;
183d95e75fdSopenharmony_ci        MessageParcel statechangeReply;
184d95e75fdSopenharmony_ci        ASSERT_TRUE(statechangeData.WriteInt32(slotId));
185d95e75fdSopenharmony_ci        ASSERT_EQ(stub->OnCallStateChangeReportInner(statechangeData, statechangeReply), TELEPHONY_SUCCESS);
186d95e75fdSopenharmony_ci    }
187d95e75fdSopenharmony_ci}
188d95e75fdSopenharmony_ci
189d95e75fdSopenharmony_ci/**
190d95e75fdSopenharmony_ci * @tc.number   cellular_call_SatelliteCallCallbackStub_0002
191d95e75fdSopenharmony_ci * @tc.name     Test for SatelliteCallCallbackStub
192d95e75fdSopenharmony_ci * @tc.desc     Function test
193d95e75fdSopenharmony_ci */
194d95e75fdSopenharmony_ciHWTEST_F(SatelliteTest, cellular_call_SatelliteCallCallbackStub_0002, Function | MediumTest | Level3)
195d95e75fdSopenharmony_ci{
196d95e75fdSopenharmony_ci    sptr<SatelliteCallCallbackStub> stub = (std::make_unique<SatelliteCallCallbackStub>()).release();
197d95e75fdSopenharmony_ci    ASSERT_TRUE(stub != nullptr);
198d95e75fdSopenharmony_ci    int32_t slotId = 0;
199d95e75fdSopenharmony_ci    RadioResponseInfo rilRadioResponse;
200d95e75fdSopenharmony_ci    rilRadioResponse.error = ErrType::ERR_GENERIC_FAILURE;
201d95e75fdSopenharmony_ci    MessageParcel answerData;
202d95e75fdSopenharmony_ci    MessageParcel answerReply;
203d95e75fdSopenharmony_ci    ASSERT_TRUE(answerData.WriteInt32(slotId));
204d95e75fdSopenharmony_ci    ASSERT_TRUE(answerData.WriteRawData((const void *)&rilRadioResponse, sizeof(RadioResponseInfo)));
205d95e75fdSopenharmony_ci    ASSERT_EQ(stub->OnAnswerResponseInner(answerData, answerReply), TELEPHONY_SUCCESS);
206d95e75fdSopenharmony_ci
207d95e75fdSopenharmony_ci    MessageParcel dialData;
208d95e75fdSopenharmony_ci    MessageParcel dialReply;
209d95e75fdSopenharmony_ci    ASSERT_TRUE(dialData.WriteInt32(slotId));
210d95e75fdSopenharmony_ci    ASSERT_TRUE(dialData.WriteRawData((const void *)&rilRadioResponse, sizeof(RadioResponseInfo)));
211d95e75fdSopenharmony_ci    ASSERT_EQ(stub->OnDialResponseInner(dialData, dialReply), TELEPHONY_SUCCESS);
212d95e75fdSopenharmony_ci
213d95e75fdSopenharmony_ci    MessageParcel CallsData;
214d95e75fdSopenharmony_ci    MessageParcel CallsReply;
215d95e75fdSopenharmony_ci    ASSERT_TRUE(CallsData.WriteInt32(slotId));
216d95e75fdSopenharmony_ci    ASSERT_TRUE(CallsData.WriteRawData((const void *)&rilRadioResponse, sizeof(RadioResponseInfo)));
217d95e75fdSopenharmony_ci    ASSERT_EQ(stub->OnGetSatelliteCallsDataResponseInner(CallsData, CallsReply), TELEPHONY_SUCCESS);
218d95e75fdSopenharmony_ci
219d95e75fdSopenharmony_ci    MessageParcel hangupData;
220d95e75fdSopenharmony_ci    MessageParcel hangupReply;
221d95e75fdSopenharmony_ci    ASSERT_TRUE(hangupData.WriteInt32(slotId));
222d95e75fdSopenharmony_ci    ASSERT_TRUE(hangupData.WriteRawData((const void *)&rilRadioResponse, sizeof(RadioResponseInfo)));
223d95e75fdSopenharmony_ci    ASSERT_EQ(stub->OnHangUpResponseInner(hangupData, hangupReply), TELEPHONY_SUCCESS);
224d95e75fdSopenharmony_ci
225d95e75fdSopenharmony_ci    MessageParcel rejectData;
226d95e75fdSopenharmony_ci    MessageParcel rejectReply;
227d95e75fdSopenharmony_ci    ASSERT_TRUE(rejectData.WriteInt32(slotId));
228d95e75fdSopenharmony_ci    ASSERT_TRUE(rejectData.WriteRawData((const void *)&rilRadioResponse, sizeof(RadioResponseInfo)));
229d95e75fdSopenharmony_ci    ASSERT_EQ(stub->OnRejectResponseInner(rejectData, rejectReply), TELEPHONY_SUCCESS);
230d95e75fdSopenharmony_ci
231d95e75fdSopenharmony_ci    MessageParcel statechangeData;
232d95e75fdSopenharmony_ci    MessageParcel statechangeReply;
233d95e75fdSopenharmony_ci    ASSERT_TRUE(statechangeData.WriteInt32(slotId));
234d95e75fdSopenharmony_ci    ASSERT_EQ(stub->OnCallStateChangeReportInner(statechangeData, statechangeReply), TELEPHONY_SUCCESS);
235d95e75fdSopenharmony_ci}
236d95e75fdSopenharmony_ci} // namespace Telephony
237d95e75fdSopenharmony_ci} // namespace OHOS
238