From 9f155aa61836a6b7a2926f635df3920fb77a6b80 Mon Sep 17 00:00:00 2001 From: chen0088 Date: Wed, 2 Nov 2022 15:41:18 +0800 Subject: [PATCH] fix:add unittest Signed-off-by: chen0088 --- bundle.json | 1 + services/data_process/test/unittest/BUILD.gn | 17 ++ .../test/unittest/common/pipeline/BUILD.gn | 76 +++++++ .../pipeline/dcamera_pipeline_sink_test.cpp | 190 +++++++++++++++++ .../pipeline/dcamera_pipeline_source_test.cpp | 192 ++++++++++++++++++ .../mock_dcamera_data_process_listener.h | 40 ++++ 6 files changed, 516 insertions(+) create mode 100644 services/data_process/test/unittest/BUILD.gn create mode 100644 services/data_process/test/unittest/common/pipeline/BUILD.gn create mode 100644 services/data_process/test/unittest/common/pipeline/dcamera_pipeline_sink_test.cpp create mode 100644 services/data_process/test/unittest/common/pipeline/dcamera_pipeline_source_test.cpp create mode 100644 services/data_process/test/unittest/common/pipeline/mock_dcamera_data_process_listener.h diff --git a/bundle.json b/bundle.json index d5e2cd35..135921de 100644 --- a/bundle.json +++ b/bundle.json @@ -96,6 +96,7 @@ "//foundation/distributedhardware/distributed_camera/services/cameraservice/sinkservice/test/unittest:sink_service_test", "//foundation/distributedhardware/distributed_camera/services/cameraservice/sourceservice/test/unittest:source_service_test", "//foundation/distributedhardware/distributed_camera/services/cameraservice/base/test/unittest:services_base_test", + "//foundation/distributedhardware/distributed_camera/services/data_process/test/unittest:data_process_test", "//foundation/distributedhardware/distributed_camera/interfaces/inner_kits/native_cpp/test/fuzztest:fuzztest" ] } diff --git a/services/data_process/test/unittest/BUILD.gn b/services/data_process/test/unittest/BUILD.gn new file mode 100644 index 00000000..3a36afb5 --- /dev/null +++ b/services/data_process/test/unittest/BUILD.gn @@ -0,0 +1,17 @@ +# Copyright (c) 2022 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("data_process_test") { + testonly = true + deps = [ "common/pipeline:dcamera_pipeline_test" ] +} diff --git a/services/data_process/test/unittest/common/pipeline/BUILD.gn b/services/data_process/test/unittest/common/pipeline/BUILD.gn new file mode 100644 index 00000000..befb4ea7 --- /dev/null +++ b/services/data_process/test/unittest/common/pipeline/BUILD.gn @@ -0,0 +1,76 @@ +# Copyright (c) 2022 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( + "//foundation/distributedhardware/distributed_camera/distributedcamera.gni") + +module_out_path = "distributed_camera/dcamera_data_process_test" + +config("module_private_config") { + visibility = [ ":*" ] + include_dirs = [ + "${services_path}/data_process/include/interfaces", + "${services_path}/data_process/include/eventbus", + "${services_path}/data_process/include/pipeline", + "${services_path}/data_process/include/utils", + "${services_path}/data_process/include/pipeline_node/multimedia_codec/decoder", + "${services_path}/data_process/include/pipeline_node/multimedia_codec/encoder", + "${services_path}/data_process/include/pipeline_node/colorspace_conversion", + "${services_path}/data_process/include/pipeline_node/fpscontroller", + "${services_path}/data_process/include/pipeline_node/scale_conversion", + "${services_path}/cameraservice/sinkservice/include/distributedcameramgr", + "${common_path}/include/constants", + "${common_path}/include/utils", + "${innerkits_path}/native_cpp/camera_source/include", + "//commonlibrary/c_utils/base/include", + "${fwk_common_path}/utils/include", + "${fwk_utils_path}/include/eventbus", + ] +} + +ohos_unittest("DCameraDataProcessPipelineTest") { + module_out_path = module_out_path + + sources = [ + "dcamera_pipeline_sink_test.cpp", + "dcamera_pipeline_source_test.cpp", + ] + + configs = [ ":module_private_config" ] + + deps = [ + "${common_path}:distributed_camera_utils", + "${services_path}/data_process:distributed_camera_data_process", + "//foundation/graphic/graphic_2d/frameworks/surface:surface", + "//third_party/ffmpeg:libohosffmpeg", + ] + + external_deps = [ + "c_utils:utils", + "eventhandler:libeventhandler", + "hitrace_native:hitrace_meter", + "multimedia_player_framework:media_client", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"DCameraDataProcessPipelineTest\"", + "LOG_DOMAIN=0xD004100", + ] +} + +group("dcamera_pipeline_test") { + testonly = true + deps = [ ":DCameraDataProcessPipelineTest" ] +} diff --git a/services/data_process/test/unittest/common/pipeline/dcamera_pipeline_sink_test.cpp b/services/data_process/test/unittest/common/pipeline/dcamera_pipeline_sink_test.cpp new file mode 100644 index 00000000..395430b0 --- /dev/null +++ b/services/data_process/test/unittest/common/pipeline/dcamera_pipeline_sink_test.cpp @@ -0,0 +1,190 @@ +/* + * Copyright (c) 2022 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 + +#include "dcamera_pipeline_sink.h" +#include "distributed_camera_constants.h" +#include "distributed_camera_errno.h" +#include "mock_dcamera_data_process_listener.h" + +using namespace testing::ext; + +namespace OHOS { +namespace DistributedHardware { +class DCameraPipelineSinkTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); + + std::shared_ptr testSinkPipeline_; +}; + +namespace { +const int32_t TEST_WIDTH = 1920; +const int32_t TEST_HEIGTH = 1080; +} + +void DCameraPipelineSinkTest::SetUpTestCase(void) +{ +} + +void DCameraPipelineSinkTest::TearDownTestCase(void) +{ +} + +void DCameraPipelineSinkTest::SetUp(void) +{ + testSinkPipeline_ = std::make_shared(); +} + +void DCameraPipelineSinkTest::TearDown(void) +{ + testSinkPipeline_ = nullptr; +} + +/** + * @tc.name: dcamera_pipeline_sink_test_001 + * @tc.desc: Verify pipeline sink CreateDataProcessPipeline normal. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(DCameraPipelineSinkTest, dcamera_pipeline_sink_test_001, TestSize.Level1) +{ + EXPECT_EQ(false, testSinkPipeline_ == nullptr); + + std::shared_ptr listener = std::make_shared(); + VideoConfigParams srcParams(VideoCodecType::NO_CODEC, + Videoformat::NV21, + DCAMERA_PRODUCER_FPS_DEFAULT, + TEST_WIDTH, + TEST_HEIGTH); + VideoConfigParams destParams(VideoCodecType::CODEC_H265, + Videoformat::NV21, + DCAMERA_PRODUCER_FPS_DEFAULT, + TEST_WIDTH, + TEST_HEIGTH); + int32_t rc = testSinkPipeline_->CreateDataProcessPipeline(PipelineType::VIDEO, srcParams, destParams, listener); + EXPECT_EQ(rc, DCAMERA_OK); +} + +/** + * @tc.name: dcamera_pipeline_sink_test_002 + * @tc.desc: Verify pipeline sink ProcessData normal. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(DCameraPipelineSinkTest, dcamera_pipeline_sink_test_002, TestSize.Level1) +{ + EXPECT_EQ(false, testSinkPipeline_ == nullptr); + + std::shared_ptr listener = std::make_shared(); + VideoConfigParams srcParams(VideoCodecType::NO_CODEC, + Videoformat::NV21, + DCAMERA_PRODUCER_FPS_DEFAULT, + TEST_WIDTH, + TEST_HEIGTH); + VideoConfigParams destParams(VideoCodecType::CODEC_H265, + Videoformat::NV21, + DCAMERA_PRODUCER_FPS_DEFAULT, + TEST_WIDTH, + TEST_HEIGTH); + int32_t rc = testSinkPipeline_->CreateDataProcessPipeline(PipelineType::VIDEO, srcParams, destParams, listener); + EXPECT_EQ(rc, DCAMERA_OK); + + size_t capacity = 100; + std::vector> buffers; + std::shared_ptr db = std::make_shared(capacity); + buffers.push_back(db); + rc = testSinkPipeline_->ProcessData(buffers); + EXPECT_EQ(rc, DCAMERA_OK); +} + +/** + * @tc.name: dcamera_pipeline_sink_test_003 + * @tc.desc: Verify pipeline sink CreateDataProcessPipeline abnormal. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(DCameraPipelineSinkTest, dcamera_pipeline_sink_test_003, TestSize.Level1) +{ + EXPECT_EQ(false, testSinkPipeline_ == nullptr); + + std::shared_ptr listener = std::make_shared(); + VideoConfigParams srcParams(VideoCodecType::NO_CODEC, + Videoformat::NV21, + DCAMERA_PRODUCER_FPS_DEFAULT, + TEST_WIDTH, + TEST_HEIGTH); + VideoConfigParams destParams(VideoCodecType::CODEC_H265, + Videoformat::NV21, + DCAMERA_PRODUCER_FPS_DEFAULT, + TEST_WIDTH, + TEST_HEIGTH); + int32_t rc = testSinkPipeline_->CreateDataProcessPipeline( + PipelineType::PHOTO_JPEG, srcParams, destParams, listener); + EXPECT_EQ(rc, DCAMERA_NOT_FOUND); +} + +/** + * @tc.name: dcamera_pipeline_sink_test_004 + * @tc.desc: Verify pipeline sink ProcessData abnormal. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(DCameraPipelineSinkTest, dcamera_pipeline_sink_test_004, TestSize.Level1) +{ + EXPECT_EQ(false, testSinkPipeline_ == nullptr); + + std::shared_ptr listener = std::make_shared(); + VideoConfigParams srcParams(VideoCodecType::NO_CODEC, + Videoformat::NV21, + DCAMERA_PRODUCER_FPS_DEFAULT, + TEST_WIDTH, + TEST_HEIGTH); + VideoConfigParams destParams(VideoCodecType::CODEC_H265, + Videoformat::NV21, + DCAMERA_PRODUCER_FPS_DEFAULT, + TEST_WIDTH, + TEST_HEIGTH); + int32_t rc = testSinkPipeline_->CreateDataProcessPipeline(PipelineType::VIDEO, srcParams, destParams, listener); + EXPECT_EQ(rc, DCAMERA_OK); + + std::vector> buffers; + rc = testSinkPipeline_->ProcessData(buffers); + EXPECT_EQ(rc, DCAMERA_BAD_VALUE); +} + +/** + * @tc.name: dcamera_pipeline_sink_test_005 + * @tc.desc: Verify pipeline sink ProcessData abnormal. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(DCameraPipelineSinkTest, dcamera_pipeline_sink_test_005, TestSize.Level1) +{ + EXPECT_EQ(false, testSinkPipeline_ == nullptr); + + size_t capacity = 100; + std::vector> buffers; + std::shared_ptr db = std::make_shared(capacity); + buffers.push_back(db); + int32_t rc = testSinkPipeline_->ProcessData(buffers); + EXPECT_EQ(rc, DCAMERA_INIT_ERR); +} +} // namespace DistributedHardware +} // namespace OHOS diff --git a/services/data_process/test/unittest/common/pipeline/dcamera_pipeline_source_test.cpp b/services/data_process/test/unittest/common/pipeline/dcamera_pipeline_source_test.cpp new file mode 100644 index 00000000..c4d53277 --- /dev/null +++ b/services/data_process/test/unittest/common/pipeline/dcamera_pipeline_source_test.cpp @@ -0,0 +1,192 @@ +/* + * Copyright (c) 2022 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 + +#include "dcamera_pipeline_source.h" +#include "distributed_camera_constants.h" +#include "distributed_camera_errno.h" +#include "mock_dcamera_data_process_listener.h" + +using namespace testing::ext; + +namespace OHOS { +namespace DistributedHardware { +class DCameraPipelineSourceTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); + + std::shared_ptr testSourcePipeline_; +}; + +namespace { +const int32_t TEST_WIDTH = 1920; +const int32_t TEST_HEIGTH = 1080; +const int32_t TEST_WIDTH2 = 640; +const int32_t TEST_HEIGTH2 = 480; +} + +void DCameraPipelineSourceTest::SetUpTestCase(void) +{ +} + +void DCameraPipelineSourceTest::TearDownTestCase(void) +{ +} + +void DCameraPipelineSourceTest::SetUp(void) +{ + testSourcePipeline_ = std::make_shared(); +} + +void DCameraPipelineSourceTest::TearDown(void) +{ + testSourcePipeline_ = nullptr; +} + +/** + * @tc.name: dcamera_pipeline_source_test_001 + * @tc.desc: Verify pipeline source CreateDataProcessPipeline normal. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(DCameraPipelineSourceTest, dcamera_pipeline_source_test_001, TestSize.Level1) +{ + EXPECT_EQ(false, testSourcePipeline_ == nullptr); + + std::shared_ptr listener = std::make_shared(); + VideoConfigParams srcParams(VideoCodecType::CODEC_H264, + Videoformat::NV12, + DCAMERA_PRODUCER_FPS_DEFAULT, + TEST_WIDTH, + TEST_HEIGTH); + VideoConfigParams destParams(VideoCodecType::CODEC_H264, + Videoformat::NV21, + DCAMERA_PRODUCER_FPS_DEFAULT, + TEST_WIDTH2, + TEST_HEIGTH2); + int32_t rc = testSourcePipeline_->CreateDataProcessPipeline(PipelineType::VIDEO, srcParams, destParams, listener); + EXPECT_EQ(rc, DCAMERA_OK); +} + +/** + * @tc.name: dcamera_pipeline_source_test_002 + * @tc.desc: Verify pipeline source ProcessData normal. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(DCameraPipelineSourceTest, dcamera_pipeline_source_test_002, TestSize.Level1) +{ + EXPECT_EQ(false, testSourcePipeline_ == nullptr); + + std::shared_ptr listener = std::make_shared(); + VideoConfigParams srcParams(VideoCodecType::CODEC_H265, + Videoformat::NV21, + DCAMERA_PRODUCER_FPS_DEFAULT, + TEST_WIDTH, + TEST_HEIGTH); + VideoConfigParams destParams(VideoCodecType::CODEC_H265, + Videoformat::NV21, + DCAMERA_PRODUCER_FPS_DEFAULT, + TEST_WIDTH, + TEST_HEIGTH); + int32_t rc = testSourcePipeline_->CreateDataProcessPipeline(PipelineType::VIDEO, srcParams, destParams, listener); + EXPECT_EQ(rc, DCAMERA_OK); + + size_t capacity = 100; + std::vector> buffers; + std::shared_ptr db = std::make_shared(capacity); + buffers.push_back(db); + rc = testSourcePipeline_->ProcessData(buffers); + EXPECT_EQ(rc, DCAMERA_OK); +} + +/** + * @tc.name: dcamera_pipeline_source_test_003 + * @tc.desc: Verify pipeline source CreateDataProcessPipeline abnormal. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(DCameraPipelineSourceTest, dcamera_pipeline_source_test_003, TestSize.Level1) +{ + EXPECT_EQ(false, testSourcePipeline_ == nullptr); + + std::shared_ptr listener = std::make_shared(); + VideoConfigParams srcParams(VideoCodecType::NO_CODEC, + Videoformat::NV21, + DCAMERA_PRODUCER_FPS_DEFAULT, + TEST_WIDTH, + TEST_HEIGTH); + VideoConfigParams destParams(VideoCodecType::CODEC_H265, + Videoformat::NV21, + DCAMERA_PRODUCER_FPS_DEFAULT, + TEST_WIDTH, + TEST_HEIGTH); + int32_t rc = testSourcePipeline_->CreateDataProcessPipeline( + PipelineType::PHOTO_JPEG, srcParams, destParams, listener); + EXPECT_EQ(rc, DCAMERA_NOT_FOUND); +} + +/** + * @tc.name: dcamera_pipeline_source_test_004 + * @tc.desc: Verify pipeline source ProcessData abnormal. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(DCameraPipelineSourceTest, dcamera_pipeline_source_test_004, TestSize.Level1) +{ + EXPECT_EQ(false, testSourcePipeline_ == nullptr); + + std::shared_ptr listener = std::make_shared(); + VideoConfigParams srcParams(VideoCodecType::NO_CODEC, + Videoformat::NV21, + DCAMERA_PRODUCER_FPS_DEFAULT, + TEST_WIDTH, + TEST_HEIGTH); + VideoConfigParams destParams(VideoCodecType::NO_CODEC, + Videoformat::NV21, + DCAMERA_PRODUCER_FPS_DEFAULT, + TEST_WIDTH, + TEST_HEIGTH); + int32_t rc = testSourcePipeline_->CreateDataProcessPipeline(PipelineType::VIDEO, srcParams, destParams, listener); + EXPECT_EQ(rc, DCAMERA_OK); + + std::vector> buffers; + rc = testSourcePipeline_->ProcessData(buffers); + EXPECT_EQ(rc, DCAMERA_BAD_VALUE); +} + +/** + * @tc.name: dcamera_pipeline_source_test_005 + * @tc.desc: Verify pipeline source ProcessData abnormal. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(DCameraPipelineSourceTest, dcamera_pipeline_source_test_005, TestSize.Level1) +{ + EXPECT_EQ(false, testSourcePipeline_ == nullptr); + + size_t capacity = 100; + std::vector> buffers; + std::shared_ptr db = std::make_shared(capacity); + buffers.push_back(db); + int32_t rc = testSourcePipeline_->ProcessData(buffers); + EXPECT_EQ(rc, DCAMERA_INIT_ERR); +} +} // namespace DistributedHardware +} // namespace OHOS diff --git a/services/data_process/test/unittest/common/pipeline/mock_dcamera_data_process_listener.h b/services/data_process/test/unittest/common/pipeline/mock_dcamera_data_process_listener.h new file mode 100644 index 00000000..acdfd710 --- /dev/null +++ b/services/data_process/test/unittest/common/pipeline/mock_dcamera_data_process_listener.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2022 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 OHOS_MOCK_DCAMERA_DATA_PROCESS_LISTENER_H +#define OHOS_MOCK_DCAMERA_DATA_PROCESS_LISTENER_H + +#include "data_process_listener.h" + +namespace OHOS { +namespace DistributedHardware { +class MockDCameraDataProcessListener : public DataProcessListener { +public: + MockDCameraDataProcessListener() = default; + ~MockDCameraDataProcessListener() = default; + + void OnProcessedVideoBuffer(const std::shared_ptr& videoResult) override + { + (void)videoResult; + } + + void OnError(DataProcessErrorType errorType) override + { + (void)errorType; + } +}; +} // namespace OHOS +} // namespace DistributedHardware +#endif // OHOS_MOCK_DCAMERA_DATA_PROCESS_LISTENER_H -- Gitee