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