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 "ims_call_callback_proxy.h"
25 #include "ims_call_callback_stub.h"
26 #include "ims_call_client.h"
27 #include "ims_control.h"
28 #include "ims_error.h"
29 #include "ims_test.h"
30 #include "securec.h"
31 
32 namespace OHOS {
33 namespace Telephony {
34 using namespace testing::ext;
35 const std::string PHONE_NUMBER = "0000000";
36 const int32_t DEFAULT_INDEX = 1;
37 
38 /**
39  * @tc.number   cellular_call_ImsCallCallbackProxy_0001
40  * @tc.name     Test for ImsCallCallbackProxy
41  * @tc.desc     Function test
42  */
43 HWTEST_F(ImsTest, cellular_call_ImsCallCallbackProxy_0001, Function | MediumTest | Level3)
44 {
45     const sptr<ImsCallCallbackInterface> imsCallCallback_ = (std::make_unique<ImsCallCallbackStub>()).release();
46     auto callCallbackProxy =
47         (std::make_unique<ImsCallCallbackProxy>(imsCallCallback_->AsObject().GetRefPtr())).release();
48     ASSERT_TRUE(callCallbackProxy != nullptr);
49     for (int32_t slotId = 0; slotId < SIM_SLOT_COUNT; slotId++) {
50         if (!HasSimCard(slotId)) {
51             continue;
52         }
53         EventFwk::MatchingSkills matchingSkills;
54         matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_OPERATOR_CONFIG_CHANGED);
55         EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills);
56         auto handler = std::make_shared<CellularCallHandler>(subscriberInfo);
57         handler->SetSlotId(slotId);
58         handler->RegisterImsCallCallbackHandler();
59         RadioResponseInfo rilRadioResponse;
60         rilRadioResponse.error = ErrType::ERR_GENERIC_FAILURE;
61         ASSERT_EQ(callCallbackProxy->DialResponse(slotId, rilRadioResponse), TELEPHONY_SUCCESS);
62         ASSERT_EQ(callCallbackProxy->HangUpResponse(slotId, rilRadioResponse), TELEPHONY_SUCCESS);
63         ASSERT_EQ(callCallbackProxy->RejectWithReasonResponse(slotId, rilRadioResponse), TELEPHONY_SUCCESS);
64         ASSERT_EQ(callCallbackProxy->AnswerResponse(slotId, rilRadioResponse), TELEPHONY_SUCCESS);
65         ASSERT_EQ(callCallbackProxy->HoldCallResponse(slotId, rilRadioResponse), TELEPHONY_SUCCESS);
66         ASSERT_EQ(callCallbackProxy->UnHoldCallResponse(slotId, rilRadioResponse), TELEPHONY_SUCCESS);
67         ASSERT_EQ(callCallbackProxy->SwitchCallResponse(slotId, rilRadioResponse), TELEPHONY_SUCCESS);
68         ASSERT_EQ(callCallbackProxy->StartDtmfResponse(slotId, rilRadioResponse), TELEPHONY_SUCCESS);
69         ASSERT_GE(callCallbackProxy->SendDtmfResponse(slotId, rilRadioResponse, DEFAULT_INDEX), TELEPHONY_SUCCESS);
70         ASSERT_EQ(callCallbackProxy->StopDtmfResponse(slotId, rilRadioResponse), TELEPHONY_SUCCESS);
71         ASSERT_EQ(callCallbackProxy->SetImsSwitchResponse(slotId, rilRadioResponse), TELEPHONY_SUCCESS);
72         ASSERT_EQ(callCallbackProxy->GetImsSwitchResponse(slotId, rilRadioResponse), TELEPHONY_SUCCESS);
73         ASSERT_EQ(callCallbackProxy->GetImsCallsDataResponse(slotId, rilRadioResponse), TELEPHONY_SUCCESS);
74         ASSERT_EQ(callCallbackProxy->CallStateChangeReport(slotId), TELEPHONY_SUCCESS);
75         ImsCurrentCallList imsCallList;
76         imsCallList.callSize = 0;
77         ASSERT_EQ(callCallbackProxy->GetImsCallsDataResponse(slotId, imsCallList), TELEPHONY_SUCCESS);
78         DisconnectedDetails details;
79         ASSERT_EQ(callCallbackProxy->LastCallFailReasonResponse(slotId, details), TELEPHONY_SUCCESS);
80         RingbackVoice ringback;
81         ASSERT_EQ(callCallbackProxy->CallRingBackReport(slotId, ringback), TELEPHONY_SUCCESS);
82         int32_t active = 0;
83         ASSERT_EQ(callCallbackProxy->GetImsSwitchResponse(slotId, active), TELEPHONY_SUCCESS);
84         MuteControlResponse muteResponse;
85         ASSERT_EQ(callCallbackProxy->SetMuteResponse(slotId, muteResponse), TELEPHONY_SUCCESS);
86         ASSERT_EQ(callCallbackProxy->CombineConferenceResponse(slotId, rilRadioResponse), TELEPHONY_SUCCESS);
87         ASSERT_EQ(callCallbackProxy->InviteToConferenceResponse(slotId, rilRadioResponse), TELEPHONY_SUCCESS);
88     }
89 }
90 
91 /**
92  * @tc.number   cellular_call_ImsCallCallbackProxy_0002
93  * @tc.name     Test for ImsCallCallbackProxy
94  * @tc.desc     Function test
95  */
96 HWTEST_F(ImsTest, cellular_call_ImsCallCallbackProxy_0002, Function | MediumTest | Level3)
97 {
98     const sptr<ImsCallCallbackInterface> imsCallCallback_ = (std::make_unique<ImsCallCallbackStub>()).release();
99     auto callCallbackProxy =
100         (std::make_unique<ImsCallCallbackProxy>(imsCallCallback_->AsObject().GetRefPtr())).release();
101     ASSERT_TRUE(callCallbackProxy != nullptr);
102     for (int32_t slotId = 0; slotId < SIM_SLOT_COUNT; slotId++) {
103         if (!HasSimCard(slotId)) {
104             continue;
105         }
106         EventFwk::MatchingSkills matchingSkills;
107         matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_OPERATOR_CONFIG_CHANGED);
108         EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills);
109         auto handler = std::make_shared<CellularCallHandler>(subscriberInfo);
110         handler->SetSlotId(slotId);
111         handler->RegisterImsCallCallbackHandler();
112         GetClipResult clipResult;
113         clipResult.result.index = INVALID_INDEX;
114         ASSERT_EQ(callCallbackProxy->GetClipResponse(slotId, clipResult), TELEPHONY_SUCCESS);
115         GetClirResult clirResult;
116         clirResult.result.index = INVALID_INDEX;
117         ASSERT_EQ(callCallbackProxy->GetClirResponse(slotId, clirResult), TELEPHONY_SUCCESS);
118         SsBaseResult normalResult;
119         normalResult.index = DEFAULT_INDEX;
120         ASSERT_EQ(callCallbackProxy->SetClipResponse(slotId, normalResult), TELEPHONY_SUCCESS);
121         ASSERT_EQ(callCallbackProxy->SetClirResponse(slotId, normalResult), TELEPHONY_SUCCESS);
122         ASSERT_EQ(callCallbackProxy->SetCallTransferResponse(slotId, normalResult), TELEPHONY_SUCCESS);
123         ASSERT_EQ(callCallbackProxy->SetCallRestrictionResponse(slotId, normalResult), TELEPHONY_SUCCESS);
124         ASSERT_EQ(callCallbackProxy->SetCallWaitingResponse(slotId, normalResult), TELEPHONY_SUCCESS);
125         ASSERT_EQ(callCallbackProxy->SetColrResponse(slotId, normalResult), TELEPHONY_SUCCESS);
126         ASSERT_EQ(callCallbackProxy->SetColpResponse(slotId, normalResult), TELEPHONY_SUCCESS);
127         CallForwardQueryInfoList callList;
128         callList.result.index = INVALID_INDEX;
129         ASSERT_EQ(callCallbackProxy->GetCallTransferResponse(slotId, callList), TELEPHONY_SUCCESS);
130         CallRestrictionResult crResult;
131         crResult.result.index = INVALID_INDEX;
132         ASSERT_EQ(callCallbackProxy->GetCallRestrictionResponse(slotId, crResult), TELEPHONY_SUCCESS);
133         CallWaitResult cwResult;
134         cwResult.result.index = INVALID_INDEX;
135         ASSERT_EQ(callCallbackProxy->GetCallWaitingResponse(slotId, cwResult), TELEPHONY_SUCCESS);
136         GetColrResult colrResult;
137         colrResult.result.index = INVALID_INDEX;
138         ASSERT_EQ(callCallbackProxy->GetColrResponse(slotId, colrResult), TELEPHONY_SUCCESS);
139         GetColpResult colpResult;
140         colpResult.result.index = INVALID_INDEX;
141         ASSERT_EQ(callCallbackProxy->GetColpResponse(slotId, colpResult), TELEPHONY_SUCCESS);
142     }
143 }
144 
145 /**
146  * @tc.number   cellular_call_ImsCallCallbackProxy_0003
147  * @tc.name     Test for ImsCallCallbackProxy
148  * @tc.desc     Function test
149  */
150 HWTEST_F(ImsTest, cellular_call_ImsCallCallbackProxy_0003, Function | MediumTest | Level3)
151 {
152     const sptr<ImsCallCallbackInterface> imsCallCallback_ = (std::make_unique<ImsCallCallbackStub>()).release();
153     auto callCallbackProxy =
154         (std::make_unique<ImsCallCallbackProxy>(imsCallCallback_->AsObject().GetRefPtr())).release();
155     ASSERT_TRUE(callCallbackProxy != nullptr);
156     for (int32_t slotId = 0; slotId < SIM_SLOT_COUNT; slotId++) {
157         if (!HasSimCard(slotId)) {
158             continue;
159         }
160         EventFwk::MatchingSkills matchingSkills;
161         matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_OPERATOR_CONFIG_CHANGED);
162         EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills);
163         auto handler = std::make_shared<CellularCallHandler>(subscriberInfo);
164         handler->SetSlotId(slotId);
165         handler->RegisterImsCallCallbackHandler();
166         ImsCallModeReceiveInfo callModeReceiveInfo;
167         callModeReceiveInfo.callIndex = DEFAULT_INDEX;
168         ASSERT_EQ(
169             callCallbackProxy->ReceiveUpdateCallMediaModeResponse(slotId, callModeReceiveInfo), TELEPHONY_SUCCESS);
170         ASSERT_EQ(
171             callCallbackProxy->ReceiveUpdateCallMediaModeRequest(slotId, callModeReceiveInfo), TELEPHONY_SUCCESS);
172         ImsCallSessionEventInfo callSessionEventInfo;
173         callSessionEventInfo.callIndex = DEFAULT_INDEX;
174         ASSERT_EQ(callCallbackProxy->CallSessionEventChanged(slotId, callSessionEventInfo), TELEPHONY_SUCCESS);
175         ImsCallPeerDimensionsInfo callPeerDimensionsInfo;
176         callPeerDimensionsInfo.callIndex = DEFAULT_INDEX;
177         ASSERT_EQ(callCallbackProxy->PeerDimensionsChanged(slotId, callPeerDimensionsInfo), TELEPHONY_SUCCESS);
178         ImsCallDataUsageInfo callDataUsageInfo;
179         callDataUsageInfo.callIndex = DEFAULT_INDEX;
180         ASSERT_EQ(callCallbackProxy->CallDataUsageChanged(slotId, callDataUsageInfo), TELEPHONY_SUCCESS);
181         CameraCapabilitiesInfo cameraCapabilitiesInfo;
182         cameraCapabilitiesInfo.callIndex = DEFAULT_INDEX;
183         ASSERT_EQ(callCallbackProxy->CameraCapabilitiesChanged(slotId, cameraCapabilitiesInfo), TELEPHONY_SUCCESS);
184     }
185 }
186 } // namespace Telephony
187 } // namespace OHOS
188