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