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