From 60fe3c387f93202b52463ab7116051de9eeebe3e Mon Sep 17 00:00:00 2001 From: zhuzhihui7 Date: Thu, 10 Apr 2025 15:14:51 +0800 Subject: [PATCH] unit test pr wangz20250410001 Signed-off-by: zhuzhihui7 Change-Id: Ica591d108a308d7d697a69e9559214b6bc9cd35c --- .../dcamera_feeding_smoother_test.cpp | 83 +++++++++++++++++ .../dcamera_source_controller_test.cpp | 80 +++++++++++++++++ .../test/unittest/common/pipeline/BUILD.gn | 1 + .../pipeline/decode_surface_listener_test.cpp | 88 +++++++++++++++++++ .../decode_data_process_test.cpp | 65 ++++++++++++++ 5 files changed, 317 insertions(+) create mode 100644 services/data_process/test/unittest/common/pipeline/decode_surface_listener_test.cpp diff --git a/services/cameraservice/sourceservice/test/unittest/common/distributedcameramgr/dcamera_feeding_smoother_test.cpp b/services/cameraservice/sourceservice/test/unittest/common/distributedcameramgr/dcamera_feeding_smoother_test.cpp index 66f8aefc..f5cb6d74 100644 --- a/services/cameraservice/sourceservice/test/unittest/common/distributedcameramgr/dcamera_feeding_smoother_test.cpp +++ b/services/cameraservice/sourceservice/test/unittest/common/distributedcameramgr/dcamera_feeding_smoother_test.cpp @@ -25,6 +25,57 @@ using namespace testing::ext; namespace OHOS { namespace DistributedHardware { + +class FeedableDataImpl : public IFeedableData { +public: + int64_t GetTimeStamp() override + { + return 1; + } +}; + +class FeedableDataProducerImpl : public IFeedableDataProducer { +public: + void OnSmoothFinished(const std::shared_ptr &data) override + { + if (data) { + data->GetTimeStamp(); + } + return; + } +}; + +class DCameraFeedingSmootherImpl : public IFeedingSmoother { +public: + ~DCameraFeedingSmootherImpl() override = default; + + void PrepareSmooth() override + { + } + + void InitBaseline(const int64_t timeStampBaseline, const int64_t clockBaseline) override + { + } + + void InitTimeStatistician() override + { + dCameraStatistician_ = std::make_shared(); + } + + int32_t NotifySmoothFinished(const std::shared_ptr &data) override + { + return listener_->OnSmoothFinished(data); + } + +private: + constexpr static uint8_t DYNAMIC_BALANCE_THRE = 3; + constexpr static int32_t SMOOTH_BUFFER_TIME_US = 20000; + constexpr static uint32_t AVER_INTERVAL_DIFF_THRE_US = 2000; + constexpr static uint32_t FEED_ONCE_DIFF_THRE_US = 10000; + + std::shared_ptr dCameraStatistician_ = nullptr; +}; + const int32_t SLEEP_TIME = 1000; const int64_t FRAME_INTERVAL = 40000; const uint8_t TWOFOLD = 2; @@ -204,5 +255,37 @@ HWTEST_F(DCameraFeedingSmotherTest, dcamera_feeding_smoother_test_007, TestSize. int32_t ret = smoother->StopSmooth(); EXPECT_EQ(SMOOTH_IS_STOPED, ret); } + +/** + * @tc.name: dcamera_feeding_smoother_test_008 + * @tc.desc: Verify SyncClock func. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(DCameraFeedingSmotherTest, dcamera_feeding_smoother_test_008, TestSize.Level1) +{ + DHLOGI("dcamera_feeding_smoother_test_008"); + std::unique_ptr smoother = std::make_unique(); + int32_t ret = smoother->StartSmooth(); + size_t capacity = 1; + std::shared_ptr data = std::make_shared(capacity); + smoother->state_ = SmoothState::SMOOTH_STOP; + smoother->PushData(data); + smoother->state_ = SmoothState::SMOOTH_START; + smoother->PushData(data); + smoother->InitTimeStatistician(); + smoother->CheckIsProcessInDynamicBalanceOnce(); + std::shared_ptr producer = std::make_shared(); + std::shared_ptr listener = std::make_shared(producer); + smoother->RegisterListener(listener); + std::shared_ptr iFeedableData = std::make_shared(); + std::unique_ptr smootherImpl = std::make_unique(); + smootherImpl->RegisterListener(listener); + smootherImpl->NotifySmoothFinished(iFeedableData); + std::this_thread::sleep_for(std::chrono::microseconds(1000)); + ret = smootherImpl->StopSmooth(); + ret = smoother->StopSmooth(); + EXPECT_EQ(SMOOTH_SUCCESS, ret); +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/services/cameraservice/sourceservice/test/unittest/common/distributedcameramgr/dcamera_source_controller_test.cpp b/services/cameraservice/sourceservice/test/unittest/common/distributedcameramgr/dcamera_source_controller_test.cpp index dc9ad94b..cc43d74d 100644 --- a/services/cameraservice/sourceservice/test/unittest/common/distributedcameramgr/dcamera_source_controller_test.cpp +++ b/services/cameraservice/sourceservice/test/unittest/common/distributedcameramgr/dcamera_source_controller_test.cpp @@ -32,6 +32,54 @@ using namespace testing::ext; namespace OHOS { namespace DistributedHardware { + +class DCameraSourceStateImpl : public DCameraSourceState { +public: + int32_t Execute(std::shared_ptr &camDev, DCAMERA_EVENT eventType, + DCameraSourceEvent &event) override + { + return 0; + } + + DCameraStateType GetStateType() override + { + return DCameraStateType::DCAMERA_STATE_INIT; + } +}; + +class CameraStateListenerImpl : public ICameraStateListener { +public: + int32_t OnRegisterNotify(const std::string &devId, const std::string &dhId, const std::string &reqId, + int32_t status, std::string &data) override + { + return 0; + } + + int32_t OnUnregisterNotify(const std::string &devId, const std::string &dhId, const std::string &reqId, + int32_t status, std::string &data) override + { + return 0; + } + + int32_t OnHardwareStateChanged(const std::string &devId, const std::string &dhId, int32_t status) override + { + return 0; + } + + int32_t OnDataSyncTrigger(const std::string &devId) override + { + return 0; + } + + void SetCallback(sptr callback) override + { + callback_ = callback; + } + +private: + sptr callback_; +}; + std::string g_channelStr = ""; class DCameraSourceControllerTest : public testing::Test { public: @@ -570,5 +618,37 @@ HWTEST_F(DCameraSourceControllerTest, dcamera_source_controller_test_020, TestSi ret = controller_->StopCapture(); EXPECT_EQ(ret, DCAMERA_BAD_OPERATE); } + +/** + * @tc.name: dcamera_source_controller_test_021 + * @tc.desc: Verify source controller DCameraNotify. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(DCameraSourceControllerTest, dcamera_source_controller_test_021, TestSize.Level1) +{ + std::shared_ptr events = std::make_shared(); + events->eventType_ = 1; + events->eventResult_ = DCAMERA_EVENT_CAMERA_SUCCESS; + events->eventContent_ = START_CAPTURE_SUCC; + controller_->camHdiProvider_ = IDCameraProvider::Get(HDF_DCAMERA_EXT_SERVICE); + int32_t ret = controller_->DCameraNotify(events); + int32_t state = 2; + std::shared_ptr stateLisener = std::make_shared(); + std::shared_ptr camDev = std::make_shared("devId", "dhId", + stateLisener); + std::shared_ptr stMachine = std::make_shared(camDev); + controller_->stateMachine_ = stMachine; + std::shared_ptr currentState = std::make_shared(); + controller_->stateMachine_->currentState_ = currentState; + controller_->OnSessionState(state, "networkId"); + controller_->camDev_ = std::make_shared("devId", "dhId", stateLisener); + controller_->PostChannelDisconnectedEvent(); + controller_->PauseDistributedHardware("networkId"); + controller_->ResumeDistributedHardware("networkId"); + controller_->StopDistributedHardware("networkId"); + controller_->UnInit(); + EXPECT_EQ(ret, DCAMERA_BAD_OPERATE); } } +} \ No newline at end of file diff --git a/services/data_process/test/unittest/common/pipeline/BUILD.gn b/services/data_process/test/unittest/common/pipeline/BUILD.gn index 0d4f5022..6c7c517a 100644 --- a/services/data_process/test/unittest/common/pipeline/BUILD.gn +++ b/services/data_process/test/unittest/common/pipeline/BUILD.gn @@ -52,6 +52,7 @@ ohos_unittest("DCameraDataProcessPipelineTest") { sources = [ "dcamera_pipeline_sink_test.cpp", "dcamera_pipeline_source_test.cpp", + "decode_surface_listener_test.cpp", ] configs = [ ":module_private_config" ] diff --git a/services/data_process/test/unittest/common/pipeline/decode_surface_listener_test.cpp b/services/data_process/test/unittest/common/pipeline/decode_surface_listener_test.cpp new file mode 100644 index 00000000..fc746314 --- /dev/null +++ b/services/data_process/test/unittest/common/pipeline/decode_surface_listener_test.cpp @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2022-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 + +#include "decode_data_process.h" +#include "decode_video_callback.h" +#include "decode_surface_listener.h" +#include "dcamera_pipeline_sink.h" +#include "distributed_camera_constants.h" +#include "distributed_camera_errno.h" +#include "distributed_hardware_log.h" +#include "fps_controller_process.h" +#include "mock_dcamera_data_process_listener.h" + + +using namespace testing::ext; + +namespace OHOS { +namespace DistributedHardware { +class DecodeSurfaceListenerTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); +}; + +void DecodeSurfaceListenerTest::SetUpTestCase(void) +{ +} + +void DecodeSurfaceListenerTest::TearDownTestCase(void) +{ +} + +void DecodeSurfaceListenerTest::SetUp(void) +{ +} + +void DecodeSurfaceListenerTest::TearDown(void) +{ +} + +/** + * @tc.name: decode_surface_listener_test_001 + * @tc.desc: Verify decode surface listener normal. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(DecodeSurfaceListenerTest, decode_surface_listener_test_001, TestSize.Level1) +{ + std::shared_ptr pipeEventHandler = std::make_shared(); + std::weak_ptr callbackPipSource = std::make_shared(); + sptr surface = IConsumerSurface::Create(); + std::weak_ptr decodeVideoNode = std::make_shared(pipeEventHandler, + callbackPipSource); + std::shared_ptr listener = std::make_shared(surface, + decodeVideoNode); + listener->SetDecodeVideoNode(decodeVideoNode); + listener->GetDecodeVideoNode(); + listener->OnBufferAvailable(); + std::shared_ptr dCallBack = std::make_shared(decodeVideoNode); + std::shared_ptr buffer = nullptr; + dCallBack->OnInputBufferAvailable(0, buffer); + Media::Format format; + dCallBack->OnOutputFormatChanged(format); + std::shared_ptr buffer2 = nullptr; + MediaAVCodec::AVCodecBufferInfo info; + MediaAVCodec::AVCodecBufferFlag flag = MediaAVCodec::AVCODEC_BUFFER_FLAG_CODEC_DATA; + dCallBack->OnOutputBufferAvailable(0, info, flag, buffer2); + int32_t rc = DCAMERA_OK; + EXPECT_EQ(rc, DCAMERA_OK); +} +} // namespace DistributedHardware +} // namespace OHOS diff --git a/services/data_process/test/unittest/common/pipeline_node/decode_data_process_test.cpp b/services/data_process/test/unittest/common/pipeline_node/decode_data_process_test.cpp index 7dbd0e5d..8e8f8a02 100644 --- a/services/data_process/test/unittest/common/pipeline_node/decode_data_process_test.cpp +++ b/services/data_process/test/unittest/common/pipeline_node/decode_data_process_test.cpp @@ -580,5 +580,70 @@ HWTEST_F(DecodeDataProcessTest, decode_data_process_test_016, TestSize.Level1) testDecodeDataProcess_->isDecoderProcess_.store(true); EXPECT_EQ(rc, DCAMERA_OK); } + +/** + * @tc.name: decode_data_process_test_017 + * @tc.desc: Verify decode data process func. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(DecodeDataProcessTest, decode_data_process_test_017, TestSize.Level1) +{ + DHLOGI("DecodeDataProcessTest decode_data_process_test_017"); + EXPECT_EQ(false, testDecodeDataProcess_ == nullptr); + VideoConfigParams srcParams2(VideoCodecType::CODEC_H264, + Videoformat::NV12, DCAMERA_PRODUCER_FPS_DEFAULT, 2000, 2000); + VideoConfigParams destParams2(VideoCodecType::NO_CODEC, + Videoformat::NV21, DCAMERA_PRODUCER_FPS_DEFAULT, 2000, 2000); + VideoConfigParams procConfig2; + int32_t rc = testDecodeDataProcess_->InitNode(srcParams2, destParams2, procConfig2); + testDecodeDataProcess_->OnError(); + testDecodeDataProcess_->isDecoderProcess_.store(true); + EXPECT_EQ(rc, DCAMERA_OK); +} + +/** + * @tc.name: decode_data_process_test_018 + * @tc.desc: Verify decode data process func. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(DecodeDataProcessTest, decode_data_process_test_018, TestSize.Level1) +{ + DHLOGI("DecodeDataProcessTest decode_data_process_test_018"); + EXPECT_EQ(false, testDecodeDataProcess_ == nullptr); + VideoConfigParams srcParams3(VideoCodecType::CODEC_H265, + Videoformat::NV12, DCAMERA_PRODUCER_FPS_DEFAULT, TEST_WIDTH, TEST_HEIGTH); + VideoConfigParams destParams3(VideoCodecType::NO_CODEC, + Videoformat::NV21, DCAMERA_PRODUCER_FPS_DEFAULT, TEST_WIDTH, TEST_HEIGTH); + VideoConfigParams procConfig3; + int32_t rc = testDecodeDataProcess_->InitNode(srcParams3, destParams3, procConfig3); + testDecodeDataProcess_->OnError(); + testDecodeDataProcess_->isDecoderProcess_.store(true); + DHLOGI("DecodeDataProcessTest 14"); + EXPECT_EQ(rc, DCAMERA_OK); +} + +/** + * @tc.name: decode_data_process_test_019 + * @tc.desc: Verify decode data process func. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(DecodeDataProcessTest, decode_data_process_test_019, TestSize.Level1) +{ + DHLOGI("DecodeDataProcessTest decode_data_process_test_019"); + EXPECT_EQ(false, testDecodeDataProcess_ == nullptr); + VideoConfigParams srcParams4(VideoCodecType::NO_CODEC, + Videoformat::NV12, DCAMERA_PRODUCER_FPS_DEFAULT, TEST_WIDTH, TEST_HEIGTH); + VideoConfigParams destParams4(VideoCodecType::NO_CODEC, + Videoformat::NV21, DCAMERA_PRODUCER_FPS_DEFAULT, TEST_WIDTH, TEST_HEIGTH); + VideoConfigParams procConfig4; + int32_t rc = testDecodeDataProcess_->InitNode(srcParams4, destParams4, procConfig4); + testDecodeDataProcess_->OnError(); + testDecodeDataProcess_->isDecoderProcess_.store(true); + EXPECT_EQ(rc, DCAMERA_OK); +} + } // namespace DistributedHardware } // namespace OHOS -- Gitee