1fa7767c5Sopenharmony_ci/* 2fa7767c5Sopenharmony_ci * Copyright (c) 2023-2023 Huawei Device Co., Ltd. 3fa7767c5Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4fa7767c5Sopenharmony_ci * you may not use this file except in compliance with the License. 5fa7767c5Sopenharmony_ci * You may obtain a copy of the License at 6fa7767c5Sopenharmony_ci * 7fa7767c5Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8fa7767c5Sopenharmony_ci * 9fa7767c5Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10fa7767c5Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11fa7767c5Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12fa7767c5Sopenharmony_ci * See the License for the specific language governing permissions and 13fa7767c5Sopenharmony_ci * limitations under the License. 14fa7767c5Sopenharmony_ci */ 15fa7767c5Sopenharmony_ci 16fa7767c5Sopenharmony_ci#include "gtest/gtest.h" 17fa7767c5Sopenharmony_ci#include "plugin/plugins/demuxer/wav_demuxer/wav_demuxer_plugin.h" 18fa7767c5Sopenharmony_ci 19fa7767c5Sopenharmony_ciusing namespace testing::ext; 20fa7767c5Sopenharmony_ciusing namespace OHOS::Media::Plugin; 21fa7767c5Sopenharmony_ciusing namespace OHOS::Media::Plugin::WavPlugin; 22fa7767c5Sopenharmony_ci 23fa7767c5Sopenharmony_cinamespace OHOS { 24fa7767c5Sopenharmony_cinamespace Media { 25fa7767c5Sopenharmony_cinamespace Test { 26fa7767c5Sopenharmony_cistd::shared_ptr<WavDemuxerPlugin> WavDemuxerPluginCreate(const std::string& name) 27fa7767c5Sopenharmony_ci{ 28fa7767c5Sopenharmony_ci return std::make_shared<WavDemuxerPlugin>(name); 29fa7767c5Sopenharmony_ci} 30fa7767c5Sopenharmony_ci 31fa7767c5Sopenharmony_ciHWTEST(TestWavDemuxerPlugin, find_wav_demuxer_plugins_process, TestSize.Level1) 32fa7767c5Sopenharmony_ci{ 33fa7767c5Sopenharmony_ci std::shared_ptr<WavDemuxerPlugin> wavDemuxerPlugin = WavDemuxerPluginCreate("process"); 34fa7767c5Sopenharmony_ci ASSERT_TRUE(WavDemuxerPlugin != nullptr); 35fa7767c5Sopenharmony_ci auto resetStatus = wavDemuxerPlugin->Reset(); 36fa7767c5Sopenharmony_ci ASSERT_TRUE(resetStatus == Status::OK); 37fa7767c5Sopenharmony_ci auto initStatus = wavDemuxerPlugin->Init(); 38fa7767c5Sopenharmony_ci ASSERT_TRUE(initStatus == Status::OK); 39fa7767c5Sopenharmony_ci auto prepareStatus = wavDemuxerPlugin->Prepare(); 40fa7767c5Sopenharmony_ci ASSERT_TRUE(prepareStatus == Status::OK); 41fa7767c5Sopenharmony_ci auto startStatus = wavDemuxerPlugin->Start(); 42fa7767c5Sopenharmony_ci ASSERT_TRUE(startStatus == Status::OK); 43fa7767c5Sopenharmony_ci auto stopStatus = wavDemuxerPlugin->Stop(); 44fa7767c5Sopenharmony_ci ASSERT_TRUE(stopStatus == Status::OK); 45fa7767c5Sopenharmony_ci auto freeStatus = wavDemuxerPlugin->Deinit(); 46fa7767c5Sopenharmony_ci ASSERT_TRUE(freeStatus == Status::OK); 47fa7767c5Sopenharmony_ci} 48fa7767c5Sopenharmony_ci 49fa7767c5Sopenharmony_ciHWTEST(TestWavDemuxerPlugin, find_wav_demuxer_plugins_get_parameter, TestSize.Level1) 50fa7767c5Sopenharmony_ci{ 51fa7767c5Sopenharmony_ci std::shared_ptr<WavDemuxerPlugin> wavDemuxerPlugin = WavDemuxerPluginCreate("get parameter"); 52fa7767c5Sopenharmony_ci ASSERT_TRUE(wavDemuxerPlugin != nullptr); 53fa7767c5Sopenharmony_ci ValueType para; 54fa7767c5Sopenharmony_ci auto channelLayoutStatus = wavDemuxerPlugin->GetParameter(Tag::AUDIO_CHANNEL_LAYOUT, para); 55fa7767c5Sopenharmony_ci ASSERT_TRUE(channelLayoutStatus == Status::ERROR_UNIMPLEMENTED); 56fa7767c5Sopenharmony_ci auto mediaTypeStatus = wavDemuxerPlugin->GetParameter(Tag::MEDIA_TYPE, para); 57fa7767c5Sopenharmony_ci ASSERT_TRUE(mediaTypeStatus == Status::ERROR_UNIMPLEMENTED); 58fa7767c5Sopenharmony_ci auto sampleRateStatus = wavDemuxerPlugin->GetParameter(Tag::AUDIO_SAMPLE_RATE, para); 59fa7767c5Sopenharmony_ci ASSERT_TRUE(sampleRateStatus == Status::ERROR_UNIMPLEMENTED); 60fa7767c5Sopenharmony_ci auto bitrateStatus = wavDemuxerPlugin->GetParameter(Tag::MEDIA_BITRATE, para); 61fa7767c5Sopenharmony_ci ASSERT_TRUE(bitrateStatus == Status::ERROR_UNIMPLEMENTED); 62fa7767c5Sopenharmony_ci auto channelsStatus = wavDemuxerPlugin->GetParameter(Tag::AUDIO_CHANNELS, para); 63fa7767c5Sopenharmony_ci ASSERT_TRUE(channelsStatus == Status::ERROR_UNIMPLEMENTED); 64fa7767c5Sopenharmony_ci auto trackIdStatus = wavDemuxerPlugin->GetParameter(Tag::TRACK_ID, para); 65fa7767c5Sopenharmony_ci ASSERT_TRUE(trackIdStatus == Status::ERROR_UNIMPLEMENTED); 66fa7767c5Sopenharmony_ci auto mimeStatus = wavDemuxerPlugin->GetParameter(Tag::MIME, para); 67fa7767c5Sopenharmony_ci ASSERT_TRUE(mimeStatus == Status::ERROR_UNIMPLEMENTED); 68fa7767c5Sopenharmony_ci auto mpegVersionStatus = wavDemuxerPlugin->GetParameter(Tag::AUDIO_MPEG_VERSION, para); 69fa7767c5Sopenharmony_ci ASSERT_TRUE(mpegVersionStatus == Status::ERROR_UNIMPLEMENTED); 70fa7767c5Sopenharmony_ci auto sampleFormatStatus = wavDemuxerPlugin->GetParameter(Tag::AUDIO_SAMPLE_FORMAT, para); 71fa7767c5Sopenharmony_ci ASSERT_TRUE(sampleFormatStatus == Status::ERROR_UNIMPLEMENTED); 72fa7767c5Sopenharmony_ci auto samplePerFrameStatus = wavDemuxerPlugin->GetParameter(Tag::AUDIO_SAMPLE_PER_FRAME, para); 73fa7767c5Sopenharmony_ci ASSERT_TRUE(samplePerFrameStatus == Status::ERROR_UNIMPLEMENTED); 74fa7767c5Sopenharmony_ci} 75fa7767c5Sopenharmony_ci 76fa7767c5Sopenharmony_ciHWTEST(TestWavDemuxerPlugin, find_wav_demuxer_plugins_set_parameter, TestSize.Level1) 77fa7767c5Sopenharmony_ci{ 78fa7767c5Sopenharmony_ci std::shared_ptr<WavDemuxerPlugin> wavDemuxerPlugin = WavDemuxerPluginCreate("get parameter"); 79fa7767c5Sopenharmony_ci ASSERT_TRUE(wavDemuxerPlugin != nullptr); 80fa7767c5Sopenharmony_ci ASSERT_TRUE(wavDemuxerPlugin->SetParameter(Tag::AUDIO_CHANNEL_LAYOUT, AudioChannelLayout::STEREO) 81fa7767c5Sopenharmony_ci == Status::ERROR_UNIMPLEMENTED); 82fa7767c5Sopenharmony_ci ASSERT_TRUE(wavDemuxerPlugin->SetParameter(Tag::MEDIA_TYPE, MediaType::AUDIO) == Status::ERROR_UNIMPLEMENTED); 83fa7767c5Sopenharmony_ci ASSERT_TRUE(wavDemuxerPlugin->SetParameter(Tag::TRACK_ID, 0) == Status::ERROR_UNIMPLEMENTED); 84fa7767c5Sopenharmony_ci ASSERT_TRUE(wavDemuxerPlugin->SetParameter(Tag::MIME, MEDIA_MIME_AUDIO_RAW) == Status::ERROR_UNIMPLEMENTED); 85fa7767c5Sopenharmony_ci ASSERT_TRUE(wavDemuxerPlugin->SetParameter(Tag::AUDIO_SAMPLE_FORMAT, AudioSampleFormat::WAVE_FORMAT_PCM) 86fa7767c5Sopenharmony_ci == Status::ERROR_UNIMPLEMENTED); 87fa7767c5Sopenharmony_ci ASSERT_TRUE(wavDemuxerPlugin->SetParameter(Tag::AUDIO_SAMPLE_PER_FRAME, 8192) // sample per frame: 8192 88fa7767c5Sopenharmony_ci == Status::ERROR_UNIMPLEMENTED); 89fa7767c5Sopenharmony_ci} 90fa7767c5Sopenharmony_ci 91fa7767c5Sopenharmony_ciHWTEST(TestWavDemuxerPlugin, find_wav_demuxer_plugins_get_allocator, TestSize.Level1) 92fa7767c5Sopenharmony_ci{ 93fa7767c5Sopenharmony_ci std::shared_ptr<WavDemuxerPlugin> wavDemuxerPlugin = WavDemuxerPluginCreate("get allocator"); 94fa7767c5Sopenharmony_ci ASSERT_TRUE(wavDemuxerPlugin != nullptr); 95fa7767c5Sopenharmony_ci auto allocator = wavDemuxerPlugin->GetAllocator(); 96fa7767c5Sopenharmony_ci ASSERT_TRUE(allocator == nullptr); 97fa7767c5Sopenharmony_ci} 98fa7767c5Sopenharmony_ci 99fa7767c5Sopenharmony_ciHWTEST(TestWavDemuxerPlugin, find_wav_demuxer_plugins_set_callback, TestSize.Level1) 100fa7767c5Sopenharmony_ci{ 101fa7767c5Sopenharmony_ci std::shared_ptr<WavDemuxerPlugin> wavDemuxerPlugin = WavDemuxerPluginCreate("set callback"); 102fa7767c5Sopenharmony_ci ASSERT_TRUE(wavDemuxerPlugin != nullptr); 103fa7767c5Sopenharmony_ci Callback* cb = new Callback(); 104fa7767c5Sopenharmony_ci auto status = wavDemuxerPlugin->SetCallback(cb); 105fa7767c5Sopenharmony_ci ASSERT_TRUE(status == Status::OK); 106fa7767c5Sopenharmony_ci} 107fa7767c5Sopenharmony_ci 108fa7767c5Sopenharmony_ciHWTEST(TestWavDemuxerPlugin, find_wav_demuxer_plugins_get_track_count, TestSize.Level1) 109fa7767c5Sopenharmony_ci{ 110fa7767c5Sopenharmony_ci std::shared_ptr<WavDemuxerPlugin> wavDemuxerPlugin = WavDemuxerPluginCreate("get track count"); 111fa7767c5Sopenharmony_ci ASSERT_TRUE(wavDemuxerPlugin != nullptr); 112fa7767c5Sopenharmony_ci ASSERT_TRUE(wavDemuxerPlugin->GetTrackCount() == 0); 113fa7767c5Sopenharmony_ci} 114fa7767c5Sopenharmony_ci 115fa7767c5Sopenharmony_ciHWTEST(TestWavDemuxerPlugin, find_wav_demuxer_plugins_select_track, TestSize.Level1) 116fa7767c5Sopenharmony_ci{ 117fa7767c5Sopenharmony_ci std::shared_ptr<WavDemuxerPlugin> wavDemuxerPlugin = WavDemuxerPluginCreate("select track"); 118fa7767c5Sopenharmony_ci ASSERT_TRUE(wavDemuxerPlugin != nullptr); 119fa7767c5Sopenharmony_ci auto selectStatus = wavDemuxerPlugin->SelectTrack(0); 120fa7767c5Sopenharmony_ci ASSERT_TRUE(selectStatus == Status::OK); 121fa7767c5Sopenharmony_ci} 122fa7767c5Sopenharmony_ci 123fa7767c5Sopenharmony_ciHWTEST(TestWavDemuxerPlugin, find_wav_demuxer_plugins_unselect_track, TestSize.Level1) 124fa7767c5Sopenharmony_ci{ 125fa7767c5Sopenharmony_ci std::shared_ptr<WavDemuxerPlugin> wavDemuxerPlugin = WavDemuxerPluginCreate("unselect track"); 126fa7767c5Sopenharmony_ci ASSERT_TRUE(wavDemuxerPlugin != nullptr); 127fa7767c5Sopenharmony_ci auto unselectStatus = wavDemuxerPlugin->UnselectTrack(0); 128fa7767c5Sopenharmony_ci ASSERT_TRUE(unselectStatus == Status::OK); 129fa7767c5Sopenharmony_ci} 130fa7767c5Sopenharmony_ci 131fa7767c5Sopenharmony_ciHWTEST(TestWavDemuxerPlugin, find_wav_demuxer_plugins_get_select_track, TestSize.Level1) 132fa7767c5Sopenharmony_ci{ 133fa7767c5Sopenharmony_ci std::shared_ptr<WavDemuxerPlugin> wavDemuxerPlugin = WavDemuxerPluginCreate("get select track"); 134fa7767c5Sopenharmony_ci ASSERT_TRUE(wavDemuxerPlugin != nullptr); 135fa7767c5Sopenharmony_ci std::vector<int32_t> trackIds = new std::vector<int32_t>[1]; 136fa7767c5Sopenharmony_ci auto selectStatus = wavDemuxerPlugin->GetSelectedTracks(trackIds); 137fa7767c5Sopenharmony_ci ASSERT_TRUE(selectStatus == Status::OK); 138fa7767c5Sopenharmony_ci} 139fa7767c5Sopenharmony_ci 140fa7767c5Sopenharmony_ci} // namespace Test 141fa7767c5Sopenharmony_ci} // namespace Media 142fa7767c5Sopenharmony_ci} // namespace OHOS