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
RemoveMonitor(int32_t monitorId)50 void MockInputAdapter::RemoveMonitor(int32_t monitorId)
51 {}
52
AddInterceptor(std::function<void(std::shared_ptr<MMI::PointerEvent>)> pointerCb)53 int32_t MockInputAdapter::AddInterceptor(std::function<void(std::shared_ptr<MMI::PointerEvent>)> pointerCb)
54 {
55 return RET_OK;
56 }
57
AddInterceptor(std::function<void(std::shared_ptr<MMI::KeyEvent>)> keyCb)58 int32_t MockInputAdapter::AddInterceptor(std::function<void(std::shared_ptr<MMI::KeyEvent>)> keyCb)
59 {
60 return RET_OK;
61 }
62
AddInterceptor(std::function<void(std::shared_ptr<MMI::PointerEvent>)> pointerCb, std::function<void(std::shared_ptr<MMI::KeyEvent>)> keyCb)63 int32_t MockInputAdapter::AddInterceptor(std::function<void(std::shared_ptr<MMI::PointerEvent>)> pointerCb,
64 std::function<void(std::shared_ptr<MMI::KeyEvent>)> keyCb)
65 {
66 return RET_OK;
67 }
68
RemoveInterceptor(int32_t interceptorId)69 void MockInputAdapter::RemoveInterceptor(int32_t interceptorId)
70 {}
71
AddFilter(std::function<bool(std::shared_ptr<MMI::PointerEvent>)> callback)72 int32_t MockInputAdapter::AddFilter(std::function<bool(std::shared_ptr<MMI::PointerEvent>)> callback)
73 {
74 return RET_OK;
75 }
76
RemoveFilter(int32_t filterId)77 void MockInputAdapter::RemoveFilter(int32_t filterId)
78 {}
79
SetPointerVisibility(bool visible, int32_t priority)80 int32_t MockInputAdapter::SetPointerVisibility(bool visible, int32_t priority)
81 {
82 return RET_OK;
83 }
84
SetPointerLocation(int32_t x, int32_t y)85 int32_t MockInputAdapter::SetPointerLocation(int32_t x, int32_t y)
86 {
87 return RET_OK;
88 }
89
EnableInputDevice(bool enable)90 int32_t MockInputAdapter::EnableInputDevice(bool enable)
91 {
92 return RET_OK;
93 }
94
SimulateInputEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent)95 void MockInputAdapter::SimulateInputEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent)
96 {}
97
SimulateInputEvent(std::shared_ptr<MMI::KeyEvent> keyEvent)98 void MockInputAdapter::SimulateInputEvent(std::shared_ptr<MMI::KeyEvent> keyEvent)
99 {}
100
AddVirtualInputDevice(std::shared_ptr<MMI::InputDevice> device, int32_t &deviceId)101 int32_t MockInputAdapter::AddVirtualInputDevice(std::shared_ptr<MMI::InputDevice> device, int32_t &deviceId)
102 {
103 return RET_OK;
104 }
105
RemoveVirtualInputDevice(int32_t deviceId)106 int32_t MockInputAdapter::RemoveVirtualInputDevice(int32_t deviceId)
107 {
108 return RET_OK;
109 }
110
MockPluginManager(IContext *context)111 MockPluginManager::MockPluginManager(IContext *context)
112 {
113 pluginMgr_ = std::make_unique<PluginManager>(context);
114 }
115
LoadCooperate()116 ICooperate* MockPluginManager::LoadCooperate()
117 {
118 return pluginMgr_->LoadCooperate();
119 }
120
UnloadCooperate()121 void MockPluginManager::UnloadCooperate()
122 {
123 pluginMgr_->UnloadCooperate();
124 }
125
LoadMotionDrag()126 IMotionDrag* MockPluginManager::LoadMotionDrag()
127 {
128 return nullptr;
129 }
130
UnloadMotionDrag()131 void MockPluginManager::UnloadMotionDrag()
132 {}
133
TestContext()134 TestContext::TestContext()
135 {
136 ddm_ = std::make_unique<DDMAdapter>();
137 input_ = std::make_unique<MockInputAdapter>();
138 pluginMgr_ = std::make_unique<MockPluginManager>(this);
139 dsoftbus_ = std::make_unique<DSoftbusAdapter>();
140 }
141
GetDelegateTasks()142 IDelegateTasks& TestContext::GetDelegateTasks()
143 {
144 return delegateTasks_;
145 }
146
GetDeviceManager()147 IDeviceManager& TestContext::GetDeviceManager()
148 {
149 return devMgr_;
150 }
151
GetTimerManager()152 ITimerManager& TestContext::GetTimerManager()
153 {
154 return timerMgr_;
155 }
156
GetDragManager()157 IDragManager& TestContext::GetDragManager()
158 {
159 return dragMgr_;
160 }
161
GetSocketSessionManager()162 ISocketSessionManager& TestContext::GetSocketSessionManager()
163 {
164 return socketSessionMgr_;
165 }
166
GetDDM()167 IDDMAdapter& TestContext::GetDDM()
168 {
169 return *ddm_;
170 }
171
GetPluginManager()172 IPluginManager& TestContext::GetPluginManager()
173 {
174 return *pluginMgr_;
175 }
176
GetInput()177 IInputAdapter& TestContext::GetInput()
178 {
179 return *input_;
180 }
181
GetDSoftbus()182 IDSoftbusAdapter& TestContext::GetDSoftbus()
183 {
184 return *dsoftbus_;
185 }
186 } // namespace DeviceStatus
187 } // namespace Msdp
188 } // namespace OHOS
189