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 #define private public
16 #define protected public
17 #include "bluetooth_call_client.h"
18 #include "bluetooth_call_manager.h"
19 #include "bluetooth_call_service.h"
20 #include "bluetooth_connection.h"
21 #include "common_event_manager.h"
22 #include "common_event_support.h"
23 #include "gtest/gtest.h"
24 #include "ims_call.h"
25 #include "voip_call.h"
26 #include "audio_control_manager.h"
27 #include "call_state_processor.h"
28
29 namespace OHOS {
30 namespace Telephony {
31 using namespace testing::ext;
32 constexpr int WAIT_TIME = 3;
33 constexpr int DEFAULT_SLOT_ID = 0;
34 constexpr int VALID_CALL_ID = 1;
35 constexpr const char* NUMBER = "10086";
36 constexpr const char* NAME = "test";
37
38 class ZeroBranch7Test : public testing::Test {
39 public:
40 static void SetUpTestCase();
41 static void TearDownTestCase();
42 void SetUp();
43 void TearDown();
44 };
SetUpTestCase()45 void ZeroBranch7Test::SetUpTestCase() {}
46
TearDownTestCase()47 void ZeroBranch7Test::TearDownTestCase() {}
48
SetUp()49 void ZeroBranch7Test::SetUp()
50 {
51 DelayedSingleton<AudioProxy>::GetInstance()->SetAudioMicStateChangeCallback();
52 DelayedSingleton<AudioProxy>::GetInstance()->SetAudioDeviceChangeCallback();
53 DelayedSingleton<AudioProxy>::GetInstance()->SetAudioPreferDeviceChangeCallback();
54 }
55
TearDown()56 void ZeroBranch7Test::TearDown()
57 {
58 sleep(1);
59 }
60
61 /**
62 * @tc.number Telephony_AudioControlManager_001
63 * @tc.name test error branch
64 * @tc.desc Function test
65 */
66 HWTEST_F(ZeroBranch7Test, Telephony_AudioControlManager_001, Function | MediumTest | Level3)
67 {
68 DialParaInfo mDialParaInfo;
69 mDialParaInfo.accountId = 0;
70 sptr<OHOS::Telephony::CallBase> callObjectPtr = nullptr;
71 DelayedSingleton<CallStateProcessor>::GetInstance()->holdingCalls_.insert(1);
72 auto audioControl = DelayedSingleton<AudioControlManager>::GetInstance();
73 audioControl->VideoStateUpdated(callObjectPtr, VideoStateType::TYPE_VOICE, VideoStateType::TYPE_VIDEO);
74 callObjectPtr = new IMSCall(mDialParaInfo);
75 callObjectPtr->SetCallType(CallType::TYPE_IMS);
76 audioControl->VideoStateUpdated(callObjectPtr, VideoStateType::TYPE_VOICE, VideoStateType::TYPE_VIDEO);
77 callObjectPtr->SetCrsType(2);
78 audioControl->VideoStateUpdated(callObjectPtr, VideoStateType::TYPE_VOICE, VideoStateType::TYPE_VIDEO);
79 audioControl->UpdateDeviceTypeForVideoOrSatelliteCall();
80 audioControl->MuteNetWorkRingTone();
81 audioControl->IsBtOrWireHeadPlugin();
82 sptr<CallBase> call = nullptr;
83 audioControl->IncomingCallHungUp(call, false, "");
84 audioControl->CallStateUpdated(call, TelCallState::CALL_STATUS_DIALING, TelCallState::CALL_STATUS_ALERTING);
85 call = new VoIPCall(mDialParaInfo);
86 call->SetCallType(CallType::TYPE_VOIP);
87 audioControl->CallStateUpdated(call, TelCallState::CALL_STATUS_DIALING, TelCallState::CALL_STATUS_ALERTING);
88 audioControl->HandleCallStateUpdated(call, TelCallState::CALL_STATUS_DIALING, TelCallState::CALL_STATUS_ANSWERED);
89 audioControl->HandleNextState(call, TelCallState::CALL_STATUS_ALERTING);
90 audioControl->HandleNextState(call, TelCallState::CALL_STATUS_INCOMING);
91 audioControl->HandleNextState(call, TelCallState::CALL_STATUS_WAITING);
92 audioControl->HandlePriorState(call, TelCallState::CALL_STATUS_ALERTING);
93 audioControl->HandlePriorState(call, TelCallState::CALL_STATUS_INCOMING);
94 audioControl->HandlePriorState(call, TelCallState::CALL_STATUS_WAITING);
95 audioControl->HandlePriorState(call, TelCallState::CALL_STATUS_HOLDING);
96 call->SetCallRunningState(CallRunningState::CALL_RUNNING_STATE_ACTIVE);
97 audioControl->HandlePriorState(call, TelCallState::CALL_STATUS_INCOMING);
98 audioControl->HandlePriorState(call, TelCallState::CALL_STATUS_WAITING);
99 audioControl->UpdateForegroundLiveCall();
100 audioControl->ProcessAudioWhenCallActive(call);
101 std::string emptyNumber = "";
102 call->SetAccountNumber(emptyNumber);
103 audioControl->HandleNewActiveCall(call);
104 call->SetAccountNumber(NUMBER);
105 call->SetCallType(CallType::TYPE_CS);
106 audioControl->HandleNewActiveCall(call);
107 call->SetCallType(CallType::TYPE_SATELLITE);
108 audioControl->HandleNewActiveCall(call);
109 call->SetCallType(CallType::TYPE_ERR_CALL);
110 audioControl->HandleNewActiveCall(call);
111 audioControl->GetCallList().empty();
112 EXPECT_TRUE(audioControl != nullptr);
113 }
114
115 /**
116 * @tc.number Telephony_AudioControlManager_002
117 * @tc.name test error branch
118 * @tc.desc Function test
119 */
120 HWTEST_F(ZeroBranch7Test, Telephony_AudioControlManager_002, Function | MediumTest | Level3)
121 {
122 auto audioControl = DelayedSingleton<AudioControlManager>::GetInstance();
123 AudioDevice device;
124 device.deviceType = AudioDeviceType::DEVICE_DISTRIBUTED_PAD;
125 if (memset_s(device.address, kMaxAddressLen + 1, 0, kMaxAddressLen + 1) != EOK) {
126 return;
127 }
128 audioControl->SetAudioDevice(device);
129 device.deviceType = AudioDeviceType::DEVICE_DISTRIBUTED_PHONE;
130 audioControl->SetAudioDevice(device);
131 device.deviceType = AudioDeviceType::DEVICE_DISTRIBUTED_AUTOMOTIVE;
132 audioControl->SetAudioDevice(device);
133 device.deviceType = AudioDeviceType::DEVICE_BLUETOOTH_SCO;
134 audioControl->SetAudioDevice(device);
135 audioControl->PlayRingtone();
136 audioControl->PlaySoundtone();
137 audioControl->StopRingtone();
138 audioControl->GetInitAudioDeviceType();
139 audioControl->SetMute(false);
140 audioControl->MuteRinger();
141 audioControl->PlayCallEndedTone(CallEndedType::PHONE_IS_BUSY);
142 audioControl->PlayCallEndedTone(CallEndedType::CALL_ENDED_NORMALLY);
143 audioControl->PlayCallEndedTone(CallEndedType::UNKNOWN);
144 audioControl->PlayCallEndedTone(CallEndedType::INVALID_NUMBER);
145 audioControl->PlayCallEndedTone(static_cast<CallEndedType>(5));
146 audioControl->GetCallBase(VALID_CALL_ID);
147 audioControl->IsEmergencyCallExists();
148 audioControl->SetToneState(ToneState::TONEING);
149 audioControl->IsNumberAllowed(NUMBER);
150 ASSERT_TRUE(audioControl != nullptr);
151 }
152
153 /**
154 * @tc.number Telephony_AudioControlManager_003
155 * @tc.name test error branch
156 * @tc.desc Function test
157 */
158 HWTEST_F(ZeroBranch7Test, Telephony_AudioControlManager_003, Function | MediumTest | Level3)
159 {
160 auto audioControl = DelayedSingleton<AudioControlManager>::GetInstance();
161 audioControl->IsTonePlaying();
162 audioControl->IsCurrentRinging();
163 audioControl->PlayRingback();
164 audioControl->StopWaitingTone();
165 audioControl->PlayDtmfTone('a');
166 audioControl->StopDtmfTone();
167 audioControl->OnPostDialNextChar('a');
168 audioControl->IsSoundPlaying();
169 ASSERT_TRUE(audioControl->IsVideoCall(VideoStateType::TYPE_VIDEO));
170 }
171
172 /**
173 * @tc.number Telephony_AudioControlManager_004
174 * @tc.name test error branch
175 * @tc.desc Function test
176 */
177 HWTEST_F(ZeroBranch7Test, Telephony_AudioControlManager_004, Function | MediumTest | Level3)
178 {
179 auto audioControl = DelayedSingleton<AudioControlManager>::GetInstance();
180 audioControl->isCrsVibrating_ = true;
181 audioControl->MuteNetWorkRingTone();
182 DisconnectedDetails details;
183 audioControl->CallDestroyed(details);
184 audioControl->toneState_ = ToneState::CALLENDED;
185 audioControl->StopCallTone();
186 audioControl->tone_ = nullptr;
187 audioControl->StopCallTone();
188 audioControl->GetAudioInterruptState();
189 audioControl->SetVolumeAudible();
190 audioControl->ringState_ = RingState::RINGING;
191 audioControl->MuteRinger();
192 ASSERT_TRUE(audioControl->GetCurrentActiveCall() == nullptr);
193 }
194
195 /**
196 * @tc.number Telephony_CallBroadcastSubscriber_001
197 * @tc.name test error branch
198 * @tc.desc Function test
199 */
200 HWTEST_F(ZeroBranch7Test, Telephony_CallBroadcastSubscriber_001, Function | MediumTest | Level3)
201 {
202 EventFwk::MatchingSkills matchingSkills;
203 matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_SIM_STATE_CHANGED);
204 EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills);
205 CallBroadcastSubscriber subscriber(subscriberInfo);
206 EventFwk::CommonEventData eventData;
207 ASSERT_NO_THROW(subscriber.OnReceiveEvent(eventData));
208 ASSERT_NO_THROW(subscriber.UnknownBroadcast(eventData));
209 ASSERT_NO_THROW(subscriber.SimStateBroadcast(eventData));
210 ASSERT_NO_THROW(subscriber.ConnectCallUiServiceBroadcast(eventData));
211 ASSERT_NO_THROW(subscriber.HighTempLevelChangedBroadcast(eventData));
212 ASSERT_NO_THROW(subscriber.ConnectCallUiSuperPrivacyModeBroadcast(eventData));
213 ASSERT_NO_THROW(subscriber.UpdateBluetoothDeviceName(eventData));
214 ASSERT_NO_THROW(subscriber.ConnectCallUiUserSwitchedBroadcast(eventData));
215 ASSERT_NO_THROW(subscriber.ShutdownBroadcast(eventData));
216 ASSERT_NO_THROW(subscriber.HsdrEventBroadcast(eventData));
217 ASSERT_NO_THROW(subscriber.ScreenUnlockedBroadcast(eventData));
218 }
219
220 /**
221 * @tc.number Telephony_CallStatusCallbackStub_008
222 * @tc.name test error branch
223 * @tc.desc Function test
224 */
225 HWTEST_F(ZeroBranch7Test, Telephony_CallStatusCallbackStub_001, Function | MediumTest | Level3)
226 {
227 auto callStatusCallback = std::make_shared<CallStatusCallback>();
228 MessageParcel messageParcel;
229 messageParcel.WriteInterfaceToken(CallStatusCallbackStub::GetDescriptor());
230 messageParcel.WriteInt32(0);
231 messageParcel.WriteString("hello");
232 MessageParcel reply;
233 ASSERT_EQ(callStatusCallback->OnUpdateDisconnectedCause(messageParcel, reply), TELEPHONY_SUCCESS);
234 MessageParcel dataParcel2;
235 dataParcel2.WriteInterfaceToken(CallStatusCallbackStub::GetDescriptor());
236 dataParcel2.WriteInt32(0);
237 callStatusCallback->OnUpdateRBTPlayInfo(dataParcel2, reply);
238 callStatusCallback->OnUpdateSetWaitingResult(dataParcel2, reply);
239 callStatusCallback->OnUpdateSetRestrictionResult(dataParcel2, reply);
240 callStatusCallback->OnUpdateSetRestrictionPasswordResult(dataParcel2, reply);
241 callStatusCallback->OnUpdateSetTransferResult(dataParcel2, reply);
242 callStatusCallback->OnUpdateSetCallClirResult(dataParcel2, reply);
243 callStatusCallback->OnStartRttResult(dataParcel2, reply);
244 callStatusCallback->OnStopRttResult(dataParcel2, reply);
245 callStatusCallback->OnSetImsConfigResult(dataParcel2, reply);
246 callStatusCallback->OnSetImsFeatureValueResult(dataParcel2, reply);
247 callStatusCallback->OnInviteToConferenceResult(dataParcel2, reply);
248 callStatusCallback->OnStartDtmfResult(dataParcel2, reply);
249 callStatusCallback->OnStopDtmfResult(dataParcel2, reply);
250 callStatusCallback->OnSendUssdResult(dataParcel2, reply);
251 callStatusCallback->OnGetImsCallDataResult(dataParcel2, reply);
252 ASSERT_EQ(callStatusCallback->OnCloseUnFinishedUssdResult(dataParcel2, reply), TELEPHONY_SUCCESS);
253 }
254
255 /**
256 * @tc.number Telephony_CallStatusCallbackStub_009
257 * @tc.name test error branch
258 * @tc.desc Function test
259 */
260 HWTEST_F(ZeroBranch7Test, Telephony_CallStatusCallbackStub_002, Function | MediumTest | Level3)
261 {
262 auto callStatusCallback = std::make_shared<CallStatusCallback>();
263 MessageParcel dataParce3;
264 dataParce3.WriteInterfaceToken(CallStatusCallbackStub::GetDescriptor());
265 int32_t length = sizeof(ClirResponse);
266 dataParce3.WriteInt32(length);
267 ClirResponse clirResponse;
268 dataParce3.WriteRawData((const void *)&clirResponse, length);
269 dataParce3.RewindRead(0);
270 MessageParcel reply;
271 callStatusCallback->OnUpdateGetCallClirResult(dataParce3, reply);
272
273 MessageParcel dataParce4;
274 dataParce4.WriteInterfaceToken(CallStatusCallbackStub::GetDescriptor());
275 length = sizeof(CallModeReportInfo);
276 dataParce4.WriteInt32(length);
277 CallModeReportInfo callModeReportInfo;
278 dataParce4.WriteRawData((const void *)&callModeReportInfo, length);
279 dataParce4.RewindRead(0);
280 callStatusCallback->OnReceiveImsCallModeResponse(dataParce4, reply);
281 MessageParcel dataParce5;
282 dataParce5.WriteInterfaceToken(CallStatusCallbackStub::GetDescriptor());
283 dataParce5.WriteString("a");
284 callStatusCallback->OnPostDialNextChar(dataParce5, reply);
285 callStatusCallback->OnReportPostDialDelay(dataParce5, reply);
286
287 MessageParcel dataParce6;
288 dataParce6.WriteInterfaceToken(CallStatusCallbackStub::GetDescriptor());
289 dataParce6.WriteString("123");
290 dataParce6.WriteString("abc");
291 dataParce6.WriteInt32(0);
292 dataParce6.WriteInt32(0);
293 ASSERT_EQ(callStatusCallback->OnUpdateVoipEventInfo(dataParce6, reply), TELEPHONY_SUCCESS);
294 }
295 } // namespace Telephony
296 } // namespace OHOS
297