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