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: ReleaseChildGroupById(const std::string & id)31 void ReleaseChildGroupById(const std::string& id) override {} RegisterDataChangeListener(const RefPtr<V2::DataChangeListener> & listener)32 void RegisterDataChangeListener(const RefPtr<V2::DataChangeListener>& listener) override {} UnregisterDataChangeListener(V2::DataChangeListener * listener)33 void UnregisterDataChangeListener(V2::DataChangeListener* listener) override {} 34 35 protected: OnGetTotalCount()36 int32_t OnGetTotalCount() override 37 { 38 return static_cast<int32_t>(cachedItems_.size()); 39 } DeleteExpiringItemImmediately()40 bool DeleteExpiringItemImmediately() override 41 { 42 return false; 43 } OnGetChildByIndex(int32_t index,std::unordered_map<std::string,NG::LazyForEachCacheChild> & cachedItems)44 std::pair<std::string, RefPtr<NG::UINode>> OnGetChildByIndex( 45 int32_t index, std::unordered_map<std::string, NG::LazyForEachCacheChild>& cachedItems) override 46 { 47 return { std::to_string(index), 48 AceType::MakeRefPtr<NG::FrameNode>(V2::TEXT_ETS_TAG, -1, AceType::MakeRefPtr<NG::Pattern>()) }; 49 } OnGetChildByIndexNew(int32_t index,std::map<int32_t,NG::LazyForEachChild> & cachedItems,std::unordered_map<std::string,NG::LazyForEachCacheChild> & expiringItems)50 std::pair<std::string, RefPtr<NG::UINode>> OnGetChildByIndexNew(int32_t index, 51 std::map<int32_t, NG::LazyForEachChild>& cachedItems, 52 std::unordered_map<std::string, NG::LazyForEachCacheChild>& expiringItems) override 53 { 54 return { std::to_string(index), 55 AceType::MakeRefPtr<NG::FrameNode>(V2::TEXT_ETS_TAG, -1, AceType::MakeRefPtr<NG::Pattern>()) }; 56 } OnExpandChildrenOnInitialInNG()57 void OnExpandChildrenOnInitialInNG() override {} 58 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)59 void NotifyDataDeleted(const RefPtr<NG::UINode>& lazyForEachNode, size_t index, bool removeIds) override {}; NotifyDataAdded(size_t index)60 void NotifyDataAdded(size_t index) override {}; KeepRemovedItemInCache(NG::LazyForEachChild node,std::unordered_map<std::string,NG::LazyForEachCacheChild> & cachedItems)61 void KeepRemovedItemInCache(NG::LazyForEachChild node, 62 std::unordered_map<std::string, NG::LazyForEachCacheChild>& cachedItems) override {}; 63 }; 64 } // namespace OHOS::Ace::Framework 65 66 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_TEST_MOCK_SYNTAX_MOCK_LAZY_FOR_EACH_BUILDER_H 67