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 
TestContext()110 TestContext::TestContext()
111 {
112     input_ = std::make_unique<MockInputAdapter>();
113     pluginMgr_ = std::make_unique<PluginManager>(this);
114     dsoftbus_ = std::make_unique<DSoftbusAdapter>();
115 }
116 
GetDelegateTasks()117 IDelegateTasks& TestContext::GetDelegateTasks()
118 {
119     return delegateTasks_;
120 }
121 
GetDeviceManager()122 IDeviceManager& TestContext::GetDeviceManager()
123 {
124     return devMgr_;
125 }
126 
GetTimerManager()127 ITimerManager& TestContext::GetTimerManager()
128 {
129     return timerMgr_;
130 }
131 
GetDragManager()132 IDragManager& TestContext::GetDragManager()
133 {
134     return dragMgr_;
135 }
136 
GetSocketSessionManager()137 ISocketSessionManager& TestContext::GetSocketSessionManager()
138 {
139     return socketSessionMgr_;
140 }
141 
GetPluginManager()142 IPluginManager& TestContext::GetPluginManager()
143 {
144     return *pluginMgr_;
145 }
146 
GetInput()147 IInputAdapter& TestContext::GetInput()
148 {
149     return *input_;
150 }
151 
GetDSoftbus()152 IDSoftbusAdapter& TestContext::GetDSoftbus()
153 {
154     return *dsoftbus_;
155 }
156 } // namespace DeviceStatus
157 } // namespace Msdp
158 } // namespace OHOS
159