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