1 /*
2  * Copyright (c) 2023 iSoftStone Information Technology (Group) 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 "gtest/gtest.h"
17 #include "core/components_ng/property/property.h"
18 
19 using namespace testing;
20 using namespace testing::ext;
21 
22 namespace OHOS::Ace::NG {
23 namespace {
24 constexpr PropertyChangeFlag TEST_PROPERTY_UPDATE_NORMAL = 0;
25 constexpr PropertyChangeFlag TEST_PROPERTY_UPDATE_RENDER_BY_CHILD_REQUEST = 1 << 7;
26 constexpr PropertyChangeFlag TEST_PROPERTY_UPDATE_RENDER = 1 << 6;
27 constexpr PropertyChangeFlag TEST_PROPERTY_UPDATE_MEASURE = 1;
28 constexpr PropertyChangeFlag TEST_PROPERTY_UPDATE_BY_CHILD_REQUEST = 1 << 5;
29 constexpr PropertyChangeFlag TEST_PROPERTY_UPDATE_MEASURE_SELF_AND_PARENT = 1 << 4;
30 constexpr PropertyChangeFlag TEST_PROPERTY_UPDATE_MEASURE_SELF = 1 << 3;
31 }
32 
33 class PropertyTestNg : public testing::Test {};
34 
35 /**
36  * @tc.name: PropertyTestNgTest001
37  * @tc.desc: Test CheckNeedRender funcation.
38  * @tc.type: FUNC
39  */
40 HWTEST_F(PropertyTestNg, PropertyTestNgTest001, TestSize.Level1)
41 {
42     /**
43      * @tc.steps: step1. call CheckNeedRender and set input is TEST_PROPERTY_UPDATE_NORMAL.
44      * @tc.expected: the return value is false.
45      */
46     bool retFlag = CheckNeedRender(TEST_PROPERTY_UPDATE_NORMAL);
47     EXPECT_FALSE(retFlag);
48 
49     /**
50      * @tc.steps: step2. call CheckNeedRender and set input is TEST_PROPERTY_UPDATE_RENDER_BY_CHILD_REQUEST.
51      * @tc.expected: the return value is true.
52      */
53     retFlag = CheckNeedRender(TEST_PROPERTY_UPDATE_RENDER_BY_CHILD_REQUEST);
54     EXPECT_TRUE(retFlag);
55 
56     /**
57      * @tc.steps: step3. call CheckNeedRender and set input is TEST_PROPERTY_UPDATE_RENDER.
58      * @tc.expected: the return value is true.
59      */
60     retFlag = CheckNeedRender(TEST_PROPERTY_UPDATE_RENDER);
61     EXPECT_TRUE(retFlag);
62 }
63 
64 /**
65  * @tc.name: PropertyTestNgTest002
66  * @tc.desc: Test CheckNeedRequestMeasureAndLayout funcation.
67  * @tc.type: FUNC
68  */
69 HWTEST_F(PropertyTestNg, PropertyTestNgTest002, TestSize.Level1)
70 {
71     /**
72      * @tc.steps: step1. call CheckNeedRequestMeasureAndLayout and set input is PROPERTY_UPDATE_MEASURE.
73      * @tc.expected: the return value is true.
74      */
75     bool retFlag = CheckNeedRequestMeasureAndLayout(TEST_PROPERTY_UPDATE_MEASURE);
76     EXPECT_TRUE(retFlag);
77 
78     /**
79      * @tc.steps: step2. call CheckNeedRequestMeasureAndLayout and set input is TEST_PROPERTY_UPDATE_BY_CHILD_REQUEST.
80      * @tc.expected: the return value is true.
81      */
82     retFlag = CheckNeedRequestMeasureAndLayout(TEST_PROPERTY_UPDATE_BY_CHILD_REQUEST);
83     EXPECT_TRUE(retFlag);
84 
85     /**
86      * @tc.steps: step3. call CheckNeedRequestMeasureAndLayout and set input flag is TEST_PROPERTY_UPDATE_NORMAL.
87      * @tc.expected: the return value is false.
88      */
89     retFlag = CheckNeedRequestMeasureAndLayout(TEST_PROPERTY_UPDATE_NORMAL);
90     EXPECT_FALSE(retFlag);
91 }
92 
93 /**
94  * @tc.name: PropertyTestNgTest003
95  * @tc.desc: Test CheckNeedRequestParentMeasure funcation.
96  * @tc.type: FUNC
97  */
98 HWTEST_F(PropertyTestNg, PropertyTestNgTest003, TestSize.Level1)
99 {
100     /**
101      * @tc.steps: step1. call CheckNeedRequestParentMeasure and set input is TEST_PROPERTY_UPDATE_MEASURE.
102      * @tc.expected: the return value is true.
103      */
104     bool retFlag = CheckNeedRequestParentMeasure(TEST_PROPERTY_UPDATE_MEASURE);
105     EXPECT_TRUE(retFlag);
106 
107     /**
108      * @tc.steps: step2. call CheckNeedRequestParentMeasure set input is TEST_PROPERTY_UPDATE_BY_CHILD_REQUEST.
109      * @tc.expected: the return value is true.
110      */
111     retFlag = CheckNeedRequestParentMeasure(TEST_PROPERTY_UPDATE_BY_CHILD_REQUEST);
112     EXPECT_TRUE(retFlag);
113 
114     /**
115      * @tc.steps: step3. call CheckNeedRequestParentMeasure set input is TEST_PROPERTY_UPDATE_MEASURE_SELF_AND_PARENT.
116      * @tc.expected: the return value is true.
117      */
118     retFlag = CheckNeedRequestParentMeasure(TEST_PROPERTY_UPDATE_MEASURE_SELF_AND_PARENT);
119     EXPECT_TRUE(retFlag);
120 
121     /**
122      * @tc.steps: step4. call CheckNeedRequestParentMeasure set input is TEST_PROPERTY_UPDATE_NORMAL.
123      * @tc.expected: the return value is false.
124      */
125     retFlag = CheckNeedRequestParentMeasure(TEST_PROPERTY_UPDATE_NORMAL);
126     EXPECT_FALSE(retFlag);
127 }
128 
129 /**
130  * @tc.name: PropertyTestNgTest004
131  * @tc.desc: Test CheckNeedMeasure funcation.
132  * @tc.type: FUNC
133  */
134 HWTEST_F(PropertyTestNg, PropertyTestNgTest004, TestSize.Level1)
135 {
136     /**
137      * @tc.steps: step1. call CheckNeedMeasure and set input is TEST_PROPERTY_UPDATE_MEASURE_SELF_AND_PARENT.
138      * @tc.expected: the return value is true.
139      */
140     bool retFlag = CheckNeedMeasure(TEST_PROPERTY_UPDATE_MEASURE_SELF_AND_PARENT);
141     EXPECT_TRUE(retFlag);
142 
143     /**
144      * @tc.steps: step2. call CheckNeedMeasure and set input is TEST_PROPERTY_UPDATE_MEASURE_SELF.
145      * @tc.expected: the return value is true.
146      */
147     retFlag = CheckNeedMeasure(TEST_PROPERTY_UPDATE_MEASURE_SELF);
148     EXPECT_TRUE(retFlag);
149 
150     /**
151      * @tc.steps: step3. call CheckNeedMeasure and set input is TEST_PROPERTY_UPDATE_MEASURE_SELF.
152      * @tc.expected: the return value is false.
153      */
154     retFlag = CheckNeedMeasure(TEST_PROPERTY_UPDATE_NORMAL);
155     EXPECT_FALSE(retFlag);
156 }
157 
158 /**
159  * @tc.name: PropertyTestNgTest005
160  * @tc.desc: Test CheckForceParentMeasureFlag funcation.
161  * @tc.type: FUNC
162  */
163 HWTEST_F(PropertyTestNg, PropertyTestNgTest005, TestSize.Level1)
164 {
165     /**
166      * @tc.steps: step1. call CheckForceParentMeasureFlag and set input is TEST_PROPERTY_UPDATE_MEASURE.
167      * @tc.expected: the return value is true.
168      */
169     bool retFlag = CheckForceParentMeasureFlag(TEST_PROPERTY_UPDATE_MEASURE);
170     EXPECT_TRUE(retFlag);
171 
172     /**
173      * @tc.steps: step2. call CheckForceParentMeasureFlag set input is TEST_PROPERTY_UPDATE_MEASURE_SELF_AND_PARENT.
174      * @tc.expected: the return value is true.
175      */
176     retFlag = CheckForceParentMeasureFlag(TEST_PROPERTY_UPDATE_MEASURE_SELF_AND_PARENT);
177     EXPECT_TRUE(retFlag);
178 
179     /**
180      * @tc.steps: step3. call CheckForceParentMeasureFlag and set input is TEST_PROPERTY_UPDATE_NORMAL.
181      * @tc.expected: the return value is false.
182      */
183     retFlag = CheckForceParentMeasureFlag(TEST_PROPERTY_UPDATE_NORMAL);
184     EXPECT_FALSE(retFlag);
185 }
186 
187 /**
188  * @tc.name: PropertyTestNgTest006
189  * @tc.desc: Test CheckUpdateByChildRequest funcation.
190  * @tc.type: FUNC
191  */
192 HWTEST_F(PropertyTestNg, PropertyTestNgTest006, TestSize.Level1)
193 {
194     /**
195      * @tc.steps: step1. call CheckUpdateByChildRequest and set input is TEST_PROPERTY_UPDATE_BY_CHILD_REQUEST.
196      * @tc.expected: step1. the return value is true.
197      */
198     bool retFlag = CheckUpdateByChildRequest(TEST_PROPERTY_UPDATE_BY_CHILD_REQUEST);
199     EXPECT_TRUE(retFlag);
200 
201     /**
202      * @tc.steps: step2. call CheckUpdateByChildRequest and set input is TEST_PROPERTY_UPDATE_NORMAL.
203      * @tc.expected: step2. the return value is false.
204      */
205     retFlag = CheckUpdateByChildRequest(TEST_PROPERTY_UPDATE_NORMAL);
206     EXPECT_FALSE(retFlag);
207 }
208 
209 /**
210  * @tc.name: PropertyTestNgTest007
211  * @tc.desc: Test CheckNoChanged funcation.
212  * @tc.type: FUNC
213  */
214 HWTEST_F(PropertyTestNg, PropertyTestNgTest007, TestSize.Level1)
215 {
216     /**
217      * @tc.steps: step1. call CheckNoChanged and set input is TEST_PROPERTY_UPDATE_MEASURE.
218      * @tc.expected: the return value is false.
219      */
220     bool retFlag = CheckNoChanged(TEST_PROPERTY_UPDATE_MEASURE);
221     EXPECT_FALSE(retFlag);
222 
223     /**
224      * @tc.steps: step2. call CheckNoChanged and set input is TEST_PROPERTY_UPDATE_NORMAL.
225      * @tc.expected: the return value is true.
226      */
227     retFlag = CheckNoChanged(TEST_PROPERTY_UPDATE_NORMAL);
228     EXPECT_TRUE(retFlag);
229 }
230 /**
231  * @tc.name: PropertyTestNgTest008
232  * @tc.desc: Test CheckNeedLayout funcation.
233  * @tc.type: FUNC
234  */
235 HWTEST_F(PropertyTestNg, PropertyTestNgTest008, TestSize.Level1)
236 {
237     /**
238      * @tc.steps: step1. call CheckNeedLayout and set input is TEST_PROPERTY_UPDATE_NORMAL.
239      * @tc.expected:the return value is false.
240      */
241     bool retFlag = CheckNeedLayout(TEST_PROPERTY_UPDATE_NORMAL);
242     EXPECT_FALSE(retFlag);
243 }
244 } // namespace OHOS::Ace::NG
245