• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "ddm_adapter.h"
19 #include "dsoftbus_adapter.h"
20 #include "fi_log.h"
21 #include "plugin_manager.h"
22 
23 #undef LOG_TAG
24 #define LOG_TAG "IntentionServiceTest"
25 
26 namespace OHOS {
27 namespace Msdp {
28 namespace DeviceStatus {
29 
PostSyncTask(DTaskCallback callback)30 int32_t MockDelegateTasks::PostSyncTask(DTaskCallback callback)
31 {
32     return callback();
33 }
34 
PostAsyncTask(DTaskCallback callback)35 int32_t MockDelegateTasks::PostAsyncTask(DTaskCallback callback)
36 {
37     return callback();
38 }
39 
AddMonitor(std::function<void (std::shared_ptr<MMI::PointerEvent>)> callback)40 int32_t MockInputAdapter::AddMonitor(std::function<void(std::shared_ptr<MMI::PointerEvent>)> callback)
41 {
42     return RET_OK;
43 }
44 
AddMonitor(std::function<void (std::shared_ptr<MMI::KeyEvent>)> callback)45 int32_t MockInputAdapter::AddMonitor(std::function<void(std::shared_ptr<MMI::KeyEvent>)> callback)
46 {
47     return RET_OK;
48 }
49 
AddMonitor(std::function<void (std::shared_ptr<MMI::PointerEvent>)> pointerCallback,std::function<void (std::shared_ptr<MMI::KeyEvent>)> keyCallback,MMI::HandleEventType eventType)50 int32_t MockInputAdapter::AddMonitor(std::function<void(std::shared_ptr<MMI::PointerEvent>)> pointerCallback,
51     std::function<void(std::shared_ptr<MMI::KeyEvent>)> keyCallback, MMI::HandleEventType eventType)
52 {
53     return RET_OK;
54 }
55 
RemoveMonitor(int32_t monitorId)56 void MockInputAdapter::RemoveMonitor(int32_t monitorId)
57 {}
58 
AddPreMonitor(std::function<void (std::shared_ptr<MMI::PointerEvent>)> pointerCallback,std::function<void (std::shared_ptr<MMI::KeyEvent>)> keyCallback,MMI::HandleEventType eventType,std::vector<int32_t> keys)59 int32_t MockInputAdapter::AddPreMonitor(std::function<void(std::shared_ptr<MMI::PointerEvent>)> pointerCallback,
60     std::function<void(std::shared_ptr<MMI::KeyEvent>)> keyCallback,
61     MMI::HandleEventType eventType, std::vector<int32_t> keys)
62 {
63     return RET_OK;
64 }
65 
RemovePreMonitor(int32_t monitorId)66 void MockInputAdapter::RemovePreMonitor(int32_t monitorId)
67 {}
68 
AddInterceptor(std::function<void (std::shared_ptr<MMI::PointerEvent>)> pointCallback)69 int32_t MockInputAdapter::AddInterceptor(std::function<void(std::shared_ptr<MMI::PointerEvent>)> pointCallback)
70 {
71     return RET_OK;
72 }
73 
AddInterceptor(std::function<void (std::shared_ptr<MMI::KeyEvent>)> keyCallback)74 int32_t MockInputAdapter::AddInterceptor(std::function<void(std::shared_ptr<MMI::KeyEvent>)> keyCallback)
75 {
76     return RET_OK;
77 }
78 
AddInterceptor(std::function<void (std::shared_ptr<MMI::PointerEvent>)> pointCallback,std::function<void (std::shared_ptr<MMI::KeyEvent>)> keyCallback)79 int32_t MockInputAdapter::AddInterceptor(std::function<void(std::shared_ptr<MMI::PointerEvent>)> pointCallback,
80     std::function<void(std::shared_ptr<MMI::KeyEvent>)> keyCallback)
81 {
82     return RET_OK;
83 }
84 
RemoveInterceptor(int32_t interceptorId)85 void MockInputAdapter::RemoveInterceptor(int32_t interceptorId)
86 {}
87 
AddFilter(std::function<bool (std::shared_ptr<MMI::PointerEvent>)> callback)88 int32_t MockInputAdapter::AddFilter(std::function<bool(std::shared_ptr<MMI::PointerEvent>)> callback)
89 {
90     return RET_OK;
91 }
92 
RemoveFilter(int32_t filterId)93 void MockInputAdapter::RemoveFilter(int32_t filterId)
94 {}
95 
SetPointerVisibility(bool visible,int32_t priority)96 int32_t MockInputAdapter::SetPointerVisibility(bool visible, int32_t priority)
97 {
98     return RET_OK;
99 }
100 
SetPointerLocation(int32_t x,int32_t y,int32_t displayId)101 int32_t MockInputAdapter::SetPointerLocation(int32_t x, int32_t y, int32_t displayId)
102 {
103     return RET_OK;
104 }
105 
EnableInputDevice(bool enable)106 int32_t MockInputAdapter::EnableInputDevice(bool enable)
107 {
108     return RET_OK;
109 }
110 
SimulateInputEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent)111 void MockInputAdapter::SimulateInputEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent)
112 {}
113 
SimulateInputEvent(std::shared_ptr<MMI::KeyEvent> keyEvent)114 void MockInputAdapter::SimulateInputEvent(std::shared_ptr<MMI::KeyEvent> keyEvent)
115 {}
116 
AddVirtualInputDevice(std::shared_ptr<MMI::InputDevice> device,int32_t & deviceId)117 int32_t MockInputAdapter::AddVirtualInputDevice(std::shared_ptr<MMI::InputDevice> device, int32_t &deviceId)
118 {
119     return RET_OK;
120 }
121 
RemoveVirtualInputDevice(int32_t deviceId)122 int32_t MockInputAdapter::RemoveVirtualInputDevice(int32_t deviceId)
123 {
124     return RET_OK;
125 }
126 
GetPointerSpeed(int32_t & speed)127 int32_t MockInputAdapter::GetPointerSpeed(int32_t &speed)
128 {
129     return RET_OK;
130 }
131 
SetPointerSpeed(int32_t speed)132 int32_t MockInputAdapter::SetPointerSpeed(int32_t speed)
133 {
134     return RET_OK;
135 }
136 
GetTouchPadSpeed(int32_t & speed)137 int32_t MockInputAdapter::GetTouchPadSpeed(int32_t &speed)
138 {
139     return RET_OK;
140 }
141 
SetTouchPadSpeed(int32_t speed)142 int32_t MockInputAdapter::SetTouchPadSpeed(int32_t speed)
143 {
144     return RET_OK;
145 }
146 
HasLocalPointerDevice()147 bool MockInputAdapter::HasLocalPointerDevice()
148 {
149     return true;
150 }
151 
RegisterDevListener(MMIDevListener devAddedCallback,MMIDevListener devRemovedCallback)152 int32_t MockInputAdapter::RegisterDevListener(MMIDevListener devAddedCallback, MMIDevListener devRemovedCallback)
153 {
154     return RET_OK;
155 }
156 
UnregisterDevListener()157 int32_t MockInputAdapter::UnregisterDevListener()
158 {
159     return RET_OK;
160 }
161 
MockPluginManager(IContext * context)162 MockPluginManager::MockPluginManager(IContext *context)
163 {
164     pluginMgr_ = std::make_unique<PluginManager>(context);
165 }
166 
LoadCooperate()167 ICooperate* MockPluginManager::LoadCooperate()
168 {
169     return pluginMgr_->LoadCooperate();
170 }
171 
UnloadCooperate()172 void MockPluginManager::UnloadCooperate()
173 {
174     pluginMgr_->UnloadCooperate();
175 }
176 
LoadMotionDrag()177 IMotionDrag* MockPluginManager::LoadMotionDrag()
178 {
179     return nullptr;
180 }
181 
UnloadMotionDrag()182 void MockPluginManager::UnloadMotionDrag()
183 {}
184 
TestContext()185 TestContext::TestContext()
186 {
187     ddm_ = std::make_unique<DDMAdapter>();
188     input_ = std::make_unique<MockInputAdapter>();
189     pluginMgr_ = std::make_unique<MockPluginManager>(this);
190     dsoftbus_ = std::make_unique<DSoftbusAdapter>();
191 }
192 
GetDelegateTasks()193 IDelegateTasks& TestContext::GetDelegateTasks()
194 {
195     return delegateTasks_;
196 }
197 
GetDeviceManager()198 IDeviceManager& TestContext::GetDeviceManager()
199 {
200     return devMgr_;
201 }
202 
GetTimerManager()203 ITimerManager& TestContext::GetTimerManager()
204 {
205     return timerMgr_;
206 }
207 
GetDragManager()208 IDragManager& TestContext::GetDragManager()
209 {
210     return dragMgr_;
211 }
212 
GetSocketSessionManager()213 ISocketSessionManager& TestContext::GetSocketSessionManager()
214 {
215     return socketSessionMgr_;
216 }
217 
GetDDM()218 IDDMAdapter& TestContext::GetDDM()
219 {
220     return *ddm_;
221 }
222 
GetPluginManager()223 IPluginManager& TestContext::GetPluginManager()
224 {
225     return *pluginMgr_;
226 }
227 
GetInput()228 IInputAdapter& TestContext::GetInput()
229 {
230     return *input_;
231 }
232 
GetDSoftbus()233 IDSoftbusAdapter& TestContext::GetDSoftbus()
234 {
235     return *dsoftbus_;
236 }
237 } // namespace DeviceStatus
238 } // namespace Msdp
239 } // namespace OHOS
240