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 #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 
32     void Init(UDSServer&) override {}
33     MOCK_METHOD(int32_t, GetClientFd, (std::shared_ptr<PointerEvent>));
34     MOCK_METHOD(int32_t, GetClientFd, (std::shared_ptr<PointerEvent>, int32_t));
35     void UpdateDisplayInfo(DisplayGroupInfo&) override {}
36     void UpdateDisplayInfoExtIfNeed(DisplayGroupInfo&, bool) override {}
37     void UpdateWindowInfo(const WindowGroupInfo&) override {}
38 #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_POINTER_DRAWING)
39     void SetWindowPointerStyle(WindowArea area, int32_t, int32_t) override {}
40 #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_POINTER_DRAWING
41     MOCK_METHOD(int32_t, ClearWindowPointerStyle, (int32_t, int32_t));
42     void Dump(int32_t, const std::vector<std::string>&) override {}
43     MOCK_METHOD(int32_t, GetWindowPid, (int32_t), (const));
44     MOCK_METHOD(int32_t, SetMouseCaptureMode, (int32_t, bool));
45     MOCK_METHOD(bool, GetMouseIsCaptureMode, (), (const));
46     MOCK_METHOD(int32_t, GetDisplayBindInfo, (DisplayBindInfos&));
47     MOCK_METHOD(int32_t, SetDisplayBind, (int32_t, int32_t, std::string&));
48     MOCK_METHOD(int32_t, AppendExtraData, (const ExtraData&));
49     MOCK_METHOD(bool, IsWindowVisible, (int32_t));
50     MOCK_METHOD(ExtraData, GetExtraData, (), (const));
51     MOCK_METHOD(const std::vector<WindowInfo>&, GetWindowGroupInfoByDisplayId, (int32_t), (const));
52     MOCK_METHOD((std::pair<double, double>), TransformWindowXY, (const WindowInfo&, double, double), (const));
53     MOCK_METHOD((std::pair<double, double>), TransformDisplayXY, (const DisplayInfo&, double, double), (const));
54     void ClearTargetWindowId(int32_t pointerId) override {}
55 
56 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
57     MOCK_METHOD((std::vector<std::pair<int32_t, TargetInfo>>), UpdateTarget, (std::shared_ptr<KeyEvent>));
58     MOCK_METHOD(void, HandleKeyEventWindowId, (std::shared_ptr<KeyEvent>));
59 #endif // OHOS_BUILD_ENABLE_KEYBOARD
60 
61     MOCK_METHOD(int32_t, CheckWindowIdPermissionByPid, (int32_t, int32_t));
62     MOCK_METHOD(int32_t, GetCurrentUserId, ());
63     MOCK_METHOD(void, SetFoldState, ());
64 
65 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
66     MOCK_METHOD(MouseLocation, GetMouseInfo, ());
67     MOCK_METHOD(CursorPosition, GetCursorPos, ());
68     MOCK_METHOD(CursorPosition, ResetCursorPos, ());
69     void UpdateAndAdjustMouseLocation(int32_t&, double&, double&, bool) override {}
70 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
71 
72 #ifdef OHOS_BUILD_ENABLE_POINTER
73     MOCK_METHOD(int32_t, SetHoverScrollState, (bool));
74     MOCK_METHOD(bool, GetHoverScrollState, (), (const));
75     MOCK_METHOD(bool, IsMouseSimulate, (), (const));
76     MOCK_METHOD(bool, SelectPointerChangeArea, (int32_t, int32_t, int32_t));
77 #endif // OHOS_BUILD_ENABLE_POINTER
78 
79 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
80     MOCK_METHOD(int32_t, SetPointerStyle, (int32_t, int32_t, PointerStyle, bool));
81     MOCK_METHOD(int32_t, GetPointerStyle, (int32_t, int32_t, PointerStyle&, bool), (const));
82     void DispatchPointer(int32_t pointerAction, int32_t windowId = -1) override {}
83     void SendPointerEvent(int32_t pointerAction) override {}
84 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
85 
86 #ifdef OHOS_BUILD_ENABLE_POINTER
87 #ifdef OHOS_BUILD_ENABLE_POINTER_DRAWING
88     MOCK_METHOD(bool, IsNeedRefreshLayer, (int32_t));
89 #endif // OHOS_BUILD_ENABLE_POINTER_DRAWING
90 #endif //OHOS_BUILD_ENABLE_POINTER
91 
92 #ifdef OHOS_BUILD_ENABLE_TOUCH
93     MOCK_METHOD(bool, TouchPointToDisplayPoint, (int32_t, struct libinput_event_touch*, EventTouch&, int32_t&));
94     MOCK_METHOD(bool, CalculateTipPoint, (struct libinput_event_tablet_tool*, int32_t&, PhysicalCoordinate&), (const));
95     MOCK_METHOD(const DisplayInfo*, GetDefaultDisplayInfo, (), (const));
96     MOCK_METHOD(void, ReverseXY, (int32_t&, int32_t&));
97     MOCK_METHOD(void, SendCancelEventWhenLock, ());
98 #endif // OHOS_BUILD_ENABLE_TOUCH
99 
100 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
101     void DrawTouchGraphic(std::shared_ptr<PointerEvent>) override {}
102     MOCK_METHOD(int32_t, UpdateTargetPointer, (std::shared_ptr<PointerEvent>));
103     MOCK_METHOD(const DisplayInfo*, GetPhysicalDisplay, (int32_t), (const));
104 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
105 
106 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
107     void UpdatePointerChangeAreas() override {}
108 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
109 
110     MOCK_METHOD(std::optional<WindowInfo>, GetWindowAndDisplayInfo, (int32_t, int32_t));
111     void SetWindowStateNotifyPid(int32_t pid) override {}
112     int32_t GetWindowStateNotifyPid() override { return 0; }
113     int32_t GetPidByWindowId(int32_t pid) override { return 0; }
GetCancelEventFlag(std::shared_ptr<PointerEvent> pointerEvent)114     bool GetCancelEventFlag(std::shared_ptr<PointerEvent> pointerEvent) { return false; }
115     MOCK_METHOD(int32_t, SetPixelMapData, (int32_t infoId, void *pixelMap), (override));
116 
117     void GetTargetWindowIds(int32_t, int32_t, std::vector<int32_t>&) override {}
118     MOCK_METHOD(int32_t, SetCurrentUser, (int32_t));
119     MOCK_METHOD(DisplayMode, GetDisplayMode, (), (const));
120 #ifdef OHOS_BUILD_ENABLE_ANCO
121     MOCK_METHOD(int32_t, AncoAddChannel, (sptr<IAncoChannel>));
122     MOCK_METHOD(int32_t, AncoRemoveChannel, (sptr<IAncoChannel>));
123     MOCK_METHOD(void, CleanShellWindowIds, ());
124     MOCK_METHOD(bool, IsKnuckleOnAncoWindow, (std::shared_ptr<PointerEvent>));
125 #endif // OHOS_BUILD_ENABLE_ANCO
126 
127     static std::shared_ptr<InputWindowsManagerMock> GetInstance();
128 
129 private:
130     static std::mutex mutex_;
131     static std::shared_ptr<InputWindowsManagerMock> instance_;
132 };
133 
134 #define WIN_MGR_MOCK ::OHOS::MMI::InputWindowsManagerMock::GetInstance()
135 } // namespace MMI
136 } // namespace OHOS
137 #endif // INPUT_WINDOWS_MANAGER_MOCK_H
138