1 /* 2 * Copyright (c) 2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include <gtest/gtest.h> 17 18 #include "text_effect.h" 19 #include "text_effect_macro.h" 20 21 using namespace testing; 22 using namespace testing::ext; 23 using namespace OHOS::Rosen; 24 25 class TextEffectFactoryCreatorTest : public testing::Test { 26 public: SetUp()27 void SetUp() override {} TearDown()28 void TearDown() override 29 { 30 TextEffectFactoryCreator::GetInstance().factoryTable_.erase(TextEffectStrategy::STRATEGY_BUTT); 31 } 32 }; 33 34 class TextTestEffect : public TextEffect { 35 public: 36 TextTestEffect() = default; 37 ~TextTestEffect() override = default; 38 UpdateEffectConfig(const std::unordered_map<TextEffectAttribute,std::string> & config)39 int UpdateEffectConfig(const std::unordered_map<TextEffectAttribute, std::string>& config) override { return 0; } AppendTypography(const std::vector<TypographyConfig> & typographyConfigs)40 int AppendTypography(const std::vector<TypographyConfig>& typographyConfigs) override { return 0; } RemoveTypography(const std::vector<TypographyConfig> & typographyConfigs)41 void RemoveTypography(const std::vector<TypographyConfig>& typographyConfigs) override {} UpdateTypography(std::vector<std::pair<TypographyConfig,TypographyConfig>> & typographyConfigs)42 int UpdateTypography(std::vector<std::pair<TypographyConfig, TypographyConfig>>& typographyConfigs) override 43 { 44 return 0; 45 } StartEffect(Drawing::Canvas * canvas,double x,double y)46 void StartEffect(Drawing::Canvas* canvas, double x, double y) override {} StopEffect()47 void StopEffect() override {} NoEffect(Drawing::Canvas * canvas,double x,double y)48 void NoEffect(Drawing::Canvas* canvas, double x, double y) override {} 49 }; 50 51 52 /* 53 * @tc.name: TextEffectFactoryCreatorTest001 54 * @tc.desc: Test for RegisterFactory action 55 * @tc.type: FUNC 56 */ 57 HWTEST_F(TextEffectFactoryCreatorTest, TextEffectFactoryCreatorTest001, TestSize.Level0) 58 { 59 REGISTER_TEXT_EFFECT_FACTORY_IMPL(Test, TextEffectStrategy::STRATEGY_BUTT); 60 TextEffectFactoryCreator& creator = TextEffectFactoryCreator::GetInstance(); 61 std::shared_ptr<TextEffectFactory> factory = creator.factoryTable_[TextEffectStrategy::STRATEGY_BUTT]; 62 bool result = creator.RegisterFactory(TextEffectStrategy::STRATEGY_BUTT, nullptr); 63 EXPECT_FALSE(result); 64 creator.factoryTable_.erase(TextEffectStrategy::STRATEGY_BUTT); 65 result = creator.RegisterFactory(TextEffectStrategy::STRATEGY_BUTT, factory); 66 EXPECT_TRUE(result); 67 result = creator.RegisterFactory(TextEffectStrategy::STRATEGY_BUTT, factory); 68 EXPECT_FALSE(result); 69 } 70 71 /* 72 * @tc.name: TextEffectFactoryCreatorTest002 73 * @tc.desc: Test for CreateTextEffect action 74 * @tc.type: FUNC 75 */ 76 HWTEST_F(TextEffectFactoryCreatorTest, TextEffectFactoryCreatorTest002, TestSize.Level0) 77 { 78 TextEffectFactoryCreator& creator = TextEffectFactoryCreator::GetInstance(); 79 std::shared_ptr<TextEffect> effect = creator.CreateTextEffect(TextEffectStrategy::STRATEGY_BUTT); 80 EXPECT_EQ(effect, nullptr); 81 REGISTER_TEXT_EFFECT_FACTORY_IMPL(Test, TextEffectStrategy::STRATEGY_BUTT); 82 effect = creator.CreateTextEffect(TextEffectStrategy::STRATEGY_BUTT); 83 EXPECT_NE(effect, nullptr); 84 creator.UnregisterFactory(TextEffectStrategy::STRATEGY_BUTT); 85 effect = creator.CreateTextEffect(TextEffectStrategy::STRATEGY_BUTT); 86 EXPECT_EQ(effect, nullptr); 87 }