• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 #include "text_style.h"
18 
19 using namespace testing;
20 using namespace testing::ext;
21 using namespace OHOS::Rosen::SPText;
22 
23 namespace txt {
24 class TextStyleTest : public testing::Test {
25 public:
26     void SetUp() override;
27     void TearDown() override;
28 
29 private:
30     std::shared_ptr<TextStyle> textStyle_;
31 };
32 
SetUp()33 void TextStyleTest::SetUp()
34 {
35     textStyle_ = std::make_shared<TextStyle>();
36     ASSERT_NE(textStyle_, nullptr);
37 }
38 
TearDown()39 void TextStyleTest::TearDown() {}
40 
41 /*
42  * @tc.name: TextStyleTest001
43  * @tc.desc: test for Equal
44  * @tc.type: FUNC
45  */
46 HWTEST_F(TextStyleTest, TextStyleTest001, TestSize.Level0)
47 {
48     TextStyle textStyleCompare;
49     EXPECT_EQ((*textStyle_), textStyleCompare);
50 }
51 
52 /*
53  * @tc.name: TextStyleTest002
54  * @tc.desc: test for change fontFeatures
55  * @tc.type: FUNC
56  */
57 HWTEST_F(TextStyleTest, TextStyleTest002, TestSize.Level0)
58 {
59     FontFeatures fontFeatures;
60     fontFeatures.SetFeature("tag", 0);
61     textStyle_->fontFeatures = fontFeatures;
62     ASSERT_EQ(textStyle_->fontFeatures.GetFontFeatures().size(), 1);
63     EXPECT_EQ(textStyle_->fontFeatures.GetFontFeatures().at(0).first, fontFeatures.GetFontFeatures().at(0).first);
64     EXPECT_EQ(textStyle_->fontFeatures.GetFontFeatures().at(0).second, fontFeatures.GetFontFeatures().at(0).second);
65     EXPECT_EQ(textStyle_->fontFeatures.GetFeatureSettings(), "tag=0");
66 }
67 
68 /*
69  * @tc.name: TextStyleTest003
70  * @tc.desc: test for change fontVariations
71  * @tc.type: FUNC
72  */
73 HWTEST_F(TextStyleTest, TextStyleTest003, TestSize.Level0)
74 {
75     FontVariations fontVariations;
76     fontVariations.SetAxisValue("tag", 0.0);
77     textStyle_->fontVariations = fontVariations;
78     ASSERT_EQ(textStyle_->fontVariations.GetAxisValues().size(), 1);
79     EXPECT_EQ(textStyle_->fontVariations.GetAxisValues().at("tag"), fontVariations.GetAxisValues().at("tag"));
80 }
81 
82 /*
83  * @tc.name: TextStyleTest004
84  * @tc.desc: test for change textShadows
85  * @tc.type: FUNC
86  */
87 HWTEST_F(TextStyleTest, TextStyleTest004, TestSize.Level0)
88 {
89     TextShadow textShadowDefault;
90     SkColor color = 255; // 255 just fot test
91     SkPoint offset { 0, 0 };
92     TextShadow textShadow(color, offset, 0.0);
93     EXPECT_NE(textShadowDefault, textShadow);
94     EXPECT_FALSE(textShadow.HasShadow());
95 
96     std::vector<TextShadow> textShadows;
97     textShadows.emplace_back(textShadowDefault);
98     textShadows.emplace_back(textShadow);
99     textStyle_->textShadows = textShadows;
100     EXPECT_EQ(textStyle_->textShadows.size(), 2);
101 }
102 
103 /*
104  * @tc.name: TextStyleTest005
105  * @tc.desc: test for change backgroundRect
106  * @tc.type: FUNC
107  */
108 HWTEST_F(TextStyleTest, TextStyleTest005, TestSize.Level0)
109 {
110     RectStyle backgroundRect = { 0, 1.0f, 0.0f, 0.0f, 0.0f };
111     EXPECT_NE(textStyle_->backgroundRect, backgroundRect);
112     textStyle_->backgroundRect = backgroundRect;
113     EXPECT_EQ(textStyle_->backgroundRect, backgroundRect);
114 }
115 
116 /*
117  * @tc.name: TextStyleTest006
118  * @tc.desc: test font features' GetFeatureSettings
119  * @tc.type: FUNC
120  */
121 HWTEST_F(TextStyleTest, TextStyleTest006, TestSize.Level0)
122 {
123     FontFeatures fontFeatures;
124     EXPECT_TRUE(fontFeatures.GetFeatureSettings().empty());
125     fontFeatures.SetFeature("a", 0);
126     fontFeatures.SetFeature("b", 1);
127     EXPECT_EQ(fontFeatures.GetFeatureSettings(), "a=0,b=1");
128 }
129 
130 /*
131  * @tc.name: TextStyleTest007
132  * @tc.desc: text shadow equal test
133  * @tc.type: FUNC
134  */
135 HWTEST_F(TextStyleTest, TextStyleTest007, TestSize.Level0)
136 {
137     TextShadow shadowA;
138     TextShadow shadowB;
139     EXPECT_EQ(shadowA, shadowB);
140     // 0.2 is just for test
141     shadowB.blurSigma = 0.2;
142     EXPECT_NE(shadowA, shadowB);
143 }
144 } // namespace txt