1 /*
2  * Copyright (c) 2021-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 "gtest/gtest.h"
17 #include "plugin/plugins/ffmpeg_adapter/audio_decoder/audio_ffmpeg_decoder_plugin.h"
18 #include "plugin/common/plugin_caps_builder.h"
19 
20 namespace OHOS {
21 namespace Media {
22 namespace Test {
23 using namespace Plugin;
24 using namespace Ffmpeg;
25 using namespace testing::ext;
AuFfmpegDecoderCreator(const std::string & name)26 std::shared_ptr<CodecPlugin> AuFfmpegDecoderCreator(const std::string& name)
27 {
28     return std::make_shared<AudioFfmpegDecoderPlugin>(name);
29 }
30 
31 HWTEST(AudioFfmpegDecoderPluginTest, test_Init, TestSize.Level1)
32 {
33     std::shared_ptr<CodecPlugin> aDecoderPlugin = AuFfmpegDecoderCreator("AudioFfmpegDecoderPluginTest");
34     ASSERT_EQ(Status::ERROR_UNSUPPORTED_FORMAT, aDecoderPlugin->Init());
35 }
36 
37 HWTEST(AudioFfmpegDecoderPluginTest, test_Prepare, TestSize.Level1)
38 {
39     std::shared_ptr<CodecPlugin> aDecoderPlugin = AuFfmpegDecoderCreator("AudioFfmpegDecoderPluginTest");
40     ASSERT_EQ(Status::ERROR_WRONG_STATE, aDecoderPlugin->Prepare());
41 }
42 
43 HWTEST(AudioFfmpegDecoderPluginTest, test_Reset, TestSize.Level1)
44 {
45     std::shared_ptr<CodecPlugin> aEncoderPlugin = AuFfmpegDecoderCreator("AudioFfmpegDecoderPluginTest");
46     ASSERT_EQ(Status::OK, aEncoderPlugin->Reset());
47 }
48 
49 HWTEST(AudioFfmpegDecoderPluginTest, test_Start, TestSize.Level1)
50 {
51     std::shared_ptr<CodecPlugin> aDecoderPlugin = AuFfmpegDecoderCreator("AudioFfmpegDecoderPluginTest");
52     ASSERT_EQ(Status::ERROR_WRONG_STATE, aDecoderPlugin->Start());
53 }
54 
55 HWTEST(AudioFfmpegDecoderPluginTest, test_Stop, TestSize.Level1)
56 {
57     std::shared_ptr<CodecPlugin> aDecoderPlugin = AuFfmpegDecoderCreator("AudioFfmpegDecoderPluginTest");
58     ASSERT_EQ(Status::OK, aDecoderPlugin->Stop());
59 }
60 
61 HWTEST(AudioFfmpegDecoderPluginTest, test_SetParameter, TestSize.Level1)
62 {
63     std::shared_ptr<CodecPlugin> aDecoderPlugin = AuFfmpegDecoderCreator("AudioFfmpegDecoderPluginTest");
64     ValueType value = 128;
65     ASSERT_EQ(Status::OK, aDecoderPlugin->SetParameter(Tag::AUDIO_SAMPLE_PER_FRAME, &value));
66 }
67 
68 HWTEST(AudioFfmpegDecoderPluginTest, test_GetParameter, TestSize.Level1)
69 {
70     std::shared_ptr<CodecPlugin> aDecoderPlugin = AuFfmpegDecoderCreator("AudioFfmpegDecoderPluginTest");
71     ValueType value;
72     ASSERT_EQ(Status::ERROR_INVALID_PARAMETER, aDecoderPlugin->GetParameter(Tag::REQUIRED_OUT_BUFFER_CNT, value));
73 }
74 
75 HWTEST(AudioFfmpegDecoderPluginTest, test_Flush, TestSize.Level1)
76 {
77     std::shared_ptr<CodecPlugin> aDecoderPlugin = AuFfmpegDecoderCreator("AudioFfmpegDecoderPluginTest");
78     ASSERT_EQ(Status::OK, aDecoderPlugin->Flush());
79 }
80 
81 HWTEST(AudioFfmpegDecoderPluginTest, test_QueInputBuffer, TestSize.Level1)
82 {
83     std::shared_ptr<CodecPlugin> aDecoderPlugin = AuFfmpegDecoderCreator("AudioFfmpegDecoderPluginTest");
84     std::shared_ptr<Buffer> inputBuffer = std::make_shared<Buffer>(BufferMetaType::AUDIO);
85     int32_t timeoutMs = 100;
86     ASSERT_EQ(Status::ERROR_INVALID_DATA, aDecoderPlugin->QueueInputBuffer(inputBuffer, timeoutMs));
87     uint32_t size = 16;
88     inputBuffer->AllocMemory(nullptr, size);
89     ASSERT_EQ(Status::ERROR_WRONG_STATE, aDecoderPlugin->QueueInputBuffer(inputBuffer, timeoutMs));
90     inputBuffer->flag = 1;
91     ASSERT_EQ(Status::ERROR_WRONG_STATE, aDecoderPlugin->QueueInputBuffer(inputBuffer, timeoutMs));
92 }
93 
94 } //namespace Test
95 } //namespace Media
96 } //namespace OHOS