1 /*
2 * Copyright (C) 2021-2022 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 #include "call_manager_special_mock.h"
17 #include <thread>
18 #include <chrono>
19 #include "call_manager_connect.h"
20 #include "call_voice_assistant_manager.h"
21 #include "spam_call_adapter.h"
22 #include "bluetooth_call_client.h"
23 #include "bluetooth_call_manager.h"
24 #include "bluetooth_call_service.h"
25 #include "bluetooth_connection.h"
26 #include "iremote_broker.h"
27 #include "call_ability_connect_callback.h"
28 #include "call_ability_report_proxy.h"
29 #include "call_connect_ability.h"
30 #include "call_control_manager.h"
31 #include "call_manager_client.h"
32 #include "call_manager_hisysevent.h"
33 #include "call_number_utils.h"
34 #include "call_policy.h"
35 #include "call_records_manager.h"
36 #include "call_request_event_handler_helper.h"
37 #include "call_request_handler.h"
38 #include "call_request_process.h"
39 #include "call_setting_manager.h"
40 #include "call_state_report_proxy.h"
41 #include "call_status_manager.h"
42 #include "cellular_call_connection.h"
43 #include "common_event_manager.h"
44 #include "common_event_support.h"
45 #include "cs_call.h"
46 #include "cs_conference.h"
47 #include "distributed_call_manager.h"
48 #include "gtest/gtest.h"
49 #include "i_voip_call_manager_service.h"
50 #include "ims_call.h"
51 #include "ims_conference.h"
52 #include "incoming_call_notification.h"
53 #include "missed_call_notification.h"
54 #include "ott_call.h"
55 #include "ott_conference.h"
56 #include "reject_call_sms.h"
57 #include "report_call_info_handler.h"
58 #include "satellite_call.h"
59 #include "surface_utils.h"
60 #include "telephony_errors.h"
61 #include "telephony_hisysevent.h"
62 #include "telephony_log_wrapper.h"
63 #include "video_call_state.h"
64 #include "video_control_manager.h"
65 #include "voip_call_manager_proxy.h"
66 #include "voip_call.h"
67 #include "accesstoken_kit.h"
68 #include "token_setproc.h"
69 #include "nativetoken_kit.h"
70 #include "number_identity_data_base_helper.h"
71 #include "call_ability_callback_death_recipient.h"
72 #include "app_state_observer.h"
73 #include "call_ability_callback_proxy.h"
74 #include "super_privacy_manager_client.h"
75 #include "call_status_callback.h"
76 #include "satellite_call_control.h"
77 #include "proximity_sensor.h"
78 #include "status_bar.h"
79 #include "wired_headset.h"
80 #include "call_status_policy.h"
81 #include "call_superprivacy_control_manager.h"
82 #include "bluetooth_hfp_ag.h"
83 #include "call_manager_service.h"
84 #include "telephony_types.h"
85 #include "telephony_permission.h"
86 #include "voip_call_connection.h"
87 #include "number_identity_service.h"
88 #include "bluetooth_call.h"
89 #include "bluetooth_call_connection.h"
90 #include "bluetooth_call_state.h"
91 #include "call_broadcast_subscriber.h"
92 #include "call_incoming_filter_manager.h"
93 #include "call_object_manager.h"
94 #include "call_wired_headset.h"
95 #include "fold_status_manager.h"
96 #include "audio_control_manager.h"
97 #include "call_state_processor.h"
98
99 namespace OHOS {
100 namespace Telephony {
101 using namespace testing::ext;
102
103 class SpecialBranch1Test : public testing::Test {
104 public:
105 static void SetUpTestCase();
106 static void TearDownTestCase();
107 void SetUp();
108 void TearDown();
109 };
110
SetUpTestCase()111 void SpecialBranch1Test::SetUpTestCase()
112 {
113 const char *perms[1] = {
114 "ohos.permission.WRITE_CALL_LOG",
115 };
116 NativeTokenInfoParams infoInstance = {
117 .dcapsNum = 0,
118 .permsNum = 1,
119 .aclsNum = 0,
120 .dcaps = nullptr,
121 .perms = perms,
122 .acls = nullptr,
123 .processName = "SpecialBranch1Test",
124 .aplStr = "system_basic",
125 };
126 uint64_t tokenId = GetAccessTokenId(&infoInstance);
127 SetSelfTokenID(tokenId);
128 auto result = Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo();
129 EXPECT_EQ(result, Security::AccessToken::RET_SUCCESS);
130 }
131
TearDownTestCase()132 void SpecialBranch1Test::TearDownTestCase()
133 {
134 }
135
SetUp()136 void SpecialBranch1Test::SetUp()
137 {
138 }
139
TearDown()140 void SpecialBranch1Test::TearDown()
141 {
142 sleep(1);
143 }
144
145 /**
146 * @tc.number Telephony_CallManagerService_001
147 * @tc.name test branch
148 * @tc.desc Function test
149 */
150 HWTEST_F(SpecialBranch1Test, Telephony_CallManagerService_001, TestSize.Level0)
151 {
152 std::shared_ptr<CallManagerService> callManagerService = std::make_shared<CallManagerService>();
153 ASSERT_TRUE(callManagerService != nullptr);
154 sptr<ICallAbilityCallback> callback;
155 int32_t ret = callManagerService->RegisterCallBack(callback);
156 EXPECT_NE(ret, 0);
157 }
158
159 /**
160 * @tc.number Telephony_CallManagerService_002
161 * @tc.name test branch
162 * @tc.desc Function test
163 */
164 HWTEST_F(SpecialBranch1Test, Telephony_CallManagerService_002, TestSize.Level0)
165 {
166 std::shared_ptr<CallManagerService> callManagerService = std::make_shared<CallManagerService>();
167 ASSERT_TRUE(callManagerService != nullptr);
168 int32_t ret = callManagerService->UnRegisterCallBack();
169 EXPECT_NE(ret, 0);
170 }
171
172 /**
173 * @tc.number Telephony_CallManagerService_003
174 * @tc.name test branch
175 * @tc.desc Function test
176 */
177 HWTEST_F(SpecialBranch1Test, Telephony_CallManagerService_003, TestSize.Level0)
178 {
179 std::shared_ptr<CallManagerService> callManagerService = std::make_shared<CallManagerService>();
180 ASSERT_TRUE(callManagerService != nullptr);
181 int32_t ret = callManagerService->ObserverOnCallDetailsChange();
182 EXPECT_NE(ret, 0);
183 }
184
185 /**
186 * @tc.number Telephony_CallManagerService_004
187 * @tc.name test branch
188 * @tc.desc Function test
189 */
190 HWTEST_F(SpecialBranch1Test, Telephony_CallManagerService_004, TestSize.Level0)
191 {
192 std::shared_ptr<CallManagerService> callManagerService = std::make_shared<CallManagerService>();
193 ASSERT_TRUE(callManagerService != nullptr);
194 CallRestrictionInfo info;
195 int32_t ret = callManagerService->SetCallRestriction(0, info);
196 EXPECT_NE(ret, 0);
197 }
198
199 /**
200 * @tc.number Telephony_CallManagerService_005
201 * @tc.name test branch
202 * @tc.desc Function test
203 */
204 HWTEST_F(SpecialBranch1Test, Telephony_CallManagerService_005, TestSize.Level0)
205 {
206 std::shared_ptr<CallManagerService> callManagerService = std::make_shared<CallManagerService>();
207 ASSERT_TRUE(callManagerService != nullptr);
208 CallTransferInfo info;
209 int32_t ret = callManagerService->SetCallTransferInfo(0, info);
210 EXPECT_NE(ret, 0);
211 }
212
213 /**
214 * @tc.number Telephony_CallManagerService_006
215 * @tc.name test branch
216 * @tc.desc Function test
217 */
218 HWTEST_F(SpecialBranch1Test, Telephony_CallManagerService_006, TestSize.Level0)
219 {
220 std::shared_ptr<CallManagerService> callManagerService = std::make_shared<CallManagerService>();
221 ASSERT_TRUE(callManagerService != nullptr);
222 AudioDevice audioDevice;
223 int32_t ret = callManagerService->SetAudioDevice(audioDevice);
224 EXPECT_NE(ret, 0);
225 }
226
227 /**
228 * @tc.number Telephony_CallManagerService_007
229 * @tc.name test branch
230 * @tc.desc Function test
231 */
232 HWTEST_F(SpecialBranch1Test, Telephony_CallManagerService_007, TestSize.Level0)
233 {
234 std::shared_ptr<CallManagerService> callManagerService = std::make_shared<CallManagerService>();
235 ASSERT_TRUE(callManagerService != nullptr);
236 std::string surfaceId;
237 int32_t ret = callManagerService->SetPreviewWindow(0, surfaceId, nullptr);
238 EXPECT_NE(ret, 0);
239 }
240
241 /**
242 * @tc.number Telephony_CallManagerService_008
243 * @tc.name test branch
244 * @tc.desc Function test
245 */
246 HWTEST_F(SpecialBranch1Test, Telephony_CallManagerService_008, TestSize.Level1)
247 {
248 std::shared_ptr<CallManagerService> callManagerService = std::make_shared<CallManagerService>();
249 ASSERT_TRUE(callManagerService != nullptr);
250 std::string surfaceId;
251 int32_t ret = callManagerService->SetDisplayWindow(0, surfaceId, nullptr);
252 EXPECT_NE(ret, 0);
253 }
254
255 /**
256 * @tc.number Telephony_CallManagerService_009
257 * @tc.name test branch
258 * @tc.desc Function test
259 */
260 HWTEST_F(SpecialBranch1Test, Telephony_CallManagerService_009, TestSize.Level0)
261 {
262 std::shared_ptr<CallManagerService> callManagerService = std::make_shared<CallManagerService>();
263 ASSERT_TRUE(callManagerService != nullptr);
264 std::vector<OttCallDetailsInfo> ottVec;
265 int32_t ret = callManagerService->ReportOttCallDetailsInfo(ottVec);
266 EXPECT_NE(ret, 0);
267 }
268
269 /**
270 * @tc.number Telephony_CallManagerService_010
271 * @tc.name test branch
272 * @tc.desc Function test
273 */
274 HWTEST_F(SpecialBranch1Test, Telephony_CallManagerService_010, TestSize.Level0)
275 {
276 std::shared_ptr<CallManagerService> callManagerService = std::make_shared<CallManagerService>();
277 ASSERT_TRUE(callManagerService != nullptr);
278 OttCallEventInfo eventInfo;
279 int32_t ret = callManagerService->ReportOttCallEventInfo(eventInfo);
280 EXPECT_NE(ret, 0);
281 }
282
283 /**
284 * @tc.number Telephony_SatelliteCall_001
285 * @tc.name test branch
286 * @tc.desc Function test
287 */
288 HWTEST_F(SpecialBranch1Test, Telephony_SatelliteCall_001, TestSize.Level0)
289 {
290 DialParaInfo info;
291 std::shared_ptr<SatelliteCall> satelliteCall = std::make_shared<SatelliteCall>(info);
292 ASSERT_TRUE(satelliteCall != nullptr);
293 satelliteCall->HoldCall();
294 satelliteCall->UnHoldCall();
295 satelliteCall->SwitchCall();
296 satelliteCall->SetMute(0, 0);
297 satelliteCall->CombineConference();
298 satelliteCall->HandleCombineConferenceFailEvent();
299 satelliteCall->SeparateConference();
300 satelliteCall->KickOutFromConference();
301 satelliteCall->CanCombineConference();
302 satelliteCall->CanSeparateConference();
303 satelliteCall->CanKickOutFromConference();
304 satelliteCall->LaunchConference();
305 satelliteCall->ExitConference();
306 satelliteCall->HoldConference();
307 int32_t callId = 0;
308 satelliteCall->GetMainCallId(callId);
309 std::vector<std::u16string> callIdList;
310 satelliteCall->GetSubCallIdList(callIdList);
311 satelliteCall->GetCallIdListForConference(callIdList);
312 int32_t ret = satelliteCall->IsSupportConferenceable();
313 EXPECT_NE(ret, 0);
314 }
315
316 } // namespace Telephony
317 } // namespace OHOS
318