diff --git a/av_transport/distributed_av_transport.gni b/av_transport/distributed_av_transport.gni index b750f0743bf2941f7ec391e855b48062a21550f2..d97ce451dc1813a5af827f2589c108cd06e42d96 100644 --- a/av_transport/distributed_av_transport.gni +++ b/av_transport/distributed_av_transport.gni @@ -36,6 +36,8 @@ filters_path = "${distributed_av_transport_path}/av_trans_engine/filters" filter_path = "${distributed_av_transport_path}/framework/filter" +pipeline_path = "${distributed_av_transport_path}/framework/pipeline" + dh_fwk_utils_path = "${distributedhardwarefwk_path}/common/utils" dh_fwk_services_path = "${distributedhardwarefwk_path}/services" diff --git a/av_transport/framework/pipeline/test/BUILD.gn b/av_transport/framework/pipeline/test/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..293ea2008ca156dc71370a3a62729850c325909c --- /dev/null +++ b/av_transport/framework/pipeline/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_pipeline_test") { + testonly = true + + deps = [ "unittest:framework_pipeline_unittest" ] +} diff --git a/av_transport/framework/pipeline/test/unittest/BUILD.gn b/av_transport/framework/pipeline/test/unittest/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..6cc333cdf4d4eff19df1bc357fd546c678a0a812 --- /dev/null +++ b/av_transport/framework/pipeline/test/unittest/BUILD.gn @@ -0,0 +1,68 @@ +# 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/distributed_hardware_fwk/av_transport/pipeline/" + +ohos_unittest("AvTransportPipelineTest") { + module_out_path = module_out_path + + include_dirs = [ + "${common_path}/include", + "${filter_path}/include", + "${distributed_av_transport_path}/framework", + "${pipeline_path}/test/unittest", + ] + + sources = [ + "${filter_path}/src/filter.cpp", + "${pipeline_path}/src/pipeline.cpp", + "pipeline_test.cpp", + ] + + cflags = [ + "-O2", + "-fPIC", + "-Wall", + "-fexceptions", + "-Dprivate = public", + "-Dprotected = public", + ] + cflags_cc = cflags + + deps = [] + + if (histreamer_compile_part) { + external_deps = [ "media_foundation:media_foundation" ] + } + + external_deps += [ + "bounds_checking_function:libsec_shared", + "cJSON:cjson", + "c_utils:utils", + "dsoftbus:softbus_client", + "googletest:gmock", + "googletest:gtest", + "hilog:libhilog", + "libevdev:libevdev", + ] +} + +group("framework_pipeline_unittest") { + testonly = true + + deps = [ ":AvTransportPipelineTest" ] +} diff --git a/av_transport/framework/pipeline/test/unittest/pipeline_test.cpp b/av_transport/framework/pipeline/test/unittest/pipeline_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ce8acfa5d2040c94f24d53ed24b1f654ffeb0b17 --- /dev/null +++ b/av_transport/framework/pipeline/test/unittest/pipeline_test.cpp @@ -0,0 +1,259 @@ +/* + * 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 "pipeline_test.h" + +#include +#include + +#include "osal/task/autolock.h" +#include "osal/task/jobutils.h" + +#include "av_trans_log.h" + +using namespace testing::ext; +using namespace OHOS::DistributedHardware; + +namespace OHOS { +namespace DistributedHardware { +namespace Pipeline { +void PipelineTest::SetUp() +{ +} + +void PipelineTest::TearDown() +{ +} + +void PipelineTest::SetUpTestCase() +{ +} + +void PipelineTest::TearDownTestCase() +{ +} + +HWTEST_F(PipelineTest, Prepare_001, testing::ext::TestSize.Level1) +{ + Pipeline pipeline; + std::shared_ptr receiver = nullptr; + std::shared_ptr callback = nullptr; + std::string groupId = "test_group"; + pipeline.Init(receiver, callback, groupId); + + pipeline.filters_.emplace_back(nullptr); + Status ret1 = pipeline.Prepare(); + EXPECT_EQ(ret1, Status::OK); + + pipeline.filters_.clear(); + auto mockFilter = std::make_shared("testFilter", FilterType::FILTERTYPE_VENC, true); + pipeline.filters_.emplace_back(mockFilter); + Status ret2 = pipeline.Prepare(); + EXPECT_EQ(ret2, Status::OK); +} + +HWTEST_F(PipelineTest, Start_001, testing::ext::TestSize.Level1) +{ + Pipeline pipeline; + std::shared_ptr receiver = nullptr; + std::shared_ptr callback = nullptr; + std::string groupId = "test_group"; + pipeline.Init(receiver, callback, groupId); + + pipeline.filters_.emplace_back(nullptr); + Status ret1 = pipeline.Start(); + EXPECT_EQ(ret1, Status::OK); + + pipeline.filters_.clear(); + auto mockFilter = std::make_shared("testFilter", FilterType::FILTERTYPE_VENC, true); + pipeline.filters_.emplace_back(mockFilter); + Status ret2 = pipeline.Start(); + EXPECT_EQ(ret2, Status::OK); +} + +HWTEST_F(PipelineTest, Pause_001, testing::ext::TestSize.Level1) +{ + Pipeline pipeline; + std::shared_ptr receiver = nullptr; + std::shared_ptr callback = nullptr; + std::string groupId = "test_group"; + pipeline.Init(receiver, callback, groupId); + + pipeline.filters_.emplace_back(nullptr); + Status ret1 = pipeline.Pause(); + EXPECT_EQ(ret1, Status::OK); + + pipeline.filters_.clear(); + auto mockFilter = std::make_shared("testFilter", FilterType::FILTERTYPE_VENC, true); + pipeline.filters_.emplace_back(mockFilter); + Status ret2 = pipeline.Pause(); + EXPECT_EQ(ret2, Status::OK); +} + +HWTEST_F(PipelineTest, Resume_001, testing::ext::TestSize.Level1) +{ + Pipeline pipeline; + std::shared_ptr receiver = nullptr; + std::shared_ptr callback = nullptr; + std::string groupId = "test_group"; + pipeline.Init(receiver, callback, groupId); + + pipeline.filters_.emplace_back(nullptr); + Status ret1 = pipeline.Resume(); + EXPECT_EQ(ret1, Status::OK); + + pipeline.filters_.clear(); + auto mockFilter = std::make_shared("testFilter", FilterType::FILTERTYPE_VENC, true); + pipeline.filters_.emplace_back(mockFilter); + Status ret2 = pipeline.Resume(); + EXPECT_EQ(ret2, Status::OK); +} + +HWTEST_F(PipelineTest, Stop_001, testing::ext::TestSize.Level1) +{ + Pipeline pipeline; + std::shared_ptr receiver = nullptr; + std::shared_ptr callback = nullptr; + std::string groupId = "test_group"; + pipeline.Init(receiver, callback, groupId); + + pipeline.filters_.emplace_back(nullptr); + Status ret1 = pipeline.Stop(); + EXPECT_EQ(ret1, Status::OK); + + pipeline.filters_.clear(); + auto mockFilter = std::make_shared("testFilter", FilterType::FILTERTYPE_VENC, true); + pipeline.filters_.emplace_back(mockFilter); + Status ret2 = pipeline.Stop(); + EXPECT_EQ(ret2, Status::OK); +} + +HWTEST_F(PipelineTest, Flush_001, testing::ext::TestSize.Level1) +{ + Pipeline pipeline; + std::shared_ptr receiver = nullptr; + std::shared_ptr callback = nullptr; + std::string groupId = "test_group"; + pipeline.Init(receiver, callback, groupId); + + pipeline.filters_.emplace_back(nullptr); + Status ret1 = pipeline.Flush(); + EXPECT_EQ(ret1, Status::OK); + + pipeline.filters_.clear(); + auto mockFilter = std::make_shared("testFilter", FilterType::FILTERTYPE_VENC, true); + pipeline.filters_.emplace_back(mockFilter); + Status ret2 = pipeline.Flush(); + EXPECT_EQ(ret2, Status::OK); +} + +HWTEST_F(PipelineTest, Release_001, testing::ext::TestSize.Level1) +{ + Pipeline pipeline; + std::shared_ptr receiver = nullptr; + std::shared_ptr callback = nullptr; + std::string groupId = "test_group"; + pipeline.Init(receiver, callback, groupId); + + pipeline.filters_.emplace_back(nullptr); + Status ret1 = pipeline.Release(); + EXPECT_EQ(ret1, Status::OK); + + pipeline.filters_.clear(); + auto mockFilter = std::make_shared("testFilter", FilterType::FILTERTYPE_VENC, true); + pipeline.filters_.emplace_back(mockFilter); + Status ret2 = pipeline.Release(); + EXPECT_EQ(ret2, Status::OK); +} + +HWTEST_F(PipelineTest, Preroll_001, testing::ext::TestSize.Level1) +{ + Pipeline pipeline; + std::shared_ptr receiver = nullptr; + std::shared_ptr callback = nullptr; + std::string groupId = "test_group"; + pipeline.Init(receiver, callback, groupId); + + pipeline.filters_.emplace_back(nullptr); + Status ret1 = pipeline.Preroll(true); + EXPECT_EQ(ret1, Status::OK); + + pipeline.filters_.clear(); + auto mockFilter = std::make_shared("testFilter", FilterType::FILTERTYPE_VENC, true); + pipeline.filters_.emplace_back(mockFilter); + Status ret2 = pipeline.Preroll(false); + EXPECT_EQ(ret2, Status::OK); +} + +HWTEST_F(PipelineTest, SetPlayRange_001, testing::ext::TestSize.Level1) +{ + Pipeline pipeline; + std::shared_ptr receiver = nullptr; + std::shared_ptr callback = nullptr; + std::string groupId = "test_group"; + pipeline.Init(receiver, callback, groupId); + + pipeline.filters_.emplace_back(nullptr); + Status ret1 = pipeline.SetPlayRange(0, 10); + EXPECT_EQ(ret1, Status::OK); + + pipeline.filters_.clear(); + auto mockFilter = std::make_shared("testFilter", FilterType::FILTERTYPE_VENC, true); + pipeline.filters_.emplace_back(mockFilter); + Status ret2 = pipeline.SetPlayRange(10, 20); + EXPECT_EQ(ret2, Status::OK); +} + +HWTEST_F(PipelineTest, AddHeadFilters_001, testing::ext::TestSize.Level1) +{ + Pipeline pipeline; + std::shared_ptr receiver = nullptr; + std::shared_ptr callback = nullptr; + std::string groupId = "test_group"; + pipeline.Init(receiver, callback, groupId); + + std::vector> filtersIn; + filtersIn.emplace_back(nullptr); + + auto validFilter = std::make_shared("testFilter", FilterType::FILTERTYPE_VENC, true); + filtersIn.emplace_back(validFilter); + Status ret = pipeline.AddHeadFilters(filtersIn); + EXPECT_EQ(ret, Status::OK); + EXPECT_EQ(pipeline.filters_.size(), 1); + EXPECT_NE(pipeline.filters_[0], nullptr); +} + +HWTEST_F(PipelineTest, RemoveHeadFilter_001, testing::ext::TestSize.Level1) +{ + Pipeline pipeline; + std::shared_ptr receiver = nullptr; + std::shared_ptr callback = nullptr; + std::string groupId = "test_group"; + pipeline.Init(receiver, callback, groupId); + + auto validFilter = std::make_shared("testFilter", FilterType::FILTERTYPE_VENC, true); + pipeline.filters_.emplace_back(validFilter); + + Status ret1 = pipeline.RemoveHeadFilter(validFilter); + EXPECT_EQ(ret1, Status::OK); + EXPECT_EQ(pipeline.filters_.size(), 0); + + std::shared_ptr nullFilter = nullptr; + Status ret2 = pipeline.RemoveHeadFilter(nullFilter); + EXPECT_EQ(ret2, Status::OK); +} +} // namespace Pipeline +} // namespace DistributedHardware +} // namespace OHOS \ No newline at end of file diff --git a/av_transport/framework/pipeline/test/unittest/pipeline_test.h b/av_transport/framework/pipeline/test/unittest/pipeline_test.h new file mode 100644 index 0000000000000000000000000000000000000000..38973e54118f8b887931fd65bde55727d965f46c --- /dev/null +++ b/av_transport/framework/pipeline/test/unittest/pipeline_test.h @@ -0,0 +1,45 @@ +/* + * 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 PIPELINE_TEST_H +#define PIPELINE_TEST_H + +#include +#include +#include +#include +#include "osal/task/mutex.h" + +#include "pipeline_status.h" +#include "gmock/gmock.h" +#include "filter.h" +#include "pipeline/include/pipeline.h" + +namespace OHOS { +namespace DistributedHardware { +namespace Pipeline { + +class PipelineTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp() override; + void TearDown() override; +}; +} // namespace Pipeline +} // namespace DistributedHardware +} // namespace OHOS + +#endif // PIPELINE_TEST_H \ No newline at end of file diff --git a/bundle.json b/bundle.json index d5e91c6f6e230245d3bc629273adbccec4fadf3c..a6123c25f90df7ff66a0c46c7e640b039899f88c 100644 --- a/bundle.json +++ b/bundle.json @@ -162,6 +162,7 @@ "//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/framework/pipeline/test:framework_pipeline_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",