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 "common/rs_rect.h" 17 #include "gtest/gtest.h" 18 #include "font_collection.h" 19 #include "text_style.h" 20 #include "typography_style.h" 21 #include "typography_types.h" 22 23 using namespace testing; 24 using namespace testing::ext; 25 26 namespace OHOS { 27 namespace Rosen { 28 class OHSkiaTxtTest : public testing::Test {}; 29 30 /* 31 * @tc.name: OHSkiaTxtTest001 32 * @tc.desc: test for text 33 * @tc.type: FUNC 34 */ 35 HWTEST_F(OHSkiaTxtTest, OHSkiaTxtTest001, TestSize.Level0) 36 { 37 RectT<int> rectTest; 38 // 1 is used for initialization 39 Vector4<int> vecTest(1); 40 rectTest = rectTest.MakeOutset(vecTest); 41 EXPECT_EQ(rectTest.left_, -1); 42 EXPECT_EQ(rectTest.top_, -1); 43 EXPECT_EQ(rectTest.width_, 2); 44 EXPECT_EQ(rectTest.height_, 2); 45 46 // 0 is used for initialization 47 RectStyle rectStyle1 = {0, 0, 0, 0, 0}; 48 // 1 is used for initialization 49 RectStyle rectStyle2 = {1, 1, 1, 1, 1}; 50 EXPECT_EQ(rectStyle1 != rectStyle2, true); 51 52 Drawing::Color color = Drawing::Color::COLOR_WHITE; 53 // 0 is used for initialization 54 Drawing::Point offset{0, 0}; 55 // 0 is used for initialization 56 TextShadow TextShadow1(color, offset, 0); 57 // 1 is used for initialization 58 TextShadow TextShadow2(color, offset, 1); 59 EXPECT_EQ(TextShadow1 == TextShadow2, false); 60 EXPECT_EQ(TextShadow1 != TextShadow2, true); 61 EXPECT_EQ(TextShadow1.HasShadow(), false); 62 } 63 64 /* 65 * @tc.name: OHSkiaTxtTest002 66 * @tc.desc: test for text 67 * @tc.type: FUNC 68 */ 69 HWTEST_F(OHSkiaTxtTest, OHSkiaTxtTest002, TestSize.Level0) 70 { 71 TextStyle textStyle1; 72 TextStyle textStyle2; 73 textStyle2.isPlaceholder = true; 74 EXPECT_EQ(textStyle1.EqualByFonts(textStyle2), false); 75 EXPECT_EQ(textStyle1.MatchOneAttribute(ALL_ATTRIBUTES, textStyle2), true); 76 bool res1; 77 res1 = textStyle1.MatchOneAttribute(FOREGROUND, textStyle2); 78 res1 = textStyle1.MatchOneAttribute(BACKGROUND, textStyle2); 79 res1 = textStyle1.MatchOneAttribute(SHADOW, textStyle2); 80 res1 = textStyle1.MatchOneAttribute(DECORATIONS, textStyle2); 81 res1 = textStyle1.MatchOneAttribute(LETTER_SPACING, textStyle2); 82 res1 = textStyle1.MatchOneAttribute(WORD_SPACING, textStyle2); 83 res1 = textStyle1.MatchOneAttribute(FONT, textStyle2); 84 bool res2 = textStyle2.MatchOneAttribute(FONT, textStyle1); 85 EXPECT_EQ(res1, res2); 86 87 FontFeatures fontFeatures; 88 std::string str1 = fontFeatures.GetFeatureSettings(); 89 // 1 is used for test 90 fontFeatures.SetFeature("123", 1); 91 str1 = fontFeatures.GetFeatureSettings(); 92 FontVariations fontVariations1; 93 std::string str2 = "123"; 94 // 1 is used for initialization 95 float value = 1; 96 fontVariations1.SetAxisValue(str2, value); 97 FontVariations fontVariations2; 98 EXPECT_EQ(fontVariations1 == fontVariations2, false); 99 fontVariations1.Clear(); 100 101 auto fontCollection = FontCollection::From(nullptr); 102 TypographyStyle typographyStyle1; 103 TypographyStyle typographyStyle2; 104 // 15 is used for initialization 105 typographyStyle2.fontSize = 15; 106 EXPECT_EQ(typographyStyle1 == typographyStyle2, false); 107 EXPECT_EQ(typographyStyle1.IsUnlimitedLines(), true); 108 EXPECT_NE(typographyStyle1.IsEllipsized(), typographyStyle1.ellipsis.empty()); 109 typographyStyle2.textAlign = TextAlign::END; 110 EXPECT_EQ(typographyStyle2.GetEffectiveAlign(), TextAlign::RIGHT); 111 112 // 1 is used for initialization 113 Boundary boundary1(1, 1); 114 // 1 is used for initialization 115 Boundary boundary2(1, 1); 116 EXPECT_EQ(boundary1 == boundary2, true); 117 } 118 } // namespace Rosen 119 } // namespace OHOS 120