• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 #include <gtest/gtest.h>
16 
17 #include "audio_service_log.h"
18 #include "audio_errors.h"
19 #include "audio_server.h"
20 #include "audio_service.h"
21 #include "system_ability_definition.h"
22 
23 using namespace testing::ext;
24 
25 namespace OHOS {
26 namespace AudioStandard {
27 
28 class AudioServerUnitTest : public testing::Test {
29 public:
30     static void SetUpTestCase(void);
31     static void TearDownTestCase(void);
32     void SetUp();
33     void TearDown();
34 };
35 
36 /**
37  * @tc.name  : Test CreatePlaybackCapturerManager API
38  * @tc.type  : FUNC
39  * @tc.number: CreatePlaybackCapturerManager_001
40  * @tc.desc  : Test CreatePlaybackCapturerManager interface using empty case.
41  */
42 HWTEST(AudioServerUnitTest, CreatePlaybackCapturerManager_001, TestSize.Level1)
43 {
44     AUDIO_INFO_LOG("AudioServerUnitTest CreatePlaybackCapturerManager_001 start");
45     int32_t systemAbilityId = 100;
46     std::shared_ptr<AudioServer> audioServer = std::make_shared<AudioServer>(systemAbilityId, true);
47     bool ret = audioServer->CreatePlaybackCapturerManager();
48     EXPECT_EQ(true, ret);
49 }
50 
51 /**
52  * @tc.name  : Test SetIORoutes API
53  * @tc.type  : FUNC
54  * @tc.number: SetIORoutes_001
55  * @tc.desc  : Test SetIORoutes interface using empty case, when type is DEVICE_TYPE_USB_ARM_HEADSET,
56                 deviceType is DEVICE_TYPE_USB_ARM_HEADSET.
57  */
58 HWTEST(AudioServerUnitTest, SetIORoutes_001, TestSize.Level1)
59 {
60     AUDIO_INFO_LOG("AudioServerUnitTest SetIORoutes_001 start");
61     int32_t systemAbilityId = 100;
62     std::shared_ptr<AudioServer> audioServer = std::make_shared<AudioServer>(systemAbilityId, true);
63     DeviceType type = DEVICE_TYPE_USB_ARM_HEADSET;
64     DeviceFlag flag = ALL_DEVICES_FLAG;
65     std::vector<DeviceType> deviceTypes;
66     DeviceType deviceType = DEVICE_TYPE_USB_ARM_HEADSET;
67     deviceTypes.push_back(deviceType);
68     BluetoothOffloadState a2dpOffloadFlag = A2DP_OFFLOAD;
69     bool ret = audioServer->SetIORoutes(type, flag, deviceTypes, a2dpOffloadFlag);
70     EXPECT_EQ(false, ret);
71 }
72 
73 /**
74  * @tc.name  : Test OnAddSystemAbility API
75  * @tc.type  : FUNC
76  * @tc.number: OnAddSystemAbility_001
77  * @tc.desc  : Test OnAddSystemAbility interface using empty case.
78  */
79 HWTEST(AudioServerUnitTest, OnAddSystemAbility_001, TestSize.Level1)
80 {
81     AUDIO_INFO_LOG("AudioServerUnitTest OnAddSystemAbility_001 start");
82     int32_t systemAbilityId = 100;
83     std::shared_ptr<AudioServer> audioServer = std::make_shared<AudioServer>(systemAbilityId, true);
84     const std::string deviceId = "";
85     audioServer->OnAddSystemAbility(LAST_SYS_ABILITY_ID, deviceId);
86 }
87 
88 /**
89  * @tc.name  : Test InitMaxRendererStreamCntPerUid API
90  * @tc.type  : FUNC
91  * @tc.number: InitMaxRendererStreamCntPerUid_001
92  * @tc.desc  : Test InitMaxRendererStreamCntPerUid interface using empty case.
93  */
94 HWTEST(AudioServerUnitTest, InitMaxRendererStreamCntPerUid_001, TestSize.Level1)
95 {
96     AUDIO_INFO_LOG("AudioServerUnitTest InitMaxRendererStreamCntPerUid_001 start");
97     int32_t systemAbilityId = 100;
98     std::shared_ptr<AudioServer> audioServer = std::make_shared<AudioServer>(systemAbilityId, true);
99     ASSERT_TRUE(audioServer != nullptr);
100     audioServer->InitMaxRendererStreamCntPerUid();
101 }
102 
103 /**
104  * @tc.name  : Test WriteServiceStartupError API
105  * @tc.type  : FUNC
106  * @tc.number: WriteServiceStartupError_001
107  * @tc.desc  : Test WriteServiceStartupError interface using empty case.
108  */
109 HWTEST(AudioServerUnitTest, WriteServiceStartupError_001, TestSize.Level1)
110 {
111     AUDIO_INFO_LOG("AudioServerUnitTest WriteServiceStartupError_001 start");
112     int32_t systemAbilityId = 100;
113     std::shared_ptr<AudioServer> audioServer = std::make_shared<AudioServer>(systemAbilityId, true);
114     ASSERT_TRUE(audioServer != nullptr);
115     audioServer->WriteServiceStartupError();
116 }
117 
118 /**
119  * @tc.name  : Test CheckMaxRendererInstances API
120  * @tc.type  : FUNC
121  * @tc.number: CheckMaxRendererInstances_001
122  * @tc.desc  : Test CheckMaxRendererInstances interface using empty case.
123  */
124 HWTEST(AudioServerUnitTest, CheckMaxRendererInstances_001, TestSize.Level1)
125 {
126     AUDIO_INFO_LOG("AudioServerUnitTest CheckMaxRendererInstances_001 start");
127     int32_t systemAbilityId = 100;
128     std::shared_ptr<AudioServer> audioServer = std::make_shared<AudioServer>(systemAbilityId, true);
129     ASSERT_TRUE(audioServer != nullptr);
130     int32_t ret = audioServer->CheckMaxRendererInstances();
131     EXPECT_EQ(ret, SUCCESS);
132 }
133 
134 /**
135  * @tc.name  : Test CheckMaxRendererInstances API
136  * @tc.type  : FUNC
137  * @tc.number: CheckMaxRendererInstances_002
138  * @tc.desc  : Test CheckMaxRendererInstances interface using empty case.
139  */
140 HWTEST(AudioServerUnitTest, CheckMaxRendererInstances_002, TestSize.Level1)
141 {
142     AUDIO_INFO_LOG("AudioServerUnitTest CheckMaxRendererInstances_002 start");
143     int32_t systemAbilityId = 100;
144     std::shared_ptr<AudioServer> audioServer = std::make_shared<AudioServer>(systemAbilityId, true);
145     ASSERT_TRUE(audioServer != nullptr);
146     AudioService::GetInstance()->currentRendererStreamCnt_ = 128;
147     int32_t ret = audioServer->CheckMaxRendererInstances();
148     EXPECT_EQ(ret, ERR_EXCEED_MAX_STREAM_CNT);
149 }
150 
151 /**
152  * @tc.name  : Test CheckAndWaitAudioPolicyReady API
153  * @tc.type  : FUNC
154  * @tc.number: CheckAndWaitAudioPolicyReady_001
155  * @tc.desc  : Test CheckAndWaitAudioPolicyReady interface using empty case.
156  */
157 HWTEST(AudioServerUnitTest, CheckAndWaitAudioPolicyReady_001, TestSize.Level1)
158 {
159     AUDIO_INFO_LOG("AudioServerUnitTest CheckAndWaitAudioPolicyReady_001 start");
160     int32_t systemAbilityId = 100;
161     std::shared_ptr<AudioServer> audioServer = std::make_shared<AudioServer>(systemAbilityId, true);
162     ASSERT_TRUE(audioServer != nullptr);
163     int32_t ret = audioServer->CheckAndWaitAudioPolicyReady();
164     EXPECT_EQ(ret, SUCCESS);
165 }
166 
167 /**
168  * @tc.name  : Test CheckAndWaitAudioPolicyReady API
169  * @tc.type  : FUNC
170  * @tc.number: CheckAndWaitAudioPolicyReady_002
171  * @tc.desc  : Test CheckAndWaitAudioPolicyReady interface using empty case.
172  */
173 HWTEST(AudioServerUnitTest, CheckAndWaitAudioPolicyReady_002, TestSize.Level1)
174 {
175     AUDIO_INFO_LOG("AudioServerUnitTest CheckAndWaitAudioPolicyReady_002 start");
176     int32_t systemAbilityId = 100;
177     std::shared_ptr<AudioServer> audioServer = std::make_shared<AudioServer>(systemAbilityId, true);
178     ASSERT_TRUE(audioServer != nullptr);
179     audioServer->waitCreateStreamInServerCount_ = 6;
180     int32_t ret = audioServer->CheckAndWaitAudioPolicyReady();
181     EXPECT_EQ(ret, ERR_RETRY_IN_CLIENT);
182 }
183 
184 /**
185  * @tc.name  : Test CheckAndWaitAudioPolicyReady API
186  * @tc.type  : FUNC
187  * @tc.number: CheckAndWaitAudioPolicyReady_003
188  * @tc.desc  : Test CheckAndWaitAudioPolicyReady interface using empty case.
189  */
190 HWTEST(AudioServerUnitTest, CheckAndWaitAudioPolicyReady_003, TestSize.Level1)
191 {
192     AUDIO_INFO_LOG("AudioServerUnitTest CheckAndWaitAudioPolicyReady_003 start");
193     int32_t systemAbilityId = 100;
194     std::shared_ptr<AudioServer> audioServer = std::make_shared<AudioServer>(systemAbilityId, true);
195     ASSERT_TRUE(audioServer != nullptr);
196     audioServer->isAudioPolicyReady_ = true;
197     int32_t ret = audioServer->CheckAndWaitAudioPolicyReady();
198     EXPECT_EQ(ret, SUCCESS);
199 }
200 
201 /**
202  * @tc.name  : Test RegisterAudioCapturerSourceCallback API
203  * @tc.type  : FUNC
204  * @tc.number: RegisterAudioCapturerSourceCallback_001
205  * @tc.desc  : Test RegisterAudioCapturerSourceCallback interface using empty case.
206  */
207 HWTEST(AudioServerUnitTest, RegisterAudioCapturerSourceCallback_001, TestSize.Level1)
208 {
209     AUDIO_INFO_LOG("AudioServerUnitTest RegisterAudioCapturerSourceCallback_001 start");
210     int32_t systemAbilityId = 100;
211     std::shared_ptr<AudioServer> audioServer = std::make_shared<AudioServer>(systemAbilityId, true);
212     ASSERT_TRUE(audioServer != nullptr);
213     audioServer->RegisterAudioCapturerSourceCallback();
214 }
215 
216 /**
217  * @tc.name  : Test RegisterAudioRendererSinkCallback API
218  * @tc.type  : FUNC
219  * @tc.number: RegisterAudioRendererSinkCallback_001
220  * @tc.desc  : Test RegisterAudioRendererSinkCallback interface using empty case.
221  */
222 HWTEST(AudioServerUnitTest, RegisterAudioRendererSinkCallback_001, TestSize.Level1)
223 {
224     AUDIO_INFO_LOG("AudioServerUnitTest RegisterAudioRendererSinkCallback_001 start");
225     int32_t systemAbilityId = 100;
226     std::shared_ptr<AudioServer> audioServer = std::make_shared<AudioServer>(systemAbilityId, true);
227     ASSERT_TRUE(audioServer != nullptr);
228     audioServer->RegisterAudioRendererSinkCallback();
229 }
230 
231 /**
232  * @tc.name  : Test OnRenderSinkStateChange API
233  * @tc.type  : FUNC
234  * @tc.number: OnRenderSinkStateChange_001
235  * @tc.desc  : Test OnRenderSinkStateChange interface using empty case.
236  */
237 HWTEST(AudioServerUnitTest, OnRenderSinkStateChange_001, TestSize.Level1)
238 {
239     AUDIO_INFO_LOG("AudioServerUnitTest OnRenderSinkStateChange_001 start");
240     int32_t systemAbilityId = 100;
241     std::shared_ptr<AudioServer> audioServer = std::make_shared<AudioServer>(systemAbilityId, true);
242     ASSERT_TRUE(audioServer != nullptr);
243     uint32_t sinkId = 1;
244     bool started = true;
245     audioServer->OnRenderSinkStateChange(sinkId, started);
246 }
247 
248 /**
249  * @tc.name  : Test CheckHibernateState API
250  * @tc.type  : FUNC
251  * @tc.number: CheckHibernateState_001
252  * @tc.desc  : Test CheckHibernateState interface using empty case.
253  */
254 HWTEST(AudioServerUnitTest, CheckHibernateState_001, TestSize.Level1)
255 {
256     AUDIO_INFO_LOG("AudioServerUnitTest CheckHibernateState_001 start");
257     int32_t systemAbilityId = 100;
258     std::shared_ptr<AudioServer> audioServer = std::make_shared<AudioServer>(systemAbilityId, true);
259     ASSERT_TRUE(audioServer != nullptr);
260     bool hibernate = true;
261     audioServer->CheckHibernateState(hibernate);
262 }
263 
264 /**
265  * @tc.name  : Test CreateIpcOfflineStream API
266  * @tc.type  : FUNC
267  * @tc.number: CreateIpcOfflineStream_001
268  * @tc.desc  : Test CreateIpcOfflineStream interface using empty case.
269  */
270 HWTEST(AudioServerUnitTest, CreateIpcOfflineStream_001, TestSize.Level1)
271 {
272     AUDIO_INFO_LOG("AudioServerUnitTest CreateIpcOfflineStream_001 start");
273     int32_t systemAbilityId = 100;
274     std::shared_ptr<AudioServer> audioServer = std::make_shared<AudioServer>(systemAbilityId, true);
275     ASSERT_TRUE(audioServer != nullptr);
276     int32_t errorCode = 0;
277     sptr<IRemoteObject> obj = audioServer->CreateIpcOfflineStream(errorCode);
278     EXPECT_NE(obj, nullptr);
279 }
280 
281 /**
282  * @tc.name  : Test GetOfflineAudioEffectChains API
283  * @tc.type  : FUNC
284  * @tc.number: GetOfflineAudioEffectChains_001
285  * @tc.desc  : Test GetOfflineAudioEffectChains interface using empty case.
286  */
287 HWTEST(AudioServerUnitTest, GetOfflineAudioEffectChains_001, TestSize.Level1)
288 {
289     AUDIO_INFO_LOG("AudioServerUnitTest GetOfflineAudioEffectChains_001 start");
290     int32_t systemAbilityId = 100;
291     std::shared_ptr<AudioServer> audioServer = std::make_shared<AudioServer>(systemAbilityId, true);
292     ASSERT_TRUE(audioServer != nullptr);
293     std::vector<std::string> effectChains = {};
294     int32_t ret = audioServer->GetOfflineAudioEffectChains(effectChains);
295     EXPECT_EQ(ret, SUCCESS);
296 }
297 
298 /**
299  * @tc.name  : Test GenerateSessionId API
300  * @tc.type  : FUNC
301  * @tc.number: GenerateSessionId_001
302  * @tc.desc  : Test GenerateSessionId interface using empty case.
303  */
304 HWTEST(AudioServerUnitTest, GenerateSessionId_001, TestSize.Level1)
305 {
306     AUDIO_INFO_LOG("AudioServerUnitTest GenerateSessionId_001 start");
307     int32_t systemAbilityId = 100;
308     std::shared_ptr<AudioServer> audioServer = std::make_shared<AudioServer>(systemAbilityId, true);
309     ASSERT_TRUE(audioServer != nullptr);
310     uint32_t sessionId = 1;
311     int32_t ret = audioServer->GenerateSessionId(sessionId);
312     EXPECT_EQ(ret, ERROR);
313 }
314 
315 /**
316  * @tc.name  : Test GetAllSinkInputs API
317  * @tc.type  : FUNC
318  * @tc.number: GetAllSinkInputs_001
319  * @tc.desc  : Test GetAllSinkInputs interface using empty case.
320  */
321 HWTEST(AudioServerUnitTest, GetAllSinkInputs_001, TestSize.Level1)
322 {
323     AUDIO_INFO_LOG("AudioServerUnitTest GetAllSinkInputs_001 start");
324     int32_t systemAbilityId = 100;
325     std::shared_ptr<AudioServer> audioServer = std::make_shared<AudioServer>(systemAbilityId, true);
326     ASSERT_TRUE(audioServer != nullptr);
327     std::vector<SinkInput> sinkInputs = {};
328     audioServer->GetAllSinkInputs(sinkInputs);
329 }
330 
331 /**
332  * @tc.name  : Test NotifyAudioPolicyReady API
333  * @tc.type  : FUNC
334  * @tc.number: NotifyAudioPolicyReady_001
335  * @tc.desc  : Test NotifyAudioPolicyReady interface using empty case.
336  */
337 HWTEST(AudioServerUnitTest, NotifyAudioPolicyReady_001, TestSize.Level1)
338 {
339     AUDIO_INFO_LOG("AudioServerUnitTest NotifyAudioPolicyReady_001 start");
340     int32_t systemAbilityId = 100;
341     std::shared_ptr<AudioServer> audioServer = std::make_shared<AudioServer>(systemAbilityId, true);
342     ASSERT_TRUE(audioServer != nullptr);
343     audioServer->NotifyAudioPolicyReady();
344 }
345 
346 /**
347  * @tc.name  : Test CheckCaptureLimit API
348  * @tc.type  : FUNC
349  * @tc.number: CheckCaptureLimit_001
350  * @tc.desc  : Test CheckCaptureLimit interface using empty case.
351  */
352 #ifdef HAS_FEATURE_INNERCAPTURER
353 HWTEST(AudioServerUnitTest, CheckCaptureLimit_001, TestSize.Level1)
354 {
355     AUDIO_INFO_LOG("AudioServerUnitTest CheckCaptureLimit_001 start");
356     int32_t systemAbilityId = 100;
357     std::shared_ptr<AudioServer> audioServer = std::make_shared<AudioServer>(systemAbilityId, true);
358     ASSERT_TRUE(audioServer != nullptr);
359     AudioPlaybackCaptureConfig config;
360     int32_t innerCapId = 0;
361     int32_t ret = audioServer->CheckCaptureLimit(config, innerCapId);
362     EXPECT_EQ(ret, SUCCESS);
363 }
364 
365 /**
366  * @tc.name  : Test SetInnerCapLimit API
367  * @tc.type  : FUNC
368  * @tc.number: SetInnerCapLimit_001
369  * @tc.desc  : Test SetInnerCapLimit interface using empty case.
370  */
371 HWTEST(AudioServerUnitTest, SetInnerCapLimit_001, TestSize.Level1)
372 {
373     AUDIO_INFO_LOG("AudioServerUnitTest SetInnerCapLimit_001 start");
374     int32_t systemAbilityId = 100;
375     std::shared_ptr<AudioServer> audioServer = std::make_shared<AudioServer>(systemAbilityId, true);
376     ASSERT_TRUE(audioServer != nullptr);
377     int32_t innerCapId = 0;
378     int32_t ret = audioServer->SetInnerCapLimit(innerCapId);
379     EXPECT_EQ(ret, SUCCESS);
380 }
381 
382 /**
383  * @tc.name  : Test ReleaseCaptureLimit API
384  * @tc.type  : FUNC
385  * @tc.number: ReleaseCaptureLimit_001
386  * @tc.desc  : Test ReleaseCaptureLimit interface using empty case.
387  */
388 HWTEST(AudioServerUnitTest, ReleaseCaptureLimit_001, TestSize.Level1)
389 {
390     AUDIO_INFO_LOG("AudioServerUnitTest ReleaseCaptureLimit_001 start");
391     int32_t systemAbilityId = 100;
392     std::shared_ptr<AudioServer> audioServer = std::make_shared<AudioServer>(systemAbilityId, true);
393     ASSERT_TRUE(audioServer != nullptr);
394     int32_t innerCapId = 0;
395     int32_t ret = audioServer->ReleaseCaptureLimit(innerCapId);
396     EXPECT_EQ(ret, SUCCESS);
397 }
398 #endif
399 
400 /**
401  * @tc.name  : Test LoadHdiAdapter API
402  * @tc.type  : FUNC
403  * @tc.number: LoadHdiAdapter_001
404  * @tc.desc  : Test LoadHdiAdapter interface using empty case.
405  */
406 HWTEST(AudioServerUnitTest, LoadHdiAdapter_001, TestSize.Level1)
407 {
408     AUDIO_INFO_LOG("AudioServerUnitTest LoadHdiAdapter_001 start");
409     int32_t systemAbilityId = 100;
410     std::shared_ptr<AudioServer> audioServer = std::make_shared<AudioServer>(systemAbilityId, true);
411     ASSERT_TRUE(audioServer != nullptr);
412     uint32_t devMgrType = 0;
413     std::string adapterName = "test";
414     int32_t ret = audioServer->LoadHdiAdapter(devMgrType, adapterName);
415     EXPECT_NE(ret, SUCCESS);
416 }
417 
418 /**
419  * @tc.name  : Test UnloadHdiAdapter API
420  * @tc.type  : FUNC
421  * @tc.number: UnloadHdiAdapter_001
422  * @tc.desc  : Test UnloadHdiAdapter interface using empty case.
423  */
424 HWTEST(AudioServerUnitTest, UnloadHdiAdapter_001, TestSize.Level1)
425 {
426     AUDIO_INFO_LOG("AudioServerUnitTest UnloadHdiAdapter_001 start");
427     int32_t systemAbilityId = 100;
428     std::shared_ptr<AudioServer> audioServer = std::make_shared<AudioServer>(systemAbilityId, true);
429     ASSERT_TRUE(audioServer != nullptr);
430     uint32_t devMgrType = 0;
431     const std::string adapterName = "test";
432     bool force = false;
433     audioServer->UnloadHdiAdapter(devMgrType, adapterName, force);
434 }
435 } // namespace AudioStandard
436 } //