2 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
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-test-suite-utils.h>
29 void utc_dali_rotation_gesture_recognizer_startup(void)
31 test_return_value = TET_UNDEF;
34 void utc_dali_rotation_gesture_recognizer_cleanup(void)
36 test_return_value = TET_PASS;
39 ///////////////////////////////////////////////////////////////////////////////
46 : functorCalled(false),
47 voidFunctorCalled(false),
48 receivedGesture(Gesture::Started)
53 functorCalled = false;
54 voidFunctorCalled = false;
56 receivedGesture.state = Gesture::Started;
57 receivedGesture.rotation = 0.0f;
58 receivedGesture.screenCenterPoint = Vector2(0.0f, 0.0f);
59 receivedGesture.localCenterPoint = Vector2(0.0f, 0.0f);
65 bool voidFunctorCalled;
66 RotationGesture receivedGesture;
70 // Functor that sets the data when called
71 struct GestureReceivedFunctor
73 GestureReceivedFunctor(SignalData& data) : signalData(data) { }
75 void operator()(Actor actor, const RotationGesture& rotation)
77 signalData.functorCalled = true;
78 signalData.receivedGesture = rotation;
79 signalData.rotatedActor = actor;
84 signalData.voidFunctorCalled = true;
87 SignalData& signalData;
90 Integration::TouchEvent GenerateDoubleTouch( PointState::Type stateA, const Vector2& screenPositionA, PointState::Type stateB, const Vector2& screenPositionB, uint32_t time )
92 Integration::TouchEvent touchEvent;
93 Integration::Point point;
94 point.SetState( stateA );
95 point.SetScreenPosition( screenPositionA );
96 point.SetDeviceClass( Device::Class::TOUCH );
97 point.SetDeviceSubclass( Device::Subclass::NONE );
98 touchEvent.points.push_back( point );
99 point.SetScreenPosition( screenPositionB );
100 point.SetState( stateB);
101 touchEvent.points.push_back( point );
102 touchEvent.time = time;
109 ///////////////////////////////////////////////////////////////////////////////
111 int UtcDaliRotationGestureRecognizerMinimumTouchEvents(void)
113 TestApplication application;
115 Actor actor = Actor::New();
116 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
117 actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
118 application.GetScene().Add( actor );
120 application.SendNotification();
121 application.Render();
124 GestureReceivedFunctor functor( data );
126 RotationGestureDetector detector = RotationGestureDetector::New();
127 detector.Attach( actor );
128 detector.DetectedSignal().Connect( &application, functor );
131 // 2 touch events make a gesture begin
132 Integration::SetRotationGestureMinimumTouchEvents( 2 );
133 application.ProcessEvent( GenerateDoubleTouch( PointState::DOWN, Vector2( 20.0f, 20.0f ), PointState::DOWN, Vector2( 20.0f, 90.0f ), 150 ) );
134 application.ProcessEvent( GenerateDoubleTouch( PointState::MOTION, Vector2( 20.0f, 20.0f ), PointState::MOTION, Vector2( 90.0f, 90.0f ), 160 ) );
136 DALI_TEST_EQUALS( Gesture::Started, data.receivedGesture.state, TEST_LOCATION );
137 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
141 // 4 touch events make a gesture begin
142 Integration::SetRotationGestureMinimumTouchEvents( 4 );
143 application.ProcessEvent( GenerateDoubleTouch( PointState::DOWN, Vector2( 20.0f, 20.0f ), PointState::DOWN, Vector2( 20.0f, 90.0f ), 150 ) );
144 application.ProcessEvent( GenerateDoubleTouch( PointState::MOTION, Vector2( 20.0f, 20.0f ), PointState::MOTION, Vector2( 90.0f, 90.0f ), 160 ) );
146 // Check the gesture is not detected unlike previous case
147 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
152 int UtcDaliRotationGestureRecognizerMinimumTouchEventsAfterStart(void)
154 TestApplication application;
156 Actor actor = Actor::New();
157 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
158 actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
159 application.GetScene().Add( actor );
161 application.SendNotification();
162 application.Render();
165 GestureReceivedFunctor functor( data );
167 RotationGestureDetector detector = RotationGestureDetector::New();
168 detector.Attach( actor );
169 detector.DetectedSignal().Connect( &application, functor );
172 // > 2 touch events make a gesture begin
173 // > 4 touch events generate gestures after begin
174 Integration::SetRotationGestureMinimumTouchEvents(2);
175 Integration::SetRotationGestureMinimumTouchEventsAfterStart(6);
177 application.ProcessEvent( GenerateDoubleTouch( PointState::DOWN, Vector2( 20.0f, 20.0f ), PointState::DOWN, Vector2( 20.0f, 90.0f ), 150 ) );
178 application.ProcessEvent( GenerateDoubleTouch( PointState::MOTION, Vector2( 20.0f, 20.0f ), PointState::MOTION, Vector2( 90.0f, 90.0f ), 160 ) );
180 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
181 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
183 application.ProcessEvent( GenerateDoubleTouch( PointState::MOTION, Vector2( 20.0f, 20.0f ), PointState::MOTION, Vector2( 20.0f, 90.0f ), 170 ) );
184 application.ProcessEvent( GenerateDoubleTouch( PointState::MOTION, Vector2( 20.0f, 20.0f ), PointState::MOTION, Vector2( 20.0f, 90.0f ), 180 ) );
185 application.ProcessEvent( GenerateDoubleTouch( PointState::MOTION, Vector2( 20.0f, 20.0f ), PointState::MOTION, Vector2( 20.0f, 90.0f ), 190 ) );
186 application.ProcessEvent( GenerateDoubleTouch( PointState::MOTION, Vector2( 20.0f, 20.0f ), PointState::MOTION, Vector2( 20.0f, 90.0f ), 200 ) );
187 // > Test : not enough touch events to make the gesture state "Continuing"
188 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
190 application.ProcessEvent( GenerateDoubleTouch( PointState::MOTION, Vector2( 20.0f, 20.0f ), PointState::MOTION, Vector2( 20.0f, 90.0f ), 210 ) );
191 application.ProcessEvent( GenerateDoubleTouch( PointState::MOTION, Vector2( 20.0f, 20.0f ), PointState::MOTION, Vector2( 20.0f, 90.0f ), 220 ) );
192 // > Test : 6 touch events after start make the gesture state "Continuing"
193 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);