diff --git a/services/cameraservice/sinkservice/test/unittest/common/distributedcamera/BUILD.gn b/services/cameraservice/sinkservice/test/unittest/common/distributedcamera/BUILD.gn index 5a4a12cd1ccfe99340d0647f11213a21ee24c8c2..66d95bd138d3dd359bd534c832fbc1bed1e841b2 100644 --- a/services/cameraservice/sinkservice/test/unittest/common/distributedcamera/BUILD.gn +++ b/services/cameraservice/sinkservice/test/unittest/common/distributedcamera/BUILD.gn @@ -52,6 +52,7 @@ ohos_unittest("DistributedCameraSinkServiceTest") { sources = [ "dcamera_sink_hidumper_test.cpp", "distributed_camera_sink_service_test.cpp", + "distributed_camera_sink_stub_test.cpp", ] configs = [ ":module_private_config" ] diff --git a/services/cameraservice/sinkservice/test/unittest/common/distributedcamera/distributed_camera_sink_stub_test.cpp b/services/cameraservice/sinkservice/test/unittest/common/distributedcamera/distributed_camera_sink_stub_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6446e9353ed6a54f62e1f25cdcc628f8efd17cb1 --- /dev/null +++ b/services/cameraservice/sinkservice/test/unittest/common/distributedcamera/distributed_camera_sink_stub_test.cpp @@ -0,0 +1,202 @@ +/* + * 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 "distributed_camera_sink_proxy.h" +#include "distributed_camera_sink_stub.h" +#include "distributed_hardware_log.h" +#include "mock_distributed_camera_sink_stub.h" + +using namespace testing::ext; + +namespace OHOS { +namespace DistributedHardware { +class DcameraSinkStubTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); +}; + +void DcameraSinkStubTest::SetUpTestCase(void) +{ + DHLOGI("DcameraSinkStubTest::SetUpTestCase"); +} + +void DcameraSinkStubTest::TearDownTestCase(void) +{ + DHLOGI("DcameraSinkStubTest::TearDownTestCase"); +} + +void DcameraSinkStubTest::SetUp(void) +{ + DHLOGI("DcameraSinkStubTest::SetUp"); +} + +void DcameraSinkStubTest::TearDown(void) +{ + DHLOGI("DcameraSinkStubTest::TearDown"); +} + +/** + * @tc.name: dcamera_sink_stub_test_001 + * @tc.desc: Verify the InitSink function. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(DcameraSinkStubTest, dcamera_sink_stub_test_001, TestSize.Level1) +{ + DHLOGI("DcameraSinkStubTest::dcamera_sink_stub_test_001"); + sptr sinkStubPtr = new MockDistributedCameraSinkStub(); + DistributedCameraSinkProxy sinkProxy(sinkStubPtr); + std::string params = "params000"; + int32_t ret = sinkProxy.InitSink(params); + EXPECT_EQ(DCAMERA_OK, ret); +} + +/** + * @tc.name: dcamera_sink_stub_test_002 + * @tc.desc: Verify the ReleaseSink function. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(DcameraSinkStubTest, dcamera_sink_stub_test_002, TestSize.Level1) +{ + DHLOGI("DcameraSinkStubTest::dcamera_sink_stub_test_002"); + sptr sinkStubPtr = new MockDistributedCameraSinkStub(); + DistributedCameraSinkProxy sinkProxy(sinkStubPtr); + int32_t ret = sinkProxy.ReleaseSink(); + EXPECT_EQ(DCAMERA_OK, ret); +} + +/** + * @tc.name: dcamera_sink_stub_test_003 + * @tc.desc: Verify the SubscribeLocalHardware function. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(DcameraSinkStubTest, dcamera_sink_stub_test_003, TestSize.Level1) +{ + DHLOGI("DcameraSinkStubTest::dcamera_sink_stub_test_003"); + sptr sinkStubPtr = new MockDistributedCameraSinkStub(); + DistributedCameraSinkProxy sinkProxy(sinkStubPtr); + std::string dhId = "dhId000"; + std::string params = "params000"; + int32_t ret = sinkProxy.SubscribeLocalHardware(dhId, params); + EXPECT_EQ(DCAMERA_OK, ret); +} + +/** + * @tc.name: dcamera_sink_stub_test_004 + * @tc.desc: Verify the UnsubscribeLocalHardware function. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(DcameraSinkStubTest, dcamera_sink_stub_test_004, TestSize.Level1) +{ + DHLOGI("DcameraSinkStubTest::dcamera_sink_stub_test_004"); + sptr sinkStubPtr = new MockDistributedCameraSinkStub(); + DistributedCameraSinkProxy sinkProxy(sinkStubPtr); + std::string dhId = "dhId000"; + int32_t ret = sinkProxy.UnsubscribeLocalHardware(dhId); + EXPECT_EQ(DCAMERA_OK, ret); +} + +/** + * @tc.name: dcamera_sink_stub_test_005 + * @tc.desc: Verify the StopCapture function. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(DcameraSinkStubTest, dcamera_sink_stub_test_005, TestSize.Level1) +{ + DHLOGI("DcameraSinkStubTest::dcamera_sink_stub_test_005"); + sptr sinkStubPtr = new MockDistributedCameraSinkStub(); + DistributedCameraSinkProxy sinkProxy(sinkStubPtr); + std::string dhId = "dhId000"; + int32_t ret = sinkProxy.StopCapture(dhId); + EXPECT_EQ(DCAMERA_OK, ret); +} + +/** + * @tc.name: dcamera_sink_stub_test_006 + * @tc.desc: Verify the ChannelNeg function. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(DcameraSinkStubTest, dcamera_sink_stub_test_006, TestSize.Level1) +{ + DHLOGI("DcameraSinkStubTest::dcamera_sink_stub_test_006"); + sptr sinkStubPtr = new MockDistributedCameraSinkStub(); + DistributedCameraSinkProxy sinkProxy(sinkStubPtr); + std::string dhId = "dhId000"; + std::string channelInfo = "channelInfo000"; + int32_t ret = sinkProxy.ChannelNeg(dhId, channelInfo); + EXPECT_EQ(DCAMERA_OK, ret); +} + +/** + * @tc.name: dcamera_sink_stub_test_007 + * @tc.desc: Verify the GetCameraInfo function. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(DcameraSinkStubTest, dcamera_sink_stub_test_007, TestSize.Level1) +{ + DHLOGI("DcameraSinkStubTest::dcamera_sink_stub_test_007"); + sptr sinkStubPtr = new MockDistributedCameraSinkStub(); + DistributedCameraSinkProxy sinkProxy(sinkStubPtr); + std::string dhId = "dhId000"; + std::string cameraInfo = "cameraInfo000"; + int32_t ret = sinkProxy.GetCameraInfo(dhId, cameraInfo); + EXPECT_EQ(DCAMERA_OK, ret); +} + +/** + * @tc.name: dcamera_sink_stub_test_008 + * @tc.desc: Verify the OpenChannel function. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(DcameraSinkStubTest, dcamera_sink_stub_test_008, TestSize.Level1) +{ + DHLOGI("DcameraSinkStubTest::dcamera_sink_stub_test_008"); + sptr sinkStubPtr = new MockDistributedCameraSinkStub(); + DistributedCameraSinkProxy sinkProxy(sinkStubPtr); + std::string dhId = "dhId000"; + std::string openInfo = "openInfo000"; + int32_t ret = sinkProxy.OpenChannel(dhId, openInfo); + EXPECT_EQ(DCAMERA_OK, ret); +} + +/** + * @tc.name: dcamera_sink_stub_test_009 + * @tc.desc: Verify the CloseChannel function. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(DcameraSinkStubTest, dcamera_sink_stub_test_009, TestSize.Level1) +{ + DHLOGI("DcameraSinkStubTest::dcamera_sink_stub_test_009"); + sptr sinkStubPtr = new MockDistributedCameraSinkStub(); + DistributedCameraSinkProxy sinkProxy(sinkStubPtr); + std::string dhId = "dhId000"; + int32_t ret = sinkProxy.CloseChannel(dhId); + EXPECT_EQ(DCAMERA_OK, ret); +} +} // namespace DistributedHardware +} // namespace OHOS \ No newline at end of file diff --git a/services/cameraservice/sinkservice/test/unittest/common/distributedcamera/mock_distributed_camera_sink_stub.h b/services/cameraservice/sinkservice/test/unittest/common/distributedcamera/mock_distributed_camera_sink_stub.h new file mode 100644 index 0000000000000000000000000000000000000000..c19b785665912bab3fd792d21a3816bc342348e9 --- /dev/null +++ b/services/cameraservice/sinkservice/test/unittest/common/distributedcamera/mock_distributed_camera_sink_stub.h @@ -0,0 +1,85 @@ +/* + * 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 "distributed_camera_errno.h" +#include "distributed_camera_sink_stub.h" + +namespace OHOS { +namespace DistributedHardware { +class MockDistributedCameraSinkStub : public DistributedCameraSinkStub { +public: + MockDistributedCameraSinkStub() = default; + virtual ~MockDistributedCameraSinkStub() = default; + int32_t InitSink(const std::string ¶ms) + { + (void)params; + return DCAMERA_OK; + } + + int32_t ReleaseSink() + { + return DCAMERA_OK; + } + + int32_t SubscribeLocalHardware(const std::string &dhId, const std::string ¶m) + { + (void)dhId; + (void)param; + return DCAMERA_OK; + } + + int32_t UnsubscribeLocalHardware(const std::string &dhId) + { + (void)dhId; + return DCAMERA_OK; + } + + int32_t StopCapture(const std::string &dhId) + { + (void)dhId; + return DCAMERA_OK; + } + + int32_t ChannelNeg(const std::string &dhId, std::string& channelInfo) + { + (void)dhId; + (void)channelInfo; + return DCAMERA_OK; + } + + int32_t GetCameraInfo(const std::string &dhId, std::string& cameraInfo) + { + (void)dhId; + (void)cameraInfo; + return DCAMERA_OK; + } + + int32_t OpenChannel(const std::string &dhId, std::string& openInfo) + { + (void)dhId; + (void)openInfo; + return DCAMERA_OK; + } + + int32_t CloseChannel(const std::string &dhId) + { + (void)dhId; + return DCAMERA_OK; + } +}; + + +} // namespace DistributedHardware +} // namespace OHOS \ No newline at end of file diff --git a/services/cameraservice/sourceservice/test/unittest/common/distributedcamera/BUILD.gn b/services/cameraservice/sourceservice/test/unittest/common/distributedcamera/BUILD.gn index 608a775afde7cc50f72e845a1dafa511064ab01f..2951575b367e496e77bb73f2dbda3b64a96cee5e 100644 --- a/services/cameraservice/sourceservice/test/unittest/common/distributedcamera/BUILD.gn +++ b/services/cameraservice/sourceservice/test/unittest/common/distributedcamera/BUILD.gn @@ -60,6 +60,7 @@ ohos_unittest("DCameraSourceTest") { "dcamera_source_callback proxy_test.cpp", "dcamera_source_hidumper_test.cpp", "distributed_camera_source_service_test.cpp", + "distributed_camera_source_stub_test.cpp", ] configs = [ ":module_private_config" ] diff --git a/services/cameraservice/sourceservice/test/unittest/common/distributedcamera/distributed_camera_source_stub_test.cpp b/services/cameraservice/sourceservice/test/unittest/common/distributedcamera/distributed_camera_source_stub_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c5e0ef328317dca76a1aaa1e3f10178d05a576b2 --- /dev/null +++ b/services/cameraservice/sourceservice/test/unittest/common/distributedcamera/distributed_camera_source_stub_test.cpp @@ -0,0 +1,145 @@ +/* + * 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_callback.h" +#include "distributed_camera_source_proxy.h" +#include "distributed_camera_source_stub.h" +#include "distributed_hardware_log.h" +#include "mock_distributed_camera_source_stub.h" + +using namespace testing::ext; + +namespace OHOS { +namespace DistributedHardware { +class DcameraSourceStubTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); +}; + +void DcameraSourceStubTest::SetUpTestCase(void) +{ + DHLOGI("DcameraSourceStubTest::SetUpTestCase"); +} + +void DcameraSourceStubTest::TearDownTestCase(void) +{ + DHLOGI("DcameraSourceStubTest::TearDownTestCase"); +} + +void DcameraSourceStubTest::SetUp(void) +{ + DHLOGI("DcameraSourceStubTest::SetUp"); +} + +void DcameraSourceStubTest::TearDown(void) +{ + DHLOGI("DcameraSourceStubTest::TearDown"); +} + +/** + * @tc.name: dcamera_source_stub_test_001 + * @tc.desc: Verify the InitSource function. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(DcameraSourceStubTest, dcamera_source_stub_test_001, TestSize.Level1) +{ + DHLOGI("DcameraSourceStubTest::dcamera_source_stub_test_001"); + sptr sourceStubPtr = new MockDistributedCameraSourceStub(); + DistributedCameraSourceProxy sourceProxy(sourceStubPtr); + std::string params = "params000"; + sptr callback = new DCameraSourceCallback(); + int32_t ret = sourceProxy.InitSource(params, callback); + EXPECT_EQ(DCAMERA_OK, ret); +} + +/** + * @tc.name: dcamera_source_stub_test_002 + * @tc.desc: Verify the ReleaseSource function. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(DcameraSourceStubTest, dcamera_source_stub_test_002, TestSize.Level1) +{ + DHLOGI("DcameraSourceStubTest::dcamera_source_stub_test_002"); + sptr sourceStubPtr = new MockDistributedCameraSourceStub(); + DistributedCameraSourceProxy sourceProxy(sourceStubPtr); + int32_t ret = sourceProxy.ReleaseSource(); + EXPECT_EQ(DCAMERA_OK, ret); +} + +/** + * @tc.name: dcamera_source_stub_test_003 + * @tc.desc: Verify the RegisterDistributedHardware function. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(DcameraSourceStubTest, dcamera_source_stub_test_003, TestSize.Level1) +{ + DHLOGI("DcameraSourceStubTest::dcamera_source_stub_test_003"); + sptr sourceStubPtr = new MockDistributedCameraSourceStub(); + DistributedCameraSourceProxy sourceProxy(sourceStubPtr); + std::string devId = "devId000"; + std::string dhId = "dhId000"; + std::string reqId = "reqId000"; + EnableParam param; + param.version = "1"; + param.attrs = "attrs"; + int32_t ret = sourceProxy.RegisterDistributedHardware(devId, dhId, reqId, param); + EXPECT_EQ(DCAMERA_OK, ret); +} + +/** + * @tc.name: dcamera_source_stub_test_004 + * @tc.desc: Verify the UnregisterDistributedHardware function. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(DcameraSourceStubTest, dcamera_source_stub_test_004, TestSize.Level1) +{ + DHLOGI("DcameraSourceStubTest::dcamera_source_stub_test_004"); + sptr sourceStubPtr = new MockDistributedCameraSourceStub(); + DistributedCameraSourceProxy sourceProxy(sourceStubPtr); + std::string devId = "devId000"; + std::string dhId = "dhId000"; + std::string reqId = "reqId000"; + int32_t ret = sourceProxy.UnregisterDistributedHardware(devId, dhId, reqId); + EXPECT_EQ(DCAMERA_OK, ret); +} + +/** + * @tc.name: dcamera_source_stub_test_005 + * @tc.desc: Verify the DCameraNotify function. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(DcameraSourceStubTest, dcamera_source_stub_test_005, TestSize.Level1) +{ + DHLOGI("DcameraSourceStubTest::dcamera_source_stub_test_005"); + sptr sourceStubPtr = new MockDistributedCameraSourceStub(); + DistributedCameraSourceProxy sourceProxy(sourceStubPtr); + std::string devId = "devId000"; + std::string dhId = "dhId000"; + std::string events = "events000"; + int32_t ret = sourceProxy.DCameraNotify(devId, dhId, events); + EXPECT_EQ(DCAMERA_OK, ret); +} +} // namespace DistributedHardware +} // namespace OHOS \ No newline at end of file diff --git a/services/cameraservice/sourceservice/test/unittest/common/distributedcamera/mock_distributed_camera_source_stub.h b/services/cameraservice/sourceservice/test/unittest/common/distributedcamera/mock_distributed_camera_source_stub.h new file mode 100644 index 0000000000000000000000000000000000000000..707bf1adef90786dc6f8c08fc14bb5edd63bd68d --- /dev/null +++ b/services/cameraservice/sourceservice/test/unittest/common/distributedcamera/mock_distributed_camera_source_stub.h @@ -0,0 +1,68 @@ +/* + * 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 "distributed_camera_errno.h" +#include "distributed_camera_source_stub.h" + +namespace OHOS { +namespace DistributedHardware { +class MockDistributedCameraSourceStub : public DistributedCameraSourceStub { +public: + MockDistributedCameraSourceStub() = default; + virtual ~MockDistributedCameraSourceStub() = default; + int32_t InitSource(const std::string& params, const sptr& callback) + { + (void)params; + (void)callback; + return DCAMERA_OK; + } + + int32_t ReleaseSource() + { + return DCAMERA_OK; + } + + int32_t RegisterDistributedHardware(const std::string& devId, const std::string& dhId, + const std::string& reqId, const EnableParam& param) + { + (void)devId; + (void)dhId; + (void)reqId; + (void)param; + return DCAMERA_OK; + } + + int32_t UnregisterDistributedHardware(const std::string& devId, const std::string& dhId, + const std::string& reqId) + { + (void)devId; + (void)dhId; + (void)reqId; + return DCAMERA_OK; + } + + int32_t DCameraNotify(const std::string& devId, const std::string& dhId, + std::string& events) + { + (void)devId; + (void)dhId; + (void)events; + return DCAMERA_OK; + } +}; + + +} // namespace DistributedHardware +} // namespace OHOS \ No newline at end of file