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