• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-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 "gtest/gtest.h"
17 #include "audio_sink.h"
18 #include "audio_effect.h"
19 #include "filter/filter.h"
20 #include "common/log.h"
21 
22 using namespace testing::ext;
23 
24 namespace OHOS {
25 namespace Media {
26 namespace Test {
27 
28 class TestEventReceiver : public Pipeline::EventReceiver {
29 public:
TestEventReceiver()30     explicit TestEventReceiver()
31     {
32         MEDIA_LOG_I("TestEventReceiver ctor ");
33     }
34 
OnEvent(const Event & event)35     void OnEvent(const Event &event)
36     {
37         MEDIA_LOG_I("TestEventReceiver OnEvent " PUBLIC_LOG_S, event.srcFilter.c_str());
38     }
39 
40 private:
41 };
42 
AudioSinkCreate()43 std::shared_ptr<AudioSink> AudioSinkCreate()
44 {
45     auto audioSink = std::make_shared<AudioSink>();
46     std::shared_ptr<Pipeline::EventReceiver> testEventReceiver = std::make_shared<TestEventReceiver>();
47     auto meta = std::make_shared<Meta>();
48     auto initStatus = audioSink->Init(meta, testEventReceiver);
49     if (initStatus == Status::OK) {
50         return audioSink;
51     } else {
52         return nullptr;
53     }
54 }
55 
56 HWTEST(TestAudioSink, find_audio_sink_process, TestSize.Level1)
57 {
58     std::shared_ptr<AudioSink> audioSink = AudioSinkCreate();
59     ASSERT_TRUE(audioSink != nullptr);
60     auto preStatus = audioSink->Prepare();
61     ASSERT_TRUE(preStatus == Status::OK);
62     auto startStatus = audioSink->Start();
63     ASSERT_TRUE(startStatus == Status::OK);
64     auto pauseStatus = audioSink->Pause();
65     ASSERT_TRUE(pauseStatus == Status::OK);
66     auto stopStatus = audioSink->Stop();
67     ASSERT_TRUE(stopStatus == Status::OK);
68     auto flushStatus = audioSink->Flush();
69     ASSERT_TRUE(flushStatus == Status::OK);
70     auto resumeStatus = audioSink->Resume();
71     ASSERT_TRUE(resumeStatus == Status::OK);
72     auto freeStatus = audioSink->Release();
73     ASSERT_TRUE(freeStatus == Status::OK);
74 }
75 
76 HWTEST(TestAudioSink, find_audio_sink_set_volume, TestSize.Level1)
77 {
78     std::shared_ptr<AudioSink> audioSink = AudioSinkCreate();
79     ASSERT_TRUE(audioSink != nullptr);
80     float volume = 0.5f;
81     auto setVolumeStatus =  audioSink->SetVolume(volume);
82     ASSERT_TRUE(setVolumeStatus == Status::OK);
83 }
84 
85 HWTEST(TestAudioSink, find_audio_sink_set_speed, TestSize.Level1)
86 {
87     std::shared_ptr<AudioSink> audioSink = AudioSinkCreate();
88     ASSERT_TRUE(audioSink != nullptr);
89     float speed = 1.0f;
90     auto setVolumeStatus =  audioSink->SetSpeed(speed);
91     ASSERT_TRUE(setVolumeStatus == Status::OK);
92 }
93 
94 HWTEST(TestAudioSink, find_audio_sink_audio_effect, TestSize.Level1)
95 {
96     std::shared_ptr<AudioSink> audioSink = AudioSinkCreate();
97     ASSERT_TRUE(audioSink != nullptr);
98     auto setEffectStatus =  audioSink->SetAudioEffectMode(AudioStandard::EFFECT_NONE);
99     ASSERT_TRUE(setEffectStatus == Status::OK);
100     int32_t audioEffectMode;
101     auto getEffectStatus =  audioSink->GetAudioEffectMode(audioEffectMode);
102     ASSERT_TRUE(getEffectStatus == Status::OK);
103 }
104 
105 } // namespace Test
106 } // namespace Media
107 } // namespace OHOS