• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-2025 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 <cstdint>
17 #include <thread>
18 #include <gtest/gtest.h>
19 #include "gmock/gmock.h"
20 #include "audio_utils.h"
21 #include "parameter.h"
22 #include "audio_channel_blend.h"
23 #include "volume_ramp.h"
24 #include "audio_speed.h"
25 #include "audio_errors.h"
26 #include "audio_scope_exit.h"
27 #include "audio_safe_block_queue.h"
28 
29 using namespace testing::ext;
30 using namespace testing;
31 using namespace std;
32 namespace OHOS {
33 namespace AudioStandard {
34 
35 constexpr unsigned int QUEUE_SLOTS = 10;
36 constexpr unsigned int THREAD_NUM = QUEUE_SLOTS + 1;
37 
38 class MockExe {
39 public:
40     MOCK_METHOD(void, Exe, ());
41 };
42 
43 class AudioUtilsUnitTest : public testing::Test {
44 public:
45     static void SetUpTestCase(void);
46     static void TearDownTestCase(void);
47     void SetUp();
48     void TearDown();
49 };
50 
SetUpTestCase(void)51 void AudioUtilsUnitTest::SetUpTestCase(void)
52 {
53     // input testsuit setup step,setup invoked before all testcases
54 }
55 
TearDownTestCase(void)56 void AudioUtilsUnitTest::TearDownTestCase(void)
57 {
58     // input testsuit teardown step,teardown invoked after all testcases
59 }
60 
SetUp(void)61 void AudioUtilsUnitTest::SetUp(void)
62 {
63     // input testcase setup step,setup invoked before each testcases
64 }
65 
TearDown(void)66 void AudioUtilsUnitTest::TearDown(void)
67 {
68     // input testcase teardown step,teardown invoked after each testcases
69 }
70 
71 /**
72 * @tc.name  : Test ClockTime API
73 * @tc.type  : FUNC
74 * @tc.number: ClockTime_001
75 * @tc.desc  : Test ClockTime interface.
76 */
77 HWTEST(AudioUtilsUnitTest, ClockTime_001, TestSize.Level1)
78 {
79     const int64_t CLOCK_TIME = 0;
80     int32_t ret = -1;
81     ret = ClockTime::AbsoluteSleep(CLOCK_TIME);
82     EXPECT_EQ(SUCCESS - 1, ret);
83 
84     int64_t nanoTime = 1000;
85     ret = ClockTime::AbsoluteSleep(nanoTime);
86     EXPECT_EQ(SUCCESS, ret);
87 
88     ret = ClockTime::RelativeSleep(CLOCK_TIME);
89     EXPECT_EQ(SUCCESS - 1, ret);
90 
91     ret = ClockTime::RelativeSleep(nanoTime);
92     EXPECT_EQ(SUCCESS, ret);
93 }
94 
95 /**
96 * @tc.name  : Test Trace API
97 * @tc.type  : FUNC
98 * @tc.number: Trace_001
99 * @tc.desc  : Test Trace interface.
100 */
101 HWTEST(AudioUtilsUnitTest, Trace_001, TestSize.Level1)
102 {
103     std::string value = "Test";
104     std::shared_ptr<Trace> trace = std::make_shared<Trace>(value);
105     trace->End();
106     int64_t count = 1;
107     Trace::Count(value, count);
108 }
109 
110 /**
111 * @tc.name  : Test PermissionUtil API
112 * @tc.type  : FUNC
113 * @tc.number: PermissionUtil_001
114 * @tc.desc  : Test PermissionUtil interface.
115 */
116 HWTEST(AudioUtilsUnitTest, PermissionUtil_001, TestSize.Level1)
117 {
118     bool ret1 = PermissionUtil::VerifyIsSystemApp();
119     EXPECT_EQ(true, ret1);
120     bool ret2 = PermissionUtil::VerifySelfPermission();
121     EXPECT_EQ(true, ret2);
122     bool ret3 = PermissionUtil::VerifySystemPermission();
123     EXPECT_EQ(true, ret3);
124 }
125 
126 /**
127 * @tc.name  : Test AdjustStereoToMonoForPCM API
128 * @tc.type  : FUNC
129 * @tc.number: AdjustStereoToMonoForPCM_001
130 * @tc.desc  : Test AdjustStereoToMonoForPCM interface.
131 */
132 HWTEST(AudioUtilsUnitTest, AdjustStereoToMonoForPCM_001, TestSize.Level1)
133 {
134     uint64_t len = 2;
135 
136     const int8_t BitRET = 1;
137     int8_t arr1[2] = {1, 2};
138     int8_t *data1 = &arr1[0];
139     AdjustStereoToMonoForPCM8Bit(data1, len);
140     EXPECT_EQ(BitRET, data1[0]);
141     EXPECT_EQ(BitRET, data1[1]);
142 
143     len = 4;
144     const int16_t Bit16RET = 1;
145     int16_t arr2[2] = {1, 2};
146     int16_t *data2 = &arr2[0];
147     AdjustStereoToMonoForPCM16Bit(data2, len);
148     EXPECT_EQ(Bit16RET, data2[0]);
149     EXPECT_EQ(Bit16RET, data2[1]);
150 
151     len = 8;
152     const int32_t Bit32RET = 1;
153     int32_t arr4[2] = {1, 2};
154     int32_t *data4 = &arr4[0];
155     AdjustStereoToMonoForPCM32Bit(data4, len);
156     EXPECT_EQ(Bit32RET, data4[0]);
157     EXPECT_EQ(Bit32RET, data4[1]);
158 }
159 
160 /**
161 * @tc.name  : Test AdjustAudioBalanceForPCM API
162 * @tc.type  : FUNC
163 * @tc.number: AdjustAudioBalanceForPCM_001
164 * @tc.desc  : Test AdjustAudioBalanceForPCM interface.
165 */
166 HWTEST(AudioUtilsUnitTest, AdjustAudioBalanceForPCM_001, TestSize.Level1)
167 {
168     float left = 2.0;
169     float right = 2.0;
170     uint64_t len = 2;
171 
172     const int8_t Bit8RET1 = 2;
173     const int8_t Bit8RET2 = 4;
174     int8_t arr1[2] = {1, 2};
175     int8_t *data1 = &arr1[0];
176     AdjustAudioBalanceForPCM8Bit(data1, len, left, right);
177     EXPECT_EQ(Bit8RET1, data1[0]);
178     EXPECT_EQ(Bit8RET2, data1[1]);
179 
180     len = 4;
181     const int16_t Bit16RET1 = 2;
182     const int16_t Bit16RET2 = 4;
183     int16_t arr2[2] = {1, 2};
184     int16_t *data2 = &arr2[0];
185     AdjustAudioBalanceForPCM16Bit(data2, len, left, right);
186     EXPECT_EQ(Bit16RET1, data2[0]);
187     EXPECT_EQ(Bit16RET2, data2[1]);
188 
189     len = 8;
190     const int32_t Bit32RET = 2;
191     int32_t arr4[2] = {1, 2};
192     int32_t *data4 = &arr4[0];
193     AdjustAudioBalanceForPCM32Bit(data4, len, left, right);
194     EXPECT_EQ(Bit32RET, data4[0]);
195     EXPECT_EQ(Bit32RET * 2, data4[1]);
196 }
197 
198 /**
199 * @tc.name  : Test GetSysPara API
200 * @tc.type  : FUNC
201 * @tc.number: GetSysPara_001
202 * @tc.desc  : Test GetSysPara interface.
203 */
204 HWTEST(AudioUtilsUnitTest, GetSysPara_001, TestSize.Level1)
205 {
206     const char *invaildKey = nullptr;
207     int32_t value32 = 2;
208     bool result = GetSysPara(invaildKey, value32);
209     EXPECT_EQ(false, result);
210     const char *key = "debug.audio_service.testmodeon";
211     bool result1 = GetSysPara(key, value32);
212     EXPECT_EQ(true, result1);
213     uint32_t valueU32 = 3;
214     bool result2 = GetSysPara(key, valueU32);
215     EXPECT_EQ(true, result2);
216     int64_t value64 = 0;
217     bool result3 = GetSysPara(key, value64);
218     EXPECT_EQ(true, result3);
219     std::string strValue = "100";
220     bool result4 = GetSysPara(key, strValue);
221     EXPECT_EQ(true, result4);
222 }
223 
224 /**
225 * @tc.name  : Test UpdateMaxAmplitude API
226 * @tc.type  : FUNC
227 * @tc.number: UpdateMaxAmplitude_001
228 * @tc.desc  : Test UpdateMaxAmplitude interface  when adapterFormat is SAMPLE_U8_C.
229 */
230 HWTEST(AudioUtilsUnitTest, UpdateMaxAmplitude_001, TestSize.Level0)
231 {
232     ConvertHdiFormat adapterFormat = SAMPLE_U8_C;
233     char frame[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
234     uint64_t replyBytes = 10;
235     float result = UpdateMaxAmplitude(adapterFormat, frame, replyBytes);
236     EXPECT_NEAR(result, 0.071, 0.001);
237 }
238 
239 /**
240 * @tc.name  : Test UpdateMaxAmplitude API
241 * @tc.type  : FUNC
242 * @tc.number: UpdateMaxAmplitude_002
243 * @tc.desc  : Test UpdateMaxAmplitude interface  when adapterFormat is SAMPLE_S16_C.
244 */
245 HWTEST(AudioUtilsUnitTest, UpdateMaxAmplitude_002, TestSize.Level0)
246 {
247     ConvertHdiFormat adapterFormat = SAMPLE_S16_C;
248     char frame[20] = {0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9};
249     uint64_t replyBytes = 10;
250     float result = UpdateMaxAmplitude(adapterFormat, frame, replyBytes);
251     EXPECT_NEAR(result, 0.032, 0.001);
252 }
253 
254 /**
255 * @tc.name  : Test UpdateMaxAmplitude API
256 * @tc.type  : FUNC
257 * @tc.number: UpdateMaxAmplitude_003
258 * @tc.desc  : Test UpdateMaxAmplitude interface  when adapterFormat is SAMPLE_S24_C.
259 */
260 HWTEST(AudioUtilsUnitTest, UpdateMaxAmplitude_003, TestSize.Level0)
261 {
262     ConvertHdiFormat adapterFormat = SAMPLE_S24_C;
263     char frame[30] = {0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4,
264                      5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9};
265     uint64_t replyBytes = 10;
266     float result = UpdateMaxAmplitude(adapterFormat, frame, replyBytes);
267     EXPECT_NEAR(result, 0.016, 0.001);
268 }
269 
270 /**
271 * @tc.name  : Test UpdateMaxAmplitude API
272 * @tc.type  : FUNC
273 * @tc.number: UpdateMaxAmplitude_004
274 * @tc.desc  : Test UpdateMaxAmplitude interface  when adapterFormat is SAMPLE_S32_C.
275 */
276 HWTEST(AudioUtilsUnitTest, UpdateMaxAmplitude_004, TestSize.Level0)
277 {
278     ConvertHdiFormat adapterFormat = SAMPLE_S32_C;
279     char frame[40] = {0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4,
280                     5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9};
281     uint64_t replyBytes = 10;
282     float result = UpdateMaxAmplitude(adapterFormat, frame, replyBytes);
283     EXPECT_NEAR(result, 0, 0.1);
284 }
285 
286 /**
287 * @tc.name  : Test UpdateMaxAmplitude API
288 * @tc.type  : FUNC
289 * @tc.number: UpdateMaxAmplitude_005
290 * @tc.desc  : Test UpdateMaxAmplitude interface when adapterFormat is not supported then AUDIO_INFO_LOG is called
291 */
292 HWTEST(AudioUtilsUnitTest, UpdateMaxAmplitude_005, TestSize.Level0)
293 {
294     ConvertHdiFormat adapterFormat = INVALID_WIDTH_C;
295     char frame[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
296     uint64_t replyBytes = 10;
297     float result = UpdateMaxAmplitude(adapterFormat, frame, replyBytes);
298     EXPECT_EQ(result, 0);
299 }
300 
301 /**
302 * @tc.name  : Test CalculateMaxAmplitudeForPCM8Bit API
303 * @tc.type  : FUNC
304 * @tc.number: CalculateMaxAmplitudeForPCM8Bit_001
305 * @tc.desc  : Test CalculateMaxAmplitudeForPCM8Bit interface Return 0 when frame is null arry
306 */
307 HWTEST(AudioUtilsUnitTest, CalculateMaxAmplitudeForPCM8Bit_001, TestSize.Level0)
308 {
309     int8_t frame[0];
310     uint64_t nSamples = 0;
311     float result = CalculateMaxAmplitudeForPCM8Bit(frame, nSamples);
312     EXPECT_EQ(result, 0);
313 }
314 
315 /**
316 * @tc.name  : Test CalculateMaxAmplitudeForPCM8Bit API
317 * @tc.type  : FUNC
318 * @tc.number: CalculateMaxAmplitudeForPCM8Bit_002
319 * @tc.desc  : Test CalculateMaxAmplitudeForPCM8Bit interface Return 0 when nSamples is 0
320 */
321 HWTEST(AudioUtilsUnitTest, CalculateMaxAmplitudeForPCM8Bit_002, TestSize.Level0)
322 {
323     int8_t frame1[1] = {1};
324     uint64_t nSamples1 = 0;
325     float result = CalculateMaxAmplitudeForPCM8Bit(frame1, nSamples1);
326     EXPECT_EQ(result, 0);
327 }
328 
329 /**
330 * @tc.name  : Test CalculateMaxAmplitudeForPCM8Bit API
331 * @tc.type  : FUNC
332 * @tc.number: CalculateMaxAmplitudeForPCM8Bit_003
333 * @tc.desc  : Test CalculateMaxAmplitudeForPCM8Bit interface
334 *             Return MaxAmplitude when frame is not null arry and nSamples is not 0
335 */
336 HWTEST(AudioUtilsUnitTest, CalculateMaxAmplitudeForPCM8Bit_003, TestSize.Level0)
337 {
338     int8_t frame2[3] = {1, -2, 3};
339     uint64_t nSamples2 = 3;
340     float result = CalculateMaxAmplitudeForPCM8Bit(frame2, nSamples2);
341     EXPECT_FLOAT_EQ(result, 3.0f/ SCHAR_MAX);
342 }
343 
344 /**
345 * @tc.name  : Test CalculateMaxAmplitudeForPCM16Bit API
346 * @tc.type  : FUNC
347 * @tc.number: CalculateMaxAmplitudeForPCM16Bit_001
348 * @tc.desc  : Test CalculateMaxAmplitudeForPCM16Bit interface .Return 0 when  nSamples is 0
349 */
350 HWTEST(AudioUtilsUnitTest, CalculateMaxAmplitudeForPCM16Bit_001, TestSize.Level0)
351 {
352     int16_t frame[1] = {100};
353     uint64_t nSamples = 0;
354     float result = CalculateMaxAmplitudeForPCM16Bit(frame, nSamples);
355     EXPECT_EQ(result, 0);
356 }
357 
358 /**
359 * @tc.name  : Test CalculateMaxAmplitudeForPCM16Bit API
360 * @tc.type  : FUNC
361 * @tc.number: CalculateMaxAmplitudeForPCM16Bit_002
362 * @tc.desc  : Test CalculateMaxAmplitudeForPCM16Bit interface .Return 1.0 when value < 0
363 */
364 HWTEST(AudioUtilsUnitTest, CalculateMaxAmplitudeForPCM16Bit_002, TestSize.Level0)
365 {
366     int16_t frame[5] = {-6554, -8192, -10923, -16384, -32767};;
367     uint64_t nSamples = 5;
368     float result = CalculateMaxAmplitudeForPCM16Bit(frame, nSamples);
369     EXPECT_NEAR(result, 1.0, 0.1);
370 }
371 
372 /**
373 * @tc.name  : Test CalculateMaxAmplitudeForPCM16Bit API
374 * @tc.type  : FUNC
375 * @tc.number: CalculateMaxAmplitudeForPCM16Bit_003
376 * @tc.desc  : Test CalculateMaxAmplitudeForPCM16Bit interface .update curMaxAmplitude when curMaxAmplitude < value
377 */
378 HWTEST(AudioUtilsUnitTest, CalculateMaxAmplitudeForPCM16Bit_003, TestSize.Level0)
379 {
380     int16_t frame[5] = {6554, 8192, 10923, 16384, 32767};;
381     uint64_t nSamples = 5;
382     float result = CalculateMaxAmplitudeForPCM16Bit(frame, nSamples);
383     EXPECT_NEAR(result, 1.0, 0.001);
384 }
385 
386 /**
387 * @tc.name  : Test CalculateMaxAmplitudeForPCM16Bit API
388 * @tc.type  : FUNC
389 * @tc.number: CalculateMaxAmplitudeForPCM16Bit_004
390 * @tc.desc  : Test CalculateMaxAmplitudeForPCM16Bit interface
391 *               when value isn't bigger than curMaxAmplitude and smaller than 0.
392 */
393 HWTEST(AudioUtilsUnitTest, CalculateMaxAmplitudeForPCM16Bit_004, TestSize.Level0)
394 {
395     int16_t frame[5] = {0};;
396     uint64_t nSamples = 5;
397     float result = CalculateMaxAmplitudeForPCM16Bit(frame, nSamples);
398     EXPECT_EQ(result, 0);
399 }
400 
401 /**
402 * @tc.name  : Test CalculateMaxAmplitudeForPCM16Bit API
403 * @tc.type  : FUNC
404 * @tc.number: CalculateMaxAmplitudeForPCM16Bit_005
405 * @tc.desc  : Test CalculateMaxAmplitudeForPCM16Bit interface when value contains  negative and positive numbers.
406 */
407 HWTEST(AudioUtilsUnitTest, CalculateMaxAmplitudeForPCM16Bit_005, TestSize.Level0)
408 {
409     int16_t frame[5] = {-6554, -8192, 0, 10923, 16384};
410     uint64_t nSamples = 5;
411     float result = CalculateMaxAmplitudeForPCM16Bit(frame, nSamples);
412     EXPECT_NEAR(result, 0.5, 0.1);
413 }
414 
415 /**
416 * @tc.name  : Test CalculateMaxAmplitudeForPCM24Bit API
417 * @tc.type  : FUNC
418 * @tc.number: CalculateMaxAmplitudeForPCM24Bit_001
419 * @tc.desc  : Test CalculateMaxAmplitudeForPCM24Bit interface .Return 0 when  nSamples is 0
420 */
421 HWTEST(AudioUtilsUnitTest, CalculateMaxAmplitudeForPCM24Bit_001, TestSize.Level0)
422 {
423     char frame[1] = {100};
424     uint64_t nSamples = 0;
425     float result = CalculateMaxAmplitudeForPCM24Bit(frame, nSamples);
426     EXPECT_EQ(result, 0);
427 }
428 
429 /**
430 * @tc.name  : Test CalculateMaxAmplitudeForPCM24Bit API
431 * @tc.type  : FUNC
432 * @tc.number: CalculateMaxAmplitudeForPCM24Bit_002
433 * @tc.desc  : Test CalculateMaxAmplitudeForPCM24Bit interface .Return 1.0 when value < 0
434 */
435 HWTEST(AudioUtilsUnitTest, CalculateMaxAmplitudeForPCM24Bit_002, TestSize.Level0)
436 {
437     char frame[15] = {0xC0, 0x00, 0x00, 0xE0, 0x00, 0x00, 0xF0, 0x00, 0x00, 0xF8, 0x00, 0x00, 0xF4, 0x00, 0x00};
438 
439     uint64_t nSamples = 5;
440     float result = CalculateMaxAmplitudeForPCM24Bit(frame, nSamples);
441     EXPECT_NEAR(result, 3.0e-05, 0.1e-05);
442 }
443 
444 /**
445 * @tc.name  : Test CalculateMaxAmplitudeForPCM24Bit API
446 * @tc.type  : FUNC
447 * @tc.number: CalculateMaxAmplitudeForPCM24Bit_003
448 * @tc.desc  : Test CalculateMaxAmplitudeForPCM24Bit interface .update curMaxAmplitude when curMaxAmplitude < value
449 */
450 HWTEST(AudioUtilsUnitTest, CalculateMaxAmplitudeForPCM24Bit_003, TestSize.Level0)
451 {
452     char frame[15] = {0x40, 0x00, 0x00, 0x20, 0x00, 0x00, 0x10, 0x00, 0x00, 0x08, 0x00, 0x00, 0x04, 0x00, 0x00};
453     uint64_t nSamples = 5;
454     float result = CalculateMaxAmplitudeForPCM24Bit(frame, nSamples);
455     EXPECT_NEAR(result, 0.76e-05, 0.1e-05);
456 }
457 
458 /**
459 * @tc.name  : Test CalculateMaxAmplitudeForPCM24Bit API
460 * @tc.type  : FUNC
461 * @tc.number: CalculateMaxAmplitudeForPCM24Bit_004
462 * @tc.desc  : Test CalculateMaxAmplitudeForPCM24Bit interface
463 *               when value isn't bigger than curMaxAmplitude and smaller than 0.
464 */
465 HWTEST(AudioUtilsUnitTest, CalculateMaxAmplitudeForPCM24Bit_004, TestSize.Level0)
466 {
467     char frame[3] = {0x00, 0x00, 0x00};
468     uint64_t nSamples = 1;
469     float result = CalculateMaxAmplitudeForPCM24Bit(frame, nSamples);
470     EXPECT_NEAR(result, 0, 0.1);
471 }
472 
473 /**
474 * @tc.name  : Test CalculateMaxAmplitudeForPCM24Bit API
475 * @tc.type  : FUNC
476 * @tc.number: CalculateMaxAmplitudeForPCM24Bit_005
477 * @tc.desc  : Test CalculateMaxAmplitudeForPCM24Bit interface when value contains  negative and positive numbers.
478 */
479 HWTEST(AudioUtilsUnitTest, CalculateMaxAmplitudeForPCM24Bit_005, TestSize.Level0)
480 {
481     char frame[15] = {0xC0, 0x00, 0x00, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x40, 0x00, 0x00};
482     uint64_t nSamples = 5;
483     float result = CalculateMaxAmplitudeForPCM24Bit(frame, nSamples);
484     EXPECT_NEAR(result,  2.7e-05, 0.1e-05);
485 }
486 
487 /**
488 * @tc.name  : Test CalculateMaxAmplitudeForPCM32Bit API
489 * @tc.type  : FUNC
490 * @tc.number: CalculateMaxAmplitudeForPCM32Bit_001
491 * @tc.desc  : Test CalculateMaxAmplitudeForPCM32Bit interface .Return 0 when  nSamples is 0
492 */
493 HWTEST(AudioUtilsUnitTest, CalculateMaxAmplitudeForPCM32Bit_001, TestSize.Level0)
494 {
495     int32_t frame[1] = {100};
496     uint64_t nSamples = 0;
497     float result = CalculateMaxAmplitudeForPCM32Bit(frame, nSamples);
498     EXPECT_EQ(result, 0);
499 }
500 
501 /**
502 * @tc.name  : Test CalculateMaxAmplitudeForPCM32Bit API
503 * @tc.type  : FUNC
504 * @tc.number: CalculateMaxAmplitudeForPCM32Bit_002
505 * @tc.desc  : Test CalculateMaxAmplitudeForPCM32Bit interface .Return 1.0 when value < 0
506 */
507 HWTEST(AudioUtilsUnitTest, CalculateMaxAmplitudeForPCM32Bit_002, TestSize.Level0)
508 {
509     int32_t frame[4] = {-1, 1, 0, 8};
510     uint64_t nSamples = 4;
511     float result = CalculateMaxAmplitudeForPCM32Bit(frame, nSamples);
512     EXPECT_NEAR(result, 0, 0.0001);
513 }
514 
515 /**
516 * @tc.name  : Test CalculateMaxAmplitudeForPCM32Bit API
517 * @tc.type  : FUNC
518 * @tc.number: CalculateMaxAmplitudeForPCM32Bit_003
519 * @tc.desc  : Test CalculateMaxAmplitudeForPCM32Bit interface .update curMaxAmplitude when curMaxAmplitude < value
520 */
521 HWTEST(AudioUtilsUnitTest, CalculateMaxAmplitudeForPCM32Bit_003, TestSize.Level0)
522 {
523     int32_t frame[4] = {0, 1, -1, 8};
524     uint64_t nSamples = 4;
525     float result = CalculateMaxAmplitudeForPCM32Bit(frame, nSamples);
526     EXPECT_NEAR(result, 0, 0.0001);
527 }
528 
529 /**
530 * @tc.name  : Test CalculateMaxAmplitudeForPCM32Bit API
531 * @tc.type  : FUNC
532 * @tc.number: CalculateMaxAmplitudeForPCM32Bit_004
533 * @tc.desc  : Test CalculateMaxAmplitudeForPCM32Bit interface
534 *               when value isn't bigger than curMaxAmplitude and smaller than 0.
535 */
536 HWTEST(AudioUtilsUnitTest, CalculateMaxAmplitudeForPCM32Bit_004, TestSize.Level0)
537 {
538     int32_t frame[6] = {0};
539     uint64_t nSamples = 6;
540     float result = CalculateMaxAmplitudeForPCM32Bit(frame, nSamples);
541     EXPECT_EQ(result, 0);
542 }
543 
544 /**
545 * @tc.name  : Test GetFormatByteSize API
546 * @tc.type  : FUNC
547 * @tc.number: GetFormatByteSize_001
548 * @tc.desc  : Test GetFormatByteSize interface Return 2 when format is  SAMPLE_S16LE
549 */
550 HWTEST(AudioUtilsUnitTest, GetFormatByteSize_001, TestSize.Level0)
551 {
552     int32_t format = 100;
553     int32_t formatByteSize = GetFormatByteSize(format);
554     EXPECT_EQ(formatByteSize, 2);
555 }
556 
557 /**
558 * @tc.name  : Test GetFormatByteSize API
559 * @tc.type  : FUNC
560 * @tc.number: GetFormatByteSize_002
561 * @tc.desc  : Test GetFormatByteSize interface Return 2 when  when format is other int32_t
562 */
563 HWTEST(AudioUtilsUnitTest, GetFormatByteSize_002, TestSize.Level0)
564 {
565     int32_t format = SAMPLE_S16LE;
566     int32_t formatByteSize = GetFormatByteSize(format);
567     EXPECT_EQ(formatByteSize, 2);
568 }
569 
570 /**
571 * @tc.name  : Test GetFormatByteSize API
572 * @tc.type  : FUNC
573 * @tc.number: GetFormatByteSize_003
574 * @tc.desc  : Test GetFormatByteSize interface Return 3 when format is  SAMPLE_S24LE
575 */
576 HWTEST(AudioUtilsUnitTest, GetFormatByteSize_003, TestSize.Level0)
577 {
578     int32_t format = SAMPLE_S24LE;
579     int32_t formatByteSize = GetFormatByteSize(format);
580     EXPECT_EQ(formatByteSize, 3);
581 }
582 
583 /**
584 * @tc.name  : Test GetFormatByteSize API
585 * @tc.type  : FUNC
586 * @tc.number: GetFormatByteSize_004
587 * @tc.desc  : Test GetFormatByteSize interface Return 4 when format is  SAMPLE_S32LE
588 */
589 HWTEST(AudioUtilsUnitTest, GetFormatByteSize_004, TestSize.Level0)
590 {
591     int32_t format = SAMPLE_S32LE;
592     int32_t formatByteSize = GetFormatByteSize(format);
593     EXPECT_EQ(formatByteSize, 4);
594 }
595 
596 /**
597 * @tc.name  : Test SignalDetectAgent::DetectSignalData API
598 * @tc.type  : FUNC
599 * @tc.number: SignalDetectAgent_DetectSignalData_001
600 * @tc.desc  : Test DetectSignalData interface Return  false when bufferLen is 0
601 */
602 HWTEST(AudioUtilsUnitTest, SignalDetectAgent_DetectSignalData_001, TestSize.Level0)
603 {
604     int32_t buffer[10] = {0};
605     size_t bufferLen = 0;
606     struct SignalDetectAgent signalDetectAgent;
607     bool ret = signalDetectAgent.DetectSignalData(buffer, bufferLen);
608     EXPECT_EQ(ret, false);
609 }
610 /**
611 * @tc.name  : Test SignalDetectAgent::DetectSignalData API
612 * @tc.type  : FUNC
613 * @tc.number: SignalDetectAgent_DetectSignalData_002
614 * @tc.desc  : Test DetectSignalData interface Return  false when NearZero(tempMax) is true and NearZero(tempMin) is true
615 */
616 HWTEST(AudioUtilsUnitTest, SignalDetectAgent_DetectSignalData_002, TestSize.Level0)
617 {
618     int32_t buffer[10] = {2, 3, 2, 3, 2, 3, 2, 3, 2, 3};
619     size_t bufferLen = 10 * sizeof(int32_t);
620 
621     struct SignalDetectAgent signalDetectAgent;
622     bool ret = signalDetectAgent.DetectSignalData(buffer, bufferLen);
623     EXPECT_EQ(ret, false);
624 }
625 
626 /**
627 * @tc.name  : Test SignalDetectAgent::DetectSignalData API
628 * @tc.type  : FUNC
629 * @tc.number: SignalDetectAgent_DetectSignalData_003
630 * @tc.desc  : Test DetectSignalData interface Return  true when currentPeakIndex is -1
631 */
632 HWTEST(AudioUtilsUnitTest, SignalDetectAgent_DetectSignalData_003, TestSize.Level0)
633 {
634     int32_t buffer[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
635     size_t bufferLen = 10 * sizeof(int32_t);
636 
637     struct SignalDetectAgent signalDetectAgent;
638     signalDetectAgent.ResetDetectResult();
639     signalDetectAgent.channels_ = 1;
640     bool ret = signalDetectAgent.DetectSignalData(buffer, bufferLen);
641     EXPECT_EQ(ret, false);
642 }
643 
644 /**
645 * @tc.name  : Test SignalDetectAgent::DetectSignalData API
646 * @tc.type  : FUNC
647 * @tc.number: SignalDetectAgent_DetectSignalData_004
648 * @tc.desc  : Test DetectSignalData interface Return  true when blankPeriod_ < thresholdBlankPeriod
649 */
650 HWTEST(AudioUtilsUnitTest, SignalDetectAgent_DetectSignalData_004, TestSize.Level0)
651 {
652     int32_t buffer[10] = {0, 1, 0, 1, 0, 1, 0, 1, 0, 1 };
653     size_t bufferLen = 10 * sizeof(int32_t);
654 
655     struct SignalDetectAgent signalDetectAgent;
656     signalDetectAgent.ResetDetectResult();
657     signalDetectAgent.channels_ = 1 ;
658     signalDetectAgent.sampleRate_ = 100;
659     bool ret = signalDetectAgent.DetectSignalData(buffer, bufferLen);
660     EXPECT_EQ(ret, false);
661 }
662 
663 /**
664 * @tc.name  : Test SignalDetectAgent::ResetDetectResult API
665 * @tc.type  : FUNC
666 * @tc.number: SignalDetectAgent_ResetDetectResult_001
667 * @tc.desc  : Test ResetDetectResult interface.
668 */
669 HWTEST(AudioUtilsUnitTest, SignalDetectAgent_ResetDetectResult_001, TestSize.Level0)
670 {
671     struct SignalDetectAgent signalDetectAgent;
672     signalDetectAgent.ResetDetectResult();
673     EXPECT_EQ(signalDetectAgent.blankHaveOutput_, true);
674     EXPECT_EQ(signalDetectAgent.hasFirstNoneZero_, false);
675     EXPECT_EQ(signalDetectAgent.lastPeakSignal_, SHRT_MIN);
676     EXPECT_EQ(signalDetectAgent.signalDetected_, true);
677     EXPECT_EQ(signalDetectAgent.dspTimestampGot_, false);
678 }
679 
680 /**
681 * @tc.name  : Test AudioInfoDumpUtils::GetStreamName  API
682 * @tc.type  : FUNC
683 * @tc.number: AudioInfoDumpUtils_GetStreamName_001
684 * @tc.desc  : Test AudioInfoDumpUtils GetStreamName API,Return VOICE_ASSISTANT
685 *             when streamType is STREAM_VOICE_ASSISTANT
686 */
687 HWTEST(AudioUtilsUnitTest, AudioInfoDumpUtils_GetStreamName_001, TestSize.Level0)
688 {
689     AudioStreamType streamType = STREAM_VOICE_ASSISTANT;
690     const std::string streamName = AudioInfoDumpUtils::GetStreamName(streamType);
691     EXPECT_EQ(streamName, "VOICE_ASSISTANT");
692 }
693 /**
694 * @tc.name  : Test AudioInfoDumpUtils::GetStreamName  API
695 * @tc.type  : FUNC
696 * @tc.number: AudioInfoDumpUtils_GetStreamName_002
697 * @tc.desc  : Test AudioInfoDumpUtils GetStreamName API,Return VOICE_CALL
698 *             when streamType is STREAM_VOICE_CALL
699 */
700 HWTEST(AudioUtilsUnitTest, AudioInfoDumpUtils_GetStreamName_002, TestSize.Level0)
701 {
702     AudioStreamType streamType = STREAM_VOICE_CALL;
703     const std::string streamName = AudioInfoDumpUtils::GetStreamName(streamType);
704     EXPECT_EQ(streamName, "VOICE_CALL");
705 }
706 
707 /**
708 * @tc.name  : Test AudioInfoDumpUtils::GetStreamName  API
709 * @tc.type  : FUNC
710 * @tc.number: AudioInfoDumpUtils_GetStreamName_003
711 * @tc.desc  : Test AudioInfoDumpUtils GetStreamName API,Return VOICE_CALL
712 *             when streamType is STREAM_VOICE_COMMUNICATION
713 */
714 HWTEST(AudioUtilsUnitTest, AudioInfoDumpUtils_GetStreamName_003, TestSize.Level0)
715 {
716     AudioStreamType streamType = STREAM_VOICE_COMMUNICATION;
717     const std::string streamName = AudioInfoDumpUtils::GetStreamName(streamType);
718     EXPECT_EQ(streamName, "VOICE_COMMUNICATION");
719 }
720 /**
721 * @tc.name  : Test AudioInfoDumpUtils::GetStreamName  API
722 * @tc.type  : FUNC
723 * @tc.number: AudioInfoDumpUtils_GetStreamName_004
724 * @tc.desc  : Test AudioInfoDumpUtils GetStreamName API,Return SYSTEM
725 *             when streamType is STREAM_SYSTEM
726 */
727 HWTEST(AudioUtilsUnitTest, AudioInfoDumpUtils_GetStreamName_004, TestSize.Level0)
728 {
729     AudioStreamType streamType = STREAM_SYSTEM;
730     const std::string streamName = AudioInfoDumpUtils::GetStreamName(streamType);
731     EXPECT_EQ(streamName, "SYSTEM");
732 }
733 
734 /**
735 * @tc.name  : Test AudioInfoDumpUtils::GetStreamName  API
736 * @tc.type  : FUNC
737 * @tc.number: AudioInfoDumpUtils_GetStreamName_005
738 * @tc.desc  : Test AudioInfoDumpUtils GetStreamName API,Return RING
739 *             when streamType is STREAM_RING
740 */
741 HWTEST(AudioUtilsUnitTest, AudioInfoDumpUtils_GetStreamName_005, TestSize.Level0)
742 {
743     AudioStreamType streamType = STREAM_RING;
744     const std::string streamName = AudioInfoDumpUtils::GetStreamName(streamType);
745     EXPECT_EQ(streamName, "RING");
746 }
747 /**
748 * @tc.name  : Test AudioInfoDumpUtils::GetStreamName  API
749 * @tc.type  : FUNC
750 * @tc.number: AudioInfoDumpUtils_GetStreamName_006
751 * @tc.desc  : Test AudioInfoDumpUtils GetStreamName API,Return MUSIC
752 *             when streamType is STREAM_MUSIC
753 */
754 HWTEST(AudioUtilsUnitTest, AudioInfoDumpUtils_GetStreamName_006, TestSize.Level0)
755 {
756     AudioStreamType streamType = STREAM_MUSIC;
757     const std::string streamName = AudioInfoDumpUtils::GetStreamName(streamType);
758     EXPECT_EQ(streamName, "MUSIC");
759 }
760 
761 /**
762 * @tc.name  : Test AudioInfoDumpUtils::GetStreamName  API
763 * @tc.type  : FUNC
764 * @tc.number: AudioInfoDumpUtils_GetStreamName_007
765 * @tc.desc  : Test AudioInfoDumpUtils GetStreamName API,Return ALARM
766 *             when streamType is STREAM_ALARM
767 */
768 HWTEST(AudioUtilsUnitTest, AudioInfoDumpUtils_GetStreamName_007, TestSize.Level0)
769 {
770     AudioStreamType streamType = STREAM_ALARM;
771     const std::string streamName = AudioInfoDumpUtils::GetStreamName(streamType);
772     EXPECT_EQ(streamName, "ALARM");
773 }
774 
775 /**
776 * @tc.name  : Test AudioInfoDumpUtils::GetStreamName  API
777 * @tc.type  : FUNC
778 * @tc.number: AudioInfoDumpUtils_GetStreamName_008
779 * @tc.desc  : Test AudioInfoDumpUtils GetStreamName API,Return NOTIFICATION
780 *             when streamType is STREAM_NOTIFICATION
781 */
782 HWTEST(AudioUtilsUnitTest, AudioInfoDumpUtils_GetStreamName_008, TestSize.Level0)
783 {
784     AudioStreamType streamType = STREAM_NOTIFICATION;
785     const std::string streamName = AudioInfoDumpUtils::GetStreamName(streamType);
786     EXPECT_EQ(streamName, "NOTIFICATION");
787 }
788 
789 /**
790 * @tc.name  : Test AudioInfoDumpUtils::GetStreamName  API
791 * @tc.type  : FUNC
792 * @tc.number: AudioInfoDumpUtils_GetStreamName_009
793 * @tc.desc  : Test AudioInfoDumpUtils GetStreamName API,Return BLUETOOTH_SCO
794 *             when streamType is STREAM_BLUETOOTH_SCO
795 */
796 HWTEST(AudioUtilsUnitTest, AudioInfoDumpUtils_GetStreamName_009, TestSize.Level0)
797 {
798     AudioStreamType streamType = STREAM_BLUETOOTH_SCO;
799     const std::string streamName = AudioInfoDumpUtils::GetStreamName(streamType);
800     EXPECT_EQ(streamName, "BLUETOOTH_SCO");
801 }
802 
803 /**
804 * @tc.name  : Test AudioInfoDumpUtils::GetStreamName  API
805 * @tc.type  : FUNC
806 * @tc.number: AudioInfoDumpUtils_GetStreamName_010
807 * @tc.desc  : Test AudioInfoDumpUtils GetStreamName API,Return DTMF
808 *             when streamType is STREAM_DTMF
809 */
810 HWTEST(AudioUtilsUnitTest, AudioInfoDumpUtils_GetStreamName_010, TestSize.Level0)
811 {
812     AudioStreamType streamType = STREAM_DTMF;
813     const std::string streamName = AudioInfoDumpUtils::GetStreamName(streamType);
814     EXPECT_EQ(streamName, "DTMF");
815 }
816 
817 /**
818 * @tc.name  : Test AudioInfoDumpUtils::GetStreamName  API
819 * @tc.type  : FUNC
820 * @tc.number: AudioInfoDumpUtils_GetStreamName_011
821 * @tc.desc  : Test AudioInfoDumpUtils GetStreamName API,Return TTS
822 *             when streamType is STREAM_TTS
823 */
824 HWTEST(AudioUtilsUnitTest, AudioInfoDumpUtils_GetStreamName_011, TestSize.Level0)
825 {
826     AudioStreamType streamType = STREAM_TTS;
827     const std::string streamName = AudioInfoDumpUtils::GetStreamName(streamType);
828     EXPECT_EQ(streamName, "TTS");
829 }
830 
831 /**
832 * @tc.name  : Test AudioInfoDumpUtils::GetStreamName  API
833 * @tc.type  : FUNC
834 * @tc.number: AudioInfoDumpUtils_GetStreamName_013
835 * @tc.desc  : Test AudioInfoDumpUtils GetStreamName API,Return ULTRASONIC
836 *             when streamType is STREAM_ULTRASONIC
837 */
838 HWTEST(AudioUtilsUnitTest, AudioInfoDumpUtils_GetStreamName_013, TestSize.Level0)
839 {
840     AudioStreamType streamType = STREAM_ULTRASONIC;
841     const std::string streamName = AudioInfoDumpUtils::GetStreamName(streamType);
842     EXPECT_EQ(streamName, "ULTRASONIC");
843 }
844 
845 /**
846 * @tc.name  : Test AudioInfoDumpUtils::GetStreamName  API
847 * @tc.type  : FUNC
848 * @tc.number: AudioInfoDumpUtils_GetStreamName_014
849 * @tc.desc  : Test AudioInfoDumpUtils GetStreamName API,Return WAKEUP
850 *             when streamType is STREAM_WAKEUP
851 */
852 HWTEST(AudioUtilsUnitTest, AudioInfoDumpUtils_GetStreamName_014, TestSize.Level0)
853 {
854     AudioStreamType streamType = STREAM_WAKEUP;
855     const std::string streamName = AudioInfoDumpUtils::GetStreamName(streamType);
856     EXPECT_EQ(streamName, "WAKEUP");
857 }
858 
859 /**
860 * @tc.name  : Test AudioInfoDumpUtils::GetStreamName  API
861 * @tc.type  : FUNC
862 * @tc.number: AudioInfoDumpUtils_GetStreamName_015
863 * @tc.desc  : Test AudioInfoDumpUtils GetStreamName API,Return UNKNOWN
864 *             when streamType is others
865 */
866 HWTEST(AudioUtilsUnitTest, AudioInfoDumpUtils_GetStreamName_015, TestSize.Level0)
867 {
868     AudioStreamType streamType = STREAM_DEFAULT;
869     const std::string streamName = AudioInfoDumpUtils::GetStreamName(streamType);
870     EXPECT_EQ(streamName, "UNKNOWN");
871 }
872 
873 /**
874 * @tc.name  : Test AudioInfoDumpUtils::GetDeviceTypeName  API
875 * @tc.type  : FUNC
876 * @tc.number: AudioInfoDumpUtils_GetDeviceTypeName_001
877 * @tc.desc  : Test AudioInfoDumpUtils GetDeviceTypeName API,Return EARPIECE
878 *             when deviceType is DEVICE_TYPE_EARPIECE
879 */
880 HWTEST(AudioUtilsUnitTest, AudioInfoDumpUtils_GetDeviceTypeName_001, TestSize.Level0)
881 {
882     DeviceType deviceType = DEVICE_TYPE_EARPIECE;
883     const std::string deviceTypeName = AudioInfoDumpUtils::GetDeviceTypeName(deviceType);
884     EXPECT_EQ(deviceTypeName, "EARPIECE");
885 }
886 
887 /**
888 * @tc.name  : Test AudioInfoDumpUtils::GetDeviceTypeName  API
889 * @tc.type  : FUNC
890 * @tc.number: AudioInfoDumpUtils_GetDeviceTypeName_002
891 * @tc.desc  : Test AudioInfoDumpUtils GetDeviceTypeName API,Return SPEAKER
892 *             when deviceType is DEVICE_TYPE_SPEAKER
893 */
894 HWTEST(AudioUtilsUnitTest, AudioInfoDumpUtils_GetDeviceTypeName_002, TestSize.Level0)
895 {
896     DeviceType deviceType = DEVICE_TYPE_SPEAKER;
897     const std::string deviceTypeName = AudioInfoDumpUtils::GetDeviceTypeName(deviceType);
898     EXPECT_EQ(deviceTypeName, "SPEAKER");
899 }
900 
901 /**
902 * @tc.name  : Test AudioInfoDumpUtils::GetDeviceTypeName  API
903 * @tc.type  : FUNC
904 * @tc.number: AudioInfoDumpUtils_GetDeviceTypeName_003
905 * @tc.desc  : Test AudioInfoDumpUtils GetDeviceTypeName API,Return WIRED_HEADSET
906 *             when deviceType is DEVICE_TYPE_WIRED_HEADSET
907 */
908 HWTEST(AudioUtilsUnitTest, AudioInfoDumpUtils_GetDeviceTypeName_003, TestSize.Level0)
909 {
910     DeviceType deviceType = DEVICE_TYPE_WIRED_HEADSET;
911     const std::string deviceTypeName = AudioInfoDumpUtils::GetDeviceTypeName(deviceType);
912     EXPECT_EQ(deviceTypeName, "WIRED_HEADSET");
913 }
914 
915 /**
916 * @tc.name  : Test AudioInfoDumpUtils::GetDeviceTypeName  API
917 * @tc.type  : FUNC
918 * @tc.number: AudioInfoDumpUtils_GetDeviceTypeName_004
919 * @tc.desc  : Test AudioInfoDumpUtils GetDeviceTypeName API,Return SPEAKER
920 *             when deviceType is DEVICE_TYPE_WIRED_HEADPHONES
921 */
922 HWTEST(AudioUtilsUnitTest, AudioInfoDumpUtils_GetDeviceTypeName_004, TestSize.Level0)
923 {
924     DeviceType deviceType = DEVICE_TYPE_WIRED_HEADPHONES;
925     const std::string deviceTypeName = AudioInfoDumpUtils::GetDeviceTypeName(deviceType);
926     EXPECT_EQ(deviceTypeName, "WIRED_HEADPHONES");
927 }
928 
929 /**
930 * @tc.name  : Test AudioInfoDumpUtils::GetDeviceTypeName  API
931 * @tc.type  : FUNC
932 * @tc.number: AudioInfoDumpUtils_GetDeviceTypeName_005
933 * @tc.desc  : Test AudioInfoDumpUtils GetDeviceTypeName API,Return BLUETOOTH_SCO
934 *             when deviceType is DEVICE_TYPE_BLUETOOTH_SCO
935 */
936 HWTEST(AudioUtilsUnitTest, AudioInfoDumpUtils_GetDeviceTypeName_005, TestSize.Level0)
937 {
938     DeviceType deviceType = DEVICE_TYPE_BLUETOOTH_SCO;
939     const std::string deviceTypeName = AudioInfoDumpUtils::GetDeviceTypeName(deviceType);
940     EXPECT_EQ(deviceTypeName, "BLUETOOTH_SCO");
941 }
942 
943 /**
944 * @tc.name  : Test AudioInfoDumpUtils::GetDeviceTypeName  API
945 * @tc.type  : FUNC
946 * @tc.number: AudioInfoDumpUtils_GetDeviceTypeName_006
947 * @tc.desc  : Test AudioInfoDumpUtils GetDeviceTypeName API,Return BLUETOOTH_A2DP
948 *             when deviceType is DEVICE_TYPE_BLUETOOTH_A2DP
949 */
950 HWTEST(AudioUtilsUnitTest, AudioInfoDumpUtils_GetDeviceTypeName_006, TestSize.Level0)
951 {
952     DeviceType deviceType = DEVICE_TYPE_BLUETOOTH_A2DP;
953     const std::string deviceTypeName = AudioInfoDumpUtils::GetDeviceTypeName(deviceType);
954     EXPECT_EQ(deviceTypeName, "BLUETOOTH_A2DP");
955 }
956 
957 /**
958 * @tc.name  : Test AudioInfoDumpUtils::GetDeviceTypeName  API
959 * @tc.type  : FUNC
960 * @tc.number: AudioInfoDumpUtils_GetDeviceTypeName_007
961 * @tc.desc  : Test AudioInfoDumpUtils GetDeviceTypeName API,Return MIC
962 *             when deviceType is DEVICE_TYPE_MIC
963 */
964 HWTEST(AudioUtilsUnitTest, AudioInfoDumpUtils_GetDeviceTypeName_007, TestSize.Level0)
965 {
966     DeviceType deviceType = DEVICE_TYPE_MIC;
967     const std::string deviceTypeName = AudioInfoDumpUtils::GetDeviceTypeName(deviceType);
968     EXPECT_EQ(deviceTypeName, "MIC");
969 }
970 
971 /**
972 * @tc.name  : Test AudioInfoDumpUtils::GetDeviceTypeName  API
973 * @tc.type  : FUNC
974 * @tc.number: AudioInfoDumpUtils_GetDeviceTypeName_008
975 * @tc.desc  : Test AudioInfoDumpUtils GetDeviceTypeName API,Return WAKEUP
976 *             when deviceType is DEVICE_TYPE_WAKEUP
977 */
978 HWTEST(AudioUtilsUnitTest, AudioInfoDumpUtils_GetDeviceTypeName_008, TestSize.Level0)
979 {
980     DeviceType deviceType = DEVICE_TYPE_WAKEUP;
981     const std::string deviceTypeName = AudioInfoDumpUtils::GetDeviceTypeName(deviceType);
982     EXPECT_EQ(deviceTypeName, "WAKEUP");
983 }
984 
985 /**
986 * @tc.name  : Test AudioInfoDumpUtils::GetDeviceTypeName  API
987 * @tc.type  : FUNC
988 * @tc.number: AudioInfoDumpUtils_GetDeviceTypeName_009
989 * @tc.desc  : Test AudioInfoDumpUtils GetDeviceTypeName API,Return NONE
990 *             when deviceType is DEVICE_TYPE_NONE
991 */
992 HWTEST(AudioUtilsUnitTest, AudioInfoDumpUtils_GetDeviceTypeName_009, TestSize.Level0)
993 {
994     DeviceType deviceType = DEVICE_TYPE_NONE;
995     const std::string deviceTypeName = AudioInfoDumpUtils::GetDeviceTypeName(deviceType);
996     EXPECT_EQ(deviceTypeName, "NONE");
997 }
998 
999 /**
1000 * @tc.name  : Test AudioInfoDumpUtils::GetDeviceTypeName  API
1001 * @tc.type  : FUNC
1002 * @tc.number: AudioInfoDumpUtils_GetDeviceTypeName_010
1003 * @tc.desc  : Test AudioInfoDumpUtils GetDeviceTypeName API,Return INVALID
1004 *             when deviceType is DEVICE_TYPE_INVALID
1005 */
1006 HWTEST(AudioUtilsUnitTest, AudioInfoDumpUtils_GetDeviceTypeName_010, TestSize.Level0)
1007 {
1008     DeviceType deviceType = DEVICE_TYPE_INVALID;
1009     const std::string deviceTypeName = AudioInfoDumpUtils::GetDeviceTypeName(deviceType);
1010     EXPECT_EQ(deviceTypeName, "INVALID");
1011 }
1012 
1013 /**
1014 * @tc.name  : Test AudioInfoDumpUtils::GetDeviceTypeName  API
1015 * @tc.type  : FUNC
1016 * @tc.number: AudioInfoDumpUtils_GetDeviceTypeName_011
1017 * @tc.desc  : Test AudioInfoDumpUtils GetDeviceTypeName API,Return UNKNOWN
1018 *             when deviceType is others
1019 */
1020 HWTEST(AudioUtilsUnitTest, AudioInfoDumpUtils_GetDeviceTypeName_011, TestSize.Level0)
1021 {
1022     DeviceType deviceType = DEVICE_TYPE_DEFAULT;
1023     const std::string deviceTypeName = AudioInfoDumpUtils::GetDeviceTypeName(deviceType);
1024     EXPECT_EQ(deviceTypeName, "UNKNOWN");
1025 }
1026 
1027 /**
1028 * @tc.name  : Test AudioInfoDumpUtils::GetDeviceTypeName  API
1029 * @tc.type  : FUNC
1030 * @tc.number: AudioInfoDumpUtils_GetDeviceTypeName_012
1031 * @tc.desc  : Test AudioInfoDumpUtils GetDeviceTypeName API,Return HDMI
1032 *             when deviceType is DEVICE_TYPE_HDMI
1033 */
1034 HWTEST(AudioUtilsUnitTest, AudioInfoDumpUtils_GetDeviceTypeName_012, TestSize.Level0)
1035 {
1036     DeviceType deviceType = DEVICE_TYPE_HDMI;
1037     const std::string deviceTypeName = AudioInfoDumpUtils::GetDeviceTypeName(deviceType);
1038     EXPECT_EQ(deviceTypeName, "HDMI");
1039 }
1040 
1041 /**
1042  * @tc.name  : Test AudioInfoDumpUtils::GetDeviceTypeName  API
1043  * @tc.type  : FUNC
1044  * @tc.number: AudioInfoDumpUtils_GetDeviceTypeName_013
1045  * @tc.desc  : Test AudioInfoDumpUtils GetDeviceTypeName API,Return NEARLINK
1046  *             when deviceType is DEVICE_TYPE_NEARLINK
1047  */
1048 HWTEST(AudioUtilsUnitTest, AudioInfoDumpUtils_GetDeviceTypeName_013, TestSize.Level0)
1049 {
1050     DeviceType deviceType = DEVICE_TYPE_NEARLINK;
1051     const std::string deviceTypeName = AudioInfoDumpUtils::GetDeviceTypeName(deviceType);
1052     EXPECT_EQ(deviceTypeName, "NEARLINK");
1053 }
1054 
1055 /**
1056  * @tc.name  : Test AudioInfoDumpUtils::GetDeviceTypeName  API
1057  * @tc.type  : FUNC
1058  * @tc.number: AudioInfoDumpUtils_GetDeviceTypeName_014
1059  * @tc.desc  : Test AudioInfoDumpUtils GetDeviceTypeName API,Return REMOTE_CAST
1060  *             when deviceType is DEVICE_TYPE_REMOTE_CAST
1061  */
1062 HWTEST(AudioUtilsUnitTest, AudioInfoDumpUtils_GetDeviceTypeName_014, TestSize.Level0)
1063 {
1064     DeviceType deviceType = DEVICE_TYPE_REMOTE_CAST;
1065     const std::string deviceTypeName = AudioInfoDumpUtils::GetDeviceTypeName(deviceType);
1066     EXPECT_EQ(deviceTypeName, "REMOTE_CAST");
1067 }
1068 
1069 /**
1070 * @tc.name  : Test AudioInfoDumpUtils::GetDeviceTypeName  API
1071 * @tc.type  : FUNC
1072 * @tc.number: AudioInfoDumpUtils_GetDeviceTypeName_015
1073 * @tc.desc  : Test AudioInfoDumpUtils GetDeviceTypeName API,Return HEARING_AID
1074 *             when deviceType is DEVICE_TYPE_HEARING_AID
1075 */
1076 HWTEST(AudioUtilsUnitTest, AudioInfoDumpUtils_GetDeviceTypeName_015, TestSize.Level0)
1077 {
1078     DeviceType deviceType = DEVICE_TYPE_HEARING_AID;
1079     const std::string deviceTypeName = AudioInfoDumpUtils::GetDeviceTypeName(deviceType);
1080     EXPECT_EQ(deviceTypeName, "HEARING_AID");
1081 }
1082 
1083 /**
1084 * @tc.name  : Test AudioInfoDumpUtils::GetConnectTypeName  API
1085 * @tc.type  : FUNC
1086 * @tc.number: AudioInfoDumpUtils_GetConnectTypeName_001
1087 * @tc.desc  : Test AudioInfoDumpUtils GetConnectTypeName API,Return LOCAL
1088 *             when connectType is CONNECT_TYPE_LOCAL
1089 */
1090 HWTEST(AudioUtilsUnitTest, AudioInfoDumpUtils_GetConnectTypeName_001, TestSize.Level0)
1091 {
1092     ConnectType connectType = OHOS::AudioStandard::CONNECT_TYPE_LOCAL;
1093     const std::string connectTypeName = AudioInfoDumpUtils::GetConnectTypeName(connectType);
1094     EXPECT_EQ(connectTypeName, "LOCAL");
1095 }
1096 
1097 /**
1098 * @tc.name  : Test AudioInfoDumpUtils::GetConnectTypeName  API
1099 * @tc.type  : FUNC
1100 * @tc.number: AudioInfoDumpUtils_GetConnectTypeName_002
1101 * @tc.desc  : Test AudioInfoDumpUtils GetConnectTypeName API,Return REMOTE
1102 *             when connectType is CONNECT_TYPE_DISTRIBUTED
1103 */
1104 HWTEST(AudioUtilsUnitTest, AudioInfoDumpUtils_GetConnectTypeName_002, TestSize.Level0)
1105 {
1106     ConnectType connectType = AudioStandard::CONNECT_TYPE_DISTRIBUTED;
1107     const std::string connectTypeName = AudioInfoDumpUtils::GetConnectTypeName(connectType);
1108     EXPECT_EQ(connectTypeName, "REMOTE");
1109 }
1110 
1111 /**
1112 * @tc.name  : Test AudioInfoDumpUtils::GetConnectTypeName  API
1113 * @tc.type  : FUNC
1114 * @tc.number: AudioInfoDumpUtils_GetConnectTypeName_003
1115 * @tc.desc  : Test AudioInfoDumpUtils GetConnectTypeName API,Return UNKNOWN
1116 *             when connectType is others
1117 */
1118 HWTEST(AudioUtilsUnitTest, AudioInfoDumpUtils_GetConnectTypeName_003, TestSize.Level0)
1119 {
1120     ConnectType connectType =  static_cast<ConnectType>(-1);
1121     const std::string connectTypeName = AudioInfoDumpUtils::GetConnectTypeName(connectType);
1122     EXPECT_EQ(connectTypeName, "UNKNOWN");
1123 }
1124 
1125 /**
1126 * @tc.name  : Test AudioInfoDumpUtils::GetSourceName  API
1127 * @tc.type  : FUNC
1128 * @tc.number: AudioInfoDumpUtils_GetSourceName_001
1129 * @tc.desc  : Test AudioInfoDumpUtils GetSourceName API,Return INVALID
1130 *             when sourceType is SOURCE_TYPE_INVALID
1131 */
1132 HWTEST(AudioUtilsUnitTest, AudioInfoDumpUtils_GetSourceName_001, TestSize.Level0)
1133 {
1134     SourceType sourceType = SOURCE_TYPE_INVALID;
1135     const std::string sourceName = AudioInfoDumpUtils::GetSourceName(sourceType);
1136     EXPECT_EQ(sourceName, "INVALID");
1137 }
1138 
1139 /**
1140 * @tc.name  : Test AudioInfoDumpUtils::GetSourceName  API
1141 * @tc.type  : FUNC
1142 * @tc.number: AudioInfoDumpUtils_GetSourceName_002
1143 * @tc.desc  : Test AudioInfoDumpUtils GetSourceName API,Return MIC
1144 *             when sourceType is SOURCE_TYPE_MIC
1145 */
1146 HWTEST(AudioUtilsUnitTest, AudioInfoDumpUtils_GetSourceName_002, TestSize.Level0)
1147 {
1148     SourceType sourceType = SOURCE_TYPE_MIC;
1149     const std::string sourceName = AudioInfoDumpUtils::GetSourceName(sourceType);
1150     EXPECT_EQ(sourceName, "MIC");
1151 }
1152 
1153 /**
1154 * @tc.name  : Test AudioInfoDumpUtils::GetSourceName  API
1155 * @tc.type  : FUNC
1156 * @tc.number: AudioInfoDumpUtils_GetSourceName_003
1157 * @tc.desc  : Test AudioInfoDumpUtils GetSourceName API,Return VOICE_RECOGNITION
1158 *             when sourceType is SOURCE_TYPE_VOICE_RECOGNITION
1159 */
1160 HWTEST(AudioUtilsUnitTest, AudioInfoDumpUtils_GetSourceName_003, TestSize.Level0)
1161 {
1162     SourceType sourceType = SOURCE_TYPE_VOICE_RECOGNITION;
1163     const std::string sourceName = AudioInfoDumpUtils::GetSourceName(sourceType);
1164     EXPECT_EQ(sourceName, "VOICE_RECOGNITION");
1165 }
1166 
1167 /**
1168 * @tc.name  : Test AudioInfoDumpUtils::GetSourceName  API
1169 * @tc.type  : FUNC
1170 * @tc.number: AudioInfoDumpUtils_GetSourceName_004
1171 * @tc.desc  : Test AudioInfoDumpUtils GetSourceName API,Return ULTRASONIC
1172 *             when sourceType is SOURCE_TYPE_ULTRASONIC
1173 */
1174 HWTEST(AudioUtilsUnitTest, AudioInfoDumpUtils_GetSourceName_004, TestSize.Level0)
1175 {
1176     SourceType sourceType = SOURCE_TYPE_ULTRASONIC;
1177     const std::string sourceName = AudioInfoDumpUtils::GetSourceName(sourceType);
1178     EXPECT_EQ(sourceName, "ULTRASONIC");
1179 }
1180 
1181 /**
1182 * @tc.name  : Test AudioInfoDumpUtils::GetSourceName  API
1183 * @tc.type  : FUNC
1184 * @tc.number: AudioInfoDumpUtils_GetSourceName_005
1185 * @tc.desc  : Test AudioInfoDumpUtils GetSourceName API,Return VOICE_COMMUNICATION
1186 *             when sourceType is SOURCE_TYPE_VOICE_COMMUNICATION
1187 */
1188 HWTEST(AudioUtilsUnitTest, AudioInfoDumpUtils_GetSourceName_005, TestSize.Level0)
1189 {
1190     SourceType sourceType = SOURCE_TYPE_VOICE_COMMUNICATION;
1191     const std::string sourceName = AudioInfoDumpUtils::GetSourceName(sourceType);
1192     EXPECT_EQ(sourceName, "VOICE_COMMUNICATION");
1193 }
1194 
1195 /**
1196 * @tc.name  : Test AudioInfoDumpUtils::GetSourceName  API
1197 * @tc.type  : FUNC
1198 * @tc.number: AudioInfoDumpUtils_GetSourceName_006
1199 * @tc.desc  : Test AudioInfoDumpUtils GetSourceName API,Return WAKEUP
1200 *             when sourceType is SOURCE_TYPE_WAKEUP
1201 */
1202 HWTEST(AudioUtilsUnitTest, AudioInfoDumpUtils_GetSourceName_006, TestSize.Level0)
1203 {
1204     SourceType sourceType = SOURCE_TYPE_WAKEUP;
1205     const std::string sourceName = AudioInfoDumpUtils::GetSourceName(sourceType);
1206     EXPECT_EQ(sourceName, "WAKEUP");
1207 }
1208 
1209 /**
1210 * @tc.name  : Test AudioInfoDumpUtils::GetSourceName  API
1211 * @tc.type  : FUNC
1212 * @tc.number: AudioInfoDumpUtils_GetSourceName_007
1213 * @tc.desc  : Test AudioInfoDumpUtils GetSourceName API,Return SOURCE_TYPE_LIVE
1214 *             when sourceType is others
1215 */
1216 HWTEST(AudioUtilsUnitTest, AudioInfoDumpUtils_GetSourceName_007, TestSize.Level0)
1217 {
1218     SourceType sourceType = SOURCE_TYPE_MAX;
1219     const std::string sourceName = AudioInfoDumpUtils::GetSourceName(sourceType);
1220     EXPECT_EQ(sourceName, "SOURCE_TYPE_LIVE");
1221 }
1222 
1223 /**
1224  * @tc.name  : Test AudioInfoDumpUtils::GetSourceName  API
1225  * @tc.type  : FUNC
1226  * @tc.number: AudioInfoDumpUtils_GetSourceName_008
1227  * @tc.desc  : Test AudioInfoDumpUtils GetSourceName API,Return SOURCE_TYPE_UNPROCESSED
1228  *             when sourceType is SOURCE_TYPE_UNPROCESSED
1229  */
1230 HWTEST(AudioUtilsUnitTest, AudioInfoDumpUtils_GetSourceName_008, TestSize.Level0)
1231 {
1232     SourceType sourceType = SOURCE_TYPE_UNPROCESSED;
1233     const std::string sourceName = AudioInfoDumpUtils::GetSourceName(sourceType);
1234     EXPECT_EQ(sourceName, "SOURCE_TYPE_UNPROCESSED");
1235 }
1236 
1237 /**
1238 * @tc.name  : Test AudioInfoDumpUtils::GetDeviceVolumeTypeName  API
1239 * @tc.type  : FUNC
1240 * @tc.number: AudioInfoDumpUtils_GetDeviceVolumeTypeName_001
1241 * @tc.desc  : Test AudioInfoDumpUtils GetDeviceVolumeTypeName API,Return EARPIECE
1242 *             when deviceType is EARPIECE_VOLUME_TYPE
1243 */
1244 HWTEST(AudioUtilsUnitTest, AudioInfoDumpUtils_GetDeviceVolumeTypeName_001, TestSize.Level0)
1245 {
1246     DeviceVolumeType deviceType = EARPIECE_VOLUME_TYPE;
1247     const std::string deviceTypeName = AudioInfoDumpUtils::GetDeviceVolumeTypeName(deviceType);
1248     EXPECT_EQ(deviceTypeName, "EARPIECE");
1249 }
1250 
1251 /**
1252 * @tc.name  : Test AudioInfoDumpUtils::GetDeviceVolumeTypeName  API
1253 * @tc.type  : FUNC
1254 * @tc.number: AudioInfoDumpUtils_GetDeviceVolumeTypeName_002
1255 * @tc.desc  : Test AudioInfoDumpUtils GetDeviceVolumeTypeName API,Return SPEAKER
1256 *             when deviceType is SPEAKER_VOLUME_TYPE
1257 */
1258 HWTEST(AudioUtilsUnitTest, AudioInfoDumpUtils_GetDeviceVolumeTypeName_002, TestSize.Level0)
1259 {
1260     DeviceVolumeType deviceType = SPEAKER_VOLUME_TYPE;
1261     const std::string deviceTypeName = AudioInfoDumpUtils::GetDeviceVolumeTypeName(deviceType);
1262     EXPECT_EQ(deviceTypeName, "SPEAKER");
1263 }
1264 
1265 /**
1266 * @tc.name  : Test AudioInfoDumpUtils::GetDeviceVolumeTypeName  API
1267 * @tc.type  : FUNC
1268 * @tc.number: AudioInfoDumpUtils_GetDeviceVolumeTypeName_003
1269 * @tc.desc  : Test AudioInfoDumpUtils GetDeviceVolumeTypeName API,Return HEADSET
1270 *             when deviceType is HEADSET_VOLUME_TYPE
1271 */
1272 HWTEST(AudioUtilsUnitTest, AudioInfoDumpUtils_GetDeviceVolumeTypeName_003, TestSize.Level0)
1273 {
1274     DeviceVolumeType deviceType = HEADSET_VOLUME_TYPE;
1275     const std::string deviceTypeName = AudioInfoDumpUtils::GetDeviceVolumeTypeName(deviceType);
1276     EXPECT_EQ(deviceTypeName, "HEADSET");
1277 }
1278 
1279 /**
1280 * @tc.name  : Test AudioInfoDumpUtils::GetDeviceVolumeTypeName  API
1281 * @tc.type  : FUNC
1282 * @tc.number: AudioInfoDumpUtils_GetDeviceVolumeTypeName_004
1283 * @tc.desc  : Test AudioInfoDumpUtils GetDeviceVolumeTypeName API,Return UNKNOWN
1284 *             when deviceType is others
1285 */
1286 HWTEST(AudioUtilsUnitTest, AudioInfoDumpUtils_GetDeviceVolumeTypeName_004, TestSize.Level0)
1287 {
1288     DeviceVolumeType deviceType = static_cast<DeviceVolumeType>(-1);
1289     const std::string deviceTypeName = AudioInfoDumpUtils::GetDeviceVolumeTypeName(deviceType);
1290     EXPECT_EQ(deviceTypeName, "UNKNOWN");
1291 }
1292 
1293 
1294 /**
1295 * @tc.name  : Test GetEncryptStr  API
1296 * @tc.type  : FUNC
1297 * @tc.number: GetEncryptStr_001
1298 * @tc.desc  : Test GetEncryptStr API,Return empty when src is empty
1299 */
1300 HWTEST(AudioUtilsUnitTest, GetEncryptStr_001, TestSize.Level0)
1301 {
1302     const std::string src = "";
1303     std::string dst = GetEncryptStr(src);
1304     EXPECT_EQ(dst, "");
1305 }
1306 
1307 /**
1308 * @tc.name  : Test GetEncryptStr  API
1309 * @tc.type  : FUNC
1310 * @tc.number: GetEncryptStr_002
1311 * @tc.desc  : Test GetEncryptStr APIwhen length of src less than MIN_LEN
1312 */
1313 HWTEST(AudioUtilsUnitTest, GetEncryptStr_002, TestSize.Level0)
1314 {
1315     const std::string src = "abcdef";
1316     std::string dst = GetEncryptStr(src);
1317     EXPECT_EQ(dst, "*bcdef");
1318 }
1319 
1320 /**
1321 * @tc.name  : Test Hide API
1322 * @tc.type  : FUNC
1323 * @tc.number: Hide_001
1324 * @tc.desc  : Test Hide API
1325 */
1326 HWTEST(AudioUtilsUnitTest, Hide_001, TestSize.Level0)
1327 {
1328     string str{"12345"};
1329     EXPECT_EQ(Hide(str), "*");
1330     str = "123456";
1331     EXPECT_EQ(Hide(str), "123*456");
1332     str = "13682363247";
1333     EXPECT_EQ(Hide(str), "136*247");
1334 }
1335 
1336 class DemoThreadData {
1337 public:
DemoThreadData()1338     DemoThreadData()
1339     {
1340         putStatus = false;
1341         getStatus = false;
1342     }
1343     bool putStatus;
1344     bool getStatus;
1345     static AudioSafeBlockQueue<int> shareQueue;
1346 
Put(int j)1347     void Put(int j)
1348     {
1349         shareQueue.Push(j);
1350         putStatus = true;
1351     }
1352 
Get()1353     void Get()
1354     {
1355         shareQueue.Pop();
1356         getStatus = true;
1357     }
1358 };
1359 
1360 AudioSafeBlockQueue<int> DemoThreadData::shareQueue(QUEUE_SLOTS);
1361 
PutHandleThreadData(DemoThreadData & q,int i)1362 void PutHandleThreadData(DemoThreadData& q, int i)
1363 {
1364     q.Put(i);
1365 }
1366 
GetThreadDatePushedStatus(std::array<DemoThreadData,THREAD_NUM> & demoDatas,unsigned int & pushedIn,unsigned int & unpushedIn)1367 void GetThreadDatePushedStatus(std::array<DemoThreadData, THREAD_NUM>& demoDatas, unsigned int& pushedIn,
1368                                unsigned int& unpushedIn)
1369 {
1370     pushedIn = 0;
1371     unpushedIn = 0;
1372     for (auto& t : demoDatas) {
1373         if (t.putStatus) {
1374             pushedIn++;
1375         } else {
1376             unpushedIn++;
1377         }
1378     }
1379 }
1380 
GetThreadDateGetedStatus(std::array<DemoThreadData,THREAD_NUM> & demoDatas,unsigned int & getedOut,unsigned int & ungetedOut)1381 void GetThreadDateGetedStatus(std::array<DemoThreadData, THREAD_NUM>& demoDatas,
1382     unsigned int& getedOut, unsigned int& ungetedOut)
1383 {
1384     getedOut = 0;
1385     ungetedOut = 0;
1386     for (auto& t : demoDatas) {
1387         if (t.getStatus) {
1388             getedOut++;
1389         } else {
1390             ungetedOut++;
1391         }
1392     }
1393 }
1394 
PutHandleThreadDataTime(DemoThreadData & q,int i,std::chrono::system_clock::time_point absTime)1395 void PutHandleThreadDataTime(DemoThreadData& q, int i, std::chrono::system_clock::time_point absTime)
1396 {
1397     cout << "thread-" << std::this_thread::get_id() << " run time: "
1398         << std::chrono::system_clock::to_time_t(absTime) << endl;
1399     std::this_thread::sleep_until(absTime);
1400 
1401     q.Put(i);
1402 }
1403 
GetHandleThreadDataTime(DemoThreadData & q,int i,std::chrono::system_clock::time_point absTime)1404 void GetHandleThreadDataTime(DemoThreadData& q, int i, std::chrono::system_clock::time_point absTime)
1405 {
1406     cout << "thread-" << std::this_thread::get_id() << " run time: "
1407         << std::chrono::system_clock::to_time_t(absTime) << endl;
1408     std::this_thread::sleep_until(absTime);
1409 
1410     q.Get();
1411 }
1412 
1413 /*
1414  * @tc.name: testPut001
1415  * @tc.desc: Single-threaded call put and get to determine that the normal scenario
1416  */
1417 HWTEST(AudioUtilsUnitTest, testPut001, TestSize.Level0)
1418 {
1419     AudioSafeBlockQueue<int> qi(10);
1420     int i = 1;
1421     qi.Push(i);
1422     EXPECT_EQ(static_cast<unsigned>(1), qi.Size());
1423 }
1424 
1425 /*
1426  * @tc.name: testGet001
1427  * @tc.desc: Single-threaded call put and get to determine that the normal scenario
1428  */
1429 HWTEST(AudioUtilsUnitTest, testGet001, TestSize.Level0)
1430 {
1431     AudioSafeBlockQueue<int> qi(10);
1432     for (int i = 0; i < 3; i++) {
1433         qi.Push(i);
1434     }
1435     EXPECT_EQ(static_cast<unsigned>(3), qi.Size());
1436     int t = qi.Pop();
1437     ASSERT_EQ(t, 0);
1438 }
1439 
ThreadsJoin(std::thread (& threads)[THREAD_NUM])1440 static void ThreadsJoin(std::thread (&threads)[THREAD_NUM])
1441 {
1442     for (auto& t : threads) {
1443         t.join();
1444     }
1445 }
1446 
CheckFullQueueStatus(std::array<DemoThreadData,THREAD_NUM> & demoDatas,unsigned int & pushedIn,unsigned int & unpushedIn,unsigned int & getedOut,unsigned int & ungetedOut)1447 static void CheckFullQueueStatus(std::array<DemoThreadData, THREAD_NUM>& demoDatas, unsigned int& pushedIn,
1448     unsigned int& unpushedIn, unsigned int& getedOut, unsigned int& ungetedOut)
1449 {
1450     ASSERT_TRUE(DemoThreadData::shareQueue.IsFull());
1451     GetThreadDatePushedStatus(demoDatas, pushedIn, unpushedIn);
1452     GetThreadDateGetedStatus(demoDatas, getedOut, ungetedOut);
1453     ASSERT_EQ(pushedIn, THREAD_NUM);
1454     ASSERT_EQ(getedOut, THREAD_NUM - QUEUE_SLOTS);
1455 }
1456 
1457 /*
1458  * @tc.name: testMutilthreadPutAndBlock001
1459  * @tc.desc: Multiple threads put until blocking runs, one thread gets, all threads finish running normally
1460  */
1461 HWTEST(AudioUtilsUnitTest, testMutilthreadPutAndBlock001, TestSize.Level0)
1462 {
1463     std::thread threads[THREAD_NUM];
1464 
1465     std::array<DemoThreadData, THREAD_NUM> demoDatas;
1466     demoDatas.fill(DemoThreadData());
1467 
1468     for (unsigned int i = 0; i < THREAD_NUM; i++) {
1469         threads[i] = std::thread(PutHandleThreadData, std::ref(demoDatas[i]), i);
1470     }
1471 
1472     // 1. queue is full and some threads is blocked
1473     std::this_thread::sleep_for(std::chrono::seconds(2));
1474     ASSERT_TRUE(DemoThreadData::shareQueue.IsFull());
1475 
1476     unsigned int pushedIn = 0, unpushedIn = 0, getedOut = 0, ungetedOut = 0;
1477     GetThreadDatePushedStatus(demoDatas, pushedIn, unpushedIn);
1478 
1479     ASSERT_EQ(pushedIn, QUEUE_SLOTS);
1480     ASSERT_EQ(unpushedIn, THREAD_NUM - QUEUE_SLOTS);
1481 
1482     // 2. get one out  and wait some put in
1483     for (unsigned int i = 0; i < THREAD_NUM - QUEUE_SLOTS; i++) {
1484         demoDatas[0].Get();
1485     }
1486 
1487     std::this_thread::sleep_for(std::chrono::seconds(2));
1488     // queue is full and some threads is blocked and is not joined
1489     CheckFullQueueStatus(demoDatas, pushedIn, unpushedIn, getedOut, ungetedOut);
1490     ThreadsJoin(threads);
1491 
1492     while (!DemoThreadData::shareQueue.IsEmpty()) {
1493         demoDatas[0].Get();
1494     }
1495 
1496     // here means all thread end ok or if some operation blocked and the testcase blocked
1497 }
1498 
GetTimeAddTwoSeconds()1499 static std::time_t GetTimeAddTwoSeconds()
1500 {
1501     using std::chrono::system_clock;
1502     std::time_t timeT = system_clock::to_time_t(system_clock::now());
1503     cout << "start time: " << timeT << endl;
1504     const int twoSec = 2;
1505     timeT += twoSec;
1506     return timeT;
1507 }
1508 
1509 /*
1510  * @tc.name: testMutilthreadConcurrentPutAndBlockInblankqueue001
1511  * @tc.desc: Multi-threaded put() on the empty queue. When n threads are waiting to reach a certain
1512  * time-point, everyone puts concurrent to see the status of the queue and the state of the thread.
1513  */
1514 HWTEST(AudioUtilsUnitTest, testMutilthreadConcurrentPutAndBlockInblankqueue001, TestSize.Level0)
1515 {
1516     // 1. prepare
1517     std::thread threads[THREAD_NUM];
1518     std::array<DemoThreadData, THREAD_NUM> demoDatas;
1519     demoDatas.fill(DemoThreadData());
1520 
1521     using std::chrono::system_clock;
1522 
1523     std::time_t timeT = GetTimeAddTwoSeconds();
1524     // 2. start thread
1525     ASSERT_TRUE(DemoThreadData::shareQueue.IsEmpty());
1526     for (unsigned int i = 0; i < THREAD_NUM; i++) {
1527         threads[i] = std::thread(PutHandleThreadDataTime, std::ref(demoDatas[i]), i, system_clock::from_time_t(timeT));
1528     }
1529 
1530     // 1. queue is full and some threads is blocked
1531     std::this_thread::sleep_for(std::chrono::seconds(4));
1532     ASSERT_TRUE(DemoThreadData::shareQueue.IsFull());
1533 
1534     unsigned int pushedIn = 0;
1535     unsigned int unpushedIn = 0;
1536     unsigned int getedOut = 0;
1537     unsigned int ungetedOut = 0;
1538     GetThreadDatePushedStatus(demoDatas, pushedIn, unpushedIn);
1539 
1540     ASSERT_EQ(pushedIn, QUEUE_SLOTS);
1541     ASSERT_EQ(unpushedIn, THREAD_NUM - QUEUE_SLOTS);
1542 
1543     // 2. get one out  and wait some put in
1544     for (unsigned int i = 0; i < THREAD_NUM - QUEUE_SLOTS; i++) {
1545         demoDatas[0].Get();
1546     }
1547 
1548     std::this_thread::sleep_for(std::chrono::seconds(2));
1549     // queue is full and some threads is blocked and is not joined
1550     CheckFullQueueStatus(demoDatas, pushedIn, unpushedIn, getedOut, ungetedOut);
1551     ThreadsJoin(threads);
1552 
1553     while (!DemoThreadData::shareQueue.IsEmpty()) {
1554         demoDatas[0].Get();
1555     }
1556     // here means all thread end ok or if some operation blocked and the testcase blocked
1557 }
1558 
QueuePushInfull()1559 static void QueuePushInfull()
1560 {
1561     for (unsigned int i = 0; i < QUEUE_SLOTS; i++) {
1562         int t = i;
1563         DemoThreadData::shareQueue.Push(t);
1564     }
1565 }
1566 
QueuePushInnotfull(const unsigned int remain)1567 static void QueuePushInnotfull(const unsigned int remain)
1568 {
1569     for (unsigned int i = 0; i < QUEUE_SLOTS - remain; i++) {
1570         int t = i;
1571         DemoThreadData::shareQueue.Push(t);
1572     }
1573 }
1574 
1575 /*
1576  * @tc.name: testMutilthreadConcurrentPutAndBlockInfullqueue001
1577  * @tc.desc: Multi-threaded put() on the full queue. When n threads are waiting to reach a certain
1578  * time-point, everyone puts concurrent to see the status of the queue and the state of the thread.
1579  */
1580 HWTEST(AudioUtilsUnitTest, testMutilthreadConcurrentPutAndBlockInfullqueue001, TestSize.Level0)
1581 {
1582     // 1. prepare
1583     std::thread threads[THREAD_NUM];
1584     std::array<DemoThreadData, THREAD_NUM> demoDatas;
1585     demoDatas.fill(DemoThreadData());
1586 
1587     using std::chrono::system_clock;
1588 
1589     std::time_t timeT = GetTimeAddTwoSeconds();
1590     ASSERT_TRUE(DemoThreadData::shareQueue.IsEmpty());
1591     QueuePushInfull();
1592     ASSERT_TRUE(DemoThreadData::shareQueue.IsFull());
1593 
1594     // 2. start thread put in full queue
1595     for (unsigned int i = 0; i < THREAD_NUM; i++) {
1596         threads[i] = std::thread(PutHandleThreadDataTime, std::ref(demoDatas[i]), i, system_clock::from_time_t(timeT));
1597     }
1598 
1599     std::this_thread::sleep_for(std::chrono::seconds(3));
1600     // 3. now thread is running and all is blocked
1601     unsigned int pushedIn = 0;
1602     unsigned int unpushedIn = 0;
1603     GetThreadDatePushedStatus(demoDatas, pushedIn, unpushedIn);
1604     ASSERT_EQ(pushedIn, static_cast<unsigned int>(0));
1605     ASSERT_EQ(unpushedIn, THREAD_NUM);
1606     ASSERT_TRUE(DemoThreadData::shareQueue.IsFull());
1607     for (unsigned int i = 0; i < THREAD_NUM; i++) {
1608         cout << "get out one and then the queue is full" << endl;
1609         DemoThreadData::shareQueue.Pop();
1610         std::this_thread::sleep_for(std::chrono::seconds(1));
1611         ASSERT_TRUE(DemoThreadData::shareQueue.IsFull());
1612         GetThreadDatePushedStatus(demoDatas, pushedIn, unpushedIn);
1613         ASSERT_EQ(pushedIn, i + 1);
1614         ASSERT_EQ(unpushedIn, THREAD_NUM - (i + 1));
1615     }
1616 
1617     ThreadsJoin(threads);
1618     while (!DemoThreadData::shareQueue.IsEmpty()) {
1619         demoDatas[0].Get();
1620     }
1621 }
1622 
1623 /*
1624  * @tc.name: testMutilthreadConcurrentGetAndBlockInblankqueue001
1625  * @tc.desc: Multi-threaded get() on the empty queue. When n threads are waiting to reach a certain
1626  * time-point, everyone gets concurrent to see the status of the queue and the state of the thread.
1627  */
1628 HWTEST(AudioUtilsUnitTest, testMutilthreadConcurrentGetAndBlockInblankqueue001, TestSize.Level0)
1629 {
1630     // 1. prepare
1631     std::thread threads[THREAD_NUM];
1632     std::array<DemoThreadData, THREAD_NUM> demoDatas;
1633     demoDatas.fill(DemoThreadData());
1634 
1635     using std::chrono::system_clock;
1636 
1637     std::time_t timeT = GetTimeAddTwoSeconds();
1638     ASSERT_TRUE(DemoThreadData::shareQueue.IsEmpty());
1639 
1640     // 2. start thread put in empty queue
1641     for (unsigned int i = 0; i < THREAD_NUM; i++) {
1642         threads[i] = std::thread(GetHandleThreadDataTime,
1643             std::ref(demoDatas[i]), i, system_clock::from_time_t(timeT));
1644     }
1645     std::this_thread::sleep_for(std::chrono::seconds(3));
1646 
1647     // 3. now thread is running and all is blocked
1648     unsigned int getedOut = 0;
1649     unsigned int ungetedOut = 0;
1650     GetThreadDateGetedStatus(demoDatas, getedOut, ungetedOut);
1651     ASSERT_EQ(getedOut, static_cast<unsigned int>(0));
1652     ASSERT_EQ(ungetedOut, THREAD_NUM);
1653     ASSERT_TRUE(DemoThreadData::shareQueue.IsEmpty());
1654 
1655     int value = 1;
1656 
1657     for (unsigned int i = 0; i < THREAD_NUM; i++) {
1658         cout << "put in one and then the queue is empty" << endl;
1659         DemoThreadData::shareQueue.Push(value);
1660         std::this_thread::sleep_for(std::chrono::seconds(1));
1661         ASSERT_TRUE(DemoThreadData::shareQueue.IsEmpty());
1662         GetThreadDateGetedStatus(demoDatas, getedOut, ungetedOut);
1663         ASSERT_EQ(getedOut, i + 1);
1664         ASSERT_EQ(ungetedOut, THREAD_NUM - (i + 1));
1665     }
1666 
1667     ThreadsJoin(threads);
1668     while (!DemoThreadData::shareQueue.IsEmpty()) {
1669         demoDatas[0].Get();
1670     }
1671 }
1672 /*
1673  * @tc.name: testMutilthreadConcurrentGetAndBlockInfullqueue001
1674  * @tc.desc: Multi-threaded get() on the full queue. When n threads are waiting to reach a certain
1675  * time-point, everyone gets concurrent to see the status of the queue and the state of the thread.
1676  */
1677 HWTEST(AudioUtilsUnitTest, testMutilthreadConcurrentGetAndBlockInfullqueue001, TestSize.Level0)
1678 {
1679     // 1. prepare
1680     std::thread threads[THREAD_NUM];
1681     std::array<DemoThreadData, THREAD_NUM> demoDatas;
1682     demoDatas.fill(DemoThreadData());
1683 
1684     using std::chrono::system_clock;
1685 
1686     std::time_t timeT = GetTimeAddTwoSeconds();
1687     ASSERT_TRUE(DemoThreadData::shareQueue.IsEmpty());
1688     int t = 1;
1689     for (unsigned int i = 0; i < QUEUE_SLOTS; i++) {
1690         DemoThreadData::shareQueue.Push(t);
1691     }
1692     ASSERT_TRUE(DemoThreadData::shareQueue.IsFull());
1693 
1694     // 2. start thread put in full queue
1695     for (unsigned int i = 0; i < THREAD_NUM; i++) {
1696         threads[i] = std::thread(GetHandleThreadDataTime, std::ref(demoDatas[i]), i, system_clock::from_time_t(timeT));
1697     }
1698 
1699     std::this_thread::sleep_for(std::chrono::seconds(4));
1700     // 3. start judge
1701     ASSERT_TRUE(DemoThreadData::shareQueue.IsEmpty());
1702 
1703     unsigned int getedOut = 0;
1704     unsigned int ungetedOut = 0;
1705     GetThreadDateGetedStatus(demoDatas, getedOut, ungetedOut);
1706 
1707     ASSERT_EQ(getedOut, QUEUE_SLOTS);
1708     ASSERT_EQ(ungetedOut, THREAD_NUM - QUEUE_SLOTS);
1709 
1710     // 2.  put one in  and wait some get out
1711     for (unsigned int i = 0; i < THREAD_NUM - QUEUE_SLOTS; i++) {
1712         demoDatas[0].Put(t);
1713     }
1714 
1715     std::this_thread::sleep_for(std::chrono::seconds(2));
1716     // queue is full and some threads is blocked and is not joined
1717     ASSERT_TRUE(DemoThreadData::shareQueue.IsEmpty());
1718     GetThreadDateGetedStatus(demoDatas, getedOut, ungetedOut);
1719     ASSERT_EQ(getedOut, THREAD_NUM);
1720     ASSERT_EQ(ungetedOut, static_cast<unsigned int>(0));
1721 
1722     ThreadsJoin(threads);
1723     while (!DemoThreadData::shareQueue.IsEmpty()) {
1724         demoDatas[0].Get();
1725     }
1726 }
1727 
1728 /*
1729  * @tc.name: testMutilthreadConcurrentGetAndBlockInnotfullqueue001
1730  * @tc.desc: Multi-threaded get() on the notfull queue. When n threads are waiting to reach a certain
1731  * time-point, everyone get concurrent to see the status of the queue and the state of the thread.
1732  */
1733 HWTEST(AudioUtilsUnitTest, testMutilthreadConcurrentGetAndBlockInnotfullqueue001, TestSize.Level0)
1734 {
1735     // 1. prepare
1736     std::thread threads[THREAD_NUM];
1737     std::array<DemoThreadData, THREAD_NUM> demoDatas;
1738     demoDatas.fill(DemoThreadData());
1739 
1740     using std::chrono::system_clock;
1741 
1742     const unsigned int REMAIN_SLOTS = 5;
1743     std::time_t timeT = GetTimeAddTwoSeconds();
1744     ASSERT_TRUE(DemoThreadData::shareQueue.IsEmpty());
1745     QueuePushInnotfull(REMAIN_SLOTS);
1746 
1747     // 2. start thread put in not full queue
1748     for (unsigned int i = 0; i < THREAD_NUM; i++) {
1749         threads[i] = std::thread(GetHandleThreadDataTime,
1750             std::ref(demoDatas[i]), i, system_clock::from_time_t(timeT));
1751     }
1752 
1753     std::this_thread::sleep_for(std::chrono::seconds(3));
1754 
1755     unsigned int getedOut = 0;
1756     unsigned int ungetedOut = 0;
1757     GetThreadDateGetedStatus(demoDatas, getedOut, ungetedOut);
1758     ASSERT_EQ(getedOut, QUEUE_SLOTS - REMAIN_SLOTS);
1759     ASSERT_EQ(ungetedOut, THREAD_NUM - (QUEUE_SLOTS - REMAIN_SLOTS));
1760 
1761     // 3. put ungetedOut
1762     for (unsigned int i = 0; i < ungetedOut; i++) {
1763         int t = i;
1764         DemoThreadData::shareQueue.Push(t);
1765     }
1766 
1767     std::this_thread::sleep_for(std::chrono::seconds(1));
1768     GetThreadDateGetedStatus(demoDatas, getedOut, ungetedOut);
1769     ASSERT_EQ(getedOut, THREAD_NUM);
1770     ASSERT_EQ(ungetedOut, static_cast<unsigned int>(0));
1771 
1772     ThreadsJoin(threads);
1773     while (!DemoThreadData::shareQueue.IsEmpty()) {
1774         demoDatas[0].Get();
1775     }
1776 }
1777 
1778 /*
1779  * @tc.name: testMutilthreadConcurrentPutAndBlockInnotfullqueue001
1780  * @tc.desc: Multi-threaded put() on the not full queue. When n threads are waiting to reach a certain
1781  * time-point, everyone puts concurrent to see the status of the queue and the state of the thread.
1782  */
1783 HWTEST(AudioUtilsUnitTest, testMutilthreadConcurrentPutAndBlockInnotfullqueue001, TestSize.Level0)
1784 {
1785     // 1. prepare
1786     std::thread threads[THREAD_NUM];
1787     std::array<DemoThreadData, THREAD_NUM> demoDatas;
1788     demoDatas.fill(DemoThreadData());
1789 
1790     using std::chrono::system_clock;
1791 
1792     const unsigned int REMAIN_SLOTS = 5;
1793     std::time_t timeT = GetTimeAddTwoSeconds();
1794     ASSERT_TRUE(DemoThreadData::shareQueue.IsEmpty());
1795     QueuePushInnotfull(REMAIN_SLOTS);
1796 
1797     // 2. start thread put in not full queue
1798     for (unsigned int i = 0; i < THREAD_NUM; i++) {
1799         threads[i] = std::thread(PutHandleThreadDataTime,
1800             std::ref(demoDatas[i]), i, system_clock::from_time_t(timeT));
1801     }
1802 
1803     std::this_thread::sleep_for(std::chrono::seconds(3));
1804 
1805     unsigned int putedin = 0;
1806     unsigned int unputedin = 0;
1807     GetThreadDatePushedStatus(demoDatas, putedin, unputedin);
1808     ASSERT_EQ(putedin, REMAIN_SLOTS);
1809     ASSERT_EQ(unputedin, THREAD_NUM - REMAIN_SLOTS);
1810 
1811     // 3. put ungetedOut
1812     for (unsigned int i = 0; i < unputedin; i++) {
1813         DemoThreadData::shareQueue.Pop();
1814     }
1815 
1816     std::this_thread::sleep_for(std::chrono::seconds(1));
1817     GetThreadDatePushedStatus(demoDatas, putedin, unputedin);
1818     ASSERT_EQ(putedin, THREAD_NUM);
1819     ASSERT_EQ(unputedin, static_cast<unsigned int>(0));
1820 
1821     ThreadsJoin(threads);
1822     while (!DemoThreadData::shareQueue.IsEmpty()) {
1823         demoDatas[0].Get();
1824     }
1825 }
1826 
CheckQueueStatus(std::array<DemoThreadData,THREAD_NUM> & demoDatas)1827 static void CheckQueueStatus(std::array<DemoThreadData, THREAD_NUM>& demoDatas)
1828 {
1829     unsigned int getedOut = 0;
1830     unsigned int ungetedOut = 0;
1831     unsigned int pushedIn = 0;
1832     unsigned int unpushedIn = 0;
1833     GetThreadDateGetedStatus(demoDatas, getedOut, ungetedOut);
1834     GetThreadDatePushedStatus(demoDatas, pushedIn, unpushedIn);
1835 
1836     ASSERT_EQ(pushedIn, THREAD_NUM);
1837     ASSERT_EQ(getedOut, THREAD_NUM);
1838 }
1839 
1840 /*
1841  * @tc.name: testMutilthreadConcurrentGetAndPopInblankqueue001
1842  * @tc.desc: Multi-threaded put() and Multi-threaded get() on the empty queue. When all threads are waiting to reach
1843  * a certain time-point, everyone run concurrently to see the status of the queue and the state of the thread.
1844  */
1845 HWTEST(AudioUtilsUnitTest, testMutilthreadConcurrentGetAndPopInblankqueue001, TestSize.Level0)
1846 {
1847     // 1. prepare
1848     std::thread threadsout[THREAD_NUM];
1849     std::array<DemoThreadData, THREAD_NUM> demoDatas;
1850     demoDatas.fill(DemoThreadData());
1851 
1852     std::thread threadsin[THREAD_NUM];
1853 
1854     using std::chrono::system_clock;
1855 
1856     std::time_t timeT = GetTimeAddTwoSeconds();
1857     ASSERT_TRUE(DemoThreadData::shareQueue.IsEmpty());
1858 
1859     // 2. start thread put and get in empty queue
1860 
1861     for (unsigned int i = 0; i < THREAD_NUM; i++) {
1862         threadsout[i] = std::thread(GetHandleThreadDataTime,
1863             std::ref(demoDatas[i]), i, system_clock::from_time_t(timeT));
1864     }
1865 
1866     for (unsigned int i = 0; i < THREAD_NUM; i++) {
1867         threadsin[i] = std::thread(PutHandleThreadDataTime,
1868             std::ref(demoDatas[i]), i, system_clock::from_time_t(timeT));
1869     }
1870 
1871     std::this_thread::sleep_for(std::chrono::seconds(3));
1872 
1873     ASSERT_TRUE(DemoThreadData::shareQueue.IsEmpty());
1874     CheckQueueStatus(demoDatas);
1875 
1876     ThreadsJoin(threadsout);
1877     ThreadsJoin(threadsin);
1878 
1879     while (!DemoThreadData::shareQueue.IsEmpty()) {
1880         demoDatas[0].Get();
1881     }
1882 }
1883 
1884 /*
1885  * @tc.name: testMutilthreadConcurrentGetAndPopInfullqueue001
1886  * @tc.desc: Multi-threaded put() and Multi-threaded get() on the full queue.
1887  * When all threads are waiting to reach a certain
1888  * time-point, everyone run concurrently to see the status of the queue and the state of the thread.
1889  */
1890 HWTEST(AudioUtilsUnitTest, testMutilthreadConcurrentGetAndPopInfullqueue001, TestSize.Level0)
1891 {
1892     // 1. prepare
1893     std::thread threadsout[THREAD_NUM];
1894     std::array<DemoThreadData, THREAD_NUM> demoDatas;
1895     demoDatas.fill(DemoThreadData());
1896 
1897     std::thread threadsin[THREAD_NUM];
1898 
1899     using std::chrono::system_clock;
1900 
1901     std::time_t timeT = GetTimeAddTwoSeconds();
1902     ASSERT_TRUE(DemoThreadData::shareQueue.IsEmpty());
1903     int t = 1;
1904     for (unsigned int i = 0; i < QUEUE_SLOTS; i++) {
1905         DemoThreadData::shareQueue.Push(t);
1906     }
1907     ASSERT_TRUE(DemoThreadData::shareQueue.IsFull());
1908     // 2. start thread put in not full queue
1909     for (unsigned int i = 0; i < THREAD_NUM; i++) {
1910         threadsin[i] = std::thread(PutHandleThreadDataTime,
1911             std::ref(demoDatas[i]), i, system_clock::from_time_t(timeT));
1912     }
1913 
1914     for (unsigned int i = 0; i < THREAD_NUM; i++) {
1915         threadsout[i] = std::thread(GetHandleThreadDataTime,
1916             std::ref(demoDatas[i]), i, system_clock::from_time_t(timeT));
1917     }
1918 
1919     std::this_thread::sleep_for(std::chrono::seconds(3));
1920 
1921     ASSERT_TRUE(DemoThreadData::shareQueue.IsFull());
1922     CheckQueueStatus(demoDatas);
1923 
1924     ThreadsJoin(threadsout);
1925     ThreadsJoin(threadsin);
1926 
1927     while (!DemoThreadData::shareQueue.IsEmpty()) {
1928         demoDatas[0].Get();
1929     }
1930 }
1931 
1932 /**
1933  * @tc.name  : Test AudioBlend  API
1934  * @tc.type  : FUNC
1935  * @tc.number: AudioBlend_001
1936  * @tc.desc  : Test AudioBlend Process API
1937  */
1938 HWTEST(AudioUtilsUnitTest, AudioBlend_001, TestSize.Level1)
1939 {
1940     shared_ptr<AudioBlend> audioBlend = std::make_shared<AudioBlend>(MODE_DEFAULT, SAMPLE_U8, MONO);
1941     EXPECT_EQ(audioBlend->blendMode_, MODE_DEFAULT);
1942 
1943     audioBlend->SetParams(MODE_BLEND_LR, SAMPLE_U8, MONO);
1944     EXPECT_EQ(audioBlend->blendMode_, MODE_BLEND_LR);
1945 }
1946 
1947 /**
1948  * @tc.name  : Test Process API
1949  * @tc.type  : FUNC
1950  * @tc.number: audio_channel_blend_001
1951  * @tc.desc  : Test AudioBlend Process API,Return buffer
1952  *             when blendMode is channel 0
1953  */
1954 HWTEST(AudioUtilsUnitTest, audio_channel_blend_001, TestSize.Level1)
1955 {
1956     uint8_t b[8] = {2, 4, 6, 8, 10, 12, 14, 16};
1957     uint8_t format = 0;
1958     uint8_t channels = 0;
1959     shared_ptr<AudioBlend> audioBlend = std::make_shared<AudioBlend>(MODE_DEFAULT, format, channels);
1960     audioBlend->Process(b, 8);
1961     EXPECT_EQ(b[0], 2);
1962 }
1963 
1964 /**
1965  * @tc.name  : Test audio_channel_blend API
1966  * @tc.type  : FUNC
1967  * @tc.number: audio_channel_blend_002
1968  * @tc.desc  : Test AudioBlend Process API,Return buffer
1969  *             when blendMode is MODE_BLEND_LR,channel 8
1970  */
1971 HWTEST(AudioUtilsUnitTest, audio_channel_blend_002, TestSize.Level1)
1972 {
1973     uint8_t b[8] = {2, 4, 6, 8, 10, 12, 14, 16};
1974     uint8_t format = SAMPLE_U8;
1975     uint8_t channels = CHANNEL_8;
1976     ChannelBlendMode blendMode = MODE_BLEND_LR;
1977     shared_ptr<AudioBlend> audioBlend = std::make_shared<AudioBlend>(blendMode, format, channels);
1978     audioBlend->Process(b, 8);
1979     EXPECT_EQ(b[7], 15);
1980     EXPECT_EQ(b[5], 11);
1981     EXPECT_EQ(b[1], 3);
1982 }
1983 
1984 /**
1985  * @tc.name  : Test audio_channel_blend API
1986  * @tc.type  : FUNC
1987  * @tc.number: audio_channel_blend_003
1988  * @tc.desc  : Test AudioBlend Process API,Return buffer
1989  *             when blendMode is MODE_BLEND_LR,channel 6
1990  */
1991 HWTEST(AudioUtilsUnitTest, audio_channel_blend_003, TestSize.Level1)
1992 {
1993     uint8_t b[8] = {2, 4, 6, 8, 10, 12, 14, 16};
1994     uint8_t format = SAMPLE_U8;
1995     uint8_t channels = CHANNEL_6;
1996     ChannelBlendMode blendMode = MODE_BLEND_LR;
1997     shared_ptr<AudioBlend> audioBlend = std::make_shared<AudioBlend>(blendMode, format, channels);
1998     audioBlend->Process(b, 8);
1999     EXPECT_EQ(b[5], 11);
2000     EXPECT_EQ(b[1], 3);
2001 }
2002 
2003 /**
2004  * @tc.name  : Test audio_channel_blend API
2005  * @tc.type  : FUNC
2006  * @tc.number: audio_channel_blend_004
2007  * @tc.desc  : Test AudioBlend Process API,Return buffer
2008  *             when blendMode is MODE_BLEND_LR,channel 4
2009  */
2010 HWTEST(AudioUtilsUnitTest, audio_channel_blend_004, TestSize.Level1)
2011 {
2012     uint8_t b[8] = {2, 4, 6, 8, 10, 12, 14, 16};
2013     uint8_t format = SAMPLE_S16LE;
2014     uint8_t channels = CHANNEL_4;
2015     ChannelBlendMode blendMode = MODE_BLEND_LR;
2016     shared_ptr<AudioBlend> audioBlend = std::make_shared<AudioBlend>(blendMode, format, channels);
2017     audioBlend->Process(b, 8);
2018     EXPECT_EQ(b[3], 6);
2019     EXPECT_EQ(b[1], 6);
2020 }
2021 
2022 /**
2023  * @tc.name  : Test audio_channel_blend API
2024  * @tc.type  : FUNC
2025  * @tc.number: audio_channel_blend_005
2026  * @tc.desc  : Test AudioBlend Process API,Return buffer
2027  *             when blendMode is MODE_BLEND_LR,STEREO
2028  */
2029 HWTEST(AudioUtilsUnitTest, audio_channel_blend_005, TestSize.Level1)
2030 {
2031     uint8_t b[8] = {2, 4, 6, 8, 10, 12, 14, 16};
2032     uint8_t format = SAMPLE_S32LE;
2033     uint8_t channels = STEREO;
2034     ChannelBlendMode blendMode = MODE_BLEND_LR;
2035     shared_ptr<AudioBlend> audioBlend = std::make_shared<AudioBlend>(blendMode, format, channels);
2036     audioBlend->Process(b, 4);
2037     EXPECT_EQ(b[1], 4);
2038 }
2039 
2040 /**
2041  * @tc.name  : Test audio_channel_blend API
2042  * @tc.type  : FUNC
2043  * @tc.number: audio_channel_blend_006
2044  * @tc.desc  : Test AudioBlend Process API,Return buffer
2045  *             when blendMode is MODE_ALL_LEFT,channel 8
2046  */
2047 HWTEST(AudioUtilsUnitTest, audio_channel_blend_006, TestSize.Level1)
2048 {
2049     uint8_t b[8] = {2, 4, 6, 8, 10, 12, 14, 16};
2050     uint8_t format = SAMPLE_U8;
2051     uint8_t channels = CHANNEL_8;
2052     ChannelBlendMode blendMode = MODE_ALL_LEFT;
2053     shared_ptr<AudioBlend> audioBlend = std::make_shared<AudioBlend>(blendMode, format, channels);
2054     audioBlend->Process(b, 8);
2055     EXPECT_EQ(b[7], 14);
2056     EXPECT_EQ(b[5], 10);
2057     EXPECT_EQ(b[1], 2);
2058 }
2059 
2060 /**
2061  * @tc.name  : Test audio_channel_blend API
2062  * @tc.type  : FUNC
2063  * @tc.number: audio_channel_blend_007
2064  * @tc.desc  : Test AudioBlend Process API,Return buffer
2065  *             when blendMode is MODE_ALL_LEFT,channel 6
2066  */
2067 HWTEST(AudioUtilsUnitTest, audio_channel_blend_007, TestSize.Level1)
2068 {
2069     uint8_t b[8] = {2, 4, 6, 8, 10, 12, 14, 16};
2070     uint8_t format = SAMPLE_U8;
2071     uint8_t channels = CHANNEL_6;
2072     ChannelBlendMode blendMode = MODE_ALL_LEFT;
2073     shared_ptr<AudioBlend> audioBlend = std::make_shared<AudioBlend>(blendMode, format, channels);
2074     audioBlend->Process(b, 8);
2075     EXPECT_EQ(b[5], 10);
2076     EXPECT_EQ(b[1], 2);
2077 }
2078 
2079 /**
2080  * @tc.name  : Test audio_channel_blend API
2081  * @tc.type  : FUNC
2082  * @tc.number: audio_channel_blend_008
2083  * @tc.desc  : Test AudioBlend Process API,Return buffer
2084  *             when blendMode is MODE_ALL_LEFT,channel 4
2085  */
2086 HWTEST(AudioUtilsUnitTest, audio_channel_blend_008, TestSize.Level1)
2087 {
2088     uint8_t b[8] = {2, 4, 6, 8, 10, 12, 14, 16};
2089     uint8_t format = SAMPLE_S16LE;
2090     uint8_t channels = CHANNEL_4;
2091     ChannelBlendMode blendMode = MODE_ALL_LEFT;
2092     shared_ptr<AudioBlend> audioBlend = std::make_shared<AudioBlend>(blendMode, format, channels);
2093     audioBlend->Process(b, 8);
2094     EXPECT_EQ(b[3], 4);
2095     EXPECT_EQ(b[1], 4);
2096 }
2097 
2098 /**
2099  * @tc.name  : Test audio_channel_blend API
2100  * @tc.type  : FUNC
2101  * @tc.number: audio_channel_blend_009
2102  * @tc.desc  : Test AudioBlend Process API,Return buffer
2103  *             when blendMode is MODE_ALL_LEFT,STEREO
2104  */
2105 HWTEST(AudioUtilsUnitTest, audio_channel_blend_009, TestSize.Level1)
2106 {
2107     uint8_t b[8] = {2, 4, 6, 8, 10, 12, 14, 16};
2108     uint8_t format = SAMPLE_S32LE;
2109     uint8_t channels = STEREO;
2110     ChannelBlendMode blendMode = MODE_ALL_LEFT;
2111     shared_ptr<AudioBlend> audioBlend = std::make_shared<AudioBlend>(blendMode, format, channels);
2112     audioBlend->Process(b, 8);
2113     EXPECT_EQ(b[1], 4);
2114 }
2115 
2116 /**
2117  * @tc.name  : Test audio_channel_blend API
2118  * @tc.type  : FUNC
2119  * @tc.number: audio_channel_blend_010
2120  * @tc.desc  : Test AudioBlend Process API,Return buffer
2121  *             when blendMode is MODE_ALL_RIGHT,channel 8
2122  */
2123 HWTEST(AudioUtilsUnitTest, audio_channel_blend_010, TestSize.Level1)
2124 {
2125     uint8_t b[8] = {2, 4, 6, 8, 10, 12, 14, 16};
2126     uint8_t format = SAMPLE_S16LE;
2127     uint8_t channels = CHANNEL_8;
2128     ChannelBlendMode blendMode = MODE_ALL_LEFT;
2129     shared_ptr<AudioBlend> audioBlend = std::make_shared<AudioBlend>(blendMode, format, channels);
2130     audioBlend->Process(b, 8);
2131     EXPECT_EQ(b[6], 14);
2132 }
2133 
2134 /**
2135  * @tc.name  : Test audio_channel_blend  API
2136  * @tc.type  : FUNC
2137  * @tc.number: audio_channel_blend_011
2138  * @tc.desc  : Test AudioBlend Process API,Return buffer
2139  *             when blendMode is MODE_ALL_RIGHT,channel 6
2140  */
2141 HWTEST(AudioUtilsUnitTest, audio_channel_blend_011, TestSize.Level1)
2142 {
2143     uint8_t b[8] = {2, 4, 6, 8, 10, 12, 14, 16};
2144     uint8_t format = SAMPLE_S24LE;
2145     uint8_t channels = CHANNEL_6;
2146     ChannelBlendMode blendMode = MODE_ALL_RIGHT;
2147     shared_ptr<AudioBlend> audioBlend = std::make_shared<AudioBlend>(blendMode, format, channels);
2148     audioBlend->Process(b, 8);
2149     EXPECT_EQ(b[0], 2);
2150 }
2151 
2152 /**
2153  * @tc.name  : Test audio_channel_blend API
2154  * @tc.type  : FUNC
2155  * @tc.number: audio_channel_blend_012
2156  * @tc.desc  : Test AudioBlend Process API,Return buffer
2157  *             when blendMode is MODE_ALL_RIGHT,STEREO
2158  */
2159 HWTEST(AudioUtilsUnitTest, audio_channel_blend_012, TestSize.Level1)
2160 {
2161     uint8_t b[8] = {2, 4, 6, 8, 10, 12, 14, 16};
2162     uint8_t format = SAMPLE_S32LE;
2163     uint8_t channels = CHANNEL_4;
2164     ChannelBlendMode blendMode = MODE_ALL_RIGHT;
2165     shared_ptr<AudioBlend> audioBlend = std::make_shared<AudioBlend>(blendMode, format, channels);
2166     audioBlend->Process(b, 8);
2167     EXPECT_EQ(b[2], 6);
2168     EXPECT_EQ(b[0], 2);
2169 }
2170 
2171 /**
2172  * @tc.name  : Test audio_channel_blend  API
2173  * @tc.type  : FUNC
2174  * @tc.number: audio_channel_blend_013
2175  * @tc.desc  : Test AudioBlend Process API,Return buffer
2176  *             when blendMode is MODE_ALL_RIGHT,STEREO
2177  */
2178 HWTEST(AudioUtilsUnitTest, audio_channel_blend_013, TestSize.Level1)
2179 {
2180     uint8_t b[8] = {2, 4, 6, 8, 10, 12, 14, 16};
2181     uint8_t format = SAMPLE_S24LE;
2182     uint8_t channels = CHANNEL_3;
2183     ChannelBlendMode blendMode = MODE_ALL_RIGHT;
2184     shared_ptr<AudioBlend> audioBlend = std::make_shared<AudioBlend>(blendMode, format, channels);
2185     audioBlend->Process(b, 8);
2186     EXPECT_EQ(b[0], 2);
2187 }
2188 
2189 /**
2190  * @tc.name  : Test audio_channel_blend API
2191  * @tc.type  : FUNC
2192  * @tc.number: audio_channel_blend_014
2193  * @tc.desc  : Test AudioBlend Process API,Return buffer
2194  *             when channel is 0 or blendMode is MODE_DEFAULT
2195  */
2196 HWTEST(AudioUtilsUnitTest, audio_channel_blend_014, TestSize.Level1)
2197 {
2198     uint8_t buffer1[8] = {2, 4, 6, 8, 10, 12, 14, 16};
2199     uint8_t buffer2[16] = {0, 2, 0, 4, 0, 6, 0, 8, 0, 10, 0, 12, 0, 14, 0, 16};
2200     uint8_t buffer3[24] = {0, 0, 2, 0, 0, 4, 0, 0, 6, 0, 0, 8, 0, 0, 10, 0, 0, 12, 0, 0, 14, 0, 0, 16};
2201     uint8_t buffer4[32] =
2202         {0, 0, 0, 2, 0, 0, 0, 4, 0, 0, 0, 6, 0, 0, 0, 8, 0, 0, 0, 10, 0, 0, 0, 12, 0, 0, 0, 14, 0, 0, 0, 16};
2203     shared_ptr<AudioBlend> audioBlend = std::make_shared<AudioBlend>(MODE_DEFAULT, SAMPLE_S24LE, 0);
2204     audioBlend->ProcessWithBlendMode<uint8_t>(reinterpret_cast<uint8_t*>(buffer1), 8);
2205     EXPECT_EQ(buffer1[0], 2);
2206 
2207     audioBlend->ProcessWithBlendMode<int16_t>(reinterpret_cast<int16_t*>(buffer2), 8);
2208     EXPECT_EQ(buffer2[1], 2);
2209 
2210     audioBlend->ProcessWithBlendMode<int24_t>(reinterpret_cast<int24_t*>(buffer3), 8);
2211     EXPECT_EQ(buffer3[2], 2);
2212 
2213     audioBlend->ProcessWithBlendMode<int32_t>(reinterpret_cast<int32_t*>(buffer4), 8);
2214     EXPECT_EQ(buffer4[3], 2);
2215 
2216     audioBlend->SetParams(MODE_DEFAULT, SAMPLE_S24LE, 1);
2217     audioBlend->ProcessWithBlendMode<uint8_t>(reinterpret_cast<uint8_t*>(buffer1), 8);
2218     EXPECT_EQ(buffer1[0], 2);
2219 
2220     audioBlend->ProcessWithBlendMode<int16_t>(reinterpret_cast<int16_t*>(buffer2), 8);
2221     EXPECT_EQ(buffer2[1], 2);
2222 
2223     audioBlend->ProcessWithBlendMode<int24_t>(reinterpret_cast<int24_t*>(buffer3), 8);
2224     EXPECT_EQ(buffer3[2], 2);
2225 
2226     audioBlend->ProcessWithBlendMode<int32_t>(reinterpret_cast<int32_t*>(buffer4), 8);
2227     EXPECT_EQ(buffer4[3], 2);
2228 }
2229 
2230 /**
2231  * @tc.name  : Test audio_channel_blend API
2232  * @tc.type  : FUNC
2233  * @tc.number: audio_channel_blend_015
2234  * @tc.desc  : Test AudioBlend Process API,Return buffer
2235  *             when channel is 1, blendMode is MODE_BLEND_LR, MODE_ALL_LEFT or MODE_ALL_RIGHT.
2236  */
2237 HWTEST(AudioUtilsUnitTest, audio_channel_blend_015, TestSize.Level1)
2238 {
2239     uint8_t buffer1[8] = {2, 4, 6, 8, 10, 12, 14, 16};
2240     uint8_t buffer2[16] = {0, 2, 0, 4, 0, 6, 0, 8, 0, 10, 0, 12, 0, 14, 0, 16};
2241     uint8_t buffer3[24] = {0, 0, 2, 0, 0, 4, 0, 0, 6, 0, 0, 8, 0, 0, 10, 0, 0, 12, 0, 0, 14, 0, 0, 16};
2242     uint8_t buffer4[32] =
2243         {0, 0, 0, 2, 0, 0, 0, 4, 0, 0, 0, 6, 0, 0, 0, 8, 0, 0, 0, 10, 0, 0, 0, 12, 0, 0, 0, 14, 0, 0, 0, 16};
2244     shared_ptr<AudioBlend> audioBlend = std::make_shared<AudioBlend>(MODE_BLEND_LR, SAMPLE_U8, 1);
2245     audioBlend->ProcessWithBlendMode<uint8_t>(reinterpret_cast<uint8_t*>(buffer1), 8);
2246     EXPECT_EQ(buffer1[0], 2);
2247 
2248     audioBlend->ProcessWithBlendMode<int16_t>(reinterpret_cast<int16_t*>(buffer2), 8);
2249     EXPECT_EQ(buffer2[1], 2);
2250 
2251     audioBlend->ProcessWithBlendMode<int24_t>(reinterpret_cast<int24_t*>(buffer3), 8);
2252     EXPECT_EQ(buffer3[2], 2);
2253 
2254     audioBlend->ProcessWithBlendMode<int32_t>(reinterpret_cast<int32_t*>(buffer4), 8);
2255     EXPECT_EQ(buffer4[3], 2);
2256 
2257     audioBlend->SetParams(MODE_ALL_LEFT, SAMPLE_U8, 1);
2258     audioBlend->ProcessWithBlendMode<uint8_t>(reinterpret_cast<uint8_t*>(buffer1), 8);
2259     EXPECT_EQ(buffer1[0], 2);
2260 
2261     audioBlend->ProcessWithBlendMode<int16_t>(reinterpret_cast<int16_t*>(buffer2), 8);
2262     EXPECT_EQ(buffer2[1], 2);
2263 
2264     audioBlend->ProcessWithBlendMode<int24_t>(reinterpret_cast<int24_t*>(buffer3), 8);
2265     EXPECT_EQ(buffer3[2], 2);
2266 
2267     audioBlend->ProcessWithBlendMode<int32_t>(reinterpret_cast<int32_t*>(buffer4), 8);
2268     EXPECT_EQ(buffer4[3], 2);
2269 
2270     audioBlend->SetParams(MODE_ALL_RIGHT, SAMPLE_U8, 1);
2271     audioBlend->ProcessWithBlendMode<uint8_t>(reinterpret_cast<uint8_t*>(buffer1), 8);
2272     EXPECT_EQ(buffer1[0], 2);
2273 
2274     audioBlend->ProcessWithBlendMode<int16_t>(reinterpret_cast<int16_t*>(buffer2), 8);
2275     EXPECT_EQ(buffer2[1], 2);
2276 
2277     audioBlend->ProcessWithBlendMode<int24_t>(reinterpret_cast<int24_t*>(buffer3), 8);
2278     EXPECT_EQ(buffer3[2], 2);
2279 
2280     audioBlend->ProcessWithBlendMode<int32_t>(reinterpret_cast<int32_t*>(buffer4), 8);
2281     EXPECT_EQ(buffer4[3], 2);
2282 }
2283 
2284 /**
2285  * @tc.name  : Test audio_channel_blend API
2286  * @tc.type  : FUNC
2287  * @tc.number: audio_channel_blend_016
2288  * @tc.desc  : Test AudioBlend Process API,Return buffer
2289  *             when channel is STEREO, blendMode is MODE_BLEND_LR, MODE_ALL_LEFT or MODE_ALL_RIGHT.
2290  */
2291 HWTEST(AudioUtilsUnitTest, audio_channel_blend_016, TestSize.Level1)
2292 {
2293     uint8_t buffer1[8] = {2, 4, 6, 8, 10, 12, 14, 16};
2294     uint8_t buffer2[16] = {0, 2, 0, 4, 0, 6, 0, 8, 0, 10, 0, 12, 0, 14, 0, 16};
2295     uint8_t buffer3[24] = {0, 0, 2, 0, 0, 4, 0, 0, 6, 0, 0, 8, 0, 0, 10, 0, 0, 12, 0, 0, 14, 0, 0, 16};
2296     uint8_t buffer4[32] =
2297         {0, 0, 0, 2, 0, 0, 0, 4, 0, 0, 0, 6, 0, 0, 0, 8, 0, 0, 0, 10, 0, 0, 0, 12, 0, 0, 0, 14, 0, 0, 0, 16};
2298     shared_ptr<AudioBlend> audioBlend = std::make_shared<AudioBlend>(MODE_BLEND_LR, 3, STEREO);
2299     audioBlend->ProcessWithBlendMode<uint8_t>(reinterpret_cast<uint8_t*>(buffer1), 8);
2300     EXPECT_EQ(buffer1[0], 3);
2301 
2302     audioBlend->ProcessWithBlendMode<int16_t>(reinterpret_cast<int16_t*>(buffer2), 8);
2303     EXPECT_EQ(buffer2[1], 3);
2304 
2305     audioBlend->ProcessWithBlendMode<int24_t>(reinterpret_cast<int24_t*>(buffer3), 8);
2306     EXPECT_EQ(buffer3[2], 3);
2307 
2308     audioBlend->ProcessWithBlendMode<int32_t>(reinterpret_cast<int32_t*>(buffer4), 8);
2309     EXPECT_EQ(buffer4[3], 3);
2310 
2311     audioBlend->SetParams(MODE_ALL_LEFT, 3, STEREO);
2312     audioBlend->ProcessWithBlendMode<uint8_t>(reinterpret_cast<uint8_t*>(buffer1), 8);
2313     EXPECT_EQ(buffer1[0], 3);
2314 
2315     audioBlend->ProcessWithBlendMode<int16_t>(reinterpret_cast<int16_t*>(buffer2), 8);
2316     EXPECT_EQ(buffer2[1], 3);
2317 
2318     audioBlend->ProcessWithBlendMode<int24_t>(reinterpret_cast<int24_t*>(buffer3), 8);
2319     EXPECT_EQ(buffer3[2], 3);
2320 
2321     audioBlend->ProcessWithBlendMode<int32_t>(reinterpret_cast<int32_t*>(buffer4), 8);
2322     EXPECT_EQ(buffer4[3], 3);
2323 
2324     audioBlend->SetParams(MODE_ALL_RIGHT, 3, STEREO);
2325     audioBlend->ProcessWithBlendMode<uint8_t>(reinterpret_cast<uint8_t*>(buffer1), 8);
2326     EXPECT_EQ(buffer1[0], 3);
2327 
2328     audioBlend->ProcessWithBlendMode<int16_t>(reinterpret_cast<int16_t*>(buffer2), 8);
2329     EXPECT_EQ(buffer2[1], 3);
2330 
2331     audioBlend->ProcessWithBlendMode<int24_t>(reinterpret_cast<int24_t*>(buffer3), 8);
2332     EXPECT_EQ(buffer3[2], 3);
2333 
2334     audioBlend->ProcessWithBlendMode<int32_t>(reinterpret_cast<int32_t*>(buffer4), 8);
2335     EXPECT_EQ(buffer4[3], 3);
2336 }
2337 
2338 /**
2339  * @tc.name  : Test audio_channel_blend API
2340  * @tc.type  : FUNC
2341  * @tc.number: audio_channel_blend_017
2342  * @tc.desc  : Test AudioBlend Process API,Return buffer
2343  *             when channel is CHANNEL_5, blendMode is MODE_BLEND_LR, MODE_ALL_LEFT or MODE_ALL_RIGHT.
2344  */
2345 HWTEST(AudioUtilsUnitTest, audio_channel_blend_017, TestSize.Level1)
2346 {
2347     uint8_t buffer1[8] = {2, 4, 6, 8, 10, 12, 14, 16};
2348     uint8_t buffer2[16] = {0, 2, 0, 4, 0, 6, 0, 8, 0, 10, 0, 12, 0, 14, 0, 16};
2349     uint8_t buffer3[24] = {0, 0, 2, 0, 0, 4, 0, 0, 6, 0, 0, 8, 0, 0, 10, 0, 0, 12, 0, 0, 14, 0, 0, 16};
2350     uint8_t buffer4[32] =
2351         {0, 0, 0, 2, 0, 0, 0, 4, 0, 0, 0, 6, 0, 0, 0, 8, 0, 0, 0, 10, 0, 0, 0, 12, 0, 0, 0, 14, 0, 0, 0, 16};
2352     shared_ptr<AudioBlend> audioBlend = std::make_shared<AudioBlend>(MODE_BLEND_LR, 0, CHANNEL_5);
2353     audioBlend->ProcessWithBlendMode<uint8_t>(reinterpret_cast<uint8_t*>(buffer1), 8);
2354     EXPECT_EQ(buffer1[2], 7);
2355 
2356     audioBlend->ProcessWithBlendMode<int16_t>(reinterpret_cast<int16_t*>(buffer2), 8);
2357     EXPECT_EQ(buffer2[5], 7);
2358 
2359     audioBlend->ProcessWithBlendMode<int24_t>(reinterpret_cast<int24_t*>(buffer3), 8);
2360     EXPECT_EQ(buffer3[8], 7);
2361 
2362     audioBlend->ProcessWithBlendMode<int32_t>(reinterpret_cast<int32_t*>(buffer4), 8);
2363     EXPECT_EQ(buffer4[11], 7);
2364 
2365     audioBlend->SetParams(MODE_ALL_LEFT, 0, CHANNEL_5);
2366     audioBlend->ProcessWithBlendMode<uint8_t>(reinterpret_cast<uint8_t*>(buffer1), 8);
2367     EXPECT_EQ(buffer1[2], 7);
2368 
2369     audioBlend->ProcessWithBlendMode<int16_t>(reinterpret_cast<int16_t*>(buffer2), 8);
2370     EXPECT_EQ(buffer2[5], 7);
2371 
2372     audioBlend->ProcessWithBlendMode<int24_t>(reinterpret_cast<int24_t*>(buffer3), 8);
2373     EXPECT_EQ(buffer3[8], 7);
2374 
2375     audioBlend->ProcessWithBlendMode<int32_t>(reinterpret_cast<int32_t*>(buffer4), 8);
2376     EXPECT_EQ(buffer4[11], 7);
2377 
2378     audioBlend->SetParams(MODE_ALL_RIGHT, 0, CHANNEL_5);
2379     audioBlend->ProcessWithBlendMode<uint8_t>(reinterpret_cast<uint8_t*>(buffer1), 8);
2380     EXPECT_EQ(buffer1[2], 7);
2381 
2382     audioBlend->ProcessWithBlendMode<int16_t>(reinterpret_cast<int16_t*>(buffer2), 8);
2383     EXPECT_EQ(buffer2[5], 7);
2384 
2385     audioBlend->ProcessWithBlendMode<int24_t>(reinterpret_cast<int24_t*>(buffer3), 8);
2386     EXPECT_EQ(buffer3[8], 7);
2387 
2388     audioBlend->ProcessWithBlendMode<int32_t>(reinterpret_cast<int32_t*>(buffer4), 8);
2389     EXPECT_EQ(buffer4[11], 7);
2390 }
2391 
2392 /**
2393  * @tc.name  : Test audio_channel_blend API
2394  * @tc.type  : FUNC
2395  * @tc.number: audio_channel_blend_017
2396  * @tc.desc  : Test AudioBlend Process API,Return buffer
2397  *             when channel is CHANNEL_7, blendMode is MODE_BLEND_LR, MODE_ALL_LEFT or MODE_ALL_RIGHT.
2398  */
2399 HWTEST(AudioUtilsUnitTest, audio_channel_blend_018, TestSize.Level1)
2400 {
2401     uint8_t buffer1[8] = {2, 4, 6, 8, 10, 12, 14, 16};
2402     uint8_t buffer2[16] = {0, 2, 0, 4, 0, 6, 0, 8, 0, 10, 0, 12, 0, 14, 0, 16};
2403     uint8_t buffer3[24] = {0, 0, 2, 0, 0, 4, 0, 0, 6, 0, 0, 8, 0, 0, 10, 0, 0, 12, 0, 0, 14, 0, 0, 16};
2404     uint8_t buffer4[32] =
2405         {0, 0, 0, 2, 0, 0, 0, 4, 0, 0, 0, 6, 0, 0, 0, 8, 0, 0, 0, 10, 0, 0, 0, 12, 0, 0, 0, 14, 0, 0, 0, 16};
2406     shared_ptr<AudioBlend> audioBlend = std::make_shared<AudioBlend>(MODE_BLEND_LR, 0, CHANNEL_7);
2407     audioBlend->ProcessWithBlendMode<uint8_t>(reinterpret_cast<uint8_t*>(buffer1), 8);
2408     EXPECT_EQ(buffer1[0], 3);
2409 
2410     audioBlend->ProcessWithBlendMode<int16_t>(reinterpret_cast<int16_t*>(buffer2), 8);
2411     EXPECT_EQ(buffer2[1], 3);
2412 
2413     audioBlend->ProcessWithBlendMode<int24_t>(reinterpret_cast<int24_t*>(buffer3), 8);
2414     EXPECT_EQ(buffer3[2], 3);
2415 
2416     audioBlend->ProcessWithBlendMode<int32_t>(reinterpret_cast<int32_t*>(buffer4), 8);
2417     EXPECT_EQ(buffer4[3], 3);
2418 
2419     audioBlend->SetParams(MODE_ALL_LEFT, 0, CHANNEL_7);
2420     audioBlend->ProcessWithBlendMode<uint8_t>(reinterpret_cast<uint8_t*>(buffer1), 8);
2421     EXPECT_EQ(buffer1[0], 3);
2422 
2423     audioBlend->ProcessWithBlendMode<int16_t>(reinterpret_cast<int16_t*>(buffer2), 8);
2424     EXPECT_EQ(buffer2[1], 3);
2425 
2426     audioBlend->ProcessWithBlendMode<int24_t>(reinterpret_cast<int24_t*>(buffer3), 8);
2427     EXPECT_EQ(buffer3[2], 3);
2428 
2429     audioBlend->ProcessWithBlendMode<int32_t>(reinterpret_cast<int32_t*>(buffer4), 8);
2430     EXPECT_EQ(buffer4[3], 3);
2431 
2432     audioBlend->SetParams(MODE_ALL_RIGHT, 0, CHANNEL_7);
2433     audioBlend->ProcessWithBlendMode<uint8_t>(reinterpret_cast<uint8_t*>(buffer1), 8);
2434     EXPECT_EQ(buffer1[0], 3);
2435 
2436     audioBlend->ProcessWithBlendMode<int16_t>(reinterpret_cast<int16_t*>(buffer2), 8);
2437     EXPECT_EQ(buffer2[1], 3);
2438 
2439     audioBlend->ProcessWithBlendMode<int24_t>(reinterpret_cast<int24_t*>(buffer3), 8);
2440     EXPECT_EQ(buffer3[2], 3);
2441 
2442     audioBlend->ProcessWithBlendMode<int32_t>(reinterpret_cast<int32_t*>(buffer4), 8);
2443     EXPECT_EQ(buffer4[3], 3);
2444 }
2445 
2446 /**
2447  * @tc.name  : Test audio_channel_blend API
2448  * @tc.type  : FUNC
2449  * @tc.number: audio_channel_blend_017
2450  * @tc.desc  : Test AudioBlend Process API,Return buffer
2451  *             when channel is CHANNEL_8, blendMode is MODE_BLEND_LR, MODE_ALL_LEFT or MODE_ALL_RIGHT.
2452  */
2453 HWTEST(AudioUtilsUnitTest, audio_channel_blend_019, TestSize.Level1)
2454 {
2455     uint8_t buffer1[8] = {2, 4, 6, 8, 10, 12, 14, 16};
2456     uint8_t buffer2[16] = {0, 2, 0, 4, 0, 6, 0, 8, 0, 10, 0, 12, 0, 14, 0, 16};
2457     uint8_t buffer3[24] = {0, 0, 2, 0, 0, 4, 0, 0, 6, 0, 0, 8, 0, 0, 10, 0, 0, 12, 0, 0, 14, 0, 0, 16};
2458     uint8_t buffer4[32] =
2459         {0, 0, 0, 2, 0, 0, 0, 4, 0, 0, 0, 6, 0, 0, 0, 8, 0, 0, 0, 10, 0, 0, 0, 12, 0, 0, 0, 14, 0, 0, 0, 16};
2460     shared_ptr<AudioBlend> audioBlend = std::make_shared<AudioBlend>(MODE_BLEND_LR, 0, CHANNEL_8);
2461     audioBlend->ProcessWithBlendMode<uint8_t>(reinterpret_cast<uint8_t*>(buffer1), 8);
2462     EXPECT_EQ(buffer1[0], 3);
2463 
2464     audioBlend->ProcessWithBlendMode<int16_t>(reinterpret_cast<int16_t*>(buffer2), 8);
2465     EXPECT_EQ(buffer2[1], 3);
2466 
2467     audioBlend->ProcessWithBlendMode<int24_t>(reinterpret_cast<int24_t*>(buffer3), 8);
2468     EXPECT_EQ(buffer3[2], 3);
2469 
2470     audioBlend->ProcessWithBlendMode<int32_t>(reinterpret_cast<int32_t*>(buffer4), 8);
2471     EXPECT_EQ(buffer4[3], 3);
2472 
2473     audioBlend->SetParams(MODE_ALL_LEFT, 0, CHANNEL_8);
2474     audioBlend->ProcessWithBlendMode<uint8_t>(reinterpret_cast<uint8_t*>(buffer1), 8);
2475     EXPECT_EQ(buffer1[0], 3);
2476 
2477     audioBlend->ProcessWithBlendMode<int16_t>(reinterpret_cast<int16_t*>(buffer2), 8);
2478     EXPECT_EQ(buffer2[1], 3);
2479 
2480     audioBlend->ProcessWithBlendMode<int24_t>(reinterpret_cast<int24_t*>(buffer3), 8);
2481     EXPECT_EQ(buffer3[2], 3);
2482 
2483     audioBlend->ProcessWithBlendMode<int32_t>(reinterpret_cast<int32_t*>(buffer4), 8);
2484     EXPECT_EQ(buffer4[3], 3);
2485 
2486     audioBlend->SetParams(MODE_ALL_RIGHT, 0, CHANNEL_8);
2487     audioBlend->ProcessWithBlendMode<uint8_t>(reinterpret_cast<uint8_t*>(buffer1), 8);
2488     EXPECT_EQ(buffer1[0], 3);
2489 
2490     audioBlend->ProcessWithBlendMode<int16_t>(reinterpret_cast<int16_t*>(buffer2), 8);
2491     EXPECT_EQ(buffer2[1], 3);
2492 
2493     audioBlend->ProcessWithBlendMode<int24_t>(reinterpret_cast<int24_t*>(buffer3), 8);
2494     EXPECT_EQ(buffer3[2], 3);
2495 
2496     audioBlend->ProcessWithBlendMode<int32_t>(reinterpret_cast<int32_t*>(buffer4), 8);
2497     EXPECT_EQ(buffer4[3], 3);
2498 }
2499 
2500 /**
2501 * @tc.name  : Test SetVolumeRampConfig  API
2502 * @tc.type  : FUNC
2503 * @tc.number: SetVolumeRampConfig_001
2504 * @tc.desc  : Test SetVolumeRampConfig API,
2505 *             when rampDirection_ is RAMP_UP
2506 */
2507 HWTEST(AudioUtilsUnitTest, SetVolumeRampConfig_001, TestSize.Level1)
2508 {
2509     shared_ptr<VolumeRamp> volumeRamp = std::make_shared<VolumeRamp>();
2510     volumeRamp->SetVolumeRampConfig(9.9f, 10.1f, 4);
2511     EXPECT_EQ(volumeRamp->rampDirection_, RAMP_DOWN);
2512 }
2513 
2514 /**
2515 * @tc.name  : Test GetRampVolume  API
2516 * @tc.type  : FUNC
2517 * @tc.number: GetRampVolume_001
2518 * @tc.desc  : Test GetRampVolume API,
2519 *             when ret is 0.0f
2520 */
2521 HWTEST(AudioUtilsUnitTest, GetRampVolume_001, TestSize.Level1)
2522 {
2523     shared_ptr<VolumeRamp> volumeRamp = std::make_shared<VolumeRamp>();
2524     volumeRamp->isVolumeRampActive_ = true;
2525     volumeRamp->initTime_ = -1;
2526     float ret = volumeRamp->GetRampVolume();
2527     EXPECT_EQ(ret, 0.0f);
2528 }
2529 
2530 /**
2531 * @tc.name  : Test GetRampVolume  API
2532 * @tc.type  : FUNC
2533 * @tc.number: GetRampVolume_002
2534 * @tc.desc  : Test GetRampVolume API,
2535 *             when ret is 0.0f
2536 */
2537 HWTEST(AudioUtilsUnitTest, GetRampVolume_002, TestSize.Level1)
2538 {
2539     shared_ptr<VolumeRamp> volumeRamp = std::make_shared<VolumeRamp>();
2540     float ret = volumeRamp->GetRampVolume();
2541     EXPECT_EQ(ret, 1.0f);
2542 }
2543 
2544 /**
2545 * @tc.name  : Test GetScaledTime  API
2546 * @tc.type  : FUNC
2547 * @tc.number: GetScaledTime_001
2548 * @tc.desc  : Test GetScaledTime API,return offset,
2549 *             when offset is 0.0f
2550 */
2551 HWTEST(AudioUtilsUnitTest, GetScaledTime_001, TestSize.Level1)
2552 {
2553     shared_ptr<VolumeRamp> volumeRamp = std::make_shared<VolumeRamp>();
2554     volumeRamp->isVolumeRampActive_ = true;
2555     volumeRamp->scale_ = 10.0f;
2556     volumeRamp->initTime_ = 1;
2557     float ret = volumeRamp->GetScaledTime(1000);
2558     EXPECT_EQ(ret, 1.0f);
2559 }
2560 
2561 /**
2562 * @tc.name  : Test GetScaledTime  API
2563 * @tc.type  : FUNC
2564 * @tc.number: GetScaledTime_002
2565 * @tc.desc  : Test GetScaledTime API,return offset,
2566 *             when offset is 1.0f
2567 */
2568 HWTEST(AudioUtilsUnitTest, GetScaledTime_002, TestSize.Level1)
2569 {
2570     shared_ptr<VolumeRamp> volumeRamp = std::make_shared<VolumeRamp>();
2571     volumeRamp->isVolumeRampActive_ = true;
2572     volumeRamp->scale_ = -10.0f;
2573     volumeRamp->initTime_ = 1;
2574     float ret = volumeRamp->GetScaledTime(1000);
2575     EXPECT_EQ(ret, 0.0f);
2576 }
2577 
2578 /**
2579 * @tc.name  : Test GetScaledTime  API
2580 * @tc.type  : FUNC
2581 * @tc.number: GetScaledTime_003
2582 * @tc.desc  : Test GetScaledTime API,return offset,
2583 *             when offset is 0.0f
2584 */
2585 HWTEST(AudioUtilsUnitTest, GetScaledTime_003, TestSize.Level1)
2586 {
2587     shared_ptr<VolumeRamp> volumeRamp = std::make_shared<VolumeRamp>();
2588     volumeRamp->rampDirection_ = RAMP_DOWN;
2589     volumeRamp->isVolumeRampActive_ = true;
2590     volumeRamp->scale_ = 10.0f;
2591     volumeRamp->initTime_ = 1;
2592     float ret = volumeRamp->GetScaledTime(1000);
2593     EXPECT_EQ(ret, 0.0f);
2594 }
2595 
2596 /**
2597 * @tc.name  : Test GetScaledTime  API
2598 * @tc.type  : FUNC
2599 * @tc.number: GetScaledTime_004
2600 * @tc.desc  : Test GetScaledTime API,return offset,
2601 *             when offset is 1.0f
2602 */
2603 HWTEST(AudioUtilsUnitTest, GetScaledTime_004, TestSize.Level1)
2604 {
2605     shared_ptr<VolumeRamp> volumeRamp = std::make_shared<VolumeRamp>();
2606     volumeRamp->initTime_ = 1;
2607     volumeRamp->rampDirection_ = RAMP_DOWN;
2608     volumeRamp->isVolumeRampActive_ = true;
2609     volumeRamp->scale_ = -10.0f;
2610     float ret = volumeRamp->GetScaledTime(1000);
2611     EXPECT_EQ(ret, 1.0f);
2612 }
2613 
2614 /**
2615 * @tc.name  : Test GetScaledTime  API
2616 * @tc.type  : FUNC
2617 * @tc.number: GetScaledTime_004
2618 * @tc.desc  : Test GetScaledTime API,return offset,
2619 *             when offset is 1.0f
2620 */
2621 HWTEST(AudioUtilsUnitTest, GetScaledTime_005, TestSize.Level1)
2622 {
2623     shared_ptr<VolumeRamp> volumeRamp = std::make_shared<VolumeRamp>();
2624     volumeRamp->rampDirection_ = RAMP_DOWN;
2625     volumeRamp->isVolumeRampActive_ = true;
2626     volumeRamp->scale_ = -10.0f;
2627     volumeRamp->initTime_ = 1;
2628     float ret = volumeRamp->GetScaledTime(1000);
2629     EXPECT_EQ(ret, 1.0f);
2630 }
2631 
2632 /**
2633 * @tc.name  : Test LoadChangeSpeedFunc API
2634 * @tc.type  : FUNC
2635 * @tc.number: LoadChangeSpeedFunc_001
2636 * @tc.desc  : Test LoadChangeSpeedFunc API
2637 */
2638 HWTEST(AudioUtilsUnitTest, LoadChangeSpeedFunc_001, TestSize.Level1)
2639 {
2640     shared_ptr<AudioSpeed> audioSpeed = std::make_shared<AudioSpeed>(1, 1, 1);
2641     audioSpeed->format_ = 0;
2642     int32_t result = audioSpeed->LoadChangeSpeedFunc();
2643     EXPECT_EQ(0, result);
2644 }
2645 
2646 /**
2647 * @tc.name  : Test LoadChangeSpeedFunc API
2648 * @tc.type  : FUNC
2649 * @tc.number: LoadChangeSpeedFunc_002
2650 * @tc.desc  : Test LoadChangeSpeedFunc API
2651 */
2652 HWTEST(AudioUtilsUnitTest, LoadChangeSpeedFunc_002, TestSize.Level1)
2653 {
2654     shared_ptr<AudioSpeed> audioSpeed = std::make_shared<AudioSpeed>(1, 1, 1);
2655     audioSpeed->format_ = 1;
2656     int32_t result = audioSpeed->LoadChangeSpeedFunc();
2657     EXPECT_EQ(0, result);
2658 }
2659 
2660 /**
2661 * @tc.name  : Test LoadChangeSpeedFunc  API
2662 * @tc.type  : FUNC
2663 * @tc.number: LoadChangeSpeedFunc_003
2664 * @tc.desc  : Test LoadChangeSpeedFunc API
2665 */
2666 HWTEST(AudioUtilsUnitTest, LoadChangeSpeedFunc_003, TestSize.Level1)
2667 {
2668     shared_ptr<AudioSpeed> audioSpeed = std::make_shared<AudioSpeed>(1, 1, 1);
2669     audioSpeed->format_ = -1;
2670     int32_t result = audioSpeed->LoadChangeSpeedFunc();
2671     EXPECT_EQ(0, result);
2672 }
2673 
2674 /**
2675 * @tc.name  : Test AbsoluteSleep  API
2676 * @tc.type  : FUNC
2677 * @tc.number: AbsoluteSleep_001
2678 * @tc.desc  : Test AbsoluteSleep API
2679 */
2680 HWTEST(AudioUtilsUnitTest, AbsoluteSleep_001, TestSize.Level1)
2681 {
2682     const int64_t CLOCK_TIME = 0;
2683     int32_t ret = ClockTime::AbsoluteSleep(CLOCK_TIME);
2684     EXPECT_EQ(SUCCESS - 1, ret);
2685 }
2686 
2687 /**
2688 * @tc.name  : Test RelativeSleep  API
2689 * @tc.type  : FUNC
2690 * @tc.number: RelativeSleep_001
2691 * @tc.desc  : Test RelativeSleep API
2692 */
2693 HWTEST(AudioUtilsUnitTest, RelativeSleep_001, TestSize.Level1)
2694 {
2695     const int64_t CLOCK_TIME = 0;
2696     int32_t ret = ClockTime::RelativeSleep(CLOCK_TIME);
2697     EXPECT_EQ(SUCCESS - 1, ret);
2698 }
2699 
2700 /**
2701 * @tc.name  : Test AudioInfoDumpUtils::GetStreamName  API
2702 * @tc.type  : FUNC
2703 * @tc.number: AudioInfoDumpUtils_GetStreamName_016
2704 * @tc.desc  : Test AudioInfoDumpUtils GetStreamName API, Return UNKNOWN
2705 *             when streamType is others
2706 */
2707 HWTEST(AudioUtilsUnitTest, AudioInfoDumpUtils_GetStreamName_016, TestSize.Level0)
2708 {
2709     AudioStreamType streamType = STREAM_ACCESSIBILITY;
2710     const std::string streamName = AudioInfoDumpUtils::GetStreamName(streamType);
2711     EXPECT_EQ(streamName, "ACCESSIBILITY");
2712 }
2713 
2714 /**
2715 * @tc.name  : Test MockPcmData  API
2716 * @tc.type  : FUNC
2717 * @tc.number: MockPcmData_001
2718 * @tc.desc  : Test MockPcmData API
2719 */
2720 HWTEST(AudioUtilsUnitTest, MockPcmData_001, TestSize.Level1)
2721 {
2722     uint8_t buffer[0] = {};
2723     size_t bufferLen = 0;
2724     int32_t sampleRate = 44100;
2725     int32_t channelCount = 2;
2726     int32_t sampleFormat = 16;
2727     std::string appName = "com.example.null";
2728     uint32_t sessionId = 0;
2729 
2730     std::shared_ptr<AudioLatencyMeasurement> audioLatencyMeasurement =
2731         std::make_shared<AudioLatencyMeasurement>(sampleRate, channelCount, sampleFormat, appName, sessionId);
2732 
2733     bool ret = audioLatencyMeasurement->MockPcmData(buffer, bufferLen);
2734     EXPECT_EQ(ret, false);
2735 }
2736 
2737 /**
2738 * @tc.name  : Test MockPcmData  API
2739 * @tc.type  : FUNC
2740 * @tc.number: MockPcmData_002
2741 * @tc.desc  : Test MockPcmData API
2742 */
2743 HWTEST(AudioUtilsUnitTest, MockPcmData_002, TestSize.Level1)
2744 {
2745     uint8_t buffer[4096] = {0};
2746     size_t bufferLen = sizeof(buffer);
2747     int32_t sampleRate = 44100;
2748     int32_t channelCount = 2;
2749     int32_t sampleFormat = 16;
2750     std::string appName = "com.example.test";
2751     uint32_t sessionId = 0;
2752 
2753     std::shared_ptr<AudioLatencyMeasurement> audioLatencyMeasurement =
2754         std::make_shared<AudioLatencyMeasurement>(sampleRate, channelCount, sampleFormat, appName, sessionId);
2755 
2756     audioLatencyMeasurement->mockedTime_ = 2000;
2757     bool ret = audioLatencyMeasurement->MockPcmData(buffer, bufferLen);
2758     EXPECT_EQ(ret, true);
2759 
2760     audioLatencyMeasurement->mockedTime_ = 2000;
2761     audioLatencyMeasurement->format_ = SAMPLE_S32LE;
2762     ret = audioLatencyMeasurement->MockPcmData(buffer, bufferLen);
2763     EXPECT_EQ(ret, true);
2764 }
2765 
2766 /**
2767 * @tc.name  : Test UpdateClientTime  API
2768 * @tc.type  : FUNC
2769 * @tc.number: UpdateClientTime_001
2770 * @tc.desc  : Test UpdateClientTime API
2771 */
2772 HWTEST(AudioUtilsUnitTest, UpdateClientTime_001, TestSize.Level1)
2773 {
2774     bool isRenderer = true;
2775     std::string Timestamp = "abcdef";
2776     LatencyMonitor::GetInstance().UpdateClientTime(isRenderer, Timestamp);
2777 }
2778 
2779 /**
2780 * @tc.name  : Test UpdateClientTime  API
2781 * @tc.type  : FUNC
2782 * @tc.number: UpdateClientTime_002
2783 * @tc.desc  : Test UpdateClientTime API
2784 */
2785 HWTEST(AudioUtilsUnitTest, UpdateClientTime_002, TestSize.Level1)
2786 {
2787     bool isRenderer = false;
2788     std::string Timestamp = "abcdef";
2789     LatencyMonitor::GetInstance().UpdateClientTime(isRenderer, Timestamp);
2790 }
2791 
2792 /**
2793 * @tc.name  : Test UpdateSinkOrSourceTime  API
2794 * @tc.type  : FUNC
2795 * @tc.number: UpdateSinkOrSourceTime_001
2796 * @tc.desc  : Test UpdateSinkOrSourceTime API
2797 */
2798 HWTEST(AudioUtilsUnitTest, UpdateSinkOrSourceTime_001, TestSize.Level1)
2799 {
2800     bool isRenderer = true;
2801     std::string Timestamp = "abcdef";
2802     LatencyMonitor::GetInstance().UpdateSinkOrSourceTime(isRenderer, Timestamp);
2803 }
2804 
2805 /**
2806 * @tc.name  : Test UpdateSinkOrSourceTime  API
2807 * @tc.type  : FUNC
2808 * @tc.number: UpdateSinkOrSourceTime_002
2809 * @tc.desc  : Test UpdateSinkOrSourceTime API
2810 */
2811 HWTEST(AudioUtilsUnitTest, UpdateSinkOrSourceTime_002, TestSize.Level1)
2812 {
2813     bool isRenderer = false;
2814     std::string Timestamp = "abcdef";
2815     LatencyMonitor::GetInstance().UpdateSinkOrSourceTime(isRenderer, Timestamp);
2816 }
2817 
2818 /**
2819 * @tc.name  : Test ShowTimestamp  API
2820 * @tc.type  : FUNC
2821 * @tc.number: ShowTimestamp_001
2822 * @tc.desc  : Test ShowTimestamp API
2823 */
2824 HWTEST(AudioUtilsUnitTest, ShowTimestamp_001, TestSize.Level1)
2825 {
2826     bool isRenderer = false;
2827     LatencyMonitor::GetInstance().ShowTimestamp(isRenderer);
2828 }
2829 
2830 /**
2831 * @tc.name  : Test ShowTimestamp  API
2832 * @tc.type  : FUNC
2833 * @tc.number: ShowTimestamp_002
2834 * @tc.desc  : Test ShowTimestamp API
2835 */
2836 HWTEST(AudioUtilsUnitTest, ShowTimestamp_002, TestSize.Level1)
2837 {
2838     bool isRenderer = false;
2839     LatencyMonitor latencyMonitor = LatencyMonitor::GetInstance();
2840     latencyMonitor.extraStrLen_ = 1;
2841     latencyMonitor.UpdateDspTime("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
2842     latencyMonitor.ShowTimestamp(isRenderer);
2843 }
2844 
2845 /**
2846 * @tc.name  : Test ShowTimestamp  API
2847 * @tc.type  : FUNC
2848 * @tc.number: ShowTimestamp_003
2849 * @tc.desc  : Test ShowTimestamp API
2850 */
2851 HWTEST(AudioUtilsUnitTest, ShowTimestamp_003, TestSize.Level1)
2852 {
2853     bool isRenderer = true;
2854     LatencyMonitor latencyMonitor = LatencyMonitor::GetInstance();
2855     latencyMonitor.extraStrLen_ = 1;
2856     latencyMonitor.ShowTimestamp(isRenderer);
2857 }
2858 
2859 /**
2860 * @tc.name  : Test ShowTimestamp  API
2861 * @tc.type  : FUNC
2862 * @tc.number: ShowTimestamp_004
2863 * @tc.desc  : Test ShowTimestamp API
2864 */
2865 HWTEST(AudioUtilsUnitTest, ShowTimestamp_004, TestSize.Level1)
2866 {
2867     bool isRenderer = true;
2868     LatencyMonitor latencyMonitor = LatencyMonitor::GetInstance();
2869     latencyMonitor.extraStrLen_ = 1;
2870     latencyMonitor.UpdateDspTime("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
2871     latencyMonitor.ShowTimestamp(isRenderer);
2872 }
2873 
2874 /**
2875 * @tc.name  : Test GetVolumeTypeFromStreamType  API
2876 * @tc.type  : FUNC
2877 * @tc.number: GetVolumeTypeFromStreamType_001
2878 * @tc.desc  : Test GetVolumeTypeFromStreamType API
2879 */
2880 HWTEST(AudioUtilsUnitTest, GetVolumeTypeFromStreamType_001, TestSize.Level1)
2881 {
2882     AudioStreamType ret = VolumeUtils::GetVolumeTypeFromStreamType(STREAM_BLUETOOTH_SCO);
2883     EXPECT_EQ(STREAM_MUSIC, ret);
2884 }
2885 
2886 /**
2887 * @tc.name  : Test GetEncryptStr  API
2888 * @tc.type  : FUNC
2889 * @tc.number: GetEncryptStr_003
2890 * @tc.desc  : Test GetEncryptStr API
2891 */
2892 HWTEST(AudioUtilsUnitTest, GetEncryptStr_003, TestSize.Level1)
2893 {
2894     const std::string src = "abcdefgh";
2895     std::string dst = GetEncryptStr(src);
2896     EXPECT_EQ(dst, "ab*defgh");
2897 }
2898 
2899 /**
2900 * @tc.name  : Test ConvertNetworkId  API
2901 * @tc.type  : FUNC
2902 * @tc.number: ConvertNetworkId_001
2903 * @tc.desc  : Test ConvertNetworkId API
2904 */
2905 HWTEST(AudioUtilsUnitTest, ConvertNetworkId_001, TestSize.Level1)
2906 {
2907     const std::string src = "abcdefgh";
2908     std::string dst = ConvertNetworkId(src);
2909     EXPECT_EQ(dst, REMOTE_NETWORK_ID);
2910 }
2911 
2912 /**
2913 * @tc.name  : Test ConvertNetworkId  API
2914 * @tc.type  : FUNC
2915 * @tc.number: ConvertNetworkId_002
2916 * @tc.desc  : Test ConvertNetworkId API
2917 */
2918 HWTEST(AudioUtilsUnitTest, ConvertNetworkId_002, TestSize.Level1)
2919 {
2920     const std::string src;
2921     std::string dst = ConvertNetworkId(src);
2922     EXPECT_EQ(dst, src);
2923 }
2924 
2925 /**
2926 * @tc.name  : Test ConvertNetworkId  API
2927 * @tc.type  : FUNC
2928 * @tc.number: ConvertNetworkId_003
2929 * @tc.desc  : Test ConvertNetworkId API
2930 */
2931 HWTEST(AudioUtilsUnitTest, ConvertNetworkId_003, TestSize.Level1)
2932 {
2933     const std::string src = LOCAL_NETWORK_ID;
2934     std::string dst = ConvertNetworkId(src);
2935     EXPECT_EQ(dst, LOCAL_NETWORK_ID);
2936 }
2937 
2938 /**
2939 * @tc.name  : Test CheckCallingUidPermission  API
2940 * @tc.type  : FUNC
2941 * @tc.number: CheckCallingUidPermission_001
2942 * @tc.desc  : Test CheckCallingUidPermission API
2943 */
2944 HWTEST(AudioUtilsUnitTest, CheckCallingUidPermission_001, TestSize.Level1)
2945 {
2946     const std::vector<uid_t> allowedUids = {};
2947     bool result = PermissionUtil::CheckCallingUidPermission(allowedUids);
2948     EXPECT_EQ(result, false);
2949 }
2950 
2951 /**
2952 * @tc.name  : Test CheckCallingUidPermission  API
2953 * @tc.type  : FUNC
2954 * @tc.number: CheckCallingUidPermission_002
2955 * @tc.desc  : Test CheckCallingUidPermission API
2956 */
2957 HWTEST(AudioUtilsUnitTest, CheckCallingUidPermission_002, TestSize.Level1)
2958 {
2959     const std::vector<uid_t> allowedUids = {3001, 3003};
2960     bool result = PermissionUtil::CheckCallingUidPermission(allowedUids);
2961     EXPECT_EQ(result, false);
2962 }
2963 
2964 /**
2965 * @tc.name  : Test UpdateBGSet  API
2966 * @tc.type  : FUNC
2967 * @tc.number: UpdateBGSet_001
2968 * @tc.desc  : Test UpdateBGSet API
2969 */
2970 HWTEST(AudioUtilsUnitTest, UpdateBGSet_001, TestSize.Level1)
2971 {
2972     PermissionUtil::UpdateBGSet();
2973 
2974     char ch = '0';
2975     bool result = PermissionUtil::IsFoldAble(ch);
2976     EXPECT_EQ(result, false);
2977 
2978     ch = '2';
2979     result = PermissionUtil::IsFoldAble(ch);
2980     EXPECT_EQ(result, true);
2981 
2982     ch = '4';
2983     result = PermissionUtil::IsFoldAble(ch);
2984     EXPECT_EQ(result, true);
2985 
2986     ch = '5';
2987     result = PermissionUtil::IsFoldAble(ch);
2988     EXPECT_EQ(result, true);
2989 }
2990 
2991 /**
2992 * @tc.name  : Test NeedVerifyBackgroundCapture  API
2993 * @tc.type  : FUNC
2994 * @tc.number: NeedVerifyBackgroundCapture_001
2995 * @tc.desc  : Test NeedVerifyBackgroundCapture API
2996 */
2997 HWTEST(AudioUtilsUnitTest, NeedVerifyBackgroundCapture_001, TestSize.Level1)
2998 {
2999     int32_t callingUid = 6699;
3000     SourceType sourceType = SOURCE_TYPE_PLAYBACK_CAPTURE;
3001     bool result = PermissionUtil::NeedVerifyBackgroundCapture(callingUid, sourceType);
3002     EXPECT_EQ(result, false);
3003 }
3004 
3005 /**
3006 * @tc.name  : Test NeedVerifyBackgroundCapture  API
3007 * @tc.type  : FUNC
3008 * @tc.number: NeedVerifyBackgroundCapture_002
3009 * @tc.desc  : Test NeedVerifyBackgroundCapture API
3010 */
3011 HWTEST(AudioUtilsUnitTest, NeedVerifyBackgroundCapture_002, TestSize.Level1)
3012 {
3013     int32_t callingUid = 7000;
3014     SourceType sourceType = SOURCE_TYPE_PLAYBACK_CAPTURE;
3015     bool result = PermissionUtil::NeedVerifyBackgroundCapture(callingUid, sourceType);
3016     EXPECT_EQ(result, false);
3017 }
3018 
3019 /**
3020 * @tc.name  : Test NeedVerifyBackgroundCapture  API
3021 * @tc.type  : FUNC
3022 * @tc.number: NeedVerifyBackgroundCapture_003
3023 * @tc.desc  : Test NeedVerifyBackgroundCapture API
3024 */
3025 HWTEST(AudioUtilsUnitTest, NeedVerifyBackgroundCapture_003, TestSize.Level1)
3026 {
3027     int32_t callingUid = 7000;
3028     SourceType sourceType = SOURCE_TYPE_INVALID;
3029     bool result = PermissionUtil::NeedVerifyBackgroundCapture(callingUid, sourceType);
3030     EXPECT_EQ(result, true);
3031 }
3032 
3033 /**
3034 * @tc.name  : Test WriteDumpFile  API
3035 * @tc.type  : FUNC
3036 * @tc.number: WriteDumpFile_001
3037 * @tc.desc  : Test WriteDumpFile API
3038 */
3039 HWTEST(AudioUtilsUnitTest, WriteDumpFile_001, TestSize.Level1)
3040 {
3041     uint32_t buffer[10] = {0};
3042     size_t buffersize = 10;
3043     FILE* tempFile = std::tmpfile();
3044     DumpFileUtil::WriteDumpFile(tempFile, buffer, buffersize);
3045     fclose(tempFile);
3046 }
3047 
3048 /**
3049 * @tc.name  : Test ChangeDumpFileState  API
3050 * @tc.type  : FUNC
3051 * @tc.number: ChangeDumpFileState_001
3052 * @tc.desc  : Test ChangeDumpFileState API
3053 */
3054 HWTEST(AudioUtilsUnitTest, ChangeDumpFileState_001, TestSize.Level1)
3055 {
3056     std::string para = DumpFileUtil::DUMP_SERVER_PARA;
3057     std::string fileName = "dump_bluetooth_audiosink.pcm";
3058     const char *key = "sys.audio.dump.writeserver.enable";
3059     const char *value = "w";
3060     SetParameter(key, value);
3061     FILE* tempFile = std::tmpfile();
3062     DumpFileUtil::ChangeDumpFileState(para, &tempFile, fileName);
3063     fclose(tempFile);
3064 }
3065 
3066 /**
3067 * @tc.name  : Test ChangeDumpFileState  API
3068 * @tc.type  : FUNC
3069 * @tc.number: ChangeDumpFileState_002
3070 * @tc.desc  : Test ChangeDumpFileState API
3071 */
3072 HWTEST(AudioUtilsUnitTest, ChangeDumpFileState_002, TestSize.Level1)
3073 {
3074     std::string para = DumpFileUtil::DUMP_CLIENT_PARA;
3075     std::string fileName = "dump_bluetooth_audiosink.pcm";
3076     const char *key = "sys.audio.dump.writeserver.enable";
3077     const char *value = "a";
3078     SetParameter(key, value);
3079     FILE* tempFile = std::tmpfile();
3080     DumpFileUtil::ChangeDumpFileState(para, &tempFile, fileName);
3081     fclose(tempFile);
3082 }
3083 
3084 /**
3085 * @tc.name  : Test ChangeDumpFileState  API
3086 * @tc.type  : FUNC
3087 * @tc.number: ChangeDumpFileState_003
3088 * @tc.desc  : Test ChangeDumpFileState API
3089 */
3090 HWTEST(AudioUtilsUnitTest, ChangeDumpFileState_003, TestSize.Level1)
3091 {
3092     std::string para = DumpFileUtil::DUMP_CLIENT_PARA;
3093     std::string fileName = "dump_bluetooth_audiosink.pcm";
3094     const char *key = "sys.audio.dump.writeserver.enable";
3095     const char *value = "a";
3096     SetParameter(key, value);
3097     FILE* tempFile = std::tmpfile();
3098     DumpFileUtil::ChangeDumpFileState(para, &tempFile, fileName);
3099     fclose(tempFile);
3100 }
3101 
3102 /**
3103 * @tc.name  : Test OpenDumpFile  API
3104 * @tc.type  : FUNC
3105 * @tc.number: OpenDumpFile_001
3106 * @tc.desc  : Test OpenDumpFile API
3107 */
3108 HWTEST(AudioUtilsUnitTest, OpenDumpFile_001, TestSize.Level1)
3109 {
3110     std::string para = "w";
3111     std::string fileName = "dump_bluetooth_audiosink.pcm";
3112     FILE* tempFile = std::tmpfile();
3113     DumpFileUtil::OpenDumpFile(para, fileName, &tempFile);
3114     fclose(tempFile);
3115 }
3116 
3117 /**
3118 * @tc.name  : Test OpenDumpFile  API
3119 * @tc.type  : FUNC
3120 * @tc.number: OpenDumpFile_002
3121 * @tc.desc  : Test OpenDumpFile API
3122 */
3123 HWTEST(AudioUtilsUnitTest, OpenDumpFile_002, TestSize.Level1)
3124 {
3125     std::string para = DumpFileUtil::DUMP_CLIENT_PARA;
3126     std::string fileName = "dump_bluetooth_audiosink.pcm";
3127     FILE* tempFile = std::tmpfile();
3128     DumpFileUtil::OpenDumpFile(para, fileName, &tempFile);
3129     fclose(tempFile);
3130 }
3131 
3132 /**
3133 * @tc.name  : Test OpenDumpFileInner  API
3134 * @tc.type  : FUNC
3135 * @tc.number: OpenDumpFileInner_001
3136 * @tc.desc  : Test OpenDumpFileInner API
3137 */
3138 HWTEST(AudioUtilsUnitTest, OpenDumpFileInner_001, TestSize.Level1)
3139 {
3140     std::string para = DumpFileUtil::DUMP_SERVER_PARA;
3141     std::string fileName = "dump_bluetooth_audiosink.pcm";
3142     FILE* tempFile = std::tmpfile();
3143     const char *key = "sys.audio.dump.writeserver.enable";
3144     const char *value = "w";
3145     SetParameter(key, value);
3146     AudioDumpFileType fileType = static_cast<AudioDumpFileType>(3);
3147     FILE *ret = DumpFileUtil::OpenDumpFileInner(para, fileName, fileType);
3148     ASSERT_TRUE(ret == nullptr);
3149     fclose(tempFile);
3150 }
3151 
3152 /**
3153 * @tc.name  : Test OpenDumpFileInner  API
3154 * @tc.type  : FUNC
3155 * @tc.number: OpenDumpFileInner_002
3156 * @tc.desc  : Test OpenDumpFileInner API
3157 */
3158 HWTEST(AudioUtilsUnitTest, OpenDumpFileInner_002, TestSize.Level1)
3159 {
3160     std::string para = DumpFileUtil::DUMP_SERVER_PARA;
3161     std::string fileName = "dump_bluetooth_audiosink.pcm";
3162     FILE* tempFile = std::tmpfile();
3163     const char *key = "sys.audio.dump.writeserver.enable";
3164     const char *value = "w";
3165     SetParameter(key, value);
3166     DumpFileUtil::OpenDumpFile(para, fileName, &tempFile);
3167     fclose(tempFile);
3168 }
3169 
3170 /**
3171 * @tc.name  : Test OpenDumpFileInner  API
3172 * @tc.type  : FUNC
3173 * @tc.number: OpenDumpFileInner_003
3174 * @tc.desc  : Test OpenDumpFileInner API
3175 */
3176 HWTEST(AudioUtilsUnitTest, OpenDumpFileInner_003, TestSize.Level1)
3177 {
3178     std::string para = DumpFileUtil::DUMP_SERVER_PARA;
3179     std::string fileName = "dump_bluetooth_audiosink.pcm";
3180     FILE* tempFile = std::tmpfile();
3181     const char *key = "sys.audio.dump.writeserver.enable";
3182     const char *value = "a";
3183     SetParameter(key, value);
3184     DumpFileUtil::OpenDumpFile(para, fileName, &tempFile);
3185     fclose(tempFile);
3186 }
3187 
3188 /**
3189 * @tc.name  : Test CheckAudioData  API
3190 * @tc.type  : FUNC
3191 * @tc.number: CheckAudioData_001
3192 * @tc.desc  : Test CheckAudioData API
3193 */
3194 HWTEST(AudioUtilsUnitTest, CheckAudioData_001, TestSize.Level1)
3195 {
3196     uint8_t buffer[10] = {0};
3197     size_t bufferLen = 0;
3198     struct SignalDetectAgent signalDetectAgent;
3199     signalDetectAgent.formatByteSize_ = 1;
3200     signalDetectAgent.sampleFormat_= SAMPLE_S32LE;
3201     bool ret = signalDetectAgent.CheckAudioData(buffer, bufferLen);
3202     EXPECT_EQ(ret, false);
3203 }
3204 
3205 /**
3206 * @tc.name  : Test CheckAudioData  API
3207 * @tc.type  : FUNC
3208 * @tc.number: CheckAudioData_002
3209 * @tc.desc  : Test CheckAudioData API
3210 */
3211 HWTEST(AudioUtilsUnitTest, CheckAudioData_002, TestSize.Level1)
3212 {
3213     uint8_t buffer[10] = {2, 3, 2, 3, 2, 3, 2, 3, 2, 3};
3214     size_t bufferLen = 10 * sizeof(int32_t);
3215     struct SignalDetectAgent signalDetectAgent;
3216     signalDetectAgent.formatByteSize_ = 1;
3217     signalDetectAgent.sampleFormat_= SAMPLE_S24LE;
3218     bool ret = signalDetectAgent.CheckAudioData(buffer, bufferLen);
3219     EXPECT_EQ(ret, false);
3220 }
3221 
3222 /**
3223 * @tc.name  : Test CheckAudioData  API
3224 * @tc.type  : FUNC
3225 * @tc.number: CheckAudioData_003
3226 * @tc.desc  : Test CheckAudioData API
3227 */
3228 HWTEST(AudioUtilsUnitTest, CheckAudioData_003, TestSize.Level1)
3229 {
3230     uint8_t buffer[10] = {2, 3, 2, 3, 2, 3, 2, 3, 2, 3};
3231     size_t bufferLen = 10 * sizeof(int32_t);
3232     struct SignalDetectAgent signalDetectAgent;
3233     signalDetectAgent.formatByteSize_ = 1;
3234     bool ret = signalDetectAgent.CheckAudioData(buffer, bufferLen);
3235     EXPECT_EQ(ret, false);
3236 
3237     signalDetectAgent.sampleFormat_ = SAMPLE_S32LE;
3238     ret = signalDetectAgent.CheckAudioData(buffer, bufferLen);
3239     EXPECT_EQ(ret, false);
3240 
3241     signalDetectAgent.sampleFormat_ = SAMPLE_F32LE;
3242     ret = signalDetectAgent.CheckAudioData(buffer, bufferLen);
3243     EXPECT_EQ(ret, false);
3244 
3245     signalDetectAgent.sampleFormat_ = SAMPLE_S24LE;
3246     ret = signalDetectAgent.CheckAudioData(buffer, bufferLen);
3247     EXPECT_EQ(ret, false);
3248 }
3249 
3250 /**
3251 * @tc.name  : Test AudioScopeExit  API
3252 * @tc.type  : FUNC
3253 * @tc.number: AudioScopeExit_001
3254 * @tc.desc  : Test AudioScopeExit API
3255 */
3256 HWTEST(AudioUtilsUnitTest, AudioScopeExit_001, TestSize.Level1)
3257 {
3258     MockExe mock;
3259     InSequence seq;
3260     EXPECT_CALL(mock, Exe()).Times(1);
__anon252b39a00102() 3261     AudioScopeExit scopeExit([&mock] () {
3262         mock.Exe();
3263     });
3264 }
3265 
3266 /**
3267 * @tc.name  : Test AudioScopeExit  API
3268 * @tc.type  : FUNC
3269 * @tc.number: AudioScopeExit_002
3270 * @tc.desc  : Test AudioScopeExit API
3271 */
3272 HWTEST(AudioUtilsUnitTest, AudioScopeExit_002, TestSize.Level1)
3273 {
3274     MockExe mock;
3275     InSequence seq;
3276     EXPECT_CALL(mock, Exe()).Times(0);
__anon252b39a00202() 3277     AudioScopeExit scopeExit([&mock] () {
3278         mock.Exe();
3279     });
3280     scopeExit.Relase();
3281 }
3282 
3283 /**
3284 * @tc.name  : Test AudioUtils API
3285 * @tc.type  : FUNC
3286 * @tc.number: AudioUtilsUnitTest_001
3287 * @tc.desc  : Test AudioUtils API
3288 */
3289 HWTEST(AudioUtilsUnitTest, AudioUtilsUnitTest_001, TestSize.Level1)
3290 {
3291     AudioSampleFormat format = SAMPLE_U8;
3292 
3293     uint32_t ret = Util::GetSamplePerFrame(format);
3294     EXPECT_EQ(ret, 1);
3295 
3296     format = SAMPLE_S16LE;
3297     ret = Util::GetSamplePerFrame(format);
3298     EXPECT_EQ(ret, 2);
3299 
3300     format = SAMPLE_S24LE;
3301     ret = Util::GetSamplePerFrame(format);
3302     EXPECT_EQ(ret, 3);
3303 
3304     format = SAMPLE_S32LE;
3305     ret = Util::GetSamplePerFrame(format);
3306     EXPECT_EQ(ret, 4);
3307 
3308     format = INVALID_WIDTH;
3309     ret = Util::GetSamplePerFrame(format);
3310     EXPECT_EQ(ret, 2);
3311 }
3312 
3313 /**
3314 * @tc.name  : Test AudioUtils API
3315 * @tc.type  : FUNC
3316 * @tc.number: AudioUtilsUnitTest_002
3317 * @tc.desc  : Test AudioUtils API
3318 */
3319 HWTEST(AudioUtilsUnitTest, AudioUtilsUnitTest_002, TestSize.Level1)
3320 {
3321     std::string funcName = "AudioUtilsUnitTest_002";
3322     WatchTimeout watchTimeout(funcName);
3323 
3324         watchTimeout.CheckCurrTimeout();
3325         EXPECT_EQ(watchTimeout.isChecked_, true);
3326 
3327         watchTimeout.timeoutNs_ = 0;
3328         watchTimeout.CheckCurrTimeout();
3329         EXPECT_EQ(watchTimeout.isChecked_, true);
3330 }
3331 
3332 /**
3333 * @tc.name  : Test AudioUtils API
3334 * @tc.type  : FUNC
3335 * @tc.number: AudioUtilsUnitTest_003
3336 * @tc.desc  : Test AudioUtils API
3337 */
3338 HWTEST(AudioUtilsUnitTest, AudioUtilsUnitTest_003, TestSize.Level1)
3339 {
3340     int32_t uid = 1003;
3341     bool ret = CheckoutSystemAppUtil::CheckoutSystemApp(uid);
3342     EXPECT_EQ(ret, true);
3343 
3344     uid = 1;
3345     ret = CheckoutSystemAppUtil::CheckoutSystemApp(uid);
3346     EXPECT_EQ(ret, false);
3347 }
3348 
3349 /**
3350 * @tc.name  : Test AudioUtils API
3351 * @tc.type  : FUNC
3352 * @tc.number: AudioUtilsUnitTest_004
3353 * @tc.desc  : Test AudioUtils API
3354 */
3355 HWTEST(AudioUtilsUnitTest, AudioUtilsUnitTest_004, TestSize.Level1)
3356 {
3357     int64_t nanoTime = 0;
3358     std::string ret = ClockTime::NanoTimeToString(nanoTime);
3359     EXPECT_EQ(ret, "08:00:00");
3360 }
3361 
3362 /**
3363 * @tc.name  : Test AudioUtils API
3364 * @tc.type  : FUNC
3365 * @tc.number: AudioUtilsUnitTest_005
3366 * @tc.desc  : Test AudioUtils API
3367 */
3368 HWTEST(AudioUtilsUnitTest, AudioUtilsUnitTest_005, TestSize.Level1)
3369 {
3370     std::string tag = "";
3371     uint32_t timeoutSeconds = 0;
3372     AudioXCollie audioXCollie(tag, timeoutSeconds, nullptr, nullptr, AUDIO_XCOLLIE_FLAG_LOG);
3373     audioXCollie.isCanceled_ = false;
3374     audioXCollie.CancelXCollieTimer();
3375     EXPECT_EQ(audioXCollie.isCanceled_, true);
3376 
3377     audioXCollie.CancelXCollieTimer();
3378     EXPECT_EQ(audioXCollie.isCanceled_, true);
3379 }
3380 
3381 /**
3382 * @tc.name  : Test AudioUtils API
3383 * @tc.type  : FUNC
3384 * @tc.number: AudioUtilsUnitTest_006
3385 * @tc.desc  : Test AudioUtils API
3386 */
3387 HWTEST(AudioUtilsUnitTest, AudioUtilsUnitTest_006, TestSize.Level1)
3388 {
3389     bool ret = PermissionUtil::VerifyIsShell();
3390     EXPECT_EQ(ret, true);
3391 
3392     ret = PermissionUtil::VerifyIsAudio();
3393     EXPECT_EQ(ret, true);
3394 
3395     int32_t callingUid = 6699;
3396     SourceType sourceType = SOURCE_TYPE_INVALID;
3397     ret = PermissionUtil::NeedVerifyBackgroundCapture(callingUid, sourceType);
3398     EXPECT_EQ(ret, false);
3399 
3400     callingUid = 1000;
3401     sourceType = SOURCE_TYPE_PLAYBACK_CAPTURE;
3402     ret = PermissionUtil::NeedVerifyBackgroundCapture(callingUid, sourceType);
3403     EXPECT_EQ(ret, false);
3404 
3405     callingUid = 1000;
3406     sourceType = SOURCE_TYPE_VOICE_RECOGNITION;
3407     ret = PermissionUtil::NeedVerifyBackgroundCapture(callingUid, sourceType);
3408     EXPECT_EQ(ret, true);
3409 
3410     uint32_t tokenId = 1;
3411     uint64_t fullTokenId = 1;
3412     ret = PermissionUtil::VerifyBackgroundCapture(tokenId, fullTokenId);
3413     EXPECT_EQ(ret, false);
3414 }
3415 
3416 /**
3417  * @tc.name  : Test AudioUtils API
3418  * @tc.type  : FUNC
3419  * @tc.number: AudioUtilsUnitTest_007
3420  * @tc.desc  : Test AudioUtils API
3421  */
3422 HWTEST(AudioUtilsUnitTest, AudioUtilsUnitTest_007, TestSize.Level1)
3423 {
3424     std::string str1 = "-0";
3425     uint64_t result64 = 1;
3426     EXPECT_TRUE(StringConverter(str1, result64));
3427     EXPECT_EQ(result64, 0);
3428 
3429     uint32_t result32 = 1;
3430     EXPECT_TRUE(StringConverter(str1, result32));
3431     EXPECT_EQ(result32, 0);
3432 
3433     uint16_t result16 = 1;
3434     EXPECT_TRUE(StringConverter(str1, result16));
3435     EXPECT_EQ(result16, 0);
3436 
3437     uint8_t result8 = 1;
3438     EXPECT_TRUE(StringConverter(str1, result8));
3439     EXPECT_EQ(result8, 0);
3440 
3441     int32_t result32Signed = 1;
3442     EXPECT_TRUE(StringConverter(str1, result32Signed));
3443     EXPECT_EQ(result32Signed, 0);
3444 
3445     int8_t result8Signed = 1;
3446     EXPECT_TRUE(StringConverter(str1, result8Signed));
3447     EXPECT_EQ(result8Signed, 0);
3448 
3449     std::string str2 = "10";
3450     EXPECT_TRUE(StringConverter(str2, result64));
3451     EXPECT_EQ(result64, 10);
3452 
3453     EXPECT_TRUE(StringConverter(str2, result32));
3454     EXPECT_EQ(result32, 10);
3455 
3456     EXPECT_TRUE(StringConverter(str2, result16));
3457     EXPECT_EQ(result16, 10);
3458 
3459     EXPECT_TRUE(StringConverter(str2, result8));
3460     EXPECT_EQ(result8, 10);
3461 
3462     EXPECT_TRUE(StringConverter(str2, result32Signed));
3463     EXPECT_EQ(result32Signed, 10);
3464 
3465     EXPECT_TRUE(StringConverter(str2, result8Signed));
3466     EXPECT_EQ(result8Signed, 10);
3467 }
3468 
3469 /**
3470 * @tc.name  : Test GetSupportedAudioVolumeTypes  API
3471 * @tc.type  : FUNC
3472 * @tc.number: GetSupportedAudioVolumeTypes_001
3473 * @tc.desc  : Test GetSupportedAudioVolumeTypes API
3474 */
3475 HWTEST(AudioUtilsUnitTest, GetSupportedAudioVolumeTypes_001, TestSize.Level1)
3476 {
3477     auto ret = VolumeUtils::GetSupportedAudioVolumeTypes();
3478     EXPECT_GE(ret.size(), 0);
3479 }
3480 
3481 /**
3482 * @tc.name  : Test GetStreamUsagesByVolumeType  API
3483 * @tc.type  : FUNC
3484 * @tc.number: GetStreamUsagesByVolumeType_001
3485 * @tc.desc  : Test GetStreamUsagesByVolumeType API
3486 */
3487 HWTEST(AudioUtilsUnitTest, GetStreamUsagesByVolumeType_001, TestSize.Level1)
3488 {
3489     auto ret = VolumeUtils::GetStreamUsagesByVolumeType(STREAM_MUSIC);
3490     EXPECT_GE(ret.size(), 0);
3491 }
3492 } // namespace AudioStandard
3493 } // namespace OHOS
3494