From dafcd2f5f6a63b6b9a17898cbfcc032b51cf1c7e Mon Sep 17 00:00:00 2001 From: zhangzezhong Date: Thu, 12 Jun 2025 19:10:14 +0800 Subject: [PATCH] add AmsMgrScheduler unittest cases for ability_runtime Signed-off-by: zhangzezhong --- .../ams_mgr_scheduler_second_test.cpp | 130 ++++++++++++++++++ .../insight_intent_utils_test.cpp | 78 ++++++++++- 2 files changed, 207 insertions(+), 1 deletion(-) diff --git a/test/unittest/ams_mgr_scheduler_second_test/ams_mgr_scheduler_second_test.cpp b/test/unittest/ams_mgr_scheduler_second_test/ams_mgr_scheduler_second_test.cpp index b66b43280d6..266ea153dcf 100644 --- a/test/unittest/ams_mgr_scheduler_second_test/ams_mgr_scheduler_second_test.cpp +++ b/test/unittest/ams_mgr_scheduler_second_test/ams_mgr_scheduler_second_test.cpp @@ -2123,6 +2123,136 @@ HWTEST_F(AmsMgrSchedulerSecondTest, AmsMgrSchedulerSecondTest_IsCallerKilling_00 EXPECT_FALSE(ret); TAG_LOGI(AAFwkTag::TEST, "AmsMgrSchedulerSecondTest_IsCallerKilling_003 end"); } + +/* + * Feature: AmsMgrScheduler + * Function: KillProcessesInBatch + * SubFunction: NA + * FunctionPoints: AmsMgrScheduler KillProcessesInBatch + * EnvConditions: NA + * CaseDescription: not initial scheduler + */ +HWTEST_F(AmsMgrSchedulerSecondTest, KillProcessesInBatch_001, TestSize.Level1) +{ + std::shared_ptr amsMgrScheduler = std::make_shared(nullptr, nullptr); + ASSERT_NE(amsMgrScheduler, nullptr); + std::vector pids = {0}; + int32_t ret = amsMgrScheduler->KillProcessesInBatch(pids); + EXPECT_EQ(ret, ERR_INVALID_OPERATION); +} + +/* + * Feature: AmsMgrScheduler + * Function: KillProcessesInBatch + * SubFunction: NA + * FunctionPoints: AmsMgrScheduler KillProcessesInBatch + * EnvConditions: NA + * CaseDescription: initial scheduler call KillProcessesInBatch success + */ +HWTEST_F(AmsMgrSchedulerSecondTest, KillProcessesInBatch_002, TestSize.Level1) +{ + auto appMgrServiceInner = std::make_shared(); + std::shared_ptr amsMgrScheduler = + std::make_shared(appMgrServiceInner, taskHandler_); + ASSERT_NE(amsMgrScheduler, nullptr); + std::vector pids = {0}; + int32_t ret = amsMgrScheduler->KillProcessesInBatch(pids); + EXPECT_NE(ret, ERR_INVALID_OPERATION); +} + +/* + * Feature: AmsMgrScheduler + * Function: ForceKillApplication + * SubFunction: NA + * FunctionPoints: AmsMgrScheduler ForceKillApplication + * EnvConditions: NA + * CaseDescription: not initial scheduler + */ +HWTEST_F(AmsMgrSchedulerSecondTest, ForceKillApplication_001, TestSize.Level1) +{ + std::shared_ptr amsMgrScheduler = std::make_shared(nullptr, nullptr); + ASSERT_NE(amsMgrScheduler, nullptr); + std::string bundleName = "bundleName"; + int userId = -1; + int appIndex = 0; + int32_t ret = amsMgrScheduler->ForceKillApplication(bundleName, userId, appIndex); + EXPECT_EQ(ret, ERR_INVALID_OPERATION); +} + +/* + * Feature: AmsMgrScheduler + * Function: ForceKillApplication + * SubFunction: NA + * FunctionPoints: AmsMgrScheduler ForceKillApplication + * EnvConditions: NA + * CaseDescription: initial scheduler call ForceKillApplication success + */ +HWTEST_F(AmsMgrSchedulerSecondTest, ForceKillApplication_002, TestSize.Level1) +{ + auto appMgrServiceInner = std::make_shared(); + std::shared_ptr amsMgrScheduler = + std::make_shared(appMgrServiceInner, taskHandler_); + ASSERT_NE(amsMgrScheduler, nullptr); + std::string bundleName = "bundleName"; + int userId = -1; + int appIndex = 0; + int32_t ret = amsMgrScheduler->ForceKillApplication(bundleName, userId, appIndex); + EXPECT_NE(ret, ERR_INVALID_OPERATION); +} + +/* + * Feature: AmsMgrScheduler + * Function: IsNoRequireBigMemory + * SubFunction: NA + * FunctionPoints: AmsMgrScheduler IsNoRequireBigMemory + * EnvConditions: NA + * CaseDescription: not initial scheduler + */ +HWTEST_F(AmsMgrSchedulerSecondTest, IsNoRequireBigMemory_001, TestSize.Level1) +{ + std::shared_ptr amsMgrScheduler = std::make_shared(nullptr, nullptr); + ASSERT_NE(amsMgrScheduler, nullptr); + bool ret = amsMgrScheduler->IsNoRequireBigMemory(); + EXPECT_TRUE(ret); +} + +/* + * Feature: AmsMgrScheduler + * Function: IsNoRequireBigMemory + * SubFunction: NA + * FunctionPoints: AmsMgrScheduler IsNoRequireBigMemory + * EnvConditions: NA + * CaseDescription: have no permission + */ +HWTEST_F(AmsMgrSchedulerSecondTest, IsNoRequireBigMemory_002, TestSize.Level1) +{ + auto appMgrServiceInner = std::make_shared(); + std::shared_ptr amsMgrScheduler = + std::make_shared(appMgrServiceInner, taskHandler_); + ASSERT_NE(amsMgrScheduler, nullptr); + IPCSkeleton::SetCallingUid(-1); + bool ret = amsMgrScheduler->IsNoRequireBigMemory(); + EXPECT_TRUE(ret); +} + +/* + * Feature: AmsMgrScheduler + * Function: IsNoRequireBigMemory + * SubFunction: NA + * FunctionPoints: AmsMgrScheduler IsNoRequireBigMemory + * EnvConditions: NA + * CaseDescription: initial scheduler call IsNoRequireBigMemory success + */ +HWTEST_F(AmsMgrSchedulerSecondTest, IsNoRequireBigMemory_003, TestSize.Level1) +{ + auto appMgrServiceInner = std::make_shared(); + std::shared_ptr amsMgrScheduler = + std::make_shared(appMgrServiceInner, taskHandler_); + ASSERT_NE(amsMgrScheduler, nullptr); + IPCSkeleton::SetCallingUid(Constants::FOUNDATION_UID); + bool ret = amsMgrScheduler->IsNoRequireBigMemory(); + EXPECT_TRUE(ret); +} } // AppExecFwk } // OHOS diff --git a/test/unittest/insight_intent/insight_intent_utils_test/insight_intent_utils_test.cpp b/test/unittest/insight_intent/insight_intent_utils_test/insight_intent_utils_test.cpp index 46b059016ae..97c2c6caef3 100644 --- a/test/unittest/insight_intent/insight_intent_utils_test/insight_intent_utils_test.cpp +++ b/test/unittest/insight_intent/insight_intent_utils_test/insight_intent_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 @@ -309,6 +309,82 @@ HWTEST_F(InsightIntentUtilsTest, ConvertExtractInsightIntentGenericInfo_0100, Te TAG_LOGI(AAFwkTag::TEST, "InsightIntentUtilsTest ConvertExtractInsightIntentGenericInfo_0100 end."); } +/** + * @tc.name: ConvertExtractInsightIntentGenericInfo_0110 + * @tc.desc: basic function test of convert info. + * @tc.type: FUNC + */ +HWTEST_F(InsightIntentUtilsTest, ConvertExtractInsightIntentGenericInfo_0110, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "InsightIntentUtilsTest ConvertExtractInsightIntentGenericInfo_0110 start"); + AbilityRuntime::InsightIntentUtils utils; + InsightIntentInfoForQuery insightIntentInfoForQuery; + TEST_INSIGHT_INTENT_GENERIC_INFO.decoratorType = "@InsightIntentPage"; + auto result = utils.ConvertExtractInsightIntentGenericInfo(TEST_INSIGHT_INTENT_GENERIC_INFO, + insightIntentInfoForQuery); + EXPECT_EQ(result, ERR_OK); + Mock::VerifyAndClear(mockBundleMgr); + testing::Mock::AllowLeak(mockBundleMgr); + TAG_LOGI(AAFwkTag::TEST, "InsightIntentUtilsTest ConvertExtractInsightIntentGenericInfo_0110 end."); +} +/** + * @tc.name: ConvertExtractInsightIntentGenericInfo_0120 + * @tc.desc: basic function test of convert info. + * @tc.type: FUNC + */ + +HWTEST_F(InsightIntentUtilsTest, ConvertExtractInsightIntentGenericInfo_0120, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "InsightIntentUtilsTest ConvertExtractInsightIntentGenericInfo_0120 start"); + AbilityRuntime::InsightIntentUtils utils; + InsightIntentInfoForQuery insightIntentInfoForQuery; + TEST_INSIGHT_INTENT_GENERIC_INFO.decoratorType = "@InsightIntentEntry"; + auto result = utils.ConvertExtractInsightIntentGenericInfo(TEST_INSIGHT_INTENT_GENERIC_INFO, + insightIntentInfoForQuery); + EXPECT_EQ(result, ERR_OK); + Mock::VerifyAndClear(mockBundleMgr); + testing::Mock::AllowLeak(mockBundleMgr); + TAG_LOGI(AAFwkTag::TEST, "InsightIntentUtilsTest ConvertExtractInsightIntentGenericInfo_0120 end."); +} + +/** + * @tc.name: ConvertExtractInsightIntentGenericInfo_0130 + * @tc.desc: basic function test of convert info. + * @tc.type: FUNC + */ +HWTEST_F(InsightIntentUtilsTest, ConvertExtractInsightIntentGenericInfo_0130, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "InsightIntentUtilsTest ConvertExtractInsightIntentGenericInfo_0130 start"); + AbilityRuntime::InsightIntentUtils utils; + InsightIntentInfoForQuery insightIntentInfoForQuery; + TEST_INSIGHT_INTENT_GENERIC_INFO.decoratorType = "@InsightIntentFunctionMethod"; + auto result = utils.ConvertExtractInsightIntentGenericInfo(TEST_INSIGHT_INTENT_GENERIC_INFO, + insightIntentInfoForQuery); + EXPECT_EQ(result, ERR_OK); + Mock::VerifyAndClear(mockBundleMgr); + testing::Mock::AllowLeak(mockBundleMgr); + TAG_LOGI(AAFwkTag::TEST, "InsightIntentUtilsTest ConvertExtractInsightIntentGenericInfo_0130 end."); +} + +/** + * @tc.name: ConvertExtractInsightIntentGenericInfo_0140 + * @tc.desc: basic function test of convert info. + * @tc.type: FUNC + */ +HWTEST_F(InsightIntentUtilsTest, ConvertExtractInsightIntentGenericInfo_0140, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "InsightIntentUtilsTest ConvertExtractInsightIntentGenericInfo_0140 start"); + AbilityRuntime::InsightIntentUtils utils; + InsightIntentInfoForQuery insightIntentInfoForQuery; + TEST_INSIGHT_INTENT_GENERIC_INFO.decoratorType = "@InsightIntentForm"; + auto result = utils.ConvertExtractInsightIntentGenericInfo(TEST_INSIGHT_INTENT_GENERIC_INFO, + insightIntentInfoForQuery); + EXPECT_EQ(result, ERR_OK); + Mock::VerifyAndClear(mockBundleMgr); + testing::Mock::AllowLeak(mockBundleMgr); + TAG_LOGI(AAFwkTag::TEST, "InsightIntentUtilsTest ConvertExtractInsightIntentGenericInfo_0140 end."); +} + /** * @tc.name: ConvertExtractInsightIntentGenericInfo_0200 * @tc.desc: basic function test of convert info. -- Gitee