diff --git a/test/unittest/core/pattern/scroll/mock_task_executor.h b/test/unittest/core/pattern/scroll/mock_task_executor.h deleted file mode 100644 index 08727d1d3c50e78067a3dff9b851e77b852a250e..0000000000000000000000000000000000000000 --- a/test/unittest/core/pattern/scroll/mock_task_executor.h +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FOUNDATION_ACE_TEST_UNITTEST_CORE_PATTERN_SCROLL_MOCK_TASK_EXECUTOR_H -#define FOUNDATION_ACE_TEST_UNITTEST_CORE_PATTERN_SCROLL_MOCK_TASK_EXECUTOR_H - -#include "gmock/gmock.h" - -#include "base/thread/task_executor.h" -#include "base/utils/utils.h" - -namespace OHOS::Ace { -class MockTaskExecutor : public TaskExecutor { -public: - MockTaskExecutor() = default; - explicit MockTaskExecutor(bool delayRun) : delayRun_(delayRun) {} - - bool OnPostTask(Task&& task, TaskType type, uint32_t delayTime, const std::string& name, - PriorityType priorityType = PriorityType::LOW) const override - { - CHECK_NULL_RETURN(task, false); - if (delayRun_) { - return true; - } - delayTask_ = task; - return true; - } - - void RunDelayTask() - { - if (delayTask_) { - delayTask_(); - } - } - - bool WillRunOnCurrentThread(TaskType type) const override - { - return true; - } - - Task WrapTaskWithTraceId(Task&& /*task*/, int32_t /*id*/) const override - { - return nullptr; - } - - void AddTaskObserver(Task&& callback) override {} - - void RemoveTaskObserver() override {} - - void RemoveTask(TaskType type, const std::string& name) override {} - - bool OnPostTaskWithoutTraceId(Task&& task, TaskType type, uint32_t delayTime, const std::string& name, - PriorityType priorityType = PriorityType::LOW) const override - { - CHECK_NULL_RETURN(task, false); - if (delayRun_) { - return true; - } - task(); - return true; - } - -private: - bool delayRun_ = false; - mutable Task delayTask_; -}; -} // namespace OHOS::Ace -#endif // FOUNDATION_ACE_TEST_UNITTEST_CORE_PATTERN_SCROLL_MOCK_TASK_EXECUTOR_H diff --git a/test/unittest/core/pattern/scroll/scroll_effect_test_ng.cpp b/test/unittest/core/pattern/scroll/scroll_effect_test_ng.cpp index 13e17652f0695db069ac11372f319bee7bae3180..53c7cc5f16474076392a146bc06ce01e5b46388c 100644 --- a/test/unittest/core/pattern/scroll/scroll_effect_test_ng.cpp +++ b/test/unittest/core/pattern/scroll/scroll_effect_test_ng.cpp @@ -13,7 +13,6 @@ * limitations under the License. */ -#include "mock_task_executor.h" #include "scroll_test_ng.h" #include "test/mock/core/pipeline/mock_pipeline_context.h" #include "test/mock/core/render/mock_render_context.h" diff --git a/test/unittest/core/pattern/scroll/scroll_inner_event_test_ng.cpp b/test/unittest/core/pattern/scroll/scroll_inner_event_test_ng.cpp index e50da550ce5f317d8e50e0fc1813a40036ef0c97..102f9db7fff2209cbc0533a97566fae6a09a4a81 100644 --- a/test/unittest/core/pattern/scroll/scroll_inner_event_test_ng.cpp +++ b/test/unittest/core/pattern/scroll/scroll_inner_event_test_ng.cpp @@ -13,7 +13,6 @@ * limitations under the License. */ -#include "mock_task_executor.h" #include "scroll_test_ng.h" #include "test/mock/core/animation/mock_animation_manager.h" #include "test/mock/core/common/mock_container.h" diff --git a/test/unittest/core/pattern/scroll/scroll_inner_layout_test_ng.cpp b/test/unittest/core/pattern/scroll/scroll_inner_layout_test_ng.cpp index dfbf2190cdafa1d74f9c9c55c0fdd042b04454b3..ae4ee755c45aaf0b38c8038506487ed38f8f7751 100644 --- a/test/unittest/core/pattern/scroll/scroll_inner_layout_test_ng.cpp +++ b/test/unittest/core/pattern/scroll/scroll_inner_layout_test_ng.cpp @@ -13,7 +13,6 @@ * limitations under the License. */ -#include "mock_task_executor.h" #include "scroll_test_ng.h" #include "test/mock/core/animation/mock_animation_manager.h" #include "test/mock/core/pipeline/mock_pipeline_context.h" diff --git a/test/unittest/core/pattern/scroll/scroll_test_ng.cpp b/test/unittest/core/pattern/scroll/scroll_test_ng.cpp index 0ed26800c7a97401be337a3a6ab0231ea7b03c09..4041462bd8b49ebe74421b69ed09e82e18fc6ba0 100644 --- a/test/unittest/core/pattern/scroll/scroll_test_ng.cpp +++ b/test/unittest/core/pattern/scroll/scroll_test_ng.cpp @@ -15,7 +15,6 @@ #include "scroll_test_ng.h" -#include "mock_task_executor.h" #include "test/mock/core/common/mock_container.h" #include "test/mock/core/common/mock_theme_manager.h" #include "test/mock/core/pipeline/mock_pipeline_context.h" diff --git a/test/unittest/core/pattern/scroll/scroll_test_ng.h b/test/unittest/core/pattern/scroll/scroll_test_ng.h index bdd539cdbdd33f8e4d8190219ac6eb6e5685b938..c1b9ced9a6548f354fcd860cac99aa3f878e72ad 100644 --- a/test/unittest/core/pattern/scroll/scroll_test_ng.h +++ b/test/unittest/core/pattern/scroll/scroll_test_ng.h @@ -24,6 +24,9 @@ #include "core/components_ng/pattern/scroll/scroll_model_ng.h" #include "core/components_ng/pattern/scroll/scroll_pattern.h" +#include "gmock/gmock.h" +#include "base/thread/task_executor.h" +#include "base/utils/utils.h" namespace OHOS::Ace::NG { constexpr float DEFAULT_ACTIVE_WIDTH = 8.0f; @@ -36,6 +39,61 @@ constexpr float SCROLL_PAGING_SPEED_THRESHOLD = 1200.0f; constexpr float BAR_WIDTH = 10.f; constexpr char SCROLL_BAR_COLOR[] = "#66182431"; +class MockTaskExecutor : public TaskExecutor { +public: + MockTaskExecutor() = default; + explicit MockTaskExecutor(bool delayRun) : delayRun_(delayRun) {} + + bool OnPostTask(Task&& task, TaskType type, uint32_t delayTime, const std::string& name, + PriorityType priorityType = PriorityType::LOW) const override + { + CHECK_NULL_RETURN(task, false); + if (delayRun_) { + return true; + } + delayTask_ = task; + return true; + } + + void RunDelayTask() + { + if (delayTask_) { + delayTask_(); + } + } + + bool WillRunOnCurrentThread(TaskType type) const override + { + return true; + } + + Task WrapTaskWithTraceId(Task&& /*task*/, int32_t /*id*/) const override + { + return nullptr; + } + + void AddTaskObserver(Task&& callback) override {} + + void RemoveTaskObserver() override {} + + void RemoveTask(TaskType type, const std::string& name) override {} + + bool OnPostTaskWithoutTraceId(Task&& task, TaskType type, uint32_t delayTime, const std::string& name, + PriorityType priorityType = PriorityType::LOW) const override + { + CHECK_NULL_RETURN(task, false); + if (delayRun_) { + return true; + } + task(); + return true; + } + +private: + bool delayRun_ = false; + mutable Task delayTask_; +}; + class ScrollTestNg : public ScrollableUtilsTestNG { public: static void SetUpTestSuite(); diff --git a/test/unittest/core/pipeline/pipeline_context_test_ng_new.cpp b/test/unittest/core/pipeline/pipeline_context_test_ng_new.cpp index 0a5a9a69b13eec2c39f92aed06a6b38ad92c4e49..3fcd9797c0ed13612c83b4e50998e239359683b2 100644 --- a/test/unittest/core/pipeline/pipeline_context_test_ng_new.cpp +++ b/test/unittest/core/pipeline/pipeline_context_test_ng_new.cpp @@ -23,7 +23,7 @@ #include "core/components_ng/pattern/navigation/navigation_pattern.h" #include "core/components_ng/pattern/navrouter/navdestination_group_node.h" #include "test/mock/core/common/mock_container.h" -#include "test/unittest/core/pattern/scroll/mock_task_executor.h" +#include "test/mock/base/mock_task_executor.h" using namespace testing; using namespace testing::ext;