Revert "[Tizen] Move DevelHandle::GetCurrentProperty to public"
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-AlphaFunction.cpp
1 /*
2  * Copyright (c) 2017 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/devel-api/object/handle-devel.h>
23 #include <dali-test-suite-utils.h>
24
25 using namespace Dali;
26
27 float customAlphaFunction( float progress )
28 {
29   return progress;
30 }
31
32 void utc_dali_alpha_function_startup(void)
33 {
34   test_return_value = TET_UNDEF;
35 }
36
37 void utc_dali_alpha_function_cleanup(void)
38 {
39   test_return_value = TET_PASS;
40 }
41
42 int UtcDaliAlphaFunctionDefaultConstructorP(void)
43 {
44   TestApplication application;
45   AlphaFunction alpha;
46
47   //Should return the default alpha function
48   DALI_TEST_EQUALS( alpha.GetBuiltinFunction(), AlphaFunction::DEFAULT, TEST_LOCATION);
49
50   //Check the mode is BUILTIN_FUNCTION
51   DALI_TEST_EQUALS( alpha.GetMode(), AlphaFunction::BUILTIN_FUNCTION, TEST_LOCATION);
52
53   END_TEST;
54 }
55
56 int UtcDaliAlphaFunctionConstructorFromBuiltinP(void)
57 {
58   TestApplication application;
59
60   //Construct the alpha function with a built-in function
61   AlphaFunction alpha( AlphaFunction::EASE_IN_OUT);
62
63   //Check if the built-in alpha function is EASE_IN_OUT
64   DALI_TEST_EQUALS( alpha.GetBuiltinFunction(), AlphaFunction::EASE_IN_OUT, TEST_LOCATION);
65
66   //Check the mode is BUILTIN_FUNCTION
67   DALI_TEST_EQUALS( alpha.GetMode(), AlphaFunction::BUILTIN_FUNCTION, TEST_LOCATION);
68
69   END_TEST;
70 }
71
72 int UtcDaliAlphaFunctionConstructorFromFunctionPointerdP(void)
73 {
74   TestApplication application;
75
76   //Construct the alpha function with a function pointer
77   AlphaFunction alpha( &customAlphaFunction );
78
79   //Check that the custom function points to the custom alpha function
80   DALI_TEST_EQUALS( alpha.GetCustomFunction(), &customAlphaFunction, TEST_LOCATION);
81
82   //Check the mode is CUSTOM_FUNCTION
83   DALI_TEST_EQUALS( alpha.GetMode(), AlphaFunction::CUSTOM_FUNCTION, TEST_LOCATION);
84
85
86   END_TEST;
87 }
88
89 int UtcDaliAlphaFunctionConstructorFromControlPointsP(void)
90 {
91   TestApplication application;
92
93   //Construct the alpha function with two control points
94   Vector2 controlPoint0 = Vector2(0.0f,1.0f);
95   Vector2 controlPoint1 = Vector2(1.0f,0.0f);
96   AlphaFunction alpha(controlPoint0,controlPoint1);
97
98   //Check if the control points have the correct value
99   Vector4 controlPoints = alpha.GetBezierControlPoints();
100   DALI_TEST_EQUALS( Vector2(controlPoints.x,controlPoints.y), controlPoint0, TEST_LOCATION);
101   DALI_TEST_EQUALS( Vector2(controlPoints.z,controlPoints.w), controlPoint1, TEST_LOCATION);
102
103   //Check the mode is BEZIER
104   DALI_TEST_EQUALS( alpha.GetMode(), AlphaFunction::BEZIER, TEST_LOCATION);
105
106   END_TEST;
107 }
108
109 int UtcDaliAlphaFunctionConstructorFromControlPointsN(void)
110 {
111   TestApplication application;
112
113   //Construct the alpha function with two control points
114   Vector2 controlPoint0 = Vector2(-10.0f,1.0f);
115   Vector2 controlPoint1 = Vector2(10.0f,0.0f);
116   AlphaFunction alpha(controlPoint0,controlPoint1);
117
118   //x components of the control points should have been clamped to [0,1] to ensure the curve is monotonic
119   Vector4 controlPoints = alpha.GetBezierControlPoints();
120   DALI_TEST_EQUALS( Vector2(controlPoints.x,controlPoints.y), Vector2(0.0f,1.0f), TEST_LOCATION);
121   DALI_TEST_EQUALS( Vector2(controlPoints.z,controlPoints.w), Vector2(1.0f,0.0f), TEST_LOCATION);
122
123   //Check the mode is BEZIER
124   DALI_TEST_EQUALS( alpha.GetMode(), AlphaFunction::BEZIER, TEST_LOCATION);
125
126   END_TEST;
127 }
128
129 int UtcDaliAlphaFunctionGetBuiltinFunctionP(void)
130 {
131   TestApplication application;
132   AlphaFunction alpha( AlphaFunction::EASE_IN);
133
134   //Check if the builtin alpha function is EASE_IN
135   DALI_TEST_EQUALS( alpha.GetBuiltinFunction(), AlphaFunction::EASE_IN, TEST_LOCATION);
136
137   //Check the mode is BUILTIN_FUNCTION
138   DALI_TEST_EQUALS( alpha.GetMode(), AlphaFunction::BUILTIN_FUNCTION, TEST_LOCATION);
139
140   END_TEST;
141 }
142
143 int UtcDaliAlphaFunctionGetCustomFunctionP(void)
144 {
145   TestApplication application;
146   AlphaFunction alpha( &customAlphaFunction );
147
148   //Check that the custom function points to the custom alpha function
149   DALI_TEST_EQUALS( alpha.GetCustomFunction(), &customAlphaFunction, TEST_LOCATION);
150
151   //Check the mode is CUSTOM_FUNCTION
152   DALI_TEST_EQUALS( alpha.GetMode(), AlphaFunction::CUSTOM_FUNCTION, TEST_LOCATION);
153
154   END_TEST;
155 }
156
157 int UtcDaliAlphaFunctionGetControlPointsFunctionP(void)
158 {
159   TestApplication application;
160
161   Vector2 controlPoint0 = Vector2(0.0f,1.0f);
162   Vector2 controlPoint1 = Vector2(1.0f,0.0f);
163   AlphaFunction alpha( controlPoint0,controlPoint1 );
164
165   //Check if the control points have the correct value
166   Vector4 controlPoints = alpha.GetBezierControlPoints();
167   DALI_TEST_EQUALS( Vector2(controlPoints.x,controlPoints.y), controlPoint0, TEST_LOCATION);
168   DALI_TEST_EQUALS( Vector2(controlPoints.z,controlPoints.w), controlPoint1, TEST_LOCATION);
169
170   //Check the mode is BEZIER
171   DALI_TEST_EQUALS( alpha.GetMode(), AlphaFunction::BEZIER, TEST_LOCATION);
172
173   END_TEST;
174 }
175
176 int UtcDaliAlphaFunctionGetModeP(void)
177 {
178   TestApplication application;
179
180   //Create alpha function using a built-in function
181   AlphaFunction alphaBuiltin( AlphaFunction::EASE_IN);
182
183   //Check the mode is BUILTIN_FUNCTION
184   DALI_TEST_EQUALS( alphaBuiltin.GetMode(), AlphaFunction::BUILTIN_FUNCTION, TEST_LOCATION);
185
186   //Create alpha function with pointer to function
187   AlphaFunction alphaCustom( &customAlphaFunction );
188   //Check the mode is CUSTOM_FUNCTION
189   DALI_TEST_EQUALS( alphaCustom.GetMode(), AlphaFunction::CUSTOM_FUNCTION, TEST_LOCATION);
190
191   //Create alpha function with control points
192   Vector2 controlPoint0 = Vector2(0.0f,1.0f);
193   Vector2 controlPoint1 = Vector2(1.0f,0.0f);
194   AlphaFunction alphaBezier( controlPoint0,controlPoint1 );
195   //Check the mode is BEZIER
196   DALI_TEST_EQUALS( alphaBezier.GetMode(), AlphaFunction::BEZIER, TEST_LOCATION);
197
198   END_TEST;
199 }
200
201 int UtcDaliAlphaFunctionBezier(void)
202 {
203   TestApplication application;
204
205   Actor actor = Actor::New();
206
207   // Register a float property
208   float startValue(0.0f);
209   Property::Index index = actor.RegisterProperty( "testProperty",  startValue );
210   Stage::GetCurrent().Add(actor);
211   DALI_TEST_EQUALS( actor.GetProperty<float>(index), startValue, TEST_LOCATION );
212
213   // Build the animation
214   float durationSeconds(1.0f);
215   Animation animation = Animation::New(durationSeconds);
216   float targetValue(1.0f);
217
218   Vector2 controlPoint0 = Vector2(0.25f,0.5f);
219   Vector2 controlPoint1 = Vector2(0.75f,0.5f);
220   animation.AnimateTo(Property(actor, "testProperty"), targetValue, AlphaFunction(controlPoint0,controlPoint1));
221
222   // Start the animation
223   animation.Play();
224
225   application.SendNotification();
226   application.Render(static_cast<unsigned int>(durationSeconds*200.0f)/* 20% progress */);
227   application.SendNotification();
228   float epsilon(0.01f);
229   DALI_TEST_EQUALS( DevelHandle::GetCurrentProperty< float >( actor, index ), 0.271964f, epsilon, TEST_LOCATION );
230
231   application.SendNotification();
232   application.Render(static_cast<unsigned int>(durationSeconds*200.0f) + 1u/*40% progress*/);
233   application.SendNotification();
234   DALI_TEST_EQUALS( DevelHandle::GetCurrentProperty< float >( actor, index ), 0.432387f, epsilon, TEST_LOCATION );
235
236   application.SendNotification();
237   application.Render(static_cast<unsigned int>(durationSeconds*200.0f) + 1u/*60% progress*/);
238   application.SendNotification();
239   DALI_TEST_EQUALS( DevelHandle::GetCurrentProperty< float >( actor, index ), 0.567613f, epsilon, TEST_LOCATION );
240
241   application.SendNotification();
242   application.Render(static_cast<unsigned int>(durationSeconds*200.0f) + 1u/*80% progress*/);
243   application.SendNotification();
244   DALI_TEST_EQUALS( DevelHandle::GetCurrentProperty< float >( actor, index ), 0.728037f, epsilon, TEST_LOCATION );
245
246   application.SendNotification();
247   application.Render(static_cast<unsigned int>(durationSeconds*200.0f) + 1u/*just beyond the animation duration*/);
248   application.SendNotification();
249   DALI_TEST_EQUALS( DevelHandle::GetCurrentProperty< float >( actor, index ), targetValue, TEST_LOCATION );
250
251   END_TEST;
252 }
253