From a62a38095d743cdaf5ef881b53668f01da48b0aa Mon Sep 17 00:00:00 2001 From: chen0088 Date: Tue, 20 Dec 2022 17:55:55 +0800 Subject: [PATCH] fix:add unittest Signed-off-by: chen0088 --- .../dcamera_sink_hidumper_test.cpp | 17 +++ .../common/distributedcameramgr/BUILD.gn | 1 + .../dcamera_sink_controller_test.cpp | 137 ++++++++++++++++++ .../dcamera_sink_service_ipc_test.cpp | 97 +++++++++++++ .../mock_camera_channel.h | 7 + .../mock_camera_operator.h | 12 ++ .../mock_dcamera_sink_output.h | 10 ++ .../dcamera_channel_sink_impl_test.cpp | 1 + 8 files changed, 282 insertions(+) create mode 100644 services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/dcamera_sink_service_ipc_test.cpp diff --git a/services/cameraservice/sinkservice/test/unittest/common/distributedcamera/dcamera_sink_hidumper_test.cpp b/services/cameraservice/sinkservice/test/unittest/common/distributedcamera/dcamera_sink_hidumper_test.cpp index a278b824..77ab973b 100644 --- a/services/cameraservice/sinkservice/test/unittest/common/distributedcamera/dcamera_sink_hidumper_test.cpp +++ b/services/cameraservice/sinkservice/test/unittest/common/distributedcamera/dcamera_sink_hidumper_test.cpp @@ -151,5 +151,22 @@ HWTEST_F(DcameraSinkHidumperTest, dcamera_sink_hidumper_test_006, TestSize.Level bool ret = DcameraSinkHidumper::GetInstance().Dump(args, result); EXPECT_EQ(true, ret); } + +/** + * @tc.name: dcamera_sink_hidumper_test_007 + * @tc.desc: Verify the Dump function. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(DcameraSinkHidumperTest, dcamera_sink_hidumper_test_007, TestSize.Level1) +{ + DHLOGI("DcameraSinkHidumperTest::dcamera_sink_hidumper_test_007"); + std::vector args; + std::string str1 = "-help"; + args.push_back(str1); + std::string result; + bool ret = DcameraSinkHidumper::GetInstance().Dump(args, result); + EXPECT_EQ(true, ret); +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/BUILD.gn b/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/BUILD.gn index 8b0bb2ef..cf58475f 100644 --- a/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/BUILD.gn +++ b/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/BUILD.gn @@ -63,6 +63,7 @@ ohos_unittest("DCameraSinkMgrTest") { "dcamera_sink_data_process_test.cpp", "dcamera_sink_dev_test.cpp", "dcamera_sink_output_test.cpp", + "dcamera_sink_service_ipc_test.cpp", ] configs = [ ":module_private_config" ] diff --git a/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/dcamera_sink_controller_test.cpp b/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/dcamera_sink_controller_test.cpp index 47498f2c..7f0681cb 100644 --- a/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/dcamera_sink_controller_test.cpp +++ b/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/dcamera_sink_controller_test.cpp @@ -38,6 +38,9 @@ using namespace testing::ext; namespace OHOS { namespace DistributedHardware { +std::string g_channelStr = ""; +std::string g_outputStr = ""; +std::string g_operatorStr = ""; class DCameraSinkControllerTest : public testing::Test { public: static void SetUpTestCase(void); @@ -212,6 +215,7 @@ HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_005, TestSize.L DCameraMetadataSettingCmd cmdMetadata; cmdMetadata.Unmarshal(TEST_METADATA_SETTING_CMD_JSON); ret = controller_->UpdateSettings(cmdMetadata.value_); + controller_->OnMetadataResult(cmdMetadata.value_); EXPECT_EQ(DCAMERA_OK, ret); } @@ -361,5 +365,138 @@ HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_014, TestSize.L int32_t ret = controller_->CloseChannel(); EXPECT_EQ(DCAMERA_OK, ret); } + +/** + * @tc.name: dcamera_sink_controller_test_015 + * @tc.desc: Verify the UpdateSettings function. + * @tc.type: FUNC + * @tc.require: AR000GK6N1 + */ +HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_015, TestSize.Level1) +{ + DCameraCaptureInfoCmd cmd; + cmd.Unmarshal(TEST_CAPTURE_INFO_CMD_JSON); + int32_t ret = controller_->StartCapture(cmd.value_); + EXPECT_EQ(DCAMERA_OK, ret); + + DCameraMetadataSettingCmd cmdMetadata; + cmdMetadata.Unmarshal(TEST_METADATA_SETTING_CMD_JSON); + g_operatorStr = "test015"; + ret = controller_->UpdateSettings(cmdMetadata.value_); + EXPECT_EQ(DCAMERA_BAD_VALUE, ret); +} + +/** + * @tc.name: dcamera_sink_controller_test_016 + * @tc.desc: Verify the OpenChannel function. + * @tc.type: FUNC + * @tc.require: AR000GK6N1 + */ +HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_016, TestSize.Level1) +{ + DCameraOpenInfoCmd cmd; + cmd.Unmarshal(TEST_OPEN_INFO_CMD_JSON); + g_channelStr = "test016"; + int32_t ret = controller_->OpenChannel(cmd.value_); + EXPECT_EQ(DCAMERA_BAD_VALUE, ret); +} + +/** + * @tc.name: dcamera_sink_controller_test_017 + * @tc.desc: Verify the CloseChannel function. + * @tc.type: FUNC + * @tc.require: AR000GK6N1 + */ +HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_017, TestSize.Level1) +{ + g_channelStr = "test017"; + int32_t ret = controller_->CloseChannel(); + EXPECT_EQ(DCAMERA_OK, ret); +} + +/** + * @tc.name: dcamera_sink_controller_test_018 + * @tc.desc: Verify the CloseChannel function. + * @tc.type: FUNC + * @tc.require: AR000GK6N1 + */ +HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_018, TestSize.Level1) +{ + g_outputStr = "test018"; + int32_t ret = controller_->CloseChannel(); + EXPECT_EQ(DCAMERA_OK, ret); +} + +/** + * @tc.name: dcamera_sink_controller_test_019 + * @tc.desc: Verify the Init and UnInit function. + * @tc.type: FUNC + * @tc.require: AR000GK6MV + */ +HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_019, TestSize.Level1) +{ + g_outputStr = "test019"; + int32_t ret = controller_->UnInit(); + EXPECT_EQ(DCAMERA_OK, ret); +} + +/** + * @tc.name: dcamera_sink_controller_test_020 + * @tc.desc: Verify the Init and UnInit function. + * @tc.type: FUNC + * @tc.require: AR000GK6MV + */ +HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_020, TestSize.Level1) +{ + g_operatorStr = "test020"; + int32_t ret = controller_->UnInit(); + EXPECT_EQ(DCAMERA_OK, ret); +} + +/** + * @tc.name: dcamera_sink_controller_test_021 + * @tc.desc: Verify the StartCapture function. + * @tc.type: FUNC + * @tc.require: AR000GK6MU + */ +HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_021, TestSize.Level1) +{ + DCameraCaptureInfoCmd cmd; + cmd.Unmarshal(TEST_CAPTURE_INFO_CMD_JSON); + g_outputStr = "test021"; + int32_t ret = controller_->StartCapture(cmd.value_); + EXPECT_EQ(DCAMERA_BAD_VALUE, ret); +} + +/** + * @tc.name: dcamera_sink_controller_test_022 + * @tc.desc: Verify the StartCapture function. + * @tc.type: FUNC + * @tc.require: AR000GK6MU + */ +HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_022, TestSize.Level1) +{ + DCameraCaptureInfoCmd cmd; + cmd.Unmarshal(TEST_CAPTURE_INFO_CMD_JSON); + g_outputStr = ""; + g_operatorStr = "test022"; + int32_t ret = controller_->StartCapture(cmd.value_); + EXPECT_EQ(DCAMERA_ALLOC_ERROR, ret); +} + +/** + * @tc.name: dcamera_sink_controller_test_023 + * @tc.desc: Verify the StartCapture function. + * @tc.type: FUNC + * @tc.require: AR000GK6MU + */ +HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_023, TestSize.Level1) +{ + DCameraCaptureInfoCmd cmd; + cmd.Unmarshal(TEST_CAPTURE_INFO_CMD_JSON); + g_operatorStr = "test023"; + int32_t ret = controller_->StartCapture(cmd.value_); + EXPECT_EQ(DCAMERA_DEVICE_BUSY, ret); +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/dcamera_sink_service_ipc_test.cpp b/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/dcamera_sink_service_ipc_test.cpp new file mode 100644 index 00000000..c40df48c --- /dev/null +++ b/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/dcamera_sink_service_ipc_test.cpp @@ -0,0 +1,97 @@ +/* + * 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 + +#define private public +#include "dcamera_sink_service_ipc.h" +#undef private +#include "distributed_hardware_log.h" + +using namespace testing::ext; + +namespace OHOS { +namespace DistributedHardware { +class DCameraSinkServiceIpcTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); +}; + +void DCameraSinkServiceIpcTest::SetUpTestCase(void) +{ + DHLOGI("DCameraSinkServiceIpcTest::SetUpTestCase"); +} + +void DCameraSinkServiceIpcTest::TearDownTestCase(void) +{ + DHLOGI("DCameraSinkServiceIpcTest::TearDownTestCase"); +} + +void DCameraSinkServiceIpcTest::SetUp(void) +{ + DHLOGI("DCameraSinkServiceIpcTest::SetUp"); +} + +void DCameraSinkServiceIpcTest::TearDown(void) +{ + DHLOGI("DCameraSinkServiceIpcTest::TearDown"); +} + +/** + * @tc.name: dcamera_sink_service_ipc_test_001 + * @tc.desc: Verify the dcamera sink service ipc function. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(DCameraSinkServiceIpcTest, dcamera_sink_service_ipc_test_001, TestSize.Level1) +{ + DHLOGI("DCameraSinkServiceIpcTest::dcamera_sink_service_ipc_test_001"); + DCameraSinkServiceIpc::GetInstance().UnInit(); + DCameraSinkServiceIpc::GetInstance().Init(); + DCameraSinkServiceIpc::GetInstance().UnInit(); + DCameraSinkServiceIpc::GetInstance().isInit_ = true; + DCameraSinkServiceIpc::GetInstance().Init(); + DCameraSinkServiceIpc::GetInstance().UnInit(); + EXPECT_EQ(false, DCameraSinkServiceIpc::GetInstance().isInit_); +} + +/** + * @tc.name: dcamera_sink_service_ipc_test_002 + * @tc.desc: Verify the dcamera sink service ipc function. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(DCameraSinkServiceIpcTest, dcamera_sink_service_ipc_test_002, TestSize.Level1) +{ + DHLOGI("DCameraSinkServiceIpcTest::dcamera_sink_service_ipc_test_002"); + std::string devId = ""; + sptr sourceSA = DCameraSinkServiceIpc::GetInstance().GetSourceRemoteCamSrv(devId); + EXPECT_EQ(nullptr, sourceSA); + + devId = "devId000"; + sourceSA = DCameraSinkServiceIpc::GetInstance().GetSourceRemoteCamSrv(devId); + EXPECT_EQ(nullptr, sourceSA); + + DCameraSinkServiceIpc::GetInstance().DeleteSourceRemoteCamSrv(devId); + DCameraSinkServiceIpc::GetInstance().ClearSourceRemoteCamSrv(); + wptr remote; + DCameraSinkServiceIpc::GetInstance().OnSourceRemoteCamSrvDied(remote); + EXPECT_EQ(nullptr, sourceSA); +} +} // namespace DistributedHardware +} // namespace OHOS \ No newline at end of file diff --git a/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/mock_camera_channel.h b/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/mock_camera_channel.h index 412eabff..d85e77be 100644 --- a/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/mock_camera_channel.h +++ b/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/mock_camera_channel.h @@ -21,6 +21,7 @@ namespace OHOS { namespace DistributedHardware { +extern std::string g_channelStr; class MockCameraChannel : public ICameraChannel { public: explicit MockCameraChannel() @@ -44,11 +45,17 @@ public: int32_t CreateSession(std::vector& camIndexs, std::string sessionFlag, DCameraSessionMode sessionMode, std::shared_ptr& listener) { + if (g_channelStr == "test016") { + return DCAMERA_BAD_VALUE; + } return DCAMERA_OK; } int32_t ReleaseSession() { + if (g_channelStr == "test017") { + return DCAMERA_BAD_VALUE; + } return DCAMERA_OK; } diff --git a/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/mock_camera_operator.h b/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/mock_camera_operator.h index 6627eb8d..aa1ea369 100644 --- a/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/mock_camera_operator.h +++ b/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/mock_camera_operator.h @@ -21,6 +21,7 @@ namespace OHOS { namespace DistributedHardware { +extern std::string g_operatorStr; class MockCameraOperator : public ICameraOperator { public: explicit MockCameraOperator() @@ -38,11 +39,17 @@ public: int32_t UnInit() { + if (g_operatorStr == "test020") { + return DCAMERA_BAD_VALUE; + } return DCAMERA_OK; } int32_t UpdateSettings(std::vector>& settings) { + if (g_operatorStr == "test015") { + return DCAMERA_BAD_VALUE; + } return DCAMERA_OK; } @@ -59,6 +66,11 @@ public: int32_t StartCapture(std::vector>& captureInfos, sptr& surface) { + if (g_operatorStr == "test022") { + return DCAMERA_ALLOC_ERROR; + } else if (g_operatorStr == "test023") { + return DCAMERA_DEVICE_BUSY; + } return DCAMERA_OK; } diff --git a/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/mock_dcamera_sink_output.h b/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/mock_dcamera_sink_output.h index 1fb1af63..b4ea4a44 100644 --- a/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/mock_dcamera_sink_output.h +++ b/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/mock_dcamera_sink_output.h @@ -22,6 +22,7 @@ namespace OHOS { namespace DistributedHardware { +extern std::string g_outputStr; class MockDCameraSinkOutput : public ICameraSinkOutput { public: explicit MockDCameraSinkOutput(const std::string& dhId, const std::shared_ptr& cameraOperator) @@ -38,10 +39,16 @@ public: } int32_t UnInit() { + if (g_outputStr == "test019") { + return DCAMERA_BAD_VALUE; + } return DCAMERA_OK; } int32_t StartCapture(std::vector>& captureInfos) { + if (g_outputStr == "test021") { + return DCAMERA_BAD_VALUE; + } return DCAMERA_OK; } int32_t StopCapture() @@ -54,6 +61,9 @@ public: } int32_t CloseChannel() { + if (g_outputStr == "test018") { + return DCAMERA_BAD_VALUE; + } return DCAMERA_OK; } int32_t GetProperty(const std::string& propertyName, PropertyCarrier& propertyCarrier) diff --git a/services/channel/test/unittest/common/channel/dcamera_channel_sink_impl_test.cpp b/services/channel/test/unittest/common/channel/dcamera_channel_sink_impl_test.cpp index 628a3854..141fc403 100644 --- a/services/channel/test/unittest/common/channel/dcamera_channel_sink_impl_test.cpp +++ b/services/channel/test/unittest/common/channel/dcamera_channel_sink_impl_test.cpp @@ -34,6 +34,7 @@ using namespace testing::ext; namespace OHOS { namespace DistributedHardware { +std::string g_operatorStr = ""; class DCameraChannelSinkImplTest : public testing::Test { public: static void SetUpTestCase(void); -- Gitee