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