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 int32_t AddMonitor(std::function<void(std::shared_ptr<MMI::PointerEvent>)> pointCallback, 40 std::function<void(std::shared_ptr<MMI::KeyEvent>)> keyCallback, MMI::HandleEventType eventType) override; 41 void RemoveMonitor(int32_t monitorId) override; 42 43 int32_t AddInterceptor(std::function<void(std::shared_ptr<MMI::PointerEvent>)> pointCallback) override; 44 int32_t AddInterceptor(std::function<void(std::shared_ptr<MMI::KeyEvent>)> keyCallback) override; 45 int32_t AddInterceptor(std::function<void(std::shared_ptr<MMI::PointerEvent>)> pointCallback, 46 std::function<void(std::shared_ptr<MMI::KeyEvent>)> keyCallback) override; 47 void RemoveInterceptor(int32_t interceptorId) override; 48 49 int32_t AddFilter(std::function<bool(std::shared_ptr<MMI::PointerEvent>)> callback) override; 50 void RemoveFilter(int32_t filterId) override; 51 52 int32_t SetPointerVisibility(bool visible, int32_t priority = 0) override; 53 int32_t SetPointerLocation(int32_t x, int32_t y, int32_t displayId) override; 54 int32_t EnableInputDevice(bool enable) override; 55 56 void SimulateInputEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent) override; 57 void SimulateInputEvent(std::shared_ptr<MMI::KeyEvent> keyEvent) override; 58 int32_t AddVirtualInputDevice(std::shared_ptr<MMI::InputDevice> device, int32_t &deviceId) override; 59 int32_t RemoveVirtualInputDevice(int32_t deviceId) override; 60 int32_t GetPointerSpeed(int32_t &speed) override; 61 int32_t SetPointerSpeed(int32_t speed) override; 62 int32_t GetTouchPadSpeed(int32_t &speed) override; 63 int32_t SetTouchPadSpeed(int32_t speed) override; 64 bool HasLocalPointerDevice() override; 65 }; 66 67 class MockPluginManager : public IPluginManager { 68 public: 69 MockPluginManager(IContext *context); 70 ICooperate* LoadCooperate() override; 71 void UnloadCooperate() override; 72 IMotionDrag* LoadMotionDrag() override; 73 void UnloadMotionDrag() override; 74 private: 75 std::unique_ptr<IPluginManager> pluginMgr_; 76 }; 77 78 class TestContext final : public IContext { 79 public: 80 TestContext(); 81 ~TestContext() = default; 82 DISALLOW_COPY_AND_MOVE(TestContext); 83 84 IDelegateTasks& GetDelegateTasks() override; 85 IDeviceManager& GetDeviceManager() override; 86 ITimerManager& GetTimerManager() override; 87 IDragManager& GetDragManager() override; 88 IDDMAdapter& GetDDM() override; 89 IPluginManager& GetPluginManager() override; 90 ISocketSessionManager& GetSocketSessionManager() override; 91 IInputAdapter& GetInput() override; 92 IDSoftbusAdapter& GetDSoftbus() override; 93 94 private: 95 MockDelegateTasks delegateTasks_; 96 DeviceManager devMgr_; 97 TimerManager timerMgr_; 98 DragManager dragMgr_; 99 SocketSessionManager socketSessionMgr_; 100 std::unique_ptr<IDDMAdapter> ddm_ { nullptr }; 101 std::unique_ptr<IInputAdapter> input_ { nullptr }; 102 std::unique_ptr<IPluginManager> pluginMgr_ { nullptr }; 103 std::unique_ptr<IDSoftbusAdapter> dsoftbus_ { nullptr }; 104 }; 105 } // namespace DeviceStatus 106 } // namespace Msdp 107 } // namespace OHOS 108 #endif // TEST_CONTEXT_H