• 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 "components/ui_view_group.h"
17 
18 #include <climits>
19 #include <gtest/gtest.h>
20 
21 using namespace testing::ext;
22 namespace OHOS {
23 namespace {
24     const int16_t POS_X = 10;
25     const int16_t POS_Y = 20;
26     const int16_t DEFAULE_WIDTH = 100;
27     const int16_t DEFAULE_HEIGHT = 100;
28     const int16_t BUTTON_WIDTH = 20;
29     const int16_t BUTTON_HEIGHT = 20;
30     const int16_t MARGIN_LEFT = 50;
31     const int16_t MARGIN_TOP = 30;
32     const int16_t PADDING_LEFT = 10;
33     const int16_t PADDING_TOP = 20;
34     const int16_t PADDING_RIGHT = 30;
35     const int16_t PADDING_BOTTOM = 40;
36     const int16_t BORDER_WIDTH = 10;
37     const float POS_X_PERCENT = 0.1;
38     const float POS_Y_PERCENT = 0.2;
39     const float DEFAULT_WIDTH_PERCENT = 0.3;
40     const float DEFAULT_HEIGHT_PERCENT = 0.4;
41     const float INVAILD_PERCENT_ZERO = 0.0f;
42     const float INVAILD_PERCENT_ONE = 1.0f;
43     const int16_t DEFAULE_ANGLE = 45;
44     const Vector2<float> VIEW_CENTER = {50, 50};
45     const Vector2<float> SCALE_VALUE = {0.5f, 0.5f};
46     const Vector2<int16_t> POLYGON1 = {0, 0};
47     const Vector2<int16_t> POLYGON2 = {70, 70};
48     const Vector2<int16_t> POLYGON3 = {0, 140};
49     const Vector2<int16_t> POLYGON4 = {-70, 70};
50 }
51 
52 class UIViewTest : public testing::Test {
53 public:
UIViewTest()54     UIViewTest() : view_(nullptr) {}
~UIViewTest()55     virtual ~UIViewTest() {}
SetUpTestCase()56     static void SetUpTestCase() {}
TearDownTestCase()57     static void TearDownTestCase() {}
58     void SetUp();
59     void TearDown();
60     UIView* view_;
61 };
62 
SetUp()63 void UIViewTest::SetUp()
64 {
65     if (view_ == nullptr) {
66         view_ = new UIView();
67     }
68 }
69 
TearDown()70 void UIViewTest::TearDown()
71 {
72     if (view_ != nullptr) {
73         delete view_;
74         view_ = nullptr;
75     }
76 }
77 
78 /**
79  * @tc.name: UIViewSetOnDragListener_001
80  * @tc.desc: Verify SetOnDragListener function, equal.
81  * @tc.type: FUNC
82  * @tc.require: AR000EEMQF
83  */
84 HWTEST_F(UIViewTest, UIViewSetOnDragListener_001, TestSize.Level1)
85 {
86     if (view_ == nullptr) {
87         EXPECT_NE(0, 0);
88         return;
89     }
90     UIView::OnDragListener* listener = new UIView::OnDragListener();
91     view_->SetOnDragListener(listener);
92     EXPECT_EQ(view_->GetOnDragListener(), listener);
93     delete listener;
94 }
95 
96 /**
97  * @tc.name: UIViewSetOnClickListener_001
98  * @tc.desc: Verify SetOnClickListener function, equal.
99  * @tc.type: FUNC
100  * @tc.require: AR000EEMQF
101  */
102 HWTEST_F(UIViewTest, UIViewSetOnClickListener_001, TestSize.Level1)
103 {
104     if (view_ == nullptr) {
105         EXPECT_NE(0, 0);
106         return;
107     }
108     UIView::OnClickListener* listener = new UIView::OnClickListener();
109     view_->SetOnClickListener(listener);
110     EXPECT_EQ(view_->GetOnClickListener(), listener);
111     delete listener;
112 }
113 
114 /**
115  * @tc.name: UIViewSetOnLongPressListener_001
116  * @tc.desc: Verify SetOnLongPressListener function, equal.
117  * @tc.type: FUNC
118  * @tc.require: AR000EEMQF
119  */
120 HWTEST_F(UIViewTest, UIViewSetOnLongPressListener_001, TestSize.Level1)
121 {
122     if (view_ == nullptr) {
123         EXPECT_NE(0, 0);
124         return;
125     }
126     UIView::OnLongPressListener* listener = new UIView::OnLongPressListener();
127     view_->SetOnLongPressListener(listener);
128     EXPECT_EQ(view_->GetOnLongPressListener(), listener);
129     delete listener;
130 }
131 
132 /**
133  * @tc.name: UIViewSetOnTouchListener_001
134  * @tc.desc: Verify SetOnTouchListener function, equal.
135  * @tc.type: FUNC
136  * @tc.require: AR000EEMQF
137  */
138 HWTEST_F(UIViewTest, UIViewSetOnTouchListener_001, TestSize.Level1)
139 {
140     if (view_ == nullptr) {
141         EXPECT_NE(0, 0);
142         return;
143     }
144     UIView::OnTouchListener* listener = new UIView::OnTouchListener();
145     view_->SetOnTouchListener(listener);
146     EXPECT_EQ(view_->GetTouchListener(), listener);
147     delete listener;
148 }
149 
150 /**
151  * @tc.name: UIViewSetParent_001
152  * @tc.desc: Verify SetParent function, equal.
153  * @tc.type: FUNC
154  * @tc.require: AR000EEMQF
155  */
156 HWTEST_F(UIViewTest, UIViewSetParent_001, TestSize.Level1)
157 {
158     if (view_ == nullptr) {
159         EXPECT_NE(0, 0);
160         return;
161     }
162     UIViewGroup* viewGroup = new UIViewGroup();
163     if (viewGroup == nullptr) {
164         EXPECT_NE(0, 0);
165         return;
166     }
167     view_->SetParent(viewGroup);
168     EXPECT_EQ(view_->GetParent(), viewGroup);
169 
170     delete viewGroup;
171 }
172 
173 /**
174  * @tc.name: UIViewSetNextSibling_001
175  * @tc.desc: Verify SetNextSibling function, equal.
176  * @tc.type: FUNC
177  * @tc.require: AR000EEMQF
178  */
179 HWTEST_F(UIViewTest, UIViewSetNextSibling_001, TestSize.Level1)
180 {
181     if (view_ == nullptr) {
182         EXPECT_NE(0, 0);
183         return;
184     }
185     UIView* tempView = new UIView();
186     if (tempView == nullptr) {
187         EXPECT_NE(0, 0);
188         return;
189     }
190     view_->SetNextSibling(tempView);
191     EXPECT_EQ(view_->GetNextSibling(), tempView);
192 
193     delete tempView;
194 }
195 
196 /**
197  * @tc.name: UIViewSetVisible_001
198  * @tc.desc: Verify SetVisible function, equal.
199  * @tc.type: FUNC
200  * @tc.require: AR000EEMQF
201  */
202 HWTEST_F(UIViewTest, UIViewSetVisible_001, TestSize.Level1)
203 {
204     if (view_ == nullptr) {
205         EXPECT_NE(0, 0);
206         return;
207     }
208     view_->SetVisible(true);
209     EXPECT_EQ(view_->IsVisible(), true);
210 }
211 
212 /**
213  * @tc.name: UIViewSetTouchable_001
214  * @tc.desc: Verify SetTouchable function, equal.
215  * @tc.type: FUNC
216  * @tc.require: AR000EEMQF
217  */
218 HWTEST_F(UIViewTest, UIViewSetTouchable_001, TestSize.Level1)
219 {
220     if (view_ == nullptr) {
221         EXPECT_NE(0, 0);
222         return;
223     }
224     view_->SetTouchable(true);
225     EXPECT_EQ(view_->IsTouchable(), true);
226 }
227 
228 /**
229  * @tc.name: UIViewSetDraggable_001
230  * @tc.desc: Verify SetDraggable function, equal.
231  * @tc.type: FUNC
232  * @tc.require: AR000EEMQF
233  */
234 HWTEST_F(UIViewTest, UIViewSetDraggable_001, TestSize.Level1)
235 {
236     if (view_ == nullptr) {
237         EXPECT_NE(0, 0);
238         return;
239     }
240     view_->SetDraggable(true);
241     EXPECT_EQ(view_->IsDraggable(), true);
242 }
243 
244 /**
245  * @tc.name: UIViewSetDragParentInstead_001
246  * @tc.desc: Verify SetDragParentInstead function, equal.
247  * @tc.type: FUNC
248  * @tc.require: AR000EEMQF
249  */
250 HWTEST_F(UIViewTest, UIViewSetDragParentInstead_001, TestSize.Level1)
251 {
252     if (view_ == nullptr) {
253         EXPECT_NE(0, 0);
254         return;
255     }
256     view_->SetDragParentInstead(true);
257     EXPECT_EQ(view_->IsDragParentInstead(), true);
258 }
259 
260 /**
261  * @tc.name: UIViewResizeVisibleArea_001
262  * @tc.desc: Verify ResizeVisibleArea function, equal.
263  * @tc.type: FUNC
264  * @tc.require: AR000EEMQF
265  */
266 HWTEST_F(UIViewTest, UIViewResizeVisibleArea_001, TestSize.Level1)
267 {
268     if (view_ == nullptr) {
269         EXPECT_NE(0, 0);
270         return;
271     }
272     view_->ResizeVisibleArea(POS_X, POS_Y, DEFAULE_WIDTH, DEFAULE_HEIGHT);
273 
274     EXPECT_EQ(view_->GetVisibleRect().GetWidth(), DEFAULE_WIDTH);
275     EXPECT_EQ(view_->GetVisibleRect().GetHeight(), DEFAULE_HEIGHT);
276 }
277 
278 /**
279  * @tc.name: UIViewSetWidth_001
280  * @tc.desc: Verify SetWidth function, equal.
281  * @tc.type: FUNC
282  * @tc.require: AR000EEMQF
283  */
284 HWTEST_F(UIViewTest, UIViewSetWidth_001, TestSize.Level1)
285 {
286     if (view_ == nullptr) {
287         EXPECT_NE(0, 0);
288         return;
289     }
290     view_->SetWidth(0);
291     EXPECT_EQ(view_->GetWidth(), 0);
292     view_->SetWidth(DEFAULE_WIDTH);
293     EXPECT_EQ(view_->GetWidth(), DEFAULE_WIDTH);
294 }
295 
296 /**
297  * @tc.name: UIViewSetHeight_001
298  * @tc.desc: Verify SetHeight function, equal.
299  * @tc.type: FUNC
300  * @tc.require: AR000EEMQF
301  */
302 HWTEST_F(UIViewTest, UIViewSetHeight_001, TestSize.Level1)
303 {
304     if (view_ == nullptr) {
305         EXPECT_NE(0, 0);
306         return;
307     }
308     view_->SetHeight(0);
309     EXPECT_EQ(view_->GetHeight(), 0);
310     view_->SetHeight(DEFAULE_HEIGHT);
311     EXPECT_EQ(view_->GetHeight(), DEFAULE_HEIGHT);
312 }
313 
314 /**
315  * @tc.name: UIViewResize_001
316  * @tc.desc: Verify Resize function, equal.
317  * @tc.type: FUNC
318  * @tc.require: AR000EEMQF
319  */
320 HWTEST_F(UIViewTest, UIViewResize_001, TestSize.Level1)
321 {
322     if (view_ == nullptr) {
323         EXPECT_NE(0, 0);
324         return;
325     }
326     view_->Resize(0, 0);
327     EXPECT_EQ(view_->GetHeight(), 0);
328     EXPECT_EQ(view_->GetWidth(), 0);
329     view_->Resize(DEFAULE_WIDTH, DEFAULE_HEIGHT);
330     EXPECT_EQ(view_->GetHeight(), DEFAULE_HEIGHT);
331     EXPECT_EQ(view_->GetWidth(), DEFAULE_WIDTH);
332 }
333 
334 /**
335  * @tc.name: UIViewSetX_001
336  * @tc.desc: Verify SetX function, equal.
337  * @tc.type: FUNC
338  * @tc.require: AR000EEMQF
339  */
340 HWTEST_F(UIViewTest, UIViewSetX_001, TestSize.Level1)
341 {
342     if (view_ == nullptr) {
343         EXPECT_NE(0, 0);
344         return;
345     }
346     view_->SetX(0);
347     EXPECT_EQ(view_->GetX(), 0);
348     view_->SetX(POS_X);
349     EXPECT_EQ(view_->GetX(), POS_X);
350 }
351 
352 /**
353  * @tc.name: UIViewSetY_001
354  * @tc.desc: Verify SetY function, equal.
355  * @tc.type: FUNC
356  * @tc.require: AR000EEMQF
357  */
358 HWTEST_F(UIViewTest, UIViewSetY_001, TestSize.Level1)
359 {
360     if (view_ == nullptr) {
361         EXPECT_NE(0, 0);
362         return;
363     }
364     view_->SetY(0);
365     EXPECT_EQ(view_->GetY(), 0);
366     view_->SetY(POS_Y);
367     EXPECT_EQ(view_->GetY(), POS_Y);
368 }
369 
370 /**
371  * @tc.name: UIViewSetPosition_001
372  * @tc.desc: Verify SetPosition function, equal.
373  * @tc.type: FUNC
374  * @tc.require: AR000EEMQF
375  */
376 HWTEST_F(UIViewTest, UIViewSetPosition_001, TestSize.Level1)
377 {
378     if (view_ == nullptr) {
379         EXPECT_NE(0, 0);
380         return;
381     }
382     view_->SetPosition(0, 0);
383     EXPECT_EQ(view_->GetX(), 0);
384     EXPECT_EQ(view_->GetY(), 0);
385     view_->SetPosition(POS_X, POS_Y);
386     EXPECT_EQ(view_->GetX(), POS_X);
387     EXPECT_EQ(view_->GetY(), POS_Y);
388 }
389 
390 /**
391  * @tc.name: UIViewSetPosition_002
392  * @tc.desc: Verify SetPosition function, equal.
393  * @tc.type: FUNC
394  * @tc.require: AR000EEMQF
395  */
396 HWTEST_F(UIViewTest, UIViewSetPosition_002, TestSize.Level1)
397 {
398     if (view_ == nullptr) {
399         EXPECT_NE(0, 0);
400         return;
401     }
402     view_->SetPosition(0, 0, 0, 0);
403     EXPECT_EQ(view_->GetHeight(), 0);
404     EXPECT_EQ(view_->GetWidth(), 0);
405     EXPECT_EQ(view_->GetX(), 0);
406     EXPECT_EQ(view_->GetY(), 0);
407     view_->SetPosition(POS_X, POS_Y, DEFAULE_WIDTH, DEFAULE_HEIGHT);
408     EXPECT_EQ(view_->GetHeight(), DEFAULE_HEIGHT);
409     EXPECT_EQ(view_->GetWidth(), DEFAULE_WIDTH);
410     EXPECT_EQ(view_->GetX(), POS_X);
411     EXPECT_EQ(view_->GetY(), POS_Y);
412 }
413 
414 /**
415  * @tc.name: UIViewSetWidthPercent_001
416  * @tc.desc: Verify SetWidthPercent function, equal.
417  * @tc.type: FUNC
418  * @tc.require: SR000F3PE8
419  */
420 HWTEST_F(UIViewTest, UIViewSetWidthPercent_001, TestSize.Level0)
421 {
422     if (view_ == nullptr) {
423         EXPECT_NE(0, 0);
424         return;
425     }
426     view_->SetPosition(POS_X, POS_Y, DEFAULE_WIDTH, DEFAULE_HEIGHT);
427     EXPECT_EQ(view_->GetHeight(), DEFAULE_HEIGHT);
428     EXPECT_EQ(view_->GetWidth(), DEFAULE_WIDTH);
429     EXPECT_EQ(view_->GetX(), POS_X);
430     EXPECT_EQ(view_->GetY(), POS_Y);
431 
432     // Not has parent, SetWidthPercent failed
433     view_->SetWidthPercent(POS_X_PERCENT);
434     EXPECT_EQ(view_->GetWidth(), DEFAULE_WIDTH);
435 
436     // Parent does not SetWidth, view SetWidthPercent failed
437     UIViewGroup* viewGroup = new UIViewGroup();
438     viewGroup->Add(view_);
439     view_->SetWidthPercent(POS_X_PERCENT);
440     EXPECT_EQ(view_->GetWidth(), DEFAULE_WIDTH);
441 
442     viewGroup->SetWidth(DEFAULE_WIDTH);
443     viewGroup->SetHeight(DEFAULE_HEIGHT);
444 
445     // Input invaild percent, SetWidthPercent failed
446     view_->SetWidthPercent(INVAILD_PERCENT_ZERO);
447     EXPECT_EQ(view_->GetWidth(), DEFAULE_WIDTH);
448     view_->SetWidthPercent(INVAILD_PERCENT_ONE);
449     EXPECT_EQ(view_->GetWidth(), DEFAULE_WIDTH);
450 
451     view_->SetWidthPercent(POS_X_PERCENT);
452     EXPECT_EQ(view_->GetWidth(), (int16_t)(DEFAULE_WIDTH * POS_X_PERCENT));
453 
454     delete viewGroup;
455 }
456 
457 /**
458  * @tc.name: UIViewSetHeightPercent_001
459  * @tc.desc: Verify SetHeightPercent function, equal.
460  * @tc.type: FUNC
461  * @tc.require: AR000F4770
462  */
463 HWTEST_F(UIViewTest, UIViewSetHeightPercent_001, TestSize.Level0)
464 {
465     if (view_ == nullptr) {
466         EXPECT_NE(0, 0);
467         return;
468     }
469     view_->SetPosition(POS_X, POS_Y, DEFAULE_WIDTH, DEFAULE_HEIGHT);
470     EXPECT_EQ(view_->GetHeight(), DEFAULE_HEIGHT);
471     EXPECT_EQ(view_->GetWidth(), DEFAULE_WIDTH);
472     EXPECT_EQ(view_->GetX(), POS_X);
473     EXPECT_EQ(view_->GetY(), POS_Y);
474 
475     // Not has parent, SetHeightPercent failed
476     view_->SetHeightPercent(POS_Y_PERCENT);
477     EXPECT_EQ(view_->GetHeight(), DEFAULE_HEIGHT);
478 
479     // Parent does not SetHeight, view SetHeightPercent failed
480     UIViewGroup* viewGroup = new UIViewGroup();
481     viewGroup->Add(view_);
482     view_->SetHeightPercent(POS_Y_PERCENT);
483     EXPECT_EQ(view_->GetHeight(), DEFAULE_HEIGHT);
484 
485     viewGroup->SetWidth(DEFAULE_WIDTH);
486     viewGroup->SetHeight(DEFAULE_HEIGHT);
487 
488     // Input invaild percent, SetHeightPercent failed
489     view_->SetHeightPercent(INVAILD_PERCENT_ZERO);
490     EXPECT_EQ(view_->GetHeight(), DEFAULE_HEIGHT);
491     view_->SetHeightPercent(INVAILD_PERCENT_ONE);
492     EXPECT_EQ(view_->GetHeight(), DEFAULE_HEIGHT);
493 
494     view_->SetHeightPercent(POS_Y_PERCENT);
495     EXPECT_EQ(view_->GetHeight(), (int16_t)(DEFAULE_HEIGHT * POS_Y_PERCENT));
496 
497     delete viewGroup;
498 }
499 
500 /**
501  * @tc.name: UIViewResizePercent_001
502  * @tc.desc: Verify ResizePercent function, equal.
503  * @tc.type: FUNC
504  * @tc.require: AR000F4770
505  */
506 HWTEST_F(UIViewTest, UIViewResizePercent_001, TestSize.Level0)
507 {
508     if (view_ == nullptr) {
509         EXPECT_NE(0, 0);
510         return;
511     }
512     view_->SetPosition(POS_X, POS_Y, DEFAULE_WIDTH, DEFAULE_HEIGHT);
513     EXPECT_EQ(view_->GetHeight(), DEFAULE_HEIGHT);
514     EXPECT_EQ(view_->GetWidth(), DEFAULE_WIDTH);
515     EXPECT_EQ(view_->GetX(), POS_X);
516     EXPECT_EQ(view_->GetY(), POS_Y);
517 
518     // Not has parent, ResizePercent failed
519     view_->ResizePercent(POS_X_PERCENT, POS_Y_PERCENT);
520     EXPECT_EQ(view_->GetHeight(), DEFAULE_HEIGHT);
521     EXPECT_EQ(view_->GetWidth(), DEFAULE_WIDTH);
522 
523     // Parent does not SetWidth and SetHeight, view ResizePercent failed
524     UIViewGroup* viewGroup = new UIViewGroup();
525     viewGroup->Add(view_);
526     view_->ResizePercent(POS_X_PERCENT, POS_Y_PERCENT);
527     EXPECT_EQ(view_->GetHeight(), DEFAULE_HEIGHT);
528     EXPECT_EQ(view_->GetWidth(), DEFAULE_WIDTH);
529 
530     viewGroup->SetWidth(DEFAULE_WIDTH);
531     viewGroup->SetHeight(DEFAULE_HEIGHT);
532 
533     // Input invaild percent, ResizePercent failed
534     view_->ResizePercent(INVAILD_PERCENT_ZERO, POS_Y_PERCENT);
535     EXPECT_EQ(view_->GetHeight(), DEFAULE_HEIGHT);
536     EXPECT_EQ(view_->GetWidth(), DEFAULE_WIDTH);
537     view_->ResizePercent(POS_X_PERCENT, INVAILD_PERCENT_ONE);
538     EXPECT_EQ(view_->GetHeight(), DEFAULE_HEIGHT);
539     EXPECT_EQ(view_->GetWidth(), DEFAULE_WIDTH);
540 
541     view_->ResizePercent(POS_X_PERCENT, POS_Y_PERCENT);
542     EXPECT_EQ(view_->GetHeight(), (int16_t)(DEFAULE_HEIGHT * POS_Y_PERCENT));
543     EXPECT_EQ(view_->GetWidth(), (int16_t)(DEFAULE_WIDTH * POS_X_PERCENT));
544 
545     delete viewGroup;
546 }
547 
548 /**
549  * @tc.name: UIViewSetXPercent_001
550  * @tc.desc: Verify SetXPercent function, equal.
551  * @tc.type: FUNC
552  * @tc.require: AR000F4770
553  */
554 HWTEST_F(UIViewTest, UIViewSetXPercent_001, TestSize.Level0)
555 {
556     if (view_ == nullptr) {
557         EXPECT_NE(0, 0);
558         return;
559     }
560     view_->SetPosition(POS_X, POS_Y, DEFAULE_WIDTH, DEFAULE_HEIGHT);
561     EXPECT_EQ(view_->GetHeight(), DEFAULE_HEIGHT);
562     EXPECT_EQ(view_->GetWidth(), DEFAULE_WIDTH);
563     EXPECT_EQ(view_->GetX(), POS_X);
564     EXPECT_EQ(view_->GetY(), POS_Y);
565 
566     // Not has parent, SetXPercent failed
567     view_->SetXPercent(POS_X_PERCENT);
568     EXPECT_EQ(view_->GetX(), POS_X);
569 
570     // Parent does not SetWidth, view SetXPercent failed
571     UIViewGroup* viewGroup = new UIViewGroup();
572     viewGroup->Add(view_);
573     view_->SetXPercent(POS_X_PERCENT);
574     EXPECT_EQ(view_->GetX(), POS_X);
575 
576     viewGroup->SetWidth(DEFAULE_WIDTH);
577     viewGroup->SetHeight(DEFAULE_HEIGHT);
578 
579     // Input invaild percent, SetXPercent failed
580     view_->SetXPercent(INVAILD_PERCENT_ZERO);
581     EXPECT_EQ(view_->GetX(), POS_X);
582     view_->SetXPercent(INVAILD_PERCENT_ONE);
583     EXPECT_EQ(view_->GetX(), POS_X);
584 
585     view_->SetXPercent(POS_X_PERCENT);
586     EXPECT_EQ(view_->GetX(), (int16_t)(POS_X_PERCENT * DEFAULE_WIDTH));
587 
588     delete viewGroup;
589 }
590 
591 /**
592  * @tc.name: UIViewSetYPercent_001
593  * @tc.desc: Verify SetYPercent function, equal.
594  * @tc.type: FUNC
595  * @tc.require: AR000F4770
596  */
597 HWTEST_F(UIViewTest, UIViewSetYPercent_001, TestSize.Level0)
598 {
599     if (view_ == nullptr) {
600         EXPECT_NE(0, 0);
601         return;
602     }
603     view_->SetPosition(POS_X, POS_Y, DEFAULE_WIDTH, DEFAULE_HEIGHT);
604     EXPECT_EQ(view_->GetHeight(), DEFAULE_HEIGHT);
605     EXPECT_EQ(view_->GetWidth(), DEFAULE_WIDTH);
606     EXPECT_EQ(view_->GetX(), POS_X);
607     EXPECT_EQ(view_->GetY(), POS_Y);
608 
609     // Not has parent, SetYPercent failed
610     view_->SetYPercent(POS_Y_PERCENT);
611     EXPECT_EQ(view_->GetY(), POS_Y);
612 
613     // Parent does not SetHeight, view SetYPercent failed
614     UIViewGroup* viewGroup = new UIViewGroup();
615     viewGroup->Add(view_);
616     view_->SetYPercent(POS_Y_PERCENT);
617     EXPECT_EQ(view_->GetY(), POS_Y);
618 
619     viewGroup->SetWidth(DEFAULE_WIDTH);
620     viewGroup->SetHeight(DEFAULE_HEIGHT);
621 
622     // Input invaild percent, SetYPercent failed
623     view_->SetYPercent(INVAILD_PERCENT_ZERO);
624     EXPECT_EQ(view_->GetY(), POS_Y);
625     view_->SetYPercent(INVAILD_PERCENT_ONE);
626     EXPECT_EQ(view_->GetY(), POS_Y);
627 
628     view_->SetYPercent(POS_Y_PERCENT);
629     EXPECT_EQ(view_->GetY(), (int16_t)(POS_Y_PERCENT * DEFAULE_HEIGHT));
630 
631     delete viewGroup;
632 }
633 
634 /**
635  * @tc.name: UIViewSetPositionPercent_001
636  * @tc.desc: Verify SetPositionPercent function, equal.
637  * @tc.type: FUNC
638  * @tc.require: AR000F4770
639  */
640 HWTEST_F(UIViewTest, UIViewSetPositionPercent_001, TestSize.Level0)
641 {
642     if (view_ == nullptr) {
643         EXPECT_NE(0, 0);
644         return;
645     }
646     view_->SetPosition(POS_X, POS_Y, DEFAULE_WIDTH, DEFAULE_HEIGHT);
647     EXPECT_EQ(view_->GetHeight(), DEFAULE_HEIGHT);
648     EXPECT_EQ(view_->GetWidth(), DEFAULE_WIDTH);
649     EXPECT_EQ(view_->GetX(), POS_X);
650     EXPECT_EQ(view_->GetY(), POS_Y);
651 
652     // Not has parent, SetPositionPercent failed
653     view_->SetPositionPercent(POS_X_PERCENT, POS_Y_PERCENT);
654     EXPECT_EQ(view_->GetX(), POS_X);
655     EXPECT_EQ(view_->GetY(), POS_Y);
656 
657     // Parent does not SetWidth, view SetPositionPercent failed
658     UIViewGroup* viewGroup = new UIViewGroup();
659     viewGroup->Add(view_);
660     view_->SetPositionPercent(POS_X_PERCENT, POS_Y_PERCENT);
661     EXPECT_EQ(view_->GetX(), POS_X);
662     EXPECT_EQ(view_->GetY(), POS_Y);
663 
664     viewGroup->SetWidth(DEFAULE_WIDTH);
665     viewGroup->SetHeight(DEFAULE_HEIGHT);
666 
667     // Input invaild percent, SetPositionPercent failed
668     view_->SetPositionPercent(INVAILD_PERCENT_ZERO, INVAILD_PERCENT_ONE);
669     EXPECT_EQ(view_->GetX(), POS_X);
670     EXPECT_EQ(view_->GetY(), POS_Y);
671 
672     view_->SetPositionPercent(POS_X_PERCENT, POS_Y_PERCENT);
673     EXPECT_EQ(view_->GetX(), (int16_t)(POS_X_PERCENT * DEFAULE_WIDTH));
674     EXPECT_EQ(view_->GetY(), (int16_t)(POS_Y_PERCENT * DEFAULE_HEIGHT));
675 
676     delete viewGroup;
677 }
678 
679 /**
680  * @tc.name: Graphic_UIView_Test_SetPositionPercent_002
681  * @tc.desc: Verify SetPositionPercent function, equal.
682  * @tc.type: FUNC
683  * @tc.require: AR000F4770
684  */
685 HWTEST_F(UIViewTest, UIViewSetPositionPercent_002, TestSize.Level0)
686 {
687     if (view_ == nullptr) {
688         EXPECT_NE(0, 0);
689         return;
690     }
691     view_->SetPosition(POS_X, POS_Y, DEFAULE_WIDTH, DEFAULE_HEIGHT);
692     EXPECT_EQ(view_->GetHeight(), DEFAULE_HEIGHT);
693     EXPECT_EQ(view_->GetWidth(), DEFAULE_WIDTH);
694     EXPECT_EQ(view_->GetX(), POS_X);
695     EXPECT_EQ(view_->GetY(), POS_Y);
696 
697     // Not has parent, SetPositionPercent failed
698     view_->SetPositionPercent(POS_X_PERCENT, POS_Y_PERCENT, DEFAULT_WIDTH_PERCENT, DEFAULT_HEIGHT_PERCENT);
699     EXPECT_EQ(view_->GetHeight(), DEFAULE_HEIGHT);
700     EXPECT_EQ(view_->GetWidth(), DEFAULE_WIDTH);
701     EXPECT_EQ(view_->GetX(), POS_X);
702     EXPECT_EQ(view_->GetY(), POS_Y);
703 
704     // Parent does not SetWidth, view SetPositionPercent failed
705     UIViewGroup* viewGroup = new UIViewGroup();
706     viewGroup->Add(view_);
707     view_->SetPositionPercent(POS_X_PERCENT, POS_Y_PERCENT, DEFAULT_WIDTH_PERCENT, DEFAULT_HEIGHT_PERCENT);
708     EXPECT_EQ(view_->GetHeight(), DEFAULE_HEIGHT);
709     EXPECT_EQ(view_->GetWidth(), DEFAULE_WIDTH);
710     EXPECT_EQ(view_->GetX(), POS_X);
711     EXPECT_EQ(view_->GetY(), POS_Y);
712 
713     viewGroup->SetWidth(DEFAULE_WIDTH);
714     viewGroup->SetHeight(DEFAULE_HEIGHT);
715 
716     // Input invaild percent, SetPositionPercent failed
717     view_->SetPositionPercent(INVAILD_PERCENT_ZERO, INVAILD_PERCENT_ONE, DEFAULT_WIDTH_PERCENT, DEFAULT_HEIGHT_PERCENT);
718     EXPECT_EQ(view_->GetHeight(), DEFAULE_HEIGHT);
719     EXPECT_EQ(view_->GetWidth(), DEFAULE_WIDTH);
720     EXPECT_EQ(view_->GetX(), POS_X);
721     EXPECT_EQ(view_->GetY(), POS_Y);
722 
723 
724     view_->SetPositionPercent(POS_X_PERCENT, POS_Y_PERCENT, DEFAULT_WIDTH_PERCENT, DEFAULT_HEIGHT_PERCENT);
725     EXPECT_EQ(view_->GetHeight(), (int16_t)(DEFAULE_HEIGHT * DEFAULT_HEIGHT_PERCENT));
726     EXPECT_EQ(view_->GetWidth(), (int16_t)(DEFAULE_WIDTH * DEFAULT_WIDTH_PERCENT));
727     EXPECT_EQ(view_->GetX(), (int16_t)(POS_X_PERCENT * DEFAULE_WIDTH));
728     EXPECT_EQ(view_->GetY(), (int16_t)(POS_Y_PERCENT * DEFAULE_HEIGHT));
729 
730     delete viewGroup;
731 }
732 
733 /**
734  * @tc.name: UIViewSetViewId_001
735  * @tc.desc: Verify SetViewId function, equal.
736  * @tc.type: FUNC
737  * @tc.require: AR000EEMQF
738  */
739 HWTEST_F(UIViewTest, UIViewSetViewId_001, TestSize.Level1)
740 {
741     if (view_ == nullptr) {
742         EXPECT_NE(0, 0);
743         return;
744     }
745     const char* id = "graphic_unittest_view";
746 
747     view_->SetViewId(id);
748     EXPECT_EQ(memcmp(view_->GetViewId(), id, strlen(id)), 0);
749 }
750 
751 /**
752  * @tc.name: UIViewSetViewIndex_001
753  * @tc.desc: Verify SetViewIndex function, equal.
754  * @tc.type: FUNC
755  * @tc.require: AR000EEMQF
756  */
757 HWTEST_F(UIViewTest, UIViewSetViewIndex_001, TestSize.Level1)
758 {
759     if (view_ == nullptr) {
760         EXPECT_NE(0, 0);
761         return;
762     }
763     int16_t index = 1;
764 
765     view_->SetViewIndex(index);
766     EXPECT_EQ(view_->GetViewIndex(), index);
767 }
768 
769 /**
770  * @tc.name: UIViewGetViewType_001
771  * @tc.desc: Verify GetViewType function, equal.
772  * @tc.type: FUNC
773  * @tc.require: AR000EEMQF
774  */
775 HWTEST_F(UIViewTest, UIViewGetViewType_001, TestSize.Level1)
776 {
777     if (view_ == nullptr) {
778         EXPECT_NE(0, 0);
779         return;
780     }
781     EXPECT_EQ(view_->GetViewType(), UI_NUMBER_MAX);
782 }
783 
784 /**
785  * @tc.name: UIViewSetOpaScale_001
786  * @tc.desc: Verify SetOpaScale function, equal.
787  * @tc.type: FUNC
788  * @tc.require: AR000F4E5D
789  */
790 HWTEST_F(UIViewTest, UIViewSetOpaScale_001, TestSize.Level1)
791 {
792     if (view_ == nullptr) {
793         EXPECT_NE(0, 0);
794         return;
795     }
796     uint8_t opaScale = OPA_OPAQUE;
797 
798     view_->SetOpaScale(OPA_OPAQUE);
799     EXPECT_EQ(view_->GetOpaScale(), OPA_OPAQUE);
800 }
801 
802 /**
803  * @tc.name: UIViewSetOpaScale_002
804  * @tc.desc: Verify SetOpaScale function, equal.
805  * @tc.type: FUNC
806  * @tc.require: SR000F3PEB
807  */
808 HWTEST_F(UIViewTest, UIViewSetOpaScale_002, TestSize.Level1)
809 {
810     if (view_ == nullptr) {
811         EXPECT_NE(0, 0);
812         return;
813     }
814     uint8_t opaScale = OPA_OPAQUE;
815 
816     view_->SetOpaScale(OPA_OPAQUE);
817     view_->SetStyle(STYLE_BACKGROUND_OPA, opaScale >> 1);
818     view_->SetStyle(STYLE_BORDER_OPA, opaScale >> 1);
819     EXPECT_EQ(view_->GetOpaScale(), OPA_OPAQUE);
820 }
821 
822 /**
823  * @tc.name: UIViewSetStyle_001
824  * @tc.desc: Verify SetStyle function, equal.
825  * @tc.type: FUNC
826  * @tc.require: AR000EEMQF
827  */
828 HWTEST_F(UIViewTest, UIViewSetStyle_001, TestSize.Level1)
829 {
830     if (view_ == nullptr) {
831         EXPECT_NE(0, 0);
832         return;
833     }
834     Style style;
835     style.borderOpa_ = OPA_OPAQUE;
836     view_->SetStyle(style);
837     EXPECT_EQ(view_->GetStyleConst().borderOpa_, OPA_OPAQUE);
838     view_->SetStyle(STYLE_LINE_OPA, OPA_OPAQUE);
839     EXPECT_EQ(view_->GetStyle(STYLE_LINE_OPA), OPA_OPAQUE);
840 }
841 
842 /**
843  * @tc.name: UIViewLayoutOfParent_001
844  * @tc.desc: Verify LayoutOfParent function, equal.
845  * @tc.type: FUNC
846  * @tc.require: AR000EEMQF
847  */
848 HWTEST_F(UIViewTest, UIViewLayoutOfParent_001, TestSize.Level0)
849 {
850     if (view_ == nullptr) {
851         EXPECT_NE(0, 0);
852         return;
853     }
854     UIViewGroup* viewGroup = new UIViewGroup();
855     viewGroup->SetPosition(0, 0, DEFAULE_WIDTH, DEFAULE_HEIGHT);
856     view_->SetPosition(POS_X, POS_Y, BUTTON_WIDTH, BUTTON_HEIGHT);
857     viewGroup->Add(view_);
858     int16_t centerX = (DEFAULE_WIDTH- BUTTON_WIDTH) / 2; // 2: center of x;
859     int16_t centerY = (DEFAULE_HEIGHT- BUTTON_HEIGHT) / 2; // 2: center of y;
860     EXPECT_EQ(view_->GetX(), POS_X);
861     EXPECT_EQ(view_->GetY(), POS_Y);
862     view_->LayoutCenterOfParent();
863     EXPECT_EQ(view_->GetX(), centerX);
864     EXPECT_EQ(view_->GetY(), centerY);
865     view_->LayoutLeftOfParent();
866     EXPECT_EQ(view_->GetX(), 0);
867     EXPECT_EQ(view_->GetY(), centerY);
868     view_->LayoutRightOfParent();
869     EXPECT_EQ(view_->GetX(), DEFAULE_WIDTH- BUTTON_WIDTH);
870     EXPECT_EQ(view_->GetY(), centerY);
871     view_->LayoutTopOfParent();
872     EXPECT_EQ(view_->GetX(), DEFAULE_WIDTH- BUTTON_WIDTH);
873     EXPECT_EQ(view_->GetY(), 0);
874     view_->LayoutBottomOfParent();
875     EXPECT_EQ(view_->GetX(), DEFAULE_WIDTH- BUTTON_WIDTH);
876     EXPECT_EQ(view_->GetY(), DEFAULE_HEIGHT- BUTTON_HEIGHT);
877 
878     delete viewGroup;
879 }
880 
881 /**
882  * @tc.name: UIViewAlignToSibling_001
883  * @tc.desc: Verify AlignToSibling function, equal.
884  * @tc.type: FUNC
885  * @tc.require: AR000EEMQF
886  */
887 HWTEST_F(UIViewTest, UIViewAlignToSibling_001, TestSize.Level0)
888 {
889     if (view_ == nullptr) {
890         EXPECT_NE(0, 0);
891         return;
892     }
893     UIViewGroup* viewGroup = new UIViewGroup();
894     viewGroup->SetPosition(0, 0, DEFAULE_WIDTH, DEFAULE_HEIGHT);
895     view_->SetPosition(POS_X, POS_Y, BUTTON_WIDTH, BUTTON_HEIGHT);
896     viewGroup->Add(view_);
897     int16_t centerX = (DEFAULE_WIDTH- BUTTON_WIDTH) / 2; // 2: center of x;
898     int16_t centerY = (DEFAULE_HEIGHT- BUTTON_HEIGHT) / 2; // 2: center of y;
899     UIView* view2 = new UIView();
900     view2->SetPosition(centerX, centerY, BUTTON_WIDTH, BUTTON_HEIGHT);
901     view2->SetViewId("refView");
902     viewGroup->Add(view2);
903     EXPECT_EQ(view_->GetX(), POS_X);
904     EXPECT_EQ(view_->GetY(), POS_Y);
905     view_->AlignLeftToSibling("refView");
906     EXPECT_EQ(view_->GetX(), centerX);
907     EXPECT_EQ(view_->GetY(), POS_Y);
908     view_->AlignRightToSibling("refView");
909     EXPECT_EQ(view_->GetX(), centerX);
910     EXPECT_EQ(view_->GetY(), POS_Y);
911     view_->AlignTopToSibling("refView");
912     EXPECT_EQ(view_->GetX(), centerX);
913     EXPECT_EQ(view_->GetY(), centerY);
914     view_->AlignBottomToSibling("refView");
915     EXPECT_EQ(view_->GetX(), centerX);
916     EXPECT_EQ(view_->GetY(), centerY);
917     view_->AlignHorCenterToSibling("refView");
918     EXPECT_EQ(view_->GetX(), centerX);
919     EXPECT_EQ(view_->GetY(), centerY);
920     view_->AlignVerCenterToSibling("refView");
921     EXPECT_EQ(view_->GetX(), centerX);
922     EXPECT_EQ(view_->GetY(), centerY);
923 
924     delete view2;
925     delete viewGroup;
926 }
927 
928 /**
929  * @tc.name: UIViewLayoutToSibling_001
930  * @tc.desc: Verify LayoutToSibling function, equal.
931  * @tc.type: FUNC
932  * @tc.require: AR000EEMQF
933  */
934 HWTEST_F(UIViewTest, UIViewLayoutToSibling_001, TestSize.Level0)
935 {
936     if (view_ == nullptr) {
937         EXPECT_NE(0, 0);
938         return;
939     }
940     UIViewGroup* viewGroup = new UIViewGroup();
941     viewGroup->SetPosition(0, 0, DEFAULE_WIDTH, DEFAULE_HEIGHT);
942     view_->SetPosition(POS_X, POS_Y, BUTTON_WIDTH, BUTTON_HEIGHT);
943     viewGroup->Add(view_);
944     int16_t centerX = (DEFAULE_WIDTH- BUTTON_WIDTH) / 2; // 2: center of x;
945     int16_t centerY = (DEFAULE_HEIGHT- BUTTON_HEIGHT) / 2; // 2: center of y;
946     UIView* view2 = new UIView();
947     view2->SetPosition(centerX, centerY, BUTTON_WIDTH, BUTTON_HEIGHT);
948     view2->SetViewId("refView");
949     viewGroup->Add(view2);
950     EXPECT_EQ(view_->GetX(), POS_X);
951     EXPECT_EQ(view_->GetY(), POS_Y);
952     view_->LayoutLeftToSibling("refView");
953     EXPECT_EQ(view_->GetX(), BUTTON_WIDTH);
954     EXPECT_EQ(view_->GetY(), POS_Y);
955     view_->LayoutRightToSibling("refView");
956     EXPECT_EQ(view_->GetX(), centerX + BUTTON_WIDTH);
957     EXPECT_EQ(view_->GetY(), POS_Y);
958     view_->LayoutTopToSibling("refView");
959     EXPECT_EQ(view_->GetX(), centerX + BUTTON_WIDTH);
960     EXPECT_EQ(view_->GetY(), BUTTON_HEIGHT);
961     view_->LayoutBottomToSibling("refView");
962     EXPECT_EQ(view_->GetX(), centerX + BUTTON_WIDTH);
963     EXPECT_EQ(view_->GetY(), centerY + BUTTON_HEIGHT);
964 
965     delete view2;
966     delete viewGroup;
967 }
968 
969 /**
970  * @tc.name: Graphic_UIView_Test_Rotate_001
971  * @tc.desc: Verify Rotate function, equal.
972  * @tc.type: FUNC
973  * @tc.require: SR000F3PEC
974  */
975 HWTEST_F(UIViewTest, Graphic_UIView_Test_Rotate_001, TestSize.Level1)
976 {
977     if (view_ == nullptr) {
978         EXPECT_NE(0, 0);
979         return;
980     }
981     view_->SetPosition(0, 0, DEFAULE_WIDTH, DEFAULE_HEIGHT);
982     view_->Rotate(DEFAULE_ANGLE, {0, 0});
983     TransformMap& trans = view_->GetTransformMap();
984     EXPECT_EQ(view_->GetOrigRect(), trans.GetTransMapRect());
985 }
986 
987 /**
988  * @tc.name: Graphic_UIView_Test_Rotate_002
989  * @tc.desc: Verify Rotate function, equal.
990  * @tc.type: FUNC
991  * @tc.require: AR000F4E5E
992  */
993 HWTEST_F(UIViewTest, Graphic_UIView_Test_Rotate_002, TestSize.Level1)
994 {
995     if (view_ == nullptr) {
996         EXPECT_NE(0, 0);
997         return;
998     }
999     view_->SetPosition(0, 0, DEFAULE_WIDTH, DEFAULE_HEIGHT);
1000     view_->Rotate(DEFAULE_ANGLE, {0, 0});
1001     Polygon polygon = view_->GetTransformMap().GetPolygon();
1002 
1003     EXPECT_EQ(POLYGON1,  polygon[0]); // 0: polygon num
1004     EXPECT_EQ(POLYGON2,  polygon[1]); // 1: polygon num
1005     EXPECT_EQ(POLYGON3,  polygon[2]); // 2: polygon num
1006     EXPECT_EQ(POLYGON4,  polygon[3]); // 3: polygon num
1007 }
1008 
1009 /**
1010  * @tc.name: Graphic_UIView_Test_Scale_001
1011  * @tc.desc: Verify Scale function, equal.
1012  * @tc.type: FUNC
1013  * @tc.require: SR000ERCQH
1014  */
1015 HWTEST_F(UIViewTest, Graphic_UIView_Test_Scale_001, TestSize.Level0)
1016 {
1017     if (view_ == nullptr) {
1018         EXPECT_NE(0, 0);
1019         return;
1020     }
1021     view_->SetPosition(0, 0, DEFAULE_WIDTH, DEFAULE_HEIGHT);
1022     view_->Scale(SCALE_VALUE, VIEW_CENTER);
1023     TransformMap& trans = view_->GetTransformMap();
1024     EXPECT_EQ(view_->GetOrigRect(), trans.GetTransMapRect());
1025 }
1026 
1027 /**
1028  * @tc.name: Graphic_UIView_Test_Scale_002
1029  * @tc.desc: Verify Scale function, equal.
1030  * @tc.type: FUNC
1031  * @tc.require: AR000EVI2T
1032  */
1033 HWTEST_F(UIViewTest, Graphic_UIView_Test_Scale_002, TestSize.Level1)
1034 {
1035     if (view_ == nullptr) {
1036         EXPECT_NE(0, 0);
1037         return;
1038     }
1039     view_->SetPosition(0, 0, DEFAULE_WIDTH, DEFAULE_HEIGHT);
1040     view_->Scale(SCALE_VALUE, {0, 0});
1041     Polygon polygon = view_->GetTransformMap().GetPolygon();
1042     EXPECT_EQ(0, polygon[0].x_);
1043     EXPECT_EQ(0, polygon[0].y_);
1044     EXPECT_EQ(DEFAULE_WIDTH >> 1, polygon[2].x_); // 2: polygon num
1045     EXPECT_EQ(DEFAULE_HEIGHT >> 1, polygon[2].y_); // 2: polygon num
1046 }
1047 
1048 /**
1049  * @tc.name: Graphic_UIView_Test_Margin_001
1050  * @tc.desc: Test whether the Rect is normal in the margin scenario.
1051  * @tc.type: FUNC
1052  * @tc.require: AR000FQNFP
1053  */
1054 HWTEST_F(UIViewTest, Graphic_UIView_Test_Margin_001, TestSize.Level0)
1055 {
1056     if (view_ == nullptr) {
1057         EXPECT_NE(0, 0);
1058         return;
1059     }
1060     view_->SetStyle(STYLE_MARGIN_LEFT, MARGIN_LEFT);
1061     view_->SetStyle(STYLE_MARGIN_TOP, MARGIN_TOP);
1062     view_->SetPosition(0, 0, DEFAULE_WIDTH, DEFAULE_HEIGHT);
1063     EXPECT_EQ(DEFAULE_WIDTH, view_->GetWidth());
1064     EXPECT_EQ(DEFAULE_HEIGHT, view_->GetHeight());
1065     EXPECT_EQ(0, view_->GetX());
1066     EXPECT_EQ(0, view_->GetY());
1067     Rect rect = view_->GetRelativeRect();
1068     EXPECT_EQ(MARGIN_LEFT, rect.GetX());
1069     EXPECT_EQ(MARGIN_TOP, rect.GetY());
1070 }
1071 
1072 /**
1073  * @tc.name: Graphic_UIView_Test_Padding_001
1074  * @tc.desc: Test whether the Rect is normal in the setting padding scene.
1075  * @tc.type: FUNC
1076  * @tc.require: AR000FQNFP
1077  */
1078 HWTEST_F(UIViewTest, Graphic_UIView_Test_Padding_001, TestSize.Level0)
1079 {
1080     if (view_ == nullptr) {
1081         EXPECT_NE(0, 0);
1082         return;
1083     }
1084     view_->SetStyle(STYLE_PADDING_LEFT, PADDING_LEFT);
1085     view_->SetStyle(STYLE_PADDING_TOP, PADDING_TOP);
1086     view_->SetStyle(STYLE_PADDING_RIGHT, PADDING_RIGHT);
1087     view_->SetStyle(STYLE_PADDING_BOTTOM, PADDING_BOTTOM);
1088     view_->SetPosition(0, 0, DEFAULE_WIDTH, DEFAULE_HEIGHT);
1089     Rect rect = view_->GetContentRect();
1090     EXPECT_EQ(PADDING_LEFT, rect.GetX());
1091     EXPECT_EQ(PADDING_TOP, rect.GetY());
1092     EXPECT_EQ(PADDING_LEFT + DEFAULE_WIDTH - 1, rect.GetRight());
1093     EXPECT_EQ(PADDING_TOP + DEFAULE_HEIGHT - 1, rect.GetBottom());
1094     rect = view_->GetRelativeRect();
1095     EXPECT_EQ(0, rect.GetX());
1096     EXPECT_EQ(0, rect.GetY());
1097     EXPECT_EQ(PADDING_LEFT + PADDING_RIGHT + DEFAULE_WIDTH - 1, rect.GetRight());
1098     EXPECT_EQ(PADDING_TOP + PADDING_BOTTOM + DEFAULE_HEIGHT - 1, rect.GetBottom());
1099 }
1100 
1101 /**
1102  * @tc.name: Graphic_UIView_Test_Border_001
1103  * @tc.desc: Test whether the Rect is normal in the setting of the border scene.
1104  * @tc.type: FUNC
1105  * @tc.require: AR000FQNFP
1106  */
1107 HWTEST_F(UIViewTest, Graphic_UIView_Test_Border_001, TestSize.Level0)
1108 {
1109     if (view_ == nullptr) {
1110         EXPECT_NE(0, 0);
1111         return;
1112     }
1113     view_->SetStyle(STYLE_BORDER_WIDTH, BORDER_WIDTH);
1114     view_->SetPosition(0, 0, DEFAULE_WIDTH, DEFAULE_HEIGHT);
1115     Rect rect = view_->GetContentRect();
1116     EXPECT_EQ(BORDER_WIDTH, rect.GetX());
1117     EXPECT_EQ(BORDER_WIDTH, rect.GetY());
1118     EXPECT_EQ(BORDER_WIDTH + DEFAULE_WIDTH - 1, rect.GetRight());
1119     EXPECT_EQ(BORDER_WIDTH + DEFAULE_HEIGHT - 1, rect.GetBottom());
1120     rect = view_->GetRelativeRect();
1121     EXPECT_EQ(0, rect.GetX());
1122     EXPECT_EQ(0, rect.GetY());
1123     EXPECT_EQ(BORDER_WIDTH + BORDER_WIDTH + DEFAULE_WIDTH - 1, rect.GetRight());
1124     EXPECT_EQ(BORDER_WIDTH + BORDER_WIDTH + DEFAULE_HEIGHT - 1, rect.GetBottom());
1125 }
1126 } // namespace OHOS
1127