2 * Copyright (c) 2017 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/devel-api/object/handle-devel.h>
23 #include <dali-test-suite-utils.h>
27 float customAlphaFunction( float progress )
32 void utc_dali_alpha_function_startup(void)
34 test_return_value = TET_UNDEF;
37 void utc_dali_alpha_function_cleanup(void)
39 test_return_value = TET_PASS;
42 int UtcDaliAlphaFunctionDefaultConstructorP(void)
44 TestApplication application;
47 //Should return the default alpha function
48 DALI_TEST_EQUALS( alpha.GetBuiltinFunction(), AlphaFunction::DEFAULT, TEST_LOCATION);
50 //Check the mode is BUILTIN_FUNCTION
51 DALI_TEST_EQUALS( alpha.GetMode(), AlphaFunction::BUILTIN_FUNCTION, TEST_LOCATION);
56 int UtcDaliAlphaFunctionConstructorFromBuiltinP(void)
58 TestApplication application;
60 //Construct the alpha function with a built-in function
61 AlphaFunction alpha( AlphaFunction::EASE_IN_OUT);
63 //Check if the built-in alpha function is EASE_IN_OUT
64 DALI_TEST_EQUALS( alpha.GetBuiltinFunction(), AlphaFunction::EASE_IN_OUT, TEST_LOCATION);
66 //Check the mode is BUILTIN_FUNCTION
67 DALI_TEST_EQUALS( alpha.GetMode(), AlphaFunction::BUILTIN_FUNCTION, TEST_LOCATION);
72 int UtcDaliAlphaFunctionConstructorFromFunctionPointerdP(void)
74 TestApplication application;
76 //Construct the alpha function with a function pointer
77 AlphaFunction alpha( &customAlphaFunction );
79 //Check that the custom function points to the custom alpha function
80 DALI_TEST_EQUALS( alpha.GetCustomFunction(), &customAlphaFunction, TEST_LOCATION);
82 //Check the mode is CUSTOM_FUNCTION
83 DALI_TEST_EQUALS( alpha.GetMode(), AlphaFunction::CUSTOM_FUNCTION, TEST_LOCATION);
89 int UtcDaliAlphaFunctionConstructorFromControlPointsP(void)
91 TestApplication application;
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);
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);
103 //Check the mode is BEZIER
104 DALI_TEST_EQUALS( alpha.GetMode(), AlphaFunction::BEZIER, TEST_LOCATION);
109 int UtcDaliAlphaFunctionConstructorFromControlPointsN(void)
111 TestApplication application;
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);
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);
123 //Check the mode is BEZIER
124 DALI_TEST_EQUALS( alpha.GetMode(), AlphaFunction::BEZIER, TEST_LOCATION);
129 int UtcDaliAlphaFunctionGetBuiltinFunctionP(void)
131 TestApplication application;
132 AlphaFunction alpha( AlphaFunction::EASE_IN);
134 //Check if the builtin alpha function is EASE_IN
135 DALI_TEST_EQUALS( alpha.GetBuiltinFunction(), AlphaFunction::EASE_IN, TEST_LOCATION);
137 //Check the mode is BUILTIN_FUNCTION
138 DALI_TEST_EQUALS( alpha.GetMode(), AlphaFunction::BUILTIN_FUNCTION, TEST_LOCATION);
143 int UtcDaliAlphaFunctionGetCustomFunctionP(void)
145 TestApplication application;
146 AlphaFunction alpha( &customAlphaFunction );
148 //Check that the custom function points to the custom alpha function
149 DALI_TEST_EQUALS( alpha.GetCustomFunction(), &customAlphaFunction, TEST_LOCATION);
151 //Check the mode is CUSTOM_FUNCTION
152 DALI_TEST_EQUALS( alpha.GetMode(), AlphaFunction::CUSTOM_FUNCTION, TEST_LOCATION);
157 int UtcDaliAlphaFunctionGetControlPointsFunctionP(void)
159 TestApplication application;
161 Vector2 controlPoint0 = Vector2(0.0f,1.0f);
162 Vector2 controlPoint1 = Vector2(1.0f,0.0f);
163 AlphaFunction alpha( controlPoint0,controlPoint1 );
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);
170 //Check the mode is BEZIER
171 DALI_TEST_EQUALS( alpha.GetMode(), AlphaFunction::BEZIER, TEST_LOCATION);
176 int UtcDaliAlphaFunctionGetModeP(void)
178 TestApplication application;
180 //Create alpha function using a built-in function
181 AlphaFunction alphaBuiltin( AlphaFunction::EASE_IN);
183 //Check the mode is BUILTIN_FUNCTION
184 DALI_TEST_EQUALS( alphaBuiltin.GetMode(), AlphaFunction::BUILTIN_FUNCTION, TEST_LOCATION);
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);
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);
201 int UtcDaliAlphaFunctionBezier(void)
203 TestApplication application;
205 Actor actor = Actor::New();
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 );
213 // Build the animation
214 float durationSeconds(1.0f);
215 Animation animation = Animation::New(durationSeconds);
216 float targetValue(1.0f);
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));
222 // Start the animation
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 );
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 );
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 );
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 );
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 );