1 /*
2 * Copyright (c) 2020-2021 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/text.h"
17
18 #include <climits>
19 #include <gtest/gtest.h>
20
21 using namespace testing::ext;
22 namespace OHOS {
23 class TextTest : public testing::Test {
24 public:
25 static void SetUpTestCase(void);
26 static void TearDownTestCase(void);
27 static Text* text_;
28 };
29
30 Text* TextTest::text_ = nullptr;
31
SetUpTestCase(void)32 void TextTest::SetUpTestCase(void)
33 {
34 if (text_ == nullptr) {
35 text_ = new Text();
36 }
37 }
38
TearDownTestCase(void)39 void TextTest::TearDownTestCase(void)
40 {
41 if (text_ != nullptr) {
42 delete text_;
43 text_ = nullptr;
44 }
45 }
46
47 /**
48 * @tc.name: TextSetText_001
49 * @tc.desc: Verify SetText function, equal.
50 * @tc.type: FUNC
51 * @tc.require: AR000DSMQ1
52 */
53 HWTEST_F(TextTest, TextSetText_001, TestSize.Level0)
54 {
55 if (text_ == nullptr) {
56 EXPECT_NE(0, 0);
57 return;
58 }
59 const char* text = "unit test text";
60 text_->SetText(text);
61 EXPECT_EQ(strcmp(text_->GetText(), text), 0);
62 }
63
64 /**
65 * @tc.name: TextSetDirect_001
66 * @tc.desc: Verify SetDirect function, equal.
67 * @tc.type: FUNC
68 * @tc.require: AR000DSMQ1
69 */
70 HWTEST_F(TextTest, TextSetDirect_001, TestSize.Level0)
71 {
72 if (text_ == nullptr) {
73 EXPECT_NE(0, 0);
74 return;
75 }
76 UITextLanguageDirect direct = UITextLanguageDirect::TEXT_DIRECT_LTR;
77 text_->SetDirect(direct);
78 EXPECT_EQ(text_->GetDirect(), direct);
79 direct = UITextLanguageDirect::TEXT_DIRECT_RTL;
80 text_->SetDirect(direct);
81 EXPECT_EQ(text_->GetDirect(), direct);
82 }
83
84 /**
85 * @tc.name: TextSetAlign_001
86 * @tc.desc: Verify SetAlign function, equal.
87 * @tc.type: FUNC
88 * @tc.require: AR000DSMQ1
89 */
90 HWTEST_F(TextTest, TextSetAlign_001, TestSize.Level1)
91 {
92 if (text_ == nullptr) {
93 EXPECT_NE(0, 0);
94 return;
95 }
96 text_->SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_TOP);
97 EXPECT_EQ(text_->IsNeedRefresh(), true);
98 EXPECT_EQ(text_->GetHorAlign(), TEXT_ALIGNMENT_LEFT);
99 EXPECT_EQ(text_->GetVerAlign(), TEXT_ALIGNMENT_TOP);
100 }
101
102 /**
103 * @tc.name: TextSetExpand_001
104 * @tc.desc: Verify SetExpand function, equal.
105 * @tc.type: FUNC
106 * @tc.require: AR000DSMQ1
107 */
108 HWTEST_F(TextTest, TextSetExpand_001, TestSize.Level1)
109 {
110 if (text_ == nullptr) {
111 EXPECT_NE(0, 0);
112 return;
113 }
114 EXPECT_EQ(text_->IsExpandWidth(), false);
115 text_->SetExpandWidth(true);
116 EXPECT_EQ(text_->IsExpandWidth(), true);
117
118 EXPECT_EQ(text_->IsExpandHeight(), false);
119 text_->SetExpandHeight(true);
120 EXPECT_EQ(text_->IsExpandHeight(), true);
121 }
122 } // namespace OHOS