From d3f7c8ca4996b336194e8ea481fd042758d2e85c Mon Sep 17 00:00:00 2001 From: vv Date: Tue, 19 Nov 2024 22:28:35 +0800 Subject: [PATCH] =?UTF-8?q?DM=E5=A4=9A=E7=94=A8=E6=88=B7=E9=9C=80=E6=B1=82?= =?UTF-8?q?UT=E8=A1=A5=E5=85=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: vv --- ...Test_dm_deviceprofile_connector_second.cpp | 241 ++++++++++++++++++ ...UTTest_dm_deviceprofile_connector_second.h | 2 + 2 files changed, 243 insertions(+) diff --git a/test/commonunittest/UTTest_dm_deviceprofile_connector_second.cpp b/test/commonunittest/UTTest_dm_deviceprofile_connector_second.cpp index 692c4a701..461e8e2f6 100644 --- a/test/commonunittest/UTTest_dm_deviceprofile_connector_second.cpp +++ b/test/commonunittest/UTTest_dm_deviceprofile_connector_second.cpp @@ -42,6 +42,58 @@ void DeviceProfileConnectorSecondTest::TearDownTestCase() distributedDeviceProfileClientMock_ = nullptr; } +void AddAccessControlProfile(std::vector& accessControlProfiles) +{ + int32_t userId = 123456; + int32_t bindType = 256; + int32_t deviceIdType = 1; + uint32_t bindLevel = 1; + uint32_t status = 1; + uint32_t authenticationType = 2; + uint32_t accesserId = 1; + uint32_t tokenId = 1001; + + std::string oldAccountId = "oldAccountId"; + std::string newAccountId = "newAccountId"; + std::string deviceIdEr = "remoteDeviceId"; + std::string deviceIdEe = "localDeviceId"; + std::string trustDeviceId = "123456"; + + DistributedDeviceProfile::Accesser accesser; + accesser.SetAccesserId(accesserId); + accesser.SetAccesserDeviceId(deviceIdEr); + accesser.SetAccesserUserId(userId); + accesser.SetAccesserAccountId(oldAccountId); + accesser.SetAccesserTokenId(tokenId); + accesser.SetAccesserBundleName("bundleName"); + accesser.SetAccesserHapSignature("uph1"); + accesser.SetAccesserBindLevel(bindLevel); + + DistributedDeviceProfile::Accessee accessee; + accessee.SetAccesseeId(accesserId); + accessee.SetAccesseeDeviceId(deviceIdEe); + accessee.SetAccesseeUserId(userId); + accessee.SetAccesseeAccountId(newAccountId); + accessee.SetAccesseeTokenId(tokenId); + accessee.SetAccesseeBundleName("bundleName"); + accessee.SetAccesseeHapSignature("uph1"); + accessee.SetAccesseeBindLevel(bindLevel); + + DistributedDeviceProfile::AccessControlProfile profileFifth; + profileFifth.SetAccessControlId(accesserId); + profileFifth.SetAccesserId(accesserId); + profileFifth.SetAccesseeId(accesserId); + profileFifth.SetTrustDeviceId(trustDeviceId); + profileFifth.SetBindType(bindType); + profileFifth.SetAuthenticationType(authenticationType); + profileFifth.SetDeviceIdType(deviceIdType); + profileFifth.SetStatus(status); + profileFifth.SetBindLevel(bindLevel); + profileFifth.SetAccesser(accesser); + profileFifth.SetAccessee(accessee); + accessControlProfiles.push_back(profileFifth); +} + HWTEST_F(DeviceProfileConnectorSecondTest, GetAccessControlProfile_201, testing::ext::TestSize.Level0) { EXPECT_CALL(*distributedDeviceProfileClientMock_, GetAccessControlProfile(_, _)).WillOnce(Return(ERR_DM_FAILED)); @@ -111,5 +163,194 @@ HWTEST_F(DeviceProfileConnectorSecondTest, GetAllAccessControlProfile_201, testi auto ret = DeviceProfileConnector::GetInstance().GetAllAccessControlProfile(); EXPECT_TRUE(ret.empty()); } + +HWTEST_F(DeviceProfileConnectorSecondTest, DeleteAclForAccountLogOut_001, testing::ext::TestSize.Level0) +{ + std::string localUdid = "local_device_id"; + int32_t localUserId = 1; + std::string peerUdid = "peer_device_id"; + int32_t peerUserId = 2; + + int32_t result = connector.DeleteAclForAccountLogOut(localUdid, localUserId, peerUdid, peerUserId); + + EXPECT_EQ(result, false); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, DeleteAppBindLevel_001, testing::ext::TestSize.Level0) +{ + DmOfflineParam offlineParam; + std::string pkgName = "com.example.app"; + std::vector profiles = {}; + std::string localUdid = "local_udid"; + std::string remoteUdid = "remote_udid"; + + connector.DeleteAppBindLevel(offlineParam, pkgName, profiles, localUdid, remoteUdid); + + EXPECT_EQ(offlineParam.processVec.size(), 0); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, CheckIsSameAccount_001, testing::ext::TestSize.Level0) +{ + DmAccessCaller caller; + caller.pkgName = "test_pkg"; + std::string srcUdid = "src_udid"; + DmAccessCallee callee; + std::string sinkUdid = "non_identical_udid"; + + EXPECT_EQ(connector.CheckIsSameAccount(caller, srcUdid, callee, sinkUdid), ERR_DM_FAILED); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, GetDeviceIdAndBindLevel_001, testing::ext::TestSize.Level0) +{ + std::vector userIds = {4, 5, 6}; + std::string localUdid = "local_udid"; + auto result = connector.GetDeviceIdAndBindLevel(userIds, localUdid); + EXPECT_TRUE(result.empty()); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, GetAclProfileByUserId_001, testing::ext::TestSize.Level0) +{ + std::string localUdid = "localDevice"; + int32_t userId = -1; + std::string remoteUdid = "remoteDevice"; + auto result = connector.GetAclProfileByUserId(localUdid, userId, remoteUdid); + EXPECT_TRUE(result.empty()); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, GetAclProfileByUserId_002, testing::ext::TestSize.Level0) +{ + std::string localUdid = "localDevice"; + int32_t userId = 1; + std::string remoteUdid = "nonExistentDevice"; + auto result = connector.GetAclProfileByUserId(localUdid, userId, remoteUdid); + + EXPECT_TRUE(result.empty()); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, GetAclProfileByUserId_003, testing::ext::TestSize.Level0) +{ + std::string localUdid = ""; + int32_t userId = 0; + std::string remoteUdid = ""; + auto result = connector.GetAclProfileByUserId(localUdid, userId, remoteUdid); + EXPECT_TRUE(result.empty()); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, GetOfflineProcessInfo_001, testing::ext::TestSize.Level0) +{ + std::string localUdid = "invalid_device"; + std::vector localUserIds = {1, 2}; + std::string remoteUdid = "remote_device"; + std::vector remoteUserIds = {3, 4}; + + std::vector result = + connector.GetOfflineProcessInfo(localUdid, localUserIds, remoteUdid, remoteUserIds); + + EXPECT_TRUE(result.empty()); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, GetOfflineProcessInfo_002, testing::ext::TestSize.Level0) +{ + std::string localUdid = "local_device"; + std::vector localUserIds = {1, 2}; + std::string remoteUdid = "remote_device"; + std::vector remoteUserIds = {99, 100}; + std::vector result = + connector.GetOfflineProcessInfo(localUdid, localUserIds, remoteUdid, remoteUserIds); + + EXPECT_TRUE(result.empty()); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, GetOfflineProcessInfo_003, testing::ext::TestSize.Level0) +{ + std::string localUdid = "local_device"; + std::vector localUserIds = {}; + std::string remoteUdid = "remote_device"; + std::vector remoteUserIds = {3, 4}; + std::vector result = + connector.GetOfflineProcessInfo(localUdid, localUserIds, remoteUdid, remoteUserIds); + + EXPECT_TRUE(result.empty()); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, GetUserIdAndBindLevel_001, testing::ext::TestSize.Level0) +{ + std::string localUdid = "local_udid"; + std::string peerUdid = "peer_udid"; + std::map result = connector.GetUserIdAndBindLevel(localUdid, peerUdid); + + EXPECT_TRUE(result.empty()); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, GetUserIdAndBindLevel_002, testing::ext::TestSize.Level0) +{ + std::string localUdid = "local_udid"; + std::string peerUdid = "peer_udid"; + EXPECT_CALL(*distributedDeviceProfileClientMock_, GetAccessControlProfile(_, _)).WillOnce(Return(DM_OK)); + std::map result = connector.GetUserIdAndBindLevel(localUdid, peerUdid); + + EXPECT_TRUE(result.empty()); +} + + +HWTEST_F(DeviceProfileConnectorSecondTest, GetDevIdAndUserIdByActHash_001, testing::ext::TestSize.Level0) +{ + std::string localUdid = "local_udid_123"; + std::string peerUdid = "peer_udid_456"; + int32_t peerUserId = 789; + std::string peerAccountHash = "invalid_hash"; + std::multimap result = + connector.GetDevIdAndUserIdByActHash(localUdid, peerUdid, peerUserId, peerAccountHash); + + EXPECT_TRUE(result.empty()); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, GetDevIdAndUserIdByActHash_002, testing::ext::TestSize.Level0) +{ + std::string localUdid = "local_udid_123"; + std::string peerUdid = "non_matching_udid"; + int32_t peerUserId = 789; + std::string peerAccountHash = "valid_hash"; + std::multimap result = + connector.GetDevIdAndUserIdByActHash(localUdid, peerUdid, peerUserId, peerAccountHash); + + EXPECT_TRUE(result.empty()); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, GetDevIdAndUserIdByActHash_003, testing::ext::TestSize.Level0) +{ + std::string localUdid = "local_udid_123"; + std::string peerUdid = "peer_udid_456"; + int32_t peerUserId = -1; + std::string peerAccountHash = "valid_hash"; + std::multimap result = + connector.GetDevIdAndUserIdByActHash(localUdid, peerUdid, peerUserId, peerAccountHash); + + EXPECT_TRUE(result.empty()); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, GetDevIdAndUserIdByActHash_004, testing::ext::TestSize.Level0) +{ + std::string localUdid = ""; + std::string peerUdid = ""; + int32_t peerUserId = 0; + std::string peerAccountHash = ""; + std::multimap result = + connector.GetDevIdAndUserIdByActHash(localUdid, peerUdid, peerUserId, peerAccountHash); + + EXPECT_TRUE(result.empty()); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, GetDeviceIdAndUserId_001, testing::ext::TestSize.Level0) +{ + auto result = connector.GetDeviceIdAndUserId("device4", 4); + EXPECT_EQ(result.size(), 0); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, GetDeviceIdAndUserId_002, testing::ext::TestSize.Level0) +{ + auto result = connector.GetDeviceIdAndUserId("", 0); + EXPECT_EQ(result.size(), 0); +} } // namespace DistributedHardware } // namespace OHOS diff --git a/test/commonunittest/UTTest_dm_deviceprofile_connector_second.h b/test/commonunittest/UTTest_dm_deviceprofile_connector_second.h index 7f638ce73..e7539e321 100644 --- a/test/commonunittest/UTTest_dm_deviceprofile_connector_second.h +++ b/test/commonunittest/UTTest_dm_deviceprofile_connector_second.h @@ -19,6 +19,7 @@ #include #include +#include "access_control_profile.h" #include "deviceprofile_connector.h" #include "distributed_device_profile_client_mock.h" #include "deviceprofile_connector_mock.h" @@ -31,6 +32,7 @@ public: static void TearDownTestCase(); void SetUp(); void TearDown(); + DeviceProfileConnector connector; static inline std::shared_ptr distributedDeviceProfileClientMock_ = -- Gitee