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 "plugin/plugins/demuxer/minimp4_demuxer/minimp4_demuxer_plugin.h"
18
19using namespace testing::ext;
20using namespace OHOS::Media::Plugin;
21using namespace OHOS::Media::Plugin::Minimp4;
22
23namespace OHOS {
24namespace Media {
25namespace Test {
26std::shared_ptr<MiniMP4DemuxerPlugin> MiniMP4DemuxerPluginCreate(const std::string& name)
27{
28    return std::make_shared<MiniMP4DemuxerPlugin>(name);
29}
30
31HWTEST(TestMiniMp4DemuxerPlugin, find_minimp4_demuxer_plugins_process, TestSize.Level1)
32{
33    std::shared_ptr<MiniMP4DemuxerPlugin> minimp4DemuxerPlugin = MiniMP4DemuxerPluginCreate("process");
34    ASSERT_TRUE(minimp4DemuxerPlugin != nullptr);
35    auto resetStatus = minimp4DemuxerPlugin->Reset();
36    ASSERT_TRUE(resetStatus == Status::OK);
37    auto initStatus = minimp4DemuxerPlugin->Init();
38    ASSERT_TRUE(initStatus == Status::OK);
39    auto prepareStatus = minimp4DemuxerPlugin->Prepare();
40    ASSERT_TRUE(prepareStatus == Status::OK);
41    auto startStatus = minimp4DemuxerPlugin->Start();
42    ASSERT_TRUE(startStatus == Status::OK);
43    auto stopStatus = minimp4DemuxerPlugin->Stop();
44    ASSERT_TRUE(stopStatus == Status::OK);
45    auto freeStatus = minimp4DemuxerPlugin->Deinit();
46    ASSERT_TRUE(freeStatus == Status::OK);
47}
48
49HWTEST(TestMiniMp4DemuxerPlugin, find_minimp4_demuxer_plugins_get_parameter, TestSize.Level1)
50{
51    std::shared_ptr<MiniMP4DemuxerPlugin> minimp4DemuxerPlugin = MiniMP4DemuxerPluginCreate("get parameter");
52    ASSERT_TRUE(minimp4DemuxerPlugin != nullptr);
53    ValueType para;
54    auto channelLayoutStatus =  minimp4DemuxerPlugin->GetParameter(Tag::AUDIO_CHANNEL_LAYOUT, para);
55    ASSERT_TRUE(channelLayoutStatus == Status::ERROR_UNIMPLEMENTED);
56    auto mediaTypeStatus =  minimp4DemuxerPlugin->GetParameter(Tag::MEDIA_TYPE, para);
57    ASSERT_TRUE(mediaTypeStatus == Status::ERROR_UNIMPLEMENTED);
58    auto sampleRateStatus =  minimp4DemuxerPlugin->GetParameter(Tag::AUDIO_SAMPLE_RATE, para);
59    ASSERT_TRUE(sampleRateStatus == Status::ERROR_UNIMPLEMENTED);
60    auto bitrateStatus =  minimp4DemuxerPlugin->GetParameter(Tag::MEDIA_BITRATE, para);
61    ASSERT_TRUE(bitrateStatus == Status::ERROR_UNIMPLEMENTED);
62    auto channelsStatus =  minimp4DemuxerPlugin->GetParameter(Tag::AUDIO_CHANNELS, para);
63    ASSERT_TRUE(channelsStatus == Status::ERROR_UNIMPLEMENTED);
64    auto trackIdStatus =  minimp4DemuxerPlugin->GetParameter(Tag::TRACK_ID, para);
65    ASSERT_TRUE(trackIdStatus == Status::ERROR_UNIMPLEMENTED);
66    auto mimeStatus =  minimp4DemuxerPlugin->GetParameter(Tag::MIME, para);
67    ASSERT_TRUE(mimeStatus == Status::ERROR_UNIMPLEMENTED);
68    auto mpegVersionStatus =  minimp4DemuxerPlugin->GetParameter(Tag::AUDIO_MPEG_VERSION, para);
69    ASSERT_TRUE(mpegVersionStatus == Status::ERROR_UNIMPLEMENTED);
70    auto sampleFormatStatus =  minimp4DemuxerPlugin->GetParameter(Tag::AUDIO_SAMPLE_FORMAT, para);
71    ASSERT_TRUE(sampleFormatStatus == Status::ERROR_UNIMPLEMENTED);
72    auto samplePerFrameStatus =  minimp4DemuxerPlugin->GetParameter(Tag::AUDIO_SAMPLE_PER_FRAME, para);
73    ASSERT_TRUE(samplePerFrameStatus == Status::ERROR_UNIMPLEMENTED);
74}
75
76HWTEST(TestMiniMp4DemuxerPlugin, find_minimp4_demuxer_plugins_set_parameter, TestSize.Level1)
77{
78    std::shared_ptr<MiniMP4DemuxerPlugin> minimp4DemuxerPlugin = MiniMP4DemuxerPluginCreate("get parameter");
79    ASSERT_TRUE(minimp4DemuxerPlugin != nullptr);
80    ASSERT_TRUE(minimp4DemuxerPlugin->SetParameter(Tag::AUDIO_CHANNEL_LAYOUT, AudioChannelLayout::STEREO)
81        == Status::ERROR_UNIMPLEMENTED);
82    ASSERT_TRUE(minimp4DemuxerPlugin->SetParameter(Tag::MEDIA_TYPE, MediaType::AUDIO) == Status::ERROR_UNIMPLEMENTED);
83    ASSERT_TRUE(minimp4DemuxerPlugin->SetParameter(Tag::TRACK_ID, 0) == Status::ERROR_UNIMPLEMENTED);
84    ASSERT_TRUE(minimp4DemuxerPlugin->SetParameter(Tag::MIME, MEDIA_MIME_AUDIO_RAW) == Status::ERROR_UNIMPLEMENTED);
85    ASSERT_TRUE(minimp4DemuxerPlugin->SetParameter(Tag::AUDIO_SAMPLE_FORMAT, AudioSampleFormat::WAVE_FORMAT_PCM)
86        == Status::ERROR_UNIMPLEMENTED);
87    ASSERT_TRUE(minimp4DemuxerPlugin->SetParameter(Tag::AUDIO_SAMPLE_PER_FRAME, 8192) // sample per frame: 8192
88        == Status::ERROR_UNIMPLEMENTED);
89}
90
91HWTEST(TestMiniMp4DemuxerPlugin, find_minimp4_demuxer_plugins_get_allocator, TestSize.Level1)
92{
93    std::shared_ptr<MiniMP4DemuxerPlugin> minimp4DemuxerPlugin = MiniMP4DemuxerPluginCreate("get allocator");
94    ASSERT_TRUE(minimp4DemuxerPlugin != nullptr);
95    auto allocator =  minimp4DemuxerPlugin->GetAllocator();
96    ASSERT_TRUE(allocator == nullptr);
97}
98
99HWTEST(TestMiniMp4DemuxerPlugin, find_minimp4_demuxer_plugins_set_callback, TestSize.Level1)
100{
101    std::shared_ptr<MiniMP4DemuxerPlugin> minimp4DemuxerPlugin = MiniMP4DemuxerPluginCreate("set callback");
102    ASSERT_TRUE(minimp4DemuxerPlugin != nullptr);
103    Callback* cb = new Callback();
104    auto status = minimp4DemuxerPlugin->SetCallback(cb);
105    ASSERT_TRUE(status == Status::OK);
106}
107
108HWTEST(TestMiniMp4DemuxerPlugin, find_minimp4_demuxer_plugins_get_track_count, TestSize.Level1)
109{
110    std::shared_ptr<MiniMP4DemuxerPlugin> minimp4DemuxerPlugin = MiniMP4DemuxerPluginCreate("get track count");
111    ASSERT_TRUE(minimp4DemuxerPlugin != nullptr);
112    ASSERT_TRUE(minimp4DemuxerPlugin->GetTrackCount() == 0);
113}
114
115HWTEST(TestMiniMp4DemuxerPlugin, find_minimp4_demuxer_plugins_select_track, TestSize.Level1)
116{
117    std::shared_ptr<MiniMP4DemuxerPlugin> minimp4DemuxerPlugin = MiniMP4DemuxerPluginCreate("select track");
118    ASSERT_TRUE(minimp4DemuxerPlugin != nullptr);
119    auto selectStatus = minimp4DemuxerPlugin->SelectTrack(0);
120    ASSERT_TRUE(selectStatus == Status::OK);
121}
122
123HWTEST(TestMiniMp4DemuxerPlugin, find_minimp4_demuxer_plugins_unselect_track, TestSize.Level1)
124{
125    std::shared_ptr<MiniMP4DemuxerPlugin> minimp4DemuxerPlugin = MiniMP4DemuxerPluginCreate("unselect track");
126    ASSERT_TRUE(minimp4DemuxerPlugin != nullptr);
127    auto unselectStatus = minimp4DemuxerPlugin->UnselectTrack(0);
128    ASSERT_TRUE(unselectStatus == Status::OK);
129}
130
131HWTEST(TestMiniMp4DemuxerPlugin, find_minimp4_demuxer_plugins_get_select_track, TestSize.Level1)
132{
133    std::shared_ptr<MiniMP4DemuxerPlugin> minimp4DemuxerPlugin = MiniMP4DemuxerPluginCreate("get select track");
134    ASSERT_TRUE(minimp4DemuxerPlugin != nullptr);
135    std::vector<int32_t> trackIds = new std::vector<int32_t>[1];
136    auto selectStatus = minimp4DemuxerPlugin->GetSelectedTracks(trackIds);
137    ASSERT_TRUE(selectStatus == Status::OK);
138}
139
140} // namespace Test
141} // namespace Media
142} // namespace OHOS