diff --git a/test/commonunittest/UTTest_dm_deviceprofile_connector_second.cpp b/test/commonunittest/UTTest_dm_deviceprofile_connector_second.cpp index cfc68e1456446425bfd503ce859964ba9025d4c6..526a5f0b3b1fbf1be3d5d59d363fff62d0d17aba 100644 --- a/test/commonunittest/UTTest_dm_deviceprofile_connector_second.cpp +++ b/test/commonunittest/UTTest_dm_deviceprofile_connector_second.cpp @@ -935,5 +935,46 @@ HWTEST_F(DeviceProfileConnectorSecondTest, GetAuthFormMap_007, testing::ext::Tes EXPECT_EQ(ret.size(), 1); EXPECT_EQ(ret[trustDeviceId], DmAuthForm::IDENTICAL_ACCOUNT); } + +HWTEST_F(DeviceProfileConnectorSecondTest, GetDeviceIdAndUdidListByTokenId_001, testing::ext::TestSize.Level1) +{ + std::vector userIds; + std::string emptyUdid; + int32_t tokenId = 1234; + + auto result = DeviceProfileConnector::GetInstance().GetDeviceIdAndUdidListByTokenId(userIds, emptyUdid, tokenId); + EXPECT_TRUE(result.empty()); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, GetDeviceIdAndUdidListByTokenId_002, testing::ext::TestSize.Level1) +{ + std::vector emptyUserIds; + std::string localUdid = "localDeviceId"; + int32_t tokenId = 1234; + + auto result = DeviceProfileConnector::GetInstance().GetDeviceIdAndUdidListByTokenId(emptyUserIds, localUdid, tokenId); + EXPECT_TRUE(result.empty()); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, GetDeviceIdAndUdidListByTokenId_003, testing::ext::TestSize.Level1) +{ + std::vector userIds = {1, 2}; + std::string emptyUdid; + int32_t tokenId = 1234; + + auto result = DeviceProfileConnector::GetInstance().GetDeviceIdAndUdidListByTokenId(userIds, emptyUdid, tokenId); + EXPECT_TRUE(result.empty()); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, GetDeviceIdAndUdidListByTokenId_004, testing::ext::TestSize.Level1) +{ + std::vector userIds = {1, 2}; + std::string localUdid = "localDeviceId"; + int32_t tokenId = 1234; + + EXPECT_CALL(*distributedDeviceProfileClientMock_, GetAllAccessControlProfile(_)).WillOnce(Return(DM_OK)); + auto result = DeviceProfileConnector::GetInstance().GetDeviceIdAndUdidListByTokenId(userIds, localUdid, tokenId); + EXPECT_TRUE(result.empty()); +} } // namespace DistributedHardware } // namespace OHOS diff --git a/test/unittest/UTTest_device_manager_service_impl_first.cpp b/test/unittest/UTTest_device_manager_service_impl_first.cpp index b6a89fcacd61faaafeceb9a7e74d5af884286e3e..1930e26be031cc895f2e7e0cd39647592462fb0c 100644 --- a/test/unittest/UTTest_device_manager_service_impl_first.cpp +++ b/test/unittest/UTTest_device_manager_service_impl_first.cpp @@ -43,6 +43,7 @@ void DeviceManagerServiceImplFirstTest::SetUpTestCase() DmSoftbusConnector::dmSoftbusConnector = softbusConnectorMock_; DmDmDeviceStateManager::dmDeviceStateManager = dmDeviceStateManagerMock_; DmDeviceManagerServiceImpl::dmDeviceManagerServiceImpl = deviceManagerServiceImplMock_; + DmHiChainConnector::dmHiChainConnector = hiChainConnectorMock_; } void DeviceManagerServiceImplFirstTest::TearDownTestCase() @@ -57,6 +58,8 @@ void DeviceManagerServiceImplFirstTest::TearDownTestCase() dmDeviceStateManagerMock_ = nullptr; DmDeviceManagerServiceImpl::dmDeviceManagerServiceImpl = nullptr; deviceManagerServiceImplMock_ = nullptr; + DmHiChainConnector::dmHiChainConnector = nullptr; + hiChainConnectorMock_ = nullptr; } namespace { @@ -532,6 +535,259 @@ HWTEST_F(DeviceManagerServiceImplFirstTest, SetOnlineProcessInfo_006, testing::e EXPECT_EQ(devInfo.authForm, DmAuthForm::SHARE); } + +HWTEST_F(DeviceManagerServiceImplFirstTest, GetDeviceIdByUserIdAndTokenId_001, testing::ext::TestSize.Level1) +{ + int32_t userId = 1; + int32_t tokenId = 1234; + + EXPECT_CALL(*deviceProfileConnectorMock_, GetDeviceIdAndUdidListByTokenId(_, _, _)) + .WillOnce(Return(std::vector())); + + auto result = deviceManagerServiceImpl_->GetDeviceIdByUserIdAndTokenId(userId, tokenId); + EXPECT_TRUE(result.empty()); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, GetDeviceIdByUserIdAndTokenId_002, testing::ext::TestSize.Level1) +{ + int32_t userId = 1; + int32_t tokenId = 1234; + + std::vector expectedDeviceIds = {"deviceId1"}; + EXPECT_CALL(*deviceProfileConnectorMock_, GetDeviceIdAndUdidListByTokenId(_, _, _)) + .WillOnce(Return(expectedDeviceIds)); + + auto result = deviceManagerServiceImpl_->GetDeviceIdByUserIdAndTokenId(userId, tokenId); + EXPECT_EQ(result.size(), 1); + EXPECT_EQ(result[0], "deviceId1"); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, GetDeviceIdByUserIdAndTokenId_003, testing::ext::TestSize.Level1) +{ + int32_t userId = 1; + int32_t tokenId = 1234; + + std::vector expectedDeviceIds = {"deviceId1", "deviceId2"}; + EXPECT_CALL(*deviceProfileConnectorMock_, GetDeviceIdAndUdidListByTokenId(_, _, _)) + .WillOnce(Return(expectedDeviceIds)); + + auto result = deviceManagerServiceImpl_->GetDeviceIdByUserIdAndTokenId(userId, tokenId); + EXPECT_EQ(result.size(), 2); + EXPECT_NE(std::find(result.begin(), result.end(), "deviceId1"), result.end()); + EXPECT_NE(std::find(result.begin(), result.end(), "deviceId2"), result.end()); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, ProcessAppUninstall_001, testing::ext::TestSize.Level1) +{ + int32_t userId = 1001; + int32_t accessTokenId = 2001; + + deviceManagerServiceImpl_->listener_ = nullptr; + + auto result = deviceManagerServiceImpl_->ProcessAppUninstall(userId, accessTokenId); + EXPECT_EQ(result, ERR_DM_POINT_NULL); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, ProcessAppUninstall_002, testing::ext::TestSize.Level1) +{ + int32_t userId = 1; + int32_t accessTokenId = 1234; + + EXPECT_CALL(*deviceProfileConnectorMock_, GetAllAclIncludeLnnAcl()) + .WillOnce(Return(std::vector())); + + int32_t result = deviceManagerServiceImpl_->ProcessAppUninstall(userId, accessTokenId); + EXPECT_EQ(result, DM_OK); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, ProcessAppUninstall_003, testing::ext::TestSize.Level1) +{ + int32_t userId = 1; + int32_t accessTokenId = 1234; + + std::vector profiles; + DistributedDeviceProfile::AccessControlProfile profile; + profile.GetAccesser().SetAccesserTokenId(5678); + profiles.push_back(profile); + + EXPECT_CALL(*deviceProfileConnectorMock_, GetAllAclIncludeLnnAcl()) + .WillOnce(Return(profiles)); + + int32_t result = deviceManagerServiceImpl_->ProcessAppUninstall(userId, accessTokenId); + EXPECT_EQ(result, DM_OK); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, ProcessAppUninstall_004, testing::ext::TestSize.Level1) +{ + int32_t userId = 1; + int32_t accessTokenId = 1234; + + std::vector profiles; + DistributedDeviceProfile::AccessControlProfile profile; + profile.GetAccesser().SetAccesserTokenId(accessTokenId); + profiles.push_back(profile); + + EXPECT_CALL(*deviceProfileConnectorMock_, GetAllAclIncludeLnnAcl()) + .WillOnce(Return(profiles)); + EXPECT_CALL(*hiChainConnectorMock_, DeleteGroupByACL(_, _)).Times(1); + + int32_t result = deviceManagerServiceImpl_->ProcessAppUninstall(userId, accessTokenId); + EXPECT_EQ(result, DM_OK); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, ProcessAppUninstall_005, testing::ext::TestSize.Level1) +{ + int32_t userId = 1; + int32_t accessTokenId = 1234; + + std::vector profiles; + DistributedDeviceProfile::AccessControlProfile profile; + profile.GetAccesser().SetAccesserTokenId(accessTokenId); + profiles.push_back(profile); + + EXPECT_CALL(*deviceProfileConnectorMock_, GetAllAclIncludeLnnAcl()) + .WillOnce(Return(profiles)); + EXPECT_CALL(*deviceProfileConnectorMock_, IsLnnAcl(_)).WillRepeatedly(Return(true)); + EXPECT_CALL(*deviceProfileConnectorMock_, CacheAcerAclId(_, _)).Times(1); + EXPECT_CALL(*hiChainConnectorMock_, DeleteGroupByACL(_, _)).Times(1); + + int32_t result = deviceManagerServiceImpl_->ProcessAppUninstall(userId, accessTokenId); + EXPECT_EQ(result, DM_OK); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, ProcessAppUninstall_006, testing::ext::TestSize.Level1) +{ + int32_t userId = 1; + int32_t accessTokenId = 1234; + + std::vector profiles; + DistributedDeviceProfile::AccessControlProfile profile; + profile.GetAccesser().SetAccesserTokenId(accessTokenId); + profiles.push_back(profile); + + EXPECT_CALL(*deviceProfileConnectorMock_, GetAllAclIncludeLnnAcl()) + .WillOnce(Return(profiles)); + EXPECT_CALL(*hiChainConnectorMock_, DeleteGroupByACL(_, _)).Times(0); + + int32_t result = deviceManagerServiceImpl_->ProcessAppUninstall(userId, accessTokenId); + EXPECT_EQ(result, DM_OK); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, ProcessAppUninstall_007, testing::ext::TestSize.Level1) +{ + int32_t userId = 1; + int32_t accessTokenId = 1234; + + std::vector profiles; + DistributedDeviceProfile::AccessControlProfile profile; + profile.GetAccesser().SetAccesserTokenId(accessTokenId); + profiles.push_back(profile); + + EXPECT_CALL(*deviceProfileConnectorMock_, GetAllAclIncludeLnnAcl()) + .WillOnce(Return(profiles)); + EXPECT_CALL(*deviceProfileConnectorMock_, IsLnnAcl(_)).WillRepeatedly(Return(false)); + EXPECT_CALL(*hiChainConnectorMock_, DeleteGroupByACL(_, _)).Times(1); + + int32_t result = deviceManagerServiceImpl_->ProcessAppUninstall(userId, accessTokenId); + EXPECT_EQ(result, DM_OK); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, ProcessUnBindApp_001, testing::ext::TestSize.Level1) +{ + int32_t userId = 1; + int32_t accessTokenId = 1234; + std::string extra = "invalid_json"; + std::string udid = "remoteUdid"; + + EXPECT_CALL(*deviceManagerServiceImplMock_, HandleAppUnBindEvent(userId, udid, accessTokenId)).Times(1); + + deviceManagerServiceImpl_->ProcessUnBindApp(userId, accessTokenId, extra, udid); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, ProcessUnBindApp_002, testing::ext::TestSize.Level1) +{ + int32_t userId = 1; + int32_t accessTokenId = 1234; + std::string extra = R"({"key": "value"})"; + std::string udid = "remoteUdid"; + + EXPECT_CALL(*deviceManagerServiceImplMock_, HandleAppUnBindEvent(userId, udid, accessTokenId)).Times(1); + + deviceManagerServiceImpl_->ProcessUnBindApp(userId, accessTokenId, extra, udid); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, ProcessUnBindApp_003, testing::ext::TestSize.Level1) +{ + int32_t userId = 1; + int32_t accessTokenId = 1234; + int32_t peerTokenId = 5678; + std::string extra = R"({"peerTokenId": 5678})"; + std::string udid = "remoteUdid"; + + EXPECT_CALL(*deviceManagerServiceImplMock_, HandleAppUnBindEvent(userId, udid, accessTokenId, peerTokenId)).Times(1); + + deviceManagerServiceImpl_->ProcessUnBindApp(userId, accessTokenId, extra, udid); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, ProcessUnBindApp_004, testing::ext::TestSize.Level1) +{ + int32_t userId = 1; + int32_t accessTokenId = 1234; + std::string extra = R"({"peerTokenId": "invalid"})"; + std::string udid = "remoteUdid"; + + EXPECT_CALL(*deviceManagerServiceImplMock_, HandleAppUnBindEvent(userId, udid, accessTokenId)).Times(1); + + deviceManagerServiceImpl_->ProcessUnBindApp(userId, accessTokenId, extra, udid); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, ProcessUnBindApp_005, testing::ext::TestSize.Level1) +{ + int32_t userId = 1; + int32_t accessTokenId = 1234; + std::string extra = ""; + std::string udid = "remoteUdid"; + + EXPECT_CALL(*deviceManagerServiceImplMock_, HandleAppUnBindEvent(userId, udid, accessTokenId)).Times(1); + + deviceManagerServiceImpl_->ProcessUnBindApp(userId, accessTokenId, extra, udid); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, DeleteAclByTokenId_001, testing::ext::TestSize.Level1) +{ + int32_t accessTokenId = 1234; + std::vector profiles; + DistributedDeviceProfile::AccessControlProfile profile; + profile.GetAccesser().SetAccesserTokenId(5678); + profiles.push_back(profile); + + std::map delProfileMap; + std::vector> delACLInfoVec; + std::vector userIdVec; + + deviceManagerServiceImpl_->DeleteAclByTokenId(accessTokenId, profiles, delProfileMap, delACLInfoVec, userIdVec); + + EXPECT_TRUE(delProfileMap.empty()); + EXPECT_TRUE(delACLInfoVec.empty()); + EXPECT_TRUE(userIdVec.empty()); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, DeleteAclByTokenId_002, testing::ext::TestSize.Level1) +{ + int32_t accessTokenId = 1234; + std::vector profiles; + + std::map delProfileMap; + std::vector> delACLInfoVec; + std::vector userIdVec; + + deviceManagerServiceImpl_->DeleteAclByTokenId(accessTokenId, profiles, delProfileMap, delACLInfoVec, userIdVec); + + EXPECT_TRUE(profiles.empty()); + EXPECT_TRUE(delProfileMap.empty()); + EXPECT_TRUE(delACLInfoVec.empty()); + EXPECT_TRUE(userIdVec.empty()); +} } // namespace } // namespace DistributedHardware } // namespace OHOS diff --git a/test/unittest/UTTest_device_manager_service_impl_first.h b/test/unittest/UTTest_device_manager_service_impl_first.h index 0ed0c30c47b5b9fe5a2223c62a2ba3d8386ae45d..04dcec1a1384fd255bab2c5edbe2a1a769a837d7 100644 --- a/test/unittest/UTTest_device_manager_service_impl_first.h +++ b/test/unittest/UTTest_device_manager_service_impl_first.h @@ -29,6 +29,7 @@ #include "softbus_connector_mock.h" #include "dm_device_state_manager_mock.h" #include "device_manager_service_impl_mock.h" +#include "hichain_connector_mock.h" namespace OHOS { namespace DistributedHardware { @@ -51,6 +52,8 @@ public: std::make_shared(); static inline std::shared_ptr deviceManagerServiceImplMock_ = std::make_shared(); + static inline std::shared_ptr hiChainConnectorMock_ = + std::make_shared(); }; } // namespace DistributedHardware } // namespace OHOS diff --git a/test/unittest/UTTest_device_manager_service_three.cpp b/test/unittest/UTTest_device_manager_service_three.cpp index fdbadb7bbd26e56c7b1e5aa7b3c7fc82a29e537f..7a31597d6a91a5551b1eaabaf60cdb2db963981b 100644 --- a/test/unittest/UTTest_device_manager_service_three.cpp +++ b/test/unittest/UTTest_device_manager_service_three.cpp @@ -88,6 +88,8 @@ void DeviceManagerServiceThreeTest::TearDownTestCase() namespace { +const int32_t SEND_DELAY_MAX_TIME = 5; + void SetSetDnPolicyPermission() { const int32_t permsNum = 1; @@ -624,6 +626,196 @@ HWTEST_F(DeviceManagerServiceThreeTest, ClearDiscoveryCache_001, testing::ext::T EXPECT_NE(DeviceManagerService::GetInstance().discoveryMgr_, nullptr); DeviceManagerService::GetInstance().UninitDMServiceListener(); } + +HWTEST_F(DeviceManagerServiceThreeTest, ValidateUnBindDeviceParams_301, testing::ext::TestSize.Level1) +{ + std::string pkgName = "ohos.test.pkgName"; + std::string deviceId = "deviceId"; + EXPECT_CALL(*deviceManagerServiceMock_, IsDMServiceImplReady()).WillOnce(Return(ERR_DM_FAILED)); + int32_t ret = DeviceManagerService::GetInstance().ValidateUnBindDeviceParams(pkgName, deviceId); + EXPECT_EQ(ret, DM_OK); +} + +HWTEST_F(DeviceManagerServiceThreeTest, ValidateUnBindDeviceParams_302, testing::ext::TestSize.Level1) +{ + std::string pkgName = "ohos.test.pkgName"; + std::string deviceId = "deviceId"; + std::string extra; + EXPECT_CALL(*deviceManagerServiceMock_, IsDMServiceImplReady()).WillOnce(Return(ERR_DM_FAILED)); + int32_t ret = DeviceManagerService::GetInstance().ValidateUnBindDeviceParams(pkgName, deviceId, extra); + EXPECT_EQ(ret, DM_OK); +} + +HWTEST_F(DeviceManagerServiceThreeTest, ProcessUninstApp_301, testing::ext::TestSize.Level1) +{ + int32_t userId = 100; + int32_t tokenId = 200; + DeviceManagerService::GetInstance().softbusListener_ = std::make_shared(); + EXPECT_CALL(*deviceManagerServiceMock_, IsDMServiceImplReady()).WillOnce(Return(false)); + DeviceManagerService::GetInstance().ProcessUninstApp(userId, tokenId); + EXPECT_NE(DeviceManagerService::GetInstance().softbusListener_, nullptr); + DeviceManagerService::GetInstance().softbusListener_ = nullptr; +} + +HWTEST_F(DeviceManagerServiceThreeTest, ProcessUnBindApp_301, testing::ext::TestSize.Level1) +{ + int32_t userId = 100; + int32_t tokenId = 200; + std::string extra; + std::string udid = "ohos.test.udid"; + DeviceManagerService::GetInstance().softbusListener_ = std::make_shared(); + EXPECT_CALL(*deviceManagerServiceMock_, IsDMServiceImplReady()).WillOnce(Return(false)); + DeviceManagerService::GetInstance().ProcessUnBindApp(userId, tokenId, extra, udid); + EXPECT_NE(DeviceManagerService::GetInstance().softbusListener_, nullptr); + DeviceManagerService::GetInstance().softbusListener_ = nullptr; +} + +HWTEST_F(DeviceManagerServiceThreeTest, CalculateBroadCastDelayTime_001, testing::ext::TestSize.Level1) +{ + DeviceManagerService::GetInstance().SendLastBroadCastTime_ = 10; + int32_t delayTime = DeviceManagerService::GetInstance().CalculateBroadCastDelayTime(); + EXPECT_NE(delayTime, SEND_DELAY_MAX_TIME); +} + +HWTEST_F(DeviceManagerServiceThreeTest, CalculateBroadCastDelayTime_002, testing::ext::TestSize.Level1) +{ + int32_t delayTime = DeviceManagerService::GetInstance().CalculateBroadCastDelayTime(); + EXPECT_NE(delayTime, SEND_DELAY_MAX_TIME); +} +HWTEST_F(DeviceManagerServiceThreeTest, ParseRelationShipChangeType_001, testing::ext::TestSize.Level1) +{ + RelationShipChangeMsg msg; + msg.type = RelationShipChangeType::APP_UNINSTALL; + auto ret = DeviceManagerService::GetInstance().ParseRelationShipChangeType(msg); + EXPECT_EQ(ret, true); +} + +HWTEST_F(DeviceManagerServiceThreeTest, SubscribePackageCommonEvent_301, testing::ext::TestSize.Level1) +{ + DeviceManagerService::GetInstance().packageCommonEventManager_ = std::make_shared(); + DeviceManagerService::GetInstance().softbusListener_ = std::make_shared(); + EXPECT_NE(DeviceManagerService::GetInstance().softbusListener_, nullptr); + DeviceManagerService::GetInstance().softbusListener_ = nullptr; + +} + +HWTEST_F(DeviceManagerServiceThreeTest, SubscribePackageCommonEvent_302, testing::ext::TestSize.Level1) +{ + DeviceManagerService::GetInstance().packageCommonEventManager_ = std::make_shared(); + DeviceManagerService::GetInstance().softbusListener_ = std::make_shared(); + EXPECT_NE(DeviceManagerService::GetInstance().softbusListener_, nullptr); + DeviceManagerService::GetInstance().softbusListener_ = nullptr; +} + +HWTEST_F(DeviceManagerServiceThreeTest, SubscribePackageCommonEvent_303, testing::ext::TestSize.Level1) +{ + DeviceManagerService::GetInstance().packageCommonEventManager_ = nullptr; + DeviceManagerService::GetInstance().softbusListener_ = std::make_shared(); + EXPECT_NE(DeviceManagerService::GetInstance().softbusListener_, nullptr); + DeviceManagerService::GetInstance().softbusListener_ = nullptr; +} + +HWTEST_F(DeviceManagerServiceThreeTest, SubscribePackageCommonEvent_304, testing::ext::TestSize.Level1) +{ + DeviceManagerService::GetInstance().packageCommonEventManager_ = nullptr; + DeviceManagerService::GetInstance().softbusListener_ = std::make_shared(); + EXPECT_NE(DeviceManagerService::GetInstance().softbusListener_, nullptr); + DeviceManagerService::GetInstance().softbusListener_ = nullptr; +} + +HWTEST_F(DeviceManagerServiceThreeTest, NotifyRemoteUninstallApp_301, testing::ext::TestSize.Level1) +{ + int32_t userId = 100; + int32_t tokenId = 200; + DeviceManagerService::GetInstance().softbusListener_ = std::make_shared(); + EXPECT_CALL(*deviceManagerServiceMock_, IsDMServiceImplReady()).WillOnce(Return(false)); + DeviceManagerService::GetInstance().NotifyRemoteUninstallApp(userId, tokenId); + EXPECT_NE(DeviceManagerService::GetInstance().softbusListener_, nullptr); + DeviceManagerService::GetInstance().softbusListener_ = nullptr; +} + +HWTEST_F(DeviceManagerServiceThreeTest, NotifyRemoteUninstallApp_302, testing::ext::TestSize.Level1) +{ + int32_t userId = 100; + int32_t tokenId = 200; + DeviceManagerService::GetInstance().softbusListener_ = nullptr; + EXPECT_CALL(*deviceManagerServiceMock_, IsDMServiceImplReady()).WillOnce(Return(false)); + DeviceManagerService::GetInstance().NotifyRemoteUninstallApp(userId, tokenId); + EXPECT_EQ(DeviceManagerService::GetInstance().softbusListener_, nullptr); +} + +HWTEST_F(DeviceManagerServiceThreeTest, NotifyRemoteUninstallAppByWifi_001, testing::ext::TestSize.Level1) +{ + int32_t userId = 100; + int32_t tokenId = 200; + std::map wifiDevices; + DeviceManagerService::GetInstance().timer_ = nullptr; + DeviceManagerService::GetInstance().NotifyRemoteUninstallAppByWifi(userId, tokenId, wifiDevices); + EXPECT_EQ(DeviceManagerService::GetInstance().timer_, nullptr); +} + +HWTEST_F(DeviceManagerServiceThreeTest, NotifyRemoteUninstallAppByWifi_002, testing::ext::TestSize.Level1) +{ + int32_t userId = 100; + int32_t tokenId = 200; + std::map wifiDevices; + DeviceManagerService::GetInstance().timer_ = std::make_shared(); + DeviceManagerService::GetInstance().NotifyRemoteUninstallAppByWifi(userId, tokenId, wifiDevices); + EXPECT_NE(DeviceManagerService::GetInstance().timer_, nullptr); +} + +HWTEST_F(DeviceManagerServiceThreeTest, NotifyRemoteUninstallAppByWifi_003, testing::ext::TestSize.Level1) +{ + int32_t userId = 100; + int32_t tokenId = 200; + std::map wifiDevices; + DeviceManagerService::GetInstance().timer_ = nullptr; + DeviceManagerService::GetInstance().NotifyRemoteUninstallAppByWifi(userId, tokenId, wifiDevices); + EXPECT_EQ(DeviceManagerService::GetInstance().timer_, nullptr); +} + +HWTEST_F(DeviceManagerServiceThreeTest, NotifyRemoteUnBindAppByWifi_001, testing::ext::TestSize.Level1) +{ + int32_t userId = 100; + int32_t tokenId = 200; + std::map wifiDevices; + std::string extra; + DeviceManagerService::GetInstance().timer_ = std::make_shared(); + DeviceManagerService::GetInstance().NotifyRemoteUnBindAppByWifi(userId, tokenId, extra, wifiDevices); + EXPECT_NE(DeviceManagerService::GetInstance().timer_, nullptr); +} + +HWTEST_F(DeviceManagerServiceThreeTest, ProcessReceiveRspAppUninstall_301, testing::ext::TestSize.Level1) +{ + std::string remoteUdid = "ohos"; + DeviceManagerService::GetInstance().timer_ = std::make_shared(); + DeviceManagerService::GetInstance().ProcessReceiveRspAppUninstall(remoteUdid); + EXPECT_NE(DeviceManagerService::GetInstance().timer_, nullptr); +} + +HWTEST_F(DeviceManagerServiceThreeTest, ProcessReceiveRspAppUninstall_302, testing::ext::TestSize.Level1) +{ + std::string remoteUdid = "ohos"; + DeviceManagerService::GetInstance().timer_ = nullptr; + DeviceManagerService::GetInstance().ProcessReceiveRspAppUninstall(remoteUdid); + EXPECT_EQ(DeviceManagerService::GetInstance().timer_, nullptr); +} + +HWTEST_F(DeviceManagerServiceThreeTest, ProcessReceiveRspAppUnbind_301, testing::ext::TestSize.Level1) +{ + std::string remoteUdid = "ohos"; + DeviceManagerService::GetInstance().timer_ = std::make_shared(); + DeviceManagerService::GetInstance().ProcessReceiveRspAppUnbind(remoteUdid); + EXPECT_NE(DeviceManagerService::GetInstance().timer_, nullptr); +} + +HWTEST_F(DeviceManagerServiceThreeTest, ProcessReceiveRspAppUnbind_302, testing::ext::TestSize.Level1) +{ + std::string remoteUdid = "ohos"; + DeviceManagerService::GetInstance().timer_ = nullptr; + DeviceManagerService::GetInstance().ProcessReceiveRspAppUnbind(remoteUdid); + EXPECT_EQ(DeviceManagerService::GetInstance().timer_, nullptr); +} } // namespace } // namespace DistributedHardware } // namespace OHOS diff --git a/test/unittest/UTTest_device_manager_service_two.cpp b/test/unittest/UTTest_device_manager_service_two.cpp index 7f15c8ffe7d1b602d0f7a5325099212452d616bc..c9cb5fd7e4224ce5abd7a914fdffcb202030f0b3 100644 --- a/test/unittest/UTTest_device_manager_service_two.cpp +++ b/test/unittest/UTTest_device_manager_service_two.cpp @@ -1879,6 +1879,85 @@ HWTEST_F(DeviceManagerServiceTest, GetLocalDeviceName_201, testing::ext::TestSiz int32_t ret = DeviceManagerService::GetInstance().GetLocalDeviceName(deviceName); EXPECT_EQ(ret, DM_OK); } + +HWTEST_F(DeviceManagerServiceTest, ValidateUnBindDeviceParams_201, testing::ext::TestSize.Level1) +{ + std::string pkgName = ""; + std::string deviceId = ""; + int32_t ret = DeviceManagerService::GetInstance().ValidateUnBindDeviceParams(pkgName, deviceId); + EXPECT_EQ(ret, ERR_DM_INPUT_PARA_INVALID); +} + +HWTEST_F(DeviceManagerServiceTest, ValidateUnBindDeviceParams_202, testing::ext::TestSize.Level1) +{ + std::string pkgName = "ohos.test.pkgName"; + std::string deviceId = "deviceId"; + DeletePermission(); + int32_t ret = DeviceManagerService::GetInstance().ValidateUnBindDeviceParams(pkgName, deviceId); + EXPECT_EQ(ret, ERR_DM_NO_PERMISSION); +} + +HWTEST_F(DeviceManagerServiceTest, ValidateUnBindDeviceParams_203, testing::ext::TestSize.Level1) +{ + std::string pkgName = ""; + std::string deviceId = ""; + std::string extra; + int32_t ret = DeviceManagerService::GetInstance().ValidateUnBindDeviceParams(pkgName, deviceId, extra); + EXPECT_EQ(ret, ERR_DM_INPUT_PARA_INVALID); +} + +HWTEST_F(DeviceManagerServiceTest, ValidateUnBindDeviceParams_204, testing::ext::TestSize.Level1) +{ + std::string pkgName = "ohos.test.pkgName"; + std::string deviceId = "deviceId"; + std::string extra; + DeletePermission(); + int32_t ret = DeviceManagerService::GetInstance().ValidateUnBindDeviceParams(pkgName, deviceId, extra); + EXPECT_EQ(ret, ERR_DM_NO_PERMISSION); +} + +HWTEST_F(DeviceManagerServiceTest, SendUninstAppByWifi_001, testing::ext::TestSize.Level1) +{ + int32_t userId = 1001; + int32_t tokenId = 1002; + std::string networkId = "networkId123"; + EXPECT_CALL(*dMCommToolMock_, SendUninstAppObj(_, _, _)).WillOnce(Return(DM_OK)); + int32_t ret = DeviceManagerService::GetInstance().SendUninstAppByWifi(userId, tokenId, networkId); + EXPECT_EQ(ret, DM_OK); +} + +HWTEST_F(DeviceManagerServiceTest, SendUninstAppByWifi_002, testing::ext::TestSize.Level1) +{ + int32_t userId = 1001; + int32_t tokenId = 1002; + std::string networkId = "networkId123"; + EXPECT_CALL(*dMCommToolMock_, SendUninstAppObj(_, _, _)).WillOnce(Return(ERR_DM_FAILED)); + int32_t ret = DeviceManagerService::GetInstance().SendUninstAppByWifi(userId, tokenId, networkId); + EXPECT_EQ(ret, ERR_DM_FAILED); +} + +HWTEST_F(DeviceManagerServiceTest, GetNotifyRemoteUnBindAppWay_001, testing::ext::TestSize.Level1) +{ + int32_t userId = 1001; + int32_t tokenId = 11; + std::map wifiDevices; + bool isBleWay = false; + DeviceManagerService::GetInstance().softbusListener_ = std::make_shared(); + DeviceManagerService::GetInstance().GetNotifyRemoteUnBindAppWay(userId, tokenId, wifiDevices, isBleWay); + EXPECT_NE(DeviceManagerService::GetInstance().softbusListener_, nullptr); + DeviceManagerService::GetInstance().softbusListener_ = nullptr; +} +HWTEST_F(DeviceManagerServiceTest, GetNotifyRemoteUnBindAppWay_002, testing::ext::TestSize.Level1) +{ + int32_t userId = 1001; + int32_t tokenId = 11; + std::map wifiDevices; + bool isBleWay = false; + DeviceManagerService::GetInstance().softbusListener_ = nullptr; + DeviceManagerService::GetInstance().GetNotifyRemoteUnBindAppWay(userId, tokenId, wifiDevices, isBleWay); + EXPECT_EQ(DeviceManagerService::GetInstance().softbusListener_, nullptr); + +} } // namespace } // namespace DistributedHardware } // namespace OHOS diff --git a/test/unittest/UTTest_dm_comm_tool.cpp b/test/unittest/UTTest_dm_comm_tool.cpp index 0f8971cf88f54a38cbf868f495d3b4c4c4216b01..1d940323223f1bbe760cbf27f678680ec39f5950 100644 --- a/test/unittest/UTTest_dm_comm_tool.cpp +++ b/test/unittest/UTTest_dm_comm_tool.cpp @@ -468,5 +468,290 @@ HWTEST_F(DMCommToolTest, ProcessResponseUserStopEvent_004, testing::ext::TestSiz EXPECT_NO_THROW(dmCommTool->ProcessResponseUserStopEvent(commMsg)); } +HWTEST_F(DMCommToolTest, SendUninstAppObj_001, testing::ext::TestSize.Level1) +{ + int32_t userId = 0; + int32_t tokenId = 0; + std::string networkId = ""; + int32_t result = dmCommTool->SendUninstAppObj(userId, tokenId, networkId); + EXPECT_EQ(result, ERR_DM_INPUT_PARA_INVALID); +} + +HWTEST_F(DMCommToolTest, SendUninstAppObj_002, testing::ext::TestSize.Level1) +{ + int32_t userId = 0; + int32_t tokenId = 0; + std::string networkId = "123456"; + dmCommTool->dmTransportPtr_ = nullptr; + int32_t result = dmCommTool->SendUninstAppObj(userId, tokenId, networkId); + EXPECT_EQ(result, ERR_DM_FAILED); +} + +HWTEST_F(DMCommToolTest, SendUninstAppObj_003, testing::ext::TestSize.Level1) +{ + int32_t userId = 0; + int32_t tokenId = 0; + std::string networkId = "123456"; + + EXPECT_CALL(*dmTransportMock_, StartSocket(_, _)).WillOnce(Return(ERR_DM_FAILED)); + int32_t result = dmCommTool->SendUninstAppObj(userId, tokenId, networkId); + EXPECT_EQ(result, ERR_DM_FAILED); + + EXPECT_CALL(*dmTransportMock_, StartSocket(_, _)).WillOnce(DoAll(SetArgReferee<1>(1), Return(DM_OK))); + EXPECT_CALL(*dmTransportMock_, Send(_, _, _)).WillOnce(Return(ERR_DM_FAILED)); + result = dmCommTool->SendUninstAppObj(userId, tokenId, networkId); + EXPECT_EQ(result, ERR_DM_FAILED); + + EXPECT_CALL(*dmTransportMock_, StartSocket(_, _)).WillOnce(DoAll(SetArgReferee<1>(1), Return(DM_OK))); + EXPECT_CALL(*dmTransportMock_, Send(_, _, _)).WillOnce(Return(DM_OK)); + result = dmCommTool->SendUninstAppObj(userId, tokenId, networkId); + EXPECT_EQ(result, DM_OK); +} + +HWTEST_F(DMCommToolTest, RspAppUninstall_001, testing::ext::TestSize.Level1) +{ + int32_t socketId = 0; + std::string rmtNetworkId = ""; + dmCommTool->dmTransportPtr_ = nullptr; + int32_t result = dmCommTool->RspAppUninstall(rmtNetworkId, socketId); + EXPECT_EQ(result, ERR_DM_FAILED); +} + +HWTEST_F(DMCommToolTest, RspAppUninstall_002, testing::ext::TestSize.Level1) +{ + int32_t socketId = 0; + std::string rmtNetworkId = ""; + EXPECT_CALL(*dmTransportMock_, Send(_, _, _)).WillOnce(Return(ERR_DM_FAILED)); + int32_t result = dmCommTool->RspAppUninstall(rmtNetworkId, socketId); + EXPECT_EQ(result, ERR_DM_FAILED); +} + +HWTEST_F(DMCommToolTest, RspAppUninstall_003, testing::ext::TestSize.Level1) +{ + int32_t socketId = 0; + std::string rmtNetworkId = ""; + EXPECT_CALL(*dmTransportMock_, Send(_, _, _)).WillOnce(Return(DM_OK)); + int32_t result = dmCommTool->RspAppUninstall(rmtNetworkId, socketId); + EXPECT_EQ(result, DM_OK); +} + +HWTEST_F(DMCommToolTest, RspAppUnbind_001, testing::ext::TestSize.Level1) +{ + int32_t socketId = 0; + std::string rmtNetworkId = ""; + dmCommTool->dmTransportPtr_ = nullptr; + int32_t result = dmCommTool->RspAppUnbind(rmtNetworkId, socketId); + EXPECT_EQ(result, ERR_DM_FAILED); +} + +HWTEST_F(DMCommToolTest, RspAppUnbind_002, testing::ext::TestSize.Level1) +{ + int32_t socketId = 0; + std::string rmtNetworkId = ""; + EXPECT_CALL(*dmTransportMock_, Send(_, _, _)).WillOnce(Return(ERR_DM_FAILED)); + int32_t result = dmCommTool->RspAppUnbind(rmtNetworkId, socketId); + EXPECT_EQ(result, ERR_DM_FAILED); +} + +HWTEST_F(DMCommToolTest, RspAppUnbind_003, testing::ext::TestSize.Level1) +{ + int32_t socketId = 0; + std::string rmtNetworkId = ""; + EXPECT_CALL(*dmTransportMock_, Send(_, _, _)).WillOnce(Return(DM_OK)); + int32_t result = dmCommTool->RspAppUnbind(rmtNetworkId, socketId); + EXPECT_EQ(result, DM_OK); +} + +HWTEST_F(DMCommToolTest, SendUnBindAppObj_001, testing::ext::TestSize.Level1) +{ + int32_t userId = 0; + int32_t tokenId = 0; + std::string extra = ""; + std::string networkId = ""; + std::string udid = "12211"; + int32_t result = dmCommTool->SendUnBindAppObj(userId, tokenId, extra, networkId, udid); + EXPECT_EQ(result, ERR_DM_INPUT_PARA_INVALID); +} + +HWTEST_F(DMCommToolTest, SendUnBindAppObj_002, testing::ext::TestSize.Level1) +{ + int32_t userId = 0; + int32_t tokenId = 0; + std::string extra = ""; + std::string networkId = "123456"; + std::string udid = "12211"; + dmCommTool->dmTransportPtr_ = nullptr; + int32_t result = dmCommTool->SendUnBindAppObj(userId, tokenId, extra, networkId, udid); + EXPECT_EQ(result, ERR_DM_FAILED); +} + +HWTEST_F(DMCommToolTest, SendUnBindAppObj_003, testing::ext::TestSize.Level1) +{ + int32_t userId = 0; + int32_t tokenId = 0; + std::string extra = ""; + std::string networkId = "123456"; + std::string udid = "12211"; + + EXPECT_CALL(*dmTransportMock_, StartSocket(_, _)).WillOnce(Return(ERR_DM_FAILED)); + int32_t result = dmCommTool->SendUnBindAppObj(userId, tokenId, extra, networkId, udid); + EXPECT_EQ(result, ERR_DM_FAILED); + + EXPECT_CALL(*dmTransportMock_, StartSocket(_, _)).WillOnce(DoAll(SetArgReferee<1>(1), Return(DM_OK))); + EXPECT_CALL(*dmTransportMock_, Send(_, _, _)).WillOnce(Return(ERR_DM_FAILED)); + result = dmCommTool->SendUnBindAppObj(userId, tokenId, extra, networkId, udid); + EXPECT_EQ(result, ERR_DM_FAILED); + + EXPECT_CALL(*dmTransportMock_, StartSocket(_, _)).WillOnce(DoAll(SetArgReferee<1>(1), Return(DM_OK))); + EXPECT_CALL(*dmTransportMock_, Send(_, _, _)).WillOnce(Return(DM_OK)); + result = dmCommTool->SendUnBindAppObj(userId, tokenId, extra, networkId, udid); + EXPECT_EQ(result, DM_OK); +} + +HWTEST_F(DMCommToolTest, ProcessReceiveUninstAppEvent_001, testing::ext::TestSize.Level1) +{ + std::shared_ptr commMsg = nullptr; + EXPECT_NO_THROW(dmCommTool->ProcessReceiveUninstAppEvent(commMsg)); +} + +HWTEST_F(DMCommToolTest, ProcessReceiveUninstAppEvent_002, testing::ext::TestSize.Level1) +{ + std::shared_ptr commMsg_ = std::make_shared(1, "invalid_json"); + std::shared_ptr commMsg = std::make_shared("networkId", commMsg_, 0); + EXPECT_NO_THROW(dmCommTool->ProcessReceiveUninstAppEvent(commMsg)); +} + +HWTEST_F(DMCommToolTest, ProcessReceiveUninstAppEvent_003, testing::ext::TestSize.Level1) +{ + std::string validJson = R"({ "userId": "aaa" })"; + std::shared_ptr commMsg_ = std::make_shared(1, validJson); + std::shared_ptr commMsg = std::make_shared("networkId", commMsg_, 0); + EXPECT_CALL(*dmTransportMock_, Send(_, _, _)).WillOnce(Return(DM_OK)); + EXPECT_NO_THROW(dmCommTool->ProcessReceiveUninstAppEvent(commMsg)); +} + +HWTEST_F(DMCommToolTest, ProcessReceiveUninstAppEvent_004, testing::ext::TestSize.Level1) +{ + std::string validJson = R"({ "userId": "1234", "tokenId": "1234" })"; + std::shared_ptr commMsg_ = std::make_shared(1, validJson); + std::shared_ptr commMsg = std::make_shared("networkId", commMsg_, 0); + EXPECT_CALL(*dmTransportMock_, Send(_, _, _)).WillOnce(Return(DM_OK)); + EXPECT_NO_THROW(dmCommTool->ProcessReceiveUninstAppEvent(commMsg)); +} + +HWTEST_F(DMCommToolTest, ProcessReceiveUnBindAppEvent_001, testing::ext::TestSize.Level1) +{ + std::shared_ptr commMsg = nullptr; + EXPECT_NO_THROW(dmCommTool->ProcessReceiveUnBindAppEvent(commMsg)); +} + +HWTEST_F(DMCommToolTest, ProcessReceiveUnBindAppEvent_002, testing::ext::TestSize.Level1) +{ + std::shared_ptr commMsg_ = std::make_shared(1, "invalid_json"); + std::shared_ptr commMsg = std::make_shared("networkId", commMsg_, 0); + EXPECT_NO_THROW(dmCommTool->ProcessReceiveUnBindAppEvent(commMsg)); +} + +HWTEST_F(DMCommToolTest, ProcessReceiveUnBindAppEvent_003, testing::ext::TestSize.Level1) +{ + std::string validJson = R"({ "userId": "aaa", "tokenId": "bbb" })"; + std::shared_ptr commMsg_ = std::make_shared(1, validJson); + std::shared_ptr commMsg = std::make_shared("networkId", commMsg_, 0); + EXPECT_CALL(*dmTransportMock_, Send(_, _, _)).WillOnce(Return(DM_OK)); + EXPECT_NO_THROW(dmCommTool->ProcessReceiveUnBindAppEvent(commMsg)); +} + +HWTEST_F(DMCommToolTest, ProcessReceiveUnBindAppEvent_004, testing::ext::TestSize.Level1) +{ + std::string validJson = R"({ "userId": "1234", "tokenId": "1234" })"; + std::shared_ptr commMsg_ = std::make_shared(1, validJson); + std::shared_ptr commMsg = std::make_shared("networkId", commMsg_, 0); + EXPECT_CALL(*dmTransportMock_, Send(_, _, _)).WillOnce(Return(DM_OK)); + EXPECT_NO_THROW(dmCommTool->ProcessReceiveUnBindAppEvent(commMsg)); +} + +HWTEST_F(DMCommToolTest, StopSocket_001, testing::ext::TestSize.Level1) +{ + std::string networkId = "123456"; + dmCommTool->dmTransportPtr_ = nullptr; + EXPECT_NO_THROW(dmCommTool->StopSocket(networkId)); +} + +HWTEST_F(DMCommToolTest, StopSocket_002, testing::ext::TestSize.Level1) +{ + std::string networkId = "123456"; + EXPECT_NO_THROW(dmCommTool->StopSocket(networkId)); +} + +HWTEST_F(DMCommToolTest, ProcessReceiveRspAppUninstallEvent_001, testing::ext::TestSize.Level1) +{ + std::shared_ptr commMsg = nullptr; + EXPECT_NO_THROW(dmCommTool->ProcessReceiveRspAppUninstallEvent(commMsg)); +} + +HWTEST_F(DMCommToolTest, ProcessReceiveRspAppUninstallEvent_002, testing::ext::TestSize.Level1) +{ + std::string validJson = R"({ "userId": "1234", "tokenId": "1234" })"; + std::shared_ptr commMsg_ = std::make_shared(1, validJson); + std::shared_ptr commMsg = std::make_shared("networkId", commMsg_, 0); + dmCommTool->dmTransportPtr_ = nullptr; + EXPECT_NO_THROW(dmCommTool->ProcessReceiveRspAppUninstallEvent(commMsg)); +} + +HWTEST_F(DMCommToolTest, ProcessReceiveRspAppUninstallEvent_003, testing::ext::TestSize.Level1) +{ + std::string validJson = R"({ "userId": "1234", "tokenId": "1234" })"; + std::shared_ptr commMsg_ = std::make_shared(1, validJson); + std::shared_ptr commMsg = std::make_shared("networkId", commMsg_, 0); + EXPECT_CALL(*softbusCacheMock_, GetUdidFromCache(_, _)) + .WillOnce(DoAll(SetArgReferee<1>(""), Return(ERR_DM_FAILED))); + EXPECT_NO_THROW(dmCommTool->ProcessReceiveRspAppUninstallEvent(commMsg)); +} + +HWTEST_F(DMCommToolTest, ProcessReceiveRspAppUninstallEvent_004, testing::ext::TestSize.Level1) +{ + std::string validJson = R"({ "userId": "1234", "tokenId": "1234" })"; + std::shared_ptr commMsg_ = std::make_shared(1, validJson); + std::shared_ptr commMsg = std::make_shared("networkId", commMsg_, 0); + EXPECT_CALL(*softbusCacheMock_, GetUdidFromCache(_, _)) + .WillOnce(DoAll(SetArgReferee<1>("validUdid"), Return(DM_OK))); + EXPECT_NO_THROW(dmCommTool->ProcessReceiveRspAppUninstallEvent(commMsg)); +} + +HWTEST_F(DMCommToolTest, ProcessReceiveRspAppUnbindEvent_001, testing::ext::TestSize.Level1) +{ + std::shared_ptr commMsg = nullptr; + EXPECT_NO_THROW(dmCommTool->ProcessReceiveRspAppUnbindEvent(commMsg)); +} + +HWTEST_F(DMCommToolTest, ProcessReceiveRspAppUnbindEvent_002, testing::ext::TestSize.Level1) +{ + std::string validJson = R"({ "userId": "1234", "tokenId": "1234" })"; + std::shared_ptr commMsg_ = std::make_shared(1, validJson); + std::shared_ptr commMsg = std::make_shared("networkId", commMsg_, 0); + dmCommTool->dmTransportPtr_ = nullptr; + EXPECT_NO_THROW(dmCommTool->ProcessReceiveRspAppUnbindEvent(commMsg)); +} + +HWTEST_F(DMCommToolTest, ProcessReceiveRspAppUnbindEvent_003, testing::ext::TestSize.Level1) +{ + std::string validJson = R"({ "userId": "1234", "tokenId": "1234" })"; + std::shared_ptr commMsg_ = std::make_shared(1, validJson); + std::shared_ptr commMsg = std::make_shared("networkId", commMsg_, 0); + EXPECT_CALL(*softbusCacheMock_, GetUdidFromCache(_, _)) + .WillOnce(DoAll(SetArgReferee<1>(""), Return(ERR_DM_FAILED))); + EXPECT_NO_THROW(dmCommTool->ProcessReceiveRspAppUnbindEvent(commMsg)); +} + +HWTEST_F(DMCommToolTest, ProcessReceiveRspAppUnbindEvent_004, testing::ext::TestSize.Level1) +{ + std::string validJson = R"({ "userId": "1234", "tokenId": "1234" })"; + std::shared_ptr commMsg_ = std::make_shared(1, validJson); + std::shared_ptr commMsg = std::make_shared("networkId", commMsg_, 0); + EXPECT_CALL(*softbusCacheMock_, GetUdidFromCache(_, _)) + .WillOnce(DoAll(SetArgReferee<1>("validUdid"), Return(DM_OK))); + EXPECT_NO_THROW(dmCommTool->ProcessReceiveRspAppUnbindEvent(commMsg)); +} + } // DistributedHardware } // OHOS \ No newline at end of file diff --git a/test/unittest/UTTest_dm_transport_msg.cpp b/test/unittest/UTTest_dm_transport_msg.cpp index 87900c12e8d722cfe8f425d352d73c4b67fb688a..072213267a69a91b8db485d6a881e8fda3127b1c 100644 --- a/test/unittest/UTTest_dm_transport_msg.cpp +++ b/test/unittest/UTTest_dm_transport_msg.cpp @@ -357,5 +357,67 @@ HWTEST_F(DMTransportMsgTest, ToString_01, testing::ext::TestSize.Level1) auto notifyUserIdsString = notifyUserIds.ToString(); EXPECT_EQ(notifyUserIdsString, jsonObj); } + +HWTEST_F(DMTransportMsgTest, UninstAppToJsonAndFromJson, testing::ext::TestSize.Level1) +{ + UninstAppMsg uninstAppMsg(2, 3); + + cJSON *jsonObject = cJSON_CreateObject(); + ToJson(jsonObject, uninstAppMsg); + + UninstAppMsg newUninstAppMsg; + FromJson(jsonObject, newUninstAppMsg); + + EXPECT_EQ(newUninstAppMsg.userId_, 2); + EXPECT_EQ(newUninstAppMsg.tokenId_, 3); + + cJSON_Delete(jsonObject); + + cJSON *nullJsonObject = nullptr; + ToJson(nullJsonObject, uninstAppMsg); + + UninstAppMsg emptyMsg; + FromJson(nullJsonObject, emptyMsg); + + EXPECT_EQ(emptyMsg.userId_, -1); + cJSON *emptyObject = cJSON_CreateObject(); + FromJson(emptyObject, emptyMsg); + EXPECT_EQ(emptyMsg.userId_, -1); + + cJSON_Delete(nullJsonObject); + cJSON_Delete(emptyObject); +} + +HWTEST_F(DMTransportMsgTest, UnbindAppToJsonAndFromJson, testing::ext::TestSize.Level1) +{ + UnBindAppMsg unBindAppMsg(2, 3, "", "test_udid"); + + cJSON *jsonObject = cJSON_CreateObject(); + ToJson(jsonObject, unBindAppMsg); + + UnBindAppMsg newUnBindAppMsg; + FromJson(jsonObject, newUnBindAppMsg); + + EXPECT_EQ(newUnBindAppMsg.userId_, 2); + EXPECT_EQ(newUnBindAppMsg.tokenId_, 3); + EXPECT_EQ(newUnBindAppMsg.extra_, ""); + EXPECT_EQ(newUnBindAppMsg.udid_, "test_udid"); + + cJSON_Delete(jsonObject); + + cJSON *nullJsonObject = nullptr; + ToJson(nullJsonObject, unBindAppMsg); + + UnBindAppMsg emptyMsg; + FromJson(nullJsonObject, emptyMsg); + + EXPECT_EQ(emptyMsg.userId_, -1); + cJSON *emptyObject = cJSON_CreateObject(); + FromJson(emptyObject, emptyMsg); + EXPECT_EQ(emptyMsg.userId_, -1); + + cJSON_Delete(nullJsonObject); + cJSON_Delete(emptyObject); +} } // DistributedHardware } // OHOS \ No newline at end of file diff --git a/test/unittest/UTTest_relationship_sync_mgr.cpp b/test/unittest/UTTest_relationship_sync_mgr.cpp index eddc9b49ef759cf7830c49df24743c56b4784d8b..398e4ef0774dfc1f3a2990e411d0498c7635ddcb 100644 --- a/test/unittest/UTTest_relationship_sync_mgr.cpp +++ b/test/unittest/UTTest_relationship_sync_mgr.cpp @@ -912,6 +912,10 @@ HWTEST_F(ReleationShipSyncMgrTest, FromBroadcastPayLoad_010, testing::ext::TestS type = RelationShipChangeType::SHARE_UNBIND; ret = msg.FromBroadcastPayLoad(payloadJson, type); EXPECT_FALSE(ret); + + type = RelationShipChangeType::APP_UNINSTALL; + ret = msg.FromBroadcastPayLoad(payloadJson, type); + EXPECT_FALSE(ret); } HWTEST_F(ReleationShipSyncMgrTest, IsChangeTypeValid_001, testing::ext::TestSize.Level1) @@ -968,6 +972,19 @@ HWTEST_F(ReleationShipSyncMgrTest, IsValid_011, testing::ext::TestSize.Level1) ASSERT_FALSE(msg.IsValid()); } +HWTEST_F(ReleationShipSyncMgrTest, IsValid_012, testing::ext::TestSize.Level1) +{ + RelationShipChangeMsg msg; + msg.type = RelationShipChangeType::APP_UNINSTALL; + msg.userId = 12345; + msg.tokenId = 12345; + + ASSERT_TRUE(msg.IsValid()); + + msg.userId = UINT32_MAX; + ASSERT_FALSE(msg.IsValid()); +} + /** * @tc.name: ToBroadcastPayLoad_001 * @tc.type: FUNC @@ -1230,6 +1247,23 @@ HWTEST_F(ReleationShipSyncMgrTest, ToBroadcastPayLoad_012, testing::ext::TestSiz EXPECT_EQ(result, false); } +HWTEST_F(ReleationShipSyncMgrTest, ToBroadcastPayLoad_013, testing::ext::TestSize.Level1) +{ + RelationShipChangeMsg msg; + msg.type = RelationShipChangeType::APP_UNINSTALL; + msg.userId = 12345; + msg.tokenId = 67890; + msg.peerUdids = {"udid1", "udid2"}; + + uint8_t* msgPtr = nullptr; + uint32_t len = 0; + + bool result = msg.ToBroadcastPayLoad(msgPtr, len); + ASSERT_TRUE(result); + + delete[] msgPtr; +} + HWTEST_F(ReleationShipSyncMgrTest, ToShareUnbindPayLoad_001, testing::ext::TestSize.Level1) { RelationShipChangeMsg msg; @@ -1383,6 +1417,49 @@ HWTEST_F(ReleationShipSyncMgrTest, FromShareUnbindPayLoad_005, testing::ext::Tes cJSON_Delete(payloadJson); } +HWTEST_F(ReleationShipSyncMgrTest, ToAppUninstallPayLoad_001, testing::ext::TestSize.Level1) +{ + RelationShipChangeMsg msg; + msg.userId = 12345; + msg.tokenId = 67890; + msg.broadCastId = 0; + uint8_t* msgPtr = nullptr; + uint32_t len = 0; + msg.ToAppUninstallPayLoad(msgPtr, len); + ASSERT_EQ(len, 7); +} + +HWTEST_F(ReleationShipSyncMgrTest, FromAppUninstallPayLoad_001, testing::ext::TestSize.Level1) +{ + RelationShipChangeMsg msg; + cJSON payloadJson; + bool result = msg.FromAppUninstallPayLoad(&payloadJson); + ASSERT_EQ(result, false); + result = msg.FromAppUninstallPayLoad(nullptr); + ASSERT_EQ(result, false); + const char* jsonString = R"({ + "MsgType": "0", + "userId": "12345", + "accountId": "a******3", + "tokenId": 67890, + "peerUdids": ["u******1", "u******2"], + "peerUdid": "p******d", + "accountName": "t******t", + "syncUserIdFlag": 1, + "test1": 1, + "test2": 2, + "test3": 3, + "test4": 4, + "userIds": [ + {"type": 1, "userId": 111}, + {"type": 0, "userId": 222} + ] + })"; + cJSON *jsonObject = cJSON_Parse(jsonString); + result = msg.FromAppUninstallPayLoad(jsonObject); + ASSERT_EQ(result, false); +} + } } // namespace DistributedHardware } // namespace OHOS diff --git a/test/unittest/mock/device_manager_service_impl_mock.cpp b/test/unittest/mock/device_manager_service_impl_mock.cpp index d4cbeecf6646b7969c63fa78cec076ac084f7e58..d1ba3eb32a58cbdef8d18b5416febbd783528d7c 100644 --- a/test/unittest/mock/device_manager_service_impl_mock.cpp +++ b/test/unittest/mock/device_manager_service_impl_mock.cpp @@ -89,5 +89,18 @@ int32_t DeviceManagerServiceImpl::CheckDeviceInfoPermission(const std::string &l { return DmDeviceManagerServiceImpl::dmDeviceManagerServiceImpl->CheckDeviceInfoPermission(localUdid, peerDeviceId); } + +void DeviceManagerServiceImpl::HandleAppUnBindEvent(int32_t remoteUserId, const std::string &remoteUdid, + int32_t tokenId) +{ + DmDeviceManagerServiceImpl::dmDeviceManagerServiceImpl->HandleAppUnBindEvent(remoteUserId, remoteUdid, tokenId); +} + +void DeviceManagerServiceImpl::HandleAppUnBindEvent(int32_t remoteUserId, const std::string &remoteUdid, + int32_t tokenId, int32_t peerTokenId) +{ + DmDeviceManagerServiceImpl::dmDeviceManagerServiceImpl->HandleAppUnBindEvent(remoteUserId, remoteUdid, + tokenId, peerTokenId); +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/test/unittest/mock/device_manager_service_impl_mock.h b/test/unittest/mock/device_manager_service_impl_mock.h index 81f1a9e548f9d51df09c98adc6c019e1cadfc82a..21d34eb56b56ee6204dd5c0eaf5e057b75248406 100644 --- a/test/unittest/mock/device_manager_service_impl_mock.h +++ b/test/unittest/mock/device_manager_service_impl_mock.h @@ -43,6 +43,9 @@ public: virtual void HandleShareUnbindBroadCast(const std::string &credId, const int32_t &userId, const std::string &localUdid) = 0; virtual int32_t CheckDeviceInfoPermission(const std::string &localUdid, const std::string &peerDeviceId) = 0; + virtual void HandleAppUnBindEvent(int32_t remoteUserId, const std::string &remoteUdid, int32_t tokenId) = 0; + virtual void HandleAppUnBindEvent(int32_t remoteUserId, const std::string &remoteUdid, + int32_t tokenId, int32_t peerTokenId) = 0; public: static inline std::shared_ptr dmDeviceManagerServiceImpl = nullptr; }; @@ -63,6 +66,9 @@ public: std::string &, bool &)); MOCK_METHOD(void, HandleShareUnbindBroadCast, (const std::string &, const int32_t &, const std::string &)); MOCK_METHOD(int32_t, CheckDeviceInfoPermission, (const std::string &, const std::string &)); + MOCK_METHOD(void, HandleAppUnBindEvent, (int32_t remoteUserId, const std::string &remoteUdid, int32_t tokenId)); + MOCK_METHOD(void, HandleAppUnBindEvent, (int32_t remoteUserId, const std::string &remoteUdid, + int32_t tokenId, int32_t peerTokenId)); }; } } diff --git a/test/unittest/mock/deviceprofile_connector_mock.cpp b/test/unittest/mock/deviceprofile_connector_mock.cpp index 2619091edea05680098720fb52cfe2b0ef7bf2ad..4f82813a289ff08bcde1d6432d874c10a940a3a5 100644 --- a/test/unittest/mock/deviceprofile_connector_mock.cpp +++ b/test/unittest/mock/deviceprofile_connector_mock.cpp @@ -182,5 +182,23 @@ std::vector DeviceProfileConnect { return DmDeviceProfileConnector::dmDeviceProfileConnector->GetAllAclIncludeLnnAcl(); } + +std::vector DeviceProfileConnector::GetDeviceIdAndUdidListByTokenId( + const std::vector &userIds, const std::string &localUdid, int32_t tokenId) +{ + return DmDeviceProfileConnector::dmDeviceProfileConnector->GetDeviceIdAndUdidListByTokenId(userIds, localUdid, + tokenId); +} + +void DeviceProfileConnector::CacheAcerAclId(const DistributedDeviceProfile::AccessControlProfile &profile, + std::vector &aclInfos) +{ + DmDeviceProfileConnector::dmDeviceProfileConnector->CacheAcerAclId(profile, aclInfos); +} + +bool DeviceProfileConnector::IsLnnAcl(const DistributedDeviceProfile::AccessControlProfile &profile) +{ + return DmDeviceProfileConnector::dmDeviceProfileConnector->IsLnnAcl(profile); +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/test/unittest/mock/deviceprofile_connector_mock.h b/test/unittest/mock/deviceprofile_connector_mock.h index a643fc5001e10a9b9b74e9363da2cf8c4bd1d0df..84d5c9d04804bd05482ac71f3d149a58a32ab81a 100644 --- a/test/unittest/mock/deviceprofile_connector_mock.h +++ b/test/unittest/mock/deviceprofile_connector_mock.h @@ -70,6 +70,11 @@ public: const std::string &targetDeviceId, int32_t userId) = 0; virtual std::vector GetAccessControlProfile() = 0; virtual std::vector GetAllAclIncludeLnnAcl() = 0; + virtual std::vector GetDeviceIdAndUdidListByTokenId(const std::vector &userIds, + const std::string &localUdid, int32_t tokenId) = 0; + virtual void CacheAcerAclId(const DistributedDeviceProfile::AccessControlProfile &profile, + std::vector &aclInfos) = 0; + virtual bool IsLnnAcl(const DistributedDeviceProfile::AccessControlProfile &profile) = 0; public: static inline std::shared_ptr dmDeviceProfileConnector = nullptr; }; @@ -114,6 +119,11 @@ public: (const std::string &localDeviceId, const std::string &targetDeviceId, int32_t userId)); MOCK_METHOD(std::vector, GetAccessControlProfile, ()); MOCK_METHOD(std::vector, GetAllAclIncludeLnnAcl, ()); + MOCK_METHOD(std::vector, GetDeviceIdAndUdidListByTokenId, (const std::vector &userIds, + const std::string &localUdid, int32_t tokenId)); + MOCK_METHOD(void, CacheAcerAclId, (const DistributedDeviceProfile::AccessControlProfile &profile, + std::vector &aclInfos)); + MOCK_METHOD(bool, IsLnnAcl, (const DistributedDeviceProfile::AccessControlProfile &profile)); }; } } diff --git a/test/unittest/mock/dm_comm_tool_mock.cpp b/test/unittest/mock/dm_comm_tool_mock.cpp index 28afdc998e2ac95d06f460877fd9509f404fe18b..adc96723072ed9651807d3471367deba6a254a62 100644 --- a/test/unittest/mock/dm_comm_tool_mock.cpp +++ b/test/unittest/mock/dm_comm_tool_mock.cpp @@ -34,5 +34,10 @@ int32_t DMCommTool::CreateUserStopMessage(int32_t stopUserId, std::string &msgSt { return DmDMCommTool::dmDMCommTool->CreateUserStopMessage(stopUserId, msgStr); } + +int32_t DMCommTool::SendUninstAppObj(int32_t userId, int32_t tokenId, const std::string &networkId) +{ + return DmDMCommTool::dmDMCommTool->SendUninstAppObj(userId, tokenId, networkId); +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/test/unittest/mock/dm_comm_tool_mock.h b/test/unittest/mock/dm_comm_tool_mock.h index 735f8179c9dd4b1032e6c2543f8f3eac9116b0ea..b423a48968192fef7dd82751d62a2c195636088c 100644 --- a/test/unittest/mock/dm_comm_tool_mock.h +++ b/test/unittest/mock/dm_comm_tool_mock.h @@ -30,6 +30,7 @@ public: const std::vector &foregroundUserIds, const std::vector &backgroundUserIds) = 0; virtual int32_t SendUserStop(const std::string rmtNetworkId, int32_t stopUserId) = 0; virtual int32_t CreateUserStopMessage(int32_t stopUserId, std::string &msgStr) = 0; + virtual int32_t SendUninstAppObj(int32_t userId, int32_t tokenId, const std::string &networkId) = 0; public: static inline std::shared_ptr dmDMCommTool = nullptr; }; @@ -40,6 +41,7 @@ public: const std::vector &)); MOCK_METHOD(int32_t, SendUserStop, (const std::string, int32_t)); MOCK_METHOD(int32_t, CreateUserStopMessage, (int32_t stopUserId, std::string &msgStr)); + MOCK_METHOD(int32_t, SendUninstAppObj, (int32_t userId, int32_t tokenId, const std::string &networkId)); }; } } diff --git a/test/unittest/mock/hichain_connector_mock.cpp b/test/unittest/mock/hichain_connector_mock.cpp index c5642dec804e4b6028217acd084cf63539fcb183..2771745d7be4cb27e4d26c5469c1776eda3912b7 100644 --- a/test/unittest/mock/hichain_connector_mock.cpp +++ b/test/unittest/mock/hichain_connector_mock.cpp @@ -40,5 +40,11 @@ int32_t HiChainConnector::GetRelatedGroups(int32_t userId, const std::string &de { return DmHiChainConnector::dmHiChainConnector->GetRelatedGroups(userId, deviceId, groupList); } + +int32_t HiChainConnector::DeleteGroupByACL(std::vector> &delACLInfoVec, + std::vector &userIdVec) +{ + return DmHiChainConnector::dmHiChainConnector->DeleteGroupByACL(delACLInfoVec, userIdVec); +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/test/unittest/mock/hichain_connector_mock.h b/test/unittest/mock/hichain_connector_mock.h index 70f99a2a18f85d7a9ecdb64aff402125c2bed08a..a6b6028ea9b073c6590c365da8de363dd8f13a80 100644 --- a/test/unittest/mock/hichain_connector_mock.h +++ b/test/unittest/mock/hichain_connector_mock.h @@ -32,6 +32,8 @@ public: virtual int32_t GetRelatedGroups(const std::string &deviceId, std::vector &groupList) = 0; virtual int32_t GetRelatedGroups(int32_t userId, const std::string &deviceId, std::vector &groupList) = 0; + virtual int32_t DeleteGroupByACL(std::vector> &delACLInfoVec, + std::vector &userIdVec) = 0; public: static inline std::shared_ptr dmHiChainConnector = nullptr; }; @@ -42,6 +44,8 @@ public: MOCK_METHOD(bool, IsDevicesInP2PGroup, (const std::string &, const std::string &)); MOCK_METHOD(int32_t, GetRelatedGroups, (const std::string &, std::vector &)); MOCK_METHOD(int32_t, GetRelatedGroups, (int32_t, const std::string &, std::vector &)); + MOCK_METHOD(int32_t, DeleteGroupByACL, ((std::vector> &), + (std::vector &))); }; } }