mirror of
https://gitee.com/openharmony/deviceprofile_device_info_manager
synced 2024-11-22 23:19:50 +00:00
add ut
Signed-off-by: torrizo <lishenhao2@huawei.com>
This commit is contained in:
parent
0e593d4eee
commit
d3827e1861
@ -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",
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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",
|
||||
|
@ -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
|
||||
} // namespace OHOS
|
||||
|
@ -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",
|
||||
|
@ -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.
|
||||
|
280
services/core/test/unittest/dp_account_common_event_test.cpp
Normal file
280
services/core/test/unittest/dp_account_common_event_test.cpp
Normal file
@ -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 <gtest/gtest.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
|
||||
#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<DpAccountCommonEventManager> accountCommonEventManager;
|
||||
accountCommonEventManager = std::make_shared<DpAccountCommonEventManager>();
|
||||
AccountEventCallback callback = [=](const auto &arg1, const auto &arg2) {
|
||||
DistributedDeviceProfileServiceNew::GetInstance().AccountCommonEventCallback(arg1, arg2);
|
||||
};
|
||||
std::vector<std::string> 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<DpAccountCommonEventManager> accountCommonEventManager;
|
||||
accountCommonEventManager = std::make_shared<DpAccountCommonEventManager>();
|
||||
AccountEventCallback callback = [=](const auto &arg1, const auto &arg2) {
|
||||
DistributedDeviceProfileServiceNew::GetInstance().AccountCommonEventCallback(arg1, arg2);
|
||||
};
|
||||
std::vector<std::string> 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<DpAccountCommonEventManager> accountCommonEventManager;
|
||||
accountCommonEventManager = std::make_shared<DpAccountCommonEventManager>();
|
||||
AccountEventCallback callback = [=](const auto &arg1, const auto &arg2) {
|
||||
DistributedDeviceProfileServiceNew::GetInstance().AccountCommonEventCallback(arg1, arg2);
|
||||
};
|
||||
std::vector<std::string> 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<DpAccountCommonEventManager> accountCommonEventManager;
|
||||
accountCommonEventManager = std::make_shared<DpAccountCommonEventManager>();
|
||||
AccountEventCallback callback = nullptr;
|
||||
std::vector<std::string> 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<DpAccountCommonEventManager> accountCommonEventManager;
|
||||
accountCommonEventManager = std::make_shared<DpAccountCommonEventManager>();
|
||||
AccountEventCallback callback = nullptr;
|
||||
std::vector<std::string> 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<DpAccountCommonEventManager> accountCommonEventManager;
|
||||
accountCommonEventManager = std::make_shared<DpAccountCommonEventManager>();
|
||||
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<DpAccountCommonEventManager> accountCommonEventManager;
|
||||
accountCommonEventManager = std::make_shared<DpAccountCommonEventManager>();
|
||||
AccountEventCallback callback = [=](const auto &arg1, const auto &arg2) {
|
||||
DistributedDeviceProfileServiceNew::GetInstance().AccountCommonEventCallback(arg1, arg2);
|
||||
};
|
||||
std::vector<std::string> 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<DpAccountCommonEventManager> accountCommonEventManager;
|
||||
accountCommonEventManager = std::make_shared<DpAccountCommonEventManager>();
|
||||
accountCommonEventManager->eventValidFlag_ = true;
|
||||
AccountEventCallback callback = [=](const auto &arg1, const auto &arg2) {
|
||||
DistributedDeviceProfileServiceNew::GetInstance().AccountCommonEventCallback(arg1, arg2);
|
||||
};
|
||||
std::vector<std::string> 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<DpAccountEventSubscriber>(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<DpAccountCommonEventManager> accountCommonEventManager;
|
||||
accountCommonEventManager = std::make_shared<DpAccountCommonEventManager>();
|
||||
accountCommonEventManager->eventValidFlag_ = true;
|
||||
AccountEventCallback callback = [=](const auto &arg1, const auto &arg2) {
|
||||
DistributedDeviceProfileServiceNew::GetInstance().AccountCommonEventCallback(arg1, arg2);
|
||||
};
|
||||
std::vector<std::string> 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<DpAccountEventSubscriber>(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<DpAccountCommonEventManager> accountCommonEventManager;
|
||||
accountCommonEventManager = std::make_shared<DpAccountCommonEventManager>();
|
||||
AccountEventCallback callback = [=](const auto &arg1, const auto &arg2) {
|
||||
DistributedDeviceProfileServiceNew::GetInstance().AccountCommonEventCallback(arg1, arg2);
|
||||
};
|
||||
std::vector<std::string> 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
|
@ -313,11 +313,29 @@ HWTEST_F(DPSubscribeInfoTest, Stub_002, TestSize.Level1)
|
||||
OHOS::sptr<IProfileChangeListener> proxy = OHOS::iface_cast<IProfileChangeListener>(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<IProfileChangeListener> 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
|
||||
|
118
services/core/test/unittest/multi_user_manager_test.cpp
Normal file
118
services/core/test/unittest/multi_user_manager_test.cpp
Normal file
@ -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 <gtest/gtest.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
|
||||
#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
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user