diff --git a/services/src/ui_appearance_ability.cpp b/services/src/ui_appearance_ability.cpp index 59d5a5172769d8be1607c365238e58f23526a622..40b6dc93971b25392252bf021d1f51c68557b326 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 437b5a076225c1944297597d442f9bdffc6b084c..6e283a120563aefc93c722c9ed1f9f9b193efc92 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