• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "audio_renderer_unit_test.h"
17 
18 #include <thread>
19 
20 #include "audio_errors.h"
21 #include "audio_info.h"
22 #include "audio_renderer.h"
23 
24 using namespace std;
25 using namespace testing::ext;
26 
27 namespace OHOS {
28 namespace AudioStandard {
29 namespace {
30     const string AUDIORENDER_TEST_FILE_PATH = "/data/test_44100_2.wav";
31     const int32_t VALUE_NEGATIVE = -1;
32     const int32_t VALUE_ZERO = 0;
33     const int32_t VALUE_HUNDRED = 100;
34     const int32_t VALUE_THOUSAND = 1000;
35     const int32_t RENDERER_FLAG = 0;
36     // Writing only 500 buffers of data for test
37     const int32_t WRITE_BUFFERS_COUNT = 500;
38     constexpr int32_t PAUSE_BUFFER_POSITION = 400000;
39     constexpr int32_t PAUSE_RENDER_TIME_SECONDS = 1;
40 
41     constexpr uint64_t BUFFER_DURATION_FIVE = 5;
42     constexpr uint64_t BUFFER_DURATION_TEN = 10;
43     constexpr uint64_t BUFFER_DURATION_FIFTEEN = 15;
44     constexpr uint64_t BUFFER_DURATION_TWENTY = 20;
45 
46     static size_t g_reqBufLen = 0;
47 } // namespace
48 
SetUpTestCase(void)49 void AudioRendererUnitTest::SetUpTestCase(void) {}
TearDownTestCase(void)50 void AudioRendererUnitTest::TearDownTestCase(void) {}
SetUp(void)51 void AudioRendererUnitTest::SetUp(void) {}
TearDown(void)52 void AudioRendererUnitTest::TearDown(void) {}
53 
OnWriteData(size_t length)54 void AudioRenderModeCallbackTest::OnWriteData(size_t length)
55 {
56     g_reqBufLen = length;
57 }
58 
InitializeRenderer(unique_ptr<AudioRenderer> & audioRenderer)59 int32_t AudioRendererUnitTest::InitializeRenderer(unique_ptr<AudioRenderer> &audioRenderer)
60 {
61     AudioRendererParams rendererParams;
62     rendererParams.sampleFormat = SAMPLE_S16LE;
63     rendererParams.sampleRate = SAMPLE_RATE_44100;
64     rendererParams.channelCount = STEREO;
65     rendererParams.encodingType = ENCODING_PCM;
66 
67     return audioRenderer->SetParams(rendererParams);
68 }
69 
InitializeRendererOptions(AudioRendererOptions & rendererOptions)70 void AudioRendererUnitTest::InitializeRendererOptions(AudioRendererOptions &rendererOptions)
71 {
72     rendererOptions.streamInfo.samplingRate = AudioSamplingRate::SAMPLE_RATE_44100;
73     rendererOptions.streamInfo.encoding = AudioEncodingType::ENCODING_PCM;
74     rendererOptions.streamInfo.format = AudioSampleFormat::SAMPLE_S16LE;
75     rendererOptions.streamInfo.channels = AudioChannel::STEREO;
76     rendererOptions.rendererInfo.contentType = ContentType::CONTENT_TYPE_MUSIC;
77     rendererOptions.rendererInfo.streamUsage = StreamUsage::STREAM_USAGE_MEDIA;
78     rendererOptions.rendererInfo.rendererFlags = RENDERER_FLAG;
79     return;
80 }
81 
StartRenderThread(AudioRenderer * audioRenderer)82 void StartRenderThread(AudioRenderer *audioRenderer)
83 {
84     int32_t ret = -1;
85     FILE *wavFile = fopen(AUDIORENDER_TEST_FILE_PATH.c_str(), "rb");
86     ASSERT_NE(nullptr, wavFile);
87 
88     size_t bufferLen;
89     ret = audioRenderer->GetBufferSize(bufferLen);
90     EXPECT_EQ(SUCCESS, ret);
91 
92     auto buffer = std::make_unique<uint8_t[]>(bufferLen);
93     ASSERT_NE(nullptr, buffer);
94 
95     size_t bytesToWrite = 0;
96     int32_t bytesWritten = 0;
97     size_t minBytes = 4;
98     int32_t numBuffersToRender = WRITE_BUFFERS_COUNT;
99 
100     while (numBuffersToRender) {
101         bytesToWrite = fread(buffer.get(), 1, bufferLen, wavFile);
102         bytesWritten = 0;
103         while ((static_cast<size_t>(bytesWritten) < bytesToWrite) &&
104             ((static_cast<size_t>(bytesToWrite) - bytesWritten) > minBytes)) {
105             bytesWritten += audioRenderer->Write(buffer.get() + static_cast<size_t>(bytesWritten),
106                                                  bytesToWrite - static_cast<size_t>(bytesWritten));
107             EXPECT_GE(bytesWritten, VALUE_ZERO);
108             if (bytesWritten < 0) {
109                 break;
110             }
111         }
112         numBuffersToRender--;
113     }
114 
115     audioRenderer->Drain();
116 
117     fclose(wavFile);
118 }
119 
120 /**
121 * @tc.name  : Test GetSupportedFormats API
122 * @tc.number: Audio_Renderer_GetSupportedFormats_001
123 * @tc.desc  : Test GetSupportedFormats interface. Returns supported Formats on success.
124 */
125 HWTEST(AudioRendererUnitTest, Audio_Renderer_GetSupportedFormats_001, TestSize.Level0)
126 {
127     vector<AudioSampleFormat> supportedFormatList = AudioRenderer::GetSupportedFormats();
128     EXPECT_EQ(AUDIO_SUPPORTED_FORMATS.size(), supportedFormatList.size());
129 }
130 
131 /**
132 * @tc.name  : Test GetSupportedChannels API
133 * @tc.number: Audio_Renderer_GetSupportedChannels_001
134 * @tc.desc  : Test GetSupportedChannels interface. Returns supported Channels on success.
135 */
136 HWTEST(AudioRendererUnitTest, Audio_Renderer_GetSupportedChannels_001, TestSize.Level0)
137 {
138     vector<AudioChannel> supportedChannelList = AudioRenderer::GetSupportedChannels();
139     EXPECT_EQ(AUDIO_SUPPORTED_CHANNELS.size(), supportedChannelList.size());
140 }
141 
142 /**
143 * @tc.name  : Test GetSupportedEncodingTypes API
144 * @tc.number: Audio_Renderer_GetSupportedEncodingTypes_001
145 * @tc.desc  : Test GetSupportedEncodingTypes interface. Returns supported Encoding types on success.
146 */
147 HWTEST(AudioRendererUnitTest, Audio_Renderer_GetSupportedEncodingTypes_001, TestSize.Level0)
148 {
149     vector<AudioEncodingType> supportedEncodingTypes
150                                         = AudioRenderer::GetSupportedEncodingTypes();
151     EXPECT_EQ(AUDIO_SUPPORTED_ENCODING_TYPES.size(), supportedEncodingTypes.size());
152 }
153 
154 /**
155 * @tc.name  : Test GetSupportedSamplingRates API
156 * @tc.number: Audio_Renderer_GetSupportedSamplingRates_001
157 * @tc.desc  : Test GetSupportedSamplingRates interface. Returns supported Sampling rates on success.
158 */
159 HWTEST(AudioRendererUnitTest, Audio_Renderer_GetSupportedSamplingRates_001, TestSize.Level0)
160 {
161     vector<AudioSamplingRate> supportedSamplingRates = AudioRenderer::GetSupportedSamplingRates();
162     EXPECT_EQ(AUDIO_SUPPORTED_SAMPLING_RATES.size(), supportedSamplingRates.size());
163 }
164 
165 /**
166 * @tc.name  : Test Create API via legal input.
167 * @tc.number: Audio_Renderer_Create_001
168 * @tc.desc  : Test Create interface with STREAM_MUSIC. Returns audioRenderer instance, if create is successful.
169 */
170 HWTEST(AudioRendererUnitTest, Audio_Renderer_Create_001, TestSize.Level0)
171 {
172     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(STREAM_MUSIC);
173     EXPECT_NE(nullptr, audioRenderer);
174 }
175 
176 /**
177 * @tc.name  : Test Create API via legal input.
178 * @tc.number: Audio_Renderer_Create_002
179 * @tc.desc  : Test Create interface with STREAM_RING. Returns audioRenderer instance, if create is successful.
180 */
181 HWTEST(AudioRendererUnitTest, Audio_Renderer_Create_002, TestSize.Level0)
182 {
183     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(STREAM_RING);
184     EXPECT_NE(nullptr, audioRenderer);
185 }
186 
187 /**
188 * @tc.name  : Test Create API via legal input.
189 * @tc.number: Audio_Renderer_Create_003
190 * @tc.desc  : Test Create interface with STREAM_VOICE_CALL. Returns audioRenderer instance if create is successful.
191 *             Note: instance will be created but functional support for STREAM_VOICE_CALL not available yet.
192 */
193 HWTEST(AudioRendererUnitTest, Audio_Renderer_Create_003, TestSize.Level0)
194 {
195     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(STREAM_VOICE_CALL);
196     EXPECT_NE(nullptr, audioRenderer);
197 }
198 
199 /**
200 * @tc.name  : Test Create API via legal input.
201 * @tc.number: Audio_Renderer_Create_004
202 * @tc.desc  : Test Create interface with STREAM_SYSTEM. Returns audioRenderer instance, if create is successful.
203 *             Note: instance will be created but functional support for STREAM_SYSTEM not available yet.
204 */
205 HWTEST(AudioRendererUnitTest, Audio_Renderer_Create_004, TestSize.Level0)
206 {
207     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(STREAM_SYSTEM);
208     EXPECT_NE(nullptr, audioRenderer);
209 }
210 
211 /**
212 * @tc.name  : Test Create API via legal input.
213 * @tc.number: Audio_Renderer_Create_005
214 * @tc.desc  : Test Create interface with STREAM_BLUETOOTH_SCO. Returns audioRenderer instance, if create is successful.
215 *             Note: instance will be created but functional support for STREAM_BLUETOOTH_SCO not available yet
216 */
217 HWTEST(AudioRendererUnitTest, Audio_Renderer_Create_005, TestSize.Level0)
218 {
219     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(STREAM_BLUETOOTH_SCO);
220     EXPECT_NE(nullptr, audioRenderer);
221 }
222 
223 /**
224 * @tc.name  : Test Create API via legal input.
225 * @tc.number: Audio_Renderer_Create_006
226 * @tc.desc  : Test Create interface with STREAM_ALARM. Returns audioRenderer instance, if create is successful.
227 *             Note: instance will be created but functional support for STREAM_ALARM not available yet.
228 */
229 HWTEST(AudioRendererUnitTest, Audio_Renderer_Create_006, TestSize.Level0)
230 {
231     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(STREAM_ALARM);
232     EXPECT_NE(nullptr, audioRenderer);
233 }
234 
235 /**
236 * @tc.name  : Test Create API via legal input.
237 * @tc.number: Audio_Renderer_Create_007
238 * @tc.desc  : Test Create interface with STREAM_NOTIFICATION. Returns audioRenderer instance, if create is successful.
239 *             Note: instance will be created but functional support for STREAM_NOTIFICATION not available yet.
240 */
241 HWTEST(AudioRendererUnitTest, Audio_Renderer_Create_007, TestSize.Level0)
242 {
243     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(STREAM_NOTIFICATION);
244     EXPECT_NE(nullptr, audioRenderer);
245 }
246 
247 /**
248 * @tc.name  : Test Create API via legal input.
249 * @tc.number: Audio_Renderer_Create_008
250 * @tc.desc  : Test Create interface with AudioRendererOptions below.
251 *             Returns audioRenderer instance, if create is successful.
252 *             rendererOptions.streamInfo.samplingRate = SAMPLE_RATE_96000;
253 *             rendererOptions.streamInfo.encoding = ENCODING_PCM;
254 *             rendererOptions.streamInfo.format = SAMPLE_U8;
255 *             rendererOptions.streamInfo.channels = MONO;
256 *             rendererOptions.rendererInfo.contentType = CONTENT_TYPE_MUSIC;
257 *             rendererOptions.rendererInfo.streamUsage = STREAM_USAGE_MEDIA;
258 *             rendererOptions.rendererInfo.rendererFlags = RENDERER_FLAG;
259 */
260 HWTEST(AudioRendererUnitTest, Audio_Renderer_Create_008, TestSize.Level1)
261 {
262     AudioRendererOptions rendererOptions;
263     rendererOptions.streamInfo.samplingRate = AudioSamplingRate::SAMPLE_RATE_96000;
264     rendererOptions.streamInfo.encoding = AudioEncodingType::ENCODING_PCM;
265     rendererOptions.streamInfo.format = AudioSampleFormat::SAMPLE_U8;
266     rendererOptions.streamInfo.channels = AudioChannel::MONO;
267     rendererOptions.rendererInfo.contentType = ContentType::CONTENT_TYPE_MUSIC;
268     rendererOptions.rendererInfo.streamUsage = StreamUsage::STREAM_USAGE_MEDIA;
269     rendererOptions.rendererInfo.rendererFlags = RENDERER_FLAG;
270 
271     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
272     EXPECT_NE(nullptr, audioRenderer);
273     audioRenderer->Release();
274 }
275 
276 /**
277 * @tc.name  : Test Create API via legal input.
278 * @tc.number: Audio_Renderer_Create_009
279 * @tc.desc  : Test Create interface with AudioRendererOptions below.
280 *             Returns audioRenderer instance, if create is successful.
281 *             rendererOptions.streamInfo.samplingRate = SAMPLE_RATE_96000;
282 *             rendererOptions.streamInfo.encoding = ENCODING_PCM;
283 *             rendererOptions.streamInfo.format = SAMPLE_U8;
284 *             rendererOptions.streamInfo.channels = STEREO;
285 *             rendererOptions.rendererInfo.contentType = CONTENT_TYPE_MOVIE;
286 *             rendererOptions.rendererInfo.streamUsage = STREAM_USAGE_MEDIA;
287 *             rendererOptions.rendererInfo.rendererFlags = RENDERER_FLAG;
288 */
289 HWTEST(AudioRendererUnitTest, Audio_Renderer_Create_009, TestSize.Level1)
290 {
291     AudioRendererOptions rendererOptions;
292     rendererOptions.streamInfo.samplingRate = AudioSamplingRate::SAMPLE_RATE_8000;
293     rendererOptions.streamInfo.encoding = AudioEncodingType::ENCODING_PCM;
294     rendererOptions.streamInfo.format = AudioSampleFormat::SAMPLE_U8;
295     rendererOptions.streamInfo.channels = AudioChannel::STEREO;
296     rendererOptions.rendererInfo.contentType = ContentType::CONTENT_TYPE_MOVIE;
297     rendererOptions.rendererInfo.streamUsage = StreamUsage::STREAM_USAGE_MEDIA;
298     rendererOptions.rendererInfo.rendererFlags = RENDERER_FLAG;
299 
300     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
301     EXPECT_NE(nullptr, audioRenderer);
302     audioRenderer->Release();
303 }
304 
305 /**
306 * @tc.name  : Test Create API via legal input.
307 * @tc.number: Audio_Renderer_Create_010
308 * @tc.desc  : Test Create interface with AudioRendererOptions below.
309 *             Returns audioRenderer instance, if create is successful.
310 *             rendererOptions.streamInfo.samplingRate = SAMPLE_RATE_64000;
311 *             rendererOptions.streamInfo.encoding = ENCODING_PCM;
312 *             rendererOptions.streamInfo.format = SAMPLE_S32LE;
313 *             rendererOptions.streamInfo.channels = MONO;
314 *             rendererOptions.rendererInfo.contentType = CONTENT_TYPE_RINGTONE;
315 *             rendererOptions.rendererInfo.streamUsage = STREAM_USAGE_NOTIFICATION_RINGTONE;
316 *             rendererOptions.rendererInfo.rendererFlags = RENDERER_FLAG;
317 */
318 HWTEST(AudioRendererUnitTest, Audio_Renderer_Create_010, TestSize.Level1)
319 {
320     AudioRendererOptions rendererOptions;
321     rendererOptions.streamInfo.samplingRate = AudioSamplingRate::SAMPLE_RATE_64000;
322     rendererOptions.streamInfo.encoding = AudioEncodingType::ENCODING_PCM;
323     rendererOptions.streamInfo.format = AudioSampleFormat::SAMPLE_S32LE;
324     rendererOptions.streamInfo.channels = AudioChannel::MONO;
325     rendererOptions.rendererInfo.contentType = ContentType::CONTENT_TYPE_RINGTONE;
326     rendererOptions.rendererInfo.streamUsage = StreamUsage::STREAM_USAGE_NOTIFICATION_RINGTONE;
327     rendererOptions.rendererInfo.rendererFlags = RENDERER_FLAG;
328 
329     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
330     EXPECT_NE(nullptr, audioRenderer);
331     audioRenderer->Release();
332 }
333 
334 /**
335 * @tc.name  : Test Create API via legal input.
336 * @tc.number: Audio_Renderer_Create_011
337 * @tc.desc  : Test Create interface with AudioRendererOptions below.
338 *             Returns audioRenderer instance, if create is successful.
339 *             rendererOptions.streamInfo.samplingRate = SAMPLE_RATE_48000;
340 *             rendererOptions.streamInfo.encoding = ENCODING_PCM;
341 *             rendererOptions.streamInfo.format = SAMPLE_S24LE;
342 *             rendererOptions.streamInfo.channels = STEREO;
343 *             rendererOptions.rendererInfo.contentType = CONTENT_TYPE_MOVIE;
344 *             rendererOptions.rendererInfo.streamUsage = STREAM_USAGE_MEDIA;
345 *             rendererOptions.rendererInfo.rendererFlags = RENDERER_FLAG;
346 */
347 HWTEST(AudioRendererUnitTest, Audio_Renderer_Create_011, TestSize.Level1)
348 {
349     AudioRendererOptions rendererOptions;
350     rendererOptions.streamInfo.samplingRate = AudioSamplingRate::SAMPLE_RATE_48000;
351     rendererOptions.streamInfo.encoding = AudioEncodingType::ENCODING_PCM;
352     rendererOptions.streamInfo.format = AudioSampleFormat::SAMPLE_S24LE;
353     rendererOptions.streamInfo.channels = AudioChannel::STEREO;
354     rendererOptions.rendererInfo.contentType = ContentType::CONTENT_TYPE_MOVIE;
355     rendererOptions.rendererInfo.streamUsage = StreamUsage::STREAM_USAGE_MEDIA;
356     rendererOptions.rendererInfo.rendererFlags = RENDERER_FLAG;
357 
358     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
359     EXPECT_NE(nullptr, audioRenderer);
360     audioRenderer->Release();
361 }
362 
363 /**
364 * @tc.name  : Test Create API via legal input.
365 * @tc.number: Audio_Renderer_Create_012
366 * @tc.desc  : Test Create interface with AudioRendererOptions below.
367 *             Returns audioRenderer instance, if create is successful.
368 *             rendererOptions.streamInfo.samplingRate = SAMPLE_RATE_44100;
369 *             rendererOptions.streamInfo.encoding = ENCODING_PCM;
370 *             rendererOptions.streamInfo.format = SAMPLE_S16LE;
371 *             rendererOptions.streamInfo.channels = MONO;
372 *             rendererOptions.rendererInfo.contentType = CONTENT_TYPE_SONIFICATION;
373 *             rendererOptions.rendererInfo.streamUsage = STREAM_USAGE_VOICE_ASSISTANT;
374 *             rendererOptions.rendererInfo.rendererFlags = RENDERER_FLAG;
375 */
376 HWTEST(AudioRendererUnitTest, Audio_Renderer_Create_012, TestSize.Level1)
377 {
378     AudioRendererOptions rendererOptions;
379     rendererOptions.streamInfo.samplingRate = AudioSamplingRate::SAMPLE_RATE_44100;
380     rendererOptions.streamInfo.encoding = AudioEncodingType::ENCODING_PCM;
381     rendererOptions.streamInfo.format = AudioSampleFormat::SAMPLE_S16LE;
382     rendererOptions.streamInfo.channels = AudioChannel::MONO;
383     rendererOptions.rendererInfo.contentType = ContentType::CONTENT_TYPE_SONIFICATION;
384     rendererOptions.rendererInfo.streamUsage = StreamUsage::STREAM_USAGE_VOICE_ASSISTANT;
385     rendererOptions.rendererInfo.rendererFlags = RENDERER_FLAG;
386 
387     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
388     EXPECT_NE(nullptr, audioRenderer);
389     audioRenderer->Release();
390 }
391 
392 /**
393 * @tc.name  : Test Create API via legal input.
394 * @tc.number: Audio_Renderer_Create_013
395 * @tc.desc  : Test Create interface with AudioRendererOptions below.
396 *             Returns audioRenderer instance, if create is successful.
397 *             rendererOptions.streamInfo.samplingRate = SAMPLE_RATE_22050;
398 *             rendererOptions.streamInfo.encoding = ENCODING_PCM;
399 *             rendererOptions.streamInfo.format = SAMPLE_S24LE;
400 *             rendererOptions.streamInfo.channels = STEREO;
401 *             rendererOptions.rendererInfo.contentType = CONTENT_TYPE_SPEECH;
402 *             rendererOptions.rendererInfo.streamUsage = STREAM_USAGE_VOICE_COMMUNICATION;
403 *             rendererOptions.rendererInfo.rendererFlags = RENDERER_FLAG;
404 */
405 HWTEST(AudioRendererUnitTest, Audio_Renderer_Create_013, TestSize.Level1)
406 {
407     AudioRendererOptions rendererOptions;
408     rendererOptions.streamInfo.samplingRate = AudioSamplingRate::SAMPLE_RATE_22050;
409     rendererOptions.streamInfo.encoding = AudioEncodingType::ENCODING_PCM;
410     rendererOptions.streamInfo.format = AudioSampleFormat::SAMPLE_S24LE;
411     rendererOptions.streamInfo.channels = AudioChannel::STEREO;
412     rendererOptions.rendererInfo.contentType = ContentType::CONTENT_TYPE_SPEECH;
413     rendererOptions.rendererInfo.streamUsage = StreamUsage::STREAM_USAGE_VOICE_COMMUNICATION;
414     rendererOptions.rendererInfo.rendererFlags = RENDERER_FLAG;
415 
416     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
417     EXPECT_NE(nullptr, audioRenderer);
418     audioRenderer->Release();
419 }
420 
421 /**
422 * @tc.name  : Test Create API via legal input.
423 * @tc.number: Audio_Renderer_Create_014
424 * @tc.desc  : Test Create interface with AudioRendererOptions below.
425 *             Returns audioRenderer instance, if create is successful.
426 *             rendererOptions.streamInfo.samplingRate = SAMPLE_RATE_12000;
427 *             rendererOptions.streamInfo.encoding = ENCODING_PCM;
428 *             rendererOptions.streamInfo.format = SAMPLE_S24LE;
429 *             rendererOptions.streamInfo.channels = MONO;
430 *             rendererOptions.rendererInfo.contentType = CONTENT_TYPE_MUSIC;
431 *             rendererOptions.rendererInfo.streamUsage = STREAM_USAGE_VOICE_ASSISTANT;
432 *             rendererOptions.rendererInfo.rendererFlags = RENDERER_FLAG;
433 */
434 HWTEST(AudioRendererUnitTest, Audio_Renderer_Create_014, TestSize.Level1)
435 {
436     AudioRendererOptions rendererOptions;
437     rendererOptions.streamInfo.samplingRate = AudioSamplingRate::SAMPLE_RATE_12000;
438     rendererOptions.streamInfo.encoding = AudioEncodingType::ENCODING_PCM;
439     rendererOptions.streamInfo.format = AudioSampleFormat::SAMPLE_S24LE;
440     rendererOptions.streamInfo.channels = AudioChannel::MONO;
441     rendererOptions.rendererInfo.contentType = ContentType::CONTENT_TYPE_MUSIC;
442     rendererOptions.rendererInfo.streamUsage = StreamUsage::STREAM_USAGE_VOICE_ASSISTANT;
443     rendererOptions.rendererInfo.rendererFlags = RENDERER_FLAG;
444 
445     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
446     EXPECT_NE(nullptr, audioRenderer);
447     audioRenderer->Release();
448 }
449 
450 /**
451 * @tc.name  : Test SetParams API via legal input
452 * @tc.number: Audio_Renderer_SetParams_001
453 * @tc.desc  : Test SetParams interface. Returns 0 {SUCCESS}, if the setting is successful.
454 *             rendererParams.sampleFormat = SAMPLE_S16LE;
455 *             rendererParams.sampleRate = SAMPLE_RATE_44100;
456 *             rendererParams.channelCount = STEREO;
457 *             rendererParams.encodingType = ENCODING_PCM;
458 */
459 HWTEST(AudioRendererUnitTest, Audio_Renderer_SetParams_001, TestSize.Level1)
460 {
461     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(STREAM_MUSIC);
462     ASSERT_NE(nullptr, audioRenderer);
463 
464     AudioRendererParams rendererParams;
465     rendererParams.sampleFormat = SAMPLE_S16LE;
466     rendererParams.sampleRate = SAMPLE_RATE_44100;
467     rendererParams.channelCount = STEREO;
468     rendererParams.encodingType = ENCODING_PCM;
469 
470     int32_t ret = audioRenderer->SetParams(rendererParams);
471     EXPECT_EQ(SUCCESS, ret);
472     audioRenderer->Release();
473 }
474 
475 /**
476 * @tc.name  : Test SetParams API via legal input.
477 * @tc.number: Audio_Renderer_SetParams_002
478 * @tc.desc  : Test SetParams interface. Returns 0 {SUCCESS}, if the setting is successful.
479 *             rendererParams.sampleFormat = SAMPLE_S16LE;
480 *             rendererParams.sampleRate = SAMPLE_RATE_8000;
481 *             rendererParams.channelCount = MONO;
482 *             rendererParams.encodingType = ENCODING_PCM;
483 */
484 HWTEST(AudioRendererUnitTest, Audio_Renderer_SetParams_002, TestSize.Level1)
485 {
486     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(STREAM_MUSIC);
487     ASSERT_NE(nullptr, audioRenderer);
488 
489     AudioRendererParams rendererParams;
490     rendererParams.sampleFormat = SAMPLE_S16LE;
491     rendererParams.sampleRate = SAMPLE_RATE_8000;
492     rendererParams.channelCount = MONO;
493     rendererParams.encodingType = ENCODING_PCM;
494 
495     int32_t ret = audioRenderer->SetParams(rendererParams);
496     EXPECT_EQ(SUCCESS, ret);
497     audioRenderer->Release();
498 }
499 
500 /**
501 * @tc.name  : Test SetParams API via legal input.
502 * @tc.number: Audio_Renderer_SetParams_003
503 * @tc.desc  : Test SetParams interface. Returns 0 {SUCCESS}, if the setting is successful.
504 *             rendererParams.sampleFormat = SAMPLE_S16LE;
505 *             rendererParams.sampleRate = SAMPLE_RATE_11025;
506 *             rendererParams.channelCount = STEREO;
507 *             rendererParams.encodingType = ENCODING_PCM;
508 */
509 HWTEST(AudioRendererUnitTest, Audio_Renderer_SetParams_003, TestSize.Level1)
510 {
511     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(STREAM_MUSIC);
512     ASSERT_NE(nullptr, audioRenderer);
513 
514     AudioRendererParams rendererParams;
515     rendererParams.sampleFormat = SAMPLE_S16LE;
516     rendererParams.sampleRate = SAMPLE_RATE_11025;
517     rendererParams.channelCount = STEREO;
518     rendererParams.encodingType = ENCODING_PCM;
519 
520     int32_t ret = audioRenderer->SetParams(rendererParams);
521     EXPECT_EQ(SUCCESS, ret);
522     audioRenderer->Release();
523 }
524 
525 /**
526 * @tc.name  : Test SetParams API via legal input.
527 * @tc.number: Audio_Renderer_SetParams_004
528 * @tc.desc  : Test SetParams interface. Returns 0 {SUCCESS}, if the setting is successful.
529 *             rendererParams.sampleFormat = SAMPLE_S16LE;
530 *             rendererParams.sampleRate = SAMPLE_RATE_22050;
531 *             rendererParams.channelCount = MONO;
532 *             rendererParams.encodingType = ENCODING_PCM;
533 */
534 HWTEST(AudioRendererUnitTest, Audio_Renderer_SetParams_004, TestSize.Level1)
535 {
536     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(STREAM_MUSIC);
537     ASSERT_NE(nullptr, audioRenderer);
538 
539     AudioRendererParams rendererParams;
540     rendererParams.sampleFormat = SAMPLE_S16LE;
541     rendererParams.sampleRate = SAMPLE_RATE_22050;
542     rendererParams.channelCount = MONO;
543     rendererParams.encodingType = ENCODING_PCM;
544 
545     int32_t ret = audioRenderer->SetParams(rendererParams);
546     EXPECT_EQ(SUCCESS, ret);
547     audioRenderer->Release();
548 }
549 
550 /**
551 * @tc.name  : Test SetParams API via legal input.
552 * @tc.number: Audio_Renderer_SetParams_005
553 * @tc.desc  : Test SetParams interface. Returns 0 {SUCCESS}, if the setting is successful.
554 *             rendererParams.sampleFormat = SAMPLE_S16LE;
555 *             rendererParams.sampleRate = SAMPLE_RATE_96000;
556 *             rendererParams.channelCount = MONO;
557 *             rendererParams.encodingType = ENCODING_PCM;
558 */
559 HWTEST(AudioRendererUnitTest, Audio_Renderer_SetParams_005, TestSize.Level1)
560 {
561     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(STREAM_MUSIC);
562     ASSERT_NE(nullptr, audioRenderer);
563 
564     AudioRendererParams rendererParams;
565     rendererParams.sampleFormat = SAMPLE_S16LE;
566     rendererParams.sampleRate = SAMPLE_RATE_96000;
567     rendererParams.channelCount = MONO;
568     rendererParams.encodingType = ENCODING_PCM;
569 
570     int32_t ret = audioRenderer->SetParams(rendererParams);
571     EXPECT_EQ(SUCCESS, ret);
572 }
573 
574 /**
575 * @tc.name  : Test SetParams API via legal input.
576 * @tc.number: Audio_Renderer_SetParams_006
577 * @tc.desc  : Test SetParams interface. Returns 0 {SUCCESS}, if the setting is successful.
578 *             rendererParams.sampleFormat = SAMPLE_S24LE;
579 *             rendererParams.sampleRate = SAMPLE_RATE_64000;
580 *             rendererParams.channelCount = MONO;
581 *             rendererParams.encodingType = ENCODING_PCM;
582 */
583 HWTEST(AudioRendererUnitTest, Audio_Renderer_SetParams_006, TestSize.Level1)
584 {
585     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(STREAM_MUSIC);
586     ASSERT_NE(nullptr, audioRenderer);
587 
588     AudioRendererParams rendererParams;
589     rendererParams.sampleFormat = SAMPLE_S24LE;
590     rendererParams.sampleRate = SAMPLE_RATE_64000;
591     rendererParams.channelCount = MONO;
592     rendererParams.encodingType = ENCODING_PCM;
593 
594     int32_t ret = audioRenderer->SetParams(rendererParams);
595     EXPECT_EQ(SUCCESS, ret);
596 }
597 
598 /**
599 * @tc.name  : Test SetParams API via illegal input.
600 * @tc.number: Audio_Renderer_SetParams_007
601 * @tc.desc  : Test SetParams interface. Returns 0 {SUCCESS}, if the setting is successful.
602 *             rendererParams.sampleFormat = SAMPLE_S16LE;
603 *             rendererParams.sampleRate = SAMPLE_RATE_16000;
604 *             rendererParams.channelCount = STEREO;
605 *             rendererParams.encodingType = ENCODING_PCM;
606 */
607 HWTEST(AudioRendererUnitTest, Audio_Renderer_SetParams_007, TestSize.Level1)
608 {
609     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(STREAM_MUSIC);
610     ASSERT_NE(nullptr, audioRenderer);
611 
612     AudioRendererParams rendererParams;
613     rendererParams.sampleFormat = SAMPLE_S16LE;
614     rendererParams.sampleRate = SAMPLE_RATE_16000;
615     rendererParams.channelCount = STEREO;
616     rendererParams.encodingType = ENCODING_PCM;
617 
618     int32_t ret = audioRenderer->SetParams(rendererParams);
619     EXPECT_EQ(SUCCESS, ret);
620     audioRenderer->Release();
621 }
622 
623 /**
624 * @tc.name  : Test SetParams API stability.
625 * @tc.number: Audio_Renderer_SetParams_Stability_001
626 * @tc.desc  : Test SetParams interface stability.
627 */
628 HWTEST(AudioRendererUnitTest, Audio_Renderer_SetParams_Stability_001, TestSize.Level1)
629 {
630     int32_t ret = -1;
631     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(STREAM_MUSIC);
632     ASSERT_NE(nullptr, audioRenderer);
633 
634     AudioRendererParams rendererParams;
635     rendererParams.sampleFormat = SAMPLE_S16LE;
636     rendererParams.sampleRate = SAMPLE_RATE_44100;
637     rendererParams.channelCount = STEREO;
638     rendererParams.encodingType = ENCODING_PCM;
639 
640     for (int i = 0; i < VALUE_HUNDRED; i++) {
641         ret = audioRenderer->SetParams(rendererParams);
642         EXPECT_EQ(SUCCESS, ret);
643 
644         AudioRendererParams getRendererParams;
645         ret = audioRenderer->GetParams(getRendererParams);
646         EXPECT_EQ(SUCCESS, ret);
647     }
648 
649     audioRenderer->Release();
650 }
651 
652 /**
653 * @tc.name  : Test GetParams API via legal input.
654 * @tc.number: Audio_Renderer_GetParams_001
655 * @tc.desc  : Test GetParams interface. Returns 0 {SUCCESS}, if the getting is successful.
656 */
657 HWTEST(AudioRendererUnitTest, Audio_Renderer_GetParams_001, TestSize.Level1)
658 {
659     int32_t ret = -1;
660     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(STREAM_MUSIC);
661     ASSERT_NE(nullptr, audioRenderer);
662 
663     AudioRendererParams rendererParams;
664     rendererParams.sampleFormat = SAMPLE_S16LE;
665     rendererParams.sampleRate = SAMPLE_RATE_44100;
666     rendererParams.channelCount = STEREO;
667     rendererParams.encodingType = ENCODING_PCM;
668     ret = audioRenderer->SetParams(rendererParams);
669     EXPECT_EQ(SUCCESS, ret);
670 
671     AudioRendererParams getRendererParams;
672     ret = audioRenderer->GetParams(getRendererParams);
673     EXPECT_EQ(SUCCESS, ret);
674     EXPECT_EQ(rendererParams.sampleFormat, getRendererParams.sampleFormat);
675     EXPECT_EQ(rendererParams.sampleRate, getRendererParams.sampleRate);
676     EXPECT_EQ(rendererParams.channelCount, getRendererParams.channelCount);
677     EXPECT_EQ(rendererParams.encodingType, getRendererParams.encodingType);
678 
679     audioRenderer->Release();
680 }
681 
682 /**
683 * @tc.name  : Test GetParams API via legal state, RENDERER_RUNNING: GetParams after Start.
684 * @tc.number: Audio_Renderer_GetParams_002
685 * @tc.desc  : Test GetParams interface. Returns 0 {SUCCESS} if the getting is successful.
686 */
687 HWTEST(AudioRendererUnitTest, Audio_Renderer_GetParams_002, TestSize.Level1)
688 {
689     int32_t ret = -1;
690     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(STREAM_MUSIC);
691     ASSERT_NE(nullptr, audioRenderer);
692 
693     AudioRendererParams rendererParams;
694     rendererParams.sampleFormat = SAMPLE_S16LE;
695     rendererParams.sampleRate = SAMPLE_RATE_44100;
696     rendererParams.channelCount = MONO;
697     rendererParams.encodingType = ENCODING_PCM;
698     ret = audioRenderer->SetParams(rendererParams);
699     EXPECT_EQ(SUCCESS, ret);
700 
701     bool isStarted = audioRenderer->Start();
702     EXPECT_EQ(true, isStarted);
703 
704     AudioRendererParams getRendererParams;
705     ret = audioRenderer->GetParams(getRendererParams);
706     EXPECT_EQ(SUCCESS, ret);
707 
708     audioRenderer->Release();
709 }
710 
711 /**
712 * @tc.name  : Test GetParams API via illegal state, RENDERER_NEW: Call GetParams without SetParams.
713 * @tc.number: Audio_Renderer_GetParams_003
714 * @tc.desc  : Test GetParams interface. Returns error code, if the renderer state is RENDERER_NEW.
715 */
716 HWTEST(AudioRendererUnitTest, Audio_Renderer_GetParams_003, TestSize.Level1)
717 {
718     int32_t ret = -1;
719     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(STREAM_MUSIC);
720     ASSERT_NE(nullptr, audioRenderer);
721 
722     AudioRendererParams rendererParams;
723     rendererParams.sampleFormat = SAMPLE_S16LE;
724     rendererParams.sampleRate = SAMPLE_RATE_44100;
725     rendererParams.channelCount = MONO;
726     rendererParams.encodingType = ENCODING_PCM;
727 
728     AudioRendererParams getRendererParams;
729     ret = audioRenderer->GetParams(getRendererParams);
730     EXPECT_EQ(ERR_OPERATION_FAILED, ret);
731 }
732 
733 /**
734 * @tc.name  : Test GetParams API via illegal state, RENDERER_RELEASED: Call GetParams after Release.
735 * @tc.number: Audio_Renderer_GetParams_004
736 * @tc.desc  : Test GetParams interface. Returns error code, if the renderer state is RENDERER_RELEASED.
737 */
738 HWTEST(AudioRendererUnitTest, Audio_Renderer_GetParams_004, TestSize.Level1)
739 {
740     int32_t ret = -1;
741     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(STREAM_MUSIC);
742     ASSERT_NE(nullptr, audioRenderer);
743 
744     ret = AudioRendererUnitTest::InitializeRenderer(audioRenderer);
745     EXPECT_EQ(SUCCESS, ret);
746 
747     bool isReleased = audioRenderer->Release();
748     EXPECT_EQ(true, isReleased);
749 
750     AudioRendererParams getRendererParams;
751     ret = audioRenderer->GetParams(getRendererParams);
752     EXPECT_EQ(ERR_OPERATION_FAILED, ret);
753 }
754 
755 /**
756 * @tc.name  : Test GetParams API via legal state, RENDERER_STOPPED: GetParams after Stop.
757 * @tc.number: Audio_Renderer_GetParams_005
758 * @tc.desc  : Test GetParams interface. Returns 0 {SUCCESS}, if the getting is successful.
759 */
760 HWTEST(AudioRendererUnitTest, Audio_Renderer_GetParams_005, TestSize.Level1)
761 {
762     int32_t ret = -1;
763     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(STREAM_MUSIC);
764     ASSERT_NE(nullptr, audioRenderer);
765 
766     ret = AudioRendererUnitTest::InitializeRenderer(audioRenderer);
767     EXPECT_EQ(SUCCESS, ret);
768 
769     bool isStarted = audioRenderer->Start();
770     EXPECT_EQ(true, isStarted);
771 
772     bool isStopped = audioRenderer->Stop();
773     EXPECT_EQ(true, isStopped);
774 
775     AudioRendererParams getRendererParams;
776     ret = audioRenderer->GetParams(getRendererParams);
777     EXPECT_EQ(SUCCESS, ret);
778 
779     audioRenderer->Release();
780 }
781 
782 /**
783 * @tc.name  : Test GetParams API stability.
784 * @tc.number: Audio_Renderer_GetParams_Stability_001
785 * @tc.desc  : Test GetParams interface stability.
786 */
787 HWTEST(AudioRendererUnitTest, Audio_Renderer_GetParams_Stability_001, TestSize.Level1)
788 {
789     int32_t ret = -1;
790     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(STREAM_MUSIC);
791     ASSERT_NE(nullptr, audioRenderer);
792 
793     AudioRendererParams rendererParams;
794     rendererParams.sampleFormat = SAMPLE_S16LE;
795     rendererParams.sampleRate = SAMPLE_RATE_44100;
796     rendererParams.channelCount = STEREO;
797     rendererParams.encodingType = ENCODING_PCM;
798 
799     ret = audioRenderer->SetParams(rendererParams);
800     EXPECT_EQ(SUCCESS, ret);
801 
802     for (int i = 0; i < VALUE_THOUSAND; i++) {
803         AudioRendererParams getRendererParams;
804         ret = audioRenderer->GetParams(getRendererParams);
805         EXPECT_EQ(SUCCESS, ret);
806     }
807 
808     audioRenderer->Release();
809 }
810 
811 /**
812 * @tc.name  : Test GetBufferSize API via legal input.
813 * @tc.number: Audio_Renderer_GetBufferSize_001
814 * @tc.desc  : Test GetBufferSize interface. Returns 0 {SUCCESS}, if the getting is successful.
815 */
816 HWTEST(AudioRendererUnitTest, Audio_Renderer_GetBufferSize_001, TestSize.Level1)
817 {
818     int32_t ret = -1;
819     AudioRendererOptions rendererOptions;
820 
821     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
822     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
823     ASSERT_NE(nullptr, audioRenderer);
824 
825     size_t bufferLen;
826     ret = audioRenderer->GetBufferSize(bufferLen);
827     EXPECT_EQ(SUCCESS, ret);
828 
829     audioRenderer->Release();
830 }
831 
832 /**
833 * @tc.name  : Test GetBufferSize API via illegal state, RENDERER_NEW: without initializing the renderer.
834 * @tc.number: Audio_Renderer_GetBufferSize_002
835 * @tc.desc  : Test GetBufferSize interface. Returns error code, if the renderer state is RENDERER_NEW.
836 */
837 HWTEST(AudioRendererUnitTest, Audio_Renderer_GetBufferSize_002, TestSize.Level1)
838 {
839     int32_t ret = -1;
840     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(STREAM_MUSIC);
841     ASSERT_NE(nullptr, audioRenderer);
842 
843     size_t bufferLen;
844     ret = audioRenderer->GetBufferSize(bufferLen);
845     EXPECT_EQ(ERR_OPERATION_FAILED, ret);
846 }
847 
848 /**
849 * @tc.name  : Test GetBufferSize API via illegal state, RENDERER_RELEASED: call Release before GetBufferSize
850 * @tc.number: Audio_Renderer_GetBufferSize_003
851 * @tc.desc  : Test GetBufferSize interface. Returns error code, if the renderer state is RENDERER_RELEASED.
852 */
853 HWTEST(AudioRendererUnitTest, Audio_Renderer_GetBufferSize_003, TestSize.Level1)
854 {
855     int32_t ret = -1;
856     AudioRendererOptions rendererOptions;
857 
858     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
859     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
860     ASSERT_NE(nullptr, audioRenderer);
861 
862     bool isReleased = audioRenderer->Release();
863     EXPECT_EQ(true, isReleased);
864 
865     size_t bufferLen;
866     ret = audioRenderer->GetBufferSize(bufferLen);
867     EXPECT_EQ(ERR_OPERATION_FAILED, ret);
868 }
869 
870 /**
871 * @tc.name  : Test GetBufferSize API via legal state, RENDERER_STOPPED: call Stop before GetBufferSize
872 * @tc.number: Audio_Renderer_GetBufferSize_004
873 * @tc.desc  : Test GetBufferSize interface. Returns 0 {SUCCESS}, if the getting is successful.
874 */
875 HWTEST(AudioRendererUnitTest, Audio_Renderer_GetBufferSize_004, TestSize.Level1)
876 {
877     int32_t ret = -1;
878     AudioRendererOptions rendererOptions;
879 
880     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
881     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
882     ASSERT_NE(nullptr, audioRenderer);
883 
884     bool isStarted = audioRenderer->Start();
885     EXPECT_EQ(true, isStarted);
886 
887     bool isStopped = audioRenderer->Stop();
888     EXPECT_EQ(true, isStopped);
889 
890     size_t bufferLen;
891     ret = audioRenderer->GetBufferSize(bufferLen);
892     EXPECT_EQ(SUCCESS, ret);
893 
894     audioRenderer->Release();
895 }
896 
897 /**
898 * @tc.name  : Test GetBufferSize API via legal state, RENDERER_RUNNING: call Start before GetBufferSize
899 * @tc.number: Audio_Renderer_GetBufferSize_005
900 * @tc.desc  : test GetBufferSize interface. Returns 0 {SUCCESS}, if the getting is successful.
901 */
902 HWTEST(AudioRendererUnitTest, Audio_Renderer_GetBufferSize_005, TestSize.Level1)
903 {
904     int32_t ret = -1;
905     AudioRendererOptions rendererOptions;
906 
907     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
908     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
909     ASSERT_NE(nullptr, audioRenderer);
910 
911     bool isStarted = audioRenderer->Start();
912     EXPECT_EQ(true, isStarted);
913 
914     size_t bufferLen;
915     ret = audioRenderer->GetBufferSize(bufferLen);
916     EXPECT_EQ(SUCCESS, ret);
917 
918     audioRenderer->Release();
919 }
920 
921 /**
922 * @tc.name  : Test GetFrameCount API via legal input.
923 * @tc.number: Audio_Renderer_GetFrameCount_001
924 * @tc.desc  : test GetFrameCount interface, Returns 0 {SUCCESS}, if the getting is successful.
925 */
926 HWTEST(AudioRendererUnitTest, Audio_Renderer_GetFrameCount_001, TestSize.Level1)
927 {
928     int32_t ret = -1;
929     AudioRendererOptions rendererOptions;
930 
931     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
932     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
933     ASSERT_NE(nullptr, audioRenderer);
934 
935     uint32_t frameCount;
936     ret = audioRenderer->GetFrameCount(frameCount);
937     EXPECT_EQ(SUCCESS, ret);
938 
939     audioRenderer->Release();
940 }
941 
942 /**
943 * @tc.name  : Test GetFrameCount API via illegal state, RENDERER_NEW: without initialiing the renderer.
944 * @tc.number: Audio_Renderer_GetFrameCount_002
945 * @tc.desc  : Test GetFrameCount interface. Returns error code, if the renderer state is RENDERER_NEW.
946 */
947 HWTEST(AudioRendererUnitTest, Audio_Renderer_GetFrameCount_002, TestSize.Level1)
948 {
949     int32_t ret = -1;
950     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(STREAM_MUSIC);
951     ASSERT_NE(nullptr, audioRenderer);
952 
953     uint32_t frameCount;
954     ret = audioRenderer->GetFrameCount(frameCount);
955     EXPECT_EQ(ERR_OPERATION_FAILED, ret);
956 }
957 
958 /**
959 * @tc.name  : Test GetFrameCount API via legal state, RENDERER_RUNNING: call Start before GetFrameCount.
960 * @tc.number: Audio_Renderer_GetFrameCount_003
961 * @tc.desc  : Test GetFrameCount interface. Returns 0 {SUCCESS}, if the getting is successful.
962 */
963 HWTEST(AudioRendererUnitTest, Audio_Renderer_GetFrameCount_003, TestSize.Level1)
964 {
965     int32_t ret = -1;
966     AudioRendererOptions rendererOptions;
967 
968     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
969     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
970     ASSERT_NE(nullptr, audioRenderer);
971 
972     bool isStarted = audioRenderer->Start();
973     EXPECT_EQ(true, isStarted);
974 
975     uint32_t frameCount;
976     ret = audioRenderer->GetFrameCount(frameCount);
977     EXPECT_EQ(SUCCESS, ret);
978 
979     audioRenderer->Release();
980 }
981 
982 /**
983 * @tc.name  : Test GetFrameCount API via legal state, RENDERER_STOPPED: call Stop before GetFrameCount
984 * @tc.number: Audio_Renderer_GetFrameCount_004
985 * @tc.desc  : Test GetFrameCount interface. Returns 0 {SUCCESS}, if the getting is successful.
986 */
987 HWTEST(AudioRendererUnitTest, Audio_Renderer_GetFrameCount_004, TestSize.Level1)
988 {
989     int32_t ret = -1;
990     AudioRendererOptions rendererOptions;
991 
992     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
993     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
994     ASSERT_NE(nullptr, audioRenderer);
995 
996     bool isStarted = audioRenderer->Start();
997     EXPECT_EQ(true, isStarted);
998 
999     bool isStopped = audioRenderer->Stop();
1000     EXPECT_EQ(true, isStopped);
1001 
1002     uint32_t frameCount;
1003     ret = audioRenderer->GetFrameCount(frameCount);
1004     EXPECT_EQ(SUCCESS, ret);
1005 
1006     audioRenderer->Release();
1007 }
1008 
1009 /**
1010 * @tc.name  : Test GetFrameCount API via illegal state, RENDERER_RELEASED: call Release before GetFrameCount
1011 * @tc.number: Audio_Renderer_GetFrameCount_005
1012 * @tc.desc  : Test GetFrameCount interface.  Returns error code, if the state is RENDERER_RELEASED.
1013 */
1014 HWTEST(AudioRendererUnitTest, Audio_Renderer_GetFrameCount_005, TestSize.Level1)
1015 {
1016     int32_t ret = -1;
1017     AudioRendererOptions rendererOptions;
1018 
1019     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
1020     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
1021     ASSERT_NE(nullptr, audioRenderer);
1022 
1023     bool isReleased = audioRenderer->Release();
1024     EXPECT_EQ(true, isReleased);
1025 
1026     uint32_t frameCount;
1027     ret = audioRenderer->GetFrameCount(frameCount);
1028     EXPECT_EQ(ERR_OPERATION_FAILED, ret);
1029 }
1030 
1031 /**
1032 * @tc.name  : Test GetFrameCount API via legal state, RENDERER_PAUSED: call Pause before GetFrameCount
1033 * @tc.number: Audio_Renderer_GetFrameCount_006
1034 * @tc.desc  : Test GetFrameCount interface. Returns 0 {SUCCESS}, if the getting is successful.
1035 */
1036 HWTEST(AudioRendererUnitTest, Audio_Renderer_GetFrameCount_006, TestSize.Level1)
1037 {
1038     int32_t ret = -1;
1039     AudioRendererOptions rendererOptions;
1040 
1041     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
1042     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
1043     ASSERT_NE(nullptr, audioRenderer);
1044 
1045     bool isStarted = audioRenderer->Start();
1046     EXPECT_EQ(true, isStarted);
1047 
1048     bool isPaused = audioRenderer->Pause();
1049     EXPECT_EQ(true, isPaused);
1050 
1051     uint32_t frameCount;
1052     ret = audioRenderer->GetFrameCount(frameCount);
1053     EXPECT_EQ(SUCCESS, ret);
1054 
1055     audioRenderer->Release();
1056 }
1057 
1058 /**
1059 * @tc.name  : Test SetVolume
1060 * @tc.number: Audio_Renderer_SetVolume_001
1061 * @tc.desc  : Test SetVolume interface, Returns 0 {SUCCESS}, if the track volume is set.
1062 */
1063 HWTEST(AudioRendererUnitTest, Audio_Renderer_SetVolume_001, TestSize.Level1)
1064 {
1065     int32_t ret = -1;
1066     AudioRendererOptions rendererOptions;
1067 
1068     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
1069     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
1070     ASSERT_NE(nullptr, audioRenderer);
1071 
1072     ret = audioRenderer->SetVolume(0.5);
1073     EXPECT_EQ(SUCCESS, ret);
1074 
1075     bool isReleased = audioRenderer->Release();
1076     EXPECT_EQ(true, isReleased);
1077 }
1078 
1079 /**
1080 * @tc.name  : Test SetVolume
1081 * @tc.number: Audio_Renderer_SetVolume_002
1082 * @tc.desc  : Test SetVolume interface for minimum and maximum volumes.
1083 */
1084 HWTEST(AudioRendererUnitTest, Audio_Renderer_SetVolume_002, TestSize.Level1)
1085 {
1086     int32_t ret = -1;
1087     AudioRendererOptions rendererOptions;
1088 
1089     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
1090     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
1091     ASSERT_NE(nullptr, audioRenderer);
1092 
1093     ret = audioRenderer->SetVolume(0);
1094     EXPECT_EQ(SUCCESS, ret);
1095 
1096     ret = audioRenderer->SetVolume(1.0);
1097     EXPECT_EQ(SUCCESS, ret);
1098 
1099     bool isReleased = audioRenderer->Release();
1100     EXPECT_EQ(true, isReleased);
1101 }
1102 
1103 /**
1104 * @tc.name  : Test SetVolume
1105 * @tc.number: Audio_Renderer_SetVolume_003
1106 * @tc.desc  : Test SetVolume interface for out of range values.
1107 */
1108 HWTEST(AudioRendererUnitTest, Audio_Renderer_SetVolume_003, TestSize.Level1)
1109 {
1110     int32_t ret = -1;
1111     AudioRendererOptions rendererOptions;
1112 
1113     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
1114     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
1115     ASSERT_NE(nullptr, audioRenderer);
1116 
1117     ret = audioRenderer->SetVolume(-0.5);
1118     EXPECT_NE(SUCCESS, ret);
1119 
1120     ret = audioRenderer->SetVolume(1.5);
1121     EXPECT_NE(SUCCESS, ret);
1122 
1123     bool isReleased = audioRenderer->Release();
1124     EXPECT_EQ(true, isReleased);
1125 }
1126 
1127 /**
1128 * @tc.name  : Test SetVolume
1129 * @tc.number: Audio_Renderer_SetVolume_Stability_001
1130 * @tc.desc  : Test SetVolume interface stability.
1131 */
1132 HWTEST(AudioRendererUnitTest, Audio_Renderer_SetVolume_Stability_001, TestSize.Level1)
1133 {
1134     AudioRendererOptions rendererOptions;
1135 
1136     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
1137     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
1138     ASSERT_NE(nullptr, audioRenderer);
1139 
1140     bool isStarted = audioRenderer->Start();
1141     EXPECT_EQ(true, isStarted);
1142 
1143     thread renderThread(StartRenderThread, audioRenderer.get());
1144 
1145     for (int i = 0; i < VALUE_THOUSAND; i++) {
1146         audioRenderer->SetVolume(0.1);
1147         audioRenderer->SetVolume(1.0);
1148     }
1149 
1150     renderThread.join();
1151 
1152     bool isStopped = audioRenderer->Stop();
1153     EXPECT_EQ(true, isStopped);
1154 
1155     bool isReleased = audioRenderer->Release();
1156     EXPECT_EQ(true, isReleased);
1157 }
1158 
1159 /**
1160 * @tc.name  : Test GetVolume
1161 * @tc.number: Audio_Renderer_GetVolume_001
1162 * @tc.desc  : Test GetVolume interface to get the default value.
1163 */
1164 HWTEST(AudioRendererUnitTest, Audio_Renderer_GetVolume_001, TestSize.Level1)
1165 {
1166     AudioRendererOptions rendererOptions;
1167 
1168     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
1169     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
1170     ASSERT_NE(nullptr, audioRenderer);
1171 
1172     float volume = audioRenderer->GetVolume();
1173     EXPECT_EQ(1.0, volume);
1174 
1175     bool isReleased = audioRenderer->Release();
1176     EXPECT_EQ(true, isReleased);
1177 }
1178 
1179 /**
1180 * @tc.name  : Test GetVolume
1181 * @tc.number: Audio_Renderer_GetVolume_002
1182 * @tc.desc  : Test GetVolume interface after set volume call.
1183 */
1184 HWTEST(AudioRendererUnitTest, Audio_Renderer_GetVolume_002, TestSize.Level1)
1185 {
1186     int32_t ret = -1;
1187     AudioRendererOptions rendererOptions;
1188 
1189     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
1190     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
1191     ASSERT_NE(nullptr, audioRenderer);
1192 
1193     ret = audioRenderer->SetVolume(0.5);
1194     EXPECT_EQ(SUCCESS, ret);
1195 
1196     float volume = audioRenderer->GetVolume();
1197     EXPECT_EQ(0.5, volume);
1198 
1199     bool isReleased = audioRenderer->Release();
1200     EXPECT_EQ(true, isReleased);
1201 }
1202 
1203 /**
1204 * @tc.name  : Test GetVolume
1205 * @tc.number: Audio_Renderer_GetVolume_003
1206 * @tc.desc  : Test GetVolume interface after set volume fails.
1207 */
1208 HWTEST(AudioRendererUnitTest, Audio_Renderer_GetVolume_003, TestSize.Level1)
1209 {
1210     int32_t ret = -1;
1211     AudioRendererOptions rendererOptions;
1212 
1213     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
1214     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
1215     ASSERT_NE(nullptr, audioRenderer);
1216 
1217     ret = audioRenderer->SetVolume(0.5);
1218     EXPECT_EQ(SUCCESS, ret);
1219 
1220     ret = audioRenderer->SetVolume(1.5);
1221     EXPECT_NE(SUCCESS, ret);
1222 
1223     float volume = audioRenderer->GetVolume();
1224     EXPECT_EQ(0.5, volume);
1225 
1226     bool isReleased = audioRenderer->Release();
1227     EXPECT_EQ(true, isReleased);
1228 }
1229 
1230 /**
1231 * @tc.name  : Test Start API via legal state, RENDERER_PREPARED.
1232 * @tc.number: Audio_Renderer_Start_001
1233 * @tc.desc  : Test Start interface. Returns true if start is successful.
1234 */
1235 HWTEST(AudioRendererUnitTest, Audio_Renderer_Start_001, TestSize.Level1)
1236 {
1237     AudioRendererOptions rendererOptions;
1238 
1239     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
1240     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
1241     ASSERT_NE(nullptr, audioRenderer);
1242 
1243     bool isStarted = audioRenderer->Start();
1244     EXPECT_EQ(true, isStarted);
1245 
1246     audioRenderer->Release();
1247 }
1248 
1249 /**
1250 * @tc.name  : Test Start API via illegal state, RENDERER_NEW: without initializing the renderer.
1251 * @tc.number: Audio_Renderer_Start_002
1252 * @tc.desc  : Test Start interface. Returns false, if the renderer state is RENDERER_NEW.
1253 */
1254 HWTEST(AudioRendererUnitTest, Audio_Renderer_Start_002, TestSize.Level1)
1255 {
1256     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(STREAM_MUSIC);
1257     ASSERT_NE(nullptr, audioRenderer);
1258 
1259     bool isStarted = audioRenderer->Start();
1260     EXPECT_EQ(false, isStarted);
1261 }
1262 
1263 /**
1264 * @tc.name  : Test Start API via illegal state, RENDERER_RELEASED: call Start after Release
1265 * @tc.number: Audio_Renderer_Start_003
1266 * @tc.desc  : Test Start interface. Returns false, if the renderer state is RENDERER_RELEASED.
1267 */
1268 HWTEST(AudioRendererUnitTest, Audio_Renderer_Start_003, TestSize.Level1)
1269 {
1270     AudioRendererOptions rendererOptions;
1271 
1272     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
1273     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
1274     ASSERT_NE(nullptr, audioRenderer);
1275 
1276     bool isReleased = audioRenderer->Release();
1277     EXPECT_EQ(true, isReleased);
1278 
1279     bool isStarted = audioRenderer->Start();
1280     EXPECT_EQ(false, isStarted);
1281 
1282     audioRenderer->Release();
1283 }
1284 
1285 /**
1286 * @tc.name  : Test Start API via legal state, RENDERER_STOPPED: Start Stop and then Start again
1287 * @tc.number: Audio_Renderer_Start_004
1288 * @tc.desc  : Test Start interface. Returns true, if the start is successful.
1289 */
1290 HWTEST(AudioRendererUnitTest, Audio_Renderer_Start_004, TestSize.Level1)
1291 {
1292     AudioRendererOptions rendererOptions;
1293 
1294     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
1295     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
1296     ASSERT_NE(nullptr, audioRenderer);
1297 
1298     bool isStarted = audioRenderer->Start();
1299     EXPECT_EQ(true, isStarted);
1300 
1301     bool isStopped = audioRenderer->Stop();
1302     EXPECT_EQ(true, isStopped);
1303 
1304     isStarted = audioRenderer->Start();
1305     EXPECT_EQ(true, isStarted);
1306 
1307     audioRenderer->Release();
1308 }
1309 
1310 /**
1311 * @tc.name  : Test Start API via illegal state, RENDERER_RUNNING : call Start repeatedly
1312 * @tc.number: Audio_Renderer_Start_005
1313 * @tc.desc  : Test Start interface. Returns false, if the renderer state is RENDERER_RUNNING.
1314 */
1315 HWTEST(AudioRendererUnitTest, Audio_Renderer_Start_005, TestSize.Level1)
1316 {
1317     AudioRendererOptions rendererOptions;
1318 
1319     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
1320     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
1321     ASSERT_NE(nullptr, audioRenderer);
1322 
1323     bool isStarted = audioRenderer->Start();
1324     EXPECT_EQ(true, isStarted);
1325 
1326     isStarted = audioRenderer->Start();
1327     EXPECT_EQ(false, isStarted);
1328 
1329     audioRenderer->Release();
1330 }
1331 
1332 /**
1333 * @tc.name  : Test Start API via legal state, RENDERER_PAUSED : call Start after pause
1334 * @tc.number: Audio_Renderer_Start_005
1335 * @tc.desc  : Test Start interface. Returns false, if the renderer state is RENDERER_PAUSED.
1336 */
1337 HWTEST(AudioRendererUnitTest, Audio_Renderer_Start_006, TestSize.Level1)
1338 {
1339     AudioRendererOptions rendererOptions;
1340 
1341     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
1342     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
1343     ASSERT_NE(nullptr, audioRenderer);
1344 
1345     bool isStarted = audioRenderer->Start();
1346     EXPECT_EQ(true, isStarted);
1347 
1348     bool isPaused = audioRenderer->Pause();
1349     EXPECT_EQ(true, isPaused);
1350 
1351     isStarted = audioRenderer->Start();
1352     EXPECT_EQ(true, isStarted);
1353 
1354     audioRenderer->Release();
1355 }
1356 
1357 /**
1358 * @tc.name  : Test Write API.
1359 * @tc.number: Audio_Renderer_Write_001
1360 * @tc.desc  : Test Write interface. Returns number of bytes written, if the write is successful.
1361 */
1362 
1363 HWTEST(AudioRendererUnitTest, Audio_Renderer_Write_001, TestSize.Level1)
1364 {
1365     int32_t ret = -1;
1366     FILE *wavFile = fopen(AUDIORENDER_TEST_FILE_PATH.c_str(), "rb");
1367     ASSERT_NE(nullptr, wavFile);
1368 
1369     AudioRendererOptions rendererOptions;
1370     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
1371     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
1372     ASSERT_NE(nullptr, audioRenderer);
1373 
1374     bool isStarted = audioRenderer->Start();
1375     EXPECT_EQ(true, isStarted);
1376 
1377     size_t bufferLen;
1378     ret = audioRenderer->GetBufferSize(bufferLen);
1379     EXPECT_EQ(SUCCESS, ret);
1380 
1381     uint8_t *buffer = (uint8_t *) malloc(bufferLen);
1382     ASSERT_NE(nullptr, buffer);
1383 
1384     size_t bytesToWrite = 0;
1385     int32_t bytesWritten = 0;
1386     size_t minBytes = 4;
1387     int32_t numBuffersToRender = WRITE_BUFFERS_COUNT;
1388 
1389     while (numBuffersToRender) {
1390         bytesToWrite = fread(buffer, 1, bufferLen, wavFile);
1391         bytesWritten = 0;
1392         while ((static_cast<size_t>(bytesWritten) < bytesToWrite) &&
1393             ((static_cast<size_t>(bytesToWrite) - bytesWritten) > minBytes)) {
1394             bytesWritten += audioRenderer->Write(buffer + static_cast<size_t>(bytesWritten),
1395                                                  bytesToWrite - static_cast<size_t>(bytesWritten));
1396             EXPECT_GE(bytesWritten, VALUE_ZERO);
1397             if (bytesWritten < 0) {
1398                 break;
1399             }
1400         }
1401         numBuffersToRender--;
1402     }
1403 
1404     audioRenderer->Drain();
1405     audioRenderer->Stop();
1406     audioRenderer->Release();
1407 
1408     free(buffer);
1409     fclose(wavFile);
1410 }
1411 
1412 /**
1413 * @tc.name  : Test Write API via illegl state, RENDERER_NEW : without Initializing the renderer.
1414 * @tc.number: Audio_Renderer_Write_002
1415 * @tc.desc  : Test Write interface. Returns error code, if the renderer state is RENDERER_NEW.
1416 *           : bufferLen is invalid here, firstly bufferLen is validated in Write. So it returns ERR_INVALID_PARAM.
1417 */
1418 HWTEST(AudioRendererUnitTest, Audio_Renderer_Write_002, TestSize.Level1)
1419 {
1420     int32_t ret = -1;
1421     FILE *wavFile = fopen(AUDIORENDER_TEST_FILE_PATH.c_str(), "rb");
1422     ASSERT_NE(nullptr, wavFile);
1423 
1424     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(STREAM_MUSIC);
1425     ASSERT_NE(nullptr, audioRenderer);
1426 
1427     bool isStarted = audioRenderer->Start();
1428     EXPECT_EQ(false, isStarted);
1429 
1430     size_t bufferLen;
1431     ret = audioRenderer->GetBufferSize(bufferLen);
1432     EXPECT_EQ(ERR_OPERATION_FAILED, ret);
1433 
1434     uint8_t *buffer = (uint8_t *) malloc(bufferLen);
1435     ASSERT_NE(nullptr, buffer);
1436 
1437     size_t bytesToWrite = fread(buffer, 1, bufferLen, wavFile);
1438     int32_t bytesWritten = audioRenderer->Write(buffer, bytesToWrite);
1439     EXPECT_EQ(ERR_INVALID_PARAM, bytesWritten);
1440 
1441     free(buffer);
1442     fclose(wavFile);
1443 }
1444 
1445 /**
1446 * @tc.name  : Test Write API via illegl state, RENDERER_PREPARED : Write without Start.
1447 * @tc.number: Audio_Renderer_Write_003
1448 * @tc.desc  : Test Write interface. Returns error code, if the renderer state is not RENDERER_RUNNING.
1449 */
1450 HWTEST(AudioRendererUnitTest, Audio_Renderer_Write_003, TestSize.Level1)
1451 {
1452     int32_t ret = -1;
1453     FILE *wavFile = fopen(AUDIORENDER_TEST_FILE_PATH.c_str(), "rb");
1454     ASSERT_NE(nullptr, wavFile);
1455 
1456     AudioRendererOptions rendererOptions;
1457 
1458     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
1459     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
1460     ASSERT_NE(nullptr, audioRenderer);
1461 
1462     size_t bufferLen;
1463     ret = audioRenderer->GetBufferSize(bufferLen);
1464     EXPECT_EQ(SUCCESS, ret);
1465 
1466     uint8_t *buffer = (uint8_t *) malloc(bufferLen);
1467     ASSERT_NE(nullptr, buffer);
1468 
1469     size_t bytesToWrite = fread(buffer, 1, bufferLen, wavFile);
1470     int32_t bytesWritten = audioRenderer->Write(buffer, bytesToWrite);
1471     EXPECT_EQ(ERR_ILLEGAL_STATE, bytesWritten);
1472 
1473     audioRenderer->Release();
1474 
1475     free(buffer);
1476     fclose(wavFile);
1477 }
1478 
1479 /**
1480 * @tc.name  : Test Write API via illegal input, bufferLength = 0.
1481 * @tc.number: Audio_Renderer_Write_004
1482 * @tc.desc  : Test Write interface. Returns error code, if the bufferLength <= 0.
1483 */
1484 HWTEST(AudioRendererUnitTest, Audio_Renderer_Write_004, TestSize.Level1)
1485 {
1486     FILE *wavFile = fopen(AUDIORENDER_TEST_FILE_PATH.c_str(), "rb");
1487     ASSERT_NE(nullptr, wavFile);
1488 
1489     AudioRendererOptions rendererOptions;
1490 
1491     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
1492     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
1493     ASSERT_NE(nullptr, audioRenderer);
1494 
1495     bool isStarted = audioRenderer->Start();
1496     EXPECT_EQ(true, isStarted);
1497 
1498     size_t bufferLen = 0;
1499 
1500     uint8_t *buffer = (uint8_t *) malloc(bufferLen);
1501     ASSERT_NE(nullptr, buffer);
1502 
1503     size_t bytesToWrite = fread(buffer, 1, bufferLen, wavFile);
1504     int32_t bytesWritten = audioRenderer->Write(buffer, bytesToWrite);
1505     EXPECT_EQ(ERR_INVALID_PARAM, bytesWritten);
1506 
1507     audioRenderer->Stop();
1508     audioRenderer->Release();
1509 
1510     free(buffer);
1511     fclose(wavFile);
1512 }
1513 
1514 /**
1515 * @tc.name  : Test Write API via illegal input, buffer = nullptr.
1516 * @tc.number: Audio_Renderer_Write_005
1517 * @tc.desc  : Test Write interface. Returns error code, if the buffer = nullptr.
1518 */
1519 HWTEST(AudioRendererUnitTest, Audio_Renderer_Write_005, TestSize.Level1)
1520 {
1521     int32_t ret = -1;
1522     FILE *wavFile = fopen(AUDIORENDER_TEST_FILE_PATH.c_str(), "rb");
1523     ASSERT_NE(nullptr, wavFile);
1524 
1525     AudioRendererOptions rendererOptions;
1526 
1527     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
1528     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
1529     ASSERT_NE(nullptr, audioRenderer);
1530 
1531     bool isStarted = audioRenderer->Start();
1532     EXPECT_EQ(true, isStarted);
1533 
1534     size_t bufferLen;
1535     ret = audioRenderer->GetBufferSize(bufferLen);
1536     EXPECT_EQ(SUCCESS, ret);
1537 
1538     uint8_t *buffer = (uint8_t *) malloc(bufferLen);
1539     ASSERT_NE(nullptr, buffer);
1540 
1541     size_t bytesToWrite = fread(buffer, 1, bufferLen, wavFile);
1542     uint8_t *buffer_null = nullptr;
1543     int32_t bytesWritten = audioRenderer->Write(buffer_null, bytesToWrite);
1544     EXPECT_EQ(ERR_INVALID_PARAM, bytesWritten);
1545 
1546     audioRenderer->Stop();
1547     audioRenderer->Release();
1548 
1549     free(buffer);
1550     fclose(wavFile);
1551 }
1552 
1553 /**
1554 * @tc.name  : Test Write API via illegal state, RENDERER_STOPPED: Write after Stop
1555 * @tc.number: Audio_Renderer_Write_006
1556 * @tc.desc  : Test Write interface. Returns error code, if the renderer state is not RENDERER_RUNNING
1557 */
1558 HWTEST(AudioRendererUnitTest, Audio_Renderer_Write_006, TestSize.Level1)
1559 {
1560     int32_t ret = -1;
1561     FILE *wavFile = fopen(AUDIORENDER_TEST_FILE_PATH.c_str(), "rb");
1562     ASSERT_NE(nullptr, wavFile);
1563 
1564     AudioRendererOptions rendererOptions;
1565 
1566     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
1567     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
1568     ASSERT_NE(nullptr, audioRenderer);
1569 
1570     bool isStarted = audioRenderer->Start();
1571     EXPECT_EQ(true, isStarted);
1572 
1573     size_t bufferLen;
1574     ret = audioRenderer->GetBufferSize(bufferLen);
1575     EXPECT_EQ(SUCCESS, ret);
1576 
1577     uint8_t *buffer = (uint8_t *) malloc(bufferLen);
1578     ASSERT_NE(nullptr, buffer);
1579 
1580     bool isStopped = audioRenderer->Stop();
1581     EXPECT_EQ(true, isStopped);
1582 
1583     size_t bytesToWrite = fread(buffer, 1, bufferLen, wavFile);
1584     int32_t bytesWritten = audioRenderer->Write(buffer, bytesToWrite);
1585     EXPECT_EQ(ERR_ILLEGAL_STATE, bytesWritten);
1586 
1587     audioRenderer->Release();
1588 
1589     free(buffer);
1590     fclose(wavFile);
1591 }
1592 
1593 /**
1594 * @tc.name  : Test Write API via illegal state, RENDERER_RELEASED: Write after Release
1595 * @tc.number: Audio_Renderer_Write_007
1596 * @tc.desc  : Test Write interface. Returns error code, if the renderer state is not RENDERER_RUNNING
1597 */
1598 HWTEST(AudioRendererUnitTest, Audio_Renderer_Write_007, TestSize.Level1)
1599 {
1600     int32_t ret = -1;
1601     FILE *wavFile = fopen(AUDIORENDER_TEST_FILE_PATH.c_str(), "rb");
1602     ASSERT_NE(nullptr, wavFile);
1603 
1604     AudioRendererOptions rendererOptions;
1605 
1606     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
1607     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
1608     ASSERT_NE(nullptr, audioRenderer);
1609 
1610     bool isStarted = audioRenderer->Start();
1611     EXPECT_EQ(true, isStarted);
1612 
1613     size_t bufferLen;
1614     ret = audioRenderer->GetBufferSize(bufferLen);
1615     EXPECT_EQ(SUCCESS, ret);
1616 
1617     uint8_t *buffer = (uint8_t *) malloc(bufferLen);
1618     ASSERT_NE(nullptr, buffer);
1619 
1620     bool isReleased = audioRenderer->Release();
1621     EXPECT_EQ(true, isReleased);
1622 
1623     size_t bytesToWrite = fread(buffer, 1, bufferLen, wavFile);
1624     int32_t bytesWritten = audioRenderer->Write(buffer, bytesToWrite);
1625     EXPECT_EQ(ERR_ILLEGAL_STATE, bytesWritten);
1626 
1627     free(buffer);
1628     fclose(wavFile);
1629 }
1630 
1631 /**
1632 * @tc.name  : Test Write API.
1633 * @tc.number: Audio_Renderer_Write_008
1634 * @tc.desc  : Test Write interface after pause and resume. Returns number of bytes written, if the write is successful.
1635 */
1636 
1637 HWTEST(AudioRendererUnitTest, Audio_Renderer_Write_008, TestSize.Level1)
1638 {
1639     FILE *wavFile = fopen(AUDIORENDER_TEST_FILE_PATH.c_str(), "rb");
1640     ASSERT_NE(nullptr, wavFile);
1641 
1642     AudioRendererOptions rendererOptions;
1643 
1644     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
1645     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
1646     ASSERT_NE(nullptr, audioRenderer);
1647 
1648     bool isStarted = audioRenderer->Start();
1649     EXPECT_EQ(true, isStarted);
1650 
1651     size_t bufferLen;
1652     int32_t ret = audioRenderer->GetBufferSize(bufferLen);
1653     EXPECT_EQ(SUCCESS, ret);
1654 
1655     uint8_t *buffer = (uint8_t *) malloc(bufferLen);
1656     ASSERT_NE(nullptr, buffer);
1657 
1658     size_t bytesToWrite = 0;
1659     int32_t bytesWritten = 0;
1660     size_t minBytes = 4;
1661     int32_t numBuffersToRender = WRITE_BUFFERS_COUNT;
1662     bool pauseTested = false;
1663 
1664     while (numBuffersToRender) {
1665         bytesToWrite = fread(buffer, 1, bufferLen, wavFile);
1666         bytesWritten = 0;
1667         uint64_t currFilePos = ftell(wavFile);
1668         if (!pauseTested && (currFilePos > PAUSE_BUFFER_POSITION) && audioRenderer->Pause()) {
1669             pauseTested = true;
1670             sleep(PAUSE_RENDER_TIME_SECONDS);
1671             isStarted = audioRenderer->Start();
1672             EXPECT_EQ(true, isStarted);
1673 
1674             ret = audioRenderer->SetVolume(0.5);
1675             EXPECT_EQ(SUCCESS, ret);
1676             float volume = audioRenderer->GetVolume();
1677             EXPECT_EQ(0.5, volume);
1678         }
1679 
1680         while ((static_cast<size_t>(bytesWritten) < bytesToWrite) &&
1681             ((static_cast<size_t>(bytesToWrite) - bytesWritten) > minBytes)) {
1682             bytesWritten += audioRenderer->Write(buffer + static_cast<size_t>(bytesWritten),
1683                                                  bytesToWrite - static_cast<size_t>(bytesWritten));
1684             EXPECT_GE(bytesWritten, VALUE_ZERO);
1685             if (bytesWritten < 0) {
1686                 break;
1687             }
1688         }
1689         numBuffersToRender--;
1690     }
1691 
1692     audioRenderer->Drain();
1693     audioRenderer->Stop();
1694     audioRenderer->Release();
1695 
1696     free(buffer);
1697     fclose(wavFile);
1698 }
1699 
1700 /**
1701 * @tc.name  : Test Write API via illegl render mode, RENDER_MODE_CALLBACK.
1702 * @tc.number: Audio_Renderer_Write_009
1703 * @tc.desc  : Test Write interface. Returns error code, if the render mode is RENDER_MODE_CALLBACK.
1704 *           : In RENDER_MODE_CALLBACK Write API call not supported. By default render mode is RENDER_MODE_NORMAL.
1705 */
1706 HWTEST(AudioRendererUnitTest, Audio_Renderer_Write_009, TestSize.Level1)
1707 {
1708     int32_t ret = -1;
1709     FILE *wavFile = fopen(AUDIORENDER_TEST_FILE_PATH.c_str(), "rb");
1710     ASSERT_NE(nullptr, wavFile);
1711 
1712     AudioRendererOptions rendererOptions;
1713 
1714     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
1715     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
1716     ASSERT_NE(nullptr, audioRenderer);
1717 
1718     ret = audioRenderer->SetRenderMode(RENDER_MODE_CALLBACK);
1719     EXPECT_EQ(SUCCESS, ret);
1720 
1721     size_t bufferLen;
1722     ret = audioRenderer->GetBufferSize(bufferLen);
1723     EXPECT_EQ(SUCCESS, ret);
1724 
1725     uint8_t *buffer = (uint8_t *) malloc(bufferLen);
1726     ASSERT_NE(nullptr, buffer);
1727 
1728     bool isStarted = audioRenderer->Start();
1729     EXPECT_EQ(true, isStarted);
1730 
1731     size_t bytesToWrite = fread(buffer, 1, bufferLen, wavFile);
1732     int32_t bytesWritten = audioRenderer->Write(buffer, bytesToWrite);
1733     EXPECT_EQ(ERR_INCORRECT_MODE, bytesWritten);
1734 
1735     audioRenderer->Release();
1736 
1737     free(buffer);
1738     fclose(wavFile);
1739 }
1740 
1741 /**
1742 * @tc.name  : Test GetAudioTime API via legal input.
1743 * @tc.number: Audio_Renderer_GetAudioTime_001
1744 * @tc.desc  : Test GetAudioTime interface. Returns true, if the getting is successful.
1745 */
1746 HWTEST(AudioRendererUnitTest, Audio_Renderer_GetAudioTime_001, TestSize.Level1)
1747 {
1748     int32_t ret = -1;
1749     FILE *wavFile = fopen(AUDIORENDER_TEST_FILE_PATH.c_str(), "rb");
1750     ASSERT_NE(nullptr, wavFile);
1751 
1752     AudioRendererOptions rendererOptions;
1753 
1754     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
1755     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
1756     ASSERT_NE(nullptr, audioRenderer);
1757 
1758     bool isStarted = audioRenderer->Start();
1759     EXPECT_EQ(true, isStarted);
1760 
1761     size_t bufferLen;
1762     ret = audioRenderer->GetBufferSize(bufferLen);
1763     EXPECT_EQ(SUCCESS, ret);
1764 
1765     uint8_t *buffer = (uint8_t *) malloc(bufferLen);
1766     ASSERT_NE(nullptr, buffer);
1767 
1768     size_t bytesToWrite = fread(buffer, 1, bufferLen, wavFile);
1769     int32_t bytesWritten = audioRenderer->Write(buffer, bytesToWrite);
1770     EXPECT_GE(bytesWritten, VALUE_ZERO);
1771 
1772     Timestamp timeStamp;
1773     bool getAudioTime = audioRenderer->GetAudioTime(timeStamp, Timestamp::Timestampbase::MONOTONIC);
1774     EXPECT_EQ(true, getAudioTime);
1775     EXPECT_GE(timeStamp.time.tv_sec, (const long)VALUE_ZERO);
1776     EXPECT_GE(timeStamp.time.tv_nsec, (const long)VALUE_ZERO);
1777 
1778     audioRenderer->Drain();
1779     audioRenderer->Stop();
1780     audioRenderer->Release();
1781 
1782     free(buffer);
1783     fclose(wavFile);
1784 }
1785 
1786 /**
1787 * @tc.name  : Test GetAudioTime API via illegal state, RENDERER_NEW: GetAudioTime without initializing the renderer.
1788 * @tc.number: Audio_Renderer_GetAudioTime_002
1789 * @tc.desc  : Test GetAudioTime interface. Returns false, if the renderer state is RENDERER_NEW
1790 */
1791 HWTEST(AudioRendererUnitTest, Audio_Renderer_GetAudioTime_002, TestSize.Level1)
1792 {
1793     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(STREAM_MUSIC);
1794     ASSERT_NE(nullptr, audioRenderer);
1795 
1796     Timestamp timeStamp;
1797     bool getAudioTime = audioRenderer->GetAudioTime(timeStamp, Timestamp::Timestampbase::MONOTONIC);
1798     EXPECT_EQ(false, getAudioTime);
1799 }
1800 
1801 /**
1802 * @tc.name  : Test GetAudioTime API via legal state, RENDERER_RUNNING.
1803 * @tc.number: Audio_Renderer_GetAudioTime_003
1804 * @tc.desc  : test GetAudioTime interface. Returns true, if the getting is successful.
1805 */
1806 HWTEST(AudioRendererUnitTest, Audio_Renderer_GetAudioTime_003, TestSize.Level1)
1807 {
1808     AudioRendererOptions rendererOptions;
1809 
1810     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
1811     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
1812     ASSERT_NE(nullptr, audioRenderer);
1813 
1814     bool isStarted = audioRenderer->Start();
1815     EXPECT_EQ(true, isStarted);
1816 
1817     Timestamp timeStamp;
1818     bool getAudioTime = audioRenderer->GetAudioTime(timeStamp, Timestamp::Timestampbase::MONOTONIC);
1819     EXPECT_EQ(true, getAudioTime);
1820 
1821     audioRenderer->Release();
1822 }
1823 
1824 /**
1825 * @tc.name  : Test GetAudioTime API via legal state, RENDERER_STOPPED.
1826 * @tc.number: Audio_Renderer_GetAudioTime_004
1827 * @tc.desc  : Test GetAudioTime interface. Returns true, if the getting is successful.
1828 */
1829 HWTEST(AudioRendererUnitTest, Audio_Renderer_GetAudioTime_004, TestSize.Level1)
1830 {
1831     AudioRendererOptions rendererOptions;
1832 
1833     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
1834     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
1835     ASSERT_NE(nullptr, audioRenderer);
1836 
1837     bool isStarted = audioRenderer->Start();
1838     EXPECT_EQ(true, isStarted);
1839 
1840     bool isStopped = audioRenderer->Stop();
1841     EXPECT_EQ(true, isStopped);
1842 
1843     Timestamp timeStamp;
1844     bool getAudioTime = audioRenderer->GetAudioTime(timeStamp, Timestamp::Timestampbase::MONOTONIC);
1845     EXPECT_EQ(true, getAudioTime);
1846 
1847     audioRenderer->Release();
1848 }
1849 
1850 /**
1851 * @tc.name  : Test GetAudioTime API via illegal state, RENDERER_RELEASED: GetAudioTime after Release.
1852 * @tc.number: Audio_Renderer_GetAudioTime_005
1853 * @tc.desc  : Test GetAudioTime interface. Returns false, if the renderer state is RENDERER_RELEASED
1854 */
1855 HWTEST(AudioRendererUnitTest, Audio_Renderer_GetAudioTime_005, TestSize.Level1)
1856 {
1857     AudioRendererOptions rendererOptions;
1858 
1859     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
1860     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
1861     ASSERT_NE(nullptr, audioRenderer);
1862 
1863     bool isStarted = audioRenderer->Start();
1864     EXPECT_EQ(true, isStarted);
1865 
1866     bool isStopped = audioRenderer->Stop();
1867     EXPECT_EQ(true, isStopped);
1868 
1869     bool isReleased = audioRenderer->Release();
1870     EXPECT_EQ(true, isReleased);
1871 
1872     Timestamp timeStamp;
1873     bool getAudioTime = audioRenderer->GetAudioTime(timeStamp, Timestamp::Timestampbase::MONOTONIC);
1874     EXPECT_EQ(false, getAudioTime);
1875 }
1876 
1877 /**
1878 * @tc.name  : Test GetAudioTime API via legal state, RENDERER_PAUSED.
1879 * @tc.number: Audio_Renderer_GetAudioTime_006
1880 * @tc.desc  : Test GetAudioTime interface. Returns true, if the getting is successful.
1881 */
1882 HWTEST(AudioRendererUnitTest, Audio_Renderer_GetAudioTime_006, TestSize.Level1)
1883 {
1884     AudioRendererOptions rendererOptions;
1885 
1886     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
1887     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
1888     ASSERT_NE(nullptr, audioRenderer);
1889 
1890     bool isStarted = audioRenderer->Start();
1891     EXPECT_EQ(true, isStarted);
1892 
1893     bool isPaused = audioRenderer->Pause();
1894     EXPECT_EQ(true, isPaused);
1895 
1896     Timestamp timeStamp;
1897     bool getAudioTime = audioRenderer->GetAudioTime(timeStamp, Timestamp::Timestampbase::MONOTONIC);
1898     EXPECT_EQ(true, getAudioTime);
1899 
1900     audioRenderer->Release();
1901 }
1902 
1903 /**
1904 * @tc.name  : Test GetAudioTime API stability.
1905 * @tc.number: Audio_Renderer_GetAudioTime_Stability_001
1906 * @tc.desc  : Test GetAudioTime interface stability.
1907 */
1908 HWTEST(AudioRendererUnitTest, Audio_Renderer_GetAudioTime_Stability_001, TestSize.Level1)
1909 {
1910     AudioRendererOptions rendererOptions;
1911 
1912     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
1913     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
1914     ASSERT_NE(nullptr, audioRenderer);
1915 
1916     bool isStarted = audioRenderer->Start();
1917     EXPECT_EQ(true, isStarted);
1918 
1919     thread renderThread(StartRenderThread, audioRenderer.get());
1920 
1921     for (int i = 0; i < VALUE_THOUSAND; i++) {
1922         Timestamp timeStamp;
1923         bool getAudioTime = audioRenderer->GetAudioTime(timeStamp, Timestamp::Timestampbase::MONOTONIC);
1924         EXPECT_EQ(true, getAudioTime);
1925     }
1926 
1927     renderThread.join();
1928 
1929     bool isStopped = audioRenderer->Stop();
1930     EXPECT_EQ(true, isStopped);
1931 
1932     bool isReleased = audioRenderer->Release();
1933     EXPECT_EQ(true, isReleased);
1934 }
1935 
1936 /**
1937 * @tc.name  : Test Drain API.
1938 * @tc.number: Audio_Renderer_Drain_001
1939 * @tc.desc  : Test Drain interface. Returns true, if the flush is successful.
1940 */
1941 HWTEST(AudioRendererUnitTest, Audio_Renderer_Drain_001, TestSize.Level1)
1942 {
1943     int32_t ret = -1;
1944     FILE *wavFile = fopen(AUDIORENDER_TEST_FILE_PATH.c_str(), "rb");
1945     ASSERT_NE(nullptr, wavFile);
1946 
1947     AudioRendererOptions rendererOptions;
1948 
1949     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
1950     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
1951     ASSERT_NE(nullptr, audioRenderer);
1952 
1953     bool isStarted = audioRenderer->Start();
1954     EXPECT_EQ(true, isStarted);
1955 
1956     size_t bufferLen;
1957     ret = audioRenderer->GetBufferSize(bufferLen);
1958     EXPECT_EQ(SUCCESS, ret);
1959 
1960     uint8_t *buffer = (uint8_t *) malloc(bufferLen);
1961     ASSERT_NE(nullptr, buffer);
1962 
1963     size_t bytesToWrite = fread(buffer, 1, bufferLen, wavFile);
1964     int32_t bytesWritten = audioRenderer->Write(buffer, bytesToWrite);
1965     EXPECT_GE(bytesWritten, VALUE_ZERO);
1966 
1967     bool isDrained = audioRenderer->Drain();
1968     EXPECT_EQ(true, isDrained);
1969 
1970     audioRenderer->Stop();
1971     audioRenderer->Release();
1972 
1973     free(buffer);
1974     fclose(wavFile);
1975 }
1976 
1977 /**
1978 * @tc.name  : Test Drain API via illegal state, RENDERER_NEW: Without initializing the renderer.
1979 * @tc.number: Audio_Renderer_Drain_002
1980 * @tc.desc  : Test Drain interface. Returns false, if the renderer state is not RENDERER_RUNNING.
1981 */
1982 HWTEST(AudioRendererUnitTest, Audio_Renderer_Drain_002, TestSize.Level1)
1983 {
1984     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(STREAM_MUSIC);
1985     ASSERT_NE(nullptr, audioRenderer);
1986 
1987     bool isDrained = audioRenderer->Drain();
1988     EXPECT_EQ(false, isDrained);
1989 
1990     audioRenderer->Release();
1991 }
1992 
1993 /**
1994 * @tc.name  : Test Drain API via illegal state, RENDERER_PREPARED: Without Start.
1995 * @tc.number: Audio_Renderer_Drain_003
1996 * @tc.desc  : Test Drain interface. Returns false, if the renderer state is not RENDERER_RUNNING.
1997 */
1998 HWTEST(AudioRendererUnitTest, Audio_Renderer_Drain_003, TestSize.Level1)
1999 {
2000     AudioRendererOptions rendererOptions;
2001 
2002     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
2003     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
2004     ASSERT_NE(nullptr, audioRenderer);
2005 
2006     bool isDrained = audioRenderer->Drain();
2007     EXPECT_EQ(false, isDrained);
2008 
2009     audioRenderer->Release();
2010 }
2011 
2012 /**
2013 * @tc.name  : Test Drain API via illegal state, RENDERER_STOPPED: call Stop before Drain.
2014 * @tc.number: Audio_Renderer_Drain_004
2015 * @tc.desc  : Test Drain interface. Returns false, if the renderer state is not RENDERER_RUNNING.
2016 */
2017 HWTEST(AudioRendererUnitTest, Audio_Renderer_Drain_004, TestSize.Level1)
2018 {
2019     AudioRendererOptions rendererOptions;
2020 
2021     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
2022     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
2023     ASSERT_NE(nullptr, audioRenderer);
2024 
2025     bool isStarted = audioRenderer->Start();
2026     EXPECT_EQ(true, isStarted);
2027 
2028     bool isStopped = audioRenderer->Stop();
2029     EXPECT_EQ(true, isStopped);
2030 
2031     bool isDrained = audioRenderer->Drain();
2032     EXPECT_EQ(false, isDrained);
2033 
2034     audioRenderer->Release();
2035 }
2036 
2037 /**
2038 * @tc.name  : Test Drain API via illegal state, RENDERER_RELEASED: call Release before Drain.
2039 * @tc.number: Audio_Renderer_Drain_005
2040 * @tc.desc  : Test Drain interface. Returns false, if the renderer state is not RENDERER_RUNNING.
2041 */
2042 HWTEST(AudioRendererUnitTest, Audio_Renderer_Drain_005, TestSize.Level1)
2043 {
2044     AudioRendererOptions rendererOptions;
2045 
2046     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
2047     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
2048     ASSERT_NE(nullptr, audioRenderer);
2049 
2050     bool isStarted = audioRenderer->Start();
2051     EXPECT_EQ(true, isStarted);
2052 
2053     bool isReleased = audioRenderer->Release();
2054     EXPECT_EQ(true, isReleased);
2055 
2056     bool isDrained = audioRenderer->Drain();
2057     EXPECT_EQ(false, isDrained);
2058 
2059     audioRenderer->Release();
2060 }
2061 
2062 /**
2063 * @tc.name  : Test Drain API via illegal state, RENDERER_PAUSED: call Pause before Drain.
2064 * @tc.number: Audio_Renderer_Drain_006
2065 * @tc.desc  : Test Drain interface. Returns false, if the renderer state is not RENDERER_RUNNING.
2066 */
2067 HWTEST(AudioRendererUnitTest, Audio_Renderer_Drain_006, TestSize.Level1)
2068 {
2069     AudioRendererOptions rendererOptions;
2070 
2071     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
2072     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
2073     ASSERT_NE(nullptr, audioRenderer);
2074 
2075     bool isStarted = audioRenderer->Start();
2076     EXPECT_EQ(true, isStarted);
2077 
2078     bool isPaused = audioRenderer->Pause();
2079     EXPECT_EQ(true, isPaused);
2080 
2081     bool isDrained = audioRenderer->Drain();
2082     EXPECT_EQ(false, isDrained);
2083 
2084     audioRenderer->Release();
2085 }
2086 
2087 /**
2088 * @tc.name  : Test Drain API stability.
2089 * @tc.number: Audio_Renderer_Drain_Stability_001
2090 * @tc.desc  : Test Drain interface stability.
2091 */
2092 HWTEST(AudioRendererUnitTest, Audio_Renderer_Drain_Stability_001, TestSize.Level1)
2093 {
2094     AudioRendererOptions rendererOptions;
2095 
2096     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
2097     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
2098     ASSERT_NE(nullptr, audioRenderer);
2099 
2100     bool isStarted = audioRenderer->Start();
2101     EXPECT_EQ(true, isStarted);
2102 
2103     thread renderThread(StartRenderThread, audioRenderer.get());
2104 
2105     for (int i = 0; i < VALUE_THOUSAND; i++) {
2106         bool isDrained = audioRenderer->Drain();
2107         EXPECT_EQ(true, isDrained);
2108     }
2109 
2110     renderThread.join();
2111 
2112     bool isStopped = audioRenderer->Stop();
2113     EXPECT_EQ(true, isStopped);
2114 
2115     bool isReleased = audioRenderer->Release();
2116     EXPECT_EQ(true, isReleased);
2117 }
2118 
2119 /**
2120 * @tc.name  : Test Flush API.
2121 * @tc.number: Audio_Renderer_Flush_001
2122 * @tc.desc  : Test Flush interface. Returns true, if the flush is successful.
2123 */
2124 HWTEST(AudioRendererUnitTest, Audio_Renderer_Flush_001, TestSize.Level1)
2125 {
2126     int32_t ret = -1;
2127     FILE *wavFile = fopen(AUDIORENDER_TEST_FILE_PATH.c_str(), "rb");
2128     ASSERT_NE(nullptr, wavFile);
2129 
2130     AudioRendererOptions rendererOptions;
2131 
2132     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
2133     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
2134     ASSERT_NE(nullptr, audioRenderer);
2135 
2136     bool isStarted = audioRenderer->Start();
2137     EXPECT_EQ(true, isStarted);
2138 
2139     size_t bufferLen;
2140     ret = audioRenderer->GetBufferSize(bufferLen);
2141     EXPECT_EQ(SUCCESS, ret);
2142 
2143     uint8_t *buffer = (uint8_t *) malloc(bufferLen);
2144     ASSERT_NE(nullptr, buffer);
2145 
2146     size_t bytesToWrite = fread(buffer, 1, bufferLen, wavFile);
2147     int32_t bytesWritten = audioRenderer->Write(buffer, bytesToWrite);
2148     EXPECT_GE(bytesWritten, VALUE_ZERO);
2149 
2150     bool isFlushed = audioRenderer->Flush();
2151     EXPECT_EQ(true, isFlushed);
2152 
2153     audioRenderer->Release();
2154 
2155     free(buffer);
2156     fclose(wavFile);
2157 }
2158 
2159 /**
2160 * @tc.name  : Test Flush API.
2161 * @tc.number: Audio_Renderer_Flush_002
2162 * @tc.desc  : Test Flush interface after Pause call. Returns true, if the flush is successful.
2163 */
2164 HWTEST(AudioRendererUnitTest, Audio_Renderer_Flush_002, TestSize.Level1)
2165 {
2166     int32_t ret = -1;
2167     FILE *wavFile = fopen(AUDIORENDER_TEST_FILE_PATH.c_str(), "rb");
2168     ASSERT_NE(nullptr, wavFile);
2169 
2170     AudioRendererOptions rendererOptions;
2171 
2172     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
2173     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
2174     ASSERT_NE(nullptr, audioRenderer);
2175 
2176     bool isStarted = audioRenderer->Start();
2177     EXPECT_EQ(true, isStarted);
2178 
2179     size_t bufferLen;
2180     ret = audioRenderer->GetBufferSize(bufferLen);
2181     EXPECT_EQ(SUCCESS, ret);
2182 
2183     uint8_t *buffer = (uint8_t *) malloc(bufferLen);
2184     ASSERT_NE(nullptr, buffer);
2185 
2186     size_t bytesToWrite = fread(buffer, 1, bufferLen, wavFile);
2187     int32_t bytesWritten = audioRenderer->Write(buffer, bytesToWrite);
2188     EXPECT_GE(bytesWritten, VALUE_ZERO);
2189 
2190     audioRenderer->Pause();
2191 
2192     bool isFlushed = audioRenderer->Flush();
2193     EXPECT_EQ(true, isFlushed);
2194 
2195     audioRenderer->Release();
2196 
2197     free(buffer);
2198     fclose(wavFile);
2199 }
2200 
2201 /**
2202 * @tc.name  : Test Flush API via illegal state, RENDERER_NEW: Without initializing the renderer.
2203 * @tc.number: Audio_Renderer_Flush_003
2204 * @tc.desc  : Test Flush interface. Returns false, if the renderer state is not RENDERER_RUNNING or RENDERER_PAUSED.
2205 */
2206 HWTEST(AudioRendererUnitTest, Audio_Renderer_Flush_003, TestSize.Level1)
2207 {
2208     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(STREAM_MUSIC);
2209     ASSERT_NE(nullptr, audioRenderer);
2210 
2211     bool isFlushed = audioRenderer->Flush();
2212     EXPECT_EQ(false, isFlushed);
2213 }
2214 
2215 /**
2216 * @tc.name  : Test Flush API via illegal state, RENDERER_PREPARED: Without Start.
2217 * @tc.number: Audio_Renderer_Flush_004
2218 * @tc.desc  : Test Flush interface. Returns false, if the renderer state is not RENDERER_RUNNING or RENDERER_PAUSED.
2219 */
2220 HWTEST(AudioRendererUnitTest, Audio_Renderer_Flush_004, TestSize.Level1)
2221 {
2222     AudioRendererOptions rendererOptions;
2223 
2224     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
2225     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
2226     ASSERT_NE(nullptr, audioRenderer);
2227 
2228     bool isFlushed = audioRenderer->Flush();
2229     EXPECT_EQ(false, isFlushed);
2230 
2231     audioRenderer->Release();
2232 }
2233 
2234 /**
2235 * @tc.name  : Test Flush API: call Stop before Flush.
2236 * @tc.number: Audio_Renderer_Flush_005
2237 * @tc.desc  : Test Flush interface. Returns true, if the renderer state is RENDERER_STOPPED.
2238 */
2239 HWTEST(AudioRendererUnitTest, Audio_Renderer_Flush_005, TestSize.Level1)
2240 {
2241     AudioRendererOptions rendererOptions;
2242 
2243     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
2244     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
2245     ASSERT_NE(nullptr, audioRenderer);
2246 
2247     bool isStarted = audioRenderer->Start();
2248     EXPECT_EQ(true, isStarted);
2249 
2250     bool isStopped = audioRenderer->Stop();
2251     EXPECT_EQ(true, isStopped);
2252 
2253     bool isFlushed = audioRenderer->Flush();
2254     EXPECT_EQ(true, isFlushed);
2255 
2256     audioRenderer->Release();
2257 }
2258 
2259 /**
2260 * @tc.name  : Test Flush API via illegal state, RENDERER_RELEASED: call Release before Flush.
2261 * @tc.number: Audio_Renderer_Flush_006
2262 * @tc.desc  : Test Flush interface. Returns false, if the renderer state is not RENDERER_RUNNING.
2263 */
2264 HWTEST(AudioRendererUnitTest, Audio_Renderer_Flush_006, TestSize.Level1)
2265 {
2266     AudioRendererOptions rendererOptions;
2267 
2268     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
2269     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
2270     ASSERT_NE(nullptr, audioRenderer);
2271 
2272     bool isStarted = audioRenderer->Start();
2273     EXPECT_EQ(true, isStarted);
2274 
2275     bool isReleased = audioRenderer->Release();
2276     EXPECT_EQ(true, isReleased);
2277 
2278     bool isFlushed = audioRenderer->Flush();
2279     EXPECT_EQ(false, isFlushed);
2280 }
2281 
2282 /**
2283 * @tc.name  : Test Flush API stability.
2284 * @tc.number: Audio_Renderer_Flush_Stability_001
2285 * @tc.desc  : Test Flush interface stability.
2286 */
2287 HWTEST(AudioRendererUnitTest, Audio_Renderer_Flush_Stability_001, TestSize.Level1)
2288 {
2289     AudioRendererOptions rendererOptions;
2290 
2291     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
2292     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
2293     ASSERT_NE(nullptr, audioRenderer);
2294 
2295     bool isStarted = audioRenderer->Start();
2296     EXPECT_EQ(true, isStarted);
2297 
2298     thread renderThread(StartRenderThread, audioRenderer.get());
2299 
2300     for (int i = 0; i < VALUE_THOUSAND; i++) {
2301         bool isFlushed = audioRenderer->Flush();
2302         EXPECT_EQ(true, isFlushed);
2303     }
2304 
2305     renderThread.join();
2306 
2307     bool isStopped = audioRenderer->Stop();
2308     EXPECT_EQ(true, isStopped);
2309 
2310     bool isReleased = audioRenderer->Release();
2311     EXPECT_EQ(true, isReleased);
2312 }
2313 
2314 /**
2315 * @tc.name  : Test Pause API.
2316 * @tc.number: Audio_Renderer_Pause_001
2317 * @tc.desc  : Test Pause interface. Returns true, if the pause is successful.
2318 */
2319 HWTEST(AudioRendererUnitTest, Audio_Renderer_Pause_001, TestSize.Level1)
2320 {
2321     int32_t ret = -1;
2322     FILE *wavFile = fopen(AUDIORENDER_TEST_FILE_PATH.c_str(), "rb");
2323     ASSERT_NE(nullptr, wavFile);
2324 
2325     AudioRendererOptions rendererOptions;
2326 
2327     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
2328     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
2329     ASSERT_NE(nullptr, audioRenderer);
2330 
2331     bool isStarted = audioRenderer->Start();
2332     EXPECT_EQ(true, isStarted);
2333 
2334     size_t bufferLen;
2335     ret = audioRenderer->GetBufferSize(bufferLen);
2336     EXPECT_EQ(SUCCESS, ret);
2337 
2338     uint8_t *buffer = (uint8_t *) malloc(bufferLen);
2339     ASSERT_NE(nullptr, buffer);
2340 
2341     size_t bytesToWrite = fread(buffer, 1, bufferLen, wavFile);
2342     int32_t bytesWritten = audioRenderer->Write(buffer, bytesToWrite);
2343     EXPECT_GE(bytesWritten, VALUE_ZERO);
2344 
2345     audioRenderer->Drain();
2346 
2347     bool isPaused = audioRenderer->Pause();
2348     EXPECT_EQ(true, isPaused);
2349 
2350     audioRenderer->Release();
2351 
2352     free(buffer);
2353     fclose(wavFile);
2354 }
2355 
2356 /**
2357 * @tc.name  : Test Pause API via illegal state, RENDERER_NEW: call Pause without Initializing the renderer.
2358 * @tc.number: Audio_Renderer_Pause_002
2359 * @tc.desc  : Test Pause interface. Returns false, if the renderer state is not RENDERER_RUNNING.
2360 */
2361 HWTEST(AudioRendererUnitTest, Audio_Renderer_Pause_002, TestSize.Level1)
2362 {
2363     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(STREAM_MUSIC);
2364     ASSERT_NE(nullptr, audioRenderer);
2365 
2366     bool isPaused = audioRenderer->Pause();
2367     EXPECT_EQ(false, isPaused);
2368 }
2369 
2370 /**
2371 * @tc.name  : Test Pause API via illegal state, RENDERER_PREPARED: call Pause without Start.
2372 * @tc.number: Audio_Renderer_Pause_003
2373 * @tc.desc  : Test Pause interface. Returns false, if the renderer state is not RENDERER_RUNNING.
2374 */
2375 HWTEST(AudioRendererUnitTest, Audio_Renderer_Pause_003, TestSize.Level1)
2376 {
2377     AudioRendererOptions rendererOptions;
2378 
2379     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
2380     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
2381     ASSERT_NE(nullptr, audioRenderer);
2382 
2383     bool isPaused = audioRenderer->Pause();
2384     EXPECT_EQ(false, isPaused);
2385 
2386     audioRenderer->Release();
2387 }
2388 
2389 /**
2390 * @tc.name  : Test Pause API via illegal state, RENDERER_RELEASED: call Pause after Release.
2391 * @tc.number: Audio_Renderer_Pause_004
2392 * @tc.desc  : Test Pause interface. Returns false, if the renderer state is not RENDERER_RUNNING.
2393 */
2394 HWTEST(AudioRendererUnitTest, Audio_Renderer_Pause_004, TestSize.Level1)
2395 {
2396     AudioRendererOptions rendererOptions;
2397 
2398     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
2399     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
2400     ASSERT_NE(nullptr, audioRenderer);
2401 
2402     bool isStarted = audioRenderer->Start();
2403     EXPECT_EQ(true, isStarted);
2404 
2405     bool isReleased = audioRenderer->Release();
2406     EXPECT_EQ(true, isReleased);
2407 
2408     bool isPaused = audioRenderer->Pause();
2409     EXPECT_EQ(false, isPaused);
2410 }
2411 
2412 /**
2413 * @tc.name  : Test Pause and resume
2414 * @tc.number: Audio_Renderer_Pause_005
2415 * @tc.desc  : Test Pause interface. Returns true , if the pause is successful.
2416 */
2417 HWTEST(AudioRendererUnitTest, Audio_Renderer_Pause_005, TestSize.Level1)
2418 {
2419     AudioRendererOptions rendererOptions;
2420 
2421     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
2422     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
2423     ASSERT_NE(nullptr, audioRenderer);
2424 
2425     bool isStarted = audioRenderer->Start();
2426     EXPECT_EQ(true, isStarted);
2427 
2428     bool isPaused = audioRenderer->Pause();
2429     EXPECT_EQ(true, isPaused);
2430 
2431     isStarted = audioRenderer->Start();
2432     EXPECT_EQ(true, isStarted);
2433 
2434     audioRenderer->Stop();
2435     audioRenderer->Release();
2436 }
2437 
2438 /**
2439 * @tc.name  : Test Pause API via illegal state, RENDERER_STOPPED: call Pause after Stop.
2440 * @tc.number: Audio_Renderer_Pause_006
2441 * @tc.desc  : Test Pause interface. Returns false, if the renderer state is not RENDERER_RUNNING.
2442 */
2443 HWTEST(AudioRendererUnitTest, Audio_Renderer_Pause_006, TestSize.Level1)
2444 {
2445     AudioRendererOptions rendererOptions;
2446 
2447     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
2448     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
2449     ASSERT_NE(nullptr, audioRenderer);
2450 
2451     bool isStarted = audioRenderer->Start();
2452     EXPECT_EQ(true, isStarted);
2453 
2454     bool isStopped = audioRenderer->Stop();
2455     EXPECT_EQ(true, isStopped);
2456 
2457     bool isPaused = audioRenderer->Pause();
2458     EXPECT_EQ(false, isPaused);
2459     audioRenderer->Release();
2460 }
2461 
2462 /**
2463 * @tc.name  : Test Pause and resume
2464 * @tc.number: Audio_Renderer_Pause_Stability_001
2465 * @tc.desc  : Test Pause interface for stability.
2466 */
2467 HWTEST(AudioRendererUnitTest, Audio_Renderer_Pause_Stability_001, TestSize.Level1)
2468 {
2469     int32_t ret = -1;
2470     AudioRendererOptions rendererOptions;
2471 
2472     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
2473     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
2474     ASSERT_NE(nullptr, audioRenderer);
2475 
2476     bool isStarted = audioRenderer->Start();
2477     EXPECT_EQ(true, isStarted);
2478 
2479     FILE *wavFile = fopen(AUDIORENDER_TEST_FILE_PATH.c_str(), "rb");
2480     ASSERT_NE(nullptr, wavFile);
2481 
2482     size_t bufferLen;
2483     ret = audioRenderer->GetBufferSize(bufferLen);
2484     EXPECT_EQ(SUCCESS, ret);
2485 
2486     uint8_t *buffer = (uint8_t *) malloc(bufferLen);
2487     ASSERT_NE(nullptr, buffer);
2488 
2489     size_t bytesToWrite = 0;
2490     int32_t bytesWritten = 0;
2491     size_t minBytes = 4;
2492     int32_t numBuffersToRender = WRITE_BUFFERS_COUNT;
2493 
2494     while (numBuffersToRender) {
2495         bytesToWrite = fread(buffer, 1, bufferLen, wavFile);
2496         bytesWritten = 0;
2497         while ((static_cast<size_t>(bytesWritten) < bytesToWrite) &&
2498             ((static_cast<size_t>(bytesToWrite) - bytesWritten) > minBytes)) {
2499             bytesWritten += audioRenderer->Write(buffer + static_cast<size_t>(bytesWritten),
2500                                                  bytesToWrite - static_cast<size_t>(bytesWritten));
2501             EXPECT_GE(bytesWritten, VALUE_ZERO);
2502             if (bytesWritten < 0) {
2503                 break;
2504             }
2505         }
2506         EXPECT_EQ(true, audioRenderer->Pause());
2507         EXPECT_EQ(true, audioRenderer->Start());
2508         numBuffersToRender--;
2509     }
2510 
2511     audioRenderer->Drain();
2512 
2513     free(buffer);
2514     fclose(wavFile);
2515 
2516     bool isStopped = audioRenderer->Stop();
2517     EXPECT_EQ(true, isStopped);
2518 
2519     bool isReleased = audioRenderer->Release();
2520     EXPECT_EQ(true, isReleased);
2521 }
2522 
2523 /**
2524 * @tc.name  : Test Stop API.
2525 * @tc.number: Audio_Renderer_Stop_001
2526 * @tc.desc  : Test Stop interface. Returns true, if the stop is successful.
2527 */
2528 HWTEST(AudioRendererUnitTest, Audio_Renderer_Stop_001, TestSize.Level1)
2529 {
2530     int32_t ret = -1;
2531     FILE *wavFile = fopen(AUDIORENDER_TEST_FILE_PATH.c_str(), "rb");
2532     ASSERT_NE(nullptr, wavFile);
2533 
2534     AudioRendererOptions rendererOptions;
2535 
2536     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
2537     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
2538     ASSERT_NE(nullptr, audioRenderer);
2539 
2540     bool isStarted = audioRenderer->Start();
2541     EXPECT_EQ(true, isStarted);
2542 
2543     size_t bufferLen;
2544     ret = audioRenderer->GetBufferSize(bufferLen);
2545     EXPECT_EQ(SUCCESS, ret);
2546 
2547     uint8_t *buffer = (uint8_t *) malloc(bufferLen);
2548     ASSERT_NE(nullptr, buffer);
2549 
2550     size_t bytesToWrite = fread(buffer, 1, bufferLen, wavFile);
2551     int32_t bytesWritten = audioRenderer->Write(buffer, bytesToWrite);
2552     EXPECT_GE(bytesWritten, VALUE_ZERO);
2553 
2554     audioRenderer->Drain();
2555 
2556     bool isStopped = audioRenderer->Stop();
2557     EXPECT_EQ(true, isStopped);
2558 
2559     audioRenderer->Release();
2560 
2561     free(buffer);
2562     fclose(wavFile);
2563 }
2564 
2565 /**
2566 * @tc.name  : Test Stop API via illegal state, RENDERER_NEW: call Stop without Initializing the renderer.
2567 * @tc.number: Audio_Renderer_Stop_002
2568 * @tc.desc  : Test Stop interface. Returns false, if the renderer state is not RENDERER_RUNNING.
2569 */
2570 HWTEST(AudioRendererUnitTest, Audio_Renderer_Stop_002, TestSize.Level1)
2571 {
2572     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(STREAM_MUSIC);
2573     ASSERT_NE(nullptr, audioRenderer);
2574 
2575     bool isStopped = audioRenderer->Stop();
2576     EXPECT_EQ(false, isStopped);
2577 }
2578 
2579 /**
2580 * @tc.name  : Test Stop API via illegal state, RENDERER_PREPARED: call Stop without Start.
2581 * @tc.number: Audio_Renderer_Stop_003
2582 * @tc.desc  : Test Stop interface. Returns false, if the renderer state is not RENDERER_RUNNING.
2583 */
2584 HWTEST(AudioRendererUnitTest, Audio_Renderer_Stop_003, TestSize.Level1)
2585 {
2586     AudioRendererOptions rendererOptions;
2587 
2588     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
2589     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
2590     ASSERT_NE(nullptr, audioRenderer);
2591 
2592     bool isStopped = audioRenderer->Stop();
2593     EXPECT_EQ(false, isStopped);
2594 
2595     audioRenderer->Release();
2596 }
2597 
2598 /**
2599 * @tc.name  : Test Stop API via illegal state, RENDERER_RELEASED: call Stop after Release.
2600 * @tc.number: Audio_Renderer_Stop_004
2601 * @tc.desc  : Test Stop interface. Returns false, if the renderer state is not RENDERER_RUNNING.
2602 */
2603 HWTEST(AudioRendererUnitTest, Audio_Renderer_Stop_004, TestSize.Level1)
2604 {
2605     AudioRendererOptions rendererOptions;
2606 
2607     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
2608     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
2609     ASSERT_NE(nullptr, audioRenderer);
2610 
2611     bool isStarted = audioRenderer->Start();
2612     EXPECT_EQ(true, isStarted);
2613 
2614     bool isReleased = audioRenderer->Release();
2615     EXPECT_EQ(true, isReleased);
2616 
2617     bool isStopped = audioRenderer->Stop();
2618     EXPECT_EQ(false, isStopped);
2619 }
2620 
2621 /**
2622 * @tc.name  : Test Stop API via legal state. call Start, Stop, Start and Stop again
2623 * @tc.number: Audio_Renderer_Stop_005
2624 * @tc.desc  : Test Stop interface. Returns true , if the stop is successful.
2625 */
2626 HWTEST(AudioRendererUnitTest, Audio_Renderer_Stop_005, TestSize.Level1)
2627 {
2628     AudioRendererOptions rendererOptions;
2629 
2630     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
2631     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
2632     ASSERT_NE(nullptr, audioRenderer);
2633 
2634     bool isStarted = audioRenderer->Start();
2635     EXPECT_EQ(true, isStarted);
2636 
2637     bool isStopped = audioRenderer->Stop();
2638     EXPECT_EQ(true, isStopped);
2639 
2640     isStarted = audioRenderer->Start();
2641     EXPECT_EQ(true, isStarted);
2642 
2643     isStopped = audioRenderer->Stop();
2644     EXPECT_EQ(true, isStopped);
2645     audioRenderer->Release();
2646 }
2647 
2648 /**
2649 * @tc.name  : Test Stop API via legal state, RENDERER_PAUSED: call Stop after Pause.
2650 * @tc.number: Audio_Renderer_Stop_006
2651 * @tc.desc  : Test Stop interface. Returns false, if the renderer state is not RENDERER_RUNNING or RENDERER_PAUSED.
2652 */
2653 HWTEST(AudioRendererUnitTest, Audio_Renderer_Stop_006, TestSize.Level1)
2654 {
2655     AudioRendererOptions rendererOptions;
2656 
2657     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
2658     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
2659     ASSERT_NE(nullptr, audioRenderer);
2660 
2661     bool isStarted = audioRenderer->Start();
2662     EXPECT_EQ(true, isStarted);
2663 
2664     bool isPaused = audioRenderer->Pause();
2665     EXPECT_EQ(true, isPaused);
2666 
2667     bool isStopped = audioRenderer->Stop();
2668     EXPECT_EQ(true, isStopped);
2669     audioRenderer->Release();
2670 }
2671 
2672 /**
2673 * @tc.name  : Test Release API.
2674 * @tc.number: Audio_Renderer_Release_001
2675 * @tc.desc  : Test Release interface. Returns true, if the release is successful.
2676 */
2677 HWTEST(AudioRendererUnitTest, Audio_Renderer_Release_001, TestSize.Level1)
2678 {
2679     int32_t ret = -1;
2680     FILE *wavFile = fopen(AUDIORENDER_TEST_FILE_PATH.c_str(), "rb");
2681     ASSERT_NE(nullptr, wavFile);
2682 
2683     AudioRendererOptions rendererOptions;
2684 
2685     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
2686     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
2687     ASSERT_NE(nullptr, audioRenderer);
2688 
2689     bool isStarted = audioRenderer->Start();
2690     EXPECT_EQ(true, isStarted);
2691 
2692     size_t bufferLen;
2693     ret = audioRenderer->GetBufferSize(bufferLen);
2694     EXPECT_EQ(SUCCESS, ret);
2695 
2696     uint8_t *buffer = (uint8_t *) malloc(bufferLen);
2697     ASSERT_NE(nullptr, buffer);
2698 
2699     size_t bytesToWrite = fread(buffer, 1, bufferLen, wavFile);
2700     int32_t bytesWritten = audioRenderer->Write(buffer, bytesToWrite);
2701     EXPECT_GE(bytesWritten, VALUE_ZERO);
2702 
2703     audioRenderer->Drain();
2704     audioRenderer->Stop();
2705 
2706     bool isReleased = audioRenderer->Release();
2707     EXPECT_EQ(true, isReleased);
2708 
2709     free(buffer);
2710     fclose(wavFile);
2711 }
2712 
2713 /**
2714 * @tc.name  : Test Release API via illegal state, RENDERER_NEW: Call Release without initializing the renderer.
2715 * @tc.number: Audio_Renderer_Release_002
2716 * @tc.desc  : Test Release interface, Returns false, if the state is RENDERER_NEW.
2717 */
2718 HWTEST(AudioRendererUnitTest, Audio_Renderer_Release_002, TestSize.Level1)
2719 {
2720     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(STREAM_MUSIC);
2721     ASSERT_NE(nullptr, audioRenderer);
2722 
2723     bool isReleased = audioRenderer->Release();
2724     EXPECT_EQ(false, isReleased);
2725 }
2726 
2727 /**
2728 * @tc.name  : Test Release API via illegal state, RENDERER_RELEASED: call Release repeatedly.
2729 * @tc.number: Audio_Renderer_Release_003
2730 * @tc.desc  : Test Release interface. Returns false, if the state is already RENDERER_RELEASED.
2731 */
2732 HWTEST(AudioRendererUnitTest, Audio_Renderer_Release_003, TestSize.Level1)
2733 {
2734     AudioRendererOptions rendererOptions;
2735 
2736     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
2737     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
2738     ASSERT_NE(nullptr, audioRenderer);
2739 
2740     bool isReleased = audioRenderer->Release();
2741     EXPECT_EQ(true, isReleased);
2742 
2743     isReleased = audioRenderer->Release();
2744     EXPECT_EQ(false, isReleased);
2745 }
2746 
2747 /**
2748 * @tc.name  : Test Release API via legal state, RENDERER_RUNNING: call Release after Start
2749 * @tc.number: Audio_Renderer_Release_004
2750 * @tc.desc  : Test Release interface. Returns true, if the release is successful.
2751 */
2752 HWTEST(AudioRendererUnitTest, Audio_Renderer_Release_004, TestSize.Level1)
2753 {
2754     AudioRendererOptions rendererOptions;
2755 
2756     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
2757     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
2758     ASSERT_NE(nullptr, audioRenderer);
2759 
2760     bool isStarted = audioRenderer->Start();
2761     EXPECT_EQ(true, isStarted);
2762 
2763     bool isReleased = audioRenderer->Release();
2764     EXPECT_EQ(true, isReleased);
2765 }
2766 
2767 /**
2768 * @tc.name  : Test Release API via legal state, RENDERER_STOPPED: call release after Start and Stop
2769 * @tc.number: Audio_Renderer_Release_005
2770 * @tc.desc  : Test Release interface. Returns true, if the release is successful.
2771 */
2772 HWTEST(AudioRendererUnitTest, Audio_Renderer_Release_005, TestSize.Level1)
2773 {
2774     AudioRendererOptions rendererOptions;
2775 
2776     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
2777     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
2778     ASSERT_NE(nullptr, audioRenderer);
2779 
2780     bool isStarted = audioRenderer->Start();
2781     EXPECT_EQ(true, isStarted);
2782 
2783     bool isStopped = audioRenderer->Stop();
2784     EXPECT_EQ(true, isStopped);
2785 
2786     bool isReleased = audioRenderer->Release();
2787     EXPECT_EQ(true, isReleased);
2788 }
2789 
2790 /**
2791 * @tc.name  : Test Release API via legal state, RENDERER_PAUSED: call release after Start and Pause
2792 * @tc.number: Audio_Renderer_Release_006
2793 * @tc.desc  : Test Release interface. Returns true, if the release is successful.
2794 */
2795 HWTEST(AudioRendererUnitTest, Audio_Renderer_Release_006, TestSize.Level1)
2796 {
2797     AudioRendererOptions rendererOptions;
2798 
2799     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
2800     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
2801     ASSERT_NE(nullptr, audioRenderer);
2802 
2803     bool isStarted = audioRenderer->Start();
2804     EXPECT_EQ(true, isStarted);
2805 
2806     bool isPaused = audioRenderer->Pause();
2807     EXPECT_EQ(true, isPaused);
2808 
2809     bool isReleased = audioRenderer->Release();
2810     EXPECT_EQ(true, isReleased);
2811 }
2812 
2813 /**
2814 * @tc.name  : Test GetStatus API.
2815 * @tc.number: Audio_Renderer_GetStatus_001
2816 * @tc.desc  : Test GetStatus interface. Returns correct state on success.
2817 */
2818 HWTEST(AudioRendererUnitTest, Audio_Renderer_GetStatus_001, TestSize.Level1)
2819 {
2820     RendererState state = RENDERER_INVALID;
2821 
2822     AudioRendererOptions rendererOptions;
2823 
2824     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
2825     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
2826     ASSERT_NE(nullptr, audioRenderer);
2827 
2828     state = audioRenderer->GetStatus();
2829     EXPECT_EQ(RENDERER_PREPARED, state);
2830 
2831     bool isStarted = audioRenderer->Start();
2832     EXPECT_EQ(true, isStarted);
2833     state = audioRenderer->GetStatus();
2834     EXPECT_EQ(RENDERER_RUNNING, state);
2835 
2836     bool isStopped = audioRenderer->Stop();
2837     EXPECT_EQ(true, isStopped);
2838     state = audioRenderer->GetStatus();
2839     EXPECT_EQ(RENDERER_STOPPED, state);
2840 
2841     bool isReleased = audioRenderer->Release();
2842     EXPECT_EQ(true, isReleased);
2843     state = audioRenderer->GetStatus();
2844     EXPECT_EQ(RENDERER_RELEASED, state);
2845 }
2846 
2847 /**
2848 * @tc.name  : Test GetStatus API, call Start without Initializing the renderer
2849 * @tc.number: Audio_Renderer_GetStatus_002
2850 * @tc.desc  : Test GetStatus interface. Not changes to RENDERER_RUNNING, if the current state is RENDERER_NEW.
2851 */
2852 HWTEST(AudioRendererUnitTest, Audio_Renderer_GetStatus_002, TestSize.Level1)
2853 {
2854     RendererState state = RENDERER_INVALID;
2855 
2856     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(STREAM_MUSIC);
2857     ASSERT_NE(nullptr, audioRenderer);
2858 
2859     bool isStarted = audioRenderer->Start();
2860     EXPECT_EQ(false, isStarted);
2861     state = audioRenderer->GetStatus();
2862     EXPECT_NE(RENDERER_RUNNING, state);
2863     EXPECT_EQ(RENDERER_NEW, state);
2864 }
2865 
2866 /**
2867 * @tc.name  : Test GetStatus API, call Stop without Start
2868 * @tc.number: Audio_Renderer_GetStatus_003
2869 * @tc.desc  : Test GetStatus interface. Not changes to RENDERER_STOPPED, if the current state is RENDERER_PREPARED.
2870 */
2871 HWTEST(AudioRendererUnitTest, Audio_Renderer_GetStatus_003, TestSize.Level1)
2872 {
2873     RendererState state = RENDERER_INVALID;
2874     AudioRendererOptions rendererOptions;
2875 
2876     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
2877     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
2878     ASSERT_NE(nullptr, audioRenderer);
2879 
2880     bool isStopped = audioRenderer->Stop();
2881     EXPECT_EQ(false, isStopped);
2882     state = audioRenderer->GetStatus();
2883     EXPECT_NE(RENDERER_STOPPED, state);
2884     EXPECT_EQ(RENDERER_PREPARED, state);
2885 
2886     audioRenderer->Release();
2887 }
2888 
2889 /**
2890 * @tc.name  : Test GetStatus API, call Start, Stop and then Start again
2891 * @tc.number: Audio_Renderer_GetStatus_004
2892 * @tc.desc  : Test GetStatus interface.  Returns correct state on success.
2893 */
2894 HWTEST(AudioRendererUnitTest, Audio_Renderer_GetStatus_004, TestSize.Level1)
2895 {
2896     RendererState state = RENDERER_INVALID;
2897 
2898     AudioRendererOptions rendererOptions;
2899 
2900     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
2901     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
2902     ASSERT_NE(nullptr, audioRenderer);
2903 
2904     bool isStarted = audioRenderer->Start();
2905     EXPECT_EQ(true, isStarted);
2906     state = audioRenderer->GetStatus();
2907     EXPECT_EQ(RENDERER_RUNNING, state);
2908 
2909     bool isStopped = audioRenderer->Stop();
2910     EXPECT_EQ(true, isStopped);
2911     state = audioRenderer->GetStatus();
2912     EXPECT_EQ(RENDERER_STOPPED, state);
2913 
2914     isStarted = audioRenderer->Start();
2915     EXPECT_EQ(true, isStarted);
2916     state = audioRenderer->GetStatus();
2917     EXPECT_EQ(RENDERER_RUNNING, state);
2918 
2919     audioRenderer->Release();
2920 }
2921 
2922 /**
2923 * @tc.name  : Test GetStatus API, call Release without initializing
2924 * @tc.number: Audio_Renderer_GetStatus_005
2925 * @tc.desc  : Test GetStatus interface. Not changes to RENDERER_RELEASED, if the current state is RENDERER_NEW.
2926 */
2927 HWTEST(AudioRendererUnitTest, Audio_Renderer_GetStatus_005, TestSize.Level1)
2928 {
2929     RendererState state = RENDERER_INVALID;
2930 
2931     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(STREAM_MUSIC);
2932     ASSERT_NE(nullptr, audioRenderer);
2933 
2934     bool isReleased = audioRenderer->Release();
2935     EXPECT_EQ(false, isReleased);
2936     state = audioRenderer->GetStatus();
2937     EXPECT_NE(RENDERER_RELEASED, state);
2938     EXPECT_EQ(RENDERER_NEW, state);
2939 }
2940 
2941 /**
2942 * @tc.name  : Test GetLatency API.
2943 * @tc.number: Audio_Renderer_GetLatency_001
2944 * @tc.desc  : Test GetLatency interface. Returns 0 {SUCCESS}, if the getting is successful.
2945 */
2946 HWTEST(AudioRendererUnitTest, Audio_Renderer_GetLatency_001, TestSize.Level1)
2947 {
2948     int32_t ret = -1;
2949     FILE *wavFile = fopen(AUDIORENDER_TEST_FILE_PATH.c_str(), "rb");
2950     ASSERT_NE(nullptr, wavFile);
2951 
2952     AudioRendererOptions rendererOptions;
2953 
2954     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
2955     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
2956     ASSERT_NE(nullptr, audioRenderer);
2957 
2958     bool isStarted = audioRenderer->Start();
2959     EXPECT_EQ(true, isStarted);
2960 
2961     size_t bufferLen;
2962     ret = audioRenderer->GetBufferSize(bufferLen);
2963     EXPECT_EQ(SUCCESS, ret);
2964 
2965     uint8_t *buffer = (uint8_t *) malloc(bufferLen);
2966     ASSERT_NE(nullptr, buffer);
2967 
2968     size_t bytesToWrite = 0;
2969     int32_t bytesWritten = 0;
2970     size_t minBytes = 4;
2971     int32_t numBuffersToRender = WRITE_BUFFERS_COUNT;
2972 
2973     while (numBuffersToRender) {
2974         bytesToWrite = fread(buffer, 1, bufferLen, wavFile);
2975         bytesWritten = 0;
2976         uint64_t latency;
2977         ret = audioRenderer->GetLatency(latency);
2978         EXPECT_EQ(SUCCESS, ret);
2979         while ((static_cast<size_t>(bytesWritten) < bytesToWrite) &&
2980             ((static_cast<size_t>(bytesToWrite) - bytesWritten) > minBytes)) {
2981             bytesWritten += audioRenderer->Write(buffer + static_cast<size_t>(bytesWritten),
2982                                                  bytesToWrite - static_cast<size_t>(bytesWritten));
2983             EXPECT_GE(bytesWritten, VALUE_ZERO);
2984             if (bytesWritten < 0) {
2985                 break;
2986             }
2987         }
2988         numBuffersToRender--;
2989     }
2990 
2991     audioRenderer->Drain();
2992     audioRenderer->Release();
2993 
2994     free(buffer);
2995     fclose(wavFile);
2996 }
2997 
2998 /**
2999 * @tc.name  : Test GetLatency API via illegal state, RENDERER_NEW: without initializing the renderer
3000 * @tc.number: Audio_Renderer_GetLatency_002
3001 * @tc.desc  : Test GetLatency interface. Returns error code, if the renderer state is RENDERER_NEW.
3002 */
3003 HWTEST(AudioRendererUnitTest, Audio_Renderer_GetLatency_002, TestSize.Level1)
3004 {
3005     int32_t ret = -1;
3006 
3007     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(STREAM_MUSIC);
3008     ASSERT_NE(nullptr, audioRenderer);
3009 
3010     bool isStarted = audioRenderer->Start();
3011     EXPECT_EQ(false, isStarted);
3012 
3013     uint64_t latency;
3014     ret = audioRenderer->GetLatency(latency);
3015     EXPECT_EQ(ERR_OPERATION_FAILED, ret);
3016 }
3017 
3018 /**
3019 * @tc.name  : Test GetLatency API via legal state, RENDERER_PREPARED
3020 * @tc.number: Audio_Renderer_GetLatency_003
3021 * @tc.desc  : Test GetLatency interface. Returns 0 {SUCCESS}, if the getting is successful.
3022 */
3023 HWTEST(AudioRendererUnitTest, Audio_Renderer_GetLatency_003, TestSize.Level1)
3024 {
3025     int32_t ret = -1;
3026     AudioRendererOptions rendererOptions;
3027 
3028     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
3029     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
3030     ASSERT_NE(nullptr, audioRenderer);
3031 
3032     uint64_t latency;
3033     ret = audioRenderer->GetLatency(latency);
3034     EXPECT_EQ(SUCCESS, ret);
3035 
3036     audioRenderer->Release();
3037 }
3038 
3039 /**
3040 * @tc.name  : Test GetLatency API via legal state, RENDERER_STOPPED: After Stop
3041 * @tc.number: Audio_Renderer_GetLatency_004
3042 * @tc.desc  : Test GetLatency interface. Returns 0 {SUCCESS}, if the getting is successful.
3043 */
3044 HWTEST(AudioRendererUnitTest, Audio_Renderer_GetLatency_004, TestSize.Level1)
3045 {
3046     int32_t ret = -1;
3047     AudioRendererOptions rendererOptions;
3048 
3049     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
3050     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
3051     ASSERT_NE(nullptr, audioRenderer);
3052 
3053     bool isStarted = audioRenderer->Start();
3054     EXPECT_EQ(true, isStarted);
3055 
3056     bool isStopped = audioRenderer->Stop();
3057     EXPECT_EQ(true, isStopped);
3058 
3059     uint64_t latency;
3060     ret = audioRenderer->GetLatency(latency);
3061     EXPECT_EQ(SUCCESS, ret);
3062 
3063     audioRenderer->Release();
3064 }
3065 
3066 /**
3067 * @tc.name  : Test GetLatency API via illegal state, RENDERER_RELEASED: After Release
3068 * @tc.number: Audio_Renderer_GetLatency_005
3069 * @tc.desc  : Test GetLatency interface. Returns error code, if the renderer state is RENDERER_RELEASED.
3070 */
3071 HWTEST(AudioRendererUnitTest, Audio_Renderer_GetLatency_005, TestSize.Level1)
3072 {
3073     int32_t ret = -1;
3074     AudioRendererOptions rendererOptions;
3075 
3076     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
3077     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
3078     ASSERT_NE(nullptr, audioRenderer);
3079 
3080     bool isStarted = audioRenderer->Start();
3081     EXPECT_EQ(true, isStarted);
3082 
3083     bool isReleased = audioRenderer->Release();
3084     EXPECT_EQ(true, isReleased);
3085 
3086     uint64_t latency;
3087     ret = audioRenderer->GetLatency(latency);
3088     EXPECT_EQ(ERR_OPERATION_FAILED, ret);
3089 }
3090 
3091 /**
3092 * @tc.name  : Test SetRendererCallback with null pointer.
3093 * @tc.number: Audio_Renderer_SetRendererCallback_001
3094 * @tc.desc  : Test SetRendererCallback interface. Returns error code, if null pointer is set.
3095 */
3096 HWTEST(AudioRendererUnitTest, Audio_Renderer_SetRendererCallback_001, TestSize.Level1)
3097 {
3098     int32_t ret = -1;
3099 
3100     AudioRendererOptions rendererOptions;
3101     rendererOptions.streamInfo.samplingRate = AudioSamplingRate::SAMPLE_RATE_44100;
3102     rendererOptions.streamInfo.encoding = AudioEncodingType::ENCODING_PCM;
3103     rendererOptions.streamInfo.format = AudioSampleFormat::SAMPLE_S16LE;
3104     rendererOptions.streamInfo.channels = AudioChannel::STEREO;
3105     rendererOptions.rendererInfo.contentType = ContentType::CONTENT_TYPE_MUSIC;
3106     rendererOptions.rendererInfo.streamUsage = StreamUsage::STREAM_USAGE_MEDIA;
3107     rendererOptions.rendererInfo.rendererFlags = RENDERER_FLAG;
3108 
3109     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
3110     ASSERT_NE(nullptr, audioRenderer);
3111 
3112     ret = audioRenderer->SetRendererCallback(nullptr);
3113     EXPECT_NE(SUCCESS, ret);
3114     EXPECT_EQ(ERR_INVALID_PARAM, ret);
3115 }
3116 
3117 /**
3118 * @tc.name  : Test SetRendererCallback with valid callback pointer.
3119 * @tc.number: Audio_Renderer_SetRendererCallback_002
3120 * @tc.desc  : Test SetRendererCallback interface. Returns success, if valid callback is set.
3121 */
3122 HWTEST(AudioRendererUnitTest, Audio_Renderer_SetRendererCallback_002, TestSize.Level1)
3123 {
3124     int32_t ret = -1;
3125 
3126     AudioRendererOptions rendererOptions;
3127     rendererOptions.streamInfo.samplingRate = AudioSamplingRate::SAMPLE_RATE_44100;
3128     rendererOptions.streamInfo.encoding = AudioEncodingType::ENCODING_PCM;
3129     rendererOptions.streamInfo.format = AudioSampleFormat::SAMPLE_S16LE;
3130     rendererOptions.streamInfo.channels = AudioChannel::STEREO;
3131     rendererOptions.rendererInfo.contentType = ContentType::CONTENT_TYPE_MUSIC;
3132     rendererOptions.rendererInfo.streamUsage = StreamUsage::STREAM_USAGE_MEDIA;
3133     rendererOptions.rendererInfo.rendererFlags = RENDERER_FLAG;
3134 
3135     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
3136     ASSERT_NE(nullptr, audioRenderer);
3137 
3138     shared_ptr<AudioRendererCallbackTest> audioRendererCB = make_shared<AudioRendererCallbackTest>();
3139     ret = audioRenderer->SetRendererCallback(audioRendererCB);
3140     EXPECT_EQ(SUCCESS, ret);
3141 }
3142 
3143 /**
3144 * @tc.name  : Test SetRendererCallback via illegal state, RENDERER_RELEASED: After RELEASED
3145 * @tc.number: Audio_Renderer_SetRendererCallback_003
3146 * @tc.desc  : Test SetRendererCallback interface. Returns error, if callback is set in released state.
3147 */
3148 HWTEST(AudioRendererUnitTest, Audio_Renderer_SetRendererCallback_003, TestSize.Level1)
3149 {
3150     int32_t ret = -1;
3151 
3152     AudioRendererOptions rendererOptions;
3153     rendererOptions.streamInfo.samplingRate = AudioSamplingRate::SAMPLE_RATE_44100;
3154     rendererOptions.streamInfo.encoding = AudioEncodingType::ENCODING_PCM;
3155     rendererOptions.streamInfo.format = AudioSampleFormat::SAMPLE_S16LE;
3156     rendererOptions.streamInfo.channels = AudioChannel::STEREO;
3157     rendererOptions.rendererInfo.contentType = ContentType::CONTENT_TYPE_MUSIC;
3158     rendererOptions.rendererInfo.streamUsage = StreamUsage::STREAM_USAGE_MEDIA;
3159     rendererOptions.rendererInfo.rendererFlags = RENDERER_FLAG;
3160 
3161     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
3162     ASSERT_NE(nullptr, audioRenderer);
3163 
3164     bool isReleased = audioRenderer->Release();
3165     EXPECT_EQ(true, isReleased);
3166 
3167     RendererState state = audioRenderer->GetStatus();
3168     EXPECT_EQ(RENDERER_RELEASED, state);
3169 
3170     shared_ptr<AudioRendererCallbackTest> audioRendererCB = make_shared<AudioRendererCallbackTest>();
3171     ret = audioRenderer->SetRendererCallback(audioRendererCB);
3172     EXPECT_NE(SUCCESS, ret);
3173     EXPECT_EQ(ERR_ILLEGAL_STATE, ret);
3174 }
3175 
3176 /**
3177 * @tc.name  : Test SetRendererCallback via legal state, RENDERER_PREPARED: After PREPARED
3178 * @tc.number: Audio_Renderer_SetRendererCallback_004
3179 * @tc.desc  : Test SetRendererCallback interface. Returns success, if callback is set in proper state.
3180 */
3181 HWTEST(AudioRendererUnitTest, Audio_Renderer_SetRendererCallback_004, TestSize.Level1)
3182 {
3183     int32_t ret = -1;
3184 
3185     AudioRendererOptions rendererOptions;
3186     rendererOptions.streamInfo.samplingRate = AudioSamplingRate::SAMPLE_RATE_44100;
3187     rendererOptions.streamInfo.encoding = AudioEncodingType::ENCODING_PCM;
3188     rendererOptions.streamInfo.format = AudioSampleFormat::SAMPLE_S16LE;
3189     rendererOptions.streamInfo.channels = AudioChannel::STEREO;
3190     rendererOptions.rendererInfo.contentType = ContentType::CONTENT_TYPE_MUSIC;
3191     rendererOptions.rendererInfo.streamUsage = StreamUsage::STREAM_USAGE_MEDIA;
3192     rendererOptions.rendererInfo.rendererFlags = RENDERER_FLAG;
3193 
3194     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
3195     ASSERT_NE(nullptr, audioRenderer);
3196 
3197     RendererState state = audioRenderer->GetStatus();
3198     EXPECT_EQ(RENDERER_PREPARED, state);
3199 
3200     shared_ptr<AudioRendererCallbackTest> audioRendererCB = make_shared<AudioRendererCallbackTest>();
3201     ret = audioRenderer->SetRendererCallback(audioRendererCB);
3202     EXPECT_EQ(SUCCESS, ret);
3203 }
3204 
3205 /**
3206 * @tc.name  : Test SetRenderMode via legal input, RENDER_MODE_CALLBACK
3207 * @tc.number: Audio_Renderer_SetRenderMode_001
3208 * @tc.desc  : Test SetRenderMode interface. Returns SUCCESS, if the render mode is successfully set.
3209 */
3210 HWTEST(AudioRendererUnitTest, Audio_Renderer_SetRenderMode_001, TestSize.Level1)
3211 {
3212     int32_t ret = -1;
3213     AudioRendererOptions rendererOptions;
3214 
3215     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
3216     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
3217     ASSERT_NE(nullptr, audioRenderer);
3218 
3219     ret = audioRenderer->SetRenderMode(RENDER_MODE_CALLBACK);
3220     EXPECT_EQ(SUCCESS, ret);
3221 
3222     audioRenderer->Release();
3223 }
3224 
3225 /**
3226 * @tc.name  : Test SetRenderMode via legal input, RENDER_MODE_NORMAL
3227 * @tc.number: Audio_Renderer_SetRenderMode_002
3228 * @tc.desc  : Test SetRenderMode interface. Returns SUCCESS, if the render mode is successfully set.
3229 */
3230 HWTEST(AudioRendererUnitTest, Audio_Renderer_SetRenderMode_002, TestSize.Level1)
3231 {
3232     int32_t ret = -1;
3233     AudioRendererOptions rendererOptions;
3234 
3235     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
3236     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
3237     ASSERT_NE(nullptr, audioRenderer);
3238 
3239     ret = audioRenderer->SetRenderMode(RENDER_MODE_NORMAL);
3240     EXPECT_EQ(SUCCESS, ret);
3241 
3242     audioRenderer->Release();
3243 }
3244 
3245 /**
3246 * @tc.name  : Test GetRenderMode with, RENDER_MODE_CALLBACK
3247 * @tc.number: Audio_Renderer_GetRenderMode_001
3248 * @tc.desc  : Test GetRenderMode interface. Returns the current render mode.
3249 */
3250 HWTEST(AudioRendererUnitTest, Audio_Renderer_GetRenderMode_001, TestSize.Level1)
3251 {
3252     int32_t ret = -1;
3253     AudioRendererOptions rendererOptions;
3254 
3255     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
3256     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
3257     ASSERT_NE(nullptr, audioRenderer);
3258 
3259     ret = audioRenderer->SetRenderMode(RENDER_MODE_CALLBACK);
3260     EXPECT_EQ(SUCCESS, ret);
3261     AudioRenderMode renderMode = audioRenderer->GetRenderMode();
3262     EXPECT_EQ(RENDER_MODE_CALLBACK, renderMode);
3263 
3264     audioRenderer->Release();
3265 }
3266 
3267 /**
3268 * @tc.name  : Test GetRenderMode with, RENDER_MODE_NORMAL
3269 * @tc.number: Audio_Renderer_GetRenderMode_002
3270 * @tc.desc  : Test GetRenderMode interface. Returns the current render mode.
3271 */
3272 HWTEST(AudioRendererUnitTest, Audio_Renderer_GetRenderMode_002, TestSize.Level1)
3273 {
3274     int32_t ret = -1;
3275     AudioRendererOptions rendererOptions;
3276 
3277     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
3278     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
3279     ASSERT_NE(nullptr, audioRenderer);
3280 
3281     ret = audioRenderer->SetRenderMode(RENDER_MODE_NORMAL);
3282     EXPECT_EQ(SUCCESS, ret);
3283     AudioRenderMode renderMode = audioRenderer->GetRenderMode();
3284     EXPECT_EQ(RENDER_MODE_NORMAL, renderMode);
3285 
3286     audioRenderer->Release();
3287 }
3288 
3289 /**
3290 * @tc.name  : Test GetRenderMode with, default renderMode
3291 * @tc.number: Audio_Renderer_GetRenderMode_003
3292 * @tc.desc  : Test GetRenderMode interface. Returns the default render mode RENDER_MODE_NORMAL.
3293 */
3294 HWTEST(AudioRendererUnitTest, Audio_Renderer_GetRenderMode_003, TestSize.Level1)
3295 {
3296     AudioRendererOptions rendererOptions;
3297 
3298     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
3299     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
3300     ASSERT_NE(nullptr, audioRenderer);
3301 
3302     AudioRenderMode renderMode = audioRenderer->GetRenderMode();
3303     EXPECT_EQ(RENDER_MODE_NORMAL, renderMode);
3304 
3305     audioRenderer->Release();
3306 }
3307 
3308 /**
3309 * @tc.name  : Test SetRendererWriteCallback via legal render mode, RENDER_MODE_CALLBACK
3310 * @tc.number: Audio_Renderer_SetRendererWriteCallback_001
3311 * @tc.desc  : Test SetRendererWriteCallback interface. Returns SUCCESS, if the callback is successfully set.
3312 */
3313 HWTEST(AudioRendererUnitTest, Audio_Renderer_SetRendererWriteCallback_001, TestSize.Level1)
3314 {
3315     int32_t ret = -1;
3316     AudioRendererOptions rendererOptions;
3317 
3318     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
3319     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
3320     ASSERT_NE(nullptr, audioRenderer);
3321 
3322     ret = audioRenderer->SetRenderMode(RENDER_MODE_CALLBACK);
3323     EXPECT_EQ(SUCCESS, ret);
3324     AudioRenderMode renderMode = audioRenderer->GetRenderMode();
3325     EXPECT_EQ(RENDER_MODE_CALLBACK, renderMode);
3326 
3327     shared_ptr<AudioRendererWriteCallback> cb = make_shared<AudioRenderModeCallbackTest>();
3328 
3329     ret = audioRenderer->SetRendererWriteCallback(cb);
3330     EXPECT_EQ(SUCCESS, ret);
3331 
3332     audioRenderer->Release();
3333 }
3334 
3335 /**
3336 * @tc.name  : Test SetRendererWriteCallback via illegal render mode, RENDER_MODE_NORMAL
3337 * @tc.number: Audio_Renderer_SetRendererWriteCallback_002
3338 * @tc.desc  : Test SetRendererWriteCallback interface. Returns error code, if the render mode is not callback.
3339 */
3340 HWTEST(AudioRendererUnitTest, Audio_Renderer_SetRendererWriteCallback_002, TestSize.Level1)
3341 {
3342     int32_t ret = -1;
3343     AudioRendererOptions rendererOptions;
3344 
3345     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
3346     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
3347     ASSERT_NE(nullptr, audioRenderer);
3348 
3349     ret = audioRenderer->SetRenderMode(RENDER_MODE_NORMAL);
3350     EXPECT_EQ(SUCCESS, ret);
3351     AudioRenderMode renderMode = audioRenderer->GetRenderMode();
3352     EXPECT_EQ(RENDER_MODE_NORMAL, renderMode);
3353 
3354     shared_ptr<AudioRendererWriteCallback> cb = make_shared<AudioRenderModeCallbackTest>();
3355 
3356     ret = audioRenderer->SetRendererWriteCallback(cb);
3357     EXPECT_EQ(ERR_INCORRECT_MODE, ret);
3358 
3359     audioRenderer->Release();
3360 }
3361 
3362 /**
3363 * @tc.name  : Test SetRendererWriteCallback via illegal render mode, default render mode RENDER_MODE_NORMAL
3364 * @tc.number: Audio_Renderer_SetRendererWriteCallback_003
3365 * @tc.desc  : Test SetRendererWriteCallback interface. Returns error code, if the render mode is not callback.
3366 */
3367 HWTEST(AudioRendererUnitTest, Audio_Renderer_SetRendererWriteCallback_003, TestSize.Level1)
3368 {
3369     int32_t ret = -1;
3370     AudioRendererOptions rendererOptions;
3371 
3372     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
3373     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
3374     ASSERT_NE(nullptr, audioRenderer);
3375 
3376     shared_ptr<AudioRendererWriteCallback> cb = make_shared<AudioRenderModeCallbackTest>();
3377 
3378     ret = audioRenderer->SetRendererWriteCallback(cb);
3379     EXPECT_EQ(ERR_INCORRECT_MODE, ret);
3380 
3381     audioRenderer->Release();
3382 }
3383 
3384 /**
3385 * @tc.name  : Test SetRendererWriteCallback via illegal input, nullptr
3386 * @tc.number: Audio_Renderer_SetRendererWriteCallback_004
3387 * @tc.desc  : Test SetRendererWriteCallback interface. Returns error code, if the callback reference is nullptr.
3388 */
3389 HWTEST(AudioRendererUnitTest, Audio_Renderer_SetRendererWriteCallback_004, TestSize.Level1)
3390 {
3391     int32_t ret = -1;
3392     AudioRendererOptions rendererOptions;
3393 
3394     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
3395     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
3396     ASSERT_NE(nullptr, audioRenderer);
3397 
3398     ret = audioRenderer->SetRenderMode(RENDER_MODE_CALLBACK);
3399     EXPECT_EQ(SUCCESS, ret);
3400     AudioRenderMode renderMode = audioRenderer->GetRenderMode();
3401     EXPECT_EQ(RENDER_MODE_CALLBACK, renderMode);
3402 
3403     ret = audioRenderer->SetRendererWriteCallback(nullptr);
3404     EXPECT_EQ(ERR_INVALID_PARAM, ret);
3405 
3406     audioRenderer->Release();
3407 }
3408 
3409 /**
3410 * @tc.name  : Test GetBufferDesc via legal render mode, RENDER_MODE_CALLBACK
3411 * @tc.number: Audio_Renderer_GetBufferDesc_001
3412 * @tc.desc  : Test GetBufferDesc interface. Returns SUCCESS, if BufferDesc obtained successfully.
3413 */
3414 HWTEST(AudioRendererUnitTest, Audio_Renderer_GetBufferDesc_001, TestSize.Level1)
3415 {
3416     int32_t ret = -1;
3417     AudioRendererOptions rendererOptions;
3418 
3419     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
3420     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
3421     ASSERT_NE(nullptr, audioRenderer);
3422 
3423     ret = audioRenderer->SetRenderMode(RENDER_MODE_CALLBACK);
3424     EXPECT_EQ(SUCCESS, ret);
3425     AudioRenderMode renderMode = audioRenderer->GetRenderMode();
3426     EXPECT_EQ(RENDER_MODE_CALLBACK, renderMode);
3427 
3428     shared_ptr<AudioRendererWriteCallback> cb = make_shared<AudioRenderModeCallbackTest>();
3429 
3430     ret = audioRenderer->SetRendererWriteCallback(cb);
3431     EXPECT_EQ(SUCCESS, ret);
3432 
3433     BufferDesc bufDesc {};
3434     bufDesc.buffer = nullptr;
3435     bufDesc.dataLength = g_reqBufLen;
3436     ret = audioRenderer->GetBufferDesc(bufDesc);
3437     EXPECT_EQ(SUCCESS, ret);
3438     EXPECT_NE(nullptr, bufDesc.buffer);
3439 
3440     audioRenderer->Release();
3441 }
3442 
3443 /**
3444 * @tc.name  : Test GetBufferDesc via illegal render mode, RENDER_MODE_NORMAL
3445 * @tc.number: Audio_Renderer_GetBufferDesc_002
3446 * @tc.desc  : Test GetBufferDesc interface. Returns errorcode, if render mode is not callback.
3447 */
3448 HWTEST(AudioRendererUnitTest, Audio_Renderer_GetBufferDesc_002, TestSize.Level1)
3449 {
3450     int32_t ret = -1;
3451     AudioRendererOptions rendererOptions;
3452 
3453     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
3454     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
3455     ASSERT_NE(nullptr, audioRenderer);
3456 
3457     shared_ptr<AudioRendererWriteCallback> cb = make_shared<AudioRenderModeCallbackTest>();
3458 
3459     ret = audioRenderer->SetRendererWriteCallback(cb);
3460     EXPECT_EQ(ERR_INCORRECT_MODE, ret);
3461 
3462     BufferDesc bufDesc {};
3463     bufDesc.buffer = nullptr;
3464     bufDesc.dataLength = g_reqBufLen;
3465     ret = audioRenderer->GetBufferDesc(bufDesc);
3466     EXPECT_EQ(ERR_INCORRECT_MODE, ret);
3467     EXPECT_EQ(nullptr, bufDesc.buffer);
3468 
3469     audioRenderer->Release();
3470 }
3471 
3472 /**
3473 * @tc.name  : Test Enqueue via legal render mode, RENDER_MODE_CALLBACK
3474 * @tc.number: Audio_Renderer_Enqueue_001
3475 * @tc.desc  : Test Enqueue interface. Returns SUCCESS , if the buff desc enqueued successfully.
3476 */
3477 HWTEST(AudioRendererUnitTest, Audio_Renderer_Enqueue_001, TestSize.Level1)
3478 {
3479     int32_t ret = -1;
3480     AudioRendererOptions rendererOptions;
3481 
3482     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
3483     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
3484     ASSERT_NE(nullptr, audioRenderer);
3485 
3486     ret = audioRenderer->SetRenderMode(RENDER_MODE_CALLBACK);
3487     EXPECT_EQ(SUCCESS, ret);
3488     AudioRenderMode renderMode = audioRenderer->GetRenderMode();
3489     EXPECT_EQ(RENDER_MODE_CALLBACK, renderMode);
3490 
3491     shared_ptr<AudioRendererWriteCallback> cb = make_shared<AudioRenderModeCallbackTest>();
3492 
3493     ret = audioRenderer->SetRendererWriteCallback(cb);
3494     EXPECT_EQ(SUCCESS, ret);
3495 
3496     bool isStarted = audioRenderer->Start();
3497     EXPECT_EQ(true, isStarted);
3498 
3499     BufferDesc bufDesc {};
3500     bufDesc.buffer = nullptr;
3501     bufDesc.dataLength = g_reqBufLen;
3502     ret = audioRenderer->GetBufferDesc(bufDesc);
3503     EXPECT_EQ(SUCCESS, ret);
3504     EXPECT_NE(nullptr, bufDesc.buffer);
3505 
3506     ret = audioRenderer->Enqueue(bufDesc);
3507     EXPECT_EQ(SUCCESS, ret);
3508 
3509     audioRenderer->Stop();
3510     audioRenderer->Release();
3511 }
3512 
3513 /**
3514 * @tc.name  : Test Enqueue via illegal render mode, RENDER_MODE_NORMAL
3515 * @tc.number: Audio_Renderer_Enqueue_002
3516 * @tc.desc  : Test Enqueue interface. Returns error code, if the render mode is not callback.
3517 */
3518 HWTEST(AudioRendererUnitTest, Audio_Renderer_Enqueue_002, TestSize.Level1)
3519 {
3520     int32_t ret = -1;
3521     AudioRendererOptions rendererOptions;
3522 
3523     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
3524     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
3525     ASSERT_NE(nullptr, audioRenderer);
3526 
3527     shared_ptr<AudioRendererWriteCallback> cb = make_shared<AudioRenderModeCallbackTest>();
3528 
3529     ret = audioRenderer->SetRendererWriteCallback(cb);
3530     EXPECT_EQ(ERR_INCORRECT_MODE, ret);
3531 
3532     bool isStarted = audioRenderer->Start();
3533     EXPECT_EQ(true, isStarted);
3534 
3535     BufferDesc bufDesc {};
3536     bufDesc.buffer = nullptr;
3537     bufDesc.dataLength = g_reqBufLen;
3538     ret = audioRenderer->GetBufferDesc(bufDesc);
3539     EXPECT_EQ(ERR_INCORRECT_MODE, ret);
3540 
3541     ret = audioRenderer->Enqueue(bufDesc);
3542     EXPECT_EQ(ERR_INCORRECT_MODE, ret);
3543 
3544     audioRenderer->Stop();
3545     audioRenderer->Release();
3546 }
3547 
3548 /**
3549 * @tc.name  : Test Enqueue via illegal input, buffer nullptr
3550 * @tc.number: Audio_Renderer_Enqueue_003
3551 * @tc.desc  : Test Enqueue interface. Returns error code, if the buffer nullptr
3552 */
3553 HWTEST(AudioRendererUnitTest, Audio_Renderer_Enqueue_003, TestSize.Level1)
3554 {
3555     int32_t ret = -1;
3556     AudioRendererOptions rendererOptions;
3557 
3558     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
3559     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
3560     ASSERT_NE(nullptr, audioRenderer);
3561 
3562     ret = audioRenderer->SetRenderMode(RENDER_MODE_CALLBACK);
3563     EXPECT_EQ(SUCCESS, ret);
3564     AudioRenderMode renderMode = audioRenderer->GetRenderMode();
3565     EXPECT_EQ(RENDER_MODE_CALLBACK, renderMode);
3566 
3567     shared_ptr<AudioRendererWriteCallback> cb = make_shared<AudioRenderModeCallbackTest>();
3568 
3569     ret = audioRenderer->SetRendererWriteCallback(cb);
3570     EXPECT_EQ(SUCCESS, ret);
3571 
3572     bool isStarted = audioRenderer->Start();
3573     EXPECT_EQ(true, isStarted);
3574 
3575     BufferDesc bufDesc {};
3576     bufDesc.buffer = nullptr;
3577     bufDesc.dataLength = g_reqBufLen;
3578 
3579     ret = audioRenderer->Enqueue(bufDesc);
3580     EXPECT_EQ(ERR_INVALID_PARAM, ret);
3581 
3582     audioRenderer->Stop();
3583     audioRenderer->Release();
3584 }
3585 
3586 /**
3587 * @tc.name  : Test Clear via legal render mode, RENDER_MODE_CALLBACK
3588 * @tc.number: Audio_Renderer_Clear_001
3589 * @tc.desc  : Test Clear interface. Returns SUCCESS , if the buff queue cleared successfully.
3590 */
3591 HWTEST(AudioRendererUnitTest, Audio_Renderer_Clear_001, TestSize.Level1)
3592 {
3593     int32_t ret = -1;
3594     AudioRendererOptions rendererOptions;
3595 
3596     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
3597     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
3598     ASSERT_NE(nullptr, audioRenderer);
3599 
3600     ret = audioRenderer->SetRenderMode(RENDER_MODE_CALLBACK);
3601     EXPECT_EQ(SUCCESS, ret);
3602     AudioRenderMode renderMode = audioRenderer->GetRenderMode();
3603     EXPECT_EQ(RENDER_MODE_CALLBACK, renderMode);
3604 
3605     shared_ptr<AudioRendererWriteCallback> cb = make_shared<AudioRenderModeCallbackTest>();
3606 
3607     ret = audioRenderer->SetRendererWriteCallback(cb);
3608     EXPECT_EQ(SUCCESS, ret);
3609 
3610     bool isStarted = audioRenderer->Start();
3611     EXPECT_EQ(true, isStarted);
3612 
3613     BufferDesc bufDesc {};
3614     bufDesc.buffer = nullptr;
3615     bufDesc.dataLength = g_reqBufLen;
3616     ret = audioRenderer->GetBufferDesc(bufDesc);
3617     EXPECT_EQ(SUCCESS, ret);
3618     EXPECT_NE(nullptr, bufDesc.buffer);
3619 
3620     ret = audioRenderer->Enqueue(bufDesc);
3621     EXPECT_EQ(SUCCESS, ret);
3622 
3623     ret = audioRenderer->Clear();
3624     EXPECT_EQ(SUCCESS, ret);
3625 
3626     audioRenderer->Stop();
3627     audioRenderer->Release();
3628 }
3629 
3630 /**
3631 * @tc.name  : Test Clear via illegal render mode, RENDER_MODE_NORMAL
3632 * @tc.number: Audio_Renderer_Clear_002
3633 * @tc.desc  : Test Clear interface. Returns error code, if the render mode is not callback.
3634 */
3635 HWTEST(AudioRendererUnitTest, Audio_Renderer_Clear_002, TestSize.Level1)
3636 {
3637     int32_t ret = -1;
3638     AudioRendererOptions rendererOptions;
3639 
3640     AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
3641     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
3642     ASSERT_NE(nullptr, audioRenderer);
3643 
3644     shared_ptr<AudioRendererWriteCallback> cb = make_shared<AudioRenderModeCallbackTest>();
3645 
3646     ret = audioRenderer->SetRendererWriteCallback(cb);
3647     EXPECT_EQ(ERR_INCORRECT_MODE, ret);
3648 
3649     bool isStarted = audioRenderer->Start();
3650     EXPECT_EQ(true, isStarted);
3651 
3652     BufferDesc bufDesc {};
3653     bufDesc.buffer = nullptr;
3654     bufDesc.dataLength = g_reqBufLen;
3655     ret = audioRenderer->GetBufferDesc(bufDesc);
3656     EXPECT_EQ(ERR_INCORRECT_MODE, ret);
3657 
3658     ret = audioRenderer->Enqueue(bufDesc);
3659     EXPECT_EQ(ERR_INCORRECT_MODE, ret);
3660 
3661     ret = audioRenderer->Clear();
3662     EXPECT_EQ(ERR_INCORRECT_MODE, ret);
3663 
3664     audioRenderer->Stop();
3665     audioRenderer->Release();
3666 }
3667 
3668 /**
3669 * @tc.name  : Test GetRendererInfo API after calling create
3670 * @tc.number: Audio_Renderer_GetRendererInfo_001
3671 * @tc.desc  : Test GetRendererInfo interface. Check whether renderer info returns proper data
3672 */
3673 HWTEST(AudioRendererUnitTest, Audio_Renderer_GetRendererInfo_001, TestSize.Level1)
3674 {
3675     AudioRendererOptions rendererOptions;
3676     rendererOptions.streamInfo.samplingRate = AudioSamplingRate::SAMPLE_RATE_96000;
3677     rendererOptions.streamInfo.encoding = AudioEncodingType::ENCODING_PCM;
3678     rendererOptions.streamInfo.format = AudioSampleFormat::SAMPLE_U8;
3679     rendererOptions.streamInfo.channels = AudioChannel::MONO;
3680     rendererOptions.rendererInfo.contentType = ContentType::CONTENT_TYPE_MUSIC;
3681     rendererOptions.rendererInfo.streamUsage = StreamUsage::STREAM_USAGE_MEDIA;
3682     rendererOptions.rendererInfo.rendererFlags = RENDERER_FLAG;
3683 
3684     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
3685     EXPECT_NE(nullptr, audioRenderer);
3686 
3687     AudioRendererInfo rendererInfo;
3688     audioRenderer->GetRendererInfo(rendererInfo);
3689 
3690     EXPECT_EQ(ContentType::CONTENT_TYPE_MUSIC, rendererInfo.contentType);
3691     EXPECT_EQ(StreamUsage::STREAM_USAGE_MEDIA, rendererInfo.streamUsage);
3692     EXPECT_EQ(RENDERER_FLAG, rendererInfo.rendererFlags);
3693     audioRenderer->Release();
3694 }
3695 
3696 /**
3697 * @tc.name  : Test GetRendererInfo API via legal state, RENDERER_RUNNING: GetRendererInfo after Start.
3698 * @tc.number: Audio_Renderer_GetRendererInfo_002
3699 * @tc.desc  : Test GetRendererInfo interface. Check whether renderer info returns proper data
3700 */
3701 HWTEST(AudioRendererUnitTest, Audio_Renderer_GetRendererInfo_002, TestSize.Level1)
3702 {
3703     AudioRendererOptions rendererOptions;
3704     rendererOptions.streamInfo.samplingRate = AudioSamplingRate::SAMPLE_RATE_96000;
3705     rendererOptions.streamInfo.encoding = AudioEncodingType::ENCODING_PCM;
3706     rendererOptions.streamInfo.format = AudioSampleFormat::SAMPLE_U8;
3707     rendererOptions.streamInfo.channels = AudioChannel::MONO;
3708     rendererOptions.rendererInfo.contentType = ContentType::CONTENT_TYPE_MUSIC;
3709     rendererOptions.rendererInfo.streamUsage = StreamUsage::STREAM_USAGE_MEDIA;
3710     rendererOptions.rendererInfo.rendererFlags = RENDERER_FLAG;
3711 
3712     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
3713     EXPECT_NE(nullptr, audioRenderer);
3714 
3715     bool isStarted = audioRenderer->Start();
3716     EXPECT_EQ(true, isStarted);
3717 
3718     AudioRendererInfo rendererInfo;
3719     audioRenderer->GetRendererInfo(rendererInfo);
3720 
3721     EXPECT_EQ(ContentType::CONTENT_TYPE_MUSIC, rendererInfo.contentType);
3722     EXPECT_EQ(StreamUsage::STREAM_USAGE_MEDIA, rendererInfo.streamUsage);
3723     EXPECT_EQ(RENDERER_FLAG, rendererInfo.rendererFlags);
3724 
3725     audioRenderer->Stop();
3726     audioRenderer->Release();
3727 }
3728 
3729 /**
3730 * @tc.name  : Test GetRendererInfo API via legal state, RENDERER_RELEASED: Call GetRendererInfo after Release.
3731 * @tc.number: Audio_Renderer_GetRendererInfo_003
3732 * @tc.desc  : Test GetRendererInfo interface. Check whether renderer info returns proper data
3733 */
3734 HWTEST(AudioRendererUnitTest, Audio_Renderer_GetRendererInfo_003, TestSize.Level1)
3735 {
3736     AudioRendererOptions rendererOptions;
3737     rendererOptions.streamInfo.samplingRate = AudioSamplingRate::SAMPLE_RATE_96000;
3738     rendererOptions.streamInfo.encoding = AudioEncodingType::ENCODING_PCM;
3739     rendererOptions.streamInfo.format = AudioSampleFormat::SAMPLE_U8;
3740     rendererOptions.streamInfo.channels = AudioChannel::MONO;
3741     rendererOptions.rendererInfo.contentType = ContentType::CONTENT_TYPE_MUSIC;
3742     rendererOptions.rendererInfo.streamUsage = StreamUsage::STREAM_USAGE_MEDIA;
3743     rendererOptions.rendererInfo.rendererFlags = RENDERER_FLAG;
3744 
3745     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
3746     EXPECT_NE(nullptr, audioRenderer);
3747 
3748     bool isReleased = audioRenderer->Release();
3749     EXPECT_EQ(true, isReleased);
3750 
3751     AudioRendererInfo rendererInfo;
3752     audioRenderer->GetRendererInfo(rendererInfo);
3753 
3754     EXPECT_EQ(ContentType::CONTENT_TYPE_MUSIC, rendererInfo.contentType);
3755     EXPECT_EQ(StreamUsage::STREAM_USAGE_MEDIA, rendererInfo.streamUsage);
3756     EXPECT_EQ(RENDERER_FLAG, rendererInfo.rendererFlags);
3757 }
3758 
3759 /**
3760 * @tc.name  : Test GetRendererInfo API via legal state, RENDERER_STOPPED: Call GetRendererInfo after Stop.
3761 * @tc.number: Audio_Renderer_GetRendererInfo_004
3762 * @tc.desc  : Test GetRendererInfo interface. Check whether renderer info returns proper data
3763 */
3764 HWTEST(AudioRendererUnitTest, Audio_Renderer_GetRendererInfo_004, TestSize.Level1)
3765 {
3766     AudioRendererOptions rendererOptions;
3767     rendererOptions.streamInfo.samplingRate = AudioSamplingRate::SAMPLE_RATE_96000;
3768     rendererOptions.streamInfo.encoding = AudioEncodingType::ENCODING_PCM;
3769     rendererOptions.streamInfo.format = AudioSampleFormat::SAMPLE_U8;
3770     rendererOptions.streamInfo.channels = AudioChannel::MONO;
3771     rendererOptions.rendererInfo.contentType = ContentType::CONTENT_TYPE_MUSIC;
3772     rendererOptions.rendererInfo.streamUsage = StreamUsage::STREAM_USAGE_MEDIA;
3773     rendererOptions.rendererInfo.rendererFlags = RENDERER_FLAG;
3774 
3775     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
3776     EXPECT_NE(nullptr, audioRenderer);
3777 
3778     bool isStarted = audioRenderer->Start();
3779     EXPECT_EQ(true, isStarted);
3780 
3781     bool isStopped = audioRenderer->Stop();
3782     EXPECT_EQ(true, isStopped);
3783 
3784     AudioRendererInfo rendererInfo;
3785     audioRenderer->GetRendererInfo(rendererInfo);
3786 
3787     EXPECT_EQ(ContentType::CONTENT_TYPE_MUSIC, rendererInfo.contentType);
3788     EXPECT_EQ(StreamUsage::STREAM_USAGE_MEDIA, rendererInfo.streamUsage);
3789     EXPECT_EQ(RENDERER_FLAG, rendererInfo.rendererFlags);
3790 
3791     audioRenderer->Release();
3792 }
3793 
3794 /**
3795 * @tc.name  : Test GetRendererInfo API Stability
3796 * @tc.number: Audio_Renderer_GetRendererInfo_Stability_001
3797 * @tc.desc  : Test GetRendererInfo interface Stability
3798 */
3799 HWTEST(AudioRendererUnitTest, Audio_Renderer_GetRendererInfo_Stability_001, TestSize.Level1)
3800 {
3801     AudioRendererOptions rendererOptions;
3802     rendererOptions.streamInfo.samplingRate = AudioSamplingRate::SAMPLE_RATE_96000;
3803     rendererOptions.streamInfo.encoding = AudioEncodingType::ENCODING_PCM;
3804     rendererOptions.streamInfo.format = AudioSampleFormat::SAMPLE_U8;
3805     rendererOptions.streamInfo.channels = AudioChannel::MONO;
3806     rendererOptions.rendererInfo.contentType = ContentType::CONTENT_TYPE_MUSIC;
3807     rendererOptions.rendererInfo.streamUsage = StreamUsage::STREAM_USAGE_MEDIA;
3808     rendererOptions.rendererInfo.rendererFlags = RENDERER_FLAG;
3809 
3810     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
3811     EXPECT_NE(nullptr, audioRenderer);
3812 
3813     for (int i = 0; i < VALUE_THOUSAND; i++) {
3814 
3815         AudioRendererInfo rendererInfo;
3816         audioRenderer->GetRendererInfo(rendererInfo);
3817 
3818         EXPECT_EQ(ContentType::CONTENT_TYPE_MUSIC, rendererInfo.contentType);
3819         EXPECT_EQ(StreamUsage::STREAM_USAGE_MEDIA, rendererInfo.streamUsage);
3820         EXPECT_EQ(RENDERER_FLAG, rendererInfo.rendererFlags);
3821     }
3822     audioRenderer->Release();
3823 }
3824 
3825 /**
3826 * @tc.name  : Test GetStreamInfo API after calling create
3827 * @tc.number: Audio_Renderer_GetStreamInfo_001
3828 * @tc.desc  : Test GetStreamInfo interface. Check whether stream related data is returned correctly
3829 */
3830 HWTEST(AudioRendererUnitTest, Audio_Renderer_GetStreamInfo_001, TestSize.Level1)
3831 {
3832     AudioRendererOptions rendererOptions;
3833     rendererOptions.streamInfo.samplingRate = AudioSamplingRate::SAMPLE_RATE_96000;
3834     rendererOptions.streamInfo.encoding = AudioEncodingType::ENCODING_PCM;
3835     rendererOptions.streamInfo.format = AudioSampleFormat::SAMPLE_U8;
3836     rendererOptions.streamInfo.channels = AudioChannel::MONO;
3837     rendererOptions.rendererInfo.contentType = ContentType::CONTENT_TYPE_MUSIC;
3838     rendererOptions.rendererInfo.streamUsage = StreamUsage::STREAM_USAGE_MEDIA;
3839     rendererOptions.rendererInfo.rendererFlags = RENDERER_FLAG;
3840 
3841     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
3842     EXPECT_NE(nullptr, audioRenderer);
3843 
3844     AudioStreamInfo streamInfo;
3845     audioRenderer->GetStreamInfo(streamInfo);
3846 
3847     EXPECT_EQ(AudioSamplingRate::SAMPLE_RATE_96000, streamInfo.samplingRate);
3848     EXPECT_EQ(AudioEncodingType::ENCODING_PCM, streamInfo.encoding);
3849     EXPECT_EQ(AudioSampleFormat::SAMPLE_U8, streamInfo.format);
3850     EXPECT_EQ(AudioChannel::MONO, streamInfo.channels);
3851     audioRenderer->Release();
3852 }
3853 
3854 /**
3855 * @tc.name  : Test GetStreamInfo via legal state,  RENDERER_RUNNING: GetStreamInfo after Start.
3856 * @tc.number: Audio_Renderer_GetStreamInfo_002
3857 * @tc.desc  : Test GetStreamInfo interface. Check whether stream related data is returned correctly
3858 */
3859 HWTEST(AudioRendererUnitTest, Audio_Renderer_GetStreamInfo_002, TestSize.Level1)
3860 {
3861     int32_t ret = -1;
3862 
3863     AudioRendererOptions rendererOptions;
3864     rendererOptions.streamInfo.samplingRate = AudioSamplingRate::SAMPLE_RATE_96000;
3865     rendererOptions.streamInfo.encoding = AudioEncodingType::ENCODING_PCM;
3866     rendererOptions.streamInfo.format = AudioSampleFormat::SAMPLE_U8;
3867     rendererOptions.streamInfo.channels = AudioChannel::MONO;
3868     rendererOptions.rendererInfo.contentType = ContentType::CONTENT_TYPE_MUSIC;
3869     rendererOptions.rendererInfo.streamUsage = StreamUsage::STREAM_USAGE_MEDIA;
3870     rendererOptions.rendererInfo.rendererFlags = RENDERER_FLAG;
3871 
3872     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
3873     EXPECT_NE(nullptr, audioRenderer);
3874 
3875     bool isStarted = audioRenderer->Start();
3876     EXPECT_EQ(true, isStarted);
3877 
3878     AudioStreamInfo streamInfo;
3879     ret = audioRenderer->GetStreamInfo(streamInfo);
3880 
3881     EXPECT_EQ(SUCCESS, ret);
3882     EXPECT_EQ(AudioSamplingRate::SAMPLE_RATE_96000, streamInfo.samplingRate);
3883     EXPECT_EQ(AudioEncodingType::ENCODING_PCM, streamInfo.encoding);
3884     EXPECT_EQ(AudioSampleFormat::SAMPLE_U8, streamInfo.format);
3885     EXPECT_EQ(AudioChannel::MONO, streamInfo.channels);
3886 
3887     audioRenderer->Stop();
3888     audioRenderer->Release();
3889 }
3890 
3891 /**
3892 * @tc.name  : Test GetStreamInfo via illegal state, RENDERER_RELEASED: GetStreamInfo after Release.
3893 * @tc.number: Audio_Renderer_GetStreamInfo_003
3894 * @tc.desc  : Test GetStreamInfo interface. Returns error code, if the renderer state is RENDERER_RELEASED.
3895 */
3896 HWTEST(AudioRendererUnitTest, Audio_Renderer_GetStreamInfo_003, TestSize.Level1)
3897 {
3898     int32_t ret = -1;
3899 
3900     AudioRendererOptions rendererOptions;
3901     rendererOptions.streamInfo.samplingRate = AudioSamplingRate::SAMPLE_RATE_96000;
3902     rendererOptions.streamInfo.encoding = AudioEncodingType::ENCODING_PCM;
3903     rendererOptions.streamInfo.format = AudioSampleFormat::SAMPLE_U8;
3904     rendererOptions.streamInfo.channels = AudioChannel::MONO;
3905     rendererOptions.rendererInfo.contentType = ContentType::CONTENT_TYPE_MUSIC;
3906     rendererOptions.rendererInfo.streamUsage = StreamUsage::STREAM_USAGE_MEDIA;
3907     rendererOptions.rendererInfo.rendererFlags = RENDERER_FLAG;
3908 
3909     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
3910     EXPECT_NE(nullptr, audioRenderer);
3911 
3912     bool isReleased = audioRenderer->Release();
3913     EXPECT_EQ(true, isReleased);
3914 
3915     AudioStreamInfo streamInfo;
3916     ret = audioRenderer->GetStreamInfo(streamInfo);
3917 
3918     EXPECT_EQ(ERR_OPERATION_FAILED, ret);
3919 }
3920 
3921 /**
3922 * @tc.name  : Test GetStreamInfo via legal state, RENDERER_STOPPED: GetStreamInfo after Stop.
3923 * @tc.number: Audio_Renderer_GetStreamInfo_004
3924 * @tc.desc  : Test GetStreamInfo interface. Check whether stream related data is returned correctly
3925 */
3926 HWTEST(AudioRendererUnitTest, Audio_Renderer_GetStreamInfo_004, TestSize.Level1)
3927 {
3928     int32_t ret = -1;
3929 
3930     AudioRendererOptions rendererOptions;
3931     rendererOptions.streamInfo.samplingRate = AudioSamplingRate::SAMPLE_RATE_96000;
3932     rendererOptions.streamInfo.encoding = AudioEncodingType::ENCODING_PCM;
3933     rendererOptions.streamInfo.format = AudioSampleFormat::SAMPLE_U8;
3934     rendererOptions.streamInfo.channels = AudioChannel::MONO;
3935     rendererOptions.rendererInfo.contentType = ContentType::CONTENT_TYPE_MUSIC;
3936     rendererOptions.rendererInfo.streamUsage = StreamUsage::STREAM_USAGE_MEDIA;
3937     rendererOptions.rendererInfo.rendererFlags = RENDERER_FLAG;
3938 
3939     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
3940     EXPECT_NE(nullptr, audioRenderer);
3941 
3942     bool isStarted = audioRenderer->Start();
3943     EXPECT_EQ(true, isStarted);
3944 
3945     bool isStopped = audioRenderer->Stop();
3946     EXPECT_EQ(true, isStopped);
3947 
3948     AudioStreamInfo streamInfo;
3949     ret = audioRenderer->GetStreamInfo(streamInfo);
3950 
3951     EXPECT_EQ(SUCCESS, ret);
3952     EXPECT_EQ(AudioSamplingRate::SAMPLE_RATE_96000, streamInfo.samplingRate);
3953     EXPECT_EQ(AudioEncodingType::ENCODING_PCM, streamInfo.encoding);
3954     EXPECT_EQ(AudioSampleFormat::SAMPLE_U8, streamInfo.format);
3955     EXPECT_EQ(AudioChannel::MONO, streamInfo.channels);
3956 
3957     audioRenderer->Release();
3958 }
3959 
3960 /**
3961 * @tc.name  : Test GetStreamInfo via legal state, RENDERER_PAUSED: GetStreamInfo after Pause.
3962 * @tc.number: Audio_Renderer_GetStreamInfo_005
3963 * @tc.desc  : Test GetStreamInfo interface. Check whether stream related data is returned correctly
3964 */
3965 HWTEST(AudioRendererUnitTest, Audio_Renderer_GetStreamInfo_005, TestSize.Level1)
3966 {
3967     int32_t ret = -1;
3968 
3969     AudioRendererOptions rendererOptions;
3970     rendererOptions.streamInfo.samplingRate = AudioSamplingRate::SAMPLE_RATE_96000;
3971     rendererOptions.streamInfo.encoding = AudioEncodingType::ENCODING_PCM;
3972     rendererOptions.streamInfo.format = AudioSampleFormat::SAMPLE_U8;
3973     rendererOptions.streamInfo.channels = AudioChannel::MONO;
3974     rendererOptions.rendererInfo.contentType = ContentType::CONTENT_TYPE_MUSIC;
3975     rendererOptions.rendererInfo.streamUsage = StreamUsage::STREAM_USAGE_MEDIA;
3976     rendererOptions.rendererInfo.rendererFlags = RENDERER_FLAG;
3977 
3978     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
3979     EXPECT_NE(nullptr, audioRenderer);
3980 
3981     bool isStarted = audioRenderer->Start();
3982     EXPECT_EQ(true, isStarted);
3983 
3984     bool isPaused = audioRenderer->Pause();
3985     EXPECT_EQ(true, isPaused);
3986 
3987     AudioStreamInfo streamInfo;
3988     ret = audioRenderer->GetStreamInfo(streamInfo);
3989 
3990     EXPECT_EQ(SUCCESS, ret);
3991     EXPECT_EQ(AudioSamplingRate::SAMPLE_RATE_96000, streamInfo.samplingRate);
3992     EXPECT_EQ(AudioEncodingType::ENCODING_PCM, streamInfo.encoding);
3993     EXPECT_EQ(AudioSampleFormat::SAMPLE_U8, streamInfo.format);
3994     EXPECT_EQ(AudioChannel::MONO, streamInfo.channels);
3995 
3996     audioRenderer->Stop();
3997     audioRenderer->Release();
3998 }
3999 
4000 /**
4001 * @tc.name  : Test GetStreamInfo API stability.
4002 * @tc.number: Audio_Renderer_GetStreamInfo_Stability_001
4003 * @tc.desc  : Test GetStreamInfo interface stability
4004 */
4005 HWTEST(AudioRendererUnitTest, Audio_Renderer_GetStreamInfo_Stability_001, TestSize.Level1)
4006 {
4007     int32_t ret = -1;
4008 
4009     AudioRendererOptions rendererOptions;
4010     rendererOptions.streamInfo.samplingRate = AudioSamplingRate::SAMPLE_RATE_96000;
4011     rendererOptions.streamInfo.encoding = AudioEncodingType::ENCODING_PCM;
4012     rendererOptions.streamInfo.format = AudioSampleFormat::SAMPLE_U8;
4013     rendererOptions.streamInfo.channels = AudioChannel::MONO;
4014     rendererOptions.rendererInfo.contentType = ContentType::CONTENT_TYPE_MUSIC;
4015     rendererOptions.rendererInfo.streamUsage = StreamUsage::STREAM_USAGE_MEDIA;
4016     rendererOptions.rendererInfo.rendererFlags = RENDERER_FLAG;
4017 
4018     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
4019     EXPECT_NE(nullptr, audioRenderer);
4020 
4021     bool isStarted = audioRenderer->Start();
4022     EXPECT_EQ(true, isStarted);
4023 
4024 
4025     for (int i = 0; i < VALUE_THOUSAND; i++) {
4026         AudioStreamInfo streamInfo;
4027         ret = audioRenderer->GetStreamInfo(streamInfo);
4028         EXPECT_EQ(SUCCESS, ret);
4029     }
4030 
4031     audioRenderer->Stop();
4032     audioRenderer->Release();
4033 }
4034 
4035 /**
4036 * @tc.name  : Test SetBufferDuration API
4037 * @tc.number: Audio_Renderer_SetBufferDuration_001
4038 * @tc.desc  : Test SetBufferDuration interface. Check whether valid parameters are accepted.
4039 */
4040 HWTEST(AudioRendererUnitTest, Audio_Renderer_SetBufferDuration_001, TestSize.Level1)
4041 {
4042     int32_t ret = -1;
4043 
4044     AudioRendererOptions rendererOptions;
4045     rendererOptions.streamInfo.samplingRate = AudioSamplingRate::SAMPLE_RATE_96000;
4046     rendererOptions.streamInfo.encoding = AudioEncodingType::ENCODING_PCM;
4047     rendererOptions.streamInfo.format = AudioSampleFormat::SAMPLE_U8;
4048     rendererOptions.streamInfo.channels = AudioChannel::MONO;
4049     rendererOptions.rendererInfo.contentType = ContentType::CONTENT_TYPE_MUSIC;
4050     rendererOptions.rendererInfo.streamUsage = StreamUsage::STREAM_USAGE_MEDIA;
4051     rendererOptions.rendererInfo.rendererFlags = RENDERER_FLAG;
4052 
4053     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
4054     EXPECT_NE(nullptr, audioRenderer);
4055 
4056     ret = audioRenderer->SetBufferDuration(BUFFER_DURATION_FIVE);
4057     EXPECT_EQ(SUCCESS, ret);
4058 
4059     ret = audioRenderer->SetBufferDuration(BUFFER_DURATION_TEN);
4060     EXPECT_EQ(SUCCESS, ret);
4061 
4062     ret = audioRenderer->SetBufferDuration(BUFFER_DURATION_FIFTEEN);
4063     EXPECT_EQ(SUCCESS, ret);
4064 
4065     ret = audioRenderer->SetBufferDuration(BUFFER_DURATION_TWENTY);
4066     EXPECT_EQ(SUCCESS, ret);
4067 }
4068 
4069 /**
4070 * @tc.name  : Test SetBufferDuration API
4071 * @tc.number: Audio_Renderer_SetBufferDuration_002
4072 * @tc.desc  : Test SetBufferDuration interface. Check whether invalid parameters are rejected.
4073 */
4074 HWTEST(AudioRendererUnitTest, Audio_Renderer_SetBufferDuration_002, TestSize.Level1)
4075 {
4076     int32_t ret = -1;
4077 
4078     AudioRendererOptions rendererOptions;
4079     rendererOptions.streamInfo.samplingRate = AudioSamplingRate::SAMPLE_RATE_96000;
4080     rendererOptions.streamInfo.encoding = AudioEncodingType::ENCODING_PCM;
4081     rendererOptions.streamInfo.format = AudioSampleFormat::SAMPLE_U8;
4082     rendererOptions.streamInfo.channels = AudioChannel::MONO;
4083     rendererOptions.rendererInfo.contentType = ContentType::CONTENT_TYPE_MUSIC;
4084     rendererOptions.rendererInfo.streamUsage = StreamUsage::STREAM_USAGE_MEDIA;
4085     rendererOptions.rendererInfo.rendererFlags = RENDERER_FLAG;
4086 
4087     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
4088     EXPECT_NE(nullptr, audioRenderer);
4089 
4090     ret = audioRenderer->SetBufferDuration(VALUE_NEGATIVE);
4091     EXPECT_NE(SUCCESS, ret);
4092 
4093     ret = audioRenderer->SetBufferDuration(VALUE_ZERO);
4094     EXPECT_NE(SUCCESS, ret);
4095 
4096     ret = audioRenderer->SetBufferDuration(VALUE_HUNDRED);
4097     EXPECT_NE(SUCCESS, ret);
4098 }
4099 
4100 /**
4101 * @tc.name  : Test SetRendererPositionCallback API
4102 * @tc.number: Audio_Renderer_SetRendererPositionCallback_001
4103 * @tc.desc  : Test SetRendererPositionCallback interface to check set position callback is success for valid callback.
4104 */
4105 HWTEST(AudioRendererUnitTest, Audio_Renderer_SetRendererPositionCallback_001, TestSize.Level1)
4106 {
4107     int32_t ret = -1;
4108 
4109     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(STREAM_MUSIC);
4110     ASSERT_NE(nullptr, audioRenderer);
4111 
4112     shared_ptr<RendererPositionCallbackTest> positionCB = std::make_shared<RendererPositionCallbackTest>();
4113     ret = audioRenderer->SetRendererPositionCallback(VALUE_THOUSAND, positionCB);
4114     EXPECT_EQ(SUCCESS, ret);
4115 }
4116 
4117 /**
4118 * @tc.name  : Test SetRendererPositionCallback API
4119 * @tc.number: Audio_Renderer_SetRendererPositionCallback_002
4120 * @tc.desc  : Test SetRendererPositionCallback interface again after unregister.
4121 */
4122 HWTEST(AudioRendererUnitTest, Audio_Renderer_SetRendererPositionCallback_002, TestSize.Level1)
4123 {
4124     int32_t ret = -1;
4125 
4126     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(STREAM_MUSIC);
4127     ASSERT_NE(nullptr, audioRenderer);
4128 
4129     shared_ptr<RendererPositionCallbackTest> positionCB1 = std::make_shared<RendererPositionCallbackTest>();
4130     ret = audioRenderer->SetRendererPositionCallback(VALUE_THOUSAND, positionCB1);
4131     EXPECT_EQ(SUCCESS, ret);
4132 
4133     audioRenderer->UnsetRendererPositionCallback();
4134 
4135     shared_ptr<RendererPositionCallbackTest> positionCB2 = std::make_shared<RendererPositionCallbackTest>();
4136     ret = audioRenderer->SetRendererPositionCallback(VALUE_THOUSAND, positionCB2);
4137     EXPECT_EQ(SUCCESS, ret);
4138 }
4139 
4140 /**
4141 * @tc.name  : Test SetRendererPositionCallback API
4142 * @tc.number: Audio_Renderer_SetRendererPositionCallback_003
4143 * @tc.desc  : Test SetRendererPositionCallback interface with null callback.
4144 */
4145 HWTEST(AudioRendererUnitTest, Audio_Renderer_SetRendererPositionCallback_003, TestSize.Level1)
4146 {
4147     int32_t ret = -1;
4148 
4149     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(STREAM_MUSIC);
4150     ASSERT_NE(nullptr, audioRenderer);
4151 
4152     ret = audioRenderer->SetRendererPositionCallback(VALUE_THOUSAND, nullptr);
4153     EXPECT_NE(SUCCESS, ret);
4154 }
4155 
4156 /**
4157 * @tc.name  : Test SetRendererPositionCallback API
4158 * @tc.number: Audio_Renderer_SetRendererPositionCallback_004
4159 * @tc.desc  : Test SetRendererPositionCallback interface with invalid parameter.
4160 */
4161 HWTEST(AudioRendererUnitTest, Audio_Renderer_SetRendererPositionCallback_004, TestSize.Level1)
4162 {
4163     int32_t ret = -1;
4164 
4165     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(STREAM_MUSIC);
4166     ASSERT_NE(nullptr, audioRenderer);
4167 
4168     shared_ptr<RendererPositionCallbackTest> positionCB = std::make_shared<RendererPositionCallbackTest>();
4169     ret = audioRenderer->SetRendererPositionCallback(VALUE_ZERO, positionCB);
4170     EXPECT_NE(SUCCESS, ret);
4171 
4172     ret = audioRenderer->SetRendererPositionCallback(VALUE_NEGATIVE, positionCB);
4173     EXPECT_NE(SUCCESS, ret);
4174 }
4175 
4176 /**
4177 * @tc.name  : Test SetRendererPeriodPositionCallback API
4178 * @tc.number: Audio_Renderer_SetRendererPeriodPositionCallback_001
4179 * @tc.desc  : Test SetRendererPeriodPositionCallback interface to check set period position
4180 *             callback is success for valid callback.
4181 */
4182 HWTEST(AudioRendererUnitTest, Audio_Renderer_SetRendererPeriodPositionCallback_001, TestSize.Level1)
4183 {
4184     int32_t ret = -1;
4185 
4186     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(STREAM_MUSIC);
4187     ASSERT_NE(nullptr, audioRenderer);
4188 
4189     shared_ptr<RendererPeriodPositionCallbackTest> positionCB = std::make_shared<RendererPeriodPositionCallbackTest>();
4190     ret = audioRenderer->SetRendererPeriodPositionCallback(VALUE_THOUSAND, positionCB);
4191     EXPECT_EQ(SUCCESS, ret);
4192 }
4193 
4194 /**
4195 * @tc.name  : Test SetRendererPeriodPositionCallback API
4196 * @tc.number: Audio_Renderer_SetRendererPeriodPositionCallback_002
4197 * @tc.desc  : Test SetRendererPeriodPositionCallback interface again after unregister.
4198 */
4199 HWTEST(AudioRendererUnitTest, Audio_Renderer_SetRendererPeriodPositionCallback_002, TestSize.Level1)
4200 {
4201     int32_t ret = -1;
4202 
4203     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(STREAM_MUSIC);
4204     ASSERT_NE(nullptr, audioRenderer);
4205 
4206     shared_ptr<RendererPeriodPositionCallbackTest> positionCB1 = std::make_shared<RendererPeriodPositionCallbackTest>();
4207     ret = audioRenderer->SetRendererPeriodPositionCallback(VALUE_THOUSAND, positionCB1);
4208     EXPECT_EQ(SUCCESS, ret);
4209 
4210     audioRenderer->UnsetRendererPeriodPositionCallback();
4211 
4212     shared_ptr<RendererPeriodPositionCallbackTest> positionCB2 = std::make_shared<RendererPeriodPositionCallbackTest>();
4213     ret = audioRenderer->SetRendererPeriodPositionCallback(VALUE_THOUSAND, positionCB2);
4214     EXPECT_EQ(SUCCESS, ret);
4215 }
4216 
4217 /**
4218 * @tc.name  : Test SetRendererPeriodPositionCallback API
4219 * @tc.number: Audio_Renderer_SetRendererPeriodPositionCallback_003
4220 * @tc.desc  : Test SetRendererPeriodPositionCallback interface with null callback.
4221 */
4222 HWTEST(AudioRendererUnitTest, Audio_Renderer_SetRendererPeriodPositionCallback_003, TestSize.Level1)
4223 {
4224     int32_t ret = -1;
4225 
4226     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(STREAM_MUSIC);
4227     ASSERT_NE(nullptr, audioRenderer);
4228 
4229     ret = audioRenderer->SetRendererPeriodPositionCallback(VALUE_THOUSAND, nullptr);
4230     EXPECT_NE(SUCCESS, ret);
4231 }
4232 
4233 /**
4234 * @tc.name  : Test SetRendererPeriodPositionCallback API
4235 * @tc.number: Audio_Renderer_SetRendererPeriodPositionCallback_004
4236 * @tc.desc  : Test SetRendererPeriodPositionCallback interface with invalid parameter.
4237 */
4238 HWTEST(AudioRendererUnitTest, Audio_Renderer_SetRendererPeriodPositionCallback_004, TestSize.Level1)
4239 {
4240     int32_t ret = -1;
4241 
4242     unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(STREAM_MUSIC);
4243     ASSERT_NE(nullptr, audioRenderer);
4244 
4245     shared_ptr<RendererPeriodPositionCallbackTest> positionCB = std::make_shared<RendererPeriodPositionCallbackTest>();
4246     ret = audioRenderer->SetRendererPeriodPositionCallback(VALUE_ZERO, positionCB);
4247     EXPECT_NE(SUCCESS, ret);
4248 
4249     ret = audioRenderer->SetRendererPeriodPositionCallback(VALUE_NEGATIVE, positionCB);
4250     EXPECT_NE(SUCCESS, ret);
4251 }
4252 } // namespace AudioStandard
4253 } // namespace OHOS
4254