From e46f6081407dab2f2803fb861805fb882ca889ed Mon Sep 17 00:00:00 2001 From: wkljy Date: Thu, 10 Jul 2025 17:36:47 +0800 Subject: [PATCH] jingtai Signed-off-by: wkljy Change-Id: I3bec39b10ae52c5725fdb05e2e2a7db2c031f20e Change-Id: I23af3acf40b3f3dd9093746a5eb76f2e4a3de2eb --- .../ets_environment/src/dynamic_loader.cpp | 4 +- .../ets_environment/src/ets_environment.cpp | 2 +- .../src/ani_common_configuration.cpp | 18 ++- .../runtime_test/ets_runtime_test.cpp | 1 + .../ui_extension_context_test.cpp | 17 +++ .../want_agent_helper_test.cpp | 113 ++++++++++++++++++ 6 files changed, 149 insertions(+), 6 deletions(-) diff --git a/ets_environment/frameworks/ets_environment/src/dynamic_loader.cpp b/ets_environment/frameworks/ets_environment/src/dynamic_loader.cpp index 6b293493744..6aa2f529f2b 100644 --- a/ets_environment/frameworks/ets_environment/src/dynamic_loader.cpp +++ b/ets_environment/frameworks/ets_environment/src/dynamic_loader.cpp @@ -41,7 +41,9 @@ static void ReadDlError() return; } auto ends = sprintf_s(g_dlError, sizeof(g_dlError), "%s", errMsg); - if (ends >= ERROR_BUF_SIZE) { + if (ends < 0) { + return; + } else if (ends >= ERROR_BUF_SIZE) { g_dlError[ERROR_BUF_SIZE - 1] = '\0'; } else { g_dlError[ends] = '\0'; diff --git a/ets_environment/frameworks/ets_environment/src/ets_environment.cpp b/ets_environment/frameworks/ets_environment/src/ets_environment.cpp index 64f3efc9db9..3596dc42004 100644 --- a/ets_environment/frameworks/ets_environment/src/ets_environment.cpp +++ b/ets_environment/frameworks/ets_environment/src/ets_environment.cpp @@ -76,7 +76,7 @@ bool ETSEnvironment::LoadBootPathFile(std::string &bootfiles) TAG_LOGE(AAFwkTag::ETSRUNTIME, "read json error"); return false; } - nlohmann::json jsonObject = nlohmann::json::parse(inFile); + nlohmann::json jsonObject = nlohmann::json::parse(inFile, nullptr, false); if (jsonObject.is_discarded()) { TAG_LOGE(AAFwkTag::ETSRUNTIME, "json discarded error"); inFile.close(); diff --git a/frameworks/ets/ani/ani_common/src/ani_common_configuration.cpp b/frameworks/ets/ani/ani_common/src/ani_common_configuration.cpp index c2324ca79ca..345288acdf8 100644 --- a/frameworks/ets/ani/ani_common/src/ani_common_configuration.cpp +++ b/frameworks/ets/ani/ani_common/src/ani_common_configuration.cpp @@ -76,12 +76,22 @@ void SetAdditionalConfiguration(ani_env *env, ani_object object, const AppExecFw env->Object_SetPropertyByName_Ref(object, "fontId", GetAniString(env, str)); std::string fontSizeScale = configuration.GetItem(AAFwk::GlobalConfigurationKey::SYSTEM_FONT_SIZE_SCALE); - env->Object_SetPropertyByName_Ref( - object, "fontSizeScale", CreateDouble(env, fontSizeScale != "" ? std::stod(fontSizeScale) : 1.0)); + try { + env->Object_SetPropertyByName_Ref( + object, "fontSizeScale", CreateDouble(env, fontSizeScale != "" ? std::stod(fontSizeScale) : 1.0)); + } catch (...) { + TAG_LOGE(AAFwkTag::ANI, "stod(%{public}s) failed", fontSizeScale.c_str()); + return; + } std::string fontWeightScale = configuration.GetItem(AAFwk::GlobalConfigurationKey::SYSTEM_FONT_WEIGHT_SCALE); - env->Object_SetPropertyByName_Ref( - object, "fontWeightScale", CreateDouble(env, fontWeightScale != "" ? std::stod(fontWeightScale) : 1.0)); + try { + env->Object_SetPropertyByName_Ref( + object, "fontWeightScale", CreateDouble(env, fontWeightScale != "" ? std::stod(fontWeightScale) : 1.0)); + } catch (...) { + TAG_LOGE(AAFwkTag::ANI, "stod(%{public}s) failed", fontWeightScale.c_str()); + return; + } str = configuration.GetItem(AAFwk::GlobalConfigurationKey::SYSTEM_MCC); env->Object_SetPropertyByName_Ref(object, "mcc", GetAniString(env, str)); diff --git a/test/unittest/runtime_test/ets_runtime_test.cpp b/test/unittest/runtime_test/ets_runtime_test.cpp index cda5f628c58..0e1e4760f5f 100644 --- a/test/unittest/runtime_test/ets_runtime_test.cpp +++ b/test/unittest/runtime_test/ets_runtime_test.cpp @@ -152,6 +152,7 @@ HWTEST_F(EtsRuntimeTest, LoadModule_0100, TestSize.Level1) std::string modulePath = "dir.test.module"; std::string hapPath = "/some/hap"; std::string srcEntrance = "main.ets"; + etsRuntime->PreloadModule(moduleName, hapPath, false, false); auto result = etsRuntime->LoadModule(moduleName, modulePath, hapPath, false, false, srcEntrance); EXPECT_EQ(result, nullptr); } diff --git a/test/unittest/ui_extension_context_test/ui_extension_context_test.cpp b/test/unittest/ui_extension_context_test/ui_extension_context_test.cpp index 655b3aa6839..35ef6fd2960 100644 --- a/test/unittest/ui_extension_context_test/ui_extension_context_test.cpp +++ b/test/unittest/ui_extension_context_test/ui_extension_context_test.cpp @@ -595,6 +595,23 @@ HWTEST_F(UIExtensionContextTest, GetAbilityInfoType_0100, TestSize.Level1) TAG_LOGI(AAFwkTag::TEST, "GetAbilityInfoType_0100 end"); } +/** + * @tc.number: StartUIAbilities_1000 + * @tc.name: StartUIAbilities + * @tc.desc: Start abilitys. + */ +HWTEST_F(UIExtensionContextTest, StartUIAbilities_1000, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "StartUIAbilities_1000 start"); + + auto context = std::make_shared(); + std::vector wantList; + std::string requestKey = "12345"; + EXPECT_TRUE(context->StartUIAbilities(wantList, requestKey) != ERR_OK); + + TAG_LOGI(AAFwkTag::TEST, "StartUIAbilities_1000 end"); +} + /** * @tc.number: StartAbility_0300 * @tc.name: StartAbility diff --git a/test/unittest/want_agent_helper_test/want_agent_helper_test.cpp b/test/unittest/want_agent_helper_test/want_agent_helper_test.cpp index 1b58b7e0509..f5ffd1b4adb 100644 --- a/test/unittest/want_agent_helper_test/want_agent_helper_test.cpp +++ b/test/unittest/want_agent_helper_test/want_agent_helper_test.cpp @@ -1404,4 +1404,117 @@ HWTEST_F(WantAgentHelperTest, WantAgentHelper_6600, Function | MediumTest | Leve const auto retCode = WantAgentHelper::GetBundleName(wantAgent, actualBundleName); ASSERT_TRUE(retCode == ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_PARAMETER); } + +/** + * @tc.name: CreateLocalWantAgent_0100 + * @tc.desc: Test CreateLocalWantAgent with null context + * @tc.type: FUNC + */ +HWTEST_F(WantAgentHelperTest, CreateLocalWantAgent_0100, TestSize.Level1) +{ + std::shared_ptr want = std::make_shared(); + std::vector> wants = {want}; + LocalWantAgentInfo paramsInfo(10, WantAgentConstant::OperationType::START_ABILITY, wants); + + auto requestCode = paramsInfo.GetRequestCode(); + EXPECT_EQ(requestCode, 10); + auto operationType = paramsInfo.GetOperationType(); + EXPECT_EQ(operationType, WantAgentConstant::OperationType::START_ABILITY); + auto wantGet = paramsInfo.GetWants(); + EXPECT_EQ(wantGet.size(), 1); + + std::shared_ptr wantAgent; + ErrCode result = WantAgentHelper::CreateLocalWantAgent(nullptr, paramsInfo, wantAgent); + + EXPECT_EQ(result, ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_PARAMETER); +} + +/** + * @tc.name: CreateLocalWantAgent_0200 + * @tc.desc: Test CreateLocalWantAgent with empty wants + * @tc.type: FUNC + */ +HWTEST_F(WantAgentHelperTest, CreateLocalWantAgent_0200, TestSize.Level1) +{ + auto context = std::make_shared(); + + std::vector> wants; + LocalWantAgentInfo paramsInfo(10, WantAgentConstant::OperationType::START_ABILITY, wants); + + std::shared_ptr wantAgent; + ErrCode result = WantAgentHelper::CreateLocalWantAgent(context, paramsInfo, wantAgent); + + EXPECT_EQ(result, ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_PARAMETER); +} + +/** + * @tc.name: CreateLocalWantAgent_0300 + * @tc.desc: Test CreateLocalWantAgent with null want in wants + * @tc.type: FUNC + */ +HWTEST_F(WantAgentHelperTest, CreateLocalWantAgent_0300, TestSize.Level1) +{ + auto context = std::make_shared(); + + std::vector> wants = {nullptr}; + LocalWantAgentInfo paramsInfo(10, WantAgentConstant::OperationType::START_ABILITY, wants); + + std::shared_ptr wantAgent; + ErrCode result = WantAgentHelper::CreateLocalWantAgent(context, paramsInfo, wantAgent); + + EXPECT_EQ(result, ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_PARAMETER); +} + +/** + * @tc.name: CreateLocalWantAgent_0400 + * @tc.desc: Test CreateLocalWantAgent with valid parameters + * @tc.type: FUNC + */ +HWTEST_F(WantAgentHelperTest, CreateLocalWantAgent_0400, TestSize.Level1) +{ + auto context = std::make_shared(); + + std::shared_ptr want = std::make_shared(); + std::vector> wants = {want}; + LocalWantAgentInfo paramsInfo(10, WantAgentConstant::OperationType::START_ABILITY, wants); + + std::shared_ptr wantAgent; + ErrCode result = WantAgentHelper::CreateLocalWantAgent(context, paramsInfo, wantAgent); + + EXPECT_EQ(result, ERR_OK); + + // Verify the created WantAgent + std::shared_ptr retrievedWant; + ErrCode getWantResult = WantAgentHelper::GetWant(wantAgent, retrievedWant); + EXPECT_EQ(getWantResult, ERR_OK); + + int32_t operationType; + ErrCode getTypeResult = WantAgentHelper::GetType(wantAgent, operationType); + EXPECT_EQ(getTypeResult, ERR_OK); + EXPECT_EQ(operationType, static_cast(WantAgentConstant::OperationType::START_ABILITY)); +} + +/** + * @tc.name: CreateLocalWantAgent_0500 + * @tc.desc: Test CreateLocalWantAgent with different operation types + * @tc.type: FUNC + */ +HWTEST_F(WantAgentHelperTest, CreateLocalWantAgent_0500, TestSize.Level1) +{ + auto context = std::make_shared(); + + std::shared_ptr want = std::make_shared(); + std::vector> wants = {want}; + LocalWantAgentInfo paramsInfo(10, WantAgentConstant::OperationType::SEND_COMMON_EVENT, wants); + + std::shared_ptr wantAgent; + ErrCode result = WantAgentHelper::CreateLocalWantAgent(context, paramsInfo, wantAgent); + + EXPECT_EQ(result, ERR_OK); + + int32_t operationType; + ErrCode getTypeResult = WantAgentHelper::GetType(wantAgent, operationType); + EXPECT_EQ(getTypeResult, ERR_OK); + EXPECT_EQ(operationType, static_cast(WantAgentConstant::OperationType::SEND_COMMON_EVENT)); +} } // namespace OHOS::AbilityRuntime::WantAgent -- Gitee