• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_TEST_MOCK_SYNTAX_MOCK_LAZY_FOR_EACH_BUILDER_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_TEST_MOCK_SYNTAX_MOCK_LAZY_FOR_EACH_BUILDER_H
18 
19 #include "base/memory/ace_type.h"
20 #define private public
21 #include "mock_lazy_for_each_actuator.h"
22 
23 #include "core/components_ng/syntax/lazy_for_each_builder.h"
24 #include "core/pipeline_ng/ui_task_scheduler.h"
25 
26 namespace OHOS::Ace::Framework {
27 class MockLazyForEachBuilder : public NG::LazyForEachBuilder, public MockLazyForEachActuator {
28     DECLARE_ACE_TYPE(MockLazyForEachBuilder, NG::LazyForEachBuilder, MockLazyForEachActuator);
29 
30 public:
31     explicit MockLazyForEachBuilder(bool deleteExpiringItemImmediately = false)
deleteExpiringItemImmediately_(deleteExpiringItemImmediately)32         : deleteExpiringItemImmediately_(deleteExpiringItemImmediately) {}
ReleaseChildGroupById(const std::string & id)33     void ReleaseChildGroupById(const std::string& id) override {}
RegisterDataChangeListener(const RefPtr<V2::DataChangeListener> & listener)34     void RegisterDataChangeListener(const RefPtr<V2::DataChangeListener>& listener) override {}
UnregisterDataChangeListener(V2::DataChangeListener * listener)35     void UnregisterDataChangeListener(V2::DataChangeListener* listener) override {}
36 
37 protected:
OnGetTotalCount()38     int32_t OnGetTotalCount() override
39     {
40         return static_cast<int32_t>(cachedItems_.size());
41     }
DeleteExpiringItemImmediately()42     bool DeleteExpiringItemImmediately() override
43     {
44         return deleteExpiringItemImmediately_;
45     }
OnGetChildByIndex(int32_t index,std::unordered_map<std::string,NG::LazyForEachCacheChild> & cachedItems)46     std::pair<std::string, RefPtr<NG::UINode>> OnGetChildByIndex(
47         int32_t index, std::unordered_map<std::string, NG::LazyForEachCacheChild>& cachedItems) override
48     {
49         return { std::to_string(index),
50             AceType::MakeRefPtr<NG::FrameNode>(V2::TEXT_ETS_TAG, -1, AceType::MakeRefPtr<NG::Pattern>()) };
51     }
OnGetChildByIndexNew(int32_t index,std::map<int32_t,NG::LazyForEachChild> & cachedItems,std::unordered_map<std::string,NG::LazyForEachCacheChild> & expiringItems)52     std::pair<std::string, RefPtr<NG::UINode>> OnGetChildByIndexNew(int32_t index,
53         std::map<int32_t, NG::LazyForEachChild>& cachedItems,
54         std::unordered_map<std::string, NG::LazyForEachCacheChild>& expiringItems) override
55     {
56         return { std::to_string(index),
57             AceType::MakeRefPtr<NG::FrameNode>(V2::TEXT_ETS_TAG, -1, AceType::MakeRefPtr<NG::Pattern>()) };
58     }
OnExpandChildrenOnInitialInNG()59     void OnExpandChildrenOnInitialInNG() override {}
60     void NotifyDataChanged(size_t index, const RefPtr<NG::UINode>& lazyForEachNode, bool isRebuild = true) override {};
NotifyDataDeleted(const RefPtr<NG::UINode> & lazyForEachNode,size_t index,bool removeIds)61     void NotifyDataDeleted(const RefPtr<NG::UINode>& lazyForEachNode, size_t index, bool removeIds) override {};
NotifyDataAdded(size_t index)62     void NotifyDataAdded(size_t index) override {};
KeepRemovedItemInCache(NG::LazyForEachChild node,std::unordered_map<std::string,NG::LazyForEachCacheChild> & cachedItems)63     void KeepRemovedItemInCache(NG::LazyForEachChild node,
64         std::unordered_map<std::string, NG::LazyForEachCacheChild>& cachedItems) override {};
65 private:
66     bool deleteExpiringItemImmediately_;
67 };
68 } // namespace OHOS::Ace::Framework
69 
70 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_TEST_MOCK_SYNTAX_MOCK_LAZY_FOR_EACH_BUILDER_H
71