2 * Copyright (c) 2015 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-test-suite-utils.h>
26 float customAlphaFunction( float progress )
31 void utc_dali_alpha_function_startup(void)
33 test_return_value = TET_UNDEF;
36 void utc_dali_alpha_function_cleanup(void)
38 test_return_value = TET_PASS;
41 int UtcDaliAlphaFunctionDefaultConstructorP(void)
43 TestApplication application;
46 //Should return the default alpha function
47 DALI_TEST_EQUALS( alpha.GetBuiltinFunction(), AlphaFunction::DEFAULT, TEST_LOCATION);
49 //Check the mode is BUILTIN_FUNCTION
50 DALI_TEST_EQUALS( alpha.GetMode(), AlphaFunction::BUILTIN_FUNCTION, TEST_LOCATION);
55 int UtcDaliAlphaFunctionConstructorFromBuiltinP(void)
57 TestApplication application;
59 //Construct the alpha function with a built-in function
60 AlphaFunction alpha( AlphaFunction::EASE_IN_OUT);
62 //Check if the built-in alpha function is EASE_IN_OUT
63 DALI_TEST_EQUALS( alpha.GetBuiltinFunction(), AlphaFunction::EASE_IN_OUT, TEST_LOCATION);
65 //Check the mode is BUILTIN_FUNCTION
66 DALI_TEST_EQUALS( alpha.GetMode(), AlphaFunction::BUILTIN_FUNCTION, TEST_LOCATION);
71 int UtcDaliAlphaFunctionConstructorFromFunctionPointerdP(void)
73 TestApplication application;
75 //Construct the alpha function with a function pointer
76 AlphaFunction alpha( &customAlphaFunction );
78 //Check that the custom function points to the custom alpha function
79 DALI_TEST_EQUALS( alpha.GetCustomFunction(), &customAlphaFunction, TEST_LOCATION);
81 //Check the mode is CUSTOM_FUNCTION
82 DALI_TEST_EQUALS( alpha.GetMode(), AlphaFunction::CUSTOM_FUNCTION, TEST_LOCATION);
88 int UtcDaliAlphaFunctionConstructorFromControlPointsP(void)
90 TestApplication application;
92 //Construct the alpha function with two control points
93 Vector2 controlPoint0 = Vector2(0.0f,1.0f);
94 Vector2 controlPoint1 = Vector2(1.0f,0.0f);
95 AlphaFunction alpha(controlPoint0,controlPoint1);
97 //Check if the control points have the correct value
98 Vector4 controlPoints = alpha.GetBezierControlPoints();
99 DALI_TEST_EQUALS( Vector2(controlPoints.x,controlPoints.y), controlPoint0, TEST_LOCATION);
100 DALI_TEST_EQUALS( Vector2(controlPoints.z,controlPoints.w), controlPoint1, TEST_LOCATION);
102 //Check the mode is BEZIER
103 DALI_TEST_EQUALS( alpha.GetMode(), AlphaFunction::BEZIER, TEST_LOCATION);
108 int UtcDaliAlphaFunctionConstructorFromControlPointsN(void)
110 TestApplication application;
112 //Construct the alpha function with two control points
113 Vector2 controlPoint0 = Vector2(-10.0f,1.0f);
114 Vector2 controlPoint1 = Vector2(10.0f,0.0f);
115 AlphaFunction alpha(controlPoint0,controlPoint1);
117 //x components of the control points should have been clamped to [0,1] to ensure the curve is monotonic
118 Vector4 controlPoints = alpha.GetBezierControlPoints();
119 DALI_TEST_EQUALS( Vector2(controlPoints.x,controlPoints.y), Vector2(0.0f,1.0f), TEST_LOCATION);
120 DALI_TEST_EQUALS( Vector2(controlPoints.z,controlPoints.w), Vector2(1.0f,0.0f), TEST_LOCATION);
122 //Check the mode is BEZIER
123 DALI_TEST_EQUALS( alpha.GetMode(), AlphaFunction::BEZIER, TEST_LOCATION);
128 int UtcDaliAlphaFunctionGetBuiltinFunctionP(void)
130 TestApplication application;
131 AlphaFunction alpha( AlphaFunction::EASE_IN);
133 //Check if the builtin alpha function is EASE_IN
134 DALI_TEST_EQUALS( alpha.GetBuiltinFunction(), AlphaFunction::EASE_IN, TEST_LOCATION);
136 //Check the mode is BUILTIN_FUNCTION
137 DALI_TEST_EQUALS( alpha.GetMode(), AlphaFunction::BUILTIN_FUNCTION, TEST_LOCATION);
142 int UtcDaliAlphaFunctionGetCustomFunctionP(void)
144 TestApplication application;
145 AlphaFunction alpha( &customAlphaFunction );
147 //Check that the custom function points to the custom alpha function
148 DALI_TEST_EQUALS( alpha.GetCustomFunction(), &customAlphaFunction, TEST_LOCATION);
150 //Check the mode is CUSTOM_FUNCTION
151 DALI_TEST_EQUALS( alpha.GetMode(), AlphaFunction::CUSTOM_FUNCTION, TEST_LOCATION);
156 int UtcDaliAlphaFunctionGetControlPointsFunctionP(void)
158 TestApplication application;
160 Vector2 controlPoint0 = Vector2(0.0f,1.0f);
161 Vector2 controlPoint1 = Vector2(1.0f,0.0f);
162 AlphaFunction alpha( controlPoint0,controlPoint1 );
164 //Check if the control points have the correct value
165 Vector4 controlPoints = alpha.GetBezierControlPoints();
166 DALI_TEST_EQUALS( Vector2(controlPoints.x,controlPoints.y), controlPoint0, TEST_LOCATION);
167 DALI_TEST_EQUALS( Vector2(controlPoints.z,controlPoints.w), controlPoint1, TEST_LOCATION);
169 //Check the mode is BEZIER
170 DALI_TEST_EQUALS( alpha.GetMode(), AlphaFunction::BEZIER, TEST_LOCATION);
175 int UtcDaliAlphaFunctionGetModeP(void)
177 TestApplication application;
179 //Create alpha function using a built-in function
180 AlphaFunction alphaBuiltin( AlphaFunction::EASE_IN);
182 //Check the mode is BUILTIN_FUNCTION
183 DALI_TEST_EQUALS( alphaBuiltin.GetMode(), AlphaFunction::BUILTIN_FUNCTION, TEST_LOCATION);
185 //Create alpha function with pointer to function
186 AlphaFunction alphaCustom( &customAlphaFunction );
187 //Check the mode is CUSTOM_FUNCTION
188 DALI_TEST_EQUALS( alphaCustom.GetMode(), AlphaFunction::CUSTOM_FUNCTION, TEST_LOCATION);
190 //Create alpha function with control points
191 Vector2 controlPoint0 = Vector2(0.0f,1.0f);
192 Vector2 controlPoint1 = Vector2(1.0f,0.0f);
193 AlphaFunction alphaBezier( controlPoint0,controlPoint1 );
194 //Check the mode is BEZIER
195 DALI_TEST_EQUALS( alphaBezier.GetMode(), AlphaFunction::BEZIER, TEST_LOCATION);
200 int UtcDaliAlphaFunctionBezier(void)
202 TestApplication application;
204 Actor actor = Actor::New();
206 // Register a float property
207 float startValue(0.0f);
208 Property::Index index = actor.RegisterProperty( "testProperty", startValue );
209 Stage::GetCurrent().Add(actor);
210 DALI_TEST_EQUALS( actor.GetProperty<float>(index), startValue, TEST_LOCATION );
212 // Build the animation
213 float durationSeconds(1.0f);
214 Animation animation = Animation::New(durationSeconds);
215 float targetValue(1.0f);
217 Vector2 controlPoint0 = Vector2(0.25f,0.5f);
218 Vector2 controlPoint1 = Vector2(0.75f,0.5f);
219 animation.AnimateTo(Property(actor, "testProperty"), targetValue, AlphaFunction(controlPoint0,controlPoint1));
221 // Start the animation
224 application.SendNotification();
225 application.Render(static_cast<unsigned int>(durationSeconds*200.0f)/* 20% progress */);
226 application.SendNotification();
227 float epsilon(0.01f);
228 DALI_TEST_EQUALS( actor.GetProperty<float>(index), 0.271964f, epsilon, TEST_LOCATION );
230 application.SendNotification();
231 application.Render(static_cast<unsigned int>(durationSeconds*200.0f) + 1u/*40% progress*/);
232 application.SendNotification();
233 DALI_TEST_EQUALS( actor.GetProperty<float>(index), 0.432387f, epsilon, TEST_LOCATION );
235 application.SendNotification();
236 application.Render(static_cast<unsigned int>(durationSeconds*200.0f) + 1u/*60% progress*/);
237 application.SendNotification();
238 DALI_TEST_EQUALS( actor.GetProperty<float>(index), 0.567613f, epsilon, TEST_LOCATION );
240 application.SendNotification();
241 application.Render(static_cast<unsigned int>(durationSeconds*200.0f) + 1u/*80% progress*/);
242 application.SendNotification();
243 DALI_TEST_EQUALS( actor.GetProperty<float>(index), 0.728037f, epsilon, TEST_LOCATION );
245 application.SendNotification();
246 application.Render(static_cast<unsigned int>(durationSeconds*200.0f) + 1u/*just beyond the animation duration*/);
247 application.SendNotification();
248 DALI_TEST_EQUALS( actor.GetProperty<float>(index), targetValue, TEST_LOCATION );