diff --git a/common/include/utils/content_sensor_manager_utils.h b/common/include/utils/content_sensor_manager_utils.h index 07387f9e5b134aefbe80050ee499da89144fef7b..0e44572a1c0087504d773e54615ee7d2c85d642e 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 @@ -16,8 +16,9 @@ #ifndef OHOS_DP_CONTENT_SENSOR_MANAGER_UTILS_H #define OHOS_DP_CONTENT_SENSOR_MANAGER_UTILS_H -#include +#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 f03544a5fb9a73044bcbc0bc216189a29b4deff7..3d7c418151f07f4301102cfa98ab3f7f5b060ea5 100644 --- a/common/src/utils/content_sensor_manager_utils.cpp +++ b/common/src/utils/content_sensor_manager_utils.cpp @@ -14,14 +14,22 @@ */ #include "content_sensor_manager_utils.h" + +#include + #include "parameter.h" + #include "distributed_device_profile_log.h" 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 SYS_SETTINGS_DATA_SYNC_PARAM_LEN = 128; } IMPLEMENT_SINGLE_INSTANCE(ContentSensorManagerUtils); std::string ContentSensorManagerUtils::ObtainProductModel() @@ -155,5 +163,23 @@ std::string ContentSensorManagerUtils::ObtainLocalUdid() localUdid_ = localUdidTemp; return localUdid_; } + +void ContentSensorManagerUtils::ObtainDeviceDataSyncMode() +{ + 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 is not e2e device"); +} + +bool ContentSensorManagerUtils::IsDeviceE2ESync() +{ + return isDeviceE2ESync_.load(); +} } // namespace DistributedDeviceProfile -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/common/test/profilechangelistenerstubunittest/profile_change_listener_stub_test.cpp b/common/test/profilechangelistenerstubunittest/profile_change_listener_stub_test.cpp index 23c8f274e4d238c48304f6dd0406afdd0339fbd2..1b3697c4a3730ddc48afd0ea244f68f4bcde5b14 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 diff --git a/old/services/core/test/BUILD.gn b/old/services/core/test/BUILD.gn index c5dc895089d5fd34b4c59ab2f8748fd714939574..6de4af778adda02dd16fc1be2f58fee74d9f061b 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", 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 0000000000000000000000000000000000000000..8b9675d2155179912ae0c1f68ab9f3d9b4a33f08 --- /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 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 407387a291b99e622c6712b6cddabe5ed4d42450..17034f22e96ccbe4a9232f1d7f40405990ffc9f3 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 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 41b5a2d5753f4c229b923afe4f5015f06d51536b..8b1917295d42bfe34f92a16a498a9176133e39a8 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 diff --git a/services/core/include/deviceprofilemanager/device_profile_manager.h b/services/core/include/deviceprofilemanager/device_profile_manager.h index 8fe7726edaf970ef45f36930ff0ff9e0335b3cd4..b1c8eab3a6079fd5ecec852661f40b17decea8a3 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 b6e4b2cdb80f7646d0571b012496c07579c515db..7b4147a32add798f0ea456418e50e1579c358278 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 b0c30d7ae198621e8e8fd7c2538d39cfdc233d90..7d3f7ff328f81940a589ed16f7cab828422a8181 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, networkId:%{public}s", ProfileUtils::GetAnonyString(deviceInfo.networkId).c_str()); + 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 is not 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 fb322cb074cf80572bc340eba36cc2083cde8669..623385e22fcf757c5c7718d2d2141a9e431b9862 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 is not 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 d2daee675eb14d71e3f23de921806e980fd94ed7..0d819836e87a64be6dd5858cdd6bae7bdc436f68 100644 --- a/services/core/src/utils/profile_cache.cpp +++ b/services/core/src/utils/profile_cache.cpp @@ -40,6 +40,7 @@ namespace { int32_t ProfileCache::Init() { HILOGI("call!"); + ContentSensorManagerUtils::GetInstance().ObtainDeviceDataSyncMode(); RefreshProfileCache(); syncListenerDeathRecipient_ = sptr(new SyncSubscriberDeathRecipient); std::vector allOnlineDeviceInfo; diff --git a/services/core/test/unittest/device_profile_manager_test.cpp b/services/core/test/unittest/device_profile_manager_test.cpp index 3a023b006d5e72cdace976c46d1608822fd31672..7bb404dabf8cbbd08ed24114d8aa77fc1c23fce1 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/distributed_device_profile_stub_new_test.cpp b/services/core/test/unittest/distributed_device_profile_stub_new_test.cpp index 6917ece9dcc0186b358cb0cae415320df7910c51..d68167ea26574e7fd177eafcf87f52a049dbb0f2 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 diff --git a/services/core/test/unittest/dp_profile_service_test.cpp b/services/core/test/unittest/dp_profile_service_test.cpp index d38d0527521f78e47b79f7b2d67ae153435ce8ab..2142bcc108b9caa5ae1d02ba0ad42d34601dcd45 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,7 @@ 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 +295,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 b18c3e00ccea0aae660ad300f301c04983c0465e..a20f3da295635fea1cf876b20f0a0adfaf53bbad 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); } /** @@ -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. @@ -1150,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); } /** @@ -1541,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 diff --git a/services/core/test/unittest/subscribe_profile_manager_test.cpp b/services/core/test/unittest/subscribe_profile_manager_test.cpp index d117a08168f8dbd62cc1b93e1c979e14997d4eb7..5ce12e91196694434f90ec01fc359b20f44b7580 100644 --- a/services/core/test/unittest/subscribe_profile_manager_test.cpp +++ b/services/core/test/unittest/subscribe_profile_manager_test.cpp @@ -773,5 +773,154 @@ HWTEST_F(SubscribeProfileManagerTest, NotifyCharProfileDelete_003, TestSize.Leve 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