From 31d48dde19c7ee8025a2b909d82a8b3f402915f6 Mon Sep 17 00:00:00 2001 From: chen0088 Date: Wed, 30 Oct 2024 16:36:06 +0800 Subject: [PATCH] add ut Signed-off-by: chen0088 --- .../common/distributedcameramgr/BUILD.gn | 1 + .../dcamera_source_controller_test.cpp | 20 +++++ ...era_source_input_channel_listener_test.cpp | 86 +++++++++++++++++++ .../dcamera_source_input_test.cpp | 14 ++- ...mera_stream_data_process_producer_test.cpp | 2 +- 5 files changed, 120 insertions(+), 3 deletions(-) create mode 100644 services/cameraservice/sourceservice/test/unittest/common/distributedcameramgr/dcamera_source_input_channel_listener_test.cpp diff --git a/services/cameraservice/sourceservice/test/unittest/common/distributedcameramgr/BUILD.gn b/services/cameraservice/sourceservice/test/unittest/common/distributedcameramgr/BUILD.gn index 0a05c6ad..d0a99d2b 100644 --- a/services/cameraservice/sourceservice/test/unittest/common/distributedcameramgr/BUILD.gn +++ b/services/cameraservice/sourceservice/test/unittest/common/distributedcameramgr/BUILD.gn @@ -65,6 +65,7 @@ ohos_unittest("DCameraSourceMgrTest") { "dcamera_source_controller_test.cpp", "dcamera_source_data_process_test.cpp", "dcamera_source_dev_test.cpp", + "dcamera_source_input_channel_listener_test.cpp", "dcamera_source_input_test.cpp", "dcamera_source_service_ipc_test.cpp", "dcamera_source_state_machine_test.cpp", 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 c4e2b206..81f4bc9a 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 @@ -56,6 +56,7 @@ const int32_t TEST_FORMAT = 4; const int32_t TEST_DATASPACE = 8; const int32_t TEST_ISCAPTURE = 0; const int32_t TEST_SLEEP_SEC = 200000; +const size_t DATABUFF_MAX_SIZE = 100 * 1024 * 1024; } void DCameraSourceControllerTest::SetUpTestCase(void) @@ -100,6 +101,7 @@ HWTEST_F(DCameraSourceControllerTest, dcamera_source_controller_test_001, TestSi int32_t ret = controller_->Init(indexs_); EXPECT_EQ(ret, DCAMERA_INIT_ERR); } + /** * @tc.name: dcamera_source_controller_test_002 * @tc.desc: Verify source controller UnInit. @@ -113,6 +115,7 @@ HWTEST_F(DCameraSourceControllerTest, dcamera_source_controller_test_002, TestSi ret = controller_->UnInit(); EXPECT_EQ(ret, DCAMERA_OK); } + /** * @tc.name: dcamera_source_controller_test_003 * @tc.desc: Verify source controller StartCapture. @@ -143,6 +146,7 @@ HWTEST_F(DCameraSourceControllerTest, dcamera_source_controller_test_003, TestSi controller_->UnInit(); EXPECT_EQ(ret, DCAMERA_OK); } + /** * @tc.name: dcamera_source_controller_test_004 * @tc.desc: Verify source controller StartCapture and StopCapture. @@ -307,12 +311,28 @@ HWTEST_F(DCameraSourceControllerTest, dcamera_source_controller_test_010, TestSi std::make_shared(controller_); int32_t state = 0; listener->OnSessionState(state, ""); + state = 1; + listener->OnSessionState(state, ""); int32_t eventType = 1; int32_t eventReason = 1; std::string detail = "OnSessionErrorTest"; listener->OnSessionError(eventType, eventReason, detail); std::vector> buffers; listener->OnDataReceived(buffers); + size_t capacity = 0; + std::shared_ptr dataBuffer = std::make_shared(capacity); + buffers.push_back(dataBuffer); + listener->OnDataReceived(buffers); + buffers.clear(); + capacity = DATABUFF_MAX_SIZE + 1; + dataBuffer = std::make_shared(capacity); + buffers.push_back(dataBuffer); + listener->OnDataReceived(buffers); + buffers.clear(); + capacity = 1; + dataBuffer = std::make_shared(capacity); + buffers.push_back(dataBuffer); + listener->OnDataReceived(buffers); ret = controller_->UnInit(); EXPECT_EQ(ret, DCAMERA_OK); } diff --git a/services/cameraservice/sourceservice/test/unittest/common/distributedcameramgr/dcamera_source_input_channel_listener_test.cpp b/services/cameraservice/sourceservice/test/unittest/common/distributedcameramgr/dcamera_source_input_channel_listener_test.cpp new file mode 100644 index 00000000..5c44783c --- /dev/null +++ b/services/cameraservice/sourceservice/test/unittest/common/distributedcameramgr/dcamera_source_input_channel_listener_test.cpp @@ -0,0 +1,86 @@ +/* + * Copyright (c) 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 "dcamera_source_input_channel_listener.h" +#include "dcamera_source_input.h" +#include "distributed_camera_errno.h" +#include "mock_dcamera_source_state_listener.h" + +using namespace testing::ext; + +namespace OHOS { +namespace DistributedHardware { +class DCameraSourceInputChannelListenerTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); + + std::shared_ptr conListener_; +private: + static void SetStreamInfos(); + static void SetCaptureInfos(); +}; + +namespace { +const std::string TEST_DEVICE_ID = "bb536a637105409e904d4da83790a4a7"; +const std::string TEST_CAMERA_DH_ID_0 = "camera_0"; +} + +void DCameraSourceInputChannelListenerTest::SetUpTestCase(void) +{ +} + +void DCameraSourceInputChannelListenerTest::TearDownTestCase(void) +{ +} + +void DCameraSourceInputChannelListenerTest::SetUp(void) +{ + std::shared_ptr stateListener = std::make_shared(); + std::shared_ptr camDev = + std::make_shared(TEST_DEVICE_ID, TEST_CAMERA_DH_ID_0, stateListener); + std::shared_ptr testInput = + std::make_shared(TEST_DEVICE_ID, TEST_CAMERA_DH_ID_0, camDev); + conListener_ = std::make_shared(testInput, CONTINUOUS_FRAME); +} + +void DCameraSourceInputChannelListenerTest::TearDown(void) +{ + conListener_ = nullptr; +} + +/** + * @tc.name: dcamera_source_input_channel_listener_test_001 + * @tc.desc: Verify source inptut channel listener func. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(DCameraSourceInputChannelListenerTest, dcamera_source_input_channel_listener_test_001, TestSize.Level1) +{ + EXPECT_EQ(false, conListener_ == nullptr); + + int32_t test = 0; + std::string str = "test001"; + std::vector> buffers; + conListener_->OnSessionState(test, str); + conListener_->OnSessionError(test, test, str); + conListener_->OnDataReceived(buffers); + EXPECT_EQ(true, test == 0); +} +} // namespace DistributedHardware +} // namespace OHOS diff --git a/services/cameraservice/sourceservice/test/unittest/common/distributedcameramgr/dcamera_source_input_test.cpp b/services/cameraservice/sourceservice/test/unittest/common/distributedcameramgr/dcamera_source_input_test.cpp index 1b40d056..9b396a48 100644 --- a/services/cameraservice/sourceservice/test/unittest/common/distributedcameramgr/dcamera_source_input_test.cpp +++ b/services/cameraservice/sourceservice/test/unittest/common/distributedcameramgr/dcamera_source_input_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * 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 @@ -81,7 +81,7 @@ void DCameraSourceInputTest::SetStreamInfos() streamInfo2->format_ = 1; streamInfo2->dataspace_ = 1; streamInfo2->encodeType_ = ENCODE_TYPE_JPEG; - streamInfo2->type_ = SNAPSHOT_FRAME; + streamInfo2->type_ = CONTINUOUS_FRAME; g_streamInfos.push_back(streamInfo1); g_streamInfos.push_back(streamInfo2); } @@ -190,6 +190,10 @@ HWTEST_F(DCameraSourceInputTest, dcamera_source_input_test_003, TestSize.Level1) rc = testInput_->ConfigStreams(g_streamInfos); EXPECT_EQ(rc, DCAMERA_OK); + std::vector> streamInfos; + rc = testInput_->ConfigStreams(streamInfos); + EXPECT_EQ(rc, DCAMERA_OK); + rc = testInput_->UnInit(); EXPECT_EQ(rc, DCAMERA_OK); } @@ -422,6 +426,12 @@ HWTEST_F(DCameraSourceInputTest, dcamera_source_input_test_015, TestSize.Level1) testInput_->FinshFrameAsyncTrace(DCStreamType::CONTINUOUS_FRAME); testInput_->FinshFrameAsyncTrace(DCStreamType::SNAPSHOT_FRAME); + int32_t state = 0; + testInput_->OnSessionState(DCStreamType::CONTINUOUS_FRAME, state); + state = 1; + testInput_->OnSessionState(DCStreamType::CONTINUOUS_FRAME, state); + state = 2; + testInput_->OnSessionState(DCStreamType::CONTINUOUS_FRAME, state); rc = testInput_->EstablishSnapshotFrameSession(g_camIndexs); EXPECT_NE(rc, DCAMERA_OK); } diff --git a/services/cameraservice/sourceservice/test/unittest/common/distributedcameramgr/dcamera_stream_data_process_producer_test.cpp b/services/cameraservice/sourceservice/test/unittest/common/distributedcameramgr/dcamera_stream_data_process_producer_test.cpp index f5308785..c2a3f93c 100644 --- a/services/cameraservice/sourceservice/test/unittest/common/distributedcameramgr/dcamera_stream_data_process_producer_test.cpp +++ b/services/cameraservice/sourceservice/test/unittest/common/distributedcameramgr/dcamera_stream_data_process_producer_test.cpp @@ -155,7 +155,6 @@ HWTEST_F(DCameraStreamDataProcessProducerTest, dcamera_stream_data_process_produ streamProcess2->Start(); streamProcess2->FeedStream(buffer); streamProcess2->FeedStream(buffer); - streamProcess2->Stop(); DHBase dhBase; dhBase.deviceId_ = TEST_DEVICE_ID; dhBase.dhId_ = TEST_CAMERA_DH_ID_0; @@ -163,6 +162,7 @@ HWTEST_F(DCameraStreamDataProcessProducerTest, dcamera_stream_data_process_produ EXPECT_EQ(DCAMERA_BAD_VALUE, ret); ret = streamProcess2->FeedStreamToDriver(dhBase, buffer); EXPECT_EQ(DCAMERA_BAD_VALUE, ret); + streamProcess2->Stop(); } /** -- Gitee