• 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 "paragraph_style.h"
18 #include "text_style.h"
19 
20 using namespace testing;
21 using namespace testing::ext;
22 
23 namespace txt {
24 class ParagraphStyleTest : public testing::Test {};
25 
26 /*
27  * @tc.name: ParagraphStyleTest001
28  * @tc.desc: test for ConvertToTextStyle
29  * @tc.type: FUNC
30  */
31 HWTEST_F(ParagraphStyleTest, ParagraphStyleTest001, TestSize.Level0)
32 {
33     auto paragraphStyle = std::make_shared<OHOS::Rosen::SPText::ParagraphStyle>();
34     auto result = paragraphStyle->ConvertToTextStyle();
35     EXPECT_EQ(result.fontSize, paragraphStyle->fontSize);
36 }
37 
38 /*
39  * @tc.name: ParagraphStyleTest002
40  * @tc.desc: test for GetEquivalentAlign
41  * @tc.type: FUNC
42  */
43 HWTEST_F(ParagraphStyleTest, ParagraphStyleTest002, TestSize.Level0)
44 {
45     auto paragraphStyle = std::make_shared<OHOS::Rosen::SPText::ParagraphStyle>();
46     // 默认 TextDirection 为 LTR
47     paragraphStyle->textAlign = OHOS::Rosen::SPText::TextAlign::START;
48     auto result1 = paragraphStyle->GetEquivalentAlign();
49     EXPECT_EQ(result1, OHOS::Rosen::SPText::TextAlign::LEFT);
50 
51     paragraphStyle->textAlign = OHOS::Rosen::SPText::TextAlign::END;
52     auto result2 = paragraphStyle->GetEquivalentAlign();
53     EXPECT_EQ(result2, OHOS::Rosen::SPText::TextAlign::RIGHT);
54 
55     paragraphStyle->textAlign = OHOS::Rosen::SPText::TextAlign::JUSTIFY;
56     auto result3 = paragraphStyle->GetEquivalentAlign();
57     EXPECT_EQ(result3, OHOS::Rosen::SPText::TextAlign::JUSTIFY);
58 
59     // 此处更改 TextDirection 为 RTL
60     paragraphStyle->textDirection = OHOS::Rosen::SPText::TextDirection::RTL;
61     paragraphStyle->textAlign = OHOS::Rosen::SPText::TextAlign::START;
62     auto result4 = paragraphStyle->GetEquivalentAlign();
63     EXPECT_EQ(result4, OHOS::Rosen::SPText::TextAlign::RIGHT);
64 
65     paragraphStyle->textAlign = OHOS::Rosen::SPText::TextAlign::END;
66     auto result5 = paragraphStyle->GetEquivalentAlign();
67     EXPECT_EQ(result5, OHOS::Rosen::SPText::TextAlign::LEFT);
68 
69     paragraphStyle->textAlign = OHOS::Rosen::SPText::TextAlign::JUSTIFY;
70     auto result6 = paragraphStyle->GetEquivalentAlign();
71     EXPECT_EQ(result6, OHOS::Rosen::SPText::TextAlign::JUSTIFY);
72 }
73 
74 } // namespace txt