From d3827e186106845f1a1ee19ed446ff182accefea Mon Sep 17 00:00:00 2001 From: torrizo Date: Fri, 22 Nov 2024 09:11:47 +0000 Subject: [PATCH] add ut Signed-off-by: torrizo --- common/test/deviceprofileunittest/BUILD.gn | 5 +- .../device_profile_test.cpp | 36 ++- .../BUILD.gn | 5 +- .../profile_change_listener_stub_test.cpp | 35 ++- services/core/test/BUILD.gn | 22 ++ .../unittest/device_profile_manager_test.cpp | 58 ++++ .../unittest/dp_account_common_event_test.cpp | 280 ++++++++++++++++++ .../test/unittest/dp_subscribe_info_test.cpp | 18 ++ .../test/unittest/multi_user_manager_test.cpp | 118 ++++++++ .../profile_change_listener_proxy_test.cpp | 15 + 10 files changed, 588 insertions(+), 4 deletions(-) create mode 100644 services/core/test/unittest/dp_account_common_event_test.cpp create mode 100644 services/core/test/unittest/multi_user_manager_test.cpp diff --git a/common/test/deviceprofileunittest/BUILD.gn b/common/test/deviceprofileunittest/BUILD.gn index 6e9eb0e5..d953091f 100644 --- a/common/test/deviceprofileunittest/BUILD.gn +++ b/common/test/deviceprofileunittest/BUILD.gn @@ -20,7 +20,10 @@ module_output_path = "device_info_manager/commontest" ohos_unittest("DeviceProfileTest") { module_out_path = module_output_path - + cflags = [ + "-Dprivate=public", + "-Dprotected=public", + ] include_dirs = [ "include/interfaces", "include/constants", diff --git a/common/test/deviceprofileunittest/device_profile_test.cpp b/common/test/deviceprofileunittest/device_profile_test.cpp index 580518ba..f43a9965 100644 --- a/common/test/deviceprofileunittest/device_profile_test.cpp +++ b/common/test/deviceprofileunittest/device_profile_test.cpp @@ -66,5 +66,39 @@ HWTEST_F(DeviceProfileTest, dump_001, TestSize.Level0) auto result = deviceProfile.dump(); EXPECT_NE(0, result.length()); } + +HWTEST_F(DeviceProfileTest, IsMultiUser_001, TestSize.Level0) +{ + DeviceProfile deviceProfile; + deviceProfile.isMultiUser_ = true; + auto result = deviceProfile.IsMultiUser(); + EXPECT_EQ(true, result); +} + +HWTEST_F(DeviceProfileTest, SetIsMultiUser_001, TestSize.Level0) +{ + DeviceProfile deviceProfile; + bool isMultiUser = true; + deviceProfile.SetIsMultiUser(isMultiUser); + auto result = deviceProfile.isMultiUser_; + EXPECT_EQ(result, true); +} + +HWTEST_F(DeviceProfileTest, GetUserId_001, TestSize.Level0) +{ + DeviceProfile deviceProfile; + deviceProfile.userId_ = 0; + auto result = deviceProfile.GetUserId(); + EXPECT_EQ(0, result); +} + +HWTEST_F(DeviceProfileTest, SetUserId_001, TestSize.Level0) +{ + DeviceProfile deviceProfile; + int32_t userId = 1; + deviceProfile.SetUserId(userId); + auto result = deviceProfile.userId_; + EXPECT_EQ(1, result); +} +} } -} \ No newline at end of file diff --git a/common/test/profilechangelistenerstubunittest/BUILD.gn b/common/test/profilechangelistenerstubunittest/BUILD.gn index 8b69b841..b54aa75c 100644 --- a/common/test/profilechangelistenerstubunittest/BUILD.gn +++ b/common/test/profilechangelistenerstubunittest/BUILD.gn @@ -20,7 +20,10 @@ module_output_path = "device_info_manager/commontest" ohos_unittest("ProfileChangeListenerStubTest") { module_out_path = module_output_path - + cflags = [ + "-Dprivate=public", + "-Dprotected=public", + ] include_dirs = [ "include/interfaces", "include/constants", diff --git a/common/test/profilechangelistenerstubunittest/profile_change_listener_stub_test.cpp b/common/test/profilechangelistenerstubunittest/profile_change_listener_stub_test.cpp index 1b3697c4..e36fad2a 100644 --- a/common/test/profilechangelistenerstubunittest/profile_change_listener_stub_test.cpp +++ b/common/test/profilechangelistenerstubunittest/profile_change_listener_stub_test.cpp @@ -381,5 +381,38 @@ HWTEST_F(ProfileChangeListenerStubTest, OnRemoteRequest_014, TestSize.Level0) int32_t ret = listenerStub_->OnRemoteRequest(code, data, reply, option); EXPECT_EQ(305, ret); } + +HWTEST_F(ProfileChangeListenerStubTest, OnTrustDeviceProfileActiveInner_001, TestSize.Level0) +{ + MessageParcel data; + data.WriteInterfaceToken(IProfileChangeListener::GetDescriptor()); + MessageParcel reply; + int32_t ret = listenerStub_->OnTrustDeviceProfileActiveInner(data, reply); + EXPECT_NE(DP_SUCCESS, ret); +} + + +HWTEST_F(ProfileChangeListenerStubTest, OnTrustDeviceProfileInactiveInner_001, TestSize.Level0) +{ + MessageParcel data; + data.WriteInterfaceToken(IProfileChangeListener::GetDescriptor()); + MessageParcel reply; + int32_t ret = listenerStub_->OnTrustDeviceProfileInactiveInner(data, reply); + EXPECT_NE(DP_SUCCESS, ret); +} + +HWTEST_F(ProfileChangeListenerStubTest, OnTrustDeviceProfileActive_001, TestSize.Level0) +{ + TrustDeviceProfile profile; + int32_t ret = listenerStub_->OnTrustDeviceProfileActive(profile); + EXPECT_EQ(DP_SUCCESS, ret); +} + +HWTEST_F(ProfileChangeListenerStubTest, OnTrustDeviceProfileInactivet_001, TestSize.Level0) +{ + TrustDeviceProfile profile; + int32_t ret = listenerStub_->OnTrustDeviceProfileInactive(profile); + EXPECT_EQ(DP_SUCCESS, ret); +} } // namespace DistributedDeviceProfile -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/services/core/test/BUILD.gn b/services/core/test/BUILD.gn index eb13da61..a7d04351 100644 --- a/services/core/test/BUILD.gn +++ b/services/core/test/BUILD.gn @@ -417,6 +417,26 @@ ohos_unittest("trust_Device_Profile_test") { subsystem_name = "deviceprofile" } +ohos_unittest("multi_user_manager_test") { + module_out_path = module_output_path + sources = [ "unittest/multi_user_manager_test.cpp" ] + configs = device_profile_configs + deps = device_profile_deps + external_deps = device_profile_external_deps + part_name = "device_info_manager" + subsystem_name = "deviceprofile" +} + +ohos_unittest("dp_account_common_event_test") { + module_out_path = module_output_path + sources = [ "unittest/dp_account_common_event_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 = [ @@ -433,6 +453,7 @@ group("unittest") { ":device_profile_manager_new_test", ":distributed_device_profile_client_kv_new_test", ":distributed_device_profile_stub_new_test", + ":dp_account_common_event_test", ":dp_content_sensor_test", ":dp_dm_adapter_test", ":dp_dumper_new_test", @@ -441,6 +462,7 @@ group("unittest") { ":kv_adapter_new_test", ":kv_store_death_recipient_test", ":kv_sync_completed_listener_test", + ":multi_user_manager_test", ":profile_cache_new_test", ":profile_control_utils_test", ":profile_utils_new_test", diff --git a/services/core/test/unittest/device_profile_manager_test.cpp b/services/core/test/unittest/device_profile_manager_test.cpp index a734aa8b..aee285d0 100644 --- a/services/core/test/unittest/device_profile_manager_test.cpp +++ b/services/core/test/unittest/device_profile_manager_test.cpp @@ -1045,6 +1045,64 @@ HWTEST_F(DeviceProfileManagerTest, DeleteServiceProfile004, TestSize.Level1) DeviceProfileManager::GetInstance().isFirst_.store(false); } +/** + * @tc.name: SetIsMultiUser001 + * @tc.desc: SetIsMultiUser Success, SetIsMultiUser Success. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(DeviceProfileManagerTest, SetIsMultiUser001, TestSize.Level1) +{ + ServiceProfile serviceProfile7; + bool isMultiUser = true; + serviceProfile7.SetIsMultiUser(isMultiUser); + EXPECT_EQ(true, serviceProfile7.isMultiUser_); +} + +/** + * @tc.name: IsMultiUser001 + * @tc.desc: IsMultiUser Success, IsMultiUser Success. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(DeviceProfileManagerTest, IsMultiUser001, TestSize.Level1) +{ + ServiceProfile serviceProfile8; + bool isMultiUser = true; + serviceProfile8.SetIsMultiUser(isMultiUser); + bool ret = serviceProfile8.IsMultiUser(); + EXPECT_EQ(true, ret); +} + +/** + * @tc.name: SetUserId001 + * @tc.desc: SetUserId Success, SetUserId Success. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(DeviceProfileManagerTest, SetUserId001, TestSize.Level1) +{ + ServiceProfile serviceProfile9; + int32_t userId = 1; + serviceProfile9.SetUserId(userId); + EXPECT_EQ(1, serviceProfile9.userId_); +} + +/** + * @tc.name: GetUserId001 + * @tc.desc: GetUserId Success, GetUserId Success. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(DeviceProfileManagerTest, GetUserId001, TestSize.Level1) +{ + ServiceProfile serviceProfile9; + int32_t userId = 1; + serviceProfile9.SetUserId(userId); + bool ret = serviceProfile9.GetUserId(); + EXPECT_EQ(true, ret); +} + /** * @tc.name: DeleteCharacteristicProfile001 * @tc.desc: DeleteCharacteristicProfile succeed. diff --git a/services/core/test/unittest/dp_account_common_event_test.cpp b/services/core/test/unittest/dp_account_common_event_test.cpp new file mode 100644 index 00000000..b3a7987c --- /dev/null +++ b/services/core/test/unittest/dp_account_common_event_test.cpp @@ -0,0 +1,280 @@ +/* + * 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 +#include +#include +#include + +#include "distributed_device_profile_service_new.h" +#include "multi_user_manager.h" +#include "common_event_subscribe_info.h" +#include "common_event_support.h" +#include "matching_skills.h" +#include "system_ability_status_change_stub.h" + +namespace OHOS { +namespace DistributedDeviceProfile { +using namespace testing::ext; +using namespace std; +namespace { + const std::string TAG = "AccountCommonEventTest"; +} +class AccountCommonEventTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); +}; + +void AccountCommonEventTest::SetUpTestCase() +{ +} + +void AccountCommonEventTest::TearDownTestCase() +{ +} + +void AccountCommonEventTest::SetUp() +{ +} + +void AccountCommonEventTest::TearDown() +{ +} + +/* + * @tc.name: SubscribeAccountCommonEvent + * @tc.desc: Normal testCase of AccountCommonEventTest for CRUD + * @tc.type: FUNC + */ +HWTEST_F(AccountCommonEventTest, SubscribeAccountCommonEvent_001, TestSize.Level1) +{ + std::shared_ptr accountCommonEventManager; + accountCommonEventManager = std::make_shared(); + AccountEventCallback callback = [=](const auto &arg1, const auto &arg2) { + DistributedDeviceProfileServiceNew::GetInstance().AccountCommonEventCallback(arg1, arg2); + }; + std::vector accountCommonEventVec; + accountCommonEventManager->eventValidFlag_ = true; + accountCommonEventVec.emplace_back(EventFwk::CommonEventSupport::COMMON_EVENT_USER_SWITCHED); + accountCommonEventVec.emplace_back(EventFwk::CommonEventSupport::COMMON_EVENT_USER_REMOVED); + accountCommonEventVec.emplace_back(EventFwk::CommonEventSupport::COMMON_EVENT_HWID_LOGOUT); + accountCommonEventVec.emplace_back(EventFwk::CommonEventSupport::COMMON_EVENT_HWID_LOGIN); + bool ret = accountCommonEventManager->SubscribeAccountCommonEvent(accountCommonEventVec, callback); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: SubscribeAccountCommonEvent + * @tc.desc: Normal testCase of AccountCommonEventTest for CRUD + * @tc.type: FUNC + */ +HWTEST_F(AccountCommonEventTest, SubscribeAccountCommonEvent_002, TestSize.Level1) +{ + std::shared_ptr accountCommonEventManager; + accountCommonEventManager = std::make_shared(); + AccountEventCallback callback = [=](const auto &arg1, const auto &arg2) { + DistributedDeviceProfileServiceNew::GetInstance().AccountCommonEventCallback(arg1, arg2); + }; + std::vector accountCommonEventVec; + accountCommonEventManager->eventValidFlag_ = false; + accountCommonEventVec.emplace_back(EventFwk::CommonEventSupport::COMMON_EVENT_USER_SWITCHED); + accountCommonEventVec.emplace_back(EventFwk::CommonEventSupport::COMMON_EVENT_USER_REMOVED); + accountCommonEventVec.emplace_back(EventFwk::CommonEventSupport::COMMON_EVENT_HWID_LOGOUT); + accountCommonEventVec.emplace_back(EventFwk::CommonEventSupport::COMMON_EVENT_HWID_LOGIN); + bool ret = accountCommonEventManager->SubscribeAccountCommonEvent(accountCommonEventVec, callback); + EXPECT_EQ(ret, true); +} + +/* + * @tc.name: SubscribeAccountCommonEvent + * @tc.desc: Normal testCase of AccountCommonEventTest for CRUD + * @tc.type: FUNC + */ +HWTEST_F(AccountCommonEventTest, SubscribeAccountCommonEvent_003, TestSize.Level1) +{ + std::shared_ptr accountCommonEventManager; + accountCommonEventManager = std::make_shared(); + AccountEventCallback callback = [=](const auto &arg1, const auto &arg2) { + DistributedDeviceProfileServiceNew::GetInstance().AccountCommonEventCallback(arg1, arg2); + }; + std::vector accountCommonEventVec; + bool ret = accountCommonEventManager->SubscribeAccountCommonEvent(accountCommonEventVec, callback); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: SubscribeAccountCommonEvent + * @tc.desc: Normal testCase of AccountCommonEventTest for CRUD + * @tc.type: FUNC + */ +HWTEST_F(AccountCommonEventTest, SubscribeAccountCommonEvent_004, TestSize.Level1) +{ + std::shared_ptr accountCommonEventManager; + accountCommonEventManager = std::make_shared(); + AccountEventCallback callback = nullptr; + std::vector accountCommonEventVec; + accountCommonEventVec.emplace_back(EventFwk::CommonEventSupport::COMMON_EVENT_USER_SWITCHED); + accountCommonEventVec.emplace_back(EventFwk::CommonEventSupport::COMMON_EVENT_USER_REMOVED); + accountCommonEventVec.emplace_back(EventFwk::CommonEventSupport::COMMON_EVENT_HWID_LOGOUT); + accountCommonEventVec.emplace_back(EventFwk::CommonEventSupport::COMMON_EVENT_HWID_LOGIN); + bool ret = accountCommonEventManager->SubscribeAccountCommonEvent(accountCommonEventVec, callback); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: SubscribeAccountCommonEvent + * @tc.desc: Normal testCase of AccountCommonEventTest for CRUD + * @tc.type: FUNC + */ +HWTEST_F(AccountCommonEventTest, SubscribeAccountCommonEvent_005, TestSize.Level1) +{ + std::shared_ptr accountCommonEventManager; + accountCommonEventManager = std::make_shared(); + AccountEventCallback callback = nullptr; + std::vector accountCommonEventVec; + accountCommonEventVec.emplace_back("11111"); + bool ret = accountCommonEventManager->SubscribeAccountCommonEvent(accountCommonEventVec, callback); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: UnsubscribeAccountCommonEvent + * @tc.desc: Normal testCase of AccountCommonEventTest for CRUD + * @tc.type: FUNC + */ +HWTEST_F(AccountCommonEventTest, UnsubscribeAccountCommonEvent_001, TestSize.Level1) +{ + std::shared_ptr accountCommonEventManager; + accountCommonEventManager = std::make_shared(); + accountCommonEventManager->eventValidFlag_ = false; + bool ret = accountCommonEventManager->UnsubscribeAccountCommonEvent(); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: UnsubscribeAccountCommonEvent + * @tc.desc: Normal testCase of AccountCommonEventTest for CRUD + * @tc.type: FUNC + */ +HWTEST_F(AccountCommonEventTest, UnsubscribeAccountCommonEvent_002, TestSize.Level1) +{ + std::shared_ptr accountCommonEventManager; + accountCommonEventManager = std::make_shared(); + AccountEventCallback callback = [=](const auto &arg1, const auto &arg2) { + DistributedDeviceProfileServiceNew::GetInstance().AccountCommonEventCallback(arg1, arg2); + }; + std::vector accountCommonEventVec; + accountCommonEventManager->eventValidFlag_ = false; + accountCommonEventVec.emplace_back(EventFwk::CommonEventSupport::COMMON_EVENT_USER_SWITCHED); + accountCommonEventVec.emplace_back(EventFwk::CommonEventSupport::COMMON_EVENT_USER_REMOVED); + accountCommonEventVec.emplace_back(EventFwk::CommonEventSupport::COMMON_EVENT_HWID_LOGOUT); + accountCommonEventVec.emplace_back(EventFwk::CommonEventSupport::COMMON_EVENT_HWID_LOGIN); + accountCommonEventManager->SubscribeAccountCommonEvent(accountCommonEventVec, callback); + accountCommonEventManager->subscriber_ = nullptr; + bool ret = accountCommonEventManager->UnsubscribeAccountCommonEvent(); + EXPECT_EQ(ret, true); +} + +/* + * @tc.name: UnsubscribeAccountCommonEvent + * @tc.desc: Normal testCase of AccountCommonEventTest for CRUD + * @tc.type: FUNC + */ +HWTEST_F(AccountCommonEventTest, UnsubscribeAccountCommonEvent_003, TestSize.Level1) +{ + std::shared_ptr accountCommonEventManager; + accountCommonEventManager = std::make_shared(); + accountCommonEventManager->eventValidFlag_ = true; + AccountEventCallback callback = [=](const auto &arg1, const auto &arg2) { + DistributedDeviceProfileServiceNew::GetInstance().AccountCommonEventCallback(arg1, arg2); + }; + std::vector accountCommonEventVec; + accountCommonEventVec.emplace_back(EventFwk::CommonEventSupport::COMMON_EVENT_USER_SWITCHED); + accountCommonEventVec.emplace_back(EventFwk::CommonEventSupport::COMMON_EVENT_USER_REMOVED); + accountCommonEventVec.emplace_back(EventFwk::CommonEventSupport::COMMON_EVENT_HWID_LOGOUT); + accountCommonEventVec.emplace_back(EventFwk::CommonEventSupport::COMMON_EVENT_HWID_LOGIN); + EventFwk::MatchingSkills matchingSkills; + for (auto &item : accountCommonEventVec) { + matchingSkills.AddEvent(item); + } + CommonEventSubscribeInfo subscriberInfo(matchingSkills); + accountCommonEventManager->subscriber_ = + std::make_shared(subscriberInfo, callback, accountCommonEventVec); + accountCommonEventManager->statusChangeListener_ = nullptr; + bool ret = accountCommonEventManager->UnsubscribeAccountCommonEvent(); + EXPECT_EQ(ret, true); +} + +/* + * @tc.name: UnsubscribeAccountCommonEvent + * @tc.desc: Normal testCase of AccountCommonEventTest for CRUD + * @tc.type: FUNC + */ +HWTEST_F(AccountCommonEventTest, UnsubscribeAccountCommonEvent_004, TestSize.Level1) +{ + std::shared_ptr accountCommonEventManager; + accountCommonEventManager = std::make_shared(); + accountCommonEventManager->eventValidFlag_ = true; + AccountEventCallback callback = [=](const auto &arg1, const auto &arg2) { + DistributedDeviceProfileServiceNew::GetInstance().AccountCommonEventCallback(arg1, arg2); + }; + std::vector accountCommonEventVec; + accountCommonEventVec.emplace_back(EventFwk::CommonEventSupport::COMMON_EVENT_USER_SWITCHED); + accountCommonEventVec.emplace_back(EventFwk::CommonEventSupport::COMMON_EVENT_USER_REMOVED); + accountCommonEventVec.emplace_back(EventFwk::CommonEventSupport::COMMON_EVENT_HWID_LOGOUT); + accountCommonEventVec.emplace_back(EventFwk::CommonEventSupport::COMMON_EVENT_HWID_LOGIN); + EventFwk::MatchingSkills matchingSkills; + for (auto &item : accountCommonEventVec) { + matchingSkills.AddEvent(item); + } + CommonEventSubscribeInfo subscriberInfo(matchingSkills); + accountCommonEventManager->subscriber_ = + std::make_shared(subscriberInfo, callback, accountCommonEventVec); + accountCommonEventManager->statusChangeListener_ = + new (std::nothrow) DpAccountCommonEventManager:: + SystemAbilityStatusChangeListener(accountCommonEventManager->subscriber_); + bool ret = accountCommonEventManager->UnsubscribeAccountCommonEvent(); + EXPECT_EQ(ret, true); +} + +/* + * @tc.name: UnsubscribeAccountCommonEvent + * @tc.desc: Normal testCase of AccountCommonEventTest for CRUD + * @tc.type: FUNC + */ +HWTEST_F(AccountCommonEventTest, UnsubscribeAccountCommonEvent_005, TestSize.Level1) +{ + std::shared_ptr accountCommonEventManager; + accountCommonEventManager = std::make_shared(); + AccountEventCallback callback = [=](const auto &arg1, const auto &arg2) { + DistributedDeviceProfileServiceNew::GetInstance().AccountCommonEventCallback(arg1, arg2); + }; + std::vector accountCommonEventVec; + accountCommonEventManager->eventValidFlag_ = false; + accountCommonEventVec.emplace_back(EventFwk::CommonEventSupport::COMMON_EVENT_USER_SWITCHED); + accountCommonEventVec.emplace_back(EventFwk::CommonEventSupport::COMMON_EVENT_USER_REMOVED); + accountCommonEventVec.emplace_back(EventFwk::CommonEventSupport::COMMON_EVENT_HWID_LOGOUT); + accountCommonEventVec.emplace_back(EventFwk::CommonEventSupport::COMMON_EVENT_HWID_LOGIN); + accountCommonEventManager->SubscribeAccountCommonEvent(accountCommonEventVec, callback); + bool ret = accountCommonEventManager->UnsubscribeAccountCommonEvent(); + EXPECT_EQ(ret, true); +} +} // namespace DistributedDeviceProfile +} // namespace OHOS \ No newline at end of file diff --git a/services/core/test/unittest/dp_subscribe_info_test.cpp b/services/core/test/unittest/dp_subscribe_info_test.cpp index ebb34ef1..28e59011 100644 --- a/services/core/test/unittest/dp_subscribe_info_test.cpp +++ b/services/core/test/unittest/dp_subscribe_info_test.cpp @@ -313,11 +313,29 @@ HWTEST_F(DPSubscribeInfoTest, Stub_002, TestSize.Level1) OHOS::sptr proxy = OHOS::iface_cast(subscribeInfo.GetListener()); TrustDeviceProfile profile; profile.SetPeerUserId(1001); + profile.GetPeerUserId(); ASSERT_NE(proxy, nullptr); int32_t ret = proxy->OnTrustDeviceProfileActive(profile); EXPECT_EQ(ret, DP_SUCCESS); ret = proxy->OnTrustDeviceProfileInactive(profile); EXPECT_EQ(ret, DP_SUCCESS); } + +/* + * @tc.name: IProfileChangeListener_001 + * @tc.desc: Normal testCase of DPSubscribeInfoTest for CRUD + * @tc.type: FUNC + */ +HWTEST_F(DPSubscribeInfoTest, IProfileChangeListener_001, TestSize.Level1) +{ + OHOS::sptr subscribeDPChangeListener = + new(std::nothrow) DPSubscribeInfoTest::SubscribeDPChangeListener; + TrustDeviceProfile profile; + profile.SetPeerUserId(1001); + int32_t ret = subscribeDPChangeListener->OnTrustDeviceProfileActive(profile); + EXPECT_EQ(ret, DP_SUCCESS); + ret = subscribeDPChangeListener->OnTrustDeviceProfileInactive(profile); + EXPECT_EQ(ret, DP_SUCCESS); +} } // namespace DistributedDeviceProfile } // namespace OHOS diff --git a/services/core/test/unittest/multi_user_manager_test.cpp b/services/core/test/unittest/multi_user_manager_test.cpp new file mode 100644 index 00000000..50f1abbb --- /dev/null +++ b/services/core/test/unittest/multi_user_manager_test.cpp @@ -0,0 +1,118 @@ +/* + * 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 +#include +#include +#include + +#include "multi_user_manager.h" +#include "distributed_device_profile_errors.h" + +namespace OHOS { +namespace DistributedDeviceProfile { +using namespace testing::ext; +using namespace std; +namespace { + const std::string TAG = "MultiUserManagerTest"; +} +class MultiUserManagerTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); +}; + +void MultiUserManagerTest::SetUpTestCase() +{ +} + +void MultiUserManagerTest::TearDownTestCase() +{ +} + +void MultiUserManagerTest::SetUp() +{ +} + +void MultiUserManagerTest::TearDown() +{ +} + +/* + * @tc.name: init + * @tc.desc: Normal testCase of MultiUserManagerTest for CRUD + * @tc.type: FUNC + */ +HWTEST_F(MultiUserManagerTest, init_001, TestSize.Level1) +{ + int32_t ret = MultiUserManager::GetInstance().Init(); + EXPECT_EQ(ret, DP_SUCCESS); +} + +/* + * @tc.name: UnInit + * @tc.desc: Normal testCase of MultiUserManagerTest for CRUD + * @tc.type: FUNC + */ +HWTEST_F(MultiUserManagerTest, UnInit_001, TestSize.Level1) +{ + int32_t ret = MultiUserManager::GetInstance().UnInit(); + EXPECT_EQ(ret, DP_SUCCESS); +} + +/* + * @tc.name: UnInit + * @tc.desc: Normal testCase of MultiUserManagerTest for CRUD + * @tc.type: FUNC + */ +HWTEST_F(MultiUserManagerTest, SetCurrentForegroundUserID_001, TestSize.Level1) +{ + int32_t userId = 0; + MultiUserManager::GetInstance().SetCurrentForegroundUserID(userId); + EXPECT_EQ(MultiUserManager::GetInstance().foregroundUserId_, userId); +} + +/* + * @tc.name: GetCurrentForegroundUserID + * @tc.desc: Normal testCase of MultiUserManagerTest for CRUD + * @tc.type: FUNC + */ +HWTEST_F(MultiUserManagerTest, GetCurrentForegroundUserID_001, TestSize.Level1) +{ + int32_t userId = 0; + MultiUserManager::GetInstance().SetCurrentForegroundUserID(userId); + int32_t ret = MultiUserManager::GetInstance().GetCurrentForegroundUserID(); + EXPECT_EQ(ret, MultiUserManager::GetInstance().foregroundUserId_); +} + +/* + * @tc.name: GetForegroundUserIDFromOs + * @tc.desc: Normal testCase of MultiUserManagerTest for CRUD + * @tc.type: FUNC + */ +HWTEST_F(MultiUserManagerTest, GetForegroundUserIDFromOs_001, TestSize.Level1) +{ + int32_t foregroundId = 0; + int32_t userId = 0; + MultiUserManager::GetInstance().SetCurrentForegroundUserID(userId); + int32_t ret = MultiUserManager::GetInstance().GetForegroundUserIDFromOs(foregroundId); + EXPECT_EQ(ret, DP_SUCCESS); +} +} // namespace DistributedDeviceProfile +} // namespace OHOS \ No newline at end of file diff --git a/services/core/test/unittest/profile_change_listener_proxy_test.cpp b/services/core/test/unittest/profile_change_listener_proxy_test.cpp index 2d86cc75..dd0a9cab 100644 --- a/services/core/test/unittest/profile_change_listener_proxy_test.cpp +++ b/services/core/test/unittest/profile_change_listener_proxy_test.cpp @@ -130,5 +130,20 @@ HWTEST_F(ProfileChangeListenerProxyTest, OnCharacteristicProfile_001, TestSize.L ret = proxy.OnCharacteristicProfileDelete(oldProfile); EXPECT_NE(ret, DP_SUCCESS); } + +/* + * @tc.name: OnTrustDeviceProfileActive_001 + * @tc.desc: Normal testCase of ProfileChangeListenerProxyTest for CRUD + * @tc.type: FUNC + */ +HWTEST_F(ProfileChangeListenerProxyTest, OnTrustDeviceProfileActive_001, TestSize.Level1) +{ + TrustDeviceProfile Profile; + OHOS::DistributedDeviceProfile::ProfileListenerProxy proxy(nullptr); + int32_t ret = proxy.OnTrustDeviceProfileActive(Profile); + EXPECT_NE(ret, DP_SUCCESS); + ret = proxy.OnTrustDeviceProfileInactive(Profile); + EXPECT_NE(ret, DP_SUCCESS); +} } // namespace DistributedDeviceProfile } // namespace OHOS