1 /*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <cstdio>
17 #include <gtest/gtest.h>
18
19 #include "define_multimodal.h"
20 #include "general_touchscreen.h"
21 #include "general_uwb_remote_control.h"
22 #include "input_device_manager.h"
23 #include "i_input_windows_manager.h"
24 #include "libinput-private.h"
25 #include "libinput_wrapper.h"
26 #include "touch_transform_processor.h"
27
28 namespace OHOS {
29 namespace MMI {
30 namespace {
31 using namespace testing::ext;
32 constexpr int32_t MAX_MOVE_FLAG = 6;
33 } // namespace
34
35 class TouchTransformProcessorTest : public testing::Test {
36 public:
37 static void SetUpTestCase(void);
38 static void TearDownTestCase(void);
39 void SetUp();
40 void TearDown();
41
42 private:
43 static void SetupTouchscreen();
44 static void SetupUwbRemoteControl();
45 static void CloseTouchscreen();
46 static void CloseUwbRemoteControl();
47 static GeneralUwbRemoteControl vUwbRemoteControl_;
48 static GeneralTouchscreen vTouchscreen_;
49 static LibinputWrapper libinput_;
50 };
51
52 GeneralUwbRemoteControl TouchTransformProcessorTest::vUwbRemoteControl_;
53 GeneralTouchscreen TouchTransformProcessorTest::vTouchscreen_;
54 LibinputWrapper TouchTransformProcessorTest::libinput_;
55
SetUpTestCase(void)56 void TouchTransformProcessorTest::SetUpTestCase(void)
57 {
58 ASSERT_TRUE(libinput_.Init());
59 SetupTouchscreen();
60 SetupUwbRemoteControl();
61 }
62
TearDownTestCase(void)63 void TouchTransformProcessorTest::TearDownTestCase(void)
64 {
65 CloseTouchscreen();
66 CloseUwbRemoteControl();
67 }
68
SetupTouchscreen()69 void TouchTransformProcessorTest::SetupTouchscreen()
70 {
71 ASSERT_TRUE(vTouchscreen_.SetUp());
72 std::cout << "device node name: " << vTouchscreen_.GetDevPath() << std::endl;
73 ASSERT_TRUE(libinput_.AddPath(vTouchscreen_.GetDevPath()));
74 libinput_event *event = libinput_.Dispatch();
75 ASSERT_TRUE(event != nullptr);
76 ASSERT_EQ(libinput_event_get_type(event), LIBINPUT_EVENT_DEVICE_ADDED);
77 struct libinput_device *device = libinput_event_get_device(event);
78 ASSERT_TRUE(device != nullptr);
79 }
80
SetupUwbRemoteControl()81 void TouchTransformProcessorTest::SetupUwbRemoteControl()
82 {
83 ASSERT_TRUE(vUwbRemoteControl_.SetUp());
84 std::cout << "device node name: " << vUwbRemoteControl_.GetDevPath() << std::endl;
85 ASSERT_TRUE(libinput_.AddPath(vUwbRemoteControl_.GetDevPath()));
86 libinput_event *event = libinput_.Dispatch();
87 ASSERT_TRUE(event != nullptr);
88 ASSERT_EQ(libinput_event_get_type(event), LIBINPUT_EVENT_DEVICE_ADDED);
89 struct libinput_device *device = libinput_event_get_device(event);
90 ASSERT_TRUE(device != nullptr);
91 }
92
CloseTouchscreen()93 void TouchTransformProcessorTest::CloseTouchscreen()
94 {
95 libinput_.RemovePath(vTouchscreen_.GetDevPath());
96 vTouchscreen_.Close();
97 }
98
CloseUwbRemoteControl()99 void TouchTransformProcessorTest::CloseUwbRemoteControl()
100 {
101 libinput_.RemovePath(vUwbRemoteControl_.GetDevPath());
102 vUwbRemoteControl_.Close();
103 }
104
SetUp()105 void TouchTransformProcessorTest::SetUp()
106 {
107 }
108
TearDown()109 void TouchTransformProcessorTest::TearDown()
110 {
111 }
112
113 /**
114 * @tc.name: TouchTransformProcessorTest_OnEventTouchDown_001
115 * @tc.desc: Test the funcation OnEventTouchDown
116 * @tc.type: FUNC
117 * @tc.require:
118 */
119 HWTEST_F(TouchTransformProcessorTest, OnEventTouchDown_001, TestSize.Level1)
120 {
121 int32_t deviceId = 6;
122 TouchTransformProcessor processor(deviceId);
123 libinput_event* event = nullptr;
124 bool ret = processor.OnEventTouchDown(event);
125 ASSERT_FALSE(ret);
126 }
127
128 /**
129 * @tc.name: TouchTransformProcessorTest_UpdatePointerItemProperties_001
130 * @tc.desc: Test the funcation UpdatePointerItemByTouchInfo
131 * @tc.type: FUNC
132 * @tc.require:
133 */
134 HWTEST_F(TouchTransformProcessorTest, UpdatePointerItemProperties_001, TestSize.Level1)
135 {
136 PointerEvent::PointerItem item;
137 EventTouch touchInfo;
138 touchInfo.point.x = 10;
139 touchInfo.point.y = 20;
140 touchInfo.toolRect.point.x = 30;
141 touchInfo.toolRect.point.y = 40;
142 touchInfo.toolRect.width = 50;
143 touchInfo.toolRect.height = 60;
144 int32_t deviceId = 6;
145 TouchTransformProcessor processor(deviceId);
146 processor.UpdatePointerItemByTouchInfo(item, touchInfo);
147 ASSERT_EQ(item.GetDisplayX(), touchInfo.point.x);
148 ASSERT_EQ(item.GetDisplayY(), touchInfo.point.y);
149 ASSERT_EQ(item.GetGlobalX(), touchInfo.globalCoord.x);
150 ASSERT_EQ(item.GetGlobalY(), touchInfo.globalCoord.y);
151 ASSERT_EQ(item.GetDisplayXPos(), touchInfo.point.x);
152 ASSERT_EQ(item.GetDisplayYPos(), touchInfo.point.y);
153 ASSERT_EQ(item.GetRawDisplayX(), touchInfo.point.x);
154 ASSERT_EQ(item.GetRawDisplayY(), touchInfo.point.y);
155 ASSERT_EQ(item.GetToolDisplayX(), touchInfo.toolRect.point.x);
156 ASSERT_EQ(item.GetToolDisplayY(), touchInfo.toolRect.point.y);
157 ASSERT_EQ(item.GetToolWidth(), touchInfo.toolRect.width);
158 ASSERT_EQ(item.GetToolHeight(), touchInfo.toolRect.height);
159 }
160
161 /**
162 * @tc.name: TouchTransformProcessorTest_OnEventTouchMotion_001
163 * @tc.desc: Test the funcation OnEventTouchMotion
164 * @tc.type: FUNC
165 * @tc.require:
166 */
167 HWTEST_F(TouchTransformProcessorTest, OnEventTouchMotion_001, TestSize.Level1)
168 {
169 int32_t deviceId = 6;
170 TouchTransformProcessor processor(deviceId);
171 libinput_event* event = nullptr;
172 bool ret = processor.OnEventTouchMotion(event);
173 ASSERT_FALSE(ret);
174 }
175
176 /**
177 * @tc.name: TouchTransformProcessorTest_OnEventTouchUp_001
178 * @tc.desc: Test the funcation OnEventTouchUp
179 * @tc.type: FUNC
180 * @tc.require:
181 */
182 HWTEST_F(TouchTransformProcessorTest, OnEventTouchUp_001, TestSize.Level1)
183 {
184 int32_t deviceId = 6;
185 TouchTransformProcessor processor(deviceId);
186 libinput_event* event = nullptr;
187 bool ret = processor.OnEventTouchUp(event);
188 ASSERT_FALSE(ret);
189 }
190
191 /**
192 * @tc.name: TouchTransformProcessorTest_GetTouchToolType_001
193 * @tc.desc: Test the funcation GetTouchToolType
194 * @tc.type: FUNC
195 * @tc.require:
196 */
197 HWTEST_F(TouchTransformProcessorTest, GetTouchToolType_001, TestSize.Level1)
198 {
199 int32_t deviceId = 6;
200 TouchTransformProcessor processor(deviceId);
201 struct libinput_device *device = nullptr;
202 int32_t toolType = processor.GetTouchToolType(device);
203 ASSERT_EQ(toolType, PointerEvent::TOOL_TYPE_FINGER);
204 }
205
206 /**
207 * @tc.name: TouchTransformProcessorTest_InitToolTypes_001
208 * @tc.desc: Test the funcation InitToolTypes
209 * @tc.type: FUNC
210 * @tc.require:
211 */
212 HWTEST_F(TouchTransformProcessorTest, InitToolTypes_001, TestSize.Level1)
213 {
214 int32_t deviceId = 6;
215 TouchTransformProcessor processor(deviceId);
216 processor.InitToolTypes();
217 ASSERT_EQ(processor.vecToolType_.size(), 16);
218 ASSERT_EQ(processor.vecToolType_[0].first, BTN_TOOL_PEN);
219 ASSERT_EQ(processor.vecToolType_[0].second, PointerEvent::TOOL_TYPE_PEN);
220 ASSERT_EQ(processor.vecToolType_[1].first, BTN_TOOL_RUBBER);
221 ASSERT_EQ(processor.vecToolType_[1].second, PointerEvent::TOOL_TYPE_RUBBER);
222 ASSERT_EQ(processor.vecToolType_[2].first, BTN_TOOL_BRUSH);
223 ASSERT_EQ(processor.vecToolType_[2].second, PointerEvent::TOOL_TYPE_BRUSH);
224 ASSERT_EQ(processor.vecToolType_[3].first, BTN_TOOL_PENCIL);
225 ASSERT_EQ(processor.vecToolType_[3].second, PointerEvent::TOOL_TYPE_PENCIL);
226 ASSERT_EQ(processor.vecToolType_[4].first, BTN_TOOL_AIRBRUSH);
227 ASSERT_EQ(processor.vecToolType_[4].second, PointerEvent::TOOL_TYPE_AIRBRUSH);
228 ASSERT_EQ(processor.vecToolType_[5].first, BTN_TOOL_FINGER);
229 ASSERT_EQ(processor.vecToolType_[5].second, PointerEvent::TOOL_TYPE_FINGER);
230 ASSERT_EQ(processor.vecToolType_[6].first, BTN_TOOL_MOUSE);
231 ASSERT_EQ(processor.vecToolType_[6].second, PointerEvent::TOOL_TYPE_MOUSE);
232 ASSERT_EQ(processor.vecToolType_[7].first, BTN_TOOL_LENS);
233 ASSERT_EQ(processor.vecToolType_[7].second, PointerEvent::TOOL_TYPE_LENS);
234 }
235
236 /**
237 * @tc.name: TouchTransformProcessorTest_OnEventTouchDown_002
238 * @tc.desc: Test the funcation OnEventTouchDown
239 * @tc.type: FUNC
240 * @tc.require:
241 */
242 HWTEST_F(TouchTransformProcessorTest, OnEventTouchDown_002, TestSize.Level1)
243 {
244 CALL_TEST_DEBUG;
245 int32_t deviceId = 6;
246 TouchTransformProcessor processor(deviceId);
247 libinput_event* event = nullptr;
248 bool ret = processor.OnEventTouchDown(event);
249 ASSERT_FALSE(ret);
250 processor.pointerEvent_ = PointerEvent::Create();
251 ASSERT_TRUE(processor.pointerEvent_ != nullptr);
252 vTouchscreen_.SendEvent(EV_ABS, ABS_MT_TRACKING_ID, 0);
253 vTouchscreen_.SendEvent(EV_ABS, ABS_MT_POSITION_X, 5190);
254 vTouchscreen_.SendEvent(EV_ABS, ABS_MT_POSITION_Y, 8306);
255 vTouchscreen_.SendEvent(EV_ABS, ABS_MT_PRESSURE, 321);
256 vTouchscreen_.SendEvent(EV_ABS, ABS_MT_TOUCH_MAJOR, 198);
257 vTouchscreen_.SendEvent(EV_ABS, ABS_MT_TOUCH_MINOR, 180);
258 vTouchscreen_.SendEvent(EV_ABS, ABS_MT_ORIENTATION, -64);
259 vTouchscreen_.SendEvent(EV_ABS, ABS_MT_BLOB_ID, 2);
260 vTouchscreen_.SendEvent(EV_SYN, SYN_MT_REPORT, 0);
261 vTouchscreen_.SendEvent(EV_KEY, BTN_TOUCH, 1);
262 vTouchscreen_.SendEvent(EV_SYN, SYN_REPORT, 0);
263 event = libinput_.Dispatch();
264 ASSERT_TRUE(event != nullptr);
265 auto touch = libinput_event_get_touch_event(event);
266 ASSERT_TRUE(touch != nullptr);
267 auto device = libinput_event_get_device(event);
268 ASSERT_TRUE(device != nullptr);
269 ret = processor.OnEventTouchDown(event);
270 ASSERT_FALSE(ret);
271 }
272
273 /**
274 * @tc.name: TouchTransformProcessorTest_NotifyFingersenseProcess_001
275 * @tc.desc: Test the funcation NotifyFingersenseProcess
276 * @tc.type: FUNC
277 * @tc.require:
278 */
279 HWTEST_F(TouchTransformProcessorTest, NotifyFingersenseProcess_001, TestSize.Level1)
280 {
281 CALL_TEST_DEBUG;
282 int32_t deviceId = 6;
283 TouchTransformProcessor processor(deviceId);
284 PointerEvent::PointerItem item;
285 int32_t toolType = 0;
286 EXPECT_NO_FATAL_FAILURE(processor.NotifyFingersenseProcess(item, toolType));
287 }
288
289 /**
290 * @tc.name: TouchTransformProcessorTest_OnEventTouchMotion_002
291 * @tc.desc: Test the funcation OnEventTouchMotion
292 * @tc.type: FUNC
293 * @tc.require:
294 */
295 HWTEST_F(TouchTransformProcessorTest, OnEventTouchMotion_002, TestSize.Level1)
296 {
297 CALL_TEST_DEBUG;
298 int32_t deviceId = 6;
299 TouchTransformProcessor processor(deviceId);
300 libinput_event* event = nullptr;
301 bool ret = processor.OnEventTouchMotion(event);
302 ASSERT_FALSE(ret);
303 processor.pointerEvent_ = PointerEvent::Create();
304 ASSERT_TRUE(processor.pointerEvent_ != nullptr);
305 vTouchscreen_.SendEvent(EV_ABS, ABS_MT_POSITION_X, 5199);
306 vTouchscreen_.SendEvent(EV_ABS, ABS_MT_POSITION_Y, 8297);
307 vTouchscreen_.SendEvent(EV_ABS, ABS_MT_PRESSURE, 356);
308 vTouchscreen_.SendEvent(EV_ABS, ABS_MT_TRACKING_ID, 0);
309 vTouchscreen_.SendEvent(EV_ABS, ABS_MT_TOUCH_MAJOR, 216);
310 vTouchscreen_.SendEvent(EV_ABS, ABS_MT_TOUCH_MINOR, 162);
311 vTouchscreen_.SendEvent(EV_ABS, ABS_MT_ORIENTATION, -79);
312 vTouchscreen_.SendEvent(EV_ABS, ABS_MT_BLOB_ID, 2);
313 vTouchscreen_.SendEvent(EV_SYN, SYN_MT_REPORT, 0);
314 vTouchscreen_.SendEvent(EV_SYN, SYN_REPORT, 0);
315 event = libinput_.Dispatch();
316 ASSERT_TRUE(event != nullptr);
317 auto touch = libinput_event_get_touch_event(event);
318 ASSERT_TRUE(touch != nullptr);
319 EXPECT_NO_FATAL_FAILURE(processor.OnEventTouchMotion(event));
320 }
321
322 /**
323 * @tc.name: TouchTransformProcessorTest_OnEventTouchUp_002
324 * @tc.desc: Test the funcation OnEventTouchUp
325 * @tc.type: FUNC
326 * @tc.require:
327 */
328 HWTEST_F(TouchTransformProcessorTest, OnEventTouchUp_002, TestSize.Level1)
329 {
330 CALL_TEST_DEBUG;
331 int32_t deviceId = 6;
332 TouchTransformProcessor processor(deviceId);
333 libinput_event* event = nullptr;
334 bool ret = processor.OnEventTouchUp(event);
335 ASSERT_FALSE(ret);
336 processor.pointerEvent_ = PointerEvent::Create();
337 ASSERT_TRUE(processor.pointerEvent_ != nullptr);
338 vTouchscreen_.SendEvent(EV_ABS, ABS_MT_POSITION_X, 6486);
339 vTouchscreen_.SendEvent(EV_ABS, ABS_MT_POSITION_Y, 7289);
340 vTouchscreen_.SendEvent(EV_ABS, ABS_MT_PRESSURE, 313);
341 vTouchscreen_.SendEvent(EV_ABS, ABS_MT_TRACKING_ID, 0);
342 vTouchscreen_.SendEvent(EV_ABS, ABS_MT_TOUCH_MAJOR, 198);
343 vTouchscreen_.SendEvent(EV_ABS, ABS_MT_TOUCH_MINOR, 180);
344 vTouchscreen_.SendEvent(EV_ABS, ABS_MT_ORIENTATION, -58);
345 vTouchscreen_.SendEvent(EV_ABS, ABS_MT_BLOB_ID, 2);
346 vTouchscreen_.SendEvent(EV_SYN, SYN_MT_REPORT, 0);
347 vTouchscreen_.SendEvent(EV_KEY, BTN_TOUCH, 0);
348 vTouchscreen_.SendEvent(EV_SYN, SYN_REPORT, 0);
349 event = libinput_.Dispatch();
350 ASSERT_TRUE(event != nullptr);
351 auto touch = libinput_event_get_touch_event(event);
352 ASSERT_TRUE(touch != nullptr);
353 EXPECT_NO_FATAL_FAILURE(processor.OnEventTouchUp(event));
354 }
355
356 /**
357 * @tc.name: TouchTransformProcessorTest_OnEvent_001
358 * @tc.desc: Test OnEvent
359 * @tc.type: FUNC
360 * @tc.require:
361 */
362 HWTEST_F(TouchTransformProcessorTest, TouchTransformProcessorTest_OnEvent_001, TestSize.Level1)
363 {
364 CALL_TEST_DEBUG;
365 int32_t deviceId = 6;
366 vTouchscreen_.SendEvent(EV_ABS, ABS_MT_TRACKING_ID, 0);
367 vTouchscreen_.SendEvent(EV_ABS, ABS_MT_POSITION_X, 5190);
368 vTouchscreen_.SendEvent(EV_ABS, ABS_MT_POSITION_Y, 8306);
369 vTouchscreen_.SendEvent(EV_ABS, ABS_MT_PRESSURE, 321);
370 vTouchscreen_.SendEvent(EV_ABS, ABS_MT_TOUCH_MAJOR, 198);
371 vTouchscreen_.SendEvent(EV_ABS, ABS_MT_TOUCH_MINOR, 180);
372 vTouchscreen_.SendEvent(EV_ABS, ABS_MT_ORIENTATION, -64);
373 vTouchscreen_.SendEvent(EV_ABS, ABS_MT_BLOB_ID, 2);
374 vTouchscreen_.SendEvent(EV_SYN, SYN_MT_REPORT, 0);
375 vTouchscreen_.SendEvent(EV_KEY, BTN_TOUCH, 1);
376 vTouchscreen_.SendEvent(EV_SYN, SYN_REPORT, 0);
377 libinput_event *event = libinput_.Dispatch();
378 ASSERT_TRUE(event != nullptr);
379 struct libinput_device *dev = libinput_event_get_device(event);
380 ASSERT_TRUE(dev != nullptr);
381 std::cout << "pointer device: " << libinput_device_get_name(dev) << std::endl;
382 TouchTransformProcessor processor(deviceId);
383 processor.pointerEvent_ = nullptr;
384 auto ret = processor.OnEvent(event);
385 ASSERT_FALSE(ret);
386 processor.pointerEvent_ = PointerEvent::Create();
387 ASSERT_TRUE(processor.pointerEvent_ != nullptr);
388 EXPECT_NO_FATAL_FAILURE(processor.OnEvent(event));
389 }
390
391 /**
392 * @tc.name: TouchTransformProcessorTest_OnEvent_002
393 * @tc.desc: Test OnEvent
394 * @tc.type: FUNC
395 * @tc.require:
396 */
397 HWTEST_F(TouchTransformProcessorTest, TouchTransformProcessorTest_OnEvent_002, TestSize.Level1)
398 {
399 CALL_TEST_DEBUG;
400 int32_t deviceId = 6;
401 TouchTransformProcessor processor(deviceId);
402 processor.pointerEvent_ = PointerEvent::Create();
403 ASSERT_TRUE(processor.pointerEvent_ != nullptr);
404 vTouchscreen_.SendEvent(EV_ABS, ABS_MT_POSITION_X, 5199);
405 vTouchscreen_.SendEvent(EV_ABS, ABS_MT_POSITION_Y, 8297);
406 vTouchscreen_.SendEvent(EV_ABS, ABS_MT_PRESSURE, 356);
407 vTouchscreen_.SendEvent(EV_ABS, ABS_MT_TRACKING_ID, 0);
408 vTouchscreen_.SendEvent(EV_ABS, ABS_MT_TOUCH_MAJOR, 216);
409 vTouchscreen_.SendEvent(EV_ABS, ABS_MT_TOUCH_MINOR, 162);
410 vTouchscreen_.SendEvent(EV_ABS, ABS_MT_ORIENTATION, -79);
411 vTouchscreen_.SendEvent(EV_ABS, ABS_MT_BLOB_ID, 2);
412 vTouchscreen_.SendEvent(EV_SYN, SYN_MT_REPORT, 0);
413 vTouchscreen_.SendEvent(EV_SYN, SYN_REPORT, 0);
414 libinput_event *event = libinput_.Dispatch();
415 ASSERT_TRUE(event != nullptr);
416 struct libinput_device *dev = libinput_event_get_device(event);
417 ASSERT_TRUE(dev != nullptr);
418 std::cout << "pointer device: " << libinput_device_get_name(dev) << std::endl;
419 EXPECT_NO_FATAL_FAILURE(processor.OnEvent(event));
420 }
421
422 /**
423 * @tc.name: TouchTransformProcessorTest_OnEvent_003
424 * @tc.desc: Test OnEvent
425 * @tc.type: FUNC
426 * @tc.require:
427 */
428 HWTEST_F(TouchTransformProcessorTest, TouchTransformProcessorTest_OnEvent_003, TestSize.Level1)
429 {
430 CALL_TEST_DEBUG;
431 int32_t deviceId = 6;
432 TouchTransformProcessor processor(deviceId);
433 processor.pointerEvent_ = PointerEvent::Create();
434 ASSERT_TRUE(processor.pointerEvent_ != nullptr);
435 vTouchscreen_.SendEvent(EV_ABS, ABS_MT_POSITION_X, 6486);
436 vTouchscreen_.SendEvent(EV_ABS, ABS_MT_POSITION_Y, 7289);
437 vTouchscreen_.SendEvent(EV_ABS, ABS_MT_PRESSURE, 313);
438 vTouchscreen_.SendEvent(EV_ABS, ABS_MT_TRACKING_ID, 0);
439 vTouchscreen_.SendEvent(EV_ABS, ABS_MT_TOUCH_MAJOR, 198);
440 vTouchscreen_.SendEvent(EV_ABS, ABS_MT_TOUCH_MINOR, 180);
441 vTouchscreen_.SendEvent(EV_ABS, ABS_MT_ORIENTATION, -58);
442 vTouchscreen_.SendEvent(EV_ABS, ABS_MT_BLOB_ID, 2);
443 vTouchscreen_.SendEvent(EV_SYN, SYN_MT_REPORT, 0);
444 vTouchscreen_.SendEvent(EV_KEY, BTN_TOUCH, 0);
445 vTouchscreen_.SendEvent(EV_SYN, SYN_REPORT, 0);
446 libinput_event *event = libinput_.Dispatch();
447 ASSERT_TRUE(event != nullptr);
448 struct libinput_device *dev = libinput_event_get_device(event);
449 ASSERT_TRUE(dev != nullptr);
450 std::cout << "pointer device: " << libinput_device_get_name(dev) << std::endl;
451 EXPECT_NO_FATAL_FAILURE(processor.OnEvent(event));
452 }
453
454 /**
455 * @tc.name: TouchTransformProcessorTest_TouchTransformProcessorTest_MoveFlag_001
456 * @tc.desc: Test the field MoveFlag
457 * @tc.type: FUNC
458 * @tc.require:
459 */
460 HWTEST_F(TouchTransformProcessorTest, TouchTransformProcessorTest_MoveFlag_001, TestSize.Level1)
461 {
462 CALL_TEST_DEBUG;
463 libinput_.DrainEvents();
464 int32_t varMoveFlag = 0;
465 for (varMoveFlag = 1; varMoveFlag <= MAX_MOVE_FLAG; varMoveFlag++) {
466 vUwbRemoteControl_.SendEvent(EV_ABS, ABS_MT_TRACKING_ID, 0);
467 vUwbRemoteControl_.SendEvent(EV_ABS, ABS_MT_POSITION_X, 5190 + varMoveFlag*30);
468 vUwbRemoteControl_.SendEvent(EV_ABS, ABS_MT_POSITION_Y, 8306);
469 vUwbRemoteControl_.SendEvent(EV_ABS, ABS_MT_PRESSURE, 321);
470 vUwbRemoteControl_.SendEvent(EV_ABS, ABS_MT_TOUCH_MAJOR, 198);
471 vUwbRemoteControl_.SendEvent(EV_ABS, ABS_MT_TOUCH_MINOR, 180);
472 vUwbRemoteControl_.SendEvent(EV_ABS, ABS_MT_ORIENTATION, -64);
473 vUwbRemoteControl_.SendEvent(EV_ABS, ABS_MT_BLOB_ID, 2);
474 vUwbRemoteControl_.SendEvent(EV_SYN, SYN_MT_REPORT, 0);
475 if (varMoveFlag != MAX_MOVE_FLAG) {
476 vUwbRemoteControl_.SendEvent(EV_KEY, BTN_TOUCH, 1);
477 } else {
478 vUwbRemoteControl_.SendEvent(EV_KEY, BTN_TOUCH, 0);
479 }
480 vUwbRemoteControl_.SendEvent(EV_SYN, SYN_REPORT, 0);
481 }
482 libinput_event *event = libinput_.Dispatch();
483 while (event != nullptr) {
484 auto type = libinput_event_get_type(event);
485 if (type == LIBINPUT_EVENT_TOUCH_CANCEL || type == LIBINPUT_EVENT_TOUCH_FRAME) {
486 event = libinput_.Dispatch();
487 continue;
488 }
489 auto touch = libinput_event_get_touch_event(event);
490 ASSERT_TRUE(touch != nullptr);
491 int32_t moveFlag = libinput_event_touch_get_move_flag(touch);
492 ASSERT_EQ(moveFlag, -1);
493 event = libinput_.Dispatch();
494 }
495 }
496
497 /**
498 * @tc.name: TouchTransformProcessorTest_TouchTransformProcessorTest_MoveFlag_002
499 * @tc.desc: Test the field MoveFlag
500 * @tc.type: FUNC
501 * @tc.require:
502 */
503 HWTEST_F(TouchTransformProcessorTest, TouchTransformProcessorTest_MoveFlag_002, TestSize.Level1)
504 {
505 CALL_TEST_DEBUG;
506 libinput_.DrainEvents();
507 int32_t varMoveFlag = 0;
508 for (varMoveFlag = 1; varMoveFlag <= MAX_MOVE_FLAG; varMoveFlag++) {
509 vUwbRemoteControl_.SendEvent(EV_ABS, ABS_MT_TRACKING_ID, 0);
510 vUwbRemoteControl_.SendEvent(EV_ABS, ABS_MT_POSITION_X, 5190 + varMoveFlag*30);
511 vUwbRemoteControl_.SendEvent(EV_ABS, ABS_MT_POSITION_Y, 8306);
512 vUwbRemoteControl_.SendEvent(EV_ABS, ABS_MT_PRESSURE, 321);
513 vUwbRemoteControl_.SendEvent(EV_ABS, ABS_MT_MOVEFLAG, varMoveFlag);
514 vUwbRemoteControl_.SendEvent(EV_ABS, ABS_MT_TOUCH_MAJOR, 198);
515 vUwbRemoteControl_.SendEvent(EV_ABS, ABS_MT_TOUCH_MINOR, 180);
516 vUwbRemoteControl_.SendEvent(EV_ABS, ABS_MT_ORIENTATION, -64);
517 vUwbRemoteControl_.SendEvent(EV_ABS, ABS_MT_BLOB_ID, 2);
518 vUwbRemoteControl_.SendEvent(EV_SYN, SYN_MT_REPORT, 0);
519 if (varMoveFlag != MAX_MOVE_FLAG) {
520 vUwbRemoteControl_.SendEvent(EV_KEY, BTN_TOUCH, 1);
521 } else {
522 vUwbRemoteControl_.SendEvent(EV_KEY, BTN_TOUCH, 0);
523 }
524 vUwbRemoteControl_.SendEvent(EV_SYN, SYN_REPORT, 0);
525 }
526 libinput_event *event = libinput_.Dispatch();
527 varMoveFlag = 1;
528 while (event != nullptr) {
529 auto type = libinput_event_get_type(event);
530 if (type == LIBINPUT_EVENT_TOUCH_CANCEL || type == LIBINPUT_EVENT_TOUCH_FRAME) {
531 event = libinput_.Dispatch();
532 continue;
533 }
534 auto touch = libinput_event_get_touch_event(event);
535 ASSERT_TRUE(touch != nullptr);
536 int32_t moveFlag = libinput_event_touch_get_move_flag(touch);
537 ASSERT_EQ(moveFlag, varMoveFlag);
538 varMoveFlag++;
539 event = libinput_.Dispatch();
540 }
541 }
542 } // namespace MMI
543 } // namespace OHOS