[Tizen] Add screen and client rotation itself function
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-PanGesture.cpp
1 /*
2  * Copyright (c) 2014 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-test-suite-utils.h>
23
24 using namespace Dali;
25
26 void utc_dali_pan_gesture_startup(void)
27 {
28   test_return_value = TET_UNDEF;
29 }
30
31 void utc_dali_pan_gesture_cleanup(void)
32 {
33   test_return_value = TET_PASS;
34 }
35
36
37
38 int UtcDaliPanGestureConstructor(void)
39 {
40   TestApplication application; // Reset all test adapter return codes
41
42   PanGesture gesture;
43   DALI_TEST_EQUALS(Gesture::Clear, gesture.state, TEST_LOCATION);
44   DALI_TEST_EQUALS(1u, gesture.numberOfTouches, TEST_LOCATION);
45   DALI_TEST_EQUALS(Gesture::Pan, gesture.type, TEST_LOCATION);
46
47   PanGesture gesture2(Gesture::Started);
48   DALI_TEST_EQUALS(Gesture::Started, gesture2.state, TEST_LOCATION);
49   DALI_TEST_EQUALS(1u, gesture2.numberOfTouches, TEST_LOCATION);
50   DALI_TEST_EQUALS(Gesture::Pan, gesture2.type, TEST_LOCATION);
51
52   PanGesture gesture3(Gesture::Continuing);
53   DALI_TEST_EQUALS(Gesture::Continuing, gesture3.state, TEST_LOCATION);
54   DALI_TEST_EQUALS(1u, gesture3.numberOfTouches, TEST_LOCATION);
55   DALI_TEST_EQUALS(Gesture::Pan, gesture3.type, TEST_LOCATION);
56
57   PanGesture gesture4(Gesture::Finished);
58   DALI_TEST_EQUALS(Gesture::Finished, gesture4.state, TEST_LOCATION);
59   DALI_TEST_EQUALS(1u, gesture4.numberOfTouches, TEST_LOCATION);
60   DALI_TEST_EQUALS(Gesture::Pan, gesture4.type, TEST_LOCATION);
61
62   // Test copy constructor
63   gesture4.numberOfTouches = 3u;
64
65   PanGesture pan(gesture4);
66   DALI_TEST_EQUALS(Gesture::Finished, pan.state, TEST_LOCATION);
67   DALI_TEST_EQUALS(3u, pan.numberOfTouches, TEST_LOCATION);
68   DALI_TEST_EQUALS(Gesture::Pan, pan.type, TEST_LOCATION);
69   END_TEST;
70 }
71
72 int UtcDaliPanGestureAssignment(void)
73 {
74   // Test Assignment operator
75   PanGesture gesture(Gesture::Started);
76   DALI_TEST_EQUALS(Gesture::Started, gesture.state, TEST_LOCATION);
77   DALI_TEST_EQUALS(1u, gesture.numberOfTouches, TEST_LOCATION);
78   DALI_TEST_EQUALS(Gesture::Pan, gesture.type, TEST_LOCATION);
79
80   PanGesture gesture2(Gesture::Continuing);
81   DALI_TEST_EQUALS(Gesture::Continuing, gesture2.state, TEST_LOCATION);
82   DALI_TEST_EQUALS(1u, gesture2.numberOfTouches, TEST_LOCATION);
83   DALI_TEST_EQUALS(Gesture::Pan, gesture2.type, TEST_LOCATION);
84
85   gesture2.numberOfTouches = 3u;
86
87   gesture = gesture2;
88   DALI_TEST_EQUALS(Gesture::Continuing, gesture.state, TEST_LOCATION);
89   DALI_TEST_EQUALS(3u, gesture.numberOfTouches, TEST_LOCATION);
90   DALI_TEST_EQUALS(Gesture::Pan, gesture.type, TEST_LOCATION);
91   END_TEST;
92 }
93
94 int UtcDaliPanGestureGetSpeed(void)
95 {
96   PanGesture gesture(Gesture::Started);
97   DALI_TEST_EQUALS(0.0f, gesture.GetSpeed(), TEST_LOCATION);
98
99   gesture.velocity = Vector2(3.0f, -4.0f);
100
101   DALI_TEST_EQUALS(5.0f, gesture.GetSpeed(), TEST_LOCATION);
102   END_TEST;
103 }
104
105 int UtcDaliPanGestureGetDistance(void)
106 {
107   PanGesture gesture(Gesture::Started);
108   DALI_TEST_EQUALS(0.0f, gesture.GetDistance(), TEST_LOCATION);
109
110   gesture.displacement = Vector2(-30.0f, -40.0f);
111
112   DALI_TEST_EQUALS(50.0f, gesture.GetDistance(), TEST_LOCATION);
113   END_TEST;
114 }
115
116 int UtcDaliPanGestureGetScreenSpeed(void)
117 {
118   PanGesture gesture(Gesture::Started);
119   DALI_TEST_EQUALS(0.0f, gesture.GetScreenSpeed(), TEST_LOCATION);
120
121   gesture.screenVelocity = Vector2(3.0f, -4.0f);
122
123   DALI_TEST_EQUALS(5.0f, gesture.GetScreenSpeed(), TEST_LOCATION);
124   END_TEST;
125 }
126
127 int UtcDaliPanGestureGetScreenDistance(void)
128 {
129   PanGesture gesture(Gesture::Started);
130   DALI_TEST_EQUALS(0.0f, gesture.GetScreenDistance(), TEST_LOCATION);
131
132   gesture.screenDisplacement = Vector2(-30.0f, -40.0f);
133
134   DALI_TEST_EQUALS(50.0f, gesture.GetScreenDistance(), TEST_LOCATION);
135   END_TEST;
136 }
137
138 int UtcDaliPanGestureDynamicAllocation(void)
139 {
140   PanGesture* gesture = new PanGesture( Gesture::Started );
141   DALI_TEST_EQUALS(Gesture::Started, gesture->state, TEST_LOCATION);
142   DALI_TEST_EQUALS(1u, gesture->numberOfTouches, TEST_LOCATION);
143   DALI_TEST_EQUALS(Gesture::Pan, gesture->type, TEST_LOCATION);
144   delete gesture;
145
146   END_TEST;
147 }
148
149 int UtcDaliPanGestureDetectorRegisterProperty(void)
150 {
151   TestApplication application;
152
153   GestureDetector detector = PanGestureDetector::New();
154
155   Property::Index index = detector.RegisterProperty( "sceneProperty", 0 );
156   DALI_TEST_EQUALS( index, (Property::Index)PROPERTY_CUSTOM_START_INDEX, TEST_LOCATION );
157   DALI_TEST_EQUALS( detector.GetProperty< int32_t >( index ), 0, TEST_LOCATION );
158   detector.SetProperty( index, -99 );
159
160   using Dali::Animation;
161   Animation animation = Animation::New( 1.0f );
162   animation.AnimateTo( Property( detector, index ), 99 );
163   DALI_TEST_EQUALS( detector.GetProperty< int32_t >( index ), -99, TEST_LOCATION );
164
165   // create another pan gesture
166   GestureDetector detector2 = PanGestureDetector::New();
167   DALI_TEST_EQUALS( detector2.GetProperty< int32_t >( index ), 0, TEST_LOCATION );
168
169   // Start the animation
170   animation.Play();
171   application.SendNotification();
172   application.Render( 500 /* 50% progress */);
173   DALI_TEST_EQUALS( detector.GetCurrentProperty< int32_t >( index ), 0 /*half way*/, TEST_LOCATION );
174
175   // register another pan gesture value
176   Property::Index index2 = detector2.RegisterProperty( "sceneProperty2", 12 );
177   DALI_TEST_EQUALS( index2, (Property::Index)PROPERTY_CUSTOM_START_INDEX, TEST_LOCATION );
178   DALI_TEST_EQUALS( detector2.GetProperty< int32_t >( index2 ), 12, TEST_LOCATION );
179   DALI_TEST_EQUALS( detector2.GetCurrentProperty< int32_t >( index2 ), 12, TEST_LOCATION );
180
181   DALI_TEST_EQUALS( detector.GetProperty< int32_t >( index ), 99 /*target*/, TEST_LOCATION );
182   DALI_TEST_EQUALS( detector.GetCurrentProperty< int32_t >( index ), 0, TEST_LOCATION );
183
184   Animation animation2 = Animation::New( 1.0f );
185   animation2.AnimateTo( Property( detector2, index2 ), -99 );
186   // Start the animation
187   animation2.Play();
188   application.SendNotification();
189   application.Render( 1000 /* 100% more progress */);
190
191   DALI_TEST_EQUALS( detector2.GetProperty< int32_t >( index2 ), -99, TEST_LOCATION );
192   DALI_TEST_EQUALS( detector2.GetCurrentProperty< int32_t >( index2 ), -99, TEST_LOCATION );
193
194   DALI_TEST_EQUALS( detector.GetProperty< int32_t >( index ), 99, TEST_LOCATION );
195   DALI_TEST_EQUALS( detector.GetCurrentProperty< int32_t >( index ), 99, TEST_LOCATION );
196
197   END_TEST;
198 }
199