• 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 #include <climits>
18 #include <gtest/gtest.h>
19 
20 using namespace testing::ext;
21 namespace OHOS {
22 class UIViewGroupTest : public testing::Test {
23 public:
UIViewGroupTest()24     UIViewGroupTest() : viewGroup_(nullptr) {}
~UIViewGroupTest()25     ~UIViewGroupTest() {}
SetUpTestCase(void)26     static void SetUpTestCase(void) {}
TearDownTestCase(void)27     static void TearDownTestCase(void) {}
28     void SetUp(void);
29     void TearDown(void);
30     UIViewGroup* viewGroup_;
31 };
32 
SetUp(void)33 void UIViewGroupTest::SetUp(void)
34 {
35     if (viewGroup_ == nullptr) {
36         viewGroup_ = new UIViewGroup();
37     }
38 }
39 
TearDown(void)40 void UIViewGroupTest::TearDown(void)
41 {
42     if (viewGroup_ != nullptr) {
43         delete viewGroup_;
44         viewGroup_ = nullptr;
45     }
46 }
47 
48 /**
49  * @tc.name: UIViewGroupAdd_001
50  * @tc.desc: Verify Add function.
51  * @tc.type: FUNC
52  * @tc.require: AR000EEMQF
53  */
54 HWTEST_F(UIViewGroupTest, UIViewGroupAdd_001, TestSize.Level0)
55 {
56     if (viewGroup_ == nullptr) {
57         EXPECT_EQ(1, 0);
58         return;
59     }
60     UIView* view = new UIView();
61     if (view == nullptr) {
62         EXPECT_EQ(1, 0);
63         return;
64     }
65     viewGroup_->Add(view);
66     EXPECT_EQ(view, viewGroup_->GetChildrenHead());
67     EXPECT_EQ(view->GetParent(), viewGroup_);
68 
69     delete view;
70 }
71 
72 /**
73  * @tc.name: UIViewGroupInsert_001
74  * @tc.desc: Verify Insert function.
75  * @tc.type: FUNC
76  * @tc.require: AR000EEMQF
77  */
78 HWTEST_F(UIViewGroupTest, UIViewGroupInsert_001, TestSize.Level0)
79 {
80     if (viewGroup_ == nullptr) {
81         EXPECT_EQ(1, 0);
82         return;
83     }
84     UIView* preView = new UIView();
85     if (preView == nullptr) {
86         EXPECT_EQ(1, 0);
87         return;
88     }
89     UIView* view = new UIView();
90 
91     viewGroup_->Add(preView);
92     viewGroup_->Insert(preView, view);
93     EXPECT_EQ(view, preView->GetNextSibling());
94 
95     delete preView;
96     delete view;
97 }
98 
99 /**
100  * @tc.name: UIViewGroupRemove_001
101  * @tc.desc: Verify Remove function.
102  * @tc.type: FUNC
103  * @tc.require: AR000EEMQF
104  */
105 HWTEST_F(UIViewGroupTest, UIViewGroupRemove_001, TestSize.Level0)
106 {
107     if (viewGroup_ == nullptr) {
108         EXPECT_EQ(1, 0);
109         return;
110     }
111     UIView* view = new UIView();
112     if (view == nullptr) {
113         EXPECT_EQ(1, 0);
114         return;
115     }
116     viewGroup_->Add(view);
117     viewGroup_->Remove(view);
118     EXPECT_EQ(nullptr, viewGroup_->GetChildrenHead());
119     EXPECT_EQ(nullptr, view->GetParent());
120 
121     delete view;
122 }
123 
124 /**
125  * @tc.name: UIViewGroupRemoveAll_001
126  * @tc.desc: Verify RemoveAll function.
127  * @tc.type: FUNC
128  * @tc.require: AR000EEMQF
129  */
130 HWTEST_F(UIViewGroupTest, UIViewGroupRemoveAll_001, TestSize.Level0)
131 {
132     if (viewGroup_ == nullptr) {
133         EXPECT_EQ(1, 0);
134         return;
135     }
136     UIView* view = new UIView();
137     UIView* view2 = new UIView();
138 
139     viewGroup_->Add(view);
140     viewGroup_->RemoveAll();
141     EXPECT_EQ(nullptr, viewGroup_->GetChildrenHead());
142 
143     delete view;
144     delete view2;
145 }
146 
147 /**
148  * @tc.name: UIViewGroupGetViewType_001
149  * @tc.desc: Verify GetViewType function.
150  * @tc.type: FUNC
151  * @tc.require: AR000EEMQF
152  */
153 HWTEST_F(UIViewGroupTest, UIViewGroupGetViewType_001, TestSize.Level1)
154 {
155     if (viewGroup_ == nullptr) {
156         EXPECT_EQ(1, 0);
157         return;
158     }
159     EXPECT_EQ(viewGroup_->GetViewType(), UI_VIEW_GROUP);
160 }
161 } // namespace OHOS