• 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 #include "test/mock/base/mock_task_executor.h"
16 #include "test/unittest/core/gestures/gestures_common_test_ng.h"
17 #include "ui/base/referenced.h"
18 
19 using namespace testing;
20 using namespace testing::ext;
21 
22 namespace OHOS::Ace::NG {
23 namespace {
24 constexpr float GESTURE_EVENT_PROPERTY_DEFAULT_VALUE = 0.0;
25 constexpr float GESTURE_EVENT_PROPERTY_VALUE = 10.0;
26 constexpr int64_t DEFAULT_MOVE_TIME = 1000000000;
27 const std::string TEST_EXTRA_INFO = "Reject: received cancel and succeed.";
28 constexpr double DEFAULT_LONGPRESS_DURATION = 500.0;
29 struct MockLongPressRecognizerCase {
30     int32_t fingers;
31     double duration;
32     int32_t time;
33     RefereeState refereeState;
34     int32_t expectedFingers;
35     double expectedDuration;
36     RefereeState expectedRefereeState;
37     std::vector<TouchEvent> inputTouchEvents;
38 };
39 } // namespace
40 
41 class LongPressRecognizerTestNg : public GesturesCommonTestNg {
42 public:
43     static void SetUpTestSuite();
44     static void TearDownTestSuite();
45 };
46 
SetUpTestSuite()47 void LongPressRecognizerTestNg::SetUpTestSuite()
48 {
49     MockPipelineContext::SetUp();
50 }
51 
TearDownTestSuite()52 void LongPressRecognizerTestNg::TearDownTestSuite()
53 {
54     MockPipelineContext::TearDown();
55 }
56 
57 /**
58  * @tc.name: LongPressRecognizerTest001
59  * @tc.desc: Test LongPressRecognizer function: OnAccepted OnRejected
60  * @tc.type: FUNC
61  */
62 HWTEST_F(LongPressRecognizerTestNg, LongPressRecognizerTest001, TestSize.Level1)
63 {
64     /**
65      * @tc.steps: step1. create LongPressRecognizer.
66      */
67     RefPtr<LongPressRecognizer> longPressRecognizer =
68         AceType::MakeRefPtr<LongPressRecognizer>(LONG_PRESS_DURATION, FINGER_NUMBER, false);
69     OnLongPress onLongPress;
70     TouchEvent touchEvent;
71 
72     /**
73      * @tc.steps: step2. call OnAccepted function and compare result.
74      * @tc.steps: case1: !onLongPress, !empty, repeat
75      * @tc.expected: step2. result equals.
76      */
77     longPressRecognizer->touchPoints_[touchEvent.id] = touchEvent;
78     longPressRecognizer->repeat_ = true;
79     longPressRecognizer->OnAccepted();
80     EXPECT_EQ(longPressRecognizer->refereeState_, RefereeState::SUCCEED);
81 
82     /**
83      * @tc.steps: step2. call OnAccepted function and compare result.
84      * @tc.steps: case2: !onLongPress, empty, !repeat
85      * @tc.expected: step2. result equals.
86      */
87     longPressRecognizer->touchPoints_.clear();
88     longPressRecognizer->repeat_ = false;
89     longPressRecognizer->OnAccepted();
90     EXPECT_EQ(longPressRecognizer->refereeState_, RefereeState::SUCCEED);
91 
92     /**
93      * @tc.steps: step2. call OnAccepted function and compare result.
94      * @tc.steps: case3: onLongPress, empty, !repeat
95      * @tc.expected: step2. result equals.
96      */
97     longPressRecognizer->touchPoints_.clear();
98     longPressRecognizer->repeat_ = false;
99     longPressRecognizer->OnAccepted();
100     EXPECT_EQ(longPressRecognizer->refereeState_, RefereeState::SUCCEED);
101 
102     /**
103      * @tc.steps: step2. call OnAccepted function and compare result.
104      * @tc.steps: case4: onLongPress, !empty, !repeat
105      * @tc.expected: step2. result equals.
106      */
107     longPressRecognizer->touchPoints_.clear();
108     longPressRecognizer->touchPoints_[touchEvent.id] = touchEvent;
109     longPressRecognizer->repeat_ = false;
110     longPressRecognizer->OnAccepted();
111     EXPECT_EQ(longPressRecognizer->refereeState_, RefereeState::SUCCEED);
112 
113     /**
114      * @tc.steps: step3. call OnRejected function and compare result.
115      * @tc.expected: step3. result equals.
116      */
117     longPressRecognizer->OnRejected();
118     EXPECT_EQ(longPressRecognizer->refereeState_, RefereeState::SUCCEED);
119 }
120 
121 /**
122  * @tc.name: LongPressRecognizerTest002
123  * @tc.desc: Test LongPressRecognizer function: HandleTouchMoveEvent
124  * @tc.type: FUNC
125  */
126 HWTEST_F(LongPressRecognizerTestNg, LongPressRecognizerTest002, TestSize.Level1)
127 {
128     /**
129      * @tc.steps: step1. create LongPressRecognizer.
130      */
131     RefPtr<LongPressRecognizer> longPressRecognizer =
132         AceType::MakeRefPtr<LongPressRecognizer>(LONG_PRESS_DURATION, FINGER_NUMBER, false);
133 
134     /**
135      * @tc.steps: step2. call HandleTouchUpEvent function and compare result.
136      * @tc.steps: case1: referee is not SUCCEED
137      * @tc.expected: step2. result equals.
138      */
139     TouchEvent touchEvent;
140     longPressRecognizer->touchPoints_[touchEvent.id] = touchEvent;
141     longPressRecognizer->HandleTouchMoveEvent(touchEvent);
142     EXPECT_EQ(longPressRecognizer->time_, touchEvent.time);
143 
144     /**
145      * @tc.steps: step2. call HandleTouchUpEvent function and compare result.
146      * @tc.steps: case2: referee is SUCCEED
147      * @tc.expected: step2. result equals.
148      */
149     longPressRecognizer->refereeState_ = RefereeState::SUCCEED;
150     longPressRecognizer->HandleTouchMoveEvent(touchEvent);
151     EXPECT_EQ(longPressRecognizer->time_, touchEvent.time);
152 
153     /**
154      * @tc.steps: step2. call HandleTouchUpEvent function and compare result.
155      * @tc.steps: case2: referee is SUCCEED
156      * @tc.expected: step2. result equals.
157      */
158     longPressRecognizer->currentFingers_ = longPressRecognizer->fingers_;
159     longPressRecognizer->refereeState_ = RefereeState::SUCCEED;
160     longPressRecognizer->HandleTouchMoveEvent(touchEvent);
161     EXPECT_EQ(longPressRecognizer->time_, touchEvent.time);
162 }
163 
164 /**
165  * @tc.name: LongPressRecognizerTest003
166  * @tc.desc: Test LongPressRecognizer function: HandleTouchDownEvent
167  * @tc.type: FUNC
168  */
169 HWTEST_F(LongPressRecognizerTestNg, LongPressRecognizerTest003, TestSize.Level1)
170 {
171     /**
172      * @tc.steps: step1. create LongPressRecognizer.
173      */
174     RefPtr<LongPressRecognizer> longPressRecognizer =
175         AceType::MakeRefPtr<LongPressRecognizer>(LONG_PRESS_DURATION, FINGER_NUMBER, false);
176 
177     /**
178      * @tc.steps: step2. call HandleTouchUpEvent function and compare result.
179      * @tc.steps: case1: pointsCount == fingers, useCatchMode_ is true
180      * @tc.expected: step2. result equals.
181      */
182     TouchEvent touchEvent;
183     longPressRecognizer->HandleTouchDownEvent(touchEvent);
184     EXPECT_EQ(longPressRecognizer->touchPoints_.size(), 1);
185 
186     /**
187      * @tc.steps: step2. call HandleTouchUpEvent function and compare result.
188      * @tc.steps: case2: pointsCount == fingers, useCatchMode_ is true
189      * @tc.expected: step2. result equals.
190      */
191     touchEvent.sourceType = SourceType::MOUSE;
192     longPressRecognizer->isForDrag_ = true;
193     longPressRecognizer->touchPoints_[touchEvent.id] = touchEvent;
194     longPressRecognizer->fingers_ = 1;
195     longPressRecognizer->useCatchMode_ = true;
196     longPressRecognizer->HandleTouchDownEvent(touchEvent);
197     EXPECT_EQ(longPressRecognizer->globalPoint_.GetX(), touchEvent.x);
198     EXPECT_EQ(longPressRecognizer->globalPoint_.GetY(), touchEvent.y);
199     EXPECT_EQ(longPressRecognizer->refereeState_, RefereeState::READY);
200 
201     /**
202      * @tc.steps: step2. call HandleTouchUpEvent function and compare result.
203      * @tc.steps: case3: pointsCount == fingers, useCatchMode_ is false
204      * @tc.expected: step2. result equals.
205      */
206     longPressRecognizer->useCatchMode_ = false;
207     longPressRecognizer->HandleTouchDownEvent(touchEvent);
208     EXPECT_EQ(longPressRecognizer->refereeState_, RefereeState::READY);
209 
210     /**
211      * @tc.steps: step2. call HandleTouchUpEvent function and compare result.
212      * @tc.steps: case4: referee is SUCCEED
213      * @tc.expected: step2. result equals.
214      */
215     longPressRecognizer->refereeState_ = RefereeState::SUCCEED;
216     longPressRecognizer->HandleTouchDownEvent(touchEvent);
217     EXPECT_EQ(longPressRecognizer->touchPoints_.size(), 1);
218 
219     /**
220      * @tc.steps: step2. call HandleTouchUpEvent function and compare result.
221      * @tc.steps: case5: change SourceType to KEYBOARD
222      * @tc.expected: step2. result equals.
223      */
224     longPressRecognizer->refereeState_ = RefereeState::PENDING;
225     touchEvent.sourceType = SourceType::KEYBOARD;
226     longPressRecognizer->HandleTouchDownEvent(touchEvent);
227     EXPECT_EQ(longPressRecognizer->touchPoints_.size(), 1);
228 
229     /**
230      * @tc.steps: step2. call HandleTouchUpEvent function and compare result.
231      * @tc.steps: case6: change isForDrag
232      * @tc.expected: step2. result equals.
233      */
234     longPressRecognizer->isForDrag_ = !longPressRecognizer->isForDrag_;
235     longPressRecognizer->HandleTouchDownEvent(touchEvent);
236     EXPECT_EQ(longPressRecognizer->touchPoints_.size(), 1);
237 
238     /**
239      * @tc.steps: step2. call HandleTouchUpEvent function and compare result.
240      * @tc.steps: case7: change isDisableMouseLeft_
241      * @tc.expected: step2. result equals.
242      */
243     longPressRecognizer->isDisableMouseLeft_ = !longPressRecognizer->isDisableMouseLeft_;
244     longPressRecognizer->HandleTouchDownEvent(touchEvent);
245     EXPECT_EQ(longPressRecognizer->touchPoints_.size(), 1);
246 }
247 
248 /**
249  * @tc.name: LongPressRecognizerTest004
250  * @tc.desc: Test LongPressRecognizer function: HandleTouchCancelEvent UpEvent
251  * @tc.type: FUNC
252  */
253 HWTEST_F(LongPressRecognizerTestNg, LongPressRecognizerTest004, TestSize.Level1)
254 {
255     /**
256      * @tc.steps: step1. create LongPressRecognizer.
257      */
258     RefPtr<LongPressRecognizer> longPressRecognizer =
259         AceType::MakeRefPtr<LongPressRecognizer>(LONG_PRESS_DURATION, FINGER_NUMBER, false);
260 
261     /**
262      * @tc.steps: step2. call HandleTouchUpEvent function and compare result.
263      * @tc.steps: refereeState == RefereeState::SUCCEED
264      * @tc.expected: step2. result equals.
265      */
266     TouchEvent touchEvent;
267     longPressRecognizer->refereeState_ = RefereeState::SUCCEED;
268     longPressRecognizer->HandleTouchUpEvent(touchEvent);
269     longPressRecognizer->HandleTouchCancelEvent(touchEvent);
270     EXPECT_EQ(longPressRecognizer->touchPoints_.size(), 0);
271 
272     /**
273      * @tc.steps: step2. call HandleTouchUpEvent function and compare result.
274      * @tc.steps: refereeState == RefereeState::SUCCEED
275      * @tc.expected: step2. result equals.
276      */
277     longPressRecognizer->refereeState_ = RefereeState::SUCCEED;
278     longPressRecognizer->currentFingers_ = longPressRecognizer->fingers_;
279     longPressRecognizer->HandleTouchUpEvent(touchEvent);
280     longPressRecognizer->HandleTouchCancelEvent(touchEvent);
281     EXPECT_EQ(longPressRecognizer->touchPoints_.size(), 0);
282 }
283 
284 /**
285  * @tc.name: LongPressRecognizerDoRepeatTest001
286  * @tc.desc: Test LongPressRecognizer function: DoRepeat
287  * @tc.type: FUNC
288  */
289 HWTEST_F(LongPressRecognizerTestNg, LongPressRecognizerDoRepeatTest001, TestSize.Level1)
290 {
291     /**
292      * @tc.steps: step1. create LongPressRecognizer.
293      */
294     RefPtr<LongPressRecognizer> longPressRecognizer =
295         AceType::MakeRefPtr<LongPressRecognizer>(LONG_PRESS_DURATION, FINGER_NUMBER, false);
296 
297     /**
298      * @tc.steps: step2. call DoRepeat
299      * @tc.steps: refereeState == RefereeState::SUCCEED
300      * @tc.expected: step2. result equals.
301      */
302     TouchEvent touchEvent;
303     longPressRecognizer->refereeState_ = RefereeState::SUCCEED;
304     longPressRecognizer->fingers_ = 0;
305     longPressRecognizer->DoRepeat();
306     longPressRecognizer->HandleTouchCancelEvent(touchEvent);
307     EXPECT_EQ(longPressRecognizer->touchPoints_.size(), 0);
308 
309     /**
310      * @tc.steps: step2. call DoRepeat
311      * @tc.steps: refereeState == RefereeState::SUCCEED
312      * @tc.expected: step2. result equals.
313      */
314     longPressRecognizer->refereeState_ = RefereeState::DETECTING;
315     longPressRecognizer->currentFingers_ = longPressRecognizer->fingers_;
316     longPressRecognizer->fingers_ = 0;
317     longPressRecognizer->DoRepeat();
318     EXPECT_EQ(longPressRecognizer->touchPoints_.size(), 0);
319 }
320 
321 /**
322  * @tc.name: LongPressRecognizerTest005
323  * @tc.desc: Test LongPressRecognizer function: SendCallbackMsg
324  * @tc.type: FUNC
325  */
326 HWTEST_F(LongPressRecognizerTestNg, LongPressRecognizerTest005, TestSize.Level1)
327 {
328     /**
329      * @tc.steps: step1. create LongPressRecognizer.
330      */
331     RefPtr<LongPressRecognizer> longPressRecognizer =
332         AceType::MakeRefPtr<LongPressRecognizer>(LONG_PRESS_DURATION, FINGER_NUMBER, false);
333     bool isRepeat = false;
334 
335     /**
336      * @tc.steps: step2. call SendCallbackMsg function and compare result.
337      * @tc.steps: case1: onAction is no, *onAction is no
338      * @tc.expected: step2. result equals.
339      */
340     std::unique_ptr<GestureEventFunc> onAction;
341     longPressRecognizer->SendCallbackMsg(onAction, isRepeat, GestureCallbackType::START);
342     EXPECT_EQ(longPressRecognizer->touchPoints_.size(), 0);
343 
344     /**
345      * @tc.steps: step2. call SendCallbackMsg function and compare result.
346      * @tc.steps: case2: onAction is yes, *onAction is no
347      * @tc.expected: step2. result equals.
348      */
349     onAction = std::make_unique<GestureEventFunc>();
350     longPressRecognizer->SendCallbackMsg(onAction, isRepeat, GestureCallbackType::START);
351     EXPECT_EQ(longPressRecognizer->touchPoints_.size(), 0);
352 
353     /**
354      * @tc.steps: step2. call SendCallbackMsg function and compare result.
355      * @tc.steps: case3: onAction is yes, *onAction is yes, touchEvent is empty
356      * @tc.expected: step2. result equals.
357      */
__anon9a2f6d570202(GestureEvent) 358     onAction = std::make_unique<GestureEventFunc>([](GestureEvent) {});
359     longPressRecognizer->SendCallbackMsg(onAction, isRepeat, GestureCallbackType::START);
360     EXPECT_EQ(longPressRecognizer->touchPoints_.size(), 0);
361 
362     /**
363      * @tc.steps: step2. call SendCallbackMsg function and compare result.
364      * @tc.steps: case4: touchEvent is not empty, have no X and Y
365      * @tc.expected: step2. result equals.
366      */
367     TouchEvent touchEvent;
368     longPressRecognizer->touchPoints_[touchEvent.id] = touchEvent;
369     longPressRecognizer->SendCallbackMsg(onAction, isRepeat, GestureCallbackType::START);
370     EXPECT_EQ(longPressRecognizer->touchPoints_.size(), 1);
371 
372     /**
373      * @tc.steps: step2. call SendCallbackMsg function and compare result.
374      * @tc.steps: case4: touchEvent is not empty, have no X and Y
375      * @tc.expected: step2. result equals.
376      */
377     touchEvent.tiltX = 0.0f;
378     touchEvent.tiltY = 0.0f;
379     longPressRecognizer->touchPoints_[touchEvent.id] = touchEvent;
380     longPressRecognizer->SendCallbackMsg(onAction, isRepeat, GestureCallbackType::START);
381     EXPECT_EQ(longPressRecognizer->touchPoints_.size(), 1);
382 }
383 
384 /**
385  * @tc.name: LongPressRecognizerTest006
386  * @tc.desc: Test LongPressRecognizer function: ReconcileFrom
387  * @tc.type: FUNC
388  */
389 HWTEST_F(LongPressRecognizerTestNg, LongPressRecognizerTest006, TestSize.Level1)
390 {
391     /**
392      * @tc.steps: step1. create LongPressRecognizer.
393      */
394     RefPtr<LongPressRecognizer> longPressRecognizer =
395         AceType::MakeRefPtr<LongPressRecognizer>(LONG_PRESS_DURATION, FINGER_NUMBER, false);
396     RefPtr<LongPressRecognizer> longPressRecognizerPtr =
397         AceType::MakeRefPtr<LongPressRecognizer>(LONG_PRESS_DURATION, FINGER_NUMBER, false);
398 
399     /**
400      * @tc.steps: step2. call ReconcileFrom function and compare result.
401      * @tc.steps: case1: normal case
402      * @tc.expected: step2. result equals.
403      */
404     auto result = longPressRecognizer->ReconcileFrom(longPressRecognizerPtr);
405     EXPECT_EQ(result, true);
406 
407     /**
408      * @tc.steps: step2. call ReconcileFrom function and compare result.
409      * @tc.steps: case2: recognizerPtr is nullptr
410      * @tc.expected: step2. result equals.
411      */
412     result = longPressRecognizer->ReconcileFrom(nullptr);
413     EXPECT_EQ(result, false);
414 
415     /**
416      * @tc.steps: step2. call ReconcileFrom function and compare result.
417      * @tc.steps: case3: recognizerPtr, duration not same
418      * @tc.expected: step2. result equals.
419      */
420     longPressRecognizer->duration_ = 0;
421     result = longPressRecognizer->ReconcileFrom(longPressRecognizerPtr);
422     EXPECT_EQ(result, false);
423 
424     /**
425      * @tc.steps: step2. call ReconcileFrom function and compare result.
426      * @tc.steps: case4: recognizerPtr, duration same, fingers not same
427      * @tc.expected: step2. result equals.
428      */
429     longPressRecognizer->duration_ = longPressRecognizerPtr->duration_;
430     longPressRecognizer->fingers_ = longPressRecognizerPtr->fingers_ + 1;
431     result = longPressRecognizer->ReconcileFrom(longPressRecognizerPtr);
432     EXPECT_EQ(result, false);
433 
434     /**
435      * @tc.steps: step2. call ReconcileFrom function and compare result.
436      * @tc.steps: case5: recognizerPtr, fingers same, repeat not same
437      * @tc.expected: step2. result equals.
438      */
439     longPressRecognizer->fingers_ = longPressRecognizerPtr->fingers_;
440     longPressRecognizer->repeat_ = !longPressRecognizerPtr->repeat_;
441     result = longPressRecognizer->ReconcileFrom(longPressRecognizerPtr);
442     EXPECT_EQ(result, false);
443 
444     /**
445      * @tc.steps: step2. call ReconcileFrom function and compare result.
446      * @tc.steps: case5: recognizerPtr, repeat same, priorityMask not same
447      * @tc.expected: step2. result equals.
448      */
449     longPressRecognizer->repeat_ = longPressRecognizerPtr->repeat_;
450     longPressRecognizer->priorityMask_ = GestureMask::End;
451     result = longPressRecognizer->ReconcileFrom(longPressRecognizerPtr);
452     EXPECT_EQ(result, false);
453 }
454 
455 /**
456  * @tc.name: LongPressRecognizerTestGetLongPressActionFunc001
457  * @tc.desc: Test LongPressRecognizer function: GetLongPressActionFunc
458  * @tc.type: FUNC
459  */
460 HWTEST_F(LongPressRecognizerTestNg, LongPressRecognizerTestGetLongPressActionFunc001, TestSize.Level1)
461 {
462     /**
463      * @tc.steps: step1. create LongPressRecognizer.
464      */
465     RefPtr<LongPressRecognizer> longPressRecognizer =
466         AceType::MakeRefPtr<LongPressRecognizer>(LONG_PRESS_DURATION, FINGER_NUMBER, false);
467     bool isCatchMode = false;
468 
469     /**
470      * @tc.steps: step2. call GetLongPressActionFunc function and compare result.
471      * @tc.steps: case1: normal case
472      * @tc.expected: step2. result equals.
473      */
474     longPressRecognizer->refereeState_ = RefereeState::SUCCEED;
475     auto frameNode = FrameNode::CreateFrameNode("myButton", 100, AceType::MakeRefPtr<Pattern>());
476     longPressRecognizer->AttachFrameNode(frameNode);
477     longPressRecognizer->HandleOverdueDeadline(isCatchMode);
478     longPressRecognizer->DoRepeat();
479     EXPECT_EQ(longPressRecognizer->refereeState_, RefereeState::SUCCEED);
480     auto result = longPressRecognizer->GetLongPressActionFunc();
481 }
482 
483 /**
484  * @tc.name: LongPressRecognizerTestGetLongPressActionFunc003
485  * @tc.desc: Test LongPressRecognizer function: GetLongPressActionFunc
486  * @tc.type: FUNC
487  */
488 HWTEST_F(LongPressRecognizerTestNg, LongPressRecognizerTestGetLongPressActionFunc003, TestSize.Level1)
489 {
490     /**
491      * @tc.steps: step1. create LongPressRecognizer.
492      */
493     RefPtr<LongPressRecognizer> longPressRecognizer =
494         AceType::MakeRefPtr<LongPressRecognizer>(LONG_PRESS_DURATION, FINGER_NUMBER, false);
495     bool isCatchMode = false;
496 
497     /**
498      * @tc.steps: step2. call GetLongPressActionFunc function and compare result.
499      * @tc.steps: case1: normal case
500      * @tc.expected: step2. result equals.
501      */
502     longPressRecognizer->refereeState_ = RefereeState::SUCCEED;
503     auto frameNode = FrameNode::CreateFrameNode("myButton", 100, AceType::MakeRefPtr<Pattern>());
504     longPressRecognizer->AttachFrameNode(frameNode);
505     longPressRecognizer->HandleOverdueDeadline(isCatchMode);
506     longPressRecognizer->DoRepeat();
507     GestureEventFunc click;
508     GestureEvent info;
509     click = longPressRecognizer->GetLongPressActionFunc();
510     click(info);
511     EXPECT_EQ(longPressRecognizer->refereeState_, RefereeState::SUCCEED);
512 }
513 
514 /**
515  * @tc.name: LongPressRecognizerTestGetLongPressActionFunc004
516  * @tc.desc: Test LongPressRecognizer function: GetLongPressActionFunc
517  * @tc.type: FUNC
518  */
519 HWTEST_F(LongPressRecognizerTestNg, LongPressRecognizerTestGetLongPressActionFunc004, TestSize.Level1)
520 {
521     /**
522      * @tc.steps: step1. create LongPressRecognizer.
523      */
524     RefPtr<LongPressRecognizer> longPressRecognizer =
525         AceType::MakeRefPtr<LongPressRecognizer>(LONG_PRESS_DURATION, FINGER_NUMBER, false);
526     bool isCatchMode = false;
527 
528     /**
529      * @tc.steps: step2. call GetLongPressActionFunc function and compare result.
530      * @tc.steps: case1: normal case
531      * @tc.expected: step2. result equals.
532      */
533     longPressRecognizer->refereeState_ = RefereeState::SUCCEED;
534     auto frameNode = FrameNode::CreateFrameNode("myButton", 100, AceType::MakeRefPtr<Pattern>());
535     longPressRecognizer->AttachFrameNode(frameNode);
536     longPressRecognizer->HandleOverdueDeadline(isCatchMode);
537     longPressRecognizer->DoRepeat();
538     GestureEventFunc click;
539     GestureEvent info;
__anon9a2f6d570302(GestureEvent& info) 540     auto onActionStart = [](GestureEvent& info) { return true; };
__anon9a2f6d570402(GestureEvent& info) 541     auto onActionUpdate = [](GestureEvent& info) { return true; };
__anon9a2f6d570502(GestureEvent& info) 542     auto onActionEnd = [](GestureEvent& info) { return true; };
543     longPressRecognizer->SetOnActionUpdate(onActionUpdate);
544     longPressRecognizer->SetOnAction(onActionStart);
545     longPressRecognizer->SetOnActionEnd(onActionEnd);
546     click = longPressRecognizer->GetLongPressActionFunc();
547     click(info);
548     EXPECT_EQ(longPressRecognizer->refereeState_, RefereeState::SUCCEED);
549 }
550 
551 /**
552  * @tc.name: LongPressRecognizerTestGetLongPressActionFunc002
553  * @tc.desc: Test LongPressRecognizer function: GetLongPressActionFunc
554  * @tc.type: FUNC
555  */
556 HWTEST_F(LongPressRecognizerTestNg, LongPressRecognizerTestGetLongPressActionFunc002, TestSize.Level1)
557 {
558     /**
559      * @tc.steps: step1. create LongPressRecognizer.
560      */
561     RefPtr<LongPressRecognizer> longPressRecognizer =
562         AceType::MakeRefPtr<LongPressRecognizer>(LONG_PRESS_DURATION, FINGER_NUMBER, false);
563     bool isCatchMode = false;
564 
565     /**
566      * @tc.steps: step2. call GetLongPressActionFunc function and compare result.
567      * @tc.steps: case1: normal case
568      * @tc.expected: step2. result equals.
569      */
570     longPressRecognizer->refereeState_ = RefereeState::SUCCEED;
571     longPressRecognizer->fingers_ = SINGLE_FINGER_NUMBER;
572     auto frameNode = FrameNode::CreateFrameNode("myButton", 100, AceType::MakeRefPtr<Pattern>());
573     longPressRecognizer->AttachFrameNode(frameNode);
574     longPressRecognizer->HandleOverdueDeadline(isCatchMode);
575     longPressRecognizer->DoRepeat();
576     auto result = longPressRecognizer->GetLongPressActionFunc();
577     EXPECT_EQ(longPressRecognizer->refereeState_, RefereeState::SUCCEED);
578 
579     /**
580      * @tc.steps: step2. call GetLongPressActionFunc function and compare result.
581      * @tc.steps: case1: normal case
582      * @tc.expected: step2. result equals.
583      */
584     longPressRecognizer->refereeState_ = RefereeState::DETECTING;
585     longPressRecognizer->fingers_ = SINGLE_FINGER_NUMBER;
586     longPressRecognizer->HandleOverdueDeadline(isCatchMode);
587     longPressRecognizer->DoRepeat();
588     result = longPressRecognizer->GetLongPressActionFunc();
589     EXPECT_NE(longPressRecognizer->refereeState_, RefereeState::DETECTING);
590 }
591 
592 /**
593  * @tc.name: LongPressRecognizerConvertPxToVpTest001
594  * @tc.desc: Test LongPressRecognizer function: ConvertPxToVp
595  * @tc.type: FUNC
596  */
597 HWTEST_F(LongPressRecognizerTestNg, LongPressRecognizerConvertPxToVpTest001, TestSize.Level1)
598 {
599     /**
600      * @tc.steps: step1. create LongPressRecognizer.
601      */
602     RefPtr<LongPressRecognizer> longPressRecognizer =
603         AceType::MakeRefPtr<LongPressRecognizer>(LONG_PRESS_DURATION, FINGER_NUMBER, false);
604 
605     /**
606      * @tc.steps: step2. call ConvertPxToVp function and compare result.
607      * @tc.steps: case1: normal case
608      * @tc.expected: step2. result equals.
609      */
610     double result = longPressRecognizer->ConvertPxToVp(0.0);
611     EXPECT_EQ(result, 0.0);
612 }
613 
614 /**
615  * @tc.name: LongPressRecognizerTest007
616  * @tc.desc: Test LongPressRecognizer function: HandleOverdueDeadline  DoRepeat
617  * @tc.type: FUNC
618  */
619 HWTEST_F(LongPressRecognizerTestNg, LongPressRecognizerTest007, TestSize.Level1)
620 {
621     /**
622      * @tc.steps: step1. create LongPressRecognizer.
623      */
624     RefPtr<LongPressRecognizer> longPressRecognizer =
625         AceType::MakeRefPtr<LongPressRecognizer>(LONG_PRESS_DURATION, FINGER_NUMBER, false);
626     bool isCatchMode = false;
627 
628     /**
629      * @tc.steps: step2. call HandleOverdueDeadline function and compare result.
630      * @tc.steps: case1: refereeState is SUCCESS, return
631      * @tc.expected: step2. result equals.
632      */
633     longPressRecognizer->refereeState_ = RefereeState::SUCCEED;
634     auto frameNode = FrameNode::CreateFrameNode("myButton", 100, AceType::MakeRefPtr<Pattern>());
635     longPressRecognizer->AttachFrameNode(frameNode);
636     longPressRecognizer->HandleOverdueDeadline(isCatchMode);
637     longPressRecognizer->DoRepeat();
638     EXPECT_EQ(longPressRecognizer->refereeState_, RefereeState::SUCCEED);
639 
640     /**
641      * @tc.steps: step2. call HandleOverdueDeadline function and compare result.
642      * @tc.steps: case1: refereeState is DETECTING, isCatchMode is false
643      * @tc.expected: step2. result equals.
644      */
645     longPressRecognizer->refereeState_ = RefereeState::DETECTING;
646     longPressRecognizer->HandleOverdueDeadline(isCatchMode);
647     longPressRecognizer->DoRepeat();
648     EXPECT_EQ(longPressRecognizer->refereeState_, RefereeState::SUCCEED);
649 }
650 
651 /**
652  * @tc.name: LongPressRecognizerSendCallbackMsgTest001
653  * @tc.desc: Test LongPressRecognizer function: SendCallbackMsg
654  * @tc.type: FUNC
655  */
656 HWTEST_F(LongPressRecognizerTestNg, LongPressRecognizerSendCallbackMsgTest001, TestSize.Level1)
657 {
658     /**
659      * @tc.steps: step1. Create longPressRecognizer->
660      */
661     RefPtr<LongPressRecognizer> longPressRecognizer =
662         AceType::MakeRefPtr<LongPressRecognizer>(LONG_PRESS_DURATION, FINGER_NUMBER, false);
663     std::unique_ptr<GestureEventFunc> onAction;
664 
665     /**
666      * @tc.steps: step2. call SendCallbackMsg function and compare result.
667      * @tc.steps: case3: onAction is yes, *onAction is yes, touchEvent is empty, type is AXIS
668      * @tc.expected: step2. result equals.
669      */
__anon9a2f6d570602(GestureEvent) 670     onAction = std::make_unique<GestureEventFunc>([](GestureEvent) {});
671     longPressRecognizer->SendCallbackMsg(onAction, true, GestureCallbackType::START);
672     EXPECT_EQ(longPressRecognizer->touchPoints_.size(), 0);
673 }
674 
675 /**
676  * @tc.name: LongPressGestureTest001
677  * @tc.desc: Test LongPressGesture CreateRecognizer function
678  */
679 HWTEST_F(LongPressRecognizerTestNg, LongPressGestureTest001, TestSize.Level1)
680 {
681     /**
682      * @tc.steps: step1. create LongPressGesture.
683      */
684     LongPressGestureModelNG longPressGestureModelNG;
685     longPressGestureModelNG.Create(FINGER_NUMBER, false, LONG_PRESS_DURATION);
686 
687     RefPtr<GestureProcessor> gestureProcessor;
688     gestureProcessor = NG::ViewStackProcessor::GetInstance()->GetOrCreateGestureProcessor();
689     auto longPressGestureNG = AceType::DynamicCast<NG::LongPressGesture>(gestureProcessor->TopGestureNG());
690     EXPECT_EQ(longPressGestureNG->duration_, LONG_PRESS_DURATION);
691 
692     LongPressGesture longPressGesture = LongPressGesture(FINGER_NUMBER, false, LONG_PRESS_DURATION, false, false);
693     EXPECT_EQ(longPressGesture.repeat_, false);
694     EXPECT_EQ(longPressGesture.duration_, LONG_PRESS_DURATION);
695     EXPECT_EQ(longPressGesture.isForDrag_, false);
696     EXPECT_EQ(longPressGesture.isDisableMouseLeft_, false);
697 
698     /**
699      * @tc.steps: step2. call CreateRecognizer function and compare result
700      * @tc.steps: case1: onActionId, onActionEndId, onActionCancelId not existed
701      */
702     auto longPressRecognizer = AceType::DynamicCast<LongPressRecognizer>(longPressGesture.CreateRecognizer());
703     EXPECT_NE(longPressRecognizer, nullptr);
704     EXPECT_EQ(longPressRecognizer->repeat_, false);
705     EXPECT_EQ(longPressRecognizer->duration_, LONG_PRESS_DURATION);
706     EXPECT_EQ(longPressRecognizer->isForDrag_, false);
707     EXPECT_EQ(longPressRecognizer->isDisableMouseLeft_, false);
708 
709     /**
710      * @tc.steps: step2. call CreateRecognizer function and compare result
711      * @tc.steps: case2: onActionId, onActionEndId, onActionCancelId existed
712      */
713     std::unique_ptr<GestureEventFunc> onActionId;
714     std::unique_ptr<GestureEventFunc> onActionEndId;
715     std::unique_ptr<GestureEventFunc> onActionCancelId;
716     longPressGesture.onActionId_ = std::move(onActionId);
717     longPressGesture.onActionEndId_ = std::move(onActionEndId);
718     longPressGesture.onActionCancelId_ = std::move(onActionCancelId);
719     longPressRecognizer = AceType::DynamicCast<LongPressRecognizer>(longPressGesture.CreateRecognizer());
720     EXPECT_NE(longPressRecognizer, nullptr);
721     EXPECT_EQ(longPressRecognizer->repeat_, false);
722     EXPECT_EQ(longPressRecognizer->duration_, LONG_PRESS_DURATION);
723     EXPECT_EQ(longPressRecognizer->isForDrag_, false);
724     EXPECT_EQ(longPressRecognizer->isDisableMouseLeft_, false);
725 }
726 
727 /**
728  * @tc.name: LongPressGestureCreateRecognizerTest001
729  * @tc.desc: Test LongPressGesture CreateRecognizer function
730  */
731 HWTEST_F(LongPressRecognizerTestNg, LongPressGestureCreateRecognizerTest001, TestSize.Level1)
732 {
733     /**
734      * @tc.steps: step1. create LongPressGesture.
735      */
736     LongPressGestureModelNG longPressGestureModelNG;
737     longPressGestureModelNG.Create(FINGER_NUMBER, false, LONG_PRESS_DURATION);
738 
739     RefPtr<GestureProcessor> gestureProcessor;
740     gestureProcessor = NG::ViewStackProcessor::GetInstance()->GetOrCreateGestureProcessor();
741     auto longPressGestureNG = AceType::DynamicCast<NG::LongPressGesture>(gestureProcessor->TopGestureNG());
742     EXPECT_EQ(longPressGestureNG->duration_, LONG_PRESS_DURATION);
743 
744     LongPressGesture longPressGesture = LongPressGesture(FINGER_NUMBER, false, LONG_PRESS_DURATION, false, false);
745     EXPECT_EQ(longPressGesture.repeat_, false);
746     EXPECT_EQ(longPressGesture.duration_, LONG_PRESS_DURATION);
747     EXPECT_EQ(longPressGesture.isForDrag_, false);
748     EXPECT_EQ(longPressGesture.isDisableMouseLeft_, false);
749 
750     /**
751      * @tc.steps: step2. call CreateRecognizer function and compare result
752      * @tc.steps: case1: onActionId, onActionEndId, onActionCancelId not existed
753      */
754     longPressGesture.fingers_ = FINGER_NUMBER_OVER_MAX;
755     longPressGesture.duration_ = 0;
756     auto longPressRecognizer = AceType::DynamicCast<LongPressRecognizer>(longPressGesture.CreateRecognizer());
757     EXPECT_NE(longPressRecognizer, nullptr);
758 
759     /**
760      * @tc.steps: step2. call CreateRecognizer function and compare result
761      * @tc.steps: case1: onActionId, onActionEndId, onActionCancelId not existed
762      */
763     longPressGesture.fingers_ = 0;
764     longPressGesture.duration_ = 0;
765     longPressRecognizer = AceType::DynamicCast<LongPressRecognizer>(longPressGesture.CreateRecognizer());
766     EXPECT_NE(longPressRecognizer, nullptr);
767 }
768 
769 
770 /**
771  * @tc.name: LongPressGestureCreateRecognizerTest002
772  * @tc.desc: Test LongPressGesture CreateRecognizer function
773  */
774 HWTEST_F(LongPressRecognizerTestNg, LongPressGestureCreateRecognizerTest002, TestSize.Level1)
775 {
776     /**
777      * @tc.steps: step1. create LongPressGesture.
778      */
779     LongPressGestureModelNG longPressGestureModelNG;
780     longPressGestureModelNG.Create(FINGER_NUMBER, false, LONG_PRESS_DURATION);
781 
782     RefPtr<GestureProcessor> gestureProcessor;
783     gestureProcessor = NG::ViewStackProcessor::GetInstance()->GetOrCreateGestureProcessor();
784     auto longPressGestureNG = AceType::DynamicCast<NG::LongPressGesture>(gestureProcessor->TopGestureNG());
785     EXPECT_EQ(longPressGestureNG->duration_, LONG_PRESS_DURATION);
786 
787     LongPressGesture longPressGesture = LongPressGesture(FINGER_NUMBER, false, LONG_PRESS_DURATION, false, false);
788     EXPECT_EQ(longPressGesture.repeat_, false);
789     EXPECT_EQ(longPressGesture.duration_, LONG_PRESS_DURATION);
790     EXPECT_EQ(longPressGesture.isForDrag_, false);
791     EXPECT_EQ(longPressGesture.isDisableMouseLeft_, false);
792 
793     /**
794      * @tc.steps: step2. call CreateRecognizer function and compare result
795      * @tc.steps: case1: onActionId, onActionEndId, onActionCancelId not existed
796      */
797     longPressGesture.fingers_ = FINGER_NUMBER_OVER_MAX;
798     longPressGesture.duration_ = 0;
__anon9a2f6d570702(GestureEvent& info) 799     auto onActionStart = [](GestureEvent& info) { return true; };
__anon9a2f6d570802(GestureEvent& info) 800     auto onActionEnd = [](GestureEvent& info) { return true; };
__anon9a2f6d570902(GestureEvent& info) 801     auto onActionCancel = [](GestureEvent& info) { return true; };
802     longPressGesture.SetOnActionId(onActionStart);
803     longPressGesture.SetOnActionEndId(onActionEnd);
804     longPressGesture.SetOnActionCancelId(onActionCancel);
805     auto longPressRecognizer = AceType::DynamicCast<LongPressRecognizer>(longPressGesture.CreateRecognizer());
806     EXPECT_NE(longPressRecognizer, nullptr);
807 
808     /**
809      * @tc.steps: step2. call CreateRecognizer function and compare result
810      * @tc.steps: case1: onActionId, onActionEndId, onActionCancelId not existed
811      */
812     longPressGesture.fingers_ = 0;
813     longPressGesture.duration_ = 0;
814     longPressRecognizer = AceType::DynamicCast<LongPressRecognizer>(longPressGesture.CreateRecognizer());
815     EXPECT_NE(longPressRecognizer, nullptr);
816 }
817 
818 /**
819  * @tc.name: LongPressGestureCreateRecognizerTest003
820  * @tc.desc: Test LongPressGesture CreateRecognizer function
821  */
822 HWTEST_F(LongPressRecognizerTestNg, LongPressGestureCreateRecognizerTest003, TestSize.Level1)
823 {
824     /**
825      * @tc.steps: step1. create LongPressGesture.
826      */
827     LongPressGestureModelNG longPressGestureModelNG;
828     longPressGestureModelNG.Create(FINGER_NUMBER, false, LONG_PRESS_DURATION);
829 
830     RefPtr<GestureProcessor> gestureProcessor;
831     gestureProcessor = NG::ViewStackProcessor::GetInstance()->GetOrCreateGestureProcessor();
832     auto longPressGestureNG = AceType::DynamicCast<NG::LongPressGesture>(gestureProcessor->TopGestureNG());
833     EXPECT_EQ(longPressGestureNG->duration_, LONG_PRESS_DURATION);
834 
835     LongPressGesture longPressGesture = LongPressGesture(FINGER_NUMBER, false, LONG_PRESS_DURATION, false, false);
836     EXPECT_EQ(longPressGesture.repeat_, false);
837     EXPECT_EQ(longPressGesture.duration_, LONG_PRESS_DURATION);
838     EXPECT_EQ(longPressGesture.isForDrag_, false);
839     EXPECT_EQ(longPressGesture.isDisableMouseLeft_, false);
840 
841     /**
842      * @tc.steps: step2. call CreateRecognizer function and compare result
843      * @tc.steps: case1: onActionCancelId not existed
844      */
845     longPressGesture.fingers_ = FINGER_NUMBER_OVER_MAX;
846     longPressGesture.duration_ = 0;
__anon9a2f6d570a02(GestureEvent& info) 847     auto onActionCancel = [](GestureEvent& info) { return true; };
848     longPressGesture.SetOnActionCancelId(onActionCancel);
849     auto longPressRecognizer = AceType::DynamicCast<LongPressRecognizer>(longPressGesture.CreateRecognizer());
850     EXPECT_NE(longPressRecognizer, nullptr);
851 
852     /**
853      * @tc.steps: step3. call CreateRecognizer function and compare result
854      * @tc.steps: case2: onActionCancelId existed
855      */
856     longPressGesture.fingers_ = SINGLE_FINGER_NUMBER;
857     longPressGesture.duration_ = 200;
858     longPressRecognizer = AceType::DynamicCast<LongPressRecognizer>(longPressGesture.CreateRecognizer());
859     EXPECT_NE(longPressRecognizer, nullptr);
860 }
861 
862 /**
863  * @tc.name: LongPressRecognizerHandleTouchUpEventTest009
864  * @tc.desc: Test LongPressRecognizer function: HandleTouchUpEvent
865  * @tc.type: FUNC
866  */
867 HWTEST_F(LongPressRecognizerTestNg, LongPressRecognizerHandleTouchUpEventTest009, TestSize.Level1)
868 {
869     /**
870      * @tc.steps: step1. create PinchRecognizer.
871      */
872     RefPtr<LongPressRecognizer> longPressRecognizer =AceType::MakeRefPtr<LongPressRecognizer>(LONG_PRESS_DURATION,
873         FINGER_NUMBER, false);
874     TouchEvent touchEvent;
875     touchEvent.x = 100.0;
876     touchEvent.y = 100.0;
877 
878     longPressRecognizer->refereeState_ = RefereeState::DETECTING;
879     longPressRecognizer->currentFingers_ = longPressRecognizer->fingers_;
880     longPressRecognizer->HandleTouchUpEvent(touchEvent);
881     EXPECT_EQ(longPressRecognizer->repeat_, false);
882 }
883 
884 /**
885  * @tc.name: LongPressRecognizerHandleTouchCancelEventTest001
886  * @tc.desc: Test LongPressRecognizer function: HandleTouchCancelEvent
887  * @tc.type: FUNC
888  */
889 HWTEST_F(LongPressRecognizerTestNg, LongPressRecognizerHandleTouchCancelEventTest001, TestSize.Level1)
890 {
891     /**
892      * @tc.steps: step1. create LongPressRecognizer.
893      */
894     RefPtr<LongPressRecognizer> longPressRecognizer =AceType::MakeRefPtr<LongPressRecognizer>(LONG_PRESS_DURATION,
895         FINGER_NUMBER, false);
896     TouchEvent touchEvent;
897     touchEvent.x = 100.0;
898     touchEvent.y = 100.0;
899 
900     longPressRecognizer->refereeState_ = RefereeState::DETECTING;
901     longPressRecognizer->currentFingers_ = longPressRecognizer->fingers_;
902     longPressRecognizer->HandleTouchCancelEvent(touchEvent);
903     EXPECT_EQ(longPressRecognizer->repeat_, false);
904 }
905 
906 /**
907  * @tc.name: LongPressRecognizerHandleTouchDownEventTest001
908  * @tc.desc: Test LongPressRecognizer function: HandleTouchDownEvent
909  * @tc.type: FUNC
910  */
911 HWTEST_F(LongPressRecognizerTestNg, LongPressRecognizerHandleTouchDownEventTest001, TestSize.Level1)
912 {
913     /**
914      * @tc.steps: step1. create LongPressRecognizer.
915      */
916     RefPtr<LongPressRecognizer> longPressRecognizer =AceType::MakeRefPtr<LongPressRecognizer>(LONG_PRESS_DURATION,
917         FINGER_NUMBER, false);
918     TouchEvent touchEvent;
919     touchEvent.x = 100.0;
920     touchEvent.y = 100.0;
921     touchEvent.sourceType = SourceType::MOUSE;
922 
923     longPressRecognizer->refereeState_ = RefereeState::DETECTING;
924     longPressRecognizer->isDisableMouseLeft_ = true;
925     longPressRecognizer->currentFingers_ = longPressRecognizer->fingers_;
926     longPressRecognizer->HandleTouchDownEvent(touchEvent);
927     EXPECT_EQ(longPressRecognizer->repeat_, false);
928 }
929 
930 /**
931  * @tc.name: LongPressRecognizerHandleTouchMoveEventTest001
932  * @tc.desc: Test LongPressRecognizer function: HandleTouchMoveEvent
933  * @tc.type: FUNC
934  */
935 HWTEST_F(LongPressRecognizerTestNg, LongPressRecognizerHandleTouchMoveEventTest001, TestSize.Level1)
936 {
937     /**
938      * @tc.steps: step1. create LongPressRecognizer.
939      */
940     RefPtr<LongPressRecognizer> longPressRecognizer =AceType::MakeRefPtr<LongPressRecognizer>(LONG_PRESS_DURATION,
941         FINGER_NUMBER, false);
942     TouchEvent touchEvent;
943     touchEvent.x = 100.0;
944     touchEvent.y = 100.0;
945     touchEvent.sourceType = SourceType::MOUSE;
946 
947     longPressRecognizer->refereeState_ = RefereeState::DETECTING;
948     longPressRecognizer->isDisableMouseLeft_ = true;
949     longPressRecognizer->currentFingers_ = longPressRecognizer->fingers_;
950     longPressRecognizer->isForDrag_ = true;
951     longPressRecognizer->HandleTouchMoveEvent(touchEvent);
952     EXPECT_EQ(longPressRecognizer->repeat_, false);
953 
954     longPressRecognizer->refereeState_ = RefereeState::DETECTING;
955     longPressRecognizer->isDisableMouseLeft_ = false;
956     longPressRecognizer->currentFingers_ = longPressRecognizer->fingers_;
957     longPressRecognizer->isForDrag_ = false;
958     longPressRecognizer->HandleTouchMoveEvent(touchEvent);
959     EXPECT_EQ(longPressRecognizer->repeat_, false);
960 }
961 
962 /**
963  * @tc.name: LongPressRecognizerHandleOverdueDeadlineTest001
964  * @tc.desc: Test LongPressRecognizer function: HandleOverdueDeadline
965  * @tc.type: FUNC
966  */
967 HWTEST_F(LongPressRecognizerTestNg, LongPressRecognizerHandleOverdueDeadlineTest001, TestSize.Level1)
968 {
969     /**
970      * @tc.steps: step1. create LongPressRecognizer.
971      */
972     RefPtr<LongPressRecognizer> longPressRecognizer =AceType::MakeRefPtr<LongPressRecognizer>(LONG_PRESS_DURATION,
973         FINGER_NUMBER, false);
974     TouchEvent touchEvent;
975     touchEvent.x = 100.0;
976     touchEvent.y = 100.0;
977     touchEvent.sourceType = SourceType::MOUSE;
978 
979     longPressRecognizer->refereeState_ = RefereeState::DETECTING;
980     longPressRecognizer->HandleOverdueDeadline(true);
981     EXPECT_EQ(longPressRecognizer->repeat_, false);
982 }
983 
984 /**
985  * @tc.name: LongPressRecognizerThumbnailTimerTest001
986  * @tc.desc: Test ThumbnailTimer in LongPressRecognizer
987  */
988 HWTEST_F(LongPressRecognizerTestNg, LongPressRecognizerThumbnailTimerTest001, TestSize.Level1)
989 {
990     /**
991      * @tc.steps: step1. create LongPressRecognizer.
992      */
993     RefPtr<LongPressRecognizer> longPressRecognizer =AceType::MakeRefPtr<LongPressRecognizer>(LONG_PRESS_DURATION,
994         FINGER_NUMBER, false);
995 
996     /**
997      * @tc.steps: step2. set callback function.
998      */
__anon9a2f6d570b02(Offset offset) 999     auto callback = [](Offset offset) {};
1000     longPressRecognizer->callback_ = callback;
1001     longPressRecognizer->ThumbnailTimer(0);
1002     EXPECT_EQ(longPressRecognizer->refereeState_, RefereeState::READY);
1003 }
1004 
1005 /**
1006  * @tc.name: LongPressRecognizerTestGetLongPressActionFunc005
1007  * @tc.desc: Test LongPressRecognizer function: GetLongPressActionFunc
1008  * @tc.type: FUNC
1009  */
1010 HWTEST_F(LongPressRecognizerTestNg, LongPressRecognizerTestGetLongPressActionFunc005, TestSize.Level1)
1011 {
1012     /**
1013      * @tc.steps: step1. create LongPressRecognizer.
1014      */
1015     RefPtr<LongPressRecognizer> longPressRecognizer =AceType::MakeRefPtr<LongPressRecognizer>(LONG_PRESS_DURATION,
1016         FINGER_NUMBER, false);
1017     bool isCatchMode = false;
1018     longPressRecognizer->refereeState_ = RefereeState::SUCCEED;
1019     longPressRecognizer->HandleOverdueDeadline(isCatchMode);
1020     longPressRecognizer->DoRepeat();
1021     GestureEventFunc click;
1022     GestureEvent info;
1023 
1024     /**
1025      * @tc.steps: step2. call GetLongPressActionFunc function and compare result.
1026      * @tc.steps: case1: normal case
1027      * @tc.expected: step2. result equals.
1028      */
1029     click = longPressRecognizer->GetLongPressActionFunc();
1030     click(info);
1031     EXPECT_EQ(longPressRecognizer->refereeState_, RefereeState::SUCCEED);
1032 
__anon9a2f6d570c02(GestureEvent& info) 1033     auto onActionStart = [](GestureEvent& info) { return true; };
__anon9a2f6d570d02(GestureEvent& info) 1034     auto onActionUpdate = [](GestureEvent& info) { return true; };
__anon9a2f6d570e02(GestureEvent& info) 1035     auto onActionEnd = [](GestureEvent& info) { return true; };
1036     longPressRecognizer->SetOnActionUpdate(onActionUpdate);
1037     longPressRecognizer->SetOnAction(onActionStart);
1038     longPressRecognizer->SetOnActionEnd(onActionEnd);
1039     click = longPressRecognizer->GetLongPressActionFunc();
1040     click(info);
1041     EXPECT_EQ(longPressRecognizer->refereeState_, RefereeState::SUCCEED);
1042 }
1043 
1044 /**
1045  * @tc.name: LongPressRecognizerTestGetLongPressActionFunc006
1046  * @tc.desc: Test LongPressRecognizer function: GetLongPressActionFunc
1047  * @tc.type: FUNC
1048  */
1049 HWTEST_F(LongPressRecognizerTestNg, LongPressRecognizerTestGetLongPressActionFunc006, TestSize.Level1)
1050 {
1051     /**
1052      * @tc.steps: step1. create LongPressRecognizer.
1053      */
1054     RefPtr<LongPressRecognizer> longPressRecognizer =AceType::MakeRefPtr<LongPressRecognizer>(LONG_PRESS_DURATION,
1055         FINGER_NUMBER, false);
1056     GestureEventFunc click;
1057     GestureEvent info;
1058 
1059     /**
1060      * @tc.steps: step2. call GetLongPressActionFunc function and compare result.
1061      * @tc.steps: case1: normal case
1062      * @tc.expected: step2. result equals.
1063      */
1064     click = longPressRecognizer->GetLongPressActionFunc();
1065     click(info);
1066     EXPECT_EQ(longPressRecognizer->refereeState_, RefereeState::READY);
1067 
__anon9a2f6d570f02(GestureEvent& info) 1068     auto onActionStart = [](GestureEvent& info) { return true; };
__anon9a2f6d571002(GestureEvent& info) 1069     auto onActionUpdate = [](GestureEvent& info) { return true; };
__anon9a2f6d571102(GestureEvent& info) 1070     auto onActionEnd = [](GestureEvent& info) { return true; };
1071     longPressRecognizer->SetOnActionUpdate(onActionUpdate);
1072     longPressRecognizer->SetOnAction(onActionStart);
1073     longPressRecognizer->SetOnActionEnd(onActionEnd);
1074     click = longPressRecognizer->GetLongPressActionFunc();
1075     click(info);
1076     EXPECT_EQ(longPressRecognizer->refereeState_, RefereeState::READY);
1077 }
1078 
1079 /**
1080  * @tc.name: LongPressRecognizerHandleTouchUpEventTest001
1081  * @tc.desc: Test HandleTouchUpEvent in LongPressRecognizer
1082  */
1083 HWTEST_F(LongPressRecognizerTestNg, LongPressRecognizerHandleTouchUpEventTest001, TestSize.Level1)
1084 {
1085     /**
1086      * @tc.steps: step1. create LongPressRecognizer.
1087      */
1088     RefPtr<LongPressRecognizer> longPressRecognizer =AceType::MakeRefPtr<LongPressRecognizer>(LONG_PRESS_DURATION,
1089         FINGER_NUMBER, false);
1090     TouchEvent touchEvent;
1091 
1092     /**
1093      * @tc.steps: step2. set callback function.
1094      */
1095     longPressRecognizer->refereeState_ = RefereeState::SUCCEED;
1096     longPressRecognizer->currentFingers_ = longPressRecognizer->fingers_ + 1;
__anon9a2f6d571202(Offset offset) 1097     auto callback = [](Offset offset) {};
1098     longPressRecognizer->callback_ = callback;
1099     longPressRecognizer->HandleTouchUpEvent(touchEvent);
1100     EXPECT_EQ(longPressRecognizer->refereeState_, RefereeState::SUCCEED);
1101 }
1102 
1103 /**
1104  * @tc.name: LongPressRecognizerThumbnailTimerTest002
1105  * @tc.desc: Test ThumbnailTimer in LongPressRecognizer
1106  */
1107 HWTEST_F(LongPressRecognizerTestNg, LongPressRecognizerThumbnailTimerTest002, TestSize.Level1)
1108 {
1109     /**
1110      * @tc.steps: step1. create LongPressRecognizer.
1111      */
1112     RefPtr<LongPressRecognizer> longPressRecognizer =AceType::MakeRefPtr<LongPressRecognizer>(LONG_PRESS_DURATION,
1113         FINGER_NUMBER, false);
1114 
1115     /**
1116      * @tc.steps: step2. set callback function.
1117      */
__anon9a2f6d571302(Offset offset) 1118     auto callback = [](Offset offset) {};
1119     longPressRecognizer->callback_ = callback;
1120     longPressRecognizer->ThumbnailTimer(0);
1121     EXPECT_EQ(longPressRecognizer->refereeState_, RefereeState::READY);
1122 }
1123 
1124 /**
1125  * @tc.name: LongPressRecognizerTestGetLongPressActionFunc008
1126  * @tc.desc: Test LongPressRecognizer function: GetLongPressActionFunc
1127  * @tc.type: FUNC
1128  */
1129 HWTEST_F(LongPressRecognizerTestNg, LongPressRecognizerTestGetLongPressActionFunc008, TestSize.Level1)
1130 {
1131     /**
1132      * @tc.steps: step1. create LongPressRecognizer.
1133      */
1134     RefPtr<LongPressRecognizer> longPressRecognizer =AceType::MakeRefPtr<LongPressRecognizer>(LONG_PRESS_DURATION,
1135         FINGER_NUMBER, false);
1136     bool isCatchMode = false;
1137     longPressRecognizer->refereeState_ = RefereeState::SUCCEED;
1138     longPressRecognizer->HandleOverdueDeadline(isCatchMode);
1139     longPressRecognizer->DoRepeat();
1140     GestureEventFunc click;
1141     GestureEvent info;
1142 
1143     /**
1144      * @tc.steps: step2. call GetLongPressActionFunc function and compare result.
1145      * @tc.steps: case1: normal case
1146      * @tc.expected: step2. result equals.
1147      */
1148     click = longPressRecognizer->GetLongPressActionFunc();
1149     click(info);
1150     EXPECT_EQ(longPressRecognizer->refereeState_, RefereeState::SUCCEED);
1151 
__anon9a2f6d571402(GestureEvent& info) 1152     auto onActionStart = [](GestureEvent& info) { return true; };
__anon9a2f6d571502(GestureEvent& info) 1153     auto onActionUpdate = [](GestureEvent& info) { return true; };
__anon9a2f6d571602(GestureEvent& info) 1154     auto onActionEnd = [](GestureEvent& info) { return true; };
1155     longPressRecognizer->SetOnActionUpdate(onActionUpdate);
1156     longPressRecognizer->SetOnAction(onActionStart);
1157     longPressRecognizer->SetOnActionEnd(onActionEnd);
1158     click = longPressRecognizer->GetLongPressActionFunc();
1159     click(info);
1160     EXPECT_EQ(longPressRecognizer->refereeState_, RefereeState::SUCCEED);
1161 }
1162 
1163 /**
1164  * @tc.name: LongPressRecognizerTestGetLongPressActionFunc009
1165  * @tc.desc: Test LongPressRecognizer function: GetLongPressActionFunc
1166  * @tc.type: FUNC
1167  */
1168 HWTEST_F(LongPressRecognizerTestNg, LongPressRecognizerTestGetLongPressActionFunc009, TestSize.Level1)
1169 {
1170     /**
1171      * @tc.steps: step1. create LongPressRecognizer.
1172      */
1173     RefPtr<LongPressRecognizer> longPressRecognizer =AceType::MakeRefPtr<LongPressRecognizer>(LONG_PRESS_DURATION,
1174         FINGER_NUMBER, false);
1175     GestureEventFunc click;
1176     GestureEvent info;
1177 
1178     /**
1179      * @tc.steps: step2. call GetLongPressActionFunc function and compare result.
1180      * @tc.steps: case1: normal case
1181      * @tc.expected: step2. result equals.
1182      */
1183     click = longPressRecognizer->GetLongPressActionFunc();
1184     click(info);
1185     EXPECT_EQ(longPressRecognizer->refereeState_, RefereeState::READY);
1186 
__anon9a2f6d571702(GestureEvent& info) 1187     auto onActionStart = [](GestureEvent& info) { return true; };
__anon9a2f6d571802(GestureEvent& info) 1188     auto onActionUpdate = [](GestureEvent& info) { return true; };
__anon9a2f6d571902(GestureEvent& info) 1189     auto onActionEnd = [](GestureEvent& info) { return true; };
1190     longPressRecognizer->SetOnActionUpdate(onActionUpdate);
1191     longPressRecognizer->SetOnAction(onActionStart);
1192     longPressRecognizer->SetOnActionEnd(onActionEnd);
1193     click = longPressRecognizer->GetLongPressActionFunc();
1194     click(info);
1195     EXPECT_EQ(longPressRecognizer->refereeState_, RefereeState::READY);
1196 }
1197 
1198 /**
1199  * @tc.name: LongPressRecognizerHandleTouchUpEventTest002
1200  * @tc.desc: Test HandleTouchUpEvent in LongPressRecognizer
1201  */
1202 HWTEST_F(LongPressRecognizerTestNg, LongPressRecognizerHandleTouchUpEventTest002, TestSize.Level1)
1203 {
1204     /**
1205      * @tc.steps: step1. create LongPressRecognizer.
1206      */
1207     RefPtr<LongPressRecognizer> longPressRecognizer =AceType::MakeRefPtr<LongPressRecognizer>(LONG_PRESS_DURATION,
1208         FINGER_NUMBER, false);
1209     TouchEvent touchEvent;
1210 
1211     /**
1212      * @tc.steps: step2. set callback function.
1213      */
1214     longPressRecognizer->refereeState_ = RefereeState::SUCCEED;
1215     longPressRecognizer->currentFingers_ = longPressRecognizer->fingers_ + 1;
__anon9a2f6d571a02(Offset offset) 1216     auto callback = [](Offset offset) {};
1217     longPressRecognizer->callback_ = callback;
1218     longPressRecognizer->HandleTouchUpEvent(touchEvent);
1219     EXPECT_EQ(longPressRecognizer->refereeState_, RefereeState::SUCCEED);
1220 }
1221 
1222 /**
1223  * @tc.name: GestureAccessibilityEventTest002
1224  * @tc.desc: Test SetOnAccessibility in LongPressRecognizer
1225  */
1226 HWTEST_F(LongPressRecognizerTestNg, GestureAccessibilityEventTest002, TestSize.Level1)
1227 {
1228     /**
1229      * @tc.steps: step1. Create longPressRecognizer.
1230      */
1231     RefPtr<LongPressRecognizer> longPressRecognizer =
1232         AceType::MakeRefPtr<LongPressRecognizer>(LONG_PRESS_DURATION, FINGER_NUMBER, false);
1233 
1234     /**
1235      * @tc.steps: step2. set callback function.
1236      */
__anon9a2f6d571b02(AccessibilityEventType eventType) 1237     auto onAccessibilityEvent = [](AccessibilityEventType eventType) {};
1238     longPressRecognizer->SetOnAccessibility(onAccessibilityEvent);
1239     ASSERT_NE(longPressRecognizer->onAccessibilityEventFunc_, nullptr);
1240 
1241     /**
1242      * @tc.steps: step3. call callback function.
1243      * @tc.expected: refereeState_ is SUCCEED.
1244      */
1245     longPressRecognizer->OnAccepted();
1246     EXPECT_EQ(longPressRecognizer->refereeState_, RefereeState::SUCCEED);
1247 }
1248 
1249 /**
1250  * @tc.name: LongPressRecognizerHandleOverdueDeadlineTest002
1251  * @tc.desc: Test LongPressRecognizer function: HandleOverdueDeadline
1252  * @tc.type: FUNC
1253  */
1254 HWTEST_F(LongPressRecognizerTestNg, LongPressRecognizerHandleOverdueDeadlineTest002, TestSize.Level1)
1255 {
1256     /**
1257      * @tc.steps: step1. create Recognizer、TargetComponent.
1258      */
1259     RefPtr<LongPressRecognizer> longPressRecognizerPtr = AceType::MakeRefPtr<LongPressRecognizer>(LONG_PRESS_DURATION,
1260         FINGER_NUMBER, false);
1261     RefPtr<NG::TargetComponent> targetComponent = AceType::MakeRefPtr<TargetComponent>();
__anon9a2f6d571c02(const RefPtr<GestureInfo>& gestureInfo, const std::shared_ptr<BaseGestureEvent>& info) 1262     auto gestureJudgeFunc = [](const RefPtr<GestureInfo>& gestureInfo, const std::shared_ptr<BaseGestureEvent>& info) {
1263         return GestureJudgeResult::REJECT;};
1264     auto frameNode = FrameNode::CreateFrameNode("myButton", 100, AceType::MakeRefPtr<Pattern>());
1265     auto guestureEventHub = frameNode->GetOrCreateGestureEventHub();
1266     PanDirection panDirection;
1267     targetComponent->SetOnGestureJudgeBegin(gestureJudgeFunc);
1268     longPressRecognizerPtr->targetComponent_ = targetComponent;
1269     longPressRecognizerPtr->targetComponent_->node_ = frameNode;
1270     TouchEvent touchEvent;
1271     touchEvent.tiltX.emplace(1.0f);
1272     touchEvent.tiltY.emplace(1.0f);
1273     longPressRecognizerPtr->touchPoints_[touchEvent.id] = touchEvent;
1274     /**
1275      * @tc.steps: step2. call HandleOverdueDeadline function and compare result.
1276      * @tc.steps: case1: gestureInfo_ is nullptr
1277      * @tc.expected: step2. result equals REJECT.
1278      */
1279     longPressRecognizerPtr->refereeState_ = RefereeState::DETECTING;
1280     longPressRecognizerPtr->gestureInfo_ = AceType::MakeRefPtr<GestureInfo>();
1281     longPressRecognizerPtr->HandleOverdueDeadline(true);
1282     EXPECT_EQ(longPressRecognizerPtr->disposal_, GestureDisposal::REJECT);
1283 
1284     /**
1285      * @tc.steps: step2. call HandleOverdueDeadline function and compare result.
1286      * @tc.steps: case2: gestureInfo_ is not nullptr, gestureInfo_->type_ = DRAG
1287      *                   isDragUserReject_ = true
1288      * @tc.expected: step2. result equals REJECT.
1289      */
1290     longPressRecognizerPtr->refereeState_ = RefereeState::DETECTING;
1291     longPressRecognizerPtr->gestureInfo_ = AceType::MakeRefPtr<GestureInfo>();
1292     longPressRecognizerPtr->gestureInfo_->type_ = GestureTypeName::DRAG;
1293     guestureEventHub->dragEventActuator_ = AceType::MakeRefPtr<DragEventActuator>(
1294         AceType::WeakClaim(AceType::RawPtr(guestureEventHub)), panDirection, 1, 50.0f);
1295     guestureEventHub->dragEventActuator_->isDragUserReject_ = true;
1296     longPressRecognizerPtr->HandleOverdueDeadline(true);
1297     EXPECT_EQ(longPressRecognizerPtr->disposal_, GestureDisposal::REJECT);
1298 
1299     /**
1300      * @tc.steps: step2. call HandleOverdueDeadline function and compare result.
1301      * @tc.steps: case3: gestureInfo_ is not nullptr, gestureInfo_->type_ = DRAG
1302      *                   isDragUserReject_ = false
1303      * @tc.expected: step2. isDragUserReject_ = true.
1304      */
1305     longPressRecognizerPtr->refereeState_ = RefereeState::DETECTING;
1306     guestureEventHub->dragEventActuator_->isDragUserReject_ = false;
1307     longPressRecognizerPtr->HandleOverdueDeadline(true);
1308     EXPECT_TRUE(guestureEventHub->dragEventActuator_->isDragUserReject_);
1309 }
1310 
1311 /**
1312  * @tc.name: LongPressRecognizerLongPressRecognizerTest
1313  * @tc.desc: Test LongPressRecognizer function: LongPressRecognizer
1314  * @tc.type: FUNC
1315  */
1316 HWTEST_F(LongPressRecognizerTestNg, LongPressRecognizerLongPressRecognizerTest, TestSize.Level1)
1317 {
1318     /**
1319      * @tc.steps: step1. create Recognizer、TargetComponent.
1320      */
1321     RefPtr<LongPressRecognizer> longPressRecognizer1 =
1322         AceType::MakeRefPtr<LongPressRecognizer>(100, 9, false, false, false);
1323     RefPtr<LongPressRecognizer> longPressRecognizer2 =
1324         AceType::MakeRefPtr<LongPressRecognizer>(100, 11, false, false, false);
1325     RefPtr<LongPressRecognizer> longPressRecognizer3 =
1326         AceType::MakeRefPtr<LongPressRecognizer>(0, 10, false, false, false);
1327     EXPECT_EQ(longPressRecognizer1->fingers_, 9);
1328     EXPECT_EQ(longPressRecognizer2->fingers_, 1);
1329     EXPECT_EQ(longPressRecognizer3->duration_, 500);
1330 }
1331 
1332 /**
1333  * @tc.name: DeadlineTimerTest
1334  * @tc.desc: Test LongPressRecognizer function: DeadlineTimer
1335  * @tc.type: FUNC
1336  */
1337 HWTEST_F(LongPressRecognizerTestNg, DeadlineTimerTest, TestSize.Level1)
1338 {
1339     /**
1340      * @tc.steps: step1. create Recognizer、TargetComponent.
1341      */
1342     RefPtr<LongPressRecognizer> longPressRecognizerPtr = AceType::MakeRefPtr<LongPressRecognizer>(LONG_PRESS_DURATION,
1343         FINGER_NUMBER, false);
1344     longPressRecognizerPtr->DeadlineTimer(1, true);
1345     EXPECT_NE(longPressRecognizerPtr, nullptr);
1346 }
1347 
1348 /**
1349  * @tc.name: SetOnActionCancelTest001
1350  * @tc.desc: Test SendCallbackMsg function in the HandleTouchCancelEvent with touch event input. The onActionCancel
1351  * function will return GestureEvent info.
1352  * @tc.type: FUNC
1353  */
1354 HWTEST_F(LongPressRecognizerTestNg, SetOnActionCancelTest001, TestSize.Level1)
1355 {
1356     /**
1357      * @tc.steps: step1. Create LongPressRecognizer.
1358      */
1359     RefPtr<LongPressRecognizer> longPressRecognizer =
1360         AceType::MakeRefPtr<LongPressRecognizer>(LONG_PRESS_DURATION, FINGER_NUMBER, false);
1361 
1362     /**
1363      * @tc.steps: step2. Call SetOnActionCancel.
1364      * @tc.expected: LongPressRecognizer's callback onActionCancel is not nullptr.
1365      */
1366     longPressRecognizer->deviceId_ = GESTURE_EVENT_PROPERTY_VALUE;
1367     float unknownPropertyValue = GESTURE_EVENT_PROPERTY_DEFAULT_VALUE;
1368     auto onActionCancel = [&unknownPropertyValue](
__anon9a2f6d571d02( GestureEvent& info) 1369                                 GestureEvent& info) { unknownPropertyValue = info.GetDeviceId(); };
1370     longPressRecognizer->SetOnActionCancel(onActionCancel);
1371 
1372     EXPECT_NE(longPressRecognizer->onActionCancel_, nullptr);
1373 
1374     /**
1375      * @tc.steps: step3. Invoke HandleTouchCancelEvent when onActionCancel_ is not null.
1376      * @tc.expected: The functions have been executed and the unknownPropertyValue has been assigned the correct
1377      * value. LongPressRecognizer.refereeState_ = RefereeState::READY
1378      */
1379     TouchEvent touchEvent;
1380     longPressRecognizer->touchPoints_[touchEvent.id] = touchEvent;
1381     longPressRecognizer->refereeState_ = RefereeState::SUCCEED;
1382     longPressRecognizer->HandleTouchCancelEvent(touchEvent);
1383     EXPECT_EQ(unknownPropertyValue, 0);
1384     EXPECT_EQ(longPressRecognizer->refereeState_, RefereeState::READY);
1385 }
1386 
1387 /**
1388  * @tc.name: SetOnActionCancelTest002
1389  * @tc.desc: Test SendCallbackMsg function in the ReconcileFrom. The onActionCancel function will return
1390  * GestureEvent info.
1391  * @tc.type: FUNC
1392  */
1393 HWTEST_F(LongPressRecognizerTestNg, SetOnActionCancelTest002, TestSize.Level1)
1394 {
1395     /**
1396      * @tc.steps: step1. Create LongPressRecognizer.
1397      */
1398     RefPtr<LongPressRecognizer> longPressRecognizer =
1399         AceType::MakeRefPtr<LongPressRecognizer>(LONG_PRESS_DURATION, FINGER_NUMBER, false);
1400     RefPtr<LongPressRecognizer> longPressRecognizerPtr =
1401         AceType::MakeRefPtr<LongPressRecognizer>(LONG_PRESS_DURATION, FINGER_NUMBER, false);
1402 
1403     /**
1404      * @tc.steps: step2. Call SetOnActionCancel.
1405      * @tc.expected: LongPressRecognizer's callback onActionCancel is not nullptr.
1406      */
1407     longPressRecognizer->deviceId_ = GESTURE_EVENT_PROPERTY_VALUE;
1408     float unknownPropertyValue = GESTURE_EVENT_PROPERTY_DEFAULT_VALUE;
1409     auto onActionCancel = [&unknownPropertyValue](
__anon9a2f6d571e02( GestureEvent& info) 1410                                 GestureEvent& info) { unknownPropertyValue = info.GetDeviceId(); };
1411     longPressRecognizer->SetOnActionCancel(onActionCancel);
1412     EXPECT_NE(longPressRecognizer->onActionCancel_, nullptr);
1413 
1414     /**
1415      * @tc.steps: step3. Invoke ReconcileFrom when onActionCancel_ is not null.
1416      * @tc.expected: The functions have been executed and the unknownPropertyValue has been assigned the correct
1417      * value.
1418      */
1419     TouchEvent touchEvent;
1420     longPressRecognizer->touchPoints_[touchEvent.id] = touchEvent;
1421     longPressRecognizer->duration_ = 0;
1422     longPressRecognizer->refereeState_ = RefereeState::SUCCEED;
1423     auto result = longPressRecognizer->ReconcileFrom(longPressRecognizerPtr);
1424     EXPECT_EQ(unknownPropertyValue, 0);
1425     EXPECT_EQ(result, false);
1426 }
1427 
1428 /**
1429  * @tc.name: LongPressGestureLimitFingerTest001
1430  * @tc.desc: Test LongPressGesture CreateRecognizer function
1431  */
1432 HWTEST_F(LongPressRecognizerTestNg, LongPressGestureLimitFingerTest001, TestSize.Level1)
1433 {
1434     /**
1435      * @tc.steps: step1. create LongPressGesture.
1436      */
1437     LongPressGestureModelNG longPressGestureModelNG;
1438     longPressGestureModelNG.Create(FINGER_NUMBER, false, 0, IS_LIMIT_FINGER_COUNT);
1439 
1440     RefPtr<GestureProcessor> gestureProcessor;
1441     gestureProcessor = NG::ViewStackProcessor::GetInstance()->GetOrCreateGestureProcessor();
1442     auto longPressGestureNG = AceType::DynamicCast<NG::LongPressGesture>(gestureProcessor->TopGestureNG());
1443     EXPECT_EQ(longPressGestureNG->isLimitFingerCount_, IS_LIMIT_FINGER_COUNT);
1444 
1445     LongPressGesture longPressGesture = LongPressGesture(
1446         FINGER_NUMBER, false, LONG_PRESS_DURATION, false, false, IS_LIMIT_FINGER_COUNT);
1447     EXPECT_EQ(longPressGesture.repeat_, false);
1448     EXPECT_EQ(longPressGesture.duration_, LONG_PRESS_DURATION);
1449     EXPECT_EQ(longPressGesture.isForDrag_, false);
1450     EXPECT_EQ(longPressGesture.isDisableMouseLeft_, false);
1451     EXPECT_EQ(longPressGesture.isLimitFingerCount_, true);
1452 
1453     /**
1454      * @tc.steps: step2. call CreateRecognizer function and compare result
1455      * @tc.steps: case1: onActionId, onActionEndId, onActionCancelId not existed
1456      */
1457     auto longPressRecognizer = AceType::DynamicCast<LongPressRecognizer>(longPressGesture.CreateRecognizer());
1458     EXPECT_NE(longPressRecognizer, nullptr);
1459     EXPECT_EQ(longPressRecognizer->repeat_, false);
1460     EXPECT_EQ(longPressRecognizer->duration_, LONG_PRESS_DURATION);
1461     EXPECT_EQ(longPressRecognizer->isForDrag_, false);
1462     EXPECT_EQ(longPressRecognizer->isDisableMouseLeft_, false);
1463     EXPECT_EQ(longPressRecognizer->isLimitFingerCount_, true);
1464 
1465     /**
1466      * @tc.steps: step2. call CreateRecognizer function and compare result
1467      * @tc.steps: case2: onActionId, onActionEndId, onActionCancelId existed
1468      */
1469     std::unique_ptr<GestureEventFunc> onActionId;
1470     std::unique_ptr<GestureEventFunc> onActionEndId;
1471     std::unique_ptr<GestureEventFunc> onActionCancelId;
1472     longPressGesture.onActionId_ = std::move(onActionId);
1473     longPressGesture.onActionEndId_ = std::move(onActionEndId);
1474     longPressGesture.onActionCancelId_ = std::move(onActionCancelId);
1475     longPressRecognizer = AceType::DynamicCast<LongPressRecognizer>(longPressGesture.CreateRecognizer());
1476     EXPECT_NE(longPressRecognizer, nullptr);
1477     EXPECT_EQ(longPressRecognizer->isLimitFingerCount_, true);
1478 }
1479 
1480 /**
1481  * @tc.name: LongPressGestureLimitFingerTest002
1482  * @tc.desc: Test LongPressGesture CreateRecognizer function
1483  */
1484 HWTEST_F(LongPressRecognizerTestNg, LongPressGestureLimitFingerTest002, TestSize.Level1)
1485 {
1486     /**
1487      * @tc.steps: step1. create LongPressGesture.
1488      */
1489     LongPressGestureModelNG longPressGestureModelNG;
1490     longPressGestureModelNG.Create(FINGER_NUMBER, false, 0, IS_NOT_LIMIT_FINGER_COUNT);
1491 
1492     RefPtr<GestureProcessor> gestureProcessor;
1493     gestureProcessor = NG::ViewStackProcessor::GetInstance()->GetOrCreateGestureProcessor();
1494     auto longPressGestureNG = AceType::DynamicCast<NG::LongPressGesture>(gestureProcessor->TopGestureNG());
1495     EXPECT_EQ(longPressGestureNG->isLimitFingerCount_, IS_NOT_LIMIT_FINGER_COUNT);
1496 
1497     LongPressGesture longPressGesture = LongPressGesture(
1498         FINGER_NUMBER, false, LONG_PRESS_DURATION, false, false, IS_NOT_LIMIT_FINGER_COUNT);
1499     EXPECT_EQ(longPressGesture.repeat_, false);
1500     EXPECT_EQ(longPressGesture.duration_, LONG_PRESS_DURATION);
1501     EXPECT_EQ(longPressGesture.isForDrag_, false);
1502     EXPECT_EQ(longPressGesture.isDisableMouseLeft_, false);
1503     EXPECT_EQ(longPressGesture.isLimitFingerCount_, false);
1504 
1505     /**
1506      * @tc.steps: step2. call CreateRecognizer function and compare result
1507      * @tc.steps: case1: onActionId, onActionEndId, onActionCancelId not existed
1508      */
1509     auto longPressRecognizer = AceType::DynamicCast<LongPressRecognizer>(longPressGesture.CreateRecognizer());
1510     EXPECT_NE(longPressRecognizer, nullptr);
1511     EXPECT_EQ(longPressRecognizer->repeat_, false);
1512     EXPECT_EQ(longPressRecognizer->duration_, LONG_PRESS_DURATION);
1513     EXPECT_EQ(longPressRecognizer->isForDrag_, false);
1514     EXPECT_EQ(longPressRecognizer->isDisableMouseLeft_, false);
1515     EXPECT_EQ(longPressRecognizer->isLimitFingerCount_, false);
1516 
1517     /**
1518      * @tc.steps: step2. call CreateRecognizer function and compare result
1519      * @tc.steps: case2: onActionId, onActionEndId, onActionCancelId existed
1520      */
1521     std::unique_ptr<GestureEventFunc> onActionId;
1522     std::unique_ptr<GestureEventFunc> onActionEndId;
1523     std::unique_ptr<GestureEventFunc> onActionCancelId;
1524     longPressGesture.onActionId_ = std::move(onActionId);
1525     longPressGesture.onActionEndId_ = std::move(onActionEndId);
1526     longPressGesture.onActionCancelId_ = std::move(onActionCancelId);
1527     longPressRecognizer = AceType::DynamicCast<LongPressRecognizer>(longPressGesture.CreateRecognizer());
1528     EXPECT_NE(longPressRecognizer, nullptr);
1529     EXPECT_EQ(longPressRecognizer->isLimitFingerCount_, false);
1530 }
1531 
1532 /**
1533  * @tc.name: HandleTouchDownEvent001
1534  * @tc.desc: Test LongPressRecognizer function: HandleTouchDownEvent
1535  * @tc.type: FUNC
1536  */
1537 HWTEST_F(LongPressRecognizerTestNg, HandleTouchDownEvent001, TestSize.Level1)
1538 {
1539     /**
1540      * @tc.steps: step1. create LongPressRecognizer.
1541      */
1542     RefPtr<LongPressRecognizer> longPressRecognizer =
1543         AceType::MakeRefPtr<LongPressRecognizer>(LONG_PRESS_DURATION, FINGER_NUMBER, false);
1544     TouchEvent touchEvent;
1545 
1546     /**
1547      * @tc.steps: step2. call HandleTouchDownEvent function and compare result.
1548      * @tc.steps: case1: eventTimeStamp is greater than currentTimeStamp.
1549      * @tc.expected: step2. result equals.
1550      */
1551     auto eventTimeStamp = GetSysTimestamp() + DEFAULT_MOVE_TIME;
1552     touchEvent.time = TimeStamp(std::chrono::nanoseconds(eventTimeStamp));
1553     longPressRecognizer->HandleTouchDownEvent(touchEvent);
1554     EXPECT_EQ(longPressRecognizer->refereeState_, RefereeState::READY);
1555 
1556     /**
1557      * @tc.steps: step2. call HandleTouchDownEvent function and compare result.
1558      * @tc.steps: case2: isPostEventResult_ is true.
1559      * @tc.expected: step2. result equals.
1560      */
1561     longPressRecognizer->SetIsPostEventResult(true);
1562     longPressRecognizer->HandleTouchDownEvent(touchEvent);
1563     EXPECT_EQ(longPressRecognizer->refereeState_, RefereeState::READY);
1564 
1565     /**
1566      * @tc.steps: step2. call HandleTouchDownEvent function and compare result.
1567      * @tc.steps: case3: useCatchMode_ is false.
1568      * @tc.expected: step2. result equals.
1569      */
1570     touchEvent.type = TouchType::DOWN;
1571     longPressRecognizer->touchPoints_[touchEvent.id] = touchEvent;
1572     longPressRecognizer->fingers_ = 1;
1573     longPressRecognizer->useCatchMode_ = false;
1574     longPressRecognizer->HandleTouchDownEvent(touchEvent);
1575     EXPECT_EQ(longPressRecognizer->refereeState_, RefereeState::DETECTING);
1576 
1577     /**
1578      * @tc.steps: step2. call HandleTouchDownEvent function and compare result.
1579      * @tc.steps: case4: forbiddenType is TouchRestrict::LONG_PRESS.
1580      * @tc.expected: step2. result equals.
1581      */
1582     longPressRecognizer->touchRestrict_.forbiddenType = TouchRestrict::LONG_PRESS;
1583     longPressRecognizer->HandleTouchDownEvent(touchEvent);
1584     EXPECT_EQ(longPressRecognizer->disposal_, GestureDisposal::REJECT);
1585 }
1586 
1587 /**
1588  * @tc.name: HandleTouchUpEventTest001
1589  * @tc.desc: Test LongPressRecognizer function: HandleTouchUpEvent
1590  * @tc.type: FUNC
1591  */
1592 HWTEST_F(LongPressRecognizerTestNg, HandleTouchUpEventTest001, TestSize.Level1)
1593 {
1594     /**
1595      * @tc.steps: step1. create LongPressRecognizer.
1596      */
1597     RefPtr<LongPressRecognizer> longPressRecognizer =
1598         AceType::MakeRefPtr<LongPressRecognizer>(LONG_PRESS_DURATION, FINGER_NUMBER, false);
1599 
1600     /**
1601      * @tc.steps: step2. call HandleTouchUpEvent function and compare result.
1602      * @tc.steps: case1: refereeState_ is not SUCCEED.
1603      * @tc.expected: step2. result equals.
1604      */
1605     TouchEvent touchEvent;
1606     longPressRecognizer->fingersId_.insert(0);
1607     longPressRecognizer->touchPoints_[touchEvent.id] = touchEvent;
1608     longPressRecognizer->HandleTouchUpEvent(touchEvent);
1609     EXPECT_EQ(longPressRecognizer->fingersId_.size(), 0);
1610     EXPECT_EQ(longPressRecognizer->touchPoints_.size(), 0);
1611 
1612     /**
1613      * @tc.steps: step2. call HandleTouchUpEvent function and compare result.
1614      * @tc.steps: case2: refereeState_ is SUCCEED.
1615      * @tc.expected: step2. result equals.
1616      */
1617     TimeStamp timeStape = std::chrono::high_resolution_clock::now();
1618     longPressRecognizer->firstInputTime_ = timeStape;
1619     longPressRecognizer->refereeState_ = RefereeState::SUCCEED;
1620     longPressRecognizer->isLimitFingerCount_ = true;
1621     longPressRecognizer->HandleTouchUpEvent(touchEvent);
1622     EXPECT_EQ(longPressRecognizer->touchPoints_.size(), 0);
1623     EXPECT_FALSE(longPressRecognizer->hasRepeated_);
1624 
1625     /**
1626      * @tc.steps: step2. call HandleTouchUpEvent function and compare result.
1627      * @tc.steps: case3: fingers_ is 1.
1628      * @tc.expected: step2. result equals.
1629      */
1630     longPressRecognizer->fingers_ = 1;
1631     longPressRecognizer->touchPoints_[1] = touchEvent;
1632     longPressRecognizer->HandleTouchUpEvent(touchEvent);
1633     EXPECT_EQ(longPressRecognizer->touchPoints_.size(), 1);
1634 }
1635 
1636 /**
1637  * @tc.name: HandleTouchMoveEventTest001
1638  * @tc.desc: Test LongPressRecognizer function: HandleTouchMoveEvent
1639  * @tc.type: FUNC
1640  */
1641 HWTEST_F(LongPressRecognizerTestNg, HandleTouchMoveEventTest001, TestSize.Level1)
1642 {
1643     /**
1644      * @tc.steps: step1. create LongPressRecognizer.
1645      */
1646     RefPtr<LongPressRecognizer> longPressRecognizer =
1647         AceType::MakeRefPtr<LongPressRecognizer>(LONG_PRESS_DURATION, FINGER_NUMBER, false);
1648 
1649     /**
1650      * @tc.steps: step2. call HandleTouchMoveEvent function and compare result.
1651      * @tc.steps: case1: referee is not SUCCEED.
1652      * @tc.expected: step2. result equals.
1653      */
1654     TouchEvent touchEvent;
1655     TouchEvent event;
1656     touchEvent.x = 100.0f;;
1657     touchEvent.y = 100.0f;;
1658     longPressRecognizer->touchPoints_[event.id] = event;
1659     longPressRecognizer->fingers_ = 0;
1660     longPressRecognizer->refereeState_ = RefereeState::SUCCEED;
1661     longPressRecognizer->HandleTouchMoveEvent(touchEvent);
1662     EXPECT_EQ(longPressRecognizer->disposal_, GestureDisposal::NONE);
1663 
1664     /**
1665      * @tc.steps: step2. call HandleTouchMoveEvent function and compare result.
1666      * @tc.steps: case2: referee is READY.
1667      * @tc.expected: step2. result equals.
1668      */
1669     longPressRecognizer->refereeState_ = RefereeState::READY;
1670     longPressRecognizer->HandleTouchMoveEvent(touchEvent);
1671     EXPECT_EQ(longPressRecognizer->disposal_, GestureDisposal::REJECT);
1672 }
1673 
1674 /**
1675  * @tc.name: HandleTouchCancelEventTest001
1676  * @tc.desc: Test LongPressRecognizer function: HandleTouchCancelEvent
1677  * @tc.type: FUNC
1678  */
1679 HWTEST_F(LongPressRecognizerTestNg, HandleTouchCancelEventTest001, TestSize.Level1)
1680 {
1681     /**
1682      * @tc.steps: step1. create LongPressRecognizer.
1683      */
1684     RefPtr<LongPressRecognizer> longPressRecognizer =
1685         AceType::MakeRefPtr<LongPressRecognizer>(LONG_PRESS_DURATION, FINGER_NUMBER, false);
1686 
1687     /**
1688      * @tc.steps: step2. call HandleTouchCancelEvent function and compare result.
1689      * @tc.steps: case1: referee is FAIL.
1690      * @tc.expected: step2. result equals.
1691      */
1692     TouchEvent touchEvent;
1693     TouchEvent event;
1694     event.id = 1;
1695     longPressRecognizer->touchPoints_[event.id] = event;
1696     longPressRecognizer->refereeState_ = RefereeState::FAIL;
1697     longPressRecognizer->HandleTouchCancelEvent(touchEvent);
1698     EXPECT_EQ(longPressRecognizer->extraInfo_, "");
1699     EXPECT_EQ(longPressRecognizer->disposal_, GestureDisposal::NONE);
1700 
1701     /**
1702      * @tc.steps: step2. call HandleTouchCancelEvent function and compare result.
1703      * @tc.steps: case2: referee is SUCCEED.
1704      * @tc.expected: step2. result equals.
1705      */
1706     longPressRecognizer->refereeState_ = RefereeState::SUCCEED;
1707     longPressRecognizer->HandleTouchCancelEvent(touchEvent);
1708     EXPECT_EQ(longPressRecognizer->extraInfo_, TEST_EXTRA_INFO);
1709     EXPECT_EQ(longPressRecognizer->disposal_, GestureDisposal::REJECT);
1710 }
1711 
1712 /**
1713  * @tc.name: DoRepeatTest001
1714  * @tc.desc: Test LongPressRecognizer function: DoRepeat
1715  * @tc.type: FUNC
1716  */
1717 HWTEST_F(LongPressRecognizerTestNg, DoRepeatTest001, TestSize.Level1)
1718 {
1719     /**
1720      * @tc.steps: step1. create LongPressRecognizer.
1721      */
1722     RefPtr<LongPressRecognizer> longPressRecognizer =
1723         AceType::MakeRefPtr<LongPressRecognizer>(LONG_PRESS_DURATION, FINGER_NUMBER, false);
1724 
1725     /**
1726      * @tc.steps: step2. call DoRepeat function and compare result.
1727      * @tc.steps: case1: isLimitFingerCount_ is false.
1728      * @tc.expected: step2. result equals.
1729      */
1730     TouchEvent touchEvent;
1731     longPressRecognizer->touchPoints_[touchEvent.id] = touchEvent;
1732     longPressRecognizer->fingers_ = 0;
1733     longPressRecognizer->DoRepeat();
1734     longPressRecognizer->HandleTouchCancelEvent(touchEvent);
1735     EXPECT_EQ(longPressRecognizer->touchPoints_.size(), 0);
1736 
1737     /**
1738      * @tc.steps: step2. call DoRepeat function and compare result.
1739      * @tc.steps: case2: isLimitFingerCount_ is true.
1740      * @tc.expected: step2. result equals.
1741      */
1742     longPressRecognizer->isLimitFingerCount_ = true;
1743     longPressRecognizer->touchPoints_[touchEvent.id] = touchEvent;
1744     longPressRecognizer->DoRepeat();
1745     longPressRecognizer->HandleTouchCancelEvent(touchEvent);
1746     EXPECT_EQ(longPressRecognizer->touchPoints_.size(), 1);
1747 }
1748 
1749 /**
1750  * @tc.name: SendCallbackMsgTest001
1751  * @tc.desc: Test LongPressRecognizer function: SendCallbackMsg
1752  * @tc.type: FUNC
1753  */
1754 HWTEST_F(LongPressRecognizerTestNg, SendCallbackMsgTest001, TestSize.Level1)
1755 {
1756     /**
1757      * @tc.steps: step1. create LongPressRecognizer.
1758      */
1759     RefPtr<LongPressRecognizer> longPressRecognizer =
1760         AceType::MakeRefPtr<LongPressRecognizer>(LONG_PRESS_DURATION, FINGER_NUMBER, false);
1761 
1762     /**
1763      * @tc.steps: step2. call SendCallbackMsg function and compare result.
1764      * @tc.steps: case1: longPressRecorder is yes, *longPressRecorder is no.
1765      * @tc.expected: step2. result equals.
1766      */
1767     bool isRepeat = false;
1768     TouchEvent touchEvent;
__anon9a2f6d571f02(GestureEvent) 1769     std::unique_ptr<GestureEventFunc> onAction = std::make_unique<GestureEventFunc>([](GestureEvent) {});
1770     std::unique_ptr<GestureEventFunc> longPressRecorder = std::make_unique<GestureEventFunc>();;
1771     touchEvent.rollAngle = 0;
1772     longPressRecognizer->lastTouchEvent_ = touchEvent;
1773     longPressRecognizer->longPressRecorder_ = std::move(longPressRecorder);
1774     longPressRecognizer->SendCallbackMsg(onAction, isRepeat, GestureCallbackType::START);
1775     EXPECT_EQ(longPressRecognizer->touchPoints_.size(), 0);
1776 
1777     /**
1778      * @tc.steps: step2. call SendCallbackMsg function and compare result.
1779      * @tc.steps: case2: longPressRecorder is yes, *longPressRecorder is yes.
1780      * @tc.expected: step2. result equals.
1781      */
__anon9a2f6d572002(GestureEvent) 1782     longPressRecognizer->longPressRecorder_ = std::make_unique<GestureEventFunc>([](GestureEvent) {});
1783     longPressRecognizer->SendCallbackMsg(onAction, isRepeat, GestureCallbackType::START);
1784     EXPECT_EQ(longPressRecognizer->touchPoints_.size(), 0);
1785 
1786     /**
1787      * @tc.steps: step2. call SendCallbackMsg function and compare result.
1788      * @tc.steps: case3: gestureInfo_ is not nullptr.
1789      * @tc.expected: step2. result equals.
1790      */
1791     longPressRecognizer->gestureInfo_ = AceType::MakeRefPtr<GestureInfo>();
1792     longPressRecognizer->SendCallbackMsg(onAction, isRepeat, GestureCallbackType::START);
1793     EXPECT_EQ(longPressRecognizer->touchPoints_.size(), 0);
1794 
1795     /**
1796      * @tc.steps: step2. call SendCallbackMsg function and compare result.
1797      * @tc.steps: case4: gestureInfo_ is not nullptr, gestureInfo_->disposeTag_ is true.
1798      * @tc.expected: step2. result equals.
1799      */
1800     longPressRecognizer->gestureInfo_->SetDisposeTag(true);
1801     longPressRecognizer->SendCallbackMsg(onAction, isRepeat, GestureCallbackType::START);
1802     EXPECT_EQ(longPressRecognizer->touchPoints_.size(), 0);
1803 }
1804 
1805 /**
1806  * @tc.name: TriggerGestureJudgeCallbackTest001
1807  * @tc.desc: Test LongPressRecognizer function: TriggerGestureJudgeCallback
1808  * @tc.type: FUNC
1809  */
1810 HWTEST_F(LongPressRecognizerTestNg, TriggerGestureJudgeCallbackTest001, TestSize.Level1)
1811 {
1812     /**
1813      * @tc.steps: step1. create LongPressRecognizer.
1814      */
1815     RefPtr<LongPressRecognizer> longPressRecognizer =
1816         AceType::MakeRefPtr<LongPressRecognizer>(LONG_PRESS_DURATION, FINGER_NUMBER, false);
1817     RefPtr<NG::TargetComponent> targetComponent = AceType::MakeRefPtr<TargetComponent>();
__anon9a2f6d572102(const RefPtr<GestureInfo>& gestureInfo, const std::shared_ptr<BaseGestureEvent>& info) 1818     auto gestureJudgeFunc = [](const RefPtr<GestureInfo>& gestureInfo, const std::shared_ptr<BaseGestureEvent>& info) {
1819         return GestureJudgeResult::REJECT;
1820     };
1821     auto func = [](const std::shared_ptr<BaseGestureEvent>& info, const RefPtr<NGGestureRecognizer>& current,
__anon9a2f6d572202(const std::shared_ptr<BaseGestureEvent>& info, const RefPtr<NGGestureRecognizer>& current, const std::list<RefPtr<NGGestureRecognizer>>& others) 1822                     const std::list<RefPtr<NGGestureRecognizer>>& others) { return GestureJudgeResult::REJECT; };
1823 
1824     /**
1825      * @tc.steps: step2. call TriggerGestureJudgeCallback function and compare result.
1826      * @tc.steps: case1: targetComponent is default.
1827      * @tc.expected: step2. result equals.
1828      */
1829     TouchEvent touchEvent;
1830     touchEvent.rollAngle = 0;
1831     longPressRecognizer->touchPoints_[0] = touchEvent;
1832     longPressRecognizer->targetComponent_ = targetComponent;
1833     GestureJudgeResult result = longPressRecognizer->TriggerGestureJudgeCallback();
1834     EXPECT_EQ(result, GestureJudgeResult::CONTINUE);
1835 
1836     /**
1837      * @tc.steps: step2. call TriggerGestureJudgeCallback function and compare result.
1838      * @tc.steps: case2: gestureRecognizerJudgeFunc is not null.
1839      * @tc.expected: step2. result equals.
1840      */
1841     targetComponent->SetOnGestureRecognizerJudgeBegin(func);
1842     result = longPressRecognizer->TriggerGestureJudgeCallback();
1843     EXPECT_EQ(result, GestureJudgeResult::REJECT);
1844 
1845     /**
1846      * @tc.steps: step2. call TriggerGestureJudgeCallback function and compare result.
1847      * @tc.steps: case3: callback is not null.
1848      * @tc.expected: step2. result equals.
1849      */
1850     targetComponent->SetOnGestureJudgeBegin(gestureJudgeFunc);
1851     result = longPressRecognizer->TriggerGestureJudgeCallback();
1852     EXPECT_EQ(result, GestureJudgeResult::REJECT);
1853 }
1854 
1855 /**
1856  * @tc.name: HandleOverdueDeadlineTest001
1857  * @tc.desc: Test LongPressRecognizer function: HandleOverdueDeadline
1858  * @tc.type: FUNC
1859  */
1860 HWTEST_F(LongPressRecognizerTestNg, HandleOverdueDeadlineTest001, TestSize.Level1)
1861 {
1862     /**
1863      * @tc.steps: step1. create Recognizer、TargetComponent.
1864      */
1865     RefPtr<LongPressRecognizer> longPressRecognizerPtr = AceType::MakeRefPtr<LongPressRecognizer>(LONG_PRESS_DURATION,
1866         FINGER_NUMBER, false);
1867 
1868     /**
1869      * @tc.steps: step2. call HandleOverdueDeadline function and compare result.
1870      * @tc.steps: case: limitFingerCount is true.
1871      * @tc.expected: step2. result equals REJECT.
1872      */
1873     bool isCatchMode = true;
1874     TouchEvent touchEvent;
1875     longPressRecognizerPtr->SetLimitFingerCount(true);
1876     longPressRecognizerPtr->touchPoints_[touchEvent.id] = touchEvent;
1877     longPressRecognizerPtr->refereeState_ = RefereeState::DETECTING;
1878     longPressRecognizerPtr->HandleOverdueDeadline(isCatchMode);
1879     EXPECT_EQ(longPressRecognizerPtr->disposal_, GestureDisposal::REJECT);
1880 }
1881 
1882 /**
1883  * @tc.name: ReconcileFromTest001
1884  * @tc.desc: Test LongPressRecognizer function: ReconcileFrom
1885  * @tc.type: FUNC
1886  */
1887 HWTEST_F(LongPressRecognizerTestNg, ReconcileFromTest001, TestSize.Level1)
1888 {
1889     /**
1890      * @tc.steps: step1. create LongPressRecognizer.
1891      */
1892     RefPtr<LongPressRecognizer> longPressRecognizer =
1893         AceType::MakeRefPtr<LongPressRecognizer>(LONG_PRESS_DURATION, FINGER_NUMBER, false);
1894     RefPtr<LongPressRecognizer> longPressRecognizerPtr =
1895         AceType::MakeRefPtr<LongPressRecognizer>(LONG_PRESS_DURATION, FINGER_NUMBER, false);
1896 
1897     /**
1898      * @tc.steps: step2. call ReconcileFrom function and compare result.
1899      * @tc.steps: case: referee is SUCCEED.
1900      * @tc.expected: step2. result equals.
1901      */
1902     longPressRecognizer->duration_ = 0;
1903     longPressRecognizer->refereeState_ = RefereeState::SUCCEED;
1904     bool result = longPressRecognizer->ReconcileFrom(longPressRecognizerPtr);
1905     EXPECT_FALSE(result);
1906 }
1907 
1908 /**
1909  * @tc.name: ThumbnailTimerTest001
1910  * @tc.desc: Test LongPressRecognizer function: ThumbnailTimer
1911  */
1912 HWTEST_F(LongPressRecognizerTestNg, ThumbnailTimerTest001, TestSize.Level1)
1913 {
1914     /**
1915      * @tc.steps: step1. create LongPressRecognizer.
1916      */
1917     RefPtr<LongPressRecognizer> longPressRecognizer =AceType::MakeRefPtr<LongPressRecognizer>(LONG_PRESS_DURATION,
1918         FINGER_NUMBER, false);
1919 
1920     /**
1921      * @tc.steps: step2. call ThumbnailTimer function and compare result.
1922      * @tc.steps: case1: taskExecutor is not null.
1923      * @tc.expected: step2. result equals.
1924      */
1925     int32_t time = 0;
1926     auto context = PipelineContext::GetCurrentContext();
1927     ASSERT_NE(context, nullptr);
1928     context->taskExecutor_ = AceType::MakeRefPtr<MockTaskExecutor>();
1929     auto taskExecutor = context->GetTaskExecutor();
1930     ASSERT_NE(taskExecutor, nullptr);
__anon9a2f6d572302(Offset offset) 1931     auto callback = [](Offset offset) {};
1932     longPressRecognizer->callback_ = callback;
1933     longPressRecognizer->ThumbnailTimer(time);
1934     EXPECT_EQ(longPressRecognizer->refereeState_, RefereeState::READY);
1935 
1936     /**
1937      * @tc.steps: step2. call ThumbnailTimer function and compare result.
1938      * @tc.steps: case2: referee is DETECTING.
1939      * @tc.expected: step2. result equals.
1940      */
1941     longPressRecognizer->refereeState_ = RefereeState::DETECTING;
1942     longPressRecognizer->ThumbnailTimer(time);
1943     EXPECT_EQ(longPressRecognizer->globalPoint_.GetX(), 0);
1944     EXPECT_EQ(longPressRecognizer->globalPoint_.GetY(), 0);
1945 }
1946 
1947 /**
1948  * @tc.name: StartRepeatTimerTest001
1949  * @tc.desc: Test LongPressRecognizer function: StartRepeatTimer
1950  * @tc.type: FUNC
1951  */
1952 HWTEST_F(LongPressRecognizerTestNg, StartRepeatTimerTest001, TestSize.Level1)
1953 {
1954     /**
1955      * @tc.steps: step1. create LongPressRecognizer.
1956      */
1957     RefPtr<LongPressRecognizer> longPressRecognizer =
1958         AceType::MakeRefPtr<LongPressRecognizer>(LONG_PRESS_DURATION, FINGER_NUMBER, false);
1959 
1960     /**
1961      * @tc.steps: step2. call StartRepeatTimer function and compare result.
1962      * @tc.steps: case: taskExecutor is not null.
1963      * @tc.expected: step2. result equals.
1964      */
1965     auto context = PipelineContext::GetCurrentContext();
1966     ASSERT_NE(context, nullptr);
1967     context->taskExecutor_ = AceType::MakeRefPtr<MockTaskExecutor>();
1968     auto taskExecutor = context->GetTaskExecutor();
1969     ASSERT_NE(taskExecutor, nullptr);
1970     longPressRecognizer->StartRepeatTimer();
1971     EXPECT_EQ(longPressRecognizer->touchPoints_.size(), 0);
1972 }
1973 /**
1974  * @tc.name: GetOnAccessibilityEventFunc001
1975  * @tc.desc: Test LongPressRecognizer function: GetOnAccessibilityEventFunc
1976  * @tc.type: FUNC
1977  */
1978 HWTEST_F(LongPressRecognizerTestNg, GetOnAccessibilityEventFunc001, TestSize.Level1)
1979 {
1980     /**
1981      * @tc.steps: step1. create LongPressRecognizer.
1982      */
1983     RefPtr<LongPressRecognizer> longPressRecognizer =
1984         AceType::MakeRefPtr<LongPressRecognizer>(LONG_PRESS_DURATION, FINGER_NUMBER, false);
1985 
1986     /**
1987      * @tc.steps: step2. check callback function.
1988      * @tc.expected: callback function is not null.
1989      */
1990     ASSERT_NE(longPressRecognizer->onAccessibilityEventFunc_, nullptr);
1991 }
1992 
1993 /**
1994  * @tc.name: LongPressRecognizerBasicInfoTest001
1995  * @tc.desc: Test case basic input info check.
1996  * @tc.type: FUNC
1997  */
1998 HWTEST_F(LongPressRecognizerTestNg, LongPressRecognizerBasicInfoTest001, TestSize.Level1)
1999 {
2000     /**
2001      * @tc.steps: step1. Create basic info testCases.
2002      * @tc.expected: set longPressRecognizer basic info correct.
2003      */
2004     const std::vector<MockLongPressRecognizerCase> mockLongPressRecognizerCases = {
2005         {1, DEFAULT_LONGPRESS_DURATION, DEFAULT_LONGPRESS_DURATION, RefereeState::READY,
2006             1, DEFAULT_LONGPRESS_DURATION, RefereeState::READY, {}},
2007         {1, -1, DEFAULT_LONGPRESS_DURATION, RefereeState::READY,
2008             1, DEFAULT_LONGPRESS_DURATION, RefereeState::READY, {}},
2009         {-1, DEFAULT_LONGPRESS_DURATION, DEFAULT_LONGPRESS_DURATION, RefereeState::READY,
2010             1, DEFAULT_LONGPRESS_DURATION, RefereeState::READY, {}},
2011     };
2012     for (auto i = 0; i < mockLongPressRecognizerCases.size(); i++) {
2013         RefPtr<LongPressRecognizer> longPressRecognizer = AceType::MakeRefPtr<LongPressRecognizer>(
2014             mockLongPressRecognizerCases[i].duration, mockLongPressRecognizerCases[i].fingers);
2015         longPressRecognizer->refereeState_ = mockLongPressRecognizerCases[i].refereeState;
2016         EXPECT_EQ(longPressRecognizer->duration_, mockLongPressRecognizerCases[i].expectedDuration);
2017         EXPECT_EQ(longPressRecognizer->fingers_, mockLongPressRecognizerCases[i].expectedFingers);
2018         EXPECT_EQ(longPressRecognizer->refereeState_, mockLongPressRecognizerCases[i].expectedRefereeState);
2019     }
2020 }
2021 
2022 /**
2023  * @tc.name: LongPressRecognizerInjectEventsTest001
2024  * @tc.desc: Test case inject events.
2025  * @tc.type: FUNC
2026  */
2027 HWTEST_F(LongPressRecognizerTestNg, LongPressRecognizerInjectEventsTest001, TestSize.Level1)
2028 {
2029     /**
2030      * @tc.steps: step1. Create basic info testCases.
2031      * @tc.expected: set clickRecognizer basic info correct.
2032      */
2033     TouchEvent downEvent = TouchEvent();
2034     downEvent.type = TouchType::DOWN;
2035     TouchEvent moveEvent = TouchEvent();
2036     moveEvent.type = TouchType::MOVE;
2037     TouchEvent upEvent = TouchEvent();
2038     upEvent.type = TouchType::UP;
2039 
2040     const std::vector<MockLongPressRecognizerCase> mockLongPressRecognizerCases = {
2041         {1, DEFAULT_LONGPRESS_DURATION, DEFAULT_LONGPRESS_DURATION, RefereeState::READY,
2042             1, DEFAULT_LONGPRESS_DURATION, RefereeState::DETECTING, {downEvent}},
2043         {1, DEFAULT_LONGPRESS_DURATION, DEFAULT_LONGPRESS_DURATION, RefereeState::READY,
2044             1, DEFAULT_LONGPRESS_DURATION, RefereeState::DETECTING, {downEvent, moveEvent}},
2045         {1, -1, DEFAULT_LONGPRESS_DURATION, RefereeState::READY,
2046             1, DEFAULT_LONGPRESS_DURATION, RefereeState::FAIL, {downEvent, moveEvent, upEvent}},
2047         {-1, DEFAULT_LONGPRESS_DURATION, DEFAULT_LONGPRESS_DURATION, RefereeState::READY,
2048             1, DEFAULT_LONGPRESS_DURATION, RefereeState::FAIL, {downEvent, moveEvent, upEvent}},
2049     };
2050     for (auto i = 0; i < mockLongPressRecognizerCases.size(); i++) {
2051         RefPtr<LongPressRecognizer> longPressRecognizer = AceType::MakeRefPtr<LongPressRecognizer>(
2052             mockLongPressRecognizerCases[i].duration, mockLongPressRecognizerCases[i].fingers, true);
2053         longPressRecognizer->refereeState_ = mockLongPressRecognizerCases[i].refereeState;
2054         for (auto j = 0; j < mockLongPressRecognizerCases[i].inputTouchEvents.size(); j++) {
2055             longPressRecognizer->ProcessTouchEvent(mockLongPressRecognizerCases[i].inputTouchEvents[j]);
2056             std::this_thread::sleep_for(std::chrono::milliseconds(mockLongPressRecognizerCases[i].time));
2057         }
2058         EXPECT_EQ(longPressRecognizer->duration_, mockLongPressRecognizerCases[i].expectedDuration);
2059         EXPECT_EQ(longPressRecognizer->fingers_, mockLongPressRecognizerCases[i].expectedFingers);
2060         EXPECT_EQ(longPressRecognizer->refereeState_, mockLongPressRecognizerCases[i].expectedRefereeState);
2061     }
2062 }
2063 
2064 /**
2065  * @tc.name: LongPressRecognizerInjectEventsTest002
2066  * @tc.desc: Test case inject events.
2067  * @tc.type: FUNC
2068  */
2069 HWTEST_F(LongPressRecognizerTestNg, LongPressRecognizerInjectEventsTest002, TestSize.Level1)
2070 {
2071     /**
2072      * @tc.steps: step1. Create basic info testCases.
2073      * @tc.expected: set clickRecognizer basic info correct.
2074      */
2075     TouchEvent downEventFinger0 = TouchEvent();
2076     TouchEvent downEventFinger1 = TouchEvent();
2077     downEventFinger0.type = TouchType::DOWN;
2078     downEventFinger1.type = TouchType::DOWN;
2079     downEventFinger0.id = 0;
2080     downEventFinger1.id = 1;
2081 
2082     TouchEvent moveEventFinger0 = TouchEvent();
2083     TouchEvent moveEventFinger1 = TouchEvent();
2084     moveEventFinger0.type = TouchType::MOVE;
2085     moveEventFinger1.type = TouchType::MOVE;
2086     moveEventFinger0.id = 0;
2087     moveEventFinger1.id = 1;
2088 
2089     TouchEvent upEventFinger0 = TouchEvent();
2090     TouchEvent upEventFinger1 = TouchEvent();
2091     upEventFinger0.type = TouchType::UP;
2092     upEventFinger1.type = TouchType::UP;
2093     upEventFinger0.id = 0;
2094     upEventFinger1.id = 1;
2095 
2096     const std::vector<MockLongPressRecognizerCase> mockLongPressRecognizerCases = {
2097         {2, DEFAULT_LONGPRESS_DURATION, DEFAULT_LONGPRESS_DURATION, RefereeState::READY,
2098             2, DEFAULT_LONGPRESS_DURATION, RefereeState::DETECTING, {downEventFinger0, downEventFinger1}},
2099         {2, DEFAULT_LONGPRESS_DURATION, DEFAULT_LONGPRESS_DURATION, RefereeState::READY, 2, DEFAULT_LONGPRESS_DURATION,
2100             RefereeState::DETECTING, {downEventFinger0, downEventFinger1, moveEventFinger0, moveEventFinger1}},
2101         {2, DEFAULT_LONGPRESS_DURATION, DEFAULT_LONGPRESS_DURATION, RefereeState::READY,
2102             2, DEFAULT_LONGPRESS_DURATION, RefereeState::FAIL,
2103             {downEventFinger0, downEventFinger1, moveEventFinger0, moveEventFinger1, upEventFinger0, upEventFinger1}},
2104         {2, -1, DEFAULT_LONGPRESS_DURATION, RefereeState::READY, 2, DEFAULT_LONGPRESS_DURATION, RefereeState::FAIL,
2105             {downEventFinger0, downEventFinger1, moveEventFinger0, moveEventFinger1, upEventFinger0, upEventFinger1}},
2106         {-1, DEFAULT_LONGPRESS_DURATION, DEFAULT_LONGPRESS_DURATION, RefereeState::READY,
2107             1, DEFAULT_LONGPRESS_DURATION, RefereeState::FAIL,
2108             {downEventFinger0, downEventFinger1, moveEventFinger0, moveEventFinger1, upEventFinger0, upEventFinger1}},
2109     };
2110     for (auto i = 0; i < mockLongPressRecognizerCases.size(); i++) {
2111         RefPtr<LongPressRecognizer> longPressRecognizer = AceType::MakeRefPtr<LongPressRecognizer>(
2112             mockLongPressRecognizerCases[i].duration, mockLongPressRecognizerCases[i].fingers, false);
2113         longPressRecognizer->refereeState_ = mockLongPressRecognizerCases[i].refereeState;
2114         for (auto j = 0; j < mockLongPressRecognizerCases[i].inputTouchEvents.size(); j++) {
2115             longPressRecognizer->ProcessTouchEvent(mockLongPressRecognizerCases[i].inputTouchEvents[j]);
2116             std::this_thread::sleep_for(std::chrono::milliseconds(mockLongPressRecognizerCases[i].time));
2117         }
2118         EXPECT_EQ(longPressRecognizer->duration_, mockLongPressRecognizerCases[i].expectedDuration);
2119         EXPECT_EQ(longPressRecognizer->fingers_, mockLongPressRecognizerCases[i].expectedFingers);
2120         EXPECT_EQ(longPressRecognizer->refereeState_, mockLongPressRecognizerCases[i].expectedRefereeState);
2121     }
2122 }
2123 
2124 /**
2125  * @tc.name: LongPressRecognizerTypeTest001
2126  * @tc.desc: Test LongPressRecognizerType
2127  * @tc.type: FUNC
2128  */
2129 HWTEST_F(LongPressRecognizerTestNg, LongPressRecognizerTypeTest001, TestSize.Level1)
2130 {
2131     RefPtr<LongPressRecognizer> longPressRecognizer =
2132         AceType::MakeRefPtr<LongPressRecognizer>(LONG_PRESS_DURATION, FINGER_NUMBER, false);
2133     auto frameNode = FrameNode::CreateFrameNode("myButton", 100, AceType::MakeRefPtr<Pattern>());
2134     longPressRecognizer->AttachFrameNode(frameNode);
2135     longPressRecognizer->SetRecognizerType(GestureTypeName::LONG_PRESS_GESTURE);
2136 
2137     GestureEvent info;
2138     longPressRecognizer->HandleReports(info, GestureCallbackType::END);
2139     EXPECT_EQ(longPressRecognizer->GetRecognizerType(), GestureTypeName::LONG_PRESS_GESTURE);
2140 }
2141 
2142 /**
2143  * @tc.name: TriggerGestureJudgeCallbackTest002
2144  * @tc.desc: Test TriggerGestureJudgeCallback
2145  * @tc.type: FUNC
2146  */
2147 HWTEST_F(LongPressRecognizerTestNg, TriggerGestureJudgeCallbackTest002, TestSize.Level1)
2148 {
2149     RefPtr<LongPressRecognizer> longPressRecognizer =
2150         AceType::MakeRefPtr<LongPressRecognizer>(LONG_PRESS_DURATION, FINGER_NUMBER, false);
2151     RefPtr<NG::TargetComponent> targetComponent = AceType::MakeRefPtr<TargetComponent>();
2152     longPressRecognizer->inputEventType_ = InputEventType::KEYBOARD;
2153     longPressRecognizer->deviceId_ = 1;
2154     longPressRecognizer->lastAction_ = 1;
2155 
2156     auto func = [](const std::shared_ptr<BaseGestureEvent>& info, const RefPtr<NGGestureRecognizer>& current,
__anon9a2f6d572402(const std::shared_ptr<BaseGestureEvent>& info, const RefPtr<NGGestureRecognizer>& current, const std::list<RefPtr<NGGestureRecognizer>>& others) 2157                     const std::list<RefPtr<NGGestureRecognizer>>& others) {
2158         EXPECT_EQ(info->rawInputEventType_, InputEventType::KEYBOARD);
2159         EXPECT_EQ(info->rawInputDeviceId_, 1);
2160         EXPECT_EQ(info->lastAction_.value_or(0), 1);
2161         return GestureJudgeResult::REJECT;
2162     };
2163     TouchEvent touchEvent;
2164     touchEvent.rollAngle = 0;
2165     longPressRecognizer->touchPoints_[0] = touchEvent;
2166     longPressRecognizer->targetComponent_ = targetComponent;
2167     targetComponent->SetOnGestureRecognizerJudgeBegin(func);
2168     longPressRecognizer->TriggerGestureJudgeCallback();
2169 }
2170 
2171 /**
2172  * @tc.name: TriggerGestureJudgeCallbackTest003
2173  * @tc.desc: Test LongPressRecognizer function: TriggerGestureJudgeCallback
2174  * @tc.type: FUNC
2175  */
2176 HWTEST_F(LongPressRecognizerTestNg, TriggerGestureJudgeCallbackTest003, TestSize.Level1)
2177 {
2178     /**
2179      * @tc.steps: step1. create LongPressRecognizer.
2180      */
2181     RefPtr<LongPressRecognizer> longPressRecognizer =
2182         AceType::MakeRefPtr<LongPressRecognizer>(LONG_PRESS_DURATION, 2, false, false, false, true);
2183     RefPtr<NG::TargetComponent> targetComponent = AceType::MakeRefPtr<TargetComponent>();
__anon9a2f6d572502(const RefPtr<GestureInfo>& gestureInfo, const std::shared_ptr<BaseGestureEvent>& info) 2184     auto gestureJudgeFunc = [](const RefPtr<GestureInfo>& gestureInfo, const std::shared_ptr<BaseGestureEvent>& info) {
2185         return GestureJudgeResult::REJECT;
2186     };
2187     auto func = [](const std::shared_ptr<BaseGestureEvent>& info, const RefPtr<NGGestureRecognizer>& current,
__anon9a2f6d572602(const std::shared_ptr<BaseGestureEvent>& info, const RefPtr<NGGestureRecognizer>& current, const std::list<RefPtr<NGGestureRecognizer>>& others) 2188                     const std::list<RefPtr<NGGestureRecognizer>>& others) { return GestureJudgeResult::REJECT; };
2189 
2190     /**
2191      * @tc.steps: step2. call TriggerGestureJudgeCallback function and compare result.
2192      * @tc.steps: case1: targetComponent is default.
2193      * @tc.expected: step2. result equals.
2194      */
2195 
2196     targetComponent->SetOnGestureRecognizerJudgeBegin(func);
2197     TouchEvent touchEvent;
2198     touchEvent.rollAngle = 0;
2199     longPressRecognizer->touchPoints_[0] = touchEvent;
2200     longPressRecognizer->touchPoints_[1] = touchEvent;
2201     longPressRecognizer->touchPoints_[2] = touchEvent;
2202     longPressRecognizer->targetComponent_ = targetComponent;
2203     targetComponent->SetOnGestureJudgeBegin(gestureJudgeFunc);
2204     longPressRecognizer->HandleOverdueDeadline(true);
2205     EXPECT_EQ(longPressRecognizer->disposal_, GestureDisposal::NONE);
2206 }
2207 } // namespace OHOS::Ace::NG