Revert "[Tizen] Appendix log for ttrace + Print keycode and timestamp"
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-AlphaFunction.cpp
1 /*
2  * Copyright (c) 2020 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 <dali-test-suite-utils.h>
19 #include <dali/public-api/dali-core.h>
20 #include <stdlib.h>
21
22 #include <iostream>
23
24 using namespace Dali;
25
26 float customAlphaFunction(float progress)
27 {
28   return progress;
29 }
30
31 void utc_dali_alpha_function_startup(void)
32 {
33   test_return_value = TET_UNDEF;
34 }
35
36 void utc_dali_alpha_function_cleanup(void)
37 {
38   test_return_value = TET_PASS;
39 }
40
41 int UtcDaliAlphaFunctionDefaultConstructorP(void)
42 {
43   TestApplication application;
44   AlphaFunction   alpha;
45
46   //Should return the default alpha function
47   DALI_TEST_EQUALS(alpha.GetBuiltinFunction(), AlphaFunction::DEFAULT, TEST_LOCATION);
48
49   //Check the mode is BUILTIN_FUNCTION
50   DALI_TEST_EQUALS(alpha.GetMode(), AlphaFunction::BUILTIN_FUNCTION, TEST_LOCATION);
51
52   END_TEST;
53 }
54
55 int UtcDaliAlphaFunctionConstructorFromBuiltinP(void)
56 {
57   TestApplication application;
58
59   //Construct the alpha function with a built-in function
60   AlphaFunction alpha(AlphaFunction::EASE_IN_OUT);
61
62   //Check if the built-in alpha function is EASE_IN_OUT
63   DALI_TEST_EQUALS(alpha.GetBuiltinFunction(), AlphaFunction::EASE_IN_OUT, TEST_LOCATION);
64
65   //Check the mode is BUILTIN_FUNCTION
66   DALI_TEST_EQUALS(alpha.GetMode(), AlphaFunction::BUILTIN_FUNCTION, TEST_LOCATION);
67
68   END_TEST;
69 }
70
71 int UtcDaliAlphaFunctionConstructorFromFunctionPointerdP(void)
72 {
73   TestApplication application;
74
75   //Construct the alpha function with a function pointer
76   AlphaFunction alpha(&customAlphaFunction);
77
78   //Check that the custom function points to the custom alpha function
79   DALI_TEST_EQUALS(alpha.GetCustomFunction(), &customAlphaFunction, TEST_LOCATION);
80
81   //Check the mode is CUSTOM_FUNCTION
82   DALI_TEST_EQUALS(alpha.GetMode(), AlphaFunction::CUSTOM_FUNCTION, TEST_LOCATION);
83
84   END_TEST;
85 }
86
87 int UtcDaliAlphaFunctionConstructorFromControlPointsP(void)
88 {
89   TestApplication application;
90
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);
95
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);
100
101   //Check the mode is BEZIER
102   DALI_TEST_EQUALS(alpha.GetMode(), AlphaFunction::BEZIER, TEST_LOCATION);
103
104   END_TEST;
105 }
106
107 int UtcDaliAlphaFunctionConstructorFromControlPointsN(void)
108 {
109   TestApplication application;
110
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);
115
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);
120
121   //Check the mode is BEZIER
122   DALI_TEST_EQUALS(alpha.GetMode(), AlphaFunction::BEZIER, TEST_LOCATION);
123
124   END_TEST;
125 }
126
127 int UtcDaliAlphaFunctionGetBuiltinFunctionP(void)
128 {
129   TestApplication application;
130   AlphaFunction   alpha(AlphaFunction::EASE_IN);
131
132   //Check if the builtin alpha function is EASE_IN
133   DALI_TEST_EQUALS(alpha.GetBuiltinFunction(), AlphaFunction::EASE_IN, TEST_LOCATION);
134
135   //Check the mode is BUILTIN_FUNCTION
136   DALI_TEST_EQUALS(alpha.GetMode(), AlphaFunction::BUILTIN_FUNCTION, TEST_LOCATION);
137
138   END_TEST;
139 }
140
141 int UtcDaliAlphaFunctionGetCustomFunctionP(void)
142 {
143   TestApplication application;
144   AlphaFunction   alpha(&customAlphaFunction);
145
146   //Check that the custom function points to the custom alpha function
147   DALI_TEST_EQUALS(alpha.GetCustomFunction(), &customAlphaFunction, TEST_LOCATION);
148
149   //Check the mode is CUSTOM_FUNCTION
150   DALI_TEST_EQUALS(alpha.GetMode(), AlphaFunction::CUSTOM_FUNCTION, TEST_LOCATION);
151
152   END_TEST;
153 }
154
155 int UtcDaliAlphaFunctionGetControlPointsFunctionP(void)
156 {
157   TestApplication application;
158
159   Vector2       controlPoint0 = Vector2(0.0f, 1.0f);
160   Vector2       controlPoint1 = Vector2(1.0f, 0.0f);
161   AlphaFunction alpha(controlPoint0, controlPoint1);
162
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);
167
168   //Check the mode is BEZIER
169   DALI_TEST_EQUALS(alpha.GetMode(), AlphaFunction::BEZIER, TEST_LOCATION);
170
171   END_TEST;
172 }
173
174 int UtcDaliAlphaFunctionGetModeP(void)
175 {
176   TestApplication application;
177
178   //Create alpha function using a built-in function
179   AlphaFunction alphaBuiltin(AlphaFunction::EASE_IN);
180
181   //Check the mode is BUILTIN_FUNCTION
182   DALI_TEST_EQUALS(alphaBuiltin.GetMode(), AlphaFunction::BUILTIN_FUNCTION, TEST_LOCATION);
183
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);
188
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);
195
196   END_TEST;
197 }
198
199 int UtcDaliAlphaFunctionBezier(void)
200 {
201   TestApplication application;
202
203   Actor actor = Actor::New();
204
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);
210
211   // Build the animation
212   float     durationSeconds(1.0f);
213   Animation animation = Animation::New(durationSeconds);
214   float     targetValue(1.0f);
215
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));
219
220   // Start the animation
221   animation.Play();
222
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);
228
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);
233
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);
238
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);
243
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);
248
249   END_TEST;
250 }