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 #include <gmock/gmock.h>
17
18 #include <cinttypes>
19 #include <climits>
20 #include <cstdio>
21 #include <cstring>
22 #include <functional>
23 #include <sys/stat.h>
24 #include <unistd.h>
25 #include <vector>
26
27 #include "general_touchpad.h"
28 #include "i_input_windows_manager.h"
29 #include "input_device_manager.h"
30 #include "input_event_handler.h"
31 #include "key_command_handler.h"
32 #include "libinput_mock.h"
33 #include "mmi_log.h"
34 #include "timer_manager.h"
35 #include "util.h"
36
37 #undef MMI_LOG_TAG
38 #define MMI_LOG_TAG "InputEventHandlerTest"
39
40 static double g_mockLibinputDeviceGetSizeWidth = 0.0;
41 static int g_mockLibinputDeviceGetSizeRetrunIntValue = 0;
42
43 using namespace testing;
44 using namespace testing::ext;
45
46 namespace OHOS {
47 namespace MMI {
48
HandleEvent(libinput_event * event,int64_t frameTime)49 void EventNormalizeHandler::HandleEvent(libinput_event *event, int64_t frameTime) {}
50
51 class InputEventHandlerTest : public testing::Test {
52 public:
53 static void SetUpTestCase(void);
54 static void TearDownTestCase(void);
55 void SetUp();
56 void TearDown();
57 };
58
SetUpTestCase(void)59 void InputEventHandlerTest::SetUpTestCase(void) {}
60
TearDownTestCase(void)61 void InputEventHandlerTest::TearDownTestCase(void) {}
62
SetUp(void)63 void InputEventHandlerTest::SetUp(void)
64 {
65 g_mockLibinputDeviceGetSizeWidth = 0.0;
66 g_mockLibinputDeviceGetSizeRetrunIntValue = 0;
67 }
68
TearDown(void)69 void InputEventHandlerTest::TearDown(void) {}
70
71 /**
72 * @tc.name: InputEventHandler_OnEvent_001
73 * @tc.desc: Test the funcation OnEvent
74 * @tc.type: FUNC
75 * @tc.require:
76 */
77 HWTEST_F(InputEventHandlerTest, InputEventHandler_OnEvent_001, TestSize.Level1)
78 {
79 CALL_DEBUG_ENTER;
80 void *event = nullptr;
81 int64_t frameTime = 0;
82 std::shared_ptr<InputEventHandler> inputEventHandler = std::make_shared<InputEventHandler>();
83 inputEventHandler->eventNormalizeHandler_ = std::make_shared<EventNormalizeHandler>();
84 ASSERT_NO_FATAL_FAILURE(inputEventHandler->OnEvent(event, frameTime));
85 }
86
87 /**
88 * @tc.name: InputEventHandler_UpdateDwtRecord_001
89 * @tc.desc: Test the funcation UpdateDwtRecord
90 * @tc.type: FUNC
91 * @tc.require:
92 */
93 HWTEST_F(InputEventHandlerTest, InputEventHandler_UpdateDwtRecord_001, TestSize.Level1)
94 {
95 CALL_DEBUG_ENTER;
96 std::shared_ptr<InputEventHandler> inputEventHandler = std::make_shared<InputEventHandler>();
97 NiceMock<LibinputInterfaceMock> libinputMock;
98 EXPECT_CALL(libinputMock, GetEventType).WillOnce(Return(LIBINPUT_EVENT_TOUCHPAD_DOWN));
99 EXPECT_CALL(libinputMock, GetTouchpadEvent).WillOnce(Return(nullptr));
100 libinput_event event;
101 ASSERT_NO_FATAL_FAILURE(inputEventHandler->UpdateDwtRecord(&event));
102 }
103
104 /**
105 * @tc.name: InputEventHandler_UpdateDwtRecord_002
106 * @tc.desc: Test the funcation UpdateDwtRecord
107 * @tc.type: FUNC
108 * @tc.require:
109 */
110 HWTEST_F(InputEventHandlerTest, InputEventHandler_UpdateDwtRecord_002, TestSize.Level1)
111 {
112 CALL_DEBUG_ENTER;
113 std::shared_ptr<InputEventHandler> inputEventHandler = std::make_shared<InputEventHandler>();
114 NiceMock<LibinputInterfaceMock> libinputMock;
115 EXPECT_CALL(libinputMock, GetEventType).WillOnce(Return(LIBINPUT_EVENT_TOUCHPAD_MOTION));
116 EXPECT_CALL(libinputMock, GetTouchpadEvent).WillOnce(Return(nullptr));
117 libinput_event event;
118 ASSERT_NO_FATAL_FAILURE(inputEventHandler->UpdateDwtRecord(&event));
119 }
120
121 /**
122 * @tc.name: InputEventHandler_UpdateDwtRecord_003
123 * @tc.desc: Test the funcation UpdateDwtRecord
124 * @tc.type: FUNC
125 * @tc.require:
126 */
127 HWTEST_F(InputEventHandlerTest, InputEventHandler_UpdateDwtRecord_003, TestSize.Level1)
128 {
129 CALL_DEBUG_ENTER;
130 std::shared_ptr<InputEventHandler> inputEventHandler = std::make_shared<InputEventHandler>();
131 NiceMock<LibinputInterfaceMock> libinputMock;
132 EXPECT_CALL(libinputMock, GetEventType).WillOnce(Return(LIBINPUT_EVENT_KEYBOARD_KEY));
133 EXPECT_CALL(libinputMock, LibinputEventGetKeyboardEvent).WillOnce(Return(nullptr));
134 libinput_event event;
135 ASSERT_NO_FATAL_FAILURE(inputEventHandler->UpdateDwtRecord(&event));
136 }
137
138 /**
139 * @tc.name: InputEventHandler_UpdateDwtRecord_004
140 * @tc.desc: Test the funcation UpdateDwtRecord
141 * @tc.type: FUNC
142 * @tc.require:
143 */
144 HWTEST_F(InputEventHandlerTest, InputEventHandler_UpdateDwtRecord_004, TestSize.Level1)
145 {
146 CALL_DEBUG_ENTER;
147 std::shared_ptr<InputEventHandler> inputEventHandler = std::make_shared<InputEventHandler>();
148 NiceMock<LibinputInterfaceMock> libinputMock;
149 EXPECT_CALL(libinputMock, GetEventType).WillOnce(Return(LIBINPUT_EVENT_NONE));
150 libinput_event event;
151 ASSERT_NO_FATAL_FAILURE(inputEventHandler->UpdateDwtRecord(&event));
152 }
153
154 /**
155 * @tc.name: InputEventHandler_UpdateDwtTouchpadRecord_001
156 * @tc.desc: Test the funcation UpdateDwtTouchpadRecord
157 * @tc.type: FUNC
158 * @tc.require:
159 */
160 HWTEST_F(InputEventHandlerTest, InputEventHandler_UpdateDwtTouchpadRecord_001, TestSize.Level1)
161 {
162 CALL_DEBUG_ENTER;
163 std::shared_ptr<InputEventHandler> inputEventHandler = std::make_shared<InputEventHandler>();
164 NiceMock<LibinputInterfaceMock> libinputMock;
165 libinput_event_touch touchpadEvent;
166 libinput_event event;
167 libinput_device touchpadDevice;
168 g_mockLibinputDeviceGetSizeRetrunIntValue = 1;
169 EXPECT_CALL(libinputMock, GetTouchpadEvent).WillOnce(Return(&touchpadEvent));
170 EXPECT_CALL(libinputMock, GetEventType).WillOnce(Return(LIBINPUT_EVENT_NONE));
171 EXPECT_CALL(libinputMock, GetDevice).WillOnce(Return(&touchpadDevice));
172 ASSERT_NO_FATAL_FAILURE(inputEventHandler->UpdateDwtTouchpadRecord(&event));
173 }
174
175 /**
176 * @tc.name: InputEventHandler_UpdateDwtTouchpadRecord_002
177 * @tc.desc: Test the funcation UpdateDwtTouchpadRecord
178 * @tc.type: FUNC
179 * @tc.require:
180 */
181 HWTEST_F(InputEventHandlerTest, InputEventHandler_UpdateDwtTouchpadRecord_002, TestSize.Level1)
182 {
183 CALL_DEBUG_ENTER;
184 std::shared_ptr<InputEventHandler> inputEventHandler = std::make_shared<InputEventHandler>();
185 NiceMock<LibinputInterfaceMock> libinputMock;
186 libinput_event_touch touchpadEvent;
187 libinput_event event;
188 libinput_device touchpadDevice;
189 touchpadEvent.x = InputEventHandler::TOUCHPAD_EDGE_WIDTH_FOR_TAP + 1;
190 touchpadEvent.y = 0;
191 g_mockLibinputDeviceGetSizeWidth = 1000.0;
192 g_mockLibinputDeviceGetSizeRetrunIntValue = 1;
193 EXPECT_CALL(libinputMock, GetTouchpadEvent).WillRepeatedly(Return(&touchpadEvent));
194 EXPECT_CALL(libinputMock, GetEventType).WillRepeatedly(Return(LIBINPUT_EVENT_TOUCHPAD_DOWN));
195 EXPECT_CALL(libinputMock, GetDevice).WillRepeatedly(Return(&touchpadDevice));
196 ASSERT_NO_FATAL_FAILURE(inputEventHandler->UpdateDwtTouchpadRecord(&event));
197
198 touchpadEvent.x = 2000.0;
199 ASSERT_NO_FATAL_FAILURE(inputEventHandler->UpdateDwtTouchpadRecord(&event));
200
201 touchpadEvent.x = 1.0;
202 ASSERT_NO_FATAL_FAILURE(inputEventHandler->UpdateDwtTouchpadRecord(&event));
203 }
204
205 /**
206 * @tc.name: InputEventHandler_UpdateDwtTouchpadRecord_003
207 * @tc.desc: Test the funcation UpdateDwtTouchpadRecord
208 * @tc.type: FUNC
209 * @tc.require:
210 */
211 HWTEST_F(InputEventHandlerTest, InputEventHandler_UpdateDwtTouchpadRecord_003, TestSize.Level1)
212 {
213 CALL_DEBUG_ENTER;
214 std::shared_ptr<InputEventHandler> inputEventHandler = std::make_shared<InputEventHandler>();
215 NiceMock<LibinputInterfaceMock> libinputMock;
216 libinput_event_touch touchpadEvent;
217 libinput_event event;
218 libinput_device touchpadDevice;
219 touchpadEvent.x = InputEventHandler::TOUCHPAD_EDGE_WIDTH_RELEASE + 1;
220 touchpadEvent.y = 0;
221 g_mockLibinputDeviceGetSizeWidth = 1000.0;
222 g_mockLibinputDeviceGetSizeRetrunIntValue = 1;
223 EXPECT_CALL(libinputMock, GetTouchpadEvent).WillRepeatedly(Return(&touchpadEvent));
224 EXPECT_CALL(libinputMock, GetEventType).WillRepeatedly(Return(LIBINPUT_EVENT_TOUCHPAD_MOTION));
225 EXPECT_CALL(libinputMock, GetDevice).WillRepeatedly(Return(&touchpadDevice));
226 ASSERT_NO_FATAL_FAILURE(inputEventHandler->UpdateDwtTouchpadRecord(&event));
227
228 touchpadEvent.x = 2000.0;
229 ASSERT_NO_FATAL_FAILURE(inputEventHandler->UpdateDwtTouchpadRecord(&event));
230
231 touchpadEvent.x = 1.0;
232 ASSERT_NO_FATAL_FAILURE(inputEventHandler->UpdateDwtTouchpadRecord(&event));
233 }
234
235 /**
236 * @tc.name: InputEventHandler_UpdateDwtTouchpadRecord_004
237 * @tc.desc: Test the funcation UpdateDwtTouchpadRecord
238 * @tc.type: FUNC
239 * @tc.require:
240 */
241 HWTEST_F(InputEventHandlerTest, InputEventHandler_UpdateDwtTouchpadRecord_004, TestSize.Level1)
242 {
243 CALL_DEBUG_ENTER;
244 std::shared_ptr<InputEventHandler> inputEventHandler = std::make_shared<InputEventHandler>();
245 NiceMock<LibinputInterfaceMock> libinputMock;
246 libinput_event_touch touchpadEvent;
247 libinput_event event;
248 libinput_device touchpadDevice;
249 g_mockLibinputDeviceGetSizeRetrunIntValue = 1;
250 EXPECT_CALL(libinputMock, GetTouchpadEvent).WillRepeatedly(Return(&touchpadEvent));
251 EXPECT_CALL(libinputMock, GetEventType).WillRepeatedly(Return(LIBINPUT_EVENT_TOUCHPAD_MOTION));
252 EXPECT_CALL(libinputMock, GetDevice).WillRepeatedly(Return(&touchpadDevice));
253 ASSERT_NO_FATAL_FAILURE(inputEventHandler->UpdateDwtTouchpadRecord(&event));
254 }
255
256 /**
257 * @tc.name: InputEventHandler_UpdateDwtKeyboardRecord_001
258 * @tc.desc: Test the funcation UpdateDwtKeyboardRecord
259 * @tc.type: FUNC
260 * @tc.require:
261 */
262 HWTEST_F(InputEventHandlerTest, InputEventHandler_UpdateDwtKeyboardRecord_001, TestSize.Level1)
263 {
264 CALL_DEBUG_ENTER;
265 std::shared_ptr<InputEventHandler> inputEventHandler = std::make_shared<InputEventHandler>();
266 NiceMock<LibinputInterfaceMock> libinputMock;
267 libinput_event_keyboard keyboardEvent;
268 libinput_event event;
269 EXPECT_CALL(libinputMock, LibinputEventKeyboardGetKey).WillOnce(Return(KEY_LEFTCTRL));
270 EXPECT_CALL(libinputMock, LibinputEventGetKeyboardEvent).WillOnce(Return(&keyboardEvent));
271 ASSERT_NO_FATAL_FAILURE(inputEventHandler->UpdateDwtKeyboardRecord(&event));
272 }
273
274 /**
275 * @tc.name: InputEventHandler_UpdateDwtKeyboardRecord_002
276 * @tc.desc: Test the funcation UpdateDwtKeyboardRecord
277 * @tc.type: FUNC
278 * @tc.require:
279 */
280 HWTEST_F(InputEventHandlerTest, InputEventHandler_UpdateDwtKeyboardRecord_002, TestSize.Level1)
281 {
282 CALL_DEBUG_ENTER;
283 std::shared_ptr<InputEventHandler> inputEventHandler = std::make_shared<InputEventHandler>();
284 NiceMock<LibinputInterfaceMock> libinputMock;
285 libinput_event_keyboard keyboardEvent;
286 libinput_event event;
287 uint32_t key = KEY_LEFTCTRL;
288 EXPECT_CALL(libinputMock, LibinputEventGetKeyboardEvent).WillOnce(Return(&keyboardEvent));
289 EXPECT_CALL(libinputMock, LibinputEventKeyboardGetKey).WillOnce(Return(key));
290 EXPECT_CALL(libinputMock, LibinputEventKeyboardGetKeyState).WillOnce(Return(LIBINPUT_KEY_STATE_PRESSED));
291 inputEventHandler->modifierPressedCount_ = 10;
292 ASSERT_NO_FATAL_FAILURE(inputEventHandler->UpdateDwtKeyboardRecord(&event));
293 EXPECT_TRUE(inputEventHandler->isKeyPressedWithAnyModifiers_[key]);
294 }
295
296 /**
297 * @tc.name: InputEventHandler_UpdateDwtKeyboardRecord_003
298 * @tc.desc: Test the funcation UpdateDwtKeyboardRecord
299 * @tc.type: FUNC
300 * @tc.require:
301 */
302 HWTEST_F(InputEventHandlerTest, InputEventHandler_UpdateDwtKeyboardRecord_003, TestSize.Level1)
303 {
304 CALL_DEBUG_ENTER;
305 std::shared_ptr<InputEventHandler> inputEventHandler = std::make_shared<InputEventHandler>();
306 NiceMock<LibinputInterfaceMock> libinputMock;
307 libinput_event_keyboard keyboardEvent;
308 libinput_event event;
309 uint32_t key = KEY_LEFTCTRL;
310 EXPECT_CALL(libinputMock, LibinputEventGetKeyboardEvent).WillRepeatedly(Return(&keyboardEvent));
311 EXPECT_CALL(libinputMock, LibinputEventKeyboardGetKey).WillRepeatedly(Return(key));
312 EXPECT_CALL(libinputMock, LibinputEventKeyboardGetKeyState)
313 .WillOnce(Return(LIBINPUT_KEY_STATE_PRESSED))
314 .WillOnce(Return(LIBINPUT_KEY_STATE_PRESSED))
315 .WillOnce(Return(LIBINPUT_KEY_STATE_RELEASED))
316 .WillOnce(Return(LIBINPUT_KEY_STATE_RELEASED));
317 inputEventHandler->modifierPressedCount_ = 10;
318 ASSERT_NO_FATAL_FAILURE(inputEventHandler->UpdateDwtKeyboardRecord(&event));
319 EXPECT_TRUE(inputEventHandler->isKeyPressedWithAnyModifiers_[key]);
320
321 inputEventHandler->modifierPressedCount_ = 0;
322 ASSERT_NO_FATAL_FAILURE(inputEventHandler->UpdateDwtKeyboardRecord(&event));
323 EXPECT_TRUE(inputEventHandler->isKeyPressedWithAnyModifiers_[key]);
324
325 ASSERT_NO_FATAL_FAILURE(inputEventHandler->UpdateDwtKeyboardRecord(&event));
326 EXPECT_FALSE(inputEventHandler->isKeyPressedWithAnyModifiers_[key]);
327
328 ASSERT_NO_FATAL_FAILURE(inputEventHandler->UpdateDwtKeyboardRecord(&event));
329 EXPECT_FALSE(inputEventHandler->isKeyPressedWithAnyModifiers_[key]);
330 }
331
332 /**
333 * @tc.name: InputEventHandler_IsStandaloneFunctionKey_001
334 * @tc.desc: Test the funcation IsStandaloneFunctionKey
335 * @tc.type: FUNC
336 * @tc.require:
337 */
338 HWTEST_F(InputEventHandlerTest, InputEventHandler_IsStandaloneFunctionKey_001, TestSize.Level1)
339 {
340 CALL_DEBUG_ENTER;
341 std::shared_ptr<InputEventHandler> inputEventHandler = std::make_shared<InputEventHandler>();
342 uint32_t keycode = KEY_ESC;
343 EXPECT_TRUE(inputEventHandler->IsStandaloneFunctionKey(keycode));
344 }
345
346 /**
347 * @tc.name: InputEventHandler_IsStandaloneFunctionKey_002
348 * @tc.desc: Test the funcation IsStandaloneFunctionKey
349 * @tc.type: FUNC
350 * @tc.require:
351 */
352 HWTEST_F(InputEventHandlerTest, InputEventHandler_IsStandaloneFunctionKey_002, TestSize.Level1)
353 {
354 CALL_DEBUG_ENTER;
355 std::shared_ptr<InputEventHandler> inputEventHandler = std::make_shared<InputEventHandler>();
356 uint32_t keycode = 0;
357 EXPECT_FALSE(inputEventHandler->IsStandaloneFunctionKey(keycode));
358 }
359
360 /**
361 * @tc.name: InputEventHandler_IsTouchpadMistouch_001
362 * @tc.desc: Test the funcation IsTouchpadMistouch
363 * @tc.type: FUNC
364 * @tc.require:
365 */
366 HWTEST_F(InputEventHandlerTest, InputEventHandler_IsTouchpadMistouch_001, TestSize.Level1)
367 {
368 CALL_DEBUG_ENTER;
369 std::shared_ptr<InputEventHandler> inputEventHandler = std::make_shared<InputEventHandler>();
370 libinput_event event;
371 libinput_event_touch touchpadEvent;
372 NiceMock<LibinputInterfaceMock> libinputMock;
373 EXPECT_CALL(libinputMock, GetEventType)
374 .WillOnce(Return(LIBINPUT_EVENT_TOUCHPAD_MOTION))
375 .WillOnce(Return(LIBINPUT_EVENT_TABLET_TOOL_TIP))
376 .WillOnce(Return(LIBINPUT_EVENT_POINTER_BUTTON_TOUCHPAD))
377 .WillOnce(Return(LIBINPUT_EVENT_POINTER_TAP))
378 .WillOnce(Return(LIBINPUT_EVENT_POINTER_MOTION_TOUCHPAD));
379 EXPECT_CALL(libinputMock, GetTouchpadEvent).WillRepeatedly(Return(&touchpadEvent));
380 EXPECT_CALL(libinputMock, TouchpadGetTool).WillOnce(Return(MT_TOOL_PALM)).WillRepeatedly(Return(MT_TOOL_PEN));
381 inputEventHandler->isDwtEdgeAreaForTouchpadMotionActing_ = false;
382 EXPECT_FALSE(inputEventHandler->IsTouchpadMistouch(&event));
383
384 EXPECT_FALSE(inputEventHandler->IsTouchpadMistouch(&event));
385
386 EXPECT_CALL(libinputMock, LibinputGetPointerEvent).WillRepeatedly(Return(nullptr));
387 EXPECT_FALSE(inputEventHandler->IsTouchpadMistouch(&event));
388
389 EXPECT_FALSE(inputEventHandler->IsTouchpadMistouch(&event));
390
391 inputEventHandler->isDwtEdgeAreaForTouchpadMotionActing_ = false;
392 EXPECT_FALSE(inputEventHandler->IsTouchpadMistouch(&event));
393 }
394
395 /**
396 * @tc.name: InputEventHandler_IsTouchpadButtonMistouch_001
397 * @tc.desc: Test the funcation IsTouchpadButtonMistouch
398 * @tc.type: FUNC
399 * @tc.require:
400 */
401 HWTEST_F(InputEventHandlerTest, InputEventHandler_IsTouchpadButtonMistouch_001, TestSize.Level1)
402 {
403 CALL_DEBUG_ENTER;
404 std::shared_ptr<InputEventHandler> inputEventHandler = std::make_shared<InputEventHandler>();
405 libinput_event event;
406 libinput_device touchpadDevice;
407 libinput_event_pointer touchpadButtonEvent;
408 touchpadButtonEvent.buttonState = LIBINPUT_BUTTON_STATE_PRESSED;
409 NiceMock<LibinputInterfaceMock> libinputMock;
410 EXPECT_CALL(libinputMock, LibinputGetPointerEvent).WillRepeatedly(Return(&touchpadButtonEvent));
411 EXPECT_CALL(libinputMock, GetDevice).WillRepeatedly(Return(&touchpadDevice));
412 EXPECT_CALL(libinputMock, DeviceGetSize).WillOnce(Return(1)).WillRepeatedly(Return(0));
413 g_mockLibinputDeviceGetSizeRetrunIntValue = 1;
414 inputEventHandler->isDwtEdgeAreaForTouchpadButtonActing_ = true;
415 inputEventHandler->touchpadEventAbsX_ = InputEventHandler::TOUCHPAD_EDGE_WIDTH_FOR_BUTTON;
416 EXPECT_FALSE(inputEventHandler->IsTouchpadButtonMistouch(&event));
417
418 g_mockLibinputDeviceGetSizeRetrunIntValue = 0;
419 inputEventHandler->touchpadEventAbsX_ = InputEventHandler::TOUCHPAD_EDGE_WIDTH_FOR_BUTTON + 1;
420 EXPECT_TRUE(inputEventHandler->IsTouchpadButtonMistouch(&event));
421
422 inputEventHandler->isDwtEdgeAreaForTouchpadButtonActing_ = false;
423 EXPECT_FALSE(inputEventHandler->IsTouchpadButtonMistouch(&event));
424
425 touchpadButtonEvent.buttonState = LIBINPUT_BUTTON_STATE_RELEASED;
426 inputEventHandler->isButtonMistouch_ = true;
427 EXPECT_TRUE(inputEventHandler->IsTouchpadButtonMistouch(&event));
428
429 EXPECT_FALSE(inputEventHandler->IsTouchpadButtonMistouch(&event));
430 }
431
432 /**
433 * @tc.name: InputEventHandler_IsTouchpadTapMistouch_001
434 * @tc.desc: Test the funcation IsTouchpadTapMistouch
435 * @tc.type: FUNC
436 * @tc.require:
437 */
438 HWTEST_F(InputEventHandlerTest, InputEventHandler_IsTouchpadTapMistouch_001, TestSize.Level1)
439 {
440 CALL_DEBUG_ENTER;
441 std::shared_ptr<InputEventHandler> inputEventHandler = std::make_shared<InputEventHandler>();
442 libinput_event event;
443 libinput_event_pointer touchpadButtonEvent;
444 libinput_device touchpadDevice;
445 touchpadButtonEvent.buttonState = LIBINPUT_BUTTON_STATE_PRESSED;
446 g_mockLibinputDeviceGetSizeRetrunIntValue = 1;
447 NiceMock<LibinputInterfaceMock> libinputMock;
448 EXPECT_CALL(libinputMock, LibinputGetPointerEvent).WillRepeatedly(Return(&touchpadButtonEvent));
449 EXPECT_CALL(libinputMock, GetDevice).WillRepeatedly(Return(&touchpadDevice));
450 EXPECT_FALSE(inputEventHandler->IsTouchpadTapMistouch(&event));
451
452 g_mockLibinputDeviceGetSizeRetrunIntValue = 0;
453 g_mockLibinputDeviceGetSizeWidth = 1000.0;
454 inputEventHandler->touchpadEventDownAbsX_ = InputEventHandler::TOUCHPAD_EDGE_WIDTH_FOR_TAP;
455 inputEventHandler->isDwtEdgeAreaForTouchpadTapActing_ = true;
456 EXPECT_TRUE(inputEventHandler->IsTouchpadTapMistouch(&event));
457
458 inputEventHandler->isDwtEdgeAreaForTouchpadTapActing_ = false;
459 EXPECT_FALSE(inputEventHandler->IsTouchpadTapMistouch(&event));
460
461 touchpadButtonEvent.buttonState = LIBINPUT_BUTTON_STATE_RELEASED;
462 inputEventHandler->isTapMistouch_ = true;
463 EXPECT_TRUE(inputEventHandler->IsTouchpadTapMistouch(&event));
464
465 inputEventHandler->isTapMistouch_ = false;
466 EXPECT_FALSE(inputEventHandler->IsTouchpadTapMistouch(&event));
467 }
468
469 /**
470 * @tc.name: InputEventHandler_IsTouchpadMotionMistouch_001
471 * @tc.desc: Test the funcation IsTouchpadMotionMistouch
472 * @tc.type: FUNC
473 * @tc.require:
474 */
475 HWTEST_F(InputEventHandlerTest, InputEventHandler_IsTouchpadMotionMistouch_001, TestSize.Level1)
476 {
477 CALL_DEBUG_ENTER;
478 std::shared_ptr<InputEventHandler> inputEventHandler = std::make_shared<InputEventHandler>();
479 libinput_event event;
480 inputEventHandler->isDwtEdgeAreaForTouchpadMotionActing_ = false;
481 EXPECT_FALSE(inputEventHandler->IsTouchpadMotionMistouch(&event));
482
483 inputEventHandler->isDwtEdgeAreaForTouchpadMotionActing_ = true;
484 libinput_event_touch touchpadEvent;
485 libinput_device touchpadDevice;
486 NiceMock<LibinputInterfaceMock> libinputMock;
487 EXPECT_CALL(libinputMock, GetTouchpadEvent).WillRepeatedly(Return(&touchpadEvent));
488 EXPECT_CALL(libinputMock, GetDevice).WillRepeatedly(Return(&touchpadDevice));
489 EXPECT_CALL(libinputMock, DeviceGetSize).WillOnce(Return(1))
490 .WillOnce(DoAll(SetArgPointee<1>(InputEventHandler::TOUCHPAD_EDGE_WIDTH), Return(0)))
491 .WillRepeatedly(DoAll(SetArgPointee<1>(1000.0), Return(0)));
492 g_mockLibinputDeviceGetSizeRetrunIntValue = 1;
493 inputEventHandler->touchpadEventDownAbsX_ = InputEventHandler::TOUCHPAD_EDGE_WIDTH;
494 EXPECT_FALSE(inputEventHandler->IsTouchpadMotionMistouch(&event));
495
496 g_mockLibinputDeviceGetSizeRetrunIntValue = 0;
497 g_mockLibinputDeviceGetSizeWidth = InputEventHandler::TOUCHPAD_EDGE_WIDTH;
498 inputEventHandler->touchpadEventDownAbsX_ = InputEventHandler::TOUCHPAD_EDGE_WIDTH + 1;
499 EXPECT_TRUE(inputEventHandler->IsTouchpadMotionMistouch(&event));
500
501 g_mockLibinputDeviceGetSizeWidth = 1000.0;
502 EXPECT_FALSE(inputEventHandler->IsTouchpadMotionMistouch(&event));
503 }
504
505 /**
506 * @tc.name: InputEventHandler_IsTouchpadPointerMotionMistouch_001
507 * @tc.desc: Test the funcation IsTouchpadPointerMotionMistouch
508 * @tc.type: FUNC
509 * @tc.require:
510 */
511 HWTEST_F(InputEventHandlerTest, InputEventHandler_IsTouchpadPointerMotionMistouch_001, TestSize.Level1)
512 {
513 CALL_DEBUG_ENTER;
514 std::shared_ptr<InputEventHandler> inputEventHandler = std::make_shared<InputEventHandler>();
515 libinput_event event;
516 inputEventHandler->isDwtEdgeAreaForTouchpadMotionActing_ = false;
517 EXPECT_FALSE(inputEventHandler->IsTouchpadPointerMotionMistouch(&event));
518
519 libinput_event_pointer pointerEvent;
520 libinput_device touchpadDevice;
521 NiceMock<LibinputInterfaceMock> libinputMock;
522 inputEventHandler->isDwtEdgeAreaForTouchpadMotionActing_ = true;
523 g_mockLibinputDeviceGetSizeRetrunIntValue = 1;
524 EXPECT_CALL(libinputMock, LibinputGetPointerEvent).WillRepeatedly(Return(&pointerEvent));
525 EXPECT_CALL(libinputMock, GetDevice).WillRepeatedly(Return(&touchpadDevice));
526 EXPECT_CALL(libinputMock, DeviceGetSize).WillOnce(Return(1)).WillOnce(Return(0))
527 .WillOnce(DoAll(SetArgPointee<1>(InputEventHandler::TOUCHPAD_EDGE_WIDTH), Return(0)))
528 .WillRepeatedly(DoAll(SetArgPointee<1>(1000.0), Return(0)));
529 EXPECT_FALSE(inputEventHandler->IsTouchpadPointerMotionMistouch(&event));
530
531 g_mockLibinputDeviceGetSizeRetrunIntValue = 0;
532 inputEventHandler->touchpadEventDownAbsX_ = InputEventHandler::TOUCHPAD_EDGE_WIDTH;
533 EXPECT_TRUE(inputEventHandler->IsTouchpadPointerMotionMistouch(&event));
534
535 g_mockLibinputDeviceGetSizeWidth = InputEventHandler::TOUCHPAD_EDGE_WIDTH;
536 inputEventHandler->touchpadEventDownAbsX_ = InputEventHandler::TOUCHPAD_EDGE_WIDTH + 1;
537 EXPECT_TRUE(inputEventHandler->IsTouchpadPointerMotionMistouch(&event));
538
539 g_mockLibinputDeviceGetSizeWidth = 1000.0;
540 inputEventHandler->touchpadEventDownAbsX_ = InputEventHandler::TOUCHPAD_EDGE_WIDTH + 1;
541 EXPECT_FALSE(inputEventHandler->IsTouchpadPointerMotionMistouch(&event));
542 }
543 } // namespace MMI
544 } // namespace OHOS
545