From 325494fe956ed98f87b2e30ff5af1f23850015af Mon Sep 17 00:00:00 2001 From: zhangzezhong Date: Wed, 11 Jun 2025 10:28:28 +0800 Subject: [PATCH] add ApplicationCleaner unittest cases for ability_runtime Signed-off-by: zhangzezhong --- test/unittest/BUILD.gn | 2 + .../application_cleaner_second_test/BUILD.gn | 85 ++++++ .../application_cleaner_second_test.cpp | 213 +++++++++++++ .../dump_utils_test/dump_utils_test.cpp | 52 +++- .../mission_list_manager_third_test/BUILD.gn | 89 ++++++ .../mission_list_manager_third_test.cpp | 280 ++++++++++++++++++ .../start_ability_utils_test.cpp | 31 ++ .../state_utils_test/state_utils_test.cpp | 21 ++ .../update_caller_info_util_test.cpp | 57 ++++ 9 files changed, 828 insertions(+), 2 deletions(-) create mode 100644 test/unittest/application_cleaner_second_test/BUILD.gn create mode 100644 test/unittest/application_cleaner_second_test/application_cleaner_second_test.cpp create mode 100644 test/unittest/mission_list_manager_third_test/BUILD.gn create mode 100644 test/unittest/mission_list_manager_third_test/mission_list_manager_third_test.cpp diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index 32e588e4846..cdbb168f7e0 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -271,6 +271,7 @@ group("unittest") { "app_state_observer_manager_test_second:unittest", "app_utils_test:unittest", "appkit:unittest", + "application_cleaner_second_test:unittest", "application_context_second_test:unittest", "application_context_test:unittest", "assert_fault_callback_death_mgr_test:unittest", @@ -528,6 +529,7 @@ group("unittest") { "mission_list_manager_first_test:unittest", "mission_list_manager_second_test:unittest", "mission_list_manager_test:unittest", + "mission_list_manager_third_test:unittest", "mission_list_manager_ut_test:unittest", "mission_list_test:unittest", "mission_test:unittest", diff --git a/test/unittest/application_cleaner_second_test/BUILD.gn b/test/unittest/application_cleaner_second_test/BUILD.gn new file mode 100644 index 00000000000..7f7130bcfd3 --- /dev/null +++ b/test/unittest/application_cleaner_second_test/BUILD.gn @@ -0,0 +1,85 @@ +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/test.gni") +import("//foundation/ability/ability_runtime/ability_runtime.gni") + +module_output_path = "ability_runtime/ability_runtime/abilitymgr" + +ohos_unittest("application_cleaner_second_test") { + module_out_path = module_output_path + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + blocklist = "../../../test/cfi_blocklist.txt" + } + branch_protector_ret = "pac_ret" + include_dirs = [ + "${ability_runtime_services_path}/common/include", + "${ability_runtime_test_path}/mock/common/include", + ] + + sources = [ + "${ability_runtime_native_path}/appkit/app/app_context.cpp", + "${ability_runtime_native_path}/appkit/app/app_loader.cpp", + "${ability_runtime_native_path}/appkit/app/application_cleaner.cpp", + "application_cleaner_second_test.cpp", + ] + + deps = [ + "${ability_runtime_innerkits_path}/ability_manager:ability_manager", + "${ability_runtime_innerkits_path}/app_manager:app_manager", + "${ability_runtime_innerkits_path}/deps_wrapper:ability_deps_wrapper", + "${ability_runtime_native_path}/ability/native:ability_thread", + "${ability_runtime_native_path}/ability/native:abilitykit_native", + "${ability_runtime_native_path}/ability/native:configuration_helper", + "${ability_runtime_native_path}/ability/native:uiabilitykit_native", + "${ability_runtime_native_path}/appkit:app_context", + "${ability_runtime_native_path}/appkit:appkit_manager_helper", + "${ability_runtime_native_path}/appkit:appkit_native", + ] + + external_deps = [ + "ability_base:base", + "ability_base:configuration", + "ability_base:extractortool", + "ability_base:want", + "ability_runtime:runtime", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "common_event_service:cesfwk_innerkits", + "eventhandler:libeventhandler", + "ffrt:libffrt", + "googletest:gtest_main", + "hilog:libhilog", + "hitrace:hitrace_meter", + "init:libbegetutil", + "ipc:ipc_core", + "napi:ace_napi", + "resource_management:global_resmgr", + "resource_management:librawfile", + "samgr:samgr_proxy", + ] + + cflags_cc = [] + if (os_dlp_part_enabled) { + cflags_cc += [ "-DWITH_DLP" ] + } +} + +group("unittest") { + testonly = true + deps = [ ":application_cleaner_second_test" ] +} \ No newline at end of file diff --git a/test/unittest/application_cleaner_second_test/application_cleaner_second_test.cpp b/test/unittest/application_cleaner_second_test/application_cleaner_second_test.cpp new file mode 100644 index 00000000000..c55132f54bb --- /dev/null +++ b/test/unittest/application_cleaner_second_test/application_cleaner_second_test.cpp @@ -0,0 +1,213 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#define private public +#define protected public +#include "application_cleaner.h" +#include "context_impl.h" +#undef private +#undef protected + +using namespace testing::ext; +using namespace OHOS; +using namespace OHOS::AppExecFwk; +using namespace OHOS::AbilityRuntime; + +namespace OHOS { +namespace AppExecFwk { +class ApplicationCleanerSecondTest : public testing::Test { +public: + ApplicationCleanerSecondTest() + {} + ~ApplicationCleanerSecondTest() + {} + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); +}; + +void ApplicationCleanerSecondTest::SetUpTestCase(void) +{} + +void ApplicationCleanerSecondTest::TearDownTestCase(void) +{} + +void ApplicationCleanerSecondTest::SetUp(void) +{} + +void ApplicationCleanerSecondTest::TearDown(void) +{} + +/** + * @tc.number: CheckFileSize_0100 + * @tc.name: CheckFileSize + * @tc.desc: Test whether CheckFileSize and are called normally. + */ +HWTEST_F(ApplicationCleanerSecondTest, CheckFileSize_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "CheckFileSize_0100 start"; + auto cleaner = ApplicationCleaner::GetInstance(); + std::vector bundlePath{}; + std::string pathStr = "https://cn.bing.com/searchsearchsearchsearchsearch"; + bundlePath.clear(); + bundlePath.push_back(pathStr); + bool ret = cleaner->CheckFileSize(bundlePath); + EXPECT_TRUE(ret); + GTEST_LOG_(INFO) << "CheckFileSize_0100 end"; +} + +/** + * @tc.number: CheckFileSize_0200 + * @tc.name: CheckFileSize + * @tc.desc: Test whether CheckFileSize and are called normally. + */ +HWTEST_F(ApplicationCleanerSecondTest, CheckFileSize_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "CheckFileSize_0200 start"; + auto cleaner = ApplicationCleaner::GetInstance(); + std::vector bundlePath{}; + std::string pathStr = "https://cn.bing.com/searchsearchsearchsearchsearch"; + bundlePath.clear(); + for (int i = 0; i < 20000; i++) { + bundlePath.push_back(pathStr); + } + bool ret = cleaner->CheckFileSize(bundlePath); + EXPECT_TRUE(ret); + GTEST_LOG_(INFO) << "CheckFileSize_0200 end"; +} + +/** + * @tc.number: ClearTempData_0100 + * @tc.name: ClearTempData + * @tc.desc: Test whether ClearTempData and are called normally. + */ +HWTEST_F(ApplicationCleanerSecondTest, ClearTempData_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "ClearTempData_0100 start"; + auto cleaner = ApplicationCleaner::GetInstance(); + EXPECT_NE(cleaner, nullptr); + cleaner->ClearTempData(); + GTEST_LOG_(INFO) << "ClearTempData_0100 end"; +} + +/** + * @tc.number: RenameTempData_0100 + * @tc.name: RenameTempData + * @tc.desc: Test whether RenameTempData and are called normally. + */ +HWTEST_F(ApplicationCleanerSecondTest, RenameTempData_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "RenameTempData_0100 start"; + auto cleaner = ApplicationCleaner::GetInstance(); + std::vector tempDir1{}; + cleaner->context_ = AbilityRuntime::ApplicationContext::GetInstance(); + cleaner->context_->GetAllTempDir(tempDir1); + cleaner->RenameTempData(); + std::vector tempDir2{}; + cleaner->context_->GetAllTempDir(tempDir2); + bool res = std::equal(tempDir1.begin(), tempDir1.end(), tempDir2.begin()); + EXPECT_EQ(res, true); + GTEST_LOG_(INFO) << "RenameTempData_0100 end"; +} + +/** + * @tc.number: GetObsoleteBundleTempPath_0100 + * @tc.name: GetObsoleteBundleTempPath + * @tc.desc: Test whether GetObsoleteBundleTempPath and are called normally. + */ +HWTEST_F(ApplicationCleanerSecondTest, GetObsoleteBundleTempPath_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "GetObsoleteBundleTempPath_0100 start"; + auto cleaner = ApplicationCleaner::GetInstance(); + std::string path = "https://cn.bing.com/searchsearchsearchsearchsearch"; + std::vector rootPath{}; + rootPath.push_back(path); + std::vector tempPath{}; + int res = cleaner->GetObsoleteBundleTempPath(rootPath, tempPath); + EXPECT_EQ(res, 0); + GTEST_LOG_(INFO) << "GetObsoleteBundleTempPath_0100 end"; +} + +/** + * @tc.number: GetObsoleteBundleTempPath_0200 + * @tc.name: GetObsoleteBundleTempPath + * @tc.desc: Test whether GetObsoleteBundleTempPath and are called normally. + */ +HWTEST_F(ApplicationCleanerSecondTest, GetObsoleteBundleTempPath_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "GetObsoleteBundleTempPath_0200 start"; + auto cleaner = ApplicationCleaner::GetInstance(); + std::vector tempPath{}; + std::vector rootPath{}; + int res = cleaner->GetObsoleteBundleTempPath(rootPath, tempPath); + EXPECT_EQ(res, -1); + GTEST_LOG_(INFO) << "GetObsoleteBundleTempPath_0200 end"; +} + +/** + * @tc.number: RemoveDir_0100 + * @tc.name: RemoveDir + * @tc.desc: Test whether RemoveDir and are called normally. + */ +HWTEST_F(ApplicationCleanerSecondTest, RemoveDir_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "RemoveDir_0100 start"; + auto cleaner = ApplicationCleaner::GetInstance(); + std::string currentPath = "https://cn.bing.com/searchsearchsearchsearchsearch"; + bool res = cleaner->RemoveDir(currentPath); + EXPECT_EQ(res, false); + GTEST_LOG_(INFO) << "RemoveDir_0100 end"; +} + +/** + * @tc.number: RemoveDir_0200 + * @tc.name: RemoveDir + * @tc.desc: Test whether RemoveDir and are called normally. + */ +HWTEST_F(ApplicationCleanerSecondTest, RemoveDir_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "RemoveDir_0200 start"; + auto cleaner = ApplicationCleaner::GetInstance(); + std::string currentPath = ""; + bool res = cleaner->RemoveDir(currentPath); + EXPECT_FALSE(res); + GTEST_LOG_(INFO) << "RemoveDir_0200 end"; +} + +/** + * @tc.number: GetRootPath_0100 + * @tc.name: GetRootPath + * @tc.desc: Test whether GetRootPath and are called normally. + */ +HWTEST_F(ApplicationCleanerSecondTest, GetRootPath_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "GetRootPath_0100 start"; + auto cleaner = ApplicationCleaner::GetInstance(); + std::shared_ptr abilityRuntimeContext = nullptr; + std::vector bundlePath{}; + std::string pathStr = "https://cn.bing.com/searchsearchsearchsearchsearch"; + bundlePath.clear(); + bundlePath.push_back(pathStr); + cleaner->SetRuntimeContext(abilityRuntimeContext); + int ret = cleaner->GetRootPath(bundlePath); + EXPECT_EQ(ret, -1); + GTEST_LOG_(INFO) << "GetRootPath_0100 end"; +} +} +} \ No newline at end of file diff --git a/test/unittest/dump_utils_test/dump_utils_test.cpp b/test/unittest/dump_utils_test/dump_utils_test.cpp index 853e382c996..68ad50d6d35 100644 --- a/test/unittest/dump_utils_test/dump_utils_test.cpp +++ b/test/unittest/dump_utils_test/dump_utils_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -263,5 +263,53 @@ HWTEST_F(DumpUtilsTest, DumpsysMap_001, TestSize.Level1) EXPECT_EQ(result.second, DumpUtils::KEY_DUMP_SYS_DATA); TAG_LOGI(AAFwkTag::TEST, "DumpUtilsTest DumpsysMap_001 end"); } + +/* + * Feature: DumpUtils + * Function: DumpMap + * SubFunction: NA + * FunctionPoints: AbilityManagerService DumpMap + */ +HWTEST_F(DumpUtilsTest, DumpMap_001, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "DumpUtilsTest DumpMap_001 start"); + DumpUtils info; + std::string argString ="-a"; + auto result = info.DumpMap(argString); + EXPECT_TRUE(result.first); + TAG_LOGI(AAFwkTag::TEST, "DumpUtilsTest DumpMap_001 end"); +} + +/* + * Feature: DumpUtils + * Function: DumpMap + * SubFunction: NA + * FunctionPoints: AbilityManagerService DumpMap + */ +HWTEST_F(DumpUtilsTest, DumpMap_002, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "DumpUtilsTest DumpMap_002 start"); + DumpUtils info; + std::string argString ="-z"; + auto result = info.DumpMap(argString); + EXPECT_TRUE(result.first); + TAG_LOGI(AAFwkTag::TEST, "DumpUtilsTest DumpMap_002 end"); +} + +/* + * Feature: DumpUtils + * Function: DumpMap + * SubFunction: NA + * FunctionPoints: AbilityManagerService DumpMap + */ +HWTEST_F(DumpUtilsTest, DumpMap_003, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "DumpUtilsTest DumpMap_003 start"); + DumpUtils info; + std::string argString ="-b"; + auto result = info.DumpMap(argString); + EXPECT_FALSE(result.first); + TAG_LOGI(AAFwkTag::TEST, "DumpUtilsTest DumpMap_003 end"); +} } // namespace AAFwk -} // namespace OHOS +} // namespace OHOS \ No newline at end of file diff --git a/test/unittest/mission_list_manager_third_test/BUILD.gn b/test/unittest/mission_list_manager_third_test/BUILD.gn new file mode 100644 index 00000000000..ccc976b25bc --- /dev/null +++ b/test/unittest/mission_list_manager_third_test/BUILD.gn @@ -0,0 +1,89 @@ +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/test.gni") +import("//foundation/ability/ability_runtime/ability_runtime.gni") + +module_output_path = "ability_runtime/ability_runtime/abilitymgr" + +ohos_unittest("mission_list_manager_third_test") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + blocklist = "../../cfi_blocklist.txt" + } + branch_protector_ret = "pac_ret" + module_out_path = module_output_path + + include_dirs = [ + "${ability_runtime_innerkits_path}/ability_manager/include", + "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/system_ability_mock", + ] + + sources = [ + "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core/src/appmgr/mock_app_scheduler.cpp", + "mission_list_manager_third_test.cpp", # add mock file + ] + + configs = [ + "${ability_runtime_services_path}/abilitymgr:abilityms_config", + "${ability_runtime_test_path}/mock/services_abilitymgr_test:aafwk_mock_config", + ] + cflags = [] + if (target_cpu == "arm") { + cflags += [ "-DBINDER_IPC_32BIT" ] + } + deps = [ + "${ability_runtime_innerkits_path}/ability_manager:ability_manager", + "${ability_runtime_innerkits_path}/ability_manager:mission_info", + "${ability_runtime_native_path}/ability/native:abilitykit_native", + "${ability_runtime_path}/utils/server/startup:startup_util", + "${ability_runtime_services_path}/abilitymgr:abilityms", + "${ability_runtime_services_path}/abilitymgr:mission_list", + "${ability_runtime_services_path}/common:perm_verification", + "${ability_runtime_services_path}/common:task_handler_wrap", + "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/aakit:aakit_mock", + "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_appmgr_mock", + "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_bundlemgr_mock", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "common_event_service:cesfwk_innerkits", + "eventhandler:libeventhandler", + "ffrt:libffrt", + "googletest:gtest_main", + "hilog:libhilog", + "hisysevent:libhisysevent", + "ipc:ipc_core", + "napi:ace_napi", + "samgr:samgr_proxy", + ] + + if (background_task_mgr_continuous_task_enable) { + external_deps += [ "background_task_mgr:bgtaskmgr_innerkits" ] + } + cflags_cc = [] + if (os_dlp_part_enabled) { + cflags_cc += [ "-DWITH_DLP" ] + } +} + +group("unittest") { + testonly = true + + deps = [ ":mission_list_manager_third_test" ] +} diff --git a/test/unittest/mission_list_manager_third_test/mission_list_manager_third_test.cpp b/test/unittest/mission_list_manager_third_test/mission_list_manager_third_test.cpp new file mode 100644 index 00000000000..d9675bcd553 --- /dev/null +++ b/test/unittest/mission_list_manager_third_test/mission_list_manager_third_test.cpp @@ -0,0 +1,280 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#define private public +#define protected public +#include "ability_record.h" +#include "hilog_tag_wrapper.h" +#include "mission.h" +#include "mission_list_manager.h" +#include "ability_manager_service.h" +#include "task_handler_wrap.h" +#undef private +#undef protected + +using namespace testing::ext; +using namespace testing; +using namespace OHOS::AppExecFwk; + +namespace OHOS { +namespace AAFwk { +class MissionListManagerThirdTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); + std::shared_ptr InitAbilityRecord(); + int32_t ERR_INVALID_VALUE = 22; +}; + +void MissionListManagerThirdTest::SetUpTestCase(void) +{} +void MissionListManagerThirdTest::TearDownTestCase(void) +{} +void MissionListManagerThirdTest::SetUp(void) +{} +void MissionListManagerThirdTest::TearDown(void) +{} + +std::shared_ptr MissionListManagerThirdTest::InitAbilityRecord() +{ + AbilityRequest abilityRequest; + abilityRequest.appInfo.bundleName = "com.example.unittest"; + abilityRequest.abilityInfo.name = "MainAbility"; + abilityRequest.abilityInfo.type = AbilityType::PAGE; + std::shared_ptr abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest); + return abilityRecord; +} + +/* + * Feature: MissionListManager + * Function: FindEarliestMission + * SubFunction: NA + * FunctionPoints: MissionListManager FindEarliestMission + * EnvConditions: NA + * CaseDescription: Verify FindEarliestMission + */ +HWTEST_F(MissionListManagerThirdTest, FindEarliestMission_001, TestSize.Level1) +{ + int userId = 0; + auto missionListManager = std::make_shared(userId); + auto ret = missionListManager->FindEarliestMission(); + EXPECT_EQ(ret, nullptr); +} + +/* + * Feature: MissionListManager + * Function: FindEarliestMission + * SubFunction: NA + * FunctionPoints: MissionListManager FindEarliestMission + * EnvConditions: NA + * CaseDescription: Verify FindEarliestMission + */ +HWTEST_F(MissionListManagerThirdTest, FindEarliestMission_002, TestSize.Level1) +{ + int userId = 0; + auto missionListManager = std::make_shared(userId); + missionListManager->Init(); + auto ret = missionListManager->FindEarliestMission(); + EXPECT_EQ(ret, nullptr); +} + +/* + * Feature: MissionListManager + * Function: MinimizeAbility + * SubFunction: NA + * FunctionPoints: MissionListManager MinimizeAbility + * EnvConditions: NA + * CaseDescription: Verify MinimizeAbility + */ +HWTEST_F(MissionListManagerThirdTest, MinimizeAbility_001, TestSize.Level1) +{ + int userId = 0; + auto missionListManager = std::make_shared(userId); + sptr token = nullptr; + auto ret = missionListManager->MinimizeAbility(token, true); + EXPECT_EQ(ret, INNER_ERR); +} + +/* + * Feature: MissionListManager + * Function: GetMissionInfo + * SubFunction: NA + * FunctionPoints: MissionListManager GetMissionInfo + * EnvConditions: NA + * CaseDescription: Verify GetMissionInfo + */ +HWTEST_F(MissionListManagerThirdTest, GetMissionInfo_001, TestSize.Level1) +{ + int userId = 0; + auto missionListManager = std::make_shared(userId); + MissionInfo missionInfo; + auto ret = missionListManager->GetMissionInfo(0, missionInfo); + EXPECT_EQ(ret, -1); +} + +/* + * Feature: MissionListManager + * Function: GetReusedStandardMission + * SubFunction: NA + * FunctionPoints: MissionListManager GetReusedStandardMission + * EnvConditions: NA + * CaseDescription: Verify GetReusedStandardMission + */ +HWTEST_F(MissionListManagerThirdTest, GetReusedStandardMission_001, TestSize.Level1) +{ + int userId = 0; + auto missionListManager = std::make_shared(userId); + AbilityRequest abilityRequest; + abilityRequest.abilityInfo.launchMode = AppExecFwk::LaunchMode::SINGLETON; + auto ret = missionListManager->GetReusedStandardMission(abilityRequest); + EXPECT_EQ(ret, nullptr); +} + +/* + * Feature: MissionListManager + * Function: GetReusedStandardMission + * SubFunction: NA + * FunctionPoints: MissionListManager GetReusedStandardMission + * EnvConditions: NA + * CaseDescription: Verify GetReusedStandardMission + */ +HWTEST_F(MissionListManagerThirdTest, GetReusedStandardMission_002, TestSize.Level1) +{ + int userId = 0; + auto missionListManager = std::make_shared(userId); + AbilityRequest abilityRequest; + abilityRequest.abilityInfo.launchMode = AppExecFwk::LaunchMode::STANDARD; + abilityRequest.startRecent = false; + abilityRequest.abilityInfo.applicationInfo.isLauncherApp = true; + auto ret = missionListManager->GetReusedStandardMission(abilityRequest); + EXPECT_EQ(ret, nullptr); +} + +/* + * Feature: MissionListManager + * Function: GetReusedStandardMission + * SubFunction: NA + * FunctionPoints: MissionListManager GetReusedStandardMission + * EnvConditions: NA + * CaseDescription: Verify GetReusedStandardMission + */ +HWTEST_F(MissionListManagerThirdTest, GetReusedStandardMission_003, TestSize.Level1) +{ + int userId = 0; + auto missionListManager = std::make_shared(userId); + AbilityRequest abilityRequest; + abilityRequest.abilityInfo.launchMode = AppExecFwk::LaunchMode::STANDARD; + abilityRequest.startRecent = false; + abilityRequest.abilityInfo.applicationInfo.isLauncherApp = true; + missionListManager->Init(); + auto ret = missionListManager->GetReusedStandardMission(abilityRequest); + EXPECT_EQ(ret, nullptr); +} + +/* + * Feature: MissionListManager + * Function: MinimizeAbilityLocked + * SubFunction: NA + * FunctionPoints: MissionListManager MinimizeAbilityLocked + * EnvConditions: NA + * CaseDescription: Verify MinimizeAbilityLocked + */ +HWTEST_F(MissionListManagerThirdTest, MinimizeAbilityLocked_001, TestSize.Level1) +{ + int userId = 0; + auto missionListManager = std::make_shared(userId); + std::shared_ptr abilityRecord = InitAbilityRecord(); + int ret = missionListManager->MinimizeAbilityLocked(abilityRecord, true); + EXPECT_EQ(ret, ERR_OK); +} + +/* + * Feature: MissionListManager + * Function: BackToCallerAbilityWithResult + * SubFunction: NA + * FunctionPoints: MissionListManager BackToCallerAbilityWithResult + * EnvConditions: NA + * CaseDescription: Verify BackToCallerAbilityWithResult + */ +HWTEST_F(MissionListManagerThirdTest, BackToCallerAbilityWithResult_001, TestSize.Level1) +{ + int userId = 0; + auto missionListManager = std::make_shared(userId); + std::shared_ptr abilityRecord = nullptr; + Want resultWant; + int32_t ret = missionListManager->BackToCallerAbilityWithResult(abilityRecord, 0, &resultWant, 0); + EXPECT_EQ(ret, ERR_INVALID_VALUE); +} + +/* + * Feature: MissionListManager + * Function: GetAbilityNumber + * SubFunction: NA + * FunctionPoints: MissionListManager GetAbilityNumber + * EnvConditions: NA + * CaseDescription: Verify GetAbilityNumber + */ +HWTEST_F(MissionListManagerThirdTest, GetAbilityNumber_001, TestSize.Level1) +{ + int userId = 0; + auto missionListManager = std::make_shared(userId); + AbilityRequest abilityRequest; + abilityRequest.abilityInfo.deviceId = "id"; + abilityRequest.abilityInfo.bundleName = "bundle"; + abilityRequest.abilityInfo.name = "name"; + AppExecFwk::ElementName element(abilityRequest.abilityInfo.deviceId, abilityRequest.abilityInfo.bundleName, + abilityRequest.abilityInfo.name, abilityRequest.abilityInfo.moduleName); + int32_t ret = missionListManager->GetAbilityNumber(element); + EXPECT_EQ(ret, 0); +} + +/* + * Feature: MissionListManager + * Function: DoAbilityForeground + * SubFunction: NA + * FunctionPoints: MissionListManager DoAbilityForeground + * EnvConditions: NA + * CaseDescription: Verify DoAbilityForeground + */ +HWTEST_F(MissionListManagerThirdTest, DoAbilityForeground_001, TestSize.Level1) +{ + int userId = 0; + auto missionListManager = std::make_shared(userId); + std::shared_ptr abilityRecord = InitAbilityRecord(); + int ret = missionListManager->DoAbilityForeground(abilityRecord, 0); + EXPECT_EQ(ret, ERR_OK); +} + +/* + * Feature: MissionListManager + * Function: DoAbilityForeground + * SubFunction: NA + * FunctionPoints: MissionListManager DoAbilityForeground + * EnvConditions: NA + * CaseDescription: Verify DoAbilityForeground + */ +HWTEST_F(MissionListManagerThirdTest, DoAbilityForeground_002, TestSize.Level1) +{ + int userId = 0; + auto missionListManager = std::make_shared(userId); + std::shared_ptr abilityRecord = nullptr; + int ret = missionListManager->DoAbilityForeground(abilityRecord, 0); + EXPECT_EQ(ret, ERR_INVALID_VALUE); +} +} // namespace AAFwk +} // namespace OHOS diff --git a/test/unittest/start_ability_utils_test/start_ability_utils_test.cpp b/test/unittest/start_ability_utils_test/start_ability_utils_test.cpp index 25f59cbca34..19202516491 100644 --- a/test/unittest/start_ability_utils_test/start_ability_utils_test.cpp +++ b/test/unittest/start_ability_utils_test/start_ability_utils_test.cpp @@ -135,5 +135,36 @@ HWTEST_F(StartAbilityUtilsTest, CheckAppProvisionMode_003, TestSize.Level1) int32_t ret = StartAbilityUtils::CheckAppProvisionMode(bundleName, userId); EXPECT_EQ(ret, ERR_INVALID_VALUE); } + +/** + * @tc.name: CheckAppProvisionMode_004 + * @tc.desc: test class StartAbilityUtil CheckAppProvisionMode function + * @tc.type: FUNC + */ +HWTEST_F(StartAbilityUtilsTest, CheckAppProvisionMode_004, TestSize.Level1) +{ + Want want; + int32_t userId = 1001; + StartAbilityUtils::startAbilityInfo = std::make_shared(); + int32_t ret = StartAbilityUtils::CheckAppProvisionMode(want, userId); + EXPECT_EQ(ret, ERR_NOT_IN_APP_PROVISION_MODE); +} + +/** + * @tc.name: CheckAppProvisionMode_005 + * @tc.desc: test class StartAbilityUtil CheckAppProvisionMode function + * @tc.type: FUNC + */ +HWTEST_F(StartAbilityUtilsTest, CheckAppProvisionMode_005, TestSize.Level1) +{ + Want want; + int32_t userId = 1001; + StartAbilityUtils::startAbilityInfo = std::make_shared(); + StartAbilityUtils::startAbilityInfo->abilityInfo.bundleName = "bundleName"; + StartAbilityUtils::startAbilityInfo->abilityInfo.name = "name"; + StartAbilityUtils::startAbilityInfo->status = 1; + int32_t ret = StartAbilityUtils::CheckAppProvisionMode(want, userId); + EXPECT_EQ(ret, StartAbilityUtils::startAbilityInfo->status); +} } // namespace AAFwk } // namespace OHOS diff --git a/test/unittest/state_utils_test/state_utils_test.cpp b/test/unittest/state_utils_test/state_utils_test.cpp index 3c81201db80..9c0d6d6c751 100644 --- a/test/unittest/state_utils_test/state_utils_test.cpp +++ b/test/unittest/state_utils_test/state_utils_test.cpp @@ -88,5 +88,26 @@ HWTEST_F(StateUtilsTest, StateUtilsTest_ConvertStateMap_0100, TestSize.Level2) EXPECT_EQ(StateUtils::ConvertStateMap(ABILITY_STATE_BACKGROUND_FAILED), BACKGROUND_FAILED); } +/** + * @tc.number: StateUtilsTest_ConvertStateMap_0200 + * @tc.desc: ConvertStateMap + * @tc.type: FUNC + * @tc.require: No + */ +HWTEST_F(StateUtilsTest, StateUtilsTest_ConvertStateMap_0200, TestSize.Level2) +{ + EXPECT_EQ(StateUtils::ConvertStateMap(ABILITY_STATE_INVALID_WINDOW_MODE), FOREGROUND_INVALID_MODE); +} + +/** + * @tc.number: StateUtilsTest_StateToStrMap_0200 + * @tc.desc: StateToStrMap + * @tc.type: FUNC + * @tc.require: No + */ +HWTEST_F(StateUtilsTest, StateUtilsTest_StateToStrMap_0200, TestSize.Level2) +{ + EXPECT_EQ(StateUtils::StateToStrMap(FOREGROUND_INVALID_MODE), std::string("FOREGROUND_INVALID_MODE")); +} } // namespace AAFwk } // namespace OHOS diff --git a/test/unittest/update_caller_info_util_test/update_caller_info_util_test.cpp b/test/unittest/update_caller_info_util_test/update_caller_info_util_test.cpp index a99e999303e..a2ad17cbe38 100644 --- a/test/unittest/update_caller_info_util_test/update_caller_info_util_test.cpp +++ b/test/unittest/update_caller_info_util_test/update_caller_info_util_test.cpp @@ -20,6 +20,7 @@ #define protected public #include "update_caller_info_util.h" #include "ability_manager_service.h" +#include "dialog_session_manager.h" #undef private #undef protected #include "ability_manager_errors.h" @@ -154,5 +155,61 @@ HWTEST_F(UpdateCallerInfoUtilTest, ClearProtectedWantParam_002, TestSize.Level1) MyFlag::isSystemAppCallRet = true; EXPECT_EQ(want.GetStringParam(Want::PARAM_ABILITY_UNIFIED_DATA_KEY), ""); } + +/** + * @tc.name: UpdateCallerInfoUtilTest_UpdateAsCallerInfoFromCallerRecord_0002 + * @tc.desc: Test the state of QueryAllAutoStartupApplications + * @tc.type: FUNC + */ +HWTEST_F(UpdateCallerInfoUtilTest, UpdateAsCallerInfoFromCallerRecord_0002, TestSize.Level1) +{ + std::shared_ptr updateCallerUtil = std::make_shared(); + Want want; + sptr callerToken = nullptr; + std::shared_ptr abilityRecord = MockAbilityRecord(AbilityType::PAGE); + callerToken = abilityRecord->GetToken(); + + updateCallerUtil->UpdateAsCallerInfoFromCallerRecord(want, callerToken); + EXPECT_NE(callerToken, nullptr); +} + +/** + * @tc.name: UpdateCallerInfoUtilTest_UpdateAsCallerInfoFromDialog_0001 + * @tc.desc: Test the state of QueryAllAutoStartupApplications + * @tc.type: FUNC + */ +HWTEST_F(UpdateCallerInfoUtilTest, UpdateAsCallerInfoFromDialog_0001, TestSize.Level1) +{ + std::shared_ptr updateCallerUtil = std::make_shared(); + DialogSessionManager dialogSessionManager; + Want want; + const std::string TEST_DIALOG_SESSION_ID = "dialogSessionId"; + want.SetParam(KEY_REQUEST_ID, std::string("1234567890")); + sptr dilogSessionInfo = nullptr; + std::shared_ptr dialogCallerInfo = std::make_shared(); + EXPECT_NE(dialogCallerInfo, nullptr); + dialogCallerInfo->targetWant = want; + + dialogSessionManager.SetDialogSessionInfo(TEST_DIALOG_SESSION_ID, dilogSessionInfo, dialogCallerInfo); + auto callerInfo = dialogSessionManager.GetDialogCallerInfo(TEST_DIALOG_SESSION_ID); + EXPECT_NE(dialogSessionManager.GetDialogCallerInfo(TEST_DIALOG_SESSION_ID), nullptr); + + bool ret = updateCallerUtil->UpdateAsCallerInfoFromDialog(want); + EXPECT_FALSE(ret); +} + +/** + * @tc.name: UpdateCallerInfoUtilTest_UpdateAsCallerInfoFromDialog_0002 + * @tc.desc: Test the state of QueryAllAutoStartupApplications + * @tc.type: FUNC + */ +HWTEST_F(UpdateCallerInfoUtilTest, UpdateAsCallerInfoFromDialog_0002, TestSize.Level1) +{ + std::shared_ptr updateCallerUtil = std::make_shared(); + DialogSessionManager dialogSessionManager; + Want want; + bool ret = updateCallerUtil->UpdateAsCallerInfoFromDialog(want); + EXPECT_FALSE(ret); +} } // namespace AAFwk } // namespace OHOS -- Gitee