• 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/ace_type.h"
17 #include "ui/base/referenced.h"
18 
19 using namespace testing;
20 using namespace testing::ext;
21 
22 namespace OHOS::Ace::NG {
23 constexpr float GESTURE_EVENT_PROPERTY_DEFAULT_VALUE = 0.0;
24 constexpr float GESTURE_EVENT_PROPERTY_VALUE = 10.0;
25 class RotationRecognizerTestNg : public GesturesCommonTestNg {
26 public:
27     static void SetUpTestSuite();
28     static void TearDownTestSuite();
29 };
30 
SetUpTestSuite()31 void RotationRecognizerTestNg::SetUpTestSuite()
32 {
33     MockPipelineContext::SetUp();
34 }
35 
TearDownTestSuite()36 void RotationRecognizerTestNg::TearDownTestSuite()
37 {
38     MockPipelineContext::TearDown();
39 }
40 
41 /**
42  * @tc.name: RotationRecognizerTest001
43  * @tc.desc: Test RotationRecognizer function: OnAccepted OnRejected
44  * @tc.type: FUNC
45  */
46 HWTEST_F(RotationRecognizerTestNg, RotationRecognizerTest001, TestSize.Level1)
47 {
48     /**
49      * @tc.steps: step1. create RotationRecognizer.
50      */
51     RefPtr<RotationRecognizer> rotationRecognizer =
52         AceType::MakeRefPtr<RotationRecognizer>(SINGLE_FINGER_NUMBER, ROTATION_GESTURE_ANGLE);
53 
54     /**
55      * @tc.steps: step2. call OnAccepted function and compare result.
56      * @tc.expected: step2. result equals.
57      */
58     rotationRecognizer->OnAccepted();
59     EXPECT_EQ(rotationRecognizer->refereeState_, RefereeState::SUCCEED);
60 
61     /**
62      * @tc.steps: step3. call OnRejected function and compare result.
63      * @tc.expected: step3. result equals.
64      */
65     rotationRecognizer->OnRejected();
66     EXPECT_EQ(rotationRecognizer->refereeState_, RefereeState::SUCCEED);
67 }
68 
69 /**
70  * @tc.name: RotationRecognizerTest002
71  * @tc.desc: Test RotationRecognizer function: TouchDown TouchUp TouchMove
72  * @tc.type: FUNC
73  */
74 HWTEST_F(RotationRecognizerTestNg, RotationRecognizerTest002, TestSize.Level1)
75 {
76     /**
77      * @tc.steps: step1. create RotationRecognizer.
78      */
79     auto rotationRecognizer = AceType::MakeRefPtr<RotationRecognizer>(SINGLE_FINGER_NUMBER, ROTATION_GESTURE_ANGLE);
80 
81     /**
82      * @tc.steps: step2. call HandleTouchDownEvent function and compare result.
83      * @tc.steps: case1: touchPoints.size == fingers
84      * @tc.expected: step2. result equals.
85      */
86     TouchEvent touchEvent;
87     rotationRecognizer->HandleTouchDownEvent(touchEvent);
88     EXPECT_EQ(rotationRecognizer->touchPoints_[touchEvent.id].id, touchEvent.id);
89 
90     /**
91      * @tc.steps: step2. call HandleTouchDownEvent function and compare result.
92      * @tc.steps: case2: touchPoints.size < fingers
93      * @tc.expected: step2. result equals.
94      */
95     rotationRecognizer->fingers_ = FINGER_NUMBER;
96     rotationRecognizer->refereeState_ = RefereeState::SUCCEED;
97     rotationRecognizer->HandleTouchDownEvent(touchEvent);
98     rotationRecognizer->HandleTouchUpEvent(touchEvent);
99     rotationRecognizer->HandleTouchMoveEvent(touchEvent);
100     rotationRecognizer->HandleTouchCancelEvent(touchEvent);
101     EXPECT_EQ(rotationRecognizer->refereeState_, RefereeState::FAIL);
102     EXPECT_EQ(rotationRecognizer->resultAngle_, 0);
103 
104     /**
105      * @tc.steps: step2. call HandleTouchDownEvent function and compare result.
106      * @tc.steps: case3: touchPoints.size < fingers
107      * @tc.expected: step2. result equals.
108      */
109     rotationRecognizer->fingers_ = FINGER_NUMBER;
110     rotationRecognizer->refereeState_ = RefereeState::FAIL;
111     rotationRecognizer->HandleTouchDownEvent(touchEvent);
112     rotationRecognizer->HandleTouchUpEvent(touchEvent);
113     rotationRecognizer->HandleTouchMoveEvent(touchEvent);
114     rotationRecognizer->HandleTouchCancelEvent(touchEvent);
115     EXPECT_EQ(rotationRecognizer->refereeState_, RefereeState::FAIL);
116     EXPECT_EQ(rotationRecognizer->resultAngle_, 0);
117 }
118 
119 /**
120  * @tc.name: RotationRecognizerHandleTouchDownEventTest001
121  * @tc.desc: Test RotationRecognizer function: TouchDown TouchUp TouchMove
122  * @tc.type: FUNC
123  */
124 HWTEST_F(RotationRecognizerTestNg, RotationRecognizerHandleTouchDownEventTest001, TestSize.Level1)
125 {
126     /**
127      * @tc.steps: step1. create RotationRecognizer.
128      */
129     auto rotationRecognizer = AceType::MakeRefPtr<RotationRecognizer>(SINGLE_FINGER_NUMBER, ROTATION_GESTURE_ANGLE);
130 
131     /**
132      * @tc.steps: step2. call HandleTouchDownEvent function and compare result.
133      * @tc.steps: case1: touchPoints.size == fingers
134      * @tc.expected: step2. result equals.
135      */
136     TouchEvent touchEvent;
137     rotationRecognizer->fingers_ = FINGER_NUMBER_OVER_MAX;
138     rotationRecognizer->HandleTouchDownEvent(touchEvent);
139     EXPECT_EQ(rotationRecognizer->touchPoints_[touchEvent.id].id, touchEvent.id);
140 
141     /**
142      * @tc.steps: step2. call HandleTouchDownEvent function and compare result.
143      * @tc.steps: case2: touchPoints.size < fingers
144      * @tc.expected: step2. result equals.
145      */
146     rotationRecognizer->refereeState_ = RefereeState::SUCCEED;
147     rotationRecognizer->fingers_ = FINGER_NUMBER_OVER_MAX;
148     rotationRecognizer->HandleTouchDownEvent(touchEvent);
149     rotationRecognizer->HandleTouchUpEvent(touchEvent);
150     rotationRecognizer->HandleTouchMoveEvent(touchEvent);
151     rotationRecognizer->HandleTouchCancelEvent(touchEvent);
152     EXPECT_EQ(rotationRecognizer->refereeState_, RefereeState::FAIL);
153     EXPECT_EQ(rotationRecognizer->resultAngle_, 0);
154 
155     /**
156      * @tc.steps: step2. call HandleTouchDownEvent function and compare result.
157      * @tc.steps: case3: touchPoints.size < fingers
158      * @tc.expected: step2. result equals.
159      */
160     rotationRecognizer->refereeState_ = RefereeState::FAIL;
161     rotationRecognizer->fingers_ = FINGER_NUMBER_OVER_MAX;
162     rotationRecognizer->HandleTouchDownEvent(touchEvent);
163     rotationRecognizer->HandleTouchUpEvent(touchEvent);
164     rotationRecognizer->HandleTouchMoveEvent(touchEvent);
165     rotationRecognizer->HandleTouchCancelEvent(touchEvent);
166     EXPECT_EQ(rotationRecognizer->refereeState_, RefereeState::FAIL);
167     EXPECT_EQ(rotationRecognizer->resultAngle_, 0);
168 }
169 
170 /**
171  * @tc.name: RotationRecognizerHandleTouchDownEventTest002
172  * @tc.desc: Test RotationRecognizer function: HandleTouchDownEvent
173  * @tc.type: FUNC
174  */
175 HWTEST_F(RotationRecognizerTestNg, RotationRecognizerHandleTouchDownEventTest002, TestSize.Level1)
176 {
177     /**
178      * @tc.steps: step1. create RotationRecognizer.
179      */
180     RefPtr<RotationRecognizer> rotationRecognizer =
181         AceType::MakeRefPtr<RotationRecognizer>(SINGLE_FINGER_NUMBER, ROTATION_GESTURE_ANGLE);
182 
183     /**
184      * @tc.steps: step2. call HandleTouchDownEvent function and compare result.
185      * @tc.steps: case1: touchPoints.size == fingers
186      * @tc.expected: step2. result equals.
187      */
188     TouchEvent touchEvent;
189     rotationRecognizer->fingers_ = 0;
190     rotationRecognizer->HandleTouchDownEvent(touchEvent);
191     EXPECT_EQ(rotationRecognizer->touchPoints_[touchEvent.id].id, touchEvent.id);
192 
193     /**
194      * @tc.steps: step2. call HandleTouchDownEvent function and compare result.
195      * @tc.steps: case2: touchPoints.size < fingers
196      * @tc.expected: step2. result equals.
197      */
198     rotationRecognizer->refereeState_ = RefereeState::SUCCEED;
199     rotationRecognizer->fingers_ = 0;
200     rotationRecognizer->HandleTouchDownEvent(touchEvent);
201     EXPECT_EQ(rotationRecognizer->resultAngle_, 0);
202 
203     /**
204      * @tc.steps: step2. call HandleTouchDownEvent function and compare result.
205      * @tc.steps: case3: touchPoints.size < fingers
206      * @tc.expected: step2. result equals.
207      */
208     rotationRecognizer->refereeState_ = RefereeState::FAIL;
209     rotationRecognizer->fingers_ = 0;
210     rotationRecognizer->HandleTouchDownEvent(touchEvent);
211     EXPECT_EQ(rotationRecognizer->resultAngle_, 0);
212 }
213 
214 /**
215  * @tc.name: RotationRecognizerHandleTouchUpEventTest001
216  * @tc.desc: Test RotationRecognizer function: HandleTouchUpEvent
217  * @tc.type: FUNC
218  */
219 HWTEST_F(RotationRecognizerTestNg, RotationRecognizerHandleTouchUpEventTest001, TestSize.Level1)
220 {
221     /**
222      * @tc.steps: step1. create RotationRecognizer.
223      */
224     RefPtr<RotationRecognizer> rotationRecognizer =
225         AceType::MakeRefPtr<RotationRecognizer>(SINGLE_FINGER_NUMBER, ROTATION_GESTURE_ANGLE);
226 
227     /**
228      * @tc.steps: step2. call HandleTouchDownEvent function and compare result.
229      * @tc.steps: case1: touchPoints.size == fingers
230      * @tc.expected: step2. result equals.
231      */
232     TouchEvent touchEvent;
233 
234     /**
235      * @tc.steps: step2. call HandleTouchDownEvent function and compare result.
236      * @tc.steps: case2: touchPoints.size < fingers
237      * @tc.expected: step2. result equals.
238      */
239     rotationRecognizer->fingers_ = FINGER_NUMBER;
240     rotationRecognizer->refereeState_ = RefereeState::SUCCEED;
241     rotationRecognizer->currentFingers_ = rotationRecognizer->fingers_;
242     rotationRecognizer->HandleTouchUpEvent(touchEvent);
243     EXPECT_EQ(rotationRecognizer->refereeState_, RefereeState::SUCCEED);
244     EXPECT_EQ(rotationRecognizer->resultAngle_, 0);
245 
246     /**
247      * @tc.steps: step2. call HandleTouchDownEvent function and compare result.
248      * @tc.steps: case3: touchPoints.size < fingers
249      * @tc.expected: step2. result equals.
250      */
251     rotationRecognizer->fingers_ = FINGER_NUMBER;
252     rotationRecognizer->refereeState_ = RefereeState::FAIL;
253     rotationRecognizer->currentFingers_ = rotationRecognizer->fingers_;
254     rotationRecognizer->HandleTouchUpEvent(touchEvent);
255     EXPECT_EQ(rotationRecognizer->refereeState_, RefereeState::FAIL);
256     EXPECT_EQ(rotationRecognizer->resultAngle_, 0);
257 }
258 
259 /**
260  * @tc.name: RotationRecognizerHandleTouchMoveEventTest001
261  * @tc.desc: Test RotationRecognizer function: HandleTouchMoveEvent
262  * @tc.type: FUNC
263  */
264 HWTEST_F(RotationRecognizerTestNg, RotationRecognizerHandleTouchMoveEventTest001, TestSize.Level1)
265 {
266     /**
267      * @tc.steps: step1. create RotationRecognizer.
268      */
269     RefPtr<RotationRecognizer> rotationRecognizer =
270         AceType::MakeRefPtr<RotationRecognizer>(SINGLE_FINGER_NUMBER, ROTATION_GESTURE_ANGLE);
271 
272     /**
273      * @tc.steps: step2. call HandleTouchDownEvent function and compare result.
274      * @tc.steps: case1: touchPoints.size == fingers
275      * @tc.expected: step2. result equals.
276      */
277     TouchEvent touchEvent;
278 
279     /**
280      * @tc.steps: step2. call HandleTouchDownEvent function and compare result.
281      * @tc.steps: case2: touchPoints.size < fingers
282      * @tc.expected: step2. result equals.
283      */
284     rotationRecognizer->fingers_ = FINGER_NUMBER;
285     rotationRecognizer->refereeState_ = RefereeState::SUCCEED;
286     rotationRecognizer->currentFingers_ = rotationRecognizer->fingers_;
287     rotationRecognizer->HandleTouchMoveEvent(touchEvent);
288     EXPECT_EQ(rotationRecognizer->refereeState_, RefereeState::SUCCEED);
289     EXPECT_EQ(rotationRecognizer->resultAngle_, 0);
290 
291     /**
292      * @tc.steps: step2. call HandleTouchDownEvent function and compare result.
293      * @tc.steps: case3: touchPoints.size < fingers
294      * @tc.expected: step2. result equals.
295      */
296     rotationRecognizer->fingers_ = FINGER_NUMBER;
297     rotationRecognizer->refereeState_ = RefereeState::FAIL;
298     rotationRecognizer->currentFingers_ = rotationRecognizer->fingers_;
299     rotationRecognizer->HandleTouchMoveEvent(touchEvent);
300     EXPECT_EQ(rotationRecognizer->refereeState_, RefereeState::FAIL);
301     EXPECT_EQ(rotationRecognizer->resultAngle_, 0);
302 }
303 
304 /**
305  * @tc.name: RotationRecognizerHandleTouchMoveEventTest002
306  * @tc.desc: Test RotationRecognizer function: HandleTouchMoveEvent
307  * @tc.type: FUNC
308  */
309 HWTEST_F(RotationRecognizerTestNg, RotationRecognizerHandleTouchMoveEventTest002, TestSize.Level1)
310 {
311     /**
312      * @tc.steps: step1. create RotationRecognizer.
313      */
314     RefPtr<RotationRecognizer> rotationRecognizer =
315         AceType::MakeRefPtr<RotationRecognizer>(SINGLE_FINGER_NUMBER, ROTATION_GESTURE_ANGLE);
316 
317     /**
318      * @tc.steps: step2. call HandleTouchDownEvent function and compare result.
319      * @tc.steps: case1: touchPoints.size == fingers
320      * @tc.expected: step2. result equals.
321      */
322     TouchEvent touchEvent;
323 
324     /**
325      * @tc.steps: step2. call HandleTouchDownEvent function and compare result.
326      * @tc.steps: case2: touchPoints.size < fingers
327      * @tc.expected: step2. result equals.
328      */
329     rotationRecognizer->fingers_ = FINGER_NUMBER_OVER_MAX;
330     rotationRecognizer->refereeState_ = RefereeState::SUCCEED;
331     rotationRecognizer->currentFingers_ = rotationRecognizer->fingers_;
332     rotationRecognizer->HandleTouchMoveEvent(touchEvent);
333     EXPECT_EQ(rotationRecognizer->refereeState_, RefereeState::SUCCEED);
334     EXPECT_EQ(rotationRecognizer->resultAngle_, 0);
335 
336     /**
337      * @tc.steps: step2. call HandleTouchDownEvent function and compare result.
338      * @tc.steps: case3: touchPoints.size < fingers
339      * @tc.expected: step2. result equals.
340      */
341     rotationRecognizer->fingers_ = 0;
342     rotationRecognizer->refereeState_ = RefereeState::FAIL;
343     rotationRecognizer->currentFingers_ = rotationRecognizer->fingers_;
344     rotationRecognizer->HandleTouchMoveEvent(touchEvent);
345     EXPECT_EQ(rotationRecognizer->refereeState_, RefereeState::FAIL);
346     EXPECT_EQ(rotationRecognizer->resultAngle_, 0);
347 }
348 
349 /**
350  * @tc.name: RotationRecognizerHandleTouchMoveEventTest003
351  * @tc.desc: Test RotationRecognizer function: HandleTouchMoveEvent
352  * @tc.type: FUNC
353  */
354 HWTEST_F(RotationRecognizerTestNg, RotationRecognizerHandleTouchMoveEventTest003, TestSize.Level1)
355 {
356     /**
357      * @tc.steps: step1. create RotationRecognizer.
358      */
359     RefPtr<RotationRecognizer> rotationRecognizer =
360         AceType::MakeRefPtr<RotationRecognizer>(SINGLE_FINGER_NUMBER, ROTATION_GESTURE_ANGLE);
361 
362     /**
363      * @tc.steps: step2. call HandleTouchDownEvent function and compare result.
364      * @tc.steps: case1: touchPoints.size == fingers
365      * @tc.expected: step2. result equals.
366      */
367     TouchEvent touchEvent;
368 
369     /**
370      * @tc.steps: step2. call HandleTouchDownEvent function and compare result.
371      * @tc.steps: case2: touchPoints.size < fingers
372      * @tc.expected: step2. result equals.
373      */
374     rotationRecognizer->fingers_ = FINGER_NUMBER_OVER_MAX;
375     rotationRecognizer->refereeState_ = RefereeState::SUCCEED;
376     rotationRecognizer->currentFingers_ = rotationRecognizer->fingers_;
377     rotationRecognizer->HandleTouchMoveEvent(touchEvent);
378     EXPECT_EQ(rotationRecognizer->refereeState_, RefereeState::SUCCEED);
379     EXPECT_EQ(rotationRecognizer->resultAngle_, 0);
380 
381     /**
382      * @tc.steps: step2. call HandleTouchDownEvent function and compare result.
383      * @tc.steps: case3: touchPoints.size < fingers
384      * @tc.expected: step2. result equals.
385      */
386     rotationRecognizer->fingers_ = 0;
387     rotationRecognizer->refereeState_ = RefereeState::SUCCEED;
388     rotationRecognizer->currentFingers_ = rotationRecognizer->fingers_;
389     rotationRecognizer->HandleTouchMoveEvent(touchEvent);
390     EXPECT_EQ(rotationRecognizer->refereeState_, RefereeState::SUCCEED);
391     EXPECT_EQ(rotationRecognizer->resultAngle_, 0);
392 }
393 
394 /**
395  * @tc.name: RotationRecognizerTest003
396  * @tc.desc: Test RotationRecognizer function: ChangeValueRange
397  * @tc.type: FUNC
398  */
399 HWTEST_F(RotationRecognizerTestNg, RotationRecognizerTest003, TestSize.Level1)
400 {
401     /**
402      * @tc.steps: step1. create RotationRecognizer.
403      */
404     RefPtr<RotationRecognizer> rotationRecognizer =
405         AceType::MakeRefPtr<RotationRecognizer>(SINGLE_FINGER_NUMBER, ROTATION_GESTURE_ANGLE);
406 
407     /**
408      * @tc.steps: step2. call ChangeValueRange function and compare result.
409      * @tc.expected: step2. result equals.
410      */
411     auto result = rotationRecognizer->ChangeValueRange(COMMON_VALUE_RANGE_CASE);
412     EXPECT_EQ(result, COMMON_VALUE_RANGE_CASE);
413 
414     result = rotationRecognizer->ChangeValueRange(SPECIAL_VALUE_RANGE_CASE1);
415     EXPECT_EQ(result, SPECIAL_VALUE_RANGE_CASE1 - PI);
416 
417     result = rotationRecognizer->ChangeValueRange(SPECIAL_VALUE_RANGE_CASE2);
418     EXPECT_EQ(result, SPECIAL_VALUE_RANGE_CASE2 + PI);
419 }
420 
421 /**
422  * @tc.name: RotationRecognizerTest004
423  * @tc.desc: Test RotationRecognizer function: ComputeAngle
424  * @tc.type: FUNC
425  */
426 HWTEST_F(RotationRecognizerTestNg, RotationRecognizerTest004, TestSize.Level1)
427 {
428     /**
429      * @tc.steps: step1. create RotationRecognizer.
430      */
431     RefPtr<RotationRecognizer> rotationRecognizer =
432         AceType::MakeRefPtr<RotationRecognizer>(SINGLE_FINGER_NUMBER, ROTATION_GESTURE_ANGLE);
433 
434     /**
435      * @tc.steps: step2. call ComputeAngle function and compare result.
436      * @tc.expected: step2. result equals.
437      */
438     TouchEvent touchEventStart;
439     touchEventStart.id = 0;
440     rotationRecognizer->touchPoints_[0] = touchEventStart;
441     TouchEvent touchEventEnd;
442     touchEventEnd.id = 1;
443     rotationRecognizer->touchPoints_[1] = touchEventEnd;
444     auto result = rotationRecognizer->ComputeAngle();
445     EXPECT_EQ(result, 0);
446 }
447 
448 /**
449  * @tc.name: RotationRecognizerTest005
450  * @tc.desc: Test RotationRecognizer function: OnResetStatus
451  * @tc.type: FUNC
452  */
453 HWTEST_F(RotationRecognizerTestNg, RotationRecognizerTest005, TestSize.Level1)
454 {
455     /**
456      * @tc.steps: step1. create RotationRecognizer.
457      */
458     RefPtr<RotationRecognizer> rotationRecognizer =
459         AceType::MakeRefPtr<RotationRecognizer>(SINGLE_FINGER_NUMBER, ROTATION_GESTURE_ANGLE);
460 
461     /**
462      * @tc.steps: step2. call OnResetStatus function and compare result.
463      * @tc.expected: step2. result equals.
464      */
465     rotationRecognizer->OnResetStatus();
466     EXPECT_EQ(rotationRecognizer->initialAngle_, 0.0);
467     EXPECT_EQ(rotationRecognizer->currentAngle_, 0.0);
468     EXPECT_EQ(rotationRecognizer->resultAngle_, 0.0);
469 }
470 
471 /**
472  * @tc.name: RotationRecognizerTest006
473  * @tc.desc: Test RotationRecognizer function: SendCallbackMsg
474  * @tc.type: FUNC
475  */
476 HWTEST_F(RotationRecognizerTestNg, RotationRecognizerTest006, TestSize.Level1)
477 {
478     /**
479      * @tc.steps: step1. create RotationRecognizer.
480      */
481     RefPtr<RotationRecognizer> rotationRecognizer =
482         AceType::MakeRefPtr<RotationRecognizer>(SINGLE_FINGER_NUMBER, ROTATION_GESTURE_ANGLE);
483 
484     /**
485      * @tc.steps: step2. call SendCallbackMsg function and compare result.
486      * @tc.steps: case1: onAction is no, *onAction is no
487      * @tc.expected: step2. result equals.
488      */
489     std::unique_ptr<GestureEventFunc> onAction;
490     rotationRecognizer->SendCallbackMsg(onAction);
491     EXPECT_EQ(rotationRecognizer->touchPoints_.size(), 0);
492 
493     /**
494      * @tc.steps: step2. call SendCallbackMsg function and compare result.
495      * @tc.steps: case2: onAction is yes, *onAction is no
496      * @tc.expected: step2. result equals.
497      */
498     onAction = std::make_unique<GestureEventFunc>();
499     rotationRecognizer->SendCallbackMsg(onAction);
500     EXPECT_EQ(rotationRecognizer->touchPoints_.size(), 0);
501 
502     /**
503      * @tc.steps: step2. call SendCallbackMsg function and compare result.
504      * @tc.steps: case3: onAction is yes, *onAction is yes, touchEvent is empty
505      * @tc.expected: step2. result equals.
506      */
__anon0c2a03490102(GestureEvent) 507     onAction = std::make_unique<GestureEventFunc>([](GestureEvent) {});
508     rotationRecognizer->SendCallbackMsg(onAction);
509     EXPECT_EQ(rotationRecognizer->touchPoints_.size(), 0);
510 
511     /**
512      * @tc.steps: step2. call SendCallbackMsg function and compare result.
513      * @tc.steps: case4: touchEvent is not empty, have no X and Y
514      * @tc.expected: step2. result equals.
515      */
516     TouchEvent touchEvent;
517     rotationRecognizer->touchPoints_[touchEvent.id] = touchEvent;
518     rotationRecognizer->SendCallbackMsg(onAction);
519     EXPECT_EQ(rotationRecognizer->touchPoints_.size(), 1);
520 
521     /**
522      * @tc.steps: step2. call SendCallbackMsg function and compare result.
523      * @tc.steps: case4: touchEvent is not empty, have no X and Y
524      * @tc.expected: step2. result equals.
525      */
526     touchEvent.tiltX = 0.0f;
527     touchEvent.tiltY = 0.0f;
528     rotationRecognizer->touchPoints_[touchEvent.id] = touchEvent;
529     rotationRecognizer->SendCallbackMsg(onAction);
530     EXPECT_EQ(rotationRecognizer->touchPoints_.size(), 1);
531 }
532 
533 /**
534  * @tc.name: RotationRecognizerTest007
535  * @tc.desc: Test RotationRecognizer function: ReconcileFrom
536  * @tc.type: FUNC
537  */
538 HWTEST_F(RotationRecognizerTestNg, RotationRecognizerTest007, TestSize.Level1)
539 {
540     /**
541      * @tc.steps: step1. create ClickRecognizer.
542      */
543     RefPtr<RotationRecognizer> rotationRecognizer =
544         AceType::MakeRefPtr<RotationRecognizer>(SINGLE_FINGER_NUMBER, ROTATION_GESTURE_ANGLE);
545     RefPtr<RotationRecognizer> rotationRecognizerPtr =
546         AceType::MakeRefPtr<RotationRecognizer>(SINGLE_FINGER_NUMBER, ROTATION_GESTURE_ANGLE);
547     bool result = false;
548 
549     /**
550      * @tc.steps: step2. call ReconcileFrom function and compare result.
551      * @tc.steps: case1: recognizerPtr is nullptr
552      * @tc.expected: step2. result equals.
553      */
554     result = rotationRecognizer->ReconcileFrom(nullptr);
555     EXPECT_EQ(result, false);
556 
557     /**
558      * @tc.steps: step2. call ReconcileFrom function and compare result.
559      * @tc.steps: case2: recognizerPtr is normal, curr->fingers != fingers
560      * @tc.expected: step2. result equals.
561      */
562     rotationRecognizer->fingers_ = rotationRecognizerPtr->fingers_ + 1;
563     result = rotationRecognizer->ReconcileFrom(rotationRecognizerPtr);
564     EXPECT_EQ(result, false);
565 
566     /**
567      * @tc.steps: step2. call ReconcileFrom function and compare result.
568      * @tc.steps: case2: recognizerPtr is normal, curr->angle != angle
569      * @tc.expected: step2. result equals.
570      */
571     rotationRecognizer->fingers_ = rotationRecognizerPtr->fingers_;
572     rotationRecognizer->angle_ = rotationRecognizerPtr->angle_ + 1;
573     result = rotationRecognizer->ReconcileFrom(rotationRecognizerPtr);
574     EXPECT_EQ(result, false);
575 
576     /**
577      * @tc.steps: step2. call ReconcileFrom function and compare result.
578      * @tc.steps: case2: recognizerPtr is normal, curr->priorityMask != priorityMask
579      * @tc.expected: step2. result equals.
580      */
581     rotationRecognizer->fingers_ = rotationRecognizerPtr->fingers_;
582     rotationRecognizer->angle_ = rotationRecognizerPtr->angle_;
583     rotationRecognizer->priorityMask_ = GestureMask::Begin;
584     result = rotationRecognizer->ReconcileFrom(rotationRecognizerPtr);
585     EXPECT_EQ(result, false);
586 
587     /**
588      * @tc.steps: step2. call ReconcileFrom function and compare result.
589      * @tc.steps: case2: recognizerPtr is normal
590      * @tc.expected: step2. result equals.
591      */
592     rotationRecognizer->fingers_ = rotationRecognizerPtr->fingers_;
593     rotationRecognizer->angle_ = rotationRecognizerPtr->angle_;
594     rotationRecognizer->priorityMask_ = rotationRecognizerPtr->priorityMask_;
595     result = rotationRecognizer->ReconcileFrom(rotationRecognizerPtr);
596     EXPECT_EQ(result, true);
597 }
598 
599 /**
600  * @tc.name: RotationRecognizerTest008
601  * @tc.desc: Test RotationRecognizer function: HandleTouchDownEvent
602  * @tc.type: FUNC
603  */
604 HWTEST_F(RotationRecognizerTestNg, RotationRecognizerTest008, TestSize.Level1)
605 {
606     /**
607      * @tc.steps: step1. create rotationRecognizer->
608      */
609     auto rotationRecognizer = AceType::MakeRefPtr<RotationRecognizer>(SINGLE_FINGER_NUMBER, ROTATION_GESTURE_ANGLE);
610     ASSERT_NE(rotationRecognizer, nullptr);
611 
612     /**
613      * @tc.steps: step2. test with HandleTouchDownEvent(AxisEvent).
614      * @tc.expect: rotationRecognizer->lastAxisEvent_ is equal to axisEvent
615      * @tc.expect: rotationRecognizer->touchPoints_[axisEvent.id].originalId is equal to axisEvent.originalId
616      * @tc.expect: rotationRecognizer->touchPoints_[axisEvent.id].screenX is equal to axisEvent.screenX
617      * @tc.expect: rotationRecognizer->touchPoints_[axisEvent.id].screenY is equal to axisEvent.screenY
618      */
619     AxisEvent axisEvent;
620     axisEvent.id = TEST_EVENT_ID;
621     axisEvent.originalId = TEST_EVENT_ID;
622     axisEvent.isRotationEvent = true;
623 
624     rotationRecognizer->refereeState_ = RefereeState::SUCCEED;
625     rotationRecognizer->currentFingers_ = rotationRecognizer->fingers_;
626     rotationRecognizer->HandleTouchDownEvent(axisEvent);
627     EXPECT_EQ(rotationRecognizer->lastAxisEvent_.id, axisEvent.id);
628     EXPECT_EQ(rotationRecognizer->touchPoints_[axisEvent.id].originalId, axisEvent.originalId);
629     EXPECT_EQ(rotationRecognizer->touchPoints_[axisEvent.id].screenX, axisEvent.screenX);
630     EXPECT_EQ(rotationRecognizer->touchPoints_[axisEvent.id].screenY, axisEvent.screenY);
631 }
632 
633 /**
634  * @tc.name: RotationRecognizerTest009
635  * @tc.desc: Test RotationRecognizer function: HandleTouchUpEvent
636  * @tc.type: FUNC
637  */
638 HWTEST_F(RotationRecognizerTestNg, RotationRecognizerTest009, TestSize.Level1)
639 {
640     /**
641      * @tc.steps: step1. create rotationRecognizer->
642      */
643     auto rotationRecognizer = AceType::MakeRefPtr<RotationRecognizer>(SINGLE_FINGER_NUMBER, ROTATION_GESTURE_ANGLE);
644     ASSERT_NE(rotationRecognizer, nullptr);
645 
646     /**
647      * @tc.steps: step2. test with HandleTouchUpEvent(AxisEvent).
648      * @tc.expect: rotationRecognizer->lastAxisEvent_ is equal to axisEvent
649      */
650     AxisEvent axisEvent;
651     axisEvent.isRotationEvent = true;
652     axisEvent.id = TEST_EVENT_ID;
653     rotationRecognizer->refereeState_ = RefereeState::SUCCEED;
654     rotationRecognizer->currentFingers_ = rotationRecognizer->fingers_;
655     rotationRecognizer->HandleTouchUpEvent(axisEvent);
656     EXPECT_EQ(rotationRecognizer->lastAxisEvent_.id, axisEvent.id);
657 }
658 
659 /**
660  * @tc.name: RotationRecognizerTest010
661  * @tc.desc: Test RotationRecognizer function: HandleTouchMoveEvent
662  * @tc.type: FUNC
663  */
664 HWTEST_F(RotationRecognizerTestNg, RotationRecognizerTest010, TestSize.Level1)
665 {
666     /**
667      * @tc.steps: step1. create rotationRecognizer->
668      */
669     auto rotationRecognizer = AceType::MakeRefPtr<RotationRecognizer>(SINGLE_FINGER_NUMBER, ROTATION_GESTURE_ANGLE);
670     ASSERT_NE(rotationRecognizer, nullptr);
671 
672     /**
673      * @tc.steps: step2. test with HandleTouchMoveEvent(AxisEvent).
674      * @tc.expect: rotationRecognizer->lastAxisEvent_ is equal to axisEvent
675      * @tc.expect: rotationRecognizer->touchPoints_[axisEvent.id].originalId is equal to axisEvent.originalId
676      * @tc.expect: rotationRecognizer->touchPoints_[axisEvent.id].screenX is equal to axisEvent.screenX
677      * @tc.expect: rotationRecognizer->touchPoints_[axisEvent.id].screenY is equal to axisEvent.screenY
678      */
679     AxisEvent axisEvent;
680     axisEvent.id = TEST_EVENT_ID;
681     axisEvent.originalId = TEST_EVENT_ID;
682     axisEvent.isRotationEvent = true;
683     rotationRecognizer->refereeState_ = RefereeState::SUCCEED;
684     rotationRecognizer->currentFingers_ = rotationRecognizer->fingers_;
685     rotationRecognizer->HandleTouchMoveEvent(axisEvent);
686     EXPECT_EQ(rotationRecognizer->lastAxisEvent_.id, axisEvent.id);
687     EXPECT_EQ(rotationRecognizer->touchPoints_[axisEvent.id].originalId, axisEvent.originalId);
688     EXPECT_EQ(rotationRecognizer->touchPoints_[axisEvent.id].screenX, axisEvent.screenX);
689     EXPECT_EQ(rotationRecognizer->touchPoints_[axisEvent.id].screenY, axisEvent.screenY);
690 }
691 
692 /**
693  * @tc.name: RotationRecognizerSendCallbackMsgTest001
694  * @tc.desc: Test RotationRecognizer function: SendCallbackMsg
695  * @tc.type: FUNC
696  */
697 HWTEST_F(RotationRecognizerTestNg, RotationRecognizerSendCallbackMsgTest001, TestSize.Level1)
698 {
699     /**
700      * @tc.steps: step1. create RotationRecognizer.
701      */
702     RefPtr<RotationRecognizer> rotationRecognizer =
703         AceType::MakeRefPtr<RotationRecognizer>(SINGLE_FINGER_NUMBER, ROTATION_GESTURE_ANGLE);
704     std::unique_ptr<GestureEventFunc> onAction;
705 
706     /**
707      * @tc.steps: step2. call SendCallbackMsg function and compare result.
708      * @tc.steps: case3: onAction is yes, *onAction is yes, touchEvent is empty, type is AXIS
709      * @tc.expected: step2. result equals.
710      */
__anon0c2a03490202(GestureEvent) 711     onAction = std::make_unique<GestureEventFunc>([](GestureEvent) {});
712     rotationRecognizer->SendCallbackMsg(onAction);
713     EXPECT_EQ(rotationRecognizer->touchPoints_.size(), 0);
714 }
715 
716 /**
717  * @tc.name: RotationGestureTest001
718  * @tc.desc: Test RotationGesture CreateRecognizer function
719  */
720 HWTEST_F(RotationRecognizerTestNg, RotationGestureTest001, TestSize.Level1)
721 {
722     /**
723      * @tc.steps: step1. create RotationGestureGesture.
724      */
725     RotationGestureModelNG rotationGestureModelNG;
726     rotationGestureModelNG.Create(FINGER_NUMBER, ROTATION_GESTURE_ANGLE);
727 
728     RefPtr<GestureProcessor> gestureProcessor;
729     gestureProcessor = NG::ViewStackProcessor::GetInstance()->GetOrCreateGestureProcessor();
730     auto rotationGestureNG = AceType::DynamicCast<NG::RotationGesture>(gestureProcessor->TopGestureNG());
731     EXPECT_EQ(rotationGestureNG->angle_, ROTATION_GESTURE_ANGLE);
732 
733     RotationGesture rotationGesture = RotationGesture(FINGER_NUMBER, ROTATION_GESTURE_ANGLE);
734     EXPECT_EQ(rotationGesture.angle_, ROTATION_GESTURE_ANGLE);
735 
736     /**
737      * @tc.steps: step2. call CreateRecognizer function and compare result
738      * @tc.steps: case1: functions are not existed
739      */
740     rotationGesture.priority_ = GesturePriority::Low;
741     rotationGesture.gestureMask_ = GestureMask::Normal;
742     auto rotationRecognizer = AceType::DynamicCast<RotationRecognizer>(rotationGesture.CreateRecognizer());
743     EXPECT_NE(rotationRecognizer, nullptr);
744     EXPECT_EQ(rotationRecognizer->GetPriority(), GesturePriority::Low);
745     EXPECT_EQ(rotationRecognizer->GetPriorityMask(), GestureMask::Normal);
746 
747     // /**
748     //  * @tc.steps: step2. call CreateRecognizer function and compare result
749     //  * @tc.steps: case2: functions are existed
750     //  */
751     std::unique_ptr<GestureEventFunc> onActionStartId;
752     std::unique_ptr<GestureEventFunc> onActionUpdateId;
753     std::unique_ptr<GestureEventFunc> onActionEndId;
754     std::unique_ptr<GestureEventFunc> onActionCancelId;
755     rotationGesture.onActionStartId_ = std::move(onActionStartId);
756     rotationGesture.onActionUpdateId_ = std::move(onActionUpdateId);
757     rotationGesture.onActionEndId_ = std::move(onActionEndId);
758     rotationGesture.onActionCancelId_ = std::move(onActionCancelId);
759     rotationRecognizer = AceType::DynamicCast<RotationRecognizer>(rotationGesture.CreateRecognizer());
760     EXPECT_EQ(rotationRecognizer->priority_, rotationGesture.priority_);
761     EXPECT_EQ(rotationRecognizer->priorityMask_, rotationGesture.gestureMask_);
762 }
763 
764 /**
765  * @tc.name: RotationGestureCreateRecognizerTest001
766  * @tc.desc: Test RotationGesture CreateRecognizer function
767  */
768 HWTEST_F(RotationRecognizerTestNg, RotationGestureCreateRecognizerTest001, TestSize.Level1)
769 {
770     /**
771      * @tc.steps: step1. create RotationGestureGesture.
772      */
773     RotationGestureModelNG rotationGestureModelNG;
774     rotationGestureModelNG.Create(FINGER_NUMBER, ROTATION_GESTURE_ANGLE);
775 
776     RefPtr<GestureProcessor> gestureProcessor;
777     gestureProcessor = NG::ViewStackProcessor::GetInstance()->GetOrCreateGestureProcessor();
778     auto rotationGestureNG = AceType::DynamicCast<NG::RotationGesture>(gestureProcessor->TopGestureNG());
779     EXPECT_EQ(rotationGestureNG->angle_, ROTATION_GESTURE_ANGLE);
780 
781     RotationGesture rotationGesture = RotationGesture(FINGER_NUMBER, 0.0);
782     EXPECT_EQ(rotationGesture.angle_, ROTATION_GESTURE_ANGLE);
783     RotationGesture rotationGestureTwo = RotationGesture(FINGER_NUMBER, -1.0);
784     EXPECT_EQ(rotationGestureTwo.angle_, ROTATION_GESTURE_ANGLE);
785     RotationGesture rotationGestureThree = RotationGesture(FINGER_NUMBER, 361.0);
786     EXPECT_EQ(rotationGestureThree.angle_, ROTATION_GESTURE_ANGLE);
787 }
788 
789 
790 /**
791  * @tc.name: RotationGestureCreateRecognizerTest002
792  * @tc.desc: Test RotationGesture CreateRecognizer function
793  */
794 HWTEST_F(RotationRecognizerTestNg, RotationGestureCreateRecognizerTest002, TestSize.Level1)
795 {
796     /**
797      * @tc.steps: step1. create RotationGestureGesture.
798      */
799     RotationGestureModelNG rotationGestureModelNG;
800     rotationGestureModelNG.Create(FINGER_NUMBER, ROTATION_GESTURE_ANGLE);
801 
802     RefPtr<GestureProcessor> gestureProcessor;
803     gestureProcessor = NG::ViewStackProcessor::GetInstance()->GetOrCreateGestureProcessor();
804     auto rotationGestureNG = AceType::DynamicCast<NG::RotationGesture>(gestureProcessor->TopGestureNG());
805     EXPECT_EQ(rotationGestureNG->angle_, ROTATION_GESTURE_ANGLE);
806 
807     RotationGesture rotationGesture = RotationGesture(FINGER_NUMBER, ROTATION_GESTURE_ANGLE);
808     EXPECT_EQ(rotationGesture.angle_, ROTATION_GESTURE_ANGLE);
809 
810     /**
811      * @tc.steps: step2. call CreateRecognizer function and compare result
812      * @tc.steps: case1: functions are not existed
813      */
814     rotationGesture.priority_ = GesturePriority::Low;
815     rotationGesture.gestureMask_ = GestureMask::Normal;
816     auto rotationRecognizer = AceType::DynamicCast<RotationRecognizer>(rotationGesture.CreateRecognizer());
817     EXPECT_NE(rotationRecognizer, nullptr);
818     EXPECT_EQ(rotationRecognizer->GetPriority(), GesturePriority::Low);
819     EXPECT_EQ(rotationRecognizer->GetPriorityMask(), GestureMask::Normal);
820 
821     // /**
822     //  * @tc.steps: step2. call CreateRecognizer function and compare result
823     //  * @tc.steps: case2: functions are existed
824     //  */
825     std::unique_ptr<GestureEventFunc> onActionStartId;
826     std::unique_ptr<GestureEventFunc> onActionUpdateId;
827     std::unique_ptr<GestureEventFunc> onActionEndId;
828     std::unique_ptr<GestureEventFunc> onActionCancelId;
829     rotationGesture.onActionStartId_ = std::move(onActionStartId);
830     rotationGesture.onActionUpdateId_ = std::move(onActionUpdateId);
831     rotationGesture.onActionEndId_ = std::move(onActionEndId);
832     rotationGesture.onActionCancelId_ = std::move(onActionCancelId);
833     rotationGesture.priority_ = GesturePriority::Low;
834     rotationGesture.gestureMask_ = GestureMask::Normal;
__anon0c2a03490302(GestureEvent& info) 835     auto onActionStart = [](GestureEvent& info) { return true; };
__anon0c2a03490402(GestureEvent& info) 836     auto onActionUpdate = [](GestureEvent& info) { return true; };
__anon0c2a03490502(GestureEvent& info) 837     auto onActionEnd = [](GestureEvent& info) { return true; };
__anon0c2a03490602(GestureEvent& info) 838     auto onActionCancel = [](GestureEvent& info) { return true; };
839     rotationGesture.SetOnActionStartId(onActionStart);
840     rotationGesture.SetOnActionUpdateId(onActionUpdate);
841     rotationGesture.SetOnActionEndId(onActionEnd);
842     rotationGesture.SetOnActionCancelId(onActionCancel);
843     rotationRecognizer = AceType::DynamicCast<RotationRecognizer>(rotationGesture.CreateRecognizer());
844     EXPECT_EQ(rotationRecognizer->priority_, rotationGesture.priority_);
845     EXPECT_EQ(rotationRecognizer->priorityMask_, rotationGesture.gestureMask_);
846 }
847 
848 /**
849  * @tc.name: RotationRecognizerHandleTouchUpEventTest002
850  * @tc.desc: Test HandleTouchUpEvent in RotationRecognizer
851  */
852 HWTEST_F(RotationRecognizerTestNg, RotationRecognizerHandleTouchUpEventTest002, TestSize.Level1)
853 {
854     /**
855      * @tc.steps: step1. create clickRecognizerPtr.
856      */
857     RefPtr<RotationRecognizer> rotationRecognizerPtr =
858         AceType::MakeRefPtr<RotationRecognizer>(SINGLE_FINGER_NUMBER, ROTATION_GESTURE_ANGLE);
859     TouchEvent touchEvent;
860     rotationRecognizerPtr->activeFingers_.emplace_back(touchEvent.id);
861 
862     rotationRecognizerPtr->refereeState_ = RefereeState::PENDING;
863     rotationRecognizerPtr->currentFingers_ = rotationRecognizerPtr->fingers_;
864     rotationRecognizerPtr->HandleTouchUpEvent(touchEvent);
865     EXPECT_EQ(rotationRecognizerPtr->refereeState_, RefereeState::FAIL);
866 }
867 
868 /**
869  * @tc.name: RotationRecognizerHandleTouchCancelEventTest002
870  * @tc.desc: Test HandleTouchCancelEvent in RotationRecognizer
871  */
872 HWTEST_F(RotationRecognizerTestNg, RotationRecognizerHandleTouchCancelEventTest002, TestSize.Level1)
873 {
874     /**
875      * @tc.steps: step1. create clickRecognizerPtr.
876      */
877     RefPtr<RotationRecognizer> rotationRecognizerPtr =
878         AceType::MakeRefPtr<RotationRecognizer>(SINGLE_FINGER_NUMBER, ROTATION_GESTURE_ANGLE);
879     TouchEvent touchEvent;
880 
881     rotationRecognizerPtr->activeFingers_.emplace_back(touchEvent.id);
882     rotationRecognizerPtr->refereeState_ = RefereeState::PENDING;
883     rotationRecognizerPtr->HandleTouchCancelEvent(touchEvent);
884     EXPECT_EQ(rotationRecognizerPtr->refereeState_, RefereeState::FAIL);
885 }
886 
887 /**
888  * @tc.name: RotationRecognizerHandleTouchMoveEventTest006
889  * @tc.desc: Test HandleTouchMoveEvent in RotationRecognizer
890  */
891 HWTEST_F(RotationRecognizerTestNg, RotationRecognizerHandleTouchMoveEventTest006, TestSize.Level1)
892 {
893     /**
894      * @tc.steps: step1. create clickRecognizerPtr.
895      */
896     RefPtr<RotationRecognizer> rotationRecognizerPtr =
897         AceType::MakeRefPtr<RotationRecognizer>(SINGLE_FINGER_NUMBER, ROTATION_GESTURE_ANGLE);
898     TouchEvent touchEvent;
899 
900     rotationRecognizerPtr->refereeState_ = RefereeState::DETECTING;
901     rotationRecognizerPtr->fingers_ = 0;
902     rotationRecognizerPtr->currentFingers_ = rotationRecognizerPtr->fingers_;
903     rotationRecognizerPtr->HandleTouchMoveEvent(touchEvent);
904     EXPECT_EQ(rotationRecognizerPtr->refereeState_, RefereeState::DETECTING);
905 }
906 
907 /**
908  * @tc.name: RotationRecognizerPtrHandleTouchUpEventTest001
909  * @tc.desc: Test RotationRecognizer function: HandleTouchUpEvent
910  * @tc.type: FUNC
911  */
912 HWTEST_F(RotationRecognizerTestNg, RotationRecognizerPtrHandleTouchUpEventTest001, TestSize.Level1)
913 {
914     /**
915      * @tc.steps: step1. create and set Recognizer、TargetComponent.
916      */
917     RefPtr<RotationRecognizer> rotationRecognizerPtr =
918         AceType::MakeRefPtr<RotationRecognizer>(SINGLE_FINGER_NUMBER, ROTATION_GESTURE_ANGLE);
919     RefPtr<NG::TargetComponent> targetComponent = AceType::MakeRefPtr<TargetComponent>();
__anon0c2a03490702(const RefPtr<GestureInfo>& gestureInfo, const std::shared_ptr<BaseGestureEvent>& info) 920     auto gestureJudgeFunc = [](const RefPtr<GestureInfo>& gestureInfo, const std::shared_ptr<BaseGestureEvent>& info) {
921         return GestureJudgeResult::REJECT;};
922     targetComponent->SetOnGestureJudgeBegin(gestureJudgeFunc);
923     TouchEvent touchEvent;
924     touchEvent.tiltX.emplace(1.0f);
925     touchEvent.tiltY.emplace(1.0f);
926     rotationRecognizerPtr->targetComponent_ = targetComponent;
927     /**
928      * @tc.steps: step2. test the function who calls TriggerGestureJudgeCallback.
929      * @tc.expected: step2. result equals REJECT.
930      */
931     rotationRecognizerPtr->refereeState_ = RefereeState::DETECTING;
932     rotationRecognizerPtr->currentFingers_ = 2;
933     rotationRecognizerPtr->fingers_ = 2;
934     rotationRecognizerPtr->activeFingers_.push_back(touchEvent.id);
935     rotationRecognizerPtr->activeFingers_.push_back(1);
936     rotationRecognizerPtr->angle_ = 0;
937     rotationRecognizerPtr->HandleTouchMoveEvent(touchEvent);
938     EXPECT_EQ(rotationRecognizerPtr->disposal_, GestureDisposal::REJECT);
939 }
940 
941 /**
942  * @tc.name: RotationRecognizerHandleTouchDownEventTest001
943  * @tc.desc: Test RotationRecognizer function with axis event input: Down
944  * @tc.type: FUNC
945  */
946 HWTEST_F(RotationRecognizerTestNg, RotationRecognizerHandleAxisEventTest001, TestSize.Level1)
947 {
948     /**
949      * @tc.steps: step1. create rotation recognizer and axis event.
950      */
951     AxisEvent event;
952     RefPtr<RotationRecognizer> recognizer =
953         AceType::MakeRefPtr<RotationRecognizer>(SINGLE_FINGER_NUMBER, ROTATION_GESTURE_ANGLE);
954     /**
955      * @tc.steps: step2. Test HandleTouchDownEvent
956      */
957     event.isRotationEvent = false;
958     recognizer->refereeState_ = RefereeState::READY;
959     recognizer->HandleTouchDownEvent(event);
960     EXPECT_EQ(recognizer->refereeState_, RefereeState::READY);
961 
962     event.isRotationEvent = true;
963     recognizer->refereeState_ = RefereeState::READY;
964     recognizer->HandleTouchDownEvent(event);
965     EXPECT_EQ(recognizer->refereeState_, RefereeState::DETECTING);
966 
967     event.isRotationEvent = true;
968     recognizer->refereeState_ = RefereeState::SUCCEED;
969     recognizer->HandleTouchDownEvent(event);
970     EXPECT_EQ(recognizer->refereeState_, RefereeState::SUCCEED);
971 }
972 /**
973  * @tc.name: RotationRecognizerHandleTouchDownEventTest002
974  * @tc.desc: Test RotationRecognizer function with axis event input: Up
975  * @tc.type: FUNC
976  */
977 HWTEST_F(RotationRecognizerTestNg, RotationRecognizerHandleAxisEventTest002, TestSize.Level1)
978 {
979     /**
980      * @tc.steps: step1. create rotation recognizer and axis event.
981      */
982     AxisEvent event;
983     RefPtr<RotationRecognizer> recognizer =
984         AceType::MakeRefPtr<RotationRecognizer>(SINGLE_FINGER_NUMBER, ROTATION_GESTURE_ANGLE);
985     /**
986      * @tc.steps: step2. Test HandleTouchUpEvent
987      */
988     recognizer->refereeState_ = RefereeState::READY;
989     recognizer->HandleTouchUpEvent(event);
990     EXPECT_EQ(recognizer->refereeState_, RefereeState::READY);
991 
992     recognizer->refereeState_ = RefereeState::SUCCEED;
993     recognizer->HandleTouchUpEvent(event);
994     EXPECT_EQ(recognizer->refereeState_, RefereeState::SUCCEED);
995 }
996 /**
997  * @tc.name: RotationRecognizerHandleTouchDownEventTest003
998  * @tc.desc: Test RotationRecognizer function with axis event input: Move
999  * @tc.type: FUNC
1000  */
1001 HWTEST_F(RotationRecognizerTestNg, RotationRecognizerHandleAxisEventTest003, TestSize.Level1)
1002 {
1003     /**
1004      * @tc.steps: step1. create rotation recognizer and axis event.
1005      */
1006     AxisEvent event;
1007     RefPtr<RotationRecognizer> recognizer =
1008         AceType::MakeRefPtr<RotationRecognizer>(SINGLE_FINGER_NUMBER, ROTATION_GESTURE_ANGLE);
1009     /**
1010      * @tc.steps: step2. Test HandleTouchMoveEvent
1011      */
1012     event.isRotationEvent = true;
1013     recognizer->refereeState_ = RefereeState::DETECTING;
1014     recognizer->HandleTouchMoveEvent(event);
1015     EXPECT_EQ(recognizer->refereeState_, RefereeState::DETECTING);
1016 
1017     event.isRotationEvent = true;
1018     event.rotateAxisAngle = ROTATION_GESTURE_ANGLE;
1019     recognizer->refereeState_ = RefereeState::DETECTING;
1020     recognizer->HandleTouchMoveEvent(event);
1021     EXPECT_EQ(recognizer->refereeState_, RefereeState::DETECTING);
1022 
1023     event.isRotationEvent = true;
1024     event.rotateAxisAngle = 2 * ROTATION_GESTURE_ANGLE;
1025     recognizer->refereeState_ = RefereeState::DETECTING;
1026     recognizer->HandleTouchMoveEvent(event);
1027     EXPECT_NE(recognizer->refereeState_, RefereeState::DETECTING);
1028 
1029     event.isRotationEvent = true;
1030     recognizer->refereeState_ = RefereeState::SUCCEED;
1031     recognizer->HandleTouchMoveEvent(event);
1032     EXPECT_EQ(recognizer->refereeState_, RefereeState::SUCCEED);
1033 
1034     event.isRotationEvent = true;
1035     recognizer->refereeState_ = RefereeState::READY;
1036     recognizer->HandleTouchMoveEvent(event);
1037     EXPECT_EQ(recognizer->refereeState_, RefereeState::READY);
1038 
1039     event.isRotationEvent = false;
1040     recognizer->refereeState_ = RefereeState::READY;
1041     recognizer->HandleTouchMoveEvent(event);
1042     EXPECT_EQ(recognizer->refereeState_, RefereeState::READY);
1043 }
1044 /**
1045  * @tc.name: RotationRecognizerHandleTouchDownEventTest004
1046  * @tc.desc: Test RotationRecognizer function with axis event input: Cancel
1047  * @tc.type: FUNC
1048  */
1049 HWTEST_F(RotationRecognizerTestNg, RotationRecognizerHandleAxisEventTest004, TestSize.Level1)
1050 {
1051     /**
1052      * @tc.steps: step1. create rotation recognizer and axis event.
1053      */
1054     AxisEvent event;
1055     RefPtr<RotationRecognizer> recognizer =
1056         AceType::MakeRefPtr<RotationRecognizer>(SINGLE_FINGER_NUMBER, ROTATION_GESTURE_ANGLE);
1057     /**
1058      * @tc.steps: step2. Test HandleTouchCancelEvent
1059      */
1060     recognizer->refereeState_ = RefereeState::READY;
1061     recognizer->HandleTouchCancelEvent(event);
1062     EXPECT_EQ(recognizer->refereeState_, RefereeState::FAIL);
1063 
1064     recognizer->refereeState_ = RefereeState::SUCCEED;
1065     recognizer->HandleTouchCancelEvent(event);
1066     EXPECT_EQ(recognizer->refereeState_, RefereeState::SUCCEED);
1067 }
1068 
1069 /**
1070  * @tc.name: SetOnActionCancelTest001
1071  * @tc.desc: Test SendCallbackMsg function in the HandleTouchCancelEvent with touch event input. The onActionCancel
1072  * function will return GestureEvent info.
1073  * @tc.type: FUNC
1074  */
1075 HWTEST_F(RotationRecognizerTestNg, SetOnActionCancelTest001, TestSize.Level1)
1076 {
1077     /**
1078      * @tc.steps: step1. Create RotationRecognizerTestNg.
1079      */
1080     RefPtr<RotationRecognizer> rotationRecognizer =
1081         AceType::MakeRefPtr<RotationRecognizer>(SINGLE_FINGER_NUMBER, ROTATION_GESTURE_ANGLE);
1082 
1083     /**
1084      * @tc.steps: step2. Call SetOnActionCancel.
1085      * @tc.expected: RotationRecognizer's callback onActionCancel is not nullptr.
1086      */
1087     rotationRecognizer->deviceId_ = GESTURE_EVENT_PROPERTY_VALUE;
1088     double unknownPropertyValue = GESTURE_EVENT_PROPERTY_DEFAULT_VALUE;
1089     auto onActionCancel = [&unknownPropertyValue](
__anon0c2a03490802( GestureEvent& info) 1090                                 GestureEvent& info) { unknownPropertyValue = info.GetDeviceId(); };
1091     rotationRecognizer->SetOnActionCancel(onActionCancel);
1092     EXPECT_NE(rotationRecognizer->onActionCancel_, nullptr);
1093 
1094     /**
1095      * @tc.steps: step3. Invoke HandleTouchCancelEvent when onActionCancel_ is not null.
1096      * @tc.expected: The functions have been executed and the unknownPropertyValue has been assigned the correct
1097      * value. rotationRecognizer->refereeState_ = RefereeState::READY
1098      */
1099     TouchEvent touchEvent;
1100     rotationRecognizer->touchPoints_[touchEvent.id] = touchEvent;
1101     rotationRecognizer->refereeState_ = RefereeState::SUCCEED;
1102     rotationRecognizer->activeFingers_.emplace_back(touchEvent.id);
1103     rotationRecognizer->activeFingers_.push_back(1);
1104     rotationRecognizer->HandleTouchCancelEvent(touchEvent);
1105     EXPECT_EQ(unknownPropertyValue, GESTURE_EVENT_PROPERTY_VALUE);
1106     EXPECT_EQ(rotationRecognizer->refereeState_, RefereeState::READY);
1107 }
1108 
1109 /**
1110  * @tc.name: SetOnActionCancelTest002
1111  * @tc.desc: Test SendCallbackMsg function in the HandleTouchCancelEvent with axis event input. The onActionCancel
1112  * function will return GestureEvent info.
1113  * @tc.type: FUNC
1114  */
1115 HWTEST_F(RotationRecognizerTestNg, SetOnActionCancelTest002, TestSize.Level1)
1116 {
1117     /**
1118      * @tc.steps: step1. Create RotationRecognizer.
1119      */
1120     RefPtr<RotationRecognizer> rotationRecognizer =
1121         AceType::MakeRefPtr<RotationRecognizer>(SINGLE_FINGER_NUMBER, ROTATION_GESTURE_ANGLE);
1122 
1123     /**
1124      * @tc.steps: step2. Call SetOnActionCancel.
1125      * @tc.expected: rotationRecognizer's callback onActionCancel is not nullptr.
1126      */
1127     rotationRecognizer->deviceId_ = GESTURE_EVENT_PROPERTY_VALUE;
1128     double unknownPropertyValue = GESTURE_EVENT_PROPERTY_DEFAULT_VALUE;
1129     auto onActionCancel = [&unknownPropertyValue](
__anon0c2a03490902( GestureEvent& info) 1130                                 GestureEvent& info) { unknownPropertyValue = info.GetDeviceId(); };
1131     rotationRecognizer->SetOnActionCancel(onActionCancel);
1132     EXPECT_NE(rotationRecognizer->onActionCancel_, nullptr);
1133 
1134     /**
1135      * @tc.steps: step3. Invoke HandleTouchCancelEvent when onActionCancel_ is not null.
1136      * @tc.expected: The functions have been executed and the unknownPropertyValue has been assigned the correct
1137      * value.
1138      */
1139     AxisEvent axisEvent;
1140     rotationRecognizer->refereeState_ = RefereeState::SUCCEED;
1141     rotationRecognizer->HandleTouchCancelEvent(axisEvent);
1142     EXPECT_EQ(unknownPropertyValue, GESTURE_EVENT_PROPERTY_VALUE);
1143 }
1144 
1145 /**
1146  * @tc.name: SetOnActionCancelTest003
1147  * @tc.desc: Test SendCallbackMsg function in the ReconcileFrom. The onActionCancel function will return
1148  * GestureEvent info.
1149  * @tc.type: FUNC
1150  */
1151 HWTEST_F(RotationRecognizerTestNg, SetOnActionCancelTest003, TestSize.Level1)
1152 {
1153     /**
1154      * @tc.steps: step1. Create RotationRecognizer.
1155      */
1156     RefPtr<RotationRecognizer> rotationRecognizer =
1157         AceType::MakeRefPtr<RotationRecognizer>(SINGLE_FINGER_NUMBER, ROTATION_GESTURE_ANGLE);
1158     RefPtr<RotationRecognizer> rotationRecognizerPtr =
1159         AceType::MakeRefPtr<RotationRecognizer>(SINGLE_FINGER_NUMBER, ROTATION_GESTURE_ANGLE);
1160 
1161     /**
1162      * @tc.steps: step2. Call SetOnActionCancel.
1163      * @tc.expected: rotationRecognizer's callback onActionCancel is not nullptr.
1164      */
1165     rotationRecognizer->deviceId_ = GESTURE_EVENT_PROPERTY_VALUE;
1166     double unknownPropertyValue = GESTURE_EVENT_PROPERTY_DEFAULT_VALUE;
1167     auto onActionCancel = [&unknownPropertyValue](
__anon0c2a03490a02( GestureEvent& info) 1168                                 GestureEvent& info) { unknownPropertyValue = info.GetDeviceId(); };
1169     rotationRecognizer->SetOnActionCancel(onActionCancel);
1170     EXPECT_NE(rotationRecognizer->onActionCancel_, nullptr);
1171 
1172     /**
1173      * @tc.steps: step3. Invoke ReconcileFrom when onActionCancel_ is not null.
1174      * @tc.expected: The functions have been executed and the unknownPropertyValue has been assigned the correct
1175      * value.
1176      */
1177     rotationRecognizer->fingers_ = 0;
1178     rotationRecognizer->refereeState_ = RefereeState::SUCCEED;
1179     rotationRecognizer->activeFingers_.push_back(1);
1180     rotationRecognizer->activeFingers_.push_back(2);
1181     auto result = rotationRecognizer->ReconcileFrom(rotationRecognizerPtr);
1182     EXPECT_EQ(unknownPropertyValue, GESTURE_EVENT_PROPERTY_VALUE);
1183     EXPECT_EQ(result, false);
1184 }
1185 
1186 /**
1187  * @tc.name: RotationGestureLimitFingerTest001
1188  * @tc.desc: Test RotationGesture CreateRecognizer function
1189  */
1190 HWTEST_F(RotationRecognizerTestNg, RotationGestureLimitFingerTest001, TestSize.Level1)
1191 {
1192     /**
1193      * @tc.steps: step1. create RotationGestureGesture.
1194      */
1195     RotationGestureModelNG rotationGestureModelNG;
1196     rotationGestureModelNG.Create(FINGER_NUMBER, ROTATION_GESTURE_ANGLE, IS_LIMIT_FINGER_COUNT);
1197 
1198     RefPtr<GestureProcessor> gestureProcessor;
1199     gestureProcessor = NG::ViewStackProcessor::GetInstance()->GetOrCreateGestureProcessor();
1200     auto rotationGestureNG = AceType::DynamicCast<NG::RotationGesture>(gestureProcessor->TopGestureNG());
1201     EXPECT_EQ(rotationGestureNG->angle_, ROTATION_GESTURE_ANGLE);
1202     EXPECT_EQ(rotationGestureNG->isLimitFingerCount_, IS_LIMIT_FINGER_COUNT);
1203 
1204     RotationGesture rotationGesture = RotationGesture(FINGER_NUMBER, ROTATION_GESTURE_ANGLE, IS_LIMIT_FINGER_COUNT);
1205     EXPECT_EQ(rotationGesture.angle_, ROTATION_GESTURE_ANGLE);
1206     EXPECT_EQ(rotationGesture.isLimitFingerCount_, IS_LIMIT_FINGER_COUNT);
1207 
1208     /**
1209      * @tc.steps: step2. call CreateRecognizer function and compare result
1210      * @tc.steps: case1: functions are not existed
1211      */
1212     rotationGesture.priority_ = GesturePriority::Low;
1213     rotationGesture.gestureMask_ = GestureMask::Normal;
1214     auto rotationRecognizer = AceType::DynamicCast<RotationRecognizer>(rotationGesture.CreateRecognizer());
1215     EXPECT_NE(rotationRecognizer, nullptr);
1216     EXPECT_EQ(rotationRecognizer->GetPriority(), GesturePriority::Low);
1217     EXPECT_EQ(rotationRecognizer->GetPriorityMask(), GestureMask::Normal);
1218     EXPECT_EQ(rotationRecognizer->isLimitFingerCount_, IS_LIMIT_FINGER_COUNT);
1219 
1220     // /**
1221     //  * @tc.steps: step2. call CreateRecognizer function and compare result
1222     //  * @tc.steps: case2: functions are existed
1223     //  */
1224     std::unique_ptr<GestureEventFunc> onActionStartId;
1225     std::unique_ptr<GestureEventFunc> onActionUpdateId;
1226     std::unique_ptr<GestureEventFunc> onActionEndId;
1227     std::unique_ptr<GestureEventFunc> onActionCancelId;
1228     rotationGesture.onActionStartId_ = std::move(onActionStartId);
1229     rotationGesture.onActionUpdateId_ = std::move(onActionUpdateId);
1230     rotationGesture.onActionEndId_ = std::move(onActionEndId);
1231     rotationGesture.onActionCancelId_ = std::move(onActionCancelId);
1232     rotationRecognizer = AceType::DynamicCast<RotationRecognizer>(rotationGesture.CreateRecognizer());
1233     EXPECT_EQ(rotationRecognizer->priority_, rotationGesture.priority_);
1234     EXPECT_EQ(rotationRecognizer->priorityMask_, rotationGesture.gestureMask_);
1235     EXPECT_EQ(rotationRecognizer->isLimitFingerCount_, IS_LIMIT_FINGER_COUNT);
1236 }
1237 
1238 /**
1239  * @tc.name: RotationGestureLimitFingerTest002
1240  * @tc.desc: Test RotationGesture CreateRecognizer function
1241  */
1242 HWTEST_F(RotationRecognizerTestNg, RotationGestureLimitFingerTest002, TestSize.Level1)
1243 {
1244     /**
1245      * @tc.steps: step1. create RotationGestureGesture.
1246      */
1247     RotationGestureModelNG rotationGestureModelNG;
1248     rotationGestureModelNG.Create(FINGER_NUMBER, ROTATION_GESTURE_ANGLE, IS_NOT_LIMIT_FINGER_COUNT);
1249 
1250     RefPtr<GestureProcessor> gestureProcessor;
1251     gestureProcessor = NG::ViewStackProcessor::GetInstance()->GetOrCreateGestureProcessor();
1252     auto rotationGestureNG = AceType::DynamicCast<NG::RotationGesture>(gestureProcessor->TopGestureNG());
1253     EXPECT_EQ(rotationGestureNG->angle_, ROTATION_GESTURE_ANGLE);
1254     EXPECT_EQ(rotationGestureNG->isLimitFingerCount_, IS_NOT_LIMIT_FINGER_COUNT);
1255 
1256     RotationGesture rotationGesture = RotationGesture(FINGER_NUMBER, ROTATION_GESTURE_ANGLE, IS_NOT_LIMIT_FINGER_COUNT);
1257     EXPECT_EQ(rotationGesture.angle_, ROTATION_GESTURE_ANGLE);
1258     EXPECT_EQ(rotationGesture.isLimitFingerCount_, IS_NOT_LIMIT_FINGER_COUNT);
1259 
1260     /**
1261      * @tc.steps: step2. call CreateRecognizer function and compare result
1262      * @tc.steps: case1: functions are not existed
1263      */
1264     rotationGesture.priority_ = GesturePriority::Low;
1265     rotationGesture.gestureMask_ = GestureMask::Normal;
1266     auto rotationRecognizer = AceType::DynamicCast<RotationRecognizer>(rotationGesture.CreateRecognizer());
1267     EXPECT_NE(rotationRecognizer, nullptr);
1268     EXPECT_EQ(rotationRecognizer->GetPriority(), GesturePriority::Low);
1269     EXPECT_EQ(rotationRecognizer->GetPriorityMask(), GestureMask::Normal);
1270     EXPECT_EQ(rotationRecognizer->isLimitFingerCount_, IS_NOT_LIMIT_FINGER_COUNT);
1271 
1272     // /**
1273     //  * @tc.steps: step2. call CreateRecognizer function and compare result
1274     //  * @tc.steps: case2: functions are existed
1275     //  */
1276     std::unique_ptr<GestureEventFunc> onActionStartId;
1277     std::unique_ptr<GestureEventFunc> onActionUpdateId;
1278     std::unique_ptr<GestureEventFunc> onActionEndId;
1279     std::unique_ptr<GestureEventFunc> onActionCancelId;
1280     rotationGesture.onActionStartId_ = std::move(onActionStartId);
1281     rotationGesture.onActionUpdateId_ = std::move(onActionUpdateId);
1282     rotationGesture.onActionEndId_ = std::move(onActionEndId);
1283     rotationGesture.onActionCancelId_ = std::move(onActionCancelId);
1284     rotationRecognizer = AceType::DynamicCast<RotationRecognizer>(rotationGesture.CreateRecognizer());
1285     EXPECT_EQ(rotationRecognizer->priority_, rotationGesture.priority_);
1286     EXPECT_EQ(rotationRecognizer->priorityMask_, rotationGesture.gestureMask_);
1287     EXPECT_EQ(rotationRecognizer->isLimitFingerCount_, IS_NOT_LIMIT_FINGER_COUNT);
1288 }
1289 
1290 } // namespace OHOS::Ace::NG