• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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 "mock_input_manager.h"
17 
18 namespace OHOS {
19 namespace MMI {
20 static int mockKeyCode = -1;
21 static std::vector<int32_t> mockTouchActions;
22 static std::function<void(std::shared_ptr<MMI::PointerEvent>)> mockPointerCallback = nullptr;
23 static std::shared_ptr<MMI::IInputEventConsumer> mockInputEventConsumer = nullptr;
24 
GetKeyCode()25 int MockInputManager::GetKeyCode()
26 {
27     return mockKeyCode;
28 }
29 
ClearTouchActions()30 void MockInputManager::ClearTouchActions()
31 {
32     mockTouchActions.clear();
33 }
34 
GetTouchActions()35 std::vector<int32_t> MockInputManager::GetTouchActions()
36 {
37     return mockTouchActions;
38 }
39 
ClearInputEventConsumer()40 void MockInputManager::ClearInputEventConsumer()
41 {
42     mockInputEventConsumer = nullptr;
43 }
44 
GetInputEventConsumer()45 std::shared_ptr<IInputEventConsumer> MockInputManager::GetInputEventConsumer()
46 {
47     return mockInputEventConsumer;
48 }
49 
50 InputManager *InputManager::instance_ = nullptr;
51 
GetInstance()52 InputManager *InputManager::GetInstance()
53 {
54     if (!instance_) {
55         instance_ = new InputManager();
56     }
57     return instance_;
58 }
59 
SimulateInputEvent(std::shared_ptr<KeyEvent> keyEvent)60 void InputManager::SimulateInputEvent(std::shared_ptr<KeyEvent> keyEvent)
61 {
62     mockKeyCode = keyEvent->GetKeyCode();
63 }
64 
SimulateInputEvent(std::shared_ptr<PointerEvent> pointerEvent)65 void InputManager::SimulateInputEvent(std::shared_ptr<PointerEvent> pointerEvent)
66 {
67     int32_t touchAction = pointerEvent->GetPointerAction();
68     mockTouchActions.push_back(touchAction);
69 }
70 
AddInterceptor(std::shared_ptr<IInputEventConsumer> interceptorId)71 int32_t InputManager::AddInterceptor(std::shared_ptr<IInputEventConsumer> interceptorId)
72 {
73     mockInputEventConsumer = interceptorId;
74     return 0;
75 }
76 
AddInterceptor(int32_t sourceType,std::function<void (std::shared_ptr<PointerEvent>)> interceptor)77 int32_t InputManager::AddInterceptor(int32_t sourceType, std::function<void(std::shared_ptr<PointerEvent>)> interceptor)
78 {
79     mockPointerCallback = interceptor;
80     return 0;
81 }
82 
AddInterceptor(std::function<void (std::shared_ptr<KeyEvent>)> interceptor)83 int32_t InputManager::AddInterceptor(std::function<void(std::shared_ptr<KeyEvent>)> interceptor)
84 {
85     return 0;
86 }
87 
RemoveInterceptor(int32_t interceptorId)88 void InputManager::RemoveInterceptor(int32_t interceptorId)
89 {
90 }
91 }
92 }