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 "hril_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 31 namespace OHOS { 32 namespace Telephony { 33 using namespace testing::ext; 34 const int32_t SIM1_SLOTID = 0; 35 const int32_t SIM2_SLOTID = 1; 36 const std::string PHONE_NUMBER = "0000000"; 37 38 /** 39 * @tc.number cellular_call_SatelliteCallCallbackProxy_0001 40 * @tc.name Test for SatelliteCallCallbackProxy 41 * @tc.desc Function test 42 */ 43 HWTEST_F(SatelliteTest, cellular_call_SatelliteCallCallbackProxy_0001, Function | MediumTest | Level3) 44 { 45 const sptr<SatelliteCallCallbackInterface> satelliteCallCallback_ = 46 (std::make_unique<SatelliteCallCallbackStub>()).release(); 47 auto callCallbackProxy = 48 (std::make_unique<SatelliteCallCallbackProxy>(satelliteCallCallback_->AsObject().GetRefPtr())).release(); 49 ASSERT_TRUE(callCallbackProxy != nullptr); 50 for (int32_t slotId = 0; slotId < SIM_SLOT_COUNT; slotId++) { 51 if (!HasSimCard(slotId)) { 52 continue; 53 } 54 EventFwk::MatchingSkills matchingSkills; 55 matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_OPERATOR_CONFIG_CHANGED); 56 EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills); 57 auto handler = std::make_shared<CellularCallHandler>(subscriberInfo); 58 auto callClient = DelayedSingleton<SatelliteCallClient>::GetInstance(); 59 callClient->RegisterSatelliteCallCallbackHandler(slotId, handler); 60 HRilRadioResponseInfo rilRadioResponse; 61 rilRadioResponse.error = HRilErrType::HRIL_ERR_GENERIC_FAILURE; 62 63 ASSERT_EQ(callCallbackProxy->DialSatelliteResponse(slotId, rilRadioResponse), TELEPHONY_SUCCESS); 64 ASSERT_EQ(callCallbackProxy->HangUpSatelliteResponse(slotId, rilRadioResponse), TELEPHONY_SUCCESS); 65 ASSERT_EQ(callCallbackProxy->AnswerSatelliteResponse(slotId, rilRadioResponse), TELEPHONY_SUCCESS); 66 ASSERT_EQ(callCallbackProxy->RejectSatelliteResponse(slotId, rilRadioResponse), TELEPHONY_SUCCESS); 67 ASSERT_EQ(callCallbackProxy->GetSatelliteCallsDataResponse(slotId, rilRadioResponse), TELEPHONY_SUCCESS); 68 ASSERT_EQ(callCallbackProxy->CallStateChangeReport(slotId), TELEPHONY_SUCCESS); 69 SatelliteCurrentCallList satelliteCallList; 70 satelliteCallList.callSize = 0; 71 ASSERT_EQ(callCallbackProxy->GetSatelliteCallsDataResponse(slotId, satelliteCallList), TELEPHONY_SUCCESS); 72 } 73 DelayedSingleton<SatelliteCallClient>::GetInstance()->UnInit(); 74 DelayedSingleton<SatelliteCallClient>::DestroyInstance(); 75 } 76 77 /** 78 * @tc.number cellular_call_SatelliteCallCallbackStub_0001 79 * @tc.name Test for SatelliteCallCallbackStub 80 * @tc.desc Function test 81 */ 82 HWTEST_F(SatelliteTest, cellular_call_SatelliteCallCallbackStub_0001, Function | MediumTest | Level3) 83 { 84 sptr<SatelliteCallCallbackStub> stub = (std::make_unique<SatelliteCallCallbackStub>()).release(); 85 ASSERT_TRUE(stub != nullptr); 86 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) { 87 return; 88 } 89 for (int32_t slotId = 0; slotId < SIM_SLOT_COUNT; slotId++) { 90 if (!HasSimCard(slotId)) { 91 continue; 92 } 93 HRilRadioResponseInfo rilRadioResponse; 94 rilRadioResponse.error = HRilErrType::HRIL_ERR_GENERIC_FAILURE; 95 MessageParcel answerData; 96 MessageParcel answerReply; 97 ASSERT_TRUE(answerData.WriteInt32(slotId)); 98 ASSERT_TRUE(answerData.WriteRawData((const void *)&rilRadioResponse, sizeof(HRilRadioResponseInfo))); 99 ASSERT_EQ(stub->OnAnswerResponseInner(answerData, answerReply), TELEPHONY_SUCCESS); 100 101 MessageParcel dialData; 102 MessageParcel dialReply; 103 ASSERT_TRUE(dialData.WriteInt32(slotId)); 104 ASSERT_TRUE(dialData.WriteRawData((const void *)&rilRadioResponse, sizeof(HRilRadioResponseInfo))); 105 ASSERT_EQ(stub->OnDialResponseInner(dialData, dialReply), TELEPHONY_SUCCESS); 106 107 MessageParcel CallsData; 108 MessageParcel CallsReply; 109 ASSERT_TRUE(CallsData.WriteInt32(slotId)); 110 ASSERT_TRUE(CallsData.WriteRawData((const void *)&rilRadioResponse, sizeof(HRilRadioResponseInfo))); 111 ASSERT_EQ(stub->OnGetSatelliteCallsDataResponseInner(CallsData, CallsReply), TELEPHONY_SUCCESS); 112 113 MessageParcel hangupData; 114 MessageParcel hangupReply; 115 ASSERT_TRUE(hangupData.WriteInt32(slotId)); 116 ASSERT_TRUE(hangupData.WriteRawData((const void *)&rilRadioResponse, sizeof(HRilRadioResponseInfo))); 117 ASSERT_EQ(stub->OnHangUpResponseInner(hangupData, hangupReply), TELEPHONY_SUCCESS); 118 119 MessageParcel rejectData; 120 MessageParcel rejectReply; 121 ASSERT_TRUE(rejectData.WriteInt32(slotId)); 122 ASSERT_TRUE(rejectData.WriteRawData((const void *)&rilRadioResponse, sizeof(HRilRadioResponseInfo))); 123 ASSERT_EQ(stub->OnRejectResponseInner(rejectData, rejectReply), TELEPHONY_SUCCESS); 124 125 MessageParcel statechangeData; 126 MessageParcel statechangeReply; 127 ASSERT_TRUE(statechangeData.WriteInt32(slotId)); 128 ASSERT_EQ(stub->OnCallStateChangeReportInner(statechangeData, statechangeReply), TELEPHONY_SUCCESS); 129 } 130 } 131 } // namespace Telephony 132 } // namespace OHOS 133