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