1 /*
2 * Copyright (c) 2023 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 <cstddef>
17 #include <utility>
18
19 #include "gtest/gtest.h"
20 #define private public
21 #include "test/mock/core/pipeline/mock_pipeline_context.h"
22
23 #include "core/components_ng/base/view_stack_processor.h"
24 #include "core/components_ng/layout/layout_wrapper.h"
25 #include "core/components_ng/pattern/custom/custom_measure_layout_node.h"
26 #include "core/components_ng/pattern/custom/custom_measure_layout_param.h"
27 #include "core/components_ng/pattern/custom/custom_node.h"
28 #include "core/components_ng/pattern/custom/custom_node_base.h"
29 #include "core/components_ng/pattern/custom/custom_node_pattern.h"
30 #include "core/components_ng/pattern/custom/custom_title_node.h"
31 #include "core/components_ng/pattern/tabs/tab_content_pattern.h"
32
33 using namespace testing;
34 using namespace testing::ext;
35
36 namespace OHOS::Ace::NG {
37 namespace {
38 const std::string TEST_TAG("test");
39 constexpr int32_t CHILD_COUNT_0 = 0;
40 constexpr int32_t CHILD_COUNT_1 = 1;
41 } // namespace
42
43 class CustomTestNg : public testing::Test {
44 public:
SetUpTestSuite()45 static void SetUpTestSuite() {};
TearDownTestSuite()46 static void TearDownTestSuite() {};
47 void SetUp() override;
48 void TearDown() override;
49 RefPtr<FrameNode> CreateNode(const std::string& tag);
50 };
SetUp()51 void CustomTestNg::SetUp()
52 {
53 MockPipelineContext::SetUp();
54 }
55
TearDown()56 void CustomTestNg::TearDown()
57 {
58 MockPipelineContext::TearDown();
59 }
60
CreateNode(const std::string & tag)61 RefPtr<FrameNode> CustomTestNg::CreateNode(const std::string& tag)
62 {
63 auto pattern = AceType::MakeRefPtr<Pattern>();
64 auto frameNode = AceType::MakeRefPtr<FrameNode>(tag, -1, pattern);
65 pattern->AttachToFrameNode(frameNode);
66 ViewStackProcessor::GetInstance()->Push(frameNode);
67 return frameNode;
68 }
69
70 /**
71 * @tc.name: CustomTest001
72 * @tc.desc: Create Custom node and parent is not tabContent.
73 * @tc.type: FUNC
74 */
75 HWTEST_F(CustomTestNg, CustomTest001, TestSize.Level1)
76 {
77 /**
78 * @tc.steps: step1. Create Text and push it to view stack processor.
79 * @tc.expected: Make Text as CustomNode parent.
80 */
81 auto frameNode = CreateNode(V2::TEXT_ETS_TAG);
82
83 /**
84 * @tc.steps: step2. Invoke CustomNode Create function.
85 * @tc.expected: Create CustomNode.
86 */
87 auto customNode = CustomNode::CreateCustomNode(ElementRegister::GetInstance()->MakeUniqueId(), TEST_TAG);
88 EXPECT_TRUE(customNode != nullptr && customNode->GetTag() == V2::JS_VIEW_ETS_TAG);
89
90 /**
91 * @tc.steps: step3. Create Parent LayoutWrapperNode.
92 */
93 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
94 ASSERT_NE(geometryNode, nullptr);
95 auto parentLayoutWrapper =
96 AceType::MakeRefPtr<LayoutWrapperNode>(frameNode, geometryNode, frameNode->GetLayoutProperty());
97 /**
98 * @tc.steps: step4. Invoke Build and AdjustLayoutWrapperTree.
99 * @tc.expected: parentLayoutWrapper's childCount is zero.
100 */
101 customNode->Build(nullptr);
102 customNode->AdjustLayoutWrapperTree(parentLayoutWrapper, false, false);
103 EXPECT_EQ(parentLayoutWrapper->GetTotalChildCount(), CHILD_COUNT_0);
104
105 RefPtr<AceType> view;
__anon71f9752b0202() 106 auto renderFunc = [&view]() -> RefPtr<AceType> { return nullptr; };
__anon71f9752b0302() 107 auto renderFunction = [internalRender = std::move(renderFunc)]() -> RefPtr<UINode> {
108 auto uiNode = internalRender();
109 return AceType::DynamicCast<UINode>(uiNode);
110 };
111 customNode->SetRenderFunction(std::move(renderFunction));
112 customNode->Build(nullptr);
113 customNode->AdjustLayoutWrapperTree(parentLayoutWrapper, false, false);
114 EXPECT_EQ(parentLayoutWrapper->GetTotalChildCount(), CHILD_COUNT_0);
115 }
116
117 /**
118 * @tc.name: CustomTest002
119 * @tc.desc: Create Custom node and parent is tabContent.
120 * @tc.type: FUNC
121 */
122 HWTEST_F(CustomTestNg, CustomTest002, TestSize.Level1)
123 {
124 /**
125 * @tc.steps: step1. Create TabContent and push it to view stack processor.
126 * @tc.expected: Make TabContent as CustomNode parent.
127 */
128 auto frameNode = CreateNode(V2::TAB_CONTENT_ITEM_ETS_TAG);
129
130 /**
131 * @tc.steps: step2. Invoke CustomNode Create function.
132 * @tc.expected: Create CustomNode.
133 */
134 auto customNode = CustomNode::CreateCustomNode(ElementRegister::GetInstance()->MakeUniqueId(), TEST_TAG);
135 EXPECT_TRUE(customNode != nullptr && customNode->GetTag() == V2::JS_VIEW_ETS_TAG);
136
137 /**
138 * @tc.steps: step3. Create Parent LayoutWrapperNode.
139 */
140 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
141 ASSERT_NE(geometryNode, nullptr);
142 auto parentLayoutWrapper =
143 AceType::MakeRefPtr<LayoutWrapperNode>(frameNode, geometryNode, frameNode->GetLayoutProperty());
144 /**
145 * @tc.steps: step4. Invoke Build and AdjustLayoutWrapperTree.
146 * @tc.expected: parentLayoutWrapper's childCount is zero.
147 */
148 customNode->Build(nullptr);
149 customNode->AdjustLayoutWrapperTree(parentLayoutWrapper, false, false);
150 EXPECT_EQ(parentLayoutWrapper->GetTotalChildCount(), CHILD_COUNT_0);
151
152 RefPtr<AceType> view;
__anon71f9752b0402() 153 auto renderFunc = [&view]() -> RefPtr<AceType> { return nullptr; };
__anon71f9752b0502() 154 auto renderFunction = [internalRender = std::move(renderFunc)]() -> RefPtr<UINode> {
155 auto uiNode = internalRender();
156 return AceType::DynamicCast<UINode>(uiNode);
157 };
158 customNode->SetRenderFunction(std::move(renderFunction));
159 customNode->Build(nullptr);
160 customNode->AdjustLayoutWrapperTree(parentLayoutWrapper, false, false);
161 EXPECT_EQ(parentLayoutWrapper->GetTotalChildCount(), CHILD_COUNT_0);
162 }
163
164 /**
165 * @tc.name: CustomTest003
166 * @tc.desc: Create CustomMeasureLayoutNode and test fireOnMeasure and fireOnLayout.
167 * @tc.type: FUNC
168 */
169 HWTEST_F(CustomTestNg, CustomTest003, TestSize.Level1)
170 {
171 /**
172 * @tc.steps: step1. Create TabContent and push it to view stack processor.
173 * @tc.expected: Make TabContent as CustomNode parent.
174 */
175 auto frameNode = CreateNode(V2::TAB_CONTENT_ITEM_ETS_TAG);
176
177 /**
178 * @tc.steps: step2. Invoke CustomNode Create function.
179 * @tc.expected: Create CustomNode.
180 */
181 auto customNode = CustomMeasureLayoutNode::CreateCustomMeasureLayoutNode(
182 ElementRegister::GetInstance()->MakeUniqueId(), TEST_TAG);
183 EXPECT_TRUE(customNode != nullptr && customNode->GetTag() == V2::JS_VIEW_ETS_TAG);
184
185 customNode->MountToParent(frameNode);
186
187 auto textFrameNode = CreateNode(V2::TEXT_ETS_TAG);
188 textFrameNode->MountToParent(customNode);
189
190 /**
191 * @tc.steps: step3. Create Parent LayoutWrapperNode.
192 */
193 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
194 ASSERT_NE(geometryNode, nullptr);
195 auto parentLayoutWrapper = LayoutWrapperNode(frameNode, geometryNode, frameNode->GetLayoutProperty());
196 /**
197 * @tc.steps: step4. set measureFuncation and layoutFuncation and FireOnMeasure and FireOnLayout.
198 * @tc.expected: FireOnMeasure and FireOnLayout return correct value.
199 */
200 RefPtr<AceType> view;
__anon71f9752b0602() 201 auto renderFunc = [&view]() -> RefPtr<AceType> { return nullptr; };
__anon71f9752b0702() 202 auto renderFunction = [internalRender = std::move(renderFunc)]() -> RefPtr<UINode> {
203 auto uiNode = internalRender();
204 return AceType::DynamicCast<UINode>(uiNode);
205 };
206 customNode->SetRenderFunction(std::move(renderFunction));
207
208 RefPtr<GeometryNode> customGeometryNode = AceType::MakeRefPtr<GeometryNode>();
209 auto pattern = customNode->GetPattern<CustomNodePattern>();
210 ASSERT_NE(pattern, nullptr);
211 auto customLayoutAlgorithm = pattern->CreateLayoutAlgorithm();
212 ASSERT_NE(customLayoutAlgorithm, nullptr);
213 auto customLayoutWrapper =
214 AceType::MakeRefPtr<LayoutWrapperNode>(customNode, geometryNode, customNode->GetLayoutProperty());
215
216 EXPECT_FALSE(customLayoutWrapper == nullptr);
217 customLayoutWrapper->SetLayoutAlgorithm(AceType::MakeRefPtr<LayoutAlgorithmWrapper>(customLayoutAlgorithm));
218 parentLayoutWrapper.AppendChild(customLayoutWrapper);
219
220 auto fireOnMeasure = customNode->FireOnMeasure(&parentLayoutWrapper);
221 auto fireOnLayout = customNode->FireOnLayout(&parentLayoutWrapper);
222 EXPECT_EQ(fireOnMeasure, false);
223 EXPECT_EQ(fireOnLayout, false);
224
225 NG::LayoutWrapper* testMeasureFun;
226 NG::LayoutWrapper* testLayoutFunc;
227
228 auto measureFuncation = [&testMeasureFun](
__anon71f9752b0802( NG::LayoutWrapper* layoutWrapper = nullptr) 229 NG::LayoutWrapper* layoutWrapper = nullptr) { testMeasureFun = layoutWrapper; };
230 auto layoutFuncation = [&testLayoutFunc](
__anon71f9752b0902( NG::LayoutWrapper* layoutWrapper = nullptr) 231 NG::LayoutWrapper* layoutWrapper = nullptr) { testLayoutFunc = layoutWrapper; };
232 customNode->SetMeasureFunction(std::move(measureFuncation));
233 customNode->SetLayoutFunction(std::move(layoutFuncation));
234 fireOnMeasure = customNode->FireOnMeasure(&parentLayoutWrapper);
235 fireOnLayout = customNode->FireOnLayout(&parentLayoutWrapper);
236 EXPECT_EQ(fireOnMeasure, true);
237 EXPECT_EQ(fireOnLayout, true);
238 }
239
240 /**
241 * @tc.name: CustomTest004
242 * @tc.desc: Create Custom node and test MarkNeedUpdate and Update.
243 * @tc.type: FUNC
244 */
245 HWTEST_F(CustomTestNg, CustomTest004, TestSize.Level1)
246 {
247 /**
248 * @tc.steps: step1. Create TabContent and push it to view stack processor.
249 * @tc.expected: Make TabContent as CustomNode parent.
250 */
251 auto frameNode = CreateNode(V2::TAB_CONTENT_ITEM_ETS_TAG);
252
253 /**
254 * @tc.steps: step2. Invoke CustomNode Create function.
255 * @tc.expected: Create CustomNode.
256 */
257 auto customNode = CustomNode::CreateCustomNode(ElementRegister::GetInstance()->MakeUniqueId(), TEST_TAG);
258 EXPECT_TRUE(customNode != nullptr && customNode->GetTag() == V2::JS_VIEW_ETS_TAG);
259
260 /**
261 * @tc.steps: step3. Create Parent LayoutWrapperNode.
262 */
263 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
264 ASSERT_NE(geometryNode, nullptr);
265 auto parentLayoutWrapper =
266 AceType::MakeRefPtr<LayoutWrapperNode>(frameNode, geometryNode, frameNode->GetLayoutProperty());
267 /**
268 * @tc.steps: step4. set DestroyFunction and UpdateFunction, invoke Update and MarkNeedUpdate function.
269 * @tc.expected: parentLayoutWrapper's childCount is zero.
270 */
271 bool destroyFunc = false;
__anon71f9752b0a02() 272 customNode->SetDestroyFunction([&destroyFunc]() { destroyFunc = true; });
273 customNode->Update();
274 bool updateFunc = false;
__anon71f9752b0b02() 275 customNode->SetUpdateFunction([&updateFunc]() { updateFunc = true; });
276 customNode->Update();
277 customNode->MarkNeedUpdate();
278 customNode->MarkNeedUpdate();
279 customNode->AdjustLayoutWrapperTree(parentLayoutWrapper, false, false);
280 EXPECT_EQ(parentLayoutWrapper->GetTotalChildCount(), CHILD_COUNT_0);
281 }
282
283 /**
284 * @tc.name: CustomTest005
285 * @tc.desc: Create Custom node.
286 * @tc.type: FUNC
287 */
288 HWTEST_F(CustomTestNg, CustomTest005, TestSize.Level1)
289 {
290 /**
291 * @tc.steps: step1. Create TabContent and push it to view stack processor.
292 * @tc.expected: Make TabContent as CustomNode parent.
293 */
294 auto frameNode = CreateNode(V2::TAB_CONTENT_ITEM_ETS_TAG);
295
296 /**
297 * @tc.steps: step2. Invoke CustomNode Create function.
298 * @tc.expected: Create CustomNode.
299 */
300 auto customNode = CustomNode::CreateCustomNode(ElementRegister::GetInstance()->MakeUniqueId(), TEST_TAG);
301 EXPECT_TRUE(customNode != nullptr && customNode->GetTag() == V2::JS_VIEW_ETS_TAG);
302
303 /**
304 * @tc.steps: step3. Create Parent LayoutWrapperNode.
305 */
306 auto pattern = frameNode->GetPattern<Pattern>();
307 ASSERT_NE(pattern, nullptr);
308 auto layoutAlgorithm = pattern->CreateLayoutAlgorithm();
309 EXPECT_FALSE(layoutAlgorithm == nullptr);
310 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
311 ASSERT_NE(geometryNode, nullptr);
312 auto parentLayoutWrapper =
313 AceType::MakeRefPtr<LayoutWrapperNode>(frameNode, geometryNode, frameNode->GetLayoutProperty());
314 /**
315 * @tc.steps: step4. set renderFunction, add child to customNode and invoke Measure function.
316 * @tc.expected: parentLayoutWrapper's childCount is one.
317 */
318 RefPtr<AceType> view;
__anon71f9752b0c02() 319 auto renderFunc = [&view]() -> RefPtr<AceType> { return nullptr; };
__anon71f9752b0d02() 320 auto renderFunction = [internalRender = std::move(renderFunc)]() -> RefPtr<UINode> {
321 auto uiNode = internalRender();
322 return AceType::DynamicCast<UINode>(uiNode);
323 };
324 customNode->SetRenderFunction(std::move(renderFunction));
325 customNode->AdjustLayoutWrapperTree(parentLayoutWrapper, false, false);
326
327 auto textFrameNode = CreateNode(V2::TEXT_ETS_TAG);
328 textFrameNode->MountToParent(customNode);
329 layoutAlgorithm->Measure(AceType::RawPtr(parentLayoutWrapper));
330 EXPECT_EQ(parentLayoutWrapper->GetTotalChildCount(), CHILD_COUNT_1);
331 }
332
333 /**
334 * @tc.name: CustomTest006
335 * @tc.desc: Create CustomNode and child node is CustomNode and test AdjustLayoutWrapperTree.
336 * @tc.type: FUNC
337 */
338 HWTEST_F(CustomTestNg, CustomTest006, TestSize.Level1)
339 {
340 /**
341 * @tc.steps: step1. Create TabContent and push it to view stack processor.
342 * @tc.expected: Make TabContent as CustomNode parent.
343 */
344 auto frameNode = CreateNode(V2::TAB_CONTENT_ITEM_ETS_TAG);
345
346 /**
347 * @tc.steps: step2. Invoke CustomNode Create function and another CustomNode mount to CustomNode.
348 * @tc.expected: Create CustomNode.
349 */
350 auto customNode = CustomNode::CreateCustomNode(ElementRegister::GetInstance()->MakeUniqueId(), TEST_TAG);
351 EXPECT_TRUE(customNode != nullptr && customNode->GetTag() == V2::JS_VIEW_ETS_TAG);
352
353 auto childCustomNode = CustomNode::CreateCustomNode(ElementRegister::GetInstance()->MakeUniqueId(), TEST_TAG);
354 EXPECT_TRUE(childCustomNode != nullptr && childCustomNode->GetTag() == V2::JS_VIEW_ETS_TAG);
355
356 childCustomNode->MountToParent(customNode);
357
358 /**
359 * @tc.steps: step3. Create Parent LayoutWrapperNode.
360 */
361 auto pattern = frameNode->GetPattern<Pattern>();
362 ASSERT_NE(pattern, nullptr);
363 auto layoutAlgorithm = pattern->CreateLayoutAlgorithm();
364 ASSERT_NE(layoutAlgorithm, nullptr);
365 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
366 ASSERT_NE(geometryNode, nullptr);
367 customNode = nullptr;
368 customNode = CustomNode::CreateCustomNode(ElementRegister::GetInstance()->MakeUniqueId(), TEST_TAG);
369 auto parentLayoutWrapper =
370 AceType::MakeRefPtr<LayoutWrapperNode>(frameNode, geometryNode, frameNode->GetLayoutProperty());
371 /**
372 * @tc.steps: step4. set renderFunction, add child to customNode and invoke Measure function.
373 * @tc.expected: parentLayoutWrapper's childCount is one.
374 */
375 RefPtr<AceType> view;
__anon71f9752b0e02() 376 auto renderFunc = [&view]() -> RefPtr<AceType> { return nullptr; };
__anon71f9752b0f02() 377 auto renderFunction = [internalRender = std::move(renderFunc)]() -> RefPtr<UINode> {
378 auto uiNode = internalRender();
379 return AceType::DynamicCast<UINode>(uiNode);
380 };
381 customNode->SetRenderFunction(std::move(renderFunction));
382 customNode->AdjustLayoutWrapperTree(parentLayoutWrapper, false, false);
383 auto textFrameNode = CreateNode(V2::TEXT_ETS_TAG);
384 textFrameNode->MountToParent(customNode);
385 layoutAlgorithm->Measure(AceType::RawPtr(parentLayoutWrapper));
386 EXPECT_EQ(parentLayoutWrapper->GetTotalChildCount(), CHILD_COUNT_1);
387 }
388
389 /**
390 * @tc.name: CustomTest007
391 * @tc.desc: Create CustomNode and child node is CustomNode and grandChild node is CustomNode and test
392 * AdjustLayoutWrapperTree.
393 * @tc.type: FUNC
394 */
395 HWTEST_F(CustomTestNg, CustomTest007, TestSize.Level1)
396 {
397 /**
398 * @tc.steps: step1. Create TabContent and push it to view stack processor.
399 * @tc.expected: Make TabContent as CustomNode parent.
400 */
401 auto frameNode = CreateNode(V2::TAB_CONTENT_ITEM_ETS_TAG);
402
403 /**
404 * @tc.steps: step2. Invoke CustomNode Create function and another CustomNode mount to CustomNode.
405 * @tc.expected: Create CustomNode.
406 */
407 auto customNode = CustomNode::CreateCustomNode(ElementRegister::GetInstance()->MakeUniqueId(), TEST_TAG);
408 EXPECT_TRUE(customNode != nullptr && customNode->GetTag() == V2::JS_VIEW_ETS_TAG);
409
410 auto childCustomNode = CustomNode::CreateCustomNode(ElementRegister::GetInstance()->MakeUniqueId(), TEST_TAG);
411 EXPECT_TRUE(childCustomNode != nullptr && childCustomNode->GetTag() == V2::JS_VIEW_ETS_TAG);
412
413 childCustomNode->MountToParent(customNode);
414
415 auto grandChildCustomNode = CustomNode::CreateCustomNode(ElementRegister::GetInstance()->MakeUniqueId(), TEST_TAG);
416 EXPECT_TRUE(grandChildCustomNode != nullptr && grandChildCustomNode->GetTag() == V2::JS_VIEW_ETS_TAG);
417
418 grandChildCustomNode->MountToParent(childCustomNode);
419
420 /**
421 * @tc.steps: step3. Create Parent LayoutWrapperNode.
422 */
423 auto pattern = frameNode->GetPattern<Pattern>();
424 ASSERT_NE(pattern, nullptr);
425 auto layoutAlgorithm = pattern->CreateLayoutAlgorithm();
426 ASSERT_NE(layoutAlgorithm, nullptr);
427 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
428 ASSERT_NE(geometryNode, nullptr);
429 customNode = nullptr;
430 customNode = CustomNode::CreateCustomNode(ElementRegister::GetInstance()->MakeUniqueId(), TEST_TAG);
431 auto parentLayoutWrapper =
432 AceType::MakeRefPtr<LayoutWrapperNode>(frameNode, geometryNode, frameNode->GetLayoutProperty());
433 /**
434 * @tc.steps: step4. set renderFunction, add child to customNode and invoke Measure function.
435 * @tc.expected: parentLayoutWrapper's childCount is one.
436 */
437 RefPtr<AceType> view;
__anon71f9752b1002() 438 auto renderFunc = [&view]() -> RefPtr<AceType> { return nullptr; };
__anon71f9752b1102() 439 auto renderFunction = [internalRender = std::move(renderFunc)]() -> RefPtr<UINode> {
440 auto uiNode = internalRender();
441 return AceType::DynamicCast<UINode>(uiNode);
442 };
443 customNode->SetRenderFunction(std::move(renderFunction));
444 customNode->AdjustLayoutWrapperTree(parentLayoutWrapper, false, false);
445 auto textFrameNode = CreateNode(V2::TEXT_ETS_TAG);
446 textFrameNode->MountToParent(customNode);
447 layoutAlgorithm->Measure(AceType::RawPtr(parentLayoutWrapper));
448 EXPECT_EQ(parentLayoutWrapper->GetTotalChildCount(), CHILD_COUNT_1);
449 }
450
451 /**
452 * @tc.name: CustomTest008
453 * @tc.desc: Create CustomMeasureLayoutNode and test measure and layout.
454 * @tc.type: FUNC
455 */
456 HWTEST_F(CustomTestNg, CustomTest008, TestSize.Level1)
457 {
458 /**
459 * @tc.steps: step1. Create TabContent and push it to view stack processor.
460 * @tc.expected: Make TabContent as CustomNode parent.
461 */
462 auto frameNode = CreateNode(V2::TAB_CONTENT_ITEM_ETS_TAG);
463
464 /**
465 * @tc.steps: step2. Invoke CustomNode Create function and create textNode mount to CustomNode.
466 * @tc.expected: Create CustomNode.
467 */
468 auto customNode = CustomMeasureLayoutNode::CreateCustomMeasureLayoutNode(
469 ElementRegister::GetInstance()->MakeUniqueId(), TEST_TAG);
470 EXPECT_TRUE(customNode != nullptr && customNode->GetTag() == V2::JS_VIEW_ETS_TAG);
471
472 customNode->MountToParent(frameNode);
473
474 auto textFrameNode = CreateNode(V2::TEXT_ETS_TAG);
475 textFrameNode->MountToParent(customNode);
476
477 /**
478 * @tc.steps: step3. Create Parent LayoutWrapperNode.
479 */
480 auto pattern = frameNode->GetPattern<Pattern>();
481 ASSERT_NE(pattern, nullptr);
482 auto layoutAlgorithm = pattern->CreateLayoutAlgorithm();
483 ASSERT_NE(layoutAlgorithm, nullptr);
484 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
485 ASSERT_NE(geometryNode, nullptr);
486 auto parentLayoutWrapper =
487 AceType::MakeRefPtr<LayoutWrapperNode>(frameNode, geometryNode, frameNode->GetLayoutProperty());
488 EXPECT_FALSE(parentLayoutWrapper == nullptr);
489 /**
490 * @tc.steps: step4. set renderFunction, add child to customNode and invoke Measure function.
491 * @tc.expected: parentLayoutWrapper's childCount is one.
492 */
493 RefPtr<AceType> view;
__anon71f9752b1202() 494 auto renderFunc = [&view]() -> RefPtr<AceType> { return nullptr; };
__anon71f9752b1302() 495 auto renderFunction = [internalRender = std::move(renderFunc)]() -> RefPtr<UINode> {
496 auto uiNode = internalRender();
497 return AceType::DynamicCast<UINode>(uiNode);
498 };
499 customNode->SetRenderFunction(std::move(renderFunction));
500
501 RefPtr<GeometryNode> customGeometryNode = AceType::MakeRefPtr<GeometryNode>();
502 auto customPattern = customNode->GetPattern<CustomNodePattern>();
503 ASSERT_NE(customPattern, nullptr);
504 auto customLayoutAlgorithm = customPattern->CreateLayoutAlgorithm();
505 ASSERT_NE(customLayoutAlgorithm, nullptr);
506 auto customLayoutWrapper =
507 AceType::MakeRefPtr<LayoutWrapperNode>(customNode, geometryNode, customNode->GetLayoutProperty());
508 EXPECT_FALSE(customLayoutWrapper == nullptr);
509 customLayoutWrapper->SetLayoutAlgorithm(AceType::MakeRefPtr<LayoutAlgorithmWrapper>(customLayoutAlgorithm));
510 parentLayoutWrapper->AppendChild(customLayoutWrapper);
511
512 layoutAlgorithm->Measure(AceType::RawPtr(parentLayoutWrapper));
513 layoutAlgorithm->Layout(AceType::RawPtr(parentLayoutWrapper));
514 EXPECT_EQ(parentLayoutWrapper->GetTotalChildCount(), CHILD_COUNT_1);
515 }
516
517 /**
518 * @tc.name: CustomTest009
519 * @tc.desc: Create Custom node.
520 * @tc.type: FUNC
521 */
522 HWTEST_F(CustomTestNg, CustomTest009, TestSize.Level1)
523 {
524 /**
525 * @tc.steps: step1. Create Text and push it to view stack processor.
526 * @tc.expected: Make Text as CustomNode parent.
527 */
528 auto frameNode = CreateNode(V2::TEXT_ETS_TAG);
529
530 /**
531 * @tc.steps: step2. Invoke CustomNode Create function.
532 * @tc.expected: Create CustomNode.
533 */
534 auto customNode = CustomNode::CreateCustomNode(ElementRegister::GetInstance()->MakeUniqueId(), TEST_TAG);
535 EXPECT_TRUE(customNode != nullptr && customNode->GetTag() == V2::JS_VIEW_ETS_TAG);
536 bool needRebuild = true;
537
538 /**
539 * @tc.steps: step3. set needMarkParent_ and needRebuild_ and invoke MarkNeedSyncRenderTree.
540 * @tc.expected: the related function runs ok.
541 */
542 for (int i = 0; i <= 1; i++) {
543 for (int j = 0; j <= 1; j++) {
544 customNode->MarkNeedSyncRenderTree(needRebuild);
545 customNode->needMarkParent_ = false;
546 }
547 customNode->needMarkParent_ = true;
548 customNode->needRebuild_ = false;
549 }
550 EXPECT_TRUE(customNode != nullptr);
551 }
552
553 /**
554 * @tc.name: CustomTest010
555 * @tc.desc: Create Custom node.
556 * @tc.type: FUNC
557 */
558 HWTEST_F(CustomTestNg, CustomTest010, TestSize.Level1)
559 {
560 /**
561 * @tc.steps: step1. Create Text and push it to view stack processor.
562 * @tc.expected: Make Text as CustomNode parent.
563 */
564 auto frameNode = CreateNode(V2::TEXT_ETS_TAG);
565
566 /**
567 * @tc.steps: step2. Invoke CustomNode Create function.
568 * @tc.expected: Create CustomNode.
569 */
570 auto customNode = CustomNode::CreateCustomNode(ElementRegister::GetInstance()->MakeUniqueId(), TEST_TAG);
571 EXPECT_TRUE(customNode != nullptr && customNode->GetTag() == V2::JS_VIEW_ETS_TAG);
572 /**
573 * @tc.steps: step3. set recycleCustomNodeFunc and invoke FireRecycleSelf.
574 * @tc.expected: the related function runs ok.
575 */
576 bool recycleCustomNodeFunc = true;
__anon71f9752b1402(RefPtr<CustomNodeBase>) 577 customNode->SetRecycleFunction([&recycleCustomNodeFunc](RefPtr<CustomNodeBase>) { recycleCustomNodeFunc = true; });
578 customNode->FireRecycleSelf();
579 EXPECT_TRUE(customNode->needRebuild_ = true);
580 customNode->needRebuild_ = false;
581 customNode->SetRecycleFunction(nullptr);
582 customNode->FireRecycleSelf();
583 bool test = customNode->needRebuild_;
584 EXPECT_EQ(test, false);
585 }
586
587 /**
588 * @tc.name: CustomTest011
589 * @tc.desc: Create Custom node and test MarkNeedUpdate.
590 * @tc.type: FUNC
591 */
592 HWTEST_F(CustomTestNg, CustomTest011, TestSize.Level1)
593 {
594 /**
595 * @tc.steps: step1. Create TabContent and push it to view stack processor.
596 * @tc.expected: Make TabContent as CustomNode parent.
597 */
598 auto frameNode = CreateNode(V2::TAB_CONTENT_ITEM_ETS_TAG);
599
600 /**
601 * @tc.steps: step2. Invoke CustomNode Create function.
602 * @tc.expected: Create CustomNode.
603 */
604 auto customNode = CustomNode::CreateCustomNode(ElementRegister::GetInstance()->MakeUniqueId(), TEST_TAG);
605 EXPECT_TRUE(customNode != nullptr && customNode->GetTag() == V2::JS_VIEW_ETS_TAG);
606
607 /**
608 * @tc.steps: step3. Create Parent LayoutWrapperNode.
609 */
610 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
611 ASSERT_NE(geometryNode, nullptr);
612 auto parentLayoutWrapper =
613 AceType::MakeRefPtr<LayoutWrapperNode>(frameNode, geometryNode, frameNode->GetLayoutProperty());
614 /**
615 * @tc.steps: step4. set recycleRender, invoke MarkNeedUpdata function.
616 * @tc.expected: parentLayoutWrapper's childCount is zero.
617 */
618 bool destroyFunc = false;
__anon71f9752b1502() 619 customNode->SetDestroyFunction([&destroyFunc]() { destroyFunc = true; });
620 customNode->Update();
621 bool updateFunc = false;
__anon71f9752b1602() 622 customNode->SetUpdateFunction([&updateFunc]() { updateFunc = true; });
623 customNode->Update();
624 bool recycleRenderFunc = false;
__anon71f9752b1702() 625 customNode->SetRecycleRenderFunc([&recycleRenderFunc]() { recycleRenderFunc = true; });
626 customNode->MarkNeedUpdate();
627 customNode->MarkNeedUpdate();
628 bool test = customNode->needRebuild_;
629 EXPECT_NE(test, true);
630 }
631
632 /**
633 * @tc.name: CustomTest012
634 * @tc.desc: Create Custom node.
635 * @tc.type: FUNC
636 */
637 HWTEST_F(CustomTestNg, CustomTest012, TestSize.Level1)
638 {
639 /**
640 * @tc.steps: step1. Create CustomNodeLayoutAlgorithm and frameNode.
641 * @tc.expected: Make Text as CustomNode parent.
642 */
643 CustomNodeLayoutAlgorithm test = CustomNodeLayoutAlgorithm(
__anon71f9752b1802() 644 []() { return AceType::MakeRefPtr<FrameNode>("test", 1, AceType::MakeRefPtr<Pattern>()); });
645 auto frameNode = CreateNode(V2::TEXT_ETS_TAG);
646
647 /**
648 * @tc.steps: step2. Create CustomNode and set active.
649 * @tc.expected: Create CustomNode.
650 */
651 auto customNodetest = CustomNode::CreateCustomNode(ElementRegister::GetInstance()->MakeUniqueId(), TEST_TAG);
652 EXPECT_TRUE(customNodetest != nullptr && customNodetest->GetTag() == V2::JS_VIEW_ETS_TAG);
653 /**
654 * @tc.steps: step3. set RenderFunction and invoke Mersure.
655 * @tc.expected: the related function runs ok.
656 */
657 auto customNode = CustomMeasureLayoutNode::CreateCustomMeasureLayoutNode(
658 ElementRegister::GetInstance()->MakeUniqueId(), TEST_TAG);
659 EXPECT_TRUE(customNode != nullptr && customNode->GetTag() == V2::JS_VIEW_ETS_TAG);
660 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
661 ASSERT_NE(geometryNode, nullptr);
662 auto layoutWrapper = customNode->CreateLayoutWrapper();
__anon71f9752b1902() 663 auto renderfunction = []() { return AceType::MakeRefPtr<FrameNode>("test", 1, AceType::MakeRefPtr<Pattern>()); };
664 test.renderFunction_ = renderfunction;
665 test.Measure(AceType::RawPtr(layoutWrapper));
666 EXPECT_NE(renderfunction(), nullptr);
667 }
668
669 /**
670 * @tc.name: CustomTest013
671 * @tc.desc: Create Custom node.
672 * @tc.type: FUNC
673 */
674 HWTEST_F(CustomTestNg, CustomTest013, TestSize.Level1)
675 {
676 /**
677 * @tc.steps: step1. Create test.
678 * @tc.expected: Make Text as CustomNode parent.
679 */
680 CustomNodeLayoutAlgorithm test = CustomNodeLayoutAlgorithm(
__anon71f9752b1a02() 681 []() { return AceType::MakeRefPtr<FrameNode>("test", 1, AceType::MakeRefPtr<Pattern>()); });
682
683 /**
684 * @tc.steps: step2. Create frameNode.
685 * @tc.expected: Make TabContent as CustomNode parent.
686 */
687 auto frameNode = CreateNode(V2::TAB_CONTENT_ITEM_ETS_TAG);
688
689 /**
690 * @tc.steps: step3. Create LayoutWrapper, customNode, set measureFuncion and invoke Measure.
691 */
692 auto customNode = CustomMeasureLayoutNode::CreateCustomMeasureLayoutNode(
693 ElementRegister::GetInstance()->MakeUniqueId(), TEST_TAG);
694 EXPECT_TRUE(customNode != nullptr && customNode->GetTag() == V2::JS_VIEW_ETS_TAG);
695 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
696 ASSERT_NE(geometryNode, nullptr);
697 auto layoutWrapper = customNode->CreateLayoutWrapper();
__anon71f9752b1b02() 698 auto renderfunction = []() { return AceType::MakeRefPtr<FrameNode>("test", 1, AceType::MakeRefPtr<Pattern>()); };
699 test.renderFunction_ = renderfunction;
700 NG::LayoutWrapper* testMeasureFun;
701 auto measureFuncation = [&testMeasureFun](
__anon71f9752b1c02( NG::LayoutWrapper* layoutWrapper = nullptr) 702 NG::LayoutWrapper* layoutWrapper = nullptr) { testMeasureFun = layoutWrapper; };
703 customNode->SetMeasureFunction(std::move(measureFuncation));
704
705 test.Measure(AceType::RawPtr(layoutWrapper));
706 EXPECT_NE(renderfunction(), nullptr);
707 }
708
709 /**
710 * @tc.name: CustomTest014
711 * @tc.desc: Create Custom node.
712 * @tc.type: FUNC
713 */
714 HWTEST_F(CustomTestNg, CustomTest014, TestSize.Level1)
715 {
716 /**
717 * @tc.steps: step1. Create test.
718 * @tc.expected: Make Text as CustomNode parent.
719 */
720 CustomNodeLayoutAlgorithm test = CustomNodeLayoutAlgorithm(
__anon71f9752b1d02() 721 []() { return AceType::MakeRefPtr<FrameNode>("test", 1, AceType::MakeRefPtr<Pattern>()); });
722
723 /**
724 * @tc.steps: step2. Create frameNode.
725 * @tc.expected: Make TabContent as CustomNode parent.
726 */
727 auto frameNode = CreateNode(V2::TAB_CONTENT_ITEM_ETS_TAG);
728
729 /**
730 * @tc.steps: step3. Create LayoutWrapper, customNode, set LayoutFunction and invoke Layout.
731 */
732 auto customNode = CustomMeasureLayoutNode::CreateCustomMeasureLayoutNode(
733 ElementRegister::GetInstance()->MakeUniqueId(), TEST_TAG);
734 EXPECT_TRUE(customNode != nullptr && customNode->GetTag() == V2::JS_VIEW_ETS_TAG);
735 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
736 ASSERT_NE(geometryNode, nullptr);
737 auto layoutWrapper = customNode->CreateLayoutWrapper();
__anon71f9752b1e02() 738 auto renderfunction = []() { return AceType::MakeRefPtr<FrameNode>("test", 1, AceType::MakeRefPtr<Pattern>()); };
739 test.renderFunction_ = renderfunction;
740 NG::LayoutWrapper* testLayoutFunction;
741 auto LayoutFunction = [&testLayoutFunction](
__anon71f9752b1f02( NG::LayoutWrapper* layoutWrapper = nullptr) 742 NG::LayoutWrapper* layoutWrapper = nullptr) { testLayoutFunction = layoutWrapper; };
743 customNode->SetLayoutFunction(std::move(LayoutFunction));
744 test.Layout(AceType::RawPtr(layoutWrapper));
745 auto host = AceType::DynamicCast<CustomMeasureLayoutNode>(layoutWrapper->GetHostNode());
746 ASSERT_NE(host, nullptr);
747 }
748
749 /**
750 * @tc.name: CustomTest015
751 * @tc.desc: Build Custom node.
752 * @tc.type: FUNC
753 */
754 HWTEST_F(CustomTestNg, CustomTest015, TestSize.Level1)
755 {
756 /**
757 * @tc.steps: step1. Create customNode.
758 */
759 auto customNode = CustomNode::CreateCustomNode(ElementRegister::GetInstance()->MakeUniqueId(), TEST_TAG);
760
761 /**
762 * @tc.steps: step2. Create ExtraInfo and Call Build.
763 * @tc.expected: Build Seccuss
764 */
765 ExtraInfo extraTemp;
766 extraTemp.line = CHILD_COUNT_0;
767 extraTemp.page = TEST_TAG;
768 std::list<ExtraInfo> ListextraInfos;
769 ListextraInfos.push_back(extraTemp);
770 std::shared_ptr<std::list<ExtraInfo>> extraInfos = std::make_unique<std::list<ExtraInfo>>(ListextraInfos);
771 customNode->Build(extraInfos);
772 EXPECT_EQ(customNode->extraInfos_.size(), 1);
773 EXPECT_EQ(customNode->extraInfos_.front().line, CHILD_COUNT_0);
774 EXPECT_EQ(customNode->extraInfos_.front().page, TEST_TAG);
775 }
776
777 /**
778 * @tc.name: CustomTest016
779 * @tc.desc: Build Render.
780 * @tc.type: FUNC
781 */
782 HWTEST_F(CustomTestNg, CustomTest016, TestSize.Level1)
783 {
784 /**
785 * @tc.steps: step1. Create customNode.
786 */
787 auto customNode = CustomNode::CreateCustomNode(ElementRegister::GetInstance()->MakeUniqueId(), TEST_TAG);
788
789 /**
790 * @tc.steps: step2. Create renderFunction and Call Render.
791 * @tc.expected: Add Child Success
792 */
__anon71f9752b2002() 793 auto renderFunction = [&]() -> RefPtr<UINode> {
794 RefPtr<UINode> uiNode =
795 CustomNode::CreateCustomNode(ElementRegister::GetInstance()->MakeUniqueId() + 1, TEST_TAG);
796 return uiNode;
797 };
798 customNode->renderFunction_ = renderFunction;
799 customNode->Render();
800 EXPECT_EQ(customNode->GetChildren().size(), 1);
801 }
802
803 /**
804 * @tc.name: CustomTest017
805 * @tc.desc: FlushReload.
806 * @tc.type: FUNC
807 */
808 HWTEST_F(CustomTestNg, CustomTest017, TestSize.Level1)
809 {
810 /**
811 * @tc.steps: step1. Create customNode.
812 */
813 auto customNode = CustomNode::CreateCustomNode(ElementRegister::GetInstance()->MakeUniqueId(), TEST_TAG);
814
815 /**
816 * @tc.steps: step2. Create completeReloadFunc_ and Call FlushReload.
817 * @tc.expected: Add Child Success
818 */
__anon71f9752b2102() 819 auto renderFunction = [&]() -> RefPtr<UINode> {
820 RefPtr<UINode> uiNode =
821 CustomNode::CreateCustomNode(ElementRegister::GetInstance()->MakeUniqueId() + 1, TEST_TAG);
822 return uiNode;
823 };
824 customNode->completeReloadFunc_ = renderFunction;
825 customNode->FlushReload();
826 EXPECT_EQ(customNode->GetChildren().size(), 1);
827 }
828
829 /**
830 * @tc.name: CustomTest018
831 * @tc.desc: AdjustLayoutWrapperTree.
832 * @tc.type: FUNC
833 */
834 HWTEST_F(CustomTestNg, CustomTest018, TestSize.Level1)
835 {
836 /**
837 * @tc.steps: step1. Create TabContent and push it to view stack processor.
838 * @tc.expected: Make TabContent as CustomNode parent.
839 */
840 auto frameNode = CreateNode(V2::TAB_CONTENT_ITEM_ETS_TAG);
841
842 /**
843 * @tc.steps: step2. Invoke CustomNode Create function.
844 * @tc.expected: Create CustomNode.
845 */
846 auto customNode = CustomNode::CreateCustomNode(ElementRegister::GetInstance()->MakeUniqueId(), TEST_TAG);
847 EXPECT_TRUE(customNode != nullptr && customNode->GetTag() == V2::JS_VIEW_ETS_TAG);
848
849 /**
850 * @tc.steps: step3. Create Parent LayoutWrapperNode.
851 */
852 auto pattern = frameNode->GetPattern<Pattern>();
853 auto layoutAlgorithm = pattern->CreateLayoutAlgorithm();
854 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
855 auto parentLayoutWrapper =
856 AceType::MakeRefPtr<LayoutWrapperNode>(frameNode, geometryNode, frameNode->GetLayoutProperty());
857
858 /**
859 * @tc.steps: step4. set renderFunction, add child to customNode and invoke Measure function.
860 * @tc.expected: parentLayoutWrapper's childCount is one.
861 */
862 RefPtr<AceType> view;
__anon71f9752b2202() 863 auto renderFunc = [&view]() -> RefPtr<AceType> { return nullptr; };
__anon71f9752b2302() 864 auto renderFunction = [internalRender = std::move(renderFunc)]() -> RefPtr<UINode> {
865 auto uiNode = internalRender();
866 return AceType::DynamicCast<UINode>(uiNode);
867 };
868 auto customNode2 = CustomNode::CreateCustomNode(ElementRegister::GetInstance()->MakeUniqueId() + 1, TEST_TAG);
869 auto customNode3 = CustomNode::CreateCustomNode(ElementRegister::GetInstance()->MakeUniqueId() + 2, TEST_TAG);
870 customNode2->AddChild(customNode3);
871 customNode->AddChild(customNode2);
872 customNode->SetRenderFunction(std::move(renderFunction));
873 customNode->AdjustLayoutWrapperTree(parentLayoutWrapper, false, false);
874
875 auto textFrameNode = CreateNode(V2::TEXT_ETS_TAG);
876 textFrameNode->MountToParent(customNode);
877 layoutAlgorithm->Measure(AceType::RawPtr(parentLayoutWrapper));
878 EXPECT_EQ(parentLayoutWrapper->GetTotalChildCount(), CHILD_COUNT_1);
879 }
880
881 /**
882 * @tc.name: CustomTest019
883 * @tc.desc: CreateLayoutWrapper.
884 * @tc.type: FUNC
885 */
886 HWTEST_F(CustomTestNg, CustomTest019, TestSize.Level1)
887 {
888 /**
889 * @tc.steps: step1. Create frameNode.
890 */
891 auto frameNode = CreateNode(V2::TAB_CONTENT_ITEM_ETS_TAG);
892
893 /**
894 * @tc.steps: step2. Create CustomNode and Call CreateLayoutWrapper.
895 * @tc.expected: Create successful.
896 */
897 auto customNode = CustomNode::CreateCustomNode(ElementRegister::GetInstance()->MakeUniqueId(), TEST_TAG);
898 auto node = AceType::MakeRefPtr<FrameNode>("test", 1, AceType::MakeRefPtr<Pattern>());
899 node->isLayoutDirtyMarked_ = true;
900 customNode->AddChild(node);
901 RefPtr<LayoutWrapperNode> layoutWrapperNode = customNode->CreateLayoutWrapper(true, true);
902 EXPECT_NE(layoutWrapperNode, nullptr);
903 EXPECT_FALSE(node->isLayoutDirtyMarked_);
904 }
905
906 /**
907 * @tc.name: CustomTest020
908 * @tc.desc: Test cast to FireRecycleSelf.
909 * @tc.type: FUNC
910 */
911 HWTEST_F(CustomTestNg, CustomTest020, TestSize.Level1)
912 {
913 /**
914 * @tc.steps: step1. Create CustomNodeBase through customNode.
915 */
916 RefPtr<CustomNode> customNode =
917 CustomNode::CreateCustomNode(ElementRegister::GetInstance()->MakeUniqueId(), TEST_TAG);
918
919 /**
920 * @tc.steps: step2. Create frameNode and frameNode2 and Add Child to customNode.
921 */
922 auto frameNode = AceType::MakeRefPtr<FrameNode>("test1", 1, AceType::MakeRefPtr<Pattern>());
923 customNode->AddChild(frameNode);
924 auto frameNode2 = AceType::MakeRefPtr<FrameNode>("test2", 2, AceType::MakeRefPtr<Pattern>());
925 frameNode2->layoutProperty_ = AceType::MakeRefPtr<LayoutProperty>();
926 auto geo = AceType::MakeRefPtr<GeometryTransition>(TEST_TAG, true, true);
927 frameNode2->layoutProperty_->geometryTransition_ = AceType::WeakClaim(AceType::RawPtr(geo));
928 customNode->AddChild(frameNode2);
929 }
930
931 /**
932 * @tc.name: CustomTest021
933 * @tc.desc: Test cast to SetOnDumpInfoFunc.
934 * @tc.type: FUNC
935 */
936 HWTEST_F(CustomTestNg, CustomTest021, TestSize.Level1)
937 {
938 /**
939 * @tc.steps: step1. Create CustomNodeBase through customNode.
940 */
941 RefPtr<CustomNodeBase> customNode =
942 CustomNode::CreateCustomNode(ElementRegister::GetInstance()->MakeUniqueId(), TEST_TAG);
943
944 /**
945 * @tc.steps: step2. Create CallBack.
946 */
947 std::vector<std::string> vctOut;
__anon71f9752b2402(const std::vector<std::string>& vctTemp) 948 auto callback = [&](const std::vector<std::string>& vctTemp) { vctOut.assign(vctTemp.begin(), vctTemp.end()); };
949
950 /**
951 * @tc.steps: step3. Call SetOnDumpInfoFunc.
952 * @tc.expected: Excute successful and return is equal tith vctTemp.
953 */
954 customNode->SetOnDumpInfoFunc(callback);
955 std::vector<std::string> vctTemp = { "test1", "test2" };
956 customNode->onDumpInfoFunc_(vctTemp);
957 EXPECT_EQ(vctOut.size(), 2);
958 }
959
960 /**
961 * @tc.name: CustomTest022
962 * @tc.desc: Test cast to CustomNodeLayoutAlgorithm.Measure.
963 * @tc.type: FUNC
964 */
965 HWTEST_F(CustomTestNg, CustomTest022, TestSize.Level1)
966 {
967 /**
968 * @tc.steps: step1. Create test.
969 * @tc.expected: Make Text as CustomNode parent.
970 */
971 CustomNodeLayoutAlgorithm test = CustomNodeLayoutAlgorithm(
__anon71f9752b2502() 972 []() { return AceType::MakeRefPtr<FrameNode>("test", 1, AceType::MakeRefPtr<Pattern>()); });
973
974 /**
975 * @tc.steps: step2. Create LayoutWrapper, customNode.
976 */
977 auto customNode = CustomMeasureLayoutNode::CreateCustomMeasureLayoutNode(
978 ElementRegister::GetInstance()->MakeUniqueId(), TEST_TAG);
979 auto layoutWrapper = customNode->CreateLayoutWrapper();
980 auto frameChild1 =
__anon71f9752b2602() 981 FrameNode::GetOrCreateFrameNode("Child1", -1, []() { return AceType::MakeRefPtr<Pattern>(); });
982 auto frameChild2 =
__anon71f9752b2702() 983 FrameNode::GetOrCreateFrameNode("Child2", -1, []() { return AceType::MakeRefPtr<Pattern>(); });
__anon71f9752b2802() 984 auto renderfunction = [frameChild1, frameChild2]() -> RefPtr<UINode> {
985 ViewStackProcessor::GetInstance()->Push(frameChild1);
986 ViewStackProcessor::GetInstance()->Pop();
987 ViewStackProcessor::GetInstance()->Push(frameChild2);
988 ViewStackProcessor::GetInstance()->Pop();
989 return ViewStackProcessor::GetInstance()->Finish();
990 };
991 test.renderFunction_ = renderfunction;
992
993 /**
994 * @tc.steps: step3. Call Measure.
995 * @tc.expected: customNode add a Child and buildItem is equal with child
996 */
997 test.Measure(AceType::RawPtr(layoutWrapper));
998 EXPECT_EQ(customNode->GetChildren().size(), 2);
999 EXPECT_EQ(test.buildItem_, frameChild1);
1000 }
1001
1002 /**
1003 * @tc.name: CustomTest023
1004 * @tc.desc: Test cast to CustomNodeLayoutAlgorithm.Layout.
1005 * @tc.type: FUNC
1006 */
1007 HWTEST_F(CustomTestNg, CustomTest023, TestSize.Level1)
1008 {
1009 /**
1010 * @tc.steps: step1. Create test.
1011 */
1012 CustomNodeLayoutAlgorithm test = CustomNodeLayoutAlgorithm(
__anon71f9752b2902() 1013 []() { return AceType::MakeRefPtr<FrameNode>("test", 1, AceType::MakeRefPtr<Pattern>()); });
1014
1015 /**
1016 * @tc.steps: step2. Create LayoutWrapper, customNode, set LayoutFunction and invoke Layout.
1017 */
1018 auto customNode = CustomMeasureLayoutNode::CreateCustomMeasureLayoutNode(
1019 ElementRegister::GetInstance()->MakeUniqueId(), TEST_TAG);
1020 auto layoutWrapper = customNode->CreateLayoutWrapper();
1021
1022 /**
1023 * @tc.steps: step3. Create LayoutWrapperNode and add to layoutWrapper.
1024 */
1025 auto node = FrameNode::CreateFrameNode("test", 1, AceType::MakeRefPtr<Pattern>());
1026 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
1027 RefPtr<LayoutWrapperNode> layoutNode =
1028 AceType::MakeRefPtr<LayoutWrapperNode>(node, geometryNode, node->GetLayoutProperty());
1029 layoutWrapper->AppendChild(layoutNode);
1030
1031 /**
1032 * @tc.steps: step4. Call Layout.
1033 * @tc.expected: cachedList_ size is equal with layoutWrapper and active set success.
1034 */
1035 test.Layout(AceType::RawPtr(layoutWrapper));
1036 EXPECT_EQ(layoutWrapper->cachedList_.size(), 1);
1037 for (const auto& child : layoutWrapper->cachedList_) {
1038 EXPECT_TRUE(child->IsActive());
1039 }
1040 }
1041
1042 /**
1043 * @tc.name: CustomTest024
1044 * @tc.desc: Test cast to CustomNodePattern.OnDirtyLayoutWrapperSwap.
1045 * @tc.type: FUNC
1046 */
1047 HWTEST_F(CustomTestNg, CustomTest024, TestSize.Level1)
1048 {
1049 /**
1050 * @tc.steps: step1. Create FrameNode and CustomNodePattern.
1051 */
1052 auto frameNode = AceType::MakeRefPtr<FrameNode>("test1", 1, AceType::MakeRefPtr<Pattern>());
1053 WeakPtr<FrameNode> weakNode1 = AceType::WeakClaim(AceType::RawPtr(frameNode));
1054 RefPtr<CustomNodePattern> pattern = AceType::MakeRefPtr<CustomNodePattern>();
1055 pattern->AttachToFrameNode(weakNode1);
1056 EXPECT_NE(pattern->GetHost(), nullptr);
1057
1058 /**
1059 * @tc.steps: step2. Create LayoutWrapperNode and SetLayoutAlgorithm.
1060 */
1061 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
1062 RefPtr<LayoutWrapperNode> layoutNode =
1063 AceType::MakeRefPtr<LayoutWrapperNode>(frameNode, geometryNode, frameNode->GetLayoutProperty());
1064 auto rowLayoutAlgorithm1 = AceType::MakeRefPtr<LayoutAlgorithm>();
1065 RefPtr<CustomNodeLayoutAlgorithm> rowLayoutAlgorithm2 = AceType::MakeRefPtr<CustomNodeLayoutAlgorithm>(nullptr);
1066 auto frameNode2 = AceType::MakeRefPtr<FrameNode>("test2", 2, AceType::MakeRefPtr<Pattern>());
1067 rowLayoutAlgorithm2->buildItem_ = frameNode2;
1068
1069 auto temp = AceType::MakeRefPtr<LayoutAlgorithmWrapper>(rowLayoutAlgorithm1);
1070 temp->SetLayoutAlgorithm(rowLayoutAlgorithm2);
1071 layoutNode->SetLayoutAlgorithm(temp);
1072
1073 /**
1074 * @tc.steps: step3. Call OnDirtyLayoutWrapperSwap.
1075 * @tc.expected: result id false and framenode add a child seccuss
1076 */
1077 DirtySwapConfig dirtyConfig;
1078 bool bResult = pattern->OnDirtyLayoutWrapperSwap(layoutNode, dirtyConfig);
1079 EXPECT_FALSE(bResult);
1080 EXPECT_EQ(frameNode->GetChildren().size(), 1);
1081 }
1082
1083 /**
1084 * @tc.name: CustomTest025
1085 * @tc.desc: Test cast to CustomTitleNode.CreateCustomTitleNode.
1086 * @tc.type: FUNC
1087 */
1088 HWTEST_F(CustomTestNg, CustomTest025, TestSize.Level1)
1089 {
1090 RefPtr<CustomTitleNode> customTitleNode = CustomTitleNode::CreateCustomTitleNode(1, "test");
1091 EXPECT_EQ(customTitleNode->tag_, V2::JS_VIEW_ETS_TAG);
1092 EXPECT_EQ(customTitleNode->nodeId_, 1);
1093 EXPECT_EQ(customTitleNode->viewKey_, "test");
1094 }
1095
1096 /**
1097 * @tc.name: CustomTest026
1098 * @tc.desc: RenderCustomChild
1099 * @tc.type: FUNC
1100 */
1101 HWTEST_F(CustomTestNg, CustomTest026, TestSize.Level1)
1102 {
1103 /**
1104 * @tc.steps: step1. Invoke CustomNode Create function.
1105 * @tc.expected: Create CustomNode.
1106 */
1107 auto customNode = CustomNode::CreateCustomNode(ElementRegister::GetInstance()->MakeUniqueId(), TEST_TAG);
1108 /**
1109 * @tc.steps: step2. Define timestamp deadline and n.
1110 * @tc.expected: Deadline And N.
1111 */
1112 int64_t n = 1000000000;
1113 int64_t deadline = GetSysTimestamp() + n;
1114 /**
1115 * @tc.steps: step3. When he is greater than the deadline, the assertion fails.
1116 * @tc.expected: GetSysTimestamp.
1117 */
1118 if (GetSysTimestamp() > deadline) {
1119 EXPECT_FALSE(false);
1120 }
1121 customNode->Render();
1122 /**
1123 * @tc.steps: step4. Invoke RenderCustomChild function.
1124 * @tc.expected: Render CustomChild.
1125 */
1126 customNode->RenderCustomChild(deadline);
1127 bool test = customNode->RenderCustomChild(deadline);
1128 EXPECT_EQ(test, true);
1129 EXPECT_TRUE(test);
1130 /**
1131 * @tc.steps: step5. Another branch returned successful.
1132 * @tc.expected: RenderCustomChild.
1133 */
1134 int64_t deadlines = 0;
1135 bool result = customNode->RenderCustomChild(deadlines);
1136 EXPECT_FALSE(result);
1137 }
1138
1139 /**
1140 * @tc.name: CustomTest027
1141 * @tc.desc: Render
1142 * @tc.type: FUNC
1143 */
1144 HWTEST_F(CustomTestNg, CustomTest027, TestSize.Level1)
1145 {
1146 /**
1147 * @tc.steps: step1. Invoke CustomNode Create function.
1148 * @tc.expected: Create CustomNode.
1149 */
1150 auto customNode = CustomNode::CreateCustomNode(ElementRegister::GetInstance()->MakeUniqueId(), TEST_TAG);
1151 /**
1152 * @tc.steps: step2. Create renderFunction and Call Render.
1153 * @tc.expected: Add Child Success
1154 */
__anon71f9752b2a02() 1155 auto renderFunction = []() -> RefPtr<UINode> {
1156 RefPtr<UINode> uiNode =
1157 CustomNode::CreateCustomNode(ElementRegister::GetInstance()->MakeUniqueId() + 1, TEST_TAG);
1158 return uiNode;
1159 };
1160 /**
1161 * @tc.steps: step3. Create textFrameNode.
1162 */
1163 auto textFrameNode = CreateNode(V2::COMMON_VIEW_ETS_TAG);
1164 textFrameNode->AddChild(customNode);
1165 /**
1166 * @tc.steps: step4. Enter the render function.
1167 */
1168 customNode->renderFunction_ = renderFunction;
1169 customNode->Render();
1170 EXPECT_FALSE(customNode->UINode::IsNeedExportTexture());
1171 }
1172
1173 /**
1174 * @tc.name: CustomTest028
1175 * @tc.desc: GetFrameChildByIndex.
1176 * @tc.type: FUNC
1177 */
1178 HWTEST_F(CustomTestNg, CustomTest028, TestSize.Level1)
1179 {
1180 /**
1181 * @tc.steps: step1. Create frameNode.
1182 */
1183 auto frameNode = CreateNode(V2::TAB_CONTENT_ITEM_ETS_TAG);
1184
1185 /**
1186 * @tc.steps: step2. Create CustomNode and Call GetFrameChildByIndex.
1187 * @tc.expected: Create successful.
1188 */
1189 auto customNode = CustomNode::CreateCustomNode(ElementRegister::GetInstance()->MakeUniqueId(), TEST_TAG);
1190 auto node = AceType::MakeRefPtr<FrameNode>("test", 1, AceType::MakeRefPtr<Pattern>());
1191 uint32_t index = 0;
1192 customNode->AddChild(node);
1193 RefPtr<UINode> UINode = customNode->GetFrameChildByIndex(index, true);
1194 EXPECT_NE(UINode, nullptr);
1195 }
1196
1197 /**
1198 * @tc.name: CustomTest029
1199 * @tc.desc: GetFrameChildByIndex.
1200 * @tc.type: FUNC
1201 */
1202 HWTEST_F(CustomTestNg, CustomTest029, TestSize.Level1)
1203 {
1204 /**
1205 * @tc.steps: step1. Invoke CustomNode Create function.
1206 * @tc.expected: Create CustomNode.
1207 */
1208 auto customNode = CustomNode::CreateCustomNode(ElementRegister::GetInstance()->MakeUniqueId(), TEST_TAG);
1209 /**
1210 * @tc.steps: step2. Add Child Success.
1211 */
1212 auto node = AceType::MakeRefPtr<FrameNode>("test", 1, AceType::MakeRefPtr<Pattern>());
1213 customNode->AddChild(node);
1214 /**
1215 * @tc.steps: step3. Call GetFrameChildByIndex with false input parameter
1216 * @tc.expected: Create successful.
1217 */
1218 customNode->CustomNode::GetFrameChildByIndex(0, false);
1219 EXPECT_FALSE(customNode->UINode::GetFrameChildByIndex(5, false));
1220 }
1221
1222 /**
1223 * @tc.name: CustomTest030
1224 * @tc.desc: MeasureLayoutParam MeasureLayoutChild.
1225 * @tc.type: FUNC
1226 */
1227 HWTEST_F(CustomTestNg, CustomTest030, TestSize.Level1)
1228 {
1229 /**
1230 * @tc.steps: step1. Create framenode.
1231 * @tc.expected: Make TabContent as CustomNode parent.
1232 */
1233 auto frameNode = CreateNode(V2::TAB_CONTENT_ITEM_ETS_TAG);
1234
1235 /**
1236 * @tc.steps: step2. Invoke CustomNode Create function and create textNode mount to CustomNode.
1237 * @tc.expected: Create CustomNode.
1238 */
1239 auto customNode = CustomMeasureLayoutNode::CreateCustomMeasureLayoutNode(
1240 ElementRegister::GetInstance()->MakeUniqueId(), TEST_TAG);
1241 customNode->MountToParent(frameNode);
1242 auto textFrameNode = CreateNode(V2::TEXT_ETS_TAG);
1243 textFrameNode->MountToParent(customNode);
1244
1245 /**
1246 * @tc.steps: step3. Create Parent LayoutWrapperNode.
1247 */
1248 auto pattern = frameNode->GetPattern<Pattern>();
1249 auto layoutAlgorithm = pattern->CreateLayoutAlgorithm();
1250 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
1251 auto parentLayoutWrapper =
1252 AceType::MakeRefPtr<LayoutWrapperNode>(frameNode, geometryNode, frameNode->GetLayoutProperty());
1253 EXPECT_FALSE(parentLayoutWrapper == nullptr);
1254 /**
1255 * @tc.steps: step4. set renderFunction, add child to customNode and invoke Measure function.
1256 * @tc.expected: parentLayoutWrapper's childCount is one.
1257 */
1258
1259 RefPtr<GeometryNode> customGeometryNode = AceType::MakeRefPtr<GeometryNode>();
1260 auto customPattern = customNode->GetPattern<CustomNodePattern>();
1261 auto customLayoutAlgorithm = customPattern->CreateLayoutAlgorithm();
1262 auto customLayoutWrapper =
1263 AceType::MakeRefPtr<LayoutWrapperNode>(customNode, geometryNode, customNode->GetLayoutProperty());
1264 EXPECT_FALSE(customLayoutWrapper == nullptr);
1265 customLayoutWrapper->SetLayoutAlgorithm(AceType::MakeRefPtr<LayoutAlgorithmWrapper>(customLayoutAlgorithm));
1266 parentLayoutWrapper->AppendChild(customLayoutWrapper);
1267
1268 MeasureLayoutParam layoutParam(AceType::RawPtr(parentLayoutWrapper));
1269 layoutParam.CreateChildConstraint();
1270 layoutParam.children_[0].CreateChildConstraint();
1271 layoutParam.children_[0].UpdateSize(SizeF(1.0, 1.0));
1272 ASSERT_NE(layoutParam.GetOrCreateChildByIndex(0), nullptr);
1273 ASSERT_NE(layoutParam.children_[0].GetOrCreateChild(), nullptr);
1274 EXPECT_EQ(layoutParam.GetChildByIndex(1), nullptr);
1275 EXPECT_EQ(layoutParam.children_[0].GetChild(), nullptr);
1276
1277 layoutAlgorithm->Measure(AceType::RawPtr(parentLayoutWrapper));
1278 layoutAlgorithm->Layout(AceType::RawPtr(parentLayoutWrapper));
1279 DirtySwapConfig dirtySwapConfig;
1280 customPattern->OnDirtyLayoutWrapperSwap(customLayoutWrapper, dirtySwapConfig);
1281 EXPECT_EQ(parentLayoutWrapper->GetTotalChildCount(), CHILD_COUNT_1);
1282 }
1283
1284 /**
1285 * @tc.name: CustomTest031
1286 * @tc.desc: MeasureLayoutParam Update.
1287 * @tc.type: FUNC
1288 */
1289 HWTEST_F(CustomTestNg, CustomTest031, TestSize.Level1)
1290 {
1291 /**
1292 * @tc.steps: step1. Create MeasureLayoutParam.
1293 */
1294 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
1295 auto frameNode = FrameNode::CreateFrameNode("framenode", 1, AceType::MakeRefPtr<Pattern>(), true);
1296 auto layoutWrapper =
1297 AceType::MakeRefPtr<LayoutWrapperNode>(frameNode, geometryNode, frameNode->GetLayoutProperty());
1298 RefPtr<GeometryNode> childGeometryOne = AceType::MakeRefPtr<GeometryNode>();
1299 auto childNodeOne = FrameNode::CreateFrameNode("childNodeOne", 1, AceType::MakeRefPtr<Pattern>(), true);
1300 auto childWrapperOne =
1301 AceType::MakeRefPtr<LayoutWrapperNode>(childNodeOne, childGeometryOne, childNodeOne->GetLayoutProperty());
1302 RefPtr<GeometryNode> childGeometryTwo = AceType::MakeRefPtr<GeometryNode>();
1303 auto childNodeTwo = FrameNode::CreateFrameNode("childNodeTwo", 1, AceType::MakeRefPtr<Pattern>(), true);
1304 auto childWrapperTwo =
1305 AceType::MakeRefPtr<LayoutWrapperNode>(childNodeTwo, childGeometryTwo, childNodeTwo->GetLayoutProperty());
1306 layoutWrapper->AppendChild(childWrapperOne);
1307 layoutWrapper->AppendChild(childWrapperTwo);
1308 MeasureLayoutParam layoutParam(AceType::RawPtr(layoutWrapper));
1309 ASSERT_NE(layoutParam.GetOrCreateChildByIndex(0), nullptr);
1310
1311 /**
1312 * @tc.steps: step2. Create new layoutwrapper.
1313 */
1314 RefPtr<GeometryNode> testGeometryNode = AceType::MakeRefPtr<GeometryNode>();
1315 auto testNode = FrameNode::CreateFrameNode("testNode", 1, AceType::MakeRefPtr<Pattern>(), true);
1316 auto testWrapper =
1317 AceType::MakeRefPtr<LayoutWrapperNode>(testNode, testGeometryNode, testNode->GetLayoutProperty());
1318 RefPtr<GeometryNode> testGeometryOne = AceType::MakeRefPtr<GeometryNode>();
1319 auto testNodeOne = FrameNode::CreateFrameNode("testNodeOne", 1, AceType::MakeRefPtr<Pattern>(), true);
1320 auto testWrapperOne =
1321 AceType::MakeRefPtr<LayoutWrapperNode>(testNodeOne, testGeometryOne, testNodeOne->GetLayoutProperty());
1322 RefPtr<GeometryNode> testGeometryTwo = AceType::MakeRefPtr<GeometryNode>();
1323 auto testNodeTwo = FrameNode::CreateFrameNode("testNodeTwo", 1, AceType::MakeRefPtr<Pattern>(), true);
1324 auto testWrapperTwo =
1325 AceType::MakeRefPtr<LayoutWrapperNode>(testNodeTwo, testGeometryTwo, testNodeTwo->GetLayoutProperty());
1326 testWrapper->AppendChild(testWrapperOne);
1327 testWrapper->AppendChild(testWrapperTwo);
1328
1329 /**
1330 * @tc.steps: step3. call the function Update.
1331 */
1332 layoutParam.Update(AceType::RawPtr(testWrapper));
1333 ASSERT_NE(layoutParam.GetOrCreateChildByIndex(0), nullptr);
1334 }
1335
1336 /**
1337 * @tc.name: CustomTest032
1338 * @tc.desc: MeasureLayoutParam Update.
1339 * @tc.type: FUNC
1340 */
1341 HWTEST_F(CustomTestNg, CustomTest032, TestSize.Level1)
1342 {
1343 /**
1344 * @tc.steps: step1. Create MeasureLayoutParam.
1345 */
1346 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
1347 auto frameNode = FrameNode::CreateFrameNode("framenode", 1, AceType::MakeRefPtr<Pattern>(), true);
1348 auto layoutWrapper =
1349 AceType::MakeRefPtr<LayoutWrapperNode>(frameNode, geometryNode, frameNode->GetLayoutProperty());
1350 RefPtr<GeometryNode> childGeometryOne = AceType::MakeRefPtr<GeometryNode>();
1351 auto childNodeOne = FrameNode::CreateFrameNode("childNodeOne", 1, AceType::MakeRefPtr<Pattern>(), true);
1352 auto childWrapperOne =
1353 AceType::MakeRefPtr<LayoutWrapperNode>(childNodeOne, childGeometryOne, childNodeOne->GetLayoutProperty());
1354 layoutWrapper->AppendChild(childWrapperOne);
1355 MeasureLayoutParam layoutParam(AceType::RawPtr(layoutWrapper));
1356 ASSERT_NE(layoutParam.GetOrCreateChildByIndex(0), nullptr);
1357
1358 /**
1359 * @tc.steps: step2. Create new layoutwrapper.
1360 */
1361 RefPtr<GeometryNode> testGeometryNode = AceType::MakeRefPtr<GeometryNode>();
1362 auto testNode = FrameNode::CreateFrameNode("testNode", 1, AceType::MakeRefPtr<Pattern>(), true);
1363 auto testWrapper =
1364 AceType::MakeRefPtr<LayoutWrapperNode>(testNode, testGeometryNode, testNode->GetLayoutProperty());
1365 RefPtr<GeometryNode> testGeometryOne = AceType::MakeRefPtr<GeometryNode>();
1366 auto testNodeOne = FrameNode::CreateFrameNode("testNodeOne", 1, AceType::MakeRefPtr<Pattern>(), true);
1367 auto testWrapperOne =
1368 AceType::MakeRefPtr<LayoutWrapperNode>(testNodeOne, testGeometryOne, testNodeOne->GetLayoutProperty());
1369 RefPtr<GeometryNode> testGeometryTwo = AceType::MakeRefPtr<GeometryNode>();
1370 auto testNodeTwo = FrameNode::CreateFrameNode("testNodeTwo", 1, AceType::MakeRefPtr<Pattern>(), true);
1371 auto testWrapperTwo =
1372 AceType::MakeRefPtr<LayoutWrapperNode>(testNodeTwo, testGeometryTwo, testNodeTwo->GetLayoutProperty());
1373 testWrapper->AppendChild(testWrapperOne);
1374 testWrapper->AppendChild(testWrapperTwo);
1375
1376 /**
1377 * @tc.steps: step3. call the function Update.
1378 */
1379 layoutParam.Update(AceType::RawPtr(testWrapper));
1380 ASSERT_NE(layoutParam.GetOrCreateChildByIndex(0), nullptr);
1381 }
1382
1383 /**
1384 * @tc.name: CustomTest033
1385 * @tc.desc: MeasureLayoutParam Update.
1386 * @tc.type: FUNC
1387 */
1388 HWTEST_F(CustomTestNg, CustomTest033, TestSize.Level1)
1389 {
1390 /**
1391 * @tc.steps: step1. Create MeasureLayoutParam.
1392 */
1393 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
1394 auto frameNode = FrameNode::CreateFrameNode("framenode", 1, AceType::MakeRefPtr<Pattern>(), true);
1395 auto layoutWrapper =
1396 AceType::MakeRefPtr<LayoutWrapperNode>(frameNode, geometryNode, frameNode->GetLayoutProperty());
1397 RefPtr<GeometryNode> childGeometryOne = AceType::MakeRefPtr<GeometryNode>();
1398 auto childNodeOne = FrameNode::CreateFrameNode("childNodeOne", 1, AceType::MakeRefPtr<Pattern>(), true);
1399 auto childWrapperOne =
1400 AceType::MakeRefPtr<LayoutWrapperNode>(childNodeOne, childGeometryOne, childNodeOne->GetLayoutProperty());
1401 RefPtr<GeometryNode> childGeometryTwo = AceType::MakeRefPtr<GeometryNode>();
1402 auto childNodeTwo = FrameNode::CreateFrameNode("childNodeTwo", 1, AceType::MakeRefPtr<Pattern>(), true);
1403 auto childWrapperTwo =
1404 AceType::MakeRefPtr<LayoutWrapperNode>(childNodeTwo, childGeometryTwo, childNodeTwo->GetLayoutProperty());
1405 layoutWrapper->AppendChild(childWrapperOne);
1406 layoutWrapper->AppendChild(childWrapperTwo);
1407 MeasureLayoutParam layoutParam(AceType::RawPtr(layoutWrapper));
1408 ASSERT_NE(layoutParam.GetOrCreateChildByIndex(0), nullptr);
1409
1410 /**
1411 * @tc.steps: step2. Create new layoutwrapper.
1412 */
1413 RefPtr<GeometryNode> testGeometryNode = AceType::MakeRefPtr<GeometryNode>();
1414 auto testNode = FrameNode::CreateFrameNode("testNode", 1, AceType::MakeRefPtr<Pattern>(), true);
1415 auto testWrapper =
1416 AceType::MakeRefPtr<LayoutWrapperNode>(testNode, testGeometryNode, testNode->GetLayoutProperty());
1417 RefPtr<GeometryNode> testGeometryOne = AceType::MakeRefPtr<GeometryNode>();
1418 auto testNodeOne = FrameNode::CreateFrameNode("testNodeOne", 1, AceType::MakeRefPtr<Pattern>(), true);
1419 auto testWrapperOne =
1420 AceType::MakeRefPtr<LayoutWrapperNode>(testNodeOne, testGeometryOne, testNodeOne->GetLayoutProperty());
1421 testWrapper->AppendChild(testWrapperOne);
1422
1423 /**
1424 * @tc.steps: step3. call the function Update.
1425 */
1426 layoutParam.Update(AceType::RawPtr(testWrapper));
1427 ASSERT_NE(layoutParam.GetOrCreateChildByIndex(0), nullptr);
1428 }
1429
1430 /**
1431 * @tc.name: CustomTest034
1432 * @tc.desc: CustomNodeBase.
1433 * @tc.type: FUNC
1434 */
1435 HWTEST_F(CustomTestNg, CustomTest034, TestSize.Level1)
1436 {
1437 /**
1438 * @tc.steps: step1. Create customNode.
1439 */
1440 auto customNode = CustomNode::CreateCustomNode(ElementRegister::GetInstance()->MakeUniqueId(), TEST_TAG);
1441 EXPECT_TRUE(customNode != nullptr && customNode->GetTag() == V2::JS_VIEW_ETS_TAG);
1442
1443 /**
1444 * @tc.steps: step2. call the function FireRecycleRenderFunc.
1445 */
1446 bool appearFuncFlag = true;
__anon71f9752b2b02() 1447 auto appearFunc = [&appearFuncFlag]() { appearFuncFlag = !appearFuncFlag; };
1448 customNode->SetAppearFunction(std::move(appearFunc));
1449 bool didBuildFuncFlag = true;
__anon71f9752b2c02() 1450 auto didBuildFunc = [&didBuildFuncFlag]() { didBuildFuncFlag = !didBuildFuncFlag; };
1451 customNode->SetDidBuildFunction(std::move(didBuildFunc));
1452 bool recycleRenderFuncFlag = true;
__anon71f9752b2d02() 1453 auto recycleRenderFunc = [&recycleRenderFuncFlag]() { recycleRenderFuncFlag = !recycleRenderFuncFlag; };
1454 customNode->SetRecycleRenderFunc(std::move(recycleRenderFunc));
1455 customNode->FireRecycleRenderFunc();
1456 customNode.Reset();
1457 EXPECT_FALSE(appearFuncFlag);
1458 EXPECT_FALSE(didBuildFuncFlag);
1459 EXPECT_FALSE(recycleRenderFuncFlag);
1460 }
1461
1462 /**
1463 * @tc.name: CustomTest035
1464 * @tc.desc: CustomNodeBase.
1465 * @tc.type: FUNC
1466 */
1467 HWTEST_F(CustomTestNg, CustomTest035, TestSize.Level1)
1468 {
1469 /**
1470 * @tc.steps: step1. Create customNode.
1471 */
1472 auto customNode = CustomNode::CreateCustomNode(ElementRegister::GetInstance()->MakeUniqueId(), TEST_TAG);
1473 EXPECT_TRUE(customNode != nullptr && customNode->GetTag() == V2::JS_VIEW_ETS_TAG);
1474
1475 /**
1476 * @tc.steps: step2. call the function FireRecycleRenderFunc.
1477 */
1478 bool appearFuncFlag = true;
__anon71f9752b2e02() 1479 auto appearFunc = [&appearFuncFlag]() { appearFuncFlag = !appearFuncFlag; };
1480 customNode->SetAppearFunction(std::move(appearFunc));
1481 bool recycleRenderFuncFlag = true;
__anon71f9752b2f02() 1482 auto recycleRenderFunc = [&recycleRenderFuncFlag]() { recycleRenderFuncFlag = !recycleRenderFuncFlag; };
1483 customNode->SetRecycleRenderFunc(std::move(recycleRenderFunc));
1484 customNode->FireRecycleRenderFunc();
1485 customNode.Reset();
1486 EXPECT_FALSE(appearFuncFlag);
1487 EXPECT_FALSE(recycleRenderFuncFlag);
1488 }
1489
1490 /**
1491 * @tc.name: CustomTest036
1492 * @tc.desc: CustomMeasureLayoutNode::FireOnUpdateParam.
1493 * @tc.type: FUNC
1494 */
1495 HWTEST_F(CustomTestNg, CustomTest036, TestSize.Level1)
1496 {
1497 /**
1498 * @tc.steps: step1. Create customNode.
1499 */
1500 auto customNode = CustomMeasureLayoutNode::CreateCustomMeasureLayoutNode(
1501 ElementRegister::GetInstance()->MakeUniqueId(), TEST_TAG);
1502 CustomTitleNode titleNode(1, "title");
1503 titleNode.FireAppTitleCallback("abc");
1504 EXPECT_TRUE(customNode != nullptr && customNode->GetTag() == V2::JS_VIEW_ETS_TAG);
1505
1506 /**
1507 * @tc.steps: step2. call the function FireOnUpdateParam.
1508 */
1509 bool updateParamFuncFlag = true;
1510 auto updateParamFunc = [&updateParamFuncFlag](
__anon71f9752b3002( LayoutWrapper* layoutWrapper) 1511 LayoutWrapper* layoutWrapper) { updateParamFuncFlag = !updateParamFuncFlag; };
1512 customNode->SetUpdateParamFunc(std::move(updateParamFunc));
1513 RefPtr<GeometryNode> testGeometryNode = AceType::MakeRefPtr<GeometryNode>();
1514 auto testNode = FrameNode::CreateFrameNode("testNode", 1, AceType::MakeRefPtr<Pattern>(), true);
1515 auto testWrapper =
1516 AceType::MakeRefPtr<LayoutWrapperNode>(testNode, testGeometryNode, testNode->GetLayoutProperty());
1517 EXPECT_TRUE(customNode->FireOnUpdateParam(AceType::RawPtr(testWrapper)));
1518 }
1519
1520 /**
1521 * @tc.name: CustomTest037
1522 * @tc.desc: CustomNodeLayoutAlgorithm::Measure.
1523 * @tc.type: FUNC
1524 */
1525 HWTEST_F(CustomTestNg, CustomTest037, TestSize.Level1)
1526 {
1527 /**
1528 * @tc.steps: step1. Create CustomNodeLayoutAlgorithm and frameNode.
1529 */
1530 CustomNodeLayoutAlgorithm test = CustomNodeLayoutAlgorithm(nullptr);
1531 auto frameNode = CreateNode(V2::TEXT_ETS_TAG);
1532
1533 /**
1534 * @tc.steps: step2. call the function Measure.
1535 */
1536 bool measureFuncFlag = true;
__anon71f9752b3102(LayoutWrapper* layoutWrapper) 1537 auto measureFunc = [&measureFuncFlag](LayoutWrapper* layoutWrapper) { measureFuncFlag = !measureFuncFlag; };
1538 auto customNode = CustomMeasureLayoutNode::CreateCustomMeasureLayoutNode(
1539 ElementRegister::GetInstance()->MakeUniqueId(), TEST_TAG);
1540 EXPECT_TRUE(customNode != nullptr && customNode->GetTag() == V2::JS_VIEW_ETS_TAG);
1541 customNode->SetMeasureFunction(std::move(measureFunc));
1542 auto layoutWrapper = customNode->CreateLayoutWrapper();
1543 test.Measure(AceType::RawPtr(layoutWrapper));
1544 EXPECT_FALSE(measureFuncFlag);
1545 }
1546 } // namespace OHOS::Ace::NG
1547