Removed TouchEvent from actor & stage
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-RotationGestureRecognizer.cpp
1 /*
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 #include <iostream>
19
20 #include <stdlib.h>
21 #include <dali/public-api/dali-core.h>
22 #include <dali/integration-api/input-options.h>
23 #include <dali/integration-api/events/touch-event-integ.h>
24 #include <dali/devel-api/events/rotation-gesture.h>
25 #include <dali/devel-api/events/rotation-gesture-detector.h>
26 #include <dali-test-suite-utils.h>
27
28
29 using namespace Dali;
30
31 void utc_dali_rotation_gesture_recognizer_startup(void)
32 {
33   test_return_value = TET_UNDEF;
34 }
35
36 void utc_dali_rotation_gesture_recognizer_cleanup(void)
37 {
38   test_return_value = TET_PASS;
39 }
40
41 ///////////////////////////////////////////////////////////////////////////////
42 namespace
43 {
44
45 struct SignalData
46 {
47   SignalData()
48   : functorCalled(false),
49     voidFunctorCalled(false),
50     receivedGesture(Gesture::Started)
51   {}
52
53   void Reset()
54   {
55     functorCalled = false;
56     voidFunctorCalled = false;
57
58     receivedGesture.state = Gesture::Started;
59     receivedGesture.rotation = 0.0f;
60     receivedGesture.screenCenterPoint = Vector2(0.0f, 0.0f);
61     receivedGesture.localCenterPoint = Vector2(0.0f, 0.0f);
62
63     rotatedActor.Reset();
64   }
65
66   bool functorCalled;
67   bool voidFunctorCalled;
68   RotationGesture receivedGesture;
69   Actor rotatedActor;
70 };
71
72 // Functor that sets the data when called
73 struct GestureReceivedFunctor
74 {
75   GestureReceivedFunctor(SignalData& data) : signalData(data) { }
76
77   void operator()(Actor actor, const RotationGesture& rotation)
78   {
79     signalData.functorCalled = true;
80     signalData.receivedGesture = rotation;
81     signalData.rotatedActor = actor;
82   }
83
84   void operator()()
85   {
86     signalData.voidFunctorCalled = true;
87   }
88
89   SignalData& signalData;
90 };
91
92 Integration::TouchEvent GenerateDoubleTouch( PointState::Type stateA, const Vector2& screenPositionA, PointState::Type stateB, const Vector2& screenPositionB, uint32_t time )
93 {
94   Integration::TouchEvent touchEvent;
95   Integration::Point point;
96   point.SetState( stateA );
97   point.SetScreenPosition( screenPositionA );
98   point.SetDeviceClass( Device::Class::TOUCH );
99   point.SetDeviceSubclass( Device::Subclass::NONE );
100   touchEvent.points.push_back( point );
101   point.SetScreenPosition( screenPositionB );
102   point.SetState( stateB);
103   touchEvent.points.push_back( point );
104   touchEvent.time = time;
105   return touchEvent;
106 }
107
108
109 } // anon namespace
110
111 ///////////////////////////////////////////////////////////////////////////////
112
113 int UtcDaliRotationGestureRecognizerMinimumTouchEvents(void)
114 {
115   TestApplication application;
116
117   Actor actor = Actor::New();
118   actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
119   actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
120   application.GetScene().Add( actor );
121
122   application.SendNotification();
123   application.Render();
124
125   SignalData data;
126   GestureReceivedFunctor functor( data );
127
128   RotationGestureDetector detector = RotationGestureDetector::New();
129   detector.Attach( actor );
130   detector.DetectedSignal().Connect( &application, functor );
131
132   // Case 1
133   // 2 touch events make a gesture begin
134   Integration::SetRotationGestureMinimumTouchEvents( 2 );
135   application.ProcessEvent( GenerateDoubleTouch( PointState::DOWN, Vector2( 20.0f, 20.0f ), PointState::DOWN, Vector2( 20.0f, 90.0f ), 150 ) );
136   application.ProcessEvent( GenerateDoubleTouch( PointState::MOTION, Vector2( 20.0f, 20.0f ), PointState::MOTION, Vector2( 90.0f, 90.0f ), 160 ) );
137
138   DALI_TEST_EQUALS( Gesture::Started, data.receivedGesture.state, TEST_LOCATION );
139   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
140   data.Reset();
141
142   // Case 2
143   // 4 touch events make a gesture begin
144   Integration::SetRotationGestureMinimumTouchEvents( 4 );
145   application.ProcessEvent( GenerateDoubleTouch( PointState::DOWN, Vector2( 20.0f, 20.0f ), PointState::DOWN, Vector2( 20.0f, 90.0f ), 150 ) );
146   application.ProcessEvent( GenerateDoubleTouch( PointState::MOTION, Vector2( 20.0f, 20.0f ), PointState::MOTION, Vector2( 90.0f, 90.0f ), 160 ) );
147
148   // Check the gesture is not detected unlike previous case
149   DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
150
151   END_TEST;
152 }
153
154 int UtcDaliRotationGestureRecognizerMinimumTouchEventsAfterStart(void)
155 {
156   TestApplication application;
157
158   Actor actor = Actor::New();
159   actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
160   actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
161   application.GetScene().Add( actor );
162
163   application.SendNotification();
164   application.Render();
165
166   SignalData data;
167   GestureReceivedFunctor functor( data );
168
169   RotationGestureDetector detector = RotationGestureDetector::New();
170   detector.Attach( actor );
171   detector.DetectedSignal().Connect( &application, functor );
172
173   // Case 1
174   // > 2 touch events make a gesture begin
175   // > 4 touch events generate gestures after begin
176   Integration::SetRotationGestureMinimumTouchEvents(2);
177   Integration::SetRotationGestureMinimumTouchEventsAfterStart(6);
178
179   application.ProcessEvent( GenerateDoubleTouch( PointState::DOWN, Vector2( 20.0f, 20.0f ), PointState::DOWN, Vector2( 20.0f, 90.0f ), 150 ) );
180   application.ProcessEvent( GenerateDoubleTouch( PointState::MOTION, Vector2( 20.0f, 20.0f ), PointState::MOTION, Vector2( 90.0f, 90.0f ), 160 ) );
181
182   DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
183   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
184
185   application.ProcessEvent( GenerateDoubleTouch( PointState::MOTION, Vector2( 20.0f, 20.0f ), PointState::MOTION, Vector2( 20.0f, 90.0f ), 170 ) );
186   application.ProcessEvent( GenerateDoubleTouch( PointState::MOTION, Vector2( 20.0f, 20.0f ), PointState::MOTION, Vector2( 20.0f, 90.0f ), 180 ) );
187   application.ProcessEvent( GenerateDoubleTouch( PointState::MOTION, Vector2( 20.0f, 20.0f ), PointState::MOTION, Vector2( 20.0f, 90.0f ), 190 ) );
188   application.ProcessEvent( GenerateDoubleTouch( PointState::MOTION, Vector2( 20.0f, 20.0f ), PointState::MOTION, Vector2( 20.0f, 90.0f ), 200 ) );
189   // > Test : not enough touch events to make the gesture state "Continuing"
190   DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
191
192   application.ProcessEvent( GenerateDoubleTouch( PointState::MOTION, Vector2( 20.0f, 20.0f ), PointState::MOTION, Vector2( 20.0f, 90.0f ), 210 ) );
193   application.ProcessEvent( GenerateDoubleTouch( PointState::MOTION, Vector2( 20.0f, 20.0f ), PointState::MOTION, Vector2( 20.0f, 90.0f ), 220 ) );
194   // > Test : 6 touch events after start make the gesture state "Continuing"
195   DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
196
197   END_TEST;
198 }