• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "gtest/gtest.h"
16 
17 #define protected public
18 #define private public
19 
20 #include "base/log/ace_trace.h"
21 #include "core/components_ng/base/view_partial_update_model_ng.h"
22 #include "core/components_ng/base/view_stack_processor.h"
23 #include "core/components_ng/pattern/custom/custom_measure_layout_node.h"
24 #include "core/components_ng/pattern/custom/custom_title_node.h"
25 #include "core/components_ng/pattern/custom/custom_app_bar_node.h"
26 
27 using namespace testing;
28 using namespace testing::ext;
29 
30 namespace OHOS::Ace::NG {
31 class ViewPartialUpdateModelTestNg : public testing::Test {
32 public:
SetUpTestCase()33     static void SetUpTestCase() {}
TearDownTestCase()34     static void TearDownTestCase() {}
35 };
36 
37 /**
38  * @tc.name: ViewPartialUpdateModelTestNg001
39  * @tc.desc: Test the operation of view partial update model ng
40  * @tc.type: FUNC
41  */
42 HWTEST_F(ViewPartialUpdateModelTestNg, ViewPartialUpdateModelTestNg001, TestSize.Level1)
43 {
44     /**
45      * @tc.steps: step1. call the CreateNode function and set input is default value.
46      * @tc.expected: step1. info is default value and return expect value.
47      */
48     ViewPartialUpdateModelNG TestViewPartialUpdateModelNG;
49     NodeInfoPU info;
50 
51     RefPtr<AceType> customNode = TestViewPartialUpdateModelNG.CreateNode(std::move(info));
52     EXPECT_FALSE(info.isStatic);
53     EXPECT_TRUE(customNode);
54 }
55 
56 /**
57  * @tc.name: ViewPartialUpdateModelTestNg002
58  * @tc.desc: Test the operation of view partial update model ng
59  * @tc.type: FUNC
60  */
61 HWTEST_F(ViewPartialUpdateModelTestNg, ViewPartialUpdateModelTestNg002, TestSize.Level1)
62 {
63     /**
64      * @tc.steps: step1. call the CreateNode function and set info.updateViewIdFunc.
65      * @tc.expected: step1. info.updateViewIdFunc is not null and return expect value.
66      */
67     std::string viewIdStr;
68     ViewPartialUpdateModelNG TestViewPartialUpdateModelNG;
69 
__anon69f5dd460102(std::string viewId = "testViewIdStr") 70     auto updateViewNodeFunction = [&viewIdStr](std::string viewId = "testViewIdStr") { viewIdStr = viewId; };
71 
72     NodeInfoPU info = {
73         .updateViewIdFunc = std::move(updateViewNodeFunction),
74     };
75 
76     RefPtr<AceType> customNode = TestViewPartialUpdateModelNG.CreateNode(std::move(info));
77     EXPECT_NE(info.updateViewIdFunc, nullptr);
78     EXPECT_TRUE(customNode);
79 }
80 
81 /**
82  * @tc.name: ViewPartialUpdateModelTestNg003
83  * @tc.desc: Test the operation of view partial update model ng
84  * @tc.type: FUNC
85  */
86 HWTEST_F(ViewPartialUpdateModelTestNg, ViewPartialUpdateModelTestNg003, TestSize.Level1)
87 {
88     /**
89      * @tc.steps: step1. call the CreateNode function and set info.hasMeasureOrLayout is true.
90      * @tc.expected: step1. info.hasMeasureOrLayout is true and return expect value.
91      */
92     std::string viewIdStr;
93 
94     ViewPartialUpdateModelNG TestViewPartialUpdateModelNG;
95 
__anon69f5dd460202(std::string viewId = "testViewIdStr") 96     auto updateViewNodeFunction = [&viewIdStr](std::string viewId = "testViewIdStr") { viewIdStr = viewId; };
97 
98     NodeInfoPU info = {
99         .updateViewIdFunc = std::move(updateViewNodeFunction),
100         .hasMeasureOrLayout = true,
101     };
102 
103     RefPtr<AceType> customNode = TestViewPartialUpdateModelNG.CreateNode(std::move(info));
104     EXPECT_TRUE(info.hasMeasureOrLayout);
105     EXPECT_TRUE(customNode);
106 }
107 
108 /**
109  * @tc.name: ViewPartialUpdateModelTestNg004
110  * @tc.desc: Test the operation of view partial update model ng
111  * @tc.type: FUNC
112  */
113 HWTEST_F(ViewPartialUpdateModelTestNg, ViewPartialUpdateModelTestNg004, TestSize.Level1)
114 {
115     /**
116      * @tc.steps: step1. call the CreateNode function and set info.measureFunc.
117      * @tc.expected: step1. info.measureFunc is not null and return expect value.
118      */
119     std::string viewIdStr;
120     NG::LayoutWrapper* testMeasureFun;
121     ViewPartialUpdateModelNG TestViewPartialUpdateModelNG;
122 
__anon69f5dd460302(std::string viewId = "testViewIdStr") 123     auto updateViewNodeFunction = [&viewIdStr](std::string viewId = "testViewIdStr") { viewIdStr = viewId; };
124     auto measureFuncation = [&testMeasureFun](
__anon69f5dd460402( NG::LayoutWrapper* layoutWrapper = nullptr) 125                                 NG::LayoutWrapper* layoutWrapper = nullptr) { testMeasureFun = layoutWrapper; };
126 
127     NodeInfoPU info = {
128         .updateViewIdFunc = std::move(updateViewNodeFunction),
129         .measureFunc = std::move(measureFuncation),
130         .hasMeasureOrLayout = true,
131     };
132 
133     RefPtr<AceType> customNode = TestViewPartialUpdateModelNG.CreateNode(std::move(info));
134     EXPECT_NE(info.measureFunc, nullptr);
135     EXPECT_TRUE(customNode);
136 }
137 
138 /**
139  * @tc.name: ViewPartialUpdateModelTestNg005
140  * @tc.desc: Test the operation of view partial update model ng
141  * @tc.type: FUNC
142  */
143 HWTEST_F(ViewPartialUpdateModelTestNg, ViewPartialUpdateModelTestNg005, TestSize.Level1)
144 {
145     /**
146      * @tc.steps: step1. call the CreateNode function and set info.layoutFunc.
147      * @tc.expected: step1. info.layoutFunc is not null and return expect value.
148      */
149     std::string viewIdStr;
150     NG::LayoutWrapper* testMeasureFun;
151     NG::LayoutWrapper* testLayoutFunc;
152 
153     ViewPartialUpdateModelNG TestViewPartialUpdateModelNG;
154 
__anon69f5dd460502(std::string viewId = "testViewIdStr") 155     auto updateViewNodeFunction = [&viewIdStr](std::string viewId = "testViewIdStr") { viewIdStr = viewId; };
156     auto measureFuncation = [&testMeasureFun](
__anon69f5dd460602( NG::LayoutWrapper* layoutWrapper = nullptr) 157                                 NG::LayoutWrapper* layoutWrapper = nullptr) { testMeasureFun = layoutWrapper; };
158     auto layoutFuncation = [&testLayoutFunc](
__anon69f5dd460702( NG::LayoutWrapper* layoutWrapper = nullptr) 159                                NG::LayoutWrapper* layoutWrapper = nullptr) { testLayoutFunc = layoutWrapper; };
160 
161     NodeInfoPU info = {
162         .updateViewIdFunc = std::move(updateViewNodeFunction),
163         .measureFunc = std::move(measureFuncation),
164         .layoutFunc = std::move(layoutFuncation),
165         .hasMeasureOrLayout = true,
166     };
167 
168     RefPtr<AceType> customNode = TestViewPartialUpdateModelNG.CreateNode(std::move(info));
169     EXPECT_NE(info.layoutFunc, nullptr);
170     EXPECT_TRUE(customNode);
171 }
172 
173 /**
174  * @tc.name: ViewPartialUpdateModelTestNg006
175  * @tc.desc: Test the operation of view partial update model ng
176  * @tc.type: FUNC
177  */
178 HWTEST_F(ViewPartialUpdateModelTestNg, ViewPartialUpdateModelTestNg006, TestSize.Level1)
179 {
180     /**
181      * @tc.steps: step1. call the CreateNode function and set info.updateNodeFunc.
182      * @tc.expected: step1. info.updateNodeFunc is not null and return expect value.
183      */
184     std::string viewIdStr;
185     NG::LayoutWrapper* testMeasureFun;
186     NG::LayoutWrapper* testLayoutFunc;
187     WeakPtr<AceType> testUpdateNodeFunc;
188 
189     ViewPartialUpdateModelNG TestViewPartialUpdateModelNG;
190 
__anon69f5dd460802(std::string viewId = "testViewIdStr") 191     auto updateViewNodeFunction = [&viewIdStr](std::string viewId = "testViewIdStr") { viewIdStr = viewId; };
192     auto measureFuncation = [&testMeasureFun](
__anon69f5dd460902( NG::LayoutWrapper* layoutWrapper = nullptr) 193                                 NG::LayoutWrapper* layoutWrapper = nullptr) { testMeasureFun = layoutWrapper; };
194     auto layoutFuncation = [&testLayoutFunc](
__anon69f5dd460a02( NG::LayoutWrapper* layoutWrapper = nullptr) 195                                NG::LayoutWrapper* layoutWrapper = nullptr) { testLayoutFunc = layoutWrapper; };
196     auto updateNodeFuncation = [&testUpdateNodeFunc](
__anon69f5dd460b02( const RefPtr<AceType>& type = nullptr) 197                                    const RefPtr<AceType>& type = nullptr) { testUpdateNodeFunc = type; };
198 
199     NodeInfoPU info = {
200         .updateNodeFunc = std::move(updateNodeFuncation),
201         .updateViewIdFunc = std::move(updateViewNodeFunction),
202         .measureFunc = std::move(measureFuncation),
203         .layoutFunc = std::move(layoutFuncation),
204         .hasMeasureOrLayout = true,
205     };
206 
207     RefPtr<AceType> customNode = TestViewPartialUpdateModelNG.CreateNode(std::move(info));
208     EXPECT_NE(info.updateNodeFunc, nullptr);
209     EXPECT_TRUE(customNode);
210 }
211 
212 /**
213  * @tc.name: ViewPartialUpdateModelTestNg007
214  * @tc.desc: Test the operation of view partial update model ng
215  * @tc.type: FUNC
216  */
217 HWTEST_F(ViewPartialUpdateModelTestNg, ViewPartialUpdateModelTestNg007, TestSize.Level1)
218 {
219     /**
220      * @tc.steps: step1. call the CreateNode function and set info.updateNodeFunc.
221      * @tc.expected: step1. info.updateNodeFunc is not null and return expect value.
222      */
223     std::string viewIdStr;
224     NG::LayoutWrapper* testMeasureFun;
225     NG::LayoutWrapper* testLayoutFunc;
226     WeakPtr<AceType> testUpdateNodeFunc;
227     WeakPtr<AceType> testRenderfunc;
228 
229     ViewPartialUpdateModelNG TestViewPartialUpdateModelNG;
230 
__anon69f5dd460c02(std::string viewId = "testViewIdStr") 231     auto updateViewNodeFunction = [&viewIdStr](std::string viewId = "testViewIdStr") { viewIdStr = viewId; };
232     auto measureFuncation = [&testMeasureFun](
__anon69f5dd460d02( NG::LayoutWrapper* layoutWrapper = nullptr) 233                                 NG::LayoutWrapper* layoutWrapper = nullptr) { testMeasureFun = layoutWrapper; };
234     auto layoutFuncation = [&testLayoutFunc](
__anon69f5dd460e02( NG::LayoutWrapper* layoutWrapper = nullptr) 235                                NG::LayoutWrapper* layoutWrapper = nullptr) { testLayoutFunc = layoutWrapper; };
236     auto updateNodeFuncation = [&testUpdateNodeFunc](
__anon69f5dd460f02( const RefPtr<AceType>& type = nullptr) 237                                    const RefPtr<AceType>& type = nullptr) { testUpdateNodeFunc = type; };
__anon69f5dd461002(int64_t deadline, bool& isTimeout) 238     auto renderFunction = [&testRenderfunc](int64_t deadline, bool& isTimeout) -> RefPtr<AceType> { return nullptr; };
239 
240     NodeInfoPU info = {
241         .renderFunc = renderFunction,
242         .updateNodeFunc = std::move(updateNodeFuncation),
243         .updateViewIdFunc = std::move(updateViewNodeFunction),
244         .measureFunc = std::move(measureFuncation),
245         .layoutFunc = std::move(layoutFuncation),
246         .hasMeasureOrLayout = true,
247     };
248 
249     RefPtr<AceType> customNode = TestViewPartialUpdateModelNG.CreateNode(std::move(info));
250     EXPECT_NE(info.renderFunc, nullptr);
251     EXPECT_TRUE(customNode);
252 }
253 
254 /**
255  * @tc.name: ViewPartialUpdateModelTestNg008
256  * @tc.desc: Test the operation of view partial update model ng
257  * @tc.type: FUNC
258  */
259 HWTEST_F(ViewPartialUpdateModelTestNg, ViewPartialUpdateModelTestNg008, TestSize.Level1)
260 {
261     /**
262      * @tc.steps: step1. call the MarkNeedUpdate function first and set input is null.
263      * @tc.expected: step1. the return value is false.
264      */
265     const WeakPtr<AceType>& nullNode = nullptr;
266     ViewPartialUpdateModelNG TestViewPartialUpdateModelNG;
267 
268     bool testcustomNode = TestViewPartialUpdateModelNG.MarkNeedUpdate(nullNode);
269     EXPECT_FALSE(testcustomNode);
270 
271     /**
272      * @tc.steps: step2. call the MarkNeedUpdate function again and set input is not null.
273      * @tc.expected: step2. the return value is true.
274      */
275     NodeInfoPU info;
276     RefPtr<AceType> customNode = TestViewPartialUpdateModelNG.CreateNode(std::move(info));
277 
278     testcustomNode = TestViewPartialUpdateModelNG.MarkNeedUpdate(customNode);
279     EXPECT_TRUE(testcustomNode);
280 }
281 
282 /**
283  * @tc.name: ViewPartialUpdateModelTestNg009
284  * @tc.desc: Test the operation of view partial update model ng
285  * @tc.type: FUNC
286  */
287 HWTEST_F(ViewPartialUpdateModelTestNg, ViewPartialUpdateModelTestNg009, TestSize.Level1)
288 {
289     /**
290      * @tc.steps: step1. call the FinishUpdate function.
291      * @tc.expected: step1. the FinishUpdate function is run ok.
292      */
293     const WeakPtr<AceType>& viewNode = nullptr;
294     ViewPartialUpdateModelNG TestViewPartialUpdateModelNG;
295 
__anon69f5dd461102(const UpdateTask& task) 296     TestViewPartialUpdateModelNG.FinishUpdate(viewNode, 1, [](const UpdateTask& task) {});
297     auto stack = NG::ViewStackProcessor::GetInstance()->elementsStack_;
298     EXPECT_TRUE(stack.empty());
299 }
300 
301 /**
302  * @tc.name: ViewPartialUpdateModelTestNg010
303  * @tc.desc: Test the operation of view partial update model ng
304  * @tc.type: FUNC
305  */
306 HWTEST_F(ViewPartialUpdateModelTestNg, ViewPartialUpdateModelTestNg010, TestSize.Level1)
307 {
308     /**
309      * @tc.steps: step1. call the CreateNode function and set info.updateNodeFunc.
310      * @tc.expected: step1. info.updateNodeFunc is not null and return expect value.
311      */
312     std::string viewIdStr;
313     NG::LayoutWrapper* testMeasureFun;
314     NG::LayoutWrapper* testLayoutFunc;
315     WeakPtr<AceType> testUpdateNodeFunc;
316     WeakPtr<AceType> testRenderfunc;
317 
318     ViewPartialUpdateModelNG TestViewPartialUpdateModelNG;
319 
__anon69f5dd461202(std::string viewId = "testViewIdStr") 320     auto updateViewNodeFunction = [&viewIdStr](std::string viewId = "testViewIdStr") { viewIdStr = viewId; };
321     auto measureFuncation = [&testMeasureFun](
__anon69f5dd461302( NG::LayoutWrapper* layoutWrapper = nullptr) 322                                 NG::LayoutWrapper* layoutWrapper = nullptr) { testMeasureFun = layoutWrapper; };
323     auto layoutFuncation = [&testLayoutFunc](
__anon69f5dd461402( NG::LayoutWrapper* layoutWrapper = nullptr) 324                                NG::LayoutWrapper* layoutWrapper = nullptr) { testLayoutFunc = layoutWrapper; };
325     auto updateNodeFuncation = [&testUpdateNodeFunc](
__anon69f5dd461502( const RefPtr<AceType>& type = nullptr) 326                                    const RefPtr<AceType>& type = nullptr) { testUpdateNodeFunc = type; };
__anon69f5dd461602(int64_t deadline, bool& isTimeout) 327     auto renderFunction = [&testRenderfunc](int64_t deadline, bool& isTimeout) -> RefPtr<AceType> { return nullptr; };
328 
329     NodeInfoPU info = {
330         .renderFunc = renderFunction,
331         .updateNodeFunc = std::move(updateNodeFuncation),
332         .updateViewIdFunc = std::move(updateViewNodeFunction),
333         .measureFunc = std::move(measureFuncation),
334         .layoutFunc = std::move(layoutFuncation),
335         .hasMeasureOrLayout = false,
336         .isCustomTitle = true,
337     };
338 
339     RefPtr<AceType> customNode = TestViewPartialUpdateModelNG.CreateNode(std::move(info));
340     EXPECT_NE(info.renderFunc, nullptr);
341     EXPECT_TRUE(customNode);
342 }
343 
344 /**
345  * @tc.name: ViewPartialUpdateModelTestNg011
346  * @tc.desc: Test the operation of view partial update model ng
347  * @tc.type: FUNC
348  */
349 HWTEST_F(ViewPartialUpdateModelTestNg, ViewPartialUpdateModelTestNg011, TestSize.Level1)
350 {
351     /**
352      * @tc.steps: step1. call the CreateNode function and set info.updateNodeFunc.
353      * @tc.expected: step1. info.updateNodeFunc is not null and return expect value.
354      */
355     std::string viewIdStr;
356     NG::LayoutWrapper* testLayoutFunc;
357     NG::LayoutWrapper* testMeasure;
358     WeakPtr<AceType> testUpdateNodeFunc;
359     WeakPtr<AceType> testRenderfunc;
360 
361     ViewPartialUpdateModelNG TestViewPartialUpdateModelNG;
362 
__anon69f5dd461702(std::string viewId = "testViewIdStr") 363     auto updateViewNodeFunction = [&viewIdStr](std::string viewId = "testViewIdStr") { viewIdStr = viewId; };
364     auto layoutFuncation = [&testLayoutFunc](
__anon69f5dd461802( NG::LayoutWrapper* layoutWrapper = nullptr) 365                                NG::LayoutWrapper* layoutWrapper = nullptr) { testLayoutFunc = layoutWrapper; };
366     auto updateNodeFuncation = [&testUpdateNodeFunc](
__anon69f5dd461902( const RefPtr<AceType>& type = nullptr) 367                                    const RefPtr<AceType>& type = nullptr) { testUpdateNodeFunc = type; };
__anon69f5dd461a02(int64_t deadline, bool& isTimeout) 368     auto renderFunction = [&testRenderfunc](int64_t deadline, bool& isTimeout) -> RefPtr<AceType> { return nullptr; };
__anon69f5dd461b02(NG::LayoutWrapper* testMeasureWrapper = nullptr) 369     auto measureSizeFunction = [&testMeasure](NG::LayoutWrapper* testMeasureWrapper = nullptr) {
370         testMeasure = testMeasureWrapper;
371     };
372     NodeInfoPU info = {
373         .renderFunc = renderFunction,
374         .updateNodeFunc = std::move(updateNodeFuncation),
375         .updateViewIdFunc = std::move(updateViewNodeFunction),
376         .layoutFunc = std::move(layoutFuncation),
377         .measureSizeFunc = std::move(measureSizeFunction),
378         .hasMeasureOrLayout = true,
379         .isCustomTitle = false,
380     };
381 
382     RefPtr<AceType> customNode = TestViewPartialUpdateModelNG.CreateNode(std::move(info));
383     EXPECT_NE(info.renderFunc, nullptr);
384     EXPECT_TRUE(customNode);
385 }
386 
387 /**
388  * @tc.name: ViewPartialUpdateModelTestNg012
389  * @tc.desc: Test the operation of view partial update model ng
390  * @tc.type: FUNC
391  */
392 HWTEST_F(ViewPartialUpdateModelTestNg, ViewPartialUpdateModelTestNg012, TestSize.Level1)
393 {
394     /**
395      * @tc.steps: step1. call the CreateNode function and set info.updateNodeFunc.
396      * @tc.expected: step1. info.updateNodeFunc is not null and return expect value.
397      */
398     std::string viewIdStr;
399     NG::LayoutWrapper* testLayoutFunc;
400     NG::LayoutWrapper* testPlaceChildrenFunc;
401     WeakPtr<AceType> testUpdateNodeFunc;
402     WeakPtr<AceType> testRenderfunc;
403 
404     ViewPartialUpdateModelNG TestViewPartialUpdateModelNG;
405 
__anon69f5dd461c02(std::string viewId = "testViewIdStr") 406     auto updateViewNodeFunction = [&viewIdStr](std::string viewId = "testViewIdStr") { viewIdStr = viewId; };
407     auto layoutFuncation = [&testLayoutFunc](
__anon69f5dd461d02( NG::LayoutWrapper* layoutWrapper = nullptr) 408                                NG::LayoutWrapper* layoutWrapper = nullptr) { testLayoutFunc = layoutWrapper; };
409     auto updateNodeFuncation = [&testUpdateNodeFunc](
__anon69f5dd461e02( const RefPtr<AceType>& type = nullptr) 410                                    const RefPtr<AceType>& type = nullptr) { testUpdateNodeFunc = type; };
__anon69f5dd461f02(int64_t deadline, bool& isTimeout) 411     auto renderFunction = [&testRenderfunc](int64_t deadline, bool& isTimeout) -> RefPtr<AceType> { return nullptr; };
__anon69f5dd462002(NG::LayoutWrapper* testPlaceChildrenFuncWrapper = nullptr) 412     auto placeChildrenFunction = [&testPlaceChildrenFunc](NG::LayoutWrapper* testPlaceChildrenFuncWrapper = nullptr) {
413         testPlaceChildrenFunc = testPlaceChildrenFuncWrapper;
414     };
415     NodeInfoPU info = {
416         .renderFunc = renderFunction,
417         .updateNodeFunc = std::move(updateNodeFuncation),
418         .updateViewIdFunc = std::move(updateViewNodeFunction),
419         .layoutFunc = std::move(layoutFuncation),
420         .placeChildrenFunc = std::move(placeChildrenFunction),
421         .hasMeasureOrLayout = true,
422         .isCustomTitle = false,
423     };
424 
425     RefPtr<AceType> customNode = TestViewPartialUpdateModelNG.CreateNode(std::move(info));
426     EXPECT_NE(info.renderFunc, nullptr);
427     EXPECT_TRUE(customNode);
428 }
429 } // namespace OHOS::Ace::NG