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 #include "test_context.h"
17
18 #include "dsoftbus_adapter.h"
19 #include "fi_log.h"
20 #include "plugin_manager.h"
21
22 #undef LOG_TAG
23 #define LOG_TAG "IntentionServiceTest"
24
25 namespace OHOS {
26 namespace Msdp {
27 namespace DeviceStatus {
28
PostSyncTask(DTaskCallback callback)29 int32_t MockDelegateTasks::PostSyncTask(DTaskCallback callback)
30 {
31 return callback();
32 }
33
PostAsyncTask(DTaskCallback callback)34 int32_t MockDelegateTasks::PostAsyncTask(DTaskCallback callback)
35 {
36 return callback();
37 }
38
AddMonitor(std::function<void (std::shared_ptr<MMI::PointerEvent>)> callback)39 int32_t MockInputAdapter::AddMonitor(std::function<void(std::shared_ptr<MMI::PointerEvent>)> callback)
40 {
41 return RET_OK;
42 }
43
AddMonitor(std::function<void (std::shared_ptr<MMI::KeyEvent>)> callback)44 int32_t MockInputAdapter::AddMonitor(std::function<void(std::shared_ptr<MMI::KeyEvent>)> callback)
45 {
46 return RET_OK;
47 }
48
RemoveMonitor(int32_t monitorId)49 void MockInputAdapter::RemoveMonitor(int32_t monitorId)
50 {}
51
AddInterceptor(std::function<void (std::shared_ptr<MMI::PointerEvent>)> pointerCb)52 int32_t MockInputAdapter::AddInterceptor(std::function<void(std::shared_ptr<MMI::PointerEvent>)> pointerCb)
53 {
54 return RET_OK;
55 }
56
AddInterceptor(std::function<void (std::shared_ptr<MMI::KeyEvent>)> keyCb)57 int32_t MockInputAdapter::AddInterceptor(std::function<void(std::shared_ptr<MMI::KeyEvent>)> keyCb)
58 {
59 return RET_OK;
60 }
61
AddInterceptor(std::function<void (std::shared_ptr<MMI::PointerEvent>)> pointerCb,std::function<void (std::shared_ptr<MMI::KeyEvent>)> keyCb)62 int32_t MockInputAdapter::AddInterceptor(std::function<void(std::shared_ptr<MMI::PointerEvent>)> pointerCb,
63 std::function<void(std::shared_ptr<MMI::KeyEvent>)> keyCb)
64 {
65 return RET_OK;
66 }
67
RemoveInterceptor(int32_t interceptorId)68 void MockInputAdapter::RemoveInterceptor(int32_t interceptorId)
69 {}
70
AddFilter(std::function<bool (std::shared_ptr<MMI::PointerEvent>)> callback)71 int32_t MockInputAdapter::AddFilter(std::function<bool(std::shared_ptr<MMI::PointerEvent>)> callback)
72 {
73 return RET_OK;
74 }
75
RemoveFilter(int32_t filterId)76 void MockInputAdapter::RemoveFilter(int32_t filterId)
77 {}
78
SetPointerVisibility(bool visible,int32_t priority)79 int32_t MockInputAdapter::SetPointerVisibility(bool visible, int32_t priority)
80 {
81 return RET_OK;
82 }
83
SetPointerLocation(int32_t x,int32_t y)84 int32_t MockInputAdapter::SetPointerLocation(int32_t x, int32_t y)
85 {
86 return RET_OK;
87 }
88
EnableInputDevice(bool enable)89 int32_t MockInputAdapter::EnableInputDevice(bool enable)
90 {
91 return RET_OK;
92 }
93
SimulateInputEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent)94 void MockInputAdapter::SimulateInputEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent)
95 {}
96
SimulateInputEvent(std::shared_ptr<MMI::KeyEvent> keyEvent)97 void MockInputAdapter::SimulateInputEvent(std::shared_ptr<MMI::KeyEvent> keyEvent)
98 {}
99
AddVirtualInputDevice(std::shared_ptr<MMI::InputDevice> device,int32_t & deviceId)100 int32_t MockInputAdapter::AddVirtualInputDevice(std::shared_ptr<MMI::InputDevice> device, int32_t &deviceId)
101 {
102 return RET_OK;
103 }
104
RemoveVirtualInputDevice(int32_t deviceId)105 int32_t MockInputAdapter::RemoveVirtualInputDevice(int32_t deviceId)
106 {
107 return RET_OK;
108 }
109
MockPluginManager(IContext * context)110 MockPluginManager::MockPluginManager(IContext *context)
111 {
112 pluginMgr_ = std::make_unique<PluginManager>(context);
113 }
114
LoadCooperate()115 ICooperate* MockPluginManager::LoadCooperate()
116 {
117 return pluginMgr_->LoadCooperate();
118 }
119
UnloadCooperate()120 void MockPluginManager::UnloadCooperate()
121 {
122 pluginMgr_->UnloadCooperate();
123 }
124
LoadMotionDrag()125 IMotionDrag* MockPluginManager::LoadMotionDrag()
126 {
127 return nullptr;
128 }
129
UnloadMotionDrag()130 void MockPluginManager::UnloadMotionDrag()
131 {}
132
TestContext()133 TestContext::TestContext()
134 {
135 input_ = std::make_unique<MockInputAdapter>();
136 pluginMgr_ = std::make_unique<MockPluginManager>(this);
137 dsoftbus_ = std::make_unique<DSoftbusAdapter>();
138 }
139
GetDelegateTasks()140 IDelegateTasks& TestContext::GetDelegateTasks()
141 {
142 return delegateTasks_;
143 }
144
GetDeviceManager()145 IDeviceManager& TestContext::GetDeviceManager()
146 {
147 return devMgr_;
148 }
149
GetTimerManager()150 ITimerManager& TestContext::GetTimerManager()
151 {
152 return timerMgr_;
153 }
154
GetDragManager()155 IDragManager& TestContext::GetDragManager()
156 {
157 return dragMgr_;
158 }
159
GetSocketSessionManager()160 ISocketSessionManager& TestContext::GetSocketSessionManager()
161 {
162 return socketSessionMgr_;
163 }
164
GetPluginManager()165 IPluginManager& TestContext::GetPluginManager()
166 {
167 return *pluginMgr_;
168 }
169
GetInput()170 IInputAdapter& TestContext::GetInput()
171 {
172 return *input_;
173 }
174
GetDSoftbus()175 IDSoftbusAdapter& TestContext::GetDSoftbus()
176 {
177 return *dsoftbus_;
178 }
179 } // namespace DeviceStatus
180 } // namespace Msdp
181 } // namespace OHOS
182