1 /*
2  * Copyright (c) 2023 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 "soundpool_unit_test.h"
17 #include "media_errors.h"
18 
19 using namespace OHOS;
20 using namespace OHOS::Media;
21 using namespace testing::ext;
22 using namespace std;
23 
24 static const std::string g_fileName[6] = {
25     {"/data/test/test_06.ogg"},
26     {"/data/test/test_02.mp3"},
27     {"/data/test/test_01.mp3"},
28     {"/data/test/test_05.ogg"},
29     {"/data/test/test_03.mp3"},
30     {"/data/test/test_04.mp3"},
31 };
32 
33 namespace OHOS {
34 namespace Media {
SetUpTestCase(void)35 void SoundPoolUnitTest::SetUpTestCase(void) {}
36 
TearDownTestCase(void)37 void SoundPoolUnitTest::TearDownTestCase(void) {}
38 
SetUp(void)39 void SoundPoolUnitTest::SetUp(void)
40 {
41     soundPool_ = std::make_shared<SoundPoolMock>();
42     ASSERT_NE(nullptr, soundPool_);
43 }
44 
TearDown(void)45 void SoundPoolUnitTest::TearDown(void)
46 {
47     for (auto soundId : soundIDs_) {
48         if (soundId != 0) {
49             soundId = 0;
50         }
51     }
52     for (auto streamId : streamIDs_) {
53         if (streamId != 0) {
54             streamId = 0;
55         }
56     }
57     for (auto fd : fds_) {
58         if (fd != 0) {
59             fd = 0;
60         }
61     }
62     if (loadNum_ != 0 || playNum_ != 0) {
63         loadNum_ = 0;
64         playNum_ = 0;
65     }
66 
67     if (soundPool_ != nullptr) {
68         int32_t ret = soundPool_->Release();
69         soundPool_ = nullptr;
70         EXPECT_EQ(MSERR_OK, ret);
71     }
72     sleep(waitTime1);
73 }
74 
create(int maxStreams)75 void SoundPoolUnitTest::create(int maxStreams)
76 {
77     AudioStandard::AudioRendererInfo audioRenderInfo;
78     audioRenderInfo.contentType = CONTENT_TYPE_MUSIC;
79     audioRenderInfo.streamUsage = STREAM_USAGE_MUSIC;
80     audioRenderInfo.rendererFlags = 0;
81     if (soundPool_ == nullptr) {
82         cout << "create soundpool failed" << endl;
83     } else {
84         EXPECT_TRUE(soundPool_->CreateSoundPool(maxStreams, audioRenderInfo));
85     }
86 }
87 
loadUrl(std::string fileName,int32_t loadNum)88 void SoundPoolUnitTest::loadUrl(std::string fileName, int32_t loadNum)
89 {
90     fds_[loadNum] = open(fileName.c_str(), O_RDWR);
91     if (fds_[loadNum] > 0) {
92         std::string url = "fd://" + std::to_string(fds_[loadNum]);
93         soundIDs_[loadNum] = soundPool_->Load(url);
94     } else {
95         cout << "Url open failed, g_fileName " << fileName.c_str() << ", fd: " << fds_[loadNum] << endl;
96     }
97     EXPECT_GT(soundIDs_[loadNum], 0);
98 }
99 
loadFd(std::string fileName,int32_t loadNum)100 void SoundPoolUnitTest::loadFd(std::string fileName, int32_t loadNum)
101 {
102     fds_[loadNum] = open(fileName.c_str(), O_RDONLY);
103     if (fds_[loadNum] < 0) {
104         cout << "Fd open failed, g_fileName " << fileName.c_str() << ", Fd: " << fds_[loadNum] << endl;
105     }
106     size_t filesize = soundPool_->GetFileSize(fileName);
107     EXPECT_NE(filesize, 0);
108     soundIDs_[loadNum] = soundPool_->Load(fds_[loadNum], 0, filesize);
109     EXPECT_GT(soundIDs_[loadNum], 0);
110 }
111 
112 /**
113  * @tc.name: soundpool_function_001
114  * @tc.desc: function test Load Url one more time
115  * @tc.type: FUNC
116  * @tc.require:
117  */
118 HWTEST_F(SoundPoolUnitTest, soundpool_function_001, TestSize.Level2)
119 {
120     MEDIA_LOGI("soundpool_unit_test soundpool_function_001 before");
121     int maxStreams = 3;
122     create(maxStreams);
123     std::shared_ptr<SoundPoolCallbackTest> cb = std::make_shared<SoundPoolCallbackTest>(soundPool_);
124     int32_t ret = soundPool_->SetSoundPoolCallback(cb);
125     if (ret != 0) {
126         cout << "set callback failed" << endl;
127     }
128     loadUrl(g_fileName[loadNum_], loadNum_);
129     loadNum_++;
130     loadUrl(g_fileName[loadNum_], loadNum_);
131     loadNum_++;
132     loadUrl(g_fileName[1], loadNum_);
133     loadNum_++;
134     loadUrl(g_fileName[1], loadNum_);
135     sleep(waitTime3);
136     if (cb == nullptr) {
137         cout << "Invalid cb to get loaded sound num." << endl;
138         return;
139     }
140     while (true) {
141         if (cb->GetHaveLoadedSoundNum() == 4) {
142             cout << "All sound loaded url break. loaded sound num = " << cb->GetHaveLoadedSoundNum()  << endl;
143             cb->ResetHaveLoadedSoundNum();
144             break;
145         }
146     }
147     MEDIA_LOGI("soundpool_unit_test soundpool_function_001 after");
148 }
149 
150 /**
151  * @tc.name: soundpool_function_002
152  * @tc.desc: function test Load Url with invalid path
153  * @tc.type: FUNC
154  * @tc.require:
155  */
156 HWTEST_F(SoundPoolUnitTest, soundpool_function_002, TestSize.Level2)
157 {
158     MEDIA_LOGI("soundpool_unit_test soundpool_function_002 before");
159     int maxStreams = 3;
160     create(maxStreams);
161     std::shared_ptr<SoundPoolCallbackTest> cb = std::make_shared<SoundPoolCallbackTest>(soundPool_);
162     int32_t ret = soundPool_->SetSoundPoolCallback(cb);
163     if (ret != 0) {
164         cout << "set callback failed" << endl;
165     }
166     // test invalid path
167     std::string fileName = "/data/test/test_05.mp3";
168     fds_[loadNum_] = open(fileName.c_str(), O_RDWR);
169     std::string url = "fd://" + std::to_string(fds_[loadNum_]);
170     soundIDs_[loadNum_] = soundPool_->Load(url);
171     sleep(waitTime3);
172     if (fds_[loadNum_] == -1) {
173         cout << "Url open a invalid path: " << fileName.c_str() << endl;
174     }
175     EXPECT_EQ(soundIDs_[loadNum_], -1);
176     if (cb == nullptr) {
177         cout << "Invalid cb to get loaded sound num." << endl;
178         return;
179     }
180     while (true) {
181         if (cb->GetHaveLoadedSoundNum() == 1) {
182             cout << "All sound loaded url break. loaded sound num = " << cb->GetHaveLoadedSoundNum()  << endl;
183             cb->ResetHaveLoadedSoundNum();
184             break;
185         } else {
186             cout << "Sound loaded url error. loaded sound num = " << cb->GetHaveLoadedSoundNum()  << endl;
187             break;
188         }
189     }
190     MEDIA_LOGI("soundpool_unit_test soundpool_function_002 after");
191 }
192 
193 /**
194  * @tc.name: soundpool_function_003
195  * @tc.desc: function test Load Url when no callback
196  * @tc.type: FUNC
197  * @tc.require:
198  */
199 HWTEST_F(SoundPoolUnitTest, soundpool_function_003, TestSize.Level2)
200 {
201     MEDIA_LOGI("soundpool_unit_test soundpool_function_003 before");
202     int maxStreams = 3;
203     create(maxStreams);
204     // test no callback to load
205     loadUrl(g_fileName[loadNum_], loadNum_);
206     sleep(waitTime3);
207     MEDIA_LOGI("soundpool_unit_test soundpool_function_003 after");
208 }
209 
210 /**
211  * @tc.name: soundpool_function_004
212  * @tc.desc: function test Load Url after play
213  * @tc.type: FUNC
214  * @tc.require:
215  */
216 HWTEST_F(SoundPoolUnitTest, soundpool_function_004, TestSize.Level2)
217 {
218     MEDIA_LOGI("soundpool_unit_test soundpool_function_004 before");
219     int maxStreams = 3;
220     create(maxStreams);
221     std::shared_ptr<SoundPoolCallbackTest> cb = std::make_shared<SoundPoolCallbackTest>(soundPool_);
222     int32_t ret = soundPool_->SetSoundPoolCallback(cb);
223     if (ret != 0) {
224         cout << "set callback failed" << endl;
225     }
226     loadUrl(g_fileName[loadNum_], loadNum_);
227     sleep(waitTime3);
228     if (cb == nullptr) {
229         cout << "Invalid cb to get loaded sound num." << endl;
230         return;
231     }
232     while (true) {
233         if (cb->GetHaveLoadedSoundNum() == 1) {
234             cout << "All sound loaded url break. loaded sound num = " << cb->GetHaveLoadedSoundNum()  << endl;
235             cb->ResetHaveLoadedSoundNum();
236             break;
237         }
238     }
239     struct PlayParams playParameters;
240     if (soundIDs_[loadNum_] > 0) {
241         soundPool_->Play(soundIDs_[loadNum_], playParameters);
242         sleep(waitTime1);
243         loadNum_++;
244         loadUrl(g_fileName[loadNum_], loadNum_);
245         sleep(waitTime3);
246     } else {
247         cout << "Get soundId failed, please try to get soundId: " << soundIDs_[loadNum_] << endl;
248     }
249     if (cb == nullptr) {
250         cout << "Invalid cb to get played sound num." << endl;
251         return;
252     }
253     cb->ResetHavePlayedSoundNum();
254     MEDIA_LOGI("soundpool_unit_test soundpool_function_004 after");
255 }
256 
257 /**
258  * @tc.name: soundpool_function_005
259  * @tc.desc: function test Load Fd one more time
260  * @tc.type: FUNC
261  * @tc.require:
262  */
263 HWTEST_F(SoundPoolUnitTest, soundpool_function_005, TestSize.Level2)
264 {
265     MEDIA_LOGI("soundpool_unit_test soundpool_function_005 before");
266     int maxStreams = 3;
267     create(maxStreams);
268     std::shared_ptr<SoundPoolCallbackTest> cb = std::make_shared<SoundPoolCallbackTest>(soundPool_);
269     int32_t ret = soundPool_->SetSoundPoolCallback(cb);
270     if (ret != 0) {
271         cout << "set callback failed" << endl;
272     }
273     loadFd(g_fileName[loadNum_], loadNum_);
274     loadNum_++;
275     loadFd(g_fileName[loadNum_], loadNum_);
276     loadNum_++;
277     loadFd(g_fileName[1], loadNum_);
278     loadNum_++;
279     loadFd(g_fileName[1], loadNum_);
280     sleep(waitTime3);
281     if (cb == nullptr) {
282         cout << "Invalid cb to get loaded sound num." << endl;
283         return;
284     }
285     while (true) {
286         if (cb->GetHaveLoadedSoundNum() == 4) {
287             cout << "All sound loaded Fd break. loaded sound num = " << cb->GetHaveLoadedSoundNum()  << endl;
288             cb->ResetHaveLoadedSoundNum();
289             break;
290         }
291     }
292     MEDIA_LOGI("soundpool_unit_test soundpool_function_005 after");
293 }
294 
295 /**
296  * @tc.name: soundpool_function_006
297  * @tc.desc: function test Load Fd with invalid path
298  * @tc.type: FUNC
299  * @tc.require:
300  */
301 HWTEST_F(SoundPoolUnitTest, soundpool_function_006, TestSize.Level2)
302 {
303     MEDIA_LOGI("soundpool_unit_test soundpool_function_006 before");
304     int maxStreams = 3;
305     create(maxStreams);
306     std::shared_ptr<SoundPoolCallbackTest> cb = std::make_shared<SoundPoolCallbackTest>(soundPool_);
307     int32_t ret = soundPool_->SetSoundPoolCallback(cb);
308     if (ret != 0) {
309         cout << "set callback failed" << endl;
310     }
311     std::string fileName = "/data/test/test_05.mp3";
312     fds_[loadNum_] = open(fileName.c_str(), O_RDONLY);
313     size_t filesize = soundPool_->GetFileSize(fileName);
314     EXPECT_EQ(filesize, 0);
315     soundIDs_[loadNum_] = soundPool_->Load(fds_[loadNum_], 0, filesize);
316     sleep(waitTime3);
317     if (fds_[loadNum_] == -1) {
318         cout << "Fd open a invalid path: " << fileName.c_str() << endl;
319     }
320     EXPECT_EQ(soundIDs_[loadNum_], -1);
321     if (cb == nullptr) {
322         cout << "Invalid cb to get loaded sound num." << endl;
323         return;
324     }
325     while (true) {
326         if (cb->GetHaveLoadedSoundNum() == 1) {
327             cout << "All sound loaded Fd break. loaded sound num = " << cb->GetHaveLoadedSoundNum()  << endl;
328             cb->ResetHaveLoadedSoundNum();
329             break;
330         } else {
331             cout << "Sound loaded error Fd. loaded sound num = " << cb->GetHaveLoadedSoundNum()  << endl;
332             break;
333         }
334     }
335     MEDIA_LOGI("soundpool_unit_test soundpool_function_006 after");
336 }
337 
338 /**
339  * @tc.name: soundpool_function_007
340  * @tc.desc: function test Load Fd when no callback
341  * @tc.type: FUNC
342  * @tc.require:
343  */
344 HWTEST_F(SoundPoolUnitTest, soundpool_function_007, TestSize.Level2)
345 {
346     MEDIA_LOGI("soundpool_unit_test soundpool_function_007 before");
347     int maxStreams = 3;
348     create(maxStreams);
349     // test no callback to load
350     loadFd(g_fileName[loadNum_], loadNum_);
351     sleep(waitTime3);
352     MEDIA_LOGI("soundpool_unit_test soundpool_function_007 after");
353 }
354 
355 /**
356  * @tc.name: soundpool_function_008
357  * @tc.desc: function test Load Fd after paly
358  * @tc.type: FUNC
359  * @tc.require:
360  */
361 HWTEST_F(SoundPoolUnitTest, soundpool_function_008, TestSize.Level2)
362 {
363     MEDIA_LOGI("soundpool_unit_test soundpool_function_008 before");
364     int maxStreams = 3;
365     create(maxStreams);
366     std::shared_ptr<SoundPoolCallbackTest> cb = std::make_shared<SoundPoolCallbackTest>(soundPool_);
367     int32_t ret = soundPool_->SetSoundPoolCallback(cb);
368     if (ret != 0) {
369         cout << "set callback failed" << endl;
370     }
371     loadFd(g_fileName[loadNum_], loadNum_);
372     sleep(waitTime3);
373     if (cb == nullptr) {
374         cout << "Invalid cb to get loaded sound num." << endl;
375         return;
376     }
377     while (true) {
378         if (cb->GetHaveLoadedSoundNum() == 1) {
379             cout << "All sound loaded Fd break. loaded sound num = " << cb->GetHaveLoadedSoundNum()  << endl;
380             cb->ResetHaveLoadedSoundNum();
381             break;
382         } else {
383             cout << "Sound loaded Fd error. loaded sound num = " << cb->GetHaveLoadedSoundNum()  << endl;
384             break;
385         }
386     }
387     struct PlayParams playParameters;
388     if (soundIDs_[loadNum_] > 0) {
389         soundPool_->Play(soundIDs_[loadNum_], playParameters);
390         sleep(waitTime1);
391         loadNum_++;
392         loadFd(g_fileName[loadNum_], loadNum_);
393         sleep(waitTime3);
394     } else {
395         cout << "Get soundId failed, please try to get soundId: " << soundIDs_[loadNum_] << endl;
396     }
397     if (cb == nullptr) {
398         cout << "Invalid cb to get played sound num." << endl;
399         return;
400     }
401     cb->ResetHavePlayedSoundNum();
402     MEDIA_LOGI("soundpool_unit_test soundpool_function_008 after");
403 }
404 
405 /**
406  * @tc.name: soundpool_function_009
407  * @tc.desc: function test UnLoad
408  * @tc.type: FUNC
409  * @tc.require:
410  */
411 HWTEST_F(SoundPoolUnitTest, soundpool_function_009, TestSize.Level2)
412 {
413     MEDIA_LOGI("soundpool_unit_test soundpool_function_009 before");
414     int maxStreams = 3;
415     create(maxStreams);
416     std::shared_ptr<SoundPoolCallbackTest> cb = std::make_shared<SoundPoolCallbackTest>(soundPool_);
417     int32_t ret = soundPool_->SetSoundPoolCallback(cb);
418     if (ret != 0) {
419         cout << "set callback failed" << endl;
420     }
421     loadUrl(g_fileName[loadNum_], loadNum_);
422     loadNum_++;
423     loadUrl(g_fileName[loadNum_], loadNum_);
424     loadNum_++;
425     loadFd(g_fileName[loadNum_], loadNum_);
426     loadNum_++;
427     loadFd(g_fileName[loadNum_], loadNum_);
428     sleep(waitTime3);
429     if (cb == nullptr) {
430         cout << "Invalid cb to get loaded sound num." << endl;
431         return;
432     }
433     while (true) {
434         if (cb->GetHaveLoadedSoundNum() == 4) {
435             cout << "All sound loaded break. loaded sound num = " << cb->GetHaveLoadedSoundNum()  << endl;
436             cb->ResetHaveLoadedSoundNum();
437             break;
438         }
439     }
440     EXPECT_EQ(MSERR_OK, soundPool_->Unload(soundIDs_[0]));
441     EXPECT_EQ(MSERR_OK, soundPool_->Unload(soundIDs_[1]));
442     EXPECT_EQ(MSERR_OK, soundPool_->Unload(soundIDs_[2]));
443     EXPECT_EQ(MSERR_OK, soundPool_->Unload(soundIDs_[3]));
444     MEDIA_LOGI("soundpool_unit_test soundpool_function_009 after");
445 }
446 
447 /**
448  * @tc.name: soundpool_function_010
449  * @tc.desc: function test UnLoad with error path
450  * @tc.type: FUNC
451  * @tc.require:
452  */
453 HWTEST_F(SoundPoolUnitTest, soundpool_function_010, TestSize.Level2)
454 {
455     MEDIA_LOGI("soundpool_unit_test soundpool_function_010 before");
456     int maxStreams = 3;
457     create(maxStreams);
458     std::shared_ptr<SoundPoolCallbackTest> cb = std::make_shared<SoundPoolCallbackTest>(soundPool_);
459     int32_t ret = soundPool_->SetSoundPoolCallback(cb);
460     if (ret != 0) {
461         cout << "set callback failed" << endl;
462     }
463     std::string fileName = "/data/test/test_05.mp3";
464     fds_[loadNum_] = open(fileName.c_str(), O_RDWR);
465     std::string url = "fd://" + std::to_string(fds_[loadNum_]);
466     soundIDs_[loadNum_] = soundPool_->Load(url);
467     if (fds_[loadNum_] == -1) {
468         cout << "Url open a invalid path: " << fileName.c_str() << endl;
469     }
470     EXPECT_EQ(soundIDs_[loadNum_], -1);
471     loadNum_++;
472     fds_[loadNum_] = open(fileName.c_str(), O_RDONLY);
473     size_t filesize = soundPool_->GetFileSize(fileName);
474     EXPECT_EQ(filesize, 0);
475     soundIDs_[loadNum_] = soundPool_->Load(fds_[loadNum_], 0, filesize);
476     sleep(waitTime3);
477     if (fds_[loadNum_] == -1) {
478         cout << "Fd open a invalid path: " << fileName.c_str() << endl;
479     }
480     EXPECT_EQ(soundIDs_[loadNum_], -1);
481     if (cb == nullptr) {
482         cout << "Invalid cb to get loaded sound num." << endl;
483         return;
484     }
485     while (true) {
486         if (cb->GetHaveLoadedSoundNum() == 2) {
487             cout << "All sound loaded break. loaded sound num = " << cb->GetHaveLoadedSoundNum()  << endl;
488             cb->ResetHaveLoadedSoundNum();
489             break;
490         } else {
491             cout << "Sound loaded error. loaded sound num = " << cb->GetHaveLoadedSoundNum()  << endl;
492             break;
493         }
494     }
495     // test UnLoad a invalid-path return soundId
496     int32_t unload = soundPool_->Unload(soundIDs_[0]);
497     EXPECT_EQ(MSERR_NO_MEMORY, unload);
498     unload = soundPool_->Unload(soundIDs_[1]);
499     EXPECT_EQ(MSERR_NO_MEMORY, unload);
500     MEDIA_LOGI("soundpool_unit_test soundpool_function_010 after");
501 }
502 
503 /**
504  * @tc.name: soundpool_function_011
505  * @tc.desc: function test UnLoad with -1/5
506  * @tc.type: FUNC
507  * @tc.require:
508  */
509 HWTEST_F(SoundPoolUnitTest, soundpool_function_011, TestSize.Level2)
510 {
511     MEDIA_LOGI("soundpool_unit_test soundpool_function_011 before");
512     int maxStreams = 3;
513     create(maxStreams);
514     std::shared_ptr<SoundPoolCallbackTest> cb = std::make_shared<SoundPoolCallbackTest>(soundPool_);
515     int32_t ret = soundPool_->SetSoundPoolCallback(cb);
516     if (ret != 0) {
517         cout << "set callback failed" << endl;
518     }
519     // test unload -1
520     int32_t unload = soundPool_->Unload(-1);
521     EXPECT_EQ(MSERR_NO_MEMORY, unload);
522     // test unload 5
523     unload = soundPool_->Unload(5);
524     EXPECT_EQ(MSERR_NO_MEMORY, unload);
525     MEDIA_LOGI("soundpool_unit_test soundpool_function_011 after");
526 }
527 
528 /**
529  * @tc.name: soundpool_function_012
530  * @tc.desc: function test Play with undefault playParameters
531  * @tc.type: FUNC
532  * @tc.require:
533  */
534 HWTEST_F(SoundPoolUnitTest, soundpool_function_012, TestSize.Level2)
535 {
536     MEDIA_LOGI("soundpool_unit_test soundpool_function_012 before");
537     int maxStreams = 3;
538     create(maxStreams);
539     std::shared_ptr<SoundPoolCallbackTest> cb = std::make_shared<SoundPoolCallbackTest>(soundPool_);
540     int32_t ret = soundPool_->SetSoundPoolCallback(cb);
541     if (ret != 0) {
542         cout << "set callback failed" << endl;
543     }
544 
545     loadUrl(g_fileName[loadNum_], loadNum_);
546     sleep(waitTime3);
547     if (cb == nullptr) {
548         cout << "Invalid cb to get loaded sound num." << endl;
549         return;
550     }
551     while (true) {
552         if (cb->GetHaveLoadedSoundNum() == 1) {
553             cout << "All sound loaded Fd break. loaded sound num = " << cb->GetHaveLoadedSoundNum()  << endl;
554             cb->ResetHaveLoadedSoundNum();
555             break;
556         }
557     }
558     struct PlayParams playParameters;
559     playParameters.loop = -1;
560     playParameters.rate = 1;
561     playParameters.leftVolume = 0.5;
562     playParameters.rightVolume = 0.3;
563     playParameters.priority = 1;
564     playParameters.parallelPlayFlag = true;
565     if (soundIDs_[loadNum_] > 0) {
566         streamIDs_[playNum_] = soundPool_->Play(soundIDs_[loadNum_], playParameters);
567         EXPECT_GT(streamIDs_[playNum_], 0);
568         sleep(waitTime3);
569     }
570     if (cb == nullptr) {
571         cout << "Invalid cb to get played sound num." << endl;
572         return;
573     }
574     cb->ResetHavePlayedSoundNum();
575     MEDIA_LOGI("soundpool_unit_test soundpool_function_012 after");
576 }
577 
578 /**
579  * @tc.name: soundpool_function_013
580  * @tc.desc: function test Play with default playParameters
581  * @tc.type: FUNC
582  * @tc.require:
583  */
584 HWTEST_F(SoundPoolUnitTest, soundpool_function_013, TestSize.Level2)
585 {
586     MEDIA_LOGI("soundpool_unit_test soundpool_function_013 before");
587     int maxStreams = 3;
588     create(maxStreams);
589     std::shared_ptr<SoundPoolCallbackTest> cb = std::make_shared<SoundPoolCallbackTest>(soundPool_);
590     soundPool_->SetSoundPoolCallback(cb);
591     loadUrl(g_fileName[loadNum_], loadNum_);
592     sleep(waitTime3);
593     if (cb == nullptr) {
594         cout << "Invalid cb to get loaded sound num." << endl;
595         return;
596     }
597     while (true) {
598         if (cb->GetHaveLoadedSoundNum() == 1) {
599             cout << "All sound loaded Fd break. loaded sound num = " << cb->GetHaveLoadedSoundNum()  << endl;
600             cb->ResetHaveLoadedSoundNum();
601             break;
602         }
603     }
604     struct PlayParams playParameters;
605     if (soundIDs_[loadNum_] > 0) {
606         streamIDs_[playNum_] = soundPool_->Play(soundIDs_[loadNum_], playParameters);
607         EXPECT_GT(streamIDs_[playNum_], 0);
608         sleep(waitTime3);
609         playNum_++;
610         streamIDs_[playNum_] = soundPool_->Play(soundIDs_[loadNum_], playParameters);
611         EXPECT_GT(streamIDs_[playNum_], 0);
612         sleep(waitTime3);
613         playNum_++;
614         streamIDs_[playNum_] = soundPool_->Play(soundIDs_[loadNum_], playParameters);
615         EXPECT_GT(streamIDs_[playNum_], 0);
616         sleep(waitTime3);
617         playNum_++;
618         streamIDs_[playNum_] = soundPool_->Play(soundIDs_[loadNum_], playParameters);
619         EXPECT_GT(streamIDs_[playNum_], 0);
620         sleep(waitTime3);
621     } else {
622         cout << "Get soundId failed, please try to get soundId: " << soundIDs_[loadNum_] << endl;
623     }
624     if (cb == nullptr) {
625         cout << "Invalid cb to get played sound num." << endl;
626         return;
627     }
628     cb->ResetHavePlayedSoundNum();
629     MEDIA_LOGI("soundpool_unit_test soundpool_function_013 after");
630 }
631 
632 /**
633  * @tc.name: soundpool_function_014
634  * @tc.desc: function test Play with error soundID
635  * @tc.type: FUNC
636  * @tc.require:
637  */
638 HWTEST_F(SoundPoolUnitTest, soundpool_function_014, TestSize.Level2)
639 {
640     MEDIA_LOGI("soundpool_unit_test soundpool_function_014 before");
641     int maxStreams = 3;
642     create(maxStreams);
643     std::shared_ptr<SoundPoolCallbackTest> cb = std::make_shared<SoundPoolCallbackTest>(soundPool_);
644     int32_t ret = soundPool_->SetSoundPoolCallback(cb);
645     if (ret != 0) {
646         cout << "set callback failed" << endl;
647     }
648     struct PlayParams playParameters;
649     streamIDs_[playNum_] = soundPool_->Play(5, playParameters);
650     cout << "soundId 5 play, result: " << streamIDs_[playNum_] << endl;
651     EXPECT_EQ(streamIDs_[playNum_], -1);
652     sleep(waitTime1);
653     if (cb == nullptr) {
654         cout << "Invalid cb to get played sound num." << endl;
655         return;
656     }
657     cb->ResetHavePlayedSoundNum();
658     MEDIA_LOGI("soundpool_unit_test soundpool_function_014 after");
659 }
660 
661 /**
662  * @tc.name: soundpool_function_015
663  * @tc.desc: function test Play with not load number -1
664  * @tc.type: FUNC
665  * @tc.require:
666  */
667 HWTEST_F(SoundPoolUnitTest, soundpool_function_015, TestSize.Level2)
668 {
669     MEDIA_LOGI("soundpool_unit_test soundpool_function_015 before");
670     int maxStreams = 3;
671     create(maxStreams);
672     std::shared_ptr<SoundPoolCallbackTest> cb = std::make_shared<SoundPoolCallbackTest>(soundPool_);
673     int32_t ret = soundPool_->SetSoundPoolCallback(cb);
674     if (ret != 0) {
675         cout << "set callback failed" << endl;
676     }
677     struct PlayParams playParameters;
678     streamIDs_[playNum_] = soundPool_->Play(-1, playParameters);
679     cout << "soundId -1 play, result: " << streamIDs_[playNum_] << endl;
680     EXPECT_EQ(streamIDs_[playNum_], -1);
681     sleep(waitTime1);
682     if (cb == nullptr) {
683         cout << "Invalid cb to get played sound num." << endl;
684         return;
685     }
686     cb->ResetHavePlayedSoundNum();
687     MEDIA_LOGI("soundpool_unit_test soundpool_function_015 after");
688 }
689 
690 /**
691  * @tc.name: soundpool_function_016
692  * @tc.desc: function test Play with different soundID
693  * @tc.type: FUNC
694  * @tc.require:
695  */
696 HWTEST_F(SoundPoolUnitTest, soundpool_function_016, TestSize.Level2)
697 {
698     MEDIA_LOGI("soundpool_unit_test soundpool_function_016 before");
699     int maxStreams = 3;
700     create(maxStreams);
701     std::shared_ptr<SoundPoolCallbackTest> cb = std::make_shared<SoundPoolCallbackTest>(soundPool_);
702     int32_t ret = soundPool_->SetSoundPoolCallback(cb);
703     if (ret != 0) {
704         cout << "set callback failed" << endl;
705     }
706     loadUrl(g_fileName[loadNum_], loadNum_);
707     loadNum_++;
708     loadUrl(g_fileName[loadNum_], loadNum_);
709     sleep(waitTime3);
710     if (cb == nullptr) {
711         cout << "Invalid cb to get loaded sound num." << endl;
712         return;
713     }
714     while (true) {
715         if (cb->GetHaveLoadedSoundNum() == 2) {
716             cout << "All sound loaded Fd break. loaded sound num = " << cb->GetHaveLoadedSoundNum()  << endl;
717             cb->ResetHaveLoadedSoundNum();
718             break;
719         }
720     }
721     struct PlayParams playParameters;
722     streamIDs_[playNum_] = soundPool_->Play(soundIDs_[0], playParameters);
723     EXPECT_GT(streamIDs_[playNum_], 0);
724     sleep(waitTime1);
725     playNum_++;
726     streamIDs_[playNum_] = soundPool_->Play(soundIDs_[1], playParameters);
727     EXPECT_GT(streamIDs_[playNum_], 0);
728     if (cb == nullptr) {
729         cout << "Invalid cb to get played sound num." << endl;
730         return;
731     }
732     cb->ResetHavePlayedSoundNum();
733     MEDIA_LOGI("soundpool_unit_test soundpool_function_016 after");
734 }
735 
736 /**
737  * @tc.name: soundpool_function_017
738  * @tc.desc: function test Stop with same streamId
739  * @tc.type: FUNC
740  * @tc.require:
741  */
742 HWTEST_F(SoundPoolUnitTest, soundpool_function_017, TestSize.Level2)
743 {
744     MEDIA_LOGI("soundpool_unit_test soundpool_function_017 before");
745     int maxStreams = 3;
746     create(maxStreams);
747     std::shared_ptr<SoundPoolCallbackTest> cb = std::make_shared<SoundPoolCallbackTest>(soundPool_);
748     int32_t ret = soundPool_->SetSoundPoolCallback(cb);
749     if (ret != 0) {
750         cout << "set callback failed" << endl;
751     }
752     loadUrl(g_fileName[loadNum_], loadNum_);
753     sleep(waitTime3);
754     if (cb == nullptr) {
755         cout << "Invalid cb to get loaded sound num." << endl;
756         return;
757     }
758     while (true) {
759         if (cb->GetHaveLoadedSoundNum() == 1) {
760             cout << "All sound loaded Fd break. loaded sound num = " << cb->GetHaveLoadedSoundNum()  << endl;
761             cb->ResetHaveLoadedSoundNum();
762             break;
763         }
764     }
765     struct PlayParams playParameters;
766     if (soundIDs_[loadNum_] > 0) {
767         streamIDs_[playNum_] = soundPool_->Play(soundIDs_[loadNum_], playParameters);
768         EXPECT_GT(streamIDs_[playNum_], 0);
769         sleep(waitTime1);
770     }
771     if (cb == nullptr) {
772         cout << "Invalid cb to get played sound num." << endl;
773         return;
774     }
775     cb->ResetHavePlayedSoundNum();
776     if (streamIDs_[playNum_] > 0) {
777         int32_t stopResult = soundPool_->Stop(streamIDs_[playNum_]);
778         EXPECT_EQ(MSERR_OK, stopResult);
779         sleep(waitTime1);
780         int32_t stopResult1 = soundPool_->Stop(streamIDs_[playNum_]);
781         EXPECT_EQ(MSERR_OK, stopResult1);
782     }
783     MEDIA_LOGI("soundpool_unit_test soundpool_function_017 after");
784 }
785 
786 /**
787  * @tc.name: soundpool_function_018
788  * @tc.desc: function test Stop with different streamId
789  * @tc.type: FUNC
790  * @tc.require:
791  */
792 HWTEST_F(SoundPoolUnitTest, soundpool_function_018, TestSize.Level2)
793 {
794     MEDIA_LOGI("soundpool_unit_test soundpool_function_018 before");
795     int maxStreams = 3;
796     create(maxStreams);
797     std::shared_ptr<SoundPoolCallbackTest> cb = std::make_shared<SoundPoolCallbackTest>(soundPool_);
798     soundPool_->SetSoundPoolCallback(cb);
799     loadUrl(g_fileName[loadNum_], loadNum_);
800     loadNum_++;
801     loadFd(g_fileName[loadNum_], loadNum_);
802     sleep(waitTime3);
803     if (cb == nullptr) {
804         cout << "Invalid cb to get loaded sound num." << endl;
805         return;
806     }
807     while (true) {
808         if (cb->GetHaveLoadedSoundNum() == 2) {
809             cout << "All sound loaded Fd break. loaded sound num = " << cb->GetHaveLoadedSoundNum()  << endl;
810             cb->ResetHaveLoadedSoundNum();
811             break;
812         }
813     }
814     struct PlayParams playParameters;
815     if (soundIDs_[0] > 0) {
816         streamIDs_[playNum_] = soundPool_->Play(soundIDs_[0], playParameters);
817         EXPECT_GT(streamIDs_[playNum_], 0);
818         sleep(waitTime1);
819     }
820     playNum_++;
821     if (soundIDs_[1] > 0) {
822         streamIDs_[playNum_] = soundPool_->Play(soundIDs_[1], playParameters);
823         EXPECT_GT(streamIDs_[playNum_], 0);
824         sleep(waitTime1);
825     }
826     if (cb == nullptr) {
827         cout << "Invalid cb to get played sound num." << endl;
828         return;
829     }
830     cb->ResetHavePlayedSoundNum();
831     if (streamIDs_[0] > 0) {
832         EXPECT_EQ(MSERR_OK, soundPool_->Stop(streamIDs_[0]));
833     }
834     if (streamIDs_[1] > 0) {
835         EXPECT_EQ(MSERR_OK, soundPool_->Stop(streamIDs_[1]));
836     }
837     MEDIA_LOGI("soundpool_unit_test soundpool_function_018 after");
838 }
839 
840 /**
841  * @tc.name: soundpool_function_019
842  * @tc.desc: function test not Stop all streamId
843  * @tc.type: FUNC
844  * @tc.require:
845  */
846 HWTEST_F(SoundPoolUnitTest, soundpool_function_019, TestSize.Level2)
847 {
848     MEDIA_LOGI("soundpool_unit_test soundpool_function_019 before");
849     int maxStreams = 3;
850     create(maxStreams);
851     std::shared_ptr<SoundPoolCallbackTest> cb = std::make_shared<SoundPoolCallbackTest>(soundPool_);
852     soundPool_->SetSoundPoolCallback(cb);
853     loadUrl(g_fileName[loadNum_], loadNum_);
854     loadNum_++;
855     loadFd(g_fileName[loadNum_], loadNum_);
856     loadNum_++;
857     loadUrl(g_fileName[loadNum_], loadNum_);
858     sleep(waitTime3);
859     if (cb == nullptr) {
860         cout << "Invalid cb to get loaded sound num." << endl;
861         return;
862     }
863     while (true) {
864         if (cb->GetHaveLoadedSoundNum() == 3) {
865             cout << "All sound loaded Fd break. loaded sound num = " << cb->GetHaveLoadedSoundNum()  << endl;
866             cb->ResetHaveLoadedSoundNum();
867             break;
868         }
869     }
870     struct PlayParams playParameters;
871     if (soundIDs_[0] > 0) {
872         streamIDs_[playNum_] = soundPool_->Play(soundIDs_[0], playParameters);
873         EXPECT_GT(streamIDs_[playNum_], 0);
874     }
875     playNum_++;
876     if (soundIDs_[1] > 0) {
877         streamIDs_[playNum_] = soundPool_->Play(soundIDs_[1], playParameters);
878         EXPECT_GT(streamIDs_[playNum_], 0);
879         sleep(waitTime1);
880     }
881     playNum_++;
882     if (soundIDs_[2] > 0) {
883         streamIDs_[playNum_] = soundPool_->Play(soundIDs_[2], playParameters);
884         EXPECT_GT(streamIDs_[playNum_], 0);
885         sleep(waitTime1);
886     }
887     if (cb == nullptr) {
888         cout << "Invalid cb to get played sound num." << endl;
889         return;
890     }
891     cb->ResetHavePlayedSoundNum();
892     EXPECT_EQ(MSERR_OK, soundPool_->Stop(streamIDs_[0]));
893     EXPECT_EQ(MSERR_OK, soundPool_->Stop(streamIDs_[2]));
894     MEDIA_LOGI("soundpool_unit_test soundpool_function_019 after");
895 }
896 
897 /**
898  * @tc.name: soundpool_function_020
899  * @tc.desc: function test Stop with -1
900  * @tc.type: FUNC
901  * @tc.require:
902  */
903 HWTEST_F(SoundPoolUnitTest, soundpool_function_020, TestSize.Level2)
904 {
905     MEDIA_LOGI("soundpool_unit_test soundpool_function_020 before");
906     int maxStreams = 3;
907     create(maxStreams);
908     std::shared_ptr<SoundPoolCallbackTest> cb = std::make_shared<SoundPoolCallbackTest>(soundPool_);
909     int32_t ret = soundPool_->SetSoundPoolCallback(cb);
910     if (ret != 0) {
911         cout << "set callback failed" << endl;
912     }
913     loadUrl(g_fileName[loadNum_], loadNum_);
914     sleep(waitTime3);
915     if (cb == nullptr) {
916         cout << "Invalid cb to get loaded sound num." << endl;
917         return;
918     }
919     while (true) {
920         if (cb->GetHaveLoadedSoundNum() == 1) {
921             cout << "All sound loaded Fd break. loaded sound num = " << cb->GetHaveLoadedSoundNum()  << endl;
922             cb->ResetHaveLoadedSoundNum();
923             break;
924         }
925     }
926     int32_t stopResult = soundPool_->Stop(-1);
927     EXPECT_EQ(MSERR_INVALID_OPERATION, stopResult);
928     MEDIA_LOGI("soundpool_unit_test soundpool_function_020 after");
929 }
930 
931 /**
932  * @tc.name: soundpool_function_021
933  * @tc.desc: function test SetLoop
934  * @tc.type: FUNC
935  * @tc.require:
936  */
937 HWTEST_F(SoundPoolUnitTest, soundpool_function_021, TestSize.Level2)
938 {
939     MEDIA_LOGI("soundpool_unit_test soundpool_function_021 before");
940     int maxStreams = 3;
941     create(maxStreams);
942     std::shared_ptr<SoundPoolCallbackTest> cb = std::make_shared<SoundPoolCallbackTest>(soundPool_);
943     int32_t ret = soundPool_->SetSoundPoolCallback(cb);
944     if (ret != 0) {
945         cout << "set callback failed" << endl;
946     }
947     loadUrl(g_fileName[loadNum_], loadNum_);
948     sleep(waitTime3);
949     if (cb == nullptr) {
950         cout << "Invalid cb to get loaded sound num." << endl;
951         return;
952     }
953     while (true) {
954         if (cb->GetHaveLoadedSoundNum() == 1) {
955             cout << "All sound loaded Url break. loaded sound num = " << cb->GetHaveLoadedSoundNum()  << endl;
956             cb->ResetHaveLoadedSoundNum();
957             break;
958         }
959     }
960     struct PlayParams playParameters;
961     playParameters.loop = 0;
962     int32_t loop = -1;
963     if (soundIDs_[loadNum_] > 0) {
964         streamIDs_[playNum_] = soundPool_->Play(soundIDs_[loadNum_], playParameters);
965         EXPECT_GT(streamIDs_[playNum_], 0);
966         sleep(waitTime1);
967         int32_t setPool = soundPool_->SetLoop(streamIDs_[playNum_], loop);
968         EXPECT_EQ(MSERR_OK, setPool);
969         sleep(waitTime1);
970     } else {
971         cout << "Get soundId failed, please try to get soundId: " << soundIDs_[loadNum_] << endl;
972     }
973     if (cb == nullptr) {
974         cout << "Invalid cb to get played sound num." << endl;
975         return;
976     }
977     cb->ResetHavePlayedSoundNum();
978     EXPECT_EQ(MSERR_OK, soundPool_->Unload(soundIDs_[loadNum_]));
979     MEDIA_LOGI("soundpool_unit_test soundpool_function_021 after");
980 }
981 
982 /**
983  * @tc.name: soundpool_function_022
984  * @tc.desc: function test SetLoop 3
985  * @tc.type: FUNC
986  * @tc.require:
987  */
988 HWTEST_F(SoundPoolUnitTest, soundpool_function_022, TestSize.Level2)
989 {
990     MEDIA_LOGI("soundpool_unit_test soundpool_function_022 before");
991     int maxStreams = 3;
992     create(maxStreams);
993     std::shared_ptr<SoundPoolCallbackTest> cb = std::make_shared<SoundPoolCallbackTest>(soundPool_);
994     int32_t ret = soundPool_->SetSoundPoolCallback(cb);
995     if (ret != 0) {
996         cout << "set callback failed" << endl;
997     }
998     loadUrl(g_fileName[loadNum_], loadNum_);
999     sleep(waitTime3);
1000     if (cb == nullptr) {
1001         cout << "Invalid cb to get loaded sound num." << endl;
1002         return;
1003     }
1004     while (true) {
1005         if (cb->GetHaveLoadedSoundNum() == 1) {
1006             cout << "All sound loaded Url break. loaded sound num = " << cb->GetHaveLoadedSoundNum()  << endl;
1007             cb->ResetHaveLoadedSoundNum();
1008             break;
1009         }
1010     }
1011     struct PlayParams playParameters;
1012     playParameters.loop = 0;
1013     int32_t loop = 3;
1014     if (soundIDs_[loadNum_] > 0) {
1015         streamIDs_[playNum_] = soundPool_->Play(soundIDs_[loadNum_], playParameters);
1016         EXPECT_GT(streamIDs_[playNum_], 0);
1017         sleep(waitTime1);
1018         int32_t setPool = soundPool_->SetLoop(streamIDs_[playNum_], loop);
1019         EXPECT_EQ(MSERR_OK, setPool);
1020         sleep(waitTime1);
1021     } else {
1022         cout << "Get soundId failed, please try to get soundId: " << soundIDs_[loadNum_] << endl;
1023     }
1024     if (cb == nullptr) {
1025         cout << "Invalid cb to get played sound num." << endl;
1026         return;
1027     }
1028     cb->ResetHavePlayedSoundNum();
1029     MEDIA_LOGI("soundpool_unit_test soundpool_function_022 after");
1030 }
1031 
1032 /**
1033  * @tc.name: soundpool_function_023
1034  * @tc.desc: function test SetLoop -2
1035  * @tc.type: FUNC
1036  * @tc.require:
1037  */
1038 HWTEST_F(SoundPoolUnitTest, soundpool_function_023, TestSize.Level2)
1039 {
1040     MEDIA_LOGI("soundpool_unit_test soundpool_function_023 before");
1041     int maxStreams = 3;
1042     create(maxStreams);
1043     std::shared_ptr<SoundPoolCallbackTest> cb = std::make_shared<SoundPoolCallbackTest>(soundPool_);
1044     int32_t ret = soundPool_->SetSoundPoolCallback(cb);
1045     if (ret != 0) {
1046         cout << "set callback failed" << endl;
1047     }
1048     loadUrl(g_fileName[loadNum_], loadNum_);
1049     sleep(waitTime3);
1050     if (cb == nullptr) {
1051         cout << "Invalid cb to get loaded sound num." << endl;
1052         return;
1053     }
1054     while (true) {
1055         if (cb->GetHaveLoadedSoundNum() == 1) {
1056             cout << "All sound loaded Url break. loaded sound num = " << cb->GetHaveLoadedSoundNum()  << endl;
1057             cb->ResetHaveLoadedSoundNum();
1058             break;
1059         }
1060     }
1061     struct PlayParams playParameters;
1062     playParameters.loop = 0;
1063     int32_t loop = -2;
1064     if (soundIDs_[loadNum_] > 0) {
1065         streamIDs_[playNum_] = soundPool_->Play(soundIDs_[loadNum_], playParameters);
1066         EXPECT_GT(streamIDs_[playNum_], 0);
1067         sleep(waitTime1);
1068         int32_t setPool = soundPool_->SetLoop(streamIDs_[playNum_], loop);
1069         EXPECT_EQ(MSERR_OK, setPool);
1070         sleep(waitTime1);
1071     } else {
1072         cout << "Get soundId failed, please try to get soundId: " << soundIDs_[loadNum_] << endl;
1073     }
1074     if (cb == nullptr) {
1075         cout << "Invalid cb to get played sound num." << endl;
1076         return;
1077     }
1078     cb->ResetHavePlayedSoundNum();
1079     MEDIA_LOGI("soundpool_unit_test soundpool_function_023 after");
1080 }
1081 
1082 /**
1083  * @tc.name: soundpool_function_024
1084  * @tc.desc: function test SetLoop -1, streamID is -1
1085  * @tc.type: FUNC
1086  * @tc.require:
1087  */
1088 HWTEST_F(SoundPoolUnitTest, soundpool_function_024, TestSize.Level2)
1089 {
1090     MEDIA_LOGI("soundpool_unit_test soundpool_function_024 before");
1091     int maxStreams = 3;
1092     create(maxStreams);
1093     std::shared_ptr<SoundPoolCallbackTest> cb = std::make_shared<SoundPoolCallbackTest>(soundPool_);
1094     int32_t ret = soundPool_->SetSoundPoolCallback(cb);
1095     if (ret != 0) {
1096         cout << "set callback failed" << endl;
1097     }
1098     loadUrl(g_fileName[loadNum_], loadNum_);
1099     sleep(waitTime3);
1100     if (cb == nullptr) {
1101         cout << "Invalid cb to get loaded sound num." << endl;
1102         return;
1103     }
1104     while (true) {
1105         if (cb->GetHaveLoadedSoundNum() == 1) {
1106             cout << "All sound loaded Url break. loaded sound num = " << cb->GetHaveLoadedSoundNum()  << endl;
1107             cb->ResetHaveLoadedSoundNum();
1108             break;
1109         }
1110     }
1111     struct PlayParams playParameters;
1112     playParameters.loop = 0;
1113     int32_t loop = -1;
1114     if (soundIDs_[loadNum_] > 0) {
1115         streamIDs_[playNum_] = soundPool_->Play(soundIDs_[loadNum_], playParameters);
1116         EXPECT_GT(streamIDs_[playNum_], 0);
1117         sleep(waitTime1);
1118         int32_t setPool = soundPool_->SetLoop(-1, loop);
1119         EXPECT_EQ(MSERR_INVALID_OPERATION, setPool);
1120         sleep(waitTime1);
1121     } else {
1122         cout << "Get soundId failed, please try to get soundId: " << soundIDs_[loadNum_] << endl;
1123     }
1124     if (cb == nullptr) {
1125         cout << "Invalid cb to get played sound num." << endl;
1126         return;
1127     }
1128     cb->ResetHavePlayedSoundNum();
1129     MEDIA_LOGI("soundpool_unit_test soundpool_function_024 after");
1130 }
1131 
1132 /**
1133  * @tc.name: soundpool_function_025
1134  * @tc.desc: function test SetLoop 2 with different streamId
1135  * @tc.type: FUNC
1136  * @tc.require:
1137  */
1138 HWTEST_F(SoundPoolUnitTest, soundpool_function_025, TestSize.Level2)
1139 {
1140     MEDIA_LOGI("soundpool_unit_test soundpool_function_025 before");
1141     int maxStreams = 3;
1142     create(maxStreams);
1143     std::shared_ptr<SoundPoolCallbackTest> cb = std::make_shared<SoundPoolCallbackTest>(soundPool_);
1144     soundPool_->SetSoundPoolCallback(cb);
1145     loadUrl(g_fileName[loadNum_], loadNum_);
1146     loadNum_++;
1147     loadUrl(g_fileName[loadNum_], loadNum_);
1148     sleep(waitTime3);
1149     if (cb == nullptr) {
1150         cout << "Invalid cb to get loaded sound num." << endl;
1151         return;
1152     }
1153     while (true) {
1154         if (cb->GetHaveLoadedSoundNum() == 2) {
1155             cout << "All sound loaded Url break. loaded sound num = " << cb->GetHaveLoadedSoundNum()  << endl;
1156             cb->ResetHaveLoadedSoundNum();
1157             break;
1158         }
1159     }
1160     struct PlayParams playParameters;
1161     int32_t loop = 2;
1162     if (soundIDs_[0] > 0) {
1163         streamIDs_[playNum_] = soundPool_->Play(soundIDs_[0], playParameters);
1164         EXPECT_GT(streamIDs_[playNum_], 0);
1165         sleep(waitTime1);
1166         int32_t setPool = soundPool_->SetLoop(streamIDs_[playNum_], loop);
1167         EXPECT_EQ(MSERR_OK, setPool);
1168         sleep(waitTime3);
1169         playNum_++;
1170         streamIDs_[playNum_] = soundPool_->Play(soundIDs_[1], playParameters);
1171         EXPECT_GT(streamIDs_[playNum_], 0);
1172         sleep(waitTime1);
1173         int32_t setPool1 = soundPool_->SetLoop(streamIDs_[playNum_], loop);
1174         EXPECT_EQ(MSERR_OK, setPool1);
1175         sleep(waitTime3);
1176     } else {
1177         cout << "Get soundId failed, please try to get soundId: " << soundIDs_[loadNum_] << endl;
1178     }
1179     if (cb == nullptr) {
1180         cout << "Invalid cb to get played sound num." << endl;
1181         return;
1182     }
1183     cb->ResetHavePlayedSoundNum();
1184     MEDIA_LOGI("soundpool_unit_test soundpool_function_025 after");
1185 }
1186 
1187 /**
1188  * @tc.name: soundpool_function_026
1189  * @tc.desc: function test SetLoop different loop with different streamId
1190  * @tc.type: FUNC
1191  * @tc.require:
1192  */
1193 HWTEST_F(SoundPoolUnitTest, soundpool_function_026, TestSize.Level2)
1194 {
1195     MEDIA_LOGI("soundpool_unit_test soundpool_function_026 before");
1196     int maxStreams = 3;
1197     create(maxStreams);
1198     std::shared_ptr<SoundPoolCallbackTest> cb = std::make_shared<SoundPoolCallbackTest>(soundPool_);
1199     soundPool_->SetSoundPoolCallback(cb);
1200     loadUrl(g_fileName[loadNum_], loadNum_);
1201     loadNum_++;
1202     loadUrl(g_fileName[loadNum_], loadNum_);
1203     sleep(waitTime3);
1204     if (cb == nullptr) {
1205         cout << "Invalid cb to get loaded sound num." << endl;
1206         return;
1207     }
1208     while (true) {
1209         if (cb->GetHaveLoadedSoundNum() == 2) {
1210             cout << "All sound loaded Url break. loaded sound num = " << cb->GetHaveLoadedSoundNum()  << endl;
1211             cb->ResetHaveLoadedSoundNum();
1212             break;
1213         }
1214     }
1215     struct PlayParams playParameters;
1216     int32_t loop = 2;
1217     if (soundIDs_[0] > 0) {
1218         streamIDs_[playNum_] = soundPool_->Play(soundIDs_[0], playParameters);
1219         EXPECT_GT(streamIDs_[playNum_], 0);
1220         sleep(waitTime1);
1221         int32_t setPool = soundPool_->SetLoop(streamIDs_[playNum_], loop);
1222         EXPECT_EQ(MSERR_OK, setPool);
1223         sleep(waitTime3);
1224         playNum_++;
1225         streamIDs_[playNum_] = soundPool_->Play(soundIDs_[1], playParameters);
1226         EXPECT_GT(streamIDs_[playNum_], 0);
1227         sleep(waitTime1);
1228         int32_t setPool1 = soundPool_->SetLoop(streamIDs_[playNum_], -1);
1229         EXPECT_EQ(MSERR_OK, setPool1);
1230         sleep(waitTime3);
1231     } else {
1232         cout << "Get soundId failed, please try to get soundId: " << soundIDs_[loadNum_] << endl;
1233     }
1234     if (cb == nullptr) {
1235         cout << "Invalid cb to get played sound num." << endl;
1236         return;
1237     }
1238     cb->ResetHavePlayedSoundNum();
1239     MEDIA_LOGI("soundpool_unit_test soundpool_function_026 after");
1240 }
1241 
1242 /**
1243  * @tc.name: soundpool_function_027
1244  * @tc.desc: function test SetRate with different rate
1245  * @tc.type: FUNC
1246  * @tc.require:
1247  */
1248 HWTEST_F(SoundPoolUnitTest, soundpool_function_027, TestSize.Level2)
1249 {
1250     MEDIA_LOGI("soundpool_unit_test soundpool_function_027 before");
1251     int maxStreams = 3;
1252     create(maxStreams);
1253     std::shared_ptr<SoundPoolCallbackTest> cb = std::make_shared<SoundPoolCallbackTest>(soundPool_);
1254     int32_t ret = soundPool_->SetSoundPoolCallback(cb);
1255     if (ret != 0) {
1256         cout << "set callback failed" << endl;
1257     }
1258     loadUrl(g_fileName[loadNum_], loadNum_);
1259     sleep(waitTime3);
1260     if (cb == nullptr) {
1261         cout << "Invalid cb to get loaded sound num." << endl;
1262         return;
1263     }
1264     while (true) {
1265         if (cb->GetHaveLoadedSoundNum() == 1) {
1266             cout << "All sound loaded Url break. loaded sound num = " << cb->GetHaveLoadedSoundNum()  << endl;
1267             cb->ResetHaveLoadedSoundNum();
1268             break;
1269         }
1270     }
1271     struct PlayParams playParameters;
1272     playParameters.loop = -1;
1273     if (soundIDs_[loadNum_] > 0) {
1274         streamIDs_[playNum_] = soundPool_->Play(soundIDs_[loadNum_], playParameters);
1275         EXPECT_GT(streamIDs_[playNum_], 0);
1276         sleep(waitTime1);
1277         int32_t setRateResult = soundPool_->SetRate(streamIDs_[playNum_], AudioRendererRate::RENDER_RATE_DOUBLE);
1278         EXPECT_EQ(MSERR_OK, setRateResult);
1279         sleep(waitTime3);
1280         int32_t setRateResult1 = soundPool_->SetRate(streamIDs_[playNum_], AudioRendererRate::RENDER_RATE_HALF);
1281         EXPECT_EQ(MSERR_OK, setRateResult1);
1282         sleep(waitTime3);
1283     } else {
1284         cout << "Get soundId failed, please try to get soundId: " << soundIDs_[loadNum_] << endl;
1285     }
1286 
1287     if (cb == nullptr) {
1288         cout << "Invalid cb to get played sound num." << endl;
1289         return;
1290     }
1291     cb->ResetHavePlayedSoundNum();
1292     MEDIA_LOGI("soundpool_unit_test soundpool_function_027 after");
1293 }
1294 
1295 /**
1296  * @tc.name: soundpool_function_028
1297  * @tc.desc: function test SetRate with different rate and streamID
1298  * @tc.type: FUNC
1299  * @tc.require:
1300  */
1301 HWTEST_F(SoundPoolUnitTest, soundpool_function_028, TestSize.Level2)
1302 {
1303     MEDIA_LOGI("soundpool_unit_test soundpool_function_028 before");
1304     int maxStreams = 3;
1305     create(maxStreams);
1306     std::shared_ptr<SoundPoolCallbackTest> cb = std::make_shared<SoundPoolCallbackTest>(soundPool_);
1307     soundPool_->SetSoundPoolCallback(cb);
1308     loadUrl(g_fileName[loadNum_], loadNum_);
1309     loadNum_++;
1310     loadUrl(g_fileName[loadNum_], loadNum_);
1311     sleep(waitTime3);
1312     if (cb == nullptr) {
1313         cout << "Invalid cb to get loaded sound num." << endl;
1314         return;
1315     }
1316     while (true) {
1317         if (cb->GetHaveLoadedSoundNum() == 2) {
1318             cout << "All sound loaded Url break. loaded sound num = " << cb->GetHaveLoadedSoundNum()  << endl;
1319             cb->ResetHaveLoadedSoundNum();
1320             break;
1321         }
1322     }
1323     struct PlayParams playParameters;
1324     if (soundIDs_[0] > 0) {
1325         streamIDs_[playNum_] = soundPool_->Play(soundIDs_[0], playParameters);
1326         EXPECT_GT(streamIDs_[playNum_], 0);
1327         sleep(waitTime1);
1328         int32_t setRateResult = soundPool_->SetRate(streamIDs_[playNum_], AudioRendererRate::RENDER_RATE_DOUBLE);
1329         EXPECT_EQ(MSERR_OK, setRateResult);
1330         sleep(waitTime3);
1331     }
1332     playNum_++;
1333     if (soundIDs_[1] > 0) {
1334         streamIDs_[playNum_] = soundPool_->Play(soundIDs_[1], playParameters);
1335         EXPECT_GT(streamIDs_[playNum_], 0);
1336         sleep(waitTime1);
1337         int32_t setRateResult = soundPool_->SetRate(streamIDs_[playNum_], AudioRendererRate::RENDER_RATE_HALF);
1338         EXPECT_EQ(MSERR_OK, setRateResult);
1339         sleep(waitTime3);
1340     }
1341     if (cb == nullptr) {
1342         cout << "Invalid cb to get played sound num." << endl;
1343         return;
1344     }
1345     cb->ResetHavePlayedSoundNum();
1346     MEDIA_LOGI("soundpool_unit_test soundpool_function_028 after");
1347 }
1348 
1349 /**
1350  * @tc.name: soundpool_function_029
1351  * @tc.desc: function test SetRate with different streamID and same rate
1352  * @tc.type: FUNC
1353  * @tc.require:
1354  */
1355 HWTEST_F(SoundPoolUnitTest, soundpool_function_029, TestSize.Level2)
1356 {
1357     MEDIA_LOGI("soundpool_unit_test soundpool_function_029 before");
1358     int maxStreams = 3;
1359     create(maxStreams);
1360     std::shared_ptr<SoundPoolCallbackTest> cb = std::make_shared<SoundPoolCallbackTest>(soundPool_);
1361     soundPool_->SetSoundPoolCallback(cb);
1362     loadUrl(g_fileName[loadNum_], loadNum_);
1363     loadNum_++;
1364     loadUrl(g_fileName[loadNum_], loadNum_);
1365     sleep(waitTime3);
1366     if (cb == nullptr) {
1367         cout << "Invalid cb to get loaded sound num." << endl;
1368         return;
1369     }
1370     while (true) {
1371         if (cb->GetHaveLoadedSoundNum() == 2) {
1372             cout << "All sound loaded Url break. loaded sound num = " << cb->GetHaveLoadedSoundNum()  << endl;
1373             cb->ResetHaveLoadedSoundNum();
1374             break;
1375         }
1376     }
1377     struct PlayParams playParameters;
1378     playParameters.loop = -1;
1379     if (soundIDs_[0] > 0) {
1380         streamIDs_[playNum_] = soundPool_->Play(soundIDs_[0], playParameters);
1381         EXPECT_GT(streamIDs_[playNum_], 0);
1382         sleep(waitTime1);
1383         int32_t setRateResult = soundPool_->SetRate(streamIDs_[playNum_], AudioRendererRate::RENDER_RATE_DOUBLE);
1384         EXPECT_EQ(MSERR_OK, setRateResult);
1385         sleep(waitTime3);
1386     }
1387     playNum_++;
1388     if (soundIDs_[1] > 0) {
1389         streamIDs_[playNum_] = soundPool_->Play(soundIDs_[1], playParameters);
1390         EXPECT_GT(streamIDs_[playNum_], 0);
1391         sleep(waitTime1);
1392         int32_t setRateResult = soundPool_->SetRate(streamIDs_[playNum_], AudioRendererRate::RENDER_RATE_DOUBLE);
1393         EXPECT_EQ(MSERR_OK, setRateResult);
1394         sleep(waitTime3);
1395     }
1396     if (cb == nullptr) {
1397         cout << "Invalid cb to get played sound num." << endl;
1398         return;
1399     }
1400     cb->ResetHavePlayedSoundNum();
1401     MEDIA_LOGI("soundpool_unit_test soundpool_function_029 after");
1402 }
1403 
1404 /**
1405  * @tc.name: soundpool_function_030
1406  * @tc.desc: function test SetVolume 0.5
1407  * @tc.type: FUNC
1408  * @tc.require:
1409  */
1410 HWTEST_F(SoundPoolUnitTest, soundpool_function_030, TestSize.Level2)
1411 {
1412     MEDIA_LOGI("soundpool_unit_test soundpool_function_030 before");
1413     int maxStreams = 3;
1414     create(maxStreams);
1415     std::shared_ptr<SoundPoolCallbackTest> cb = std::make_shared<SoundPoolCallbackTest>(soundPool_);
1416     int32_t ret = soundPool_->SetSoundPoolCallback(cb);
1417     if (ret != 0) {
1418         cout << "set callback failed" << endl;
1419     }
1420     loadUrl(g_fileName[loadNum_], loadNum_);
1421     sleep(waitTime3);
1422     if (cb == nullptr) {
1423         cout << "Invalid cb to get loaded sound num." << endl;
1424         return;
1425     }
1426     while (true) {
1427         if (cb->GetHaveLoadedSoundNum() == 1) {
1428             cout << "All sound loaded Url break. loaded sound num = " << cb->GetHaveLoadedSoundNum()  << endl;
1429             cb->ResetHaveLoadedSoundNum();
1430             break;
1431         }
1432     }
1433     struct PlayParams playParameters;
1434     float leftVolume = 0.5;
1435     float rightVolume = 0.5;
1436     if (soundIDs_[loadNum_] > 0) {
1437         streamIDs_[playNum_] = soundPool_->Play(soundIDs_[loadNum_], playParameters);
1438         EXPECT_GT(streamIDs_[playNum_], 0);
1439         sleep(waitTime1);
1440         int32_t setVol = soundPool_->SetVolume(streamIDs_[playNum_], leftVolume, rightVolume);
1441         EXPECT_EQ(MSERR_OK, setVol);
1442         sleep(waitTime1);
1443     } else {
1444         cout << "Get soundId failed, please try to get soundId: " << soundIDs_[loadNum_] << endl;
1445     }
1446     if (cb == nullptr) {
1447         cout << "Invalid cb to get played sound num." << endl;
1448         return;
1449     }
1450     cb->ResetHavePlayedSoundNum();
1451     MEDIA_LOGI("soundpool_unit_test soundpool_function_030 after");
1452 }
1453 
1454 /**
1455  * @tc.name: soundpool_function_031
1456  * @tc.desc: function test SetVolume deifferent leftVolume
1457  * @tc.type: FUNC
1458  * @tc.require:
1459  */
1460 HWTEST_F(SoundPoolUnitTest, soundpool_function_031, TestSize.Level2)
1461 {
1462     MEDIA_LOGI("soundpool_unit_test soundpool_function_031 before");
1463     int maxStreams = 3;
1464     create(maxStreams);
1465     std::shared_ptr<SoundPoolCallbackTest> cb = std::make_shared<SoundPoolCallbackTest>(soundPool_);
1466     int32_t ret = soundPool_->SetSoundPoolCallback(cb);
1467     if (ret != 0) {
1468         cout << "set callback failed" << endl;
1469     }
1470     loadUrl(g_fileName[loadNum_], loadNum_);
1471     sleep(waitTime3);
1472     if (cb == nullptr) {
1473         cout << "Invalid cb to get loaded sound num." << endl;
1474         return;
1475     }
1476     while (true) {
1477         if (cb->GetHaveLoadedSoundNum() == 1) {
1478             cout << "All sound loaded Url break. loaded sound num = " << cb->GetHaveLoadedSoundNum()  << endl;
1479             cb->ResetHaveLoadedSoundNum();
1480             break;
1481         }
1482     }
1483     struct PlayParams playParameters;
1484     float leftVolume = 0.1;
1485     if (soundIDs_[loadNum_] > 0) {
1486         streamIDs_[playNum_] = soundPool_->Play(soundIDs_[loadNum_], playParameters);
1487         EXPECT_GT(streamIDs_[playNum_], 0);
1488         sleep(waitTime1);
1489         int32_t setVol = soundPool_->SetVolume(streamIDs_[playNum_], leftVolume, 0.0);
1490         EXPECT_EQ(MSERR_OK, setVol);
1491         sleep(waitTime3);
1492         int32_t setVol1 = soundPool_->SetVolume(streamIDs_[playNum_], 1.0, 0.0);
1493         EXPECT_EQ(MSERR_OK, setVol1);
1494         sleep(waitTime1);
1495     } else {
1496         cout << "Get soundId failed, please try to get soundId: " << soundIDs_[loadNum_] << endl;
1497     }
1498     if (cb == nullptr) {
1499         cout << "Invalid cb to get played sound num." << endl;
1500         return;
1501     }
1502     cb->ResetHavePlayedSoundNum();
1503     MEDIA_LOGI("soundpool_unit_test soundpool_function_031 after");
1504 }
1505 
1506 /**
1507  * @tc.name: soundpool_function_032
1508  * @tc.desc: function test SetVolume leftVolume -1
1509  * @tc.type: FUNC
1510  * @tc.require:
1511  */
1512 HWTEST_F(SoundPoolUnitTest, soundpool_function_032, TestSize.Level2)
1513 {
1514     MEDIA_LOGI("soundpool_unit_test soundpool_function_032 before");
1515     int maxStreams = 3;
1516     create(maxStreams);
1517     std::shared_ptr<SoundPoolCallbackTest> cb = std::make_shared<SoundPoolCallbackTest>(soundPool_);
1518     int32_t ret = soundPool_->SetSoundPoolCallback(cb);
1519     if (ret != 0) {
1520         cout << "set callback failed" << endl;
1521     }
1522     loadUrl(g_fileName[loadNum_], loadNum_);
1523     sleep(waitTime3);
1524     if (cb == nullptr) {
1525         cout << "Invalid cb to get loaded sound num." << endl;
1526         return;
1527     }
1528     while (true) {
1529         if (cb->GetHaveLoadedSoundNum() == 1) {
1530             cout << "All sound loaded Url break. loaded sound num = " << cb->GetHaveLoadedSoundNum()  << endl;
1531             cb->ResetHaveLoadedSoundNum();
1532             break;
1533         }
1534     }
1535     struct PlayParams playParameters;
1536     float leftVolume = -1;
1537     if (soundIDs_[loadNum_] > 0) {
1538         streamIDs_[playNum_] = soundPool_->Play(soundIDs_[loadNum_], playParameters);
1539         EXPECT_GT(streamIDs_[playNum_], 0);
1540         sleep(waitTime1);
1541         int32_t setVol = soundPool_->SetVolume(streamIDs_[playNum_], leftVolume, 0.0);
1542         EXPECT_EQ(MSERR_OK, setVol);
1543         sleep(waitTime1);
1544     } else {
1545         cout << "Get soundId failed, please try to get soundId: " << soundIDs_[loadNum_] << endl;
1546     }
1547     if (cb == nullptr) {
1548         cout << "Invalid cb to get played sound num." << endl;
1549         return;
1550     }
1551     cb->ResetHavePlayedSoundNum();
1552     MEDIA_LOGI("soundpool_unit_test soundpool_function_032 after");
1553 }
1554 
1555 /**
1556  * @tc.name: soundpool_function_033
1557  * @tc.desc: function test SetVolume rightVolume 2.0
1558  * @tc.type: FUNC
1559  * @tc.require:
1560  */
1561 HWTEST_F(SoundPoolUnitTest, soundpool_function_033, TestSize.Level2)
1562 {
1563     MEDIA_LOGI("soundpool_unit_test soundpool_function_033 before");
1564     int maxStreams = 3;
1565     create(maxStreams);
1566     std::shared_ptr<SoundPoolCallbackTest> cb = std::make_shared<SoundPoolCallbackTest>(soundPool_);
1567     int32_t ret = soundPool_->SetSoundPoolCallback(cb);
1568     if (ret != 0) {
1569         cout << "set callback failed" << endl;
1570     }
1571     loadUrl(g_fileName[loadNum_], loadNum_);
1572     sleep(waitTime3);
1573     if (cb == nullptr) {
1574         cout << "Invalid cb to get loaded sound num." << endl;
1575         return;
1576     }
1577     while (true) {
1578         if (cb->GetHaveLoadedSoundNum() == 1) {
1579             cout << "All sound loaded Url break. loaded sound num = " << cb->GetHaveLoadedSoundNum()  << endl;
1580             cb->ResetHaveLoadedSoundNum();
1581             break;
1582         }
1583     }
1584     struct PlayParams playParameters;
1585     float rightVolume = 2.0;
1586     if (soundIDs_[loadNum_] > 0) {
1587         streamIDs_[playNum_] = soundPool_->Play(soundIDs_[loadNum_], playParameters);
1588         EXPECT_GT(streamIDs_[playNum_], 0);
1589         sleep(waitTime1);
1590         int32_t setVol = soundPool_->SetVolume(streamIDs_[playNum_], 0.0, rightVolume);
1591         EXPECT_EQ(MSERR_OK, setVol);
1592         sleep(waitTime1);
1593     } else {
1594         cout << "Get soundId failed, please try to get soundId: " << soundIDs_[loadNum_] << endl;
1595     }
1596     if (cb == nullptr) {
1597         cout << "Invalid cb to get played sound num." << endl;
1598         return;
1599     }
1600     cb->ResetHavePlayedSoundNum();
1601     MEDIA_LOGI("soundpool_unit_test soundpool_function_033 after");
1602 }
1603 
1604 /**
1605  * @tc.name: soundpool_function_034
1606  * @tc.desc: function test SetPriority 1
1607  * @tc.type: FUNC
1608  * @tc.require:
1609  */
1610 HWTEST_F(SoundPoolUnitTest, soundpool_function_034, TestSize.Level2)
1611 {
1612     MEDIA_LOGI("soundpool_unit_test soundpool_function_034 before");
1613     int maxStreams = 1;
1614     create(maxStreams);
1615     std::shared_ptr<SoundPoolCallbackTest> cb = std::make_shared<SoundPoolCallbackTest>(soundPool_);
1616     int32_t ret = soundPool_->SetSoundPoolCallback(cb);
1617     if (ret != 0) {
1618         cout << "set callback failed" << endl;
1619     }
1620     loadUrl(g_fileName[loadNum_], loadNum_);
1621     loadNum_++;
1622     loadUrl(g_fileName[loadNum_], loadNum_);
1623     sleep(waitTime3);
1624     if (cb == nullptr) {
1625         cout << "Invalid cb to get loaded sound num." << endl;
1626         return;
1627     }
1628     while (true) {
1629         if (cb->GetHaveLoadedSoundNum() == 2) {
1630             cout << "All sound loaded Url break. loaded sound num = " << cb->GetHaveLoadedSoundNum()  << endl;
1631             cb->ResetHaveLoadedSoundNum();
1632             break;
1633         }
1634     }
1635     struct PlayParams playParameters;
1636     playParameters.loop = -1;
1637     int32_t priority  = 1;
1638     if (soundIDs_[0] > 0) {
1639         streamIDs_[playNum_] = soundPool_->Play(soundIDs_[0], playParameters);
1640         EXPECT_GT(streamIDs_[playNum_], 0);
1641         sleep(waitTime3);
1642     }
1643     playNum_++;
1644     if (soundIDs_[1] > 0) {
1645         streamIDs_[playNum_] = soundPool_->Play(soundIDs_[1], playParameters);
1646         EXPECT_GT(streamIDs_[playNum_], 0);
1647         sleep(waitTime3);
1648         int32_t setPriority = soundPool_->SetPriority(streamIDs_[playNum_], priority);
1649         EXPECT_EQ(MSERR_OK, setPriority);
1650         sleep(waitTime1);
1651     }
1652     if (cb == nullptr) {
1653         cout << "Invalid cb to get played sound num." << endl;
1654         return;
1655     }
1656     cb->ResetHavePlayedSoundNum();
1657     MEDIA_LOGI("soundpool_unit_test soundpool_function_034 after");
1658 }
1659 
1660 
1661 /**
1662  * @tc.name: soundpool_function_035
1663  * @tc.desc: function test SetPriority
1664  * @tc.type: FUNC
1665  * @tc.require:
1666  */
1667 HWTEST_F(SoundPoolUnitTest, soundpool_function_035, TestSize.Level2)
1668 {
1669     MEDIA_LOGI("soundpool_unit_test soundpool_function_035 before");
1670     int maxStreams = 1;
1671     create(maxStreams);
1672     std::shared_ptr<SoundPoolCallbackTest> cb = std::make_shared<SoundPoolCallbackTest>(soundPool_);
1673     soundPool_->SetSoundPoolCallback(cb);
1674     loadUrl(g_fileName[loadNum_], loadNum_);
1675     loadNum_++;
1676     loadUrl(g_fileName[loadNum_], loadNum_);
1677     sleep(waitTime3);
1678     if (cb == nullptr) {
1679         cout << "Invalid cb to get loaded sound num." << endl;
1680         return;
1681     }
1682     while (true) {
1683         if (cb->GetHaveLoadedSoundNum() == 2) {
1684             cout << "All sound loaded Url break. loaded sound num = " << cb->GetHaveLoadedSoundNum()  << endl;
1685             cb->ResetHaveLoadedSoundNum();
1686             break;
1687         }
1688     }
1689     struct PlayParams playParameters;
1690     playParameters.priority = 1;
1691     playParameters.loop = -1;
1692     int32_t priority  = -1;
1693     if (soundIDs_[0] > 0) {
1694         streamIDs_[playNum_] = soundPool_->Play(soundIDs_[0], playParameters);
1695         EXPECT_GT(streamIDs_[playNum_], 0);
1696         sleep(waitTime3);
1697     }
1698     playNum_++;
1699     if (soundIDs_[1] > 0) {
1700         streamIDs_[playNum_] = soundPool_->Play(soundIDs_[1], playParameters);
1701         EXPECT_GT(streamIDs_[1], 0);
1702         sleep(waitTime3);
1703     }
1704     int32_t setPriority = soundPool_->SetPriority(streamIDs_[0], priority);
1705     sleep(waitTime1);
1706     EXPECT_EQ(MSERR_OK, setPriority);
1707     if (cb == nullptr) {
1708         cout << "Invalid cb to get played sound num." << endl;
1709         return;
1710     }
1711     cb->ResetHavePlayedSoundNum();
1712     MEDIA_LOGI("soundpool_unit_test soundpool_function_035 after");
1713 }
1714 
1715 /**
1716  * @tc.name: soundpool_function_036
1717  * @tc.desc: function test Priority
1718  * @tc.type: FUNC
1719  * @tc.require:
1720  */
1721 HWTEST_F(SoundPoolUnitTest, soundpool_function_036, TestSize.Level2)
1722 {
1723     MEDIA_LOGI("soundpool_unit_test soundpool_function_036 before");
1724     int maxStreams = 3;
1725     create(maxStreams);
1726     std::shared_ptr<SoundPoolCallbackTest> cb = std::make_shared<SoundPoolCallbackTest>(soundPool_);
1727     int32_t ret = soundPool_->SetSoundPoolCallback(cb);
1728     if (ret != 0) {
1729         cout << "set callback failed" << endl;
1730     }
1731     loadUrl(g_fileName[1], loadNum_);
1732     loadNum_++;
1733     loadUrl(g_fileName[1], loadNum_);
1734     loadNum_++;
1735     loadUrl(g_fileName[1], loadNum_);
1736     loadNum_++;
1737     loadUrl(g_fileName[0], loadNum_);
1738     sleep(waitTime3);
1739     struct PlayParams playParameters;
1740     playParameters.priority = 3;
1741     if (soundIDs_[0] > 0) {
1742         streamIDs_[playNum_] = soundPool_->Play(soundIDs_[0], playParameters);
1743         EXPECT_GT(streamIDs_[playNum_], 0);
1744         sleep(waitTime2);
1745     }
1746     playNum_++;
1747     if (soundIDs_[1] > 0) {
1748         streamIDs_[playNum_] = soundPool_->Play(soundIDs_[1], playParameters);
1749         EXPECT_GT(streamIDs_[playNum_], 0);
1750         sleep(waitTime2);
1751     }
1752     playNum_++;
1753     if (soundIDs_[2] > 0) {
1754         streamIDs_[playNum_] = soundPool_->Play(soundIDs_[2], playParameters);
1755         EXPECT_GT(streamIDs_[playNum_], 0);
1756         sleep(waitTime2);
1757     }
1758     playNum_++;
1759     playParameters.priority = 5;
1760     if (soundIDs_[3] > 0) {
1761         streamIDs_[playNum_] = soundPool_->Play(soundIDs_[3], playParameters);
1762         EXPECT_GT(streamIDs_[playNum_], 0);
1763         sleep(waitTime2);
1764     }
1765     sleep(15);
1766     cb->ResetHavePlayedSoundNum();
1767     MEDIA_LOGI("soundpool_unit_test soundpool_function_036 after");
1768 }
1769 
1770 /**
1771  * @tc.name: soundpool_function_037
1772  * @tc.desc: function test Priority
1773  * @tc.type: FUNC
1774  * @tc.require:
1775  */
1776 HWTEST_F(SoundPoolUnitTest, soundpool_function_037, TestSize.Level2)
1777 {
1778     MEDIA_LOGI("soundpool_unit_test soundpool_function_037 before");
1779     int maxStreams = 3;
1780     create(maxStreams);
1781     std::shared_ptr<SoundPoolCallbackTest> cb = std::make_shared<SoundPoolCallbackTest>(soundPool_);
1782     int32_t ret = soundPool_->SetSoundPoolCallback(cb);
1783     if (ret != 0) {
1784         cout << "set callback failed" << endl;
1785     }
1786     loadUrl(g_fileName[1], loadNum_);
1787     loadNum_++;
1788     loadUrl(g_fileName[1], loadNum_);
1789     loadNum_++;
1790     loadUrl(g_fileName[1], loadNum_);
1791     loadNum_++;
1792     loadUrl(g_fileName[0], loadNum_);
1793     sleep(waitTime3);
1794     struct PlayParams playParameters;
1795     playParameters.priority = 3;
1796     if (soundIDs_[0] > 0) {
1797         streamIDs_[playNum_] = soundPool_->Play(soundIDs_[0], playParameters);
1798         EXPECT_GT(streamIDs_[playNum_], 0);
1799         sleep(waitTime2);
1800     }
1801     playNum_++;
1802     if (soundIDs_[1] > 0) {
1803         streamIDs_[playNum_] = soundPool_->Play(soundIDs_[1], playParameters);
1804         EXPECT_GT(streamIDs_[playNum_], 0);
1805         sleep(waitTime2);
1806     }
1807     playNum_++;
1808     if (soundIDs_[2] > 0) {
1809         streamIDs_[playNum_] = soundPool_->Play(soundIDs_[2], playParameters);
1810         EXPECT_GT(streamIDs_[playNum_], 0);
1811         sleep(waitTime2);
1812     }
1813     playNum_++;
1814     playParameters.priority = 1;
1815     if (soundIDs_[3] > 0) {
1816         streamIDs_[playNum_] = soundPool_->Play(soundIDs_[3], playParameters);
1817         EXPECT_GT(streamIDs_[playNum_], 0);
1818         sleep(waitTime2);
1819     }
1820     sleep(15);
1821     cb->ResetHavePlayedSoundNum();
1822     MEDIA_LOGI("soundpool_unit_test soundpool_function_037 after");
1823 }
1824 
1825 
1826 /**
1827  * @tc.name: soundpool_function_038
1828  * @tc.desc: function test MaxStreams
1829  * @tc.type: FUNC
1830  * @tc.require:
1831  */
1832 HWTEST_F(SoundPoolUnitTest, soundpool_function_038, TestSize.Level2)
1833 {
1834     MEDIA_LOGI("soundpool_unit_test soundpool_function_038 before");
1835 
1836     int maxStreams = -1;
1837     AudioStandard::AudioRendererInfo audioRenderInfo;
1838     audioRenderInfo.contentType = CONTENT_TYPE_MUSIC;
1839     audioRenderInfo.streamUsage = STREAM_USAGE_MUSIC;
1840     audioRenderInfo.rendererFlags = 0;
1841     EXPECT_FALSE(soundPool_->CreateSoundPool(maxStreams, audioRenderInfo));
1842     maxStreams = 256;
1843     EXPECT_TRUE(soundPool_->CreateSoundPool(maxStreams, audioRenderInfo));
1844 
1845     MEDIA_LOGI("soundpool_unit_test soundpool_function_038 after");
1846 }
1847 
1848 /**
1849  * @tc.name: soundpool_function_039
1850  * @tc.desc: function test CacheBuffer DoPlay fail
1851  * @tc.type: FUNC
1852  * @tc.require:
1853  */
1854 HWTEST_F(SoundPoolUnitTest, soundpool_function_039, TestSize.Level2)
1855 {
1856     MEDIA_LOGI("soundpool_unit_test soundpool_function_039 before");
1857 
1858     int maxStreams = 3;
1859     create(maxStreams);
1860     std::shared_ptr<SoundPoolCallbackTest> cb = std::make_shared<SoundPoolCallbackTest>(soundPool_);
1861     soundPool_->SetSoundPoolCallback(cb);
1862     loadUrl(g_fileName[1], loadNum_);
1863     sleep(5);
1864     struct PlayParams playParameters;
1865     if (soundIDs_[0] > 0) {
1866         streamIDs_[playNum_] = soundPool_->Play(soundIDs_[0], playParameters);
1867         EXPECT_GT(streamIDs_[playNum_], 0);
1868         sleep(waitTime1);
1869         streamIDs_[playNum_] = soundPool_->Play(soundIDs_[0], playParameters);
1870         EXPECT_GT(streamIDs_[playNum_], 0);
1871         sleep(waitTime1);
1872         streamIDs_[playNum_] = soundPool_->Play(soundIDs_[0], playParameters);
1873         EXPECT_GT(streamIDs_[playNum_], 0);
1874         sleep(waitTime1);
1875     }
1876     cb->ResetHavePlayedSoundNum();
1877 
1878     MEDIA_LOGI("soundpool_unit_test soundpool_function_039 after");
1879 }
1880 
1881 /**
1882  * @tc.name: soundpool_function_040
1883  * @tc.desc: function test play Priority
1884  * @tc.type: FUNC
1885  * @tc.require:
1886  */
1887 HWTEST_F(SoundPoolUnitTest, soundpool_function_040, TestSize.Level2)
1888 {
1889     MEDIA_LOGI("soundpool_unit_test soundpool_function_040 before");
1890 
1891     int maxStreams = 4;
1892     create(maxStreams);
1893     std::shared_ptr<SoundPoolCallbackTest> cb = std::make_shared<SoundPoolCallbackTest>(soundPool_);
1894     soundPool_->SetSoundPoolCallback(cb);
1895     loadUrl(g_fileName[2], loadNum_++);
1896     loadUrl(g_fileName[1], loadNum_++);
1897     loadUrl(g_fileName[4], loadNum_++);
1898     loadUrl(g_fileName[5], loadNum_++);
1899     sleep(5);
1900     struct PlayParams playParameters;
1901     streamIDs_[playNum_] = soundPool_->Play(soundIDs_[0], playParameters);
1902     EXPECT_GT(streamIDs_[playNum_], 0);
1903     int32_t setPriority = soundPool_->SetPriority(streamIDs_[0], 1);
1904     EXPECT_EQ(MSERR_OK, setPriority);
1905     playNum_++;
1906     sleep(waitTime1);
1907 
1908     streamIDs_[playNum_] = soundPool_->Play(soundIDs_[1], playParameters);
1909     EXPECT_GT(streamIDs_[playNum_], 0);
1910     setPriority = soundPool_->SetPriority(streamIDs_[1], 2);
1911     EXPECT_EQ(MSERR_OK, setPriority);
1912     playNum_++;
1913     sleep(waitTime1);
1914 
1915     streamIDs_[playNum_] = soundPool_->Play(soundIDs_[2], playParameters);
1916     EXPECT_GT(streamIDs_[playNum_], 0);
1917     setPriority = soundPool_->SetPriority(streamIDs_[2], 3);
1918     EXPECT_EQ(MSERR_OK, setPriority);
1919     playNum_++;
1920     sleep(waitTime1);
1921 
1922     streamIDs_[playNum_] = soundPool_->Play(soundIDs_[3], playParameters);
1923     EXPECT_GT(streamIDs_[playNum_], 0);
1924     setPriority = soundPool_->SetPriority(streamIDs_[3], 4);
1925     EXPECT_EQ(MSERR_OK, setPriority);
1926     playNum_++;
1927     sleep(waitTime10);
1928 
1929     MEDIA_LOGI("soundpool_unit_test soundpool_function_040 after");
1930 }
1931 
1932 /**
1933  * @tc.name: soundpool_function_041
1934  * @tc.desc: function test willplay Priority
1935  * @tc.type: FUNC
1936  * @tc.require:
1937  */
1938 HWTEST_F(SoundPoolUnitTest, soundpool_function_041, TestSize.Level2)
1939 {
1940     MEDIA_LOGI("soundpool_unit_test soundpool_function_041 before");
1941 
1942     int maxStreams = 1;
1943     create(maxStreams);
1944     std::shared_ptr<SoundPoolCallbackTest> cb = std::make_shared<SoundPoolCallbackTest>(soundPool_);
1945     soundPool_->SetSoundPoolCallback(cb);
1946     loadUrl(g_fileName[2], loadNum_++);
1947     loadUrl(g_fileName[1], loadNum_++);
1948     loadUrl(g_fileName[4], loadNum_++);
1949     loadUrl(g_fileName[5], loadNum_++);
1950     sleep(5);
1951     struct PlayParams playParameters;
1952     streamIDs_[playNum_] = soundPool_->Play(soundIDs_[0], playParameters);
1953     EXPECT_GT(streamIDs_[playNum_], 0);
1954     int32_t setPriority = soundPool_->SetPriority(streamIDs_[0], 1);
1955     EXPECT_EQ(MSERR_OK, setPriority);
1956     playNum_++;
1957     sleep(waitTime1);
1958 
1959     streamIDs_[playNum_] = soundPool_->Play(soundIDs_[1], playParameters);
1960     EXPECT_GT(streamIDs_[playNum_], 0);
1961     setPriority = soundPool_->SetPriority(streamIDs_[1], 2);
1962     EXPECT_EQ(MSERR_OK, setPriority);
1963     playNum_++;
1964     sleep(waitTime1);
1965 
1966     streamIDs_[playNum_] = soundPool_->Play(soundIDs_[2], playParameters);
1967     EXPECT_GT(streamIDs_[playNum_], 0);
1968     setPriority = soundPool_->SetPriority(streamIDs_[2], 3);
1969     EXPECT_EQ(MSERR_OK, setPriority);
1970     playNum_++;
1971     sleep(waitTime1);
1972 
1973     streamIDs_[playNum_] = soundPool_->Play(soundIDs_[3], playParameters);
1974     EXPECT_GT(streamIDs_[playNum_], 0);
1975     setPriority = soundPool_->SetPriority(streamIDs_[3], 4);
1976     EXPECT_EQ(MSERR_OK, setPriority);
1977     playNum_++;
1978     sleep(waitTime30);
1979 
1980     MEDIA_LOGI("soundpool_unit_test soundpool_function_041 after");
1981 }
1982 
1983 } // namespace Media
1984 } // namespace OHOS