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 TEST_CONTEXT_H
17 #define TEST_CONTEXT_H
18 
19 #include "device_manager.h"
20 #include "drag_manager.h"
21 #include "i_context.h"
22 #include "timer_manager.h"
23 
24 #include "socket_session_manager.h"
25 
26 namespace OHOS {
27 namespace Msdp {
28 namespace DeviceStatus {
29 class MockDelegateTasks : public IDelegateTasks {
30 public:
31     int32_t PostSyncTask(DTaskCallback callback) override;
32     int32_t PostAsyncTask(DTaskCallback callback) override;
33 };
34 
35 class MockInputAdapter : public IInputAdapter {
36 public:
37     int32_t AddMonitor(std::function<void(std::shared_ptr<MMI::PointerEvent>)> callback) override;
38     int32_t AddMonitor(std::function<void(std::shared_ptr<MMI::KeyEvent>)> callback) override;
39     void RemoveMonitor(int32_t monitorId) override;
40 
41     int32_t AddInterceptor(std::function<void(std::shared_ptr<MMI::PointerEvent>)> pointerCb) override;
42     int32_t AddInterceptor(std::function<void(std::shared_ptr<MMI::KeyEvent>)> keyCb) override;
43     int32_t AddInterceptor(std::function<void(std::shared_ptr<MMI::PointerEvent>)> pointerCb,
44                            std::function<void(std::shared_ptr<MMI::KeyEvent>)> keyCb) override;
45     void RemoveInterceptor(int32_t interceptorId) override;
46 
47     int32_t AddFilter(std::function<bool(std::shared_ptr<MMI::PointerEvent>)> callback) override;
48     void RemoveFilter(int32_t filterId) override;
49 
50     int32_t SetPointerVisibility(bool visible, int32_t priority = 0) override;
51     int32_t SetPointerLocation(int32_t x, int32_t y) override;
52     int32_t EnableInputDevice(bool enable) override;
53 
54     void SimulateInputEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent) override;
55     void SimulateInputEvent(std::shared_ptr<MMI::KeyEvent> keyEvent) override;
56     int32_t AddVirtualInputDevice(std::shared_ptr<MMI::InputDevice> device, int32_t &deviceId) override;
57     int32_t RemoveVirtualInputDevice(int32_t deviceId) override;
58 };
59 
60 class MockPluginManager : public IPluginManager {
61 public:
62     MockPluginManager(IContext *context);
63     ICooperate* LoadCooperate() override;
64     void UnloadCooperate() override;
65     IMotionDrag* LoadMotionDrag() override;
66     void UnloadMotionDrag() override;
67 private:
68     std::unique_ptr<IPluginManager> pluginMgr_;
69 };
70 
71 class TestContext final : public IContext {
72 public:
73     TestContext();
74     ~TestContext() = default;
75     DISALLOW_COPY_AND_MOVE(TestContext);
76 
77     IDelegateTasks& GetDelegateTasks() override;
78     IDeviceManager& GetDeviceManager() override;
79     ITimerManager& GetTimerManager() override;
80     IDragManager& GetDragManager() override;
81     IPluginManager& GetPluginManager() override;
82     ISocketSessionManager& GetSocketSessionManager() override;
83     IInputAdapter& GetInput() override;
84     IDSoftbusAdapter& GetDSoftbus() override;
85 
86 private:
87     MockDelegateTasks delegateTasks_;
88     DeviceManager devMgr_;
89     TimerManager timerMgr_;
90     DragManager dragMgr_;
91     SocketSessionManager socketSessionMgr_;
92     std::unique_ptr<IInputAdapter> input_ { nullptr };
93     std::unique_ptr<IPluginManager> pluginMgr_ { nullptr };
94     std::unique_ptr<IDSoftbusAdapter> dsoftbus_ { nullptr };
95 };
96 } // namespace DeviceStatus
97 } // namespace Msdp
98 } // namespace OHOS
99 #endif // TEST_CONTEXT_H