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 c2324ca79ca94fd173422c1d08835b9e4bc2a5af..bc8495e94b5a4acfec020b05c36b29c2401eee11 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 cda5f628c58b489701d3bd458dddfea4eb8c7d52..6b82612ba6c4e7979f8d487c4d897086497ae573 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 1b58b7e0509ae896768d9a6b1f29e1aa3061bf10..8fb884b9d6342675483fbf67a2ac238d30c855fa 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