1 /*
2 * Copyright (c) 2023 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 <gtest/gtest.h>
18 #include <libinput.h>
19
20 #include "define_multimodal.h"
21 #include "general_touchpad.h"
22 #include "input_device_manager.h"
23 #include "libinput_wrapper.h"
24 #include "touchpad_transform_processor.h"
25
26 #undef MMI_LOG_TAG
27 #define MMI_LOG_TAG "TouchPadTransformProcessorTest"
28
29 namespace OHOS {
30 namespace MMI {
31 namespace {
32 using namespace testing::ext;
33 } // namespace
34 class TouchPadTransformProcessorTest : public testing::Test {
35 public:
36 static void SetUpTestCase(void);
37 static void TearDownTestCase(void);
38 void SetUp();
39 void TearDown();
40
41 private:
42 static void SetupTouchpad();
43 static void CloseTouchpad();
44
45 static GeneralTouchpad vTouchpad_;
46 static LibinputWrapper libinput_;
47 int32_t trackingID_ { 0 };
48
49 TouchPadTransformProcessor g_processor_ { 0 };
50 bool prePinchSwitch_ { true };
51 bool preSwipeSwitch_ { true };
52 bool preRotateSwitch_ { true };
53 bool preDoubleTapDragSwitch_ { true };
54 };
55
56 GeneralTouchpad TouchPadTransformProcessorTest::vTouchpad_;
57 LibinputWrapper TouchPadTransformProcessorTest::libinput_;
58
SetUpTestCase(void)59 void TouchPadTransformProcessorTest::SetUpTestCase(void)
60 {
61 ASSERT_TRUE(libinput_.Init());
62 SetupTouchpad();
63 }
64
TearDownTestCase(void)65 void TouchPadTransformProcessorTest::TearDownTestCase(void)
66 {
67 CloseTouchpad();
68 }
69
SetupTouchpad()70 void TouchPadTransformProcessorTest::SetupTouchpad()
71 {
72 ASSERT_TRUE(vTouchpad_.SetUp());
73 std::cout << "device node name: " << vTouchpad_.GetDevPath() << std::endl;
74 ASSERT_TRUE(libinput_.AddPath(vTouchpad_.GetDevPath()));
75
76 libinput_event *event = libinput_.Dispatch();
77 ASSERT_TRUE(event != nullptr);
78 ASSERT_EQ(libinput_event_get_type(event), LIBINPUT_EVENT_DEVICE_ADDED);
79 struct libinput_device *device = libinput_event_get_device(event);
80 ASSERT_TRUE(device != nullptr);
81 INPUT_DEV_MGR->OnInputDeviceAdded(device);
82 }
83
CloseTouchpad()84 void TouchPadTransformProcessorTest::CloseTouchpad()
85 {
86 libinput_.RemovePath(vTouchpad_.GetDevPath());
87 vTouchpad_.Close();
88 }
89
SetUp()90 void TouchPadTransformProcessorTest::SetUp()
91 {
92 g_processor_.GetTouchpadPinchSwitch(prePinchSwitch_);
93 g_processor_.GetTouchpadSwipeSwitch(preSwipeSwitch_);
94 g_processor_.GetTouchpadRotateSwitch(preRotateSwitch_);
95 g_processor_.GetTouchpadDoubleTapAndDragState(preDoubleTapDragSwitch_);
96 }
97
TearDown()98 void TouchPadTransformProcessorTest::TearDown()
99 {
100 g_processor_.SetTouchpadPinchSwitch(prePinchSwitch_);
101 g_processor_.SetTouchpadSwipeSwitch(preSwipeSwitch_);
102 g_processor_.SetTouchpadRotateSwitch(preRotateSwitch_);
103 g_processor_.SetTouchpadDoubleTapAndDragState(preDoubleTapDragSwitch_);
104 }
105
106 /**
107 * @tc.name: TouchPadTransformProcessorTest_SetTouchpadPinchSwitch_01
108 * @tc.desc: Test SetTouchpadPinchSwitch
109 * @tc.type: FUNC
110 * @tc.require:
111 */
112 HWTEST_F(TouchPadTransformProcessorTest, TouchPadTransformProcessorTest_SetTouchpadPinchSwitch_01, TestSize.Level1)
113 {
114 CALL_TEST_DEBUG;
115 int32_t deviceId = 6;
116 TouchPadTransformProcessor processor(deviceId);
117 bool flag = false;
118 ASSERT_TRUE(processor.SetTouchpadPinchSwitch(flag) == RET_OK);
119 }
120
121 /**
122 * @tc.name: TouchPadTransformProcessorTest_GetTouchpadPinchSwitch_02
123 * @tc.desc: Test GetTouchpadPinchSwitch
124 * @tc.type: FUNC
125 * @tc.require:
126 */
127 HWTEST_F(TouchPadTransformProcessorTest, TouchPadTransformProcessorTest_GetTouchpadPinchSwitch_02, TestSize.Level1)
128 {
129 CALL_TEST_DEBUG;
130 int32_t deviceId = 6;
131 TouchPadTransformProcessor processor(deviceId);
132 bool flag = false;
133 processor.SetTouchpadPinchSwitch(flag);
134 bool newFlag = false;
135 processor.GetTouchpadPinchSwitch(flag);
136 ASSERT_TRUE(flag == newFlag);
137 }
138
139 /**
140 * @tc.name: TouchPadTransformProcessorTest_SetTouchpadSwipeSwitch_03
141 * @tc.desc: Test SetTouchpadSwipeSwitch
142 * @tc.type: FUNC
143 * @tc.require:
144 */
145 HWTEST_F(TouchPadTransformProcessorTest, TouchPadTransformProcessorTest_SetTouchpadSwipeSwitch_03, TestSize.Level1)
146 {
147 CALL_TEST_DEBUG;
148 int32_t deviceId = 6;
149 TouchPadTransformProcessor processor(deviceId);
150 bool flag = false;
151 ASSERT_TRUE(processor.SetTouchpadSwipeSwitch(flag) == RET_OK);
152 }
153
154 /**
155 * @tc.name: TouchPadTransformProcessorTest_GetTouchpadSwipeSwitch_04
156 * @tc.desc: Test GetTouchpadSwipeSwitch
157 * @tc.type: FUNC
158 * @tc.require:
159 */
160 HWTEST_F(TouchPadTransformProcessorTest, TouchPadTransformProcessorTest_GetTouchpadSwipeSwitch_04, TestSize.Level1)
161 {
162 CALL_TEST_DEBUG;
163 int32_t deviceId = 6;
164 TouchPadTransformProcessor processor(deviceId);
165 bool flag = false;
166 processor.SetTouchpadSwipeSwitch(flag);
167 bool newFlag = false;
168 processor.GetTouchpadSwipeSwitch(flag);
169 ASSERT_TRUE(flag == newFlag);
170 }
171
172 /**
173 * @tc.name: TouchPadTransformProcessorTest_SetTouchpadRotateSwitch_05
174 * @tc.desc: Test SetTouchpadRotateSwitch
175 * @tc.type: FUNC
176 * @tc.require:
177 */
178 HWTEST_F(TouchPadTransformProcessorTest, TouchPadTransformProcessorTest_SetTouchpadRotateSwitch_05, TestSize.Level1)
179 {
180 CALL_TEST_DEBUG;
181 int32_t deviceId = 6;
182 TouchPadTransformProcessor processor(deviceId);
183 bool rotateSwitch = false;
184 ASSERT_TRUE(processor.SetTouchpadRotateSwitch(rotateSwitch) == RET_OK);
185 }
186
187 /**
188 * @tc.name: TouchPadTransformProcessorTest_GetTouchpadRotateSwitch_06
189 * @tc.desc: Test GetTouchpadRotateSwitch
190 * @tc.type: FUNC
191 * @tc.require:
192 */
193 HWTEST_F(TouchPadTransformProcessorTest, TouchPadTransformProcessorTest_GetTouchpadRotateSwitch_06, TestSize.Level1)
194 {
195 CALL_TEST_DEBUG;
196 int32_t deviceId = 6;
197 TouchPadTransformProcessor processor(deviceId);
198 bool rotateSwitch = false;
199 processor.SetTouchpadRotateSwitch(rotateSwitch);
200 bool newRotateSwitch = false;
201 processor.GetTouchpadRotateSwitch(newRotateSwitch);
202 ASSERT_TRUE(rotateSwitch == newRotateSwitch);
203 }
204
205 /**
206 * @tc.name: TouchPadTransformProcessorTest_SetTouchpadDoubleTapAndDragState_07
207 * @tc.desc: Test SetTouchpadDoubleTapAndDragState
208 * @tc.type: FUNC
209 * @tc.require:
210 */
211 HWTEST_F(TouchPadTransformProcessorTest, TouchPadTransformProcessorTest_SetTouchpadDoubleTapAndDragState_07,
212 TestSize.Level1)
213 {
214 CALL_TEST_DEBUG;
215 int32_t deviceId = 6;
216 TouchPadTransformProcessor processor(deviceId);
217 bool flag = false;
218 ASSERT_TRUE(processor.SetTouchpadDoubleTapAndDragState(flag) == RET_OK);
219 }
220
221 /**
222 * @tc.name: TouchPadTransformProcessorTest_GetTouchpadDoubleTapAndDragState_08
223 * @tc.desc: Test GetTouchpadDoubleTapAndDragState
224 * @tc.type: FUNC
225 * @tc.require:
226 */
227 HWTEST_F(TouchPadTransformProcessorTest, TouchPadTransformProcessorTest_GetTouchpadDoubleTapAndDragState_08,
228 TestSize.Level1)
229 {
230 CALL_TEST_DEBUG;
231 int32_t deviceId = 6;
232 TouchPadTransformProcessor processor(deviceId);
233 bool flag = false;
234 processor.SetTouchpadDoubleTapAndDragState(flag);
235 bool newFlag = false;
236 processor.GetTouchpadDoubleTapAndDragState(newFlag);
237 ASSERT_TRUE(flag == newFlag);
238 }
239
240 /**
241 * @tc.name: TouchPadTransformProcessorTest_SetTouchPadMultiTapData
242 * @tc.desc: Test SetTouchPadMultiTapData
243 * @tc.type: FUNC
244 * @tc.require:
245 */
246 HWTEST_F(TouchPadTransformProcessorTest, TouchPadTransformProcessorTest_SetTouchPadMultiTapData, TestSize.Level1)
247 {
248 CALL_TEST_DEBUG;
249 int32_t deviceId = 6;
250 TouchPadTransformProcessor processor(deviceId);
251 processor.pointerEvent_ = PointerEvent::Create();
252 ASSERT_NE(processor.pointerEvent_, nullptr);
253 ASSERT_NO_FATAL_FAILURE(processor.SetTouchPadMultiTapData());
254 }
255
256 /**
257 * @tc.name: TouchPadTransformProcessorTest_ProcessTouchPadPinchDataEvent
258 * @tc.desc: Test ProcessTouchPadPinchDataEvent
259 * @tc.type: FUNC
260 * @tc.require:
261 */
262 HWTEST_F(TouchPadTransformProcessorTest, TouchPadTransformProcessorTest_ProcessTouchPadPinchDataEvent, TestSize.Level1)
263 {
264 CALL_TEST_DEBUG;
265 int32_t deviceId = 6;
266 TouchPadTransformProcessor processor(deviceId);
267 int32_t fingerCount = 2;
268 int32_t action = PointerEvent::POINTER_ACTION_AXIS_BEGIN;
269 double scale = 8.5;
270 double angle = 8.5;
271 processor.pointerEvent_ = PointerEvent::Create();
272 ASSERT_NE(processor.pointerEvent_, nullptr);
273 processor.pointerEvent_->SetFingerCount(2);
274 ASSERT_NO_FATAL_FAILURE(processor.ProcessTouchPadPinchDataEvent(fingerCount, action, scale, angle));
275
276 fingerCount = 1;
277 processor.pointerEvent_->SetFingerCount(1);
278 ASSERT_NO_FATAL_FAILURE(processor.ProcessTouchPadPinchDataEvent(fingerCount, action, scale, angle));
279
280 fingerCount = 3;
281 ASSERT_NO_FATAL_FAILURE(processor.ProcessTouchPadPinchDataEvent(fingerCount, action, scale, angle));
282 }
283
284 /**
285 * @tc.name: TouchPadTransformProcessorTest_HandleMulFingersTap_001
286 * @tc.desc: Verify if the multi-touch gesture handling is correct
287 * @tc.type: FUNC
288 * @tc.require:
289 */
290 HWTEST_F(TouchPadTransformProcessorTest, TouchPadTransformProcessorTest_HandleMulFingersTap_001, TestSize.Level1)
291 {
292 CALL_TEST_DEBUG;
293 MultiFingersTapHandler processor;
294 libinput_event_touch *event = nullptr;
295 int32_t type = 1;
296 auto ret = processor.HandleMulFingersTap(event, type);
297 ASSERT_EQ(ret, RET_ERR);
298 ASSERT_NO_FATAL_FAILURE(processor.GetMultiFingersState());
299 }
300
301 /**
302 * @tc.name: TouchPadTransformProcessorTest_SetMULTI_FINGERTAP_HDRDefault_001
303 * @tc.desc: Test the behavior of SetMULTI_FINGERTAP_HDRDefault
304 * @tc.type: FUNC
305 * @tc.require:
306 */
307 HWTEST_F(TouchPadTransformProcessorTest, SetMULTI_FINGERTAP_HDRDefault_001, TestSize.Level1)
308 {
309 CALL_TEST_DEBUG;
310 MultiFingersTapHandler processor;
311 bool isAlldefault = true;
312 ASSERT_NO_FATAL_FAILURE(processor.SetMultiFingersTapHdrDefault(isAlldefault));
313 isAlldefault = false;
314 ASSERT_NO_FATAL_FAILURE(processor.SetMultiFingersTapHdrDefault(isAlldefault));
315 }
316
317 /**
318 * @tc.name: TouchPadTransformProcessorTest_ClearPointerItems_001
319 * @tc.desc: Verifying the ability to correctly clear pointer items under given conditions
320 * @tc.type: FUNC
321 * @tc.require:
322 */
323 HWTEST_F(TouchPadTransformProcessorTest, TouchPadTransformProcessorTest_ClearPointerItems_001, TestSize.Level1)
324 {
325 CALL_TEST_DEBUG;
326 MultiFingersTapHandler processor;
327 auto pointer = PointerEvent::Create();
328 bool ret = processor.ClearPointerItems(pointer);
329 ASSERT_TRUE(ret);
330 }
331
332 /**
333 * @tc.name: TouchPadTransformProcessorTest_PutConfigDataToDatabase_001
334 * @tc.desc: Verify if the function of storing configuration data to the database works correctly
335 * @tc.type: FUNC
336 * @tc.require:
337 */
338 HWTEST_F(TouchPadTransformProcessorTest, TouchPadTransformProcessorTest_PutConfigDataToDatabase_001, TestSize.Level1)
339 {
340 CALL_TEST_DEBUG;
341 int32_t deviceId = 6;
342 TouchPadTransformProcessor processor(deviceId);
343 std::string key = "testKey";
344 bool value = true;
345 int32_t ret = processor.PutConfigDataToDatabase(key, value);
346 ASSERT_EQ(ret, RET_OK);
347 }
348
349 /**
350 * @tc.name: TouchPadTransformProcessorTest_PutConfigDataToDatabase_002
351 * @tc.desc: Verify if the function of storing configuration data to the database works correctly
352 * @tc.type: FUNC
353 * @tc.require:
354 */
355 HWTEST_F(TouchPadTransformProcessorTest, TouchPadTransformProcessorTest_PutConfigDataToDatabase_002, TestSize.Level1)
356 {
357 CALL_TEST_DEBUG;
358 int32_t deviceId = 6;
359 TouchPadTransformProcessor processor(deviceId);
360 std::string key = "testKey";
361 bool value = false;
362 int32_t ret = processor.PutConfigDataToDatabase(key, value);
363 ASSERT_EQ(ret, RET_OK);
364 }
365
366 /**
367 * @tc.name: TouchPadTransformProcessorTest_GetConfigDataFromDatabase_001
368 * @tc.desc: Verify if the functionality of getting configuration data from the database works correctly
369 * @tc.type: FUNC
370 * @tc.require:
371 */
372 HWTEST_F(TouchPadTransformProcessorTest, TouchPadTransformProcessorTest_GetConfigDataFromDatabase_001, TestSize.Level1)
373 {
374 CALL_TEST_DEBUG;
375 int32_t deviceId = 6;
376 TouchPadTransformProcessor processor(deviceId);
377 std::string key = "testKey";
378 bool value = false;
379 ASSERT_NO_FATAL_FAILURE(processor.GetConfigDataFromDatabase(key, value));
380 }
381
382 /**
383 * @tc.name: TouchPadTransformProcessorTest_GetConfigDataFromDatabase_002
384 * @tc.desc: Test the GetConfigDataFromDatabase method of the TouchPadTransformProcessor class
385 * @tc.type: FUNC
386 * @tc.require:
387 */
388 HWTEST_F(TouchPadTransformProcessorTest, TouchPadTransformProcessorTest_GetConfigDataFromDatabase_002, TestSize.Level1)
389 {
390 CALL_TEST_DEBUG;
391 int32_t deviceId = 6;
392 TouchPadTransformProcessor processor(deviceId);
393 std::string key = "testKey";
394 bool value = true;
395 ASSERT_NO_FATAL_FAILURE(processor.GetConfigDataFromDatabase(key, value));
396 }
397
398 /**
399 * @tc.name: TouchPadTransformProcessorTest_OnEventTouchPadDown_001
400 * @tc.desc: Verify the correctness of touchpad down event processing
401 * @tc.type: FUNC
402 * @tc.require:
403 */
404 HWTEST_F(TouchPadTransformProcessorTest, TouchPadTransformProcessorTest_OnEventTouchPadDown_001, TestSize.Level1)
405 {
406 CALL_TEST_DEBUG;
407 vTouchpad_.SendEvent(EV_ABS, ABS_MT_TRACKING_ID, ++trackingID_);
408 vTouchpad_.SendEvent(EV_ABS, ABS_MT_POSITION_X, 2220);
409 vTouchpad_.SendEvent(EV_ABS, ABS_MT_POSITION_Y, 727);
410 vTouchpad_.SendEvent(EV_ABS, ABS_MT_TOOL_TYPE, 2);
411 vTouchpad_.SendEvent(EV_SYN, SYN_REPORT, 0);
412 vTouchpad_.SendEvent(EV_ABS, ABS_MT_POSITION_Y, 710);
413 vTouchpad_.SendEvent(EV_SYN, SYN_REPORT, 0);
414
415 libinput_event *event = libinput_.Dispatch();
416 ASSERT_TRUE(event != nullptr);
417 struct libinput_device *dev = libinput_event_get_device(event);
418 ASSERT_TRUE(dev != nullptr);
419 std::cout << "touchpad device: " << libinput_device_get_name(dev) << std::endl;
420 auto iter = INPUT_DEV_MGR->inputDevice_.begin();
421 for (; iter != INPUT_DEV_MGR->inputDevice_.end(); ++iter) {
422 if (iter->second.inputDeviceOrigin == dev) {
423 break;
424 }
425 }
426 ASSERT_TRUE(iter != INPUT_DEV_MGR->inputDevice_.end());
427 int32_t deviceId = iter->first;
428 TouchPadTransformProcessor processor(deviceId);
429 processor.pointerEvent_ = PointerEvent::Create();
430 int32_t ret = processor.OnEventTouchPadDown(event);
431 ASSERT_EQ(ret, RET_OK);
432 }
433
434 /**
435 * @tc.name: TouchPadTransformProcessorTest_OnEventTouchPadMotion_001
436 * @tc.desc: Test the ability of the touchpad motion event processing function to handle normal input situations
437 * @tc.type: FUNC
438 * @tc.require:
439 */
440 HWTEST_F(TouchPadTransformProcessorTest, TouchPadTransformProcessorTest_OnEventTouchPadMotion_001, TestSize.Level1)
441 {
442 CALL_TEST_DEBUG;
443 vTouchpad_.SendEvent(EV_ABS, ABS_MT_TRACKING_ID, ++trackingID_);
444 vTouchpad_.SendEvent(EV_ABS, ABS_MT_POSITION_X, 2220);
445 vTouchpad_.SendEvent(EV_ABS, ABS_MT_POSITION_Y, 727);
446 vTouchpad_.SendEvent(EV_ABS, ABS_MT_TOOL_TYPE, 2);
447 vTouchpad_.SendEvent(EV_SYN, SYN_REPORT, 0);
448 vTouchpad_.SendEvent(EV_ABS, ABS_MT_POSITION_Y, 710);
449 vTouchpad_.SendEvent(EV_SYN, SYN_REPORT, 0);
450
451 libinput_event *event = libinput_.Dispatch();
452 ASSERT_TRUE(event != nullptr);
453 struct libinput_device *dev = libinput_event_get_device(event);
454 ASSERT_TRUE(dev != nullptr);
455 std::cout << "touchpad device: " << libinput_device_get_name(dev) << std::endl;
456 auto iter = INPUT_DEV_MGR->inputDevice_.begin();
457 for (; iter != INPUT_DEV_MGR->inputDevice_.end(); ++iter) {
458 if (iter->second.inputDeviceOrigin == dev) {
459 break;
460 }
461 }
462 ASSERT_TRUE(iter != INPUT_DEV_MGR->inputDevice_.end());
463 int32_t deviceId = iter->first;
464 TouchPadTransformProcessor processor(deviceId);
465 processor.pointerEvent_ = PointerEvent::Create();
466 ASSERT_TRUE(processor.pointerEvent_ != nullptr);
467 int32_t ret = processor.OnEventTouchPadMotion(event);
468 ASSERT_EQ(ret, RET_ERR);
469 }
470
471 /**
472 * @tc.name: TouchPadTransformProcessorTest_OnEventTouchPadMotion_002
473 * @tc.desc: Test the ability of the touchpad motion event processing function to handle normal input situations
474 * @tc.type: FUNC
475 * @tc.require:
476 */
477 HWTEST_F(TouchPadTransformProcessorTest, TouchPadTransformProcessorTest_OnEventTouchPadMotion_002, TestSize.Level1)
478 {
479 CALL_TEST_DEBUG;
480 vTouchpad_.SendEvent(EV_ABS, ABS_MT_TRACKING_ID, ++trackingID_);
481 vTouchpad_.SendEvent(EV_ABS, ABS_MT_POSITION_X, 2220);
482 vTouchpad_.SendEvent(EV_ABS, ABS_MT_POSITION_Y, 727);
483 vTouchpad_.SendEvent(EV_ABS, ABS_MT_TOOL_TYPE, 2);
484 vTouchpad_.SendEvent(EV_SYN, SYN_REPORT, 0);
485 vTouchpad_.SendEvent(EV_ABS, ABS_MT_POSITION_Y, 710);
486 vTouchpad_.SendEvent(EV_SYN, SYN_REPORT, 0);
487
488 libinput_event *event = libinput_.Dispatch();
489 ASSERT_TRUE(event != nullptr);
490 struct libinput_device *dev = libinput_event_get_device(event);
491 ASSERT_TRUE(dev != nullptr);
492 std::cout << "touchpad device: " << libinput_device_get_name(dev) << std::endl;
493 auto iter = INPUT_DEV_MGR->inputDevice_.begin();
494 for (; iter != INPUT_DEV_MGR->inputDevice_.end(); ++iter) {
495 if (iter->second.inputDeviceOrigin == dev) {
496 break;
497 }
498 }
499 ASSERT_TRUE(iter != INPUT_DEV_MGR->inputDevice_.end());
500 int32_t deviceId = iter->first;
501 TouchPadTransformProcessor processor(deviceId);
502 processor.pointerEvent_ = PointerEvent::Create();
503 ASSERT_TRUE(processor.pointerEvent_ != nullptr);
504 PointerEvent::PointerItem item;
505 item.SetPointerId(0);
506 processor.pointerEvent_->UpdatePointerItem(0, item);
507 int32_t ret = processor.OnEventTouchPadMotion(event);
508 ASSERT_EQ(ret, RET_OK);
509 }
510
511 /**
512 * @tc.name: TouchPadTransformProcessorTest_OnEventTouchPadUp_001
513 * @tc.desc: Verify the correctness of touchpad up event processing
514 * @tc.type: FUNC
515 * @tc.require:
516 */
517 HWTEST_F(TouchPadTransformProcessorTest, TouchPadTransformProcessorTest_OnEventTouchPadUp_001, TestSize.Level1)
518 {
519 CALL_TEST_DEBUG;
520 vTouchpad_.SendEvent(EV_ABS, ABS_MT_TRACKING_ID, ++trackingID_);
521 vTouchpad_.SendEvent(EV_ABS, ABS_MT_POSITION_X, 2220);
522 vTouchpad_.SendEvent(EV_ABS, ABS_MT_POSITION_Y, 727);
523 vTouchpad_.SendEvent(EV_ABS, ABS_MT_TOOL_TYPE, 2);
524 vTouchpad_.SendEvent(EV_SYN, SYN_REPORT, 0);
525 vTouchpad_.SendEvent(EV_ABS, ABS_MT_POSITION_Y, 710);
526 vTouchpad_.SendEvent(EV_SYN, SYN_REPORT, 0);
527
528 libinput_event *event = libinput_.Dispatch();
529 ASSERT_TRUE(event != nullptr);
530 struct libinput_device *dev = libinput_event_get_device(event);
531 ASSERT_TRUE(dev != nullptr);
532 std::cout << "touchpad device: " << libinput_device_get_name(dev) << std::endl;
533 auto iter = INPUT_DEV_MGR->inputDevice_.begin();
534 for (; iter != INPUT_DEV_MGR->inputDevice_.end(); ++iter) {
535 if (iter->second.inputDeviceOrigin == dev) {
536 break;
537 }
538 }
539 ASSERT_TRUE(iter != INPUT_DEV_MGR->inputDevice_.end());
540 int32_t deviceId = iter->first;
541 TouchPadTransformProcessor processor(deviceId);
542 processor.pointerEvent_ = PointerEvent::Create();
543 ASSERT_TRUE(processor.pointerEvent_ != nullptr);
544 PointerEvent::PointerItem item;
545 item.SetPointerId(0);
546 processor.pointerEvent_->UpdatePointerItem(0, item);
547 int32_t ret = processor.OnEventTouchPadUp(event);
548 ASSERT_EQ(ret, RET_OK);
549 }
550
551 /**
552 * @tc.name: TouchPadTransformProcessorTest_OnEventTouchPadUp_002
553 * @tc.desc: Verify the correctness of touchpad up event processing
554 * @tc.type: FUNC
555 * @tc.require:
556 */
557 HWTEST_F(TouchPadTransformProcessorTest, TouchPadTransformProcessorTest_OnEventTouchPadUp_002, TestSize.Level1)
558 {
559 CALL_TEST_DEBUG;
560 vTouchpad_.SendEvent(EV_ABS, ABS_MT_TRACKING_ID, ++trackingID_);
561 vTouchpad_.SendEvent(EV_ABS, ABS_MT_POSITION_X, 2220);
562 vTouchpad_.SendEvent(EV_ABS, ABS_MT_POSITION_Y, 727);
563 vTouchpad_.SendEvent(EV_ABS, ABS_MT_TOOL_TYPE, 2);
564 vTouchpad_.SendEvent(EV_SYN, SYN_REPORT, 0);
565 vTouchpad_.SendEvent(EV_ABS, ABS_MT_POSITION_Y, 710);
566 vTouchpad_.SendEvent(EV_SYN, SYN_REPORT, 0);
567
568 libinput_event *event = libinput_.Dispatch();
569 ASSERT_TRUE(event != nullptr);
570 struct libinput_device *dev = libinput_event_get_device(event);
571 ASSERT_TRUE(dev != nullptr);
572 std::cout << "touchpad device: " << libinput_device_get_name(dev) << std::endl;
573 auto iter = INPUT_DEV_MGR->inputDevice_.begin();
574 for (; iter != INPUT_DEV_MGR->inputDevice_.end(); ++iter) {
575 if (iter->second.inputDeviceOrigin == dev) {
576 break;
577 }
578 }
579 ASSERT_TRUE(iter != INPUT_DEV_MGR->inputDevice_.end());
580 int32_t deviceId = iter->first;
581 TouchPadTransformProcessor processor(deviceId);
582 processor.pointerEvent_ = PointerEvent::Create();
583 ASSERT_TRUE(processor.pointerEvent_ != nullptr);
584 int32_t ret = processor.OnEventTouchPadUp(event);
585 ASSERT_EQ(ret, RET_ERR);
586 }
587
588 /**
589 * @tc.name: TouchPadTransformProcessorTest_OnEventTouchPadUp_003
590 * @tc.desc: Verify the correctness of touchpad up event processing
591 * @tc.type: FUNC
592 * @tc.require:
593 */
594 HWTEST_F(TouchPadTransformProcessorTest, TouchPadTransformProcessorTest_OnEventTouchPadUp_003, TestSize.Level1)
595 {
596 CALL_TEST_DEBUG;
597 vTouchpad_.SendEvent(EV_ABS, ABS_MT_TRACKING_ID, ++trackingID_);
598 vTouchpad_.SendEvent(EV_ABS, ABS_MT_POSITION_X, 2220);
599 vTouchpad_.SendEvent(EV_ABS, ABS_MT_POSITION_Y, 727);
600 vTouchpad_.SendEvent(EV_ABS, ABS_MT_TOOL_TYPE, 2);
601 vTouchpad_.SendEvent(EV_SYN, SYN_REPORT, 0);
602 vTouchpad_.SendEvent(EV_ABS, ABS_MT_POSITION_Y, 710);
603 vTouchpad_.SendEvent(EV_SYN, SYN_REPORT, 0);
604
605 libinput_event *event = libinput_.Dispatch();
606 ASSERT_TRUE(event != nullptr);
607 struct libinput_device *dev = libinput_event_get_device(event);
608 ASSERT_TRUE(dev != nullptr);
609 std::cout << "touchpad device: " << libinput_device_get_name(dev) << std::endl;
610 auto iter = INPUT_DEV_MGR->inputDevice_.begin();
611 for (; iter != INPUT_DEV_MGR->inputDevice_.end(); ++iter) {
612 if (iter->second.inputDeviceOrigin == dev) {
613 break;
614 }
615 }
616 ASSERT_TRUE(iter != INPUT_DEV_MGR->inputDevice_.end());
617 int32_t deviceId = iter->first;
618 TouchPadTransformProcessor processor(deviceId);
619 processor.pointerEvent_ = PointerEvent::Create();
620 ASSERT_TRUE(processor.pointerEvent_ != nullptr);
621 MULTI_FINGERTAP_HDR->multiFingersState_ = MulFingersTap::TRIPLE_TAP;
622 int32_t ret = processor.OnEventTouchPadUp(event);
623 ASSERT_EQ(ret, RET_ERR);
624 }
625
626 /**
627 * @tc.name: TouchPadTransformProcessorTest_OnEvent_001
628 * @tc.desc: test OnEvent
629 * @tc.type: FUNC
630 * @tc.require:
631 */
632 HWTEST_F(TouchPadTransformProcessorTest, TouchPadTransformProcessorTest_OnEvent_001, TestSize.Level1)
633 {
634 CALL_TEST_DEBUG;
635 vTouchpad_.SendEvent(EV_ABS, ABS_MT_TRACKING_ID, ++trackingID_);
636 vTouchpad_.SendEvent(EV_ABS, ABS_MT_POSITION_X, 2220);
637 vTouchpad_.SendEvent(EV_ABS, ABS_MT_POSITION_Y, 727);
638 vTouchpad_.SendEvent(EV_ABS, ABS_MT_TOOL_TYPE, 2);
639 vTouchpad_.SendEvent(EV_SYN, SYN_REPORT, 0);
640 vTouchpad_.SendEvent(EV_ABS, ABS_MT_POSITION_Y, 710);
641 vTouchpad_.SendEvent(EV_SYN, SYN_REPORT, 0);
642
643 libinput_event *event = libinput_.Dispatch();
644 ASSERT_TRUE(event != nullptr);
645 struct libinput_device *dev = libinput_event_get_device(event);
646 ASSERT_TRUE(dev != nullptr);
647 std::cout << "touchpad device: " << libinput_device_get_name(dev) << std::endl;
648 auto iter = INPUT_DEV_MGR->inputDevice_.begin();
649 for (; iter != INPUT_DEV_MGR->inputDevice_.end(); ++iter) {
650 if (iter->second.inputDeviceOrigin == dev) {
651 break;
652 }
653 }
654 ASSERT_TRUE(iter != INPUT_DEV_MGR->inputDevice_.end());
655 int32_t deviceId = iter->first;
656 TouchPadTransformProcessor processor(deviceId);
657 auto pointerEvent = processor.OnEvent(event);
658 ASSERT_TRUE(pointerEvent == nullptr);
659 }
660
661 /**
662 * @tc.name: TouchPadTransformProcessorTest_OnEvent_002
663 * @tc.desc: test OnEvent
664 * @tc.type: FUNC
665 * @tc.require:
666 */
667 HWTEST_F(TouchPadTransformProcessorTest, TouchPadTransformProcessorTest_OnEvent_002, TestSize.Level1)
668 {
669 CALL_TEST_DEBUG;
670 vTouchpad_.SendEvent(EV_ABS, ABS_MT_TRACKING_ID, ++trackingID_);
671 vTouchpad_.SendEvent(EV_ABS, ABS_MT_POSITION_X, 2220);
672 vTouchpad_.SendEvent(EV_ABS, ABS_MT_POSITION_Y, 727);
673 vTouchpad_.SendEvent(EV_ABS, ABS_MT_TOOL_TYPE, 2);
674 vTouchpad_.SendEvent(EV_SYN, SYN_REPORT, 0);
675 vTouchpad_.SendEvent(EV_ABS, ABS_MT_POSITION_Y, 710);
676 vTouchpad_.SendEvent(EV_SYN, SYN_REPORT, 0);
677
678 libinput_event *event = libinput_.Dispatch();
679 ASSERT_TRUE(event != nullptr);
680 struct libinput_device *dev = libinput_event_get_device(event);
681 ASSERT_TRUE(dev != nullptr);
682 std::cout << "touchpad device: " << libinput_device_get_name(dev) << std::endl;
683 auto iter = INPUT_DEV_MGR->inputDevice_.begin();
684 for (; iter != INPUT_DEV_MGR->inputDevice_.end(); ++iter) {
685 if (iter->second.inputDeviceOrigin == dev) {
686 break;
687 }
688 }
689 ASSERT_TRUE(iter != INPUT_DEV_MGR->inputDevice_.end());
690 int32_t deviceId = iter->first;
691 TouchPadTransformProcessor processor(deviceId);
692 processor.pointerEvent_ = PointerEvent::Create();
693 ASSERT_TRUE(processor.pointerEvent_ != nullptr);
694 PointerEvent::PointerItem item;
695 item.SetPointerId(0);
696 item.SetDeviceId(deviceId);
697 processor.pointerEvent_->SetDeviceId(deviceId);
698 processor.pointerEvent_->UpdatePointerItem(0, item);
699 auto pointerEvent = processor.OnEvent(event);
700 ASSERT_TRUE(pointerEvent != nullptr);
701 vTouchpad_.SendEvent(EV_ABS, ABS_MT_TRACKING_ID, -1);
702 vTouchpad_.SendEvent(EV_KEY, BTN_TOUCH, 0);
703 vTouchpad_.SendEvent(EV_SYN, SYN_REPORT, 0);
704 while (event != nullptr) {
705 event = libinput_.Dispatch();
706 }
707 }
708
709 /**
710 * @tc.name: TouchPadTransformProcessorTest_OnEvent_003
711 * @tc.desc: test OnEvent
712 * @tc.type: FUNC
713 * @tc.require:
714 */
715 HWTEST_F(TouchPadTransformProcessorTest, TouchPadTransformProcessorTest_OnEvent_003, TestSize.Level1)
716 {
717 CALL_TEST_DEBUG;
718 vTouchpad_.SendEvent(EV_ABS, ABS_MT_TRACKING_ID, ++trackingID_);
719 vTouchpad_.SendEvent(EV_ABS, ABS_MT_POSITION_X, 763);
720 vTouchpad_.SendEvent(EV_ABS, ABS_MT_POSITION_Y, 663);
721 vTouchpad_.SendEvent(EV_ABS, ABS_MT_TOOL_TYPE, 2);
722 vTouchpad_.SendEvent(EV_KEY, BTN_TOUCH, 1);
723 vTouchpad_.SendEvent(EV_SYN, SYN_REPORT, 0);
724
725 libinput_event *event = libinput_.Dispatch();
726 ASSERT_TRUE(event != nullptr);
727 struct libinput_device *dev = libinput_event_get_device(event);
728 ASSERT_TRUE(dev != nullptr);
729 std::cout << "touchpad device: " << libinput_device_get_name(dev) << std::endl;
730 auto iter = INPUT_DEV_MGR->inputDevice_.begin();
731 for (; iter != INPUT_DEV_MGR->inputDevice_.end(); ++iter) {
732 if (iter->second.inputDeviceOrigin == dev) {
733 break;
734 }
735 }
736 ASSERT_TRUE(iter != INPUT_DEV_MGR->inputDevice_.end());
737 int32_t deviceId = iter->first;
738 TouchPadTransformProcessor processor(deviceId);
739 processor.pointerEvent_ = PointerEvent::Create();
740 ASSERT_TRUE(processor.pointerEvent_ != nullptr);
741 PointerEvent::PointerItem item;
742 item.SetPointerId(0);
743 item.SetDeviceId(deviceId);
744 processor.pointerEvent_->SetDeviceId(deviceId);
745 processor.pointerEvent_->UpdatePointerItem(0, item);
746 auto pointerEvent = processor.OnEvent(event);
747 ASSERT_TRUE(pointerEvent != nullptr);
748 }
749
750 /**
751 * @tc.name: TouchPadTransformProcessorTest_OnEvent_004
752 * @tc.desc: test OnEvent
753 * @tc.type: FUNC
754 * @tc.require:
755 */
756 HWTEST_F(TouchPadTransformProcessorTest, TouchPadTransformProcessorTest_OnEvent_004, TestSize.Level1)
757 {
758 CALL_TEST_DEBUG;
759 vTouchpad_.SendEvent(EV_ABS, ABS_MT_TRACKING_ID, -1);
760 vTouchpad_.SendEvent(EV_KEY, BTN_TOUCH, 0);
761 vTouchpad_.SendEvent(EV_SYN, SYN_REPORT, 0);
762
763 libinput_event *event = libinput_.Dispatch();
764 ASSERT_TRUE(event != nullptr);
765 struct libinput_device *dev = libinput_event_get_device(event);
766 ASSERT_TRUE(dev != nullptr);
767 std::cout << "touchpad device: " << libinput_device_get_name(dev) << std::endl;
768 auto iter = INPUT_DEV_MGR->inputDevice_.begin();
769 for (; iter != INPUT_DEV_MGR->inputDevice_.end(); ++iter) {
770 if (iter->second.inputDeviceOrigin == dev) {
771 break;
772 }
773 }
774 ASSERT_TRUE(iter != INPUT_DEV_MGR->inputDevice_.end());
775 int32_t deviceId = iter->first;
776 TouchPadTransformProcessor processor(deviceId);
777 processor.pointerEvent_ = PointerEvent::Create();
778 ASSERT_TRUE(processor.pointerEvent_ != nullptr);
779 PointerEvent::PointerItem item;
780 item.SetPointerId(0);
781 item.SetDeviceId(deviceId);
782 processor.pointerEvent_->SetDeviceId(deviceId);
783 processor.pointerEvent_->UpdatePointerItem(0, item);
784 auto pointerEvent = processor.OnEvent(event);
785 ASSERT_TRUE(pointerEvent != nullptr);
786 }
787
788 /**
789 * @tc.name: TouchPadTransformProcessorTest_GetTouchPadToolType_001
790 * @tc.desc: test GetTouchPadToolType
791 * @tc.type: FUNC
792 * @tc.require:
793 */
794 HWTEST_F(TouchPadTransformProcessorTest, TouchPadTransformProcessorTest_GetTouchPadToolType_001, TestSize.Level1)
795 {
796 CALL_TEST_DEBUG;
797 vTouchpad_.SendEvent(EV_ABS, ABS_MT_TRACKING_ID, ++trackingID_);
798 vTouchpad_.SendEvent(EV_ABS, ABS_MT_POSITION_X, 703);
799 vTouchpad_.SendEvent(EV_ABS, ABS_MT_POSITION_Y, 603);
800 vTouchpad_.SendEvent(EV_ABS, ABS_MT_TOOL_TYPE, -1);
801 vTouchpad_.SendEvent(EV_KEY, BTN_TOUCH, 1);
802 vTouchpad_.SendEvent(EV_SYN, SYN_REPORT, 0);
803
804 libinput_event *event = libinput_.Dispatch();
805 ASSERT_TRUE(event != nullptr);
806 struct libinput_device *dev = libinput_event_get_device(event);
807 ASSERT_TRUE(dev != nullptr);
808 std::cout << "touchpad device: " << libinput_device_get_name(dev) << std::endl;
809 auto iter = INPUT_DEV_MGR->inputDevice_.begin();
810 for (; iter != INPUT_DEV_MGR->inputDevice_.end(); ++iter) {
811 if (iter->second.inputDeviceOrigin == dev) {
812 break;
813 }
814 }
815 ASSERT_TRUE(iter != INPUT_DEV_MGR->inputDevice_.end());
816 int32_t deviceId = iter->first;
817 TouchPadTransformProcessor processor(deviceId);
818 auto touchpad = libinput_event_get_touchpad_event(event);
819 ASSERT_TRUE(touchpad != nullptr);
820 ASSERT_NO_FATAL_FAILURE(processor.GetTouchPadToolType(touchpad, dev));
821 }
822
823 /**
824 * @tc.name: TouchPadTransformProcessorTest_GetTouchPadToolType_002
825 * @tc.desc: test GetTouchPadToolType
826 * @tc.type: FUNC
827 * @tc.require:
828 */
829 HWTEST_F(TouchPadTransformProcessorTest, TouchPadTransformProcessorTest_GetTouchPadToolType_002, TestSize.Level1)
830 {
831 CALL_TEST_DEBUG;
832 vTouchpad_.SendEvent(EV_ABS, ABS_MT_POSITION_X, 773);
833 vTouchpad_.SendEvent(EV_ABS, ABS_MT_POSITION_Y, 673);
834 vTouchpad_.SendEvent(EV_ABS, ABS_MT_TOOL_TYPE, 0);
835 vTouchpad_.SendEvent(EV_SYN, SYN_REPORT, 0);
836
837 libinput_event *event = libinput_.Dispatch();
838 ASSERT_TRUE(event != nullptr);
839 struct libinput_device *dev = libinput_event_get_device(event);
840 ASSERT_TRUE(dev != nullptr);
841 std::cout << "touchpad device: " << libinput_device_get_name(dev) << std::endl;
842 auto iter = INPUT_DEV_MGR->inputDevice_.begin();
843 for (; iter != INPUT_DEV_MGR->inputDevice_.end(); ++iter) {
844 if (iter->second.inputDeviceOrigin == dev) {
845 break;
846 }
847 }
848 ASSERT_TRUE(iter != INPUT_DEV_MGR->inputDevice_.end());
849 int32_t deviceId = iter->first;
850 TouchPadTransformProcessor processor(deviceId);
851 auto touchpad = libinput_event_get_touchpad_event(event);
852 ASSERT_TRUE(touchpad != nullptr);
853 ASSERT_NO_FATAL_FAILURE(processor.GetTouchPadToolType(touchpad, dev));
854 }
855
856 /**
857 * @tc.name: TouchPadTransformProcessorTest_GetTouchPadToolType_003
858 * @tc.desc: test GetTouchPadToolType
859 * @tc.type: FUNC
860 * @tc.require:
861 */
862 HWTEST_F(TouchPadTransformProcessorTest, TouchPadTransformProcessorTest_GetTouchPadToolType_003, TestSize.Level1)
863 {
864 CALL_TEST_DEBUG;
865 vTouchpad_.SendEvent(EV_ABS, ABS_MT_POSITION_X, 783);
866 vTouchpad_.SendEvent(EV_ABS, ABS_MT_POSITION_Y, 683);
867 vTouchpad_.SendEvent(EV_ABS, ABS_MT_TOOL_TYPE, 1);
868 vTouchpad_.SendEvent(EV_SYN, SYN_REPORT, 0);
869
870 libinput_event *event = libinput_.Dispatch();
871 ASSERT_TRUE(event != nullptr);
872 struct libinput_device *dev = libinput_event_get_device(event);
873 ASSERT_TRUE(dev != nullptr);
874 std::cout << "touchpad device: " << libinput_device_get_name(dev) << std::endl;
875 auto iter = INPUT_DEV_MGR->inputDevice_.begin();
876 for (; iter != INPUT_DEV_MGR->inputDevice_.end(); ++iter) {
877 if (iter->second.inputDeviceOrigin == dev) {
878 break;
879 }
880 }
881 ASSERT_TRUE(iter != INPUT_DEV_MGR->inputDevice_.end());
882 int32_t deviceId = iter->first;
883 TouchPadTransformProcessor processor(deviceId);
884 auto touchpad = libinput_event_get_touchpad_event(event);
885 ASSERT_TRUE(touchpad != nullptr);
886 ASSERT_NO_FATAL_FAILURE(processor.GetTouchPadToolType(touchpad, dev));
887 }
888
889 /**
890 * @tc.name: TouchPadTransformProcessorTest_GetTouchPadToolType_004
891 * @tc.desc: test GetTouchPadToolType
892 * @tc.type: FUNC
893 * @tc.require:
894 */
895 HWTEST_F(TouchPadTransformProcessorTest, TouchPadTransformProcessorTest_GetTouchPadToolType_004, TestSize.Level1)
896 {
897 CALL_TEST_DEBUG;
898 vTouchpad_.SendEvent(EV_ABS, ABS_MT_POSITION_X, 793);
899 vTouchpad_.SendEvent(EV_ABS, ABS_MT_POSITION_Y, 693);
900 vTouchpad_.SendEvent(EV_ABS, ABS_MT_TOOL_TYPE, 3);
901 vTouchpad_.SendEvent(EV_SYN, SYN_REPORT, 0);
902
903 libinput_event *event = libinput_.Dispatch();
904 ASSERT_TRUE(event != nullptr);
905 struct libinput_device *dev = libinput_event_get_device(event);
906 ASSERT_TRUE(dev != nullptr);
907 std::cout << "touchpad device: " << libinput_device_get_name(dev) << std::endl;
908 auto iter = INPUT_DEV_MGR->inputDevice_.begin();
909 for (; iter != INPUT_DEV_MGR->inputDevice_.end(); ++iter) {
910 if (iter->second.inputDeviceOrigin == dev) {
911 break;
912 }
913 }
914 ASSERT_TRUE(iter != INPUT_DEV_MGR->inputDevice_.end());
915 int32_t deviceId = iter->first;
916 TouchPadTransformProcessor processor(deviceId);
917 auto touchpad = libinput_event_get_touchpad_event(event);
918 ASSERT_TRUE(touchpad != nullptr);
919 ASSERT_NO_FATAL_FAILURE(processor.GetTouchPadToolType(touchpad, dev));
920 }
921
922 /**
923 * @tc.name: TouchPadTransformProcessorTest_GetTouchPadToolType_005
924 * @tc.desc: test GetTouchPadToolType
925 * @tc.type: FUNC
926 * @tc.require:
927 */
928 HWTEST_F(TouchPadTransformProcessorTest, TouchPadTransformProcessorTest_GetTouchPadToolType_005, TestSize.Level1)
929 {
930 CALL_TEST_DEBUG;
931 vTouchpad_.SendEvent(EV_ABS, ABS_MT_POSITION_X, 693);
932 vTouchpad_.SendEvent(EV_ABS, ABS_MT_POSITION_Y, 593);
933 vTouchpad_.SendEvent(EV_SYN, SYN_REPORT, 0);
934
935 libinput_event *event = libinput_.Dispatch();
936 ASSERT_TRUE(event != nullptr);
937 struct libinput_device *dev = libinput_event_get_device(event);
938 ASSERT_TRUE(dev != nullptr);
939 std::cout << "touchpad device: " << libinput_device_get_name(dev) << std::endl;
940 auto iter = INPUT_DEV_MGR->inputDevice_.begin();
941 for (; iter != INPUT_DEV_MGR->inputDevice_.end(); ++iter) {
942 if (iter->second.inputDeviceOrigin == dev) {
943 break;
944 }
945 }
946 ASSERT_TRUE(iter != INPUT_DEV_MGR->inputDevice_.end());
947 int32_t deviceId = iter->first;
948 TouchPadTransformProcessor processor(deviceId);
949 processor.InitToolType();
950 ASSERT_NO_FATAL_FAILURE(processor.GetTouchPadToolType(dev));
951 vTouchpad_.SendEvent(EV_ABS, ABS_MT_TRACKING_ID, -1);
952 vTouchpad_.SendEvent(EV_KEY, BTN_TOUCH, 0);
953 vTouchpad_.SendEvent(EV_SYN, SYN_REPORT, 0);
954 while (event != nullptr) {
955 event = libinput_.Dispatch();
956 }
957 }
958
959 /**
960 * @tc.name: TouchPadTransformProcessorTest_GetTouchPadToolType_006
961 * @tc.desc: test GetTouchPadToolType
962 * @tc.type: FUNC
963 * @tc.require:
964 */
965 HWTEST_F(TouchPadTransformProcessorTest, TouchPadTransformProcessorTest_GetTouchPadToolType_006, TestSize.Level1)
966 {
967 CALL_TEST_DEBUG;
968 vTouchpad_.SendEvent(EV_ABS, ABS_MT_TRACKING_ID, ++trackingID_);
969 vTouchpad_.SendEvent(EV_ABS, ABS_MT_POSITION_X, 763);
970 vTouchpad_.SendEvent(EV_ABS, ABS_MT_POSITION_Y, 663);
971 vTouchpad_.SendEvent(EV_KEY, BTN_TOUCH, 1);
972 vTouchpad_.SendEvent(EV_KEY, BTN_TOOL_RUBBER, 1);
973 vTouchpad_.SendEvent(EV_SYN, SYN_REPORT, 0);
974
975 libinput_event *event = libinput_.Dispatch();
976 ASSERT_TRUE(event != nullptr);
977 struct libinput_device *dev = libinput_event_get_device(event);
978 ASSERT_TRUE(dev != nullptr);
979 std::cout << "touchpad device: " << libinput_device_get_name(dev) << std::endl;
980 auto iter = INPUT_DEV_MGR->inputDevice_.begin();
981 for (; iter != INPUT_DEV_MGR->inputDevice_.end(); ++iter) {
982 if (iter->second.inputDeviceOrigin == dev) {
983 break;
984 }
985 }
986 ASSERT_TRUE(iter != INPUT_DEV_MGR->inputDevice_.end());
987 int32_t deviceId = iter->first;
988 TouchPadTransformProcessor processor(deviceId);
989 processor.InitToolType();
990 ASSERT_NO_FATAL_FAILURE(processor.GetTouchPadToolType(dev));
991 }
992
993 /**
994 * @tc.name: TouchPadTransformProcessorTest_SetTouchPadSwipeData_001
995 * @tc.desc: test SetTouchPadSwipeData
996 * @tc.type: FUNC
997 * @tc.require:
998 */
999 HWTEST_F(TouchPadTransformProcessorTest, TouchPadTransformProcessorTest_SetTouchPadSwipeData_001, TestSize.Level1)
1000 {
1001 CALL_TEST_DEBUG;
1002 vTouchpad_.SendEvent(EV_ABS, ABS_MT_POSITION_X, 666);
1003 vTouchpad_.SendEvent(EV_ABS, ABS_MT_POSITION_Y, 555);
1004 vTouchpad_.SendEvent(EV_SYN, SYN_REPORT, 0);
1005
1006 libinput_event *event = libinput_.Dispatch();
1007 ASSERT_TRUE(event != nullptr);
1008 struct libinput_device *dev = libinput_event_get_device(event);
1009 ASSERT_TRUE(dev != nullptr);
1010 std::cout << "touchpad device: " << libinput_device_get_name(dev) << std::endl;
1011 auto iter = INPUT_DEV_MGR->inputDevice_.begin();
1012 for (; iter != INPUT_DEV_MGR->inputDevice_.end(); ++iter) {
1013 if (iter->second.inputDeviceOrigin == dev) {
1014 break;
1015 }
1016 }
1017 ASSERT_TRUE(iter != INPUT_DEV_MGR->inputDevice_.end());
1018 int32_t deviceId = iter->first;
1019 TouchPadTransformProcessor processor(deviceId);
1020 processor.SetTouchpadSwipeSwitch(false);
1021 int32_t action = PointerEvent::POINTER_ACTION_SWIPE_BEGIN;
1022 ASSERT_NO_FATAL_FAILURE(processor.SetTouchPadSwipeData(event, action));
1023 }
1024
1025 /**
1026 * @tc.name: TouchPadTransformProcessorTest_SetTouchPadSwipeData_002
1027 * @tc.desc: test SetTouchPadSwipeData
1028 * @tc.type: FUNC
1029 * @tc.require:
1030 */
1031 HWTEST_F(TouchPadTransformProcessorTest, TouchPadTransformProcessorTest_SetTouchPadSwipeData_002, TestSize.Level1)
1032 {
1033 CALL_TEST_DEBUG;
1034 vTouchpad_.SendEvent(EV_ABS, ABS_MT_POSITION_X, 555);
1035 vTouchpad_.SendEvent(EV_ABS, ABS_MT_POSITION_Y, 444);
1036 vTouchpad_.SendEvent(EV_SYN, SYN_REPORT, 0);
1037
1038 libinput_event *event = libinput_.Dispatch();
1039 ASSERT_TRUE(event != nullptr);
1040 struct libinput_device *dev = libinput_event_get_device(event);
1041 ASSERT_TRUE(dev != nullptr);
1042 std::cout << "touchpad device: " << libinput_device_get_name(dev) << std::endl;
1043 auto iter = INPUT_DEV_MGR->inputDevice_.begin();
1044 for (; iter != INPUT_DEV_MGR->inputDevice_.end(); ++iter) {
1045 if (iter->second.inputDeviceOrigin == dev) {
1046 break;
1047 }
1048 }
1049 ASSERT_TRUE(iter != INPUT_DEV_MGR->inputDevice_.end());
1050 int32_t deviceId = iter->first;
1051 TouchPadTransformProcessor processor(deviceId);
1052 processor.SetTouchpadSwipeSwitch(true);
1053 int32_t action = PointerEvent::POINTER_ACTION_SWIPE_BEGIN;
1054 ASSERT_NO_FATAL_FAILURE(processor.SetTouchPadSwipeData(event, action));
1055 }
1056
1057 /**
1058 * @tc.name: TouchPadTransformProcessorTest_CanAddToPointerMaps_001
1059 * @tc.desc: test CanAddToPointerMaps
1060 * @tc.type: FUNC
1061 * @tc.require:
1062 */
1063 HWTEST_F(TouchPadTransformProcessorTest, TouchPadTransformProcessorTest_CanAddToPointerMaps_001, TestSize.Level1)
1064 {
1065 CALL_TEST_DEBUG;
1066 vTouchpad_.SendEvent(EV_ABS, ABS_MT_POSITION_X, 511);
1067 vTouchpad_.SendEvent(EV_ABS, ABS_MT_POSITION_Y, 411);
1068 vTouchpad_.SendEvent(EV_SYN, SYN_REPORT, 0);
1069
1070 libinput_event *event = libinput_.Dispatch();
1071 ASSERT_TRUE(event != nullptr);
1072 auto touchpad = libinput_event_get_touchpad_event(event);
1073 ASSERT_TRUE(touchpad != nullptr);
1074 MultiFingersTapHandler processor;
1075 ASSERT_NO_FATAL_FAILURE(processor.CanAddToPointerMaps(touchpad));
1076 ASSERT_NO_FATAL_FAILURE(processor.CanAddToPointerMaps(touchpad));
1077 }
1078
1079 /**
1080 * @tc.name: TouchPadTransformProcessorTest_HandleMulFingersTap_002
1081 * @tc.desc: Verify if the multi-touch gesture handling is correct
1082 * @tc.type: FUNC
1083 * @tc.require:
1084 */
1085 HWTEST_F(TouchPadTransformProcessorTest, TouchPadTransformProcessorTest_HandleMulFingersTap_002, TestSize.Level1)
1086 {
1087 CALL_TEST_DEBUG;
1088 vTouchpad_.SendEvent(EV_ABS, ABS_MT_POSITION_X, 266);
1089 vTouchpad_.SendEvent(EV_ABS, ABS_MT_POSITION_Y, 255);
1090 vTouchpad_.SendEvent(EV_SYN, SYN_REPORT, 0);
1091
1092 libinput_event *event = libinput_.Dispatch();
1093 ASSERT_TRUE(event != nullptr);
1094 auto touchpad = libinput_event_get_touchpad_event(event);
1095 ASSERT_TRUE(touchpad != nullptr);
1096 MultiFingersTapHandler processor;
1097 processor.tapTrends_ = MultiFingersTapHandler::TapTrends::NO_MULTAP;
1098 int32_t type = LIBINPUT_EVENT_TOUCHPAD_DOWN;
1099 auto ret = processor.HandleMulFingersTap(touchpad, type);
1100 ASSERT_EQ(ret, RET_OK);
1101
1102 processor.tapTrends_ = MultiFingersTapHandler::TapTrends::BEGIN;
1103 ret = processor.HandleMulFingersTap(touchpad, type);
1104 ASSERT_EQ(ret, RET_OK);
1105
1106 processor.tapTrends_ = MultiFingersTapHandler::TapTrends::DOWNING;
1107 auto time = libinput_event_touchpad_get_time_usec(touchpad);
1108 processor.lastTime = time - 150 * 1e3 - 1;
1109 ret = processor.HandleMulFingersTap(touchpad, type);
1110 ASSERT_EQ(ret, RET_OK);
1111
1112 processor.tapTrends_ = MultiFingersTapHandler::TapTrends::UPING;
1113 processor.lastTime = time;
1114 processor.beginTime = time;
1115 ret = processor.HandleMulFingersTap(touchpad, type);
1116 ASSERT_EQ(ret, RET_OK);
1117 }
1118
1119 /**
1120 * @tc.name: TouchPadTransformProcessorTest_HandleMulFingersTap_003
1121 * @tc.desc: Verify if the multi-touch gesture handling is correct
1122 * @tc.type: FUNC
1123 * @tc.require:
1124 */
1125 HWTEST_F(TouchPadTransformProcessorTest, TouchPadTransformProcessorTest_HandleMulFingersTap_003, TestSize.Level1)
1126 {
1127 CALL_TEST_DEBUG;
1128 vTouchpad_.SendEvent(EV_ABS, ABS_MT_POSITION_X, 299);
1129 vTouchpad_.SendEvent(EV_ABS, ABS_MT_POSITION_Y, 260);
1130 vTouchpad_.SendEvent(EV_SYN, SYN_REPORT, 0);
1131
1132 libinput_event *event = libinput_.Dispatch();
1133 ASSERT_TRUE(event != nullptr);
1134 auto touchpad = libinput_event_get_touchpad_event(event);
1135 ASSERT_TRUE(touchpad != nullptr);
1136 MultiFingersTapHandler processor;
1137 processor.tapTrends_ = MultiFingersTapHandler::TapTrends::UPING;
1138 auto time = libinput_event_touchpad_get_time_usec(touchpad);
1139 processor.lastTime = time;
1140 processor.beginTime = time;
1141 int32_t type = LIBINPUT_EVENT_TOUCHPAD_UP;
1142 processor.CanUnsetPointerItem(touchpad);
1143 auto ret = processor.HandleMulFingersTap(touchpad, type);
1144 ASSERT_EQ(ret, RET_OK);
1145 }
1146
1147 /**
1148 * @tc.name: TouchPadTransformProcessorTest_HandleMulFingersTap_004
1149 * @tc.desc: Verify if the multi-touch gesture handling is correct
1150 * @tc.type: FUNC
1151 * @tc.require:
1152 */
1153 HWTEST_F(TouchPadTransformProcessorTest, TouchPadTransformProcessorTest_HandleMulFingersTap_004, TestSize.Level1)
1154 {
1155 CALL_TEST_DEBUG;
1156 vTouchpad_.SendEvent(EV_ABS, ABS_MT_POSITION_X, 311);
1157 vTouchpad_.SendEvent(EV_ABS, ABS_MT_POSITION_Y, 270);
1158 vTouchpad_.SendEvent(EV_SYN, SYN_REPORT, 0);
1159
1160 libinput_event *event = libinput_.Dispatch();
1161 ASSERT_TRUE(event != nullptr);
1162 auto touchpad = libinput_event_get_touchpad_event(event);
1163 ASSERT_TRUE(touchpad != nullptr);
1164 MultiFingersTapHandler processor;
1165 processor.tapTrends_ = MultiFingersTapHandler::TapTrends::UPING;
1166 auto time = libinput_event_touchpad_get_time_usec(touchpad);
1167 processor.lastTime = time;
1168 processor.beginTime = time;
1169 int32_t type = LIBINPUT_EVENT_TOUCHPAD_MOTION;
1170 auto ret = processor.HandleMulFingersTap(touchpad, type);
1171 ASSERT_EQ(ret, RET_OK);
1172 }
1173
1174 /**
1175 * @tc.name: TouchPadTransformProcessorTest_HandleMulFingersTap_005
1176 * @tc.desc: Verify if the multi-touch gesture handling is correct
1177 * @tc.type: FUNC
1178 * @tc.require:
1179 */
1180 HWTEST_F(TouchPadTransformProcessorTest, TouchPadTransformProcessorTest_HandleMulFingersTap_005, TestSize.Level1)
1181 {
1182 CALL_TEST_DEBUG;
1183 vTouchpad_.SendEvent(EV_ABS, ABS_MT_POSITION_X, 299);
1184 vTouchpad_.SendEvent(EV_ABS, ABS_MT_POSITION_Y, 260);
1185 vTouchpad_.SendEvent(EV_SYN, SYN_REPORT, 0);
1186
1187 libinput_event *event = libinput_.Dispatch();
1188 ASSERT_TRUE(event != nullptr);
1189 auto touchpad = libinput_event_get_touchpad_event(event);
1190 ASSERT_TRUE(touchpad != nullptr);
1191 MultiFingersTapHandler processor;
1192 processor.tapTrends_ = MultiFingersTapHandler::TapTrends::UPING;
1193 auto time = libinput_event_touchpad_get_time_usec(touchpad);
1194 processor.lastTime = time;
1195 processor.beginTime = time;
1196 int32_t type = LIBINPUT_EVENT_TOUCHPAD_UP;
1197 processor.CanUnsetPointerItem(touchpad);
1198 processor.downCnt = 3;
1199 processor.upCnt = 2;
1200 auto ret = processor.HandleMulFingersTap(touchpad, type);
1201 ASSERT_EQ(ret, RET_OK);
1202 }
1203
1204 /**
1205 * @tc.name: TouchPadTransformProcessorTest_CanUnsetPointerItem_001
1206 * @tc.desc: test CanUnsetPointerItem
1207 * @tc.type: FUNC
1208 * @tc.require:
1209 */
1210 HWTEST_F(TouchPadTransformProcessorTest, TouchPadTransformProcessorTest_CanUnsetPointerItem_001, TestSize.Level1)
1211 {
1212 CALL_TEST_DEBUG;
1213 vTouchpad_.SendEvent(EV_ABS, ABS_MT_POSITION_X, 530);
1214 vTouchpad_.SendEvent(EV_ABS, ABS_MT_POSITION_Y, 440);
1215 vTouchpad_.SendEvent(EV_SYN, SYN_REPORT, 0);
1216 libinput_event *event = libinput_.Dispatch();
1217 ASSERT_TRUE(event != nullptr);
1218 auto touchpad = libinput_event_get_touchpad_event(event);
1219 ASSERT_TRUE(touchpad != nullptr);
1220 MultiFingersTapHandler processor;
1221
1222 bool ret = processor.CanUnsetPointerItem(touchpad);
1223 EXPECT_TRUE(ret);
1224 }
1225 } // namespace MMI
1226 } // namespace OHOS