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.
18 #include <dali-test-suite-utils.h>
19 #include <dali/public-api/dali-core.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);
87 int UtcDaliAlphaFunctionConstructorFromControlPointsP(void)
89 TestApplication application;
91 //Construct the alpha function with two control points
92 Vector2 controlPoint0 = Vector2(0.0f, 1.0f);
93 Vector2 controlPoint1 = Vector2(1.0f, 0.0f);
94 AlphaFunction alpha(controlPoint0, controlPoint1);
96 //Check if the control points have the correct value
97 Vector4 controlPoints = alpha.GetBezierControlPoints();
98 DALI_TEST_EQUALS(Vector2(controlPoints.x, controlPoints.y), controlPoint0, TEST_LOCATION);
99 DALI_TEST_EQUALS(Vector2(controlPoints.z, controlPoints.w), controlPoint1, TEST_LOCATION);
101 //Check the mode is BEZIER
102 DALI_TEST_EQUALS(alpha.GetMode(), AlphaFunction::BEZIER, TEST_LOCATION);
107 int UtcDaliAlphaFunctionConstructorFromControlPointsN(void)
109 TestApplication application;
111 //Construct the alpha function with two control points
112 Vector2 controlPoint0 = Vector2(-10.0f, 1.0f);
113 Vector2 controlPoint1 = Vector2(10.0f, 0.0f);
114 AlphaFunction alpha(controlPoint0, controlPoint1);
116 //x components of the control points should have been clamped to [0,1] to ensure the curve is monotonic
117 Vector4 controlPoints = alpha.GetBezierControlPoints();
118 DALI_TEST_EQUALS(Vector2(controlPoints.x, controlPoints.y), Vector2(0.0f, 1.0f), TEST_LOCATION);
119 DALI_TEST_EQUALS(Vector2(controlPoints.z, controlPoints.w), Vector2(1.0f, 0.0f), TEST_LOCATION);
121 //Check the mode is BEZIER
122 DALI_TEST_EQUALS(alpha.GetMode(), AlphaFunction::BEZIER, TEST_LOCATION);
127 int UtcDaliAlphaFunctionGetBuiltinFunctionP(void)
129 TestApplication application;
130 AlphaFunction alpha(AlphaFunction::EASE_IN);
132 //Check if the builtin alpha function is EASE_IN
133 DALI_TEST_EQUALS(alpha.GetBuiltinFunction(), AlphaFunction::EASE_IN, TEST_LOCATION);
135 //Check the mode is BUILTIN_FUNCTION
136 DALI_TEST_EQUALS(alpha.GetMode(), AlphaFunction::BUILTIN_FUNCTION, TEST_LOCATION);
141 int UtcDaliAlphaFunctionGetCustomFunctionP(void)
143 TestApplication application;
144 AlphaFunction alpha(&customAlphaFunction);
146 //Check that the custom function points to the custom alpha function
147 DALI_TEST_EQUALS(alpha.GetCustomFunction(), &customAlphaFunction, TEST_LOCATION);
149 //Check the mode is CUSTOM_FUNCTION
150 DALI_TEST_EQUALS(alpha.GetMode(), AlphaFunction::CUSTOM_FUNCTION, TEST_LOCATION);
155 int UtcDaliAlphaFunctionGetControlPointsFunctionP(void)
157 TestApplication application;
159 Vector2 controlPoint0 = Vector2(0.0f, 1.0f);
160 Vector2 controlPoint1 = Vector2(1.0f, 0.0f);
161 AlphaFunction alpha(controlPoint0, controlPoint1);
163 //Check if the control points have the correct value
164 Vector4 controlPoints = alpha.GetBezierControlPoints();
165 DALI_TEST_EQUALS(Vector2(controlPoints.x, controlPoints.y), controlPoint0, TEST_LOCATION);
166 DALI_TEST_EQUALS(Vector2(controlPoints.z, controlPoints.w), controlPoint1, TEST_LOCATION);
168 //Check the mode is BEZIER
169 DALI_TEST_EQUALS(alpha.GetMode(), AlphaFunction::BEZIER, TEST_LOCATION);
174 int UtcDaliAlphaFunctionGetModeP(void)
176 TestApplication application;
178 //Create alpha function using a built-in function
179 AlphaFunction alphaBuiltin(AlphaFunction::EASE_IN);
181 //Check the mode is BUILTIN_FUNCTION
182 DALI_TEST_EQUALS(alphaBuiltin.GetMode(), AlphaFunction::BUILTIN_FUNCTION, TEST_LOCATION);
184 //Create alpha function with pointer to function
185 AlphaFunction alphaCustom(&customAlphaFunction);
186 //Check the mode is CUSTOM_FUNCTION
187 DALI_TEST_EQUALS(alphaCustom.GetMode(), AlphaFunction::CUSTOM_FUNCTION, TEST_LOCATION);
189 //Create alpha function with control points
190 Vector2 controlPoint0 = Vector2(0.0f, 1.0f);
191 Vector2 controlPoint1 = Vector2(1.0f, 0.0f);
192 AlphaFunction alphaBezier(controlPoint0, controlPoint1);
193 //Check the mode is BEZIER
194 DALI_TEST_EQUALS(alphaBezier.GetMode(), AlphaFunction::BEZIER, TEST_LOCATION);
199 int UtcDaliAlphaFunctionBezier(void)
201 TestApplication application;
203 Actor actor = Actor::New();
205 // Register a float property
206 float startValue(0.0f);
207 Property::Index index = actor.RegisterProperty("testProperty", startValue);
208 application.GetScene().Add(actor);
209 DALI_TEST_EQUALS(actor.GetProperty<float>(index), startValue, TEST_LOCATION);
211 // Build the animation
212 float durationSeconds(1.0f);
213 Animation animation = Animation::New(durationSeconds);
214 float targetValue(1.0f);
216 Vector2 controlPoint0 = Vector2(0.25f, 0.5f);
217 Vector2 controlPoint1 = Vector2(0.75f, 0.5f);
218 animation.AnimateTo(Property(actor, "testProperty"), targetValue, AlphaFunction(controlPoint0, controlPoint1));
220 // Start the animation
223 application.SendNotification();
224 application.Render(static_cast<unsigned int>(durationSeconds * 200.0f) /* 20% progress */);
225 application.SendNotification();
226 float epsilon(0.01f);
227 DALI_TEST_EQUALS(actor.GetCurrentProperty<float>(index), 0.271964f, epsilon, TEST_LOCATION);
229 application.SendNotification();
230 application.Render(static_cast<unsigned int>(durationSeconds * 200.0f) + 1u /*40% progress*/);
231 application.SendNotification();
232 DALI_TEST_EQUALS(actor.GetCurrentProperty<float>(index), 0.432387f, epsilon, TEST_LOCATION);
234 application.SendNotification();
235 application.Render(static_cast<unsigned int>(durationSeconds * 200.0f) + 1u /*60% progress*/);
236 application.SendNotification();
237 DALI_TEST_EQUALS(actor.GetCurrentProperty<float>(index), 0.567613f, epsilon, TEST_LOCATION);
239 application.SendNotification();
240 application.Render(static_cast<unsigned int>(durationSeconds * 200.0f) + 1u /*80% progress*/);
241 application.SendNotification();
242 DALI_TEST_EQUALS(actor.GetCurrentProperty<float>(index), 0.728037f, epsilon, TEST_LOCATION);
244 application.SendNotification();
245 application.Render(static_cast<unsigned int>(durationSeconds * 200.0f) + 1u /*just beyond the animation duration*/);
246 application.SendNotification();
247 DALI_TEST_EQUALS(actor.GetCurrentProperty<float>(index), targetValue, TEST_LOCATION);