From 0247005c07d4f8914f8761a8cd2c03df8d9be0fd Mon Sep 17 00:00:00 2001 From: zhuzhihui7 Date: Thu, 20 Mar 2025 11:21:09 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9Eframework/filter=E6=96=87?= =?UTF-8?q?=E4=BB=B6UT?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhuzhihui7 --- av_transport/distributed_av_transport.gni | 2 + av_transport/framework/filter/test/BUILD.gn | 18 + .../framework/filter/test/unittest/BUILD.gn | 71 ++++ .../test/unittest/filter_factory_test.cpp | 52 +++ .../test/unittest/filter_factory_test.h | 38 ++ .../filter/test/unittest/filter_test.cpp | 353 ++++++++++++++++++ .../filter/test/unittest/filter_test.h | 46 +++ bundle.json | 1 + 8 files changed, 581 insertions(+) create mode 100644 av_transport/framework/filter/test/BUILD.gn create mode 100644 av_transport/framework/filter/test/unittest/BUILD.gn create mode 100644 av_transport/framework/filter/test/unittest/filter_factory_test.cpp create mode 100644 av_transport/framework/filter/test/unittest/filter_factory_test.h create mode 100644 av_transport/framework/filter/test/unittest/filter_test.cpp create mode 100644 av_transport/framework/filter/test/unittest/filter_test.h diff --git a/av_transport/distributed_av_transport.gni b/av_transport/distributed_av_transport.gni index 87d344ae..b750f074 100644 --- a/av_transport/distributed_av_transport.gni +++ b/av_transport/distributed_av_transport.gni @@ -34,6 +34,8 @@ control_center_path = "${distributed_av_transport_path}/av_trans_control_center" filters_path = "${distributed_av_transport_path}/av_trans_engine/filters" +filter_path = "${distributed_av_transport_path}/framework/filter" + dh_fwk_utils_path = "${distributedhardwarefwk_path}/common/utils" dh_fwk_services_path = "${distributedhardwarefwk_path}/services" diff --git a/av_transport/framework/filter/test/BUILD.gn b/av_transport/framework/filter/test/BUILD.gn new file mode 100644 index 00000000..478d68bb --- /dev/null +++ b/av_transport/framework/filter/test/BUILD.gn @@ -0,0 +1,18 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +group("framework_filter_test") { + testonly = true + + deps = [ "unittest:framework_filter_unittest" ] +} diff --git a/av_transport/framework/filter/test/unittest/BUILD.gn b/av_transport/framework/filter/test/unittest/BUILD.gn new file mode 100644 index 00000000..a0da5a41 --- /dev/null +++ b/av_transport/framework/filter/test/unittest/BUILD.gn @@ -0,0 +1,71 @@ +# Copyright (c) 2023-2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/test.gni") +import("../../../../distributed_av_transport.gni") + +module_out_path = "distributed_hardware_fwk/av_transport/filter" + +ohos_unittest("AvTransportFilterTest") { + module_out_path = module_out_path + + include_dirs = [ + "${common_path}/include", + "${filter_path}/include", + "${filter_path}/test/unittest", + ] + + sources = [ + "${filter_path}/src/filter.cpp", + "${filter_path}/src/filter_factory.cpp", + "filter_factory_test.cpp", + "filter_test.cpp", + ] + + cflags = [ + "-O2", + "-fPIC", + "-Wall", + "-fexceptions", + "-Dprivate = public", + "-Dprotected = public", + ] + cflags_cc = cflags + + deps = [] + + if (histreamer_compile_part) { + external_deps = [ + "media_foundation:histreamer_base", + "media_foundation:histreamer_codec_filters", + "media_foundation:histreamer_ffmpeg_convert", + "media_foundation:histreamer_plugin_base", + ] + } + + external_deps += [ + "bounds_checking_function:libsec_shared", + "cJSON:cjson", + "c_utils:utils", + "dsoftbus:softbus_client", + "googletest:gtest", + "hilog:libhilog", + "libevdev:libevdev", + ] +} + +group("framework_filter_unittest") { + testonly = true + + deps = [ ":AvTransportFilterTest" ] +} diff --git a/av_transport/framework/filter/test/unittest/filter_factory_test.cpp b/av_transport/framework/filter/test/unittest/filter_factory_test.cpp new file mode 100644 index 00000000..c6b0ef13 --- /dev/null +++ b/av_transport/framework/filter/test/unittest/filter_factory_test.cpp @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "filter.h" +#include "filter_factory_test.h" +#include "cpp_ext/type_cast_ext.h" + +using namespace testing::ext; +using namespace OHOS::DistributedHardware; +using namespace std; + +namespace OHOS { +namespace DistributedHardware { + +void FilterFactoryTest::SetUp() +{ +} + +void FilterFactoryTest::TearDown() +{ +} + +void FilterFactoryTest::SetUpTestCase() +{ +} + +void FilterFactoryTest::TearDownTestCase() +{ +} +HWTEST_F(FilterFactoryTest, CreateFilterPriv_001, testing::ext::TestSize.Level1) +{ + auto& filterFactory = Pipeline::FilterFactory::Instance(); + std::string registeredFilterName = "registeredFilterOut"; + Pipeline::FilterType registeredType = Pipeline::FilterType::FILTERTYPE_SOURCE; + std::shared_ptr registeredFilter = + filterFactory.CreateFilterPriv(registeredFilterName, registeredType); + EXPECT_EQ(registeredFilter, nullptr); +} +} // namespace DistributedHardware +} // namespace OHOS \ No newline at end of file diff --git a/av_transport/framework/filter/test/unittest/filter_factory_test.h b/av_transport/framework/filter/test/unittest/filter_factory_test.h new file mode 100644 index 00000000..97588983 --- /dev/null +++ b/av_transport/framework/filter/test/unittest/filter_factory_test.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FILTER_FACTORT_TEST_H +#define FILTER_FACTORT_TEST_H + +#include +#include "filter.h" +#include "filter_factory.h" + +namespace OHOS { +namespace DistributedHardware { + +using namespace Pipeline; + +class FilterFactoryTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp() override; + void TearDown() override; +}; +} // namespace DistributedHardware +} // namespace OHOS + +#endif // FILTER_FACTORT_TEST_H \ No newline at end of file diff --git a/av_transport/framework/filter/test/unittest/filter_test.cpp b/av_transport/framework/filter/test/unittest/filter_test.cpp new file mode 100644 index 00000000..b128d806 --- /dev/null +++ b/av_transport/framework/filter/test/unittest/filter_test.cpp @@ -0,0 +1,353 @@ +/* + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "filter_test.h" + +#include +#include "osal/utils/util.h" +#include "av_trans_log.h" + +using namespace testing::ext; +using namespace OHOS::DistributedHardware; +using namespace std; + +namespace OHOS { +namespace DistributedHardware { + +void FilterTest::SetUp() +{ +} + +void FilterTest::TearDown() +{ +} + +void FilterTest::SetUpTestCase() +{ +} + +void FilterTest::TearDownTestCase() +{ +} + +HWTEST_F(FilterTest, LinkPipeLine_001, testing::ext::TestSize.Level1) +{ + Filter filterAsync("testFilterAsync", FilterType::FILTERTYPE_VENC, true); + std::string groupId = "testGroup"; + filterAsync.LinkPipeLine(groupId); + EXPECT_EQ(filterAsync.GetFilterType(), FilterType::FILTERTYPE_VENC); + Filter filterSync("testFilterSync", FilterType::FILTERTYPE_ASINK, false); + filterSync.LinkPipeLine(groupId); + EXPECT_TRUE(!filterSync.isAsyncMode_); +} + +HWTEST_F(FilterTest, Prepare_001, testing::ext::TestSize.Level1) +{ + Filter filterAsync("testFilterAsync", FilterType::FILTERTYPE_VENC, true); + std::unique_ptr mockTask = std::make_unique( + "mockTask", "groupId", Media::TaskType::SINGLETON, Media::TaskPriority::HIGH, false); + filterAsync.filterTask_ = std::move(mockTask); + Status result = filterAsync.Prepare(); + EXPECT_EQ(result, Status::OK); + + Filter filterSync("testFilterSync", FilterType::FILTERTYPE_VENC, false); + filterSync.filterTask_ = nullptr; + Status result_two = filterSync.Prepare(); + EXPECT_EQ(result_two, Status::OK); +} + +HWTEST_F(FilterTest, PrepareDone_001, testing::ext::TestSize.Level1) +{ + Filter filter("testFilter", FilterType::FILTERTYPE_VENC, true); + Status result1 = filter.PrepareDone(); + EXPECT_EQ(result1, Status::OK); + + Filter filterYnc("testFilterAsync", FilterType::FILTERTYPE_VENC, true); + filterYnc.nextFiltersMap_[StreamType::STREAMTYPE_ENCODED_AUDIO].push_back(nullptr); + Status result2 = filterYnc.PrepareDone(); + EXPECT_EQ(result2, Status::OK); +} + +HWTEST_F(FilterTest, Pause_001, testing::ext::TestSize.Level1) +{ + Filter filterAsync("testFilterAsync", FilterType::FILTERTYPE_VENC, true); + filterAsync.filterTask_ = std::make_unique( + "mockTask", "groupId", Media::TaskType::SINGLETON, Media::TaskPriority::HIGH, false); + auto mockNextFilter = std::make_shared("mockNextFilter", FilterType::FILTERTYPE_ASINK, false); + filterAsync.nextFiltersMap_[StreamType::STREAMTYPE_ENCODED_AUDIO].push_back(mockNextFilter); + Status result1 = filterAsync.Pause(); + EXPECT_EQ(result1, Status::OK); + + Filter filterYnc("testFilterAsync", FilterType::FILTERTYPE_VENC, true); + filterYnc.nextFiltersMap_[StreamType::STREAMTYPE_ENCODED_AUDIO].push_back(nullptr); + Status result2 = filterYnc.Pause(); + EXPECT_EQ(result2, Status::OK); +} + +HWTEST_F(FilterTest, PauseDragging_001, testing::ext::TestSize.Level1) +{ + Filter filterAsync("testFilterAsync", FilterType::FILTERTYPE_VENC, true); + filterAsync.filterTask_ = std::make_unique( + "mockTask", "groupId", Media::TaskType::SINGLETON, Media::TaskPriority::HIGH, false); + auto mockNextFilter = std::make_shared("mockNextFilter", FilterType::FILTERTYPE_ASINK, false); + filterAsync.nextFiltersMap_[StreamType::STREAMTYPE_ENCODED_AUDIO].push_back(mockNextFilter); + Status result = filterAsync.PauseDragging(); + EXPECT_EQ(result, Status::OK); + + Filter filterSync("testFilterSync", FilterType::FILTERTYPE_VENC, false); + filterSync.filterTask_ = nullptr; + auto mockNextFilter2 = std::make_shared("mockNextFilter", FilterType::FILTERTYPE_ASINK, false); + filterSync.nextFiltersMap_[StreamType::STREAMTYPE_ENCODED_AUDIO].push_back(mockNextFilter2); + Status result2 = filterSync.PauseDragging(); + EXPECT_EQ(result2, Status::OK); + + Filter filterYnc("testFilterAsync", FilterType::FILTERTYPE_VENC, true); + filterYnc.nextFiltersMap_[StreamType::STREAMTYPE_ENCODED_AUDIO].push_back(nullptr); + Status result3 = filterYnc.PauseDragging(); + EXPECT_EQ(result3, Status::OK); +} + +HWTEST_F(FilterTest, Resume_001, testing::ext::TestSize.Level1) +{ + Filter filterAsync("testFilterAsync", FilterType::FILTERTYPE_VENC, true); + filterAsync.filterTask_ = std::make_unique( + "mockTask", "groupId", Media::TaskType::SINGLETON, Media::TaskPriority::HIGH, false); + Status result_async = filterAsync.Resume(); + EXPECT_EQ(result_async, Status::OK); + + Filter filterSync("testFilterSync", FilterType::FILTERTYPE_ASINK, false); + filterSync.filterTask_ = nullptr; + auto mockNextFilter = std::make_shared("mockNextFilter", FilterType::FILTERTYPE_ASINK, false); + filterSync.nextFiltersMap_[StreamType::STREAMTYPE_ENCODED_AUDIO].push_back(mockNextFilter); + Status result_sync = filterSync.Resume(); + EXPECT_EQ(result_sync, Status::OK); + + Filter filterYnc("testFilterYnc", FilterType::FILTERTYPE_ASINK, false); + filterYnc.filterTask_ = nullptr; + filterYnc.nextFiltersMap_[StreamType::STREAMTYPE_ENCODED_AUDIO].push_back(nullptr); + Status result = filterYnc.Resume(); + EXPECT_EQ(result, Status::OK); +} + +HWTEST_F(FilterTest, ResumeDragging_001, testing::ext::TestSize.Level1) +{ + Filter filterAsync("testFilterAsync", FilterType::FILTERTYPE_VENC, true); + filterAsync.filterTask_ = std::make_unique( + "mockTask", "groupId", Media::TaskType::SINGLETON, Media::TaskPriority::HIGH, false); + Status result_async = filterAsync.ResumeDragging(); + EXPECT_EQ(result_async, Status::OK); + + Filter filterSync("testFilterSync", FilterType::FILTERTYPE_ASINK, false); + filterSync.filterTask_ = nullptr; + auto mockNextFilter = std::make_shared("mockNextFilter", FilterType::FILTERTYPE_ASINK, false); + filterSync.nextFiltersMap_[StreamType::STREAMTYPE_ENCODED_AUDIO].push_back(mockNextFilter); + Status result_sync = filterSync.ResumeDragging(); + EXPECT_EQ(result_sync, Status::OK); + + Filter filterYnc("testFilterAsync", FilterType::FILTERTYPE_VENC, true); + filterYnc.nextFiltersMap_[StreamType::STREAMTYPE_ENCODED_AUDIO].push_back(nullptr); + Status result_ync = filterYnc.ResumeDragging(); + EXPECT_EQ(result_ync, Status::OK); +} + +HWTEST_F(FilterTest, Stop_001, testing::ext::TestSize.Level1) +{ + Filter filterAsync("testFilterAsync", FilterType::FILTERTYPE_VENC, true); + filterAsync.filterTask_ = std::make_unique( + "mockTask", "groupId", Media::TaskType::SINGLETON, Media::TaskPriority::HIGH, false); + Status result_async = filterAsync.Stop(); + EXPECT_EQ(result_async, Status::OK); + + Filter filterSync("testFilterSync", FilterType::FILTERTYPE_ASINK, false); + filterSync.filterTask_ = nullptr; + auto mockNextFilter = std::make_shared("mockNextFilter", FilterType::FILTERTYPE_ASINK, false); + filterSync.nextFiltersMap_[StreamType::STREAMTYPE_ENCODED_AUDIO].push_back(mockNextFilter); + Status result_sync = filterSync.Stop(); + EXPECT_EQ(result_sync, Status::OK); + + Filter filterYnc("testFilterAsync", FilterType::FILTERTYPE_VENC, true); + filterYnc.nextFiltersMap_[StreamType::STREAMTYPE_ENCODED_AUDIO].push_back(nullptr); + Status result_ync = filterYnc.Stop(); + EXPECT_EQ(result_ync, Status::OK); +} + +HWTEST_F(FilterTest, Flush_001, testing::ext::TestSize.Level1) +{ + Filter filterAsync("testFilterAsync", FilterType::FILTERTYPE_VENC, true); + filterAsync.nextFiltersMap_[StreamType::STREAMTYPE_ENCODED_AUDIO].push_back(nullptr); + Status result1 = filterAsync.Flush(); + EXPECT_EQ(result1, Status::OK); + + Filter filterSync("testFilterAsync", FilterType::FILTERTYPE_VENC, true); + auto mockNextFilter = std::make_shared("mockNextFilter", FilterType::FILTERTYPE_ASINK, false); + filterSync.nextFiltersMap_[StreamType::STREAMTYPE_ENCODED_AUDIO].push_back(mockNextFilter); + Status result2 = filterSync.Flush(); + EXPECT_EQ(result2, Status::OK); +} + +HWTEST_F(FilterTest, Release_001, testing::ext::TestSize.Level1) +{ + Filter filterAsync("testFilterAsync", FilterType::FILTERTYPE_VENC, true); + filterAsync.filterTask_ = std::make_unique( + "mockTask", "groupId", Media::TaskType::SINGLETON, Media::TaskPriority::HIGH, false); + Status result_async = filterAsync.Release(); + EXPECT_EQ(result_async, Status::OK); + + Filter filterSync("testFilterAsync", FilterType::FILTERTYPE_VENC, true); + filterSync.nextFiltersMap_[StreamType::STREAMTYPE_ENCODED_AUDIO].push_back(nullptr); + Status result_sync = filterSync.Release(); + EXPECT_EQ(result_sync, Status::OK); + + Filter filterYnc("testFilterSync", FilterType::FILTERTYPE_ASINK, false); + filterSync.filterTask_ = nullptr; + auto mockNextFilter = std::make_shared("mockNextFilter", FilterType::FILTERTYPE_ASINK, false); + filterYnc.nextFiltersMap_[StreamType::STREAMTYPE_ENCODED_AUDIO].push_back(mockNextFilter); + Status result_ync = filterYnc.Release(); + EXPECT_EQ(result_ync, Status::OK); +} + +HWTEST_F(FilterTest, SetPlayRange_001, testing::ext::TestSize.Level1) +{ + Filter filterAsync("testFilterAsync", FilterType::FILTERTYPE_VENC, true); + auto mockNextFilter = std::make_shared("mockNextFilter", FilterType::FILTERTYPE_ASINK, false); + filterAsync.nextFiltersMap_[StreamType::STREAMTYPE_ENCODED_AUDIO].push_back(mockNextFilter); + Status result1 = filterAsync.SetPlayRange(10, 100); + + EXPECT_EQ(result1, Status::OK); + Filter filterSync("testFilterSync", FilterType::FILTERTYPE_VENC, false); + filterSync.nextFiltersMap_[StreamType::STREAMTYPE_ENCODED_AUDIO].push_back(nullptr); + Status result2 = filterSync.SetPlayRange(20, 200); + EXPECT_EQ(result2, Status::OK); +} + +HWTEST_F(FilterTest, Preroll_001, testing::ext::TestSize.Level1) +{ + Filter filterAsync1("testFilterAsync", FilterType::FILTERTYPE_VENC, true); + filterAsync1.nextFiltersMap_[StreamType::STREAMTYPE_ENCODED_AUDIO].push_back(nullptr); + Status result1 = filterAsync1.Preroll(); + EXPECT_EQ(result1, Status::OK); + + Filter filterAsync2("testFilterAsync", FilterType::FILTERTYPE_VENC, true); + auto mockNextFilter = std::make_shared("mockNextFilter", FilterType::FILTERTYPE_ASINK, false); + filterAsync2.nextFiltersMap_[StreamType::STREAMTYPE_ENCODED_AUDIO].push_back(mockNextFilter); + Status result2 = filterAsync2.Preroll(); + EXPECT_EQ(result2, Status::OK); + + Filter filterAsync3("testFilterAsync", FilterType::FILTERTYPE_VENC, true); + auto mockNextFilterFail = std::make_shared("mockNextFilterFail", FilterType::FILTERTYPE_ASINK, false); + filterAsync3.nextFiltersMap_[StreamType::STREAMTYPE_ENCODED_AUDIO].push_back(mockNextFilterFail); + Status result3 = filterAsync3.Preroll(); + EXPECT_EQ(result3, Status::OK); +} + +HWTEST_F(FilterTest, WaitPrerollDone_001, testing::ext::TestSize.Level1) +{ + Filter filterAsync1("testFilterAsync", FilterType::FILTERTYPE_VENC, true); + filterAsync1.nextFiltersMap_[StreamType::STREAMTYPE_ENCODED_AUDIO].push_back(nullptr); + Status result1 = filterAsync1.WaitPrerollDone(false); + EXPECT_EQ(result1, Status::OK); + + Filter filterAsync2("testFilterAsync", FilterType::FILTERTYPE_VENC, true); + auto mockNextFilter = std::make_shared("mockNextFilter", FilterType::FILTERTYPE_ASINK, false); + filterAsync2.nextFiltersMap_[StreamType::STREAMTYPE_ENCODED_AUDIO].push_back(mockNextFilter); + Status result2 = filterAsync2.WaitPrerollDone(false); + EXPECT_EQ(result2, Status::OK); + + Filter filterAsync3("testFilterAsync", FilterType::FILTERTYPE_VENC, true); + auto mockNextFilterFail = std::make_shared("mockNextFilterFail", FilterType::FILTERTYPE_ASINK, false); + filterAsync3.nextFiltersMap_[StreamType::STREAMTYPE_ENCODED_AUDIO].push_back(mockNextFilterFail); + Status result3 = filterAsync3.WaitPrerollDone(false); + EXPECT_EQ(result3, Status::OK); +} + +HWTEST_F(FilterTest, StartFilterTask_001, testing::ext::TestSize.Level1) +{ + Filter filterAsync("testFilterAsync", FilterType::FILTERTYPE_VENC, true); + filterAsync.filterTask_ = std::make_unique( + "mockTask", "groupId", Media::TaskType::SINGLETON, Media::TaskPriority::HIGH, false); + filterAsync.StartFilterTask(); + EXPECT_TRUE(filterAsync.filterTask_ != nullptr); + + Filter filterSync("testFilterSync", FilterType::FILTERTYPE_ASINK, false); + filterSync.filterTask_ = nullptr; + filterSync.StartFilterTask(); + EXPECT_TRUE(filterSync.filterTask_ == nullptr); +} + +HWTEST_F(FilterTest, PauseFilterTask_001, testing::ext::TestSize.Level1) +{ + Filter filterAsync("testFilterAsync", FilterType::FILTERTYPE_VENC, true); + filterAsync.filterTask_ = std::make_unique( + "mockTask", "groupId", Media::TaskType::SINGLETON, Media::TaskPriority::HIGH, false); + filterAsync.PauseFilterTask(); + EXPECT_TRUE(filterAsync.filterTask_ != nullptr); + + Filter filterSync("testFilterSync", FilterType::FILTERTYPE_ASINK, false); + filterSync.filterTask_ = nullptr; + filterSync.PauseFilterTask(); + EXPECT_TRUE(filterSync.filterTask_ == nullptr); +} + +HWTEST_F(FilterTest, ProcessInputBuffer_001, testing::ext::TestSize.Level1) +{ + Filter filterAsync("testFilterAsync", FilterType::FILTERTYPE_VENC, true); + filterAsync.filterTask_ = std::make_unique( + "mockTask", "groupId", Media::TaskType::SINGLETON, Media::TaskPriority::HIGH, false); + Status result_async = filterAsync.ProcessInputBuffer(1, 1000); + EXPECT_EQ(result_async, Status::OK); + + Filter filterSync("testFilterSync", FilterType::FILTERTYPE_ASINK, false); + filterSync.filterTask_ = nullptr; + Status result_sync = filterSync.ProcessInputBuffer(2, 2000); + EXPECT_EQ(result_sync, Status::OK); +} + +HWTEST_F(FilterTest, ProcessOutputBuffer_001, testing::ext::TestSize.Level1) +{ + Filter filterAsync("testFilterAsync", FilterType::FILTERTYPE_VENC, true); + filterAsync.filterTask_ = std::make_unique( + "mockTask", "groupId", Media::TaskType::SINGLETON, Media::TaskPriority::HIGH, false); + Status result_async = filterAsync.ProcessOutputBuffer(1, 1000, false, 0, -1); + EXPECT_EQ(result_async, Status::OK); + + Filter filterSync("testFilterSync", FilterType::FILTERTYPE_ASINK, false); + filterSync.filterTask_ = nullptr; + Status result_sync = filterSync.ProcessOutputBuffer(2, 2000, false, 0, -1); + EXPECT_EQ(result_sync, Status::OK); +} + +HWTEST_F(FilterTest, WaitAllState_001, testing::ext::TestSize.Level1) +{ + Filter filter("testFilter", FilterType::FILTERTYPE_VENC, true); + filter.ChangeState(FilterState::CREATED); + Status result1 = filter.WaitAllState(FilterState::RUNNING); + EXPECT_EQ(result1, Status::OK); + + filter.ChangeState(FilterState::RUNNING); + Status result2 = filter.WaitAllState(FilterState::RUNNING); + EXPECT_EQ(result2, Status::OK); + + filter.nextFiltersMap_[StreamType::STREAMTYPE_ENCODED_AUDIO].push_back(nullptr); + Status result3 = filter.WaitAllState(FilterState::RUNNING); + EXPECT_EQ(result3, Status::OK); + + auto mockNextFilter = std::make_shared("mockNextFilter", FilterType::FILTERTYPE_ASINK, false); + filter.nextFiltersMap_[StreamType::STREAMTYPE_ENCODED_AUDIO].push_back(mockNextFilter); + mockNextFilter->ChangeState(FilterState::RUNNING); + Status result4 = filter.WaitAllState(FilterState::RUNNING); + EXPECT_EQ(result4, Status::OK); +} +} // namespace DistributedHardware +} // namespace OHOS \ No newline at end of file diff --git a/av_transport/framework/filter/test/unittest/filter_test.h b/av_transport/framework/filter/test/unittest/filter_test.h new file mode 100644 index 00000000..f943058e --- /dev/null +++ b/av_transport/framework/filter/test/unittest/filter_test.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FILTER_TEST_H +#define FILTER_TEST_H + +#include + +#include "filter.h" +#include "buffer/avbuffer_queue_producer.h" +#include "meta/meta.h" +#include "osal/task/condition_variable.h" +#include "osal/task/mutex.h" +#include "osal/task/task.h" + +#include "pipeline_event.h" +#include "pipeline_status.h" + +namespace OHOS { +namespace DistributedHardware { + +using namespace Pipeline; + +class FilterTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp() override; + void TearDown() override; +}; +} // namespace DistributedHardware +} // namespace OHOS + +#endif // FILTER_TEST_H \ No newline at end of file diff --git a/bundle.json b/bundle.json index c851cf0a..d5e91c6f 100644 --- a/bundle.json +++ b/bundle.json @@ -161,6 +161,7 @@ "//foundation/distributedhardware/distributed_hardware_fwk/services/distributedhardwarefwkservice/test/fuzztest:fuzztest", "//foundation/distributedhardware/distributed_hardware_fwk/interfaces/inner_kits/test/fuzztest:fuzztest", "//foundation/distributedhardware/distributed_hardware_fwk/av_transport/av_trans_engine/filters/test:filter_test", + "//foundation/distributedhardware/distributed_hardware_fwk/av_transport/framework/filter/test:framework_filter_test", "//foundation/distributedhardware/distributed_hardware_fwk/av_transport/av_trans_engine/av_receiver/test/unittest:receiver_test", "//foundation/distributedhardware/distributed_hardware_fwk/av_transport/av_trans_engine/av_sender/test/unittest:sender_test", "//foundation/distributedhardware/distributed_hardware_fwk/av_transport/av_trans_engine/plugin/test:plugin_test", -- Gitee