diff --git a/services/cameraservice/sourceservice/test/unittest/common/distributedcameramgr/BUILD.gn b/services/cameraservice/sourceservice/test/unittest/common/distributedcameramgr/BUILD.gn index 74ba9ba9b0a8b865be0dc2d0638edd404cc741c5..a0d5df7a77022f4a81b462d7bf8170459e3bba51 100644 --- a/services/cameraservice/sourceservice/test/unittest/common/distributedcameramgr/BUILD.gn +++ b/services/cameraservice/sourceservice/test/unittest/common/distributedcameramgr/BUILD.gn @@ -54,7 +54,11 @@ config("module_private_config") { ohos_unittest("DCameraSourceMgrTest") { module_out_path = module_out_path - sources = [ "dcamera_source_state_machine_test.cpp" ] + sources = [ + "dcamera_source_data_process_test.cpp", + "dcamera_source_input_test.cpp", + "dcamera_source_state_machine_test.cpp", + ] configs = [ ":module_private_config" ] diff --git a/services/cameraservice/sourceservice/test/unittest/common/distributedcameramgr/dcamera_source_data_process_test.cpp b/services/cameraservice/sourceservice/test/unittest/common/distributedcameramgr/dcamera_source_data_process_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1448e71372a91b308739b0dfb0af3f2587679992 --- /dev/null +++ b/services/cameraservice/sourceservice/test/unittest/common/distributedcameramgr/dcamera_source_data_process_test.cpp @@ -0,0 +1,215 @@ +/* + * 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_source_data_process.h" +#include "distributed_camera_errno.h" + +using namespace testing::ext; + +namespace OHOS { +namespace DistributedHardware { +class DCameraSourceDataProcessTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); + + std::shared_ptr testSrcDataProcess_; +}; + +namespace { +const std::string TEST_DEVICE_ID = "bb536a637105409e904d4da83790a4a7"; +const std::string TEST_CAMERA_DH_ID_0 = "camera_0"; +const int32_t TEST_WIDTH = 1920; +const int32_t TEST_HEIGTH = 1080; +const int32_t TEST_FORMAT = 4; +const int32_t TEST_DATASPACE = 8; +const int32_t TEST_STREAMID = 2; +std::vector> g_streamInfos; +std::vector g_streamIds; +} + +void DCameraSourceDataProcessTest::SetUpTestCase(void) +{ + std::shared_ptr streamInfo1 = std::make_shared(); + streamInfo1->streamId_ = 1; + streamInfo1->width_ = TEST_WIDTH; + streamInfo1->height_ = TEST_HEIGTH; + streamInfo1->stride_ = 1; + streamInfo1->format_ = TEST_FORMAT; + streamInfo1->dataspace_ = TEST_DATASPACE; + streamInfo1->encodeType_ = ENCODE_TYPE_JPEG; + streamInfo1->type_ = SNAPSHOT_FRAME; + + std::shared_ptr streamInfo2 = std::make_shared(); + streamInfo2->streamId_ = TEST_STREAMID; + streamInfo2->width_ = TEST_WIDTH; + streamInfo2->height_ = TEST_HEIGTH; + streamInfo2->stride_ = 1; + streamInfo2->format_ = TEST_FORMAT; + streamInfo2->dataspace_ = TEST_DATASPACE; + streamInfo2->encodeType_ = ENCODE_TYPE_JPEG; + streamInfo2->type_ = SNAPSHOT_FRAME; + g_streamInfos.push_back(streamInfo1); + g_streamInfos.push_back(streamInfo2); + g_streamIds.push_back(1); + g_streamIds.push_back(TEST_STREAMID); +} + +void DCameraSourceDataProcessTest::TearDownTestCase(void) +{ +} + +void DCameraSourceDataProcessTest::SetUp(void) +{ + testSrcDataProcess_ = std::make_shared( + TEST_DEVICE_ID, TEST_CAMERA_DH_ID_0, SNAPSHOT_FRAME); +} + +void DCameraSourceDataProcessTest::TearDown(void) +{ + testSrcDataProcess_ = nullptr; +} + +/** + * @tc.name: dcamera_source_data_process_test_001 + * @tc.desc: Verify source data process ConfigStreams. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(DCameraSourceDataProcessTest, dcamera_source_data_process_test_001, TestSize.Level1) +{ + EXPECT_EQ(false, testSrcDataProcess_ == nullptr); + + int32_t rc = testSrcDataProcess_->ConfigStreams(g_streamInfos); + EXPECT_EQ(rc, DCAMERA_OK); +} + +/** + * @tc.name: dcamera_source_data_process_test_002 + * @tc.desc: Verify source data process ReleaseStreams. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(DCameraSourceDataProcessTest, dcamera_source_data_process_test_002, TestSize.Level1) +{ + EXPECT_EQ(false, testSrcDataProcess_ == nullptr); + + int32_t rc = testSrcDataProcess_->ConfigStreams(g_streamInfos); + EXPECT_EQ(rc, DCAMERA_OK); + + rc = testSrcDataProcess_->ReleaseStreams(g_streamIds); + EXPECT_EQ(rc, DCAMERA_OK); +} + +/** + * @tc.name: dcamera_source_data_process_test_003 + * @tc.desc: Verify source data process StartCapture. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(DCameraSourceDataProcessTest, dcamera_source_data_process_test_003, TestSize.Level1) +{ + EXPECT_EQ(false, testSrcDataProcess_ == nullptr); + + std::shared_ptr captureInfo = std::make_shared(); + captureInfo->streamIds_.push_back(1); + captureInfo->width_ = TEST_WIDTH; + captureInfo->height_ = TEST_HEIGTH; + captureInfo->stride_ = 1; + captureInfo->format_ = 1; + captureInfo->dataspace_ = 1; + captureInfo->encodeType_ = ENCODE_TYPE_H265; + captureInfo->type_ = CONTINUOUS_FRAME; + int32_t rc = testSrcDataProcess_->StartCapture(captureInfo); + EXPECT_EQ(rc, DCAMERA_OK); +} + +/** + * @tc.name: dcamera_source_data_process_test_004 + * @tc.desc: Verify source data process StopCapture. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(DCameraSourceDataProcessTest, dcamera_source_data_process_test_004, TestSize.Level1) +{ + EXPECT_EQ(false, testSrcDataProcess_ == nullptr); + + std::shared_ptr captureInfo = std::make_shared(); + captureInfo->streamIds_.push_back(1); + captureInfo->width_ = TEST_WIDTH; + captureInfo->height_ = TEST_HEIGTH; + captureInfo->stride_ = 1; + captureInfo->format_ = 1; + captureInfo->dataspace_ = 1; + captureInfo->encodeType_ = ENCODE_TYPE_H265; + captureInfo->type_ = CONTINUOUS_FRAME; + int32_t rc = testSrcDataProcess_->StartCapture(captureInfo); + EXPECT_EQ(rc, DCAMERA_OK); + + std::vector streamIds; + streamIds.push_back(1); + rc = testSrcDataProcess_->StopCapture(streamIds); + EXPECT_EQ(rc, DCAMERA_OK); +} + +/** + * @tc.name: dcamera_source_data_process_test_005 + * @tc.desc: Verify source data process FeedStream. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(DCameraSourceDataProcessTest, dcamera_source_data_process_test_005, TestSize.Level1) +{ + EXPECT_EQ(false, testSrcDataProcess_ == nullptr); + + size_t capacity = 100; + std::vector> buffers; + std::shared_ptr db = std::make_shared(capacity); + buffers.push_back(db); + int32_t rc = testSrcDataProcess_->ConfigStreams(g_streamInfos); + EXPECT_EQ(rc, DCAMERA_OK); + + rc = testSrcDataProcess_->FeedStream(buffers); + EXPECT_EQ(rc, DCAMERA_OK); + + rc = testSrcDataProcess_->ReleaseStreams(g_streamIds); + EXPECT_EQ(rc, DCAMERA_OK); +} + +/** + * @tc.name: dcamera_source_data_process_test_006 + * @tc.desc: Verify source data process GetProducerSize. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(DCameraSourceDataProcessTest, dcamera_source_data_process_test_006, TestSize.Level1) +{ + EXPECT_EQ(false, testSrcDataProcess_ == nullptr); + + int32_t rc = testSrcDataProcess_->ConfigStreams(g_streamInfos); + EXPECT_EQ(rc, DCAMERA_OK); + + rc = testSrcDataProcess_->GetProducerSize(); + EXPECT_EQ(rc, DCAMERA_OK); + + rc = testSrcDataProcess_->ReleaseStreams(g_streamIds); + EXPECT_EQ(rc, DCAMERA_OK); +} +} // 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 new file mode 100644 index 0000000000000000000000000000000000000000..6cf9680bae959b4507f2ea0327245ef387991eb2 --- /dev/null +++ b/services/cameraservice/sourceservice/test/unittest/common/distributedcameramgr/dcamera_source_input_test.cpp @@ -0,0 +1,366 @@ +/* + * 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_source_input.h" +#include "distributed_camera_errno.h" + +using namespace testing::ext; + +namespace OHOS { +namespace DistributedHardware { +class DCameraSourceInputTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); + + std::shared_ptr testInput_; + +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"; +const int32_t TEST_WIDTH = 1920; +const int32_t TEST_HEIGTH = 1080; +const int32_t TEST_STREAMID = 2; +std::vector> g_streamInfos; +std::vector> g_captureInfos; +std::vector> g_cameraSettings; +std::vector g_streamIds; +std::vector g_camIndexs; +} + +void DCameraSourceInputTest::SetUpTestCase(void) +{ + SetStreamInfos(); + SetCaptureInfos(); +} + +void DCameraSourceInputTest::SetStreamInfos() +{ + DCameraIndex camIndex1(TEST_DEVICE_ID, TEST_CAMERA_DH_ID_0); + g_camIndexs.push_back(camIndex1); + std::shared_ptr streamInfo1 = std::make_shared(); + streamInfo1->streamId_ = 1; + streamInfo1->width_ = TEST_WIDTH; + streamInfo1->height_ = TEST_HEIGTH; + streamInfo1->stride_ = 1; + streamInfo1->format_ = 1; + streamInfo1->dataspace_ = 1; + streamInfo1->encodeType_ = ENCODE_TYPE_JPEG; + streamInfo1->type_ = SNAPSHOT_FRAME; + + std::shared_ptr streamInfo2 = std::make_shared(); + streamInfo2->streamId_ = TEST_STREAMID; + streamInfo2->width_ = TEST_WIDTH; + streamInfo2->height_ = TEST_HEIGTH; + streamInfo2->stride_ = 1; + streamInfo2->format_ = 1; + streamInfo2->dataspace_ = 1; + streamInfo2->encodeType_ = ENCODE_TYPE_JPEG; + streamInfo2->type_ = SNAPSHOT_FRAME; + g_streamInfos.push_back(streamInfo1); + g_streamInfos.push_back(streamInfo2); +} + +void DCameraSourceInputTest::SetCaptureInfos() +{ + std::shared_ptr captureInfo1 = std::make_shared(); + captureInfo1->streamIds_.push_back(1); + captureInfo1->width_ = TEST_WIDTH; + captureInfo1->height_ = TEST_HEIGTH; + captureInfo1->stride_ = 1; + captureInfo1->format_ = 1; + captureInfo1->dataspace_ = 1; + captureInfo1->encodeType_ = ENCODE_TYPE_H265; + captureInfo1->type_ = CONTINUOUS_FRAME; + + std::shared_ptr captureInfo2 = std::make_shared(); + captureInfo2->streamIds_.push_back(1); + captureInfo2->width_ = TEST_WIDTH; + captureInfo2->height_ = TEST_HEIGTH; + captureInfo2->stride_ = 1; + captureInfo2->format_ = 1; + captureInfo2->dataspace_ = 1; + captureInfo2->encodeType_ = ENCODE_TYPE_H265; + captureInfo2->type_ = CONTINUOUS_FRAME; + g_captureInfos.push_back(captureInfo1); + g_captureInfos.push_back(captureInfo2); + + std::shared_ptr camSettings1 = std::make_shared(); + camSettings1->type_ = UPDATE_METADATA; + camSettings1->value_ = "SettingValue"; + + std::shared_ptr camSettings2 = std::make_shared(); + camSettings2->type_ = ENABLE_METADATA; + camSettings2->value_ = "SettingValue"; + g_cameraSettings.push_back(camSettings1); + g_cameraSettings.push_back(camSettings2); + + g_streamIds.push_back(1); + g_streamIds.push_back(TEST_STREAMID); +} + +void DCameraSourceInputTest::TearDownTestCase(void) +{ +} + +void DCameraSourceInputTest::SetUp(void) +{ + std::shared_ptr eventBus = std::make_shared("TestInputHandler"); + testInput_ = std::make_shared(TEST_DEVICE_ID, TEST_CAMERA_DH_ID_0, eventBus); +} + +void DCameraSourceInputTest::TearDown(void) +{ + testInput_ = nullptr; +} + +/** + * @tc.name: dcamera_source_input_test_001 + * @tc.desc: Verify source inptut Init. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(DCameraSourceInputTest, dcamera_source_input_test_001, TestSize.Level1) +{ + EXPECT_EQ(false, testInput_ == nullptr); + + int32_t rc = testInput_->Init(); + EXPECT_EQ(rc, DCAMERA_OK); +} + +/** + * @tc.name: dcamera_source_input_test_002 + * @tc.desc: Verify source inptut UnInit. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(DCameraSourceInputTest, dcamera_source_input_test_002, TestSize.Level1) +{ + EXPECT_EQ(false, testInput_ == nullptr); + + int32_t rc = testInput_->Init(); + EXPECT_EQ(rc, DCAMERA_OK); + + rc = testInput_->UnInit(); + EXPECT_EQ(rc, DCAMERA_OK); +} + +/** + * @tc.name: dcamera_source_input_test_003 + * @tc.desc: Verify source inptut ConfigStreams. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(DCameraSourceInputTest, dcamera_source_input_test_003, TestSize.Level1) +{ + EXPECT_EQ(false, testInput_ == nullptr); + + int32_t rc = testInput_->Init(); + EXPECT_EQ(rc, DCAMERA_OK); + + rc = testInput_->ConfigStreams(g_streamInfos); + EXPECT_EQ(rc, DCAMERA_OK); + + rc = testInput_->UnInit(); + EXPECT_EQ(rc, DCAMERA_OK); +} + +/** + * @tc.name: dcamera_source_input_test_004 + * @tc.desc: Verify source inptut ReleaseStreams. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(DCameraSourceInputTest, dcamera_source_input_test_004, TestSize.Level1) +{ + EXPECT_EQ(false, testInput_ == nullptr); + + int32_t rc = testInput_->Init(); + EXPECT_EQ(rc, DCAMERA_OK); + + rc = testInput_->ConfigStreams(g_streamInfos); + EXPECT_EQ(rc, DCAMERA_OK); + + bool isAllRelease = true; + rc = testInput_->ReleaseStreams(g_streamIds, isAllRelease); + EXPECT_EQ(rc, DCAMERA_OK); + + rc = testInput_->UnInit(); + EXPECT_EQ(rc, DCAMERA_OK); +} + +/** + * @tc.name: dcamera_source_input_test_005 + * @tc.desc: Verify source inptut ReleaseAllStreams. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(DCameraSourceInputTest, dcamera_source_input_test_005, TestSize.Level1) +{ + EXPECT_EQ(false, testInput_ == nullptr); + + int32_t rc = testInput_->Init(); + EXPECT_EQ(rc, DCAMERA_OK); + + rc = testInput_->ConfigStreams(g_streamInfos); + EXPECT_EQ(rc, DCAMERA_OK); + + rc = testInput_->ReleaseAllStreams(); + EXPECT_EQ(rc, DCAMERA_OK); + + rc = testInput_->UnInit(); + EXPECT_EQ(rc, DCAMERA_OK); +} + +/** + * @tc.name: dcamera_source_input_test_006 + * @tc.desc: Verify source inptut StartCapture. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(DCameraSourceInputTest, dcamera_source_input_test_006, TestSize.Level1) +{ + EXPECT_EQ(false, testInput_ == nullptr); + + int32_t rc = testInput_->Init(); + EXPECT_EQ(rc, DCAMERA_OK); + + rc = testInput_->StartCapture(g_captureInfos); + EXPECT_EQ(rc, DCAMERA_OK); + + rc = testInput_->UnInit(); + EXPECT_EQ(rc, DCAMERA_OK); +} + +/** + * @tc.name: dcamera_source_input_test_007 + * @tc.desc: Verify source inptut StopCapture. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(DCameraSourceInputTest, dcamera_source_input_test_007, TestSize.Level1) +{ + EXPECT_EQ(false, testInput_ == nullptr); + + int32_t rc = testInput_->Init(); + EXPECT_EQ(rc, DCAMERA_OK); + + rc = testInput_->StartCapture(g_captureInfos); + EXPECT_EQ(rc, DCAMERA_OK); + + bool isAllStop = true; + rc = testInput_->StopCapture(g_streamIds, isAllStop); + EXPECT_EQ(rc, DCAMERA_OK); + + rc = testInput_->UnInit(); + EXPECT_EQ(rc, DCAMERA_OK); +} + +/** + * @tc.name: dcamera_source_input_test_008 + * @tc.desc: Verify source inptut StopAllCapture. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(DCameraSourceInputTest, dcamera_source_input_test_008, TestSize.Level1) +{ + EXPECT_EQ(false, testInput_ == nullptr); + + int32_t rc = testInput_->Init(); + EXPECT_EQ(rc, DCAMERA_OK); + + rc = testInput_->StartCapture(g_captureInfos); + EXPECT_EQ(rc, DCAMERA_OK); + + rc = testInput_->StopAllCapture(); + EXPECT_EQ(rc, DCAMERA_OK); + + rc = testInput_->UnInit(); + EXPECT_EQ(rc, DCAMERA_OK); +} + +/** + * @tc.name: dcamera_source_input_test_009 + * @tc.desc: Verify source inptut OpenChannel. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(DCameraSourceInputTest, dcamera_source_input_test_009, TestSize.Level1) +{ + EXPECT_EQ(false, testInput_ == nullptr); + + int32_t rc = testInput_->Init(); + EXPECT_EQ(rc, DCAMERA_OK); + + rc = testInput_->OpenChannel(g_camIndexs); + EXPECT_EQ(rc, DCAMERA_MEMORY_OPT_ERROR); + + rc = testInput_->UnInit(); + EXPECT_EQ(rc, DCAMERA_OK); +} + +/** + * @tc.name: dcamera_source_input_test_010 + * @tc.desc: Verify source inptut CloseChannel. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(DCameraSourceInputTest, dcamera_source_input_test_010, TestSize.Level1) +{ + EXPECT_EQ(false, testInput_ == nullptr); + + int32_t rc = testInput_->Init(); + EXPECT_EQ(rc, DCAMERA_OK); + + rc = testInput_->OpenChannel(g_camIndexs); + EXPECT_EQ(rc, DCAMERA_MEMORY_OPT_ERROR); + + rc = testInput_->CloseChannel(); + EXPECT_EQ(rc, DCAMERA_OK); + + rc = testInput_->UnInit(); + EXPECT_EQ(rc, DCAMERA_OK); +} + +/** + * @tc.name: dcamera_source_input_test_011 + * @tc.desc: Verify source inptut UpdateSettings. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(DCameraSourceInputTest, dcamera_source_input_test_011, TestSize.Level1) +{ + EXPECT_EQ(false, testInput_ == nullptr); + + int32_t rc = testInput_->Init(); + EXPECT_EQ(rc, DCAMERA_OK); + + rc = testInput_->UpdateSettings(g_cameraSettings); + EXPECT_EQ(rc, DCAMERA_OK); + + rc = testInput_->UnInit(); + EXPECT_EQ(rc, DCAMERA_OK); +} +} // namespace DistributedHardware +} // namespace OHOS