diff --git a/common/test/unittest/common/utils/dcamera_utils_tools_test.cpp b/common/test/unittest/common/utils/dcamera_utils_tools_test.cpp index 98344dcf9b33db70a672535c8a6f28a920ec5e7d..1e516c7c09c05619c3f7ddd3b5b8ac80950061be 100644 --- a/common/test/unittest/common/utils/dcamera_utils_tools_test.cpp +++ b/common/test/unittest/common/utils/dcamera_utils_tools_test.cpp @@ -16,6 +16,8 @@ #include #include +#include +#include #include "accesstoken_kit.h" #include "anonymous_string.h" @@ -187,16 +189,28 @@ HWTEST_F(DcameraUtilsToolsTest, GetAnonyInt32_001, TestSize.Level1) */ HWTEST_F(DcameraUtilsToolsTest, IsOverDumpSize_001, TestSize.Level1) { + std::string DUMP_FILE_NAME = "/data/dump.txt"; + std::ofstream ofs(DUMP_FILE_NAME, std::ios::out); + if (!ofs) { + DHLOGI("open file failed"); + } else { + ofs.close(); + } + std::string fileName = ""; uint8_t *buf = nullptr; size_t size = 0; DumpBufferToFile(fileName, buf, size); EXPECT_EQ(DCAMERA_INIT_ERR, IsUnderDumpMaxSize(fileName)); + fileName = "test"; uint8_t str[] = "test"; size = strlen(reinterpret_cast(str)); DumpBufferToFile(fileName, str, size); - IsUnderDumpMaxSize(fileName); + EXPECT_EQ(DCAMERA_INIT_ERR, IsUnderDumpMaxSize(fileName)); + + DumpBufferToFile(DUMP_FILE_NAME, str, size); + EXPECT_EQ(DCAMERA_OK, IsUnderDumpMaxSize(DUMP_FILE_NAME)); } /** diff --git a/interfaces/inner_kits/native_cpp/test/unittest/common/camera_sink/BUILD.gn b/interfaces/inner_kits/native_cpp/test/unittest/common/camera_sink/BUILD.gn index f34c1b8ea8b7b3eba7c81fe8660a704936a9965a..e4e9402a41423b788eac8d1d566d9db5e8809192 100644 --- a/interfaces/inner_kits/native_cpp/test/unittest/common/camera_sink/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/unittest/common/camera_sink/BUILD.gn @@ -33,6 +33,7 @@ ohos_unittest("DCameraSinkHandlerTest") { module_out_path = module_out_path sources = [ + "callback/dcamera_sink_callback_stub_test.cpp", "callback/dcamera_sink_callback_test.cpp", "dcamera_sink_handler_ipc_test.cpp", "dcamera_sink_handler_test.cpp", diff --git a/interfaces/inner_kits/native_cpp/test/unittest/common/camera_sink/callback/dcamera_sink_callback_stub_test.cpp b/interfaces/inner_kits/native_cpp/test/unittest/common/camera_sink/callback/dcamera_sink_callback_stub_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6a955c8b487ee74af7e314c4850b9226e1713f1e --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/unittest/common/camera_sink/callback/dcamera_sink_callback_stub_test.cpp @@ -0,0 +1,92 @@ +/* + * 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_sink_callback_stub.h" +#include "dcamera_sink_callback.h" + +#include "anonymous_string.h" +#include "distributed_camera_errno.h" +#include "distributed_hardware_log.h" + +using namespace testing::ext; + +namespace OHOS { +namespace DistributedHardware { +class DCameraSinkCallbackStubTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); + + std::shared_ptr sinkCallbackStub_; +}; + +void DCameraSinkCallbackStubTest::SetUpTestCase(void) +{ + DHLOGI("enter"); +} + +void DCameraSinkCallbackStubTest::TearDownTestCase(void) +{ + DHLOGI("enter"); +} + +void DCameraSinkCallbackStubTest::SetUp(void) +{ + DHLOGI("enter"); + sinkCallbackStub_ = std::make_shared(); +} + +void DCameraSinkCallbackStubTest::TearDown(void) +{ + DHLOGI("enter"); + sinkCallbackStub_ = nullptr; +} + +/** + * @tc.name: OnRemoteRequest_001 + * @tc.desc: Verify the OnNotifyRegResult function. + * @tc.type: FUNC + * @tc.require: issue + + int32_t DCameraSinkCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, + MessageOption &option) + */ +HWTEST_F(DCameraSinkCallbackStubTest, OnRemoteRequest_001, TestSize.Level1) +{ + DHLOGI("DCameraSinkCallbackStubTest OnRemoteRequest_001."); + EXPECT_EQ(false, sinkCallbackStub_ == nullptr); + + int32_t ret = DCAMERA_OK; + int32_t UNKNOW_TRANS_ERR = 305; + uint32_t code = 0; + MessageParcel data; + MessageParcel reply; + MessageOption option; + + code = 1; + data.WriteInterfaceToken(DCameraSinkCallbackStub::GetDescriptor()); + ret = sinkCallbackStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(UNKNOW_TRANS_ERR, ret); + + data.WriteInterfaceToken(u""); + ret = sinkCallbackStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ERR_INVALID_DATA, ret); +} +} +} \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/unittest/common/camera_sink/callback/dcamera_sink_callback_test.cpp b/interfaces/inner_kits/native_cpp/test/unittest/common/camera_sink/callback/dcamera_sink_callback_test.cpp index 33cb3bf4e2ea82b365aeeb79b88bd0389e22e276..8a1d83ab5ee523b7f19e645efaa36f482835903f 100644 --- a/interfaces/inner_kits/native_cpp/test/unittest/common/camera_sink/callback/dcamera_sink_callback_test.cpp +++ b/interfaces/inner_kits/native_cpp/test/unittest/common/camera_sink/callback/dcamera_sink_callback_test.cpp @@ -104,6 +104,11 @@ HWTEST_F(DCameraSinkCallbackTest, dcamera_sink_callback_test_002, TestSize.Level bool isSameAccout = false; int32_t ret = sinkCallback_->OnNotifyResourceInfo(type, subType, networkId, isSensitive, isSameAccout); EXPECT_EQ(DCAMERA_OK, ret); + + std::shared_ptr callback = std::make_shared(); + sinkCallback_->PushPrivacyResCallback(callback); + ret = sinkCallback_->OnNotifyResourceInfo(type, subType, networkId, isSensitive, isSameAccout); + EXPECT_EQ(DCAMERA_OK, ret); } } } \ No newline at end of file diff --git a/services/cameraservice/sinkservice/test/unittest/common/distributedcamera/dcamera_sink_callback_proxy_test.cpp b/services/cameraservice/sinkservice/test/unittest/common/distributedcamera/dcamera_sink_callback_proxy_test.cpp index 7ea1c2a3f352762ad4bb9c165c608126f8f9cd54..1dcd4b7389f659de556b336d84795d6e06d4826c 100644 --- a/services/cameraservice/sinkservice/test/unittest/common/distributedcamera/dcamera_sink_callback_proxy_test.cpp +++ b/services/cameraservice/sinkservice/test/unittest/common/distributedcamera/dcamera_sink_callback_proxy_test.cpp @@ -16,6 +16,7 @@ #include #include "dcamera_sink_callback_proxy.h" +#include "dcamera_sink_callback.h" #include "distributed_camera_errno.h" #include "distributed_camera_constants.h" #include "distributed_camera_sink_proxy.h" @@ -70,5 +71,28 @@ HWTEST_F(DcameraSinkCallbackProxyTest, dcamera_sink_callback_proxy_test_001, Tes sptr callbackProxy(new DCameraSinkCallbackProxy(remoteObject)); EXPECT_EQ(false, callbackProxy == nullptr); } + +/** + * @tc.name: dcamera_sink_callback_proxy_test_002 + * @tc.desc: Verify the OnNotifyResourceInfo function. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(DcameraSinkCallbackProxyTest, dcamera_sink_callback_proxy_test_002, TestSize.Level1) +{ + DHLOGI("DcameraSinkCallbackProxyTest::dcamera_sink_callback_proxy_test_002"); + sptr remoteObject = sptr(new DCameraSinkCallback()); + sptr callbackProxy(new DCameraSinkCallbackProxy(remoteObject)); + EXPECT_EQ(false, callbackProxy == nullptr); + + int32_t ret = DCAMERA_BAD_VALUE; + ResourceEventType type = ResourceEventType::EVENT_TYPE_QUERY_RESOURCE; + std::string subtype(""); + std::string newworkId(""); + bool isSensitive = false; + bool isSameAccout = false; + ret = callbackProxy->OnNotifyResourceInfo(type, subtype, newworkId, isSensitive, isSameAccout); + 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/dcamera_source_callback_proxy_test.cpp b/services/cameraservice/sourceservice/test/unittest/common/distributedcamera/dcamera_source_callback_proxy_test.cpp index 49425de7871f15e623cfe4416cbd893fe673deb2..6ba64b5df2dcf50fefcebb0e22630125274df90b 100644 --- a/services/cameraservice/sourceservice/test/unittest/common/distributedcamera/dcamera_source_callback_proxy_test.cpp +++ b/services/cameraservice/sourceservice/test/unittest/common/distributedcamera/dcamera_source_callback_proxy_test.cpp @@ -16,6 +16,7 @@ #include #include "dcamera_source_callback_proxy.h" +#include "dcamera_source_callback.h" #include "distributed_camera_errno.h" #include "distributed_camera_constants.h" #include "distributed_camera_source_proxy.h" @@ -133,6 +134,44 @@ HWTEST_F(DcameraSourceCallbackProxyTest, dcamera_source_callback_proxy_test_003, EXPECT_EQ(DCAMERA_OK, status); } +/** + * @tc.name: dcamera_source_callback_proxy_test_004 + * @tc.desc: Verify the OnNotifyRegResult function. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(DcameraSourceCallbackProxyTest, dcamera_source_callback_proxy_test_004, TestSize.Level1) +{ + DHLOGI("DcameraSourceCallbackProxyTest::dcamera_source_callback_proxy_test_004"); + sptr samgr = + SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + sptr remoteObject = samgr->GetSystemAbility(DISTRIBUTED_HARDWARE_CAMERA_SOURCE_SA_ID); + sptr callbackProxy(new DCameraSourceCallbackProxy(remoteObject)); + EXPECT_EQ(false, callbackProxy == nullptr); + + int32_t status = 0; + const std::string maxdirstr(257, '1'); + const std::string testemptystr = ""; + const std::string teststr = "TESTSTR"; + std::string maxdirstr1(50 * 1024 * 1024 + 1, '1'); + std::string emptystr = ""; + + EXPECT_EQ(DCAMERA_BAD_VALUE, callbackProxy->OnNotifyRegResult( + testemptystr, testemptystr, testemptystr, status, emptystr)); + EXPECT_EQ(DCAMERA_BAD_VALUE, callbackProxy->OnNotifyRegResult( + maxdirstr, testemptystr, testemptystr, status, emptystr)); + EXPECT_EQ(DCAMERA_BAD_VALUE, callbackProxy->OnNotifyRegResult( + teststr, testemptystr, testemptystr, status, emptystr)); + EXPECT_EQ(DCAMERA_BAD_VALUE, callbackProxy->OnNotifyRegResult( + teststr, maxdirstr, testemptystr, status, emptystr)); + EXPECT_EQ(DCAMERA_BAD_VALUE, callbackProxy->OnNotifyRegResult( + teststr, teststr, testemptystr, status, emptystr)); + EXPECT_EQ(DCAMERA_BAD_VALUE, callbackProxy->OnNotifyRegResult( + teststr, teststr, maxdirstr, status, emptystr)); + EXPECT_EQ(DCAMERA_BAD_VALUE, callbackProxy->OnNotifyRegResult( + teststr, teststr, teststr, status, maxdirstr1)); +} + /** * @tc.name: CheckParams_001 * @tc.desc: Verify the CheckParams function. @@ -179,6 +218,22 @@ HWTEST_F(DcameraSourceCallbackProxyTest, OnDataSyncTrigger_001, TestSize.Level1) EXPECT_EQ(DCAMERA_BAD_VALUE, callbackProxy->OnDataSyncTrigger(devId)); } +/** + * @tc.name: OnDataSyncTrigger_002 + * @tc.desc: Verify the OnDataSyncTrigger function. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(DcameraSourceCallbackProxyTest, OnDataSyncTrigger_002, TestSize.Level1) +{ + DHLOGI("DcameraSourceCallbackProxyTest::OnDataSyncTrigger_002"); + + sptr remoteObject = sptr(new DCameraSourceCallback()); + sptr callbackProxy(new DCameraSourceCallbackProxy(remoteObject)); + + EXPECT_EQ(DCAMERA_BAD_VALUE, callbackProxy->OnDataSyncTrigger(TEST_DEVICE_ID)); +} + /** * @tc.name: OnHardwareStateChanged_001 * @tc.desc: Verify the OnHardwareStateChanged function. @@ -195,5 +250,21 @@ HWTEST_F(DcameraSourceCallbackProxyTest, OnHardwareStateChanged_001, TestSize.Le EXPECT_EQ(DCAMERA_BAD_VALUE, callbackProxy->OnHardwareStateChanged("", "", -1)); } + +/** + * @tc.name: OnHardwareStateChanged_002 + * @tc.desc: Verify the OnHardwareStateChanged function. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(DcameraSourceCallbackProxyTest, OnHardwareStateChanged_002, TestSize.Level1) +{ + DHLOGI("DcameraSourceCallbackProxyTest::OnHardwareStateChanged_002"); + + sptr remoteObject = sptr(new DCameraSourceCallback()); + sptr callbackProxy(new DCameraSourceCallbackProxy(remoteObject)); + + EXPECT_EQ(DCAMERA_BAD_VALUE, callbackProxy->OnHardwareStateChanged(TEST_DEVICE_ID, TEST_CAMERA_DH_ID_0, 0)); +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/services/cameraservice/sourceservice/test/unittest/common/distributedcamera/distributed_camera_source_service_test.cpp b/services/cameraservice/sourceservice/test/unittest/common/distributedcamera/distributed_camera_source_service_test.cpp index 57403d98dc047402302d8df0dd4f24852269b416..418c0cdca8cdcaeb2f4e5f0a8c9159244cb97121 100644 --- a/services/cameraservice/sourceservice/test/unittest/common/distributedcamera/distributed_camera_source_service_test.cpp +++ b/services/cameraservice/sourceservice/test/unittest/common/distributedcamera/distributed_camera_source_service_test.cpp @@ -123,6 +123,12 @@ HWTEST_F(DistributedCameraSourceServiceTest, dcamera_source_service_test_003, Te args.push_back(str); int ret = testSrcService_->Dump(fd, args); EXPECT_EQ(DCAMERA_OK, ret); + + for (int i = 0; i < 10242; i++) { + args.push_back(u""); + } + ret = testSrcService_->Dump(fd, args); + EXPECT_EQ(DCAMERA_BAD_VALUE, ret); } /** @@ -225,7 +231,10 @@ HWTEST_F(DistributedCameraSourceServiceTest, dcamera_source_service_test_009, Te DHLOGI("DistributedCameraSourceServiceTest::dcamera_source_service_test_009"); EXPECT_EQ(false, testSrcService_ == nullptr); - int32_t ret = testSrcService_->LoadDCameraHDF(); + int32_t ret = testSrcService_->UnLoadCameraHDF(); + EXPECT_EQ(DCAMERA_OK, ret); + + ret = testSrcService_->LoadDCameraHDF(); EXPECT_EQ(DCAMERA_OK, ret); ret = testSrcService_->UnLoadCameraHDF(); EXPECT_EQ(DCAMERA_OK, ret); diff --git a/services/cameraservice/sourceservice/test/unittest/common/distributedcameramgr/dcamera_source_dev_test.cpp b/services/cameraservice/sourceservice/test/unittest/common/distributedcameramgr/dcamera_source_dev_test.cpp index c5483978b4e8a5d163612d361e78f1fc511ccbfe..d0d351dcbdd23808db3d0bd8078cf4cb0361d1bc 100644 --- a/services/cameraservice/sourceservice/test/unittest/common/distributedcameramgr/dcamera_source_dev_test.cpp +++ b/services/cameraservice/sourceservice/test/unittest/common/distributedcameramgr/dcamera_source_dev_test.cpp @@ -661,5 +661,22 @@ HWTEST_F(DCameraSourceDevTest, SetHicollieFlag_001, TestSize.Level1) camDev_->SetHicollieFlag(false); EXPECT_EQ(false, camDev_->GetHicollieFlag()); } + +/** + * @tc.name: SetHicollieFlag_001 + * @tc.desc: Verify source dev SetHicollieFlag. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(DCameraSourceDevTest, GetFullCaps_001, TestSize.Level1) +{ + DHLOGI("DCameraSourceDevTest GetFullCaps_001"); + EXPECT_EQ(DCAMERA_OK, camDev_->GetFullCaps()); + + std::shared_ptr camDev1_; + std::shared_ptr stateListener1_; + camDev1_ = std::make_shared(TEST_DEVICE_ID, TEST_CAMERA_DH_ID_0, stateListener1_); + EXPECT_EQ(DCAMERA_BAD_VALUE, camDev1_->GetFullCaps()); +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file