元能力TDD覆盖率提升(ui_ability_lifecycle_manager)

Signed-off-by: zhubingwei <zhubingwei@huawei.com>
This commit is contained in:
zhubingwei
2024-05-20 19:41:34 +08:00
parent 31a68dccb1
commit 08f7ca7805
@@ -30,6 +30,7 @@
#include "process_options.h"
#include "session/host/include/session.h"
#include "session_info.h"
#include "ability_manager_service.h"
using namespace testing;
using namespace testing::ext;
@@ -2567,5 +2568,316 @@ HWTEST_F(UIAbilityLifecycleManagerTest, ChangeUIAbilityVisibilityBySCB_001, Test
int32_t ret = uiAbilityLifecycleManager->ChangeUIAbilityVisibilityBySCB(nullptr, true);
EXPECT_EQ(ERR_INVALID_VALUE, ret);
}
/**
* @tc.name: UIAbilityLifecycleManager_IsContainsAbility_0100
* @tc.desc: IsContainsAbility
* @tc.type: FUNC
*/
HWTEST_F(UIAbilityLifecycleManagerTest, IsContainsAbility_001, TestSize.Level1)
{
auto mgr = std::make_unique<UIAbilityLifecycleManager>();
EXPECT_NE(mgr, nullptr);
sptr<IRemoteObject> token = nullptr;
bool boolValue = mgr->IsContainsAbility(token);
EXPECT_FALSE(boolValue);
}
/**
* @tc.name: UIAbilityLifecycleManager_IsContainsAbility_0200
* @tc.desc: IsContainsAbility
* @tc.type: FUNC
*/
HWTEST_F(UIAbilityLifecycleManagerTest, IsContainsAbility_002, TestSize.Level1)
{
auto mgr = std::make_unique<UIAbilityLifecycleManager>();
EXPECT_NE(mgr, nullptr);
AbilityRequest abilityRequest;
auto abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest);
auto&& token = abilityRecord->GetToken()->AsObject();
mgr->sessionAbilityMap_.emplace(1, abilityRecord);
bool boolValue = mgr->IsContainsAbility(token);
EXPECT_TRUE(boolValue);
}
/**
* @tc.name: UIAbilityLifecycleManager_IsContainsAbilityInner_0100
* @tc.desc: IsContainsAbilityInner
* @tc.type: FUNC
*/
HWTEST_F(UIAbilityLifecycleManagerTest, IsContainsAbilityInner_001, TestSize.Level1)
{
auto mgr = std::make_unique<UIAbilityLifecycleManager>();
EXPECT_NE(mgr, nullptr);
sptr<IRemoteObject> token = nullptr;
bool boolValue = mgr->IsContainsAbilityInner(token);
EXPECT_FALSE(boolValue);
}
/**
* @tc.name: UIAbilityLifecycleManager_IsContainsAbilityInner_0200
* @tc.desc: IsContainsAbilityInner
* @tc.type: FUNC
*/
HWTEST_F(UIAbilityLifecycleManagerTest, IsContainsAbilityInner_002, TestSize.Level1)
{
auto mgr = std::make_unique<UIAbilityLifecycleManager>();
EXPECT_NE(mgr, nullptr);
AbilityRequest abilityRequest;
auto abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest);
auto&& token = abilityRecord->GetToken()->AsObject();
mgr->sessionAbilityMap_.emplace(1, abilityRecord);
bool boolValue = mgr->IsContainsAbilityInner(token);
EXPECT_TRUE(boolValue);
}
/**
* @tc.name: UIAbilityLifecycleManager_NotifySCBToMinimizeUIAbility_0100
* @tc.desc: NotifySCBToMinimizeUIAbility
* @tc.type: FUNC
*/
HWTEST_F(UIAbilityLifecycleManagerTest, NotifySCBToMinimizeUIAbility_001, TestSize.Level1)
{
auto mgr = std::make_unique<UIAbilityLifecycleManager>();
std::shared_ptr<AbilityRecord> abilityRecord = nullptr;
sptr<IRemoteObject> token = nullptr;
EXPECT_NE(mgr->NotifySCBToMinimizeUIAbility(abilityRecord, token), ERR_OK);
}
/**
* @tc.name: UIAbilityLifecycleManager_GetUIAbilityRecordBySessionInfo_0100
* @tc.desc: GetUIAbilityRecordBySessionInfo
* @tc.type: FUNC
*/
HWTEST_F(UIAbilityLifecycleManagerTest, GetUIAbilityRecordBySessionInfo_001, TestSize.Level1)
{
auto uiAbilityLifecycleManager = std::make_unique<UIAbilityLifecycleManager>();
EXPECT_NE(uiAbilityLifecycleManager, nullptr);
sptr<SessionInfo> sessionInfo = nullptr;
EXPECT_EQ(uiAbilityLifecycleManager->GetUIAbilityRecordBySessionInfo(sessionInfo), nullptr);
}
/**
* @tc.name: UIAbilityLifecycleManager_GetUIAbilityRecordBySessionInfo_0200
* @tc.desc: GetUIAbilityRecordBySessionInfo
* @tc.type: FUNC
*/
HWTEST_F(UIAbilityLifecycleManagerTest, GetUIAbilityRecordBySessionInfo_002, TestSize.Level1)
{
auto uiAbilityLifecycleManager = std::make_unique<UIAbilityLifecycleManager>();
EXPECT_NE(uiAbilityLifecycleManager, nullptr);
sptr<SessionInfo> sessionInfo(new SessionInfo());
sessionInfo->sessionToken = nullptr;
EXPECT_EQ(uiAbilityLifecycleManager->GetUIAbilityRecordBySessionInfo(sessionInfo), nullptr);
}
/**
* @tc.name: UIAbilityLifecycleManager_GetUIAbilityRecordBySessionInfo_0300
* @tc.desc: GetUIAbilityRecordBySessionInfo
* @tc.type: FUNC
*/
HWTEST_F(UIAbilityLifecycleManagerTest, GetUIAbilityRecordBySessionInfo_003, TestSize.Level1)
{
auto uiAbilityLifecycleManager = std::make_unique<UIAbilityLifecycleManager>();
EXPECT_NE(uiAbilityLifecycleManager, nullptr);
Rosen::SessionInfo info;
sptr<SessionInfo> sessionInfo(new SessionInfo());
sessionInfo->sessionToken = new Rosen::Session(info);
EXPECT_EQ(uiAbilityLifecycleManager->GetUIAbilityRecordBySessionInfo(sessionInfo), nullptr);
}
/**
* @tc.name: UIAbilityLifecycleManager_GetUIAbilityRecordBySessionInfo_0400
* @tc.desc: GetUIAbilityRecordBySessionInfo
* @tc.type: FUNC
*/
HWTEST_F(UIAbilityLifecycleManagerTest, GetUIAbilityRecordBySessionInfo_004, TestSize.Level1)
{
auto uiAbilityLifecycleManager = std::make_unique<UIAbilityLifecycleManager>();
EXPECT_NE(uiAbilityLifecycleManager, nullptr);
AbilityRequest abilityRequest;
Rosen::SessionInfo info;
sptr<SessionInfo> sessionInfo(new SessionInfo());
sessionInfo->sessionToken = new Rosen::Session(info);
sessionInfo->persistentId = 1;
abilityRequest.sessionInfo = sessionInfo;
auto abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest);
uiAbilityLifecycleManager->sessionAbilityMap_.emplace(sessionInfo->persistentId, abilityRecord);
EXPECT_NE(uiAbilityLifecycleManager->GetUIAbilityRecordBySessionInfo(sessionInfo), nullptr);
}
/**
* @tc.name: UIAbilityLifecycleManager_OnStartSpecifiedProcessResponse_0100
* @tc.desc: OnStartSpecifiedProcessResponse
* @tc.type: FUNC
*/
HWTEST_F(UIAbilityLifecycleManagerTest, OnStartSpecifiedProcessResponse_001, TestSize.Level1)
{
auto uiAbilityLifecycleManager = std::make_shared<UIAbilityLifecycleManager>();
EXPECT_NE(uiAbilityLifecycleManager, nullptr);
Want want;
std::string flag = "flag";
uiAbilityLifecycleManager->OnStartSpecifiedProcessResponse(want, flag);
uiAbilityLifecycleManager.reset();
}
/**
* @tc.name: UIAbilityLifecycleManager_OnStartSpecifiedProcessResponse_0200
* @tc.desc: OnStartSpecifiedProcessResponse
* @tc.type: FUNC
*/
HWTEST_F(UIAbilityLifecycleManagerTest, OnStartSpecifiedProcessResponse_002, TestSize.Level1)
{
auto uiAbilityLifecycleManager = std::make_shared<UIAbilityLifecycleManager>();
EXPECT_NE(uiAbilityLifecycleManager, nullptr);
Want want;
std::string flag = "flag";
int32_t requestId = 100;
uiAbilityLifecycleManager->OnStartSpecifiedProcessResponse(want, flag, requestId);
uiAbilityLifecycleManager.reset();
}
/**
* @tc.name: UIAbilityLifecycleManager_OnStartSpecifiedAbilityTimeoutResponse_0100
* @tc.desc: OnStartSpecifiedAbilityTimeoutResponse
* @tc.type: FUNC
*/
HWTEST_F(UIAbilityLifecycleManagerTest, OnStartSpecifiedAbilityTimeoutResponse_001, TestSize.Level1)
{
auto uiAbilityLifecycleManager = std::make_shared<UIAbilityLifecycleManager>();
EXPECT_NE(uiAbilityLifecycleManager, nullptr);
Want want;
uiAbilityLifecycleManager->OnStartSpecifiedAbilityTimeoutResponse(want);
uiAbilityLifecycleManager.reset();
}
/**
* @tc.name: UIAbilityLifecycleManager_OnStartSpecifiedAbilityTimeoutResponse_0200
* @tc.desc: OnStartSpecifiedAbilityTimeoutResponse
* @tc.type: FUNC
*/
HWTEST_F(UIAbilityLifecycleManagerTest, OnStartSpecifiedAbilityTimeoutResponse_002, TestSize.Level1)
{
auto uiAbilityLifecycleManager = std::make_shared<UIAbilityLifecycleManager>();
EXPECT_NE(uiAbilityLifecycleManager, nullptr);
Want want;
int32_t requestId = 100;
uiAbilityLifecycleManager->OnStartSpecifiedAbilityTimeoutResponse(want, requestId);
uiAbilityLifecycleManager.reset();
}
/**
* @tc.name: UIAbilityLifecycleManager_OnStartSpecifiedProcessTimeoutResponse_0100
* @tc.desc: OnStartSpecifiedProcessTimeoutResponse
* @tc.type: FUNC
*/
HWTEST_F(UIAbilityLifecycleManagerTest, OnStartSpecifiedProcessTimeoutResponse_001, TestSize.Level1)
{
auto uiAbilityLifecycleManager = std::make_shared<UIAbilityLifecycleManager>();
EXPECT_NE(uiAbilityLifecycleManager, nullptr);
Want want;
uiAbilityLifecycleManager->OnStartSpecifiedProcessTimeoutResponse(want);
uiAbilityLifecycleManager.reset();
}
/**
* @tc.name: UIAbilityLifecycleManager_OnStartSpecifiedProcessTimeoutResponse_0200
* @tc.desc: OnStartSpecifiedProcessTimeoutResponse
* @tc.type: FUNC
*/
HWTEST_F(UIAbilityLifecycleManagerTest, OnStartSpecifiedProcessTimeoutResponse_002, TestSize.Level1)
{
auto uiAbilityLifecycleManager = std::make_shared<UIAbilityLifecycleManager>();
EXPECT_NE(uiAbilityLifecycleManager, nullptr);
Want want;
int32_t requestId = 100;
uiAbilityLifecycleManager->OnStartSpecifiedProcessTimeoutResponse(want, requestId);
uiAbilityLifecycleManager.reset();
}
/**
* @tc.name: UIAbilityLifecycleManager_OnCallConnectDied_0100
* @tc.desc: OnCallConnectDied
* @tc.type: FUNC
*/
HWTEST_F(UIAbilityLifecycleManagerTest, OnCallConnectDied_001, TestSize.Level1)
{
auto uiAbilityLifecycleManager = std::make_shared<UIAbilityLifecycleManager>();
EXPECT_NE(uiAbilityLifecycleManager, nullptr);
std::shared_ptr<CallRecord> callRecord = nullptr;
uiAbilityLifecycleManager->OnCallConnectDied(callRecord);
uiAbilityLifecycleManager.reset();
}
/**
* @tc.name: UIAbilityLifecycleManager_GetSessionIdByAbilityToken_0100
* @tc.desc: GetSessionIdByAbilityToken
* @tc.type: FUNC
*/
HWTEST_F(UIAbilityLifecycleManagerTest, GetSessionIdByAbilityToken_001, TestSize.Level1)
{
auto uiAbilityLifecycleManager = std::make_unique<UIAbilityLifecycleManager>();
EXPECT_NE(uiAbilityLifecycleManager, nullptr);
sptr<IRemoteObject> token = nullptr;
EXPECT_EQ(uiAbilityLifecycleManager->GetSessionIdByAbilityToken(token), ERR_OK);
}
/**
* @tc.name: UIAbilityLifecycleManager_GetSessionIdByAbilityToken_0200
* @tc.desc: GetSessionIdByAbilityToken
* @tc.type: FUNC
*/
HWTEST_F(UIAbilityLifecycleManagerTest, GetSessionIdByAbilityToken_002, TestSize.Level1)
{
auto mgr = std::make_unique<UIAbilityLifecycleManager>();
AbilityRequest abilityRequest;
auto abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest);
mgr->sessionAbilityMap_.emplace(1, abilityRecord);
auto&& token = abilityRecord->GetToken()->AsObject();
EXPECT_EQ(mgr->GetSessionIdByAbilityToken(token), 1);
}
/**
* @tc.name: UIAbilityLifecycleManager_GetActiveAbilityList_0100
* @tc.desc: GetActiveAbilityList
* @tc.type: FUNC
*/
HWTEST_F(UIAbilityLifecycleManagerTest, GetActiveAbilityList_001, TestSize.Level1)
{
auto uiAbilityLifecycleManager = std::make_unique<UIAbilityLifecycleManager>();
EXPECT_NE(uiAbilityLifecycleManager, nullptr);
AbilityRequest abilityRequest;
auto abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest);
uiAbilityLifecycleManager->sessionAbilityMap_.emplace(1, abilityRecord);
std::string bundleName = "com.example.unittest";
std::vector<std::string> abilityList;
int32_t pid = 100;
uiAbilityLifecycleManager->GetActiveAbilityList(bundleName, abilityList, pid);
uiAbilityLifecycleManager.reset();
}
/**
* @tc.name: UIAbilityLifecycleManager_GetActiveAbilityList_0200
* @tc.desc: GetActiveAbilityList
* @tc.type: FUNC
*/
HWTEST_F(UIAbilityLifecycleManagerTest, GetActiveAbilityList_002, TestSize.Level1)
{
auto uiAbilityLifecycleManager = std::make_unique<UIAbilityLifecycleManager>();
EXPECT_NE(uiAbilityLifecycleManager, nullptr);
AbilityRequest abilityRequest;
abilityRequest.abilityInfo.launchMode = AppExecFwk::LaunchMode::STANDARD;
abilityRequest.abilityInfo.name = "testAbility";
abilityRequest.abilityInfo.moduleName = "testModule";
abilityRequest.abilityInfo.bundleName = "com.example.unittest";
auto abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest);
abilityRecord->SetOwnerMissionUserId(DelayedSingleton<AbilityManagerService>::GetInstance()->GetUserId());
uiAbilityLifecycleManager->sessionAbilityMap_.emplace(1, abilityRecord);
std::string bundleName = "com.example.unittest";
std::vector<std::string> abilityList;
int32_t pid = 100;
uiAbilityLifecycleManager->GetActiveAbilityList(bundleName, abilityList, pid);
uiAbilityLifecycleManager.reset();
}
} // namespace AAFwk
} // namespace OHOS