From 11ee42c080a44fcf2d668f5c029dc9b2729dd10f Mon Sep 17 00:00:00 2001 From: zyr020212 Date: Tue, 9 Dec 2025 13:53:22 +0800 Subject: [PATCH] addtdd Signed-off-by: zyr020212 --- .../include/mock_app_mgr_service_inner.h | 4 + .../ams_mgr_scheduler_test.cpp | 5 +- .../app_mgr_service_second_test.cpp | 16 +++ .../app_mgr_service_test.cpp | 107 ++++++++++++++++++ 4 files changed, 130 insertions(+), 2 deletions(-) diff --git a/test/mock/mock_appmgr_service/include/mock_app_mgr_service_inner.h b/test/mock/mock_appmgr_service/include/mock_app_mgr_service_inner.h index 3cf9227f2d..2ff602965b 100644 --- a/test/mock/mock_appmgr_service/include/mock_app_mgr_service_inner.h +++ b/test/mock/mock_appmgr_service/include/mock_app_mgr_service_inner.h @@ -91,6 +91,10 @@ public: MOCK_METHOD3(CheckPreloadAppRecordExist, bool(const std::string&, int32_t, int32_t)); MOCK_CONST_METHOD0(IsFoundationCall, bool()); MOCK_METHOD2(QueryRunningSharedBundles, int32_t(pid_t pid, std::map &sharedBundles)); + MOCK_METHOD2(NotifyPageShow, int32_t(const sptr &token, const PageStateData &pageStateData)); + MOCK_METHOD1(RegisterRenderStateObserver, int32_t(const sptr &observer)); + MOCK_METHOD2(RegisterApplicationStateObserver, int32_t(const sptr &observer, + const std::vector &bundleNameList)); void StartSpecifiedAbility(const AAFwk::Want&, const AppExecFwk::AbilityInfo&, int32_t) {} diff --git a/test/unittest/ams_mgr_scheduler_test/ams_mgr_scheduler_test.cpp b/test/unittest/ams_mgr_scheduler_test/ams_mgr_scheduler_test.cpp index be4704a32f..eaf622d818 100644 --- a/test/unittest/ams_mgr_scheduler_test/ams_mgr_scheduler_test.cpp +++ b/test/unittest/ams_mgr_scheduler_test/ams_mgr_scheduler_test.cpp @@ -327,9 +327,10 @@ HWTEST_F(AmsMgrSchedulerTest, RegisterApplicationStateObserver_001, TestSize.Lev { TAG_LOGD(AAFwkTag::TEST, "RegisterApplicationStateObserver_001 start"); sptr observer = new ApplicationStateObserverStub(); + std::vector bundleNameList; auto mockAppMgrServiceInner = std::make_shared(); - mockAppMgrServiceInner->RegisterApplicationStateObserver(observer); - int32_t err = mockAppMgrServiceInner->RegisterApplicationStateObserver(observer); + mockAppMgrServiceInner->RegisterApplicationStateObserver(observer, bundleNameList); + int32_t err = mockAppMgrServiceInner->RegisterApplicationStateObserver(observer, bundleNameList); // repeat register return ERR_INVALID_VALUE EXPECT_EQ(1, err); TAG_LOGD(AAFwkTag::TEST, "RegisterApplicationStateObserver_001 end"); diff --git a/test/unittest/app_mgr_service_second_test/app_mgr_service_second_test.cpp b/test/unittest/app_mgr_service_second_test/app_mgr_service_second_test.cpp index 0b21ad65d1..774824b135 100644 --- a/test/unittest/app_mgr_service_second_test/app_mgr_service_second_test.cpp +++ b/test/unittest/app_mgr_service_second_test/app_mgr_service_second_test.cpp @@ -80,6 +80,22 @@ HWTEST_F(AppMgrServiceSecondTest, NotifyPageHide_0100, TestSize.Level1) EXPECT_NE(ret, ERR_OK); } +/** + * @tc.name: NotifyPageShow_0100 + * @tc.desc: NotifyPageShow. + * @tc.type: FUNC + */ +HWTEST_F(AppMgrServiceSecondTest, NotifyPageShow_0100, TestSize.Level1) +{ + auto appMgrService = std::make_shared(); + ASSERT_NE(appMgrService, nullptr); + sptr token = nullptr; + PageStateData pageStateData; + appMgrService->SetInnerService(nullptr); + int32_t res = appMgrService->NotifyPageShow(token, pageStateData); + EXPECT_EQ(res, ERR_INVALID_OPERATION); +} + /** * @tc.name: RegisterAppRunningStatusListener_0100 * @tc.desc: RegisterAppRunningStatusListener. diff --git a/test/unittest/app_mgr_service_test/app_mgr_service_test.cpp b/test/unittest/app_mgr_service_test/app_mgr_service_test.cpp index 24f5992994..500b1d9323 100644 --- a/test/unittest/app_mgr_service_test/app_mgr_service_test.cpp +++ b/test/unittest/app_mgr_service_test/app_mgr_service_test.cpp @@ -296,6 +296,23 @@ HWTEST_F(AppMgrServiceTest, ClearUpApplicationData_001, TestSize.Level1) EXPECT_EQ(res, ERR_INVALID_OPERATION); } +/* + * Feature: AppMgrService + * Function: ClearUpApplicationDataBySelf + * SubFunction: NA + * FunctionPoints: AppMgrService ClearUpApplicationDataBySelf + * EnvConditions: NA + * CaseDescription: Verify ClearUpApplicationDataBySelf + */ +HWTEST_F(AppMgrServiceTest, ClearUpApplicationDataBySelf_0100, TestSize.Level1) +{ + auto appMgrService = std::make_shared(); + ASSERT_NE(appMgrService, nullptr); + appMgrService->SetInnerService(nullptr); + int32_t res = appMgrService->ClearUpApplicationDataBySelf(0); + EXPECT_EQ(res, ERR_INVALID_OPERATION); +} + /* * Feature: AppMgrService * Function: GetAllRunningProcesses @@ -1388,6 +1405,46 @@ HWTEST_F(AppMgrServiceTest, ChangeAppGcState_002, TestSize.Level1) appMgrService->appMgrServiceInner_ = nullptr; } +/** + * @tc.name: NotifyPageShow_001 + * @tc.desc: Test NotifyPageShow when inpit is nullptr. + * @tc.type: FUNC + */ +HWTEST_F(AppMgrServiceTest, NotifyPageShow_001, TestSize.Level1) +{ + auto appMgrService = std::make_shared(); + ASSERT_NE(appMgrService, nullptr); + sptr token = nullptr; + PageStateData pageStateData; + appMgrService->SetInnerService(nullptr); + int32_t res = appMgrService->NotifyPageShow(token, pageStateData); + EXPECT_EQ(res, ERR_INVALID_OPERATION); +} + +/** + * @tc.name: NotifyPageShow_002 + * @tc.desc: verify NotifyPageShow works. + * @tc.type: FUNC + */ +HWTEST_F(AppMgrServiceTest, NotifyPageShow_002, TestSize.Level1) +{ + auto appMgrService = std::make_shared(); + ASSERT_NE(appMgrService, nullptr); + appMgrService->SetInnerService(mockAppMgrServiceInner_); + appMgrService->taskHandler_ = taskHandler_; + appMgrService->eventHandler_ = eventHandler_; + + sptr token = nullptr; + PageStateData pageStateData; + + EXPECT_CALL(*mockAppMgrServiceInner_, NotifyPageShow(_, _)) + .Times(1) + .WillOnce(Return(ERR_OK)); + + int32_t res = appMgrService->NotifyPageShow(token, pageStateData); + EXPECT_EQ(res, ERR_OK); +} + /** * @tc.name: IsAppRunning_001 * @tc.desc: Determine that the application is running by returning a value. @@ -1411,6 +1468,23 @@ HWTEST_F(AppMgrServiceTest, IsAppRunning_001, TestSize.Level1) EXPECT_EQ(res, AAFwk::ERR_APP_CLONE_INDEX_INVALID); } +/** + * @tc.name: IsAppRunning_002 + * @tc.desc: verify IsAppRunning calls works. + * @tc.type: FUNC + */ +HWTEST_F(AppMgrServiceTest, IsAppRunning_002, TestSize.Level1) +{ + auto appMgrService = std::make_shared(); + ASSERT_NE(appMgrService, nullptr); + std::string bundleName = "test_bundleName"; + int32_t appCloneIndex = 0; + bool isRunning = false; + appMgrService->SetInnerService(nullptr); + int32_t res = appMgrService->IsAppRunning(bundleName, appCloneIndex, isRunning); + EXPECT_EQ(res, ERR_INVALID_OPERATION); +} + #ifdef SUPPORT_CHILD_PROCESS /** * @tc.name: StartChildProcess_001 @@ -1581,6 +1655,20 @@ HWTEST_F(AppMgrServiceTest, UnregisterAppForegroundStateObserver_001, TestSize.L EXPECT_EQ(ERR_INVALID_OPERATION, res); } +/** + * @tc.name: IsFinalAppProcess_001 + * @tc.desc: Test IsFinalAppProcess when inpit is nullptr. + * @tc.type: FUNC + */ +HWTEST_F(AppMgrServiceTest, IsFinalAppProcess_001, TestSize.Level1) +{ + auto appMgrService = std::make_shared(); + ASSERT_NE(appMgrService, nullptr); + appMgrService->SetInnerService(nullptr); + bool res = appMgrService->IsFinalAppProcess(); + EXPECT_EQ(res, false); +} + /** * @tc.name: RegisterRenderStateObserver_0100 * @tc.desc: Test registerRenderStateObserver when inpit is nullptr. @@ -2385,6 +2473,25 @@ HWTEST_F(AppMgrServiceTest, QueryRunningSharedBundles_003, TestSize.Level1) TAG_LOGI(AAFwkTag::TEST, "QueryRunningSharedBundles_003 end."); } +/** + * @tc.name: RegisterApplicationStateObserverWithFilter + * @tc.desc: verify RegisterApplicationStateObserverWithFilter works. + * @tc.type: FUNC + */ +HWTEST_F(AppMgrServiceTest, RegisterApplicationStateObserverWithFilter_001, TestSize.Level1) +{ + auto appMgrService = std::make_shared(); + ASSERT_NE(appMgrService, nullptr); + sptr observer = nullptr; + std::vector bundleNameList; + AppStateFilter appStateFilter; + bool isUsingFilter = false; + appMgrService->SetInnerService(nullptr); + auto res = appMgrService->RegisterApplicationStateObserverWithFilter(observer, bundleNameList, + appStateFilter, isUsingFilter); + EXPECT_EQ(ERR_INVALID_OPERATION, res); +} + /* * Feature: AppMgrService * Function: GetConfiguration