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