From 5a6a222d7f46dfa1a8db75ad992d5b72a24bd9e9 Mon Sep 17 00:00:00 2001 From: zhangzezhong Date: Wed, 3 Sep 2025 09:44:14 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=97=A0=E6=B3=95=E6=8A=9B?= =?UTF-8?q?=E5=87=BA=E9=94=99=E8=AF=AF=E7=A0=81=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangzezhong --- services/src/ui_appearance_ability.cpp | 22 ++++++------ test/unittest/ui_appearance_test.cpp | 48 ++++++++++++++++++++++++-- 2 files changed, 57 insertions(+), 13 deletions(-) diff --git a/services/src/ui_appearance_ability.cpp b/services/src/ui_appearance_ability.cpp index 59d5a51..40b6dc9 100644 --- a/services/src/ui_appearance_ability.cpp +++ b/services/src/ui_appearance_ability.cpp @@ -544,7 +544,7 @@ ErrCode UiAppearanceAbility::SetDarkMode(int32_t mode, int32_t& funcResult) if (!isCallingPerm) { LOGE("permission verification failed"); funcResult = PERMISSION_ERR; - return funcResult; + return SUCCEEDED; } auto userId = GetCallingUserId(); @@ -558,11 +558,11 @@ ErrCode UiAppearanceAbility::SetDarkMode(int32_t mode, int32_t& funcResult) } if (darkMode != currentDarkMode) { funcResult = OnSetDarkMode(userId, darkMode); - return funcResult; + return SUCCEEDED; } else { LOGW("current color mode is %{public}d, no need to change", darkMode); funcResult = SYS_ERR; - return funcResult; + return SUCCEEDED; } } @@ -635,16 +635,16 @@ ErrCode UiAppearanceAbility::SetFontScale(const std::string& fontScale, int32_t& if (!isCallingPerm) { LOGE("permission verification failed"); funcResult = PERMISSION_ERR; - return funcResult; + return SUCCEEDED; } if (!fontScale.empty()) { funcResult = OnSetFontScale(GetCallingUserId(), fontScale); - return funcResult; + return SUCCEEDED; } else { LOGE("current fontScale is empty!"); } funcResult = SYS_ERR; - return funcResult; + return SUCCEEDED; } ErrCode UiAppearanceAbility::GetFontScale(std::string& fontScale, int32_t& funcResult) @@ -660,7 +660,7 @@ ErrCode UiAppearanceAbility::GetFontScale(std::string& fontScale, int32_t& funcR } LOGD("get font scale :%{public}s", fontScale.c_str()); funcResult = SUCCEEDED; - return funcResult; + return SUCCEEDED; } int32_t UiAppearanceAbility::OnSetFontWeightScale(const int32_t userId, const std::string& fontWeightScale) @@ -700,16 +700,16 @@ ErrCode UiAppearanceAbility::SetFontWeightScale(const std::string& fontWeightSca if (!isCallingPerm) { LOGE("permission verification failed"); funcResult = PERMISSION_ERR; - return funcResult; + return SUCCEEDED; } if (!fontWeightScale.empty()) { funcResult = OnSetFontWeightScale(GetCallingUserId(), fontWeightScale); - return funcResult; + return SUCCEEDED; } else { LOGE("current fontWeightScale is empty!"); } funcResult = SYS_ERR; - return funcResult; + return SUCCEEDED; } ErrCode UiAppearanceAbility::GetFontWeightScale(std::string& fontWeightScale, int32_t& funcResult) @@ -726,7 +726,7 @@ ErrCode UiAppearanceAbility::GetFontWeightScale(std::string& fontWeightScale, in LOGD("get font weight scale :%{public}s", fontWeightScale.c_str()); funcResult = SUCCEEDED; - return funcResult; + return SUCCEEDED; } void UiAppearanceAbility::UpdateSmartGestureModeCallback(bool isAutoMode, int32_t userId) diff --git a/test/unittest/ui_appearance_test.cpp b/test/unittest/ui_appearance_test.cpp index 437b5a0..6e283a1 100644 --- a/test/unittest/ui_appearance_test.cpp +++ b/test/unittest/ui_appearance_test.cpp @@ -101,13 +101,13 @@ HWTEST_F(DarkModeTest, ui_appearance_test_001, TestSize.Level0) auto test = DarkModeTest::GetUiAppearanceAbilityTest(); int32_t result = -1; test->SetDarkMode(DarkMode::ALWAYS_DARK, result); - EXPECT_EQ(result, 0); + EXPECT_EQ(result, UiAppearanceAbilityErrCode::SUCCEEDED); int32_t mode = -1; test->GetDarkMode(mode); EXPECT_EQ(mode, DarkMode::ALWAYS_DARK); test->SetDarkMode(DarkMode::ALWAYS_LIGHT, result); - EXPECT_EQ(result, 0); + EXPECT_EQ(result, UiAppearanceAbilityErrCode::SUCCEEDED); test->GetDarkMode(mode); EXPECT_EQ(mode, DarkMode::ALWAYS_LIGHT); } @@ -283,5 +283,49 @@ HWTEST_F(DarkModeTest, ui_appearance_test_009, TestSize.Level0) bool ret = test->BackGroundAppColorSwitch(nullptr, 0); EXPECT_EQ(false, ret); } + +/** + * @tc.name: ui_appearance_test_010 + * @tc.desc: Test SetFontScale and GetFontScale APIs when repeatedly setting font scale. + * @tc.type: FUNC + */ +HWTEST_F(DarkModeTest, ui_appearance_test_010, TestSize.Level0) +{ + LOGI("Test SetFontScale and GetFontScale APIs when repeatedly setting font scale."); + + auto test = DarkModeTest::GetUiAppearanceAbilityTest(); + int32_t result = -1; + test->SetFontScale("", result); + EXPECT_EQ(result, UiAppearanceAbilityErrCode::SYS_ERR); + std::string scale = "1"; + test->SetFontScale(scale, result); + EXPECT_EQ(result, UiAppearanceAbilityErrCode::SUCCEEDED); + std::string scaleGet; + test->GetFontScale(scaleGet, result); + ASSERT_EQ(result, UiAppearanceAbilityErrCode::SUCCEEDED); + EXPECT_EQ(scale, scaleGet); +} + +/** + * @tc.name: ui_appearance_test_011 + * @tc.desc: Test SetFontWeightScale and GetFontWeightScale APIs when repeatedly setting font weight scale. + * @tc.type: FUNC + */ +HWTEST_F(DarkModeTest, ui_appearance_test_011, TestSize.Level0) +{ + LOGI("Test SetFontWeightScale and GetFontWeightScale APIs when repeatedly setting font weight scale."); + + auto test = DarkModeTest::GetUiAppearanceAbilityTest(); + int32_t result = -1; + test->SetFontWeightScale("", result); + EXPECT_EQ(result, UiAppearanceAbilityErrCode::SYS_ERR); + std::string scale = "1"; + test->SetFontWeightScale(scale, result); + EXPECT_EQ(result, UiAppearanceAbilityErrCode::SUCCEEDED); + std::string scaleGet; + test->GetFontWeightScale(scaleGet, result); + ASSERT_EQ(result, UiAppearanceAbilityErrCode::SUCCEEDED); + EXPECT_EQ(scale, scaleGet); +} } // namespace ArkUi::UiAppearance } // namespace OHOS -- Gitee