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