• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 #ifndef FOUNDATION_ACE_TEST_UNITTEST_CORE_SYNTAX_REPEAT_VIRTUAL_2_TEST_NG_H
17 #define FOUNDATION_ACE_TEST_UNITTEST_CORE_SYNTAX_REPEAT_VIRTUAL_2_TEST_NG_H
18 
19 #include <optional>
20 #include <utility>
21 
22 #include "gtest/gtest.h"
23 
24 #include "base/memory/ace_type.h"
25 #include "base/memory/referenced.h"
26 
27 #define private public
28 #define protected public
29 #include "test/mock/core/pipeline/mock_pipeline_context.h"
30 
31 #include "core/components_ng/base/frame_node.h"
32 #include "core/components_ng/base/view_stack_processor.h"
33 #include "core/components_ng/syntax/repeat_virtual_scroll_2_model_ng.h"
34 #include "core/components_ng/syntax/repeat_virtual_scroll_2_node.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 #undef private
39 #undef protected
40 
41 namespace OHOS::Ace::NG {
42 class RepeatVirtual2TestNg : public testing::Test {
43 public:
SetUp()44     void SetUp() override
45     {
46         MockPipelineContext::SetUp();
47     }
48 
TearDown()49     void TearDown() override
50     {
51         MockPipelineContext::TearDown();
52     }
53 
54     RefPtr<FrameNode> CreateNode(const std::string& tag);
55 
56     RefPtr<RepeatVirtualScroll2Node> CreateRepeatVirtualNode(uint32_t totalCount);
57 
58     // create ListItemNode with 2 Text Node inside
59     RefPtr<FrameNode> CreateListItemNode();
60 
GetElmtId()61     ElementIdType GetElmtId()
62     {
63         elmtId_++;
64         return elmtId_;
65     }
66 
67     ElementIdType elmtId_ = 10000;
68 
69     /**
70      * Map: Repeat node index -> L1 cache repeat node rid
71      */
72     std::map<IndexType, RIDType> l1Rid4Index_;
73     /**
74      * Function needed by RepeatVirtualScrollCaches constructor is special test case
75      */
76     std::function<std::pair<RIDType, uint32_t>(IndexType)> onGetRid4Index_;
77     std::function<void(IndexType, IndexType)> onRecycleItems_;
78     std::function<void(int32_t, int32_t, int32_t, int32_t, bool, bool)> onActiveRange_;
79     std::function<void(IndexType, IndexType)> onMoveFromTo_;
80     std::function<void()> onPurge_;
81 };
82 } // namespace OHOS::Ace::NG
83 #endif // FOUNDATION_ACE_TEST_UNITTEST_CORE_SYNTAX_REPEAT_VIRTUAL_2_TEST_NG_H