• 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 #ifndef FOUNDATION_ACE_TEST_UNITTEST_CORE_PATTERN_SCROLL_MOCK_TASK_EXECUTOR_H
17 #define FOUNDATION_ACE_TEST_UNITTEST_CORE_PATTERN_SCROLL_MOCK_TASK_EXECUTOR_H
18 
19 #include "gmock/gmock.h"
20 
21 #include "base/thread/task_executor.h"
22 #include "base/utils/utils.h"
23 
24 namespace OHOS::Ace {
25 class MockScrollTaskExecutor : public TaskExecutor {
26 public:
27     MockScrollTaskExecutor() = default;
MockScrollTaskExecutor(bool delayRun)28     explicit MockScrollTaskExecutor(bool delayRun) : delayRun_(delayRun) {}
29 
30     bool OnPostTask(Task&& task, TaskType type, uint32_t delayTime, const std::string& name,
31         PriorityType priorityType = PriorityType::LOW) const override
32     {
33         CHECK_NULL_RETURN(task, false);
34         if (delayRun_) {
35             return true;
36         }
37         delayTask_ = task;
38         return true;
39     }
40 
RunDelayTask()41     void RunDelayTask()
42     {
43         if (delayTask_) {
44             delayTask_();
45         }
46     }
47 
WillRunOnCurrentThread(TaskType type)48     bool WillRunOnCurrentThread(TaskType type) const override
49     {
50         return true;
51     }
52 
WrapTaskWithTraceId(Task &&,int32_t)53     Task WrapTaskWithTraceId(Task&& /*task*/, int32_t /*id*/) const override
54     {
55         return nullptr;
56     }
57 
AddTaskObserver(Task && callback)58     void AddTaskObserver(Task&& callback) override {}
59 
RemoveTaskObserver()60     void RemoveTaskObserver() override {}
61 
RemoveTask(TaskType type,const std::string & name)62     void RemoveTask(TaskType type, const std::string& name) override {}
63 
64     bool OnPostTaskWithoutTraceId(Task&& task, TaskType type, uint32_t delayTime, const std::string& name,
65         PriorityType priorityType = PriorityType::LOW) const override
66     {
67         CHECK_NULL_RETURN(task, false);
68         if (delayRun_) {
69             return true;
70         }
71         task();
72         return true;
73     }
74 
75 private:
76     bool delayRun_ = false;
77     mutable Task delayTask_;
78 };
79 } // namespace OHOS::Ace
80 #endif // FOUNDATION_ACE_TEST_UNITTEST_CORE_PATTERN_SCROLL_MOCK_TASK_EXECUTOR_H
81