• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <cstdio>
17 #include <gmock/gmock.h>
18 #include <gtest/gtest.h>
19 
20 #include "define_multimodal.h"
21 #include "libinput_mock.h"
22 #include "preferences_manager_mock.h"
23 #include "mouse_transform_processor.h"
24 #include "input_device_manager.h"
25 #include "mouse_device_state.h"
26 #include "i_input_windows_manager.h"
27 
28 
29 #undef MMI_LOG_TAG
30 #define MMI_LOG_TAG "MouseTransformProcessorMockTest"
31 
32 namespace OHOS {
33 namespace MMI {
34 namespace {
35 using namespace testing;
36 using namespace testing::ext;
37 constexpr uint32_t TP_CLICK_FINGER_ONE { 1 };
38 constexpr uint32_t TP_RIGHT_CLICK_FINGER_CNT { 2 };
39 constexpr int32_t BTN_RIGHT_MENUE_CODE { 0x118 };
40 }
41 class MouseTransformProcessorMockTest : public testing::Test {
42 public:
43     static void SetUpTestCase(void);
44     static void TearDownTestCase(void);
45     void SetUp();
46     void TearDown();
47 };
48 
SetUpTestCase(void)49 void MouseTransformProcessorMockTest::SetUpTestCase(void)
50 {}
51 
TearDownTestCase(void)52 void MouseTransformProcessorMockTest::TearDownTestCase(void)
53 {}
54 
SetUp()55 void MouseTransformProcessorMockTest::SetUp()
56 {}
57 
TearDown()58 void MouseTransformProcessorMockTest::TearDown()
59 {}
60 
61 /**
62  * @tc.name: MouseTransformProcessorMockTest_Normalize_01
63  * @tc.desc: Normalize
64  * @tc.type: FUNC
65  * @tc.require:
66  */
67 HWTEST_F(MouseTransformProcessorMockTest, MouseTransformProcessorMockTest_Normalize_01, TestSize.Level1)
68 {
69     CALL_TEST_DEBUG;
70     int32_t deviceId = 6;
71     MouseTransformProcessor processor(deviceId);
72 
73     libinput_event event {};
74     libinput_event_pointer pointerevent {};
75     NiceMock<LibinputInterfaceMock> libinputMock;
76     EXPECT_CALL(libinputMock, GetEventType).WillRepeatedly(Return(LIBINPUT_EVENT_POINTER_MOTION_TOUCHPAD));
77     EXPECT_CALL(libinputMock, LibinputGetPointerEvent).WillOnce(Return(&pointerevent));
78 
79     int32_t ret = processor.Normalize(&event);
80     EXPECT_EQ(ret, RET_ERR);
81 }
82 
83 /**
84  * @tc.name: MouseTransformProcessorMockTest_Normalize_02
85  * @tc.desc: Normalize
86  * @tc.type: FUNC
87  * @tc.require:
88  */
89 HWTEST_F(MouseTransformProcessorMockTest, MouseTransformProcessorMockTest_Normalize_02, TestSize.Level1)
90 {
91     CALL_TEST_DEBUG;
92     int32_t deviceId = 2;
93     MouseTransformProcessor processor(deviceId);
94 
95     libinput_event event {};
96     libinput_event_pointer pointerevent {};
97     NiceMock<LibinputInterfaceMock> libinputMock;
98     EXPECT_CALL(libinputMock, GetEventType).WillRepeatedly(Return(LIBINPUT_EVENT_POINTER_BUTTON_TOUCHPAD));
99     EXPECT_CALL(libinputMock, LibinputGetPointerEvent).WillOnce(Return(&pointerevent));
100 
101     int32_t ret = processor.Normalize(&event);
102     EXPECT_EQ(ret, RET_ERR);
103 }
104 
105 /**
106  * @tc.name: MouseTransformProcessorMockTest_Normalize_03
107  * @tc.desc: Normalize
108  * @tc.type: FUNC
109  * @tc.require:
110  */
111 HWTEST_F(MouseTransformProcessorMockTest, MouseTransformProcessorMockTest_Normalize_03, TestSize.Level1)
112 {
113     CALL_TEST_DEBUG;
114     int32_t deviceId = 3;
115     MouseTransformProcessor processor(deviceId);
116 
117     libinput_event event {};
118     libinput_event_pointer pointerevent {};
119     NiceMock<LibinputInterfaceMock> libinputMock;
120     EXPECT_CALL(libinputMock, GetEventType).WillRepeatedly(Return(LIBINPUT_EVENT_POINTER_AXIS));
121     EXPECT_CALL(libinputMock, LibinputGetPointerEvent).WillOnce(Return(&pointerevent));
122 
123     int32_t ret = processor.Normalize(&event);
124     EXPECT_EQ(ret, RET_ERR);
125 }
126 
127 /**
128  * @tc.name: MouseTransformProcessorMockTest_HandleAxisBeginEndInner_01
129  * @tc.desc: HandleAxisBeginEndInner
130  * @tc.type: FUNC
131  * @tc.require:
132  */
133 HWTEST_F(MouseTransformProcessorMockTest, MouseTransformProcessorMockTest_HandleAxisBeginEndInner_01, TestSize.Level1)
134 {
135     CALL_TEST_DEBUG;
136     int32_t deviceId = 2;
137     MouseTransformProcessor processor(deviceId);
138     libinput_event event {};
139     NiceMock<LibinputInterfaceMock> libinputMock;
140     EXPECT_CALL(libinputMock, GetEventType).WillRepeatedly(Return(LIBINPUT_EVENT_TOUCHPAD_DOWN));
141     processor.isPressed_ = false;
142     int32_t ret = processor.HandleAxisBeginEndInner(&event);
143     EXPECT_EQ(ret, RET_OK);
144 }
145 
146 /**
147  * @tc.name: MouseTransformProcessorMockTest_HandleAxisBeginEndInner_02
148  * @tc.desc: HandleAxisBeginEndInner
149  * @tc.type: FUNC
150  * @tc.require:
151  */
152 HWTEST_F(MouseTransformProcessorMockTest, MouseTransformProcessorMockTest_HandleAxisBeginEndInner_02, TestSize.Level1)
153 {
154     CALL_TEST_DEBUG;
155     int32_t deviceId = 3;
156     MouseTransformProcessor processor(deviceId);
157     libinput_event event {};
158     NiceMock<LibinputInterfaceMock> libinputMock;
159     EXPECT_CALL(libinputMock, GetEventType).WillRepeatedly(Return(LIBINPUT_EVENT_TOUCHPAD_UP));
160     processor.isPressed_ = false;
161     int32_t ret = processor.HandleAxisBeginEndInner(&event);
162     EXPECT_EQ(ret, RET_OK);
163 }
164 
165 /**
166  * @tc.name: MouseTransformProcessorMockTest_HandleAxisInner_01
167  * @tc.desc: HandleAxisInner
168  * @tc.type: FUNC
169  * @tc.require:
170  */
171 HWTEST_F(MouseTransformProcessorMockTest, MouseTransformProcessorMockTest_HandleAxisInner_01, TestSize.Level1)
172 {
173     CALL_TEST_DEBUG;
174     int32_t deviceId = 3;
175     MouseTransformProcessor processor(deviceId);
176     bool tpScrollSwitch;
177 
178     libinput_event_pointer event {};
179     NiceMock<LibinputInterfaceMock> libinputMock;
180     EXPECT_CALL(libinputMock, GetAxisSource).WillRepeatedly(Return(LIBINPUT_POINTER_AXIS_SOURCE_FINGER));
181     tpScrollSwitch = false;
182     int32_t ret = processor.HandleAxisInner(&event);
183     EXPECT_EQ(ret, RET_ERR);
184 }
185 
186 /**
187  * @tc.name: MouseTransformProcessorMockTest_HandleAxisInner_02
188  * @tc.desc: HandleAxisInner
189  * @tc.type: FUNC
190  * @tc.require:
191  */
192 HWTEST_F(MouseTransformProcessorMockTest, MouseTransformProcessorMockTest_HandleAxisInner_02, TestSize.Level1)
193 {
194     CALL_TEST_DEBUG;
195     int32_t deviceId = 5;
196     MouseTransformProcessor processor(deviceId);
197     bool tpScrollSwitch;
198 
199     libinput_event_pointer event {};
200     NiceMock<LibinputInterfaceMock> libinputMock;
201     EXPECT_CALL(libinputMock, GetAxisSource).WillRepeatedly(Return(LIBINPUT_POINTER_AXIS_SOURCE_FINGER));
202     tpScrollSwitch = false;
203     int32_t ret = processor.HandleAxisInner(&event);
204     EXPECT_EQ(ret, RET_ERR);
205 }
206 
207 /**
208  * @tc.name: MouseTransformProcessorMockTest_HandleTwoFingerButton_01
209  * @tc.desc: HandleTouchpadTwoFingerButton
210  * @tc.type: FUNC
211  * @tc.require:
212  */
213 HWTEST_F(MouseTransformProcessorMockTest, MouseTransformProcessorMockTest_HandleTwoFingerButton_01, TestSize.Level1)
214 {
215     CALL_TEST_DEBUG;
216     int32_t deviceId = 3;
217     MouseTransformProcessor processor(deviceId);
218     uint32_t button = MouseDeviceState::LIBINPUT_BUTTON_CODE::LIBINPUT_RIGHT_BUTTON_CODE;
219     int32_t evenType = LIBINPUT_EVENT_POINTER_BUTTON_TOUCHPAD;
220 
221     libinput_event_pointer event {};
222     NiceMock<LibinputInterfaceMock> libinputMock;
223     EXPECT_CALL(libinputMock, PointerEventGetFingerCount).WillRepeatedly(Return(TP_RIGHT_CLICK_FINGER_CNT));
224     ASSERT_NO_FATAL_FAILURE(processor.HandleTouchpadTwoFingerButton(&event, evenType, button));
225 }
226 
227 /**
228  * @tc.name: MouseTransformProcessorMockTest_HandleTwoFingerButton_02
229  * @tc.desc: HandleTouchpadTwoFingerButton
230  * @tc.type: FUNC
231  * @tc.require:
232  */
233 HWTEST_F(MouseTransformProcessorMockTest, MouseTransformProcessorMockTest_HandleTwoFingerButton_02, TestSize.Level1)
234 {
235     CALL_TEST_DEBUG;
236     int32_t deviceId = 5;
237     MouseTransformProcessor processor(deviceId);
238     uint32_t button = MouseDeviceState::LIBINPUT_BUTTON_CODE::LIBINPUT_RIGHT_BUTTON_CODE;
239     int32_t evenType = LIBINPUT_EVENT_POINTER_BUTTON_TOUCHPAD;
240 
241     libinput_event_pointer event {};
242     NiceMock<LibinputInterfaceMock> libinputMock;
243     EXPECT_CALL(libinputMock, PointerEventGetFingerCount).WillRepeatedly(Return(TP_CLICK_FINGER_ONE));
244     ASSERT_NO_FATAL_FAILURE(processor.HandleTouchpadTwoFingerButton(&event, evenType, button));
245 }
246 
247 /**
248  * @tc.name: MouseTransformProcessorMockTest_HandleTwoFingerButton_03
249  * @tc.desc: HandleTouchpadTwoFingerButton
250  * @tc.type: FUNC
251  * @tc.require:
252  */
253 HWTEST_F(MouseTransformProcessorMockTest, MouseTransformProcessorMockTest_HandleTwoFingerButton_03, TestSize.Level1)
254 {
255     CALL_TEST_DEBUG;
256     int32_t deviceId = 5;
257     MouseTransformProcessor processor(deviceId);
258     uint32_t button = BTN_RIGHT_MENUE_CODE;
259     int32_t evenType = LIBINPUT_EVENT_POINTER_BUTTON_TOUCHPAD;
260 
261     libinput_event_pointer event {};
262     NiceMock<LibinputInterfaceMock> libinputMock;
263     EXPECT_CALL(libinputMock, PointerEventGetFingerCount).WillRepeatedly(Return(TP_CLICK_FINGER_ONE));
264     ASSERT_NO_FATAL_FAILURE(processor.HandleTouchpadTwoFingerButton(&event, evenType, button));
265 }
266 
267 /**
268  * @tc.name: MouseTransformProcessorMockTest_HandleMotionInner_01
269  * @tc.desc: HandleMotionInner
270  * @tc.type: FUNC
271  * @tc.require:
272  */
273 HWTEST_F(MouseTransformProcessorMockTest, MouseTransformProcessorMockTest_HandleMotionInner_01, TestSize.Level1)
274 {
275     CALL_TEST_DEBUG;
276     int32_t deviceId = 5;
277     MouseTransformProcessor processor(deviceId);
278 
279     libinput_event_pointer pointerevent {};
280     libinput_event event {};
281 
282     CursorPosition cursorPos = WIN_MGR->GetCursorPos();
283     EXPECT_TRUE(cursorPos.displayId < 0);
284 
285     int32_t ret = processor.HandleMotionInner(&pointerevent, &event);
286     EXPECT_EQ(ret, RET_ERR);
287 }
288 
289 /**
290  * @tc.name: MouseTransformProcessorMockTest_HandleMotionInner_02
291  * @tc.desc: HandleMotionInner
292  * @tc.type: FUNC
293  * @tc.require:
294  */
295 HWTEST_F(MouseTransformProcessorMockTest, MouseTransformProcessorMockTest_HandleMotionInner_02, TestSize.Level1)
296 {
297     CALL_TEST_DEBUG;
298     int32_t deviceId = 7;
299     Direction direction;
300     MouseTransformProcessor processor(deviceId);
301     libinput_event_pointer pointerevent {};
302     libinput_event event {};
303 
304     NiceMock<LibinputInterfaceMock> libinputMock;
305     CursorPosition cursorPos = WIN_MGR->GetCursorPos();
306     cursorPos.displayId = 2;
307     EXPECT_CALL(libinputMock, PointerGetDxUnaccelerated).WillRepeatedly(Return(2.5));
308     EXPECT_CALL(libinputMock, PointerGetDxUnaccelerated).WillRepeatedly(Return(3.5));
309 
310     direction = DIRECTION0;
311     int32_t ret = processor.HandleMotionInner(&pointerevent, &event);
312     EXPECT_EQ(ret, RET_ERR);
313 }
314 
315 /**
316  * @tc.name: MouseTransformProcessorMockTest_HandleMotionInner_03
317  * @tc.desc: HandleMotionInner
318  * @tc.type: FUNC
319  * @tc.require:
320  */
321 HWTEST_F(MouseTransformProcessorMockTest, MouseTransformProcessorMockTest_HandleMotionInner_03, TestSize.Level1)
322 {
323     CALL_TEST_DEBUG;
324     int32_t deviceId = 8;
325     Direction direction;
326     MouseTransformProcessor processor(deviceId);
327     libinput_event_pointer pointerevent {};
328     libinput_event event {};
329 
330     NiceMock<LibinputInterfaceMock> libinputMock;
331     CursorPosition cursorPos = WIN_MGR->GetCursorPos();
332     cursorPos.displayId = 2;
333     EXPECT_CALL(libinputMock, PointerGetDxUnaccelerated).WillRepeatedly(Return(2.5));
334     EXPECT_CALL(libinputMock, PointerGetDxUnaccelerated).WillRepeatedly(Return(3.5));
335     direction = DIRECTION90;
336     EXPECT_CALL(libinputMock, GetEventType).WillRepeatedly(Return(LIBINPUT_EVENT_POINTER_MOTION_TOUCHPAD));
337     int32_t ret = processor.HandleMotionInner(&pointerevent, &event);
338     EXPECT_EQ(ret, RET_ERR);
339 }
340 
341 /**
342  * @tc.name: MouseTransformProcessorMockTest_HandleMotionInner_04
343  * @tc.desc: HandleMotionInner
344  * @tc.type: FUNC
345  * @tc.require:
346  */
347 HWTEST_F(MouseTransformProcessorMockTest, MouseTransformProcessorMockTest_HandleMotionInner_04, TestSize.Level1)
348 {
349     CALL_TEST_DEBUG;
350     int32_t deviceId = 8;
351     Direction direction;
352     MouseTransformProcessor processor(deviceId);
353     libinput_event_pointer pointerevent {};
354     libinput_event event {};
355 
356     NiceMock<LibinputInterfaceMock> libinputMock;
357     CursorPosition cursorPos = WIN_MGR->GetCursorPos();
358     cursorPos.displayId = 2;
359     EXPECT_CALL(libinputMock, PointerGetDxUnaccelerated).WillRepeatedly(Return(2.5));
360     EXPECT_CALL(libinputMock, PointerGetDxUnaccelerated).WillRepeatedly(Return(3.5));
361     direction = DIRECTION90;
362     EXPECT_CALL(libinputMock, GetEventType).WillRepeatedly(Return(LIBINPUT_EVENT_POINTER_BUTTON_TOUCHPAD));
363 
364     int32_t ret = processor.HandleMotionInner(&pointerevent, &event);
365     EXPECT_EQ(ret, RET_ERR);
366 }
367 } // namespace MMI
368 } // namespace OHOS