1 /*
2 * Copyright (c) 2022 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 <memory>
17 #include <ostream>
18 #include <utility>
19
20 #include "gtest/gtest.h"
21
22 #define protected public
23 #define private public
24
25 #include "base/log/dump_log.h"
26 #include "base/log/log_wrapper.h"
27 #include "core/components_ng/base/frame_node.h"
28 #include "core/components_ng/base/ui_node.h"
29 #include "core/components_ng/event/event_hub.h"
30 #include "core/components_ng/event/focus_hub.h"
31 #include "core/components_ng/pattern/pattern.h"
32 #include "core/components_ng/property/property.h"
33 #include "core/pipeline_ng/pipeline_context.h"
34 #include "test/mock/core/pipeline/mock_pipeline_context.h"
35
36 using namespace testing;
37 using namespace testing::ext;
38
39 namespace OHOS::Ace::NG {
40 namespace {
41 const RefPtr<FrameNode> TEN0 = FrameNode::CreateFrameNode("zero", 10, AceType::MakeRefPtr<Pattern>(), true);
42 const RefPtr<FrameNode> ZERO = FrameNode::CreateFrameNode("zero", 0, AceType::MakeRefPtr<Pattern>(), true);
43 const RefPtr<FrameNode> ONE = FrameNode::CreateFrameNode("one", 1, AceType::MakeRefPtr<Pattern>(), true);
44 const RefPtr<FrameNode> TWO = FrameNode::CreateFrameNode("two", 2, AceType::MakeRefPtr<Pattern>());
45 const RefPtr<FrameNode> THREE = FrameNode::CreateFrameNode("three", 3, AceType::MakeRefPtr<Pattern>());
46 const RefPtr<FrameNode> FOUR = FrameNode::CreateFrameNode("four", 4, AceType::MakeRefPtr<Pattern>());
47 const RefPtr<FrameNode> FIVE = FrameNode::CreateFrameNode("five", 5, AceType::MakeRefPtr<Pattern>());
48 const RefPtr<FrameNode> F_ONE = FrameNode::CreateFrameNode("one", 5, AceType::MakeRefPtr<Pattern>());
49 const int32_t TEST_ID_ONE = 21;
50 const int32_t TEST_ID_TWO = 22;
51 } // namespace
52
53 class TestNode : public UINode {
54 DECLARE_ACE_TYPE(TestNode, UINode);
55
56 public:
CreateTestNode(int32_t nodeId)57 static RefPtr<TestNode> CreateTestNode(int32_t nodeId)
58 {
59 auto spanNode = MakeRefPtr<TestNode>(nodeId);
60 return spanNode;
61 }
62
IsAtomicNode() const63 bool IsAtomicNode() const override
64 {
65 return true;
66 }
67
TestNode(int32_t nodeId)68 explicit TestNode(int32_t nodeId) : UINode("TestNode", nodeId) {}
69
TouchTest(const PointF & globalPoint,const PointF & parentLocalPoint,const PointF & parentRevertPoint,TouchRestrict & touchRestrict,TouchTestResult & result,int32_t touchId,bool isDispatch=false)70 HitTestResult TouchTest(const PointF& globalPoint, const PointF& parentLocalPoint, const PointF& parentRevertPoint,
71 TouchRestrict& touchRestrict, TouchTestResult& result, int32_t touchId, bool isDispatch = false) override
72 {
73 return hitTestResult_;
74 }
75
MouseTest(const PointF & globalPoint,const PointF & parentLocalPoint,MouseTestResult & onMouseResult,MouseTestResult & onHoverResult,RefPtr<FrameNode> & hoverNode)76 HitTestResult MouseTest(const PointF& globalPoint, const PointF& parentLocalPoint, MouseTestResult& onMouseResult,
77 MouseTestResult& onHoverResult, RefPtr<FrameNode>& hoverNode) override
78 {
79 return hitTestResult_;
80 }
81
AxisTest(const PointF & globalPoint,const PointF & parentLocalPoint,AxisTestResult & onAxisResult)82 HitTestResult AxisTest(
83 const PointF& globalPoint, const PointF& parentLocalPoint, AxisTestResult& onAxisResult) override
84 {
85 return hitTestResult_;
86 }
87
88 ~TestNode() override = default;
89
90 private:
91 HitTestResult hitTestResult_;
92 };
93
94 class UINodeTestNg : public testing::Test {
95 public:
96 static void SetUpTestSuite();
97 static void TearDownTestSuite();
98 };
99
SetUpTestSuite()100 void UINodeTestNg::SetUpTestSuite()
101 {
102 MockPipelineContext::SetUp();
103 }
104
TearDownTestSuite()105 void UINodeTestNg::TearDownTestSuite()
106 {
107 MockPipelineContext::TearDown();
108 }
109
110 /**
111 * @tc.name: UINodeTestNg001
112 * @tc.desc: Test ui node method
113 * @tc.type: FUNC
114 */
115 HWTEST_F(UINodeTestNg, UINodeTestNg001, TestSize.Level1)
116 {
117 /**
118 * @tc.steps: step1. AddChild
119 * @tc.expected: children_.size = 2
120 */
121 ONE->AddChild(TWO, 1, false);
122 auto testNode = TestNode::CreateTestNode(TEST_ID_ONE);
123 auto testNode2 = TestNode::CreateTestNode(TEST_ID_TWO);
124 ONE->AddChild(testNode, 1, false);
125 ONE->AddChild(testNode, 1, false);
126 ONE->AddChild(testNode2, 1, false);
127 EXPECT_EQ(ONE->children_.size(), 3);
128 /**
129 * @tc.steps: step2. remove child three
130 */
131 auto iter = ONE->RemoveChild(FOUR);
132 EXPECT_EQ(iter, ONE->children_.end());
133 ONE->RemoveChild(testNode);
134 ONE->RemoveChild(testNode2, true);
135 /**
136 * @tc.steps: step3. remove child two
137 * @tc.expected: distance = 0
138 */
139 auto distance = ONE->RemoveChildAndReturnIndex(TWO);
140 EXPECT_EQ(distance, 0);
141 }
142
143 /**
144 * @tc.name: UINodeTestNg002
145 * @tc.desc: Test ui node method
146 * @tc.type: FUNC
147 */
148 HWTEST_F(UINodeTestNg, UINodeTestNg002, TestSize.Level1)
149 {
150 ONE->RemoveChildAtIndex(-1);
151 ONE->AddChild(TWO, 1, false);
152 /**
153 * @tc.steps: step1. RemoveChildAtIndex
154 * @tc.expected: children_.size = 0
155 */
156 ONE->RemoveChildAtIndex(0);
157 EXPECT_EQ(ONE->children_.size(), 0);
158 /**
159 * @tc.steps: step2. GetChildAtIndex
160 * @tc.expected: return nullptr
161 */
162 auto result = ONE->GetChildAtIndex(0);
163 EXPECT_EQ(result, nullptr);
164 ONE->AddChild(TWO, 1, false);
165 auto node = ONE->GetChildAtIndex(0);
166 EXPECT_EQ(strcmp(node->GetTag().c_str(), "two"), 0);
167 }
168
169 /**
170 * @tc.name: UINodeTestNg003
171 * @tc.desc: Test ui node method
172 * @tc.type: FUNC
173 */
174 HWTEST_F(UINodeTestNg, UINodeTestNg003, TestSize.Level1)
175 {
176 ONE->AddChild(TWO, 1, false);
177 /**
178 * @tc.steps: step1. ReplaceChild
179 * @tc.expected: size = 2
180 */
181 ONE->ReplaceChild(nullptr, THREE);
182 ONE->ReplaceChild(TWO, FOUR);
183 EXPECT_EQ(ONE->children_.size(), 2);
184 /**
185 * @tc.steps: step2. set TWO's hostPageId_ 1 and Clean
186 * @tc.expected: children_ = 0
187 */
188 TWO->hostPageId_ = 1;
189 ONE->MountToParent(TWO, 1, false);
190 ONE->Clean();
191 EXPECT_EQ(ONE->children_.size(), 0);
192 }
193
194 /**
195 * @tc.name: UINodeTestNg004
196 * @tc.desc: Test ui node method
197 * @tc.type: FUNC
198 */
199 HWTEST_F(UINodeTestNg, UINodeTestNg004, TestSize.Level1)
200 {
201 /**
202 * @tc.steps: step1. GetFocusParent
203 * @tc.expected: parent is nullptr
204 */
205 auto frameNode = ONE->GetFocusParent();
206 EXPECT_EQ(frameNode, nullptr);
207 FocusType focusTypes[3] = { FocusType::SCOPE, FocusType::NODE, FocusType::DISABLE };
208 auto parent = FrameNode::CreateFrameNode("parent", 2, AceType::MakeRefPtr<Pattern>());
209 RefPtr<FrameNode> frameNodes[3] = { parent, nullptr, nullptr };
210 /**
211 * @tc.steps: step2. GetFocusParent adjust FocusType
212 * @tc.expected: result is parent and nullptr
213 */
214 for (int i = 0; i < 3; ++i) {
215 auto eventHub = AceType::MakeRefPtr<EventHub>();
216 auto focusHub = AceType::MakeRefPtr<FocusHub>(eventHub, focusTypes[i]);
217 eventHub->focusHub_ = focusHub;
218 parent->eventHub_ = eventHub;
219 ONE->parent_ = parent;
220 auto result = ONE->GetFocusParent();
221 EXPECT_EQ(result, frameNodes[i]);
222 }
223 /**
224 * @tc.steps: step3. create test node and try GetFirstFocusHubChild
225 * @tc.expected: result is null
226 */
227 auto testNode = TestNode::CreateTestNode(TEST_ID_ONE);
228 EXPECT_EQ(testNode->GetFirstFocusHubChild(), nullptr);
229 /**
230 * @tc.steps: step4. config node parent and GetFocusParent;
231 * @tc.expected: result is null
232 */
233 ONE->parent_ = testNode;
234 testNode->parent_ = parent;
235 auto result = ONE->GetFocusParent();
236 EXPECT_EQ(result, nullptr);
237 }
238
239 /**
240 * @tc.name: UINodeTestNg005
241 * @tc.desc: Test ui node method
242 * @tc.type: FUNC
243 */
244 HWTEST_F(UINodeTestNg, UINodeTestNg005, TestSize.Level1)
245 {
246 /**
247 * @tc.steps: step1. GetFocusChildren
248 * @tc.expected: THREE's children size is 2
249 */
250 std::list<RefPtr<FrameNode>> children;
251 auto eventHubTwo = AceType::MakeRefPtr<EventHub>();
252 auto focusHubTwo = AceType::MakeRefPtr<FocusHub>(eventHubTwo, FocusType::NODE);
253 auto eventHubFour = AceType::MakeRefPtr<EventHub>();
254 auto focusHubFour = AceType::MakeRefPtr<FocusHub>(eventHubFour, FocusType::DISABLE);
255 eventHubTwo->focusHub_ = focusHubTwo;
256 TWO->eventHub_ = eventHubTwo;
257 eventHubFour->focusHub_ = focusHubFour;
258 FOUR->eventHub_ = eventHubFour;
259 THREE->AddChild(TWO, 1, false);
260 THREE->AddChild(FOUR, 1, false);
261 THREE->AddChild(TestNode::CreateTestNode(TEST_ID_ONE), 1, false);
262 THREE->GetFocusChildren(children);
263 EXPECT_EQ(THREE->children_.size(), 3);
264 THREE->Clean();
265 }
266
267 /**
268 * @tc.name: UINodeTestNg006
269 * @tc.desc: Test ui node method
270 * @tc.type: FUNC
271 */
272 HWTEST_F(UINodeTestNg, UINodeTestNg006, TestSize.Level1)
273 {
274 /**
275 * @tc.steps: step1. AttachToMainTree and DetachFromMainTree
276 * @tc.expected: onMainTree_ is false
277 */
278 bool mainTrees[2] = { true, false };
279 TWO->AddChild(THREE, 1, false);
280 for (int i = 0; i < 2; ++i) {
281 TWO->onMainTree_ = mainTrees[i];
282 TWO->AttachToMainTree();
283 TWO->DetachFromMainTree();
284 EXPECT_FALSE(TWO->onMainTree_);
285 }
286 TWO->Clean();
287 }
288
289 /**
290 * @tc.name: UINodeTestNg007
291 * @tc.desc: Test ui node method
292 * @tc.type: FUNC
293 */
294 HWTEST_F(UINodeTestNg, UINodeTestNg007, TestSize.Level1)
295 {
296 /**
297 * @tc.steps: step1. MovePosition
298 * @tc.expected: children_.size is 2
299 */
300 int32_t slots[4] = { 1, -1, 1, 2 };
301 THREE->AddChild(FOUR);
302 THREE->AddChild(FIVE);
303 TWO->parent_ = THREE;
304 for (int i = 0; i < 4; ++i) {
305 TWO->MovePosition(slots[i]);
306 }
307 EXPECT_EQ(THREE->children_.size(), 3);
308 THREE->Clean();
309 }
310
311 /**
312 * @tc.name: UINodeTestNg008
313 * @tc.desc: Test ui node method
314 * @tc.type: FUNC
315 */
316 HWTEST_F(UINodeTestNg, UINodeTestNg008, TestSize.Level1)
317 {
318 PropertyChangeFlag FLAG = 1;
319 ONE->children_.clear();
320 TWO->children_.clear();
321 THREE->children_.clear();
322 ONE->AddChild(TWO, 1, false);
323 ONE->parent_ = THREE;
324 ONE->UINode::UpdateLayoutPropertyFlag();
325 ONE->UINode::AdjustParentLayoutFlag(FLAG);
326 ONE->UINode::MarkNeedSyncRenderTree();
327 ONE->UINode::RebuildRenderContextTree();
328 ONE->DumpTree(0);
329 EXPECT_EQ(ONE->children_.size(), 1);
330 auto pipeline = UINode::GetContext();
331 EXPECT_NE(pipeline, nullptr);
332 }
333
334 /**
335 * @tc.name: UINodeTestNg009
336 * @tc.desc: Test ui node method
337 * @tc.type: FUNC
338 */
339 HWTEST_F(UINodeTestNg, UINodeTestNg009, TestSize.Level1)
340 {
341 /**
342 * @tc.steps: step1. FrameCount and GetChildIndexById
343 * @tc.expected: count is 2, pos is 0
344 */
345 int32_t count = ONE->FrameCount();
346 EXPECT_EQ(count, 1);
347 int32_t id1 = ONE->GetChildIndexById(4);
348 int32_t id2 = ONE->GetChildIndexById(2);
349 EXPECT_EQ(id1, -1);
350 EXPECT_EQ(id2, 0);
351 /**
352 * @tc.steps: step2. GetChildFlatIndex
353 * @tc.expected: count is 2, pos is 0
354 */
355 auto pair1 = ONE->GetChildFlatIndex(1);
356 EXPECT_EQ(pair1.second, 0);
357 auto pair2 = ONE->GetChildFlatIndex(2);
358 EXPECT_EQ(pair2.second, 0);
359 }
360
361 /**
362 * @tc.name: UINodeTestNg010
363 * @tc.desc: Test ui node method
364 * @tc.type: FUNC
365 */
366 HWTEST_F(UINodeTestNg, UINodeTestNg010, TestSize.Level1)
367 {
368 /**
369 * @tc.steps: step1. call the GetChildIndex and set input is null
370 * @tc.expected: the return value is -1
371 */
372 int retIndex = ZERO->GetChildIndex(nullptr);
373 EXPECT_EQ(retIndex, -1);
374 /**
375 * @tc.steps: step2. add one child for ZERO and call GetChildIndex
376 * @tc.expected: step2. the return value is 0
377 */
378 ZERO->AddChild(ONE);
379 retIndex = ZERO->GetChildIndex(ONE);
380 EXPECT_EQ(retIndex, 0);
381 /**
382 * @tc.steps: step3. add two child for ZERO and call GetChildIndex
383 * @tc.expected: the return value is 1
384 */
385 ZERO->AddChild(TWO);
386 retIndex = ZERO->GetChildIndex(TWO);
387 EXPECT_EQ(retIndex, 1);
388 /**
389 * @tc.steps: step4. add three child for ZERO and call GetChildIndex
390 * @tc.expected: the return value is 2
391 */
392 ZERO->AddChild(THREE);
393 retIndex = ZERO->GetChildIndex(THREE);
394 EXPECT_EQ(retIndex, 2);
395 ZERO->Clean();
396 }
397
398 /**
399 * @tc.name: UINodeTestNg011
400 * @tc.desc: Test ui node method
401 * @tc.type: FUNC
402 */
403 HWTEST_F(UINodeTestNg, UINodeTestNg011, TestSize.Level1)
404 {
405 /**
406 * @tc.steps: step1. call the MountToParent and set hostPageId_ is 0
407 * @tc.expected: step2. mount failure
408 */
409 ZERO->hostPageId_ = 0;
410 ONE->MountToParent(ZERO, 1, false);
411 int retPageId = ONE->GetPageId();
412 EXPECT_NE(retPageId, 0);
413 ONE->Clean();
414 /**
415 * @tc.steps: step2. call the MountToParent and set hostPageId_ is 0
416 * @tc.expected: mount sucess and pageid is 1
417 */
418 ZERO->hostPageId_ = 1;
419 ZERO->SetInDestroying();
420 ONE->MountToParent(ZERO, 1, false);
421 retPageId = ONE->GetPageId();
422 EXPECT_EQ(retPageId, 1);
423 ONE->Clean();
424 ZERO->Clean();
425 }
426
427 /**
428 * @tc.name: UINodeTestNg012
429 * @tc.desc: Test ui node method
430 * @tc.type: FUNC
431 */
432 HWTEST_F(UINodeTestNg, UINodeTestNg012, TestSize.Level1)
433 {
434 /**
435 * @tc.steps: step1. call the GetFirstFocusHubChild function
436 * @tc.expected: the return value is null
437 */
438 RefPtr<FocusHub> retFirstFocusHubChild = ZERO->GetFirstFocusHubChild();
439 EXPECT_EQ(retFirstFocusHubChild, nullptr);
440 /**
441 * @tc.steps: step2. call the GetFirstFocusHubChild functionand and set focus type is DISABLE
442 * @tc.expected: the return value is null
443 */
444 auto eventHubZero = AceType::MakeRefPtr<EventHub>();
445 auto focusHubZero = AceType::MakeRefPtr<FocusHub>(eventHubZero, FocusType::DISABLE);
446
447 eventHubZero->focusHub_ = focusHubZero;
448 ZERO->eventHub_ = eventHubZero;
449 retFirstFocusHubChild = ZERO->GetFirstFocusHubChild();
450 EXPECT_EQ(retFirstFocusHubChild, nullptr);
451 /**
452 * @tc.steps: step3. call the GetFirstFocusHubChild functionand set focus type is NODE
453 * @tc.expected: the return focusHub type is NODE
454 */
455 focusHubZero = AceType::MakeRefPtr<FocusHub>(eventHubZero, FocusType::NODE);
456
457 eventHubZero->focusHub_ = focusHubZero;
458 ZERO->eventHub_ = eventHubZero;
459 retFirstFocusHubChild = ZERO->GetFirstFocusHubChild();
460 EXPECT_EQ(retFirstFocusHubChild->GetFocusType(), FocusType::NODE);
461 ZERO->Clean();
462 /**
463 * @tc.steps: step4. call the GetFirstFocusHubChild functionand set focus type is SCOPE
464 * @tc.expected: the return focusHub type is SCOPE
465 */
466 focusHubZero = AceType::MakeRefPtr<FocusHub>(eventHubZero, FocusType::SCOPE);
467
468 eventHubZero->focusHub_ = focusHubZero;
469 ZERO->eventHub_ = eventHubZero;
470 retFirstFocusHubChild = ZERO->GetFirstFocusHubChild();
471 EXPECT_EQ(retFirstFocusHubChild->GetFocusType(), FocusType::SCOPE);
472 ZERO->Clean();
473 }
474
475 /**
476 * @tc.name: UINodeTestNg013
477 * @tc.desc: Test ui node method
478 * @tc.type: FUNC
479 */
480 HWTEST_F(UINodeTestNg, UINodeTestNg013, TestSize.Level1)
481 {
482 /**
483 * @tc.steps: step1. add one child to ZERO and set focus type is NODE
484 * @tc.expected: the return focusHub type is NODE
485 */
486 auto eventHubZero = AceType::MakeRefPtr<EventHub>();
487 auto focusHubZero = AceType::MakeRefPtr<FocusHub>(eventHubZero, FocusType::DISABLE);
488 auto eventHubOne = AceType::MakeRefPtr<EventHub>();
489 auto focusHubOne = AceType::MakeRefPtr<FocusHub>(eventHubOne, FocusType::NODE);
490
491 eventHubZero->focusHub_ = focusHubZero;
492 ZERO->eventHub_ = eventHubZero;
493 eventHubOne->focusHub_ = focusHubOne;
494 ONE->eventHub_ = eventHubOne;
495
496 ZERO->AddChild(ONE, 1, false);
497 RefPtr<FocusHub> retFirstFocusHubChild = ZERO->GetFirstFocusHubChild();
498 EXPECT_EQ(retFirstFocusHubChild->GetFocusType(), FocusType::NODE);
499 ZERO->Clean();
500 /**
501 * @tc.steps: step2. add one child to ZERO and set focus type is DISABLE
502 * @tc.expected: the return value is null
503 */
504 focusHubOne = AceType::MakeRefPtr<FocusHub>(eventHubOne, FocusType::DISABLE);
505
506 eventHubOne->focusHub_ = focusHubOne;
507 ONE->eventHub_ = eventHubOne;
508 ZERO->AddChild(ONE, 1, false);
509 retFirstFocusHubChild = ZERO->GetFirstFocusHubChild();
510 EXPECT_EQ(retFirstFocusHubChild, nullptr);
511 ZERO->Clean();
512 }
513
514 /**
515 * @tc.name: UINodeTestNg014
516 * @tc.desc: Test ui node method
517 * @tc.type: FUNC
518 */
519 HWTEST_F(UINodeTestNg, UINodeTestNg014, TestSize.Level1)
520 {
521 /**
522 * @tc.steps: step1. add one child to ZERO and set focus type is SCOPE
523 * @tc.expected: the return focusHub type is SCOPE
524 */
525 auto eventHubZero = AceType::MakeRefPtr<EventHub>();
526 auto focusHubZero = AceType::MakeRefPtr<FocusHub>(eventHubZero, FocusType::DISABLE);
527 auto eventHubOne = AceType::MakeRefPtr<EventHub>();
528 auto focusHubOne = AceType::MakeRefPtr<FocusHub>(eventHubOne, FocusType::SCOPE);
529
530 eventHubZero->focusHub_ = focusHubZero;
531 ZERO->eventHub_ = eventHubZero;
532 eventHubOne->focusHub_ = focusHubOne;
533 ONE->eventHub_ = eventHubOne;
534
535 ZERO->AddChild(ONE, 1, false);
536 RefPtr<FocusHub> retFirstFocusHubChild = ZERO->GetFirstFocusHubChild();
537 EXPECT_EQ(retFirstFocusHubChild->GetFocusType(), FocusType::SCOPE);
538 ZERO->Clean();
539 /**
540 * @tc.steps: step2. add one child to ZERO and set focus type is DISABLE
541 * @tc.expected: the return value is null
542 */
543 focusHubOne = AceType::MakeRefPtr<FocusHub>(eventHubOne, FocusType::DISABLE);
544
545 eventHubOne->focusHub_ = focusHubOne;
546 ONE->eventHub_ = eventHubOne;
547 ZERO->AddChild(ONE, 1, false);
548 retFirstFocusHubChild = ZERO->GetFirstFocusHubChild();
549 EXPECT_EQ(retFirstFocusHubChild, nullptr);
550 ZERO->Clean();
551 }
552
553 /**
554 * @tc.name: UINodeTestNg015
555 * @tc.desc: Test ui node method
556 * @tc.type: FUNC
557 */
558 HWTEST_F(UINodeTestNg, UINodeTestNg015, TestSize.Level1)
559 {
560 /**
561 * @tc.steps: step1. call the MovePosition and set parent_ is null
562 * @tc.expected: parentNode is null
563 */
564 ZERO->parent_ = nullptr;
565 ZERO->MovePosition(1);
566 RefPtr<UINode> retParent = ZERO->GetParent();
567 EXPECT_EQ(retParent, nullptr);
568 }
569
570 /**
571 * @tc.name: UINodeTestNg016
572 * @tc.desc: Test ui node method
573 * @tc.type: FUNC
574 */
575 HWTEST_F(UINodeTestNg, UINodeTestNg016, TestSize.Level1)
576 {
577 /**
578 * @tc.steps: step1. set propertyChangeFlag_ is PROPERTY_UPDATE_NORMAL and call the MarkDirtyNode
579 * @tc.expected: the MarkDirtyNode function is run ok and children_.size() is 1
580 */
581 PropertyChangeFlag extraFLAG = PROPERTY_UPDATE_NORMAL;
582 ZERO->layoutProperty_->propertyChangeFlag_ = PROPERTY_UPDATE_NORMAL;
583 ONE->layoutProperty_->propertyChangeFlag_ = PROPERTY_UPDATE_NORMAL;
584
585 ZERO->AddChild(ONE, 1, false);
586 ZERO->UINode::MarkDirtyNode(extraFLAG);
587 EXPECT_EQ(ZERO->children_.size(), 1);
588 ZERO->Clean();
589 /**
590 * @tc.steps: step2. set propertyChangeFlag_ is PROPERTY_UPDATE_MEASURE and call the MarkDirtyNode
591 * @tc.expected: the MarkDirtyNode function is run ok and children_.size() is 1
592 */
593 extraFLAG = PROPERTY_UPDATE_MEASURE;
594 ZERO->layoutProperty_->propertyChangeFlag_ = PROPERTY_UPDATE_MEASURE;
595 ONE->layoutProperty_->propertyChangeFlag_ = PROPERTY_UPDATE_MEASURE;
596 ZERO->AddChild(ONE, 1, false);
597 ZERO->UINode::MarkDirtyNode(extraFLAG);
598 EXPECT_EQ(ZERO->children_.size(), 1);
599 ZERO->Clean();
600 /**
601 * @tc.steps: step3. set propertyChangeFlag_ is PROPERTY_UPDATE_LAYOUT and call the MarkDirtyNode
602 * @tc.expected: the MarkDirtyNode function is run ok and children_.size() is 1
603 */
604 extraFLAG = PROPERTY_UPDATE_LAYOUT;
605 ZERO->layoutProperty_->propertyChangeFlag_ = PROPERTY_UPDATE_LAYOUT;
606 ONE->layoutProperty_->propertyChangeFlag_ = PROPERTY_UPDATE_LAYOUT;
607 ZERO->AddChild(ONE, 1, false);
608 ZERO->UINode::MarkDirtyNode(extraFLAG);
609 EXPECT_EQ(ZERO->children_.size(), 1);
610 ZERO->Clean();
611 }
612
613 /**
614 * @tc.name: UINodeTestNg017
615 * @tc.desc: Test ui node method
616 * @tc.type: FUNC
617 */
618 HWTEST_F(UINodeTestNg, UINodeTestNg017, TestSize.Level1)
619 {
620 /**
621 * @tc.steps: step1. set propertyChangeFlag_ is PROPERTY_UPDATE_NORMAL and call the MarkNeedFrameFlushDirty
622 * @tc.expected: the MarkNeedFrameFlushDirty function is run ok
623 */
624 PropertyChangeFlag extraFLAG = PROPERTY_UPDATE_NORMAL;
625 ZERO->layoutProperty_->propertyChangeFlag_ = PROPERTY_UPDATE_NORMAL;
626 ONE->layoutProperty_->propertyChangeFlag_ = PROPERTY_UPDATE_NORMAL;
627
628 ZERO->UINode::MarkNeedFrameFlushDirty(extraFLAG);
629 EXPECT_EQ(ZERO->parent_.Upgrade(), nullptr);
630 /**
631 * @tc.steps: step2. set one parent_ for ONE and call the MarkNeedFrameFlushDirty
632 * @tc.expected: the MarkNeedFrameFlushDirty function is run ok and parent_ is not null
633 */
634 ZERO->parent_ = ONE;
635 ZERO->UINode::MarkNeedFrameFlushDirty(extraFLAG);
636 ASSERT_NE(ZERO->parent_.Upgrade(), nullptr);
637 ZERO->Clean();
638 ZERO->parent_.Reset();
639 /**
640 * @tc.steps: step3. set propertyChangeFlag_ is PROPERTY_UPDATE_MEASURE and call the MarkNeedFrameFlushDirty
641 * @tc.expected: the MarkNeedFrameFlushDirty function is run ok
642 */
643 extraFLAG = PROPERTY_UPDATE_MEASURE;
644 ZERO->layoutProperty_->propertyChangeFlag_ = PROPERTY_UPDATE_MEASURE;
645 ONE->layoutProperty_->propertyChangeFlag_ = PROPERTY_UPDATE_MEASURE;
646
647 ZERO->UINode::MarkNeedFrameFlushDirty(extraFLAG);
648 EXPECT_EQ(ZERO->parent_.Upgrade(), nullptr);
649 /**
650 * @tc.steps: step4. set one parent_ for ONE and call the MarkNeedFrameFlushDirty
651 * @tc.expected: the MarkNeedFrameFlushDirty function is run ok and parent_ is not null
652 */
653 ZERO->parent_ = ONE;
654 ZERO->UINode::MarkNeedFrameFlushDirty(extraFLAG);
655 ASSERT_NE(ZERO->parent_.Upgrade(), nullptr);
656 ZERO->Clean();
657 ZERO->parent_.Reset();
658 /**
659 * @tc.steps: step5. set propertyChangeFlag_ is PROPERTY_UPDATE_LAYOUT and call the MarkNeedFrameFlushDirty
660 * @tc.expected: the MarkNeedFrameFlushDirty function is run ok
661 */
662 extraFLAG = PROPERTY_UPDATE_LAYOUT;
663 ZERO->layoutProperty_->propertyChangeFlag_ = PROPERTY_UPDATE_LAYOUT;
664 ONE->layoutProperty_->propertyChangeFlag_ = PROPERTY_UPDATE_LAYOUT;
665
666 ZERO->UINode::MarkNeedFrameFlushDirty(extraFLAG);
667 EXPECT_EQ(ZERO->parent_.Upgrade(), nullptr);
668 /**
669 * @tc.steps: step6. set one parent_ for ONE and call the MarkNeedFrameFlushDirty
670 * @tc.expected: the MarkNeedFrameFlushDirty function is run ok and parent_ is not null
671 */
672 ZERO->parent_ = ONE;
673 ZERO->UINode::MarkNeedFrameFlushDirty(extraFLAG);
674 ASSERT_NE(ZERO->parent_.Upgrade(), nullptr);
675 ZERO->Clean();
676 ZERO->parent_.Reset();
677 }
678
679 /**
680 * @tc.name: UINodeTestNg018
681 * @tc.desc: Test ui node method
682 * @tc.type: FUNC
683 */
684 HWTEST_F(UINodeTestNg, UINodeTestNg018, TestSize.Level1)
685 {
686 /**
687 * @tc.steps: step1. set ZERO->parent_ is null and call MarkNeedSyncRenderTree
688 * @tc.expected: the MarkNeedSyncRenderTree function is run ok
689 */
690 ZERO->UINode::MarkNeedSyncRenderTree();
691 EXPECT_EQ(ZERO->parent_.Upgrade(), nullptr);
692 /**
693 * @tc.steps: step2. set ZERO->parent_ is null and call RebuildRenderContextTree
694 * @tc.expected: the RebuildRenderContextTree function is run ok
695 */
696 ZERO->UINode::RebuildRenderContextTree();
697 EXPECT_EQ(ZERO->parent_.Upgrade(), nullptr);
698 }
699
700 /**
701 * @tc.name: UINodeTestNg019
702 * @tc.desc: Test ui node method
703 * @tc.type: FUNC
704 */
705 HWTEST_F(UINodeTestNg, UINodeTestNg019, TestSize.Level1)
706 {
707 /**
708 * @tc.steps: step1. call the DetachFromMainTree
709 * @tc.expected: onMainTree_ is false
710 */
711 bool mainTree = true;
712 ZERO->onMainTree_ = mainTree;
713 ZERO->DetachFromMainTree();
714 EXPECT_FALSE(ZERO->onMainTree_);
715 ZERO->Clean();
716 ZERO->UINode::OnDetachFromMainTree();
717 }
718
719 /**
720 * @tc.name: UINodeTestNg020
721 * @tc.desc: Test ui node method
722 * @tc.type: FUNC
723 */
724 HWTEST_F(UINodeTestNg, UINodeTestNg020, TestSize.Level1)
725 {
726 /**
727 * @tc.steps: step1. add one child for ZERO and call AdjustLayoutWrapperTree
728 * @tc.expected: children_.size is 1 and the AdjustLayoutWrapperTree function is run ok
729 */
730 ZERO->AddChild(ONE, 1, false);
731 RefPtr<LayoutWrapperNode> retLayoutWrapper = ZERO->UINode::CreateLayoutWrapper(true, true);
732 ZERO->UINode::AdjustLayoutWrapperTree(retLayoutWrapper, true, true);
733 EXPECT_EQ(ZERO->children_.size(), 1);
734 ZERO->Clean();
735 }
736
737 /**
738 * @tc.name: UINodeTestNg021
739 * @tc.desc: Test ui node method
740 * @tc.type: FUNC
741 */
742 HWTEST_F(UINodeTestNg, UINodeTestNg021, TestSize.Level1)
743 {
744 /**
745 * @tc.steps: step1. add one child for ZERO and call GenerateOneDepthVisibleFrame
746 * @tc.expected: children_.size is 1 and the GenerateOneDepthVisibleFrame function is run ok
747 */
748 std::list<RefPtr<FrameNode>> visibleList;
749
750 ZERO->AddChild(ONE, 1, false);
751 ZERO->GenerateOneDepthVisibleFrame(visibleList);
752 EXPECT_EQ(ZERO->children_.size(), 1);
753 ZERO->Clean();
754 }
755
756 /**
757 * @tc.name: UINodeTestNg022
758 * @tc.desc: Test ui node method
759 * @tc.type: FUNC
760 */
761 HWTEST_F(UINodeTestNg, UINodeTestNg022, TestSize.Level1)
762 {
763 /**
764 * @tc.steps: step1. add one child for ZERO and call GenerateOneDepthAllFrame
765 * @tc.expected: children_.size is 1 and the GenerateOneDepthAllFrame function is run ok
766 */
767 std::list<RefPtr<FrameNode>> visibleList;
768
769 ZERO->AddChild(ONE, 1, false);
770 ZERO->GenerateOneDepthAllFrame(visibleList);
771 EXPECT_EQ(ZERO->children_.size(), 1);
772 ZERO->Clean();
773 }
774
775 /**
776 * @tc.name: UINodeTestNg023
777 * @tc.desc: Test ui node method
778 * @tc.type: FUNC
779 */
780 HWTEST_F(UINodeTestNg, UINodeTestNg023, TestSize.Level1)
781 {
782 /**
783 * @tc.steps: step1. add one child for ZERO and call TouchTest
784 * @tc.expected: the return value is meetings expectations
785 */
786 TouchTestResult result;
787 TouchRestrict restrict;
788 const PointF GLOBAL_POINT { 20.0f, 20.0f };
789 const PointF LOCAL_POINT { 15.0f, 15.0f };
790 auto testNode = TestNode::CreateTestNode(TEST_ID_ONE);
791 ZERO->AddChild(testNode, 1, false);
792 HitTestResult retResult =
793 ZERO->UINode::TouchTest(GLOBAL_POINT, LOCAL_POINT, LOCAL_POINT, restrict, result, 1);
794 EXPECT_EQ(retResult, HitTestResult::OUT_OF_REGION);
795 testNode->hitTestResult_ = HitTestResult::STOP_BUBBLING;
796 retResult = ZERO->UINode::TouchTest(GLOBAL_POINT, LOCAL_POINT, LOCAL_POINT, restrict, result, 1);
797 EXPECT_EQ(retResult, HitTestResult::STOP_BUBBLING);
798 testNode->hitTestResult_ = HitTestResult::BUBBLING;
799 retResult = ZERO->UINode::TouchTest(GLOBAL_POINT, LOCAL_POINT, LOCAL_POINT, restrict, result, 1);
800 EXPECT_EQ(retResult, HitTestResult::BUBBLING);
801 ZERO->Clean();
802 }
803
804 /**
805 * @tc.name: UINodeTestNg024
806 * @tc.desc: Test ui node method
807 * @tc.type: FUNC
808 */
809 HWTEST_F(UINodeTestNg, UINodeTestNg024, TestSize.Level1)
810 {
811 /**
812 * @tc.steps: step1. CreateFrameNode and call MouseTest
813 * @tc.expected: the return value is meetings expectations
814 */
815 MouseTestResult result;
816 const PointF GLOBAL_POINT { 20.0f, 20.0f };
817 const PointF LOCAL_POINT { 15.0f, 15.0f };
818 RefPtr<FrameNode> TEST_HOVERNODE =
819 FrameNode::CreateFrameNode("hovernode", 100, AceType::MakeRefPtr<Pattern>(), true);
820 auto testNode = TestNode::CreateTestNode(TEST_ID_ONE);
821 ZERO->AddChild(testNode, 1, false);
822 testNode->hitTestResult_ = HitTestResult::STOP_BUBBLING;
823 HitTestResult retResult = ZERO->UINode::MouseTest(GLOBAL_POINT, LOCAL_POINT, result, result, TEST_HOVERNODE);
824 EXPECT_EQ(retResult, HitTestResult::STOP_BUBBLING);
825 testNode->hitTestResult_ = HitTestResult::BUBBLING;
826 retResult = ZERO->UINode::MouseTest(GLOBAL_POINT, LOCAL_POINT, result, result, TEST_HOVERNODE);
827 EXPECT_EQ(retResult, HitTestResult::BUBBLING);
828 ZERO->Clean();
829 }
830
831 /**
832 * @tc.name: UINodeTestNg025
833 * @tc.desc: Test ui node method
834 * @tc.type: FUNC
835 */
836 HWTEST_F(UINodeTestNg, UINodeTestNg025, TestSize.Level1)
837 {
838 /**
839 * @tc.steps: step1. add one child for ZERO and call AxisTest
840 * @tc.expected: the return value is OUT_OF_REGION
841 */
842 /**
843 * @tc.steps: step1. CreateFrameNode and call MouseTest
844 * @tc.expected: the return value is meetings expectations
845 */
846 AxisTestResult result;
847 TouchRestrict restrict;
848 const PointF GLOBAL_POINT { 20.0f, 20.0f };
849 const PointF LOCAL_POINT { 15.0f, 15.0f };
850 auto testNode = TestNode::CreateTestNode(TEST_ID_ONE);
851 ZERO->AddChild(testNode, 1, false);
852 testNode->hitTestResult_ = HitTestResult::STOP_BUBBLING;
853 HitTestResult retResult = ZERO->UINode::AxisTest(GLOBAL_POINT, LOCAL_POINT, result);
854 EXPECT_EQ(retResult, HitTestResult::STOP_BUBBLING);
855 testNode->hitTestResult_ = HitTestResult::BUBBLING;
856 retResult = ZERO->UINode::AxisTest(GLOBAL_POINT, LOCAL_POINT, result);
857 EXPECT_EQ(retResult, HitTestResult::BUBBLING);
858 ZERO->Clean();
859 }
860
861 /**
862 * @tc.name: UINodeTestNg026
863 * @tc.desc: Test ui node method
864 * @tc.type: FUNC
865 */
866 HWTEST_F(UINodeTestNg, UINodeTestNg026, TestSize.Level1)
867 {
868 /**
869 * @tc.steps: step1. add one child for ZERO and call TotalChildCount
870 * @tc.expected: the return retCount is 1
871 */
872 ZERO->AddChild(ONE, 1, false);
873 int32_t retCount = ZERO->UINode::FrameCount();
874 EXPECT_EQ(retCount, 1);
875 /**
876 * @tc.steps: step2. add two child for ZERO and call TotalChildCount
877 * @tc.expected: the return retCount is 2
878 */
879 ZERO->AddChild(TWO, 2, false);
880 retCount = ZERO->TotalChildCount();
881 EXPECT_EQ(retCount, 2);
882 /**
883 * @tc.steps: step3. add three child for ZERO and call TotalChildCount
884 * @tc.expected: the return retCount is 3
885 */
886 ZERO->AddChild(THREE, 3, false);
887 retCount = ZERO->TotalChildCount();
888 EXPECT_EQ(retCount, 3);
889 /**
890 * @tc.steps: step4. add four child for ZERO and call TotalChildCount
891 * @tc.expected: the return retCount is 4
892 */
893 ZERO->AddChild(FOUR, 4, false);
894 retCount = ZERO->TotalChildCount();
895 EXPECT_EQ(retCount, 4);
896 ZERO->Clean();
897 /**
898 * @tc.steps: step5. clean ZERO's child and TotalChildCount
899 * @tc.expected: the return retCount is 0
900 */
901 retCount = ZERO->TotalChildCount();
902 EXPECT_EQ(retCount, 0);
903 }
904
905 /**
906 * @tc.name: UINodeTestNg027
907 * @tc.desc: Test ui node method
908 * @tc.type: FUNC
909 */
910 HWTEST_F(UINodeTestNg, UINodeTestNg027, TestSize.Level1)
911 {
912 /**
913 * @tc.steps: step1. add one child for ZERO and call Build
914 * @tc.expected: the Build function is run ok
915 */
916 ZERO->AddChild(ONE, 1, false);
917 ZERO->Build(nullptr);
918 EXPECT_EQ(ZERO->children_.size(), 1);
919 ZERO->Clean();
920 }
921
922 /**
923 * @tc.name: UINodeTestNg028
924 * @tc.desc: Test ui node method
925 * @tc.type: FUNC
926 */
927 HWTEST_F(UINodeTestNg, UINodeTestNg028, TestSize.Level1)
928 {
929 /**
930 * @tc.steps: step1. add one child for ZERO and call SetActive
931 * @tc.expected: the SetActive function is run ok
932 */
933 ZERO->AddChild(ONE, 1, false);
934 ZERO->UINode::SetActive(true);
935 EXPECT_EQ(ZERO->children_.size(), 1);
936 ZERO->Clean();
937 }
938
939 /**
940 * @tc.name: UINodeTestNg029
941 * @tc.desc: Test ui node method
942 * @tc.type: FUNC
943 */
944 HWTEST_F(UINodeTestNg, UINodeTestNg029, TestSize.Level1)
945 {
946 /**
947 * @tc.steps: step1. add one child for ZERO and call OnVisibleChange
948 * @tc.expected: the OnVisibleChange function is run ok
949 */
950 ZERO->AddChild(ONE, 1, false);
951 ZERO->UINode::OnVisibleChange(true);
952 EXPECT_EQ(ZERO->children_.size(), 1);
953 ZERO->Clean();
954 }
955
956 /**
957 * @tc.name: UINodeTestNg030
958 * @tc.desc: Test ui node method
959 * @tc.type: FUNC
960 */
961 HWTEST_F(UINodeTestNg, UINodeTestNg030, TestSize.Level1)
962 {
963 /**
964 * @tc.steps: step1. add ONE child for ZERO and call GetChildFlatIndex
965 * @tc.expected: pair1.second is 0
966 */
967 ZERO->AddChild(ONE, 1, false);
968 auto pair = ZERO->GetChildFlatIndex(1);
969 EXPECT_TRUE(pair.first);
970 EXPECT_EQ(pair.second, 0);
971 ZERO->Clean();
972 /**
973 * @tc.steps: step1. AddChild TESTUINode to ZERO and GetChildFlatIndex
974 * @tc.expected: the return pair1.first is false and pair1.second is 1
975 */
976 ZERO->AddChild(TEN0, 1, false);
977 pair = ZERO->GetChildFlatIndex(10);
978 EXPECT_FALSE(pair.first);
979 EXPECT_EQ(pair.second, 1);
980 ZERO->Clean();
981 }
982
983 /**
984 * @tc.name: UINodeTestNg031
985 * @tc.desc: Test ui node method
986 * @tc.type: FUNC
987 */
988 HWTEST_F(UINodeTestNg, UINodeTestNg031, TestSize.Level1)
989 {
990 /**
991 * @tc.steps: step1. add one child to ZERO and ChildrenUpdatedFrom
992 * @tc.expected: childrenUpdatedFrom_ is 1
993 */
994 ZERO->ChildrenUpdatedFrom(1);
995 EXPECT_EQ(ZERO->childrenUpdatedFrom_, 1);
996 ZERO->Clean();
997 }
998
999 /**
1000 * @tc.name: UINodeTestNg032
1001 * @tc.desc: Test ui node method
1002 * @tc.type: FUNC
1003 */
1004 HWTEST_F(UINodeTestNg, UINodeTestNg032, TestSize.Level1)
1005 {
1006 /**
1007 * @tc.steps: step1. add one child to ZERO and MarkRemoving
1008 * @tc.expected: the return retMark is false
1009 */
1010 ZERO->AddChild(ONE, 1, false);
1011 bool retMark = ZERO->UINode::MarkRemoving();
1012 EXPECT_FALSE(retMark);
1013 ZERO->Clean();
1014 }
1015
1016 /**
1017 * @tc.name: UINodeTestNg033
1018 * @tc.desc: Test ui node method
1019 * @tc.type: FUNC
1020 */
1021 HWTEST_F(UINodeTestNg, UINodeTestNg033, TestSize.Level1)
1022 {
1023 /**
1024 * @tc.steps: step1. call the SetChildrenInDestroying
1025 * @tc.expected: children_.size = 0
1026 */
1027 ZERO->SetChildrenInDestroying();
1028 EXPECT_EQ(ZERO->children_.size(), 0);
1029 ZERO->Clean();
1030 /**
1031 * @tc.steps: step1. add two child to ZERO and call SetChildrenInDestroying
1032 * @tc.expected: step1. children_.size = 3
1033 */
1034 ZERO->AddChild(ONE, 1, false);
1035 ZERO->AddChild(TWO, 2, false);
1036 ZERO->children_.emplace_back(nullptr);
1037 ZERO->SetChildrenInDestroying();
1038 EXPECT_EQ(ZERO->children_.size(), 3);
1039 ZERO->children_.clear();
1040 ZERO->Clean();
1041 }
1042
1043 /**
1044 * @tc.name: UINodeTestNg034
1045 * @tc.desc: Test ui node method
1046 * @tc.type: FUNC
1047 */
1048 HWTEST_F(UINodeTestNg, UINodeTestNg034, TestSize.Level1)
1049 {
1050 /**
1051 * @tc.steps: step1. add two child to ZERO and call RemoveChildAtIndex
1052 * @tc.expected: children_.size = 1
1053 */
1054 ZERO->AddChild(ONE, 1, false);
1055 ZERO->RemoveChildAtIndex(1);
1056 EXPECT_EQ(ZERO->children_.size(), 1);
1057 ZERO->Clean();
1058 }
1059
1060 /**
1061 * @tc.name: UINodeTestNg035
1062 * @tc.desc: Test ui node method
1063 * @tc.type: FUNC
1064 */
1065 HWTEST_F(UINodeTestNg, UINodeTestNg035, TestSize.Level1)
1066 {
1067 /**
1068 * @tc.steps: step1. call the AddChild funtion and set child is null
1069 * @tc.expected: children_.size = 0
1070 */
1071 ZERO->AddChild(nullptr, 1, false);
1072 EXPECT_EQ(ZERO->children_.size(), 0);
1073 /**
1074 * @tc.steps: step2. AddChild
1075 * @tc.expected: children_.size = 1
1076 */
1077 ZERO->AddChild(TWO, 1, false);
1078 EXPECT_EQ(ZERO->children_.size(), 1);
1079 /**
1080 * @tc.steps: step3. call the RemoveChild funtion and set input is null
1081 * @tc.expected: the return value is children_.end()
1082 */
1083 auto interator = ZERO->RemoveChild(nullptr);
1084 EXPECT_EQ(interator, ZERO->children_.end());
1085 ZERO->Clean();
1086 }
1087
1088 /**
1089 * @tc.name: UINodeTestNg036
1090 * @tc.desc: Test ui node method
1091 * @tc.type: FUNC
1092 */
1093 HWTEST_F(UINodeTestNg, UINodeTestNg036, TestSize.Level1)
1094 {
1095 /**
1096 * @tc.steps: step1. GetChildAtIndex and set input is -1
1097 * @tc.expected: the return value is return nullptr
1098 */
1099 RefPtr<UINode> retChildAtIndex = ZERO->GetChildAtIndex(-1);
1100 EXPECT_EQ(retChildAtIndex, nullptr);
1101 }
1102
1103 /**
1104 * @tc.name: UINodeTestNg037
1105 * @tc.desc: Test ui node method
1106 * @tc.type: FUNC
1107 */
1108 HWTEST_F(UINodeTestNg, UINodeTestNg037, TestSize.Level1)
1109 {
1110 /**
1111 * @tc.steps: step1. ReplaceChild
1112 * @tc.expected: children_.size() is 0
1113 */
1114 ZERO->ReplaceChild(nullptr, nullptr);
1115 EXPECT_EQ(ZERO->children_.size(), 0);
1116 }
1117
1118 /**
1119 * @tc.name: UINodeTestNg038
1120 * @tc.desc: Test ui node method
1121 * @tc.type: FUNC
1122 */
1123 HWTEST_F(UINodeTestNg, UINodeTestNg038, TestSize.Level1)
1124 {
1125 /**
1126 * @tc.steps: step1. call the MarkDirtyNode.
1127 * @tc.expected: the MarkDirtyNode function is run ok.
1128 */
1129 PropertyChangeFlag FLAG = PROPERTY_UPDATE_NORMAL;
1130 ZERO->layoutProperty_->propertyChangeFlag_ = PROPERTY_UPDATE_NORMAL;
1131 ONE->layoutProperty_->propertyChangeFlag_ = PROPERTY_UPDATE_NORMAL;
1132 TWO->layoutProperty_->propertyChangeFlag_ = PROPERTY_UPDATE_NORMAL;
1133
1134 ONE->parent_ = ZERO;
1135 TWO->parent_ = ONE;
1136 ZERO->MarkNeedFrameFlushDirty(FLAG);
1137 EXPECT_NE(ONE->parent_.Upgrade(), nullptr);
1138 EXPECT_NE(TWO->parent_.Upgrade(), nullptr);
1139 ZERO->Clean();
1140 }
1141
1142 /**
1143 * @tc.name: UINodeTestNg039
1144 * @tc.desc: Test ui node method
1145 * @tc.type: FUNC
1146 */
1147 HWTEST_F(UINodeTestNg, UINodeTestNg039, TestSize.Level1)
1148 {
1149 /**
1150 * @tc.steps: step1. call the CreateLayoutWrapper
1151 * @tc.expected: the return value is null
1152 */
1153 RefPtr<LayoutWrapperNode> retLayoutWrapper = ZERO->UINode::CreateLayoutWrapper(true, true);
1154 EXPECT_EQ(retLayoutWrapper, nullptr);
1155 /**
1156 * @tc.steps: step2. add one child for ZERO and call CreateLayoutWrapper
1157 * @tc.expected: the return value is null
1158 */
1159 auto testNode = TestNode::CreateTestNode(TEST_ID_ONE);
1160 ZERO->AddChild(testNode, 1, false);
1161 retLayoutWrapper = ZERO->UINode::CreateLayoutWrapper(true, true);
1162 testNode->AddChild(ONE, 1, false);
1163 retLayoutWrapper = ZERO->UINode::CreateLayoutWrapper(true, true);
1164 EXPECT_NE(retLayoutWrapper, nullptr);
1165 ZERO->Clean();
1166 }
1167
1168 /**
1169 * @tc.name: UINodeTestNg040
1170 * @tc.desc: Test ui node method
1171 * @tc.type: FUNC
1172 */
1173 HWTEST_F(UINodeTestNg, UINodeTestNg040, TestSize.Level1)
1174 {
1175 /**
1176 * @tc.steps: step1. set onMainTree_ is true and call AddChild
1177 * @tc.expected: children_.size() is 2
1178 */
1179 auto it = std::find(ZERO->children_.begin(), ZERO->children_.end(), ZERO);
1180 ZERO->onMainTree_ = true;
1181 ZERO->DoAddChild(it, ONE, false);
1182 ZERO->DoAddChild(it, TWO, true);
1183 EXPECT_EQ(ZERO->children_.size(), 2);
1184 }
1185
1186 /**
1187 * @tc.name: UINodeTestNg042
1188 * @tc.desc: Test ui node method
1189 * @tc.type: FUNC
1190 */
1191 HWTEST_F(UINodeTestNg, UINodeTestNg042, TestSize.Level1)
1192 {
1193 /**
1194 * @tc.steps: step1. create some node
1195 */
1196 auto parent = FrameNode::CreateFrameNode(V2::COMMON_VIEW_ETS_TAG, 1, AceType::MakeRefPtr<Pattern>(), true);
1197 auto child = FrameNode::CreateFrameNode(V2::COMMON_VIEW_ETS_TAG, 3, AceType::MakeRefPtr<Pattern>());
1198 auto child2 = FrameNode::CreateFrameNode(V2::COMMON_VIEW_ETS_TAG, 4, AceType::MakeRefPtr<Pattern>());
1199 /**
1200 * @tc.steps: step2. call AddDisappearingChild with different condition
1201 * @tc.expected: disappearingChildren_.size() is 2
1202 */
1203 parent->AddDisappearingChild(child);
1204 child2->isDisappearing_ = true;
1205 parent->AddDisappearingChild(child2);
1206 parent->AddDisappearingChild(child);
1207 EXPECT_EQ(parent->disappearingChildren_.size(), 2);
1208 /**
1209 * @tc.steps: step3. call RemoveDisappearingChild with different condition
1210 * @tc.expected: disappearingChildren_.size() is 1
1211 */
1212 parent->RemoveDisappearingChild(child);
1213 child->isDisappearing_ = true;
1214 parent->RemoveDisappearingChild(child);
1215 EXPECT_EQ(parent->disappearingChildren_.size(), 1);
1216 }
1217
1218 /**
1219 * @tc.name: UINodeTestNg043
1220 * @tc.desc: Test ui node method
1221 * @tc.type: FUNC
1222 */
1223 HWTEST_F(UINodeTestNg, UINodeTestNg043, TestSize.Level1)
1224 {
1225 /**
1226 * @tc.steps: step1. create some node
1227 */
1228 auto parent = FrameNode::CreateFrameNode("parent", 1, AceType::MakeRefPtr<Pattern>(), true);
1229 auto child = FrameNode::CreateFrameNode("child", 3, AceType::MakeRefPtr<Pattern>());
1230 parent->AddChild(child);
1231 /**
1232 * @tc.steps: step2. call GetFrameChildByIndex
1233 * @tc.expected: return nullptr
1234 */
1235
1236 LayoutConstraintF parentLayoutConstraint;
1237 parentLayoutConstraint.maxSize.SetWidth(0);
1238 parentLayoutConstraint.maxSize.SetHeight(0);
1239 PerformanceCheckNodeMap un_Map;
1240 un_Map.emplace(0, PerformanceCheckNode());
1241 parent->UINode::OnSetCacheCount(3, parentLayoutConstraint);
1242 parent->UINode::DoRemoveChildInRenderTree(0, true);
1243 parent->UINode::DoRemoveChildInRenderTree(0, false);
1244 parent->UINode::DoRemoveChildInRenderTree(5, false);
1245 parent->UINode::GetFrameChildByIndex(0, false);
1246 EXPECT_FALSE(parent->UINode::GetDisappearingChildById(""));
1247 EXPECT_FALSE(parent->UINode::GetFrameChildByIndex(5, false));
1248 }
1249
1250 /**
1251 * @tc.name: GetCurrentCustomNodeInfo001
1252 * @tc.desc: Test ui node method GetCurrentCustomNodeInfo
1253 * @tc.type: FUNC
1254 */
1255 HWTEST_F(UINodeTestNg, GetCurrentCustomNodeInfo001, TestSize.Level1)
1256 {
1257 /**
1258 * @tc.steps: step1. create frame node
1259 */
1260 auto parentId = ElementRegister::GetInstance()->MakeUniqueId();
1261 auto childId = ElementRegister::GetInstance()->MakeUniqueId();
1262 auto parent = FrameNode::CreateFrameNode("parent_test", parentId, AceType::MakeRefPtr<Pattern>(), true);
1263 auto child = FrameNode::CreateFrameNode("child_test", childId, AceType::MakeRefPtr<Pattern>());
1264 parent->AddChild(child);
1265
1266 /**
1267 * @tc.steps: step2. call GetCurrentCustomNodeInfo
1268 * @tc.expected: return ""
1269 */
1270 std::string rusult = parent->UINode::GetCurrentCustomNodeInfo();
1271 EXPECT_EQ(rusult, "");
1272 }
1273
1274 /**
1275 * @tc.name: GetCurrentCustomNodeInfo002
1276 * @tc.desc: Test ui node method GetCurrentCustomNodeInfo
1277 * @tc.type: FUNC
1278 */
1279 HWTEST_F(UINodeTestNg, GetCurrentCustomNodeInfo002, TestSize.Level1)
1280 {
1281 /**
1282 * @tc.steps: step1. create custome node
1283 */
1284 auto parentId = ElementRegister::GetInstance()->MakeUniqueId();
1285 auto childId = ElementRegister::GetInstance()->MakeUniqueId();
1286 auto childTwoId = ElementRegister::GetInstance()->MakeUniqueId();
1287 auto parent = CustomNode::CreateCustomNode(parentId, "parent");
1288 auto child = CustomNode::CreateCustomNode(childId, "child");
1289 auto childTwo = CustomNode::CreateCustomNode(childTwoId, "child_two");
1290 parent->AddChild(child);
1291 parent->AddChild(childTwo);
1292
1293 /**
1294 * @tc.steps: step2. cover branch parent is custome and call GetCurrentCustomNodeInfo
1295 * @tc.expected: return ""
1296 */
1297 std::string rusult = parent->UINode::GetCurrentCustomNodeInfo();
1298 EXPECT_EQ(rusult, "");
1299 }
1300
1301 /**
1302 * @tc.name: GetPerformanceCheckData001
1303 * @tc.desc: Test ui node method GetCurrentCustomNodeInfo
1304 * @tc.type: FUNC
1305 */
1306 HWTEST_F(UINodeTestNg, GetPerformanceCheckData001, TestSize.Level1)
1307 {
1308 /**
1309 * @tc.steps: step1. create frame node
1310 */
1311 auto parentId = ElementRegister::GetInstance()->MakeUniqueId();
1312 auto parent = FrameNode::CreateFrameNode("parent", parentId, AceType::MakeRefPtr<Pattern>(), true);
1313 parent->tag_ = V2::COMMON_VIEW_ETS_TAG;
1314 parent->nodeInfo_ = std::make_unique<PerformanceCheckNode>();
1315
1316 /**
1317 * @tc.steps: step2. construct parameter performanceCheckNodeMap and call GetPerformanceCheckData
1318 * @tc.expected: isBuildByJS_ is false
1319 */
1320 auto nodeId = ElementRegister::GetInstance()->MakeUniqueId();
1321 PerformanceCheckNodeMap nodeMap;
1322 PerformanceCheckNode performanceCheckNode = PerformanceCheckNode();
1323 nodeMap.emplace(nodeId, performanceCheckNode);
1324
1325 parent->UINode::GetPerformanceCheckData(nodeMap);
1326 EXPECT_FALSE(parent->isBuildByJS_);
1327
1328 /**
1329 * @tc.steps: step3. change parent tag_ and call GetPerformanceCheckData
1330 * @tc.expected: isBuildByJS_ is true
1331 */
1332 parent->tag_ = V2::MENU_ETS_TAG;
1333 parent->SetBuildByJs(true);
1334 parent->UINode::GetPerformanceCheckData(nodeMap);
1335 EXPECT_TRUE(parent->isBuildByJS_);
1336 }
1337
1338 /**
1339 * @tc.name: GetPerformanceCheckData002
1340 * @tc.desc: Test ui node method GetCurrentCustomNodeInfo
1341 * @tc.type: FUNC
1342 */
1343 HWTEST_F(UINodeTestNg, GetPerformanceCheckData002, TestSize.Level1)
1344 {
1345 /**
1346 * @tc.steps: step1. create parent and childframe node
1347 */
1348 auto parentId = ElementRegister::GetInstance()->MakeUniqueId();
1349 auto childId = ElementRegister::GetInstance()->MakeUniqueId();
1350 auto parent = FrameNode::CreateFrameNode("parent", parentId, AceType::MakeRefPtr<Pattern>(), true);
1351 auto child = FrameNode::CreateFrameNode("child", childId, AceType::MakeRefPtr<Pattern>(), true);
1352
1353 parent->tag_ = V2::JS_FOR_EACH_ETS_TAG;
1354 parent->nodeInfo_ = std::make_unique<PerformanceCheckNode>();
1355 child->tag_ = V2::COMMON_VIEW_ETS_TAG;
1356 child->nodeInfo_ = std::make_unique<PerformanceCheckNode>();
1357 parent->AddChild(child);
1358
1359 /**
1360 * @tc.steps: step2. construct parameter performanceCheckNodeMap and call GetPerformanceCheckData
1361 * @tc.expected: isBuildByJS_ is false
1362 */
1363 auto nodeId = ElementRegister::GetInstance()->MakeUniqueId();
1364 PerformanceCheckNodeMap nodeMap;
1365 PerformanceCheckNode performanceCheckNode = PerformanceCheckNode();
1366 nodeMap.emplace(nodeId, performanceCheckNode);
1367
1368 parent->UINode::GetPerformanceCheckData(nodeMap);
1369 EXPECT_FALSE(parent->isBuildByJS_);
1370
1371 /**
1372 * @tc.steps: step3. change child tag_ and call GetPerformanceCheckData
1373 * @tc.expected: isBuildByJS_ is false
1374 */
1375 child->tag_ = V2::JS_FOR_EACH_ETS_TAG;
1376 parent->UINode::GetPerformanceCheckData(nodeMap);
1377 EXPECT_FALSE(parent->isBuildByJS_);
1378 }
1379
1380 /**
1381 * @tc.name: GetPerformanceCheckData003
1382 * @tc.desc: Test ui node method GetCurrentCustomNodeInfo
1383 * @tc.type: FUNC
1384 */
1385 HWTEST_F(UINodeTestNg, GetPerformanceCheckData003, TestSize.Level1)
1386 {
1387 /**
1388 * @tc.steps: step1. create frame node
1389 */
1390 auto parentId = ElementRegister::GetInstance()->MakeUniqueId();
1391 auto childId = ElementRegister::GetInstance()->MakeUniqueId();
1392 auto childTwoId = ElementRegister::GetInstance()->MakeUniqueId();
1393 auto parent = FrameNode::CreateFrameNode("parent", parentId, AceType::MakeRefPtr<Pattern>(), true);
1394 auto child = FrameNode::CreateFrameNode("child", childId, AceType::MakeRefPtr<Pattern>(), true);
1395 auto childTwo = FrameNode::CreateFrameNode("childTwo", childTwoId, AceType::MakeRefPtr<Pattern>(), true);
1396 parent->tag_ = V2::JS_FOR_EACH_ETS_TAG;
1397 parent->nodeInfo_ = std::make_unique<PerformanceCheckNode>();
1398 child->tag_ = V2::COMMON_VIEW_ETS_TAG;
1399 child->nodeInfo_ = std::make_unique<PerformanceCheckNode>();
1400 childTwo->tag_ = V2::COMMON_VIEW_ETS_TAG;
1401 childTwo->nodeInfo_ = std::make_unique<PerformanceCheckNode>();
1402 parent->AddChild(child);
1403 parent->AddChild(childTwo);
1404
1405 /**
1406 * @tc.steps: step2. construct parameter performanceCheckNodeMap and call GetPerformanceCheckData
1407 * @tc.expected: isBuildByJS_ is false
1408 */
1409 auto nodeId = ElementRegister::GetInstance()->MakeUniqueId();
1410 PerformanceCheckNodeMap nodeMap;
1411 PerformanceCheckNode performanceCheckNode = PerformanceCheckNode();
1412 nodeMap.emplace(nodeId, performanceCheckNode);
1413
1414 parent->UINode::GetPerformanceCheckData(nodeMap);
1415 EXPECT_FALSE(parent->isBuildByJS_);
1416
1417 /**
1418 * @tc.steps: step3. change child tag_ and call GetPerformanceCheckData
1419 * @tc.expected: isBuildByJS_ is false
1420 */
1421 child->tag_ = V2::JS_FOR_EACH_ETS_TAG;
1422 parent->UINode::GetPerformanceCheckData(nodeMap);
1423 EXPECT_FALSE(parent->isBuildByJS_);
1424 }
1425
1426 /**
1427 * @tc.name: UpdateConfigurationUpdate001
1428 * @tc.desc: Test ui node method UpdateConfigurationUpdate
1429 * @tc.type: FUNC
1430 */
1431 HWTEST_F(UINodeTestNg, UpdateConfigurationUpdate001, TestSize.Level1)
1432 {
1433 /**
1434 * @tc.steps: step1. create frame node
1435 */
1436 auto parentId = ElementRegister::GetInstance()->MakeUniqueId();
1437 auto parent = FrameNode::CreateFrameNode("parent", parentId, AceType::MakeRefPtr<Pattern>(), true);
1438 parent->tag_ = V2::COMMON_VIEW_ETS_TAG;
1439 parent->nodeInfo_ = std::make_unique<PerformanceCheckNode>();
1440
1441 /**
1442 * @tc.steps: step2. construct parameter configurationChange and call UpdateConfigurationUpdate
1443 * @tc.expected: cover branch needCallChildrenUpdate_ is true
1444 */
1445 ConfigurationChange configurationChange;
1446 parent->UINode::UpdateConfigurationUpdate(configurationChange);
1447 EXPECT_TRUE(parent->needCallChildrenUpdate_);
1448
1449 /**
1450 * @tc.steps: step3. create child frame node and call UpdateConfigurationUpdate
1451 * @tc.expected: cover branch children is not empty
1452 */
1453 auto childId = ElementRegister::GetInstance()->MakeUniqueId();
1454 auto childTwoId = ElementRegister::GetInstance()->MakeUniqueId();
1455 auto child = FrameNode::CreateFrameNode("child", childId, AceType::MakeRefPtr<Pattern>(), true);
1456 auto childTwo = FrameNode::CreateFrameNode("childTwo", childTwoId, AceType::MakeRefPtr<Pattern>(), true);
1457 child->tag_ = V2::COMMON_VIEW_ETS_TAG;
1458 child->nodeInfo_ = std::make_unique<PerformanceCheckNode>();
1459 childTwo->tag_ = V2::COMMON_VIEW_ETS_TAG;
1460 childTwo->nodeInfo_ = std::make_unique<PerformanceCheckNode>();
1461 parent->AddChild(child);
1462 parent->AddChild(childTwo);
1463 parent->UINode::UpdateConfigurationUpdate(configurationChange);
1464 EXPECT_TRUE(parent->needCallChildrenUpdate_);
1465
1466 /**
1467 * @tc.steps: step4. set needCallChildrenUpdate_ and call UpdateConfigurationUpdate
1468 * @tc.expected: cover branch needCallChildrenUpdate_ is false
1469 */
1470 parent->SetNeedCallChildrenUpdate(false);
1471 parent->UINode::UpdateConfigurationUpdate(configurationChange);
1472 EXPECT_FALSE(parent->needCallChildrenUpdate_);
1473 }
1474
1475 /**
1476 * @tc.name: DumpTreeById001
1477 * @tc.desc: Test ui node method DumpTreeById
1478 * @tc.type: FUNC
1479 */
1480 HWTEST_F(UINodeTestNg, DumpTreeById001, TestSize.Level1)
1481 {
1482 /**
1483 * @tc.steps: step1. create frame node
1484 */
1485 auto parentId = ElementRegister::GetInstance()->MakeUniqueId();
1486 auto childId = ElementRegister::GetInstance()->MakeUniqueId();
1487 auto parent = FrameNode::CreateFrameNode("parent", parentId, AceType::MakeRefPtr<Pattern>(), true);
1488 auto child = FrameNode::CreateFrameNode("child", childId, AceType::MakeRefPtr<Pattern>(), true);
1489
1490 parent->tag_ = V2::JS_FOR_EACH_ETS_TAG;
1491 parent->nodeInfo_ = std::make_unique<PerformanceCheckNode>();
1492 child->tag_ = V2::COMMON_VIEW_ETS_TAG;
1493 child->nodeInfo_ = std::make_unique<PerformanceCheckNode>();
1494 parent->AddChild(child);
1495
1496 /**
1497 * @tc.steps: step2. call DumpTreeById
1498 * @tc.expected: cover branch GetDumpFile is nullptr and result is false
1499 */
1500 bool result = parent->UINode::DumpTreeById(0, "");
1501 EXPECT_FALSE(result);
1502
1503 /**
1504 * @tc.steps: step3. set DumpFile and call DumpTreeById
1505 * @tc.expected: cover branch GetDumpFile is not nullptr and result is true
1506 */
1507 std::unique_ptr<std::ostream> ostream = std::make_unique<std::ostringstream>();
1508 ASSERT_NE(ostream, nullptr);
1509 DumpLog::GetInstance().SetDumpFile(std::move(ostream));
1510
1511 result = parent->UINode::DumpTreeById(0, "");
1512 EXPECT_TRUE(result);
1513 }
1514
1515 /**
1516 * @tc.name: DumpTreeById002
1517 * @tc.desc: Test ui node method DumpTreeById
1518 * @tc.type: FUNC
1519 */
1520 HWTEST_F(UINodeTestNg, DumpTreeById002, TestSize.Level1)
1521 {
1522 /**
1523 * @tc.steps: step1. create frame node
1524 */
1525 auto parentId = ElementRegister::GetInstance()->MakeUniqueId();
1526 auto childId = ElementRegister::GetInstance()->MakeUniqueId();
1527 auto parent = FrameNode::CreateFrameNode("parent", parentId, AceType::MakeRefPtr<Pattern>(), true);
1528 auto child = FrameNode::CreateFrameNode("child", childId, AceType::MakeRefPtr<Pattern>(), true);
1529
1530 parent->tag_ = V2::JS_FOR_EACH_ETS_TAG;
1531 parent->nodeInfo_ = std::make_unique<PerformanceCheckNode>();
1532 child->tag_ = V2::COMMON_VIEW_ETS_TAG;
1533 child->nodeInfo_ = std::make_unique<PerformanceCheckNode>();
1534 parent->AddChild(child);
1535
1536 std::unique_ptr<std::ostream> ostream = std::make_unique<std::ostringstream>();
1537 ASSERT_NE(ostream, nullptr);
1538 DumpLog::GetInstance().SetDumpFile(std::move(ostream));
1539
1540 /**
1541 * @tc.steps: step2. construt parameter and call DumpTreeById
1542 * @tc.expected: result is false
1543 */
1544 bool result = parent->UINode::DumpTreeById(0, "DumpTreeById002");
1545 EXPECT_FALSE(result);
1546
1547 /**
1548 * @tc.steps: step3. change parameter and call DumpTreeById
1549 * @tc.expected: result is false
1550 */
1551 result = parent->UINode::DumpTreeById(1, "");
1552 EXPECT_TRUE(result);
1553 }
1554 } // namespace OHOS::Ace::NG