From 54f77b58659aa39b9df6c7ed02f959184b536e23 Mon Sep 17 00:00:00 2001 From: torrizo Date: Tue, 13 Aug 2024 02:27:07 +0000 Subject: [PATCH 01/19] update old/services/core/test/BUILD.gn. Signed-off-by: torrizo --- old/services/core/test/BUILD.gn | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/old/services/core/test/BUILD.gn b/old/services/core/test/BUILD.gn index c5dc8950..6de4af77 100644 --- a/old/services/core/test/BUILD.gn +++ b/old/services/core/test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2023 Huawei Device Co., Ltd. +# Copyright (c) 2021-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 @@ -252,12 +252,27 @@ ohos_unittest("profile_event_notifier_proxy_test") { subsystem_name = "deviceprofile" } +ohos_unittest("distributed_device_profile_stub_test") { + module_out_path = module_output_path + cflags = [ + "-Dprivate=public", + "-Dprotected=public", + ] + sources = [ "unittest/distributed_device_profile_stub_test.cpp" ] + configs = device_profile_configs + deps = device_profile_deps + external_deps = device_profile_external_deps + part_name = "device_info_manager" + subsystem_name = "deviceprofile" +} + group("unittest") { testonly = true deps = [ ":content_sensor_test", ":device_profile_dfx_test", ":device_profile_utils_test", + ":distributed_device_profile_stub_test", ":event_subscribe_test", ":profile_authority_test", ":profile_change_handler_test", -- Gitee From 60d85f1b5a0b13367c3db222434cdb1facd787b2 Mon Sep 17 00:00:00 2001 From: torrizo Date: Tue, 13 Aug 2024 02:28:19 +0000 Subject: [PATCH 02/19] add old/services/core/test/unittest/distributed_device_profile_stub_test.cpp. Signed-off-by: torrizo --- .../distributed_device_profile_stub_test.cpp | 446 ++++++++++++++++++ 1 file changed, 446 insertions(+) create mode 100644 old/services/core/test/unittest/distributed_device_profile_stub_test.cpp diff --git a/old/services/core/test/unittest/distributed_device_profile_stub_test.cpp b/old/services/core/test/unittest/distributed_device_profile_stub_test.cpp new file mode 100644 index 00000000..8b9675d2 --- /dev/null +++ b/old/services/core/test/unittest/distributed_device_profile_stub_test.cpp @@ -0,0 +1,446 @@ +/* + * 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 + +#include "distributed_device_profile_stub.h" +#include "idistributed_device_profile.h" +#include "iremote_stub.h" +#include "device_profile_errors.h" +#include "distributed_device_profile_client.h" +#include "distributed_device_profile_enums.h" +#include "deviceprofile_ipc_interface_code.h" +#include "distributed_device_profile_errors.h" +#include "utils.h" + +namespace OHOS { +namespace DeviceProfile { + +using namespace OHOS::DistributedDeviceProfile; +using namespace testing; +using namespace testing::ext; + +class DeviceProfileStubTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); +}; + +void DeviceProfileStubTest::SetUpTestCase() +{ + DTEST_LOG << "SetUpTestCase" << std::endl; +} + +void DeviceProfileStubTest::TearDownTestCase() +{ + DTEST_LOG << "TearDownTestCase" << std::endl; +} + +void DeviceProfileStubTest::SetUp() +{ + DTEST_LOG << "SetUp" << std::endl; +} + +void DeviceProfileStubTest::TearDown() +{ + DTEST_LOG << "TearDown" << std::endl; +} + +class DistributedDeviceProfileStubTest : public DistributedDeviceProfileStub { +public: + DistributedDeviceProfileStubTest() = default; + ~DistributedDeviceProfileStubTest() = default; + int32_t PutDeviceProfile(const ServiceCharacteristicProfile& profile) + { + (void)profile; + return 0; + } + int32_t GetDeviceProfile(const std::string& udid, const std::string& serviceId, + ServiceCharacteristicProfile& profile) + { + (void)udid; + (void)serviceId; + (void)profile; + return 0; + } + int32_t DeleteDeviceProfile(const std::string& serviceId) + { + (void)serviceId; + return 0; + } + int32_t SubscribeProfileEvents(const std::list& subscribeInfos, + const sptr& profileEventNotifier, std::list& failedEvents) + { + (void)subscribeInfos; + (void)profileEventNotifier; + (void)failedEvents; + return 0; + } + int32_t UnsubscribeProfileEvents(const std::list& profileEvents, + const sptr& profileEventNotifier, std::list& failedEvents) + { + (void)profileEvents; + (void)profileEventNotifier; + (void)failedEvents; + return 0; + } + int32_t SyncDeviceProfile(const SyncOptions& syncOptions, const sptr& profileEventNotifier) + { + (void)syncOptions; + (void)profileEventNotifier; + return 0; + } +}; + +HWTEST_F(DeviceProfileStubTest, NotifyAclEventInner_001, TestSize.Level3) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + uint32_t code = static_cast(DistributedDeviceProfile::DPInterfaceCode::PUT_ACL_PROFILE); + std::shared_ptr distributedDeviceProfileStub = + std::make_shared(); + int32_t result = distributedDeviceProfileStub->NotifyAclEventInner(code, data, reply, option); + EXPECT_EQ(DP_READ_PARCEL_FAIL, result); +} + +HWTEST_F(DeviceProfileStubTest, NotifyAclEventInner_002, TestSize.Level3) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + uint32_t code = static_cast(DPInterfaceCode::UPDATE_ACL_PROFILE); + std::shared_ptr distributedDeviceProfileStub = + std::make_shared(); + int32_t result = distributedDeviceProfileStub->NotifyAclEventInner(code, data, reply, option); + EXPECT_EQ(DP_READ_PARCEL_FAIL, result); +} + +HWTEST_F(DeviceProfileStubTest, NotifyAclEventInner_003, TestSize.Level3) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + uint32_t code = static_cast(DistributedDeviceProfile::DPInterfaceCode::GET_TRUST_DEVICE_PROFILE); + std::shared_ptr distributedDeviceProfileStub = + std::make_shared(); + int32_t result = distributedDeviceProfileStub->NotifyAclEventInner(code, data, reply, option); + EXPECT_EQ(ERR_FLATTEN_OBJECT, result); +} + +HWTEST_F(DeviceProfileStubTest, NotifyAclEventInner_004, TestSize.Level3) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + uint32_t code = static_cast(DistributedDeviceProfile::DPInterfaceCode::GET_ALL_TRUST_DEVICE_PROFILE); + std::shared_ptr distributedDeviceProfileStub = + std::make_shared(); + int32_t result = distributedDeviceProfileStub->NotifyAclEventInner(code, data, reply, option); + EXPECT_EQ(DP_READ_PARCEL_FAIL, result); +} + +HWTEST_F(DeviceProfileStubTest, NotifyAclEventInner_005, TestSize.Level3) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + uint32_t code = static_cast(DistributedDeviceProfile::DPInterfaceCode::GET_ACL_PROFILE); + std::shared_ptr distributedDeviceProfileStub = + std::make_shared(); + int32_t result = distributedDeviceProfileStub->NotifyAclEventInner(code, data, reply, option); + EXPECT_EQ(DP_READ_PARCEL_FAIL, result); +} + +HWTEST_F(DeviceProfileStubTest, NotifyAclEventInner_006, TestSize.Level3) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + uint32_t code = static_cast(DistributedDeviceProfile::DPInterfaceCode::GET_ALL_ACL_PROFILE); + std::shared_ptr distributedDeviceProfileStub = + std::make_shared(); + int32_t result = distributedDeviceProfileStub->NotifyAclEventInner(code, data, reply, option); + EXPECT_EQ(DP_WRITE_PARCEL_FAIL, result); +} + +HWTEST_F(DeviceProfileStubTest, NotifyAclEventInner_007, TestSize.Level3) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + uint32_t code = static_cast(DistributedDeviceProfile::DPInterfaceCode::DELETE_ACL_PROFILE); + std::shared_ptr distributedDeviceProfileStub = + std::make_shared(); + int32_t result = distributedDeviceProfileStub->NotifyAclEventInner(code, data, reply, option); + EXPECT_EQ(ERR_FLATTEN_OBJECT, result); +} + +HWTEST_F(DeviceProfileStubTest, NotifyAclEventInner_008, TestSize.Level3) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + uint32_t code = static_cast(DistributedDeviceProfile::DPInterfaceCode::SUBSCRIBE_DEVICE_PROFILE); + std::shared_ptr distributedDeviceProfileStub = + std::make_shared(); + int32_t result = distributedDeviceProfileStub->NotifyAclEventInner(code, data, reply, option); + EXPECT_EQ(DP_READ_PARCEL_FAIL, result); +} + +HWTEST_F(DeviceProfileStubTest, NotifyAclEventInner_009, TestSize.Level3) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + uint32_t code = static_cast(DistributedDeviceProfile::DPInterfaceCode::UNSUBSCRIBE_DEVICE_PROFILE); + std::shared_ptr distributedDeviceProfileStub = + std::make_shared(); + int32_t result = distributedDeviceProfileStub->NotifyAclEventInner(code, data, reply, option); + EXPECT_EQ(DP_READ_PARCEL_FAIL, result); +} + +HWTEST_F(DeviceProfileStubTest, NotifyAclEventInner_010, TestSize.Level3) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + uint32_t code = static_cast(DistributedDeviceProfile::DPInterfaceCode::SEND_SUBSCRIBE_INFOS); + std::shared_ptr distributedDeviceProfileStub = + std::make_shared(); + int32_t result = distributedDeviceProfileStub->NotifyAclEventInner(code, data, reply, option); + EXPECT_EQ(DP_READ_PARCEL_FAIL, result); +} + +HWTEST_F(DeviceProfileStubTest, NotifyAclEventInner_011, TestSize.Level3) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + uint32_t code = static_cast(DistributedDeviceProfile::DPInterfaceCode::PUT_SERVICE_PROFILE); + std::shared_ptr distributedDeviceProfileStub = + std::make_shared(); + int32_t result = distributedDeviceProfileStub->NotifyAclEventInner(code, data, reply, option); + EXPECT_EQ(DP_READ_PARCEL_FAIL, result); +} + +HWTEST_F(DeviceProfileStubTest, NotifyAclEventInner_012, TestSize.Level3) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + uint32_t code = static_cast(DistributedDeviceProfile::DPInterfaceCode::PUT_SERVICE_PROFILE_BATCH); + std::shared_ptr distributedDeviceProfileStub = + std::make_shared(); + int32_t result = distributedDeviceProfileStub->NotifyAclEventInner(code, data, reply, option); + EXPECT_EQ(DP_READ_PARCEL_FAIL, result); +} + +HWTEST_F(DeviceProfileStubTest, NotifyAclEventInner_013, TestSize.Level3) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + uint32_t code = static_cast(DistributedDeviceProfile::DPInterfaceCode::PUT_CHAR_PROFILE); + std::shared_ptr distributedDeviceProfileStub = + std::make_shared(); + int32_t result = distributedDeviceProfileStub->NotifyAclEventInner(code, data, reply, option); + EXPECT_EQ(DP_READ_PARCEL_FAIL, result); +} + +HWTEST_F(DeviceProfileStubTest, NotifyAclEventInner_014, TestSize.Level3) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + uint32_t code = static_cast(DistributedDeviceProfile::DPInterfaceCode::PUT_CHAR_PROFILE_BATCH); + std::shared_ptr distributedDeviceProfileStub = + std::make_shared(); + int32_t result = distributedDeviceProfileStub->NotifyAclEventInner(code, data, reply, option); + EXPECT_EQ(DP_READ_PARCEL_FAIL, result); +} + +HWTEST_F(DeviceProfileStubTest, NotifyAclEventInner_015, TestSize.Level3) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + uint32_t code = 1000; + std::shared_ptr distributedDeviceProfileStub = + std::make_shared(); + int32_t result = distributedDeviceProfileStub->NotifyAclEventInner(code, data, reply, option); + EXPECT_EQ(305, result); +} + +HWTEST_F(DeviceProfileStubTest, NotifyOldEventInner_001, TestSize.Level3) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + uint32_t code = static_cast(IDeviceProfileInterfaceCode::PUT_DEVICE_PROFILE); + std::shared_ptr distributedDeviceProfileStub = + std::make_shared(); + int32_t result = distributedDeviceProfileStub->NotifyOldEventInner(code, data, reply, option); + EXPECT_EQ(ERR_NULL_OBJECT, result); +} + +HWTEST_F(DeviceProfileStubTest, NotifyOldEventInner_002, TestSize.Level3) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + uint32_t code = static_cast(IDeviceProfileInterfaceCode::DELETE_DEVICE_PROFILE); + std::shared_ptr distributedDeviceProfileStub = + std::make_shared(); + int32_t result = distributedDeviceProfileStub->NotifyOldEventInner(code, data, reply, option); + EXPECT_EQ(0, result); +} + +HWTEST_F(DeviceProfileStubTest, NotifyOldEventInner_003, TestSize.Level3) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + uint32_t code = static_cast(IDeviceProfileInterfaceCode::GET_DEVICE_PROFILE); + std::shared_ptr distributedDeviceProfileStub = + std::make_shared(); + int32_t result = distributedDeviceProfileStub->NotifyOldEventInner(code, data, reply, option); + EXPECT_EQ(ERR_FLATTEN_OBJECT, result); +} + +HWTEST_F(DeviceProfileStubTest, NotifyOldEventInner_004, TestSize.Level3) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + uint32_t code = static_cast(IDeviceProfileInterfaceCode::SUBSCRIBE_PROFILE_EVENT); + std::shared_ptr distributedDeviceProfileStub = + std::make_shared(); + int32_t result = distributedDeviceProfileStub->NotifyOldEventInner(code, data, reply, option); + EXPECT_EQ(ERR_DP_INVALID_PARAMS, result); +} + +HWTEST_F(DeviceProfileStubTest, NotifyOldEventInner_005, TestSize.Level3) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + uint32_t code = static_cast(IDeviceProfileInterfaceCode::UNSUBSCRIBE_PROFILE_EVENT); + std::shared_ptr distributedDeviceProfileStub = + std::make_shared(); + int32_t result = distributedDeviceProfileStub->NotifyOldEventInner(code, data, reply, option); + EXPECT_EQ(ERR_DP_INVALID_PARAMS, result); +} + +HWTEST_F(DeviceProfileStubTest, NotifyOldEventInner_006, TestSize.Level3) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + uint32_t code = static_cast(IDeviceProfileInterfaceCode::SYNC_DEVICE_PROFILE); + std::shared_ptr distributedDeviceProfileStub = + std::make_shared(); + int32_t result = distributedDeviceProfileStub->NotifyOldEventInner(code, data, reply, option); + EXPECT_EQ(ERR_NULL_OBJECT, result); +} + +HWTEST_F(DeviceProfileStubTest, NotifyNewEventInner_001, TestSize.Level3) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + uint32_t code = static_cast(DPInterfaceCode::GET_DEVICE_PROFILE_NEW); + std::shared_ptr distributedDeviceProfileStub = + std::make_shared(); + int32_t result = distributedDeviceProfileStub->NotifyNewEventInner(code, data, reply, option); + EXPECT_EQ(ERR_FLATTEN_OBJECT, result); +} + +HWTEST_F(DeviceProfileStubTest, NotifyNewEventInner_002, TestSize.Level3) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + uint32_t code = static_cast(DPInterfaceCode::GET_SERVICE_PROFILE); + std::shared_ptr distributedDeviceProfileStub = + std::make_shared(); + int32_t result = distributedDeviceProfileStub->NotifyNewEventInner(code, data, reply, option); + EXPECT_EQ(ERR_FLATTEN_OBJECT, result); +} + +HWTEST_F(DeviceProfileStubTest, NotifyNewEventInner_003, TestSize.Level3) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + uint32_t code = static_cast(DPInterfaceCode::GET_CHAR_PROFILE); + std::shared_ptr distributedDeviceProfileStub = + std::make_shared(); + int32_t result = distributedDeviceProfileStub->NotifyNewEventInner(code, data, reply, option); + EXPECT_EQ(ERR_FLATTEN_OBJECT, result); +} + +HWTEST_F(DeviceProfileStubTest, NotifyNewEventInner_004, TestSize.Level3) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + uint32_t code = static_cast(DPInterfaceCode::DEL_SERVICE_PROFILE); + std::shared_ptr distributedDeviceProfileStub = + std::make_shared(); + int32_t result = distributedDeviceProfileStub->NotifyNewEventInner(code, data, reply, option); + EXPECT_EQ(ERR_FLATTEN_OBJECT, result); +} + +HWTEST_F(DeviceProfileStubTest, NotifyNewEventInner_005, TestSize.Level3) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + uint32_t code = static_cast(DPInterfaceCode::DEL_CHAR_PROFILE); + std::shared_ptr distributedDeviceProfileStub = + std::make_shared(); + int32_t result = distributedDeviceProfileStub->NotifyNewEventInner(code, data, reply, option); + EXPECT_EQ(ERR_FLATTEN_OBJECT, result); +} + +HWTEST_F(DeviceProfileStubTest, NotifyNewEventInner_006, TestSize.Level3) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + uint32_t code = static_cast(DPInterfaceCode::SYNC_DEVICE_PROFILE_NEW); + std::shared_ptr distributedDeviceProfileStub = + std::make_shared(); + int32_t result = distributedDeviceProfileStub->NotifyNewEventInner(code, data, reply, option); + EXPECT_EQ(DP_READ_PARCEL_FAIL, result); +} + +HWTEST_F(DeviceProfileStubTest, NotifyNewEventInner_007, TestSize.Level3) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + uint32_t code = 1000; + std::shared_ptr distributedDeviceProfileStub = + std::make_shared(); + int32_t result = distributedDeviceProfileStub->NotifyNewEventInner(code, data, reply, option); + EXPECT_EQ(305, result); +} +} // namespace DeviceProfile +} // namespace OHOS \ No newline at end of file -- Gitee From 52d362e9e3bafffd909718861a1933bf735310b1 Mon Sep 17 00:00:00 2001 From: wangzhaohao Date: Tue, 13 Aug 2024 10:35:17 +0800 Subject: [PATCH 03/19] add UT Signed-off-by: wangzhaohao --- .../unittest/device_profile_manager_test.cpp | 160 +++++++++++++++++- .../test/unittest/dp_profile_service_test.cpp | 33 ++++ .../core/test/unittest/profile_utils_test.cpp | 150 ++++++++++++++++ 3 files changed, 341 insertions(+), 2 deletions(-) diff --git a/services/core/test/unittest/device_profile_manager_test.cpp b/services/core/test/unittest/device_profile_manager_test.cpp index 3a023b00..7bb404da 100644 --- a/services/core/test/unittest/device_profile_manager_test.cpp +++ b/services/core/test/unittest/device_profile_manager_test.cpp @@ -124,6 +124,21 @@ HWTEST_F(DeviceProfileManagerTest, UnInit001, TestSize.Level1) DeviceProfileManager::GetInstance().isFirst_.store(false); } +/** + * @tc.name: UnInit002 + * @tc.desc: deviceProfileStore_ is nullptr + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(DeviceProfileManagerTest, UnInit002, TestSize.Level1) +{ + DeviceProfileManager::GetInstance().deviceProfileStore_ = nullptr; + int32_t ret = DeviceProfileManager::GetInstance().UnInit(); + EXPECT_EQ(ret, DP_KV_DB_PTR_NULL); + DeviceProfileManager::GetInstance().Init(); + DeviceProfileManager::GetInstance().isFirst_.store(false); +} + /** * @tc.name: ReInit001 * @tc.desc: ReInit succeed. @@ -283,6 +298,32 @@ HWTEST_F(DeviceProfileManagerTest, PutDeviceProfile005, TestSize.Level1) DeviceProfileManager::GetInstance().isFirst_.store(false); } +/** + * @tc.name: PutDeviceProfile006 + * @tc.desc: PutDeviceProfile succeed. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(DeviceProfileManagerTest, PutDeviceProfile006, TestSize.Level1) +{ + DeviceProfile deviceProfile; + ContentSensorManagerUtils::GetInstance().localUdid_ = "anything111"; + deviceProfile.SetDeviceId("anything111"); + deviceProfile.SetDeviceTypeName("anything"); + deviceProfile.SetDeviceTypeId(0); + deviceProfile.SetDeviceName("anything"); + deviceProfile.SetManufactureName("anything"); + deviceProfile.SetDeviceModel("anything"); + deviceProfile.SetStorageCapability(1); + deviceProfile.SetOsSysCap("anything"); + deviceProfile.SetOsApiLevel(1); + deviceProfile.SetOsVersion("anything"); + deviceProfile.SetOsType(1); + DeviceProfileManager::GetInstance().deviceProfileStore_ = nullptr; + int32_t ret = DeviceProfileManager::GetInstance().PutDeviceProfile(deviceProfile); + EXPECT_EQ(ret, DP_KV_DB_PTR_NULL); +} + /** * @tc.name: PutServiceProfile001 * @tc.desc: PutServiceProfile succeed. @@ -383,6 +424,43 @@ HWTEST_F(DeviceProfileManagerTest, PutServiceProfile005, TestSize.Level1) DeviceProfileManager::GetInstance().isFirst_.store(false); } +/** + * @tc.name: PutServiceProfile006 + * @tc.desc: isFirst_.load() == true + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(DeviceProfileManagerTest, PutServiceProfile006, TestSize.Level1) +{ + ServiceProfile serviceProfile; + ContentSensorManagerUtils::GetInstance().localUdid_ = "deviceId112"; + serviceProfile.SetDeviceId("deviceId112"); + serviceProfile.SetServiceName("serviceName"); + serviceProfile.SetServiceType("serviceType"); + DeviceProfileManager::GetInstance().isFirst_.store(true); + int32_t ret = DeviceProfileManager::GetInstance().PutServiceProfile(serviceProfile); + DeviceProfileManager::GetInstance().isFirst_.store(false); + EXPECT_EQ(ret, DP_SUCCESS); +} + +/** + * @tc.name: PutServiceProfile007 + * @tc.desc: deviceProfileStore_ == nullptr + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(DeviceProfileManagerTest, PutServiceProfile007, TestSize.Level1) +{ + ServiceProfile serviceProfile; + ContentSensorManagerUtils::GetInstance().localUdid_ = "deviceId113"; + serviceProfile.SetDeviceId("deviceId113"); + serviceProfile.SetServiceName("serviceName"); + serviceProfile.SetServiceType("serviceType"); + DeviceProfileManager::GetInstance().deviceProfileStore_ = nullptr; + int32_t ret = DeviceProfileManager::GetInstance().PutServiceProfile(serviceProfile); + EXPECT_EQ(ret, DP_KV_DB_PTR_NULL); +} + /** * @tc.name: PutServiceProfileBatch001 * @tc.desc: PutServiceProfileBatch succeed. @@ -407,6 +485,9 @@ HWTEST_F(DeviceProfileManagerTest, PutServiceProfileBatch001, TestSize.Level1) int32_t ret = DeviceProfileManager::GetInstance().PutServiceProfileBatch(serviceProfiles); EXPECT_EQ(ret, DP_SUCCESS); + DeviceProfileManager::GetInstance().deviceProfileStore_ = nullptr; + ret = DeviceProfileManager::GetInstance().PutServiceProfileBatch(serviceProfiles); + EXPECT_EQ(ret, DP_KV_DB_PTR_NULL); } /** @@ -506,6 +587,7 @@ HWTEST_F(DeviceProfileManagerTest, PutCharacteristicProfile003, TestSize.Level1) */ HWTEST_F(DeviceProfileManagerTest, PutCharacteristicProfile004, TestSize.Level1) { + ContentSensorManagerUtils::GetInstance().localUdid_ = "deviceId10"; CharacteristicProfile charProfile10; charProfile10.SetDeviceId("deviceId10"); charProfile10.SetServiceName("serviceName10"); @@ -514,7 +596,7 @@ HWTEST_F(DeviceProfileManagerTest, PutCharacteristicProfile004, TestSize.Level1) DeviceProfileManager::GetInstance().deviceProfileStore_ = nullptr; int32_t ret = DeviceProfileManager::GetInstance().PutCharacteristicProfile(charProfile10); - EXPECT_EQ(ret, DP_INVALID_PARAMS); + EXPECT_EQ(ret, DP_KV_DB_PTR_NULL); DeviceProfileManager::GetInstance().Init(); } @@ -541,6 +623,26 @@ HWTEST_F(DeviceProfileManagerTest, PutCharacteristicProfile005, TestSize.Level1) DeviceProfileManager::GetInstance().isFirst_.store(false); } +/** + * @tc.name: PutCharacteristicProfile006 + * @tc.desc: isFirst_.load() = true + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(DeviceProfileManagerTest, PutCharacteristicProfile006, TestSize.Level1) +{ + CharacteristicProfile charProfile; + ContentSensorManagerUtils::GetInstance().localUdid_ = "deviceId111"; + charProfile.SetDeviceId("deviceId111"); + charProfile.SetServiceName("serviceName"); + charProfile.SetCharacteristicKey("characteristicKey"); + charProfile.SetCharacteristicValue("characteristicValue"); + DeviceProfileManager::GetInstance().isFirst_.store(true); + int32_t ret = DeviceProfileManager::GetInstance().PutCharacteristicProfile(charProfile); + EXPECT_EQ(ret, DP_SUCCESS); + DeviceProfileManager::GetInstance().isFirst_.store(false); +} + /** * @tc.name: PutCharacteristicProfileBatch001 * @tc.desc: PutCharacteristicProfileBatch succeed. @@ -567,6 +669,10 @@ HWTEST_F(DeviceProfileManagerTest, PutCharacteristicProfileBatch001, TestSize.Le int32_t ret = DeviceProfileManager::GetInstance().PutCharacteristicProfileBatch(charProfiles); EXPECT_EQ(ret, DP_SUCCESS); + + DeviceProfileManager::GetInstance().deviceProfileStore_ = nullptr; + ret = DeviceProfileManager::GetInstance().PutCharacteristicProfileBatch(charProfiles); + EXPECT_EQ(ret, DP_KV_DB_PTR_NULL); } /** @@ -1409,5 +1515,55 @@ HWTEST_F(DeviceProfileManagerTest, RunloadedFunction002, TestSize.Level1) int32_t ret = DeviceProfileManager::GetInstance().RunloadedFunction(deviceId, syncCb); EXPECT_EQ(ret, DP_LOAD_SYNC_ADAPTER_FAILED); } + +HWTEST_F(DeviceProfileManagerTest, GetInKvDB002, TestSize.Level1) +{ + string deviceId = ContentSensorManagerUtils::GetInstance().ObtainLocalUdid(); + DeviceProfile deviceProfile2; + deviceProfile2.SetDeviceId(deviceId); + deviceProfile2.SetDeviceTypeName("GetInKvDB001_DeviceTypeName2"); + deviceProfile2.SetDeviceTypeId(0); + deviceProfile2.SetDeviceName("GetInKvDB001_DeviceName2"); + deviceProfile2.SetManufactureName("GetInKvDB001_ManufactureName2"); + deviceProfile2.SetDeviceModel("GetInKvDB001_DeviceModel2"); + deviceProfile2.SetStorageCapability(1); + deviceProfile2.SetOsSysCap("GetInKvDB001_OsSysCap2"); + deviceProfile2.SetOsApiLevel(1); + deviceProfile2.SetOsVersion("GetInKvDB001_OsVersion2"); + deviceProfile2.SetOsType(1); + DeviceProfileManager::GetInstance().PutDeviceProfile(deviceProfile2); + + ServiceProfile serviceProfile5; + serviceProfile5.SetDeviceId(deviceId); + serviceProfile5.SetServiceName("GetInKvDB001_ServiceName2"); + serviceProfile5.SetServiceType("GetInKvDB001_ServiceType2"); + DeviceProfileManager::GetInstance().PutServiceProfile(serviceProfile5); + + CharacteristicProfile charProfile5; + charProfile5.SetDeviceId(deviceId); + charProfile5.SetServiceName("GetInKvDB001_ServiceName2"); + charProfile5.SetCharacteristicKey("GetInKvDB001_CharacteristicKey2"); + charProfile5.SetCharacteristicValue("GetInKvDB001_CharacteristicValue2"); + DeviceProfileManager::GetInstance().PutCharacteristicProfile(charProfile5); + + ProfileCache::GetInstance().DeleteDeviceProfile(deviceId); + ProfileCache::GetInstance().DeleteServiceProfile("GetInKvDB001_DeviceId2", "GetInKvDB001_ServiceName"); + ProfileCache::GetInstance().DeleteCharProfile("GetInKvDB001_DeviceId2", "GetInKvDB001_ServiceName", + "GetInKvDB001_CharacteristicKey2"); + + DeviceProfile outDeviceProfile; + DeviceProfileManager::GetInstance().GetDeviceProfile(deviceId, outDeviceProfile); + + string serviceName2 = "GetInKvDB001_ServiceName2"; + ServiceProfile outServiceProfile; + DeviceProfileManager::GetInstance().GetServiceProfile(deviceId, serviceName2, outServiceProfile); + + string serviceName3 = "GetInKvDB001_ServiceName2"; + string characteristicKey3 = "GetInKvDB001_CharacteristicKey2"; + CharacteristicProfile outCharProfile; + int32_t ret = DeviceProfileManager::GetInstance().GetCharacteristicProfile(deviceId, serviceName3, + characteristicKey3, outCharProfile); + EXPECT_EQ(ret, DP_SUCCESS); +} } // namespace DistributedDeviceProfile -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/services/core/test/unittest/dp_profile_service_test.cpp b/services/core/test/unittest/dp_profile_service_test.cpp index d38d0527..5c67f94f 100644 --- a/services/core/test/unittest/dp_profile_service_test.cpp +++ b/services/core/test/unittest/dp_profile_service_test.cpp @@ -29,6 +29,8 @@ #include "subscribe_profile_manager.h" #include "event_handler_factory.h" #include "distributed_device_profile_constants.h" +#include "dp_inited_callback_stub.h" +#include "i_dp_inited_callback.h" #undef private #undef protected @@ -83,6 +85,20 @@ void DpProfileServiceTest::TearDown() { } +class DpInitedCallback : public DpInitedCallbackStub { +public: + DpInitedCallback() + { + } + ~DpInitedCallback() + { + } + int32_t OnDpInited() + { + return 0; + } +}; + HWTEST_F(DpProfileServiceTest, Init_001, TestSize.Level1) { int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().Init(); @@ -117,6 +133,8 @@ HWTEST_F(DpProfileServiceTest, PutAccessControlProfile_001, TestSize.Level1) AccessControlProfile accessControlProfile; int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().PutAccessControlProfile(accessControlProfile); EXPECT_EQ(DP_PERMISSION_DENIED, ret); + DistributedDeviceProfileServiceNew::GetInstance().DelayUnloadTask(); + } HWTEST_F(DpProfileServiceTest, UpdateAccessControlProfile_001, TestSize.Level1) @@ -278,5 +296,20 @@ HWTEST_F(DpProfileServiceTest, Dump_001, TestSize.Level1) int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().Dump(fd, args); EXPECT_EQ(DP_INVALID_PARAMS, ret); } + +HWTEST_F(DpProfileServiceTest, SubscribeDeviceProfileInited_001, TestSize.Level1) +{ + int32_t saId = 1000; + OHOS::sptr initedCb = sptr(new DpInitedCallback()); + int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().SubscribeDeviceProfileInited(saId, initedCb); + EXPECT_EQ(DP_PERMISSION_DENIED, ret); +} + +HWTEST_F(DpProfileServiceTest, UnSubscribeDeviceProfileInited_001, TestSize.Level1) +{ + int32_t saId = 1000; + int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().UnSubscribeDeviceProfileInited(saId); + EXPECT_EQ(DP_PERMISSION_DENIED, ret); +} } } diff --git a/services/core/test/unittest/profile_utils_test.cpp b/services/core/test/unittest/profile_utils_test.cpp index b18c3e00..218031a4 100644 --- a/services/core/test/unittest/profile_utils_test.cpp +++ b/services/core/test/unittest/profile_utils_test.cpp @@ -440,6 +440,56 @@ HWTEST_F(ProfileUtilsTest, AccessControlProfileTranslateEntries001, TestSize.Lev EXPECT_EQ("123456", outProfile.GetTrustDeviceId()); } +HWTEST_F(ProfileUtilsTest, AccessControlProfileTranslateEntries002, TestSize.Level1) +{ + Accesser accesser; + accesser.SetAccesserDeviceId("acer2"); + accesser.SetAccesserUserId(11); + accesser.SetAccesserAccountId("a2"); + accesser.SetAccesserTokenId(111); + accesser.SetAccesserBundleName("b2"); + accesser.SetAccesserHapSignature("h2"); + accesser.SetAccesserBindLevel(1); + + Accessee accessee; + accessee.SetAccesseeDeviceId("acee2"); + accessee.SetAccesseeUserId(22); + accessee.SetAccesseeAccountId("a2"); + accessee.SetAccesseeTokenId(222); + accessee.SetAccesseeBundleName("bb2"); + accessee.SetAccesseeHapSignature("h2"); + accessee.SetAccesseeBindLevel(1); + + AccessControlProfile profile; + profile.SetTrustDeviceId("1234567"); + profile.SetSessionKey("key1"); + profile.SetBindType(1); + profile.SetAuthenticationType(1); + profile.SetDeviceIdType(1); + profile.SetDeviceIdHash("abcd"); + profile.SetStatus(0); + profile.SetValidPeriod(1); + profile.SetLastAuthTime(5); + profile.SetBindLevel(0); + + profile.SetAccesser(accesser); + profile.SetAccessee(accessee); + + ValuesBucket values; + ValueObject valueObject; + string strValue = ""; + int32_t res1 = ProfileUtils::AccessControlProfileToEntries(profile, values); + EXPECT_EQ(DP_SUCCESS, res1); + values.GetObject(TRUST_DEVICE_ID, valueObject); + valueObject.GetString(strValue); + EXPECT_EQ("1234567", strValue); + + AccessControlProfile outProfile; + int32_t res2 = ProfileUtils::EntriesToAccessControlProfile(values, outProfile); + EXPECT_EQ(DP_SUCCESS, res2); + EXPECT_EQ("1234567", outProfile.GetTrustDeviceId()); +} + /** * @tc.name: AccesserTranslateEntries001 * @tc.desc: AccesserToEntries and EntriesToAccesser. @@ -598,6 +648,106 @@ HWTEST_F(ProfileUtilsTest, ServiceProfileTranslateEntries001, TestSize.Level1) EXPECT_EQ("deviceId", outServiceProfile.GetDeviceId()); } +HWTEST_F(ProfileUtilsTest, AccesserTranslateEntries002, TestSize.Level1) +{ + Accesser accesser; + accesser.SetAccesserDeviceId("acer2"); + accesser.SetAccesserUserId(11); + accesser.SetAccesserAccountId("a1"); + accesser.SetAccesserTokenId(111); + accesser.SetAccesserBundleName("b1"); + accesser.SetAccesserHapSignature("h1"); + accesser.SetAccesserBindLevel(1); + + Accessee accessee; + accessee.SetAccesseeDeviceId("acee2"); + accessee.SetAccesseeUserId(22); + accessee.SetAccesseeAccountId("a1"); + accessee.SetAccesseeTokenId(222); + accessee.SetAccesseeBundleName("bb1"); + accessee.SetAccesseeHapSignature("h1"); + accessee.SetAccesseeBindLevel(1); + + AccessControlProfile profile; + profile.SetTrustDeviceId("123456"); + profile.SetSessionKey("key1"); + profile.SetBindType(1); + profile.SetAuthenticationType(1); + profile.SetDeviceIdType(1); + profile.SetDeviceIdHash("abcd"); + profile.SetStatus(0); + profile.SetValidPeriod(1); + profile.SetLastAuthTime(5); + profile.SetBindLevel(0); + + profile.SetAccesser(accesser); + profile.SetAccessee(accessee); + + ValuesBucket values; + ValueObject valueObject; + string strValue = ""; + int32_t res1 = ProfileUtils::AccesserToEntries(profile, values); + EXPECT_EQ(DP_SUCCESS, res1); + values.GetObject(ACCESSER_DEVICE_ID, valueObject); + valueObject.GetString(strValue); + EXPECT_EQ("acer2", strValue); + + Accesser outAccesser; + int32_t res2 = ProfileUtils::EntriesToAccesser(values, outAccesser); + EXPECT_EQ(DP_SUCCESS, res2); + EXPECT_EQ("acer2", outAccesser.GetAccesserDeviceId()); +} + +HWTEST_F(ProfileUtilsTest, AccesseeTranslateEntries002, TestSize.Level1) +{ + Accesser accesser; + accesser.SetAccesserDeviceId("acer2"); + accesser.SetAccesserUserId(11); + accesser.SetAccesserAccountId("a1"); + accesser.SetAccesserTokenId(111); + accesser.SetAccesserBundleName("b1"); + accesser.SetAccesserHapSignature("h1"); + accesser.SetAccesserBindLevel(1); + + Accessee accessee; + accessee.SetAccesseeDeviceId("acee2"); + accessee.SetAccesseeUserId(22); + accessee.SetAccesseeAccountId("a1"); + accessee.SetAccesseeTokenId(222); + accessee.SetAccesseeBundleName("bb1"); + accessee.SetAccesseeHapSignature("h1"); + accessee.SetAccesseeBindLevel(1); + + AccessControlProfile profile; + profile.SetTrustDeviceId("123456"); + profile.SetSessionKey("key1"); + profile.SetBindType(1); + profile.SetAuthenticationType(1); + profile.SetDeviceIdType(1); + profile.SetDeviceIdHash("abcd"); + profile.SetStatus(0); + profile.SetValidPeriod(1); + profile.SetLastAuthTime(5); + profile.SetBindLevel(0); + + profile.SetAccesser(accesser); + profile.SetAccessee(accessee); + + ValuesBucket values; + ValueObject valueObject; + string strValue = ""; + int32_t res1 = ProfileUtils::AccesseeToEntries(profile, values); + EXPECT_EQ(DP_SUCCESS, res1); + values.GetObject(ACCESSEE_DEVICE_ID, valueObject); + valueObject.GetString(strValue); + EXPECT_EQ("acee2", strValue); + + Accessee outAccessee; + int32_t res2 = ProfileUtils::EntriesToAccessee(values, outAccessee); + EXPECT_EQ(DP_SUCCESS, res2); + EXPECT_EQ("acee2", outAccessee.GetAccesseeDeviceId()); +} + /** * @tc.name: CharacteristicProfileTranslateEntries001 * @tc.desc: CharacteristicProfileToEntries and EntriesToCharProfile. -- Gitee From 2cd3959821e8d631257e5bc9ecaa25abd8ce7c8b Mon Sep 17 00:00:00 2001 From: wangzhaohao Date: Tue, 13 Aug 2024 10:45:26 +0800 Subject: [PATCH 04/19] add UT Signed-off-by: wangzhaohao --- services/core/test/unittest/dp_profile_service_test.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/services/core/test/unittest/dp_profile_service_test.cpp b/services/core/test/unittest/dp_profile_service_test.cpp index 5c67f94f..2142bcc1 100644 --- a/services/core/test/unittest/dp_profile_service_test.cpp +++ b/services/core/test/unittest/dp_profile_service_test.cpp @@ -134,7 +134,6 @@ HWTEST_F(DpProfileServiceTest, PutAccessControlProfile_001, TestSize.Level1) int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().PutAccessControlProfile(accessControlProfile); EXPECT_EQ(DP_PERMISSION_DENIED, ret); DistributedDeviceProfileServiceNew::GetInstance().DelayUnloadTask(); - } HWTEST_F(DpProfileServiceTest, UpdateAccessControlProfile_001, TestSize.Level1) -- Gitee From 7ff7b2532a286804dc57b7d76777e296ce59c2bb Mon Sep 17 00:00:00 2001 From: torrizo Date: Tue, 13 Aug 2024 03:47:14 +0000 Subject: [PATCH 05/19] update services/core/test/unittest/distributed_device_profile_stub_new_test.cpp. Signed-off-by: torrizo --- ...stributed_device_profile_stub_new_test.cpp | 352 ++++++++++++++++++ 1 file changed, 352 insertions(+) diff --git a/services/core/test/unittest/distributed_device_profile_stub_new_test.cpp b/services/core/test/unittest/distributed_device_profile_stub_new_test.cpp index 6917ece9..d68167ea 100644 --- a/services/core/test/unittest/distributed_device_profile_stub_new_test.cpp +++ b/services/core/test/unittest/distributed_device_profile_stub_new_test.cpp @@ -554,5 +554,357 @@ HWTEST_F(DistributedDeviceProfileStubNewTest, SendSubscribeInfosInner_001, TestS int32_t ret = ProfileStub_->SendSubscribeInfosInner(data, reply); EXPECT_EQ(DP_READ_PARCEL_FAIL, ret); } + +/** + * @tc.name: NotifyAclEventInner_001 + * @tc.desc: succeed + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(DistributedDeviceProfileStubNewTest, NotifyAclEventInner_001, TestSize.Level0) +{ + uint32_t code = 1000; + MessageParcel data; + MessageParcel reply; + MessageOption option; + int32_t ret = ProfileStub_->NotifyAclEventInner(code, data, reply, option); + EXPECT_EQ(305, ret); +} + +/** + * @tc.name: NotifyAclEventInner_002 + * @tc.desc: succeed + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(DistributedDeviceProfileStubNewTest, NotifyAclEventInner_002, TestSize.Level0) +{ + uint32_t code = static_cast(DPInterfaceCode::PUT_ACL_PROFILE); + MessageParcel data; + MessageParcel reply; + MessageOption option; + int32_t ret = ProfileStub_->NotifyAclEventInner(code, data, reply, option); + EXPECT_EQ(DP_READ_PARCEL_FAIL, ret); +} + +/** + * @tc.name: NotifyAclEventInner_003 + * @tc.desc: succeed + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(DistributedDeviceProfileStubNewTest, NotifyAclEventInner_003, TestSize.Level0) +{ + uint32_t code = static_cast(DPInterfaceCode::UPDATE_ACL_PROFILE); + MessageParcel data; + MessageParcel reply; + MessageOption option; + int32_t ret = ProfileStub_->NotifyAclEventInner(code, data, reply, option); + EXPECT_EQ(DP_READ_PARCEL_FAIL, ret); +} + +/** + * @tc.name: NotifyAclEventInner_004 + * @tc.desc: succeed + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(DistributedDeviceProfileStubNewTest, NotifyAclEventInner_004, TestSize.Level0) +{ + uint32_t code = static_cast(DPInterfaceCode::GET_TRUST_DEVICE_PROFILE); + MessageParcel data; + MessageParcel reply; + MessageOption option; + int32_t ret = ProfileStub_->NotifyAclEventInner(code, data, reply, option); + EXPECT_EQ(ERR_FLATTEN_OBJECT, ret); +} + +/** + * @tc.name: NotifyAclEventInner_005 + * @tc.desc: succeed + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(DistributedDeviceProfileStubNewTest, NotifyAclEventInner_005, TestSize.Level0) +{ + uint32_t code = static_cast(DPInterfaceCode::GET_ALL_TRUST_DEVICE_PROFILE); + MessageParcel data; + MessageParcel reply; + MessageOption option; + int32_t ret = ProfileStub_->NotifyAclEventInner(code, data, reply, option); + EXPECT_EQ(DP_READ_PARCEL_FAIL, ret); +} + +/** + * @tc.name: NotifyAclEventInner_006 + * @tc.desc: succeed + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(DistributedDeviceProfileStubNewTest, NotifyAclEventInner_006, TestSize.Level0) +{ + uint32_t code = static_cast(DPInterfaceCode::GET_ACL_PROFILE); + MessageParcel data; + MessageParcel reply; + MessageOption option; + int32_t ret = ProfileStub_->NotifyAclEventInner(code, data, reply, option); + EXPECT_EQ(DP_READ_PARCEL_FAIL, ret); +} + +/** + * @tc.name: NotifyAclEventInner_007 + * @tc.desc: succeed + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(DistributedDeviceProfileStubNewTest, NotifyAclEventInner_007, TestSize.Level0) +{ + uint32_t code = static_cast(DPInterfaceCode::GET_ALL_ACL_PROFILE); + MessageParcel data; + MessageParcel reply; + MessageOption option; + int32_t ret = ProfileStub_->NotifyAclEventInner(code, data, reply, option); + EXPECT_EQ(DP_WRITE_PARCEL_FAIL, ret); +} + +/** + * @tc.name: NotifyAclEventInner_008 + * @tc.desc: succeed + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(DistributedDeviceProfileStubNewTest, NotifyAclEventInner_008, TestSize.Level0) +{ + uint32_t code = static_cast(DPInterfaceCode::DELETE_ACL_PROFILE); + MessageParcel data; + MessageParcel reply; + MessageOption option; + int32_t ret = ProfileStub_->NotifyAclEventInner(code, data, reply, option); + EXPECT_EQ(ERR_FLATTEN_OBJECT, ret); +} + +/** + * @tc.name: NotifyAclEventInner_009 + * @tc.desc: succeed + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(DistributedDeviceProfileStubNewTest, NotifyAclEventInner_009, TestSize.Level0) +{ + uint32_t code = static_cast(DPInterfaceCode::SUBSCRIBE_DEVICE_PROFILE); + MessageParcel data; + MessageParcel reply; + MessageOption option; + int32_t ret = ProfileStub_->NotifyAclEventInner(code, data, reply, option); + EXPECT_EQ(DP_READ_PARCEL_FAIL, ret); +} + +/** + * @tc.name: NotifyAclEventInner_010 + * @tc.desc: succeed + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(DistributedDeviceProfileStubNewTest, NotifyAclEventInner_010, TestSize.Level0) +{ + uint32_t code = static_cast(DPInterfaceCode::UNSUBSCRIBE_DEVICE_PROFILE); + MessageParcel data; + MessageParcel reply; + MessageOption option; + int32_t ret = ProfileStub_->NotifyAclEventInner(code, data, reply, option); + EXPECT_EQ(DP_READ_PARCEL_FAIL, ret); +} + +/** + * @tc.name: NotifyAclEventInner_011 + * @tc.desc: succeed + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(DistributedDeviceProfileStubNewTest, NotifyAclEventInner_011, TestSize.Level0) +{ + uint32_t code = static_cast(DPInterfaceCode::SEND_SUBSCRIBE_INFOS); + MessageParcel data; + MessageParcel reply; + MessageOption option; + int32_t ret = ProfileStub_->NotifyAclEventInner(code, data, reply, option); + EXPECT_EQ(DP_READ_PARCEL_FAIL, ret); +} + +/** + * @tc.name: NotifyAclEventInner_012 + * @tc.desc: succeed + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(DistributedDeviceProfileStubNewTest, NotifyAclEventInner_012, TestSize.Level0) +{ + uint32_t code = static_cast(DPInterfaceCode::PUT_SERVICE_PROFILE); + MessageParcel data; + MessageParcel reply; + MessageOption option; + int32_t ret = ProfileStub_->NotifyAclEventInner(code, data, reply, option); + EXPECT_EQ(DP_READ_PARCEL_FAIL, ret); +} + +/** + * @tc.name: NotifyAclEventInner_013 + * @tc.desc: succeed + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(DistributedDeviceProfileStubNewTest, NotifyAclEventInner_013, TestSize.Level0) +{ + uint32_t code = static_cast(DPInterfaceCode::PUT_SERVICE_PROFILE_BATCH); + MessageParcel data; + MessageParcel reply; + MessageOption option; + int32_t ret = ProfileStub_->NotifyAclEventInner(code, data, reply, option); + EXPECT_EQ(DP_READ_PARCEL_FAIL, ret); +} + +/** + * @tc.name: NotifyAclEventInner_014 + * @tc.desc: succeed + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(DistributedDeviceProfileStubNewTest, NotifyAclEventInner_014, TestSize.Level0) +{ + uint32_t code = static_cast(DPInterfaceCode::PUT_CHAR_PROFILE); + MessageParcel data; + MessageParcel reply; + MessageOption option; + int32_t ret = ProfileStub_->NotifyAclEventInner(code, data, reply, option); + EXPECT_EQ(DP_READ_PARCEL_FAIL, ret); +} + +/** + * @tc.name: NotifyAclEventInner_015 + * @tc.desc: succeed + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(DistributedDeviceProfileStubNewTest, NotifyAclEventInner_015, TestSize.Level0) +{ + uint32_t code = static_cast(DPInterfaceCode::PUT_CHAR_PROFILE_BATCH); + MessageParcel data; + MessageParcel reply; + MessageOption option; + int32_t ret = ProfileStub_->NotifyAclEventInner(code, data, reply, option); + EXPECT_EQ(DP_READ_PARCEL_FAIL, ret); +} + +/** + * @tc.name: NotifyEventInner_001 + * @tc.desc: succeed + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(DistributedDeviceProfileStubNewTest, NotifyEventInner_001, TestSize.Level0) +{ + uint32_t code = static_cast(DPInterfaceCode::GET_DEVICE_PROFILE_NEW); + MessageParcel data; + MessageParcel reply; + MessageOption option; + int32_t ret = ProfileStub_->NotifyEventInner(code, data, reply, option); + EXPECT_EQ(ERR_FLATTEN_OBJECT, ret); +} + +/** + * @tc.name: NotifyEventInner_002 + * @tc.desc: succeed + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(DistributedDeviceProfileStubNewTest, NotifyEventInner_002, TestSize.Level0) +{ + uint32_t code = static_cast(DPInterfaceCode::GET_SERVICE_PROFILE); + MessageParcel data; + MessageParcel reply; + MessageOption option; + int32_t ret = ProfileStub_->NotifyEventInner(code, data, reply, option); + EXPECT_EQ(ERR_FLATTEN_OBJECT, ret); +} + +/** + * @tc.name: NotifyEventInner_003 + * @tc.desc: succeed + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(DistributedDeviceProfileStubNewTest, NotifyEventInner_003, TestSize.Level0) +{ + uint32_t code = static_cast(DPInterfaceCode::GET_CHAR_PROFILE); + MessageParcel data; + MessageParcel reply; + MessageOption option; + int32_t ret = ProfileStub_->NotifyEventInner(code, data, reply, option); + EXPECT_EQ(ERR_FLATTEN_OBJECT, ret); +} + +/** + * @tc.name: NotifyEventInner_004 + * @tc.desc: succeed + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(DistributedDeviceProfileStubNewTest, NotifyEventInner_004, TestSize.Level0) +{ + uint32_t code = static_cast(DPInterfaceCode::DEL_SERVICE_PROFILE); + MessageParcel data; + MessageParcel reply; + MessageOption option; + int32_t ret = ProfileStub_->NotifyEventInner(code, data, reply, option); + EXPECT_EQ(ERR_FLATTEN_OBJECT, ret); +} + +/** + * @tc.name: NotifyEventInner_005 + * @tc.desc: succeed + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(DistributedDeviceProfileStubNewTest, NotifyEventInner_005, TestSize.Level0) +{ + uint32_t code = static_cast(DPInterfaceCode::DEL_CHAR_PROFILE); + MessageParcel data; + MessageParcel reply; + MessageOption option; + int32_t ret = ProfileStub_->NotifyEventInner(code, data, reply, option); + EXPECT_EQ(ERR_FLATTEN_OBJECT, ret); +} + +/** + * @tc.name: NotifyEventInner_006 + * @tc.desc: succeed + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(DistributedDeviceProfileStubNewTest, NotifyEventInner_006, TestSize.Level0) +{ + uint32_t code = static_cast(DPInterfaceCode::SYNC_DEVICE_PROFILE_NEW); + MessageParcel data; + MessageParcel reply; + MessageOption option; + int32_t ret = ProfileStub_->NotifyEventInner(code, data, reply, option); + EXPECT_EQ(DP_READ_PARCEL_FAIL, ret); +} + +/** + * @tc.name: NotifyEventInner_007 + * @tc.desc: succeed + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(DistributedDeviceProfileStubNewTest, NotifyEventInner_007, TestSize.Level0) +{ + uint32_t code = 1000; + MessageParcel data; + MessageParcel reply; + MessageOption option; + int32_t ret = ProfileStub_->NotifyEventInner(code, data, reply, option); + EXPECT_EQ(305, ret); +} } // namespace DistributedDeviceProfile } // namespace OHOS -- Gitee From 30d5efce0db2f7b873b4587e182c0e2f479af216 Mon Sep 17 00:00:00 2001 From: torrizo Date: Tue, 13 Aug 2024 03:51:00 +0000 Subject: [PATCH 06/19] update old/services/core/test/unittest/profile_change_notification_test.cpp. Signed-off-by: torrizo --- .../profile_change_notification_test.cpp | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/old/services/core/test/unittest/profile_change_notification_test.cpp b/old/services/core/test/unittest/profile_change_notification_test.cpp index 407387a2..17034f22 100644 --- a/old/services/core/test/unittest/profile_change_notification_test.cpp +++ b/old/services/core/test/unittest/profile_change_notification_test.cpp @@ -318,5 +318,66 @@ HWTEST_F(ProfileChangeNotificationTest, OnRemoteRequest_003, TestSize.Level3) DTEST_LOG << "result: " << result << std::endl; EXPECT_EQ(ERR_DP_INVALID_PARAMS, result); } + + +HWTEST_F(ProfileChangeNotificationTest, OnRemoteRequest_004, TestSize.Level3) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option { MessageOption::TF_ASYNC }; + SyncResult syncResults; + if (!data.WriteInterfaceToken(ProfileEventNotifierProxy::GetDescriptor())) { + return; + } + if (!data.WriteInt32(static_cast(syncResults.size()))) { + return; + } + + uint32_t code = ProfileEvent::EVENT_SYNC_COMPLETED; + auto syncCb = std::make_shared(); + std::shared_ptr temp = std::make_shared(syncCb); + int32_t result = temp->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ERR_DP_INVALID_PARAMS, result); +} + +HWTEST_F(ProfileChangeNotificationTest, OnRemoteRequest_005, TestSize.Level3) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option { MessageOption::TF_ASYNC }; + SyncResult syncResults; + if (!data.WriteInterfaceToken(ProfileEventNotifierProxy::GetDescriptor())) { + return; + } + if (!data.WriteInt32(static_cast(syncResults.size()))) { + return; + } + + uint32_t code = ProfileEvent::EVENT_PROFILE_CHANGED; + auto syncCb = std::make_shared(); + std::shared_ptr temp = std::make_shared(syncCb); + int32_t result = temp->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ERR_DP_INVALID_PARAMS, result); +} + +HWTEST_F(ProfileChangeNotificationTest, OnRemoteRequest_006, TestSize.Level3) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option { MessageOption::TF_ASYNC }; + SyncResult syncResults; + if (!data.WriteInterfaceToken(ProfileEventNotifierProxy::GetDescriptor())) { + return; + } + if (!data.WriteInt32(static_cast(syncResults.size()))) { + return; + } + + uint32_t code = 1000; + auto syncCb = std::make_shared(); + std::shared_ptr temp = std::make_shared(syncCb); + int32_t result = temp->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(305, result); +} } } \ No newline at end of file -- Gitee From 6fed19fcbe45a7209b7e0db31e1c05be03ee3347 Mon Sep 17 00:00:00 2001 From: wangzhaohao Date: Tue, 13 Aug 2024 12:05:39 +0800 Subject: [PATCH 07/19] add UT Signed-off-by: wangzhaohao --- .../core/test/unittest/profile_utils_test.cpp | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/services/core/test/unittest/profile_utils_test.cpp b/services/core/test/unittest/profile_utils_test.cpp index 218031a4..6ece0c15 100644 --- a/services/core/test/unittest/profile_utils_test.cpp +++ b/services/core/test/unittest/profile_utils_test.cpp @@ -1300,6 +1300,12 @@ HWTEST_F(ProfileUtilsTest, IsPropertyValid005, TestSize.Level1) propertyMap.erase(property); bool res4 = ProfileUtils::IsPropertyValid(propertyMap, property, minValue, maxValue); EXPECT_EQ(false, res4); + + property = "property1"; + value = ""; + propertyMap[property] = value; + bool res5 = ProfileUtils::IsPropertyValid(propertyMap, property, minValue, maxValue); + EXPECT_EQ(false, res5); } /** @@ -1691,5 +1697,49 @@ HWTEST_F(ProfileUtilsTest, EntriesToCharProfile002, TestSize.Level1) int32_t ret2 = ProfileUtils::EntriesToCharProfile(values, profile); EXPECT_EQ(DP_INVALID_PARAMS, ret2); } + +/** + * @tc.name: GetDbKeyByProfile001 + * @tc.desc: + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ProfileUtilsTest, GetDbKeyByProfile001, TestSize.Level1) +{ + CharacteristicProfile charProfile; + charProfile.SetDeviceId("deviceId"); + charProfile.SetServiceName("serviceName"); + charProfile.SetCharacteristicKey("characteristicKey"); + charProfile.SetCharacteristicValue("characteristicValue"); + string dbKey = ""; + string succDbkey = "char#deviceId#serviceName#characteristicKey#characteristicValue"; + string failDbkey = ""; + dbKey = ProfileUtils::GetDbKeyByProfile(charProfile); + EXPECT_EQ(dbKey, succDbkey); + + charProfile.SetCharacteristicKey(""); + dbKey = ProfileUtils::GetDbKeyByProfile(charProfile); + EXPECT_EQ(dbKey, failDbkey); + + charProfile.SetServiceName(""); + dbKey = ProfileUtils::GetDbKeyByProfile(charProfile); + EXPECT_EQ(dbKey, failDbkey); + + charProfile.SetDeviceId(""); + dbKey = ProfileUtils::GetDbKeyByProfile(charProfile); + EXPECT_EQ(dbKey, failDbkey); +} + +/** + * @tc.name: IsNumStr001 + * @tc.desc: + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ProfileUtilsTest, IsNumStr001, TestSize.Level1) +{ + bool isNumStr = ProfileUtils::IsNumStr(""); + EXPECT_EQ(isNumStr,false); +} } // namespace DistributedDeviceProfile } // namespace OHOS -- Gitee From 498ab70c5fdd9168ab940a2f616ddb17b22950c0 Mon Sep 17 00:00:00 2001 From: wangzhaohao Date: Tue, 13 Aug 2024 12:16:26 +0800 Subject: [PATCH 08/19] add UT Signed-off-by: wangzhaohao --- services/core/test/unittest/profile_utils_test.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/services/core/test/unittest/profile_utils_test.cpp b/services/core/test/unittest/profile_utils_test.cpp index 6ece0c15..bf0442b7 100644 --- a/services/core/test/unittest/profile_utils_test.cpp +++ b/services/core/test/unittest/profile_utils_test.cpp @@ -1700,7 +1700,7 @@ HWTEST_F(ProfileUtilsTest, EntriesToCharProfile002, TestSize.Level1) /** * @tc.name: GetDbKeyByProfile001 - * @tc.desc: + * @tc.desc: * @tc.type: FUNC * @tc.require: */ @@ -1732,14 +1732,14 @@ HWTEST_F(ProfileUtilsTest, GetDbKeyByProfile001, TestSize.Level1) /** * @tc.name: IsNumStr001 - * @tc.desc: + * @tc.desc: * @tc.type: FUNC * @tc.require: */ HWTEST_F(ProfileUtilsTest, IsNumStr001, TestSize.Level1) { bool isNumStr = ProfileUtils::IsNumStr(""); - EXPECT_EQ(isNumStr,false); + EXPECT_EQ(isNumStr, false); } } // namespace DistributedDeviceProfile } // namespace OHOS -- Gitee From 509904c027225d9837102320f3f475cbb37fe945 Mon Sep 17 00:00:00 2001 From: torrizo Date: Tue, 13 Aug 2024 06:34:01 +0000 Subject: [PATCH 09/19] update services/core/test/unittest/profile_utils_test.cpp. Signed-off-by: torrizo --- services/core/test/unittest/profile_utils_test.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/services/core/test/unittest/profile_utils_test.cpp b/services/core/test/unittest/profile_utils_test.cpp index b18c3e00..b302a1ba 100644 --- a/services/core/test/unittest/profile_utils_test.cpp +++ b/services/core/test/unittest/profile_utils_test.cpp @@ -64,7 +64,7 @@ HWTEST_F(ProfileUtilsTest, GetDbKeyAnonyString001, TestSize.Level1) { string len2 = ""; string res = ProfileUtils::GetDbKeyAnonyString(len2); - EXPECT_EQ("******", res); + EXPECT_EQ("***", res); } /** @@ -77,7 +77,7 @@ HWTEST_F(ProfileUtilsTest, GetDbKeyAnonyString002, TestSize.Level1) { string len2 = "ab"; string res = ProfileUtils::GetDbKeyAnonyString(len2); - EXPECT_EQ("******", res); + EXPECT_EQ("***", res); } /** @@ -90,7 +90,7 @@ HWTEST_F(ProfileUtilsTest, GetDbKeyAnonyString003, TestSize.Level1) { string len2 = "ab#abc"; string res = ProfileUtils::GetDbKeyAnonyString(len2); - EXPECT_EQ("ab#a******c", res); + EXPECT_EQ("ab#a***c", res); } /** @@ -103,7 +103,7 @@ HWTEST_F(ProfileUtilsTest, GetAnonyString001, TestSize.Level1) { string len2 = "ab"; string res = ProfileUtils::GetAnonyString(len2); - EXPECT_EQ("******", res); + EXPECT_EQ("***", res); } /** @@ -116,7 +116,7 @@ HWTEST_F(ProfileUtilsTest, GetAnonyString002, TestSize.Level1) { string len5 = "abcde"; string res = ProfileUtils::GetAnonyString(len5); - EXPECT_EQ("a******e", res); + EXPECT_EQ("a***e", res); } /** @@ -129,7 +129,7 @@ HWTEST_F(ProfileUtilsTest, GetAnonyString003, TestSize.Level1) { string len22 = "abcdefghijklmnopqrstuv"; string res = ProfileUtils::GetAnonyString(len22); - EXPECT_EQ("abcd******stuv", res); + EXPECT_EQ("abcd***stuv", res); } /** -- Gitee From 84fabfd9931383ed59284c99837ef83bb61de618 Mon Sep 17 00:00:00 2001 From: torrizo Date: Tue, 13 Aug 2024 06:40:41 +0000 Subject: [PATCH 10/19] update old/services/core/test/unittest/subscribe_info_checker_test.cpp. Signed-off-by: torrizo --- .../unittest/subscribe_info_checker_test.cpp | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/old/services/core/test/unittest/subscribe_info_checker_test.cpp b/old/services/core/test/unittest/subscribe_info_checker_test.cpp index 41b5a2d5..8b191729 100644 --- a/old/services/core/test/unittest/subscribe_info_checker_test.cpp +++ b/old/services/core/test/unittest/subscribe_info_checker_test.cpp @@ -213,5 +213,70 @@ HWTEST_F(SubscribeInfoCheckerTest, GetHandler_001, TestSize.Level3) DTEST_LOG << "result: " << result << std::endl; EXPECT_EQ(nullptr, result); } + + +/** + * @tc.name: GetHandler_010 + * @tc.desc: GetHandler + * @tc.type: FUNC + * @tc.require: I4NY1T + */ +HWTEST_F(SubscribeInfoCheckerTest, Check_010, TestSize.Level3) +{ + SubscribeInfo subInfo; + subInfo.extraInfo = { + {"deviceId", "deviceId"} + }; + std::list serviceIds = {"fakeStorage", "fakeSystem"}; + subInfo.profileEvent = ProfileEvent::EVENT_SYNC_COMPLETED; + std::list infos(1, subInfo); + bool ret = SubscribeInfoChecker::GetInstance().Check(infos); + ASSERT_TRUE(ret); +} + +/** + * @tc.name: GetHandler_011 + * @tc.desc: GetHandler + * @tc.type: FUNC + * @tc.require: I4NY1T + */ +HWTEST_F(SubscribeInfoCheckerTest, Check_011, TestSize.Level3) +{ + SubscribeInfo subInfo; + subInfo.extraInfo = { + {"deviceId", "deviceId"} + }; + std::list serviceIds = {"fakeStorage", "fakeSystem"}; + subInfo.profileEvent = ProfileEvent::EVENT_UNKNOWN; + std::list infos(1, subInfo); + bool ret = SubscribeInfoChecker::GetInstance().Check(infos); + ASSERT_FALSE(ret); +} + +/** + * @tc.name: GetHandler_002 + * @tc.desc: GetHandler + * @tc.type: FUNC + * @tc.require: I4NY1T + */ +HWTEST_F(SubscribeInfoCheckerTest, GetHandler_002, TestSize.Level3) +{ + auto result = ProfileEventHandlerFactory::GetInstance().GetHandler(ProfileEvent::EVENT_PROFILE_CHANGED); + DTEST_LOG << "result: " << result << std::endl; + EXPECT_NE(nullptr, result); +} + +/** + * @tc.name: GetHandler_003 + * @tc.desc: GetHandler + * @tc.type: FUNC + * @tc.require: I4NY1T + */ +HWTEST_F(SubscribeInfoCheckerTest, GetHandler_003, TestSize.Level3) +{ + auto result = ProfileEventHandlerFactory::GetInstance().GetHandler(ProfileEvent::EVENT_UNKNOWN); + DTEST_LOG << "result: " << result << std::endl; + EXPECT_EQ(nullptr, result); +} } } \ No newline at end of file -- Gitee From a7dc1b4981f60c1090f16b8059c278f5dfe11914 Mon Sep 17 00:00:00 2001 From: torrizo Date: Tue, 13 Aug 2024 06:42:00 +0000 Subject: [PATCH 11/19] update common/test/profilechangelistenerstubunittest/profile_change_listener_stub_test.cpp. Signed-off-by: torrizo --- .../profile_change_listener_stub_test.cpp | 144 ++++++++++++++++++ 1 file changed, 144 insertions(+) diff --git a/common/test/profilechangelistenerstubunittest/profile_change_listener_stub_test.cpp b/common/test/profilechangelistenerstubunittest/profile_change_listener_stub_test.cpp index 23c8f274..1b3697c4 100644 --- a/common/test/profilechangelistenerstubunittest/profile_change_listener_stub_test.cpp +++ b/common/test/profilechangelistenerstubunittest/profile_change_listener_stub_test.cpp @@ -237,5 +237,149 @@ HWTEST_F(ProfileChangeListenerStubTest, OnCharacteristicProfileUpdateInner_001, int32_t ret = listenerStub_->OnCharacteristicProfileUpdateInner(data, reply); EXPECT_EQ(ERR_FLATTEN_OBJECT, ret); } + + +HWTEST_F(ProfileChangeListenerStubTest, OnRemoteRequest_002, TestSize.Level0) +{ + uint32_t code = static_cast(DPInterfaceCode::ON_TRUST_DEVICE_PROFILE_ADD); + MessageParcel data; + data.WriteInterfaceToken(IProfileChangeListener::GetDescriptor()); + MessageParcel reply; + MessageOption option; + int32_t ret = listenerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ERR_FLATTEN_OBJECT, ret); +} + +HWTEST_F(ProfileChangeListenerStubTest, OnRemoteRequest_003, TestSize.Level0) +{ + uint32_t code = static_cast(DPInterfaceCode::ON_TRUST_DEVICE_PROFILE_DELETE); + MessageParcel data; + data.WriteInterfaceToken(IProfileChangeListener::GetDescriptor()); + MessageParcel reply; + MessageOption option; + int32_t ret = listenerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ERR_FLATTEN_OBJECT, ret); +} + +HWTEST_F(ProfileChangeListenerStubTest, OnRemoteRequest_004, TestSize.Level0) +{ + uint32_t code = static_cast(DPInterfaceCode::ON_TRUST_DEVICE_PROFILE_UPDATE); + MessageParcel data; + data.WriteInterfaceToken(IProfileChangeListener::GetDescriptor()); + MessageParcel reply; + MessageOption option; + int32_t ret = listenerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ERR_FLATTEN_OBJECT, ret); +} + +HWTEST_F(ProfileChangeListenerStubTest, OnRemoteRequest_005, TestSize.Level0) +{ + uint32_t code = static_cast(DPInterfaceCode::ON_DEVICE_PROFILE_ADD); + MessageParcel data; + data.WriteInterfaceToken(IProfileChangeListener::GetDescriptor()); + MessageParcel reply; + MessageOption option; + int32_t ret = listenerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ERR_FLATTEN_OBJECT, ret); +} + +HWTEST_F(ProfileChangeListenerStubTest, OnRemoteRequest_006, TestSize.Level0) +{ + uint32_t code = static_cast(DPInterfaceCode::ON_DEVICE_PROFILE_DELETE); + MessageParcel data; + data.WriteInterfaceToken(IProfileChangeListener::GetDescriptor()); + MessageParcel reply; + MessageOption option; + int32_t ret = listenerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ERR_FLATTEN_OBJECT, ret); +} + +HWTEST_F(ProfileChangeListenerStubTest, OnRemoteRequest_007, TestSize.Level0) +{ + uint32_t code = static_cast(DPInterfaceCode::ON_DEVICE_PROFILE_UPDATE); + MessageParcel data; + data.WriteInterfaceToken(IProfileChangeListener::GetDescriptor()); + MessageParcel reply; + MessageOption option; + int32_t ret = listenerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ERR_FLATTEN_OBJECT, ret); +} + +HWTEST_F(ProfileChangeListenerStubTest, OnRemoteRequest_008, TestSize.Level0) +{ + uint32_t code = static_cast(DPInterfaceCode::ON_SERVICE_PROFILE_ADD); + MessageParcel data; + data.WriteInterfaceToken(IProfileChangeListener::GetDescriptor()); + MessageParcel reply; + MessageOption option; + int32_t ret = listenerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ERR_FLATTEN_OBJECT, ret); +} + +HWTEST_F(ProfileChangeListenerStubTest, OnRemoteRequest_009, TestSize.Level0) +{ + uint32_t code = static_cast(DPInterfaceCode::ON_SERVICE_PROFILE_DELETE); + MessageParcel data; + data.WriteInterfaceToken(IProfileChangeListener::GetDescriptor()); + MessageParcel reply; + MessageOption option; + int32_t ret = listenerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ERR_FLATTEN_OBJECT, ret); +} + +HWTEST_F(ProfileChangeListenerStubTest, OnRemoteRequest_010, TestSize.Level0) +{ + uint32_t code = static_cast(DPInterfaceCode::ON_SERVICE_PROFILE_UPDATE); + MessageParcel data; + data.WriteInterfaceToken(IProfileChangeListener::GetDescriptor()); + MessageParcel reply; + MessageOption option; + int32_t ret = listenerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ERR_FLATTEN_OBJECT, ret); +} + +HWTEST_F(ProfileChangeListenerStubTest, OnRemoteRequest_011, TestSize.Level0) +{ + uint32_t code = static_cast(DPInterfaceCode::ON_CHAR_PROFILE_ADD); + MessageParcel data; + data.WriteInterfaceToken(IProfileChangeListener::GetDescriptor()); + MessageParcel reply; + MessageOption option; + int32_t ret = listenerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ERR_FLATTEN_OBJECT, ret); +} + +HWTEST_F(ProfileChangeListenerStubTest, OnRemoteRequest_012, TestSize.Level0) +{ + uint32_t code = static_cast(DPInterfaceCode::ON_CHAR_PROFILE_DELETE); + MessageParcel data; + data.WriteInterfaceToken(IProfileChangeListener::GetDescriptor()); + MessageParcel reply; + MessageOption option; + int32_t ret = listenerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ERR_FLATTEN_OBJECT, ret); +} + +HWTEST_F(ProfileChangeListenerStubTest, OnRemoteRequest_013, TestSize.Level0) +{ + uint32_t code = static_cast(DPInterfaceCode::ON_CHAR_PROFILE_UPDATE); + MessageParcel data; + data.WriteInterfaceToken(IProfileChangeListener::GetDescriptor()); + MessageParcel reply; + MessageOption option; + int32_t ret = listenerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ERR_FLATTEN_OBJECT, ret); +} + +HWTEST_F(ProfileChangeListenerStubTest, OnRemoteRequest_014, TestSize.Level0) +{ + uint32_t code = 1000; + MessageParcel data; + data.WriteInterfaceToken(IProfileChangeListener::GetDescriptor()); + MessageParcel reply; + MessageOption option; + int32_t ret = listenerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(305, ret); +} } // namespace DistributedDeviceProfile } // namespace OHOS \ No newline at end of file -- Gitee From 341aad8aa48b56d463b9f2b9b5ad5ad35c074f82 Mon Sep 17 00:00:00 2001 From: torrizo Date: Tue, 13 Aug 2024 07:01:20 +0000 Subject: [PATCH 12/19] update services/core/test/unittest/subscribe_profile_manager_test.cpp. Signed-off-by: torrizo --- .../subscribe_profile_manager_test.cpp | 148 ++++++++++++++++++ 1 file changed, 148 insertions(+) diff --git a/services/core/test/unittest/subscribe_profile_manager_test.cpp b/services/core/test/unittest/subscribe_profile_manager_test.cpp index d117a081..d6ee852b 100644 --- a/services/core/test/unittest/subscribe_profile_manager_test.cpp +++ b/services/core/test/unittest/subscribe_profile_manager_test.cpp @@ -772,6 +772,154 @@ HWTEST_F(SubscribeProfileManagerTest, NotifyCharProfileDelete_003, TestSize.Leve int32_t errCode = SubscribeProfileManager::GetInstance().NotifyCharProfileDelete(dbKey, dbValue); EXPECT_EQ(errCode, DP_SUCCESS); } +/* + * @tc.name: NotifyProfileChange_003 + * @tc.desc: Normal testCase of NotifyDeviceProfileAdd for CRUD + * @tc.type: FUNC + * @tc.require: I4NY1T + */ +HWTEST_F(SubscribeProfileManagerTest, NotifyProfileChange_003, TestSize.Level1) +{ + std::string dbKey = ""; + std::string dbValue = ""; + int32_t errCode = SubscribeProfileManager::GetInstance(). + NotifyProfileChange(ProfileType::DEVICE_PROFILE, ChangeType::ADD, dbKey, dbValue); + EXPECT_EQ(errCode, DP_SUCCESS); +} + +/* + * @tc.name: NotifyProfileChange_004 + * @tc.desc: Normal testCase of NotifyDeviceProfileAdd for CRUD + * @tc.type: FUNC + * @tc.require: I4NY1T + */ +HWTEST_F(SubscribeProfileManagerTest, NotifyProfileChange_004, TestSize.Level1) +{ + std::string dbKey = ""; + std::string dbValue = ""; + int32_t errCode = SubscribeProfileManager::GetInstance(). + NotifyProfileChange(ProfileType::DEVICE_PROFILE, ChangeType::UPDATE, dbKey, dbValue); + EXPECT_EQ(errCode, DP_SUCCESS); +} + +/* + * @tc.name: NotifyProfileChange_005 + * @tc.desc: Normal testCase of NotifyDeviceProfileAdd for CRUD + * @tc.type: FUNC + * @tc.require: I4NY1T + */ +HWTEST_F(SubscribeProfileManagerTest, NotifyProfileChange_005, TestSize.Level1) +{ + std::string dbKey = ""; + std::string dbValue = ""; + int32_t errCode = SubscribeProfileManager::GetInstance(). + NotifyProfileChange(ProfileType::DEVICE_PROFILE, ChangeType::DELETE, dbKey, dbValue); + EXPECT_EQ(errCode, DP_SUCCESS); +} + +/* + * @tc.name: NotifyProfileChange_006 + * @tc.desc: Normal testCase of NotifyDeviceProfileAdd for CRUD + * @tc.type: FUNC + * @tc.require: I4NY1T + */ +HWTEST_F(SubscribeProfileManagerTest, NotifyProfileChange_006, TestSize.Level1) +{ + std::string dbKey = ""; + std::string dbValue = ""; + int32_t errCode = SubscribeProfileManager::GetInstance(). + NotifyProfileChange(ProfileType::SERVICE_PROFILE, ChangeType::ADD, dbKey, dbValue); + EXPECT_EQ(errCode, DP_SUCCESS); +} + +/* + * @tc.name: NotifyProfileChange_007 + * @tc.desc: Normal testCase of NotifyDeviceProfileAdd for CRUD + * @tc.type: FUNC + * @tc.require: I4NY1T + */ +HWTEST_F(SubscribeProfileManagerTest, NotifyProfileChange_007, TestSize.Level1) +{ + std::string dbKey = ""; + std::string dbValue = ""; + int32_t errCode = SubscribeProfileManager::GetInstance(). + NotifyProfileChange(ProfileType::SERVICE_PROFILE, ChangeType::UPDATE, dbKey, dbValue); + EXPECT_EQ(errCode, DP_SUCCESS); +} +/* + * @tc.name: NotifyProfileChange_008 + * @tc.desc: Normal testCase of NotifyDeviceProfileAdd for CRUD + * @tc.type: FUNC + * @tc.require: I4NY1T + */ +HWTEST_F(SubscribeProfileManagerTest, NotifyProfileChange_008, TestSize.Level1) +{ + std::string dbKey = ""; + std::string dbValue = ""; + int32_t errCode = SubscribeProfileManager::GetInstance(). + NotifyProfileChange(ProfileType::SERVICE_PROFILE, ChangeType::DELETE, dbKey, dbValue); + EXPECT_EQ(errCode, DP_SUCCESS); +} + +/* + * @tc.name: NotifyProfileChange_009 + * @tc.desc: Normal testCase of NotifyDeviceProfileAdd for CRUD + * @tc.type: FUNC + * @tc.require: I4NY1T + */ +HWTEST_F(SubscribeProfileManagerTest, NotifyProfileChange_009, TestSize.Level1) +{ + std::string dbKey = ""; + std::string dbValue = ""; + int32_t errCode = SubscribeProfileManager::GetInstance(). + NotifyProfileChange(ProfileType::CHAR_PROFILE, ChangeType::ADD, dbKey, dbValue); + EXPECT_EQ(errCode, DP_SUCCESS); +} + +/* + * @tc.name: NotifyProfileChange_010 + * @tc.desc: Normal testCase of NotifyDeviceProfileAdd for CRUD + * @tc.type: FUNC + * @tc.require: I4NY1T + */ +HWTEST_F(SubscribeProfileManagerTest, NotifyProfileChange_010, TestSize.Level1) +{ + std::string dbKey = ""; + std::string dbValue = ""; + int32_t errCode = SubscribeProfileManager::GetInstance(). + NotifyProfileChange(ProfileType::CHAR_PROFILE, ChangeType::UPDATE, dbKey, dbValue); + EXPECT_EQ(errCode, DP_SUCCESS); +} + +/* + * @tc.name: NotifyProfileChange_011 + * @tc.desc: Normal testCase of NotifyDeviceProfileAdd for CRUD + * @tc.type: FUNC + * @tc.require: I4NY1T + */ +HWTEST_F(SubscribeProfileManagerTest, NotifyProfileChange_011, TestSize.Level1) +{ + std::string dbKey = ""; + std::string dbValue = ""; + int32_t errCode = SubscribeProfileManager::GetInstance(). + NotifyProfileChange(ProfileType::CHAR_PROFILE, ChangeType::DELETE, dbKey, dbValue); + EXPECT_EQ(errCode, DP_SUCCESS); +} + +/* + * @tc.name: NotifyProfileChange_012 + * @tc.desc: Normal testCase of NotifyDeviceProfileAdd for CRUD + * @tc.type: FUNC + * @tc.require: I4NY1T + */ +HWTEST_F(SubscribeProfileManagerTest, NotifyProfileChange_012, TestSize.Level1) +{ + std::string dbKey = ""; + std::string dbValue = ""; + int32_t errCode = SubscribeProfileManager::GetInstance(). + NotifyProfileChange(ProfileType::CHAR_PROFILE, ChangeType::CHANGE_TYPE_MIN, dbKey, dbValue); + EXPECT_EQ(errCode, DP_INVALID_PARAMS); +} } } \ No newline at end of file -- Gitee From 30553d568c45feb88f213c2711c07fb18498ea8b Mon Sep 17 00:00:00 2001 From: torrizo Date: Tue, 13 Aug 2024 07:02:02 +0000 Subject: [PATCH 13/19] update services/core/test/unittest/subscribe_profile_manager_test.cpp. Signed-off-by: torrizo --- services/core/test/unittest/subscribe_profile_manager_test.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/services/core/test/unittest/subscribe_profile_manager_test.cpp b/services/core/test/unittest/subscribe_profile_manager_test.cpp index d6ee852b..5ce12e91 100644 --- a/services/core/test/unittest/subscribe_profile_manager_test.cpp +++ b/services/core/test/unittest/subscribe_profile_manager_test.cpp @@ -772,6 +772,7 @@ HWTEST_F(SubscribeProfileManagerTest, NotifyCharProfileDelete_003, TestSize.Leve int32_t errCode = SubscribeProfileManager::GetInstance().NotifyCharProfileDelete(dbKey, dbValue); EXPECT_EQ(errCode, DP_SUCCESS); } + /* * @tc.name: NotifyProfileChange_003 * @tc.desc: Normal testCase of NotifyDeviceProfileAdd for CRUD -- Gitee From 50d6cf10870c1472ae772cb0fc55c22d721360ab Mon Sep 17 00:00:00 2001 From: wangzhaohao Date: Thu, 15 Aug 2024 16:40:16 +0800 Subject: [PATCH 14/19] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=AB=AF=E7=AB=AF?= =?UTF-8?q?=E5=90=8C=E6=AD=A5=E5=85=9C=E5=BA=95=E6=96=B9=E6=A1=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangzhaohao --- .../utils/content_sensor_manager_utils.h | 4 ++ .../utils/content_sensor_manager_utils.cpp | 24 +++++++++- .../device_profile_manager.h | 1 + .../static_profile_manager.h | 2 + .../device_profile_manager.cpp | 45 ++++++++++++++++++- .../static_profile_manager.cpp | 36 +++++++++++++++ services/core/src/utils/profile_cache.cpp | 1 + 7 files changed, 110 insertions(+), 3 deletions(-) diff --git a/common/include/utils/content_sensor_manager_utils.h b/common/include/utils/content_sensor_manager_utils.h index 07387f9e..ac942e3a 100644 --- a/common/include/utils/content_sensor_manager_utils.h +++ b/common/include/utils/content_sensor_manager_utils.h @@ -18,6 +18,7 @@ #include #include +#include #include "single_instance.h" namespace OHOS { @@ -33,6 +34,8 @@ public: std::string ObtainOsFullName(); std::string ObtainDisplayVersion(); std::string ObtainLocalUdid(); + void ObtainDeviceDataSyncMode(); + bool IsDeviceE2ESync(); private: std::string deviceModel_ = ""; @@ -43,6 +46,7 @@ private: std::string osFullName_ = ""; std::string displayVersion_ = ""; std::string localUdid_ = ""; + std::atomic isDeviceE2ESync_ {false}; std::mutex csMutex_; }; } diff --git a/common/src/utils/content_sensor_manager_utils.cpp b/common/src/utils/content_sensor_manager_utils.cpp index f03544a5..f794cf15 100644 --- a/common/src/utils/content_sensor_manager_utils.cpp +++ b/common/src/utils/content_sensor_manager_utils.cpp @@ -13,6 +13,7 @@ * limitations under the License. */ +#include #include "content_sensor_manager_utils.h" #include "parameter.h" #include "distributed_device_profile_log.h" @@ -21,7 +22,11 @@ namespace OHOS { namespace DistributedDeviceProfile { namespace { const std::string TAG = "ContentSensorManagerUtils"; + const char* SYS_SETTINGS_DATA_SYNC = "persist.distributed_scene.sys_settings_data_sync"; + const char* UNDEFINED_VALUE = "undefined"; + const char* SYNC_TYPE_E2E = "1"; constexpr int32_t DEVICE_UUID_LENGTH = 65; + constexpr int32_t IT_BOOK_PARAM_LEN = 128; } IMPLEMENT_SINGLE_INSTANCE(ContentSensorManagerUtils); std::string ContentSensorManagerUtils::ObtainProductModel() @@ -155,5 +160,22 @@ std::string ContentSensorManagerUtils::ObtainLocalUdid() localUdid_ = localUdidTemp; return localUdid_; } + +void ContentSensorManagerUtils::ObtainDeviceDataSyncMode() +{ + char isITBookparam[IT_BOOK_PARAM_LEN + 1] = {0}; + int ret = GetParameter(SYS_SETTINGS_DATA_SYNC, UNDEFINED_VALUE, isITBookparam, IT_BOOK_PARAM_LEN); + if (ret > 0 && strncmp(isITBookparam, SYNC_TYPE_E2E, strlen(SYNC_TYPE_E2E)) == 0) { + isDeviceE2ESync_.store(true); + HILOGI("Determining the e2e device succeeded."); + return; + } + HILOGI("Determining the e2e device failed."); +} + +bool ContentSensorManagerUtils::IsDeviceE2ESync() +{ + return isDeviceE2ESync_.load(); +} } // namespace DistributedDeviceProfile -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/services/core/include/deviceprofilemanager/device_profile_manager.h b/services/core/include/deviceprofilemanager/device_profile_manager.h index 8fe7726e..b1c8eab3 100644 --- a/services/core/include/deviceprofilemanager/device_profile_manager.h +++ b/services/core/include/deviceprofilemanager/device_profile_manager.h @@ -81,6 +81,7 @@ private: void AddToPutTempCache(const std::map& values); void FixDataOnDeviceOnline(const DistributedHardware::DmDeviceInfo deviceInfo); void NotifyNotOHBaseP2pOnline(const DistributedHardware::DmDeviceInfo deviceInfo); + void E2ESyncDynamicProfile(const DistributedHardware::DmDeviceInfo deviceInfo); bool isAdapterSoLoaded_ = false; std::mutex isAdapterLoadLock_; std::mutex dynamicStoreMutex_; diff --git a/services/core/include/deviceprofilemanager/static_profile_manager.h b/services/core/include/deviceprofilemanager/static_profile_manager.h index b6e4b2cd..7b4147a3 100644 --- a/services/core/include/deviceprofilemanager/static_profile_manager.h +++ b/services/core/include/deviceprofilemanager/static_profile_manager.h @@ -17,6 +17,7 @@ #define OHOS_DP_STATIC_PROFILE_MANAGER_H #include "characteristic_profile.h" +#include "dm_device_info.h" #include "kv_adapter.h" #include "single_instance.h" @@ -33,6 +34,7 @@ public: int32_t GetCharacteristicProfile(const std::string& deviceId, const std::string& serviceName, const std::string& characteristicKey, CharacteristicProfile& charProfile); int32_t GetAllCharacteristicProfile(std::vector& staticCapabilityProfiles); + void E2ESyncStaticProfile(const DistributedHardware::DmDeviceInfo deviceInfo); private: int32_t GenerateStaticInfoProfile(const CharacteristicProfile& staticCapabilityProfile, diff --git a/services/core/src/deviceprofilemanager/device_profile_manager.cpp b/services/core/src/deviceprofilemanager/device_profile_manager.cpp index b0c30d7a..40f6d04d 100644 --- a/services/core/src/deviceprofilemanager/device_profile_manager.cpp +++ b/services/core/src/deviceprofilemanager/device_profile_manager.cpp @@ -16,22 +16,24 @@ #include "device_profile_manager.h" #include -#include "datetime_ex.h" #include #include #include +#include "datetime_ex.h" #include "dm_constants.h" #include "content_sensor_manager_utils.h" #include "distributed_device_profile_errors.h" #include "distributed_device_profile_log.h" +#include "event_handler_factory.h" #include "i_sync_completed_callback.h" #include "kv_adapter.h" #include "permission_manager.h" -#include "profile_utils.h" #include "profile_cache.h" #include "profile_control_utils.h" +#include "profile_utils.h" +#include "static_profile_manager.h" namespace OHOS { namespace DistributedDeviceProfile { @@ -641,6 +643,11 @@ void DeviceProfileManager::OnDeviceOnline(const DistributedHardware::DmDeviceInf { FixDataOnDeviceOnline(deviceInfo); NotifyNotOHBaseP2pOnline(deviceInfo); + if (ContentSensorManagerUtils::GetInstance().IsDeviceE2ESync()) { + HILOGI("need E2ESync!"); + E2ESyncDynamicProfile(deviceInfo); + StaticProfileManager::GetInstance().E2ESyncStaticProfile(deviceInfo); + } } void DeviceProfileManager::FixDataOnDeviceOnline(const DistributedHardware::DmDeviceInfo deviceInfo) @@ -726,5 +733,39 @@ void DeviceProfileManager::NotifyNotOHBaseP2pOnline(const DistributedHardware::D }; std::thread(task).detach(); } + +void DeviceProfileManager::E2ESyncDynamicProfile(const DistributedHardware::DmDeviceInfo deviceInfo) +{ + HILOGD("call!"); + auto task = [this, deviceInfo]() { + std::string remoteNetworkId = deviceInfo.networkId; + HILOGD("networkId:%{public}s", ProfileUtils::GetAnonyString(remoteNetworkId).c_str()); + if (remoteNetworkId.empty()) { + HILOGE("networkId or extraData is empty!"); + return; + } + if (!ProfileUtils::IsOHBasedDevice(deviceInfo.extraData)) { + HILOGI("device not is ohbase. remoteNetworkId=%{public}s", + ProfileUtils::GetAnonyString(remoteNetworkId).c_str()); + return; + } + std::lock_guard lock(dynamicStoreMutex_); + if (deviceProfileStore_ == nullptr) { + HILOGE("deviceProfileStore is nullptr"); + return; + } + int32_t syncResult = deviceProfileStore_->Sync({remoteNetworkId}, SyncMode::PUSH_PULL); + if (syncResult != DP_SUCCESS) { + HILOGE("E2ESyncDynamicProfile fail, res: %{public}d!", syncResult); + return; + } + HILOGI("E2ESyncDynamicProfile success!"); + }; + auto handler = EventHandlerFactory::GetInstance().GetEventHandler(); + if (handler == nullptr || !handler->PostTask(task)) { + HILOGE("Post E2ESyncDynamicProfile task fail!"); + return; + } +} } // namespace DeviceProfile } // namespace OHOS diff --git a/services/core/src/deviceprofilemanager/static_profile_manager.cpp b/services/core/src/deviceprofilemanager/static_profile_manager.cpp index fb322cb0..73b0e698 100644 --- a/services/core/src/deviceprofilemanager/static_profile_manager.cpp +++ b/services/core/src/deviceprofilemanager/static_profile_manager.cpp @@ -23,6 +23,7 @@ #include "distributed_device_profile_errors.h" #include "distributed_device_profile_log.h" +#include "event_handler_factory.h" #include "kv_data_change_listener.h" #include "kv_store_death_recipient.h" #include "kv_sync_completed_listener.h" @@ -30,6 +31,7 @@ #include "profile_cache.h" #include "profile_control_utils.h" #include "profile_utils.h" +#include "permission_manager.h" #include "static_capability_loader.h" namespace OHOS { @@ -183,5 +185,39 @@ int32_t StaticProfileManager::GenerateStaticInfoProfile(const CharacteristicProf staticCapabilityValue, staticCapabilityVersion, staticInfoProfiles); return DP_SUCCESS; } + +void StaticProfileManager::E2ESyncStaticProfile(const DistributedHardware::DmDeviceInfo deviceInfo) +{ + HILOGD("call!"); + auto task = [this, deviceInfo]() { + std::string remoteNetworkId = deviceInfo.networkId; + HILOGD("networkId:%{public}s", ProfileUtils::GetAnonyString(remoteNetworkId).c_str()); + if (remoteNetworkId.empty()) { + HILOGE("networkId or extraData is empty!"); + return; + } + if (!ProfileUtils::IsOHBasedDevice(deviceInfo.extraData)) { + HILOGI("device not is ohbase. remoteNetworkId=%{public}s", + ProfileUtils::GetAnonyString(remoteNetworkId).c_str()); + return; + } + std::lock_guard lock(staticStoreMutex_); + if (staticProfileStore_ == nullptr) { + HILOGE("staticProfileStore is nullptr"); + return; + } + int32_t syncResult = staticProfileStore_->Sync({remoteNetworkId}, SyncMode::PUSH_PULL); + if (syncResult != DP_SUCCESS) { + HILOGE("E2ESyncStaticProfile fail, res: %{public}d!", syncResult); + return; + } + HILOGI("E2ESyncStaticProfile success!"); + }; + auto handler = EventHandlerFactory::GetInstance().GetEventHandler(); + if (handler == nullptr || !handler->PostTask(task)) { + HILOGE("Post E2ESyncStaticProfile task fail!"); + return; + } +} } // namespace DistributedDeviceProfile } // namespace OHOS diff --git a/services/core/src/utils/profile_cache.cpp b/services/core/src/utils/profile_cache.cpp index d2daee67..19b0b71b 100644 --- a/services/core/src/utils/profile_cache.cpp +++ b/services/core/src/utils/profile_cache.cpp @@ -41,6 +41,7 @@ int32_t ProfileCache::Init() { HILOGI("call!"); RefreshProfileCache(); + ContentSensorManagerUtils::GetInstance().ObtainDeviceDataSyncMode(); syncListenerDeathRecipient_ = sptr(new SyncSubscriberDeathRecipient); std::vector allOnlineDeviceInfo; int32_t res = -- Gitee From ccdbd6069cfe4804f11d1b2946d437e70a9be3c2 Mon Sep 17 00:00:00 2001 From: wangzhaohao Date: Thu, 15 Aug 2024 17:35:39 +0800 Subject: [PATCH 15/19] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=A3=80=E8=A7=86?= =?UTF-8?q?=E6=84=8F=E8=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangzhaohao --- common/include/utils/content_sensor_manager_utils.h | 4 ++-- common/src/utils/content_sensor_manager_utils.cpp | 2 +- .../core/src/deviceprofilemanager/device_profile_manager.cpp | 2 +- .../core/src/deviceprofilemanager/static_profile_manager.cpp | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/common/include/utils/content_sensor_manager_utils.h b/common/include/utils/content_sensor_manager_utils.h index ac942e3a..eb776b24 100644 --- a/common/include/utils/content_sensor_manager_utils.h +++ b/common/include/utils/content_sensor_manager_utils.h @@ -16,9 +16,9 @@ #ifndef OHOS_DP_CONTENT_SENSOR_MANAGER_UTILS_H #define OHOS_DP_CONTENT_SENSOR_MANAGER_UTILS_H -#include -#include #include +#include +#include #include "single_instance.h" namespace OHOS { diff --git a/common/src/utils/content_sensor_manager_utils.cpp b/common/src/utils/content_sensor_manager_utils.cpp index f794cf15..fa98eeff 100644 --- a/common/src/utils/content_sensor_manager_utils.cpp +++ b/common/src/utils/content_sensor_manager_utils.cpp @@ -170,7 +170,7 @@ void ContentSensorManagerUtils::ObtainDeviceDataSyncMode() HILOGI("Determining the e2e device succeeded."); return; } - HILOGI("Determining the e2e device failed."); + HILOGW("Determining not is e2e device"); } bool ContentSensorManagerUtils::IsDeviceE2ESync() diff --git a/services/core/src/deviceprofilemanager/device_profile_manager.cpp b/services/core/src/deviceprofilemanager/device_profile_manager.cpp index 40f6d04d..f8878a4a 100644 --- a/services/core/src/deviceprofilemanager/device_profile_manager.cpp +++ b/services/core/src/deviceprofilemanager/device_profile_manager.cpp @@ -745,7 +745,7 @@ void DeviceProfileManager::E2ESyncDynamicProfile(const DistributedHardware::DmDe return; } if (!ProfileUtils::IsOHBasedDevice(deviceInfo.extraData)) { - HILOGI("device not is ohbase. remoteNetworkId=%{public}s", + HILOGI("device is not ohbase. remoteNetworkId=%{public}s", ProfileUtils::GetAnonyString(remoteNetworkId).c_str()); return; } diff --git a/services/core/src/deviceprofilemanager/static_profile_manager.cpp b/services/core/src/deviceprofilemanager/static_profile_manager.cpp index 73b0e698..623385e2 100644 --- a/services/core/src/deviceprofilemanager/static_profile_manager.cpp +++ b/services/core/src/deviceprofilemanager/static_profile_manager.cpp @@ -197,7 +197,7 @@ void StaticProfileManager::E2ESyncStaticProfile(const DistributedHardware::DmDev return; } if (!ProfileUtils::IsOHBasedDevice(deviceInfo.extraData)) { - HILOGI("device not is ohbase. remoteNetworkId=%{public}s", + HILOGI("device is not ohbase. remoteNetworkId=%{public}s", ProfileUtils::GetAnonyString(remoteNetworkId).c_str()); return; } -- Gitee From 1cf71e60889649c4de2780ae55f547d3d42481c0 Mon Sep 17 00:00:00 2001 From: wangzhaohao Date: Thu, 15 Aug 2024 17:38:02 +0800 Subject: [PATCH 16/19] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=A3=80=E8=A7=86?= =?UTF-8?q?=E6=84=8F=E8=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangzhaohao --- common/include/utils/content_sensor_manager_utils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/include/utils/content_sensor_manager_utils.h b/common/include/utils/content_sensor_manager_utils.h index eb776b24..0e44572a 100644 --- a/common/include/utils/content_sensor_manager_utils.h +++ b/common/include/utils/content_sensor_manager_utils.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-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 -- Gitee From 78a3557b1f42f2b172f5b40a748894ffbd304216 Mon Sep 17 00:00:00 2001 From: wangzhaohao Date: Thu, 15 Aug 2024 20:09:47 +0800 Subject: [PATCH 17/19] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=A3=80=E8=A7=86?= =?UTF-8?q?=E6=84=8F=E8=A7=81=EF=BC=8C=E6=B7=BB=E5=8A=A0=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E5=92=8C=E5=A4=B4=E6=96=87=E4=BB=B6=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangzhaohao --- common/src/utils/content_sensor_manager_utils.cpp | 5 ++++- .../core/src/deviceprofilemanager/device_profile_manager.cpp | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/common/src/utils/content_sensor_manager_utils.cpp b/common/src/utils/content_sensor_manager_utils.cpp index fa98eeff..2139a0e9 100644 --- a/common/src/utils/content_sensor_manager_utils.cpp +++ b/common/src/utils/content_sensor_manager_utils.cpp @@ -13,9 +13,12 @@ * limitations under the License. */ -#include #include "content_sensor_manager_utils.h" + +#include + #include "parameter.h" + #include "distributed_device_profile_log.h" namespace OHOS { diff --git a/services/core/src/deviceprofilemanager/device_profile_manager.cpp b/services/core/src/deviceprofilemanager/device_profile_manager.cpp index f8878a4a..7d3f7ff3 100644 --- a/services/core/src/deviceprofilemanager/device_profile_manager.cpp +++ b/services/core/src/deviceprofilemanager/device_profile_manager.cpp @@ -644,7 +644,7 @@ void DeviceProfileManager::OnDeviceOnline(const DistributedHardware::DmDeviceInf FixDataOnDeviceOnline(deviceInfo); NotifyNotOHBaseP2pOnline(deviceInfo); if (ContentSensorManagerUtils::GetInstance().IsDeviceE2ESync()) { - HILOGI("need E2ESync!"); + HILOGI("need E2ESync, networkId:%{public}s", ProfileUtils::GetAnonyString(deviceInfo.networkId).c_str()); E2ESyncDynamicProfile(deviceInfo); StaticProfileManager::GetInstance().E2ESyncStaticProfile(deviceInfo); } -- Gitee From 039c5931dd54e3c727c617522c72f95ec4e78b1e Mon Sep 17 00:00:00 2001 From: wangzhaohao Date: Thu, 15 Aug 2024 22:38:02 +0800 Subject: [PATCH 18/19] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=A3=80=E8=A7=86?= =?UTF-8?q?=E6=84=8F=E8=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangzhaohao --- common/src/utils/content_sensor_manager_utils.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/common/src/utils/content_sensor_manager_utils.cpp b/common/src/utils/content_sensor_manager_utils.cpp index 2139a0e9..3d7c4181 100644 --- a/common/src/utils/content_sensor_manager_utils.cpp +++ b/common/src/utils/content_sensor_manager_utils.cpp @@ -29,7 +29,7 @@ namespace { const char* UNDEFINED_VALUE = "undefined"; const char* SYNC_TYPE_E2E = "1"; constexpr int32_t DEVICE_UUID_LENGTH = 65; - constexpr int32_t IT_BOOK_PARAM_LEN = 128; + constexpr int32_t SYS_SETTINGS_DATA_SYNC_PARAM_LEN = 128; } IMPLEMENT_SINGLE_INSTANCE(ContentSensorManagerUtils); std::string ContentSensorManagerUtils::ObtainProductModel() @@ -166,14 +166,15 @@ std::string ContentSensorManagerUtils::ObtainLocalUdid() void ContentSensorManagerUtils::ObtainDeviceDataSyncMode() { - char isITBookparam[IT_BOOK_PARAM_LEN + 1] = {0}; - int ret = GetParameter(SYS_SETTINGS_DATA_SYNC, UNDEFINED_VALUE, isITBookparam, IT_BOOK_PARAM_LEN); - if (ret > 0 && strncmp(isITBookparam, SYNC_TYPE_E2E, strlen(SYNC_TYPE_E2E)) == 0) { + char isE2EDeviceParam[SYS_SETTINGS_DATA_SYNC_PARAM_LEN + 1] = {0}; + int ret = GetParameter(SYS_SETTINGS_DATA_SYNC, UNDEFINED_VALUE, isE2EDeviceParam, + SYS_SETTINGS_DATA_SYNC_PARAM_LEN); + if (ret > 0 && strncmp(isE2EDeviceParam, SYNC_TYPE_E2E, strlen(SYNC_TYPE_E2E)) == 0) { isDeviceE2ESync_.store(true); HILOGI("Determining the e2e device succeeded."); return; } - HILOGW("Determining not is e2e device"); + HILOGW("Determining is not e2e device"); } bool ContentSensorManagerUtils::IsDeviceE2ESync() -- Gitee From f7f9cb2c3b5c66e46c155e1bd445fe359a098927 Mon Sep 17 00:00:00 2001 From: wangzhaohao Date: Thu, 15 Aug 2024 23:42:43 +0800 Subject: [PATCH 19/19] =?UTF-8?q?ObtainDeviceDataSyncMode=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E6=8F=90=E5=89=8D=E8=B0=83=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangzhaohao --- services/core/src/utils/profile_cache.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/core/src/utils/profile_cache.cpp b/services/core/src/utils/profile_cache.cpp index 19b0b71b..0d819836 100644 --- a/services/core/src/utils/profile_cache.cpp +++ b/services/core/src/utils/profile_cache.cpp @@ -40,8 +40,8 @@ namespace { int32_t ProfileCache::Init() { HILOGI("call!"); - RefreshProfileCache(); ContentSensorManagerUtils::GetInstance().ObtainDeviceDataSyncMode(); + RefreshProfileCache(); syncListenerDeathRecipient_ = sptr(new SyncSubscriberDeathRecipient); std::vector allOnlineDeviceInfo; int32_t res = -- Gitee