• 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/unittest/core/gestures/gestures_common_test_ng.h"
16 #include "ui/base/referenced.h"
17 
18 using namespace testing;
19 using namespace testing::ext;
20 
21 namespace OHOS::Ace::NG {
22 constexpr float GESTURE_EVENT_PROPERTY_DEFAULT_VALUE = 0.0;
23 constexpr float GESTURE_EVENT_PROPERTY_VALUE = 10.0;
24 class LongPressRecognizerTestNg : public GesturesCommonTestNg {
25 public:
26     static void SetUpTestSuite();
27     static void TearDownTestSuite();
28 };
29 
SetUpTestSuite()30 void LongPressRecognizerTestNg::SetUpTestSuite()
31 {
32     MockPipelineContext::SetUp();
33 }
34 
TearDownTestSuite()35 void LongPressRecognizerTestNg::TearDownTestSuite()
36 {
37     MockPipelineContext::TearDown();
38 }
39 
40 /**
41  * @tc.name: LongPressRecognizerTest001
42  * @tc.desc: Test LongPressRecognizer function: OnAccepted OnRejected
43  * @tc.type: FUNC
44  */
45 HWTEST_F(LongPressRecognizerTestNg, LongPressRecognizerTest001, TestSize.Level1)
46 {
47     /**
48      * @tc.steps: step1. create LongPressRecognizer.
49      */
50     RefPtr<LongPressRecognizer> longPressRecognizer =
51         AceType::MakeRefPtr<LongPressRecognizer>(LONG_PRESS_DURATION, FINGER_NUMBER, false);
52     OnLongPress onLongPress;
53     TouchEvent touchEvent;
54 
55     /**
56      * @tc.steps: step2. call OnAccepted function and compare result.
57      * @tc.steps: case1: !onLongPress, !empty, repeat
58      * @tc.expected: step2. result equals.
59      */
60     longPressRecognizer->touchPoints_[touchEvent.id] = touchEvent;
61     longPressRecognizer->repeat_ = true;
62     longPressRecognizer->OnAccepted();
63     EXPECT_EQ(longPressRecognizer->refereeState_, RefereeState::SUCCEED);
64 
65     /**
66      * @tc.steps: step2. call OnAccepted function and compare result.
67      * @tc.steps: case2: !onLongPress, empty, !repeat
68      * @tc.expected: step2. result equals.
69      */
70     longPressRecognizer->touchPoints_.clear();
71     longPressRecognizer->repeat_ = false;
72     longPressRecognizer->OnAccepted();
73     EXPECT_EQ(longPressRecognizer->refereeState_, RefereeState::SUCCEED);
74 
75     /**
76      * @tc.steps: step2. call OnAccepted function and compare result.
77      * @tc.steps: case3: onLongPress, empty, !repeat
78      * @tc.expected: step2. result equals.
79      */
80     longPressRecognizer->touchPoints_.clear();
81     longPressRecognizer->repeat_ = false;
82     longPressRecognizer->OnAccepted();
83     EXPECT_EQ(longPressRecognizer->refereeState_, RefereeState::SUCCEED);
84 
85     /**
86      * @tc.steps: step2. call OnAccepted function and compare result.
87      * @tc.steps: case4: onLongPress, !empty, !repeat
88      * @tc.expected: step2. result equals.
89      */
90     longPressRecognizer->touchPoints_.clear();
91     longPressRecognizer->touchPoints_[touchEvent.id] = touchEvent;
92     longPressRecognizer->repeat_ = false;
93     longPressRecognizer->OnAccepted();
94     EXPECT_EQ(longPressRecognizer->refereeState_, RefereeState::SUCCEED);
95 
96     /**
97      * @tc.steps: step3. call OnRejected function and compare result.
98      * @tc.expected: step3. result equals.
99      */
100     longPressRecognizer->OnRejected();
101     EXPECT_EQ(longPressRecognizer->refereeState_, RefereeState::SUCCEED);
102 }
103 
104 /**
105  * @tc.name: LongPressRecognizerTest002
106  * @tc.desc: Test LongPressRecognizer function: HandleTouchMoveEvent
107  * @tc.type: FUNC
108  */
109 HWTEST_F(LongPressRecognizerTestNg, LongPressRecognizerTest002, TestSize.Level1)
110 {
111     /**
112      * @tc.steps: step1. create LongPressRecognizer.
113      */
114     RefPtr<LongPressRecognizer> longPressRecognizer =
115         AceType::MakeRefPtr<LongPressRecognizer>(LONG_PRESS_DURATION, FINGER_NUMBER, false);
116 
117     /**
118      * @tc.steps: step2. call HandleTouchUpEvent function and compare result.
119      * @tc.steps: case1: referee is not SUCCEED
120      * @tc.expected: step2. result equals.
121      */
122     TouchEvent touchEvent;
123     longPressRecognizer->touchPoints_[touchEvent.id] = touchEvent;
124     longPressRecognizer->HandleTouchMoveEvent(touchEvent);
125     EXPECT_EQ(longPressRecognizer->time_, touchEvent.time);
126 
127     /**
128      * @tc.steps: step2. call HandleTouchUpEvent function and compare result.
129      * @tc.steps: case2: referee is SUCCEED
130      * @tc.expected: step2. result equals.
131      */
132     longPressRecognizer->refereeState_ = RefereeState::SUCCEED;
133     longPressRecognizer->HandleTouchMoveEvent(touchEvent);
134     EXPECT_EQ(longPressRecognizer->time_, touchEvent.time);
135 
136     /**
137      * @tc.steps: step2. call HandleTouchUpEvent function and compare result.
138      * @tc.steps: case2: referee is SUCCEED
139      * @tc.expected: step2. result equals.
140      */
141     longPressRecognizer->currentFingers_ = longPressRecognizer->fingers_;
142     longPressRecognizer->refereeState_ = RefereeState::SUCCEED;
143     longPressRecognizer->HandleTouchMoveEvent(touchEvent);
144     EXPECT_EQ(longPressRecognizer->time_, touchEvent.time);
145 }
146 
147 /**
148  * @tc.name: LongPressRecognizerTest003
149  * @tc.desc: Test LongPressRecognizer function: HandleTouchDownEvent
150  * @tc.type: FUNC
151  */
152 HWTEST_F(LongPressRecognizerTestNg, LongPressRecognizerTest003, TestSize.Level1)
153 {
154     /**
155      * @tc.steps: step1. create LongPressRecognizer.
156      */
157     RefPtr<LongPressRecognizer> longPressRecognizer =
158         AceType::MakeRefPtr<LongPressRecognizer>(LONG_PRESS_DURATION, FINGER_NUMBER, false);
159 
160     /**
161      * @tc.steps: step2. call HandleTouchUpEvent function and compare result.
162      * @tc.steps: case1: pointsCount == fingers, useCatchMode_ is true
163      * @tc.expected: step2. result equals.
164      */
165     TouchEvent touchEvent;
166     longPressRecognizer->HandleTouchDownEvent(touchEvent);
167     EXPECT_EQ(longPressRecognizer->touchPoints_.size(), 1);
168 
169     /**
170      * @tc.steps: step2. call HandleTouchUpEvent function and compare result.
171      * @tc.steps: case2: pointsCount == fingers, useCatchMode_ is true
172      * @tc.expected: step2. result equals.
173      */
174     touchEvent.sourceType = SourceType::MOUSE;
175     longPressRecognizer->isForDrag_ = true;
176     longPressRecognizer->touchPoints_[touchEvent.id] = touchEvent;
177     longPressRecognizer->fingers_ = 1;
178     longPressRecognizer->useCatchMode_ = true;
179     longPressRecognizer->HandleTouchDownEvent(touchEvent);
180     EXPECT_EQ(longPressRecognizer->globalPoint_.GetX(), touchEvent.x);
181     EXPECT_EQ(longPressRecognizer->globalPoint_.GetY(), touchEvent.y);
182     EXPECT_EQ(longPressRecognizer->refereeState_, RefereeState::READY);
183 
184     /**
185      * @tc.steps: step2. call HandleTouchUpEvent function and compare result.
186      * @tc.steps: case3: pointsCount == fingers, useCatchMode_ is false
187      * @tc.expected: step2. result equals.
188      */
189     longPressRecognizer->useCatchMode_ = false;
190     longPressRecognizer->HandleTouchDownEvent(touchEvent);
191     EXPECT_EQ(longPressRecognizer->refereeState_, RefereeState::READY);
192 
193     /**
194      * @tc.steps: step2. call HandleTouchUpEvent function and compare result.
195      * @tc.steps: case4: referee is SUCCEED
196      * @tc.expected: step2. result equals.
197      */
198     longPressRecognizer->refereeState_ = RefereeState::SUCCEED;
199     longPressRecognizer->HandleTouchDownEvent(touchEvent);
200     EXPECT_EQ(longPressRecognizer->touchPoints_.size(), 1);
201 
202     /**
203      * @tc.steps: step2. call HandleTouchUpEvent function and compare result.
204      * @tc.steps: case5: change SourceType to KEYBOARD
205      * @tc.expected: step2. result equals.
206      */
207     longPressRecognizer->refereeState_ = RefereeState::PENDING;
208     touchEvent.sourceType = SourceType::KEYBOARD;
209     longPressRecognizer->HandleTouchDownEvent(touchEvent);
210     EXPECT_EQ(longPressRecognizer->touchPoints_.size(), 1);
211 
212     /**
213      * @tc.steps: step2. call HandleTouchUpEvent function and compare result.
214      * @tc.steps: case6: change isForDrag
215      * @tc.expected: step2. result equals.
216      */
217     longPressRecognizer->isForDrag_ = !longPressRecognizer->isForDrag_;
218     longPressRecognizer->HandleTouchDownEvent(touchEvent);
219     EXPECT_EQ(longPressRecognizer->touchPoints_.size(), 1);
220 
221     /**
222      * @tc.steps: step2. call HandleTouchUpEvent function and compare result.
223      * @tc.steps: case7: change isDisableMouseLeft_
224      * @tc.expected: step2. result equals.
225      */
226     longPressRecognizer->isDisableMouseLeft_ = !longPressRecognizer->isDisableMouseLeft_;
227     longPressRecognizer->HandleTouchDownEvent(touchEvent);
228     EXPECT_EQ(longPressRecognizer->touchPoints_.size(), 1);
229 }
230 
231 /**
232  * @tc.name: LongPressRecognizerTest004
233  * @tc.desc: Test LongPressRecognizer function: HandleTouchCancelEvent UpEvent
234  * @tc.type: FUNC
235  */
236 HWTEST_F(LongPressRecognizerTestNg, LongPressRecognizerTest004, TestSize.Level1)
237 {
238     /**
239      * @tc.steps: step1. create LongPressRecognizer.
240      */
241     RefPtr<LongPressRecognizer> longPressRecognizer =
242         AceType::MakeRefPtr<LongPressRecognizer>(LONG_PRESS_DURATION, FINGER_NUMBER, false);
243 
244     /**
245      * @tc.steps: step2. call HandleTouchUpEvent function and compare result.
246      * @tc.steps: refereeState == RefereeState::SUCCEED
247      * @tc.expected: step2. result equals.
248      */
249     TouchEvent touchEvent;
250     longPressRecognizer->refereeState_ = RefereeState::SUCCEED;
251     longPressRecognizer->HandleTouchUpEvent(touchEvent);
252     longPressRecognizer->HandleTouchCancelEvent(touchEvent);
253     EXPECT_EQ(longPressRecognizer->touchPoints_.size(), 0);
254 
255     /**
256      * @tc.steps: step2. call HandleTouchUpEvent function and compare result.
257      * @tc.steps: refereeState == RefereeState::SUCCEED
258      * @tc.expected: step2. result equals.
259      */
260     longPressRecognizer->refereeState_ = RefereeState::SUCCEED;
261     longPressRecognizer->currentFingers_ = longPressRecognizer->fingers_;
262     longPressRecognizer->HandleTouchUpEvent(touchEvent);
263     longPressRecognizer->HandleTouchCancelEvent(touchEvent);
264     EXPECT_EQ(longPressRecognizer->touchPoints_.size(), 0);
265 }
266 
267 /**
268  * @tc.name: LongPressRecognizerDoRepeatTest001
269  * @tc.desc: Test LongPressRecognizer function: DoRepeat
270  * @tc.type: FUNC
271  */
272 HWTEST_F(LongPressRecognizerTestNg, LongPressRecognizerDoRepeatTest001, TestSize.Level1)
273 {
274     /**
275      * @tc.steps: step1. create LongPressRecognizer.
276      */
277     RefPtr<LongPressRecognizer> longPressRecognizer =
278         AceType::MakeRefPtr<LongPressRecognizer>(LONG_PRESS_DURATION, FINGER_NUMBER, false);
279 
280     /**
281      * @tc.steps: step2. call DoRepeat
282      * @tc.steps: refereeState == RefereeState::SUCCEED
283      * @tc.expected: step2. result equals.
284      */
285     TouchEvent touchEvent;
286     longPressRecognizer->refereeState_ = RefereeState::SUCCEED;
287     longPressRecognizer->fingers_ = 0;
288     longPressRecognizer->DoRepeat();
289     longPressRecognizer->HandleTouchCancelEvent(touchEvent);
290     EXPECT_EQ(longPressRecognizer->touchPoints_.size(), 0);
291 
292     /**
293      * @tc.steps: step2. call DoRepeat
294      * @tc.steps: refereeState == RefereeState::SUCCEED
295      * @tc.expected: step2. result equals.
296      */
297     longPressRecognizer->refereeState_ = RefereeState::DETECTING;
298     longPressRecognizer->currentFingers_ = longPressRecognizer->fingers_;
299     longPressRecognizer->fingers_ = 0;
300     longPressRecognizer->DoRepeat();
301     EXPECT_EQ(longPressRecognizer->touchPoints_.size(), 0);
302 }
303 
304 /**
305  * @tc.name: LongPressRecognizerTest005
306  * @tc.desc: Test LongPressRecognizer function: SendCallbackMsg
307  * @tc.type: FUNC
308  */
309 HWTEST_F(LongPressRecognizerTestNg, LongPressRecognizerTest005, TestSize.Level1)
310 {
311     /**
312      * @tc.steps: step1. create LongPressRecognizer.
313      */
314     RefPtr<LongPressRecognizer> longPressRecognizer =
315         AceType::MakeRefPtr<LongPressRecognizer>(LONG_PRESS_DURATION, FINGER_NUMBER, false);
316     bool isRepeat = false;
317 
318     /**
319      * @tc.steps: step2. call SendCallbackMsg function and compare result.
320      * @tc.steps: case1: onAction is no, *onAction is no
321      * @tc.expected: step2. result equals.
322      */
323     std::unique_ptr<GestureEventFunc> onAction;
324     longPressRecognizer->SendCallbackMsg(onAction, isRepeat);
325     EXPECT_EQ(longPressRecognizer->touchPoints_.size(), 0);
326 
327     /**
328      * @tc.steps: step2. call SendCallbackMsg function and compare result.
329      * @tc.steps: case2: onAction is yes, *onAction is no
330      * @tc.expected: step2. result equals.
331      */
332     onAction = std::make_unique<GestureEventFunc>();
333     longPressRecognizer->SendCallbackMsg(onAction, isRepeat);
334     EXPECT_EQ(longPressRecognizer->touchPoints_.size(), 0);
335 
336     /**
337      * @tc.steps: step2. call SendCallbackMsg function and compare result.
338      * @tc.steps: case3: onAction is yes, *onAction is yes, touchEvent is empty
339      * @tc.expected: step2. result equals.
340      */
__anon9b4e5a350102(GestureEvent) 341     onAction = std::make_unique<GestureEventFunc>([](GestureEvent) {});
342     longPressRecognizer->SendCallbackMsg(onAction, isRepeat);
343     EXPECT_EQ(longPressRecognizer->touchPoints_.size(), 0);
344 
345     /**
346      * @tc.steps: step2. call SendCallbackMsg function and compare result.
347      * @tc.steps: case4: touchEvent is not empty, have no X and Y
348      * @tc.expected: step2. result equals.
349      */
350     TouchEvent touchEvent;
351     longPressRecognizer->touchPoints_[touchEvent.id] = touchEvent;
352     longPressRecognizer->SendCallbackMsg(onAction, isRepeat);
353     EXPECT_EQ(longPressRecognizer->touchPoints_.size(), 1);
354 
355     /**
356      * @tc.steps: step2. call SendCallbackMsg function and compare result.
357      * @tc.steps: case4: touchEvent is not empty, have no X and Y
358      * @tc.expected: step2. result equals.
359      */
360     touchEvent.tiltX = 0.0f;
361     touchEvent.tiltY = 0.0f;
362     longPressRecognizer->touchPoints_[touchEvent.id] = touchEvent;
363     longPressRecognizer->SendCallbackMsg(onAction, isRepeat);
364     EXPECT_EQ(longPressRecognizer->touchPoints_.size(), 1);
365 }
366 
367 /**
368  * @tc.name: LongPressRecognizerTest006
369  * @tc.desc: Test LongPressRecognizer function: ReconcileFrom
370  * @tc.type: FUNC
371  */
372 HWTEST_F(LongPressRecognizerTestNg, LongPressRecognizerTest006, TestSize.Level1)
373 {
374     /**
375      * @tc.steps: step1. create LongPressRecognizer.
376      */
377     RefPtr<LongPressRecognizer> longPressRecognizer =
378         AceType::MakeRefPtr<LongPressRecognizer>(LONG_PRESS_DURATION, FINGER_NUMBER, false);
379     RefPtr<LongPressRecognizer> longPressRecognizerPtr =
380         AceType::MakeRefPtr<LongPressRecognizer>(LONG_PRESS_DURATION, FINGER_NUMBER, false);
381 
382     /**
383      * @tc.steps: step2. call ReconcileFrom function and compare result.
384      * @tc.steps: case1: normal case
385      * @tc.expected: step2. result equals.
386      */
387     auto result = longPressRecognizer->ReconcileFrom(longPressRecognizerPtr);
388     EXPECT_EQ(result, true);
389 
390     /**
391      * @tc.steps: step2. call ReconcileFrom function and compare result.
392      * @tc.steps: case2: recognizerPtr is nullptr
393      * @tc.expected: step2. result equals.
394      */
395     result = longPressRecognizer->ReconcileFrom(nullptr);
396     EXPECT_EQ(result, false);
397 
398     /**
399      * @tc.steps: step2. call ReconcileFrom function and compare result.
400      * @tc.steps: case3: recognizerPtr, duration not same
401      * @tc.expected: step2. result equals.
402      */
403     longPressRecognizer->duration_ = 0;
404     result = longPressRecognizer->ReconcileFrom(longPressRecognizerPtr);
405     EXPECT_EQ(result, false);
406 
407     /**
408      * @tc.steps: step2. call ReconcileFrom function and compare result.
409      * @tc.steps: case4: recognizerPtr, duration same, fingers not same
410      * @tc.expected: step2. result equals.
411      */
412     longPressRecognizer->duration_ = longPressRecognizerPtr->duration_;
413     longPressRecognizer->fingers_ = longPressRecognizerPtr->fingers_ + 1;
414     result = longPressRecognizer->ReconcileFrom(longPressRecognizerPtr);
415     EXPECT_EQ(result, false);
416 
417     /**
418      * @tc.steps: step2. call ReconcileFrom function and compare result.
419      * @tc.steps: case5: recognizerPtr, fingers same, repeat not same
420      * @tc.expected: step2. result equals.
421      */
422     longPressRecognizer->fingers_ = longPressRecognizerPtr->fingers_;
423     longPressRecognizer->repeat_ = !longPressRecognizerPtr->repeat_;
424     result = longPressRecognizer->ReconcileFrom(longPressRecognizerPtr);
425     EXPECT_EQ(result, false);
426 
427     /**
428      * @tc.steps: step2. call ReconcileFrom function and compare result.
429      * @tc.steps: case5: recognizerPtr, repeat same, priorityMask not same
430      * @tc.expected: step2. result equals.
431      */
432     longPressRecognizer->repeat_ = longPressRecognizerPtr->repeat_;
433     longPressRecognizer->priorityMask_ = GestureMask::End;
434     result = longPressRecognizer->ReconcileFrom(longPressRecognizerPtr);
435     EXPECT_EQ(result, false);
436 }
437 
438 /**
439  * @tc.name: LongPressRecognizerTestGetLongPressActionFunc001
440  * @tc.desc: Test LongPressRecognizer function: GetLongPressActionFunc
441  * @tc.type: FUNC
442  */
443 HWTEST_F(LongPressRecognizerTestNg, LongPressRecognizerTestGetLongPressActionFunc001, TestSize.Level1)
444 {
445     /**
446      * @tc.steps: step1. create LongPressRecognizer.
447      */
448     RefPtr<LongPressRecognizer> longPressRecognizer =
449         AceType::MakeRefPtr<LongPressRecognizer>(LONG_PRESS_DURATION, FINGER_NUMBER, false);
450     bool isCatchMode = false;
451 
452     /**
453      * @tc.steps: step2. call GetLongPressActionFunc function and compare result.
454      * @tc.steps: case1: normal case
455      * @tc.expected: step2. result equals.
456      */
457     longPressRecognizer->refereeState_ = RefereeState::SUCCEED;
458     auto frameNode = FrameNode::CreateFrameNode("myButton", 100, AceType::MakeRefPtr<Pattern>());
459     longPressRecognizer->AttachFrameNode(frameNode);
460     longPressRecognizer->HandleOverdueDeadline(isCatchMode);
461     longPressRecognizer->DoRepeat();
462     EXPECT_EQ(longPressRecognizer->refereeState_, RefereeState::SUCCEED);
463     auto result = longPressRecognizer->GetLongPressActionFunc();
464 }
465 
466 /**
467  * @tc.name: LongPressRecognizerTestGetLongPressActionFunc003
468  * @tc.desc: Test LongPressRecognizer function: GetLongPressActionFunc
469  * @tc.type: FUNC
470  */
471 HWTEST_F(LongPressRecognizerTestNg, LongPressRecognizerTestGetLongPressActionFunc003, TestSize.Level1)
472 {
473     /**
474      * @tc.steps: step1. create LongPressRecognizer.
475      */
476     RefPtr<LongPressRecognizer> longPressRecognizer =
477         AceType::MakeRefPtr<LongPressRecognizer>(LONG_PRESS_DURATION, FINGER_NUMBER, false);
478     bool isCatchMode = false;
479 
480     /**
481      * @tc.steps: step2. call GetLongPressActionFunc function and compare result.
482      * @tc.steps: case1: normal case
483      * @tc.expected: step2. result equals.
484      */
485     longPressRecognizer->refereeState_ = RefereeState::SUCCEED;
486     auto frameNode = FrameNode::CreateFrameNode("myButton", 100, AceType::MakeRefPtr<Pattern>());
487     longPressRecognizer->AttachFrameNode(frameNode);
488     longPressRecognizer->HandleOverdueDeadline(isCatchMode);
489     longPressRecognizer->DoRepeat();
490     GestureEventFunc click;
491     GestureEvent info;
492     click = longPressRecognizer->GetLongPressActionFunc();
493     click(info);
494     EXPECT_EQ(longPressRecognizer->refereeState_, RefereeState::SUCCEED);
495 }
496 
497 /**
498  * @tc.name: LongPressRecognizerTestGetLongPressActionFunc004
499  * @tc.desc: Test LongPressRecognizer function: GetLongPressActionFunc
500  * @tc.type: FUNC
501  */
502 HWTEST_F(LongPressRecognizerTestNg, LongPressRecognizerTestGetLongPressActionFunc004, TestSize.Level1)
503 {
504     /**
505      * @tc.steps: step1. create LongPressRecognizer.
506      */
507     RefPtr<LongPressRecognizer> longPressRecognizer =
508         AceType::MakeRefPtr<LongPressRecognizer>(LONG_PRESS_DURATION, FINGER_NUMBER, false);
509     bool isCatchMode = false;
510 
511     /**
512      * @tc.steps: step2. call GetLongPressActionFunc function and compare result.
513      * @tc.steps: case1: normal case
514      * @tc.expected: step2. result equals.
515      */
516     longPressRecognizer->refereeState_ = RefereeState::SUCCEED;
517     auto frameNode = FrameNode::CreateFrameNode("myButton", 100, AceType::MakeRefPtr<Pattern>());
518     longPressRecognizer->AttachFrameNode(frameNode);
519     longPressRecognizer->HandleOverdueDeadline(isCatchMode);
520     longPressRecognizer->DoRepeat();
521     GestureEventFunc click;
522     GestureEvent info;
__anon9b4e5a350202(GestureEvent& info) 523     auto onActionStart = [](GestureEvent& info) { return true; };
__anon9b4e5a350302(GestureEvent& info) 524     auto onActionUpdate = [](GestureEvent& info) { return true; };
__anon9b4e5a350402(GestureEvent& info) 525     auto onActionEnd = [](GestureEvent& info) { return true; };
526     longPressRecognizer->SetOnActionUpdate(onActionUpdate);
527     longPressRecognizer->SetOnAction(onActionStart);
528     longPressRecognizer->SetOnActionEnd(onActionEnd);
529     click = longPressRecognizer->GetLongPressActionFunc();
530     click(info);
531     EXPECT_EQ(longPressRecognizer->refereeState_, RefereeState::SUCCEED);
532 }
533 
534 /**
535  * @tc.name: LongPressRecognizerTestGetLongPressActionFunc002
536  * @tc.desc: Test LongPressRecognizer function: GetLongPressActionFunc
537  * @tc.type: FUNC
538  */
539 HWTEST_F(LongPressRecognizerTestNg, LongPressRecognizerTestGetLongPressActionFunc002, TestSize.Level1)
540 {
541     /**
542      * @tc.steps: step1. create LongPressRecognizer.
543      */
544     RefPtr<LongPressRecognizer> longPressRecognizer =
545         AceType::MakeRefPtr<LongPressRecognizer>(LONG_PRESS_DURATION, FINGER_NUMBER, false);
546     bool isCatchMode = false;
547 
548     /**
549      * @tc.steps: step2. call GetLongPressActionFunc function and compare result.
550      * @tc.steps: case1: normal case
551      * @tc.expected: step2. result equals.
552      */
553     longPressRecognizer->refereeState_ = RefereeState::SUCCEED;
554     longPressRecognizer->fingers_ = SINGLE_FINGER_NUMBER;
555     auto frameNode = FrameNode::CreateFrameNode("myButton", 100, AceType::MakeRefPtr<Pattern>());
556     longPressRecognizer->AttachFrameNode(frameNode);
557     longPressRecognizer->HandleOverdueDeadline(isCatchMode);
558     longPressRecognizer->DoRepeat();
559     auto result = longPressRecognizer->GetLongPressActionFunc();
560     EXPECT_EQ(longPressRecognizer->refereeState_, RefereeState::SUCCEED);
561 
562     /**
563      * @tc.steps: step2. call GetLongPressActionFunc function and compare result.
564      * @tc.steps: case1: normal case
565      * @tc.expected: step2. result equals.
566      */
567     longPressRecognizer->refereeState_ = RefereeState::DETECTING;
568     longPressRecognizer->fingers_ = SINGLE_FINGER_NUMBER;
569     longPressRecognizer->HandleOverdueDeadline(isCatchMode);
570     longPressRecognizer->DoRepeat();
571     result = longPressRecognizer->GetLongPressActionFunc();
572     EXPECT_NE(longPressRecognizer->refereeState_, RefereeState::DETECTING);
573 }
574 
575 /**
576  * @tc.name: LongPressRecognizerConvertPxToVpTest001
577  * @tc.desc: Test LongPressRecognizer function: ConvertPxToVp
578  * @tc.type: FUNC
579  */
580 HWTEST_F(LongPressRecognizerTestNg, LongPressRecognizerConvertPxToVpTest001, TestSize.Level1)
581 {
582     /**
583      * @tc.steps: step1. create LongPressRecognizer.
584      */
585     RefPtr<LongPressRecognizer> longPressRecognizer =
586         AceType::MakeRefPtr<LongPressRecognizer>(LONG_PRESS_DURATION, FINGER_NUMBER, false);
587 
588     /**
589      * @tc.steps: step2. call ConvertPxToVp function and compare result.
590      * @tc.steps: case1: normal case
591      * @tc.expected: step2. result equals.
592      */
593     double result = longPressRecognizer->ConvertPxToVp(0.0);
594     EXPECT_EQ(result, 0.0);
595 }
596 
597 /**
598  * @tc.name: LongPressRecognizerTest007
599  * @tc.desc: Test LongPressRecognizer function: HandleOverdueDeadline  DoRepeat
600  * @tc.type: FUNC
601  */
602 HWTEST_F(LongPressRecognizerTestNg, LongPressRecognizerTest007, TestSize.Level1)
603 {
604     /**
605      * @tc.steps: step1. create LongPressRecognizer.
606      */
607     RefPtr<LongPressRecognizer> longPressRecognizer =
608         AceType::MakeRefPtr<LongPressRecognizer>(LONG_PRESS_DURATION, FINGER_NUMBER, false);
609     bool isCatchMode = false;
610 
611     /**
612      * @tc.steps: step2. call HandleOverdueDeadline function and compare result.
613      * @tc.steps: case1: refereeState is SUCCESS, return
614      * @tc.expected: step2. result equals.
615      */
616     longPressRecognizer->refereeState_ = RefereeState::SUCCEED;
617     auto frameNode = FrameNode::CreateFrameNode("myButton", 100, AceType::MakeRefPtr<Pattern>());
618     longPressRecognizer->AttachFrameNode(frameNode);
619     longPressRecognizer->HandleOverdueDeadline(isCatchMode);
620     longPressRecognizer->DoRepeat();
621     EXPECT_EQ(longPressRecognizer->refereeState_, RefereeState::SUCCEED);
622 
623     /**
624      * @tc.steps: step2. call HandleOverdueDeadline function and compare result.
625      * @tc.steps: case1: refereeState is DETECTING, isCatchMode is false
626      * @tc.expected: step2. result equals.
627      */
628     longPressRecognizer->refereeState_ = RefereeState::DETECTING;
629     longPressRecognizer->HandleOverdueDeadline(isCatchMode);
630     longPressRecognizer->DoRepeat();
631     EXPECT_EQ(longPressRecognizer->refereeState_, RefereeState::SUCCEED);
632 }
633 
634 /**
635  * @tc.name: LongPressRecognizerSendCallbackMsgTest001
636  * @tc.desc: Test LongPressRecognizer function: SendCallbackMsg
637  * @tc.type: FUNC
638  */
639 HWTEST_F(LongPressRecognizerTestNg, LongPressRecognizerSendCallbackMsgTest001, TestSize.Level1)
640 {
641     /**
642      * @tc.steps: step1. Create longPressRecognizer->
643      */
644     RefPtr<LongPressRecognizer> longPressRecognizer =
645         AceType::MakeRefPtr<LongPressRecognizer>(LONG_PRESS_DURATION, FINGER_NUMBER, false);
646     std::unique_ptr<GestureEventFunc> onAction;
647 
648     /**
649      * @tc.steps: step2. call SendCallbackMsg function and compare result.
650      * @tc.steps: case3: onAction is yes, *onAction is yes, touchEvent is empty, type is AXIS
651      * @tc.expected: step2. result equals.
652      */
__anon9b4e5a350502(GestureEvent) 653     onAction = std::make_unique<GestureEventFunc>([](GestureEvent) {});
654     longPressRecognizer->SendCallbackMsg(onAction, true);
655     EXPECT_EQ(longPressRecognizer->touchPoints_.size(), 0);
656 }
657 
658 /**
659  * @tc.name: LongPressGestureTest001
660  * @tc.desc: Test LongPressGesture CreateRecognizer function
661  */
662 HWTEST_F(LongPressRecognizerTestNg, LongPressGestureTest001, TestSize.Level1)
663 {
664     /**
665      * @tc.steps: step1. create LongPressGesture.
666      */
667     LongPressGestureModelNG longPressGestureModelNG;
668     longPressGestureModelNG.Create(FINGER_NUMBER, false, LONG_PRESS_DURATION);
669 
670     RefPtr<GestureProcessor> gestureProcessor;
671     gestureProcessor = NG::ViewStackProcessor::GetInstance()->GetOrCreateGestureProcessor();
672     auto longPressGestureNG = AceType::DynamicCast<NG::LongPressGesture>(gestureProcessor->TopGestureNG());
673     EXPECT_EQ(longPressGestureNG->duration_, LONG_PRESS_DURATION);
674 
675     LongPressGesture longPressGesture = LongPressGesture(FINGER_NUMBER, false, LONG_PRESS_DURATION, false, false);
676     EXPECT_EQ(longPressGesture.repeat_, false);
677     EXPECT_EQ(longPressGesture.duration_, LONG_PRESS_DURATION);
678     EXPECT_EQ(longPressGesture.isForDrag_, false);
679     EXPECT_EQ(longPressGesture.isDisableMouseLeft_, false);
680 
681     /**
682      * @tc.steps: step2. call CreateRecognizer function and compare result
683      * @tc.steps: case1: onActionId, onActionEndId, onActionCancelId not existed
684      */
685     auto longPressRecognizer = AceType::DynamicCast<LongPressRecognizer>(longPressGesture.CreateRecognizer());
686     EXPECT_NE(longPressRecognizer, nullptr);
687     EXPECT_EQ(longPressRecognizer->repeat_, false);
688     EXPECT_EQ(longPressRecognizer->duration_, LONG_PRESS_DURATION);
689     EXPECT_EQ(longPressRecognizer->isForDrag_, false);
690     EXPECT_EQ(longPressRecognizer->isDisableMouseLeft_, false);
691 
692     /**
693      * @tc.steps: step2. call CreateRecognizer function and compare result
694      * @tc.steps: case2: onActionId, onActionEndId, onActionCancelId existed
695      */
696     std::unique_ptr<GestureEventFunc> onActionId;
697     std::unique_ptr<GestureEventFunc> onActionEndId;
698     std::unique_ptr<GestureEventFunc> onActionCancelId;
699     longPressGesture.onActionId_ = std::move(onActionId);
700     longPressGesture.onActionEndId_ = std::move(onActionEndId);
701     longPressGesture.onActionCancelId_ = std::move(onActionCancelId);
702     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 /**
711  * @tc.name: LongPressGestureCreateRecognizerTest001
712  * @tc.desc: Test LongPressGesture CreateRecognizer function
713  */
714 HWTEST_F(LongPressRecognizerTestNg, LongPressGestureCreateRecognizerTest001, TestSize.Level1)
715 {
716     /**
717      * @tc.steps: step1. create LongPressGesture.
718      */
719     LongPressGestureModelNG longPressGestureModelNG;
720     longPressGestureModelNG.Create(FINGER_NUMBER, false, LONG_PRESS_DURATION);
721 
722     RefPtr<GestureProcessor> gestureProcessor;
723     gestureProcessor = NG::ViewStackProcessor::GetInstance()->GetOrCreateGestureProcessor();
724     auto longPressGestureNG = AceType::DynamicCast<NG::LongPressGesture>(gestureProcessor->TopGestureNG());
725     EXPECT_EQ(longPressGestureNG->duration_, LONG_PRESS_DURATION);
726 
727     LongPressGesture longPressGesture = LongPressGesture(FINGER_NUMBER, false, LONG_PRESS_DURATION, false, false);
728     EXPECT_EQ(longPressGesture.repeat_, false);
729     EXPECT_EQ(longPressGesture.duration_, LONG_PRESS_DURATION);
730     EXPECT_EQ(longPressGesture.isForDrag_, false);
731     EXPECT_EQ(longPressGesture.isDisableMouseLeft_, false);
732 
733     /**
734      * @tc.steps: step2. call CreateRecognizer function and compare result
735      * @tc.steps: case1: onActionId, onActionEndId, onActionCancelId not existed
736      */
737     longPressGesture.fingers_ = FINGER_NUMBER_OVER_MAX;
738     longPressGesture.duration_ = 0;
739     auto longPressRecognizer = AceType::DynamicCast<LongPressRecognizer>(longPressGesture.CreateRecognizer());
740     EXPECT_NE(longPressRecognizer, nullptr);
741 
742     /**
743      * @tc.steps: step2. call CreateRecognizer function and compare result
744      * @tc.steps: case1: onActionId, onActionEndId, onActionCancelId not existed
745      */
746     longPressGesture.fingers_ = 0;
747     longPressGesture.duration_ = 0;
748     longPressRecognizer = AceType::DynamicCast<LongPressRecognizer>(longPressGesture.CreateRecognizer());
749     EXPECT_NE(longPressRecognizer, nullptr);
750 }
751 
752 
753 /**
754  * @tc.name: LongPressGestureCreateRecognizerTest002
755  * @tc.desc: Test LongPressGesture CreateRecognizer function
756  */
757 HWTEST_F(LongPressRecognizerTestNg, LongPressGestureCreateRecognizerTest002, TestSize.Level1)
758 {
759     /**
760      * @tc.steps: step1. create LongPressGesture.
761      */
762     LongPressGestureModelNG longPressGestureModelNG;
763     longPressGestureModelNG.Create(FINGER_NUMBER, false, LONG_PRESS_DURATION);
764 
765     RefPtr<GestureProcessor> gestureProcessor;
766     gestureProcessor = NG::ViewStackProcessor::GetInstance()->GetOrCreateGestureProcessor();
767     auto longPressGestureNG = AceType::DynamicCast<NG::LongPressGesture>(gestureProcessor->TopGestureNG());
768     EXPECT_EQ(longPressGestureNG->duration_, LONG_PRESS_DURATION);
769 
770     LongPressGesture longPressGesture = LongPressGesture(FINGER_NUMBER, false, LONG_PRESS_DURATION, false, false);
771     EXPECT_EQ(longPressGesture.repeat_, false);
772     EXPECT_EQ(longPressGesture.duration_, LONG_PRESS_DURATION);
773     EXPECT_EQ(longPressGesture.isForDrag_, false);
774     EXPECT_EQ(longPressGesture.isDisableMouseLeft_, false);
775 
776     /**
777      * @tc.steps: step2. call CreateRecognizer function and compare result
778      * @tc.steps: case1: onActionId, onActionEndId, onActionCancelId not existed
779      */
780     longPressGesture.fingers_ = FINGER_NUMBER_OVER_MAX;
781     longPressGesture.duration_ = 0;
__anon9b4e5a350602(GestureEvent& info) 782     auto onActionStart = [](GestureEvent& info) { return true; };
__anon9b4e5a350702(GestureEvent& info) 783     auto onActionEnd = [](GestureEvent& info) { return true; };
__anon9b4e5a350802(GestureEvent& info) 784     auto onActionCancel = [](GestureEvent& info) { return true; };
785     longPressGesture.SetOnActionId(onActionStart);
786     longPressGesture.SetOnActionEndId(onActionEnd);
787     longPressGesture.SetOnActionCancelId(onActionCancel);
788     auto longPressRecognizer = AceType::DynamicCast<LongPressRecognizer>(longPressGesture.CreateRecognizer());
789     EXPECT_NE(longPressRecognizer, nullptr);
790 
791     /**
792      * @tc.steps: step2. call CreateRecognizer function and compare result
793      * @tc.steps: case1: onActionId, onActionEndId, onActionCancelId not existed
794      */
795     longPressGesture.fingers_ = 0;
796     longPressGesture.duration_ = 0;
797     longPressRecognizer = AceType::DynamicCast<LongPressRecognizer>(longPressGesture.CreateRecognizer());
798     EXPECT_NE(longPressRecognizer, nullptr);
799 }
800 
801 /**
802  * @tc.name: LongPressRecognizerHandleTouchUpEventTest009
803  * @tc.desc: Test LongPressRecognizer function: HandleTouchUpEvent
804  * @tc.type: FUNC
805  */
806 HWTEST_F(LongPressRecognizerTestNg, LongPressRecognizerHandleTouchUpEventTest009, TestSize.Level1)
807 {
808     /**
809      * @tc.steps: step1. create PinchRecognizer.
810      */
811     RefPtr<LongPressRecognizer> longPressRecognizer =AceType::MakeRefPtr<LongPressRecognizer>(LONG_PRESS_DURATION,
812         FINGER_NUMBER, false);
813     TouchEvent touchEvent;
814     touchEvent.x = 100.0;
815     touchEvent.y = 100.0;
816 
817     longPressRecognizer->refereeState_ = RefereeState::DETECTING;
818     longPressRecognizer->currentFingers_ = longPressRecognizer->fingers_;
819     longPressRecognizer->HandleTouchUpEvent(touchEvent);
820     EXPECT_EQ(longPressRecognizer->repeat_, false);
821 }
822 
823 /**
824  * @tc.name: LongPressRecognizerHandleTouchCancelEventTest001
825  * @tc.desc: Test LongPressRecognizer function: HandleTouchCancelEvent
826  * @tc.type: FUNC
827  */
828 HWTEST_F(LongPressRecognizerTestNg, LongPressRecognizerHandleTouchCancelEventTest001, TestSize.Level1)
829 {
830     /**
831      * @tc.steps: step1. create LongPressRecognizer.
832      */
833     RefPtr<LongPressRecognizer> longPressRecognizer =AceType::MakeRefPtr<LongPressRecognizer>(LONG_PRESS_DURATION,
834         FINGER_NUMBER, false);
835     TouchEvent touchEvent;
836     touchEvent.x = 100.0;
837     touchEvent.y = 100.0;
838 
839     longPressRecognizer->refereeState_ = RefereeState::DETECTING;
840     longPressRecognizer->currentFingers_ = longPressRecognizer->fingers_;
841     longPressRecognizer->HandleTouchCancelEvent(touchEvent);
842     EXPECT_EQ(longPressRecognizer->repeat_, false);
843 }
844 
845 /**
846  * @tc.name: LongPressRecognizerHandleTouchDownEventTest001
847  * @tc.desc: Test LongPressRecognizer function: HandleTouchDownEvent
848  * @tc.type: FUNC
849  */
850 HWTEST_F(LongPressRecognizerTestNg, LongPressRecognizerHandleTouchDownEventTest001, TestSize.Level1)
851 {
852     /**
853      * @tc.steps: step1. create LongPressRecognizer.
854      */
855     RefPtr<LongPressRecognizer> longPressRecognizer =AceType::MakeRefPtr<LongPressRecognizer>(LONG_PRESS_DURATION,
856         FINGER_NUMBER, false);
857     TouchEvent touchEvent;
858     touchEvent.x = 100.0;
859     touchEvent.y = 100.0;
860     touchEvent.sourceType = SourceType::MOUSE;
861 
862     longPressRecognizer->refereeState_ = RefereeState::DETECTING;
863     longPressRecognizer->isDisableMouseLeft_ = true;
864     longPressRecognizer->currentFingers_ = longPressRecognizer->fingers_;
865     longPressRecognizer->HandleTouchDownEvent(touchEvent);
866     EXPECT_EQ(longPressRecognizer->repeat_, false);
867 }
868 
869 /**
870  * @tc.name: LongPressRecognizerHandleTouchMoveEventTest001
871  * @tc.desc: Test LongPressRecognizer function: HandleTouchMoveEvent
872  * @tc.type: FUNC
873  */
874 HWTEST_F(LongPressRecognizerTestNg, LongPressRecognizerHandleTouchMoveEventTest001, TestSize.Level1)
875 {
876     /**
877      * @tc.steps: step1. create LongPressRecognizer.
878      */
879     RefPtr<LongPressRecognizer> longPressRecognizer =AceType::MakeRefPtr<LongPressRecognizer>(LONG_PRESS_DURATION,
880         FINGER_NUMBER, false);
881     TouchEvent touchEvent;
882     touchEvent.x = 100.0;
883     touchEvent.y = 100.0;
884     touchEvent.sourceType = SourceType::MOUSE;
885 
886     longPressRecognizer->refereeState_ = RefereeState::DETECTING;
887     longPressRecognizer->isDisableMouseLeft_ = true;
888     longPressRecognizer->currentFingers_ = longPressRecognizer->fingers_;
889     longPressRecognizer->isForDrag_ = true;
890     longPressRecognizer->HandleTouchMoveEvent(touchEvent);
891     EXPECT_EQ(longPressRecognizer->repeat_, false);
892 
893     longPressRecognizer->refereeState_ = RefereeState::DETECTING;
894     longPressRecognizer->isDisableMouseLeft_ = false;
895     longPressRecognizer->currentFingers_ = longPressRecognizer->fingers_;
896     longPressRecognizer->isForDrag_ = false;
897     longPressRecognizer->HandleTouchMoveEvent(touchEvent);
898     EXPECT_EQ(longPressRecognizer->repeat_, false);
899 }
900 
901 /**
902  * @tc.name: LongPressRecognizerHandleOverdueDeadlineTest001
903  * @tc.desc: Test LongPressRecognizer function: HandleOverdueDeadline
904  * @tc.type: FUNC
905  */
906 HWTEST_F(LongPressRecognizerTestNg, LongPressRecognizerHandleOverdueDeadlineTest001, TestSize.Level1)
907 {
908     /**
909      * @tc.steps: step1. create LongPressRecognizer.
910      */
911     RefPtr<LongPressRecognizer> longPressRecognizer =AceType::MakeRefPtr<LongPressRecognizer>(LONG_PRESS_DURATION,
912         FINGER_NUMBER, false);
913     TouchEvent touchEvent;
914     touchEvent.x = 100.0;
915     touchEvent.y = 100.0;
916     touchEvent.sourceType = SourceType::MOUSE;
917 
918     longPressRecognizer->refereeState_ = RefereeState::DETECTING;
919     longPressRecognizer->HandleOverdueDeadline(true);
920     EXPECT_EQ(longPressRecognizer->repeat_, false);
921 }
922 
923 /**
924  * @tc.name: LongPressRecognizerThumbnailTimerTest001
925  * @tc.desc: Test ThumbnailTimer in LongPressRecognizer
926  */
927 HWTEST_F(LongPressRecognizerTestNg, LongPressRecognizerThumbnailTimerTest001, TestSize.Level1)
928 {
929     /**
930      * @tc.steps: step1. create LongPressRecognizer.
931      */
932     RefPtr<LongPressRecognizer> longPressRecognizer =AceType::MakeRefPtr<LongPressRecognizer>(LONG_PRESS_DURATION,
933         FINGER_NUMBER, false);
934 
935     /**
936      * @tc.steps: step2. set callback function.
937      */
__anon9b4e5a350902(Offset offset) 938     auto callback = [](Offset offset) {};
939     longPressRecognizer->callback_ = callback;
940     longPressRecognizer->ThumbnailTimer(0);
941     EXPECT_EQ(longPressRecognizer->refereeState_, RefereeState::READY);
942 }
943 
944 /**
945  * @tc.name: LongPressRecognizerTestGetLongPressActionFunc005
946  * @tc.desc: Test LongPressRecognizer function: GetLongPressActionFunc
947  * @tc.type: FUNC
948  */
949 HWTEST_F(LongPressRecognizerTestNg, LongPressRecognizerTestGetLongPressActionFunc005, TestSize.Level1)
950 {
951     /**
952      * @tc.steps: step1. create LongPressRecognizer.
953      */
954     RefPtr<LongPressRecognizer> longPressRecognizer =AceType::MakeRefPtr<LongPressRecognizer>(LONG_PRESS_DURATION,
955         FINGER_NUMBER, false);
956     bool isCatchMode = false;
957     longPressRecognizer->refereeState_ = RefereeState::SUCCEED;
958     longPressRecognizer->HandleOverdueDeadline(isCatchMode);
959     longPressRecognizer->DoRepeat();
960     GestureEventFunc click;
961     GestureEvent info;
962 
963     /**
964      * @tc.steps: step2. call GetLongPressActionFunc function and compare result.
965      * @tc.steps: case1: normal case
966      * @tc.expected: step2. result equals.
967      */
968     click = longPressRecognizer->GetLongPressActionFunc();
969     click(info);
970     EXPECT_EQ(longPressRecognizer->refereeState_, RefereeState::SUCCEED);
971 
__anon9b4e5a350a02(GestureEvent& info) 972     auto onActionStart = [](GestureEvent& info) { return true; };
__anon9b4e5a350b02(GestureEvent& info) 973     auto onActionUpdate = [](GestureEvent& info) { return true; };
__anon9b4e5a350c02(GestureEvent& info) 974     auto onActionEnd = [](GestureEvent& info) { return true; };
975     longPressRecognizer->SetOnActionUpdate(onActionUpdate);
976     longPressRecognizer->SetOnAction(onActionStart);
977     longPressRecognizer->SetOnActionEnd(onActionEnd);
978     click = longPressRecognizer->GetLongPressActionFunc();
979     click(info);
980     EXPECT_EQ(longPressRecognizer->refereeState_, RefereeState::SUCCEED);
981 }
982 
983 /**
984  * @tc.name: LongPressRecognizerTestGetLongPressActionFunc006
985  * @tc.desc: Test LongPressRecognizer function: GetLongPressActionFunc
986  * @tc.type: FUNC
987  */
988 HWTEST_F(LongPressRecognizerTestNg, LongPressRecognizerTestGetLongPressActionFunc006, 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     GestureEventFunc click;
996     GestureEvent info;
997 
998     /**
999      * @tc.steps: step2. call GetLongPressActionFunc function and compare result.
1000      * @tc.steps: case1: normal case
1001      * @tc.expected: step2. result equals.
1002      */
1003     click = longPressRecognizer->GetLongPressActionFunc();
1004     click(info);
1005     EXPECT_EQ(longPressRecognizer->refereeState_, RefereeState::READY);
1006 
__anon9b4e5a350d02(GestureEvent& info) 1007     auto onActionStart = [](GestureEvent& info) { return true; };
__anon9b4e5a350e02(GestureEvent& info) 1008     auto onActionUpdate = [](GestureEvent& info) { return true; };
__anon9b4e5a350f02(GestureEvent& info) 1009     auto onActionEnd = [](GestureEvent& info) { return true; };
1010     longPressRecognizer->SetOnActionUpdate(onActionUpdate);
1011     longPressRecognizer->SetOnAction(onActionStart);
1012     longPressRecognizer->SetOnActionEnd(onActionEnd);
1013     click = longPressRecognizer->GetLongPressActionFunc();
1014     click(info);
1015     EXPECT_EQ(longPressRecognizer->refereeState_, RefereeState::READY);
1016 }
1017 
1018 /**
1019  * @tc.name: LongPressRecognizerHandleTouchUpEventTest001
1020  * @tc.desc: Test HandleTouchUpEvent in LongPressRecognizer
1021  */
1022 HWTEST_F(LongPressRecognizerTestNg, LongPressRecognizerHandleTouchUpEventTest001, TestSize.Level1)
1023 {
1024     /**
1025      * @tc.steps: step1. create LongPressRecognizer.
1026      */
1027     RefPtr<LongPressRecognizer> longPressRecognizer =AceType::MakeRefPtr<LongPressRecognizer>(LONG_PRESS_DURATION,
1028         FINGER_NUMBER, false);
1029     TouchEvent touchEvent;
1030 
1031     /**
1032      * @tc.steps: step2. set callback function.
1033      */
1034     longPressRecognizer->refereeState_ = RefereeState::SUCCEED;
1035     longPressRecognizer->currentFingers_ = longPressRecognizer->fingers_ + 1;
__anon9b4e5a351002(Offset offset) 1036     auto callback = [](Offset offset) {};
1037     longPressRecognizer->callback_ = callback;
1038     longPressRecognizer->HandleTouchUpEvent(touchEvent);
1039     EXPECT_EQ(longPressRecognizer->refereeState_, RefereeState::SUCCEED);
1040 }
1041 
1042 /**
1043  * @tc.name: LongPressRecognizerThumbnailTimerTest002
1044  * @tc.desc: Test ThumbnailTimer in LongPressRecognizer
1045  */
1046 HWTEST_F(LongPressRecognizerTestNg, LongPressRecognizerThumbnailTimerTest002, TestSize.Level1)
1047 {
1048     /**
1049      * @tc.steps: step1. create LongPressRecognizer.
1050      */
1051     RefPtr<LongPressRecognizer> longPressRecognizer =AceType::MakeRefPtr<LongPressRecognizer>(LONG_PRESS_DURATION,
1052         FINGER_NUMBER, false);
1053 
1054     /**
1055      * @tc.steps: step2. set callback function.
1056      */
__anon9b4e5a351102(Offset offset) 1057     auto callback = [](Offset offset) {};
1058     longPressRecognizer->callback_ = callback;
1059     longPressRecognizer->ThumbnailTimer(0);
1060     EXPECT_EQ(longPressRecognizer->refereeState_, RefereeState::READY);
1061 }
1062 
1063 /**
1064  * @tc.name: LongPressRecognizerTestGetLongPressActionFunc008
1065  * @tc.desc: Test LongPressRecognizer function: GetLongPressActionFunc
1066  * @tc.type: FUNC
1067  */
1068 HWTEST_F(LongPressRecognizerTestNg, LongPressRecognizerTestGetLongPressActionFunc008, TestSize.Level1)
1069 {
1070     /**
1071      * @tc.steps: step1. create LongPressRecognizer.
1072      */
1073     RefPtr<LongPressRecognizer> longPressRecognizer =AceType::MakeRefPtr<LongPressRecognizer>(LONG_PRESS_DURATION,
1074         FINGER_NUMBER, false);
1075     bool isCatchMode = false;
1076     longPressRecognizer->refereeState_ = RefereeState::SUCCEED;
1077     longPressRecognizer->HandleOverdueDeadline(isCatchMode);
1078     longPressRecognizer->DoRepeat();
1079     GestureEventFunc click;
1080     GestureEvent info;
1081 
1082     /**
1083      * @tc.steps: step2. call GetLongPressActionFunc function and compare result.
1084      * @tc.steps: case1: normal case
1085      * @tc.expected: step2. result equals.
1086      */
1087     click = longPressRecognizer->GetLongPressActionFunc();
1088     click(info);
1089     EXPECT_EQ(longPressRecognizer->refereeState_, RefereeState::SUCCEED);
1090 
__anon9b4e5a351202(GestureEvent& info) 1091     auto onActionStart = [](GestureEvent& info) { return true; };
__anon9b4e5a351302(GestureEvent& info) 1092     auto onActionUpdate = [](GestureEvent& info) { return true; };
__anon9b4e5a351402(GestureEvent& info) 1093     auto onActionEnd = [](GestureEvent& info) { return true; };
1094     longPressRecognizer->SetOnActionUpdate(onActionUpdate);
1095     longPressRecognizer->SetOnAction(onActionStart);
1096     longPressRecognizer->SetOnActionEnd(onActionEnd);
1097     click = longPressRecognizer->GetLongPressActionFunc();
1098     click(info);
1099     EXPECT_EQ(longPressRecognizer->refereeState_, RefereeState::SUCCEED);
1100 }
1101 
1102 /**
1103  * @tc.name: LongPressRecognizerTestGetLongPressActionFunc009
1104  * @tc.desc: Test LongPressRecognizer function: GetLongPressActionFunc
1105  * @tc.type: FUNC
1106  */
1107 HWTEST_F(LongPressRecognizerTestNg, LongPressRecognizerTestGetLongPressActionFunc009, 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     GestureEventFunc click;
1115     GestureEvent info;
1116 
1117     /**
1118      * @tc.steps: step2. call GetLongPressActionFunc function and compare result.
1119      * @tc.steps: case1: normal case
1120      * @tc.expected: step2. result equals.
1121      */
1122     click = longPressRecognizer->GetLongPressActionFunc();
1123     click(info);
1124     EXPECT_EQ(longPressRecognizer->refereeState_, RefereeState::READY);
1125 
__anon9b4e5a351502(GestureEvent& info) 1126     auto onActionStart = [](GestureEvent& info) { return true; };
__anon9b4e5a351602(GestureEvent& info) 1127     auto onActionUpdate = [](GestureEvent& info) { return true; };
__anon9b4e5a351702(GestureEvent& info) 1128     auto onActionEnd = [](GestureEvent& info) { return true; };
1129     longPressRecognizer->SetOnActionUpdate(onActionUpdate);
1130     longPressRecognizer->SetOnAction(onActionStart);
1131     longPressRecognizer->SetOnActionEnd(onActionEnd);
1132     click = longPressRecognizer->GetLongPressActionFunc();
1133     click(info);
1134     EXPECT_EQ(longPressRecognizer->refereeState_, RefereeState::READY);
1135 }
1136 
1137 /**
1138  * @tc.name: LongPressRecognizerHandleTouchUpEventTest002
1139  * @tc.desc: Test HandleTouchUpEvent in LongPressRecognizer
1140  */
1141 HWTEST_F(LongPressRecognizerTestNg, LongPressRecognizerHandleTouchUpEventTest002, TestSize.Level1)
1142 {
1143     /**
1144      * @tc.steps: step1. create LongPressRecognizer.
1145      */
1146     RefPtr<LongPressRecognizer> longPressRecognizer =AceType::MakeRefPtr<LongPressRecognizer>(LONG_PRESS_DURATION,
1147         FINGER_NUMBER, false);
1148     TouchEvent touchEvent;
1149 
1150     /**
1151      * @tc.steps: step2. set callback function.
1152      */
1153     longPressRecognizer->refereeState_ = RefereeState::SUCCEED;
1154     longPressRecognizer->currentFingers_ = longPressRecognizer->fingers_ + 1;
__anon9b4e5a351802(Offset offset) 1155     auto callback = [](Offset offset) {};
1156     longPressRecognizer->callback_ = callback;
1157     longPressRecognizer->HandleTouchUpEvent(touchEvent);
1158     EXPECT_EQ(longPressRecognizer->refereeState_, RefereeState::SUCCEED);
1159 }
1160 
1161 /**
1162  * @tc.name: GestureAccessibilityEventTest002
1163  * @tc.desc: Test SetOnAccessibility in LongPressRecognizer
1164  */
1165 HWTEST_F(LongPressRecognizerTestNg, GestureAccessibilityEventTest002, TestSize.Level1)
1166 {
1167     /**
1168      * @tc.steps: step1. Create longPressRecognizer.
1169      */
1170     RefPtr<LongPressRecognizer> longPressRecognizer =
1171         AceType::MakeRefPtr<LongPressRecognizer>(LONG_PRESS_DURATION, FINGER_NUMBER, false);
1172 
1173     /**
1174      * @tc.steps: step2. set callback function.
1175      */
__anon9b4e5a351902(AccessibilityEventType eventType) 1176     auto onAccessibilityEvent = [](AccessibilityEventType eventType) {};
1177     longPressRecognizer->SetOnAccessibility(onAccessibilityEvent);
1178     ASSERT_NE(longPressRecognizer->onAccessibilityEventFunc_, nullptr);
1179 
1180     /**
1181      * @tc.steps: step3. call callback function.
1182      * @tc.expected: refereeState_ is SUCCEED.
1183      */
1184     longPressRecognizer->OnAccepted();
1185     EXPECT_EQ(longPressRecognizer->refereeState_, RefereeState::SUCCEED);
1186 }
1187 
1188 /**
1189  * @tc.name: LongPressRecognizerHandleOverdueDeadlineTest002
1190  * @tc.desc: Test LongPressRecognizer function: HandleOverdueDeadline
1191  * @tc.type: FUNC
1192  */
1193 HWTEST_F(LongPressRecognizerTestNg, LongPressRecognizerHandleOverdueDeadlineTest002, TestSize.Level1)
1194 {
1195     /**
1196      * @tc.steps: step1. create Recognizer、TargetComponent.
1197      */
1198     RefPtr<LongPressRecognizer> longPressRecognizerPtr = AceType::MakeRefPtr<LongPressRecognizer>(LONG_PRESS_DURATION,
1199         FINGER_NUMBER, false);
1200     RefPtr<NG::TargetComponent> targetComponent = AceType::MakeRefPtr<TargetComponent>();
__anon9b4e5a351a02(const RefPtr<GestureInfo>& gestureInfo, const std::shared_ptr<BaseGestureEvent>& info) 1201     auto gestureJudgeFunc = [](const RefPtr<GestureInfo>& gestureInfo, const std::shared_ptr<BaseGestureEvent>& info) {
1202         return GestureJudgeResult::REJECT;};
1203     auto frameNode = FrameNode::CreateFrameNode("myButton", 100, AceType::MakeRefPtr<Pattern>());
1204     auto guestureEventHub = frameNode->GetOrCreateGestureEventHub();
1205     PanDirection panDirection;
1206     targetComponent->SetOnGestureJudgeBegin(gestureJudgeFunc);
1207     longPressRecognizerPtr->targetComponent_ = targetComponent;
1208     longPressRecognizerPtr->targetComponent_->node_ = frameNode;
1209     TouchEvent touchEvent;
1210     touchEvent.tiltX.emplace(1.0f);
1211     touchEvent.tiltY.emplace(1.0f);
1212     longPressRecognizerPtr->touchPoints_[touchEvent.id] = touchEvent;
1213     /**
1214      * @tc.steps: step2. call HandleOverdueDeadline function and compare result.
1215      * @tc.steps: case1: gestureInfo_ is nullptr
1216      * @tc.expected: step2. result equals REJECT.
1217      */
1218     longPressRecognizerPtr->refereeState_ = RefereeState::DETECTING;
1219     longPressRecognizerPtr->gestureInfo_ = AceType::MakeRefPtr<GestureInfo>();
1220     longPressRecognizerPtr->HandleOverdueDeadline(true);
1221     EXPECT_EQ(longPressRecognizerPtr->disposal_, GestureDisposal::REJECT);
1222 
1223     /**
1224      * @tc.steps: step2. call HandleOverdueDeadline function and compare result.
1225      * @tc.steps: case2: gestureInfo_ is not nullptr, gestureInfo_->type_ = DRAG
1226      *                   isDragUserReject_ = true
1227      * @tc.expected: step2. result equals REJECT.
1228      */
1229     longPressRecognizerPtr->refereeState_ = RefereeState::DETECTING;
1230     longPressRecognizerPtr->gestureInfo_ = AceType::MakeRefPtr<GestureInfo>();
1231     longPressRecognizerPtr->gestureInfo_->type_ = GestureTypeName::DRAG;
1232     guestureEventHub->dragEventActuator_ = AceType::MakeRefPtr<DragEventActuator>(
1233         AceType::WeakClaim(AceType::RawPtr(guestureEventHub)), panDirection, 1, 50.0f);
1234     guestureEventHub->dragEventActuator_->isDragUserReject_ = true;
1235     longPressRecognizerPtr->HandleOverdueDeadline(true);
1236     EXPECT_EQ(longPressRecognizerPtr->disposal_, GestureDisposal::REJECT);
1237 
1238     /**
1239      * @tc.steps: step2. call HandleOverdueDeadline function and compare result.
1240      * @tc.steps: case3: gestureInfo_ is not nullptr, gestureInfo_->type_ = DRAG
1241      *                   isDragUserReject_ = false
1242      * @tc.expected: step2. isDragUserReject_ = true.
1243      */
1244     longPressRecognizerPtr->refereeState_ = RefereeState::DETECTING;
1245     guestureEventHub->dragEventActuator_->isDragUserReject_ = false;
1246     longPressRecognizerPtr->HandleOverdueDeadline(true);
1247     EXPECT_TRUE(guestureEventHub->dragEventActuator_->isDragUserReject_);
1248 }
1249 
1250 /**
1251  * @tc.name: LongPressRecognizerLongPressRecognizerTest
1252  * @tc.desc: Test LongPressRecognizer function: LongPressRecognizer
1253  * @tc.type: FUNC
1254  */
1255 HWTEST_F(LongPressRecognizerTestNg, LongPressRecognizerLongPressRecognizerTest, TestSize.Level1)
1256 {
1257     /**
1258      * @tc.steps: step1. create Recognizer、TargetComponent.
1259      */
1260     RefPtr<LongPressRecognizer> longPressRecognizer1 =
1261         AceType::MakeRefPtr<LongPressRecognizer>(100, 9, false, false, false);
1262     RefPtr<LongPressRecognizer> longPressRecognizer2 =
1263         AceType::MakeRefPtr<LongPressRecognizer>(100, 11, false, false, false);
1264     RefPtr<LongPressRecognizer> longPressRecognizer3 =
1265         AceType::MakeRefPtr<LongPressRecognizer>(0, 10, false, false, false);
1266     EXPECT_EQ(longPressRecognizer1->fingers_, 9);
1267     EXPECT_EQ(longPressRecognizer2->fingers_, 1);
1268     EXPECT_EQ(longPressRecognizer3->duration_, 500);
1269 }
1270 
1271 /**
1272  * @tc.name: DeadlineTimerTest
1273  * @tc.desc: Test LongPressRecognizer function: DeadlineTimer
1274  * @tc.type: FUNC
1275  */
1276 HWTEST_F(LongPressRecognizerTestNg, DeadlineTimerTest, TestSize.Level1)
1277 {
1278     /**
1279      * @tc.steps: step1. create Recognizer、TargetComponent.
1280      */
1281     RefPtr<LongPressRecognizer> longPressRecognizerPtr = AceType::MakeRefPtr<LongPressRecognizer>(LONG_PRESS_DURATION,
1282         FINGER_NUMBER, false);
1283     longPressRecognizerPtr->DeadlineTimer(1, true);
1284     EXPECT_NE(longPressRecognizerPtr, nullptr);
1285 }
1286 
1287 /**
1288  * @tc.name: SetOnActionCancelTest001
1289  * @tc.desc: Test SendCallbackMsg function in the HandleTouchCancelEvent with touch event input. The onActionCancel
1290  * function will return GestureEvent info.
1291  * @tc.type: FUNC
1292  */
1293 HWTEST_F(LongPressRecognizerTestNg, SetOnActionCancelTest001, TestSize.Level1)
1294 {
1295     /**
1296      * @tc.steps: step1. Create LongPressRecognizer.
1297      */
1298     RefPtr<LongPressRecognizer> longPressRecognizer =
1299         AceType::MakeRefPtr<LongPressRecognizer>(LONG_PRESS_DURATION, FINGER_NUMBER, false);
1300 
1301     /**
1302      * @tc.steps: step2. Call SetOnActionCancel.
1303      * @tc.expected: LongPressRecognizer's callback onActionCancel is not nullptr.
1304      */
1305     longPressRecognizer->deviceId_ = GESTURE_EVENT_PROPERTY_VALUE;
1306     float unknownPropertyValue = GESTURE_EVENT_PROPERTY_DEFAULT_VALUE;
1307     auto onActionCancel = [&unknownPropertyValue](
__anon9b4e5a351b02( GestureEvent& info) 1308                                 GestureEvent& info) { unknownPropertyValue = info.GetDeviceId(); };
1309     longPressRecognizer->SetOnActionCancel(onActionCancel);
1310 
1311     EXPECT_NE(longPressRecognizer->onActionCancel_, nullptr);
1312 
1313     /**
1314      * @tc.steps: step3. Invoke HandleTouchCancelEvent when onActionCancel_ is not null.
1315      * @tc.expected: The functions have been executed and the unknownPropertyValue has been assigned the correct
1316      * value. LongPressRecognizer.refereeState_ = RefereeState::READY
1317      */
1318     TouchEvent touchEvent;
1319     longPressRecognizer->touchPoints_[touchEvent.id] = touchEvent;
1320     longPressRecognizer->refereeState_ = RefereeState::SUCCEED;
1321     longPressRecognizer->HandleTouchCancelEvent(touchEvent);
1322     EXPECT_EQ(unknownPropertyValue, GESTURE_EVENT_PROPERTY_VALUE);
1323     EXPECT_EQ(longPressRecognizer->refereeState_, RefereeState::READY);
1324 }
1325 
1326 /**
1327  * @tc.name: SetOnActionCancelTest002
1328  * @tc.desc: Test SendCallbackMsg function in the ReconcileFrom. The onActionCancel function will return
1329  * GestureEvent info.
1330  * @tc.type: FUNC
1331  */
1332 HWTEST_F(LongPressRecognizerTestNg, SetOnActionCancelTest002, TestSize.Level1)
1333 {
1334     /**
1335      * @tc.steps: step1. Create LongPressRecognizer.
1336      */
1337     RefPtr<LongPressRecognizer> longPressRecognizer =
1338         AceType::MakeRefPtr<LongPressRecognizer>(LONG_PRESS_DURATION, FINGER_NUMBER, false);
1339     RefPtr<LongPressRecognizer> longPressRecognizerPtr =
1340         AceType::MakeRefPtr<LongPressRecognizer>(LONG_PRESS_DURATION, FINGER_NUMBER, false);
1341 
1342     /**
1343      * @tc.steps: step2. Call SetOnActionCancel.
1344      * @tc.expected: LongPressRecognizer's callback onActionCancel is not nullptr.
1345      */
1346     longPressRecognizer->deviceId_ = GESTURE_EVENT_PROPERTY_VALUE;
1347     float unknownPropertyValue = GESTURE_EVENT_PROPERTY_DEFAULT_VALUE;
1348     auto onActionCancel = [&unknownPropertyValue](
__anon9b4e5a351c02( GestureEvent& info) 1349                                 GestureEvent& info) { unknownPropertyValue = info.GetDeviceId(); };
1350     longPressRecognizer->SetOnActionCancel(onActionCancel);
1351     EXPECT_NE(longPressRecognizer->onActionCancel_, nullptr);
1352 
1353     /**
1354      * @tc.steps: step3. Invoke ReconcileFrom when onActionCancel_ is not null.
1355      * @tc.expected: The functions have been executed and the unknownPropertyValue has been assigned the correct
1356      * value.
1357      */
1358     TouchEvent touchEvent;
1359     longPressRecognizer->touchPoints_[touchEvent.id] = touchEvent;
1360     longPressRecognizer->duration_ = 0;
1361     longPressRecognizer->refereeState_ = RefereeState::SUCCEED;
1362     auto result = longPressRecognizer->ReconcileFrom(longPressRecognizerPtr);
1363     EXPECT_EQ(unknownPropertyValue, GESTURE_EVENT_PROPERTY_VALUE);
1364     EXPECT_EQ(result, false);
1365 }
1366 
1367 /**
1368  * @tc.name: LongPressGestureLimitFingerTest001
1369  * @tc.desc: Test LongPressGesture CreateRecognizer function
1370  */
1371 HWTEST_F(LongPressRecognizerTestNg, LongPressGestureLimitFingerTest001, TestSize.Level1)
1372 {
1373     /**
1374      * @tc.steps: step1. create LongPressGesture.
1375      */
1376     LongPressGestureModelNG longPressGestureModelNG;
1377     longPressGestureModelNG.Create(FINGER_NUMBER, false, 0, IS_LIMIT_FINGER_COUNT);
1378 
1379     RefPtr<GestureProcessor> gestureProcessor;
1380     gestureProcessor = NG::ViewStackProcessor::GetInstance()->GetOrCreateGestureProcessor();
1381     auto longPressGestureNG = AceType::DynamicCast<NG::LongPressGesture>(gestureProcessor->TopGestureNG());
1382     EXPECT_EQ(longPressGestureNG->isLimitFingerCount_, IS_LIMIT_FINGER_COUNT);
1383 
1384     LongPressGesture longPressGesture = LongPressGesture(
1385         FINGER_NUMBER, false, LONG_PRESS_DURATION, false, false, IS_LIMIT_FINGER_COUNT);
1386     EXPECT_EQ(longPressGesture.repeat_, false);
1387     EXPECT_EQ(longPressGesture.duration_, LONG_PRESS_DURATION);
1388     EXPECT_EQ(longPressGesture.isForDrag_, false);
1389     EXPECT_EQ(longPressGesture.isDisableMouseLeft_, false);
1390     EXPECT_EQ(longPressGesture.isLimitFingerCount_, true);
1391 
1392     /**
1393      * @tc.steps: step2. call CreateRecognizer function and compare result
1394      * @tc.steps: case1: onActionId, onActionEndId, onActionCancelId not existed
1395      */
1396     auto longPressRecognizer = AceType::DynamicCast<LongPressRecognizer>(longPressGesture.CreateRecognizer());
1397     EXPECT_NE(longPressRecognizer, nullptr);
1398     EXPECT_EQ(longPressRecognizer->repeat_, false);
1399     EXPECT_EQ(longPressRecognizer->duration_, LONG_PRESS_DURATION);
1400     EXPECT_EQ(longPressRecognizer->isForDrag_, false);
1401     EXPECT_EQ(longPressRecognizer->isDisableMouseLeft_, false);
1402     EXPECT_EQ(longPressRecognizer->isLimitFingerCount_, true);
1403 
1404     /**
1405      * @tc.steps: step2. call CreateRecognizer function and compare result
1406      * @tc.steps: case2: onActionId, onActionEndId, onActionCancelId existed
1407      */
1408     std::unique_ptr<GestureEventFunc> onActionId;
1409     std::unique_ptr<GestureEventFunc> onActionEndId;
1410     std::unique_ptr<GestureEventFunc> onActionCancelId;
1411     longPressGesture.onActionId_ = std::move(onActionId);
1412     longPressGesture.onActionEndId_ = std::move(onActionEndId);
1413     longPressGesture.onActionCancelId_ = std::move(onActionCancelId);
1414     longPressRecognizer = AceType::DynamicCast<LongPressRecognizer>(longPressGesture.CreateRecognizer());
1415     EXPECT_NE(longPressRecognizer, nullptr);
1416     EXPECT_EQ(longPressRecognizer->isLimitFingerCount_, true);
1417 }
1418 
1419 /**
1420  * @tc.name: LongPressGestureLimitFingerTest002
1421  * @tc.desc: Test LongPressGesture CreateRecognizer function
1422  */
1423 HWTEST_F(LongPressRecognizerTestNg, LongPressGestureLimitFingerTest002, TestSize.Level1)
1424 {
1425     /**
1426      * @tc.steps: step1. create LongPressGesture.
1427      */
1428     LongPressGestureModelNG longPressGestureModelNG;
1429     longPressGestureModelNG.Create(FINGER_NUMBER, false, 0, IS_NOT_LIMIT_FINGER_COUNT);
1430 
1431     RefPtr<GestureProcessor> gestureProcessor;
1432     gestureProcessor = NG::ViewStackProcessor::GetInstance()->GetOrCreateGestureProcessor();
1433     auto longPressGestureNG = AceType::DynamicCast<NG::LongPressGesture>(gestureProcessor->TopGestureNG());
1434     EXPECT_EQ(longPressGestureNG->isLimitFingerCount_, IS_NOT_LIMIT_FINGER_COUNT);
1435 
1436     LongPressGesture longPressGesture = LongPressGesture(
1437         FINGER_NUMBER, false, LONG_PRESS_DURATION, false, false, IS_NOT_LIMIT_FINGER_COUNT);
1438     EXPECT_EQ(longPressGesture.repeat_, false);
1439     EXPECT_EQ(longPressGesture.duration_, LONG_PRESS_DURATION);
1440     EXPECT_EQ(longPressGesture.isForDrag_, false);
1441     EXPECT_EQ(longPressGesture.isDisableMouseLeft_, false);
1442     EXPECT_EQ(longPressGesture.isLimitFingerCount_, false);
1443 
1444     /**
1445      * @tc.steps: step2. call CreateRecognizer function and compare result
1446      * @tc.steps: case1: onActionId, onActionEndId, onActionCancelId not existed
1447      */
1448     auto longPressRecognizer = AceType::DynamicCast<LongPressRecognizer>(longPressGesture.CreateRecognizer());
1449     EXPECT_NE(longPressRecognizer, nullptr);
1450     EXPECT_EQ(longPressRecognizer->repeat_, false);
1451     EXPECT_EQ(longPressRecognizer->duration_, LONG_PRESS_DURATION);
1452     EXPECT_EQ(longPressRecognizer->isForDrag_, false);
1453     EXPECT_EQ(longPressRecognizer->isDisableMouseLeft_, false);
1454     EXPECT_EQ(longPressRecognizer->isLimitFingerCount_, false);
1455 
1456     /**
1457      * @tc.steps: step2. call CreateRecognizer function and compare result
1458      * @tc.steps: case2: onActionId, onActionEndId, onActionCancelId existed
1459      */
1460     std::unique_ptr<GestureEventFunc> onActionId;
1461     std::unique_ptr<GestureEventFunc> onActionEndId;
1462     std::unique_ptr<GestureEventFunc> onActionCancelId;
1463     longPressGesture.onActionId_ = std::move(onActionId);
1464     longPressGesture.onActionEndId_ = std::move(onActionEndId);
1465     longPressGesture.onActionCancelId_ = std::move(onActionCancelId);
1466     longPressRecognizer = AceType::DynamicCast<LongPressRecognizer>(longPressGesture.CreateRecognizer());
1467     EXPECT_NE(longPressRecognizer, nullptr);
1468     EXPECT_EQ(longPressRecognizer->isLimitFingerCount_, false);
1469 }
1470 } // namespace OHOS::Ace::NG