[dali_2.3.25] Merge branch 'devel/master'
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-Constrainer.cpp
1 /*
2  * Copyright (c) 2024 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/devel-api/animation/path-constrainer.h>
20 #include <dali/public-api/dali-core.h>
21 #include <stdlib.h>
22
23 #include <iostream>
24
25 using namespace Dali;
26 using namespace Dali::Internal;
27
28 namespace
29 {
30 static void SetupPath(Dali::Path& path)
31 {
32   path.AddPoint(Vector3(30.0, 80.0, 0.0));
33   path.AddPoint(Vector3(70.0, 120.0, 0.0));
34   path.AddPoint(Vector3(100.0, 100.0, 0.0));
35
36   //Control points for first segment
37   path.AddControlPoint(Vector3(39.0, 90.0, 0.0));
38   path.AddControlPoint(Vector3(56.0, 119.0, 0.0));
39
40   //Control points for second segment
41   path.AddControlPoint(Vector3(78.0, 120.0, 0.0));
42   path.AddControlPoint(Vector3(93.0, 104.0, 0.0));
43 }
44
45 static void SetupPathConstrainer(Dali::PathConstrainer& PathConstrainer)
46 {
47   PathConstrainer.SetProperty(Dali::PathConstrainer::Property::FORWARD, Vector3(1.0f, 0.0f, 0.0f));
48
49   Dali::Property::Array points;
50   points.Resize(3);
51   points[0] = Vector3(30.0, 80.0, 0.0);
52   points[1] = Vector3(70.0, 120.0, 0.0);
53   points[2] = Vector3(100.0, 100.0, 0.0);
54   PathConstrainer.SetProperty(Dali::PathConstrainer::Property::POINTS, points);
55
56   points.Resize(4);
57   points[0] = Vector3(39.0, 90.0, 0.0);
58   points[1] = Vector3(56.0, 119.0, 0.0);
59   points[2] = Vector3(78.0, 120.0, 0.0);
60   points[3] = Vector3(93.0, 104.0, 0.0);
61   PathConstrainer.SetProperty(Dali::PathConstrainer::Property::CONTROL_POINTS, points);
62 }
63
64 static void SetupLinearConstrainerUniformProgress(Dali::LinearConstrainer& linearConstrainer)
65 {
66   Dali::Property::Array points;
67   points.Resize(3);
68   points[0] = 0.0f;
69   points[1] = 1.0f;
70   points[2] = 0.0f;
71   linearConstrainer.SetProperty(Dali::LinearConstrainer::Property::VALUE, points);
72 }
73
74 static void VerifyLinearConstrainerUniformProgress(Dali::LinearConstrainer& linearConstrainer)
75 {
76   Dali::Property::Array points;
77   points.Resize(3);
78   points[0] = 0.0f;
79   points[1] = 1.0f;
80   points[2] = 0.0f;
81
82   Property::Value  value = linearConstrainer.GetProperty(Dali::LinearConstrainer::Property::VALUE);
83   Property::Array* array = value.GetArray();
84   DALI_TEST_CHECK(array);
85
86   const unsigned int noOfPoints = points.Size();
87   for(unsigned int i = 0; i < noOfPoints; ++i)
88   {
89     DALI_TEST_EQUALS((*array)[i].Get<float>(), points[i].Get<float>(), TEST_LOCATION);
90   }
91 }
92
93 static void SetupLinearConstrainerNonUniformProgress(Dali::LinearConstrainer& linearConstrainer)
94 {
95   Dali::Property::Array points;
96   points.Resize(3);
97   points[0] = 0.0f;
98   points[1] = 1.0f;
99   points[2] = 0.0f;
100   linearConstrainer.SetProperty(Dali::LinearConstrainer::Property::VALUE, points);
101
102   points[0] = 0.0f;
103   points[1] = 0.25f;
104   points[2] = 1.0f;
105   linearConstrainer.SetProperty(Dali::LinearConstrainer::Property::PROGRESS, points);
106 }
107
108 static void SetupLinearConstrainerNonUniformProgressNonStartWithZero(Dali::LinearConstrainer& linearConstrainer)
109 {
110   Dali::Property::Array points;
111   points.Resize(3);
112   points[0] = 0.0f;
113   points[1] = 1.0f;
114   points[2] = 0.0f;
115   linearConstrainer.SetProperty(Dali::LinearConstrainer::Property::VALUE, points);
116
117   points[0] = 0.5f;
118   points[1] = 0.75f;
119   points[2] = 1.0f;
120   linearConstrainer.SetProperty(Dali::LinearConstrainer::Property::PROGRESS, points);
121 }
122
123 } // anonymous namespace
124
125 //PathConstrainer test cases
126 int UtcPathConstrainerApply(void)
127 {
128   TestApplication application;
129
130   Dali::Actor actor = Dali::Actor::New();
131
132   // Register a float property
133   Property::Index index = actor.RegisterProperty("t", 0.0f);
134
135   application.GetScene().Add(actor);
136
137   //Create a Path
138   Dali::Path path = Dali::Path::New();
139   SetupPath(path);
140
141   //Create a PathConstrainer
142   Dali::PathConstrainer pathConstrainer = Dali::PathConstrainer::New();
143   SetupPathConstrainer(pathConstrainer);
144
145   //Apply the path constraint to the actor's position. The source property for the constraint will be the custom property "t"
146   Vector2 range(0.0f, 1.0f);
147   pathConstrainer.Apply(Property(actor, Dali::Actor::Property::POSITION), Property(actor, index), range);
148
149   //Create an animation to animate the custom property
150   float           durationSeconds(1.0f);
151   Dali::Animation animation = Dali::Animation::New(durationSeconds);
152   animation.AnimateTo(Dali::Property(actor, index), 1.0f);
153   animation.Play();
154
155   application.SendNotification();
156   application.Render(static_cast<unsigned int>(durationSeconds * 200.0f) /* 20% progress */);
157
158   Vector3 position, tangent;
159   path.Sample(0.2f, position, tangent);
160   DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION), position, TEST_LOCATION);
161
162   application.SendNotification();
163   application.Render(static_cast<unsigned int>(durationSeconds * 200.0f) /* 40% progress */);
164   path.Sample(0.4f, position, tangent);
165   DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION), position, TEST_LOCATION);
166
167   application.SendNotification();
168   application.Render(static_cast<unsigned int>(durationSeconds * 200.0f) /* 60% progress */);
169   path.Sample(0.6f, position, tangent);
170   DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION), position, TEST_LOCATION);
171
172   application.SendNotification();
173   application.Render(static_cast<unsigned int>(durationSeconds * 200.0f) /* 80% progress */);
174   path.Sample(0.8f, position, tangent);
175   DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION), position, TEST_LOCATION);
176
177   application.SendNotification();
178   application.Render(static_cast<unsigned int>(durationSeconds * 200.0f) /* 100% progress */);
179   path.Sample(1.0f, position, tangent);
180   DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION), position, TEST_LOCATION);
181
182   application.SendNotification();
183   application.Render(static_cast<unsigned int>(durationSeconds * 200.0f) /* beyond the animation duration*/);
184   DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION), position, TEST_LOCATION);
185
186   END_TEST;
187 }
188
189 int UtcPathConstrainerApplyRange(void)
190 {
191   TestApplication application;
192
193   Dali::Actor actor = Dali::Actor::New();
194
195   // Register a float property
196   Property::Index index = actor.RegisterProperty("t", 0.0f);
197   application.GetScene().Add(actor);
198
199   //Create a Path
200   Dali::Path path = Dali::Path::New();
201   SetupPath(path);
202
203   //Create a PathConstrainer
204   Dali::PathConstrainer pathConstrainer = Dali::PathConstrainer::New();
205   SetupPathConstrainer(pathConstrainer);
206
207   //Apply the path constraint to the actor's position. The source property for the constraint will be the custom property "t"
208   Vector2 range(100.0f, 300.0f);
209   pathConstrainer.Apply(Property(actor, Dali::Actor::Property::POSITION), Property(actor, index), range);
210
211   //Create an animation to animate the custom property
212   float           durationSeconds(1.0f);
213   Dali::Animation animation = Dali::Animation::New(durationSeconds);
214   animation.AnimateTo(Dali::Property(actor, index), 400.0f);
215   animation.Play();
216
217   application.SendNotification();
218   application.Render(static_cast<unsigned int>(durationSeconds * 250.0f) /* 25% progress */);
219
220   Vector3 position, tangent;
221   float   tValue;
222   actor.GetCurrentProperty(index).Get(tValue);
223   float currentCursor = (tValue - range.x) / (range.y - range.x);
224   path.Sample(currentCursor, position, tangent);
225   DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION), position, TEST_LOCATION);
226
227   application.SendNotification();
228   application.Render(static_cast<unsigned int>(durationSeconds * 250.0f) /* 50% progress */);
229   actor.GetCurrentProperty(index).Get(tValue);
230   currentCursor = (tValue - range.x) / (range.y - range.x);
231   path.Sample(currentCursor, position, tangent);
232   path.Sample(0.5, position, tangent);
233   DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION), position, TEST_LOCATION);
234
235   application.SendNotification();
236   application.Render(static_cast<unsigned int>(durationSeconds * 250.0f) /* 75% progress */);
237   actor.GetCurrentProperty(index).Get(tValue);
238   currentCursor = (tValue - range.x) / (range.y - range.x);
239   path.Sample(currentCursor, position, tangent);
240   DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION), position, TEST_LOCATION);
241
242   application.SendNotification();
243   application.Render(static_cast<unsigned int>(durationSeconds * 250.0f) /* 100% progress */);
244   actor.GetCurrentProperty(index).Get(tValue);
245   currentCursor = (tValue - range.x) / (range.y - range.x);
246   path.Sample(currentCursor, position, tangent);
247   DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION), position, TEST_LOCATION);
248
249   application.SendNotification();
250   application.Render(static_cast<unsigned int>(durationSeconds * 250.0f) /* beyond the animation duration*/);
251   actor.GetCurrentProperty(index).Get(tValue);
252   currentCursor = (tValue - range.x) / (range.y - range.x);
253   path.Sample(currentCursor, position, tangent);
254   DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION), position, TEST_LOCATION);
255
256   // Ensure GetProperty also returns the final result
257   actor.GetProperty(index).Get(tValue);
258   currentCursor = (tValue - range.x) / (range.y - range.x);
259   path.Sample(currentCursor, position, tangent);
260   DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION), position, TEST_LOCATION);
261
262   END_TEST;
263 }
264
265 int UtcPathConstrainerDestroy(void)
266 {
267   TestApplication application;
268
269   Dali::Actor actor = Dali::Actor::New();
270
271   // Register a float property
272   Property::Index index = actor.RegisterProperty("t", 0.0f);
273   application.GetScene().Add(actor);
274
275   {
276     //Create a Path
277     Dali::Path path = Dali::Path::New();
278     SetupPath(path);
279
280     //Create a PathConstrainer
281     Dali::PathConstrainer pathConstrainer = Dali::PathConstrainer::New();
282     SetupPathConstrainer(pathConstrainer);
283
284     //Apply the path constraint to the actor's position. The source property for the constraint will be the custom property "t"
285     Vector2 range(0.0f, 1.0f);
286     pathConstrainer.Apply(Property(actor, Dali::Actor::Property::POSITION), Property(actor, index), range);
287
288     //Test that the constraint is correctly applied
289     actor.SetProperty(index, 0.5f);
290     application.SendNotification();
291     application.Render(static_cast<unsigned int>(1.0f));
292
293     Vector3 position, tangent;
294     path.Sample(0.5f, position, tangent);
295     DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION), position, TEST_LOCATION);
296   }
297
298   //PathConstrainer has been destroyed. Constraint in the actor should have been removed
299   actor.SetProperty(index, 0.75f);
300   application.SendNotification();
301   application.Render(static_cast<unsigned int>(1.0f));
302
303   DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION), Vector3::ZERO, TEST_LOCATION);
304
305   END_TEST;
306 }
307
308 int UtcPathConstrainerRemove(void)
309 {
310   TestApplication application;
311
312   Dali::Actor actor = Dali::Actor::New();
313
314   // Register a float property
315   Property::Index index = actor.RegisterProperty("t", 0.0f);
316   application.GetScene().Add(actor);
317
318   //Create a Path
319   Dali::Path path = Dali::Path::New();
320   SetupPath(path);
321
322   //Create a PathConstrainer
323   Dali::PathConstrainer pathConstrainer = Dali::PathConstrainer::New();
324   SetupPathConstrainer(pathConstrainer);
325
326   //Apply the path constraint to the actor's position. The source property for the constraint will be the custom property "t"
327   Vector2 range(0.0f, 1.0f);
328   pathConstrainer.Apply(Property(actor, Dali::Actor::Property::POSITION), Property(actor, index), range);
329
330   //Test that the constraint is correctly applied
331   actor.SetProperty(index, 0.5f);
332   application.SendNotification();
333   application.Render(static_cast<unsigned int>(1.0f));
334
335   Vector3 position, tangent;
336   path.Sample(0.5f, position, tangent);
337   DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION), position, TEST_LOCATION);
338
339   //Remove constraint
340   pathConstrainer.Remove(actor);
341   actor.SetProperty(index, 0.75f);
342   application.SendNotification();
343   application.Render(static_cast<unsigned int>(1.0f));
344
345   DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION), Vector3::ZERO, TEST_LOCATION);
346
347   END_TEST;
348 }
349
350 int UtcPathConstrainerProperties(void)
351 {
352   TestApplication       application;
353   Dali::PathConstrainer pathConstrainer = Dali::PathConstrainer::New();
354
355   pathConstrainer.SetProperty(Dali::PathConstrainer::Property::FORWARD, Vector3(1.0f, 0.0f, 0.0f));
356   DALI_TEST_EQUALS(pathConstrainer.GetProperty<Vector3>(Dali::PathConstrainer::Property::FORWARD), Vector3(1.0f, 0.0f, 0.0f), TEST_LOCATION);
357   DALI_TEST_EQUALS(pathConstrainer.GetCurrentProperty<Vector3>(Dali::PathConstrainer::Property::FORWARD), Vector3(1.0f, 0.0f, 0.0f), TEST_LOCATION);
358
359   Dali::Property::Array points;
360   points.Resize(3);
361   points[0] = Vector3(30.0, 80.0, 0.0);
362   points[1] = Vector3(70.0, 120.0, 0.0);
363   points[2] = Vector3(100.0, 100.0, 0.0);
364   pathConstrainer.SetProperty(Dali::PathConstrainer::Property::POINTS, points);
365
366   {
367     Property::Value  value = pathConstrainer.GetProperty(Dali::PathConstrainer::Property::POINTS);
368     Property::Array* array = value.GetArray();
369     DALI_TEST_CHECK(array);
370
371     const unsigned int noOfPoints = points.Size();
372     for(unsigned int i = 0; i < noOfPoints; ++i)
373     {
374       DALI_TEST_EQUALS((*array)[i].Get<Vector3>(), points[i].Get<Vector3>(), TEST_LOCATION);
375     }
376   }
377
378   {
379     Property::Value  value = pathConstrainer.GetCurrentProperty(Dali::PathConstrainer::Property::POINTS);
380     Property::Array* array = value.GetArray();
381     DALI_TEST_CHECK(array);
382
383     const unsigned int noOfPoints = points.Size();
384     for(unsigned int i = 0; i < noOfPoints; ++i)
385     {
386       DALI_TEST_EQUALS((*array)[i].Get<Vector3>(), points[i].Get<Vector3>(), TEST_LOCATION);
387     }
388   }
389
390   points.Resize(4);
391   points[0] = Vector3(39.0, 90.0, 0.0);
392   points[1] = Vector3(56.0, 119.0, 0.0);
393   points[2] = Vector3(78.0, 120.0, 0.0);
394   points[3] = Vector3(93.0, 104.0, 0.0);
395   pathConstrainer.SetProperty(Dali::PathConstrainer::Property::CONTROL_POINTS, points);
396
397   {
398     Property::Value  value = pathConstrainer.GetProperty(Dali::PathConstrainer::Property::CONTROL_POINTS);
399     Property::Array* array = value.GetArray();
400     DALI_TEST_CHECK(array);
401
402     const unsigned int noOfPoints = points.Size();
403     for(unsigned int i = 0; i < noOfPoints; ++i)
404     {
405       DALI_TEST_EQUALS((*array)[i].Get<Vector3>(), points[i].Get<Vector3>(), TEST_LOCATION);
406     }
407   }
408
409   {
410     Property::Value  value = pathConstrainer.GetCurrentProperty(Dali::PathConstrainer::Property::CONTROL_POINTS);
411     Property::Array* array = value.GetArray();
412     DALI_TEST_CHECK(array);
413
414     const unsigned int noOfPoints = points.Size();
415     for(unsigned int i = 0; i < noOfPoints; ++i)
416     {
417       DALI_TEST_EQUALS((*array)[i].Get<Vector3>(), points[i].Get<Vector3>(), TEST_LOCATION);
418     }
419   }
420
421   END_TEST;
422 }
423
424 //LinearConstrainer test cases
425 int UtcLinearConstrainerDownCast(void)
426 {
427   TestApplication         application;
428   Dali::LinearConstrainer linearConstrainer = Dali::LinearConstrainer::New();
429
430   BaseHandle              handle(linearConstrainer);
431   Dali::LinearConstrainer linearConstrainer2 = Dali::LinearConstrainer::DownCast(handle);
432   DALI_TEST_EQUALS((bool)linearConstrainer2, true, TEST_LOCATION);
433
434   BaseHandle              handle2;
435   Dali::LinearConstrainer linearConstrainer3 = Dali::LinearConstrainer::DownCast(handle2);
436   DALI_TEST_EQUALS((bool)linearConstrainer3, false, TEST_LOCATION);
437
438   END_TEST;
439 }
440
441 int UtcLinearConstrainerCopyConstructor(void)
442 {
443   TestApplication         application;
444   Dali::LinearConstrainer linearConstrainer;
445   DALI_TEST_EQUALS((bool)linearConstrainer, false, TEST_LOCATION);
446
447   linearConstrainer = Dali::LinearConstrainer::New();
448   DALI_TEST_EQUALS((bool)linearConstrainer, true, TEST_LOCATION);
449
450   // call the copy constructor
451   Dali::LinearConstrainer linearConstrainer2(linearConstrainer);
452   DALI_TEST_EQUALS((bool)linearConstrainer2, true, TEST_LOCATION);
453
454   END_TEST;
455 }
456
457 int UtcLinearConstrainerMoveConstructor(void)
458 {
459   TestApplication application;
460
461   Dali::LinearConstrainer linearConstrainer = Dali::LinearConstrainer::New();
462   DALI_TEST_CHECK(linearConstrainer);
463   DALI_TEST_EQUALS(1, linearConstrainer.GetBaseObject().ReferenceCount(), TEST_LOCATION);
464
465   SetupLinearConstrainerUniformProgress(linearConstrainer);
466   VerifyLinearConstrainerUniformProgress(linearConstrainer);
467
468   Dali::LinearConstrainer moved = std::move(linearConstrainer);
469   DALI_TEST_CHECK(moved);
470   DALI_TEST_EQUALS(1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION);
471   VerifyLinearConstrainerUniformProgress(moved);
472   DALI_TEST_CHECK(!linearConstrainer);
473
474   END_TEST;
475 }
476
477 int UtcLinearConstrainerMoveAssignment(void)
478 {
479   TestApplication application;
480
481   Dali::LinearConstrainer linearConstrainer = Dali::LinearConstrainer::New();
482   DALI_TEST_CHECK(linearConstrainer);
483   DALI_TEST_EQUALS(1, linearConstrainer.GetBaseObject().ReferenceCount(), TEST_LOCATION);
484
485   SetupLinearConstrainerUniformProgress(linearConstrainer);
486   VerifyLinearConstrainerUniformProgress(linearConstrainer);
487
488   Dali::LinearConstrainer moved;
489   moved = std::move(linearConstrainer);
490   DALI_TEST_CHECK(moved);
491   DALI_TEST_EQUALS(1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION);
492   VerifyLinearConstrainerUniformProgress(moved);
493   DALI_TEST_CHECK(!linearConstrainer);
494
495   END_TEST;
496 }
497
498 int UtcLinearConstrainerApply01(void)
499 {
500   TestApplication application;
501
502   Dali::Actor actor = Dali::Actor::New();
503
504   // Register a float property
505   Property::Index index = actor.RegisterProperty("t", 0.0f);
506
507   application.GetScene().Add(actor);
508
509   //Create a LinearConstrainer without specifying progress for values
510   Dali::LinearConstrainer linearConstrainer = Dali::LinearConstrainer::New();
511   SetupLinearConstrainerUniformProgress(linearConstrainer);
512
513   //Apply the linear constraint to the actor's position. The source property for the constraint will be the custom property "t"
514   Vector2 range(0.0f, 1.0f);
515   linearConstrainer.Apply(Property(actor, Dali::Actor::Property::POSITION_X), Property(actor, index), range);
516
517   //Create an animation to animate the custom property
518   float           durationSeconds(1.0f);
519   Dali::Animation animation = Dali::Animation::New(durationSeconds);
520   animation.AnimateTo(Dali::Property(actor, index), 1.0f);
521   animation.Play();
522
523   application.SendNotification();
524   application.Render(static_cast<unsigned int>(durationSeconds * 250.0f) /* 25% progress */);
525
526   DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION).x, 0.5f, TEST_LOCATION);
527
528   application.SendNotification();
529   application.Render(static_cast<unsigned int>(durationSeconds * 250.0f) /* 50% progress */);
530   DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION).x, 1.0f, TEST_LOCATION);
531
532   application.SendNotification();
533   application.Render(static_cast<unsigned int>(durationSeconds * 250.0f) /* 75% progress */);
534   DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION).x, 0.5f, TEST_LOCATION);
535
536   application.SendNotification();
537   application.Render(static_cast<unsigned int>(durationSeconds * 250.0f) /* 100% progress */);
538   DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION).x, 0.0f, TEST_LOCATION);
539
540   application.SendNotification();
541   application.Render(static_cast<unsigned int>(durationSeconds * 250.0f) /* beyond the animation duration*/);
542   DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION).x, 0.0f, TEST_LOCATION);
543
544   //Setup a LinearConstrainer specifying the progress for each value
545   linearConstrainer.Remove(actor);
546   SetupLinearConstrainerNonUniformProgress(linearConstrainer);
547   linearConstrainer.Apply(Property(actor, Dali::Actor::Property::POSITION_X), Property(actor, index), range);
548
549   actor.SetProperty(index, 0.0f);
550   animation.Play();
551   application.SendNotification();
552   application.Render(static_cast<unsigned int>(durationSeconds * 250.0f) /* 25% progress */);
553
554   DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION).x, 1.0f, TEST_LOCATION);
555
556   application.SendNotification();
557   application.Render(static_cast<unsigned int>(durationSeconds * 250.0f) /* 50% progress */);
558   DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION).x, 2.0f / 3.0f, Math::MACHINE_EPSILON_1, TEST_LOCATION);
559
560   application.SendNotification();
561   application.Render(static_cast<unsigned int>(durationSeconds * 250.0f) /* 75% progress */);
562   DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION).x, 1.0f / 3.0f, Math::MACHINE_EPSILON_1, TEST_LOCATION);
563
564   application.SendNotification();
565   application.Render(static_cast<unsigned int>(durationSeconds * 250.0f) /* 100% progress */);
566   DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION).x, 0.0f, TEST_LOCATION);
567
568   application.SendNotification();
569   application.Render(static_cast<unsigned int>(durationSeconds * 250.0f) /* beyond the animation duration*/);
570   DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION).x, 0.0f, TEST_LOCATION);
571
572   //Setup a LinearConstrainer specifying the progress for each value which is not start with 0.0f
573   linearConstrainer.Remove(actor);
574   SetupLinearConstrainerNonUniformProgressNonStartWithZero(linearConstrainer);
575   linearConstrainer.Apply(Property(actor, Dali::Actor::Property::POSITION_X), Property(actor, index), range);
576
577   actor.SetProperty(index, 0.0f);
578   animation.Play();
579   application.SendNotification();
580   application.Render(static_cast<unsigned int>(durationSeconds * 250.0f) /* 25% progress */);
581
582   DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION).x, 0.0f, TEST_LOCATION);
583
584   application.SendNotification();
585   application.Render(static_cast<unsigned int>(durationSeconds * 250.0f) /* 50% progress */);
586   DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION).x, 0.0f, Math::MACHINE_EPSILON_1, TEST_LOCATION);
587
588   application.SendNotification();
589   application.Render(static_cast<unsigned int>(durationSeconds * 250.0f) /* 75% progress */);
590   DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION).x, 1.0f, Math::MACHINE_EPSILON_1, TEST_LOCATION);
591
592   application.SendNotification();
593   application.Render(static_cast<unsigned int>(durationSeconds * 250.0f) /* 100% progress */);
594   DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION).x, 0.0f, TEST_LOCATION);
595
596   application.SendNotification();
597   application.Render(static_cast<unsigned int>(durationSeconds * 250.0f) /* beyond the animation duration*/);
598   DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION).x, 0.0f, TEST_LOCATION);
599
600   END_TEST;
601 }
602
603 int UtcLinearConstrainerApplyRange(void)
604 {
605   TestApplication application;
606
607   Dali::Actor actor = Dali::Actor::New();
608
609   // Register a float property
610   Property::Index index = actor.RegisterProperty("t", 100.0f);
611   application.GetScene().Add(actor);
612
613   //Create a LinearConstrainer
614   Dali::LinearConstrainer linearConstrainer = Dali::LinearConstrainer::New();
615   SetupLinearConstrainerUniformProgress(linearConstrainer);
616
617   //Apply the linear constraint to the actor's position. The source property for the constraint will be the custom property "t"
618   Vector2 range(100.0f, 300.0f);
619   linearConstrainer.Apply(Property(actor, Dali::Actor::Property::POSITION_X), Property(actor, index), range);
620
621   //Create an animation to animate the custom property
622   float           durationSeconds(1.0f);
623   Dali::Animation animation = Dali::Animation::New(durationSeconds);
624   animation.AnimateTo(Dali::Property(actor, index), 300.0f);
625   animation.Play();
626
627   application.SendNotification();
628   application.Render(static_cast<unsigned int>(durationSeconds * 250.0f) /* 25% progress */);
629
630   DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION).x, 0.5f, TEST_LOCATION);
631
632   application.SendNotification();
633   application.Render(static_cast<unsigned int>(durationSeconds * 250.0f) /* 50% progress */);
634   DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION).x, 1.0f, TEST_LOCATION);
635
636   application.SendNotification();
637   application.Render(static_cast<unsigned int>(durationSeconds * 250.0f) /* 75% progress */);
638   DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION).x, 0.5f, TEST_LOCATION);
639
640   application.SendNotification();
641   application.Render(static_cast<unsigned int>(durationSeconds * 250.0f) /* 100% progress */);
642   DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION).x, 0.0f, TEST_LOCATION);
643
644   application.SendNotification();
645   application.Render(static_cast<unsigned int>(durationSeconds * 250.0f) /* beyond the animation duration*/);
646   DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION).x, 0.0f, TEST_LOCATION);
647
648   END_TEST;
649 }
650
651 int UtcLinearConstrainerDestroy(void)
652 {
653   TestApplication application;
654
655   Dali::Actor actor = Dali::Actor::New();
656
657   // Register a float property
658   Property::Index index = actor.RegisterProperty("t", 0.0f);
659   application.GetScene().Add(actor);
660
661   {
662     //Create a LinearConstrainer
663     Dali::LinearConstrainer linearConstrainer = Dali::LinearConstrainer::New();
664     SetupLinearConstrainerUniformProgress(linearConstrainer);
665
666     //Apply the linear constraint to the actor's position. The source property for the constraint will be the custom property "t"
667     Vector2 range(0.0f, 1.0f);
668     linearConstrainer.Apply(Property(actor, Dali::Actor::Property::POSITION_X), Property(actor, index), range);
669
670     //Test that the constraint is correctly applied
671     actor.SetProperty(index, 0.5f);
672     application.SendNotification();
673     application.Render(static_cast<unsigned int>(1.0f));
674
675     DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION).x, 1.0f, TEST_LOCATION);
676   }
677
678   //LinearConstrainer has been destroyed. Constraint in the actor should have been removed
679   actor.SetProperty(index, 0.75f);
680   application.SendNotification();
681   application.Render(static_cast<unsigned int>(1.0f));
682
683   DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION).x, 0.0f, TEST_LOCATION);
684
685   END_TEST;
686 }
687
688 int UtcLinearConstrainerRemove(void)
689 {
690   TestApplication application;
691
692   Dali::Actor actor = Dali::Actor::New();
693
694   // Register a float property
695   Property::Index index = actor.RegisterProperty("t", 0.0f);
696   application.GetScene().Add(actor);
697
698   //Create a LinearConstrainer
699   Dali::LinearConstrainer linearConstrainer = Dali::LinearConstrainer::New();
700   SetupLinearConstrainerUniformProgress(linearConstrainer);
701
702   //Apply the path constraint to the actor's position. The source property for the constraint will be the custom property "t"
703   Vector2 range(0.0f, 1.0f);
704   linearConstrainer.Apply(Property(actor, Dali::Actor::Property::POSITION_X), Property(actor, index), range);
705
706   //Test that the constraint is correctly applied
707   actor.SetProperty(index, 0.5f);
708   application.SendNotification();
709   application.Render(static_cast<unsigned int>(1.0f));
710
711   DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION).x, 1.0f, TEST_LOCATION);
712
713   //Remove constraint
714   linearConstrainer.Remove(actor);
715   actor.SetProperty(index, 0.75f);
716   application.SendNotification();
717   application.Render(static_cast<unsigned int>(1.0f));
718
719   DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION).x, 0.0f, TEST_LOCATION);
720
721   END_TEST;
722 }
723
724 int UtcLinearConstrainerProperties(void)
725 {
726   TestApplication application;
727
728   Dali::LinearConstrainer linearConstrainer = Dali::LinearConstrainer::New();
729
730   Dali::Property::Array points;
731   points.Resize(3);
732   points[0] = 0.0f;
733   points[1] = 1.0f;
734   points[2] = 0.0f;
735   linearConstrainer.SetProperty(Dali::LinearConstrainer::Property::VALUE, points);
736
737   {
738     Property::Value  value = linearConstrainer.GetProperty(Dali::LinearConstrainer::Property::VALUE);
739     Property::Array* array = value.GetArray();
740     DALI_TEST_CHECK(array);
741
742     const unsigned int noOfPoints = points.Size();
743     for(unsigned int i = 0; i < noOfPoints; ++i)
744     {
745       DALI_TEST_EQUALS((*array)[i].Get<float>(), points[i].Get<float>(), TEST_LOCATION);
746     }
747   }
748
749   {
750     Property::Value  value = linearConstrainer.GetCurrentProperty(Dali::LinearConstrainer::Property::VALUE);
751     Property::Array* array = value.GetArray();
752     DALI_TEST_CHECK(array);
753
754     const unsigned int noOfPoints = points.Size();
755     for(unsigned int i = 0; i < noOfPoints; ++i)
756     {
757       DALI_TEST_EQUALS((*array)[i].Get<Vector3>(), points[i].Get<Vector3>(), TEST_LOCATION);
758     }
759   }
760
761   points[0] = 0.0f;
762   points[1] = 0.25f;
763   points[2] = 1.0f;
764   linearConstrainer.SetProperty(Dali::LinearConstrainer::Property::PROGRESS, points);
765
766   {
767     Property::Value  value = linearConstrainer.GetProperty(Dali::LinearConstrainer::Property::PROGRESS);
768     Property::Array* array = value.GetArray();
769     DALI_TEST_CHECK(array);
770
771     const unsigned int noOfPoints = points.Size();
772     for(unsigned int i = 0; i < noOfPoints; ++i)
773     {
774       DALI_TEST_EQUALS((*array)[i].Get<float>(), points[i].Get<float>(), TEST_LOCATION);
775     }
776   }
777
778   {
779     Property::Value  value = linearConstrainer.GetCurrentProperty(Dali::LinearConstrainer::Property::PROGRESS);
780     Property::Array* array = value.GetArray();
781     DALI_TEST_CHECK(array);
782
783     const unsigned int noOfPoints = points.Size();
784     for(unsigned int i = 0; i < noOfPoints; ++i)
785     {
786       DALI_TEST_EQUALS((*array)[i].Get<float>(), points[i].Get<float>(), TEST_LOCATION);
787     }
788   }
789
790   END_TEST;
791 }
792
793 int UtcDaliLinearConstrainerDetectorRegisterProperty(void)
794 {
795   TestApplication application;
796
797   Dali::LinearConstrainer constrainer = Dali::LinearConstrainer::New();
798
799   Property::Index index = constrainer.RegisterProperty("sceneProperty", 0);
800   DALI_TEST_EQUALS(index, (Property::Index)PROPERTY_CUSTOM_START_INDEX, TEST_LOCATION);
801   DALI_TEST_EQUALS(constrainer.GetProperty<int32_t>(index), 0, TEST_LOCATION);
802
803   constrainer.SetProperty(index, -123);
804   DALI_TEST_EQUALS(constrainer.GetProperty<int32_t>(index), -123, TEST_LOCATION);
805
806   using Dali::Animation;
807   Animation animation = Animation::New(1.0f);
808   animation.AnimateTo(Property(constrainer, index), 99);
809
810   DALI_TEST_EQUALS(constrainer.GetProperty<int32_t>(index), -123, TEST_LOCATION);
811   // Start the animation
812   animation.Play();
813
814   application.SendNotification();
815   application.Render(1000 /* 100% progress */);
816   DALI_TEST_EQUALS(constrainer.GetProperty<int32_t>(index), 99, TEST_LOCATION);
817
818   END_TEST;
819 }
820
821 int UtcDaliPathConstrainerDetectorRegisterProperty(void)
822 {
823   TestApplication application;
824
825   Dali::PathConstrainer constrainer = Dali::PathConstrainer::New();
826
827   Property::Index index = constrainer.RegisterProperty("pathProperty", Vector2());
828   DALI_TEST_EQUALS(index, (Property::Index)PROPERTY_CUSTOM_START_INDEX, TEST_LOCATION);
829   DALI_TEST_EQUALS(constrainer.GetProperty<Vector2>(index), Vector2(), TEST_LOCATION);
830
831   constrainer.SetProperty(index, Vector2(1, 2));
832   DALI_TEST_EQUALS(constrainer.GetProperty<Vector2>(index), Vector2(1, 2), TEST_LOCATION);
833
834   using Dali::Animation;
835   Animation animation = Animation::New(1.0f);
836   animation.AnimateTo(Property(constrainer, index), Vector2(3, 4));
837
838   DALI_TEST_EQUALS(constrainer.GetProperty<Vector2>(index), Vector2(1, 2), TEST_LOCATION);
839   // Start the animation
840   animation.Play();
841
842   application.SendNotification();
843   application.Render(1000 /* 100% progress */);
844   DALI_TEST_EQUALS(constrainer.GetProperty<Vector2>(index), Vector2(3, 4), TEST_LOCATION);
845
846   END_TEST;
847 }
848
849 int UtcDaliLinearConstrainerApplyNegative(void)
850 {
851   TestApplication         application;
852   Dali::LinearConstrainer instance;
853   Dali::Actor             actor;
854   try
855   {
856     Dali::Property arg1(actor, Dali::Actor::Property::POSITION);
857     Dali::Property arg2(actor, Dali::Actor::Property::POSITION);
858     Dali::Vector2  arg3;
859     Dali::Vector2  arg4;
860     instance.Apply(arg1, arg2, arg3, arg4);
861     DALI_TEST_CHECK(false); // Should not get here
862   }
863   catch(...)
864   {
865     DALI_TEST_CHECK(true); // We expect an assert
866   }
867   END_TEST;
868 }
869
870 int UtcDaliLinearConstrainerRemoveNegative(void)
871 {
872   TestApplication         application;
873   Dali::LinearConstrainer instance;
874   try
875   {
876     Dali::Handle arg1;
877     instance.Remove(arg1);
878     DALI_TEST_CHECK(false); // Should not get here
879   }
880   catch(...)
881   {
882     DALI_TEST_CHECK(true); // We expect an assert
883   }
884   END_TEST;
885 }