!2568 Fix failure of 'ability_service_start_test'

Merge pull request !2568 from 张亚菲/zyfUT
This commit is contained in:
openharmony_ci 2022-08-02 06:47:17 +00:00 committed by Gitee
commit 3fbef914c7
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
4 changed files with 25 additions and 14 deletions

View File

@ -961,7 +961,6 @@ private:
void StopFreezingScreen();
void UserStarted(int32_t userId);
void SwitchToUser(int32_t userId);
void StartLauncherAbility(int32_t userId);
void SwitchToUser(int32_t oldUserId, int32_t userId);
void SwitchManagers(int32_t userId, bool switchUser = true);
void StartUserApps(int32_t userId, bool isBoot);

View File

@ -25,7 +25,8 @@ using namespace OHOS::AppExecFwk;
namespace OHOS {
namespace AAFwk {
namespace {
const std::string NAME_BUNDLE_MGR_SERVICE = "BundleMgrService";
const std::string TASK_NAME_START_SYSTEM_APP = "StartSystemApplication";
const std::string TASK_NAME_SUBSCRIBE_BACKGROUND_TASK = "SubscribeBackgroundTask";
}
class AbilityServiceStartTest : public testing::Test {
@ -72,6 +73,11 @@ HWTEST_F(AbilityServiceStartTest, StartUp_001, TestSize.Level1)
GTEST_LOG_(INFO) << "ability_manager_service_startup_001 start";
EXPECT_EQ(ServiceRunningState::STATE_NOT_START, aams_->QueryServiceState());
aams_->OnStart();
auto handler = aams_->GetEventHandler();
ASSERT_NE(handler, nullptr);
handler->RemoveTask(TASK_NAME_START_SYSTEM_APP);
handler->RemoveTask(TASK_NAME_SUBSCRIBE_BACKGROUND_TASK);
EXPECT_EQ(ServiceRunningState::STATE_RUNNING, aams_->QueryServiceState());
aams_->OnStop();
EXPECT_EQ(ServiceRunningState::STATE_NOT_START, aams_->QueryServiceState());
@ -90,7 +96,17 @@ HWTEST_F(AbilityServiceStartTest, StartUp_002, TestSize.Level1)
{
GTEST_LOG_(INFO) << "ability_manager_service_startup_002 start";
aams_->OnStart();
auto handler = aams_->GetEventHandler();
ASSERT_NE(handler, nullptr);
handler->RemoveTask(TASK_NAME_START_SYSTEM_APP);
handler->RemoveTask(TASK_NAME_SUBSCRIBE_BACKGROUND_TASK);
aams_->OnStart();
handler = aams_->GetEventHandler();
ASSERT_NE(handler, nullptr);
handler->RemoveTask(TASK_NAME_START_SYSTEM_APP);
handler->RemoveTask(TASK_NAME_SUBSCRIBE_BACKGROUND_TASK);
EXPECT_EQ(ServiceRunningState::STATE_RUNNING, aams_->QueryServiceState());
aams_->OnStop();
EXPECT_EQ(ServiceRunningState::STATE_NOT_START, aams_->QueryServiceState());
@ -125,6 +141,11 @@ HWTEST_F(AbilityServiceStartTest, StartUp_004, TestSize.Level1)
{
GTEST_LOG_(INFO) << "ability_manager_service_startup_004 start";
aams_->OnStart();
auto handler = aams_->GetEventHandler();
ASSERT_NE(handler, nullptr);
handler->RemoveTask(TASK_NAME_START_SYSTEM_APP);
handler->RemoveTask(TASK_NAME_SUBSCRIBE_BACKGROUND_TASK);
aams_->OnStop();
aams_->OnStop();
EXPECT_EQ(ServiceRunningState::STATE_NOT_START, aams_->QueryServiceState());
@ -145,9 +166,9 @@ HWTEST_F(AbilityServiceStartTest, StartUp_005, TestSize.Level1)
for (int i = 0; i < 10; i++) {
aams_->OnStart();
auto handler = aams_->GetEventHandler();
if (handler) {
handler->RemoveTask("startLauncherAbility");
}
ASSERT_NE(handler, nullptr);
handler->RemoveTask(TASK_NAME_START_SYSTEM_APP);
handler->RemoveTask(TASK_NAME_SUBSCRIBE_BACKGROUND_TASK);
GTEST_LOG_(INFO) << "start " << i << "times";
EXPECT_EQ(ServiceRunningState::STATE_RUNNING, aams_->QueryServiceState());
aams_->OnStop();

View File

@ -69,8 +69,6 @@ public:
void TearDown() override;
bool StartLauncherAbility() override;
bool StartNextAbility() override;
int AttachAbility(const OHOS::sptr<OHOS::AAFwk::AbilityScheduler> &scheduler,
@ -138,7 +136,6 @@ void LifecycleTest::SetUp(void)
{
OnStartabilityAms();
WaitUntilTaskFinished();
StartLauncherAbility();
command_ = std::make_unique<LifeTestCommand>();
}
@ -155,11 +152,6 @@ void LifecycleTest::TearDown(void)
startLancherFlag_ = false;
}
bool LifecycleTest::StartLauncherAbility()
{
return false;
}
bool LifecycleTest::StartNextAbility()
{
return true;

View File

@ -53,7 +53,6 @@ public:
class LifecycleTestBase {
public:
virtual bool StartLauncherAbility() = 0;
virtual bool StartNextAbility() = 0;
virtual int AttachAbility(
const OHOS::sptr<OHOS::AAFwk::AbilityScheduler> &scheduler, const OHOS::sptr<OHOS::IRemoteObject> &token) = 0;