From 00137394f01ce5bb7a412a51803c0b34140331d2 Mon Sep 17 00:00:00 2001 From: zexin_c Date: Sun, 4 Jan 2026 19:59:05 +0800 Subject: [PATCH 1/5] add capitdd Signed-off-by: zexin_c --- ...untime_application_context_second_test.cpp | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) 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..06611df5ea 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 @@ -300,4 +300,71 @@ 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) +{ + char* targetPage = ""; + int32_t targetPageNameLength = 0; + int32_t windowId = 0; + 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, -1, 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) +{ + char* targetPage = ""; + int32_t targetPageNameLength = 0; + int32_t windowId = 0; + AbilityRuntime_ErrorCode code = + OH_AbilityRuntime_ApplicationContextNotifyPageChanged(targetPage, 0, windowId); + ASSERT_EQ(code, ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID); + + code = OH_AbilityRuntime_ApplicationContextNotifyPageChanged(targetPage, -1, 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_003 + * @tc.desc: Function test with windowId is invalid + * @tc.type: FUNC + */ +HWTEST_F(CapiAbilityRuntimeApplicationContextSecondTest, NotifyPageChanged_003, TestSize.Level2) +{ + char* targetPage = ""; + int32_t targetPageNameLength = 0; + int32_t windowId = 0; + AbilityRuntime_ErrorCode code = + OH_AbilityRuntime_ApplicationContextNotifyPageChanged(targetPage, targetPageNameLength, 0); + ASSERT_EQ(code, ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID); + + code = OH_AbilityRuntime_ApplicationContextNotifyPageChanged(targetPage, targetPageNameLength, -12); + 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); +} } \ No newline at end of file From e60935fe1b29de70f4eaa440a8d2072da3470e1f Mon Sep 17 00:00:00 2001 From: zexin_c Date: Sun, 4 Jan 2026 20:17:44 +0800 Subject: [PATCH 2/5] fix Signed-off-by: zexin_c --- ...capi_ability_runtime_application_context_second_test.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 06611df5ea..69786e9eb5 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 @@ -308,7 +308,7 @@ HWTEST_F(CapiAbilityRuntimeApplicationContextSecondTest, GetLogFileDirTest_004, */ HWTEST_F(CapiAbilityRuntimeApplicationContextSecondTest, NotifyPageChanged_001, TestSize.Level2) { - char* targetPage = ""; + const char* targetPage = ""; int32_t targetPageNameLength = 0; int32_t windowId = 0; AbilityRuntime_ErrorCode code = @@ -333,7 +333,7 @@ HWTEST_F(CapiAbilityRuntimeApplicationContextSecondTest, NotifyPageChanged_001, */ HWTEST_F(CapiAbilityRuntimeApplicationContextSecondTest, NotifyPageChanged_002, TestSize.Level2) { - char* targetPage = ""; + const char* targetPage = ""; int32_t targetPageNameLength = 0; int32_t windowId = 0; AbilityRuntime_ErrorCode code = @@ -354,7 +354,7 @@ HWTEST_F(CapiAbilityRuntimeApplicationContextSecondTest, NotifyPageChanged_002, */ HWTEST_F(CapiAbilityRuntimeApplicationContextSecondTest, NotifyPageChanged_003, TestSize.Level2) { - char* targetPage = ""; + const char* targetPage = ""; int32_t targetPageNameLength = 0; int32_t windowId = 0; AbilityRuntime_ErrorCode code = From a0ffb2fa33a3c4aa096254a78becc0492eab4a6c Mon Sep 17 00:00:00 2001 From: zexin_c Date: Mon, 5 Jan 2026 10:36:46 +0800 Subject: [PATCH 3/5] add capitdd Signed-off-by: zexin_c --- ...untime_application_context_second_test.cpp | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) 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 69786e9eb5..da70f8c286 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://www.baidu.com"; } using namespace testing; @@ -310,7 +311,7 @@ HWTEST_F(CapiAbilityRuntimeApplicationContextSecondTest, NotifyPageChanged_001, { const char* targetPage = ""; int32_t targetPageNameLength = 0; - int32_t windowId = 0; + int32_t windowId = 12; AbilityRuntime_ErrorCode code = OH_AbilityRuntime_ApplicationContextNotifyPageChanged("", targetPageNameLength, windowId); ASSERT_EQ(code, ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID); @@ -321,9 +322,8 @@ HWTEST_F(CapiAbilityRuntimeApplicationContextSecondTest, NotifyPageChanged_001, code = OH_AbilityRuntime_ApplicationContextNotifyPageChanged(nullptr, targetPageNameLength, windowId); ASSERT_EQ(code, ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID); - code = OH_AbilityRuntime_ApplicationContextNotifyPageChanged(targetPage, -1, windowId); + code = OH_AbilityRuntime_ApplicationContextNotifyPageChanged(targetPage, targetPageNameLength, windowId); ASSERT_EQ(code, ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID); - } /** @@ -333,17 +333,16 @@ HWTEST_F(CapiAbilityRuntimeApplicationContextSecondTest, NotifyPageChanged_001, */ HWTEST_F(CapiAbilityRuntimeApplicationContextSecondTest, NotifyPageChanged_002, TestSize.Level2) { - const char* targetPage = ""; int32_t targetPageNameLength = 0; - int32_t windowId = 0; + int32_t windowId = 12; AbilityRuntime_ErrorCode code = - OH_AbilityRuntime_ApplicationContextNotifyPageChanged(targetPage, 0, windowId); + OH_AbilityRuntime_ApplicationContextNotifyPageChanged(TEST_PAGE_NAME, 0, windowId); ASSERT_EQ(code, ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID); - code = OH_AbilityRuntime_ApplicationContextNotifyPageChanged(targetPage, -1, windowId); + code = OH_AbilityRuntime_ApplicationContextNotifyPageChanged(TEST_PAGE_NAME, -1, windowId); ASSERT_EQ(code, ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID); - code = OH_AbilityRuntime_ApplicationContextNotifyPageChanged(targetPage, targetPageNameLength, windowId); + code = OH_AbilityRuntime_ApplicationContextNotifyPageChanged(TEST_PAGE_NAME, targetPageNameLength, windowId); ASSERT_EQ(code, ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID); } @@ -354,17 +353,16 @@ HWTEST_F(CapiAbilityRuntimeApplicationContextSecondTest, NotifyPageChanged_002, */ HWTEST_F(CapiAbilityRuntimeApplicationContextSecondTest, NotifyPageChanged_003, TestSize.Level2) { - const char* targetPage = ""; int32_t targetPageNameLength = 0; int32_t windowId = 0; AbilityRuntime_ErrorCode code = - OH_AbilityRuntime_ApplicationContextNotifyPageChanged(targetPage, targetPageNameLength, 0); + OH_AbilityRuntime_ApplicationContextNotifyPageChanged(TEST_PAGE_NAME, targetPageNameLength, 0); ASSERT_EQ(code, ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID); - code = OH_AbilityRuntime_ApplicationContextNotifyPageChanged(targetPage, targetPageNameLength, -12); + code = OH_AbilityRuntime_ApplicationContextNotifyPageChanged(TEST_PAGE_NAME, targetPageNameLength, -12); ASSERT_EQ(code, ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID); - code = OH_AbilityRuntime_ApplicationContextNotifyPageChanged(targetPage, targetPageNameLength, windowId); + code = OH_AbilityRuntime_ApplicationContextNotifyPageChanged(TEST_PAGE_NAME, targetPageNameLength, windowId); ASSERT_EQ(code, ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID); } } \ No newline at end of file From 21df490ba141b6e0ca0b7a8286370679c39c0a8b Mon Sep 17 00:00:00 2001 From: zexin_c Date: Mon, 5 Jan 2026 11:26:34 +0800 Subject: [PATCH 4/5] fix log Signed-off-by: zexin_c --- frameworks/c/ability_runtime/src/application_context.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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) { From e4c04bbd6dc763fd681b6c2d65eddba96d660c15 Mon Sep 17 00:00:00 2001 From: zexin_c Date: Mon, 5 Jan 2026 15:09:55 +0800 Subject: [PATCH 5/5] add capitdd Signed-off-by: zexin_c --- .../capi_ability_runtime_application_context_second_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 da70f8c286..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,7 +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://www.baidu.com"; +constexpr const char* TEST_PAGE_NAME = "https://xxx.test.com"; } using namespace testing;