diff --git a/frameworks/c/ability_runtime/src/application_context.cpp b/frameworks/c/ability_runtime/src/application_context.cpp index fce78767fe..507ff6f989 100644 --- a/frameworks/c/ability_runtime/src/application_context.cpp +++ b/frameworks/c/ability_runtime/src/application_context.cpp @@ -567,7 +567,7 @@ AbilityRuntime_ErrorCode OH_AbilityRuntime_ApplicationContextNotifyPageChanged( } auto err = PageConfigManager::GetInstance().NotifyPageChanged(targetPageName, targetPageNameLength, windowId); if (err == ERR_NO_INIT) { - TAG_LOGE(AAFwkTag::APPKIT, "windowId invalid"); + TAG_LOGE(AAFwkTag::APPKIT, "invalid windowId"); return ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID; } if (err != ERR_OK) { diff --git a/test/unittest/capi_ability_runtime_application_context_test/capi_ability_runtime_application_context_second_test.cpp b/test/unittest/capi_ability_runtime_application_context_test/capi_ability_runtime_application_context_second_test.cpp index 78c17ea71d..7b3a726ddd 100644 --- a/test/unittest/capi_ability_runtime_application_context_test/capi_ability_runtime_application_context_second_test.cpp +++ b/test/unittest/capi_ability_runtime_application_context_test/capi_ability_runtime_application_context_second_test.cpp @@ -33,6 +33,7 @@ constexpr const char* BASE_LOG_FILE = "/log"; constexpr const char* EL_LIST[] = { "el1", "el2", "el3", "el4", "el5" }; constexpr int32_t BUFFER_SIZE = 1024; const std::string TEST_BUNDLE_NAME = "com.example.myapplication"; +constexpr const char* TEST_PAGE_NAME = "https://xxx.test.com"; } using namespace testing; @@ -300,4 +301,68 @@ HWTEST_F(CapiAbilityRuntimeApplicationContextSecondTest, GetLogFileDirTest_004, ASSERT_EQ(writeLength, logFileDir.length()); ASSERT_STREQ(buffer, logFileDir.c_str()); } + +/** + * @tc.number: NotifyPageChanged_001 + * @tc.desc: Function test with targetPageName is nullptr + * @tc.type: FUNC + */ +HWTEST_F(CapiAbilityRuntimeApplicationContextSecondTest, NotifyPageChanged_001, TestSize.Level2) +{ + const char* targetPage = ""; + int32_t targetPageNameLength = 0; + int32_t windowId = 12; + AbilityRuntime_ErrorCode code = + OH_AbilityRuntime_ApplicationContextNotifyPageChanged("", targetPageNameLength, windowId); + ASSERT_EQ(code, ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID); + + code = OH_AbilityRuntime_ApplicationContextNotifyPageChanged(NULL, targetPageNameLength, windowId); + ASSERT_EQ(code, ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID); + + code = OH_AbilityRuntime_ApplicationContextNotifyPageChanged(nullptr, targetPageNameLength, windowId); + ASSERT_EQ(code, ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID); + + code = OH_AbilityRuntime_ApplicationContextNotifyPageChanged(targetPage, targetPageNameLength, windowId); + ASSERT_EQ(code, ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID); +} + +/** + * @tc.number: NotifyPageChanged_002 + * @tc.desc: Function test with targetPageNameLength is invalid + * @tc.type: FUNC + */ +HWTEST_F(CapiAbilityRuntimeApplicationContextSecondTest, NotifyPageChanged_002, TestSize.Level2) +{ + int32_t targetPageNameLength = 0; + int32_t windowId = 12; + AbilityRuntime_ErrorCode code = + OH_AbilityRuntime_ApplicationContextNotifyPageChanged(TEST_PAGE_NAME, 0, windowId); + ASSERT_EQ(code, ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID); + + code = OH_AbilityRuntime_ApplicationContextNotifyPageChanged(TEST_PAGE_NAME, -1, windowId); + ASSERT_EQ(code, ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID); + + code = OH_AbilityRuntime_ApplicationContextNotifyPageChanged(TEST_PAGE_NAME, targetPageNameLength, windowId); + ASSERT_EQ(code, ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID); +} + +/** + * @tc.number: NotifyPageChanged_003 + * @tc.desc: Function test with windowId is invalid + * @tc.type: FUNC + */ +HWTEST_F(CapiAbilityRuntimeApplicationContextSecondTest, NotifyPageChanged_003, TestSize.Level2) +{ + int32_t targetPageNameLength = 0; + int32_t windowId = 0; + AbilityRuntime_ErrorCode code = + OH_AbilityRuntime_ApplicationContextNotifyPageChanged(TEST_PAGE_NAME, targetPageNameLength, 0); + ASSERT_EQ(code, ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID); + + code = OH_AbilityRuntime_ApplicationContextNotifyPageChanged(TEST_PAGE_NAME, targetPageNameLength, -12); + ASSERT_EQ(code, ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID); + + code = OH_AbilityRuntime_ApplicationContextNotifyPageChanged(TEST_PAGE_NAME, targetPageNameLength, windowId); + ASSERT_EQ(code, ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID); +} } \ No newline at end of file