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