• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024-2025 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 #ifndef INPUT_WINDOWS_MANAGER_MOCK_H
17 #define INPUT_WINDOWS_MANAGER_MOCK_H
18 
19 #include <gmock/gmock.h>
20 #include "nocopyable.h"
21 
22 #include "i_input_windows_manager.h"
23 
24 namespace OHOS {
25 namespace MMI {
26 class InputWindowsManagerMock final : public IInputWindowsManager {
27 public:
28     InputWindowsManagerMock() = default;
29     ~InputWindowsManagerMock() = default;
30     DISALLOW_COPY_AND_MOVE(InputWindowsManagerMock);
31 
Init(UDSServer &)32     void Init(UDSServer&) override {}
JudgeCameraInFore()33     bool JudgeCameraInFore() override
34     {
35         return true;
36     }
37     MOCK_METHOD(int32_t, GetClientFd, (std::shared_ptr<PointerEvent>));
38     MOCK_METHOD(int32_t, GetClientFd, (std::shared_ptr<PointerEvent>, int32_t));
39     MOCK_METHOD(bool, AdjustFingerFlag, (std::shared_ptr<PointerEvent>));
40     MOCK_METHOD(void, PrintEnterEventInfo, (std::shared_ptr<PointerEvent>));
41     MOCK_METHOD(bool, IsFocusedSession, (int32_t), (const));
UpdateDisplayInfo(OLD::DisplayGroupInfo &)42     void UpdateDisplayInfo(OLD::DisplayGroupInfo&) override {}
UpdateDisplayInfoExtIfNeed(OLD::DisplayGroupInfo &,bool)43     void UpdateDisplayInfoExtIfNeed(OLD::DisplayGroupInfo&, bool) override {}
ProcessInjectEventGlobalXY(std::shared_ptr<PointerEvent>,int32_t)44     void ProcessInjectEventGlobalXY(std::shared_ptr<PointerEvent>, int32_t) override {};
UpdateWindowInfo(const WindowGroupInfo &)45     void UpdateWindowInfo(const WindowGroupInfo&) override {}
46     MOCK_METHOD(int32_t, ClearWindowPointerStyle, (int32_t, int32_t));
Dump(int32_t,const std::vector<std::string> &)47     void Dump(int32_t, const std::vector<std::string>&) override {}
48     MOCK_METHOD(int32_t, GetWindowPid, (int32_t), (const));
49     MOCK_METHOD(int32_t, SetMouseCaptureMode, (int32_t, bool));
50     MOCK_METHOD(bool, GetMouseIsCaptureMode, (), (const));
51     MOCK_METHOD(int32_t, GetDisplayBindInfo, (DisplayBindInfos&));
52     MOCK_METHOD(int32_t, SetDisplayBind, (int32_t, int32_t, std::string&));
53     MOCK_METHOD(int32_t, AppendExtraData, (const ExtraData&));
54     MOCK_METHOD(bool, IsWindowVisible, (int32_t));
55     MOCK_METHOD(ExtraData, GetExtraData, (), (const));
56     MOCK_METHOD(const std::vector<WindowInfo>, GetWindowGroupInfoByDisplayIdCopy, (int32_t), (const));
57     MOCK_METHOD((std::pair<double, double>), TransformWindowXY, (const WindowInfo&, double, double), (const));
58     MOCK_METHOD((std::pair<double, double>), TransformDisplayXY, (const OLD::DisplayInfo&, double, double), (const));
ClearTargetWindowId(int32_t pointerId)59     void ClearTargetWindowId(int32_t pointerId) override {}
60 
61 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
62     MOCK_METHOD((std::vector<std::pair<int32_t, TargetInfo>>), UpdateTarget, (std::shared_ptr<KeyEvent>));
63     MOCK_METHOD(void, HandleKeyEventWindowId, (std::shared_ptr<KeyEvent>));
64 #endif // OHOS_BUILD_ENABLE_KEYBOARD
65 
66     MOCK_METHOD(int32_t, CheckWindowIdPermissionByPid, (int32_t, int32_t));
67     MOCK_METHOD(int32_t, ClearMouseHideFlag, (int32_t));
68     MOCK_METHOD(int32_t, GetCurrentUserId, ());
69     MOCK_METHOD(void, SetFoldState, ());
70     MOCK_METHOD(bool, CheckAppFocused, (int32_t));
71 
72 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
73     MOCK_METHOD(MouseLocation, GetMouseInfo, ());
74     MOCK_METHOD(CursorPosition, GetCursorPos, ());
75     MOCK_METHOD(CursorPosition, ResetCursorPos, ());
UpdateAndAdjustMouseLocation(int32_t &,double &,double &,bool)76     void UpdateAndAdjustMouseLocation(int32_t&, double&, double&, bool) override {}
77 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
78 
79 #ifdef OHOS_BUILD_ENABLE_POINTER
80     MOCK_METHOD(int32_t, SetHoverScrollState, (bool));
81     MOCK_METHOD(bool, GetHoverScrollState, (), (const));
82     MOCK_METHOD(int32_t, GetFocusWindowId, (int32_t), (const));
83     MOCK_METHOD(bool, IsMouseSimulate, ());
84     MOCK_METHOD(bool, HasMouseHideFlag, ());
85     MOCK_METHOD(bool, SelectPointerChangeArea, (int32_t, int32_t, int32_t));
86 #endif // OHOS_BUILD_ENABLE_POINTER
87 
88 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
89     MOCK_METHOD(int32_t, SetPointerStyle, (int32_t, int32_t, PointerStyle, bool));
90     MOCK_METHOD(int32_t, GetPointerStyle, (int32_t, int32_t, PointerStyle&, bool), (const));
91     void DispatchPointer(int32_t pointerAction, int32_t windowId = -1) override {}
SendPointerEvent(int32_t pointerAction)92     void SendPointerEvent(int32_t pointerAction) override {}
UpdatePointerDrawingManagerWindowInfo()93     void UpdatePointerDrawingManagerWindowInfo() override {}
94 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
95 
96 #ifdef OHOS_BUILD_ENABLE_POINTER
97 #ifdef OHOS_BUILD_ENABLE_POINTER_DRAWING
98     MOCK_METHOD(bool, IsNeedRefreshLayer, (int32_t));
99 #endif // OHOS_BUILD_ENABLE_POINTER_DRAWING
100 #endif //OHOS_BUILD_ENABLE_POINTER
101 
102 #ifdef OHOS_BUILD_ENABLE_TOUCH
103     MOCK_METHOD(bool, TouchPointToDisplayPoint, (int32_t, struct libinput_event_touch*, EventTouch&, int32_t&, bool));
104     MOCK_METHOD(bool, CalculateTipPoint, (struct libinput_event_tablet_tool*, int32_t&, PhysicalCoordinate&));
105     MOCK_METHOD(const OLD::DisplayInfo *, GetDefaultDisplayInfo, (), (const));
106     MOCK_METHOD(void, ReverseXY, (int32_t&, int32_t&));
107     MOCK_METHOD(void, SendCancelEventWhenLock, ());
108     MOCK_METHOD(void, FoldScreenRotation, (std::shared_ptr<PointerEvent>));
109 #endif // OHOS_BUILD_ENABLE_TOUCH
110 
111 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
DrawTouchGraphic(std::shared_ptr<PointerEvent>)112     void DrawTouchGraphic(std::shared_ptr<PointerEvent>) override {}
113     MOCK_METHOD(int32_t, UpdateTargetPointer, (std::shared_ptr<PointerEvent>));
114     MOCK_METHOD(const OLD::DisplayInfo *, GetPhysicalDisplay, (int32_t), (const));
115 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
116 
117 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
UpdatePointerChangeAreas()118     void UpdatePointerChangeAreas() override {}
119 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
120 
121     MOCK_METHOD(std::optional<WindowInfo>, GetWindowAndDisplayInfo, (int32_t, int32_t));
SetWindowStateNotifyPid(int32_t pid)122     void SetWindowStateNotifyPid(int32_t pid) override {}
GetWindowStateNotifyPid()123     int32_t GetWindowStateNotifyPid() override { return 0; }
GetPidByWindowId(int32_t pid)124     int32_t GetPidByWindowId(int32_t pid) override { return 0; }
CalcDrawCoordinate(const OLD::DisplayInfo & displayInfo,PointerEvent::PointerItem pointerItem)125     std::pair<int32_t, int32_t> CalcDrawCoordinate(const OLD::DisplayInfo& displayInfo,
126         PointerEvent::PointerItem pointerItem) override { return { 0, 0 }; }
GetCancelEventFlag(std::shared_ptr<PointerEvent> pointerEvent)127     bool GetCancelEventFlag(std::shared_ptr<PointerEvent> pointerEvent) { return false; }
128     MOCK_METHOD(int32_t, SetPixelMapData, (int32_t infoId, void *pixelMap), (override));
129 
GetTargetWindowIds(int32_t,int32_t,std::vector<int32_t> &)130     void GetTargetWindowIds(int32_t, int32_t, std::vector<int32_t>&) override {}
131     MOCK_METHOD(int32_t, SetCurrentUser, (int32_t));
132     MOCK_METHOD(DisplayMode, GetDisplayMode, (), (const));
133 #ifdef OHOS_BUILD_ENABLE_ANCO
InitializeAnco()134     void InitializeAnco() override {}
135     MOCK_METHOD(int32_t, AncoAddChannel, (sptr<IAncoChannel>));
136     MOCK_METHOD(int32_t, AncoRemoveChannel, (sptr<IAncoChannel>));
137     MOCK_METHOD(void, CleanShellWindowIds, ());
138     MOCK_METHOD(bool, IsKnuckleOnAncoWindow, (std::shared_ptr<PointerEvent>));
139     MOCK_METHOD(int32_t, SyncKnuckleStatus, (bool));
140 #endif // OHOS_BUILD_ENABLE_ANCO
141 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
142     MOCK_METHOD(int32_t, ShiftAppPointerEvent, (const ShiftWindowParam&, bool));
143     MOCK_METHOD(Direction, GetDisplayDirection, (const OLD::DisplayInfo *));
144 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
145     MOCK_METHOD(bool, GetHardCursorEnabled, ());
146 #if defined(OHOS_BUILD_ENABLE_TOUCH) && defined(OHOS_BUILD_ENABLE_MONITOR)
147     MOCK_METHOD(void, AttachTouchGestureMgr, (std::shared_ptr<TouchGestureManager>));
148     MOCK_METHOD(void, CancelAllTouches, (std::shared_ptr<PointerEvent>, bool));
149 #endif // defined(OHOS_BUILD_ENABLE_TOUCH) && defined(OHOS_BUILD_ENABLE_MONITOR)
150 #ifdef OHOS_BUILD_ENABLE_TOUCH
151     MOCK_METHOD(std::shared_ptr<PointerEvent>, GetLastPointerEventForGesture, ());
152 #endif // OHOS_BUILD_ENABLE_TOUCH
153 #ifdef OHOS_BUILD_ENABLE_POINTER
154     MOCK_METHOD(bool, IsMouseDragging, (), (const));
155     MOCK_METHOD(void, EnsureMouseEventCycle, (std::shared_ptr<PointerEvent>));
156     MOCK_METHOD(void, CleanMouseEventCycle, (std::shared_ptr<PointerEvent>));
157 #endif // OHOS_BUILD_ENABLE_POINTER
158 
159     static std::shared_ptr<InputWindowsManagerMock> GetInstance();
160     static void ReleaseInstance();
161 
162 private:
163     static std::mutex mutex_;
164     static std::shared_ptr<InputWindowsManagerMock> instance_;
165 };
166 
167 #define WIN_MGR_MOCK ::OHOS::MMI::InputWindowsManagerMock::GetInstance()
168 } // namespace MMI
169 } // namespace OHOS
170 #endif // INPUT_WINDOWS_MANAGER_MOCK_H
171