• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020-2021 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 <fstream>
17 #include <iostream>
18 #include <climits>
19 #include <unistd.h>
20 #include <fcntl.h>
21 #include <sys/prctl.h>
22 #include "securec.h"
23 #include "gtest/gtest.h"
24 #include "source.h"
25 #include "player.h"
26 #include "format.h"
27 #include "thread"
28 #include "ActsMediaPlayerTest.h"
29 
30 namespace OHOS {
31 const string g_audioFileName = "Audiochannel_002.m4a";
32 
33 using OHOS::Media::Player;
34 using OHOS::Media::PlayerSeekMode;
35 using OHOS::Media::Source;
36 using OHOS::Media::Format;
37 using OHOS::Media::StreamSource;
38 using OHOS::Media::StreamCallback;
39 
StreamSourceSample(void)40 StreamSourceSample::StreamSourceSample(void)
41 {
42     aviableBuffer.clear();
43     pthread_mutex_init(&m_mutex, nullptr);
44 }
45 
~StreamSourceSample(void)46 StreamSourceSample::~StreamSourceSample(void)
47 {
48     aviableBuffer.clear();
49     pthread_mutex_destroy(&m_mutex);
50 }
51 
SetStreamCallback(const std::shared_ptr<StreamCallback> & callback)52 void StreamSourceSample::SetStreamCallback(const std::shared_ptr<StreamCallback> &callback)
53 {
54     m_callBack = callback;
55 }
56 
GetBufferAddress(size_t idx)57 uint8_t *StreamSourceSample::GetBufferAddress(size_t idx)
58 {
59     std::shared_ptr<StreamCallback> callback = m_callBack.lock();
60     if (callback == nullptr) {
61         return nullptr;
62     }
63     return callback->GetBuffer(idx);
64 }
65 
QueueBuffer(size_t index,size_t offset,size_t size,int64_t timestampUs,uint32_t flags)66 void StreamSourceSample::QueueBuffer(size_t index, size_t offset, size_t size, int64_t timestampUs, uint32_t flags)
67 {
68     std::shared_ptr<StreamCallback> callback = m_callBack.lock();
69     if (callback == nullptr) {
70         return;
71     }
72     callback->QueueBuffer(index, offset, size, timestampUs, flags);
73 }
74 
OnBufferAvailable(size_t index,size_t offset,size_t size)75 void StreamSourceSample::OnBufferAvailable(size_t index, size_t offset, size_t size)
76 {
77     IdleBuffer buffer;
78     pthread_mutex_lock(&m_mutex);
79     buffer.idx = index;
80     buffer.offset = offset;
81     buffer.size = size;
82     aviableBuffer.push_back(buffer);
83     pthread_mutex_unlock(&m_mutex);
84 }
85 
GetAvailableBuffer(IdleBuffer * buffer)86 int StreamSourceSample::GetAvailableBuffer(IdleBuffer *buffer)
87 {
88     pthread_mutex_lock(&m_mutex);
89     if (aviableBuffer.empty()) {
90         pthread_mutex_unlock(&m_mutex);
91         return -1;
92     }
93     *buffer = aviableBuffer[0];
94     aviableBuffer.erase(aviableBuffer.begin());
95     pthread_mutex_unlock(&m_mutex);
96     return 0;
97 }
98 
StreamProcess(void * arg)99 void *StreamProcess(void *arg)
100 {
101     const int gReadLen = 1024;
102     const int usleepTime = 20000;
103     const int flags1 = 8;
104     const int flags2 = 4;
105     IdleBuffer buffer;
106     int ret;
107     uint8_t *data = nullptr;
108     size_t readLen;
109     size_t len;
110     TestSample *sample = (TestSample *)arg;
111     FILE* pFile = fopen(sample->filePath, "rb");
112     if (pFile == nullptr) {
113         return nullptr;
114     }
115     prctl(PR_SET_NAME, "StreamProc", 0, 0, 0);
116     printf("[%s,%d] file:%s\n", __func__, __LINE__, sample->filePath);
117     while (sample->isThreadRunning) {
118         ret = sample->streamSample->GetAvailableBuffer(&buffer);
119         if (ret != 0) {
120             usleep(usleepTime);
121             continue;
122         }
123         data = sample->streamSample->GetBufferAddress(buffer.idx);
124         if (data == nullptr) {
125             printf("[%s, %d] get buffer null", __func__, __LINE__);
126             break;
127         }
128         len = (buffer.size < gReadLen) ? buffer.size : gReadLen;
129         readLen = fread(data + buffer.offset, 1, len, pFile);
130         if (readLen <= len && readLen > 0) {
131             sample->streamSample->QueueBuffer(buffer.idx, buffer.offset, readLen, 0, flags1);
132         } else {
133             sample->streamSample->QueueBuffer(buffer.idx, buffer.offset, readLen, 0, flags2);
134             break;
135         }
136     }
137     fclose(pFile);
138     printf("[%s,%d]\n", __func__, __LINE__);
139     return nullptr;
140 }
141 
SetSchParam(void)142 void SetSchParam(void)
143 {
144     struct sched_param param;
145     const int priorityNum = 9;
146     pthread_attr_t attr;
147     pthread_attr_getschedparam(&attr, &param);
148     param.sched_priority = priorityNum;
149     pthread_setschedparam(pthread_self(), SCHED_RR, &param);
150 }
151 
152 class ActsMediaPlayerAudioTest : public testing::Test {
153 protected:
154 // SetUpTestCase:The preset action of the test suite is executed before the first TestCase
SetUpTestCase(void)155     static void SetUpTestCase(void)
156     {
157     }
158 // TearDownTestCase:The test suite cleanup action is executed after the last TestCase
TearDownTestCase(void)159     static void TearDownTestCase(void)
160     {
161     }
162 // SetUp:Execute before each test case
SetUp()163     virtual void SetUp()
164     {
165         g_tagTestSample.adaptr = std::make_shared<Player>();
166     }
167 // TearDown:Execute after each test case
TearDown()168     virtual void TearDown()
169     {
170     }
171 };
172 
173 class PlayerliteCallback : public Media::PlayerCallback {
174 public:
175     PlayerliteCallback() = default;
176 
177     virtual ~PlayerliteCallback() = default;
178 
179     void OnPlaybackComplete() override;
180 
181     void OnError(int32_t errorType, int32_t errorCode) override;
182 
183     void OnInfo(int32_t type, int32_t extra) override;
184 
185     void OnVideoSizeChanged(int width, int height) override;
186 
187     void OnRewindToComplete() override;
188 };
189 
OnPlaybackComplete()190 void PlayerliteCallback::OnPlaybackComplete()
191 {
192     cout << "PlayerTest::OnPlaybackComplete ..." << endl;
193 }
194 
OnError(int32_t errorType,int32_t errorCode)195 void PlayerliteCallback::OnError(int32_t errorType, int32_t errorCode)
196 {
197     cout << "PlayerTest::OnError ..." << endl;
198 }
199 
OnInfo(int32_t type,int32_t extra)200 void PlayerliteCallback::OnInfo(int32_t type, int32_t extra)
201 {
202     cout << "PlayerTest::OnInfo ..." << endl;
203 }
204 
OnVideoSizeChanged(int width,int height)205 void PlayerliteCallback::OnVideoSizeChanged(int width, int height)
206 {
207     cout << "PlayerTest::OnVideoSizeChanged ..." << endl;
208 }
209 
OnRewindToComplete()210 void PlayerliteCallback::OnRewindToComplete()
211 {
212     cout << "PlayerTest::OnRewindToComplete ..." << endl;
213 }
214 
215 
FileCheck(const string & argv)216 static int32_t FileCheck(const string &argv)
217 {
218     if (strlen(argv.c_str()) < sizeof(g_tagTestSample.filePath) &&
219         realpath(argv.c_str(), g_tagTestSample.filePath) == nullptr) {
220         printf("realpath input file failed, errno: %d!\n", errno);
221         return -1;
222     }
223     return 0;
224 }
225 
CreateAndSetSource()226 static int32_t CreateAndSetSource()
227 {
228     std::string uri(g_tagTestSample.filePath);
229     Source source(uri);
230     int32_t ret = g_tagTestSample.adaptr->SetSource(source);
231     string ret1 = source.GetSourceUri();
232     return ret;
233 }
234 
235 /* *
236  * @tc.number    : SUB_MEDIA_PLAYER_PLAY_0100
237  * @tc.name      : Audio Prepare(),Play() Test.
238  * @tc.desc      : [C- SOFTWARE -0200]
239  */
HWTEST_F(ActsMediaPlayerAudioTest,player_lite_audio_test_001,Level1)240 HWTEST_F(ActsMediaPlayerAudioTest, player_lite_audio_test_001, Level1)
241 {
242     int32_t ret = FileCheck(g_audioFileName);
243     EXPECT_EQ(HI_SUCCESS, ret);
244     ret = CreateAndSetSource();
245     EXPECT_EQ(HI_SUCCESS, ret);
246     ret = g_tagTestSample.adaptr->Prepare();
247     EXPECT_EQ(HI_SUCCESS, ret);
248     ret = g_tagTestSample.adaptr->Play();
249     EXPECT_EQ(HI_SUCCESS, ret);
250     sleep(2);
251     g_tagTestSample.adaptr->Release();
252     sleep(1);
253 }
254 
255 /* *
256  * @tc.number    : SUB_MEDIA_PLAYER_PLAY_0200
257  * @tc.name      : Audio Play() Pause() Stop() Test.
258  * @tc.desc      : [C- SOFTWARE -0200]
259  */
HWTEST_F(ActsMediaPlayerAudioTest,player_lite_audio_test_002,Level1)260 HWTEST_F(ActsMediaPlayerAudioTest, player_lite_audio_test_002, Level1)
261 {
262     int32_t ret = FileCheck(g_audioFileName);
263     EXPECT_EQ(HI_SUCCESS, ret);
264     std::shared_ptr<PlayerliteCallback> callBack;
265     callBack = std::make_shared<PlayerliteCallback>();
266     g_tagTestSample.adaptr->SetPlayerCallback(callBack);
267     ret = CreateAndSetSource();
268     EXPECT_EQ(HI_SUCCESS, ret);
269     ret = g_tagTestSample.adaptr->Prepare();
270     EXPECT_EQ(HI_SUCCESS, ret);
271     ret = g_tagTestSample.adaptr->Play();
272     EXPECT_EQ(HI_SUCCESS, ret);
273     ret = g_tagTestSample.adaptr->Pause();
274     EXPECT_EQ(HI_SUCCESS, ret);
275     ret = g_tagTestSample.adaptr->Play();
276     EXPECT_EQ(HI_SUCCESS, ret);
277     ret = g_tagTestSample.adaptr->Stop();
278     EXPECT_EQ(HI_SUCCESS, ret);
279     g_tagTestSample.adaptr->Release();
280     sleep(1);
281 }
282 
283 /* *
284  * @tc.number    : SUB_MEDIA_PLAYER_PLAY_0300
285  * @tc.name      : Audio Play() stop() Test.
286  * @tc.desc      : [C- SOFTWARE -0200]
287  */
HWTEST_F(ActsMediaPlayerAudioTest,player_lite_audio_test_003,Level1)288 HWTEST_F(ActsMediaPlayerAudioTest, player_lite_audio_test_003, Level1)
289 {
290     int32_t ret = FileCheck(g_audioFileName);
291     EXPECT_EQ(HI_SUCCESS, ret);
292     std::shared_ptr<PlayerliteCallback> callBack;
293     callBack = std::make_shared<PlayerliteCallback>();
294     g_tagTestSample.adaptr->SetPlayerCallback(callBack);
295     ret = CreateAndSetSource();
296     EXPECT_EQ(HI_SUCCESS, ret);
297     ret = g_tagTestSample.adaptr->Prepare();
298     EXPECT_EQ(HI_SUCCESS, ret);
299     ret = g_tagTestSample.adaptr->Play();
300     EXPECT_EQ(HI_SUCCESS, ret);
301     ret = g_tagTestSample.adaptr->Stop();
302     EXPECT_EQ(HI_SUCCESS, ret);
303     ret = g_tagTestSample.adaptr->Play();
304     EXPECT_EQ(HI_FAILURE, ret);
305     g_tagTestSample.adaptr->Release();
306     sleep(1);
307 }
308 
309 /* *
310  * @tc.number    : SUB_MEDIA_PLAYER_PLAY_0400
311  * @tc.name      : Audio Prepare() Test.
312  * @tc.desc      : [C- SOFTWARE -0200]
313  */
HWTEST_F(ActsMediaPlayerAudioTest,player_lite_audio_test_004,Level1)314 HWTEST_F(ActsMediaPlayerAudioTest, player_lite_audio_test_004, Level1)
315 {
316     int32_t ret = FileCheck(g_audioFileName);
317     EXPECT_EQ(HI_SUCCESS, ret);
318     std::shared_ptr<PlayerliteCallback> callBack;
319     callBack = std::make_shared<PlayerliteCallback>();
320     g_tagTestSample.adaptr->SetPlayerCallback(callBack);
321     ret = CreateAndSetSource();
322     EXPECT_EQ(HI_SUCCESS, ret);
323     ret = g_tagTestSample.adaptr->Prepare();
324     EXPECT_EQ(HI_SUCCESS, ret);
325     g_tagTestSample.adaptr->Release();
326     sleep(1);
327 }
328 
329 /* *
330  * @tc.number    : SUB_MEDIA_PLAYER_PLAY_0500
331  * @tc.name      : Audio Prepare() Test.
332  * @tc.desc      : [C- SOFTWARE -0200]
333  */
HWTEST_F(ActsMediaPlayerAudioTest,player_lite_audio_test_005,Level1)334 HWTEST_F(ActsMediaPlayerAudioTest, player_lite_audio_test_005, Level1)
335 {
336     int32_t ret = FileCheck(g_audioFileName);
337     EXPECT_EQ(HI_SUCCESS, ret);
338     std::shared_ptr<PlayerliteCallback> callBack;
339     callBack = std::make_shared<PlayerliteCallback>();
340     g_tagTestSample.adaptr->SetPlayerCallback(callBack);
341     ret = CreateAndSetSource();
342     EXPECT_EQ(HI_SUCCESS, ret);
343     ret = g_tagTestSample.adaptr->Prepare();
344     EXPECT_EQ(HI_SUCCESS, ret);
345     ret = g_tagTestSample.adaptr->Prepare();
346     EXPECT_EQ(HI_SUCCESS, ret);
347     g_tagTestSample.adaptr->Release();
348     sleep(1);
349 }
350 
351 /* *
352  * @tc.number    : SUB_MEDIA_PLAYER_PLAY_0600
353  * @tc.name      : Audio Play(),Stop() Test
354  * @tc.desc      : [C- SOFTWARE -0200]
355  */
HWTEST_F(ActsMediaPlayerAudioTest,player_lite_audio_test_006,Level1)356 HWTEST_F(ActsMediaPlayerAudioTest, player_lite_audio_test_006, Level1)
357 {
358     int32_t ret = FileCheck(g_audioFileName);
359     EXPECT_EQ(HI_SUCCESS, ret);
360     std::shared_ptr<PlayerliteCallback> callBack;
361     callBack = std::make_shared<PlayerliteCallback>();
362     g_tagTestSample.adaptr->SetPlayerCallback(callBack);
363     ret = CreateAndSetSource();
364     EXPECT_EQ(HI_SUCCESS, ret);
365     ret = g_tagTestSample.adaptr->Prepare();
366     EXPECT_EQ(HI_SUCCESS, ret);
367     ret = g_tagTestSample.adaptr->Play();
368     EXPECT_EQ(HI_SUCCESS, ret);
369     ret = g_tagTestSample.adaptr->Stop();
370     EXPECT_EQ(HI_SUCCESS, ret);
371     g_tagTestSample.adaptr->Release();
372     sleep(1);
373 }
374 
375  /* *
376  * @tc.number    : SUB_MEDIA_PLAYER_PLAY_0700
377  * @tc.name      : Audio Play(),Stop(),IsPlay() Test.
378  * @tc.desc      : [C- SOFTWARE -0200]
379  */
HWTEST_F(ActsMediaPlayerAudioTest,player_lite_audio_test_007,Level1)380 HWTEST_F(ActsMediaPlayerAudioTest, player_lite_audio_test_007, Level1)
381 {
382     int32_t ret = FileCheck(g_audioFileName);
383     EXPECT_EQ(HI_SUCCESS, ret);
384     std::shared_ptr<PlayerliteCallback> callBack;
385     callBack = std::make_shared<PlayerliteCallback>();
386     g_tagTestSample.adaptr->SetPlayerCallback(callBack);
387     ret = CreateAndSetSource();
388     EXPECT_EQ(HI_SUCCESS, ret);
389     ret = g_tagTestSample.adaptr->Prepare();
390     EXPECT_EQ(HI_SUCCESS, ret);
391     ret = g_tagTestSample.adaptr->Play();
392     EXPECT_EQ(HI_SUCCESS, ret);
393     ret = g_tagTestSample.adaptr->Stop();
394     EXPECT_EQ(HI_SUCCESS, ret);
395     bool flag = g_tagTestSample.adaptr->IsPlaying();
396     EXPECT_EQ(false, flag);
397     g_tagTestSample.adaptr->Release();
398     sleep(1);
399 }
400 
401  /* *
402  * @tc.number    : SUB_MEDIA_PLAYER_PLAY_0800
403  * @tc.name      : Audio IsPlay() Test.
404  * @tc.desc      : [C- SOFTWARE -0200]
405  */
HWTEST_F(ActsMediaPlayerAudioTest,player_lite_audio_test_008,Level1)406 HWTEST_F(ActsMediaPlayerAudioTest, player_lite_audio_test_008, Level1)
407 {
408     int32_t ret = FileCheck(g_audioFileName);
409     EXPECT_EQ(HI_SUCCESS, ret);
410     std::shared_ptr<PlayerliteCallback> callBack;
411     callBack = std::make_shared<PlayerliteCallback>();
412     g_tagTestSample.adaptr->SetPlayerCallback(callBack);
413     ret = CreateAndSetSource();
414     EXPECT_EQ(HI_SUCCESS, ret);
415     ret = g_tagTestSample.adaptr->Prepare();
416     EXPECT_EQ(HI_SUCCESS, ret);
417     ret = g_tagTestSample.adaptr->Play();
418     EXPECT_EQ(HI_SUCCESS, ret);
419     bool flag = g_tagTestSample.adaptr->IsPlaying();
420     EXPECT_EQ(true, flag);
421     g_tagTestSample.adaptr->Release();
422     sleep(1);
423 }
424 
425  /* *
426  * @tc.number    : SUB_MEDIA_PLAYER_PLAY_0900
427  * @tc.name      : Audio  Play() Pause() Test.
428  * @tc.desc      : [C- SOFTWARE -0200]
429  */
HWTEST_F(ActsMediaPlayerAudioTest,player_lite_audio_test_009,Level1)430 HWTEST_F(ActsMediaPlayerAudioTest, player_lite_audio_test_009, Level1)
431 {
432     int32_t ret = FileCheck(g_audioFileName);
433     EXPECT_EQ(HI_SUCCESS, ret);
434     std::shared_ptr<PlayerliteCallback> callBack;
435     callBack = std::make_shared<PlayerliteCallback>();
436     g_tagTestSample.adaptr->SetPlayerCallback(callBack);
437     ret = CreateAndSetSource();
438     EXPECT_EQ(HI_SUCCESS, ret);
439     ret = g_tagTestSample.adaptr->Prepare();
440     EXPECT_EQ(HI_SUCCESS, ret);
441     ret = g_tagTestSample.adaptr->Play();
442     EXPECT_EQ(HI_SUCCESS, ret);
443     ret = g_tagTestSample.adaptr->Pause();
444     EXPECT_EQ(HI_SUCCESS, ret);
445     ret = g_tagTestSample.adaptr->Pause();
446     EXPECT_EQ(HI_SUCCESS, ret);
447     g_tagTestSample.adaptr->Release();
448     sleep(1);
449 }
450 
451  /* *
452  * @tc.number    : SUB_MEDIA_PLAYER_PLAY_1000
453  * @tc.name      : Audio Pause Test.
454  * @tc.desc      : [C- SOFTWARE -0200]
455  */
HWTEST_F(ActsMediaPlayerAudioTest,player_lite_audio_test_010,Level1)456 HWTEST_F(ActsMediaPlayerAudioTest, player_lite_audio_test_010, Level1)
457 {
458     int32_t ret = FileCheck(g_audioFileName);
459     EXPECT_EQ(HI_SUCCESS, ret);
460     std::shared_ptr<PlayerliteCallback> callBack;
461     callBack = std::make_shared<PlayerliteCallback>();
462     g_tagTestSample.adaptr->SetPlayerCallback(callBack);
463     ret = CreateAndSetSource();
464     EXPECT_EQ(HI_SUCCESS, ret);
465     ret = g_tagTestSample.adaptr->Prepare();
466     EXPECT_EQ(HI_SUCCESS, ret);
467     ret = g_tagTestSample.adaptr->Pause();
468     EXPECT_EQ(HI_FAILURE, ret);
469     g_tagTestSample.adaptr->Release();
470     sleep(1);
471 }
472 
473  /* *
474  * @tc.number    : SUB_MEDIA_PLAYER_PLAY_1100
475  * @tc.name      : Audio SetVolume Test.
476  * @tc.desc      : [C- SOFTWARE -0200]
477  */
HWTEST_F(ActsMediaPlayerAudioTest,player_lite_audio_test_011,Level1)478 HWTEST_F(ActsMediaPlayerAudioTest, player_lite_audio_test_011, Level1)
479 {
480     int32_t ret = FileCheck(g_audioFileName);
481     EXPECT_EQ(HI_SUCCESS, ret);
482     std::shared_ptr<PlayerliteCallback> callBack;
483     callBack = std::make_shared<PlayerliteCallback>();
484     g_tagTestSample.adaptr->SetPlayerCallback(callBack);
485     ret = CreateAndSetSource();
486     EXPECT_EQ(HI_SUCCESS, ret);
487     ret = g_tagTestSample.adaptr->Prepare();
488     EXPECT_EQ(HI_SUCCESS, ret);
489     ret = g_tagTestSample.adaptr->Play();
490     EXPECT_EQ(HI_SUCCESS, ret);
491     ret = g_tagTestSample.adaptr->SetVolume(40, 40);
492     sleep(10);
493     EXPECT_EQ(HI_SUCCESS, ret);
494     g_tagTestSample.adaptr->Release();
495     sleep(1);
496 }
497 
498  /* *
499  * @tc.number    : SUB_MEDIA_PLAYER_PLAY_1200
500  * @tc.name      : Audio SetVolume Test.
501  * @tc.desc      : [C- SOFTWARE -0200]
502  */
HWTEST_F(ActsMediaPlayerAudioTest,player_lite_audio_test_012,Level1)503 HWTEST_F(ActsMediaPlayerAudioTest, player_lite_audio_test_012, Level1)
504 {
505     int32_t ret = FileCheck(g_audioFileName);
506     EXPECT_EQ(HI_SUCCESS, ret);
507     std::shared_ptr<PlayerliteCallback> callBack;
508     callBack = std::make_shared<PlayerliteCallback>();
509     g_tagTestSample.adaptr->SetPlayerCallback(callBack);
510     ret = CreateAndSetSource();
511     EXPECT_EQ(HI_SUCCESS, ret);
512     ret = g_tagTestSample.adaptr->Prepare();
513     EXPECT_EQ(HI_SUCCESS, ret);
514     ret = g_tagTestSample.adaptr->Play();
515     EXPECT_EQ(HI_SUCCESS, ret);
516     ret = g_tagTestSample.adaptr->SetVolume(0, 0);
517     sleep(10);
518     EXPECT_EQ(HI_SUCCESS, ret);
519     g_tagTestSample.adaptr->Release();
520     sleep(1);
521 }
522 
523 /* *
524  * @tc.number    : SUB_MEDIA_PLAYER_PLAY_1300
525  * @tc.name      : Audio SetVolume Test.
526  * @tc.desc      : [C- SOFTWARE -0200]
527  */
HWTEST_F(ActsMediaPlayerAudioTest,player_lite_audio_test_013,Level1)528 HWTEST_F(ActsMediaPlayerAudioTest, player_lite_audio_test_013, Level1)
529 {
530     int32_t ret = FileCheck(g_audioFileName);
531     EXPECT_EQ(HI_SUCCESS, ret);
532     std::shared_ptr<PlayerliteCallback> callBack;
533     callBack = std::make_shared<PlayerliteCallback>();
534     g_tagTestSample.adaptr->SetPlayerCallback(callBack);
535     ret = CreateAndSetSource();
536     EXPECT_EQ(HI_SUCCESS, ret);
537     ret = g_tagTestSample.adaptr->Prepare();
538     EXPECT_EQ(HI_SUCCESS, ret);
539     ret = g_tagTestSample.adaptr->Play();
540     EXPECT_EQ(HI_SUCCESS, ret);
541     ret = g_tagTestSample.adaptr->SetVolume(-1, -1);
542     sleep(10);
543     EXPECT_EQ(HI_FAILURE, ret);
544     g_tagTestSample.adaptr->Release();
545     sleep(1);
546 }
547 
548 /* *
549  * @tc.number    : SUB_MEDIA_PLAYER_PLAY_1400
550  * @tc.name      : Audio SetVolume Test.
551  * @tc.desc      : [C- SOFTWARE -0200]
552  */
HWTEST_F(ActsMediaPlayerAudioTest,player_lite_audio_test_014,Level1)553 HWTEST_F(ActsMediaPlayerAudioTest, player_lite_audio_test_014, Level1)
554 {
555     int32_t ret = FileCheck(g_audioFileName);
556     EXPECT_EQ(HI_SUCCESS, ret);
557     std::shared_ptr<PlayerliteCallback> callBack;
558     callBack = std::make_shared<PlayerliteCallback>();
559     g_tagTestSample.adaptr->SetPlayerCallback(callBack);
560     ret = CreateAndSetSource();
561     EXPECT_EQ(HI_SUCCESS, ret);
562     ret = g_tagTestSample.adaptr->Prepare();
563     EXPECT_EQ(HI_SUCCESS, ret);
564     ret = g_tagTestSample.adaptr->Play();
565     EXPECT_EQ(HI_SUCCESS, ret);
566     ret = g_tagTestSample.adaptr->SetVolume(300, 300);
567     sleep(10);
568     EXPECT_EQ(HI_SUCCESS, ret);
569     g_tagTestSample.adaptr->Release();
570     sleep(1);
571 }
572 
573 /* *
574  * @tc.number    : SUB_MEDIA_PLAYER_PLAY_1500
575  * @tc.name      : Audio SetVolume Test.
576  * @tc.desc      : [C- SOFTWARE -0200]
577  */
HWTEST_F(ActsMediaPlayerAudioTest,player_lite_audio_test_015,Level1)578 HWTEST_F(ActsMediaPlayerAudioTest, player_lite_audio_test_015, Level1)
579 {
580     int32_t ret = FileCheck(g_audioFileName);
581     EXPECT_EQ(HI_SUCCESS, ret);
582     std::shared_ptr<PlayerliteCallback> callBack;
583     callBack = std::make_shared<PlayerliteCallback>();
584     g_tagTestSample.adaptr->SetPlayerCallback(callBack);
585     ret = CreateAndSetSource();
586     EXPECT_EQ(HI_SUCCESS, ret);
587     ret = g_tagTestSample.adaptr->Prepare();
588     EXPECT_EQ(HI_SUCCESS, ret);
589     ret = g_tagTestSample.adaptr->Play();
590     EXPECT_EQ(HI_SUCCESS, ret);
591     ret = g_tagTestSample.adaptr->SetVolume(300, 301);
592     sleep(10);
593     EXPECT_EQ(HI_FAILURE, ret);
594     g_tagTestSample.adaptr->Release();
595     sleep(1);
596 }
597 
598 /* *
599  * @tc.number    : SUB_MEDIA_PLAYER_PLAY_1600
600  * @tc.name      : Audio SetVolume Test.
601  * @tc.desc      : [C- SOFTWARE -0200]
602  */
HWTEST_F(ActsMediaPlayerAudioTest,player_lite_audio_test_016,Level1)603 HWTEST_F(ActsMediaPlayerAudioTest, player_lite_audio_test_016, Level1)
604 {
605     int32_t ret = FileCheck(g_audioFileName);
606     EXPECT_EQ(HI_SUCCESS, ret);
607     std::shared_ptr<PlayerliteCallback> callBack;
608     callBack = std::make_shared<PlayerliteCallback>();
609     g_tagTestSample.adaptr->SetPlayerCallback(callBack);
610     ret = CreateAndSetSource();
611     EXPECT_EQ(HI_SUCCESS, ret);
612     ret = g_tagTestSample.adaptr->Prepare();
613     EXPECT_EQ(HI_SUCCESS, ret);
614     ret = g_tagTestSample.adaptr->Play();
615     EXPECT_EQ(HI_SUCCESS, ret);
616     ret = g_tagTestSample.adaptr->SetVolume(50, 100);
617     sleep(10);
618     EXPECT_EQ(HI_SUCCESS, ret);
619     g_tagTestSample.adaptr->Release();
620     sleep(1);
621 }
622 
623 /* *
624  * @tc.number    : SUB_MEDIA_PLAYER_PLAY_1700
625  * @tc.name      : Audio Play, GetCurrentTime Test.
626  * @tc.desc      : [C- SOFTWARE -0200]
627  */
HWTEST_F(ActsMediaPlayerAudioTest,player_lite_audio_test_017,Level1)628 HWTEST_F(ActsMediaPlayerAudioTest, player_lite_audio_test_017, Level1)
629 {
630     int32_t ret = FileCheck(g_audioFileName);
631     EXPECT_EQ(HI_SUCCESS, ret);
632     std::shared_ptr<PlayerliteCallback> callBack;
633     callBack = std::make_shared<PlayerliteCallback>();
634     g_tagTestSample.adaptr->SetPlayerCallback(callBack);
635     ret = CreateAndSetSource();
636     EXPECT_EQ(HI_SUCCESS, ret);
637     ret = g_tagTestSample.adaptr->Prepare();
638     EXPECT_EQ(HI_SUCCESS, ret);
639     ret = g_tagTestSample.adaptr->Play();
640     EXPECT_EQ(HI_SUCCESS, ret);
641     sleep(3);
642     int64_t currentPosition;
643     ret = g_tagTestSample.adaptr->GetCurrentTime(currentPosition);
644     EXPECT_EQ(HI_SUCCESS, ret);
645     g_tagTestSample.adaptr->Release();
646     sleep(1);
647 }
648 
649 /* *
650  * @tc.number    : SUB_MEDIA_PLAYER_PLAY_1800
651  * @tc.name      : Audio Play, GetCurrentTime Test.
652  * @tc.desc      : [C- SOFTWARE -0200]
653  */
HWTEST_F(ActsMediaPlayerAudioTest,player_lite_audio_test_018,Level1)654 HWTEST_F(ActsMediaPlayerAudioTest, player_lite_audio_test_018, Level1)
655 {
656     int32_t ret = FileCheck(g_audioFileName);
657     EXPECT_EQ(HI_SUCCESS, ret);
658     std::shared_ptr<PlayerliteCallback> callBack;
659     callBack = std::make_shared<PlayerliteCallback>();
660     g_tagTestSample.adaptr->SetPlayerCallback(callBack);
661     ret = CreateAndSetSource();
662     EXPECT_EQ(HI_SUCCESS, ret);
663     ret = g_tagTestSample.adaptr->Prepare();
664     EXPECT_EQ(HI_SUCCESS, ret);
665     ret = g_tagTestSample.adaptr->Play();
666     EXPECT_EQ(HI_SUCCESS, ret);
667     g_tagTestSample.adaptr->Pause();
668     ret = g_tagTestSample.adaptr->Rewind(0, PLAYER_SEEK_NEXT_SYNC);
669     EXPECT_EQ(HI_SUCCESS, ret);
670     int64_t currentPosition;
671     ret = g_tagTestSample.adaptr->GetCurrentTime(currentPosition);
672     EXPECT_EQ(HI_SUCCESS, ret);
673     g_tagTestSample.adaptr->Release();
674     sleep(1);
675 }
676 
677 /* *
678  * @tc.number    : SUB_MEDIA_PLAYER_PLAY_1900
679  * @tc.name      : Audio Seek Test.
680  * @tc.desc      : [C- SOFTWARE -0200]
681  */
HWTEST_F(ActsMediaPlayerAudioTest,player_lite_audio_test_019,Level1)682 HWTEST_F(ActsMediaPlayerAudioTest, player_lite_audio_test_019, Level1)
683 {
684     int32_t ret = FileCheck(g_audioFileName);
685     EXPECT_EQ(HI_SUCCESS, ret);
686     std::shared_ptr<PlayerliteCallback> callBack;
687     callBack = std::make_shared<PlayerliteCallback>();
688     g_tagTestSample.adaptr->SetPlayerCallback(callBack);
689     ret = CreateAndSetSource();
690     EXPECT_EQ(HI_SUCCESS, ret);
691     ret = g_tagTestSample.adaptr->Prepare();
692     EXPECT_EQ(HI_SUCCESS, ret);
693     ret = g_tagTestSample.adaptr->Play();
694     EXPECT_EQ(HI_SUCCESS, ret);
695     g_tagTestSample.adaptr->Pause();
696     ret = g_tagTestSample.adaptr->Rewind(4, PLAYER_SEEK_NEXT_SYNC);
697     EXPECT_EQ(HI_SUCCESS, ret);
698     g_tagTestSample.adaptr->Release();
699     sleep(1);
700 }
701 
702 /* *
703  * @tc.number    : SUB_MEDIA_PLAYER_PLAY_2000
704  * @tc.name      : Audio  GetDuration Test.
705  * @tc.desc      : [C- SOFTWARE -0200]
706  */
HWTEST_F(ActsMediaPlayerAudioTest,player_lite_audio_test_020,Level1)707 HWTEST_F(ActsMediaPlayerAudioTest, player_lite_audio_test_020, Level1)
708 {
709     int32_t ret = FileCheck(g_audioFileName);
710     EXPECT_EQ(HI_SUCCESS, ret);
711     std::shared_ptr<PlayerliteCallback> callBack;
712     callBack = std::make_shared<PlayerliteCallback>();
713     g_tagTestSample.adaptr->SetPlayerCallback(callBack);
714     ret = CreateAndSetSource();
715     EXPECT_EQ(HI_SUCCESS, ret);
716     ret = g_tagTestSample.adaptr->Prepare();
717     EXPECT_EQ(HI_SUCCESS, ret);
718     int64_t duration;
719     ret = g_tagTestSample.adaptr->GetDuration(duration);
720     EXPECT_EQ(HI_SUCCESS, ret);
721     g_tagTestSample.adaptr->Release();
722     sleep(1);
723 }
724 
725 /* *
726  * @tc.number    : SUB_MEDIA_PLAYER_PLAY_2100
727  * @tc.name      : Audio  GetDuration Test.
728  * @tc.desc      : [C- SOFTWARE -0200]
729  */
HWTEST_F(ActsMediaPlayerAudioTest,player_lite_audio_test_021,Level1)730 HWTEST_F(ActsMediaPlayerAudioTest, player_lite_audio_test_021, Level1)
731 {
732     int32_t ret = FileCheck(g_audioFileName);
733     EXPECT_EQ(HI_SUCCESS, ret);
734     std::shared_ptr<PlayerliteCallback> callBack;
735     callBack = std::make_shared<PlayerliteCallback>();
736     g_tagTestSample.adaptr->SetPlayerCallback(callBack);
737     ret = CreateAndSetSource();
738     EXPECT_EQ(HI_SUCCESS, ret);
739     ret = g_tagTestSample.adaptr->Prepare();
740     EXPECT_EQ(HI_SUCCESS, ret);
741     ret = g_tagTestSample.adaptr->Play();
742     EXPECT_EQ(HI_SUCCESS, ret);
743     int64_t duration;
744     ret = g_tagTestSample.adaptr->GetDuration(duration);
745     EXPECT_EQ(HI_SUCCESS, ret);
746     g_tagTestSample.adaptr->Release();
747     sleep(1);
748 }
749 
750 /* *
751  * @tc.number    : SUB_MEDIA_PLAYER_PLAY_2200
752  * @tc.name      : Audio Reset Test.
753  * @tc.desc      : [C- SOFTWARE -0200]
754  */
HWTEST_F(ActsMediaPlayerAudioTest,player_lite_audio_test_022,Level1)755 HWTEST_F(ActsMediaPlayerAudioTest, player_lite_audio_test_022, Level1)
756 {
757     int32_t ret = FileCheck(g_audioFileName);
758     EXPECT_EQ(HI_SUCCESS, ret);
759     std::shared_ptr<PlayerliteCallback> callBack;
760     callBack = std::make_shared<PlayerliteCallback>();
761     g_tagTestSample.adaptr->SetPlayerCallback(callBack);
762     ret = CreateAndSetSource();
763     EXPECT_EQ(HI_SUCCESS, ret);
764     ret = g_tagTestSample.adaptr->Prepare();
765     EXPECT_EQ(HI_SUCCESS, ret);
766     ret = g_tagTestSample.adaptr->Play();
767     EXPECT_EQ(HI_SUCCESS, ret);
768     ret = g_tagTestSample.adaptr->Reset();
769     EXPECT_EQ(HI_SUCCESS, ret);
770     g_tagTestSample.adaptr->Release();
771     sleep(1);
772 }
773 
774 /* *
775  * @tc.number    : SUB_MEDIA_PLAYER_PLAY_2300
776  * @tc.name      : Audio Reset Test.
777  * @tc.desc      : [C- SOFTWARE -0200]
778  */
HWTEST_F(ActsMediaPlayerAudioTest,player_lite_audio_test_023,Level1)779 HWTEST_F(ActsMediaPlayerAudioTest, player_lite_audio_test_023, Level1)
780 {
781     int32_t ret = FileCheck(g_audioFileName);
782     EXPECT_EQ(HI_SUCCESS, ret);
783     std::shared_ptr<PlayerliteCallback> callBack;
784     callBack = std::make_shared<PlayerliteCallback>();
785     g_tagTestSample.adaptr->SetPlayerCallback(callBack);
786     ret = CreateAndSetSource();
787     EXPECT_EQ(HI_SUCCESS, ret);
788     ret = g_tagTestSample.adaptr->Reset();
789     EXPECT_EQ(HI_SUCCESS, ret);
790     g_tagTestSample.adaptr->Release();
791     sleep(1);
792 }
793 
794 /* *
795  * @tc.number    : SUB_MEDIA_PLAYER_PLAY_2400
796  * @tc.name      : Audio EnableSingleLoop() Test.
797  * @tc.desc      : [C- SOFTWARE -0200]
798  */
HWTEST_F(ActsMediaPlayerAudioTest,player_lite_audio_test_024,Level1)799 HWTEST_F(ActsMediaPlayerAudioTest, player_lite_audio_test_024, Level1)
800 {
801     int32_t ret = FileCheck(g_audioFileName);
802     EXPECT_EQ(HI_SUCCESS, ret);
803     std::shared_ptr<PlayerliteCallback> callBack;
804     callBack = std::make_shared<PlayerliteCallback>();
805     g_tagTestSample.adaptr->SetPlayerCallback(callBack);
806     ret = CreateAndSetSource();
807     EXPECT_EQ(HI_SUCCESS, ret);
808     ret = g_tagTestSample.adaptr->Prepare();
809     EXPECT_EQ(HI_SUCCESS, ret);
810     bool loop = true;
811     ret = g_tagTestSample.adaptr->EnableSingleLooping(loop);
812     EXPECT_EQ(HI_SUCCESS, ret);
813     ret = g_tagTestSample.adaptr->Play();
814     EXPECT_EQ(HI_SUCCESS, ret);
815     bool flag = g_tagTestSample.adaptr->IsPlaying();
816     EXPECT_EQ(true, flag);
817     g_tagTestSample.adaptr->Release();
818     sleep(1);
819 }
820 
821 /* *
822  * @tc.number    : SUB_MEDIA_PLAYER_PLAY_2500
823  * @tc.name      : Audio EnableSingleLoop() Test.
824  * @tc.desc      : [C- SOFTWARE -0200]
825  */
HWTEST_F(ActsMediaPlayerAudioTest,player_lite_audio_test_025,Level1)826 HWTEST_F(ActsMediaPlayerAudioTest, player_lite_audio_test_025, Level1)
827 {
828     int32_t ret = FileCheck(g_audioFileName);
829     EXPECT_EQ(HI_SUCCESS, ret);
830     std::shared_ptr<PlayerliteCallback> callBack;
831     callBack = std::make_shared<PlayerliteCallback>();
832     g_tagTestSample.adaptr->SetPlayerCallback(callBack);
833     ret = CreateAndSetSource();
834     EXPECT_EQ(HI_SUCCESS, ret);
835     ret = g_tagTestSample.adaptr->Prepare();
836     EXPECT_EQ(HI_SUCCESS, ret);
837     ret = g_tagTestSample.adaptr->Play();
838     sleep(1);
839     EXPECT_EQ(HI_SUCCESS, ret);
840     bool loop = true;
841     ret = g_tagTestSample.adaptr->EnableSingleLooping(loop);
842     EXPECT_EQ(HI_SUCCESS, ret);
843     bool flag = g_tagTestSample.adaptr->IsPlaying();
844     EXPECT_EQ(true, flag);
845     g_tagTestSample.adaptr->Release();
846     sleep(1);
847 }
848 } // OHOS
849