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 TestContext final : public IContext { 61 public: 62 TestContext(); 63 ~TestContext() = default; 64 DISALLOW_COPY_AND_MOVE(TestContext); 65 66 IDelegateTasks& GetDelegateTasks() override; 67 IDeviceManager& GetDeviceManager() override; 68 ITimerManager& GetTimerManager() override; 69 IDragManager& GetDragManager() override; 70 IPluginManager& GetPluginManager() override; 71 ISocketSessionManager& GetSocketSessionManager() override; 72 IInputAdapter& GetInput() override; 73 IDSoftbusAdapter& GetDSoftbus() override; 74 75 private: 76 MockDelegateTasks delegateTasks_; 77 DeviceManager devMgr_; 78 TimerManager timerMgr_; 79 DragManager dragMgr_; 80 SocketSessionManager socketSessionMgr_; 81 std::unique_ptr<IInputAdapter> input_ { nullptr }; 82 std::unique_ptr<IPluginManager> pluginMgr_ { nullptr }; 83 std::unique_ptr<IDSoftbusAdapter> dsoftbus_ { nullptr }; 84 }; 85 } // namespace DeviceStatus 86 } // namespace Msdp 87 } // namespace OHOS 88 #endif // TEST_CONTEXT_H