diff --git a/ets_environment/frameworks/ets_environment/src/dynamic_loader.cpp b/ets_environment/frameworks/ets_environment/src/dynamic_loader.cpp index 6b2934937440590733373c543d94982429321f8b..6aa2f529f2b317171ad4a10c5f579ada18747424 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 64f3efc9db93921cd906ca3b79818ba849f1b002..3596dc4200432d197d0c554a871a1567dbfd249a 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 c2324ca79ca94fd173422c1d08835b9e4bc2a5af..345288acdf866db6e2de77dba657b66da6741aae 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 cda5f628c58b489701d3bd458dddfea4eb8c7d52..0e1e4760f5fdc571a47a6f228d70363a1a57dfef 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 655b3aa68392cfa4e0104e8b36b718f302570efd..35ef6fd2960eb54912ce79a8a5bb822f540ad06e 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 1b58b7e0509ae896768d9a6b1f29e1aa3061bf10..f5ffd1b4adbe772942d041be50e2c6d2324be502 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