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 "components/ui_arc_label.h"
17 
18 #include <climits>
19 #include <gtest/gtest.h>
20 
21 using namespace testing::ext;
22 
23 namespace OHOS {
24 class UIArcLabelTest : public testing::Test {
25 public:
26     static void SetUpTestCase(void);
27     static void TearDownTestCase(void);
28     static UIArcLabel* arcLabel_;
29 };
30 UIArcLabel* UIArcLabelTest::arcLabel_ = nullptr;
31 
SetUpTestCase(void)32 void UIArcLabelTest::SetUpTestCase(void)
33 {
34     if (arcLabel_ == nullptr) {
35         arcLabel_ = new UIArcLabel();
36     }
37 }
38 
TearDownTestCase(void)39 void UIArcLabelTest::TearDownTestCase(void)
40 {
41     if (arcLabel_ != nullptr) {
42         delete arcLabel_;
43         arcLabel_ = nullptr;
44     }
45 }
46 /**
47  * @tc.name: UIArcLabelGetViewType_001
48  * @tc.desc: Verify GetViewType function, equal.
49  * @tc.type: FUNC
50  * @tc.require: AR000DSMPM
51  */
52 HWTEST_F(UIArcLabelTest, UIArcLabelGetViewType_001, TestSize.Level1)
53 {
54     if (arcLabel_ == nullptr) {
55         EXPECT_EQ(1, 0);
56         return;
57     }
58     EXPECT_EQ(arcLabel_->GetViewType(), UI_ARC_LABEL);
59 }
60 
61 /**
62  * @tc.name: UIArcLabelGetWidth_001
63  * @tc.desc: Verify GetWidth function, equal.
64  * @tc.type: FUNC
65  * @tc.require: AR000DSMPM
66  */
67 HWTEST_F(UIArcLabelTest, UIArcLabelGetWidth_001, TestSize.Level1)
68 {
69     if (arcLabel_ == nullptr) {
70         EXPECT_EQ(1, 0);
71         return;
72     }
73     const int16_t width = 100;
74     arcLabel_->SetWidth(width);
75     EXPECT_EQ(arcLabel_->GetWidth(), width);
76 }
77 
78 /**
79  * @tc.name: UIArcLabelGetHeight_001
80  * @tc.desc: Verify GetHeight function, equal.
81  * @tc.type: FUNC
82  * @tc.require: AR000DSMPM
83  */
84 HWTEST_F(UIArcLabelTest, UIArcLabelGetHeight_001, TestSize.Level1)
85 {
86     if (arcLabel_ == nullptr) {
87         EXPECT_EQ(1, 0);
88         return;
89     }
90     const int16_t height = 100;
91     arcLabel_->SetHeight(height);
92     EXPECT_EQ(arcLabel_->GetHeight(), height);
93 }
94 
95 /**
96  * @tc.name: UIArcLabelSetText_001
97  * @tc.desc: Verify SetText function, equal.
98  * @tc.type: FUNC
99  * @tc.require: AR000DSMPM
100  */
101 HWTEST_F(UIArcLabelTest, UIArcLabelSetText_001, TestSize.Level1)
102 {
103     if (arcLabel_ == nullptr) {
104         EXPECT_EQ(1, 0);
105         return;
106     }
107     const char* text = "abc";
108     arcLabel_->SetText(text);
109     EXPECT_EQ(strcmp(arcLabel_->GetText(), text), 0);
110 }
111 
112 /**
113  * @tc.name: UIArcLabelSetAlign_001
114  * @tc.desc: Verify SetAlign function, equal.
115  * @tc.type: FUNC
116  * @tc.require: AR000DSMPM
117  */
118 HWTEST_F(UIArcLabelTest, UIArcLabelSetAlign_001, TestSize.Level1)
119 {
120     if (arcLabel_ == nullptr) {
121         EXPECT_EQ(1, 0);
122         return;
123     }
124     UITextLanguageAlignment horizontalAlign = TEXT_ALIGNMENT_LEFT;
125     arcLabel_->SetAlign(horizontalAlign);
126     EXPECT_EQ(arcLabel_->GetHorAlign(), horizontalAlign);
127 }
128 
129 /**
130  * @tc.name: UIArcLabelSetArcTextCenter_001
131  * @tc.desc: Verify SetArcTextCenter function, equal.
132  * @tc.type: FUNC
133  * @tc.require: AR000DSMPM
134  */
135 HWTEST_F(UIArcLabelTest, UIArcLabelSetArcTextCenter_001, TestSize.Level1)
136 {
137     if (arcLabel_ == nullptr) {
138         EXPECT_EQ(1, 0);
139         return;
140     }
141     const int16_t posX = 10;
142     const int16_t posY = 20;
143     arcLabel_->SetArcTextCenter(posX, posY);
144     EXPECT_EQ(arcLabel_->GetArcTextCenter().x, posX);
145     EXPECT_EQ(arcLabel_->GetArcTextCenter().y, posY);
146 }
147 
148 /**
149  * @tc.name: UIArcLabelSetArcTextRadius_001
150  * @tc.desc: Verify SetArcTextRadius function, equal.
151  * @tc.type: FUNC
152  * @tc.require: AR000DSMPM
153  */
154 HWTEST_F(UIArcLabelTest, UIArcLabelSetArcTextRadius_001, TestSize.Level1)
155 {
156     if (arcLabel_ == nullptr) {
157         EXPECT_EQ(1, 0);
158         return;
159     }
160     const int16_t radius = 1;
161     arcLabel_->SetArcTextRadius(radius);
162     EXPECT_EQ(arcLabel_->GetArcTextRadius(), radius);
163 }
164 
165 /**
166  * @tc.name: UIArcLabelSetArcTextAngle_001
167  * @tc.desc: Verify SetArcTextAngle function, equal.
168  * @tc.type: FUNC
169  * @tc.require: AR000DSMPM
170  */
171 HWTEST_F(UIArcLabelTest, UIArcLabelSetArcTextAngle_001, TestSize.Level0)
172 {
173     if (arcLabel_ == nullptr) {
174         EXPECT_EQ(1, 0);
175         return;
176     }
177     const int16_t endAngle = 10;
178     arcLabel_->SetArcTextAngle(0, endAngle);
179     EXPECT_EQ(arcLabel_->GetArcTextStartAngle(), 0);
180     EXPECT_EQ(arcLabel_->GetArcTextEndAngle(), endAngle);
181 }
182 
183 /**
184  * @tc.name: UIArcLabelSetArcTextOrientation_001
185  * @tc.desc: Verify SetArcTextOrientation function, equal.
186  * @tc.type: FUNC
187  * @tc.require: AR000DSMPM
188  */
189 HWTEST_F(UIArcLabelTest, UIArcLabelSetArcTextOrientation_001, TestSize.Level1)
190 {
191     if (arcLabel_ == nullptr) {
192         EXPECT_EQ(1, 0);
193         return;
194     }
195     arcLabel_->SetArcTextOrientation(TextOrientation::INSIDE);
196     EXPECT_EQ(arcLabel_->GetArcTextOrientation(),
197         TextOrientation::INSIDE);
198     arcLabel_->SetArcTextOrientation(TextOrientation::OUTSIDE);
199     EXPECT_EQ(arcLabel_->GetArcTextOrientation(),
200         TextOrientation::OUTSIDE);
201 }
202 
203 /**
204  * @tc.name: UIArcLabelGetDirect_001
205  * @tc.desc: Verify GetDirect function, equal.
206  * @tc.type: FUNC
207  * @tc.require: AR000DSMPM
208  */
209 HWTEST_F(UIArcLabelTest, UIArcLabelGetDirect_001, TestSize.Level1)
210 {
211     if (arcLabel_ == nullptr) {
212         EXPECT_EQ(1, 0);
213         return;
214     }
215     EXPECT_EQ(arcLabel_->GetDirect(), UITextLanguageDirect(0));
216 }
217 
218 /**
219  * @tc.name: UIArcLabelSetFontId_001
220  * @tc.desc: Verify SetFontId function, equal.
221  */
222 HWTEST_F(UIArcLabelTest, UIArcLabelSetFontId_001, TestSize.Level1)
223 {
224     if (arcLabel_ == nullptr) {
225         EXPECT_EQ(1, 0);
226         return;
227     }
228     uint16_t fontId = 0;
229     arcLabel_->SetFontId(fontId);
230     EXPECT_EQ(arcLabel_->GetFontId(), fontId);
231 }
232 }
233