• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "gfx_utils/style.h"
17 
18 #include <climits>
19 #include <gtest/gtest.h>
20 
21 using namespace testing::ext;
22 namespace OHOS {
23 class StyleTest : public testing::Test {
24 public:
25     static void SetUpTestCase(void);
26     static void TearDownTestCase(void);
27     static Style* style_;
28 };
29 Style* StyleTest::style_ = nullptr;
30 
SetUpTestCase()31 void StyleTest::SetUpTestCase()
32 {
33     if (style_ == nullptr) {
34         style_ = new Style();
35     }
36 }
37 
TearDownTestCase()38 void StyleTest::TearDownTestCase()
39 {
40     if (style_ != nullptr) {
41         delete style_;
42         style_ = nullptr;
43     }
44 }
45 
46 /**
47  * @tc.name: StyleSetStyle_001
48  * @tc.desc: Verify SetStyle function, equal.
49  * @tc.type: FUNC
50  * @tc.require: AR000EEMQC
51  */
52 HWTEST_F(StyleTest, StyleSetStyle_001, TestSize.Level0)
53 {
54     if (style_ == nullptr) {
55         EXPECT_EQ(1, 0);
56         return;
57     }
58     style_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Gray().full);
59     EXPECT_EQ(style_->GetStyle(STYLE_BACKGROUND_COLOR), Color::Gray().full);
60 }
61 
62 /**
63  * @tc.name: StyleSetStyle_002
64  * @tc.desc: Verify SetStyle function, equal.
65  * @tc.type: FUNC
66  * @tc.require: AR000EEMQC
67  */
68 HWTEST_F(StyleTest, StyleSetStyle_002, TestSize.Level0)
69 {
70     if (style_ == nullptr) {
71         EXPECT_EQ(1, 0);
72         return;
73     }
74     style_->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE);
75     EXPECT_EQ(style_->GetStyle(STYLE_BACKGROUND_OPA), OPA_OPAQUE);
76 }
77 
78 /**
79  * @tc.name: StyleSetStyle_003
80  * @tc.desc: Verify SetStyle function, equal.
81  * @tc.type: FUNC
82  * @tc.require: AR000EEMQC
83  */
84 HWTEST_F(StyleTest, StyleSetStyle_003, TestSize.Level0)
85 {
86     if (style_ == nullptr) {
87         EXPECT_EQ(1, 0);
88         return;
89     }
90     style_->SetStyle(STYLE_BORDER_RADIUS, 0);
91     EXPECT_EQ(style_->GetStyle(STYLE_BORDER_RADIUS), 0);
92 }
93 
94 /**
95  * @tc.name: StyleSetStyle_004
96  * @tc.desc: Verify SetStyle function, equal.
97  * @tc.type: FUNC
98  * @tc.require: AR000EEMQC
99  */
100 HWTEST_F(StyleTest, StyleSetStyle_004, TestSize.Level0)
101 {
102     if (style_ == nullptr) {
103         EXPECT_EQ(1, 0);
104         return;
105     }
106     style_->SetStyle(STYLE_BORDER_COLOR, Color::Gray().full);
107     EXPECT_EQ(style_->GetStyle(STYLE_BORDER_COLOR), Color::Gray().full);
108 }
109 
110 /**
111  * @tc.name: StyleSetStyle_005
112  * @tc.desc: Verify SetStyle function, equal.
113  * @tc.type: FUNC
114  * @tc.require: AR000EEMQC
115  */
116 HWTEST_F(StyleTest, StyleSetStyle_005, TestSize.Level0)
117 {
118     if (style_ == nullptr) {
119         EXPECT_EQ(1, 0);
120         return;
121     }
122     style_->SetStyle(STYLE_BORDER_OPA, OPA_OPAQUE);
123     EXPECT_EQ(style_->GetStyle(STYLE_BORDER_OPA), OPA_OPAQUE);
124 }
125 
126 /**
127  * @tc.name: StyleSetStyle_006
128  * @tc.desc: Verify SetStyle function, equal.
129  * @tc.type: FUNC
130  * @tc.require: AR000EEMQC
131  */
132 HWTEST_F(StyleTest, StyleSetStyle_006, TestSize.Level0)
133 {
134     if (style_ == nullptr) {
135         EXPECT_EQ(1, 0);
136         return;
137     }
138     const int16_t BORDER_WIDTH = 1;
139     style_->SetStyle(STYLE_BORDER_WIDTH, BORDER_WIDTH);
140     EXPECT_EQ(style_->GetStyle(STYLE_BORDER_WIDTH), BORDER_WIDTH);
141 }
142 
143 /**
144  * @tc.name: StyleSetStyle_007
145  * @tc.desc: Verify SetStyle function, equal.
146  * @tc.type: FUNC
147  * @tc.require: AR000EEMQC
148  */
149 HWTEST_F(StyleTest, StyleSetStyle_007, TestSize.Level0)
150 {
151     if (style_ == nullptr) {
152         EXPECT_EQ(1, 0);
153         return;
154     }
155     style_->SetStyle(STYLE_PADDING_LEFT, 0);
156     EXPECT_EQ(style_->GetStyle(STYLE_PADDING_LEFT), 0);
157 }
158 
159 /**
160  * @tc.name: StyleSetStyle_008
161  * @tc.desc: Verify SetStyle function, equal.
162  * @tc.type: FUNC
163  * @tc.require: AR000EEMQC
164  */
165 HWTEST_F(StyleTest, StyleSetStyle_008, TestSize.Level0)
166 {
167     if (style_ == nullptr) {
168         EXPECT_EQ(1, 0);
169         return;
170     }
171     style_->SetStyle(STYLE_PADDING_RIGHT, HORIZONTAL_RESOLUTION);
172     EXPECT_EQ(style_->GetStyle(STYLE_PADDING_RIGHT), HORIZONTAL_RESOLUTION);
173 }
174 
175 /**
176  * @tc.name: StyleSetStyle_009
177  * @tc.desc: Verify SetStyle function, equal.
178  * @tc.type: FUNC
179  * @tc.require: AR000EEMQC
180  */
181 HWTEST_F(StyleTest, StyleSetStyle_009, TestSize.Level0)
182 {
183     if (style_ == nullptr) {
184         EXPECT_EQ(1, 0);
185         return;
186     }
187     style_->SetStyle(STYLE_PADDING_TOP, 0);
188     EXPECT_EQ(style_->GetStyle(STYLE_PADDING_TOP), 0);
189 }
190 
191 /**
192  * @tc.name: StyleSetStyle_010
193  * @tc.desc: Verify SetStyle function, equal.
194  * @tc.type: FUNC
195  * @tc.require: AR000EEMQC
196  */
197 HWTEST_F(StyleTest, StyleSetStyle_010, TestSize.Level0)
198 {
199     if (style_ == nullptr) {
200         EXPECT_EQ(1, 0);
201         return;
202     }
203     style_->SetStyle(STYLE_PADDING_BOTTOM, VERTICAL_RESOLUTION);
204     EXPECT_EQ(style_->GetStyle(STYLE_PADDING_BOTTOM), VERTICAL_RESOLUTION);
205 }
206 
207 /**
208  * @tc.name: StyleSetStyle_011
209  * @tc.desc: Verify SetStyle function, equal.
210  * @tc.type: FUNC
211  * @tc.require: AR000EEMQC
212  */
213 HWTEST_F(StyleTest, StyleSetStyle_011, TestSize.Level0)
214 {
215     if (style_ == nullptr) {
216         EXPECT_EQ(1, 0);
217         return;
218     }
219     style_->SetStyle(STYLE_MARGIN_LEFT, 0);
220     EXPECT_EQ(style_->GetStyle(STYLE_MARGIN_LEFT), 0);
221 }
222 
223 /**
224  * @tc.name: StyleSetStyle_012
225  * @tc.desc: Verify SetStyle function, equal.
226  * @tc.type: FUNC
227  * @tc.require: AR000EEMQC
228  */
229 HWTEST_F(StyleTest, StyleSetStyle_012, TestSize.Level0)
230 {
231     if (style_ == nullptr) {
232         EXPECT_EQ(1, 0);
233         return;
234     }
235     style_->SetStyle(STYLE_MARGIN_RIGHT, HORIZONTAL_RESOLUTION);
236     EXPECT_EQ(style_->GetStyle(STYLE_MARGIN_RIGHT), HORIZONTAL_RESOLUTION);
237 }
238 
239 /**
240  * @tc.name: StyleSetStyle_013
241  * @tc.desc: Verify SetStyle function, equal.
242  * @tc.type: FUNC
243  * @tc.require: AR000EEMQC
244  */
245 HWTEST_F(StyleTest, StyleSetStyle_013, TestSize.Level0)
246 {
247     if (style_ == nullptr) {
248         EXPECT_EQ(1, 0);
249         return;
250     }
251     style_->SetStyle(STYLE_MARGIN_TOP, 0);
252     EXPECT_EQ(style_->GetStyle(STYLE_MARGIN_TOP), 0);
253 }
254 
255 /**
256  * @tc.name: StyleSetStyle_014
257  * @tc.desc: Verify SetStyle function, equal.
258  * @tc.type: FUNC
259  * @tc.require: AR000EEMQC
260  */
261 HWTEST_F(StyleTest, StyleSetStyle_014, TestSize.Level0)
262 {
263     if (style_ == nullptr) {
264         EXPECT_EQ(1, 0);
265         return;
266     }
267     style_->SetStyle(STYLE_MARGIN_BOTTOM, VERTICAL_RESOLUTION);
268     EXPECT_EQ(style_->GetStyle(STYLE_MARGIN_BOTTOM), VERTICAL_RESOLUTION);
269 }
270 
271 /**
272  * @tc.name: StyleSetStyle_015
273  * @tc.desc: Verify SetStyle function, equal.
274  * @tc.type: FUNC
275  * @tc.require: AR000EEMQC
276  */
277 HWTEST_F(StyleTest, StyleSetStyle_015, TestSize.Level0)
278 {
279     if (style_ == nullptr) {
280         EXPECT_EQ(1, 0);
281         return;
282     }
283     style_->SetStyle(STYLE_IMAGE_OPA, OPA_OPAQUE);
284     EXPECT_EQ(style_->GetStyle(STYLE_IMAGE_OPA), OPA_OPAQUE);
285 }
286 
287 /**
288  * @tc.name: StyleSetStyle_015
289  * @tc.desc: Verify SetStyle function, equal.
290  * @tc.type: FUNC
291  * @tc.require: AR000EEMQC
292  */
293 HWTEST_F(StyleTest, StyleSetStyle_016, TestSize.Level0)
294 {
295     if (style_ == nullptr) {
296         EXPECT_EQ(1, 0);
297         return;
298     }
299     style_->SetStyle(STYLE_TEXT_COLOR, Color::Gray().full);
300     EXPECT_EQ(style_->GetStyle(STYLE_TEXT_COLOR), Color::Gray().full);
301 }
302 
303 /**
304  * @tc.name: StyleSetStyle_016
305  * @tc.desc: Verify SetStyle function, equal.
306  * @tc.type: FUNC
307  * @tc.require: AR000EEMQC
308  */
309 HWTEST_F(StyleTest, StyleSetStyle_017, TestSize.Level0)
310 {
311     if (style_ == nullptr) {
312         EXPECT_EQ(1, 0);
313         return;
314     }
315     style_->SetStyle(STYLE_TEXT_FONT, 0);
316     EXPECT_EQ(style_->GetStyle(STYLE_TEXT_FONT), 0);
317 }
318 
319 /**
320  * @tc.name: StyleSetStyle_017
321  * @tc.desc: Verify SetStyle function, equal.
322  * @tc.type: FUNC
323  * @tc.require: AR000EEMQC
324  */
325 HWTEST_F(StyleTest, StyleSetStyle_018, TestSize.Level0)
326 {
327     if (style_ == nullptr) {
328         EXPECT_EQ(1, 0);
329         return;
330     }
331     const int16_t letterSpace = 4;
332     style_->SetStyle(STYLE_LETTER_SPACE, letterSpace);
333     EXPECT_EQ(style_->GetStyle(STYLE_LETTER_SPACE), letterSpace);
334 }
335 
336 
337 /**
338  * @tc.name: StyleSetStyle_018
339  * @tc.desc: Verify SetStyle function, equal.
340  * @tc.type: FUNC
341  * @tc.require: SR000FQNF0
342  */
343 HWTEST_F(StyleTest, StyleSetStyle_019, TestSize.Level0)
344 {
345     if (style_ == nullptr) {
346         EXPECT_EQ(1, 0);
347         return;
348     }
349     const int16_t lineHeight = 10;
350     style_->SetStyle(STYLE_LINE_HEIGHT, lineHeight);
351     EXPECT_EQ(style_->GetStyle(STYLE_LINE_HEIGHT), lineHeight);
352 }
353 
354 /**
355  * @tc.name: StyleSetStyle_019
356  * @tc.desc: Verify SetStyle function, equal.
357  * @tc.type: FUNC
358  * @tc.require: AR000EEMQC
359  */
360 HWTEST_F(StyleTest, StyleSetStyle_020, TestSize.Level0)
361 {
362     if (style_ == nullptr) {
363         EXPECT_EQ(1, 0);
364         return;
365     }
366     style_->SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE);
367     EXPECT_EQ(style_->GetStyle(STYLE_TEXT_OPA), OPA_OPAQUE);
368 }
369 
370 /**
371  * @tc.name: StyleSetStyle_020
372  * @tc.desc: Verify SetStyle function, equal.
373  * @tc.type: FUNC
374  * @tc.require: AR000EEMQC
375  */
376 HWTEST_F(StyleTest, StyleSetStyle_021, TestSize.Level0)
377 {
378     if (style_ == nullptr) {
379         EXPECT_EQ(1, 0);
380         return;
381     }
382     style_->SetStyle(STYLE_LINE_COLOR, Color::Gray().full);
383     EXPECT_EQ(style_->GetStyle(STYLE_LINE_COLOR), Color::Gray().full);
384 }
385 
386 /**
387  * @tc.name: StyleSetStyle_021
388  * @tc.desc: Verify SetStyle function, equal.
389  * @tc.type: FUNC
390  * @tc.require: AR000EEMQC
391  */
392 HWTEST_F(StyleTest, StyleSetStyle_022, TestSize.Level0)
393 {
394     if (style_ == nullptr) {
395         EXPECT_EQ(1, 0);
396         return;
397     }
398     const int16_t lineWidth = 1;
399     style_->SetStyle(STYLE_LINE_WIDTH, lineWidth);
400     EXPECT_EQ(style_->GetStyle(STYLE_LINE_WIDTH), lineWidth);
401 }
402 
403 /**
404  * @tc.name: StyleSetStyle_022
405  * @tc.desc: Verify SetStyle function, equal.
406  * @tc.type: FUNC
407  * @tc.require: AR000EEMQC
408  */
409 HWTEST_F(StyleTest, StyleSetStyle_023, TestSize.Level0)
410 {
411     if (style_ == nullptr) {
412         EXPECT_EQ(1, 0);
413         return;
414     }
415     style_->SetStyle(STYLE_LINE_OPA, OPA_OPAQUE);
416     EXPECT_EQ(style_->GetStyle(STYLE_LINE_OPA), OPA_OPAQUE);
417 }
418 
419 /**
420  * @tc.name: StyleSetStyle_023
421  * @tc.desc: Verify SetStyle function, equal.
422  * @tc.type: FUNC
423  * @tc.require: AR000EEMQC
424  */
425 HWTEST_F(StyleTest, StyleSetStyle_024, TestSize.Level0)
426 {
427     if (style_ == nullptr) {
428         EXPECT_EQ(1, 0);
429         return;
430     }
431     style_->SetStyle(STYLE_LINE_CAP, CapType::CAP_ROUND);
432     EXPECT_EQ(style_->GetStyle(STYLE_LINE_CAP), CapType::CAP_ROUND);
433 }
434 } // namespace OHOS