• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <cstdio>
17 #include <gtest/gtest.h>
18 
19 #include "touch_gesture_detector.h"
20 #include "mmi_log.h"
21 
22 #undef MMI_LOG_TAG
23 #define MMI_LOG_TAG "TouchGestureDetectorTest"
24 
25 namespace OHOS {
26 namespace MMI {
27 using namespace testing;
28 using namespace testing::ext;
29 
30 class TouchGestureDetectorTest : public testing::Test {
31 public:
32     static void SetUpTestCase(void);
33     static void TearDownTestCase(void);
34     void SetUp();
35     void TearDown();
36 };
37 
38 class MyGestureListener : public TouchGestureDetector::GestureListener {
39 public:
OnGestureEvent(std::shared_ptr<PointerEvent> event,GestureMode mode)40     bool OnGestureEvent(std::shared_ptr<PointerEvent> event, GestureMode mode) override
41     {
42         return true;
43     }
44 
OnGestureTrend(std::shared_ptr<PointerEvent> event)45     void OnGestureTrend(std::shared_ptr<PointerEvent> event) override {}
46 };
47 
SetUpTestCase(void)48 void TouchGestureDetectorTest::SetUpTestCase(void)
49 {}
50 
TearDownTestCase(void)51 void TouchGestureDetectorTest::TearDownTestCase(void)
52 {}
53 
SetUp()54 void TouchGestureDetectorTest::SetUp()
55 {}
56 
TearDown()57 void TouchGestureDetectorTest::TearDown()
58 {}
59 
60 /**
61  * @tc.name: TouchGestureDetectorTest_OnTouchEvent_01
62  * @tc.desc: Test OnTouchEvent
63  * @tc.type: FUNC
64  * @tc.require:
65  */
66 HWTEST_F(TouchGestureDetectorTest, TouchGestureDetectorTest_OnTouchEvent_01, TestSize.Level1)
67 {
68     CALL_TEST_DEBUG;
69     auto listener = std::make_shared<MyGestureListener>();
70     TouchGestureType type = TOUCH_GESTURE_TYPE_SWIPE;
71     TouchGestureDetector detector(type, listener);
72     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
73     ASSERT_NE(pointerEvent, nullptr);
74 
75     pointerEvent->sourceType_ = PointerEvent::SOURCE_TYPE_TOUCHSCREEN;
76     detector.gestureEnable_ = true;
77     detector.gestureDisplayId_ = INT32_MAX;
78     pointerEvent->pointerAction_ = PointerEvent::POINTER_ACTION_UP;
79     pointerEvent->SetPointerId(0);
80     EXPECT_FALSE(detector.WhetherDiscardTouchEvent(pointerEvent));
81 
82     pointerEvent->pointerAction_ = PointerEvent::POINTER_ACTION_DOWN;
83     EXPECT_FALSE(detector.OnTouchEvent(pointerEvent));
84 
85     pointerEvent->pointerAction_ = PointerEvent::POINTER_ACTION_MOVE;
86     EXPECT_FALSE(detector.OnTouchEvent(pointerEvent));
87 
88     pointerEvent->pointerAction_ = PointerEvent::POINTER_ACTION_UP;
89     EXPECT_FALSE(detector.OnTouchEvent(pointerEvent));
90 
91     pointerEvent->pointerAction_ = PointerEvent::POINTER_ACTION_AXIS_BEGIN;
92     EXPECT_FALSE(detector.OnTouchEvent(pointerEvent));
93 }
94 
95 /**
96  * @tc.name: TouchGestureDetectorTest_OnTouchEvent_02
97  * @tc.desc: Test OnTouchEvent
98  * @tc.type: FUNC
99  * @tc.require:
100  */
101 HWTEST_F(TouchGestureDetectorTest, TouchGestureDetectorTest_OnTouchEvent_02, TestSize.Level1)
102 {
103     CALL_TEST_DEBUG;
104     auto listener = std::make_shared<MyGestureListener>();
105     TouchGestureType type = TOUCH_GESTURE_TYPE_SWIPE;
106     TouchGestureDetector detector(type, listener);
107     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
108     ASSERT_NE(pointerEvent, nullptr);
109 
110     pointerEvent->sourceType_ = PointerEvent::SOURCE_TYPE_TOUCHSCREEN;
111     detector.gestureEnable_ = false;
112     EXPECT_TRUE(detector.WhetherDiscardTouchEvent(pointerEvent));
113     EXPECT_FALSE(detector.OnTouchEvent(pointerEvent));
114 }
115 
116 /**
117  * @tc.name: TouchGestureDetectorTest_HandleDownEvent_01
118  * @tc.desc: Test HandleDownEvent
119  * @tc.type: FUNC
120  * @tc.require:
121  */
122 HWTEST_F(TouchGestureDetectorTest, TouchGestureDetectorTest_HandleDownEvent_01, TestSize.Level1)
123 {
124     CALL_TEST_DEBUG;
125     auto listener = std::make_shared<MyGestureListener>();
126     TouchGestureType type = TOUCH_GESTURE_TYPE_SWIPE;
127     TouchGestureDetector detector(type, listener);
128     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
129     ASSERT_NE(pointerEvent, nullptr);
130 
131     pointerEvent->pointerId_ = 3;
132     detector.isRecognized_ = false;
133 
134     std::list<PointerEvent::PointerItem> pointers_;
135     PointerEvent::PointerItem item1;
136     item1.SetPointerId(1);
137     PointerEvent::PointerItem item2;
138     item2.SetPointerId(2);
139     pointers_.push_back(item1);
140     pointers_.push_back(item2);
141 
142     bool ret = pointerEvent->GetPointerItem(pointerEvent->pointerId_, item2);
143     EXPECT_FALSE(ret);
144     ASSERT_NO_FATAL_FAILURE(detector.HandleDownEvent(pointerEvent));
145 }
146 
147 /**
148  * @tc.name: TouchGestureDetectorTest_HandleDownEvent_02
149  * @tc.desc: Test HandleDownEvent
150  * @tc.type: FUNC
151  * @tc.require:
152  */
153 HWTEST_F(TouchGestureDetectorTest, TouchGestureDetectorTest_HandleDownEvent_02, TestSize.Level1)
154 {
155     CALL_TEST_DEBUG;
156     auto listener = std::make_shared<MyGestureListener>();
157     TouchGestureType type = TOUCH_GESTURE_TYPE_SWIPE;
158     TouchGestureDetector detector(type, listener);
159     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
160     ASSERT_NE(pointerEvent, nullptr);
161     detector.isRecognized_ = true;
162     ASSERT_NO_FATAL_FAILURE(detector.HandleDownEvent(pointerEvent));
163 }
164 
165 /**
166  * @tc.name: TouchGestureDetectorTest_HandleMoveEvent_01
167  * @tc.desc: Test HandleMoveEvent
168  * @tc.type: FUNC
169  * @tc.require:
170  */
171 HWTEST_F(TouchGestureDetectorTest, TouchGestureDetectorTest_HandleMoveEvent_01, TestSize.Level1)
172 {
173     CALL_TEST_DEBUG;
174     auto listener = std::make_shared<MyGestureListener>();
175     TouchGestureType type = TOUCH_GESTURE_TYPE_SWIPE;
176     TouchGestureDetector detector(type, listener);
177     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
178     ASSERT_NE(pointerEvent, nullptr);
179     detector.downPoint_[1] = Point(1.0f, 2.0f);
180     detector.downPoint_[2] = Point(3.0f, 4.0f);
181     detector.downPoint_[3] = Point(5.0f, 6.0f);
182 
183     detector.fingers_.insert(1);
184     detector.fingers_.insert(0);
185     detector.fingers_.insert(3);
186     EXPECT_TRUE(detector.IsMatchGesture(ALL_FINGER_COUNT));
187 
188     detector.isRecognized_ = false;
189     ASSERT_NO_FATAL_FAILURE(detector.HandleMoveEvent(pointerEvent));
190     detector.gestureType_ = TOUCH_GESTURE_TYPE_SWIPE;
191     ASSERT_NO_FATAL_FAILURE(detector.HandleMoveEvent(pointerEvent));
192 
193     detector.gestureType_ = TOUCH_GESTURE_TYPE_PINCH;
194     ASSERT_NO_FATAL_FAILURE(detector.HandleMoveEvent(pointerEvent));
195 
196     detector.gestureType_ = 8;
197     ASSERT_NO_FATAL_FAILURE(detector.HandleMoveEvent(pointerEvent));
198 }
199 
200 /**
201  * @tc.name: TouchGestureDetectorTest_HandleMoveEvent_02
202  * @tc.desc: Test HandleMoveEvent
203  * @tc.type: FUNC
204  * @tc.require:
205  */
206 HWTEST_F(TouchGestureDetectorTest, TouchGestureDetectorTest_HandleMoveEvent_02, TestSize.Level1)
207 {
208     CALL_TEST_DEBUG;
209     auto listener = std::make_shared<MyGestureListener>();
210     TouchGestureType type = TOUCH_GESTURE_TYPE_SWIPE;
211     TouchGestureDetector detector(type, listener);
212     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
213     ASSERT_NE(pointerEvent, nullptr);
214     detector.downPoint_[1] = Point(1.0f, 2.0f);
215     detector.downPoint_[2] = Point(3.0f, 4.0f);
216     detector.downPoint_[3] = Point(5.0f, 6.0f);
217 
218     detector.fingers_.insert(1);
219     detector.fingers_.insert(0);
220     detector.fingers_.insert(3);
221     detector.isRecognized_ = true;
222     ASSERT_NO_FATAL_FAILURE(detector.HandleMoveEvent(pointerEvent));
223 }
224 
225 /**
226  * @tc.name: TouchGestureDetectorTest_HandleMoveEvent_03
227  * @tc.desc: Test HandleMoveEvent
228  * @tc.type: FUNC
229  * @tc.require:
230  */
231 HWTEST_F(TouchGestureDetectorTest, TouchGestureDetectorTest_HandleMoveEvent_03, TestSize.Level1)
232 {
233     CALL_TEST_DEBUG;
234     auto listener = std::make_shared<MyGestureListener>();
235     TouchGestureType type = TOUCH_GESTURE_TYPE_SWIPE;
236     TouchGestureDetector detector(type, listener);
237     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
238     ASSERT_NE(pointerEvent, nullptr);
239 
240     detector.downPoint_[1] = Point(1.0f, 2.0f);
241     detector.downPoint_[2] = Point(3.0f, 4.0f);
242     ASSERT_NO_FATAL_FAILURE(detector.HandleMoveEvent(pointerEvent));
243 }
244 
245 /**
246  * @tc.name: TouchGestureDetectorTest_HandleSwipeMoveEvent_01
247  * @tc.desc: Test HandleSwipeMoveEvent
248  * @tc.type: FUNC
249  * @tc.require:
250  */
251 HWTEST_F(TouchGestureDetectorTest, TouchGestureDetectorTest_HandleSwipeMoveEvent_01, TestSize.Level1)
252 {
253     CALL_TEST_DEBUG;
254     auto listener = std::make_shared<MyGestureListener>();
255     TouchGestureType type = TOUCH_GESTURE_TYPE_SWIPE;
256     TouchGestureDetector detector(type, listener);
257     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
258     ASSERT_NE(pointerEvent, nullptr);
259 
260     detector.downPoint_[1] = Point(1.0f, 2.0f);
261     detector.downPoint_[2] = Point(3.0f, 4.0f, 150000);
262     detector.isFingerReady_ = false;
263     ASSERT_NO_FATAL_FAILURE(detector.HandleSwipeMoveEvent(pointerEvent));
264 }
265 
266 /**
267  * @tc.name: TouchGestureDetectorTest_HandleSwipeMoveEvent_02
268  * @tc.desc: Test HandleSwipeMoveEvent
269  * @tc.type: FUNC
270  * @tc.require:
271  */
272 HWTEST_F(TouchGestureDetectorTest, TouchGestureDetectorTest_HandleSwipeMoveEvent_02, TestSize.Level1)
273 {
274     CALL_TEST_DEBUG;
275     auto listener = std::make_shared<MyGestureListener>();
276     TouchGestureType type = TOUCH_GESTURE_TYPE_SWIPE;
277     TouchGestureDetector detector(type, listener);
278     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
279     ASSERT_NE(pointerEvent, nullptr);
280 
281     detector.downPoint_[1] = Point(1.0f, 2.0f);
282     detector.downPoint_[2] = Point(3.0f, 4.0f, 150000);
283     detector.downPoint_[3] = Point(5.0f, 6.0f, 200000);
284     detector.isFingerReady_ = true;
285 
286     auto state = detector.ClacFingerMoveDirection(pointerEvent);
287     state = TouchGestureDetector::SlideState::DIRECTION_UNKNOW;
288     ASSERT_NO_FATAL_FAILURE(detector.HandleSwipeMoveEvent(pointerEvent));
289 
290     state = TouchGestureDetector::SlideState::DIRECTION_DOWN;
291     GestureMode mode = detector.ChangeToGestureMode(state);
292     EXPECT_FALSE(detector.NotifyGestureEvent(pointerEvent, mode));
293     ASSERT_NO_FATAL_FAILURE(detector.HandleSwipeMoveEvent(pointerEvent));
294 }
295 
296 /**
297  * @tc.name: TouchGestureDetectorTest_HandlePinchMoveEvent_01
298  * @tc.desc: Test HandlePinchMoveEvent
299  * @tc.type: FUNC
300  * @tc.require:
301  */
302 HWTEST_F(TouchGestureDetectorTest, TouchGestureDetectorTest_HandlePinchMoveEvent_01, TestSize.Level1)
303 {
304     CALL_TEST_DEBUG;
305     auto listener = std::make_shared<MyGestureListener>();
306     TouchGestureType type = TOUCH_GESTURE_TYPE_SWIPE;
307     TouchGestureDetector detector(type, listener);
308     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
309     ASSERT_NE(pointerEvent, nullptr);
310 
311     detector.downPoint_[1] = Point(1.0f, 2.0f);
312     detector.downPoint_[2] = Point(3.0f, 4.0f);
313     EXPECT_TRUE(detector.lastDistance_.empty());
314     ASSERT_NO_FATAL_FAILURE(detector.HandlePinchMoveEvent(pointerEvent));
315 }
316 
317 /**
318  * @tc.name: TouchGestureDetectorTest_HandlePinchMoveEvent_02
319  * @tc.desc: Test HandlePinchMoveEvent
320  * @tc.type: FUNC
321  * @tc.require:
322  */
323 HWTEST_F(TouchGestureDetectorTest, TouchGestureDetectorTest_HandlePinchMoveEvent_02, TestSize.Level1)
324 {
325     CALL_TEST_DEBUG;
326     auto listener = std::make_shared<MyGestureListener>();
327     TouchGestureType type = TOUCH_GESTURE_TYPE_SWIPE;
328     TouchGestureDetector detector(type, listener);
329     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
330     ASSERT_NE(pointerEvent, nullptr);
331 
332     detector.downPoint_[1] = Point(1.0f, 2.0f);
333     detector.downPoint_[2] = Point(3.0f, 4.0f);
334     detector.downPoint_[3] = Point(5.0f, 6.0f);
335     detector.downPoint_[4] = Point(7.0f, 8.0f);
336 
337     detector.lastDistance_[1] = 1.0;
338     detector.lastDistance_[2] = 2.0;
339     detector.lastDistance_[3] = 3.0;
340     EXPECT_FALSE(detector.lastDistance_.empty());
341     ASSERT_NO_FATAL_FAILURE(detector.HandlePinchMoveEvent(pointerEvent));
342 }
343 
344 /**
345  * @tc.name: TouchGestureDetectorTest_HandleUpEvent_01
346  * @tc.desc: Test HandleUpEvent
347  * @tc.type: FUNC
348  * @tc.require:
349  */
350 HWTEST_F(TouchGestureDetectorTest, TouchGestureDetectorTest_HandleUpEvent_01, TestSize.Level1)
351 {
352     CALL_TEST_DEBUG;
353     auto listener = std::make_shared<MyGestureListener>();
354     TouchGestureType type = TOUCH_GESTURE_TYPE_SWIPE;
355     TouchGestureDetector detector(type, listener);
356     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
357     ASSERT_NE(pointerEvent, nullptr);
358     pointerEvent->pointerId_ = 1;
359     detector.downPoint_[1] = Point(1.0f, 2.0f);
360     detector.downPoint_[2] = Point(3.0f, 4.0f);
361     ASSERT_NO_FATAL_FAILURE(detector.HandleUpEvent(pointerEvent));
362 
363     pointerEvent->pointerId_ = 3;
364     ASSERT_NO_FATAL_FAILURE(detector.HandleUpEvent(pointerEvent));
365 }
366 
367 /**
368  * @tc.name: TouchGestureDetectorTest_HandleUpEvent_02
369  * @tc.desc: Test HandleUpEvent
370  * @tc.type: FUNC
371  * @tc.require:
372  */
373 HWTEST_F(TouchGestureDetectorTest, TouchGestureDetectorTest_HandleUpEvent_02, TestSize.Level1)
374 {
375     CALL_TEST_DEBUG;
376     auto listener = std::make_shared<MyGestureListener>();
377     TouchGestureType type = TOUCH_GESTURE_TYPE_SWIPE;
378     TouchGestureDetector detector(type, listener);
379     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
380     ASSERT_NE(pointerEvent, nullptr);
381     pointerEvent->pointerId_ = 1;
382     EXPECT_TRUE(detector.downPoint_.empty());
383     ASSERT_NO_FATAL_FAILURE(detector.HandleUpEvent(pointerEvent));
384 }
385 
386 /**
387  * @tc.name: TouchGestureDetectorTest_WhetherDiscardTouchEvent_01
388  * @tc.desc: Test WhetherDiscardTouchEvent
389  * @tc.type: FUNC
390  * @tc.require:
391  */
392 HWTEST_F(TouchGestureDetectorTest, TouchGestureDetectorTest_WhetherDiscardTouchEvent_01, TestSize.Level1)
393 {
394     CALL_TEST_DEBUG;
395     auto listener = std::make_shared<MyGestureListener>();
396     TouchGestureType type = TOUCH_GESTURE_TYPE_SWIPE;
397     TouchGestureDetector detector(type, listener);
398     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
399     ASSERT_NE(pointerEvent, nullptr);
400 
401     pointerEvent->sourceType_ = PointerEvent::SOURCE_TYPE_MOUSE;
402     EXPECT_TRUE(detector.WhetherDiscardTouchEvent(pointerEvent));
403 
404     pointerEvent->sourceType_ = PointerEvent::SOURCE_TYPE_TOUCHSCREEN;
405     detector.gestureEnable_ = false;
406     EXPECT_TRUE(detector.WhetherDiscardTouchEvent(pointerEvent));
407 
408     pointerEvent->sourceType_ = PointerEvent::SOURCE_TYPE_TOUCHSCREEN;
409     detector.gestureEnable_ = true;
410     pointerEvent->bitwise_ = InputEvent::EVENT_FLAG_SIMULATE;
411     pointerEvent->SetPointerId(0);
412     EXPECT_TRUE(detector.WhetherDiscardTouchEvent(pointerEvent));
413 
414     pointerEvent->sourceType_ = PointerEvent::SOURCE_TYPE_TOUCHSCREEN;
415     detector.gestureEnable_ = true;
416     detector.gestureDisplayId_ = INT32_MAX - 2;
417     pointerEvent->bitwise_ = 0;
418     pointerEvent->SetPointerId(7);
419     pointerEvent->targetDisplayId_ = INT32_MAX - 1;
420     EXPECT_TRUE(detector.WhetherDiscardTouchEvent(pointerEvent));
421 
422     detector.gestureDisplayId_ = INT32_MAX;
423     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UP);
424     EXPECT_FALSE(detector.WhetherDiscardTouchEvent(pointerEvent));
425 
426     detector.gestureDisplayId_ = INT32_MAX;
427     pointerEvent->targetDisplayId_ = INT32_MAX;
428     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
429     EXPECT_FALSE(detector.WhetherDiscardTouchEvent(pointerEvent));
430 }
431 
432 /**
433  * @tc.name: TouchGestureDetectorTest_HandleFingerDown_01
434  * @tc.desc: Test HandleFingerDown
435  * @tc.type: FUNC
436  * @tc.require:
437  */
438 HWTEST_F(TouchGestureDetectorTest, TouchGestureDetectorTest_HandleFingerDown_01, TestSize.Level1)
439 {
440     CALL_TEST_DEBUG;
441     auto listener = std::make_shared<MyGestureListener>();
442     TouchGestureType type = TOUCH_GESTURE_TYPE_SWIPE;
443     TouchGestureDetector detector(type, listener);
444     detector.downPoint_[1] = Point(1.0f, 2.0f);
445     detector.downPoint_[2] = Point(3.0f, 4.0f);
446     auto fingersCount = detector.downPoint_.size();
447     EXPECT_TRUE(fingersCount < 3);
448     EXPECT_FALSE(detector.HandleFingerDown());
449 }
450 
451 /**
452  * @tc.name: TouchGestureDetectorTest_HandleFingerDown_02
453  * @tc.desc: Test HandleFingerDown
454  * @tc.type: FUNC
455  * @tc.require:
456  */
457 HWTEST_F(TouchGestureDetectorTest, TouchGestureDetectorTest_HandleFingerDown_02, TestSize.Level1)
458 {
459     CALL_TEST_DEBUG;
460     auto listener = std::make_shared<MyGestureListener>();
461     TouchGestureType type = TOUCH_GESTURE_TYPE_SWIPE;
462     TouchGestureDetector detector(type, listener);
463     detector.downPoint_[1] = Point(0.0f, 0.0f);
464     detector.downPoint_[2] = Point(1000.0f, 1000.0f);
465     detector.downPoint_[3] = Point(-1000.0f, -1000.0f);
466     detector.downPoint_[4] = Point(500.0f, -500.0f);
467     detector.downPoint_[5] = Point(-500.0f, 500.0f);
468     EXPECT_FALSE(detector.HandleFingerDown());
469 }
470 
471 /**
472  * @tc.name: TouchGestureDetectorTest_HandleFingerDown_03
473  * @tc.desc: Test HandleFingerDown
474  * @tc.type: FUNC
475  * @tc.require:
476  */
477 HWTEST_F(TouchGestureDetectorTest, TouchGestureDetectorTest_HandleFingerDown_03, TestSize.Level1)
478 {
479     CALL_TEST_DEBUG;
480     auto listener = std::make_shared<MyGestureListener>();
481     TouchGestureType type = TOUCH_GESTURE_TYPE_SWIPE;
482     TouchGestureDetector detector(type, listener);
483     detector.downPoint_[1] = Point(0.0f, 0.0f);
484     detector.downPoint_[2] = Point(100.0f, 100.0f);
485     detector.downPoint_[3] = Point(200.0f, 200.0f);
486     detector.downPoint_[4] = Point(300.0f, 300.0f);
487     detector.downPoint_[5] = Point(400.0f, 400.0f);
488     EXPECT_TRUE(detector.HandleFingerDown());
489 }
490 
491 /**
492  * @tc.name: TouchGestureDetectorTest_HandleFingerDown_04
493  * @tc.desc: Test HandleFingerDown
494  * @tc.type: FUNC
495  * @tc.require:
496  */
497 HWTEST_F(TouchGestureDetectorTest, TouchGestureDetectorTest_HandleFingerDown_04, TestSize.Level1)
498 {
499     CALL_TEST_DEBUG;
500     auto listener = std::make_shared<MyGestureListener>();
501     TouchGestureType type = TOUCH_GESTURE_TYPE_SWIPE;
502     TouchGestureDetector detector(type, listener);
503     detector.downPoint_[1] = Point(0.0f, 0.0f, 50000);
504     detector.downPoint_[2] = Point(100.0f, 100.0f, 150000);
505     detector.downPoint_[3] = Point(200.0f, 200.0f, 250000);
506     EXPECT_FALSE(detector.HandleFingerDown());
507 }
508 
509 /**
510  * @tc.name: TouchGestureDetectorTest_GetMaxFingerSpacing_01
511  * @tc.desc: Test GetMaxFingerSpacing
512  * @tc.type: FUNC
513  * @tc.require:
514  */
515 HWTEST_F(TouchGestureDetectorTest, TouchGestureDetectorTest_GetMaxFingerSpacing_01, TestSize.Level1)
516 {
517     CALL_TEST_DEBUG;
518     auto listener = std::make_shared<MyGestureListener>();
519     TouchGestureType type = TOUCH_GESTURE_TYPE_SWIPE;
520     TouchGestureDetector detector(type, listener);
521     detector.downPoint_[1] = Point(1.0f, 2.0f);
522     detector.downPoint_[2] = Point(3.0f, 4.0f);
523     ASSERT_NO_FATAL_FAILURE(detector.GetMaxFingerSpacing());
524 }
525 
526 /**
527  * @tc.name: TouchGestureDetectorTest_GetMaxFingerSpacing_02
528  * @tc.desc: Test GetMaxFingerSpacing
529  * @tc.type: FUNC
530  * @tc.require:
531  */
532 HWTEST_F(TouchGestureDetectorTest, TouchGestureDetectorTest_GetMaxFingerSpacing_02, TestSize.Level1)
533 {
534     CALL_TEST_DEBUG;
535     auto listener = std::make_shared<MyGestureListener>();
536     TouchGestureType type = TOUCH_GESTURE_TYPE_SWIPE;
537     TouchGestureDetector detector(type, listener);
538     detector.downPoint_[1] = Point(1.0f, 2.0f);
539     detector.downPoint_[2] = Point(3.0f, 4.0f);
540     detector.downPoint_[3] = Point(5.0f, 6.0f);
541     ASSERT_NO_FATAL_FAILURE(detector.GetMaxFingerSpacing());
542 }
543 
544 /**
545  * @tc.name: TouchGestureDetectorTest_GetMaxDownInterval_01
546  * @tc.desc: Test GetMaxDownInterval
547  * @tc.type: FUNC
548  * @tc.require:
549  */
550 HWTEST_F(TouchGestureDetectorTest, TouchGestureDetectorTest_GetMaxDownInterval_01, TestSize.Level1)
551 {
552     CALL_TEST_DEBUG;
553     auto listener = std::make_shared<MyGestureListener>();
554     TouchGestureType type = TOUCH_GESTURE_TYPE_SWIPE;
555     TouchGestureDetector detector(type, listener);
556     detector.downPoint_[1] = Point(1.0f, 2.0f);
557     detector.downPoint_[2] = Point(3.0f, 4.0f);
558     ASSERT_NO_FATAL_FAILURE(detector.GetMaxDownInterval());
559 }
560 
561 /**
562  * @tc.name: TouchGestureDetectorTest_GetMaxDownInterval_02
563  * @tc.desc: Test GetMaxDownInterval
564  * @tc.type: FUNC
565  * @tc.require:
566  */
567 HWTEST_F(TouchGestureDetectorTest, TouchGestureDetectorTest_GetMaxDownInterval_02, TestSize.Level1)
568 {
569     CALL_TEST_DEBUG;
570     auto listener = std::make_shared<MyGestureListener>();
571     TouchGestureType type = TOUCH_GESTURE_TYPE_SWIPE;
572     TouchGestureDetector detector(type, listener);
573     detector.downPoint_[1] = Point(1.0f, 2.0f);
574     detector.downPoint_[2] = Point(3.0f, 4.0f);
575     detector.downPoint_[3] = Point(5.0f, 6.0f);
576     ASSERT_NO_FATAL_FAILURE(detector.GetMaxDownInterval());
577 }
578 
579 /**
580  * @tc.name: TouchGestureDetectorTest_GetSlidingDirection_01
581  * @tc.desc: Test GetSlidingDirection
582  * @tc.type: FUNC
583  * @tc.require:
584  */
585 HWTEST_F(TouchGestureDetectorTest, TouchGestureDetectorTest_GetSlidingDirection_01, TestSize.Level1)
586 {
587     CALL_TEST_DEBUG;
588     auto listener = std::make_shared<MyGestureListener>();
589     TouchGestureType type = TOUCH_GESTURE_TYPE_SWIPE;
590     TouchGestureDetector detector(type, listener);
591     double angle;
592     angle = 20;
593     ASSERT_NO_FATAL_FAILURE(detector.GetSlidingDirection(angle));
594     angle = 50;
595     ASSERT_NO_FATAL_FAILURE(detector.GetSlidingDirection(angle));
596     angle = -60;
597     ASSERT_NO_FATAL_FAILURE(detector.GetSlidingDirection(angle));
598     angle = 200;
599     ASSERT_NO_FATAL_FAILURE(detector.GetSlidingDirection(angle));
600 }
601 
602 /**
603  * @tc.name: TouchGestureDetectorTest_ChangeToGestureMode_01
604  * @tc.desc: Test ChangeToGestureMode
605  * @tc.type: FUNC
606  * @tc.require:
607  */
608 HWTEST_F(TouchGestureDetectorTest, TouchGestureDetectorTest_ChangeToGestureMode_01, TestSize.Level1)
609 {
610     CALL_TEST_DEBUG;
611     auto listener = std::make_shared<MyGestureListener>();
612     TouchGestureType type = TOUCH_GESTURE_TYPE_SWIPE;
613     TouchGestureDetector detector(type, listener);
614     TouchGestureDetector::SlideState state;
615     state = TouchGestureDetector::SlideState::DIRECTION_UP;
616     EXPECT_EQ(detector.ChangeToGestureMode(state), GestureMode::ACTION_SWIPE_UP);
617 
618     state = TouchGestureDetector::SlideState::DIRECTION_DOWN;
619     EXPECT_EQ(detector.ChangeToGestureMode(state), GestureMode::ACTION_SWIPE_DOWN);
620 
621     state = TouchGestureDetector::SlideState::DIRECTION_LEFT;
622     EXPECT_EQ(detector.ChangeToGestureMode(state), GestureMode::ACTION_SWIPE_LEFT);
623 
624     state = TouchGestureDetector::SlideState::DIRECTION_RIGHT;
625     EXPECT_EQ(detector.ChangeToGestureMode(state), GestureMode::ACTION_SWIPE_RIGHT);
626 
627     state = TouchGestureDetector::SlideState::DIRECTION_UNKNOW;
628     EXPECT_EQ(detector.ChangeToGestureMode(state), GestureMode::ACTION_UNKNOWN);
629 }
630 
631 /**
632  * @tc.name: TouchGestureDetectorTest_ClacFingerMoveDirection_01
633  * @tc.desc: Test ClacFingerMoveDirection
634  * @tc.type: FUNC
635  * @tc.require:
636  */
637 HWTEST_F(TouchGestureDetectorTest, TouchGestureDetectorTest_ClacFingerMoveDirection_01, TestSize.Level1)
638 {
639     CALL_TEST_DEBUG;
640     auto listener = std::make_shared<MyGestureListener>();
641     TouchGestureType type = TOUCH_GESTURE_TYPE_SWIPE;
642     TouchGestureDetector detector(type, listener);
643     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
644     ASSERT_NE(pointerEvent, nullptr);
645     pointerEvent->pointerAction_ = PointerEvent::POINTER_ACTION_UP;
646     ASSERT_NO_FATAL_FAILURE(detector.ClacFingerMoveDirection(pointerEvent));
647 
648     pointerEvent->pointerAction_ = PointerEvent::POINTER_ACTION_MOVE;
649     detector.downPoint_[1] = Point(1.0f, 2.0f);
650     detector.downPoint_[2] = Point(3.0f, 4.0f);
651     ASSERT_NO_FATAL_FAILURE(detector.ClacFingerMoveDirection(pointerEvent));
652 }
653 
654 /**
655  * @tc.name: TouchGestureDetectorTest_ClacFingerMoveDirection_02
656  * @tc.desc: Test ClacFingerMoveDirection
657  * @tc.type: FUNC
658  * @tc.require:
659  */
660 HWTEST_F(TouchGestureDetectorTest, TouchGestureDetectorTest_ClacFingerMoveDirection_02, TestSize.Level1)
661 {
662     CALL_TEST_DEBUG;
663     auto listener = std::make_shared<MyGestureListener>();
664     TouchGestureType type = TOUCH_GESTURE_TYPE_SWIPE;
665     TouchGestureDetector detector(type, listener);
666     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
667     ASSERT_NE(pointerEvent, nullptr);
668     pointerEvent->pointerAction_ = PointerEvent::POINTER_ACTION_MOVE;
669     detector.downPoint_[1] = Point(1.0f, 2.0f);
670     detector.downPoint_[2] = Point(3.0f, 4.0f);
671     detector.downPoint_[3] = Point(5.0f, 6.0f);
672     ASSERT_NO_FATAL_FAILURE(detector.ClacFingerMoveDirection(pointerEvent));
673 }
674 
675 /**
676  * @tc.name: TouchGestureDetectorTest_CalcGravityCenter_01
677  * @tc.desc: Test CalcGravityCenter
678  * @tc.type: FUNC
679  * @tc.require:
680  */
681 HWTEST_F(TouchGestureDetectorTest, TouchGestureDetectorTest_CalcGravityCenter_01, TestSize.Level1)
682 {
683     CALL_TEST_DEBUG;
684     auto listener = std::make_shared<MyGestureListener>();
685     TouchGestureType type = TOUCH_GESTURE_TYPE_SWIPE;
686     TouchGestureDetector detector(type, listener);
687     std::map<int32_t, Point> points;
688     points[1] = Point(1.0f, 2.0f);
689     points[2] = Point(3.0f, 4.0f);
690     points[3] = Point(5.0f, 6.0f);
691     points[4] = Point(7.0f, 8.0f);
692     points[5] = Point(9.0f, 10.0f);
693     points[6] = Point(11.0f, 12.0f);
694     int32_t count = static_cast<int32_t>(points.size());
695     EXPECT_TRUE(count > 5);
696     ASSERT_NO_FATAL_FAILURE(detector.CalcGravityCenter(points));
697 }
698 
699 /**
700  * @tc.name: TouchGestureDetectorTest_CalcGravityCenter_02
701  * @tc.desc: Test CalcGravityCenter
702  * @tc.type: FUNC
703  * @tc.require:
704  */
705 HWTEST_F(TouchGestureDetectorTest, TouchGestureDetectorTest_CalcGravityCenter_02, TestSize.Level1)
706 {
707     CALL_TEST_DEBUG;
708     auto listener = std::make_shared<MyGestureListener>();
709     TouchGestureType type = TOUCH_GESTURE_TYPE_SWIPE;
710     TouchGestureDetector detector(type, listener);
711     std::map<int32_t, Point> points;
712     points[1] = Point(1.0f, 2.0f);
713     points[2] = Point(3.0f, 4.0f);
714     points[3] = Point(5.0f, 6.0f);
715     ASSERT_NO_FATAL_FAILURE(detector.CalcGravityCenter(points));
716 }
717 
718 /**
719  * @tc.name: TouchGestureDetectorTest_IsFingerMove
720  * @tc.desc: Test IsFingerMove
721  * @tc.type: FUNC
722  * @tc.require:
723  */
724 HWTEST_F(TouchGestureDetectorTest, TouchGestureDetectorTest_IsFingerMove, TestSize.Level1)
725 {
726     CALL_TEST_DEBUG;
727     TouchGestureDetector detector(TOUCH_GESTURE_TYPE_SWIPE, nullptr);
728     ASSERT_NO_FATAL_FAILURE(detector.IsFingerMove(Point(1.0f, 2.0f), Point(3.0f, 4.0f)));
729 }
730 
731 /**
732  * @tc.name: TouchGestureDetectorTest_CalcTwoPointsDistance
733  * @tc.desc: Test CalcTwoPointsDistance
734  * @tc.type: FUNC
735  * @tc.require:
736  */
737 HWTEST_F(TouchGestureDetectorTest, TouchGestureDetectorTest_CalcTwoPointsDistance, TestSize.Level1)
738 {
739     CALL_TEST_DEBUG;
740     TouchGestureDetector detector(TOUCH_GESTURE_TYPE_SWIPE, nullptr);
741     ASSERT_NO_FATAL_FAILURE(detector.CalcTwoPointsDistance(Point(1.0f, 2.0f), Point(3.0f, 4.0f)));
742 }
743 
744 /**
745  * @tc.name: TouchGestureDetectorTest_CalcClusterCenter_01
746  * @tc.desc: Test CalcClusterCenter
747  * @tc.type: FUNC
748  * @tc.require:
749  */
750 HWTEST_F(TouchGestureDetectorTest, TouchGestureDetectorTest_CalcClusterCenter_01, TestSize.Level1)
751 {
752     CALL_TEST_DEBUG;
753     TouchGestureDetector detector(TOUCH_GESTURE_TYPE_SWIPE, nullptr);
754     std::map<int32_t, Point> points;
755     ASSERT_NO_FATAL_FAILURE(detector.CalcClusterCenter(points));
756 }
757 
758 /**
759  * @tc.name: TouchGestureDetectorTest_CalcClusterCenter_02
760  * @tc.desc: Test CalcClusterCenter
761  * @tc.type: FUNC
762  * @tc.require:
763  */
764 HWTEST_F(TouchGestureDetectorTest, TouchGestureDetectorTest_CalcClusterCenter_02, TestSize.Level1)
765 {
766     CALL_TEST_DEBUG;
767     TouchGestureDetector detector(TOUCH_GESTURE_TYPE_SWIPE, nullptr);
768     std::map<int32_t, Point> points;
769     points[1] = Point(1.0f, 2.0f);
770     points[2] = Point(3.0f, 4.0f);
771     points[3] = Point(5.0f, 6.0f);
772     ASSERT_NO_FATAL_FAILURE(detector.CalcClusterCenter(points));
773 }
774 
775 /**
776  * @tc.name: TouchGestureDetectorTest_CalcAndStoreDistance_01
777  * @tc.desc: Test CalcAndStoreDistance
778  * @tc.type: FUNC
779  * @tc.require:
780  */
781 HWTEST_F(TouchGestureDetectorTest, TouchGestureDetectorTest_CalcAndStoreDistance_01, TestSize.Level1)
782 {
783     CALL_TEST_DEBUG;
784     auto listener = std::make_shared<MyGestureListener>();
785     TouchGestureType type = TOUCH_GESTURE_TYPE_SWIPE;
786     TouchGestureDetector detector(type, listener);
787     std::map<int32_t, Point> points;
788     points[1] = Point(1.0f, 2.0f);
789     points[2] = Point(3.0f, 4.0f);
790 
791     detector.downPoint_[1] = Point(1.0f, 2.0f);
792     detector.downPoint_[2] = Point(3.0f, 4.0f);
793     ASSERT_NO_FATAL_FAILURE(detector.CalcAndStoreDistance());
794 }
795 
796 /**
797  * @tc.name: TouchGestureDetectorTest_CalcAndStoreDistance_02
798  * @tc.desc: Test CalcAndStoreDistance
799  * @tc.type: FUNC
800  * @tc.require:
801  */
802 HWTEST_F(TouchGestureDetectorTest, TouchGestureDetectorTest_CalcAndStoreDistance_02, TestSize.Level1)
803 {
804     CALL_TEST_DEBUG;
805     auto listener = std::make_shared<MyGestureListener>();
806     TouchGestureType type = TOUCH_GESTURE_TYPE_SWIPE;
807     TouchGestureDetector detector(type, listener);
808     std::map<int32_t, Point> points;
809     points[1] = Point(1.0f, 2.0f);
810     points[2] = Point(3.0f, 4.0f);
811 
812     detector.downPoint_[1] = Point(1.0f, 2.0f, 50000);
813     detector.downPoint_[2] = Point(3.0f, 4.0f, 150000);
814     detector.downPoint_[3] = Point(5.0f, 6.0f, 250000);
815     detector.downPoint_[4] = Point(7.0f, 8.0f, 350000);
816     ASSERT_NO_FATAL_FAILURE(detector.CalcAndStoreDistance());
817 }
818 
819 /**
820  * @tc.name: TouchGestureDetectorTest_CalcAndStoreDistance_03
821  * @tc.desc: Test CalcAndStoreDistance
822  * @tc.type: FUNC
823  * @tc.require:
824  */
825 HWTEST_F(TouchGestureDetectorTest, TouchGestureDetectorTest_CalcAndStoreDistance_03, TestSize.Level1)
826 {
827     CALL_TEST_DEBUG;
828     auto listener = std::make_shared<MyGestureListener>();
829     TouchGestureType type = TOUCH_GESTURE_TYPE_SWIPE;
830     TouchGestureDetector detector(type, listener);
831     std::map<int32_t, Point> points;
832     points[1] = Point(1.0f, 2.0f);
833     points[2] = Point(3.0f, 4.0f);
834 
835     detector.downPoint_[1] = Point(1.0f, 2.0f, 5000);
836     detector.downPoint_[2] = Point(3.0f, 4.0f, 6000);
837     detector.downPoint_[3] = Point(5.0f, 6.0f, 7000);
838     detector.downPoint_[4] = Point(7.0f, 8.0f, 8000);
839 
840     detector.lastDistance_[1] = 10.5;
841     detector.lastDistance_[2] = 20.5;
842     detector.lastDistance_[3] = 30.5;
843     ASSERT_NO_FATAL_FAILURE(detector.CalcAndStoreDistance());
844 }
845 
846 /**
847  * @tc.name: TouchGestureDetectorTest_CalcMultiFingerMovement_01
848  * @tc.desc: Test CalcMultiFingerMovement
849  * @tc.type: FUNC
850  * @tc.require:
851  */
852 HWTEST_F(TouchGestureDetectorTest, TouchGestureDetectorTest_CalcMultiFingerMovement_01, TestSize.Level1)
853 {
854     CALL_TEST_DEBUG;
855     auto listener = std::make_shared<MyGestureListener>();
856     TouchGestureType type = TOUCH_GESTURE_TYPE_SWIPE;
857     TouchGestureDetector detector(type, listener);
858     std::map<int32_t, Point> points;
859     points[1] = Point(1.0f, 2.0f);
860     points[2] = Point(3.0f, 4.0f);
861     points[3] = Point(5.0f, 6.0f);
862 
863     detector.downPoint_[1] = Point(1.0f, 2.0f, 50000);
864     detector.downPoint_[2] = Point(3.0f, 4.0f, 150000);
865     detector.downPoint_[3] = Point(5.0f, 6.0f, 250000);
866     ASSERT_NO_FATAL_FAILURE(detector.CalcMultiFingerMovement(points));
867 }
868 
869 /**
870  * @tc.name: TouchGestureDetectorTest_CalcMultiFingerMovement_02
871  * @tc.desc: Test CalcMultiFingerMovement
872  * @tc.type: FUNC
873  * @tc.require:
874  */
875 HWTEST_F(TouchGestureDetectorTest, TouchGestureDetectorTest_CalcMultiFingerMovement_02, TestSize.Level1)
876 {
877     CALL_TEST_DEBUG;
878     auto listener = std::make_shared<MyGestureListener>();
879     TouchGestureType type = TOUCH_GESTURE_TYPE_SWIPE;
880     TouchGestureDetector detector(type, listener);
881     std::map<int32_t, Point> points;
882     points[1] = Point(1.0f, 2.0f);
883     points[2] = Point(3.0f, 4.0f);
884     points[3] = Point(5.0f, 6.0f);
885 
886     detector.downPoint_[4] = Point(1.0f, 2.0f, 5000);
887     detector.downPoint_[5] = Point(3.0f, 4.0f, 6000);
888     detector.downPoint_[6] = Point(5.0f, 6.0f, 7000);
889     ASSERT_NO_FATAL_FAILURE(detector.CalcMultiFingerMovement(points));
890 }
891 
892 /**
893  * @tc.name: TouchGestureDetectorTest_JudgeOperationMode_01
894  * @tc.desc: Test JudgeOperationMode
895  * @tc.type: FUNC
896  * @tc.require:
897  */
898 HWTEST_F(TouchGestureDetectorTest, TouchGestureDetectorTest_JudgeOperationMode_01, TestSize.Level1)
899 {
900     CALL_TEST_DEBUG;
901     auto listener = std::make_shared<MyGestureListener>();
902     TouchGestureType type = TOUCH_GESTURE_TYPE_SWIPE;
903     TouchGestureDetector detector(type, listener);
904     std::map<int32_t, Point> movePoints;
905     movePoints[1] = Point(1.0f, 2.0f);
906     movePoints[2] = Point(3.0f, 4.0f);
907     movePoints[3] = Point(5.0f, 6.0f);
908 
909     detector.downPoint_[4] = Point(1.0f, 2.0f, 5000);
910     detector.downPoint_[5] = Point(3.0f, 4.0f, 6000);
911     detector.downPoint_[6] = Point(5.0f, 6.0f, 7000);
912 
913     ASSERT_NO_FATAL_FAILURE(detector.JudgeOperationMode(movePoints));
914 }
915 
916 /**
917  * @tc.name: TouchGestureDetectorTest_JudgeOperationMode_02
918  * @tc.desc: Test JudgeOperationMode
919  * @tc.type: FUNC
920  * @tc.require:
921  */
922 HWTEST_F(TouchGestureDetectorTest, TouchGestureDetectorTest_JudgeOperationMode_02, TestSize.Level1)
923 {
924     CALL_TEST_DEBUG;
925     auto listener = std::make_shared<MyGestureListener>();
926     TouchGestureType type = TOUCH_GESTURE_TYPE_SWIPE;
927     TouchGestureDetector detector(type, listener);
928     std::map<int32_t, Point> movePoints;
929     movePoints[1] = Point(1.0f, 2.0f);
930     movePoints[2] = Point(3.0f, 4.0f);
931     movePoints[3] = Point(5.0f, 6.0f);
932 
933     detector.downPoint_[4] = Point(1.0f, 2.0f, 5000);
934     detector.downPoint_[5] = Point(3.0f, 4.0f, 6000);
935     detector.downPoint_[6] = Point(5.0f, 6.0f, 7000);
936     detector.downPoint_[7] = Point(7.0f, 8.0f, 8000);
937 
938     ASSERT_NO_FATAL_FAILURE(detector.JudgeOperationMode(movePoints));
939 }
940 
941 /**
942  * @tc.name: TouchGestureDetectorTest_JudgeOperationMode_03
943  * @tc.desc: Test JudgeOperationMode
944  * @tc.type: FUNC
945  * @tc.require:
946  */
947 HWTEST_F(TouchGestureDetectorTest, TouchGestureDetectorTest_JudgeOperationMode_03, TestSize.Level1)
948 {
949     CALL_TEST_DEBUG;
950     auto listener = std::make_shared<MyGestureListener>();
951     TouchGestureType type = TOUCH_GESTURE_TYPE_SWIPE;
952     TouchGestureDetector detector(type, listener);
953     std::map<int32_t, Point> movePoints;
954     movePoints[1] = Point(1.0f, 2.0f);
955     movePoints[2] = Point(3.0f, 4.0f);
956     movePoints[3] = Point(5.0f, 6.0f);
957 
958     detector.downPoint_[1] = Point(1.0f, 2.0f, 5000);
959     detector.downPoint_[2] = Point(3.0f, 4.0f, 6000);
960     detector.downPoint_[3] = Point(5.0f, 6.0f, 7000);
961     detector.downPoint_[4] = Point(7.0f, 8.0f, 8000);
962 
963     detector.lastDistance_[4] = 1.0;
964     detector.lastDistance_[5] = 2.0;
965     detector.lastDistance_[6] = 3.0;
966     ASSERT_NO_FATAL_FAILURE(detector.JudgeOperationMode(movePoints));
967 }
968 
969 /**
970  * @tc.name: TouchGestureDetectorTest_JudgeOperationMode_04
971  * @tc.desc: Test JudgeOperationMode
972  * @tc.type: FUNC
973  * @tc.require:
974  */
975 HWTEST_F(TouchGestureDetectorTest, TouchGestureDetectorTest_JudgeOperationMode_04, TestSize.Level1)
976 {
977     CALL_TEST_DEBUG;
978     auto listener = std::make_shared<MyGestureListener>();
979     TouchGestureType type = TOUCH_GESTURE_TYPE_SWIPE;
980     TouchGestureDetector detector(type, listener);
981     std::map<int32_t, Point> movePoints;
982     movePoints[1] = Point(1.0f, 2.0f);
983     movePoints[2] = Point(3.0f, 4.0f);
984     movePoints[3] = Point(5.0f, 6.0f);
985     movePoints[4] = Point(7.0f, 8.0f);
986 
987     detector.downPoint_[1] = Point(1.0f, 2.0f, 5000);
988     detector.downPoint_[2] = Point(3.0f, 4.0f, 6000);
989     detector.downPoint_[3] = Point(5.0f, 6.0f, 7000);
990     detector.downPoint_[4] = Point(7.0f, 8.0f, 8000);
991 
992     detector.lastDistance_[1] = 1.0;
993     detector.lastDistance_[2] = 2.0;
994     detector.lastDistance_[3] = 3.0;
995     detector.lastDistance_[4] = 4.0;
996     ASSERT_NO_FATAL_FAILURE(detector.JudgeOperationMode(movePoints));
997 }
998 
999 /**
1000  * @tc.name: TouchGestureDetectorTest_AntiJitter_01
1001  * @tc.desc: Test AntiJitter
1002  * @tc.type: FUNC
1003  * @tc.require:
1004  */
1005 HWTEST_F(TouchGestureDetectorTest, TouchGestureDetectorTest_AntiJitter_01, TestSize.Level1)
1006 {
1007     CALL_TEST_DEBUG;
1008     auto listener = std::make_shared<MyGestureListener>();
1009     TouchGestureType type = TOUCH_GESTURE_TYPE_SWIPE;
1010     TouchGestureDetector detector(type, listener);
1011     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
1012     ASSERT_NE(pointerEvent, nullptr);
1013 
1014     GestureMode mode;
1015     mode = GestureMode::ACTION_PINCH_CLOSED;
1016     detector.continuousCloseCount_ = 3;
1017     EXPECT_FALSE(detector.AntiJitter(pointerEvent, mode));
1018     detector.continuousCloseCount_ = 1;
1019     EXPECT_FALSE(detector.AntiJitter(pointerEvent, mode));
1020 
1021     mode = GestureMode::ACTION_PINCH_OPENED;
1022     detector.continuousOpenCount_ = 3;
1023     EXPECT_FALSE(detector.AntiJitter(pointerEvent, mode));
1024     detector.continuousOpenCount_ = 1;
1025     EXPECT_FALSE(detector.AntiJitter(pointerEvent, mode));
1026 
1027     mode = GestureMode::ACTION_UNKNOWN;
1028     EXPECT_FALSE(detector.AntiJitter(pointerEvent, mode));
1029 }
1030 
1031 /**
1032  * @tc.name: TouchGestureDetectorTest_AddGestureFingers_01
1033  * @tc.desc: Test AddGestureFingers
1034  * @tc.type: FUNC
1035  * @tc.require:
1036  */
1037 HWTEST_F(TouchGestureDetectorTest, TouchGestureDetectorTest_AddGestureFingers_01, TestSize.Level1)
1038 {
1039     CALL_TEST_DEBUG;
1040     auto listener = std::make_shared<MyGestureListener>();
1041     TouchGestureType type = TOUCH_GESTURE_TYPE_SWIPE;
1042     TouchGestureDetector detector(type, listener);
1043     detector.fingers_.insert(1);
1044     detector.fingers_.insert(2);
1045     detector.fingers_.insert(3);
1046     int32_t fingers = 1;
1047     ASSERT_NO_FATAL_FAILURE(detector.AddGestureFingers(fingers));
1048     fingers = 4;
1049     ASSERT_NO_FATAL_FAILURE(detector.AddGestureFingers(fingers));
1050 
1051     detector.fingers_.clear();
1052     ASSERT_NO_FATAL_FAILURE(detector.AddGestureFingers(fingers));
1053 }
1054 
1055 /**
1056  * @tc.name: TouchGestureDetectorTest_RemoveGestureFingers_01
1057  * @tc.desc: Test RemoveGestureFingers
1058  * @tc.type: FUNC
1059  * @tc.require:
1060  */
1061 HWTEST_F(TouchGestureDetectorTest, TouchGestureDetectorTest_RemoveGestureFingers_01, TestSize.Level1)
1062 {
1063     CALL_TEST_DEBUG;
1064     auto listener = std::make_shared<MyGestureListener>();
1065     TouchGestureType type = TOUCH_GESTURE_TYPE_SWIPE;
1066     TouchGestureDetector detector(type, listener);
1067     detector.fingers_.insert(1);
1068     detector.fingers_.insert(2);
1069     detector.fingers_.insert(3);
1070     int32_t fingers = 1;
1071     ASSERT_NO_FATAL_FAILURE(detector.RemoveGestureFingers(fingers));
1072     fingers = 4;
1073     ASSERT_NO_FATAL_FAILURE(detector.RemoveGestureFingers(fingers));
1074 
1075     detector.fingers_.clear();
1076     ASSERT_NO_FATAL_FAILURE(detector.RemoveGestureFingers(fingers));
1077 }
1078 
1079 /**
1080  * @tc.name: TouchGestureDetectorTest_IsMatchGesture_01
1081  * @tc.desc: Test IsMatchGesture
1082  * @tc.type: FUNC
1083  * @tc.require:
1084  */
1085 HWTEST_F(TouchGestureDetectorTest, TouchGestureDetectorTest_IsMatchGesture_01, TestSize.Level1)
1086 {
1087     CALL_TEST_DEBUG;
1088     auto listener = std::make_shared<MyGestureListener>();
1089     TouchGestureType type = TOUCH_GESTURE_TYPE_SWIPE;
1090     TouchGestureDetector detector(type, listener);
1091     detector.fingers_.insert(1);
1092     detector.fingers_.insert(2);
1093     detector.fingers_.insert(3);
1094 
1095     int32_t count = 1;
1096     GestureMode mode;
1097     mode = GestureMode::ACTION_SWIPE_DOWN;
1098     EXPECT_TRUE(detector.IsMatchGesture(mode, count));
1099     mode = GestureMode::ACTION_SWIPE_UP;
1100     EXPECT_TRUE(detector.IsMatchGesture(mode, count));
1101     mode = GestureMode::ACTION_SWIPE_LEFT;
1102     EXPECT_TRUE(detector.IsMatchGesture(mode, count));
1103     mode = GestureMode::ACTION_SWIPE_RIGHT;
1104     EXPECT_TRUE(detector.IsMatchGesture(mode, count));
1105     mode = GestureMode::ACTION_PINCH_OPENED;
1106     EXPECT_FALSE(detector.IsMatchGesture(mode, count));
1107     mode = GestureMode::ACTION_PINCH_CLOSED;
1108     EXPECT_FALSE(detector.IsMatchGesture(mode, count));
1109     mode = GestureMode::ACTION_UNKNOWN;
1110     EXPECT_FALSE(detector.IsMatchGesture(mode, count));
1111 }
1112 
1113 /**
1114  * @tc.name: TouchGestureDetectorTest_IsMatchGesture_02
1115  * @tc.desc: Test IsMatchGesture
1116  * @tc.type: FUNC
1117  * @tc.require:
1118  */
1119 HWTEST_F(TouchGestureDetectorTest, TouchGestureDetectorTest_IsMatchGesture_02, TestSize.Level1)
1120 {
1121     CALL_TEST_DEBUG;
1122     auto listener = std::make_shared<MyGestureListener>();
1123     TouchGestureType type = TOUCH_GESTURE_TYPE_SWIPE;
1124     TouchGestureDetector detector(type, listener);
1125     detector.fingers_.insert(1);
1126     detector.fingers_.insert(2);
1127     detector.fingers_.insert(3);
1128 
1129     int32_t count = 4;
1130     GestureMode mode;
1131     mode = GestureMode::ACTION_UNKNOWN;
1132     EXPECT_FALSE(detector.IsMatchGesture(mode, count));
1133 }
1134 
1135 /**
1136  * @tc.name: TouchGestureDetectorTest_NotifyGestureEvent_01
1137  * @tc.desc: Test NotifyGestureEvent
1138  * @tc.type: FUNC
1139  * @tc.require:
1140  */
1141 HWTEST_F(TouchGestureDetectorTest, TouchGestureDetectorTest_NotifyGestureEvent_01, TestSize.Level1)
1142 {
1143     CALL_TEST_DEBUG;
1144     auto listener = std::make_shared<MyGestureListener>();
1145     TouchGestureType type = TOUCH_GESTURE_TYPE_SWIPE;
1146     TouchGestureDetector detector(type, listener);
1147     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
1148     ASSERT_NE(pointerEvent, nullptr);
1149 
1150     GestureMode mode;
1151     mode = GestureMode::ACTION_UNKNOWN;
1152     EXPECT_FALSE(detector.NotifyGestureEvent(pointerEvent, mode));
1153 
1154     mode = GestureMode::ACTION_GESTURE_END;
1155     for (auto i = 0; i < 5; i++) {
1156         PointerEvent::PointerItem pointerItem;
1157         detector.fingers_.insert(i + 1);
1158         pointerEvent->pointers_.push_back(pointerItem);
1159     }
1160     EXPECT_FALSE(detector.NotifyGestureEvent(pointerEvent, mode));
1161 }
1162 
1163 /**
1164  * @tc.name: TouchGestureDetectorTest_OnTouchEvent_003
1165  * @tc.desc: Test OnTouchEvent
1166  * @tc.type: FUNC
1167  * @tc.require:
1168  */
1169 HWTEST_F(TouchGestureDetectorTest, TouchGestureDetectorTest_OnTouchEvent_003, TestSize.Level1)
1170 {
1171     CALL_TEST_DEBUG;
1172     auto listener = std::make_shared<MyGestureListener>();
1173     TouchGestureType type = TOUCH_GESTURE_TYPE_SWIPE;
1174     TouchGestureDetector detector(type, listener);
1175     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
1176     ASSERT_NE(pointerEvent, nullptr);
1177     std::shared_ptr<InputEvent> inputEvent = InputEvent::Create();
1178     ASSERT_NE(inputEvent, nullptr);
1179     inputEvent->sourceType_ = PointerEvent::SOURCE_TYPE_TOUCHSCREEN;
1180     detector.gestureEnable_ = true;
1181     inputEvent->bitwise_ = 0x00000000;
1182     pointerEvent->SetPointerId(5);
1183     detector.gestureDisplayId_ = INT32_MAX;
1184     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
1185     EXPECT_FALSE(detector.OnTouchEvent(pointerEvent));
1186     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_MOVE);
1187     EXPECT_FALSE(detector.OnTouchEvent(pointerEvent));
1188     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UP);
1189     EXPECT_FALSE(detector.OnTouchEvent(pointerEvent));
1190     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_AXIS_UPDATE);
1191     EXPECT_FALSE(detector.OnTouchEvent(pointerEvent));
1192 }
1193 
1194 /**
1195  * @tc.name: TouchGestureDetectorTest_HandleDownEvent_003
1196  * @tc.desc: Test HandleDownEvent
1197  * @tc.type: FUNC
1198  * @tc.require:
1199  */
1200 HWTEST_F(TouchGestureDetectorTest, TouchGestureDetectorTest_HandleDownEvent_003, TestSize.Level1)
1201 {
1202     CALL_TEST_DEBUG;
1203     auto listener = std::make_shared<MyGestureListener>();
1204     TouchGestureType type = TOUCH_GESTURE_TYPE_SWIPE;
1205     TouchGestureDetector detector(type, listener);
1206     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
1207     ASSERT_NE(pointerEvent, nullptr);
1208     detector.isRecognized_ = false;
1209     PointerEvent::PointerItem item1;
1210     item1.SetPointerId(1);
1211     PointerEvent::PointerItem item2;
1212     item2.SetPointerId(2);
1213     pointerEvent->pointers_.push_back(item1);
1214     pointerEvent->pointers_.push_back(item2);
1215     pointerEvent->SetPointerId(2);
1216     ASSERT_NO_FATAL_FAILURE(detector.HandleDownEvent(pointerEvent));
1217     detector.gestureType_ = TOUCH_GESTURE_TYPE_SWIPE;
1218     ASSERT_NO_FATAL_FAILURE(detector.HandleDownEvent(pointerEvent));
1219     detector.gestureType_ = TOUCH_GESTURE_TYPE_PINCH;
1220     ASSERT_NO_FATAL_FAILURE(detector.HandleDownEvent(pointerEvent));
1221     detector.gestureType_ = TOUCH_GESTURE_TYPE_NONE;
1222     ASSERT_NO_FATAL_FAILURE(detector.HandleDownEvent(pointerEvent));
1223 }
1224 
1225 /**
1226  * @tc.name: TouchGestureDetectorTest_HandleMoveEvent_004
1227  * @tc.desc: Test HandleMoveEvent
1228  * @tc.type: FUNC
1229  * @tc.require:
1230  */
1231 HWTEST_F(TouchGestureDetectorTest, TouchGestureDetectorTest_HandleMoveEvent_004, TestSize.Level1)
1232 {
1233     CALL_TEST_DEBUG;
1234     auto listener = std::make_shared<MyGestureListener>();
1235     TouchGestureType type = TOUCH_GESTURE_TYPE_SWIPE;
1236     TouchGestureDetector detector(type, listener);
1237     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
1238     ASSERT_NE(pointerEvent, nullptr);
1239     detector.isRecognized_ = true;
1240     ASSERT_NO_FATAL_FAILURE(detector.HandleMoveEvent(pointerEvent));
1241     detector.isRecognized_ = false;
1242     ASSERT_NO_FATAL_FAILURE(detector.HandleMoveEvent(pointerEvent));
1243 }
1244 
1245 /**
1246  * @tc.name: TouchGestureDetectorTest_HandlePinchMoveEvent_003
1247  * @tc.desc: Test HandlePinchMoveEvent
1248  * @tc.type: FUNC
1249  * @tc.require:
1250  */
1251 HWTEST_F(TouchGestureDetectorTest, TouchGestureDetectorTest_HandlePinchMoveEvent_003, TestSize.Level1)
1252 {
1253     CALL_TEST_DEBUG;
1254     auto listener = std::make_shared<MyGestureListener>();
1255     TouchGestureType type = TOUCH_GESTURE_TYPE_SWIPE;
1256     TouchGestureDetector detector(type, listener);
1257     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
1258     ASSERT_NE(pointerEvent, nullptr);
1259     detector.downPoint_[1] = Point(1.0f, 2.0f);
1260     detector.downPoint_[2] = Point(3.0f, 4.0f);
1261     detector.downPoint_[3] = Point(5.0f, 6.0f);
1262     detector.downPoint_[4] = Point(7.0f, 8.0f);
1263     detector.lastDistance_[1] = 1.0;
1264     detector.lastDistance_[2] = 2.0;
1265     detector.lastDistance_[3] = 3.0;
1266     PointerEvent::PointerItem item1;
1267     item1.SetPointerId(1);
1268     PointerEvent::PointerItem item2;
1269     item2.SetPointerId(2);
1270     pointerEvent->pointers_.push_back(item1);
1271     pointerEvent->pointers_.push_back(item2);
1272     pointerEvent->SetPointerId(2);
1273     ASSERT_NO_FATAL_FAILURE(detector.HandlePinchMoveEvent(pointerEvent));
1274 }
1275 
1276 /**
1277  * @tc.name: TouchGestureDetectorTest_IsPhysicalPointer_001
1278  * @tc.desc: Test IsPhysicalPointer
1279  * @tc.type: FUNC
1280  * @tc.require:
1281  */
1282 HWTEST_F(TouchGestureDetectorTest, TouchGestureDetectorTest_IsPhysicalPointer_001, TestSize.Level1)
1283 {
1284     CALL_TEST_DEBUG;
1285     auto listener = std::make_shared<MyGestureListener>();
1286     TouchGestureType type = TOUCH_GESTURE_TYPE_SWIPE;
1287     TouchGestureDetector detector(type, listener);
1288     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
1289     ASSERT_NE(pointerEvent, nullptr);
1290     std::shared_ptr<InputEvent> inputEvent = InputEvent::Create();
1291     ASSERT_NE(inputEvent, nullptr);
1292     inputEvent->bitwise_ = 0x00000000;
1293     pointerEvent->SetPointerId(5);
1294     bool ret = detector.IsPhysicalPointer(pointerEvent);
1295     EXPECT_TRUE(ret);
1296 }
1297 
1298 /**
1299  * @tc.name: TouchGestureDetectorTest_HandleUpEvent_003
1300  * @tc.desc: Test HandleUpEvent
1301  * @tc.type: FUNC
1302  * @tc.require:
1303  */
1304 HWTEST_F(TouchGestureDetectorTest, TouchGestureDetectorTest_HandleUpEvent_003, TestSize.Level1)
1305 {
1306     CALL_TEST_DEBUG;
1307     auto listener = std::make_shared<MyGestureListener>();
1308     TouchGestureType type = TOUCH_GESTURE_TYPE_SWIPE;
1309     TouchGestureDetector detector(type, listener);
1310     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
1311     ASSERT_NE(pointerEvent, nullptr);
1312     pointerEvent->pointerId_ = 1;
1313     detector.downPoint_[1] = Point(1.0f, 2.0f);
1314     detector.downPoint_[2] = Point(3.0f, 4.0f);
1315     detector.isRecognized_ = true;
1316     detector.lastTouchEvent_ = pointerEvent;
1317     ASSERT_NO_FATAL_FAILURE(detector.HandleUpEvent(pointerEvent));
1318 }
1319 } // namespace MMI
1320 } // namespace OHOS