diff --git a/test/commonunittest/UTTest_dm_auth_manager_first.cpp b/test/commonunittest/UTTest_dm_auth_manager_first.cpp index 9f294138a71a0ee20c725fc44785bf44a6a9ad60..32cd4842c403c1410f43d7c423fdcf08a8a15b0c 100644 --- a/test/commonunittest/UTTest_dm_auth_manager_first.cpp +++ b/test/commonunittest/UTTest_dm_auth_manager_first.cpp @@ -574,6 +574,30 @@ HWTEST_F(DmAuthManagerTest, GenerateGroupName_001, testing::ext::TestSize.Level0 ASSERT_TRUE(ret.empty()); } +HWTEST_F(DmAuthManagerTest, UnBindDevice_001, testing::ext::TestSize.Level0) +{ + std::string pkgName; + std::string udid = "UnBindDevice_001"; + int32_t bindLevel = DEVICE; + std::string extra = "extraTest"; + int32_t ret = authManager_->UnBindDevice(pkgName, udid, bindLevel, extra); + EXPECT_NE(ret, DM_OK); + + pkgName = "com.ohos.test"; + authManager_->isAuthenticateDevice_ = false; + ret = authManager_->UnBindDevice(pkgName, udid, bindLevel, extra); + EXPECT_NE(ret, DM_OK); + + authManager_->authRequestState_ = nullptr; + authManager_->authResponseContext_ = nullptr; + ret = authManager_->UnBindDevice(pkgName, udid, bindLevel, extra); + EXPECT_NE(ret, DM_OK); + + bindLevel = 0; + ret = authManager_->UnBindDevice(pkgName, udid, bindLevel, extra); + EXPECT_NE(ret, DM_OK); +} + HWTEST_F(DmAuthManagerTest, GenerateGroupName_002, testing::ext::TestSize.Level0) { authManager_->authResponseContext_->targetPkgName = "targetPkgNameTest"; diff --git a/test/commonunittest/UTTest_dm_auth_manager_third.cpp b/test/commonunittest/UTTest_dm_auth_manager_third.cpp index 847a93c0f194d5b822786a3d263c56aeee0c53ee..9218de28fa98140e48452c715fb260e5f411607a 100644 --- a/test/commonunittest/UTTest_dm_auth_manager_third.cpp +++ b/test/commonunittest/UTTest_dm_auth_manager_third.cpp @@ -271,6 +271,75 @@ HWTEST_F(DmAuthManagerTest, ShowStartAuthDialog001, testing::ext::TestSize.Level ASSERT_EQ(authManager_->authResponseContext_->targetDeviceName, DmDialogManager::GetInstance().targetDeviceName_); } +HWTEST_F(DmAuthManagerTest, DeleteAcl001, testing::ext::TestSize.Level0) +{ + std::string pkgName = "pkgName"; + std::string localUdid = "localUdid"; + std::string remoteUdid = "remoteUdid"; + std::string extra = "extraTest"; + int32_t sessionId = 0; + int32_t bindLevel = APP; + g_bindType = INVALIED_TYPE; + int32_t ret = authManager_->DeleteAcl(pkgName, localUdid, remoteUdid, bindLevel, extra); + EXPECT_EQ(ret, ERR_DM_FAILED); +} + +HWTEST_F(DmAuthManagerTest, DeleteAccessControlList001, testing::ext::TestSize.Level0) +{ + DmOfflineParam offlineParam; + offlineParam.leftAclNumber = 1; + std::string pkgName = "pkgName"; + std::string localDeviceId = "localDeviceId"; + std::string remoteDeviceId = "remoteDeviceId"; + int32_t bindLevel = APP; + std::string extra = ""; + auto ret = DeviceProfileConnector::GetInstance().DeleteAccessControlList(pkgName, localDeviceId, + remoteDeviceId, bindLevel, extra); + EXPECT_EQ(0, ret.leftAclNumber); +} + +HWTEST_F(DmAuthManagerTest, DeleteAccessControlList002, testing::ext::TestSize.Level0) +{ + DmOfflineParam offlineParam; + offlineParam.leftAclNumber = 1; + std::string pkgName = "pkgName"; + std::string localDeviceId = "localDeviceId"; + std::string remoteDeviceId = "remoteDeviceId"; + int32_t bindLevel = APP; + std::string extra = "extratest"; + auto ret = DeviceProfileConnector::GetInstance().DeleteAccessControlList(pkgName, localDeviceId, + remoteDeviceId, bindLevel, extra); + EXPECT_EQ(0, ret.leftAclNumber); +} + +HWTEST_F(DmAuthManagerTest, DeleteAccessControlList003, testing::ext::TestSize.Level0) +{ + DmOfflineParam offlineParam; + offlineParam.leftAclNumber = 1; + std::string pkgName = "pkgName"; + std::string localDeviceId = "localDeviceId"; + std::string remoteDeviceId = "remoteDeviceId"; + int32_t bindLevel = SERVICE; + std::string extra = "extratest"; + auto ret = DeviceProfileConnector::GetInstance().DeleteAccessControlList(pkgName, localDeviceId, + remoteDeviceId, bindLevel, extra); + EXPECT_EQ(0, ret.leftAclNumber); +} + +HWTEST_F(DmAuthManagerTest, DeleteAccessControlList004, testing::ext::TestSize.Level0) +{ + DmOfflineParam offlineParam; + offlineParam.leftAclNumber = 1; + std::string pkgName = "pkgName"; + std::string localDeviceId = "localDeviceId"; + std::string remoteDeviceId = "remoteDeviceId"; + int32_t bindLevel = DEVICE; + std::string extra = ""; + auto ret = DeviceProfileConnector::GetInstance().DeleteAccessControlList(pkgName, localDeviceId, + remoteDeviceId, bindLevel, extra); + EXPECT_EQ(0, ret.leftAclNumber); +} + HWTEST_F(DmAuthManagerTest, OnUserOperation001, testing::ext::TestSize.Level0) { int32_t action = USER_OPERATION_TYPE_AUTH_CONFIRM_TIMEOUT; diff --git a/test/commonunittest/UTTest_dm_deviceprofile_connector.cpp b/test/commonunittest/UTTest_dm_deviceprofile_connector.cpp index 87382d3fe39c56a5e5d07efd7e4cd8b3a6f3b203..4a13113b93910e126ff33b2c60d11c4475996d17 100644 --- a/test/commonunittest/UTTest_dm_deviceprofile_connector.cpp +++ b/test/commonunittest/UTTest_dm_deviceprofile_connector.cpp @@ -908,6 +908,41 @@ HWTEST_F(DeviceProfileConnectorTest, SyncAclByBindType_004, testing::ext::TestSi EXPECT_EQ(ret.empty(), true); } +HWTEST_F(DeviceProfileConnectorTest, GetParamBindTypeVec_001, testing::ext::TestSize.Level0) +{ + DistributedDeviceProfile::AccessControlProfile profiles; + profiles.SetBindType(DM_IDENTICAL_ACCOUNT); + std::string requestDeviceId = "requestDeviceId"; + std::string trustUdid = "trustUdid"; + std::vector bindTypeVec; + DeviceProfileConnector::GetInstance().GetParamBindTypeVec(profiles, requestDeviceId, bindTypeVec, trustUdid); + EXPECT_EQ(bindTypeVec, std::vector({IDENTICAL_ACCOUNT_TYPE})); +} + +HWTEST_F(DeviceProfileConnectorTest, GetParamBindTypeVec_002, testing::ext::TestSize.Level0) +{ + DistributedDeviceProfile::AccessControlProfile profiles; + profiles.SetBindType(DM_POINT_TO_POINT); + profiles.SetBindLevel(DEVICE); + std::string requestDeviceId = "requestDeviceId"; + std::string trustUdid = "trustUdid"; + std::vector bindTypeVec; + DeviceProfileConnector::GetInstance().GetParamBindTypeVec(profiles, requestDeviceId, bindTypeVec, trustUdid); + EXPECT_EQ(bindTypeVec, std::vector({DEVICE_PEER_TO_PEER_TYPE})); +} + +HWTEST_F(DeviceProfileConnectorTest, GetParamBindTypeVec_003, testing::ext::TestSize.Level0) +{ + DistributedDeviceProfile::AccessControlProfile profiles; + profiles.SetBindType(DM_ACROSS_ACCOUNT); + profiles.SetBindLevel(DEVICE); + std::string requestDeviceId = "requestDeviceId"; + std::string trustUdid = "trustUdid"; + std::vector bindTypeVec; + DeviceProfileConnector::GetInstance().GetParamBindTypeVec(profiles, requestDeviceId, bindTypeVec, trustUdid); + EXPECT_EQ(bindTypeVec, std::vector({DEVICE_ACROSS_ACCOUNT_TYPE})); +} + HWTEST_F(DeviceProfileConnectorTest, GetProcessInfoFromAclByUserId_001, testing::ext::TestSize.Level0) { std::string localDeviceId = "localDeviceId"; @@ -980,6 +1015,68 @@ HWTEST_F(DeviceProfileConnectorTest, UpdateAccessControlList_004, testing::ext:: EXPECT_EQ(ret, DM_OK); } +HWTEST_F(DeviceProfileConnectorTest, ProcessBindType_001, testing::ext::TestSize.Level0) +{ + DistributedDeviceProfile::AccessControlProfile profiles; + profiles.SetBindType(DM_IDENTICAL_ACCOUNT); + vector sinkBindType; + vector bindTypeIndex; + string localDeviceId = "localDeviceId"; + string targetDeviceId = "targetDeviceId"; + uint32_t index = 0; + DeviceProfileConnector::GetInstance().ProcessBindType(profiles, localDeviceId, + sinkBindType, bindTypeIndex, index, targetDeviceId); + EXPECT_EQ(sinkBindType, vector({IDENTICAL_ACCOUNT_TYPE})); + EXPECT_EQ(bindTypeIndex, vector({0})); +} + +HWTEST_F(DeviceProfileConnectorTest, ProcessBindType_002, testing::ext::TestSize.Level0) +{ + DistributedDeviceProfile::AccessControlProfile profiles; + profiles.SetBindType(DM_IDENTICAL_ACCOUNT); + uint32_t index = 0; + string localDeviceId = "localDeviceId"; + string targetDeviceId = "targetDeviceId"; + std::vector sinkBindType; + std::vector bindTypeIndex; + DeviceProfileConnector::GetInstance().ProcessBindType(profiles, + localDeviceId, sinkBindType, bindTypeIndex, index, targetDeviceId); + EXPECT_EQ(sinkBindType, vector({IDENTICAL_ACCOUNT_TYPE})); + EXPECT_EQ(bindTypeIndex, vector({0})); +} + +HWTEST_F(DeviceProfileConnectorTest, ProcessBindType_003, testing::ext::TestSize.Level0) +{ + DistributedDeviceProfile::AccessControlProfile profiles; + profiles.SetBindType(DM_POINT_TO_POINT); + profiles.SetBindLevel(DEVICE); + std::string targetDeviceId = "targetDeviceId"; + std::string localDeviceId = "localDeviceId"; + uint32_t index = 0; + std::vector sinkBindType; + std::vector bindTypeIndex; + DeviceProfileConnector::GetInstance().ProcessBindType(profiles, + localDeviceId, sinkBindType, bindTypeIndex, index, targetDeviceId); + EXPECT_EQ(sinkBindType, vector({DEVICE_PEER_TO_PEER_TYPE})); + EXPECT_EQ(bindTypeIndex, vector({0})); +} + +HWTEST_F(DeviceProfileConnectorTest, ProcessBindType_004, testing::ext::TestSize.Level0) +{ + DistributedDeviceProfile::AccessControlProfile profiles; + profiles.SetBindType(DM_ACROSS_ACCOUNT); + profiles.SetBindLevel(DEVICE); + std::string targetDeviceId = "targetDeviceId"; + std::string localDeviceId = "localDeviceId"; + uint32_t index = 0; + std::vector sinkBindType; + std::vector bindTypeIndex; + DeviceProfileConnector::GetInstance().ProcessBindType(profiles, + localDeviceId, sinkBindType, bindTypeIndex, index, targetDeviceId); + EXPECT_EQ(sinkBindType, vector({DEVICE_ACROSS_ACCOUNT_TYPE})); + EXPECT_EQ(bindTypeIndex, vector({0})); +} + HWTEST_F(DeviceProfileConnectorTest, CheckIdenticalAccount_001, testing::ext::TestSize.Level0) { int32_t userId = 0; @@ -1241,6 +1338,34 @@ HWTEST_F(DeviceProfileConnectorTest, DeleteAppBindLevel_001, testing::ext::TestS EXPECT_EQ(offlineParam.bindType, APP); } +HWTEST_F(DeviceProfileConnectorTest, DeleteAppBindLevel_002, testing::ext::TestSize.Level0) +{ + DmOfflineParam offlineParam; + std::string pkgName = "bundleName1"; + std::vector profiles; + std::string localUdid = "remoteDeviceId"; + std::string remoteUdid="localDeviceId"; + std::string extra = "bundleName2"; + GetAccessControlProfiles(profiles); + DeviceProfileConnector::GetInstance().DeleteAppBindLevel(offlineParam, + pkgName, profiles, localUdid, remoteUdid, extra); + EXPECT_EQ(offlineParam.bindType, APP); +} + +HWTEST_F(DeviceProfileConnectorTest, DeleteAppBindLevel_003, testing::ext::TestSize.Level0) +{ + DmOfflineParam offlineParam; + std::string pkgName = "bundleName2"; + std::vector profiles; + std::string localUdid = "localDeviceId"; + std::string remoteUdid="remoteDeviceId"; + std::string extra = "bundleName1"; + GetAccessControlProfiles(profiles); + DeviceProfileConnector::GetInstance().DeleteAppBindLevel(offlineParam, + pkgName, profiles, localUdid, remoteUdid, extra); + EXPECT_EQ(offlineParam.bindType, APP); +} + HWTEST_F(DeviceProfileConnectorTest, DeleteDeviceBindLevel_001, testing::ext::TestSize.Level0) { DmOfflineParam offlineParam; @@ -1764,6 +1889,42 @@ HWTEST_F(DeviceProfileConnectorTest, CheckSrcDevIdInAclForDevBind_005, testing:: remoteFrontUserIds); } +HWTEST_F(DeviceProfileConnectorTest, DeleteAccessControlList_001, testing::ext::TestSize.Level0) +{ + std::string pkgName = "bundleName"; + std::string localDeviceId = "localDeviceId"; + std::string remoteDeviceId = "remoteDeviceId"; + std::string extra = "extraTest"; + int32_t bindLevel = INVALIED_TYPE; + DmOfflineParam offlineParam = DeviceProfileConnector::GetInstance() + .DeleteAccessControlList(pkgName, localDeviceId, remoteDeviceId, bindLevel, extra); + EXPECT_EQ(offlineParam.bindType, INVALIED_TYPE); +} + +HWTEST_F(DeviceProfileConnectorTest, DeleteAccessControlList_002, testing::ext::TestSize.Level0) +{ + std::string pkgName = "bundleName"; + std::string localDeviceId = "localDeviceId"; + std::string remoteDeviceId = "remoteDeviceId"; + std::string extra = "extraTest"; + int32_t bindLevel = SERVICE; + DmOfflineParam offlineParam = DeviceProfileConnector::GetInstance() + .DeleteAccessControlList(pkgName, localDeviceId, remoteDeviceId, bindLevel, extra); + EXPECT_EQ(offlineParam.bindType, SERVICE); +} + +HWTEST_F(DeviceProfileConnectorTest, DeleteAccessControlList_003, testing::ext::TestSize.Level0) +{ + std::string pkgName = "bundleName"; + std::string localDeviceId = "localDeviceId"; + std::string remoteDeviceId = "remoteDeviceId"; + std::string extra = "extraTest"; + int32_t bindLevel = DEVICE; + DmOfflineParam offlineParam = DeviceProfileConnector::GetInstance() + .DeleteAccessControlList(pkgName, localDeviceId, remoteDeviceId, bindLevel, extra); + EXPECT_EQ(offlineParam.bindType, DEVICE); +} + HWTEST_F(DeviceProfileConnectorTest, CheckAccessControl_002, testing::ext::TestSize.Level0) { int32_t userId = 123456; @@ -1831,6 +1992,91 @@ HWTEST_F(DeviceProfileConnectorTest, HandleAppUnBindEvent_002, testing::ext::Tes EXPECT_EQ("bundleName", res.pkgName); } +HWTEST_F(DeviceProfileConnectorTest, HandleAppUnBindEvent_003, testing::ext::TestSize.Level0) +{ + int32_t remoteUserId = 0; + int32_t tokenId = 0; + std::string remoteUdid = "remoteDeviceId"; + std::string localUdid = "localDeviceId"; + std::string pkgName = ""; + int32_t peerTokenId = 1001; + ProcessInfo res; + res = DeviceProfileConnector::GetInstance().HandleAppUnBindEvent(remoteUserId, + remoteUdid, tokenId, localUdid, peerTokenId); + EXPECT_EQ(pkgName, res.pkgName); +} + +HWTEST_F(DeviceProfileConnectorTest, HandleAppUnBindEvent_004, testing::ext::TestSize.Level0) +{ + int32_t remoteUserId = 123456; + int32_t tokenId = 1001; + std::string remoteUdid = "remoteDeviceId"; + std::string localUdid = "localDeviceId"; + std::string pkgName = ""; + int32_t peerTokenId = 1001; + ProcessInfo res; + res = DeviceProfileConnector::GetInstance().HandleAppUnBindEvent(remoteUserId, + remoteUdid, tokenId, localUdid, peerTokenId); + EXPECT_EQ("bundleName", res.pkgName); +} + +HWTEST_F(DeviceProfileConnectorTest, GetTokenIdByNameAndDeviceId_001, testing::ext::TestSize.Level0) +{ + std::string pkgName = "bundleName1"; + std::string requestDeviceId = "remoteDeviceId"; + auto ret = DeviceProfileConnector::GetInstance().GetTokenIdByNameAndDeviceId(pkgName, requestDeviceId); + EXPECT_EQ(ret, 0); +} + +HWTEST_F(DeviceProfileConnectorTest, GetTokenIdByNameAndDeviceId_002, testing::ext::TestSize.Level0) +{ + std::vector profiles; + std::string pkgName = "bundleName2"; + std::string requestDeviceId = "localDeviceId"; + GetAccessControlProfiles(profiles); + auto ret = DeviceProfileConnector::GetInstance().GetTokenIdByNameAndDeviceId(pkgName, requestDeviceId); + EXPECT_EQ(ret, 0); +} + +HWTEST_F(DeviceProfileConnectorTest, GetTokenIdByNameAndDeviceId_003, testing::ext::TestSize.Level0) +{ + std::vector profiles; + std::string pkgName = "bundleName8"; + std::string requestDeviceId = "localDeviceId9"; + GetAccessControlProfiles(profiles); + auto ret = DeviceProfileConnector::GetInstance().GetTokenIdByNameAndDeviceId(pkgName, requestDeviceId); + EXPECT_EQ(ret, 0); +} + +HWTEST_F(DeviceProfileConnectorTest, GetTokenIdByNameAndDeviceId_004, testing::ext::TestSize.Level0) +{ + std::vector profiles; + std::string pkgName = "bundleName2"; + std::string requestDeviceId = "localDeviceId9"; + GetAccessControlProfiles(profiles); + auto ret = DeviceProfileConnector::GetInstance().GetTokenIdByNameAndDeviceId(pkgName, requestDeviceId); + EXPECT_EQ(ret, 0); +} + +HWTEST_F(DeviceProfileConnectorTest, GetTokenIdByNameAndDeviceId_005, testing::ext::TestSize.Level0) +{ + std::vector profiles; + std::string pkgName; + std::string requestDeviceId; + GetAccessControlProfiles(profiles); + auto ret = DeviceProfileConnector::GetInstance().GetTokenIdByNameAndDeviceId(pkgName, requestDeviceId); + EXPECT_EQ(ret, 0); +} + +HWTEST_F(DeviceProfileConnectorTest, GetTokenIdByNameAndDeviceId_006, testing::ext::TestSize.Level0) +{ + std::vector profiles; + std::string pkgName = "bundleName1"; + std::string requestDeviceId = "remoteDeviceId7"; + auto ret = DeviceProfileConnector::GetInstance().GetTokenIdByNameAndDeviceId(pkgName, requestDeviceId); + EXPECT_EQ(ret, 0); +} + HWTEST_F(DeviceProfileConnectorTest, GetAclProfileByUserId_001, testing::ext::TestSize.Level0) { std::string localUdid = "deviceId"; diff --git a/test/unittest/UTTest_device_manager_impl.cpp b/test/unittest/UTTest_device_manager_impl.cpp index c2e18b5a02504d828b81fb4162301932772d676a..c846464ec9859163997373d02fb3af6abae90ca6 100644 --- a/test/unittest/UTTest_device_manager_impl.cpp +++ b/test/unittest/UTTest_device_manager_impl.cpp @@ -571,6 +571,24 @@ HWTEST_F(DeviceManagerImplTest, UnBindDevice_104, testing::ext::TestSize.Level0) DeviceManager::GetInstance().UnInitDeviceManager(packName); } +HWTEST_F(DeviceManagerImplTest, UnBindDevice_105, testing::ext::TestSize.Level0) +{ + std::string packName ; + std::string deviceId = "deviceId"; + std::string extra = "extra"; + int32_t ret = DeviceManager::GetInstance().UnBindDevice(packName, deviceId, extra); + ASSERT_EQ(ret, ERR_DM_INPUT_PARA_INVALID); +} + +HWTEST_F(DeviceManagerImplTest, UnBindDevice_106, testing::ext::TestSize.Level0) +{ + std::string packName = "com.ohos.test"; + std::string deviceId; + std::string extra = "extra"; + int32_t ret = DeviceManager::GetInstance().UnBindDevice(packName, deviceId, extra); + ASSERT_EQ(ret, ERR_DM_INPUT_PARA_INVALID); +} + /** * @tc.name: BindDevice_101 * @tc.desc: 1. set packName null diff --git a/test/unittest/UTTest_device_manager_service.cpp b/test/unittest/UTTest_device_manager_service.cpp index ab1495a62f112527d74d571239e2beab85d1b958..a796001bc6c111e2f176497c3d4196eb8f76daf9 100644 --- a/test/unittest/UTTest_device_manager_service.cpp +++ b/test/unittest/UTTest_device_manager_service.cpp @@ -1252,6 +1252,44 @@ HWTEST_F(DeviceManagerServiceTest, UnBindDevice_004, testing::ext::TestSize.Leve EXPECT_EQ(ret, ERR_DM_NO_PERMISSION); } +HWTEST_F(DeviceManagerServiceTest, UnBindDevice_005, testing::ext::TestSize.Level0) +{ + std::string pkgName = "com.ohos.test"; + std::string deviceId = "1234"; + std::string extra = "extra"; + EXPECT_CALL(*softbusCacheMock_, GetUdidByUdidHash(_, _)).WillOnce(Return(ERR_DM_FAILED)); + int32_t ret = DeviceManagerService::GetInstance().UnBindDevice(pkgName, deviceId, extra); + EXPECT_EQ(ret, ERR_DM_FAILED); +} + +HWTEST_F(DeviceManagerServiceTest, UnBindDevice_006, testing::ext::TestSize.Level0) +{ + std::string pkgName = "com.ohos.test"; + std::string deviceId; + std::string extra = "extra"; + int32_t ret = DeviceManagerService::GetInstance().UnBindDevice(pkgName, deviceId, extra); + EXPECT_EQ(ret, ERR_DM_INPUT_PARA_INVALID); +} + +HWTEST_F(DeviceManagerServiceTest, UnBindDevice_007, testing::ext::TestSize.Level0) +{ + std::string pkgName; + std::string deviceId = "1234"; + std::string extra = "extra"; + int32_t ret = DeviceManagerService::GetInstance().UnBindDevice(pkgName, deviceId, extra); + EXPECT_EQ(ret, ERR_DM_INPUT_PARA_INVALID); +} + +HWTEST_F(DeviceManagerServiceTest, UnBindDevice_008, testing::ext::TestSize.Level0) +{ + std::string pkgName = "com.ohos.test"; + std::string deviceId = "1234"; + std::string extra = "extra"; + DeletePermission(); + int32_t ret = DeviceManagerService::GetInstance().UnBindDevice(pkgName, deviceId, extra); + EXPECT_EQ(ret, ERR_DM_NO_PERMISSION); +} + HWTEST_F(DeviceManagerServiceTest, OnSessionOpened_001, testing::ext::TestSize.Level0) { DeviceManagerService::GetInstance().isImplsoLoaded_ = false; @@ -2169,6 +2207,28 @@ HWTEST_F(DeviceManagerServiceTest, SetDnPolicy_003, testing::ext::TestSize.Level EXPECT_EQ(ret, ERR_DM_INPUT_PARA_INVALID); } +HWTEST_F(DeviceManagerServiceTest, SetDnPolicy_004, testing::ext::TestSize.Level0) +{ + std::string pkgName = "openharmony123"; + std::map policy; + std::vector peerUdids; + int32_t userId = 1; + uint64_t peerTokenId = 3; + uint64_t tokenId = 87; + DeviceManagerService::GetInstance().SendUnBindBroadCast(peerUdids, userId, tokenId, DEVICE, peerTokenId); + DeviceManagerService::GetInstance().SendUnBindBroadCast(peerUdids, userId, tokenId, APP, peerTokenId); + DeviceManagerService::GetInstance().SendUnBindBroadCast(peerUdids, userId, tokenId, 2, peerTokenId); + DeviceManagerService::GetInstance().SendDeviceUnBindBroadCast(peerUdids, userId); + DeviceManagerService::GetInstance().softbusListener_ = std::make_shared(); + DeviceManagerService::GetInstance().SendDeviceUnBindBroadCast(peerUdids, userId); + DeviceManagerService::GetInstance().softbusListener_ = nullptr; + std::string processName = "collaboration_service"; + EXPECT_CALL(*permissionManagerMock_, GetCallerProcessName(_)) + .WillOnce(DoAll(SetArgReferee<0>(processName), Return(DM_OK))); + int ret = DeviceManagerService::GetInstance().SetDnPolicy(pkgName, policy); + EXPECT_EQ(ret, ERR_DM_INPUT_PARA_INVALID); +} + HWTEST_F(DeviceManagerServiceTest, DestroyPinHolder_003, testing::ext::TestSize.Level0) { std::string pkgName = ""; @@ -2191,6 +2251,18 @@ HWTEST_F(DeviceManagerServiceTest, SendAppUnBindBroadCast_001, testing::ext::Tes DeviceManagerService::GetInstance().softbusListener_ = nullptr; } +HWTEST_F(DeviceManagerServiceTest, SendAppUnBindBroadCast_002, testing::ext::TestSize.Level0) +{ + std::vector peerUdids; + int32_t userId = 12; + uint64_t peerTokenId = 3; + uint64_t tokenId = 23; + DeviceManagerService::GetInstance().softbusListener_ = std::make_shared(); + DeviceManagerService::GetInstance().SendAppUnBindBroadCast(peerUdids, userId, tokenId, peerTokenId); + EXPECT_NE(DeviceManagerService::GetInstance().softbusListener_, nullptr); + DeviceManagerService::GetInstance().softbusListener_ = nullptr; +} + HWTEST_F(DeviceManagerServiceTest, SendServiceUnBindBroadCast_001, testing::ext::TestSize.Level0) { std::vector peerUdids; @@ -2542,14 +2614,6 @@ HWTEST_F(DeviceManagerServiceTest, GetEncryptedUuidByNetworkId_004, testing::ext EXPECT_EQ(ret, DM_OK); } -HWTEST_F(DeviceManagerServiceTest, StopAuthenticateDevice_004, testing::ext::TestSize.Level0) -{ - std::string pkgName = "pkgName_004"; - EXPECT_CALL(*deviceManagerServiceImplMock_, StopAuthenticateDevice(_)).WillOnce(Return(ERR_DM_FAILED)); - int32_t ret = DeviceManagerService::GetInstance().StopAuthenticateDevice(pkgName); - EXPECT_EQ(ret, ERR_DM_FAILED); -} - #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) HWTEST_F(DeviceManagerServiceTest, ConvertUdidHashToAnoyDeviceId_001, testing::ext::TestSize.Level0) { @@ -2558,12 +2622,10 @@ HWTEST_F(DeviceManagerServiceTest, ConvertUdidHashToAnoyDeviceId_001, testing::e EXPECT_CALL(*appManagerMock_, GetAppId()).WillOnce(Return("")); int32_t ret = DeviceManagerService::GetInstance().ConvertUdidHashToAnoyDeviceId(udidHash, result); EXPECT_EQ(ret, ERR_DM_FAILED); - EXPECT_CALL(*appManagerMock_, GetAppId()).WillOnce(Return("appId")); EXPECT_CALL(*cryptoMock_, ConvertUdidHashToAnoyAndSave(_, _, _)).WillOnce(Return(DM_OK)); ret = DeviceManagerService::GetInstance().ConvertUdidHashToAnoyDeviceId(udidHash, result); EXPECT_EQ(ret, DM_OK); - EXPECT_CALL(*appManagerMock_, GetAppId()).WillOnce(Return("appId")); EXPECT_CALL(*cryptoMock_, ConvertUdidHashToAnoyAndSave(_, _, _)).WillOnce(Return(ERR_DM_FAILED)); ret = DeviceManagerService::GetInstance().ConvertUdidHashToAnoyDeviceId(udidHash, result); @@ -2576,7 +2638,6 @@ HWTEST_F(DeviceManagerServiceTest, GetUdidHashByAnoyDeviceId_001, testing::ext:: std::string anoyDeviceId = "anoyDeviceId"; int32_t ret = DeviceManagerService::GetInstance().GetUdidHashByAnoyDeviceId(anoyDeviceId, udidHash); EXPECT_EQ(ret, DM_OK); - EXPECT_CALL(*kVAdapterManagerMock_, Get(_, _)).WillOnce(Return(ERR_DM_FAILED)); ret = DeviceManagerService::GetInstance().GetUdidHashByAnoyDeviceId(anoyDeviceId, udidHash); EXPECT_EQ(ret, ERR_DM_FAILED); diff --git a/test/unittest/UTTest_device_manager_service_impl.cpp b/test/unittest/UTTest_device_manager_service_impl.cpp index 5fcbc6813aa97dc547daee6d69ee86cbffeb8d9c..908ae3fa1cf702eadcfa89fe93299354602abd03 100644 --- a/test/unittest/UTTest_device_manager_service_impl.cpp +++ b/test/unittest/UTTest_device_manager_service_impl.cpp @@ -1399,6 +1399,37 @@ HWTEST_F(DeviceManagerServiceImplTest, UnBindDevice_104, testing::ext::TestSize. EXPECT_EQ(ret, ERR_DM_FAILED); } +HWTEST_F(DeviceManagerServiceImplTest, UnBindDevice_105, testing::ext::TestSize.Level0) +{ + std::string pkgName = "pkgname"; + std::string udid; + int32_t bindLevel = 0; + std::string extra = "extra"; + int32_t ret = deviceManagerServiceImpl_->UnBindDevice(pkgName, udid, bindLevel, extra); + EXPECT_EQ(ret, ERR_DM_INPUT_PARA_INVALID); +} + +HWTEST_F(DeviceManagerServiceImplTest, UnBindDevice_106, testing::ext::TestSize.Level0) +{ + std::string pkgName; + std::string udid = "123"; + int32_t bindLevel = 0; + std::string extra = "extra"; + int32_t ret = deviceManagerServiceImpl_->UnBindDevice(pkgName, udid, bindLevel, extra); + EXPECT_EQ(ret, ERR_DM_INPUT_PARA_INVALID); +} + +HWTEST_F(DeviceManagerServiceImplTest, UnBindDevice_107, testing::ext::TestSize.Level0) +{ + std::string pkgName; + std::string udid; + int32_t bindLevel = 0; + std::string extra = "extra"; + int32_t ret = deviceManagerServiceImpl_->UnBindDevice(pkgName, udid, bindLevel, extra); + deviceManagerServiceImpl_->HandleDeviceNotTrust(udid); + EXPECT_EQ(ret, ERR_DM_INPUT_PARA_INVALID); +} + HWTEST_F(DeviceManagerServiceImplTest, GetBindLevel_101, testing::ext::TestSize.Level0) { std::string pkgName = "pkgname"; @@ -1777,6 +1808,69 @@ HWTEST_F(DeviceManagerServiceImplTest, SaveOnlineDeviceInfo_001, testing::ext::T deviceManagerServiceImpl_->HandleRemoteUserRemoved(userId, remoteUdid); } +HWTEST_F(DeviceManagerServiceImplTest, SaveOnlineDeviceInfo_002, testing::ext::TestSize.Level0) +{ + std::vector deviceList; + DmDeviceInfo dmDeviceInfo; + dmDeviceInfo.authForm = DmAuthForm::ACROSS_ACCOUNT; + dmDeviceInfo.networkType = 1; + deviceList.push_back(dmDeviceInfo); + + if (deviceManagerServiceImpl_->deviceStateMgr_ == nullptr) { + deviceManagerServiceImpl_->Initialize(listener_); + } + EXPECT_CALL(*softbusConnectorMock_, GetUdidByNetworkId(_, _)).Times(::testing::AtLeast(1)).WillOnce(Return(DM_OK)); + int32_t ret = deviceManagerServiceImpl_->SaveOnlineDeviceInfo(deviceList); + EXPECT_EQ(ret, DM_OK); + + int32_t remoteUserId = 1; + std::string remoteUdid = "remoteDeviceId"; + int32_t tokenId = 0; + int32_t peerTokenId = 3; + ProcessInfo processInfo; + EXPECT_CALL(*deviceProfileConnectorMock_, HandleAppUnBindEvent(_, _, _, _)).WillOnce(Return(processInfo)); + deviceManagerServiceImpl_->HandleAppUnBindEvent(remoteUserId, remoteUdid, tokenId, peerTokenId); + + processInfo.pkgName = "pkgName"; + if (deviceManagerServiceImpl_->softbusConnector_ == nullptr) { + deviceManagerServiceImpl_->Initialize(listener_); + } + EXPECT_CALL(*deviceProfileConnectorMock_, HandleAppUnBindEvent(_, _, _, _)).WillOnce(Return(processInfo)); + deviceManagerServiceImpl_->HandleAppUnBindEvent(remoteUserId, remoteUdid, tokenId, peerTokenId); + + EXPECT_CALL(*deviceProfileConnectorMock_, HandleDevUnBindEvent(_, _, _)).WillOnce(Return(DM_INVALIED_BINDTYPE)); + deviceManagerServiceImpl_->HandleDevUnBindEvent(remoteUserId, remoteUdid); + + EXPECT_CALL(*deviceProfileConnectorMock_, HandleDevUnBindEvent(_, _, _)).WillOnce(Return(DM_IDENTICAL_ACCOUNT)); + if (deviceManagerServiceImpl_->authMgr_ == nullptr) { + deviceManagerServiceImpl_->Initialize(listener_); + } + deviceManagerServiceImpl_->HandleDevUnBindEvent(remoteUserId, remoteUdid); + + int32_t userId = 123456; + remoteUdid = "remoteDeviceId"; + if (deviceManagerServiceImpl_->hiChainConnector_ == nullptr) { + deviceManagerServiceImpl_->Initialize(listener_); + } + deviceManagerServiceImpl_->HandleRemoteUserRemoved(userId, remoteUdid); +} + +HWTEST_F(DeviceManagerServiceImplTest, GetTokenIdByNameAndDeviceId_001, testing::ext::TestSize.Level0) +{ + std::string pkgName = ""; + std::string requestDeviceId = "deviceId"; + auto ret = deviceManagerServiceImpl_->GetTokenIdByNameAndDeviceId(pkgName, requestDeviceId); + EXPECT_EQ(ret, ERR_DM_INPUT_PARA_INVALID); +} + +HWTEST_F(DeviceManagerServiceImplTest, GetTokenIdByNameAndDeviceId_002, testing::ext::TestSize.Level0) +{ + std::string pkgName = "pkgName"; + std::string requestDeviceId = ""; + auto ret = deviceManagerServiceImpl_->GetTokenIdByNameAndDeviceId(pkgName, requestDeviceId); + EXPECT_EQ(ret, ERR_DM_INPUT_PARA_INVALID); +} + HWTEST_F(DeviceManagerServiceImplTest, GetDeviceIdAndBindLevel_001, testing::ext::TestSize.Level0) { int32_t userId = 123456; diff --git a/test/unittest/UTTest_device_manager_service_two.cpp b/test/unittest/UTTest_device_manager_service_two.cpp index 21ea1d61f4c09fe2aafb8fbde9b854561068e95e..cd38fb552c01876055be24cf084f87ae5ec4684b 100644 --- a/test/unittest/UTTest_device_manager_service_two.cpp +++ b/test/unittest/UTTest_device_manager_service_two.cpp @@ -1158,6 +1158,14 @@ HWTEST_F(DeviceManagerServiceTest, SendUserIdsByWifi_201, testing::ext::TestSize backgroundUserIds); EXPECT_EQ(ret, ERR_DM_FAILED); } + +HWTEST_F(DeviceManagerServiceTest, StopAuthenticateDevice_004, testing::ext::TestSize.Level0) +{ + std::string pkgName = "pkgName_004"; + EXPECT_CALL(*deviceManagerServiceImplMock_, StopAuthenticateDevice(_)).WillOnce(Return(ERR_DM_FAILED)); + int32_t ret = DeviceManagerService::GetInstance().StopAuthenticateDevice(pkgName); + EXPECT_EQ(ret, ERR_DM_FAILED); +} } // namespace } // namespace DistributedHardware } // namespace OHOS