• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 
16 #include <gtest/gtest.h>
17 #include <gmock/gmock.h>
18 
19 #include "audio_service_log.h"
20 #include "audio_errors.h"
21 #include "fast_audio_stream.h"
22 
23 using namespace testing::ext;
24 
25 namespace OHOS {
26 namespace AudioStandard {
27 
28 class FastSystemStreamUnitTest : public testing::Test {
29 public:
30     static void SetUpTestCase(void);
31     static void TearDownTestCase(void);
32     void SetUp();
33     void TearDown();
34 };
35 
36 class AudioClientTrackerTest : public AudioClientTracker {
37 public:
38     virtual ~AudioClientTrackerTest() = default;
39     /**
40      * Mute Stream was controlled by system application
41      *
42      * @param streamSetStateEventInternal Contains the set even information.
43      */
MuteStreamImpl(const StreamSetStateEventInternal & streamSetStateEventInternal)44     virtual void MuteStreamImpl(const StreamSetStateEventInternal &streamSetStateEventInternal) {};
45     /**
46      * Unmute Stream was controlled by system application
47      *
48      * @param streamSetStateEventInternal Contains the set even information.
49      */
UnmuteStreamImpl(const StreamSetStateEventInternal & streamSetStateEventInternal)50     virtual void UnmuteStreamImpl(const StreamSetStateEventInternal &streamSetStateEventInternal) {};
51     /**
52      * Paused Stream was controlled by system application
53      *
54      * @param streamSetStateEventInternal Contains the set even information.
55      */
PausedStreamImpl(const StreamSetStateEventInternal & streamSetStateEventInternal)56     virtual void PausedStreamImpl(const StreamSetStateEventInternal &streamSetStateEventInternal) {};
57     /**
58      * Resumed Stream was controlled by system application
59      *
60      * @param streamSetStateEventInternal Contains the set even information.
61      */
ResumeStreamImpl(const StreamSetStateEventInternal & streamSetStateEventInternal)62     virtual void ResumeStreamImpl(const StreamSetStateEventInternal &streamSetStateEventInternal) {};
SetLowPowerVolumeImpl(float volume)63     virtual void SetLowPowerVolumeImpl(float volume) {};
GetLowPowerVolumeImpl(float & volume)64     virtual void GetLowPowerVolumeImpl(float &volume) {};
GetSingleStreamVolumeImpl(float & volume)65     virtual void GetSingleStreamVolumeImpl(float &volume) {};
SetOffloadModeImpl(int32_t state,bool isAppBack)66     virtual void SetOffloadModeImpl(int32_t state, bool isAppBack) {};
UnsetOffloadModeImpl()67     virtual void UnsetOffloadModeImpl() {};
68 };
69 
70 class AudioRendererFirstFrameWritingCallbackTest : public AudioRendererFirstFrameWritingCallback {
71 public:
72     virtual ~AudioRendererFirstFrameWritingCallbackTest() = default;
73     /**
74      * Called when first buffer to be enqueued.
75      */
OnFirstFrameWriting(uint64_t latency)76     virtual void OnFirstFrameWriting(uint64_t latency) {}
77 };
78 
79 class AudioRendererWriteCallbackTest : public AudioRendererWriteCallback {
80 public:
81     virtual ~AudioRendererWriteCallbackTest() = default;
82 
83     /**
84      * Called when buffer to be enqueued.
85      *
86      * @param length Indicates requested buffer length.
87      * @since 8
88      */
OnWriteData(size_t length)89     virtual void OnWriteData(size_t length) {}
90 };
91 
92 class AudioCapturerReadCallbackTest : public AudioCapturerReadCallback {
93 public:
94     virtual ~AudioCapturerReadCallbackTest() = default;
95 
96     /**
97      * Called when buffer to be enqueued.
98      *
99      * @param length Indicates requested buffer length.
100      * @since 9
101      */
OnReadData(size_t length)102     virtual void OnReadData(size_t length) {}
103 };
104 
105 class AudioStreamCallbackTest : public AudioStreamCallback {
106 public:
107     virtual ~AudioStreamCallbackTest() = default;
108     /**
109      * Called when stream state is updated.
110      *
111      * @param state Indicates the InterruptEvent information needed by client.
112      * For details, refer InterruptEvent struct in audio_info.h
113      */
OnStateChange(const State state,const StateChangeCmdType cmdType=CMD_FROM_CLIENT)114     virtual void OnStateChange(const State state, const StateChangeCmdType cmdType = CMD_FROM_CLIENT) {};
115 };
116 
117 class MockFastAudioStream : public FastAudioStream {
118 public:
119     using FastAudioStream::FastAudioStream;
120     MOCK_METHOD(float, GetDuckVolume, (),  (override));
121 };
122 
123 /**
124  * @tc.name  : Test GetVolume API
125  * @tc.type  : FUNC
126  * @tc.number: GetVolume_001
127  * @tc.desc  : Test GetVolume interface.
128  */
129 HWTEST(FastSystemStreamUnitTest, GetVolume_001, TestSize.Level1)
130 {
131     int32_t appUid = static_cast<int32_t>(getuid());
132     std::shared_ptr<FastAudioStream> fastAudioStream;
133     fastAudioStream = std::make_shared<FastAudioStream>(STREAM_MUSIC, AUDIO_MODE_PLAYBACK, appUid);
134 
135     AUDIO_INFO_LOG("AudioSystemManagerUnitTest GetVolume_001 start");
136     fastAudioStream->silentModeAndMixWithOthers_ = true;
137     float result = fastAudioStream->GetVolume();
138     AUDIO_INFO_LOG("AudioSystemManagerUnitTest GetVolume_001 result:%{public}f", result);
139     EXPECT_GT(result, 0);
140 }
141 
142 /**
143  * @tc.name  : Test SetVolume API
144  * @tc.type  : FUNC
145  * @tc.number: SetVolume_001
146  * @tc.desc  : Test SetVolume interface.
147  */
148 HWTEST(FastSystemStreamUnitTest, SetVolume_001, TestSize.Level1)
149 {
150     int32_t appUid = static_cast<int32_t>(getuid());
151     std::shared_ptr<FastAudioStream> fastAudioStream;
152     fastAudioStream = std::make_shared<FastAudioStream>(STREAM_MUSIC, AUDIO_MODE_PLAYBACK, appUid);
153 
154     float volume = 0.5f;
155     fastAudioStream->silentModeAndMixWithOthers_ = true;
156     int32_t result = fastAudioStream->SetVolume(volume);
157     AUDIO_INFO_LOG("AudioSystemManagerUnitTest SetVolume_001 result:%{public}d", result);
158     EXPECT_NE(result, ERROR);
159 }
160 
161 /**
162  * @tc.name  : Test SetSilentModeAndMixWithOthers API
163  * @tc.type  : FUNC
164  * @tc.number: SetSilentModeAndMixWithOthers_001
165  * @tc.desc  : Test SetSilentModeAndMixWithOthers interface.
166  */
167 HWTEST(FastSystemStreamUnitTest, SetSilentModeAndMixWithOthers_001, TestSize.Level1)
168 {
169     AUDIO_INFO_LOG("AudioSystemManagerUnitTest SetSilentModeAndMixWithOthers_001 start");
170     int32_t appUid = static_cast<int32_t>(getuid());
171     std::shared_ptr<FastAudioStream> fastAudioStream;
172     fastAudioStream = std::make_shared<FastAudioStream>(STREAM_MUSIC, AUDIO_MODE_PLAYBACK, appUid);
173 
174     bool on = false;
175     fastAudioStream->silentModeAndMixWithOthers_ = false;
176     fastAudioStream->SetSilentModeAndMixWithOthers(on);
177     AUDIO_INFO_LOG("AudioSystemManagerUnitTest SetSilentModeAndMixWithOthers_001 -1");
178     fastAudioStream->silentModeAndMixWithOthers_ = true;
179     fastAudioStream->SetSilentModeAndMixWithOthers(on);
180     AUDIO_INFO_LOG("AudioSystemManagerUnitTest SetSilentModeAndMixWithOthers_001 -2");
181 
182     on = true;
183     fastAudioStream->silentModeAndMixWithOthers_ = false;
184     fastAudioStream->SetSilentModeAndMixWithOthers(on);
185     AUDIO_INFO_LOG("AudioSystemManagerUnitTest SetSilentModeAndMixWithOthers_001 -3");
186     fastAudioStream->silentModeAndMixWithOthers_ = true;
187     fastAudioStream->SetSilentModeAndMixWithOthers(on);
188     AUDIO_INFO_LOG("AudioSystemManagerUnitTest SetSilentModeAndMixWithOthers_001 -4");
189 }
190 
191 /**
192  * @tc.name  : Test GetSwitchInfo API
193  * @tc.type  : FUNC
194  * @tc.number: GetSwitchInfo_001
195  * @tc.desc  : Test GetSwitchInfo interface.
196  */
197 HWTEST(FastSystemStreamUnitTest, GetSwitchInfo_001, TestSize.Level4)
198 {
199     AUDIO_INFO_LOG("AudioSystemManagerUnitTest GetSwitchInfo_001 start");
200     int32_t appUid = static_cast<int32_t>(getuid());
201     auto fastAudioStream = std::make_shared<MockFastAudioStream>(STREAM_MUSIC, AUDIO_MODE_PLAYBACK, appUid);
202     EXPECT_NE(fastAudioStream, nullptr);
203     EXPECT_CALL(*fastAudioStream, GetDuckVolume()).WillRepeatedly(testing::Return(0.2));
204 
205     IAudioStream::SwitchInfo info;
206     fastAudioStream->GetSwitchInfo(info);
207     EXPECT_EQ(info.renderMode, fastAudioStream->renderMode_);
208     AUDIO_INFO_LOG("AudioSystemManagerUnitTest GetSwitchInfo_001 end");
209 }
210 
211 /**
212  * @tc.name  : Test GetSwitchInfo API
213  * @tc.type  : FUNC
214  * @tc.number: GetSwitchInfo_002
215  * @tc.desc  : Test GetSwitchInfo interface.
216  */
217 HWTEST(FastSystemStreamUnitTest, GetSwitchInfo_002, TestSize.Level1)
218 {
219     AUDIO_INFO_LOG("AudioSystemManagerUnitTest GetSwitchInfo_002 start");
220     int32_t appUid = static_cast<int32_t>(getuid());
221     auto fastAudioStream = std::make_shared<MockFastAudioStream>(STREAM_MUSIC, AUDIO_MODE_PLAYBACK, appUid);
222     EXPECT_NE(fastAudioStream, nullptr);
223     EXPECT_CALL(*fastAudioStream, GetDuckVolume()).WillRepeatedly(testing::Return(0.2));
224 
225     std::shared_ptr<AudioRendererWriteCallback> spkCallback = std::make_shared<AudioRendererWriteCallbackTest>();
226     AudioStreamParams tempParams = {};
227     auto audioStream = IAudioStream::GetRecordStream(IAudioStream::PA_STREAM, tempParams, STREAM_MUSIC, getpid());
228     fastAudioStream->spkProcClientCb_ = std::make_shared<FastAudioStreamRenderCallback>(spkCallback, *audioStream);
229 
230     std::shared_ptr<AudioCapturerReadCallback> micCallback = std::make_shared<AudioCapturerReadCallbackTest>();
231     fastAudioStream->micProcClientCb_ = std::make_shared<FastAudioStreamCaptureCallback>(micCallback);
232 
233     fastAudioStream->firstFrameWritingCb_ = std::make_shared<AudioRendererFirstFrameWritingCallbackTest>();
234 
235     AUDIO_INFO_LOG("AudioSystemManagerUnitTest GetSwitchInfo_002 start");
236 
237     IAudioStream::SwitchInfo info;
238     fastAudioStream->GetSwitchInfo(info);
239     EXPECT_EQ(info.renderMode, fastAudioStream->renderMode_);
240     AUDIO_INFO_LOG("AudioSystemManagerUnitTest GetSwitchInfo_002 end");
241 }
242 
243 /**
244  * @tc.name  : Test UpdatePlaybackCaptureConfig API
245  * @tc.type  : FUNC
246  * @tc.number: UpdatePlaybackCaptureConfig_001
247  * @tc.desc  : Test UpdatePlaybackCaptureConfig interface.
248  */
249 HWTEST(FastSystemStreamUnitTest, UpdatePlaybackCaptureConfig_001, TestSize.Level1)
250 {
251     AUDIO_INFO_LOG("AudioSystemManagerUnitTest UpdatePlaybackCaptureConfig_001 start");
252     int32_t appUid = static_cast<int32_t>(getuid());
253     AudioPlaybackCaptureConfig config;
254     std::shared_ptr<FastAudioStream> fastAudioStream;
255     fastAudioStream = std::make_shared<FastAudioStream>(STREAM_MUSIC, AUDIO_MODE_PLAYBACK, appUid);
256     int32_t res = 0;
257     res = fastAudioStream->UpdatePlaybackCaptureConfig(config);
258     EXPECT_EQ(res, ERR_NOT_SUPPORTED);
259 }
260 
261 /**
262  * @tc.name  : Test GetAudioPipeType and SetAudioStreamType API
263  * @tc.type  : FUNC
264  * @tc.number: GetAudioPipeType_001
265  * @tc.desc  : Test GetAudioPipeType and SetAudioStreamType interface.
266  */
267 HWTEST(FastSystemStreamUnitTest, GetAudioPipeType_001, TestSize.Level1)
268 {
269     AUDIO_INFO_LOG("AudioSystemManagerUnitTest GetAudioPipeType_001 start");
270     int32_t appUid = static_cast<int32_t>(getuid());
271     AudioPipeType pipeType;
272     std::shared_ptr<FastAudioStream> fastAudioStream;
273     fastAudioStream = std::make_shared<FastAudioStream>(STREAM_MUSIC, AUDIO_MODE_PLAYBACK, appUid);
274     fastAudioStream->GetAudioPipeType(pipeType);
275     AudioStreamType audioStreamType = STREAM_DEFAULT;
276     int32_t res = fastAudioStream->SetAudioStreamType(audioStreamType);
277     EXPECT_EQ(res, ERR_INVALID_OPERATION);
278 }
279 
280 /**
281  * @tc.name  : Test GetFastStatus API
282  * @tc.type  : FUNC
283  * @tc.number: GetFastStatus_001
284  * @tc.desc  : Test GetFastStatus and SetAudioStreamType interface.
285  */
286 HWTEST(FastSystemStreamUnitTest, GetFastStatus_001, TestSize.Level1)
287 {
288     int32_t appUid = static_cast<int32_t>(getuid());
289     std::shared_ptr<FastAudioStream> fastAudioStream;
290     fastAudioStream = std::make_shared<FastAudioStream>(STREAM_MUSIC, AUDIO_MODE_PLAYBACK, appUid);
291     ASSERT_NE(fastAudioStream, nullptr);
292 
293     auto ret = fastAudioStream->GetFastStatus();
294     EXPECT_EQ(ret, FASTSTATUS_FAST);
295 }
296 
297 /**
298  * @tc.name  : Test SetMute API
299  * @tc.type  : FUNC
300  * @tc.number: SetMute_001
301  * @tc.desc  : Test SetMute interface.
302  */
303 HWTEST(FastSystemStreamUnitTest, SetMute_001, TestSize.Level1)
304 {
305     AUDIO_INFO_LOG("AudioSystemManagerUnitTest SetMute_001 start");
306     int32_t appUid = static_cast<int32_t>(getuid());
307     std::shared_ptr<FastAudioStream> fastAudioStream;
308     fastAudioStream = std::make_shared<FastAudioStream>(STREAM_MUSIC, AUDIO_MODE_PLAYBACK, appUid);
309     int32_t res = fastAudioStream->SetMute(false, StateChangeCmdType::CMD_FROM_CLIENT);
310     EXPECT_EQ(res, ERR_OPERATION_FAILED);
311 }
312 
313 /**
314  * @tc.name  : Test SetRenderMode and GetCaptureMode API
315  * @tc.type  : FUNC
316  * @tc.number: SetRenderMode_001
317  * @tc.desc  : Test SetRenderMode and GetCaptureMode interface.
318  */
319 HWTEST(FastSystemStreamUnitTest, SetRenderMode_001, TestSize.Level1)
320 {
321     AUDIO_INFO_LOG("AudioSystemManagerUnitTest SetRenderMode_001 start");
322     int32_t appUid = static_cast<int32_t>(getuid());
323     std::shared_ptr<FastAudioStream> fastAudioStream;
324     fastAudioStream = std::make_shared<FastAudioStream>(STREAM_MUSIC, AUDIO_MODE_PLAYBACK, appUid);
325     AudioRenderMode renderMode = RENDER_MODE_CALLBACK;
326     int32_t res = fastAudioStream->SetRenderMode(renderMode);
327     EXPECT_EQ(res, SUCCESS);
328 }
329 
330 /**
331  * @tc.name  : Test GetCaptureMode API
332  * @tc.type  : FUNC
333  * @tc.number: GetCaptureMode_001
334  * @tc.desc  : Test GetCaptureMode interface.
335  */
336 HWTEST(FastSystemStreamUnitTest, GetCaptureMode_001, TestSize.Level1)
337 {
338     AUDIO_INFO_LOG("AudioSystemManagerUnitTest GetCaptureMode_001 start");
339     int32_t appUid = static_cast<int32_t>(getuid());
340     std::shared_ptr<FastAudioStream> fastAudioStream;
341     fastAudioStream = std::make_shared<FastAudioStream>(STREAM_MUSIC, AUDIO_MODE_PLAYBACK, appUid);
342     AudioCaptureMode captureMode;
343     captureMode = fastAudioStream->GetCaptureMode();
344     EXPECT_EQ(captureMode, CAPTURE_MODE_CALLBACK);
345 }
346 
347 /**
348  * @tc.name  : Test SetLowPowerVolume, GetLowPowerVolume and GetSingleStreamVolume API
349  * @tc.type  : FUNC
350  * @tc.number: SetLowPowerVolume_001
351  * @tc.desc  : Test SetLowPowerVolume, GetLowPowerVolume and GetSingleStreamVolume interface.
352  */
353 HWTEST(FastSystemStreamUnitTest, SetLowPowerVolume_001, TestSize.Level1)
354 {
355     AUDIO_INFO_LOG("AudioSystemManagerUnitTest SetLowPowerVolume_001 start");
356     int32_t appUid = static_cast<int32_t>(getuid());
357     std::shared_ptr<FastAudioStream> fastAudioStream;
358     fastAudioStream = std::make_shared<FastAudioStream>(STREAM_MUSIC, AUDIO_MODE_PLAYBACK, appUid);
359     int32_t res = fastAudioStream->SetLowPowerVolume(1.0f);
360     EXPECT_EQ(res, SUCCESS);
361     float volume = fastAudioStream->GetLowPowerVolume();
362     EXPECT_EQ(volume, 1.0f);
363     volume = fastAudioStream->GetSingleStreamVolume();
364     EXPECT_EQ(volume, 1.0f);
365 }
366 
367 /**
368  * @tc.name  : Test SetOffloadMode and UnsetOffloadMode API
369  * @tc.type  : FUNC
370  * @tc.number: SetOffloadMode_001
371  * @tc.desc  : Test SetOffloadMode and UnsetOffloadMode interface.
372  */
373 HWTEST(FastSystemStreamUnitTest, SetOffloadMode_001, TestSize.Level1)
374 {
375     AUDIO_INFO_LOG("AudioSystemManagerUnitTest SetOffloadMode_001 start");
376     int32_t appUid = static_cast<int32_t>(getuid());
377     std::shared_ptr<FastAudioStream> fastAudioStream;
378     fastAudioStream = std::make_shared<FastAudioStream>(STREAM_MUSIC, AUDIO_MODE_PLAYBACK, appUid);
379     int32_t res = fastAudioStream->SetOffloadMode(0, true);
380     EXPECT_EQ(res, ERR_NOT_SUPPORTED);
381     res = fastAudioStream->UnsetOffloadMode();
382     EXPECT_EQ(res, ERR_NOT_SUPPORTED);
383 }
384 
385 /**
386  * @tc.name  : Test SetAudioEffectMode API
387  * @tc.type  : FUNC
388  * @tc.number: SetAudioEffectMode_001
389  * @tc.desc  : Test SetAudioEffectMode interface.
390  */
391 HWTEST(FastSystemStreamUnitTest, SetAudioEffectMode_001, TestSize.Level1)
392 {
393     AUDIO_INFO_LOG("AudioSystemManagerUnitTest SetAudioEffectMode_001 start");
394     int32_t appUid = static_cast<int32_t>(getuid());
395     std::shared_ptr<FastAudioStream> fastAudioStream;
396     fastAudioStream = std::make_shared<FastAudioStream>(STREAM_MUSIC, AUDIO_MODE_PLAYBACK, appUid);
397     AudioEffectMode effectMode = EFFECT_NONE;
398     int32_t res = fastAudioStream->SetAudioEffectMode(effectMode);
399     EXPECT_EQ(res, ERR_NOT_SUPPORTED);
400 }
401 
402 /**
403  * @tc.name  : Test GetFramesWritten and GetFramesRead API
404  * @tc.type  : FUNC
405  * @tc.number: GetFramesWritten_001
406  * @tc.desc  : Test GetFramesWritten and GetFramesRead interface.
407  */
408 HWTEST(FastSystemStreamUnitTest, GetFramesWritten_001, TestSize.Level1)
409 {
410     AUDIO_INFO_LOG("AudioSystemManagerUnitTest GetFramesWritten_001 start");
411     int32_t appUid = static_cast<int32_t>(getuid());
412     std::shared_ptr<FastAudioStream> fastAudioStream;
413     fastAudioStream = std::make_shared<FastAudioStream>(STREAM_MUSIC, AUDIO_MODE_PLAYBACK, appUid);
414     int32_t res = fastAudioStream->GetFramesWritten();
415     EXPECT_EQ(res, -1);
416     res = fastAudioStream->GetFramesRead();
417     EXPECT_EQ(res, -1);
418 }
419 
420 /**
421  * @tc.name  : Test SetSpeed and GetSpeed API
422  * @tc.type  : FUNC
423  * @tc.number: SetSpeed_001
424  * @tc.desc  : Test SetSpeed and GetSpeed interface.
425  */
426 HWTEST(FastSystemStreamUnitTest, SetSpeed_001, TestSize.Level1)
427 {
428     AUDIO_INFO_LOG("AudioSystemManagerUnitTest SetSpeed_001 start");
429     int32_t appUid = static_cast<int32_t>(getuid());
430     std::shared_ptr<FastAudioStream> fastAudioStream;
431     fastAudioStream = std::make_shared<FastAudioStream>(STREAM_MUSIC, AUDIO_MODE_PLAYBACK, appUid);
432     int32_t res = fastAudioStream->SetSpeed(1.0f);
433     EXPECT_EQ(res, ERR_OPERATION_FAILED);
434     float ret = fastAudioStream->GetSpeed();
435     EXPECT_EQ(ret, static_cast<float>(ERROR));
436 }
437 
438 /**
439  * @tc.name  : Test SetPitch API
440  * @tc.type  : FUNC
441  * @tc.number: SetPitch_001
442  * @tc.desc  : Test SetPitch interface.
443  */
444 HWTEST(FastSystemStreamUnitTest, SetPitch_001, TestSize.Level1)
445 {
446     AUDIO_INFO_LOG("AudioSystemManagerUnitTest SetPitch_001 start");
447     int32_t appUid = static_cast<int32_t>(getuid());
448     std::shared_ptr<FastAudioStream> fastAudioStream;
449     fastAudioStream = std::make_shared<FastAudioStream>(STREAM_MUSIC, AUDIO_MODE_PLAYBACK, appUid);
450     int32_t res = fastAudioStream->SetPitch(1.0f);
451     EXPECT_EQ(res, ERR_OPERATION_FAILED);
452 }
453 
454 /**
455  * @tc.name  : Test FlushAudioStream and DrainAudioStream API
456  * @tc.type  : FUNC
457  * @tc.number: SetSpeed_001
458  * @tc.desc  : Test FlushAudioStream and DrainAudioStream interface.
459  */
460 HWTEST(FastSystemStreamUnitTest, FlushAudioStream_001, TestSize.Level1)
461 {
462     AUDIO_INFO_LOG("AudioSystemManagerUnitTest FlushAudioStream_001 start");
463     int32_t appUid = static_cast<int32_t>(getuid());
464     std::shared_ptr<FastAudioStream> fastAudioStream;
465     fastAudioStream = std::make_shared<FastAudioStream>(STREAM_MUSIC, AUDIO_MODE_PLAYBACK, appUid);
466     bool res = fastAudioStream->FlushAudioStream();
467     EXPECT_EQ(res, true);
468     res = fastAudioStream->DrainAudioStream(true);
469     EXPECT_EQ(res, true);
470 }
471 
472 /**
473  * @tc.name  : Test callbacks and samplingrate API
474  * @tc.type  : FUNC
475  * @tc.number: SetAndGetCallback_001
476  * @tc.desc  : Test callbacks and samplingrate interface.
477  */
478 HWTEST(FastSystemStreamUnitTest, SetAndGetCallback_001, TestSize.Level1)
479 {
480     AUDIO_INFO_LOG("AudioSystemManagerUnitTest SetAndGetCallback_001 start");
481     int32_t appUid = static_cast<int32_t>(getuid());
482     std::shared_ptr<FastAudioStream> fastAudioStream;
483     fastAudioStream = std::make_shared<FastAudioStream>(STREAM_MUSIC, AUDIO_MODE_PLAYBACK, appUid);
484 
485     std::shared_ptr<RendererPeriodPositionCallback> rendererPeriodPositionCallback = nullptr;
486     fastAudioStream->SetRendererPeriodPositionCallback(0, rendererPeriodPositionCallback);
487     fastAudioStream->UnsetRendererPeriodPositionCallback();
488 
489     std::shared_ptr<CapturerPositionCallback> capturerPositionCallback = nullptr;
490     fastAudioStream->SetCapturerPositionCallback(0, capturerPositionCallback);
491     fastAudioStream->UnsetCapturerPositionCallback();
492 
493     std::shared_ptr<CapturerPeriodPositionCallback> capturerPeriodPositionCallback = nullptr;
494     fastAudioStream->SetCapturerPeriodPositionCallback(0, capturerPeriodPositionCallback);
495     fastAudioStream->UnsetCapturerPeriodPositionCallback();
496 
497     int32_t res = fastAudioStream->SetRendererSamplingRate(0);
498     EXPECT_EQ(res, ERR_OPERATION_FAILED);
499 
500     uint32_t samplingRate = fastAudioStream->streamInfo_.samplingRate;
501     uint32_t rate = fastAudioStream->GetRendererSamplingRate();
502     EXPECT_EQ(rate, samplingRate);
503 }
504 
505 /**
506  * @tc.name  : Test SetAudioStreamInfo API
507  * @tc.type  : FUNC
508  * @tc.number: SetAudioStreamInfo_001
509  * @tc.desc  : Test SetAudioStreamInfo interface.
510  */
511 HWTEST(FastSystemStreamUnitTest, SetAudioStreamInfo_001, TestSize.Level1)
512 {
513     AUDIO_INFO_LOG("AudioSystemManagerUnitTest SetAudioStreamInfo_001 start");
514     int32_t appUid = static_cast<int32_t>(getuid());
515     std::shared_ptr<FastAudioStream> fastAudioStream;
516     fastAudioStream = std::make_shared<FastAudioStream>(STREAM_MUSIC, AUDIO_MODE_PLAYBACK, appUid);
517     std::shared_ptr<AudioClientTracker> proxyObj;
518     fastAudioStream->state_ = PREPARED;
519     AudioStreamParams info;
520     int32_t res = fastAudioStream->SetAudioStreamInfo(info, proxyObj);
521     EXPECT_EQ(res, ERR_INVALID_PARAM);
522 }
523 
524 /**
525  * @tc.name  : Test SetAudioStreamInfo API
526  * @tc.type  : FUNC
527  * @tc.number: SetAudioStreamInfo_002
528  * @tc.desc  : Test SetAudioStreamInfo interface.
529  */
530 HWTEST(FastSystemStreamUnitTest, SetAudioStreamInfo_002, TestSize.Level1)
531 {
532     AUDIO_INFO_LOG("AudioSystemManagerUnitTest SetAudioStreamInfo_002 start");
533     int32_t appUid = static_cast<int32_t>(getuid());
534     std::shared_ptr<FastAudioStream> fastAudioStream;
535     fastAudioStream = std::make_shared<FastAudioStream>(STREAM_MUSIC, AUDIO_MODE_PLAYBACK, appUid);
536     std::shared_ptr<AudioClientTracker> proxyObj;
537     AudioStreamParams info;
538     info.format = AudioSampleFormat::SAMPLE_S16LE;
539     info.encoding = AudioEncodingType::ENCODING_PCM;
540     info.samplingRate = AudioSamplingRate::SAMPLE_RATE_48000;
541     info.channels = AudioChannel::MONO;
542     info.channelLayout = AudioChannelLayout::CH_LAYOUT_MONO;
543     int32_t res = fastAudioStream->SetAudioStreamInfo(info, proxyObj);
544     EXPECT_NE(res, SUCCESS);
545     auto ret = fastAudioStream->RestoreAudioStream(true);
546     EXPECT_FALSE(ret);
547 }
548 
549 /**
550  * @tc.name  : Test RestoreAudioStream API
551  * @tc.type  : FUNC
552  * @tc.number: RestoreAudioStream_001
553  * @tc.desc  : Test RestoreAudioStream interface.
554  */
555 HWTEST(FastSystemStreamUnitTest, RestoreAudioStream_001, TestSize.Level1)
556 {
557     AUDIO_INFO_LOG("AudioSystemManagerUnitTest RestoreAudioStream_001 start");
558     int32_t appUid = static_cast<int32_t>(getuid());
559     std::shared_ptr<FastAudioStream> fastAudioStream;
560     fastAudioStream = std::make_shared<FastAudioStream>(STREAM_MUSIC, AUDIO_MODE_PLAYBACK, appUid);
561     bool result = false;
562     AudioStreamParams info;
563     info.format = AudioSampleFormat::SAMPLE_S16LE;
564     info.encoding = AudioEncodingType::ENCODING_PCM;
565     info.samplingRate = AudioSamplingRate::SAMPLE_RATE_48000;
566     info.channels = AudioChannel::MONO;
567     info.channelLayout = AudioChannelLayout::CH_LAYOUT_MONO;
568     std::shared_ptr<AudioClientTracker> proxyObj = std::make_shared<AudioClientTrackerTest>();
569     fastAudioStream->proxyObj_ = proxyObj;
570     fastAudioStream->streamInfo_ = info;
571     fastAudioStream->state_ = RUNNING;
572     result = fastAudioStream->SetAudioStreamInfo(info, proxyObj);
573     EXPECT_EQ(result, true);
574     fastAudioStream->state_ = PAUSED;
575     result = fastAudioStream->SetAudioStreamInfo(info, proxyObj);
576     EXPECT_EQ(result, true);
577     fastAudioStream->state_ = STOPPED;
578     result = fastAudioStream->SetAudioStreamInfo(info, proxyObj);
579     EXPECT_EQ(result, true);
580     fastAudioStream->state_ = STOPPING;
581     result = fastAudioStream->SetAudioStreamInfo(info, proxyObj);
582     EXPECT_EQ(result, true);
583     fastAudioStream->state_ = INVALID;
584     result = fastAudioStream->SetAudioStreamInfo(info, proxyObj);
585     EXPECT_EQ(result, true);
586 }
587 
588 /**
589  * @tc.name  : Test InitializeAudioProcessConfig API
590  * @tc.type  : FUNC
591  * @tc.number: InitializeAudioProcessConfig_001
592  * @tc.desc  : Test InitializeAudioProcessConfig interface.
593  */
594 HWTEST(FastSystemStreamUnitTest, InitializeAudioProcessConfig_001, TestSize.Level1)
595 {
596     int32_t appUid = static_cast<int32_t>(getuid());
597     std::shared_ptr<FastAudioStream> fastAudioStream;
598     fastAudioStream = std::make_shared<FastAudioStream>(STREAM_MUSIC, AUDIO_MODE_PLAYBACK, appUid);
599 
600     AUDIO_INFO_LOG("AudioSystemManagerUnitTest InitializeAudioProcessConfig_001 start");
601     AudioProcessConfig config;
602     AudioStreamParams info;
603     fastAudioStream->eMode_ = static_cast<AudioMode>(-1);
604     auto result = fastAudioStream->InitializeAudioProcessConfig(config, info);
605     EXPECT_EQ(result, ERR_INVALID_OPERATION);
606 }
607 
608 /**
609  * @tc.name  : Test InitializeAudioProcessConfig API
610  * @tc.type  : FUNC
611  * @tc.number: InitializeAudioProcessConfig_002
612  * @tc.desc  : Test InitializeAudioProcessConfig interface.
613  */
614 HWTEST(FastSystemStreamUnitTest, InitializeAudioProcessConfig_002, TestSize.Level1)
615 {
616     int32_t appUid = static_cast<int32_t>(getuid());
617     std::shared_ptr<FastAudioStream> fastAudioStream;
618     fastAudioStream = std::make_shared<FastAudioStream>(STREAM_MUSIC, AUDIO_MODE_PLAYBACK, appUid);
619     AudioRendererInfo rendererInfo;
620     rendererInfo.isVirtualKeyboard = true;
621     fastAudioStream->SetRendererInfo(rendererInfo);
622 
623     AUDIO_INFO_LOG("AudioSystemManagerUnitTest InitializeAudioProcessConfig_002 start");
624     AudioProcessConfig config;
625     AudioStreamParams info;
626     auto result = fastAudioStream->InitializeAudioProcessConfig(config, info);
627     EXPECT_TRUE(config.rendererInfo.isVirtualKeyboard);
628     EXPECT_NE(result, ERR_INVALID_OPERATION);
629 }
630 
631 /**
632  * @tc.name  : Test GetState API
633  * @tc.type  : FUNC
634  * @tc.number: GetState_001
635  * @tc.desc  : Test GetState interface.
636  */
637 HWTEST(FastSystemStreamUnitTest, GetState_001, TestSize.Level1)
638 {
639     int32_t appUid = static_cast<int32_t>(getuid());
640     std::shared_ptr<FastAudioStream> fastAudioStream;
641     fastAudioStream = std::make_shared<FastAudioStream>(STREAM_MUSIC, AUDIO_MODE_PLAYBACK, appUid);
642 
643     AUDIO_INFO_LOG("AudioSystemManagerUnitTest GetState_001 start");
644     fastAudioStream->switchingInfo_.isSwitching_ = true;
645     auto result = fastAudioStream->GetState();
646     EXPECT_EQ(result, State::INVALID);
647 }
648 
649 /**
650  * @tc.name  : Test GetAudioPosition API
651  * @tc.type  : FUNC
652  * @tc.number: GetAudioPosition_001
653  * @tc.desc  : Test GetAudioPosition interface.
654  */
655 HWTEST(FastSystemStreamUnitTest, GetAudioPosition_001, TestSize.Level1)
656 {
657     int32_t appUid = static_cast<int32_t>(getuid());
658     std::shared_ptr<FastAudioStream> fastAudioStream;
659     fastAudioStream = std::make_shared<FastAudioStream>(STREAM_MUSIC, AUDIO_MODE_PLAYBACK, appUid);
660 
661     AUDIO_INFO_LOG("AudioSystemManagerUnitTest GetAudioPosition_001 start");
662     Timestamp timestamp;
663     Timestamp::Timestampbase base = Timestamp::Timestampbase::MONOTONIC;
664     auto result = fastAudioStream->GetAudioPosition(timestamp, base);
665     EXPECT_EQ(result, false);
666 }
667 
668 /**
669  * @tc.name  : Test SetRendererFirstFrameWritingCallback API
670  * @tc.type  : FUNC
671  * @tc.number: SetRendererFirstFrameWritingCallback_001
672  * @tc.desc  : Test SetRendererFirstFrameWritingCallback interface.
673  */
674 HWTEST(FastSystemStreamUnitTest, SetRendererFirstFrameWritingCallback_001, TestSize.Level1)
675 {
676     int32_t appUid = static_cast<int32_t>(getuid());
677     std::shared_ptr<FastAudioStream> fastAudioStream;
678     fastAudioStream = std::make_shared<FastAudioStream>(STREAM_MUSIC, AUDIO_MODE_PLAYBACK, appUid);
679 
680     AUDIO_INFO_LOG("AudioSystemManagerUnitTest SetRendererFirstFrameWritingCallback_001 start");
681     std::shared_ptr<AudioRendererFirstFrameWritingCallback> callback =
682         std::make_shared<AudioRendererFirstFrameWritingCallbackTest>();
683     auto result = fastAudioStream->SetRendererFirstFrameWritingCallback(callback);
684     EXPECT_EQ(result, SUCCESS);
685 }
686 
687 /**
688  * @tc.name  : Test SetPreferredFrameSize API
689  * @tc.type  : FUNC
690  * @tc.number: SetPreferredFrameSize_001
691  * @tc.desc  : Test SetPreferredFrameSize interface.
692  */
693 HWTEST(FastSystemStreamUnitTest, SetPreferredFrameSize_001, TestSize.Level1)
694 {
695     int32_t appUid = static_cast<int32_t>(getuid());
696     std::shared_ptr<FastAudioStream> fastAudioStream;
697     fastAudioStream = std::make_shared<FastAudioStream>(STREAM_MUSIC, AUDIO_MODE_PLAYBACK, appUid);
698 
699     AUDIO_INFO_LOG("AudioSystemManagerUnitTest SetPreferredFrameSize_001 start");
700     int32_t frameSize = 0;
701     fastAudioStream->SetPreferredFrameSize(frameSize);
702 }
703 
704 /**
705  * @tc.name  : Test UpdateLatencyTimestamp API
706  * @tc.type  : FUNC
707  * @tc.number: UpdateLatencyTimestamp_001
708  * @tc.desc  : Test UpdateLatencyTimestamp interface.
709  */
710 HWTEST(FastSystemStreamUnitTest, UpdateLatencyTimestamp_001, TestSize.Level1)
711 {
712     int32_t appUid = static_cast<int32_t>(getuid());
713     std::shared_ptr<FastAudioStream> fastAudioStream;
714     fastAudioStream = std::make_shared<FastAudioStream>(STREAM_MUSIC, AUDIO_MODE_PLAYBACK, appUid);
715 
716     AUDIO_INFO_LOG("AudioSystemManagerUnitTest UpdateLatencyTimestamp_001 start");
717     std::string timestamp = "";
718     bool isRenderer = true;
719     fastAudioStream->UpdateLatencyTimestamp(timestamp, isRenderer);
720 }
721 
722 /**
723  * @tc.name  : Test Read API
724  * @tc.type  : FUNC
725  * @tc.number: Read_001
726  * @tc.desc  : Test Read interface.
727  */
728 HWTEST(FastSystemStreamUnitTest, Read_001, TestSize.Level1)
729 {
730     int32_t appUid = static_cast<int32_t>(getuid());
731     std::shared_ptr<FastAudioStream> fastAudioStream;
732     fastAudioStream = std::make_shared<FastAudioStream>(STREAM_MUSIC, AUDIO_MODE_PLAYBACK, appUid);
733 
734     AUDIO_INFO_LOG("AudioSystemManagerUnitTest Read_001 start");
735     uint8_t buffer = 0XFF;
736     size_t userSize = 0;
737     bool isBlockingRead = true;
738     auto result = fastAudioStream->Read(buffer, userSize, isBlockingRead);
739     EXPECT_EQ(result, ERR_INVALID_OPERATION);
740 }
741 
742 /**
743  * @tc.name  : Test Write API
744  * @tc.type  : FUNC
745  * @tc.number: Write_001
746  * @tc.desc  : Test Write interface.
747  */
748 HWTEST(FastSystemStreamUnitTest, Write_001, TestSize.Level1)
749 {
750     int32_t appUid = static_cast<int32_t>(getuid());
751     std::shared_ptr<FastAudioStream> fastAudioStream;
752     fastAudioStream = std::make_shared<FastAudioStream>(STREAM_MUSIC, AUDIO_MODE_PLAYBACK, appUid);
753 
754     AUDIO_INFO_LOG("AudioSystemManagerUnitTest Write_001 start");
755     uint8_t *pcmBuffer = new uint8_t[2];
756     size_t pcmBufferSize = 0;
757     uint8_t *metaBuffer = new uint8_t[2];
758     size_t metaBufferSize = 0;
759     auto result = fastAudioStream->Write(pcmBuffer, pcmBufferSize, metaBuffer, metaBufferSize);
760     EXPECT_EQ(result, ERR_INVALID_OPERATION);
761 }
762 
763 /**
764  * @tc.name  : Test SetUnderflowCount API
765  * @tc.type  : FUNC
766  * @tc.number: SetUnderflowCount_001
767  * @tc.desc  : Test SetUnderflowCount interface.
768  */
769 HWTEST(FastSystemStreamUnitTest, SetUnderflowCount_001, TestSize.Level1)
770 {
771     int32_t appUid = static_cast<int32_t>(getuid());
772     std::shared_ptr<FastAudioStream> fastAudioStream;
773     fastAudioStream = std::make_shared<FastAudioStream>(STREAM_MUSIC, AUDIO_MODE_PLAYBACK, appUid);
774 
775     AUDIO_INFO_LOG("AudioSystemManagerUnitTest SetUnderflowCount_001 start");
776     uint32_t underflowCount = 0;
777     fastAudioStream->SetUnderflowCount(underflowCount);
778 }
779 
780 /**
781  * @tc.name  : Test SetOverflowCount API
782  * @tc.type  : FUNC
783  * @tc.number: SetOverflowCount_001
784  * @tc.desc  : Test SetOverflowCount interface.
785  */
786 HWTEST(FastSystemStreamUnitTest, SetOverflowCount_001, TestSize.Level1)
787 {
788     int32_t appUid = static_cast<int32_t>(getuid());
789     std::shared_ptr<FastAudioStream> fastAudioStream;
790     fastAudioStream = std::make_shared<FastAudioStream>(STREAM_MUSIC, AUDIO_MODE_PLAYBACK, appUid);
791 
792     AUDIO_INFO_LOG("AudioSystemManagerUnitTest SetOverflowCount_001 start");
793     uint32_t overflowCount = 0;
794     fastAudioStream->SetOverflowCount(overflowCount);
795 }
796 
797 /**
798  * @tc.name  : Test SetBufferSizeInMsec API
799  * @tc.type  : FUNC
800  * @tc.number: SetBufferSizeInMsec_001
801  * @tc.desc  : Test SetBufferSizeInMsec interface.
802  */
803 HWTEST(FastSystemStreamUnitTest, SetBufferSizeInMsec_001, TestSize.Level1)
804 {
805     int32_t appUid = static_cast<int32_t>(getuid());
806     std::shared_ptr<FastAudioStream> fastAudioStream;
807     fastAudioStream = std::make_shared<FastAudioStream>(STREAM_MUSIC, AUDIO_MODE_PLAYBACK, appUid);
808 
809     AUDIO_INFO_LOG("AudioSystemManagerUnitTest SetBufferSizeInMsec_001 start");
810     int32_t bufferSizeInMsec = 0;
811     auto result = fastAudioStream->SetBufferSizeInMsec(bufferSizeInMsec);
812     EXPECT_EQ(result, ERR_NOT_SUPPORTED);
813 }
814 
815 /**
816  * @tc.name  : Test SetInnerCapturerState API
817  * @tc.type  : FUNC
818  * @tc.number: SetInnerCapturerState_001
819  * @tc.desc  : Test SetInnerCapturerState interface.
820  */
821 HWTEST(FastSystemStreamUnitTest, SetInnerCapturerState_001, TestSize.Level1)
822 {
823     int32_t appUid = static_cast<int32_t>(getuid());
824     std::shared_ptr<FastAudioStream> fastAudioStream;
825     fastAudioStream = std::make_shared<FastAudioStream>(STREAM_MUSIC, AUDIO_MODE_PLAYBACK, appUid);
826 
827     AUDIO_INFO_LOG("AudioSystemManagerUnitTest SetInnerCapturerState_001 start");
828     bool isInnerCapturer = true;
829     fastAudioStream->SetInnerCapturerState(isInnerCapturer);
830 }
831 
832 /**
833  * @tc.name  : Test SetWakeupCapturerState API
834  * @tc.type  : FUNC
835  * @tc.number: SetWakeupCapturerState_001
836  * @tc.desc  : Test SetWakeupCapturerState interface.
837  */
838 HWTEST(FastSystemStreamUnitTest, SetWakeupCapturerState_001, TestSize.Level1)
839 {
840     int32_t appUid = static_cast<int32_t>(getuid());
841     std::shared_ptr<FastAudioStream> fastAudioStream;
842     fastAudioStream = std::make_shared<FastAudioStream>(STREAM_MUSIC, AUDIO_MODE_PLAYBACK, appUid);
843 
844     AUDIO_INFO_LOG("AudioSystemManagerUnitTest SetWakeupCapturerState_001 start");
845     bool isWakeupCapturer = true;
846     fastAudioStream->SetWakeupCapturerState(isWakeupCapturer);
847 }
848 
849 /**
850  * @tc.name  : Test OnFirstFrameWriting API
851  * @tc.type  : FUNC
852  * @tc.number: OnFirstFrameWriting_001
853  * @tc.desc  : Test OnFirstFrameWriting interface.
854  */
855 HWTEST(FastSystemStreamUnitTest, OnFirstFrameWriting_001, TestSize.Level1)
856 {
857     int32_t appUid = static_cast<int32_t>(getuid());
858     std::shared_ptr<FastAudioStream> fastAudioStream;
859     fastAudioStream = std::make_shared<FastAudioStream>(STREAM_MUSIC, AUDIO_MODE_PLAYBACK, appUid);
860 
861     AUDIO_INFO_LOG("AudioSystemManagerUnitTest OnFirstFrameWriting_001 start");
862     fastAudioStream->OnFirstFrameWriting();
863 }
864 
865 /**
866  * @tc.name  : Test OnHandleData API
867  * @tc.type  : FUNC
868  * @tc.number: OnHandleData_001
869  * @tc.desc  : Test OnHandleData interface.
870  */
871 HWTEST(FastSystemStreamUnitTest, OnHandleData_001, TestSize.Level1)
872 {
873     std::shared_ptr<AudioRendererWriteCallback> callback = std::make_shared<AudioRendererWriteCallbackTest>();
874     AudioStreamParams tempParams = {};
875     auto audioStream = IAudioStream::GetRecordStream(IAudioStream::PA_STREAM, tempParams, STREAM_MUSIC, getpid());
876     std::shared_ptr<FastAudioStreamRenderCallback> fastAudioStreamRenderCallback;
877     fastAudioStreamRenderCallback = std::make_shared<FastAudioStreamRenderCallback>(callback, *audioStream);
878 
879     AUDIO_INFO_LOG("AudioSystemManagerUnitTest OnHandleData_001 start");
880     size_t length = 0;
881     fastAudioStreamRenderCallback->OnHandleData(length);
882 }
883 
884 /**
885  * @tc.name  : Test ResetFirstFrameState API
886  * @tc.type  : FUNC
887  * @tc.number: ResetFirstFrameState_001
888  * @tc.desc  : Test ResetFirstFrameState interface.
889  */
890 HWTEST(FastSystemStreamUnitTest, ResetFirstFrameState_001, TestSize.Level1)
891 {
892     std::shared_ptr<AudioRendererWriteCallback> callback = std::make_shared<AudioRendererWriteCallbackTest>();
893     AudioStreamParams tempParams = {};
894     auto audioStream = IAudioStream::GetRecordStream(IAudioStream::PA_STREAM, tempParams, STREAM_MUSIC, getpid());
895     std::shared_ptr<FastAudioStreamRenderCallback> fastAudioStreamRenderCallback;
896     fastAudioStreamRenderCallback = std::make_shared<FastAudioStreamRenderCallback>(callback, *audioStream);
897 
898     AUDIO_INFO_LOG("AudioSystemManagerUnitTest ResetFirstFrameState_001 start");
899     fastAudioStreamRenderCallback->ResetFirstFrameState();
900 }
901 
902 /**
903  * @tc.name  : Test ResetFirstFrameState API
904  * @tc.type  : FUNC
905  * @tc.number: ResetFirstFrameState_002
906  * @tc.desc  : Test ResetFirstFrameState interface. - do nothing when spkProcClientCb_ is null
907  */
908 HWTEST(FastSystemStreamUnitTest, ResetFirstFrameState_002, TestSize.Level1)
909 {
910     int32_t appUid = static_cast<int32_t>(getuid());
911     std::shared_ptr<FastAudioStream> fastAudioStream =
912         std::make_shared<FastAudioStream>(STREAM_MUSIC, AUDIO_MODE_PLAYBACK, appUid);
913     EXPECT_NE(fastAudioStream, nullptr);
914 
915     std::shared_ptr<AudioRendererWriteCallback> spkCallback = std::make_shared<AudioRendererWriteCallbackTest>();
916     AudioStreamParams tempParams = {};
917     auto audioStream = IAudioStream::GetRecordStream(IAudioStream::PA_STREAM, tempParams, STREAM_MUSIC, getpid());
918     auto spkProcClientCb = std::make_shared<FastAudioStreamRenderCallback>(spkCallback, *audioStream);
919     spkProcClientCb->hasFirstFrameWrited_.store(true);
920 
921     fastAudioStream->spkProcClientCb_ = spkProcClientCb;
922     fastAudioStream->ResetFirstFrameState();
923 
924     fastAudioStream->spkProcClientCb_ = nullptr;
925     fastAudioStream->ResetFirstFrameState();
926 
927     EXPECT_EQ(spkProcClientCb->hasFirstFrameWrited_.load(), false);
928 }
929 
930 /**
931  * @tc.name  : Test GetRendererWriteCallback API
932  * @tc.type  : FUNC
933  * @tc.number: GetRendererWriteCallback_001
934  * @tc.desc  : Test GetRendererWriteCallback interface.
935  */
936 HWTEST(FastSystemStreamUnitTest, GetRendererWriteCallback_001, TestSize.Level1)
937 {
938     std::shared_ptr<AudioRendererWriteCallback> callback = std::make_shared<AudioRendererWriteCallbackTest>();
939     AudioStreamParams tempParams = {};
940     auto audioStream = IAudioStream::GetRecordStream(IAudioStream::PA_STREAM, tempParams, STREAM_MUSIC, getpid());
941     std::shared_ptr<FastAudioStreamRenderCallback> fastAudioStreamRenderCallback;
942     fastAudioStreamRenderCallback = std::make_shared<FastAudioStreamRenderCallback>(callback, *audioStream);
943 
944     AUDIO_INFO_LOG("AudioSystemManagerUnitTest GetRendererWriteCallback_001 start");
945     auto result = fastAudioStreamRenderCallback->GetRendererWriteCallback();
946     EXPECT_NE(result, nullptr);
947 }
948 
949 /**
950  * @tc.name  : Test GetCapturerReadCallback API
951  * @tc.type  : FUNC
952  * @tc.number: GetCapturerReadCallback_001
953  * @tc.desc  : Test GetCapturerReadCallback interface.
954  */
955 HWTEST(FastSystemStreamUnitTest, GetCapturerReadCallback_001, TestSize.Level1)
956 {
957     std::shared_ptr<AudioCapturerReadCallback> callback = std::make_shared<AudioCapturerReadCallbackTest>();
958     std::shared_ptr<FastAudioStreamCaptureCallback> fastAudioStreamCaptureCallback;
959     fastAudioStreamCaptureCallback = std::make_shared<FastAudioStreamCaptureCallback>(callback);
960 
961     AUDIO_INFO_LOG("AudioSystemManagerUnitTest GetCapturerReadCallback_001 start");
962     auto result = fastAudioStreamCaptureCallback->GetCapturerReadCallback();
963     EXPECT_NE(result, nullptr);
964 }
965 
966 /**
967  * @tc.name  : Test SetChannelBlendMode API
968  * @tc.type  : FUNC
969  * @tc.number: SetChannelBlendMode_001
970  * @tc.desc  : Test SetChannelBlendMode interface.
971  */
972 HWTEST(FastSystemStreamUnitTest, SetChannelBlendMode_001, TestSize.Level1)
973 {
974     int32_t appUid = static_cast<int32_t>(getuid());
975     std::shared_ptr<FastAudioStream> fastAudioStream;
976     fastAudioStream = std::make_shared<FastAudioStream>(STREAM_MUSIC, AUDIO_MODE_PLAYBACK, appUid);
977 
978     AUDIO_INFO_LOG("AudioSystemManagerUnitTest SetChannelBlendMode_001 start");
979     ChannelBlendMode blendMode = ChannelBlendMode::MODE_DEFAULT;
980     auto result = fastAudioStream->SetChannelBlendMode(blendMode);
981     EXPECT_EQ(result, SUCCESS);
982 }
983 
984 /**
985  * @tc.name  : Test SetVolumeWithRamp API
986  * @tc.type  : FUNC
987  * @tc.number: SetVolumeWithRamp_001
988  * @tc.desc  : Test SetVolumeWithRamp interface.
989  */
990 HWTEST(FastSystemStreamUnitTest, SetVolumeWithRamp_001, TestSize.Level1)
991 {
992     int32_t appUid = static_cast<int32_t>(getuid());
993     std::shared_ptr<FastAudioStream> fastAudioStream;
994     fastAudioStream = std::make_shared<FastAudioStream>(STREAM_MUSIC, AUDIO_MODE_PLAYBACK, appUid);
995 
996     AUDIO_INFO_LOG("AudioSystemManagerUnitTest SetVolumeWithRamp_001 start");
997     float volume = 0;
998     int32_t duration = 0;
999     auto result = fastAudioStream->SetVolumeWithRamp(volume, duration);
1000     EXPECT_EQ(result, SUCCESS);
1001 }
1002 
1003 /**
1004  * @tc.name  : Test GetOffloadEnable API
1005  * @tc.type  : FUNC
1006  * @tc.number: GetOffloadEnable_001
1007  * @tc.desc  : Test GetOffloadEnable interface.
1008  */
1009 HWTEST(FastSystemStreamUnitTest, GetOffloadEnable_001, TestSize.Level1)
1010 {
1011     int32_t appUid = static_cast<int32_t>(getuid());
1012     std::shared_ptr<FastAudioStream> fastAudioStream;
1013     fastAudioStream = std::make_shared<FastAudioStream>(STREAM_MUSIC, AUDIO_MODE_PLAYBACK, appUid);
1014 
1015     AUDIO_INFO_LOG("AudioSystemManagerUnitTest GetOffloadEnable_001 start");
1016     auto result = fastAudioStream->GetOffloadEnable();
1017     EXPECT_EQ(result, false);
1018 }
1019 
1020 /**
1021  * @tc.name  : Test GetSpatializationEnabled API
1022  * @tc.type  : FUNC
1023  * @tc.number: GetSpatializationEnabled_001
1024  * @tc.desc  : Test GetSpatializationEnabled interface.
1025  */
1026 HWTEST(FastSystemStreamUnitTest, GetSpatializationEnabled_001, TestSize.Level1)
1027 {
1028     int32_t appUid = static_cast<int32_t>(getuid());
1029     std::shared_ptr<FastAudioStream> fastAudioStream;
1030     fastAudioStream = std::make_shared<FastAudioStream>(STREAM_MUSIC, AUDIO_MODE_PLAYBACK, appUid);
1031 
1032     AUDIO_INFO_LOG("AudioSystemManagerUnitTest GetSpatializationEnabled_001 start");
1033     auto result = fastAudioStream->GetSpatializationEnabled();
1034     EXPECT_EQ(result, false);
1035 }
1036 
1037 /**
1038  * @tc.name  : Test GetHighResolutionEnabled API
1039  * @tc.type  : FUNC
1040  * @tc.number: GetHighResolutionEnabled_001
1041  * @tc.desc  : Test GetHighResolutionEnabled interface.
1042  */
1043 HWTEST(FastSystemStreamUnitTest, GetHighResolutionEnabled_001, TestSize.Level1)
1044 {
1045     int32_t appUid = static_cast<int32_t>(getuid());
1046     std::shared_ptr<FastAudioStream> fastAudioStream;
1047     fastAudioStream = std::make_shared<FastAudioStream>(STREAM_MUSIC, AUDIO_MODE_PLAYBACK, appUid);
1048 
1049     AUDIO_INFO_LOG("AudioSystemManagerUnitTest GetHighResolutionEnabled_001 start");
1050     auto result = fastAudioStream->GetHighResolutionEnabled();
1051     EXPECT_EQ(result, false);
1052 }
1053 
1054 /**
1055  * @tc.name  : Test SetDefaultOutputDevice API
1056  * @tc.type  : FUNC
1057  * @tc.number: SetDefaultOutputDevice_001
1058  * @tc.desc  : Test SetDefaultOutputDevice interface.
1059  */
1060 HWTEST(FastSystemStreamUnitTest, SetDefaultOutputDevice_001, TestSize.Level1)
1061 {
1062     int32_t appUid = static_cast<int32_t>(getuid());
1063     std::shared_ptr<FastAudioStream> fastAudioStream;
1064     fastAudioStream = std::make_shared<FastAudioStream>(STREAM_MUSIC, AUDIO_MODE_PLAYBACK, appUid);
1065 
1066     AUDIO_INFO_LOG("AudioSystemManagerUnitTest SetDefaultOutputDevice_001 start");
1067     DeviceType defaultOuputDevice = DeviceType::DEVICE_TYPE_INVALID;
1068     auto result = fastAudioStream->SetDefaultOutputDevice(defaultOuputDevice);
1069     EXPECT_EQ(result, ERR_OPERATION_FAILED);
1070 }
1071 
1072 /**
1073  * @tc.name  : Test GetAudioTimestampInfo API
1074  * @tc.type  : FUNC
1075  * @tc.number: GetAudioTimestampInfo_001
1076  * @tc.desc  : Test GetAudioTimestampInfo interface.
1077  */
1078 HWTEST(FastSystemStreamUnitTest, GetAudioTimestampInfo_001, TestSize.Level1)
1079 {
1080     int32_t appUid = static_cast<int32_t>(getuid());
1081     std::shared_ptr<FastAudioStream> fastAudioStream;
1082     fastAudioStream = std::make_shared<FastAudioStream>(STREAM_MUSIC, AUDIO_MODE_PLAYBACK, appUid);
1083 
1084     AUDIO_INFO_LOG("AudioSystemManagerUnitTest GetAudioTimestampInfo_001 start");
1085     Timestamp timestamp;
1086     Timestamp::Timestampbase base = Timestamp::Timestampbase::MONOTONIC;
1087     auto result = fastAudioStream->GetAudioTimestampInfo(timestamp, base);
1088     EXPECT_NE(result, SUCCESS);
1089 }
1090 
1091 /**
1092  * @tc.name  : Test SetSwitchingStatus API
1093  * @tc.type  : FUNC
1094  * @tc.number: SetSwitchingStatus_001
1095  * @tc.desc  : Test SetSwitchingStatus interface.
1096  */
1097 HWTEST(FastSystemStreamUnitTest, SetSwitchingStatus_001, TestSize.Level1)
1098 {
1099     int32_t appUid = static_cast<int32_t>(getuid());
1100     std::shared_ptr<FastAudioStream> fastAudioStream;
1101     fastAudioStream = std::make_shared<FastAudioStream>(STREAM_MUSIC, AUDIO_MODE_PLAYBACK, appUid);
1102 
1103     AUDIO_INFO_LOG("AudioSystemManagerUnitTest SetSwitchingStatus_001 start");
1104     bool isSwitching = true;
1105     fastAudioStream->SetSwitchingStatus(isSwitching);
1106 }
1107 
1108 /**
1109  * @tc.name  : Test SetSwitchingStatus API
1110  * @tc.type  : FUNC
1111  * @tc.number: SetSwitchingStatus_002
1112  * @tc.desc  : Test SetSwitchingStatus interface.
1113  */
1114 HWTEST(FastSystemStreamUnitTest, SetSwitchingStatus_002, TestSize.Level1)
1115 {
1116     int32_t appUid = static_cast<int32_t>(getuid());
1117     std::shared_ptr<FastAudioStream> fastAudioStream;
1118     fastAudioStream = std::make_shared<FastAudioStream>(STREAM_MUSIC, AUDIO_MODE_PLAYBACK, appUid);
1119 
1120     AUDIO_INFO_LOG("AudioSystemManagerUnitTest SetSwitchingStatus_002 start");
1121     bool isSwitching = false;
1122     fastAudioStream->SetSwitchingStatus(isSwitching);
1123 }
1124 
1125 /**
1126  * @tc.name  : Test InitCallbackHandler API
1127  * @tc.type  : FUNC
1128  * @tc.number: InitCallbackHandler_001
1129  * @tc.desc  : Test InitCallbackHandler interface.
1130  */
1131 HWTEST(FastSystemStreamUnitTest, InitCallbackHandler_001, TestSize.Level1)
1132 {
1133     int32_t appUid = static_cast<int32_t>(getuid());
1134     std::shared_ptr<FastAudioStream> fastAudioStream =
1135         std::make_shared<FastAudioStream>(STREAM_MUSIC, AUDIO_MODE_PLAYBACK, appUid);
1136 
1137     fastAudioStream->InitCallbackHandler();
1138     EXPECT_NE(fastAudioStream->callbackHandler_, nullptr);
1139 }
1140 
1141 /**
1142  * @tc.name  : Test SafeSendCallbackEvent API
1143  * @tc.type  : FUNC
1144  * @tc.number: SafeSendCallbackEvent_001
1145  * @tc.desc  : Test SafeSendCallbackEvent interface.
1146  */
1147 HWTEST(FastSystemStreamUnitTest, SafeSendCallbackEvent_001, TestSize.Level1)
1148 {
1149     int32_t appUid = static_cast<int32_t>(getuid());
1150     std::shared_ptr<FastAudioStream> fastAudioStream =
1151         std::make_shared<FastAudioStream>(STREAM_MUSIC, AUDIO_MODE_PLAYBACK, appUid);
1152     uint32_t eventCode = 1;
1153     int64_t data = 0;
1154 
1155     fastAudioStream->SafeSendCallbackEvent(eventCode, data);
1156     EXPECT_EQ(fastAudioStream->callbackHandler_, nullptr);
1157 
1158     fastAudioStream->runnerReleased_ = false;
1159     fastAudioStream->InitCallbackHandler();
1160     fastAudioStream->SafeSendCallbackEvent(eventCode, data);
1161     EXPECT_NE(fastAudioStream->callbackHandler_, nullptr);
1162 
1163     fastAudioStream->runnerReleased_ = true;
1164     fastAudioStream->SafeSendCallbackEvent(eventCode, data);
1165     EXPECT_NE(fastAudioStream->callbackHandler_, nullptr);
1166 }
1167 
1168 /**
1169  * @tc.name  : Test HandleStateChangeEvent API
1170  * @tc.type  : FUNC
1171  * @tc.number: HandleStateChangeEvent_001
1172  * @tc.desc  : Test HandleStateChangeEvent interface.
1173  */
1174 HWTEST(FastSystemStreamUnitTest, HandleStateChangeEvent_001, TestSize.Level1)
1175 {
1176     int32_t appUid = static_cast<int32_t>(getuid());
1177     std::shared_ptr<FastAudioStream> fastAudioStream =
1178         std::make_shared<FastAudioStream>(STREAM_MUSIC, AUDIO_MODE_PLAYBACK, appUid);
1179     int64_t data = 0;
1180     auto callback = std::make_shared<AudioStreamCallbackTest>();
1181 
1182     data = FastAudioStream::HANDLER_PARAM_NEW;
1183     fastAudioStream->SetStreamCallback(callback);
1184     fastAudioStream->HandleStateChangeEvent(data);
1185     EXPECT_NE(fastAudioStream->streamCallback_.lock(), nullptr);
1186 
1187     data = FastAudioStream::HANDLER_PARAM_STOPPING;
1188     fastAudioStream->HandleStateChangeEvent(data);
1189     EXPECT_NE(fastAudioStream->streamCallback_.lock(), nullptr);
1190 }
1191 
1192 /**
1193  * @tc.name  : Test ParamsToStateCmdType API
1194  * @tc.type  : FUNC
1195  * @tc.number: ParamsToStateCmdType_001
1196  * @tc.desc  : Test ParamsToStateCmdType interface.
1197  */
1198 HWTEST(FastSystemStreamUnitTest, ParamsToStateCmdType_001, TestSize.Level1)
1199 {
1200     int32_t appUid = static_cast<int32_t>(getuid());
1201     std::shared_ptr<FastAudioStream> fastAudioStream =
1202         std::make_shared<FastAudioStream>(STREAM_MUSIC, AUDIO_MODE_PLAYBACK, appUid);
1203     int64_t params;
1204     State state;
1205     StateChangeCmdType cmdType;
1206 
1207     params = FastAudioStream::HANDLER_PARAM_NEW;
1208     fastAudioStream->ParamsToStateCmdType(params, state, cmdType);
1209     EXPECT_EQ(state, NEW);
1210 
1211     params = FastAudioStream::HANDLER_PARAM_PREPARED;
1212     fastAudioStream->ParamsToStateCmdType(params, state, cmdType);
1213     EXPECT_EQ(state, PREPARED);
1214 
1215     params = FastAudioStream::HANDLER_PARAM_RUNNING;
1216     fastAudioStream->ParamsToStateCmdType(params, state, cmdType);
1217     EXPECT_EQ(state, RUNNING);
1218 
1219     params = FastAudioStream::HANDLER_PARAM_STOPPED;
1220     fastAudioStream->ParamsToStateCmdType(params, state, cmdType);
1221     EXPECT_EQ(state, STOPPED);
1222 
1223     params = FastAudioStream::HANDLER_PARAM_RELEASED;
1224     fastAudioStream->ParamsToStateCmdType(params, state, cmdType);
1225     EXPECT_EQ(state, RELEASED);
1226 
1227     params = FastAudioStream::HANDLER_PARAM_PAUSED;
1228     fastAudioStream->ParamsToStateCmdType(params, state, cmdType);
1229     EXPECT_EQ(state, PAUSED);
1230 
1231     params = FastAudioStream::HANDLER_PARAM_STOPPING;
1232     fastAudioStream->ParamsToStateCmdType(params, state, cmdType);
1233     EXPECT_EQ(state, STOPPING);
1234 
1235     params = FastAudioStream::HANDLER_PARAM_RUNNING_FROM_SYSTEM;
1236     fastAudioStream->ParamsToStateCmdType(params, state, cmdType);
1237     EXPECT_EQ(state, RUNNING);
1238 
1239     params = FastAudioStream::HANDLER_PARAM_PAUSED_FROM_SYSTEM;
1240     fastAudioStream->ParamsToStateCmdType(params, state, cmdType);
1241     EXPECT_EQ(state, PAUSED);
1242 
1243     params = FastAudioStream::HANDLER_PARAM_INVALID;
1244     fastAudioStream->ParamsToStateCmdType(params, state, cmdType);
1245     EXPECT_EQ(state, INVALID);
1246 }
1247 
1248 /**
1249  * @tc.name  : Test SetSourceDuration API
1250  * @tc.type  : FUNC
1251  * @tc.number: SetSourceDuration_001
1252  * @tc.desc  : Test SetSourceDuration interface.
1253  */
1254 HWTEST(FastSystemStreamUnitTest, SetSourceDuration_001, TestSize.Level1)
1255 {
1256     int32_t appUid = static_cast<int32_t>(getuid());
1257     std::shared_ptr<FastAudioStream> fastAudioStream;
1258     fastAudioStream = std::make_shared<FastAudioStream>(STREAM_MUSIC, AUDIO_MODE_RECORD, appUid);
1259     int64_t duration = 0;
1260     int32_t res;
1261     AudioStreamParams info;
1262     info.format = AudioSampleFormat::SAMPLE_S16LE;
1263     info.encoding = AudioEncodingType::ENCODING_PCM;
1264     info.samplingRate = AudioSamplingRate::SAMPLE_RATE_48000;
1265     info.channels = AudioChannel::MONO;
1266     info.channelLayout = AudioChannelLayout::CH_LAYOUT_MONO;
1267     std::shared_ptr<AudioClientTracker> proxyObj = std::make_shared<AudioClientTrackerTest>();
1268     fastAudioStream->proxyObj_ = proxyObj;
1269     fastAudioStream->streamInfo_ = info;
1270 
1271     res = fastAudioStream->SetSourceDuration(duration);
1272     EXPECT_NE(res, SUCCESS);
1273 
1274     fastAudioStream->eMode_ = AUDIO_MODE_RECORD;
1275     fastAudioStream->state_ = NEW;
1276     res = fastAudioStream->SetAudioStreamInfo(info, proxyObj);
1277     res = fastAudioStream->SetSourceDuration(duration);
1278     EXPECT_NE(res, SUCCESS);
1279 }
1280 
1281 /**
1282  * @tc.name  : Test SetStreamCallback API
1283  * @tc.type  : FUNC
1284  * @tc.number: SetStreamCallback_001
1285  * @tc.desc  : Test SetStreamCallback interface.
1286  */
1287 HWTEST(FastSystemStreamUnitTest, SetStreamCallback_001, TestSize.Level1)
1288 {
1289     int32_t appUid = static_cast<int32_t>(getuid());
1290     std::shared_ptr<FastAudioStream> fastAudioStream =
1291         std::make_shared<FastAudioStream>(STREAM_MUSIC, AUDIO_MODE_PLAYBACK, appUid);
1292     int32_t ret;
1293     std::shared_ptr<AudioStreamCallback> callback = nullptr;
1294 
1295     ret = fastAudioStream->SetStreamCallback(callback);
1296     EXPECT_NE(ret, SUCCESS);
1297 
1298     fastAudioStream->state_ = NEW;
1299     callback = std::make_shared<AudioStreamCallbackTest>();
1300     ret = fastAudioStream->SetStreamCallback(callback);
1301     EXPECT_EQ(ret, SUCCESS);
1302 
1303     fastAudioStream->state_ = PREPARED;
1304     ret = fastAudioStream->SetStreamCallback(callback);
1305     EXPECT_EQ(ret, SUCCESS);
1306 }
1307 
1308 /**
1309  * @tc.name  : Test GetAudioStreamInfo API
1310  * @tc.type  : FUNC
1311  * @tc.number: GetAudioStreamInfo_001
1312  * @tc.desc  : Test GetAudioStreamInfo interface.
1313  */
1314 HWTEST(FastSystemStreamUnitTest, GetAudioStreamInfo_001, TestSize.Level1)
1315 {
1316     int32_t appUid = static_cast<int32_t>(getuid());
1317     auto fastAudioStream =
1318         std::make_shared<FastAudioStream>(STREAM_MUSIC, AUDIO_MODE_PLAYBACK, appUid);
1319     EXPECT_NE(fastAudioStream, nullptr);
1320 
1321     AudioStreamParams audioStreamInfo;
1322     auto ret = fastAudioStream->GetAudioStreamInfo(audioStreamInfo);
1323     EXPECT_EQ(ret, SUCCESS);
1324 }
1325 
1326 /**
1327  * @tc.name  : Test GetAudioSessionID API
1328  * @tc.type  : FUNC
1329  * @tc.number: GetAudioSessionID_001
1330  * @tc.desc  : Test GetAudioSessionID interface.
1331  */
1332 HWTEST(FastSystemStreamUnitTest, GetAudioSessionID_001, TestSize.Level1)
1333 {
1334     int32_t appUid = static_cast<int32_t>(getuid());
1335     auto fastAudioStream =
1336         std::make_shared<FastAudioStream>(STREAM_MUSIC, AUDIO_MODE_PLAYBACK, appUid);
1337     EXPECT_NE(fastAudioStream, nullptr);
1338 
1339     uint32_t sessionId = 0;
1340     auto ret = fastAudioStream->GetAudioSessionID(sessionId);
1341     EXPECT_EQ(ret, ERR_OPERATION_FAILED);
1342 }
1343 
1344 /**
1345  * @tc.name  : Test GetAudioTime API
1346  * @tc.type  : FUNC
1347  * @tc.number: GetAudioTime_001
1348  * @tc.desc  : Test GetAudioTime interface.
1349  */
1350 HWTEST(FastSystemStreamUnitTest, GetAudioTime_001, TestSize.Level1)
1351 {
1352     int32_t appUid = static_cast<int32_t>(getuid());
1353     auto fastAudioStream = std::make_shared<FastAudioStream>(STREAM_MUSIC, AUDIO_MODE_PLAYBACK, appUid);
1354     EXPECT_NE(fastAudioStream, nullptr);
1355 
1356     Timestamp timestamp;
1357     auto base = static_cast<Timestamp::Timestampbase>(1);
1358     auto ret = fastAudioStream->GetAudioTime(timestamp, base);
1359     EXPECT_EQ(ret, false);
1360 
1361     ret = fastAudioStream->GetAudioTime(timestamp, Timestamp::Timestampbase::MONOTONIC);
1362     EXPECT_EQ(ret, false);
1363 
1364     AudioStreamParams info;
1365     info.format = AudioSampleFormat::SAMPLE_S16LE;
1366     info.encoding = AudioEncodingType::ENCODING_PCM;
1367     info.samplingRate = AudioSamplingRate::SAMPLE_RATE_48000;
1368     info.channels = AudioChannel::STEREO;
1369     info.channelLayout = AudioChannelLayout::CH_LAYOUT_MONO;
1370     std::shared_ptr<AudioClientTracker> proxyObj = std::make_shared<AudioClientTrackerTest>();
1371     fastAudioStream->SetAudioStreamInfo(info, proxyObj);
1372 
1373     ret = fastAudioStream->GetAudioTime(timestamp, Timestamp::Timestampbase::MONOTONIC);
1374     EXPECT_NE(ret, true);
1375 }
1376 
1377 /**
1378  * @tc.name  : Test GetBufferSize API
1379  * @tc.type  : FUNC
1380  * @tc.number: GetBufferSize_001
1381  * @tc.desc  : Test GetBufferSize interface.
1382  */
1383 HWTEST(FastSystemStreamUnitTest, GetBufferSize_001, TestSize.Level1)
1384 {
1385     int32_t appUid = static_cast<int32_t>(getuid());
1386     std::shared_ptr<FastAudioStream> fastAudioStream
1387         = std::make_shared<FastAudioStream>(STREAM_MUSIC, AUDIO_MODE_PLAYBACK, appUid);
1388     EXPECT_NE(fastAudioStream, nullptr);
1389 
1390     size_t bufferSize = 0;
1391     auto ret = fastAudioStream->GetBufferSize(bufferSize);
1392     EXPECT_EQ(ret, ERR_OPERATION_FAILED);
1393 }
1394 
1395 /**
1396  * @tc.name  : Test GetFrameCount API
1397  * @tc.type  : FUNC
1398  * @tc.number: GetFrameCount_001
1399  * @tc.desc  : Test GetFrameCount interface.
1400  */
1401 HWTEST(FastSystemStreamUnitTest, GetFrameCount_001, TestSize.Level1)
1402 {
1403     int32_t appUid = static_cast<int32_t>(getuid());
1404     std::shared_ptr<FastAudioStream> fastAudioStream
1405         = std::make_shared<FastAudioStream>(STREAM_MUSIC, AUDIO_MODE_PLAYBACK, appUid);
1406     EXPECT_NE(fastAudioStream, nullptr);
1407 
1408     size_t frameCount = 0;
1409     auto ret = fastAudioStream->GetFrameCount(frameCount);
1410     EXPECT_EQ(ret, ERR_OPERATION_FAILED);
1411 }
1412 
1413 /**
1414  * @tc.name  : Test GetLatency API
1415  * @tc.type  : FUNC
1416  * @tc.number: GetLatency_001
1417  * @tc.desc  : Test GetLatency interface.
1418  */
1419 HWTEST(FastSystemStreamUnitTest, GetLatency_001, TestSize.Level1)
1420 {
1421     int32_t appUid = static_cast<int32_t>(getuid());
1422     std::shared_ptr<FastAudioStream> fastAudioStream
1423         = std::make_shared<FastAudioStream>(STREAM_MUSIC, AUDIO_MODE_PLAYBACK, appUid);
1424     EXPECT_NE(fastAudioStream, nullptr);
1425 
1426     uint64_t latency = 0;
1427     auto ret = fastAudioStream->GetLatency(latency);
1428     EXPECT_EQ(ret, ERR_OPERATION_FAILED);
1429 }
1430 
1431 /**
1432  * @tc.name  : Test SetDuckVolume API
1433  * @tc.type  : FUNC
1434  * @tc.number: SetDuckVolume_001
1435  * @tc.desc  : Test SetDuckVolume interface.
1436  */
1437 HWTEST(FastSystemStreamUnitTest, SetDuckVolume_001, TestSize.Level1)
1438 {
1439     int32_t appUid = static_cast<int32_t>(getuid());
1440     std::shared_ptr<FastAudioStream> fastAudioStream
1441         = std::make_shared<FastAudioStream>(STREAM_MUSIC, AUDIO_MODE_PLAYBACK, appUid);
1442     EXPECT_NE(fastAudioStream, nullptr);
1443 
1444     float duckVolume = 0;
1445     auto ret = fastAudioStream->SetDuckVolume(duckVolume);
1446     EXPECT_EQ(ret, ERR_OPERATION_FAILED);
1447 }
1448 
1449 /**
1450  * @tc.name  : Test SetRenderRate API
1451  * @tc.type  : FUNC
1452  * @tc.number: SetRenderRate_001
1453  * @tc.desc  : Test SetRenderRate interface.
1454  */
1455 HWTEST(FastSystemStreamUnitTest, SetRenderRate_001, TestSize.Level1)
1456 {
1457     int32_t appUid = static_cast<int32_t>(getuid());
1458     std::shared_ptr<FastAudioStream> fastAudioStream
1459         = std::make_shared<FastAudioStream>(STREAM_MUSIC, AUDIO_MODE_PLAYBACK, appUid);
1460     EXPECT_NE(fastAudioStream, nullptr);
1461 
1462     AudioRendererRate renderRate = AudioRendererRate::RENDER_RATE_NORMAL;
1463     auto ret = fastAudioStream->SetRenderRate(renderRate);
1464     EXPECT_EQ(ret, SUCCESS);
1465 
1466     renderRate = AudioRendererRate::RENDER_RATE_DOUBLE;
1467     ret = fastAudioStream->SetRenderRate(renderRate);
1468     EXPECT_EQ(ret, ERR_INVALID_OPERATION);
1469 }
1470 
1471 /**
1472  * @tc.name  : Test SetRendererWriteCallback API
1473  * @tc.type  : FUNC
1474  * @tc.number: SetRendererWriteCallback_001
1475  * @tc.desc  : Test SetRendererWriteCallback interface.
1476  */
1477 HWTEST(FastSystemStreamUnitTest, SetRendererWriteCallback_001, TestSize.Level1)
1478 {
1479     int32_t appUid = static_cast<int32_t>(getuid());
1480     std::shared_ptr<FastAudioStream> fastAudioStream
1481         = std::make_shared<FastAudioStream>(STREAM_MUSIC, AUDIO_MODE_PLAYBACK, appUid);
1482     EXPECT_NE(fastAudioStream, nullptr);
1483 
1484     auto callback = std::make_shared<AudioRendererWriteCallbackTest>();
1485     auto ret = fastAudioStream->SetRendererWriteCallback(callback);
1486     EXPECT_EQ(ret, ERR_INVALID_PARAM);
1487 }
1488 
1489 /**
1490  * @tc.name  : Test SetCapturerReadCallback API
1491  * @tc.type  : FUNC
1492  * @tc.number: SetCapturerReadCallback_001
1493  * @tc.desc  : Test SetCapturerReadCallback interface.
1494  */
1495 HWTEST(FastSystemStreamUnitTest, SetCapturerReadCallback_001, TestSize.Level1)
1496 {
1497     int32_t appUid = static_cast<int32_t>(getuid());
1498     std::shared_ptr<FastAudioStream> fastAudioStream
1499         = std::make_shared<FastAudioStream>(STREAM_MUSIC, AUDIO_MODE_RECORD, appUid);
1500     EXPECT_NE(fastAudioStream, nullptr);
1501 
1502     auto callback = std::make_shared<AudioCapturerReadCallbackTest>();
1503     auto ret = fastAudioStream->SetCapturerReadCallback(callback);
1504     EXPECT_EQ(ret, ERR_INVALID_PARAM);
1505 }
1506 
1507 /**
1508  * @tc.name  : Test GetBufferDesc API
1509  * @tc.type  : FUNC
1510  * @tc.number: GetBufferDesc_001
1511  * @tc.desc  : Test GetBufferDesc interface.
1512  */
1513 HWTEST(FastSystemStreamUnitTest, GetBufferDesc_001, TestSize.Level1)
1514 {
1515     int32_t appUid = static_cast<int32_t>(getuid());
1516     std::shared_ptr<FastAudioStream> fastAudioStream
1517         = std::make_shared<FastAudioStream>(STREAM_MUSIC, AUDIO_MODE_PLAYBACK, appUid);
1518     EXPECT_NE(fastAudioStream, nullptr);
1519 
1520     BufferDesc bufferDesc;
1521     auto ret = fastAudioStream->GetBufferDesc(bufferDesc);
1522     EXPECT_EQ(ret, ERR_INVALID_OPERATION);
1523 
1524     AudioStreamParams info;
1525     info.format = AudioSampleFormat::SAMPLE_S16LE;
1526     info.encoding = AudioEncodingType::ENCODING_PCM;
1527     info.samplingRate = AudioSamplingRate::SAMPLE_RATE_48000;
1528     info.channels = AudioChannel::STEREO;
1529     info.channelLayout = AudioChannelLayout::CH_LAYOUT_MONO;
1530     std::shared_ptr<AudioClientTracker> proxyObj = std::make_shared<AudioClientTrackerTest>();
1531     fastAudioStream->SetAudioStreamInfo(info, proxyObj);
1532 
1533     ret = fastAudioStream->GetBufferDesc(bufferDesc);
1534     EXPECT_NE(ret, SUCCESS);
1535 }
1536 
1537 /**
1538  * @tc.name  : Test GetBufQueueState API
1539  * @tc.type  : FUNC
1540  * @tc.number: GetBufQueueState_001
1541  * @tc.desc  : Test GetBufQueueState interface.
1542  */
1543 HWTEST(FastSystemStreamUnitTest, GetBufQueueState_001, TestSize.Level1)
1544 {
1545     int32_t appUid = static_cast<int32_t>(getuid());
1546     std::shared_ptr<FastAudioStream> fastAudioStream
1547         = std::make_shared<FastAudioStream>(STREAM_MUSIC, AUDIO_MODE_PLAYBACK, appUid);
1548     EXPECT_NE(fastAudioStream, nullptr);
1549 
1550     BufferQueueState bufState;
1551     auto ret = fastAudioStream->GetBufQueueState(bufState);
1552     EXPECT_EQ(ret, SUCCESS);
1553 }
1554 
1555 /**
1556  * @tc.name  : Test InitCallbackHandler API
1557  * @tc.type  : FUNC
1558  * @tc.number: InitCallbackHandler_002
1559  * @tc.desc  : Test InitCallbackHandler interface.
1560  */
1561 HWTEST(FastSystemStreamUnitTest, InitCallbackHandler_002, TestSize.Level1)
1562 {
1563     int32_t appUid = static_cast<int32_t>(getuid());
1564     std::shared_ptr<FastAudioStream> fastAudioStream =
1565         std::make_shared<FastAudioStream>(STREAM_MUSIC, AUDIO_MODE_PLAYBACK, appUid);
1566     ASSERT_TRUE(fastAudioStream != nullptr);
1567 
1568     fastAudioStream->InitCallbackHandler();
1569     EXPECT_NE(fastAudioStream->callbackHandler_, nullptr);
1570     fastAudioStream->InitCallbackHandler();
1571 }
1572 
1573 /**
1574  * @tc.name  : Test OnHandleData API
1575  * @tc.type  : FUNC
1576  * @tc.number: OnHandleData_002
1577  * @tc.desc  : Test OnHandleData interface.
1578  */
1579 HWTEST(FastSystemStreamUnitTest, OnHandleData_002, TestSize.Level1)
1580 {
1581     std::shared_ptr<AudioRendererWriteCallback> callback = std::make_shared<AudioRendererWriteCallbackTest>();
1582     AudioStreamParams tempParams = {};
1583     auto audioStream = IAudioStream::GetRecordStream(IAudioStream::PA_STREAM, tempParams, STREAM_MUSIC, getpid());
1584     std::shared_ptr<FastAudioStreamRenderCallback> fastAudioStreamRenderCallback;
1585     fastAudioStreamRenderCallback = std::make_shared<FastAudioStreamRenderCallback>(callback, *audioStream);
1586     ASSERT_TRUE(fastAudioStreamRenderCallback != nullptr);
1587 
1588     fastAudioStreamRenderCallback->rendererWriteCallback_ = std::make_shared<AudioRendererWriteCallbackTest>();
1589     size_t length = 0;
1590     fastAudioStreamRenderCallback->OnHandleData(length);
1591     fastAudioStreamRenderCallback->OnHandleData(length);
1592     EXPECT_TRUE(fastAudioStreamRenderCallback->hasFirstFrameWrited_);
1593 }
1594 
1595 /**
1596  * @tc.name  : Test InitCallbackHandler API
1597  * @tc.type  : FUNC
1598  * @tc.number: FetchDeviceForSplitStream_001
1599  * @tc.desc  : Test InitCallbackHandler interface.
1600  */
1601 HWTEST(FastSystemStreamUnitTest, FetchDeviceForSplitStream_001, TestSize.Level1)
1602 {
1603     int32_t appUid = static_cast<int32_t>(getuid());
1604     std::shared_ptr<FastAudioStream> fastAudioStream =
1605         std::make_shared<FastAudioStream>(STREAM_MUSIC, AUDIO_MODE_PLAYBACK, appUid);
1606     ASSERT_TRUE(fastAudioStream != nullptr);
1607 
1608     fastAudioStream->FetchDeviceForSplitStream();
1609 }
1610 
1611 /**
1612  * @tc.name  : Test InitCallbackHandler API
1613  * @tc.type  : FUNC
1614  * @tc.number: RestoreAudioStream_002
1615  * @tc.desc  : Test InitCallbackHandler interface.
1616  */
1617 HWTEST(FastSystemStreamUnitTest, RestoreAudioStream_002, TestSize.Level1)
1618 {
1619     int32_t appUid = static_cast<int32_t>(getuid());
1620     std::shared_ptr<FastAudioStream> fastAudioStream =
1621         std::make_shared<FastAudioStream>(STREAM_MUSIC, AUDIO_MODE_PLAYBACK, appUid);
1622     ASSERT_TRUE(fastAudioStream != nullptr);
1623 
1624     std::shared_ptr<AudioClientTracker> proxyObj = std::make_shared<AudioClientTrackerTest>();
1625     fastAudioStream->proxyObj_ = proxyObj;
1626     fastAudioStream->state_ = RUNNING;
1627     fastAudioStream->RestoreAudioStream();
1628 }
1629 
1630 /**
1631  * @tc.name  : Test CheckRestoreStatus API
1632  * @tc.type  : FUNC
1633  * @tc.number: CheckRestoreStatus_001
1634  * @tc.desc  : Test CheckRestoreStatus interface. - return RESTORE_TO_NORMAL when spkProcClientCb_ is null
1635  */
1636 HWTEST(FastSystemStreamUnitTest, CheckRestoreStatus_001, TestSize.Level1)
1637 {
1638     int32_t appUid = static_cast<int32_t>(getuid());
1639     std::shared_ptr<FastAudioStream> fastAudioStream =
1640         std::make_shared<FastAudioStream>(STREAM_MUSIC, AUDIO_MODE_PLAYBACK, appUid);
1641     EXPECT_NE(fastAudioStream, nullptr);
1642 
1643     fastAudioStream->spkProcClientCb_ = nullptr;
1644     fastAudioStream->micProcClientCb_ = nullptr;
1645     RestoreStatus status = fastAudioStream->CheckRestoreStatus();
1646     EXPECT_EQ(status, NEED_RESTORE_TO_NORMAL);
1647 }
1648 
1649 /**
1650  * @tc.name  : Test SetCallbacksWhenRestore API
1651  * @tc.type  : FUNC
1652  * @tc.number: SetCallbacksWhenRestore_001
1653  * @tc.desc  : Test SetCallbacksWhenRestore interface using unsupported parameters.
1654  */
1655 HWTEST(FastSystemStreamUnitTest, SetCallbacksWhenRestore_001, TestSize.Level1)
1656 {
1657     int32_t appUid = static_cast<int32_t>(getuid());
1658     std::shared_ptr<FastAudioStream> fastAudioStream =
1659         std::make_shared<FastAudioStream>(STREAM_MUSIC, AUDIO_MODE_PLAYBACK, appUid);
1660     fastAudioStream->processClient_ = nullptr;
1661     fastAudioStream->eMode_ = AUDIO_MODE_PLAYBACK;
1662     int ret = fastAudioStream->SetCallbacksWhenRestore();
1663     EXPECT_EQ(ERROR_INVALID_PARAM, ret);
1664 }
1665 
1666 /**
1667  * @tc.name  : Test SetCallbacksWhenRestore API
1668  * @tc.type  : FUNC
1669  * @tc.number: SetCallbacksWhenRestore_002
1670  * @tc.desc  : Test SetCallbacksWhenRestore interface using unsupported parameters.
1671  */
1672 HWTEST(FastSystemStreamUnitTest, SetCallbacksWhenRestore_002, TestSize.Level1)
1673 {
1674     int32_t appUid = static_cast<int32_t>(getuid());
1675     std::shared_ptr<FastAudioStream> fastAudioStream =
1676         std::make_shared<FastAudioStream>(STREAM_MUSIC, AUDIO_MODE_PLAYBACK, appUid);
1677     fastAudioStream->processClient_ = nullptr;
1678     fastAudioStream->eMode_ = AUDIO_MODE_RECORD;
1679     int ret = fastAudioStream->SetCallbacksWhenRestore();
1680     EXPECT_EQ(ERROR_INVALID_PARAM, ret);
1681 }
1682 
1683 /**
1684  * @tc.name  : Test RestoreAudioStream API
1685  * @tc.type  : FUNC
1686  * @tc.number: RestoreAudioStream_003
1687  * @tc.desc  : Test RestoreAudioStream interface using unsupported parameters.
1688  */
1689 HWTEST(FastSystemStreamUnitTest, RestoreAudioStream_003, TestSize.Level1)
1690 {
1691     int32_t appUid = static_cast<int32_t>(getuid());
1692     std::shared_ptr<FastAudioStream> fastAudioStream =
1693         std::make_shared<FastAudioStream>(STREAM_MUSIC, AUDIO_MODE_PLAYBACK, appUid);
1694     bool needStoreState = true;
1695     fastAudioStream->proxyObj_ = nullptr;
1696     fastAudioStream->state_ = RELEASED;
1697     int ret = fastAudioStream->RestoreAudioStream(needStoreState);
1698     EXPECT_FALSE(ret);
1699 }
1700 
1701 /**
1702  * @tc.name  : Test RestoreAudioStream API
1703  * @tc.type  : FUNC
1704  * @tc.number: RestoreAudioStream_004
1705  * @tc.desc  : Test RestoreAudioStream interface using unsupported parameters.
1706  */
1707 HWTEST(FastSystemStreamUnitTest, RestoreAudioStream_004, TestSize.Level1)
1708 {
1709     int32_t appUid = static_cast<int32_t>(getuid());
1710     std::shared_ptr<FastAudioStream> fastAudioStream =
1711         std::make_shared<FastAudioStream>(STREAM_MUSIC, AUDIO_MODE_PLAYBACK, appUid);
1712     bool needStoreState = true;
1713     std::shared_ptr<AudioClientTracker> proxyObj = std::make_shared<AudioClientTrackerTest>();
1714     fastAudioStream->proxyObj_ = proxyObj;
1715     fastAudioStream->state_ = NEW;
1716     int ret = fastAudioStream->RestoreAudioStream(needStoreState);
1717     EXPECT_TRUE(ret);
1718 }
1719 
1720 /**
1721  * @tc.name  : Test RestoreAudioStream API
1722  * @tc.type  : FUNC
1723  * @tc.number: RestoreAudioStream_005
1724  * @tc.desc  : Test RestoreAudioStream interface using unsupported parameters.
1725  */
1726 HWTEST(FastSystemStreamUnitTest, RestoreAudioStream_005, TestSize.Level1)
1727 {
1728     int32_t appUid = static_cast<int32_t>(getuid());
1729     std::shared_ptr<FastAudioStream> fastAudioStream =
1730         std::make_shared<FastAudioStream>(STREAM_MUSIC, AUDIO_MODE_PLAYBACK, appUid);
1731     bool needStoreState = true;
1732     std::shared_ptr<AudioClientTracker> proxyObj = std::make_shared<AudioClientTrackerTest>();
1733     fastAudioStream->proxyObj_ = proxyObj;
1734     fastAudioStream->state_ = INVALID;
1735     int ret = fastAudioStream->RestoreAudioStream(needStoreState);
1736     EXPECT_TRUE(ret);
1737 }
1738 
1739 /**
1740  * @tc.name  : Test RestoreAudioStream API
1741  * @tc.type  : FUNC
1742  * @tc.number: RestoreAudioStream_006
1743  * @tc.desc  : Test RestoreAudioStream interface using unsupported parameters.
1744  */
1745 HWTEST(FastSystemStreamUnitTest, RestoreAudioStream_006, TestSize.Level1)
1746 {
1747     int32_t appUid = static_cast<int32_t>(getuid());
1748     std::shared_ptr<FastAudioStream> fastAudioStream =
1749         std::make_shared<FastAudioStream>(STREAM_MUSIC, AUDIO_MODE_PLAYBACK, appUid);
1750     bool needStoreState = true;
1751     std::shared_ptr<AudioClientTracker> proxyObj = std::make_shared<AudioClientTrackerTest>();
1752     fastAudioStream->proxyObj_ = proxyObj;
1753     fastAudioStream->state_ = RELEASED;
1754     int ret = fastAudioStream->RestoreAudioStream(needStoreState);
1755     EXPECT_TRUE(ret);
1756 }
1757 } // namespace AudioStandard
1758 } // namespace OHOS
1759