From 8ca40c82262e1e12d0e79033ee086bb664bb83e8 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 --- .../src/ani_common_configuration.cpp | 19 ++- .../runtime_test/ets_runtime_test.cpp | 3 +- .../want_agent_helper_test.cpp | 118 ++++++++++++++++++ 3 files changed, 135 insertions(+), 5 deletions(-) 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..bc8495e94b5 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,23 @@ 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; + } +>>>>>>> 4356274d7b (jingtai) 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..6b82612ba6c 100644 --- a/test/unittest/runtime_test/ets_runtime_test.cpp +++ b/test/unittest/runtime_test/ets_runtime_test.cpp @@ -115,7 +115,7 @@ HWTEST_F(EtsRuntimeTest, Initialize_100, TestSize.Level1) options_.lang = Runtime::Language::JS; std::unique_ptr jsRuntime = nullptr; std::unique_ptr etsRuntime = std::make_unique(); - bool result = etsRuntime->Initialize(options_, jsRuntime); + bool result = etsRuntimeetsRuntime->Initialize(options_, jsRuntime); EXPECT_EQ(result, false); options_.lang = Runtime::Language::ETS; } @@ -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"; + PreloadModule(moduleName, hapPath, false, false); auto result = etsRuntime->LoadModule(moduleName, modulePath, hapPath, false, false, srcEntrance); EXPECT_EQ(result, nullptr); } 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..8fb884b9d63 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,122 @@ 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) +{ + LocalWantAgentInfo paramsInfo; + std::shared_ptr want = std::make_shared(); + std::vector> wants = {want}; + paramsInfo.SetWants(wants); + paramsInfo.SetOperationType(WantAgentConstant::OperationType::START_ABILITY); + + 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(); + LocalWantAgentInfo paramsInfo; + std::vector> wants; + paramsInfo.SetWants(wants); + paramsInfo.SetOperationType(WantAgentConstant::OperationType::START_ABILITY); + + 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(); + LocalWantAgentInfo paramsInfo; + std::vector> wants = {nullptr}; + paramsInfo.SetWants(wants); + paramsInfo.SetOperationType(WantAgentConstant::OperationType::START_ABILITY); + + 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(); + context->SetBundleName("com.example.test"); + + LocalWantAgentInfo paramsInfo; + std::shared_ptr want = std::make_shared(); + std::vector> wants = {want}; + paramsInfo.SetWants(wants); + paramsInfo.SetOperationType(WantAgentConstant::OperationType::START_ABILITY); + + 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(); + context->SetBundleName("com.example.test"); + + LocalWantAgentInfo paramsInfo; + std::shared_ptr want = std::make_shared(); + std::vector> wants = {want}; + paramsInfo.SetWants(wants); + + // Test with SEND_COMMON_EVENT operation type + paramsInfo.SetOperationType(WantAgentConstant::OperationType::SEND_COMMON_EVENT); + + 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