diff --git a/test/unittest/ability_keep_alive_data_manager_test/ability_keep_alive_data_manager_test.cpp b/test/unittest/ability_keep_alive_data_manager_test/ability_keep_alive_data_manager_test.cpp index 0f9fc49e72cd59b1234e323ba950ffeb4c067241..7a8a0e92cc28366d5030f8502e686b53e4b7ed75 100644 --- a/test/unittest/ability_keep_alive_data_manager_test/ability_keep_alive_data_manager_test.cpp +++ b/test/unittest/ability_keep_alive_data_manager_test/ability_keep_alive_data_manager_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 @@ -673,28 +673,11 @@ HWTEST_F(AbilityKeepAliveDataManagerTest, DeleteKeepAliveDataWithSetterId_100, T AbilityKeepAliveDataManager abilityKeepAliveDataManager; KeepAliveInfo info; info.bundleName = "com.example.testbundle"; - auto result = abilityKeepAliveDataManager.DeleteKeepAliveDataWithSetterId(info); - EXPECT_EQ(result, ERR_INVALID_VALUE); - GTEST_LOG_(INFO) << "DeleteKeepAliveDataWithSetterId_100 end"; -} - -/** - * Feature: AbilityKeepAliveDataManager - * Function: DeleteKeepAliveDataWithSetterId - * SubFunction: NA - * FunctionPoints: AbilityKeepAliveDataManager DeleteKeepAliveDataWithSetterId - */ -HWTEST_F(AbilityKeepAliveDataManagerTest, DeleteKeepAliveDataWithSetterId_200, TestSize.Level1) -{ - GTEST_LOG_(INFO) << "DeleteKeepAliveDataWithSetterId_200 start"; - AbilityKeepAliveDataManager abilityKeepAliveDataManager; - KeepAliveInfo info; - info.bundleName = "com.example.testbundle"; info.userId = 1; info.setterId = 100; auto result = abilityKeepAliveDataManager.DeleteKeepAliveDataWithSetterId(info); EXPECT_EQ(result, ERR_OK); - GTEST_LOG_(INFO) << "DeleteKeepAliveDataWithSetterId_200 end"; + GTEST_LOG_(INFO) << "DeleteKeepAliveDataWithSetterId_100 end"; } /** @@ -703,9 +686,9 @@ HWTEST_F(AbilityKeepAliveDataManagerTest, DeleteKeepAliveDataWithSetterId_200, T * SubFunction: NA * FunctionPoints: AbilityKeepAliveDataManager DeleteKeepAliveDataWithSetterId */ -HWTEST_F(AbilityKeepAliveDataManagerTest, DeleteKeepAliveDataWithSetterId_300, TestSize.Level1) +HWTEST_F(AbilityKeepAliveDataManagerTest, DeleteKeepAliveDataWithSetterId_200, TestSize.Level1) { - GTEST_LOG_(INFO) << "DeleteKeepAliveDataWithSetterId_300 start"; + GTEST_LOG_(INFO) << "DeleteKeepAliveDataWithSetterId_200 start"; AbilityKeepAliveDataManager abilityKeepAliveDataManager; std::shared_ptr kvStorePtr = std::make_shared(); abilityKeepAliveDataManager.kvStorePtr_ = kvStorePtr; @@ -717,7 +700,7 @@ HWTEST_F(AbilityKeepAliveDataManagerTest, DeleteKeepAliveDataWithSetterId_300, T info.setterId = 100; auto result = abilityKeepAliveDataManager.DeleteKeepAliveDataWithSetterId(info); EXPECT_EQ(result, ERR_OK); - GTEST_LOG_(INFO) << "DeleteKeepAliveDataWithSetterId_300 end"; + GTEST_LOG_(INFO) << "DeleteKeepAliveDataWithSetterId_200 end"; } /** diff --git a/test/unittest/app_preloader_test/app_preloader_test.cpp b/test/unittest/app_preloader_test/app_preloader_test.cpp index 7fb0402383365d8b3c85899398f63d843a0ba457..61152cf5fa65137f4d2cf231ef1a795e597bcc05 100755 --- a/test/unittest/app_preloader_test/app_preloader_test.cpp +++ b/test/unittest/app_preloader_test/app_preloader_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 @@ -15,7 +15,9 @@ #include +#define private public #include "app_preloader.h" +#undef private #include "ability_manager_errors.h" #include "hilog_tag_wrapper.h" @@ -317,6 +319,52 @@ HWTEST_F(AppPreloaderTest, AppPreloaderTest_GetLaunchWant_0100, TestSize.Level2) EXPECT_EQ(ret, AAFwk::ERR_TARGET_BUNDLE_NOT_EXIST); } +/** + * @tc.number: AppPreloaderTest_GetLaunchWant_0200 + * @tc.desc: Test GetLaunchWant works + * @tc.type: FUNC + * @tc.Function: GetLaunchWant + * @tc.SubFunction: NA + * @tc.EnvConditions: NA + */ +HWTEST_F(AppPreloaderTest, AppPreloaderTest_GetLaunchWant_0200, TestSize.Level2) +{ + TAG_LOGD(AAFwkTag::TEST, "AppPreloaderTest_GetLaunchWant_0200 start."); + auto manager = std::make_shared(remoteClientManager_); + EXPECT_NE(manager, nullptr); + + manager->remoteClientManager_ = nullptr; + std::string bundleName = "com.acts.preloadtest"; + int32_t userId = -2; + Want want; + auto ret = manager->GetLaunchWant(bundleName, userId, want); + manager->remoteClientManager_ = remoteClientManager_; + EXPECT_FALSE(ret); +} + + /** + * @tc.number: AppPreloaderTest_GetLaunchAbilityInfo_0100 + * @tc.desc: Test GetLaunchAbilityInfo works + * @tc.type: FUNC + * @tc.Function: GetLaunchAbilityInfo + * @tc.SubFunction: NA + * @tc.EnvConditions: NA + */ +HWTEST_F(AppPreloaderTest, AppPreloaderTest_GetLaunchAbilityInfo_0100, TestSize.Level2) +{ + TAG_LOGD(AAFwkTag::TEST, "AppPreloaderTest_GetLaunchAbilityInfo_0100 start."); + auto manager = std::make_shared(remoteClientManager_); + EXPECT_NE(manager, nullptr); + + manager->remoteClientManager_ = nullptr; + Want want; + int32_t userId = -2; + AbilityInfo abilityInfo; + auto ret = manager->GetLaunchAbilityInfo(want, userId, abilityInfo); + manager->remoteClientManager_ = remoteClientManager_; + EXPECT_FALSE(ret); +} + /** * @tc.number: AppPreloaderTest_GetLaunchAbilityInfo_0200 * @tc.desc: Test GetLaunchAbilityInfo works @@ -448,5 +496,49 @@ HWTEST_F(AppPreloaderTest, AppPreloaderTest_GetBundleAndHapInfo_0200, TestSize.L auto ret = manager->GeneratePreloadRequest(bundleName, userId, appIndex, request); EXPECT_EQ(ret, AAFwk::GET_BUNDLE_INFO_FAILED); } + + /** + * @tc.number: AppPreloaderTest_GetBundleAndHapInfo_0300 + * @tc.desc: Test GetBundleAndHapInfo works + * @tc.type: FUNC + * @tc.Function: GetBundleAndHapInfo + * @tc.SubFunction: NA + * @tc.EnvConditions: NA + */ +HWTEST_F(AppPreloaderTest, AppPreloaderTest_GetBundleAndHapInfo_0300, TestSize.Level2) +{ + TAG_LOGD(AAFwkTag::TEST, "AppPreloaderTest_GetBundleAndHapInfo_0300 start."); + auto manager = std::make_shared(remoteClientManager_); + EXPECT_NE(manager, nullptr); + + manager->remoteClientManager_ = nullptr; + std::string bundleName = "com.acts.preloadtest"; + int32_t userId = -2; + AbilityInfo abilityInfo; + BundleInfo bundleInfo; + HapModuleInfo hapModuleInfo; + auto ret = manager->GetBundleAndHapInfo(bundleName, userId, abilityInfo, bundleInfo, hapModuleInfo); + manager->remoteClientManager_ = remoteClientManager_; + EXPECT_FALSE(ret); +} + + /** + * @tc.number: AppPreloaderTest_GetBundleManagerHelper_0100 + * @tc.desc: Test GetBundleManagerHelper works + * @tc.type: FUNC + * @tc.Function: GetBundleManagerHelper + * @tc.SubFunction: NA + * @tc.EnvConditions: NA + */ +HWTEST_F(AppPreloaderTest, AppPreloaderTest_GetBundleManagerHelper_0100, TestSize.Level2) +{ + TAG_LOGD(AAFwkTag::TEST, "AppPreloaderTest_GetBundleManagerHelper_0100 start."); + auto manager = std::make_shared(remoteClientManager_); + EXPECT_NE(manager, nullptr); + manager->remoteClientManager_ = nullptr; + auto ret = manager->GetBundleManagerHelper(); + manager->remoteClientManager_ = remoteClientManager_; + EXPECT_EQ(ret, nullptr); +} } // namespace AppExecFwk } // namespace OHOS diff --git a/test/unittest/app_utils_test/app_utils_test.cpp b/test/unittest/app_utils_test/app_utils_test.cpp index 560136c594abb3846e6f48ad428e0676105870d9..07cde8bd39b9a1a892eb83d59a81d8abd63f16ad 100644 --- a/test/unittest/app_utils_test/app_utils_test.cpp +++ b/test/unittest/app_utils_test/app_utils_test.cpp @@ -633,5 +633,304 @@ HWTEST_F(AppUtilsTest, IsLaunchEmbededUIAbility_0100, TestSize.Level2) bool result = appUtils.IsLaunchEmbededUIAbility(); EXPECT_FALSE(result); } + +/** + * @tc.number: AppUtilsTest_2200 + * @tc.desc: Test IsLauncher works + * @tc.type: FUNC + */ +HWTEST_F(AppUtilsTest, AppUtilsTest_2200, TestSize.Level2) +{ + TAG_LOGI(AAFwkTag::TEST, "AppUtilsTest_2200 called."); + auto &appUtils = AAFwk::AppUtils::GetInstance(); + appUtils.isSceneBoard_ = true; + std::string abilityName = "com.ohos.sceneboard"; + auto isLauncher = appUtils.IsLauncher(abilityName); + EXPECT_TRUE(isLauncher); +} + +/** + * @tc.number: AppUtilsTest_2300 + * @tc.desc: Test IsLauncher works + * @tc.type: FUNC + */ +HWTEST_F(AppUtilsTest, AppUtilsTest_2300, TestSize.Level2) +{ + TAG_LOGI(AAFwkTag::TEST, "AppUtilsTest_2300 called."); + auto &appUtils = AAFwk::AppUtils::GetInstance(); + appUtils.isSceneBoard_ = false; + std::string abilityName = "com.ohos.launcher"; + auto isLauncher = appUtils.IsLauncher(abilityName); + EXPECT_TRUE(isLauncher); +} + +/** + * @tc.number: AppUtilsTest_2400 + * @tc.desc: Test IsLauncherAbility works + * @tc.type: FUNC + */ +HWTEST_F(AppUtilsTest, AppUtilsTest_2400, TestSize.Level2) +{ + TAG_LOGI(AAFwkTag::TEST, "AppUtilsTest_2400 called."); + auto &appUtils = AAFwk::AppUtils::GetInstance(); + appUtils.isSceneBoard_ = true; + std::string abilityName = "com.ohos.sceneboard.MainAbility"; + auto isLauncherAbility = appUtils.IsLauncherAbility(abilityName); + EXPECT_TRUE(isLauncherAbility); +} + +/** + * @tc.number: AppUtilsTest_2500 + * @tc.desc: Test IsLauncherAbility works + * @tc.type: FUNC + */ +HWTEST_F(AppUtilsTest, AppUtilsTest_2500, TestSize.Level2) +{ + TAG_LOGI(AAFwkTag::TEST, "AppUtilsTest_2500 called."); + auto &appUtils = AAFwk::AppUtils::GetInstance(); + appUtils.isSceneBoard_ = false; + std::string abilityName = "com.ohos.launcher.MainAbility"; + auto isLauncherAbility = appUtils.IsLauncherAbility(abilityName); + EXPECT_TRUE(isLauncherAbility); +} + +/** + * @tc.number: AppUtilsTest_2600 + * @tc.desc: Test IsLaunchEmbededUIAbility works + * @tc.type: FUNC + */ +HWTEST_F(AppUtilsTest, AppUtilsTest_2600, TestSize.Level2) +{ + TAG_LOGI(AAFwkTag::TEST, "AppUtilsTest_2600 called."); + auto &appUtils = AAFwk::AppUtils::GetInstance(); + appUtils.isLaunchEmbededUIAbility_.isLoaded = false; + auto value = OHOS::system::GetBoolParameter("const.abilityms.launch_embeded_ui_ability", false); + auto isLaunchEmbededUIAbility = appUtils.IsLaunchEmbededUIAbility(); + EXPECT_EQ(value, isLaunchEmbededUIAbility); +} + +/** + * @tc.number: AppUtilsTest_2700 + * @tc.desc: Test IsLaunchEmbededUIAbility works + * @tc.type: FUNC + */ +HWTEST_F(AppUtilsTest, AppUtilsTest_2700, TestSize.Level2) +{ + TAG_LOGI(AAFwkTag::TEST, "AppUtilsTest_2700 called."); + auto &appUtils = AAFwk::AppUtils::GetInstance(); + appUtils.isLaunchEmbededUIAbility_.isLoaded = true; + appUtils.isLaunchEmbededUIAbility_.value = true; + auto isLaunchEmbededUIAbility = appUtils.IsLaunchEmbededUIAbility(); + EXPECT_TRUE(isLaunchEmbededUIAbility); +} + +/** + * @tc.number: AppUtilsTest_2800 + * @tc.desc: Test IsSystemReasonMessage works + * @tc.type: FUNC + */ +HWTEST_F(AppUtilsTest, AppUtilsTest_2800, TestSize.Level2) +{ + TAG_LOGI(AAFwkTag::TEST, "AppUtilsTest_2800 called."); + auto &appUtils = AAFwk::AppUtils::GetInstance(); + std::string reasonMessage = "ReasonMessage_SystemShare"; + auto isSystemReasonMessage = appUtils.IsSystemReasonMessage(reasonMessage); + EXPECT_TRUE(isSystemReasonMessage); +} + +/** + * @tc.number: AppUtilsTest_2900 + * @tc.desc: Test IsCacheAbilityEnabled works + * @tc.type: FUNC + */ +HWTEST_F(AppUtilsTest, AppUtilsTest_2900, TestSize.Level2) +{ + TAG_LOGI(AAFwkTag::TEST, "AppUtilsTest_2900 called."); + auto &appUtils = AAFwk::AppUtils::GetInstance(); + auto value = OHOS::system::GetBoolParameter("persist.sys.abilityms.cache_ability_enable", false); + auto isCacheAbilityEnabled = appUtils.IsCacheAbilityEnabled(); + EXPECT_EQ(value, isCacheAbilityEnabled); +} + +/** + * @tc.number: AppUtilsTest_3000 + * @tc.desc: Test IsSupportAppServiceExtension works + * @tc.type: FUNC + */ +HWTEST_F(AppUtilsTest, AppUtilsTest_3000, TestSize.Level2) +{ + TAG_LOGI(AAFwkTag::TEST, "AppUtilsTest_3000 called."); + auto &appUtils = AAFwk::AppUtils::GetInstance(); + appUtils.isSupportAppServiceExtension_.isLoaded = false; + auto value = OHOS::system::GetBoolParameter("const.abilityms.support_app_service", false); + auto isSupportAppServiceExtension = appUtils.IsSupportAppServiceExtension(); + EXPECT_EQ(value, isSupportAppServiceExtension); +} + +/** + * @tc.number: AppUtilsTest_3100 + * @tc.desc: Test IsSupportAppServiceExtension works + * @tc.type: FUNC + */ +HWTEST_F(AppUtilsTest, AppUtilsTest_3100, TestSize.Level2) +{ + TAG_LOGI(AAFwkTag::TEST, "AppUtilsTest_3100 called."); + auto &appUtils = AAFwk::AppUtils::GetInstance(); + appUtils.isSupportAppServiceExtension_.isLoaded = true; + appUtils.isSupportAppServiceExtension_.value = true; + auto isSupportAppServiceExtension = appUtils.IsSupportAppServiceExtension(); + EXPECT_TRUE(isSupportAppServiceExtension); +} + +/** + * @tc.number: AppUtilsTest_3200 + * @tc.desc: Test GetAncoAppIdentifiers works + * @tc.type: FUNC + */ +HWTEST_F(AppUtilsTest, AppUtilsTest_3200, TestSize.Level2) +{ + TAG_LOGI(AAFwkTag::TEST, "AppUtilsTest_3200 called."); + auto &appUtils = AAFwk::AppUtils::GetInstance(); + std::string value = system::GetParameter("persist.hmos_fusion_mgr.anco_identifier", ""); + auto identifiers = appUtils.GetAncoAppIdentifiers(); + EXPECT_EQ(value, identifiers); +} + +/** + * @tc.number: AppUtilsTest_3300 + * @tc.desc: Test GetMigrateClientBundleName works + * @tc.type: FUNC + */ +HWTEST_F(AppUtilsTest, AppUtilsTest_3300, TestSize.Level2) +{ + TAG_LOGI(AAFwkTag::TEST, "AppUtilsTest_3300 called."); + auto &appUtils = AAFwk::AppUtils::GetInstance(); + appUtils.migrateClientBundleName_.isLoaded = false; + auto value = system::GetParameter("const.sys.abilityms.migrate_client_bundle_name", ""); + auto migrateClientBundleName = appUtils.GetMigrateClientBundleName(); + EXPECT_EQ(value, migrateClientBundleName); +} + +/** + * @tc.number: AppUtilsTest_3400 + * @tc.desc: Test GetMigrateClientBundleName works + * @tc.type: FUNC + */ +HWTEST_F(AppUtilsTest, AppUtilsTest_3400, TestSize.Level2) +{ + TAG_LOGI(AAFwkTag::TEST, "AppUtilsTest_3400 called."); + auto &appUtils = AAFwk::AppUtils::GetInstance(); + appUtils.migrateClientBundleName_.isLoaded = true; + appUtils.migrateClientBundleName_.value = "value"; + auto migrateClientBundleName = appUtils.GetMigrateClientBundleName(); + EXPECT_EQ("value", migrateClientBundleName); +} + +/** + * @tc.number: AppUtilsTest_3500 + * @tc.desc: Test GetMigrateClientBundleName works + * @tc.type: FUNC + */ +HWTEST_F(AppUtilsTest, AppUtilsTest_3500, TestSize.Level2) +{ + TAG_LOGI(AAFwkTag::TEST, "AppUtilsTest_3500 called."); + auto &appUtils = AAFwk::AppUtils::GetInstance(); + appUtils.maxMultiProcessFeatureChildProcess_.isLoaded = false; + auto value = system::GetIntParameter("const.sys.abilityms.max_multi_process_feature_child_process", 0); + auto maxProcess = appUtils.MaxMultiProcessFeatureChildProcess(); + EXPECT_EQ(value, maxProcess); +} + +/** + * @tc.number: AppUtilsTest_3600 + * @tc.desc: Test IsAllowResidentInExtremeMemory works + * @tc.type: FUNC + */ +HWTEST_F(AppUtilsTest, AppUtilsTest_3600, TestSize.Level2) +{ + TAG_LOGI(AAFwkTag::TEST, "AppUtilsTest_3600 called."); + auto &appUtils = AAFwk::AppUtils::GetInstance(); + appUtils.residentProcessInExtremeMemory_.value.emplace_back("bundleName", "abilityName"); + std::string bundleName = "bundleName"; + std::string abilityName = "abilityName"; + auto ret = appUtils.IsAllowResidentInExtremeMemory(bundleName, abilityName); + EXPECT_TRUE(ret); +} + +/** + * @tc.number: AppUtilsTest_3700 + * @tc.desc: Test IsBigMemoryUnrelatedKeepAliveProc works + * @tc.type: FUNC + */ +HWTEST_F(AppUtilsTest, AppUtilsTest_3700, TestSize.Level2) +{ + TAG_LOGI(AAFwkTag::TEST, "AppUtilsTest_3700 called."); + auto &appUtils = AAFwk::AppUtils::GetInstance(); + appUtils.processProhibitedFromRestarting_.value.emplace_back("bundleName"); + std::string bundleName = "bundleName"; + auto ret = appUtils.IsBigMemoryUnrelatedKeepAliveProc(bundleName); + EXPECT_TRUE(ret); +} + +/** + * @tc.number: AppUtilsTest_3800 + * @tc.desc: Test IsRequireBigMemoryProcess works + * @tc.type: FUNC + */ +HWTEST_F(AppUtilsTest, AppUtilsTest_3800, TestSize.Level2) +{ + TAG_LOGI(AAFwkTag::TEST, "AppUtilsTest_3800 called."); + auto &appUtils = AAFwk::AppUtils::GetInstance(); + appUtils.requireBigMemoryApp_.value.emplace_back("bundleName"); + std::string bundleName = "bundleName"; + auto ret = appUtils.IsRequireBigMemoryProcess(bundleName); + EXPECT_TRUE(ret); +} + +/** + * @tc.number: AppUtilsTest_3900 + * @tc.desc: Test IsAllowStartAbilityWithoutCallerToken works + * @tc.type: FUNC + */ +HWTEST_F(AppUtilsTest, AppUtilsTest_3900, TestSize.Level2) +{ + TAG_LOGI(AAFwkTag::TEST, "AppUtilsTest_3900 called."); + auto &appUtils = AAFwk::AppUtils::GetInstance(); + appUtils.startAbilityWithoutCallerToken_.value.emplace_back("bundleName", "abilityName"); + std::string bundleName = "bundleName"; + std::string abilityName = "abilityName"; + auto ret = appUtils.IsAllowStartAbilityWithoutCallerToken(bundleName, abilityName); + EXPECT_TRUE(ret); +} + +/** + * @tc.number: AppUtilsTest_4000 + * @tc.desc: Test IsSupportNativeChildProcess works + * @tc.type: FUNC + */ +HWTEST_F(AppUtilsTest, AppUtilsTest_4000, TestSize.Level2) +{ + TAG_LOGI(AAFwkTag::TEST, "AppUtilsTest_4000 called."); + auto &appUtils = AAFwk::AppUtils::GetInstance(); + appUtils.isSupportNativeChildProcess_.isLoaded = false; + auto value = system::GetBoolParameter("persist.sys.abilityms.start_native_child_process", false); + auto isSupportNativeChildProcess = appUtils.IsSupportNativeChildProcess(); + EXPECT_EQ(value, isSupportNativeChildProcess); +} + +/** + * @tc.number: AppUtilsTest_4100 + * @tc.desc: Test IsSupportNativeChildProcess works + * @tc.type: FUNC + */ +HWTEST_F(AppUtilsTest, AppUtilsTest_4100, TestSize.Level2) +{ + TAG_LOGI(AAFwkTag::TEST, "AppUtilsTest_4100 called."); + auto &appUtils = AAFwk::AppUtils::GetInstance(); + appUtils.isSupportNativeChildProcess_.isLoaded = true; + appUtils.isSupportNativeChildProcess_.value = true; + auto isSupportNativeChildProcess = appUtils.IsSupportNativeChildProcess(); + EXPECT_TRUE(isSupportNativeChildProcess); +} } // namespace AbilityRuntime } // namespace OHOS