• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 <optional>
17 #include <utility>
18 
19 #include "gtest/gtest.h"
20 
21 #include "base/memory/ace_type.h"
22 #include "base/memory/referenced.h"
23 
24 #define private public
25 #define protected public
26 #include "test/mock/core/pipeline/mock_pipeline_context.h"
27 
28 #include "core/components_ng/base/frame_node.h"
29 #include "core/components_ng/base/view_stack_processor.h"
30 #include "core/components_ng/syntax/repeat_node.h"
31 #include "core/components_ng/syntax/repeat_model_ng.h"
32 #include "core/components_ng/syntax/repeat_virtual_scroll_caches.h"
33 #include "core/components_ng/syntax/repeat_virtual_scroll_node.h"
34 #include "core/components_ng/pattern/list/list_item_event_hub.h"
35 #include "core/components_ng/pattern/list/list_item_layout_property.h"
36 #include "core/components_ng/pattern/list/list_item_pattern.h"
37 #include "core/components_ng/pattern/list/list_pattern.h"
38 #include "core/components_ng/pattern/scrollable/scrollable_item.h"
39 #include "core/components_ng/pattern/scrollable/scrollable_item_pool.h"
40 #include "core/components_v2/inspector/inspector_constants.h"
41 #undef private
42 #undef protected
43 
44 using namespace testing;
45 using namespace testing::ext;
46 
47 namespace OHOS::Ace::NG {
48 namespace {
49 const std::string NODE_TAG = "node";
50 const std::list<std::string> FOR_REPEAT_IDS = { "0", "1", "2", "3", "4", "5" };
51 constexpr int32_t NODE_ID = 1;
52 constexpr int32_t COUNT_1 = 1;
53 constexpr int32_t COUNT_3 = 3;
54 } // namespace
55 
56 using CacheItem = RepeatVirtualScrollCaches::CacheItem;
57 
58 class RepeatVirtualTestNg : public testing::Test {
59 public:
60 
SetUp()61     void SetUp() override
62     {
63         MockPipelineContext::SetUp();
64     }
65 
TearDown()66     void TearDown() override
67     {
68         MockPipelineContext::TearDown();
69     }
70 
71     RefPtr<RepeatVirtualScrollNode> GetOrCreateRepeatNode(bool createItems);
72 
CreateNode(const std::string & tag,int32_t elmtId)73     RefPtr<FrameNode> CreateNode(const std::string& tag, int32_t elmtId)
74     {
75         auto pattern = AceType::MakeRefPtr<Pattern>();
76         auto frameNode = AceType::MakeRefPtr<FrameNode>(tag, elmtId, pattern);
77         pattern->AttachToFrameNode(frameNode);
78         ViewStackProcessor::GetInstance()->Push(frameNode);
79         return frameNode;
80     }
81 
82     // create ListItemNode with 2 Text Node inside
CreateListItemNode(int32_t elmtId)83     RefPtr<FrameNode> CreateListItemNode(int32_t elmtId)
84     {
85         auto tag = "TEXT_ETS_TAG";
86 
87         auto* stack = ViewStackProcessor::GetInstance();
88         auto liFrameNode = FrameNode::GetOrCreateFrameNode(V2::LIST_ITEM_ETS_TAG, elmtId,
89             []() { return AceType::MakeRefPtr<ListItemPattern>(nullptr, V2::ListItemStyle::NONE); });
90 
91         auto textNode = CreateNode(V2::TEXT_ETS_TAG, 100*elmtId);
92 
93         auto pattern = AceType::MakeRefPtr<Pattern>();
94         const uint32_t uniqNumMultiplier1 = 200;
95         auto textFrameNode = AceType::MakeRefPtr<FrameNode>(tag, uniqNumMultiplier1*elmtId, pattern);
96         pattern->AttachToFrameNode(textFrameNode);
97         liFrameNode->AddChild(textFrameNode);
98 
99         pattern = AceType::MakeRefPtr<Pattern>();
100         const uint32_t uniqNumMultiplier2 = 100;
101         textFrameNode = AceType::MakeRefPtr<FrameNode>(tag, uniqNumMultiplier2*elmtId, pattern);
102         pattern->AttachToFrameNode(textFrameNode);
103         liFrameNode->AddChild(textFrameNode);
104         stack->Push(liFrameNode);
105         return liFrameNode;
106     }
107 
__anona0f584000302(uint32_t forIndex) 108     const std::function<void(uint32_t)> onCreateNode = [this](uint32_t forIndex) {
109         CreateListItemNode(forIndex);
110     };
111 };
112 /**
113  * Function needed by RepeatVirtualScrollCaches constructor
114  */
__anona0f584000402(uint32_t forIndex) 115 auto g_onCreateNode = [](uint32_t forIndex) {
116 };
117 
118 /**
119  * Function needed by RepeatVirtualScrollCaches constructor
120  */
__anona0f584000502(const std::string& fromKey, uint32_t forIndex) 121 auto g_onUpdateNode = [](const std::string& fromKey, uint32_t forIndex) {
122 };
123 
124 /**
125  * Function needed by RepeatVirtualScrollCaches constructor
126  */
__anona0f584000602(uint32_t from, uint32_t to) 127 auto g_onGetKeys4Range = [](uint32_t from, uint32_t to) -> std::list<std::string> {
128     std::list<std::string> keys;
129     for (uint32_t i = from; i <= to; ++i) {
130         keys.push_back("Key" + std::to_string(i));
131     }
132     return keys;
133 };
134 
135 /**
136  * Function needed by RepeatVirtualScrollCaches constructor is special test case
137  */
__anona0f584000702(uint32_t from, uint32_t to) 138 auto g_onGetKeys4RangeMaxTo5 = [](uint32_t from, uint32_t to) -> std::list<std::string> {
139     std::list<std::string> keys;
140     for (uint32_t i = from; i <= to && i<=5; ++i) {
141         keys.push_back("Key" + std::to_string(i));
142     }
143     return keys;
144 };
145 
146 /**
147  * Function needed by RepeatVirtualScrollCaches constructor
148  */
__anona0f584000802(uint32_t from, uint32_t to) 149 auto g_onGetTypes4Range = [](uint32_t from, uint32_t to) -> std::list<std::string> {
150     std::list<std::string> types;
151     for (uint32_t i = from; i <= to; ++i) {
152         types.push_back("Type" + std::to_string(i));
153     }
154 
155     return types;
156 };
157 /**
158  * Function needed by RepeatVirtualScrollNode constructor
159  */
__anona0f584000902(int32_t from, int32_t to) 160 auto g_onSetActiveRange = [](int32_t from, int32_t to) {
161 };
162 
163 /**
164  * Map needed by RepeatVirtualScrollCaches constructor
165  */
166 const std::map<std::string, std::pair<bool, uint32_t>> cacheCountL24ttype = {
167     {"element1", { true, 1 }},
168     {"element2", { true, 2 }},
169     {"element3", { true, 3 }},
170     {"element4", { true, 4 }},
171     {"element5", { true, 5 }}
172 };
173 
174 /**
175  * Map needed by RepeatVirtualScrollNode constructor
176  */
177 const std::map<std::string, std::pair<bool, uint32_t>> templateCachedCountMap = {
178     // { template, { cachedCountSpecified, cacheCount } }
179     {"elmt1", { true, 1 } },
180     {"elmt2", { true, 2 } }
181 };
182 
GetOrCreateRepeatNode(bool createItems)183 RefPtr<RepeatVirtualScrollNode> RepeatVirtualTestNg::GetOrCreateRepeatNode(bool createItems)
184 {
185     RefPtr<RepeatVirtualScrollNode> node;
186     if (createItems) {
187         node = RepeatVirtualScrollNode::GetOrCreateRepeatNode(NODE_ID, COUNT_3, templateCachedCountMap, onCreateNode,
188             g_onUpdateNode, g_onGetKeys4Range, g_onGetTypes4Range, g_onSetActiveRange);
189     } else {
190         node = RepeatVirtualScrollNode::GetOrCreateRepeatNode(NODE_ID, COUNT_1, templateCachedCountMap, g_onCreateNode,
191             g_onUpdateNode, g_onGetKeys4Range, g_onGetTypes4Range, g_onSetActiveRange);
192     }
193     return node;
194 }
195 
196 /**
197  * @tc.name: RepeatNodeCacheTest001
198  * @tc.desc: Test GetKey4Index without fetch.
199  * @tc.type: FUNC
200  */
201 HWTEST_F(RepeatVirtualTestNg, RepeatNodeCacheTest001, TestSize.Level1)
202 {
203     RepeatVirtualScrollCaches caches(cacheCountL24ttype,
204                                      g_onCreateNode,
205                                      g_onUpdateNode,
206                                      g_onGetKeys4Range,
207                                      g_onGetTypes4Range);
208 
209     /**
210      * @tc.steps: step1. Try to get key for index 2.
211      * @tc.expected: Because second parameter is false
212      * FetchMoreKeysTTypes will not be called and std::nullopt is returned
213      */
214     std::optional<std::string> key = caches.GetKey4Index(2, false);
215     EXPECT_EQ(key, std::nullopt);
216 }
217 
218 /**
219  * @tc.name: RepeatNodeCacheTest002
220  * @tc.desc: Test GetKey4Index with fetch.
221  * @tc.type: FUNC
222  */
223 HWTEST_F(RepeatVirtualTestNg, RepeatNodeCacheTest002, TestSize.Level1)
224 {
225     RepeatVirtualScrollCaches caches(cacheCountL24ttype,
226                                      g_onCreateNode,
227                                      g_onUpdateNode,
228                                      g_onGetKeys4Range,
229                                      g_onGetTypes4Range);
230 
231      /**
232      * @tc.steps: step1. Try to get key for index 2.
233      * @tc.expected: Because second parameter is true FetchMoreKeysTTypes will be called and Key2 string is returned
234      */
235     std::optional<std::string> key = caches.GetKey4Index(2, true);
236 
237     /**
238      * @tc.steps: step2. Try to create node for index 2.
239      * @tc.expected: Because viewStack->Finish() will eventually return nullptr node will also be nullptr
240      */
241     RefPtr<UINode> node = caches.CreateNewNode(2);
242     EXPECT_EQ(node, nullptr);
243     EXPECT_EQ(key, "Key2");
244 }
245 
246 /**
247  * @tc.name: RepeatNodeCacheTest003
248  * @tc.desc: Test UpdateFromL2
249  * @tc.type: FUNC
250  */
251 HWTEST_F(RepeatVirtualTestNg, RepeatNodeCacheTest003, TestSize.Level1)
252 {
253     RepeatVirtualScrollCaches caches(cacheCountL24ttype,
254                                      g_onCreateNode,
255                                      g_onUpdateNode,
256                                      g_onGetKeys4Range,
257                                      g_onGetTypes4Range);
258 
259     /**
260      * @tc.steps: step1. Try to get UINode from index 2
261      * @tc.expected: Because there are no items in L2 nullptr is expected
262      */
263     RefPtr<UINode> node = caches.UpdateFromL2(2);
264     EXPECT_EQ(node, nullptr);
265 }
266 
267 /**
268  * @tc.name: RepeatNodeCacheTest004
269  * @tc.desc: Test GetDistanceFromRange
270  * @tc.type: FUNC
271  */
272 HWTEST_F(RepeatVirtualTestNg, RepeatNodeCacheTest004, TestSize.Level1)
273 {
274     RepeatVirtualScrollCaches caches(cacheCountL24ttype,
275                                      g_onCreateNode,
276                                      g_onUpdateNode,
277                                      g_onGetKeys4Range,
278                                      g_onGetTypes4Range);
279 
280     /**
281      * @tc.steps: step1. Get distance from active range of index 2
282      * @tc.expected: Because active range index is 0 it expected that number 2 is returned.
283      */
284     int32_t dist = caches.GetDistanceFromRange(2);
285     EXPECT_EQ(dist, 2);
286 }
287 
288 /**
289  * @tc.name: RepeatNodeCacheTest005
290  * @tc.desc: Test creation of GetOrCreateRepeatNode
291  * @tc.type: FUNC
292  */
293 HWTEST_F(RepeatVirtualTestNg, RepeatNodeCacheTest005, TestSize.Level1)
294 {
295     auto* stack = ViewStackProcessor::GetInstance();
296     auto nodeId = stack->ClaimNodeId();
297     /**
298      * @tc.steps: step1. Create node object
299      * @tc.expected: Object is not nullptr.
300      */
301     auto repeatNode = RepeatVirtualScrollNode::GetOrCreateRepeatNode(
302                           nodeId,
303                           1,
304                           templateCachedCountMap,
305                           g_onCreateNode,
306                           g_onUpdateNode,
307                           g_onGetKeys4Range,
308                           g_onGetTypes4Range,
309                           g_onSetActiveRange);
310 
311     EXPECT_NE(repeatNode, nullptr);
312 }
313 
314 /**
315  * @tc.name: RepeatNodeCacheTest006
316  * @tc.desc: Test FrameCount
317  * @tc.type: FUNC
318  */
319 HWTEST_F(RepeatVirtualTestNg, RepeatNodeCacheTest006, TestSize.Level1)
320 {
321     auto repeatNode = RepeatVirtualScrollNode::GetOrCreateRepeatNode(
322                           1,
323                           1,
324                           templateCachedCountMap,
325                           g_onCreateNode,
326                           g_onUpdateNode,
327                           g_onGetKeys4Range,
328                           g_onGetTypes4Range,
329                           g_onSetActiveRange);
330 
331     /**
332      * @tc.steps: step2. Update total count to 2
333      * @tc.expected: Object internal frame count is increased to 2
334      */
335     repeatNode->UpdateTotalCount(2);
336 
337     /**
338      * @tc.steps: step3. Get frame count
339      * @tc.expected: Object internal frame count should be 2
340      */
341     uint32_t frameCount = repeatNode->FrameCount();
342     EXPECT_EQ(frameCount, 2);
343 }
344 
345 /**
346  * @tc.name: RepeatNodeCacheTest007
347  * @tc.desc: Test GetChildren
348  * @tc.type: FUNC
349  */
350 HWTEST_F(RepeatVirtualTestNg, RepeatNodeCacheTest007, TestSize.Level1)
351 {
352     auto repeatNode = RepeatVirtualScrollNode::GetOrCreateRepeatNode(
353                           1,
354                           1,
355                           templateCachedCountMap,
356                           g_onCreateNode,
357                           g_onUpdateNode,
358                           g_onGetKeys4Range,
359                           g_onGetTypes4Range,
360                           g_onSetActiveRange);
361 
362     /**
363      * @tc.steps: step2. Get children count
364      * @tc.expected: Returns number of children. Should be 0
365      */
366     std::list<RefPtr<UINode>> nodes = repeatNode->GetChildren();
367     EXPECT_EQ(nodes.size(), 0);
368 }
369 
370 /**
371  * @tc.name: RepeatNodeCacheTest008
372  * @tc.desc: Test Multiple functions when onCreate lambda really creates node.
373  * @tc.type: FUNC
374  */
375 HWTEST_F(RepeatVirtualTestNg, RepeatNodeCacheTest008, TestSize.Level1)
376 {
377     RepeatVirtualScrollCaches caches(cacheCountL24ttype, onCreateNode,
378                                      g_onUpdateNode, g_onGetKeys4Range,
379                                      g_onGetTypes4Range);
380 
381     std::optional<std::string> key1 = caches.GetKey4Index(1, true);
382     EXPECT_EQ(key1, "Key1");
383     std::optional<std::string> key2 = caches.GetKey4Index(2, true);
384     EXPECT_EQ(key2, "Key2");
385     std::optional<std::string> key3 = caches.GetKey4Index(3, true);
386     EXPECT_EQ(key3, "Key3");
387 
388     RefPtr<UINode> node1 = caches.CreateNewNode(1);
389     EXPECT_NE(node1, nullptr);
390     RefPtr<UINode> node2 = caches.CreateNewNode(2);
391     EXPECT_NE(node2, nullptr);
392     RefPtr<UINode> node3 = caches.CreateNewNode(3);
393     EXPECT_NE(node3, nullptr);
394 
395     auto repeatNode = RepeatVirtualScrollNode::GetOrCreateRepeatNode(
396                           1, 3, templateCachedCountMap, onCreateNode,
397                           g_onUpdateNode, g_onGetKeys4Range,
398                           g_onGetTypes4Range, g_onSetActiveRange);
399 
400     repeatNode->caches_ = caches;
401     /**
402      * @tc.steps: step1. Add keys to cache
403      * @tc.expected: Items in cache size should be 3
404      */
405     repeatNode->caches_.FetchMoreKeysTTypes(1, 3);
406     repeatNode->caches_.AddKeyToL1("Key1");
407     repeatNode->caches_.AddKeyToL1("Key2");
408     repeatNode->caches_.AddKeyToL1("Key3");
409     EXPECT_EQ(repeatNode->caches_.activeNodeKeysInL1_.size(), 3);
410 
411     /**
412      * @tc.steps: step2. Dump information
413      * @tc.expected: Dumping output string should have ListItem(3) substring
414      */
415     std::string l1Dump = repeatNode->caches_.DumpL1();
416     const std::string expectedSubStringL1And4TType = "ListItem";
417     EXPECT_NE(l1Dump.find(expectedSubStringL1And4TType), std::string::npos);
418     std::string dmp4KeyType = repeatNode->caches_.DumpUINode4Key4TType();
419     EXPECT_NE(dmp4KeyType.find(expectedSubStringL1And4TType), std::string::npos);
420 
421     /**
422      * @tc.steps: step3. Find unused keys
423      * @tc.expected: Number of unused keys should be 0
424      */
425     std::set<std::pair<bool, std::string>> keys;
426     caches.FindUnusedKeys(keys);
427     EXPECT_EQ(keys.size(), 0);
428 
429     caches.UINodeHasBeenUpdated("Type1", "Key1", "Key2");
430     repeatNode->DoSetActiveChildRange(1, 3, 1, 2);
431     repeatNode->caches_.index4Key_.clear();
432     repeatNode->DropFromL1("Key1");
433     repeatNode->caches_.GetL1KeyToUpdate("Key1");
434     repeatNode->caches_.InvalidateKeyAndTTypeCaches();
435     repeatNode->UpdateRenderState(true);
436     repeatNode->UpdateRenderState(false);
437     repeatNode->RecycleItems(0, 100);
438 
439     /**
440      * @tc.steps: step4. Get GetFrameNode
441      * @tc.expected: Returns valid frame node
442      */
443     auto frameNode = repeatNode->GetFrameNode(1);
444     EXPECT_NE(frameNode, nullptr);
445 }
446 
447 /**
448  * @tc.name: RepeatNodeCacheTest009
449  * @tc.desc: Test FrameCount
450  * @tc.type: FUNC
451  */
452 HWTEST_F(RepeatVirtualTestNg, RepeatNodeCacheTest009, TestSize.Level1)
453 {
454     const uint32_t totalCount = 10;
455     const uint32_t updatedCount = 5;
456     /**
457      * @tc.steps: step1. Create node object with totalCount = 10
458      * @tc.expected: Object is not nullptr.
459      */
460     auto repeatNode = RepeatVirtualScrollNode::GetOrCreateRepeatNode(
461                           1,
462                           totalCount,
463                           templateCachedCountMap,
464                           g_onCreateNode,
465                           g_onUpdateNode,
466                           g_onGetKeys4Range,
467                           g_onGetTypes4Range,
468                           g_onSetActiveRange);
469 
470     /**
471      * @tc.steps: step2. Ask frame count
472      * @tc.expected: Should be totalCount
473      */
474     uint32_t frameCount = repeatNode->FrameCount();
475     EXPECT_EQ(frameCount, totalCount);
476 
477     /**
478      * @tc.steps: step3. Update total count to the new value
479      * @tc.expected: Should be updatedCount
480      */
481     repeatNode->UpdateTotalCount(updatedCount);
482     frameCount = repeatNode->FrameCount();
483     EXPECT_EQ(frameCount, updatedCount);
484 }
485 
486 /**
487  * @tc.name: RepeatNodeCacheTest010
488  * @tc.desc: Test GetL1KeyToUpdate
489  * @tc.type: FUNC
490  */
491 HWTEST_F(RepeatVirtualTestNg, RepeatNodeCacheTest010, TestSize.Level1)
492 {
493     RepeatVirtualScrollCaches caches(cacheCountL24ttype,
494                                      g_onCreateNode,
495                                      g_onUpdateNode,
496                                      g_onGetKeys4Range,
497                                      g_onGetTypes4Range);
498 
499     caches.FetchMoreKeysTTypes(1, 3);
500     /**
501      * @tc.steps: step1. Try to get L1 key to update
502      * @tc.expected: Because there are no L1 key for Type1
503      * std::nullopt is returned
504      */
505     std::optional<std::string> key = caches.GetL1KeyToUpdate("Type1");
506     EXPECT_EQ(key, std::nullopt);
507 }
508 
509 /**
510  * @tc.name: RepeatNodeCacheTest011
511  * @tc.desc: Test UiNodeHasBeenUpdated
512  * @tc.type: FUNC
513  */
514 HWTEST_F(RepeatVirtualTestNg, RepeatNodeCacheTest011, TestSize.Level1)
515 {
516     RepeatVirtualScrollCaches caches(cacheCountL24ttype,
517                                      g_onCreateNode,
518                                      g_onUpdateNode,
519                                      g_onGetKeys4Range,
520                                      g_onGetTypes4Range);
521 
522     /**
523      * @tc.steps: step1. Try to get UI node by calling UINodeHasBeenUpdated
524      * @tc.expected: Because there are no nodes nullptr is returned
525      */
526     RefPtr<UINode> node = caches.UINodeHasBeenUpdated("Type1", "Key0", "Key1");
527     EXPECT_EQ(node, nullptr);
528 }
529 
530 /**
531  * @tc.name: RepeatNodeCacheTest012
532  * @tc.desc: Test FindUnusedKeys
533  * @tc.type: FUNC
534  */
535 HWTEST_F(RepeatVirtualTestNg, RepeatNodeCacheTest012, TestSize.Level1)
536 {
537     RepeatVirtualScrollCaches caches(cacheCountL24ttype,
538                                      g_onCreateNode,
539                                      g_onUpdateNode,
540                                      g_onGetKeys4Range,
541                                      g_onGetTypes4Range);
542 
543     /**
544      * @tc.steps: step1. Try to get set of unused keys
545      * @tc.expected: Because there are no keys 0 is returned
546      */
547     std::set<std::pair<bool, std::string>> keys;
548     caches.FindUnusedKeys(keys);
549     EXPECT_EQ(keys.size(), 0);
550 }
551 
552 /**
553  * @tc.name: RepeatNodeCacheTest013
554  * @tc.desc: Test DumpL1
555  * @tc.type: FUNC
556  */
557 HWTEST_F(RepeatVirtualTestNg, RepeatNodeCacheTest013, TestSize.Level1)
558 {
559     RepeatVirtualScrollCaches caches(cacheCountL24ttype,
560                                      g_onCreateNode,
561                                      g_onUpdateNode,
562                                      g_onGetKeys4Range,
563                                      g_onGetTypes4Range);
564 
565     /**
566      * @tc.steps: step1. Try to call DumpL1
567      * @tc.expected: Because there are no items. Its expected that there is
568      * total number=0 substring in return value
569      */
570     std::string l1Dump = caches.DumpL1();
571     const std::string expectedSubString = "total number=0";
572     EXPECT_NE(l1Dump.find(expectedSubString), std::string::npos);
573 }
574 
575 /**
576  * @tc.name: RepeatNodeCacheTest014
577  * @tc.desc: Test DumpL2
578  * @tc.type: FUNC
579  */
580 HWTEST_F(RepeatVirtualTestNg, RepeatNodeCacheTest014, TestSize.Level1)
581 {
582     RepeatVirtualScrollCaches caches(cacheCountL24ttype,
583                                      g_onCreateNode,
584                                      g_onUpdateNode,
585                                      g_onGetKeys4Range,
586                                      g_onGetTypes4Range);
587 
588     /**
589      * @tc.steps: step1. Try to call DumpL2
590      * @tc.expected: Because there are no items. Its expected that there is size=0 substring in return value
591      */
592     std::string l2Dump = caches.DumpL2();
593     const std::string expectedSubString = "size=0";
594     EXPECT_NE(l2Dump.find(expectedSubString), std::string::npos);
595 }
596 
597 /**
598  * @tc.name: RepeatNodeCacheTest015
599  * @tc.desc: Test DumpKey4Index
600  * @tc.type: FUNC
601  */
602 HWTEST_F(RepeatVirtualTestNg, RepeatNodeCacheTest015, TestSize.Level1)
603 {
604     RepeatVirtualScrollCaches caches(cacheCountL24ttype,
605                                      g_onCreateNode,
606                                      g_onUpdateNode,
607                                      g_onGetKeys4Range,
608                                      g_onGetTypes4Range);
609 
610     /**
611      * @tc.steps: step1. Try to call DumpKey4Index
612      * @tc.expected: Because there are no items. Its expected that there is size=0 substring in return value
613      */
614     std::string key4IndexDump = caches.DumpKey4Index();
615     const std::string expectedSubString = "size=0";
616     EXPECT_NE(key4IndexDump.find(expectedSubString), std::string::npos);
617 }
618 
619 /**
620  * @tc.name: RepeatNodeCacheTest016
621  * @tc.desc: Test DumpTType4Index
622  * @tc.type: FUNC
623  */
624 HWTEST_F(RepeatVirtualTestNg, RepeatNodeCacheTest016, TestSize.Level1)
625 {
626     RepeatVirtualScrollCaches caches(cacheCountL24ttype,
627                                      g_onCreateNode,
628                                      g_onUpdateNode,
629                                      g_onGetKeys4Range,
630                                      g_onGetTypes4Range);
631 
632     /**
633      * @tc.steps: step1. Try to call DumpTType4Index
634      * @tc.expected: Because there are no items. Its expected that there is size=0 substring in return value
635      */
636     std::string tTypeIndex = caches.DumpTType4Index();
637     const std::string expectedSubString = "size=0";
638     EXPECT_NE(tTypeIndex.find(expectedSubString), std::string::npos);
639 }
640 
641 /**
642  * @tc.name: RepeatNodeCacheTest017
643  * @tc.desc: Test DumpUINode4Key
644  * @tc.type: FUNC
645  */
646 HWTEST_F(RepeatVirtualTestNg, RepeatNodeCacheTest017, TestSize.Level1)
647 {
648     RepeatVirtualScrollCaches caches(cacheCountL24ttype,
649                                      g_onCreateNode,
650                                      g_onUpdateNode,
651                                      g_onGetKeys4Range,
652                                      g_onGetTypes4Range);
653 
654     /**
655      * @tc.steps: step1. Try to call DumpUINode4Key
656      * @tc.expected: Because there are no items. Its expected that there is size=0 substring in return value
657      */
658     std::string uiNode4Key = caches.DumpUINode4Key();
659     const std::string expectedSubString = "size=0";
660     EXPECT_NE(uiNode4Key.find(expectedSubString), std::string::npos);
661 }
662 
663 /**
664  * @tc.name: RepeatNodeCacheTest018
665  * @tc.desc: Test DumpUINode4Key4TType
666  * @tc.type: FUNC
667  */
668 HWTEST_F(RepeatVirtualTestNg, RepeatNodeCacheTest018, TestSize.Level1)
669 {
670     RepeatVirtualScrollCaches caches(cacheCountL24ttype,
671                                      g_onCreateNode,
672                                      g_onUpdateNode,
673                                      g_onGetKeys4Range,
674                                      g_onGetTypes4Range);
675 
676 
677     /**
678      * @tc.steps: step1. Try to call DumpUINode4Key4TType
679      * @tc.expected: Because there are no items. Its expected that there is size=0 substring in return value
680      */
681     std::string uiNode4Key4TType = caches.DumpUINode4Key4TType();
682     const std::string expectedSubString = "size=0";
683     EXPECT_NE(uiNode4Key4TType.find(expectedSubString), std::string::npos);
684 }
685 
686 /**
687  * @tc.name: RepeatNodeCacheTest019
688  * @tc.desc: Test DumpUINodeWithKey
689  * @tc.type: FUNC
690  */
691 HWTEST_F(RepeatVirtualTestNg, RepeatNodeCacheTest019, TestSize.Level1)
692 {
693     RepeatVirtualScrollCaches caches(cacheCountL24ttype,
694                                      g_onCreateNode,
695                                      g_onUpdateNode,
696                                      g_onGetKeys4Range,
697                                      g_onGetTypes4Range);
698 
699     /**
700      * @tc.steps: step1. Try to call DumpUINodeWithKey
701      * @tc.expected: Because there are no items. Its expected that there is "no UINode" substring in return value
702      */
703     std::string uiNodeWithKey = caches.DumpUINodeWithKey("Key1");
704     const std::string expectedSubString = "no UINode";
705     EXPECT_NE(uiNodeWithKey.find(expectedSubString), std::string::npos);
706 }
707 
708 /**
709  * @tc.name: RepeatNodeCacheTest020
710  * @tc.desc: Test DumpUINode
711  * @tc.type: FUNC
712  */
713 HWTEST_F(RepeatVirtualTestNg, RepeatNodeCacheTest020, TestSize.Level1)
714 {
715     RepeatVirtualScrollCaches caches(cacheCountL24ttype,
716                                      g_onCreateNode,
717                                      g_onUpdateNode,
718                                      g_onGetKeys4Range,
719                                      g_onGetTypes4Range);
720 
721     /**
722      * @tc.steps: step1. Try to call DumpUINode
723      * @tc.expected: Because input argument is nullptr its expected that there is nullptr in return value
724      */
725     std::string uiNode = caches.DumpUINode(nullptr);
726     const std::string expectedSubString = "nullptr";
727     EXPECT_NE(uiNode.find(expectedSubString), std::string::npos);
728 }
729 
730 /**
731  * @tc.name: RepeatNodeCacheTest021
732  * @tc.desc: Test OnConfigurationUpdate function
733  * @tc.type: FUNC
734  */
735 HWTEST_F(RepeatVirtualTestNg, RepeatNodeCacheTest021, TestSize.Level1)
736 {
737     auto repeatNode = RepeatVirtualScrollNode::GetOrCreateRepeatNode(
738                           1,
739                           1,
740                           templateCachedCountMap,
741                           g_onCreateNode,
742                           g_onUpdateNode,
743                           g_onGetKeys4Range,
744                           g_onGetTypes4Range,
745                           g_onSetActiveRange);
746 
747     ConfigurationChange cfgChange;
748     cfgChange.colorModeUpdate = true;
749     /**
750      * @tc.steps: step1. Try to call GetOrCreateRepeatNode.
751      * @tc.expected: Instead of creating current node is returned,
752      */
753     auto repeatNode2 = RepeatVirtualScrollNode::GetOrCreateRepeatNode(
754                           1,
755                           1,
756                           templateCachedCountMap,
757                           g_onCreateNode,
758                           g_onUpdateNode,
759                           g_onGetKeys4Range,
760                           g_onGetTypes4Range,
761                           g_onSetActiveRange);
762 
763     EXPECT_EQ(repeatNode, repeatNode2);
764     /**
765      * @tc.steps: step3. Try to call OnConfigurationChange.
766      * @tc.expected: No code crash happens
767      */
768     repeatNode->OnConfigurationUpdate(cfgChange);
769 }
770 
771 /**
772  * @tc.name: RepeatNodeCacheTest022
773  * @tc.desc: Test FetchMoreKeysTTypes with invalid values.
774  * @tc.type: FUNC
775  */
776 HWTEST_F(RepeatVirtualTestNg, RepeatNodeCacheTest022, TestSize.Level1)
777 {
778     RepeatVirtualScrollCaches caches(cacheCountL24ttype,
779                                      g_onCreateNode,
780                                      g_onUpdateNode,
781                                      g_onGetKeys4Range,
782                                      g_onGetTypes4Range);
783 
784     /**
785      * @tc.steps: step1. Try to call FetchMoreKeysTTypes so that "from" is bigger than "to"
786      * @tc.expected: False is expected to be returned
787      */
788     bool status = caches.FetchMoreKeysTTypes(2, 1);
789     EXPECT_EQ(status, false);
790 }
791 
792 /**
793  * @tc.name: RepeatNodeCacheTest023
794  * @tc.desc: Test FetchMoreKeysTTypes with special MaxTo5 lambda.
795  * @tc.type: FUNC
796  */
797 HWTEST_F(RepeatVirtualTestNg, RepeatNodeCacheTest023, TestSize.Level1)
798 {
799     /**
800      * @tc.steps: step1. Create caches object with Keys function that limits keys to 5 (for unit testing)
801      * @tc.expected: Object is created correctly
802      */
803     RepeatVirtualScrollCaches caches(cacheCountL24ttype,
804                                      g_onCreateNode,
805                                      g_onUpdateNode,
806                                      g_onGetKeys4RangeMaxTo5,
807                                      g_onGetTypes4Range);
808 
809      /**
810      * @tc.steps: step2. Try to call FetchMoreKeysTTypes so that internally "keys"
811      * *are smaller than "types" due to g_onGetKeys4RangeMaxTo5
812      * @tc.expected: False is expected to be returned
813      */
814     bool status = caches.FetchMoreKeysTTypes(1, 10);
815     EXPECT_EQ(status, false);
816 }
817 
818 /**
819  * @tc.name: RepeatNodeCacheTest024
820  * @tc.desc: Test GetKey4Index with fetch and creating new node.
821  * @tc.type: FUNC
822  */
823 HWTEST_F(RepeatVirtualTestNg, RepeatNodeCacheTest024, TestSize.Level1)
824 {
825     RepeatVirtualScrollCaches caches(cacheCountL24ttype,
826                                      onCreateNode,
827                                      g_onUpdateNode,
828                                      g_onGetKeys4Range,
829                                      g_onGetTypes4Range);
830 
831     /**
832      * @tc.steps: step1. Try to get key for index 2.
833      * @tc.expected: Because second parameter is true FetchMoreKeysTTypes will be internally
834      * called and Key2 string is returned
835      */
836     std::optional<std::string> key = caches.GetKey4Index(2, true);
837     EXPECT_EQ(key, "Key2");
838     /**
839      * @tc.steps: step2. Try to create node for index 2.
840      * @tc.expected: Because onCreateNode lambda used that really creates node 1 is expected.
841      */
842     RefPtr<UINode> node = caches.CreateNewNode(2);
843     EXPECT_NE(node, nullptr);
844 
845     RefPtr<UINode> uinode = caches.DropFromL1("Key2");
846     EXPECT_NE(uinode, nullptr);
847 }
848 
849 /**
850  * @tc.name: RepeatNodeCacheTest025
851  * @tc.desc: Test GetDistanceFromRange
852  * @tc.type: FUNC
853  */
854 HWTEST_F(RepeatVirtualTestNg, RepeatNodeCacheTest025, TestSize.Level1)
855 {
856     RepeatVirtualScrollCaches caches(
857         cacheCountL24ttype, g_onCreateNode, g_onUpdateNode, g_onGetKeys4Range, g_onGetTypes4Range);
858 
859     int32_t dist = caches.GetDistanceFromRange(UINT32_MAX);
860     EXPECT_EQ(dist, UINT32_MAX);
861 
862     caches.lastActiveRanges_[0].first = 10;
863     caches.lastActiveRanges_[0].second = 30;
864     caches.lastActiveRanges_[1].first = 20;
865     dist = caches.GetDistanceFromRange(9);
866     EXPECT_EQ(dist, 0);
867 
868     dist = caches.GetDistanceFromRange(11);
869     EXPECT_EQ(dist, 0);
870 
871     caches.lastActiveRanges_[0].first = 10;
872     caches.lastActiveRanges_[0].second = 30;
873     caches.lastActiveRanges_[1].second = 20;
874     dist = caches.GetDistanceFromRange(29);
875     EXPECT_EQ(dist, 0);
876 
877     dist = caches.GetDistanceFromRange(31);
878     EXPECT_EQ(dist, 0);
879 }
880 
881 /**
882  * @tc.name: RepeatNodeCacheTest026
883  * @tc.desc: Test GetCachedNode4Key4Ttype
884  * @tc.type: FUNC
885  */
886 HWTEST_F(RepeatVirtualTestNg, RepeatNodeCacheTest026, TestSize.Level1)
887 {
888     /**
889      * @tc.steps: step1. Create cached object with Keys function that limits keys to 5 (for unit testing)
890      * @tc.expected: Object is created correctly
891      */
892     RepeatVirtualScrollCaches caches(
893         cacheCountL24ttype, g_onCreateNode, g_onUpdateNode, g_onGetKeys4RangeMaxTo5, g_onGetTypes4Range);
894 
895     auto ret = caches.GetCachedNode4Key4Ttype(std::nullopt, std::nullopt);
896     EXPECT_EQ(ret, nullptr);
897     ret = caches.GetCachedNode4Key4Ttype(std::string("a"), std::nullopt);
898     EXPECT_EQ(ret, nullptr);
899     ret = caches.GetCachedNode4Key4Ttype(std::nullopt, std::string("a"));
900     EXPECT_EQ(ret, nullptr);
901     ret = caches.GetCachedNode4Key4Ttype(std::string("a"), std::string("a"));
902     EXPECT_EQ(ret, nullptr);
903 
904     // std::unordered_map<std::string, std::unordered_map<std::string, RefPtr<UINode>>> node4key4ttype_;
905     caches.node4key4ttype_.insert({ std::string("a"), { { std::string("a"), nullptr } } });
906     ret = caches.GetCachedNode4Key4Ttype(std::string("a"), std::string("a"));
907     EXPECT_EQ(ret, nullptr);
908     ret = caches.GetCachedNode4Key4Ttype(std::string("b"), std::string("a"));
909     EXPECT_EQ(ret, nullptr);
910 }
911 
912 /**
913  * @tc.name: RepeatNodeCacheTest027
914  * @tc.desc: Test GetCachedNode4Key
915  * @tc.type: FUNC
916  */
917 HWTEST_F(RepeatVirtualTestNg, RepeatNodeCacheTest027, TestSize.Level1)
918 {
919     /**
920      * @tc.steps: step1. Create cached object with Keys function that limits keys to 5 (for unit testing)
921      * @tc.expected: Object is created correctly
922      */
923     RepeatVirtualScrollCaches caches(
924         cacheCountL24ttype, g_onCreateNode, g_onUpdateNode, g_onGetKeys4RangeMaxTo5, g_onGetTypes4Range);
925 
926     auto ret = caches.GetCachedNode4Key(std::nullopt);
927     EXPECT_FALSE(ret.has_value());
928 }
929 
930 /**
931  * @tc.name: RepeatNodeCacheTest028
932  * @tc.desc: Test GetTType4Index
933  * @tc.type: FUNC
934  */
935 HWTEST_F(RepeatVirtualTestNg, RepeatNodeCacheTest028, TestSize.Level1)
936 {
937     /**
938      * @tc.steps: step1. Create cached object with Keys function that limits keys to 5 (for unit testing)
939      * @tc.expected: Object is created correctly
940      */
941     RepeatVirtualScrollCaches caches(
942         cacheCountL24ttype, g_onCreateNode, g_onUpdateNode, g_onGetKeys4RangeMaxTo5, g_onGetTypes4Range);
943     std::string val("0");
944     caches.ttype4index_.insert({ 0, val });
945     auto ret = caches.GetTType4Index(0);
946     EXPECT_TRUE(ret.has_value());
947 }
948 
949 /**
950  * @tc.name: RepeatNodeCacheTest029
951  * @tc.desc: Test GetIndex4Key
952  * @tc.type: FUNC
953  */
954 HWTEST_F(RepeatVirtualTestNg, RepeatNodeCacheTest029, TestSize.Level1)
955 {
956     /**
957      * @tc.steps: step1. Create cached object with Keys function that limits keys to 5 (for unit testing)
958      * @tc.expected: Object is created correctly
959      */
960     RepeatVirtualScrollCaches caches(
961         cacheCountL24ttype, g_onCreateNode, g_onUpdateNode, g_onGetKeys4RangeMaxTo5, g_onGetTypes4Range);
962 
963     std::string key("key");
964     caches.index4Key_.insert({ key, 0 });
965     auto ret = caches.GetIndex4Key(key);
966     EXPECT_EQ(ret, 0);
967 }
968 
969 /**
970  * @tc.name: RepeatNodeCacheTest030
971  * @tc.desc: Test FindUnusedKeys
972  * @tc.type: FUNC
973  */
974 HWTEST_F(RepeatVirtualTestNg, RepeatNodeCacheTest030, TestSize.Level1)
975 {
976     /**
977      * @tc.steps: step1. Create cached object with Keys function that limits keys to 5 (for unit testing)
978      * @tc.expected: Object is created correctly
979      */
980     RepeatVirtualScrollCaches caches(
981         cacheCountL24ttype, g_onCreateNode, g_onUpdateNode, g_onGetKeys4RangeMaxTo5, g_onGetTypes4Range);
982 
983     std::string key("key");
984     caches.node4key_.insert({ key, CacheItem() });
985     std::set<std::pair<bool, std::string>> result;
986     caches.FindUnusedKeys(result);
987     EXPECT_EQ(result.size(), 1);
988 
989     result.clear();
990     caches.index4Key_.insert({ key, 0 });
991     caches.FindUnusedKeys(result);
992     EXPECT_EQ(result.size(), 0);
993 }
994 
995 /**
996  * @tc.name: RepeatNodeCacheTest031
997  * @tc.desc: Test UINodeHasBeenUpdated
998  * @tc.type: FUNC
999  */
1000 HWTEST_F(RepeatVirtualTestNg, RepeatNodeCacheTest031, TestSize.Level1)
1001 {
1002     /**
1003      * @tc.steps: step1. Create cached object with Keys function that limits keys to 5 (for unit testing)
1004      * @tc.expected: Object is created correctly
1005      */
1006     RepeatVirtualScrollCaches caches(
1007         cacheCountL24ttype, g_onCreateNode, g_onUpdateNode, g_onGetKeys4RangeMaxTo5, g_onGetTypes4Range);
1008 
1009     std::string key("key");
1010     std::string key2("key2");
1011     caches.node4key4ttype_.insert({ key, { { key2, nullptr } } });
1012     auto ret = caches.UINodeHasBeenUpdated(key, std::string("a"), std::string("a"));
1013     EXPECT_EQ(ret, nullptr);
1014     ret = caches.UINodeHasBeenUpdated(key, key2, std::string("a"));
1015     EXPECT_EQ(ret, nullptr);
1016 
1017     caches.node4key_.insert({ key2, CacheItem() });
1018     ret = caches.UINodeHasBeenUpdated(key, key2, std::string("a"));
1019     EXPECT_EQ(ret, nullptr);
1020 }
1021 
1022 /**
1023  * @tc.name: RepeatNodeCacheTest032
1024  * @tc.desc: Test GetL1KeyToUpdate
1025  * @tc.type: FUNC
1026  */
1027 HWTEST_F(RepeatVirtualTestNg, RepeatNodeCacheTest032, TestSize.Level1)
1028 {
1029     RepeatVirtualScrollCaches caches(
1030         cacheCountL24ttype, g_onCreateNode, g_onUpdateNode, g_onGetKeys4Range, g_onGetTypes4Range);
1031 
1032     std::string key("key");
1033     std::string key1("key1");
1034     caches.activeNodeKeysInL1_.insert(key);
1035     std::optional<std::string> ret = caches.GetL1KeyToUpdate(key1);
1036     EXPECT_EQ(ret, std::nullopt);
1037 
1038     caches.index4Key_.insert({ key, 0 });
1039     ret = caches.GetL1KeyToUpdate(key1);
1040     EXPECT_EQ(ret, std::nullopt);
1041 
1042     caches.index4Key_.clear();
1043     caches.node4key4ttype_.insert({ key1, {} });
1044     ret = caches.GetL1KeyToUpdate(key1);
1045     EXPECT_EQ(ret, std::nullopt);
1046 
1047     caches.node4key4ttype_.clear();
1048     caches.node4key4ttype_.insert({ key1, { { key, nullptr } } });
1049     ret = caches.GetL1KeyToUpdate(key1);
1050     EXPECT_NE(ret, std::nullopt);
1051 }
1052 
1053 /**
1054  * @tc.name: RepeatNodeCacheTest033
1055  * @tc.desc: Test GetL2KeyToUpdate
1056  * @tc.type: FUNC
1057  */
1058 HWTEST_F(RepeatVirtualTestNg, RepeatNodeCacheTest033, TestSize.Level1)
1059 {
1060     RepeatVirtualScrollCaches caches(
1061         cacheCountL24ttype, g_onCreateNode, g_onUpdateNode, g_onGetKeys4Range, g_onGetTypes4Range);
1062 
1063     auto ret = caches.GetL2KeyToUpdate(std::nullopt);
1064     EXPECT_EQ(ret, std::nullopt);
1065 
1066     std::string key("key");
1067     ret = caches.GetL2KeyToUpdate(key);
1068     EXPECT_EQ(ret, std::nullopt);
1069 
1070     caches.node4key4ttype_.insert({ key, { { key, nullptr } } });
1071     ret = caches.GetL2KeyToUpdate(key);
1072     EXPECT_NE(ret, std::nullopt);
1073 
1074     caches.node4key4ttype_.clear();
1075     caches.node4key4ttype_.insert({ key, { { key, nullptr } } });
1076     ret = caches.GetL2KeyToUpdate(key);
1077     EXPECT_NE(ret, std::nullopt);
1078 
1079     std::unordered_map<std::string, RefPtr<UINode>> nodeKey;
1080     caches.node4key4ttype_ = { { "template1", nodeKey } };
1081     ret = caches.GetL2KeyToUpdate(key);
1082     EXPECT_EQ(ret, std::nullopt);
1083 }
1084 
1085 /**
1086  * @tc.name: RepeatNodeCacheTest034
1087  * @tc.desc: Test GetFrameNodeIndex
1088  * @tc.type: FUNC
1089  */
1090 HWTEST_F(RepeatVirtualTestNg, RepeatNodeCacheTest034, TestSize.Level1)
1091 {
1092     RepeatVirtualScrollCaches caches(
1093         cacheCountL24ttype, g_onCreateNode, g_onUpdateNode, g_onGetKeys4Range, g_onGetTypes4Range);
1094 
1095     auto ret = caches.GetFrameNodeIndex(nullptr);
1096     EXPECT_EQ(ret, -1);
1097 
1098     std::string key("key");
1099     caches.activeNodeKeysInL1_.insert(key);
1100     ret = caches.GetFrameNodeIndex(nullptr);
1101     EXPECT_EQ(ret, -1);
1102 
1103     caches.node4key_.insert({ key, CacheItem() });
1104     caches.activeNodeKeysInL1_.insert(key);
1105     ret = caches.GetFrameNodeIndex(nullptr);
1106     EXPECT_EQ(ret, -1);
1107 
1108     caches.activeNodeKeysInL1_ = { "Key1", "Key2" };
1109     caches.key4index_ = { { 0, "Key1" }, { 1, "Key2" } };
1110     caches.ttype4index_ = { { 0, "template1" }, { 1, "template2" } };
1111     caches.index4ttype_ = { { "template1", 0 }, { "template2", 1 } };
1112 
1113     CacheItem cacheItem;
1114     auto node = AceType::MakeRefPtr<FrameNode>("node", -1, AceType::MakeRefPtr<Pattern>());
1115     cacheItem.item = node;
1116     std::unordered_map<std::string, RefPtr<UINode>> nodeKey = { {"Key1", node} };
1117     caches.node4key_ = { {"Key1", cacheItem} };
1118     caches.node4key4ttype_ = { {"template1", nodeKey} };
1119     ret = caches.GetFrameNodeIndex(node);
1120     EXPECT_EQ(ret, -1);
1121 
1122     caches.index4Key_ = { {"Key1", 2} };
1123     ret = caches.GetFrameNodeIndex(node);
1124     EXPECT_EQ(ret, 2);
1125 }
1126 
1127 /**
1128  * @tc.name: RepeatNodeCacheTest035
1129  * @tc.desc: Test Multiple functions
1130  * @tc.type: FUNC
1131  */
1132 HWTEST_F(RepeatVirtualTestNg, RepeatNodeCacheTest035, TestSize.Level1)
1133 {
1134     RepeatVirtualScrollCaches caches(cacheCountL24ttype,
1135                                      onCreateNode,
1136                                      g_onUpdateNode,
1137                                      g_onGetKeys4Range,
1138                                      g_onGetTypes4Range);
1139 
1140     std::optional<std::string> key1 = caches.GetKey4Index(1, true);
1141     EXPECT_EQ(key1, "Key1");
1142     std::optional<std::string> key2 = caches.GetKey4Index(2, true);
1143     EXPECT_EQ(key2, "Key2");
1144     std::optional<std::string> key3 = caches.GetKey4Index(3, true);
1145     EXPECT_EQ(key3, "Key3");
1146     RefPtr<UINode> node1 = caches.CreateNewNode(1);
1147     EXPECT_NE(node1, nullptr);
1148     RefPtr<UINode> node2 = caches.CreateNewNode(2);
1149     EXPECT_NE(node2, nullptr);
1150     RefPtr<UINode> node3 = caches.CreateNewNode(3);
1151     EXPECT_NE(node3, nullptr);
1152 
1153     auto repeatNode = RepeatVirtualScrollNode::GetOrCreateRepeatNode(
1154                           1,
1155                           3,
1156                           templateCachedCountMap,
1157                           onCreateNode,
1158                           g_onUpdateNode,
1159                           g_onGetKeys4Range,
1160                           g_onGetTypes4Range,
1161                           g_onSetActiveRange);
1162 
1163     // Set caches to repeat.
1164     repeatNode->caches_ = caches;
1165     repeatNode->caches_.FetchMoreKeysTTypes(1, 3);
1166     repeatNode->caches_.AddKeyToL1("Key1");
1167     repeatNode->caches_.AddKeyToL1("Key2");
1168     repeatNode->caches_.AddKeyToL1("Key3");
1169 
1170     std::set<int32_t> activeItems;
1171     const int largeValue = 100;
1172     for (int i = 0; i < largeValue; i++) {
1173         activeItems.insert(i);
1174     }
1175     std::set<int32_t> cachedItems;
1176     cachedItems.insert(1);
1177 
1178     /**
1179      * @tc.steps: step2. Perform two DoSetActiveChildRange calls
1180      * First with valid value 1 and second too large value
1181      * @tc.expected: Functions do not return any value
1182      */
1183     repeatNode->DoSetActiveChildRange(activeItems, cachedItems, 1);
1184     repeatNode->DoSetActiveChildRange(activeItems, cachedItems, largeValue+1);
1185 }
1186 
1187 /**
1188  * @tc.name: RepeatNodeCacheTest036
1189  * @tc.desc: Call functions that are currently empty implementations
1190  * @tc.type: FUNC
1191  */
1192 HWTEST_F(RepeatVirtualTestNg, RepeatNodeCacheTest036, TestSize.Level1)
1193 {
1194     auto repeatNode = RepeatVirtualScrollNode::GetOrCreateRepeatNode(
1195                           1,
1196                           3,
1197                           templateCachedCountMap,
1198                           onCreateNode,
1199                           g_onUpdateNode,
1200                           g_onGetKeys4Range,
1201                           g_onGetTypes4Range,
1202                           g_onSetActiveRange);
1203 
1204     EXPECT_NE(repeatNode, nullptr);
1205 
__anona0f584000a02(int32_t start, int32_t end) 1206     auto onMoveLambda = [](int32_t start, int32_t end) {
1207     };
1208     /**
1209      * @tc.steps: step1. Call functions with no implementation yet in repeat_virtual_scroll_node.cpp
1210      * @tc.expected: Not crash happens
1211      */
1212     repeatNode->SetOnMove(std::move(onMoveLambda));
1213     repeatNode->MoveData(0, 100);
1214     auto frameNode = repeatNode->GetFrameNode(1);
1215     repeatNode->InitDragManager(frameNode);
1216     repeatNode->InitAllChildrenDragManager(true);
1217 }
1218 
1219 /**
1220  * @tc.name: RepeatNodeCacheTest037
1221  * @tc.desc: Test CheckNode4IndexInL1 function
1222  * @tc.type: FUNC
1223  */
1224 HWTEST_F(RepeatVirtualTestNg, RepeatNodeCacheTest037, TestSize.Level1)
1225 {
1226     auto repeatNode = GetOrCreateRepeatNode(true);
1227     ASSERT_NE(repeatNode, nullptr);
1228     auto frameNode = AceType::MakeRefPtr<FrameNode>("node", -1, AceType::MakeRefPtr<Pattern>());
1229     auto ret = repeatNode->CheckNode4IndexInL1(3, 2, 4, 1, 1, frameNode);
1230     EXPECT_TRUE(frameNode->isActive_);
1231     EXPECT_TRUE(ret);
1232 
1233     repeatNode->SetIsLoop(true);
1234     ret = repeatNode->CheckNode4IndexInL1(3, 5, 2, 1, 1, frameNode);
1235     EXPECT_FALSE(frameNode->isActive_);
1236     EXPECT_TRUE(ret);
1237 
1238     repeatNode->SetIsLoop(false);
1239     ret = repeatNode->CheckNode4IndexInL1(3, 5, 2, 1, 1, frameNode);
1240     EXPECT_FALSE(frameNode->isActive_);
1241     EXPECT_FALSE(ret);
1242 }
1243 
1244 /**
1245  * @tc.name: RepeatNodeCacheTest038
1246  * @tc.desc: Test for DropFromL1
1247  * @tc.type: FUNC
1248  */
1249 HWTEST_F(RepeatVirtualTestNg, RepeatNodeCacheTest038, TestSize.Level1)
1250 {
1251     auto repeatNode = GetOrCreateRepeatNode(false);
1252     ASSERT_NE(repeatNode, nullptr);
1253 
1254     auto childNode = AceType::MakeRefPtr<FrameNode>("node", -1, AceType::MakeRefPtr<Pattern>());
1255     repeatNode->children_.clear();
1256     repeatNode->children_.push_back(childNode);
1257     EXPECT_EQ(repeatNode->children_.size(), 1);
1258     repeatNode->DropFromL1("Key038");
1259     EXPECT_EQ(repeatNode->children_.size(), 1);
1260 }
1261 
1262 /**
1263  * @tc.name: RepeatNodeCacheTest039
1264  * @tc.desc: Test for UpdateRenderState
1265  * @tc.type: FUNC
1266  */
1267 HWTEST_F(RepeatVirtualTestNg, RepeatNodeCacheTest039, TestSize.Level1)
1268 {
1269     auto repeatNode = GetOrCreateRepeatNode(false);
1270     ASSERT_NE(repeatNode, nullptr);
1271     auto childNode = AceType::MakeRefPtr<FrameNode>("node", -1, AceType::MakeRefPtr<Pattern>());
1272     repeatNode->children_.clear();
1273     repeatNode->children_.push_back(childNode);
1274     EXPECT_EQ(repeatNode->children_.size(), 1);
1275 
1276     auto frameNode = AceType::MakeRefPtr<FrameNode>("node", -1, AceType::MakeRefPtr<Pattern>());
1277     repeatNode->SetParent(frameNode);
1278     repeatNode->UpdateRenderState(true);
1279     EXPECT_EQ(repeatNode->children_.size(), 0);
1280 
1281     repeatNode->children_.push_back(childNode);
1282     repeatNode->UpdateRenderState(false);
1283     EXPECT_EQ(repeatNode->children_.size(), 1);
1284 }
1285 
1286 /**
1287  * @tc.name: RepeatNodeCacheTest040
1288  * @tc.desc: Test for GetFrameChildByIndex
1289  * @tc.type: FUNC
1290  */
1291 HWTEST_F(RepeatVirtualTestNg, RepeatNodeCacheTest040, TestSize.Level1)
1292 {
1293     auto repeatNode = GetOrCreateRepeatNode(false);
1294     ASSERT_NE(repeatNode, nullptr);
1295     auto childNode = repeatNode->GetFrameChildByIndex(0, false, false, false);
1296     EXPECT_EQ(childNode, nullptr);
1297 
1298     RepeatVirtualScrollCaches caches(
1299         cacheCountL24ttype, g_onCreateNode, g_onUpdateNode, g_onGetKeys4Range, g_onGetTypes4Range);
1300     caches.key4index_.insert(pair<int, string>(0, "Key1"));
1301     CacheItem cacheItem;
1302     auto nodeId = ElementRegister::GetInstance()->MakeUniqueId();
1303     auto node = AceType::MakeRefPtr<FrameNode>("node", nodeId, AceType::MakeRefPtr<Pattern>());
1304     cacheItem.item = node;
1305 
1306     RefPtr<UINode> uiNode = AceType::MakeRefPtr<FrameNode>("node", -1, AceType::MakeRefPtr<Pattern>());
1307     std::unordered_map<std::string, RefPtr<UINode>> nodeKey = { { "Key1", uiNode } };
1308     caches.node4key_ = { { "Key1", cacheItem } };
1309     caches.node4key4ttype_ = { { "template1", nodeKey } };
1310     repeatNode->caches_ = caches;
1311 
1312     childNode = repeatNode->GetFrameChildByIndex(1, false, false, false);
1313     EXPECT_EQ(childNode, nullptr);
1314 
1315     childNode = repeatNode->GetFrameChildByIndex(1, true, false, false);
1316     EXPECT_EQ(childNode, nullptr);
1317 
1318     childNode = repeatNode->GetFrameChildByIndex(0, true, false, false);
1319     repeatNode->isActive_ = true;
1320     EXPECT_EQ(childNode, nullptr);
1321 
1322     nodeKey = { { "Key1", node } };
1323     caches.index4ttype_ = { { "template1", 0 } };
1324     caches.ttype4index_ = { { 0, "template1" } };
1325     caches.node4key4ttype_ = { { "template1", nodeKey } };
1326     caches.activeNodeKeysInL1_ = { "Key1" };
1327     repeatNode->caches_ = caches;
1328     childNode = repeatNode->GetFrameChildByIndex(0, false, false, true);
1329     ASSERT_NE(childNode, nullptr);
1330     EXPECT_EQ(childNode->GetId(), nodeId);
1331 }
1332 
1333 /**
1334  * @tc.name: RepeatNodeCacheTest041
1335  * @tc.desc: Test for GetFrameChildByIndex
1336  * @tc.type: FUNC
1337  */
1338 HWTEST_F(RepeatVirtualTestNg, RepeatNodeCacheTest041, TestSize.Level1)
1339 {
1340     auto repeatNode = GetOrCreateRepeatNode(false);
1341     ASSERT_NE(repeatNode, nullptr);
1342     auto childNode = repeatNode->GetFrameChildByIndex(0, false, false, false);
1343     EXPECT_EQ(childNode, nullptr);
1344 
1345     RepeatVirtualScrollCaches caches(
1346         cacheCountL24ttype, g_onCreateNode, g_onUpdateNode, g_onGetKeys4Range, g_onGetTypes4Range);
1347     caches.key4index_.insert(pair<int, string>(0, "Key041"));
1348     CacheItem cacheItem;
1349     auto nodeId = ElementRegister::GetInstance()->MakeUniqueId();
1350     auto node = AceType::MakeRefPtr<FrameNode>("node", nodeId, AceType::MakeRefPtr<Pattern>());
1351     cacheItem.item = node;
1352     std::unordered_map<std::string, RefPtr<UINode>> nodeKey = { { "Key041", node } };
1353     caches.node4key_ = { { "Key041", cacheItem } };
1354 
1355     auto ttype = g_onGetTypes4Range(0, 0).front();
1356     caches.node4key4ttype_ = { { ttype, nodeKey } };
1357     caches.ttype4index_ = { { 0, ttype } };
1358     caches.index4ttype_ = { { ttype, 0 } };
1359     repeatNode->caches_ = caches;
1360     repeatNode->onMainTree_ = true;
1361 
__anona0f584000b02(int32_t a, int32_t b) 1362     std::function<void(int32_t, int32_t)> onMoveEvent_ = [](int32_t a, int32_t b) {};
1363     repeatNode->onMoveEvent_ = onMoveEvent_;
1364     childNode = repeatNode->GetFrameChildByIndex(0, false, false, true);
1365     ASSERT_NE(childNode, nullptr);
1366     EXPECT_EQ(childNode->GetId(), nodeId);
1367 }
1368 
1369 /**
1370  * @tc.name: RepeatNodeCacheTest042
1371  * @tc.desc: Test for GetChildren
1372  * @tc.type: FUNC
1373  */
1374 HWTEST_F(RepeatVirtualTestNg, RepeatNodeCacheTest042, TestSize.Level1)
1375 {
1376     auto repeatNode = GetOrCreateRepeatNode(false);
1377     ASSERT_NE(repeatNode, nullptr);
1378     repeatNode->caches_.activeNodeKeysInL1_ = { { "Key042", "Key2", "Key3" } };
1379 
1380     CacheItem cacheItem;
1381     auto node = AceType::MakeRefPtr<FrameNode>("node", -1, AceType::MakeRefPtr<Pattern>());
1382     cacheItem.item = node;
1383     std::unordered_map<std::string, RefPtr<UINode>> nodeKey = { { "Key042", node } };
1384     repeatNode->caches_.index4Key_ = { { "Key042", 0 } };
1385     repeatNode->caches_.node4key_ = { { "Key042", cacheItem } };
1386     auto children = repeatNode->GetChildren();
1387     EXPECT_EQ(children.size(), 1);
1388 
1389     repeatNode->children_ = { node };
1390     children = repeatNode->GetChildren();
1391     EXPECT_EQ(children.size(), 1);
1392 }
1393 
1394 /**
1395  * @tc.name: RepeatNodeCacheTest043
1396  * @tc.desc: Test UpdateChildrenFreezeState function
1397  * @tc.type: FUNC
1398  */
1399 HWTEST_F(RepeatVirtualTestNg, RepeatNodeCacheTest043, TestSize.Level1)
1400 {
1401     auto repeatNode = GetOrCreateRepeatNode(false);
1402     ASSERT_NE(repeatNode, nullptr);
1403     repeatNode->caches_.activeNodeKeysInL1_ = { { "Key043", "Key2", "Key3" } };
1404 
1405     CacheItem cacheItem;
1406     auto node = AceType::MakeRefPtr<FrameNode>("node", -1, AceType::MakeRefPtr<Pattern>());
1407     cacheItem.item = node;
1408     std::unordered_map<std::string, RefPtr<UINode>> nodeKey = { { "Key043", node } };
1409     repeatNode->caches_.node4key_ = { { "Key043", cacheItem } };
1410     auto context = MockPipelineContext::GetCurrent();
1411     ASSERT_NE(context, nullptr);
1412     context->SetOpenInvisibleFreeze(true);
1413     repeatNode->UpdateChildrenFreezeState(true);
1414     for (auto iter = repeatNode->caches_.node4key_.begin(); iter != repeatNode->caches_.node4key_.end(); ++iter) {
1415         auto item = iter->second.item;
1416         ASSERT_NE(item, nullptr);
1417         EXPECT_TRUE(item->isFreeze_);
1418     }
1419 
1420     repeatNode->UpdateChildrenFreezeState(false);
1421     for (auto iter = repeatNode->caches_.node4key_.begin(); iter != repeatNode->caches_.node4key_.end(); ++iter) {
1422         auto item = iter->second.item;
1423         ASSERT_NE(item, nullptr);
1424         EXPECT_FALSE(item->isFreeze_);
1425     }
1426 }
1427 
1428 /**
1429  * @tc.name: RepeatNodeCacheTest044
1430  * @tc.desc: Test OnConfigurationUpdate function
1431  * @tc.type: FUNC
1432  */
1433 HWTEST_F(RepeatVirtualTestNg, RepeatNodeCacheTest044, TestSize.Level1)
1434 {
1435     auto repeatNode = GetOrCreateRepeatNode(false);
1436 
1437     CacheItem cacheItem;
1438     auto frameNode = FrameNode::CreateFrameNode("frameNode", 1, AceType::MakeRefPtr<Pattern>(), true);
1439     ASSERT_NE(frameNode, nullptr);
1440     ASSERT_NE(frameNode->pattern_, nullptr);
1441 
1442     cacheItem.item = frameNode;
1443     std::unordered_map<std::string, RefPtr<UINode>> nodeKey = { { "Key044", frameNode } };
1444     repeatNode->caches_.node4key_ = { { "Key044", cacheItem } };
1445 
1446     ConfigurationChange cfgChange;
1447     cfgChange.colorModeUpdate = true;
1448     repeatNode->OnConfigurationUpdate(cfgChange);
1449 }
1450 
1451 /**
1452  * @tc.name: RepeatNodeCacheTest045
1453  * @tc.desc: Test HasOverlapWithLastActiveRange function
1454  * @tc.type: FUNC
1455  */
1456 HWTEST_F(RepeatVirtualTestNg, RepeatNodeCacheTest045, TestSize.Level1)
1457 {
1458     RepeatVirtualScrollCaches caches(
1459         cacheCountL24ttype, g_onCreateNode, g_onUpdateNode, g_onGetKeys4Range, g_onGetTypes4Range);
1460 
1461     caches.lastActiveRanges_[0].first = 10;
1462     caches.lastActiveRanges_[0].second = 30;
1463     auto ret = caches.HasOverlapWithLastActiveRange(10, 20);
1464     EXPECT_TRUE(ret);
1465 
1466     caches.lastActiveRanges_[0].first = 20;
1467     caches.lastActiveRanges_[0].second = 10;
1468     ret = caches.HasOverlapWithLastActiveRange(10, 20);
1469     EXPECT_TRUE(ret);
1470 }
1471 
1472 /**
1473  * @tc.name: RepeatNodeCacheTest046
1474  * @tc.desc: Test AddKeyToL1 function
1475  * @tc.type: FUNC
1476  */
1477 HWTEST_F(RepeatVirtualTestNg, RepeatNodeCacheTest046, TestSize.Level1)
1478 {
1479     RepeatVirtualScrollCaches caches(
1480         cacheCountL24ttype, g_onCreateNode, g_onUpdateNode, g_onGetKeys4Range, g_onGetTypes4Range);
1481 
1482     auto nodeId = ElementRegister::GetInstance()->MakeUniqueId();
1483     CacheItem cacheItem;
1484     auto node = AceType::MakeRefPtr<FrameNode>("node", nodeId, AceType::MakeRefPtr<Pattern>());
1485     cacheItem.item = node;
1486     std::unordered_map<std::string, RefPtr<UINode>> nodeKey = { { "Key046", node } };
1487     caches.node4key_ = { { "Key046", cacheItem } };
1488     caches.node4key4ttype_ = { { "template046", nodeKey } };
1489     caches.ttype4index_ = { { 0, "template046" } };
1490     caches.index4ttype_ = { { "template046", 0 } };
1491     caches.reusedNodeIds_.clear();
1492     caches.AddKeyToL1("Key046", true);
1493     EXPECT_EQ(caches.reusedNodeIds_.size(), 1);
1494     auto id = caches.reusedNodeIds_.begin();
1495     EXPECT_EQ(*id, node->GetId());
1496 
1497     caches.AddKeyToL1("Key046", true);
1498     EXPECT_EQ(caches.reusedNodeIds_.size(), 1);
1499     EXPECT_EQ(*id, node->GetId());
1500 }
1501 
1502 /**
1503  * @tc.name: RepeatNodeCacheTest047
1504  * @tc.desc: Test UpdateFromL2 function
1505  * @tc.type: FUNC
1506  */
1507 HWTEST_F(RepeatVirtualTestNg, RepeatNodeCacheTest047, TestSize.Level1)
1508 {
1509     RepeatVirtualScrollCaches caches(
1510         cacheCountL24ttype, g_onCreateNode, g_onUpdateNode, g_onGetKeys4Range, g_onGetTypes4Range);
1511     caches.ttype4index_.clear();
1512     auto retNode = caches.UpdateFromL2(0);
1513     ASSERT_EQ(retNode, nullptr);
1514 
1515     caches.ttype4index_ = { { 0, "template047" } };
1516     retNode = caches.UpdateFromL2(0);
1517     ASSERT_EQ(retNode, nullptr);
1518 
1519     retNode = caches.UpdateFromL2(0);
1520     ASSERT_EQ(retNode, nullptr);
1521 
1522     caches.key4index_ = { { 0, "Key047" } };
1523     retNode = caches.UpdateFromL2(0);
1524     ASSERT_EQ(retNode, nullptr);
1525 
1526     auto node = AceType::MakeRefPtr<FrameNode>("node", -1, AceType::MakeRefPtr<Pattern>());
1527     std::unordered_map<std::string, RefPtr<UINode>> nodeKey = { { "Key047", node } };
1528     CacheItem cacheItem;
1529     cacheItem.item = node;
1530     caches.node4key_ = { { "Key047", cacheItem } };
1531     caches.node4key4ttype_ = { { "template047", nodeKey } };
1532     retNode = caches.UpdateFromL2(0);
1533     ASSERT_NE(retNode, nullptr);
1534 }
1535 
1536 /**
1537  * @tc.name: RepeatNodeCacheTest048
1538  * @tc.desc: Test CreateNewNode function
1539  * @tc.type: FUNC
1540  */
1541 HWTEST_F(RepeatVirtualTestNg, RepeatNodeCacheTest048, TestSize.Level1)
1542 {
1543     RepeatVirtualScrollCaches caches(
1544         cacheCountL24ttype, g_onCreateNode, g_onUpdateNode, g_onGetKeys4Range, g_onGetTypes4Range);
1545     auto retNode = caches.CreateNewNode(0);
1546     ASSERT_EQ(retNode, nullptr);
1547     caches.key4index_ = { { 0, "Key048" } };
1548     auto node = AceType::MakeRefPtr<FrameNode>("node", -1, AceType::MakeRefPtr<Pattern>());
1549     std::unordered_map<std::string, RefPtr<UINode>> nodeKey = { { "Key048", node } };
1550     CacheItem cacheItem;
1551     cacheItem.item = node;
1552     caches.node4key_ = { { "Key048", cacheItem } };
1553     retNode = caches.CreateNewNode(0);
1554     ASSERT_NE(retNode, nullptr);
1555     caches.node4key_.clear();
1556     retNode = caches.CreateNewNode(0);
1557     ASSERT_EQ(retNode, nullptr);
1558 
1559     caches.ttype4index_ = { { 0, "template048" } };
1560     retNode = caches.CreateNewNode(0);
1561     ASSERT_EQ(retNode, nullptr);
1562 }
1563 
1564 /**
1565  * @tc.name: RepeatNodeCacheTest050
1566  * @tc.desc: Test RebuildL1 function
1567  * @tc.type: FUNC
1568  */
1569 HWTEST_F(RepeatVirtualTestNg, RepeatNodeCacheTest050, TestSize.Level1)
1570 {
1571     RepeatVirtualScrollCaches caches(
1572         cacheCountL24ttype, g_onCreateNode, g_onUpdateNode, g_onGetKeys4Range, g_onGetTypes4Range);
1573     caches.activeNodeKeysInL1_ = { "Key0" };
1574 
__anona0f584000c02(int32_t a, const RefPtr<UINode>& b) 1575     std::function<bool(int32_t, const RefPtr<UINode>&)> callback = [](int32_t a, const RefPtr<UINode>& b) {
1576         return true;
1577     };
1578     auto ret = caches.RebuildL1(callback);
1579     EXPECT_FALSE(ret);
1580 
1581     caches.activeNodeKeysInL1_ = { "Key050" };
1582     caches.index4Key_ = { { "Key050", 0 } };
1583     auto nodeId = ElementRegister::GetInstance()->MakeUniqueId();
1584     CacheItem cacheItem;
1585     auto node = AceType::MakeRefPtr<FrameNode>("node", nodeId, AceType::MakeRefPtr<Pattern>());
1586     cacheItem.item = node;
1587     caches.node4key_ = { { "Key050", cacheItem } };
1588     ret = caches.RebuildL1(callback);
1589     EXPECT_FALSE(ret);
1590     EXPECT_EQ(caches.activeNodeKeysInL1_.size(), 1);
1591 
__anona0f584000d02(int32_t a, const RefPtr<UINode>& b) 1592     std::function<bool(int32_t, const RefPtr<UINode>&)> callback2 = [](int32_t a, const RefPtr<UINode>& b) {
1593         return false;
1594     };
1595     ret = caches.RebuildL1(callback2);
1596     EXPECT_TRUE(ret);
1597     EXPECT_EQ(caches.activeNodeKeysInL1_.size(), 0);
1598 }
1599 
1600 /**
1601  * @tc.name: RepeatNodeCacheTest051
1602  * @tc.desc: Test SetLastActiveRange function
1603  * @tc.type: FUNC
1604  */
1605 HWTEST_F(RepeatVirtualTestNg, RepeatNodeCacheTest051, TestSize.Level1)
1606 {
1607     RepeatVirtualScrollCaches caches(
1608         cacheCountL24ttype, g_onCreateNode, g_onUpdateNode, g_onGetKeys4Range, g_onGetTypes4Range);
1609     std::pair<uint32_t, uint32_t> range = { 10, 30 };
1610     caches.lastActiveRanges_[0] = range;
1611     EXPECT_EQ(caches.lastActiveRanges_[0], range);
1612     caches.cacheCountL24ttype_ = { { "Key051", { true, 0 } } };
1613     caches.SetLastActiveRange(20, 25);
1614     EXPECT_EQ(caches.lastActiveRanges_[1], range);
1615     std::pair<uint32_t, uint32_t> range2 = { 20, 25 };
1616     EXPECT_EQ(caches.lastActiveRanges_[0], range2);
1617 
1618     caches.cacheCountL24ttype_ = { { "Key051", { false, 0 } } };
1619     caches.SetLastActiveRange(20, 25);
1620     std::map<std::string, std::pair<bool, uint32_t>> cacheCout = { { "Key051", { false, 6 } } };
1621     EXPECT_EQ(caches.cacheCountL24ttype_, cacheCout);
1622 }
1623 
1624 /**
1625  * @tc.name: RepeatNodeCacheTest052
1626  * @tc.desc: Test SetLastActiveRange function
1627  * @tc.type: FUNC
1628  */
1629 HWTEST_F(RepeatVirtualTestNg, RepeatNodeCacheTest052, TestSize.Level1)
1630 {
1631     RepeatVirtualScrollCaches caches(
1632         cacheCountL24ttype, g_onCreateNode, g_onUpdateNode, g_onGetKeys4Range, g_onGetTypes4Range);
1633 
1634     auto ret = caches.Purge();
1635     EXPECT_FALSE(ret);
1636     auto node = AceType::MakeRefPtr<FrameNode>("node", -1, AceType::MakeRefPtr<Pattern>());
1637     std::unordered_map<std::string, RefPtr<UINode>> nodeKey = { { "Key052", node } };
1638     caches.node4key4ttype_ = { { "template052", nodeKey } };
1639     ret = caches.Purge();
1640     EXPECT_TRUE(ret);
1641 }
1642 
1643 /**
1644  * @tc.name: RepeatNodeCacheTest053
1645  * @tc.desc: Test DoSetActiveChildRange function
1646  * @tc.type: FUNC
1647  */
1648 HWTEST_F(RepeatVirtualTestNg, RepeatNodeCacheTest053, TestSize.Level1)
1649 {
1650     auto repeatNode = GetOrCreateRepeatNode(true);
1651 
1652     RepeatVirtualScrollCaches caches(
1653         cacheCountL24ttype, onCreateNode, g_onUpdateNode, g_onGetKeys4Range, g_onGetTypes4Range);
1654 
1655     auto childNode = AceType::MakeRefPtr<FrameNode>("node", -1, AceType::MakeRefPtr<Pattern>());
1656     repeatNode->children_.clear();
1657     repeatNode->children_.push_back(childNode);
1658     EXPECT_EQ(repeatNode->children_.size(), 1);
1659 
1660     caches.index4Key_ = { { "Key053", 0 } };
1661     caches.activeNodeKeysInL1_ = { "Key053" };
1662     repeatNode->caches_ = caches;
1663     repeatNode->DoSetActiveChildRange(0, 1, 0, 0);
1664     EXPECT_EQ(repeatNode->children_.size(), 0);
1665 
1666     CacheItem cacheItem;
1667     auto node = AceType::MakeRefPtr<FrameNode>("node", -1, AceType::MakeRefPtr<Pattern>());
1668     cacheItem.item = node;
1669     std::unordered_map<std::string, RefPtr<UINode>> nodeKey = { { "Key053", node } };
1670     caches.node4key_ = { { "Key053", cacheItem } };
1671     repeatNode->caches_ = caches;
1672     repeatNode->DoSetActiveChildRange(0, 1, 0, 0);
1673     EXPECT_EQ(repeatNode->children_.size(), 0);
1674 
1675     repeatNode->children_.clear();
1676     repeatNode->children_.push_back(childNode);
1677     repeatNode->SetIsLoop(false);
1678     repeatNode->DoSetActiveChildRange(3, 5, 2, 1);
1679     EXPECT_EQ(repeatNode->children_.size(), 0);
1680 }
1681 
1682 /**
1683  * @tc.name: RepeatNodeCacheTest054
1684  * @tc.desc: Test DoSetActiveChildRange function
1685  * @tc.type: FUNC
1686  */
1687 HWTEST_F(RepeatVirtualTestNg, RepeatNodeCacheTest054, TestSize.Level1)
1688 {
1689     auto repeatNode = GetOrCreateRepeatNode(true);
1690 
1691     RepeatVirtualScrollCaches caches(
1692         cacheCountL24ttype, onCreateNode, g_onUpdateNode, g_onGetKeys4Range, g_onGetTypes4Range);
1693 
1694     repeatNode->caches_ = caches;
1695     repeatNode->caches_.AddKeyToL1("Key054");
1696     repeatNode->caches_.AddKeyToL1("Key2");
1697     repeatNode->caches_.AddKeyToL1("Key3");
1698     std::set<int32_t> activeItems;
1699 
1700     const int largeValue = 100;
1701     for (int i = 0; i < largeValue; i++) {
1702         activeItems.insert(i);
1703     }
1704     std::set<int32_t> cachedItems;
1705     cachedItems.insert(1);
1706     repeatNode->DoSetActiveChildRange(activeItems, cachedItems, 1);
1707 
1708     repeatNode->caches_.index4Key_ = { { "Key054", 0 } };
1709     repeatNode->caches_.activeNodeKeysInL1_ = { "Key054" };
1710     repeatNode->DoSetActiveChildRange(activeItems, cachedItems, 0);
1711 
1712     repeatNode->caches_.activeNodeKeysInL1_ = { "Key054" };
1713     auto childNode = AceType::MakeRefPtr<FrameNode>("node", -1, AceType::MakeRefPtr<Pattern>());
1714     repeatNode->children_ = { childNode };
1715     EXPECT_EQ(repeatNode->children_.size(), 1);
1716     repeatNode->DoSetActiveChildRange(activeItems, cachedItems, 0);
1717     EXPECT_EQ(repeatNode->children_.size(), 0);
1718 }
1719 
1720 /**
1721  * @tc.name: RepeatNodeCacheTest055
1722  * @tc.desc: Test DoSetActiveChildRange function
1723  * @tc.type: FUNC
1724  */
1725 HWTEST_F(RepeatVirtualTestNg, RepeatNodeCacheTest055, TestSize.Level1)
1726 {
1727     auto repeatNode = GetOrCreateRepeatNode(true);
1728 
1729     RepeatVirtualScrollCaches caches(
1730         cacheCountL24ttype, onCreateNode, g_onUpdateNode, g_onGetKeys4Range, g_onGetTypes4Range);
1731 
1732     CacheItem cacheItem;
1733     auto node = AceType::MakeRefPtr<FrameNode>("node", -1, AceType::MakeRefPtr<Pattern>());
1734     cacheItem.item = node;
1735     std::unordered_map<std::string, RefPtr<UINode>> nodeKey = { { "Key055", node } };
1736     caches.node4key_ = { { "Key055", cacheItem } };
1737     caches.index4Key_ = { { "Key055", 0 } };
1738     caches.activeNodeKeysInL1_ = { "Key055" };
1739     repeatNode->caches_ = caches;
1740     repeatNode->children_ = { node };
1741     auto childNode = AceType::MakeRefPtr<FrameNode>("node", -1, AceType::MakeRefPtr<Pattern>());
1742     node->children_ = { childNode };
1743 
1744     std::set<int32_t> activeItems;
1745     const int largeValue = 100;
1746     for (int i = 3; i < largeValue; i++) {
1747         activeItems.insert(i);
1748     }
1749 
1750     std::set<int32_t> cachedItems;
1751     cachedItems.insert(1);
1752 
1753     EXPECT_EQ(repeatNode->children_.size(), 1);
1754     repeatNode->DoSetActiveChildRange(activeItems, cachedItems, 1);
1755     EXPECT_EQ(repeatNode->children_.size(), 1);
1756 
1757     EXPECT_EQ(repeatNode->children_.size(), 1);
1758     repeatNode->DoSetActiveChildRange(activeItems, cachedItems, 1);
1759     EXPECT_EQ(repeatNode->children_.size(), 1);
1760 }
1761 
1762 /**
1763  * @tc.name: RepeatNodeCacheTest056
1764  * @tc.desc: Test DoSetActiveChildRange function
1765  * @tc.type: FUNC
1766  */
1767 HWTEST_F(RepeatVirtualTestNg, RepeatNodeCacheTest056, TestSize.Level1)
1768 {
1769     auto repeatNode = GetOrCreateRepeatNode(true);
1770 
1771     RepeatVirtualScrollCaches caches(
1772         cacheCountL24ttype, onCreateNode, g_onUpdateNode, g_onGetKeys4Range, g_onGetTypes4Range);
1773 
1774     CacheItem cacheItem;
1775     auto node = AceType::MakeRefPtr<FrameNode>("node", -1, AceType::MakeRefPtr<Pattern>());
1776     cacheItem.item = node;
1777     std::unordered_map<std::string, RefPtr<UINode>> nodeKey = { { "Key056", node } };
1778     caches.node4key_ = { { "Key056", cacheItem } };
1779     caches.index4Key_ = { { "Key056", 0 } };
1780     caches.activeNodeKeysInL1_ = { "Key056" };
1781     repeatNode->caches_ = caches;
1782     repeatNode->children_ = { node };
1783     auto childNode = AceType::MakeRefPtr<FrameNode>("node", -1, AceType::MakeRefPtr<Pattern>());
1784     node->children_ = { childNode };
1785 
1786     std::set<int32_t> activeItems;
1787     const int largeValue = 100;
1788     for (int i = 0; i < largeValue; i++) {
1789         activeItems.insert(i);
1790     }
1791 
1792     std::set<int32_t> cachedItems = { 1 };
1793 
1794     EXPECT_EQ(repeatNode->children_.size(), 1);
1795     repeatNode->DoSetActiveChildRange(activeItems, cachedItems, 1);
1796     EXPECT_EQ(repeatNode->children_.size(), 1);
1797 
1798     activeItems.clear();
1799     for (int i = 3; i < largeValue; i++) {
1800         activeItems.insert(i);
1801     }
1802 
1803     EXPECT_EQ(repeatNode->children_.size(), 1);
1804     repeatNode->DoSetActiveChildRange(activeItems, cachedItems, 0);
1805     EXPECT_EQ(repeatNode->children_.size(), 0);
1806 }
1807 
1808 /**
1809  * @tc.name: RepeatNodeCacheTest057
1810  * @tc.desc: Test for GetOrCreateRepeatNode
1811  * @tc.type: FUNC
1812  */
1813 HWTEST_F(RepeatVirtualTestNg, RepeatNodeCacheTest057, TestSize.Level1)
1814 {
1815     RepeatModelNG repeatModel;
1816     repeatModel.StartRender();
1817 
1818     auto repeatNode = AceType::DynamicCast<RepeatNode>(ViewStackProcessor::GetInstance()->Finish());
1819     ASSERT_NE(repeatNode, nullptr);
1820     EXPECT_EQ(repeatNode->GetTag(), V2::JS_REPEAT_ETS_TAG);
1821 
1822     auto nodeId = ElementRegister::GetInstance()->MakeUniqueId();
1823     auto node = repeatNode->GetOrCreateRepeatNode(nodeId);
1824     ASSERT_NE(node, nullptr);
1825 
1826     auto existNode = repeatNode->GetOrCreateRepeatNode(nodeId);
1827     ASSERT_NE(existNode, nullptr);
1828     EXPECT_EQ(existNode->GetId(), nodeId);
1829 }
1830 
1831 /**
1832  * @tc.name: RepeatNodeCacheTest058
1833  * @tc.desc: Test for FinishRepeatRender
1834  * @tc.type: FUNC
1835  */
1836 HWTEST_F(RepeatVirtualTestNg, RepeatNodeCacheTest058, TestSize.Level1)
1837 {
1838     RepeatModelNG repeatModel;
1839     repeatModel.StartRender();
1840 
1841     auto repeatNode = AceType::DynamicCast<RepeatNode>(ViewStackProcessor::GetInstance()->Finish());
1842     ASSERT_NE(repeatNode, nullptr);
1843     EXPECT_EQ(repeatNode->GetTag(), V2::JS_REPEAT_ETS_TAG);
1844 
1845     auto childNode = AceType::MakeRefPtr<FrameNode>(NODE_TAG, -1, AceType::MakeRefPtr<Pattern>());
1846     repeatNode->children_ = { childNode };
1847     EXPECT_GT(repeatNode->children_.size(), 0);
1848 
1849     std::list<std::string> ids2 = FOR_REPEAT_IDS;
1850     repeatNode->SetIds(std::move(ids2));
1851     repeatNode->CreateTempItems();
1852     EXPECT_GT(repeatNode->tempChildrenOfRepeat_.size(), 0);
1853 
1854     std::list<int32_t> arr;
1855     arr.push_back(0);
1856     repeatNode->FinishRepeatRender(arr);
1857     EXPECT_EQ(repeatNode->tempChildren_.size(), 0);
1858     EXPECT_EQ(repeatNode->tempChildrenOfRepeat_.size(), 0);
1859 }
1860 
1861 /**
1862  * @tc.name: RepeatNodeCacheTest059
1863  * @tc.desc: Test for FinishRepeatRender
1864  * @tc.type: FUNC
1865  */
1866 HWTEST_F(RepeatVirtualTestNg, RepeatNodeCacheTest059, TestSize.Level1)
1867 {
1868     RepeatModelNG repeatModel;
1869     repeatModel.StartRender();
1870 
1871     auto repeatNode = AceType::DynamicCast<RepeatNode>(ViewStackProcessor::GetInstance()->Finish());
1872     ASSERT_NE(repeatNode, nullptr);
1873     EXPECT_EQ(repeatNode->GetTag(), V2::JS_REPEAT_ETS_TAG);
1874 
1875     auto node = AceType::MakeRefPtr<FrameNode>(NODE_TAG, -1, AceType::MakeRefPtr<Pattern>());
1876     repeatNode->SetParent(node);
1877     auto childNode = AceType::MakeRefPtr<FrameNode>(NODE_TAG, -1, AceType::MakeRefPtr<Pattern>());
1878     repeatNode->children_ = { childNode };
1879     EXPECT_GT(repeatNode->children_.size(), 0);
1880 
1881     std::list<std::string> ids2 = FOR_REPEAT_IDS;
1882     repeatNode->SetIds(std::move(ids2));
1883     repeatNode->CreateTempItems();
1884     EXPECT_GT(repeatNode->tempChildrenOfRepeat_.size(), 0);
1885 
1886     std::list<int32_t> arr;
1887     arr.push_back(0);
1888     repeatNode->FinishRepeatRender(arr);
1889     EXPECT_EQ(repeatNode->tempChildren_.size(), 0);
1890     EXPECT_EQ(repeatNode->tempChildrenOfRepeat_.size(), 0);
1891 }
1892 
1893 /**
1894  * @tc.name: RepeatNodeCacheTest060
1895  * @tc.desc: Test for MoveChild
1896  * @tc.type: FUNC
1897  */
1898 HWTEST_F(RepeatVirtualTestNg, RepeatNodeCacheTest060, TestSize.Level1)
1899 {
1900     RepeatModelNG repeatModel;
1901     repeatModel.StartRender();
1902     auto repeatNode = AceType::DynamicCast<RepeatNode>(ViewStackProcessor::GetInstance()->Finish());
1903     ASSERT_NE(repeatNode, nullptr);
1904     EXPECT_EQ(repeatNode->GetTag(), V2::JS_REPEAT_ETS_TAG);
1905 
1906     auto node = AceType::MakeRefPtr<FrameNode>(NODE_TAG, -1, AceType::MakeRefPtr<Pattern>());
1907     repeatNode->SetParent(node);
1908     auto childNode = AceType::MakeRefPtr<FrameNode>(NODE_TAG, -1, AceType::MakeRefPtr<Pattern>());
1909     repeatNode->children_ = { childNode };
1910     EXPECT_GT(repeatNode->children_.size(), 0);
1911     EXPECT_EQ(repeatNode->tempChildrenOfRepeat_.size(), 0);
1912 
1913     std::list<std::string> ids2 = FOR_REPEAT_IDS;
1914     repeatNode->SetIds(std::move(ids2));
1915     repeatNode->CreateTempItems();
1916     EXPECT_GT(repeatNode->tempChildrenOfRepeat_.size(), 0);
1917 
1918     repeatNode->MoveChild(0);
1919 }
1920 
1921 /**
1922  * @tc.name: RepeatNodeCacheTest061
1923  * @tc.desc: Test for GetFrameChildByIndex
1924  * @tc.type: FUNC
1925  */
1926 HWTEST_F(RepeatVirtualTestNg, RepeatNodeCacheTest061, TestSize.Level1)
1927 {
__anona0f584000e02(uint32_t from, uint32_t to) 1928     auto onGetTypes4Range = [](uint32_t from, uint32_t to) -> std::list<std::string> {
1929         std::list<std::string> types;
1930         for (uint32_t i = from; i <= to; ++i) {
1931             types.push_back("elmt1");
1932         }
1933         return types;
1934     };
1935     // enable reuse
1936     RefPtr<RepeatVirtualScrollNode> repeatNode = RepeatVirtualScrollNode::GetOrCreateRepeatNode(
1937         NODE_ID, COUNT_3, templateCachedCountMap, onCreateNode, g_onUpdateNode, g_onGetKeys4Range, onGetTypes4Range,
1938         g_onSetActiveRange, true);
1939     ASSERT_NE(repeatNode, nullptr);
1940     repeatNode->GetFrameChildByIndex(0, true, false, true);
1941     repeatNode->GetFrameChildByIndex(1, true, false, true);
1942     repeatNode->DoSetActiveChildRange(0, 0, 0, 0);
1943     auto node = repeatNode->GetFrameChildByIndex(2, true, false, true);
1944     ASSERT_NE(node, nullptr);
1945     EXPECT_EQ(node->GetId(), 1);
1946     // diable reuse
1947     repeatNode = RepeatVirtualScrollNode::GetOrCreateRepeatNode(
1948         NODE_ID + 1, COUNT_3, templateCachedCountMap, onCreateNode, g_onUpdateNode, g_onGetKeys4Range, onGetTypes4Range,
1949         g_onSetActiveRange, false);
1950     ASSERT_NE(repeatNode, nullptr);
1951     repeatNode->GetFrameChildByIndex(0, true, false, true);
1952     repeatNode->GetFrameChildByIndex(1, true, false, true);
1953     repeatNode->DoSetActiveChildRange(0, 0, 0, 0);
1954     node = repeatNode->GetFrameChildByIndex(2, true, false, true);
1955     ASSERT_NE(node, nullptr);
1956     EXPECT_EQ(node->GetId(), 2);
1957 }
1958 } // namespace OHOS::Ace::NG
1959