Migrating to new test framework
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-Constraint.cpp
1 //
2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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 #include <iostream>
18
19 #include <stdlib.h>
20 #include <dali/dali.h>
21 #include <dali-test-suite-utils.h>
22
23 using namespace Dali;
24
25 void utc_dali_constraint_startup(void)
26 {
27   test_return_value = TET_UNDEF;
28 }
29
30 void utc_dali_constraint_cleanup(void)
31 {
32   test_return_value = TET_PASS;
33 }
34
35
36 namespace
37 {
38
39 struct EqualToQuaternion
40 {
41   EqualToQuaternion()
42   {
43   }
44
45   Quaternion operator()( const Quaternion& current, const PropertyInput& property )
46   {
47     return property.GetQuaternion();
48   }
49 };
50
51 struct EqualToVector4
52 {
53   EqualToVector4()
54   {
55   }
56
57   Vector4 operator()( const Vector4& current, const PropertyInput& property )
58   {
59     return property.GetVector4();
60   }
61 };
62
63 class PropertyInputAbstraction : public Dali::PropertyInput
64 {
65 public:
66   PropertyInputAbstraction(const bool& val) : mType(Dali::Property::BOOLEAN), mBoolData( val )  {}
67   PropertyInputAbstraction(const float& val) : mType(Dali::Property::FLOAT), mFloatData( val )  {}
68   PropertyInputAbstraction(const Vector2& val) : mType(Dali::Property::VECTOR2), mVector2Data( val )  {}
69   PropertyInputAbstraction(const Vector3& val) : mType(Dali::Property::VECTOR3), mVector3Data( val )  {}
70   PropertyInputAbstraction(const Vector4& val) : mType(Dali::Property::VECTOR4), mVector4Data( val )  {}
71   PropertyInputAbstraction(const Matrix3& val) : mType(Dali::Property::MATRIX3), mMatrix3Data( val )  {}
72   PropertyInputAbstraction(const Matrix& val) : mType(Dali::Property::MATRIX), mMatrixData( val )  {}
73   PropertyInputAbstraction(const Quaternion& val) : mType(Dali::Property::ROTATION), mQuaternionData( val )  {}
74
75   ~PropertyInputAbstraction() {}
76
77   Dali::Property::Type GetType() const { return mType; }
78
79   const bool& GetBoolean() const { return mBoolData; }
80
81   const float& GetFloat() const { return mFloatData; }
82
83   const Vector2& GetVector2() const { return mVector2Data; }
84   const Vector3& GetVector3() const { return mVector3Data; }
85   const Vector4& GetVector4() const { return mVector4Data; }
86
87   const Matrix3& GetMatrix3() const { return mMatrix3Data; }
88   const Matrix& GetMatrix() const { return mMatrixData; }
89
90   const Quaternion& GetQuaternion() const { return mQuaternionData; }
91
92 private:
93   Dali::Property::Type mType;
94   bool mBoolData;
95   float mFloatData;
96   Vector2 mVector2Data;
97   Vector3 mVector3Data;
98   Vector4 mVector4Data;
99   Matrix3 mMatrix3Data;
100   Matrix mMatrixData;
101   Quaternion mQuaternionData;
102 };
103
104 static const float POSITION_EPSILON = 0.0001f;
105 static const float ROTATION_EPSILON = 0.0001f;
106
107 struct TestConstraint
108 {
109   Vector4 operator()(const Vector4&    color)
110   {
111     return Vector4(color.x, color.y, color.z, 0.1f);
112   }
113 };
114
115 struct TestConstraintToVector3
116 {
117   TestConstraintToVector3(Vector3 target)
118   : mTarget(target)
119   {
120   }
121
122   Vector3 operator()(const Vector3& current)
123   {
124     return mTarget;
125   }
126
127   Vector3 mTarget;
128 };
129
130 struct TestColorConstraint
131 {
132   TestColorConstraint(Vector4 target)
133   : mTarget(target)
134   {
135   }
136
137   Vector4 operator()(const Vector4&    color)
138   {
139     return mTarget;
140   }
141
142   Vector4 mTarget;
143 };
144
145 struct TestPositionConstraint
146 {
147   TestPositionConstraint(Vector3 target)
148   : mTarget(target)
149   {
150   }
151
152   Vector3 operator()(const Vector3&    position)
153   {
154     return mTarget;
155   }
156
157   Vector3 mTarget;
158 };
159
160
161 struct TestAlwaysTrueConstraint
162 {
163   bool operator()( const bool& current )
164   {
165     return true;
166   }
167 };
168
169 struct TestAlwaysEqualOrGreaterThanConstraint
170 {
171   TestAlwaysEqualOrGreaterThanConstraint( float value )
172   : mValue( value )
173   {
174   }
175
176   float operator()( const float& current )
177   {
178     return ( current < mValue ) ? mValue : current;
179   }
180
181   float mValue;
182 };
183
184 struct TestAlwaysEqualOrGreaterThanConstraintVector2
185 {
186   TestAlwaysEqualOrGreaterThanConstraintVector2( Vector2 value )
187   : mValue( value )
188   {
189   }
190
191   Vector2 operator()( const Vector2& current )
192   {
193     return Vector2( ( current.x < mValue.x ) ? mValue.x : current.x,
194                     ( current.y < mValue.y ) ? mValue.y : current.y
195                   );
196   }
197
198   Vector2 mValue;
199 };
200
201 struct TestAlwaysEqualOrGreaterThanConstraintVector3
202 {
203   TestAlwaysEqualOrGreaterThanConstraintVector3( Vector3 value )
204   : mValue( value )
205   {
206   }
207
208   Vector3 operator()( const Vector3& current )
209   {
210     return Vector3( ( current.x < mValue.x ) ? mValue.x : current.x,
211                     ( current.y < mValue.y ) ? mValue.y : current.y,
212                     ( current.z < mValue.z ) ? mValue.z : current.z
213                   );
214   }
215
216   Vector3 mValue;
217 };
218
219 struct TestAlwaysEqualOrGreaterThanConstraintVector4
220 {
221   TestAlwaysEqualOrGreaterThanConstraintVector4( Vector4 value )
222   : mValue( value )
223   {
224   }
225
226   Vector4 operator()( const Vector4& current )
227   {
228     return Vector4( ( current.x < mValue.x ) ? mValue.x : current.x,
229                     ( current.y < mValue.y ) ? mValue.y : current.y,
230                     ( current.z < mValue.z ) ? mValue.z : current.z,
231                     ( current.w < mValue.w ) ? mValue.w : current.w
232                   );
233   }
234
235   Vector4 mValue;
236 };
237
238 struct TestConstraintFloat
239 {
240   TestConstraintFloat( float value )
241   : mValue( value )
242   {
243   }
244
245   float operator()( const float& current )
246   {
247     return mValue;
248   }
249
250   float mValue;
251 };
252
253 struct TestConstraintVector2
254 {
255   TestConstraintVector2( Vector2 value )
256   : mValue( value )
257   {
258   }
259
260   Vector2 operator()( const Vector2& current )
261   {
262     return mValue;
263   }
264
265   Vector2 mValue;
266 };
267
268 struct TestConstraintVector3
269 {
270   TestConstraintVector3( Vector3 value )
271   : mValue( value )
272   {
273   }
274
275   Vector3 operator()( const Vector3& current )
276   {
277     return mValue;
278   }
279
280   Vector3 mValue;
281 };
282
283 struct TestConstraintVector4
284 {
285   TestConstraintVector4( Vector4 value )
286   : mValue( value )
287   {
288   }
289
290   Vector4 operator()( const Vector4& current )
291   {
292     return mValue;
293   }
294
295   Vector4 mValue;
296 };
297
298 struct TestConstraintRotation
299 {
300   TestConstraintRotation( Quaternion rotation )
301   : mRotation( rotation )
302   {
303   }
304
305   Quaternion operator()( const Quaternion& current )
306   {
307     return mRotation;
308   }
309
310   Quaternion mRotation;
311 };
312
313 struct TestConstraintMatrix3
314 {
315   TestConstraintMatrix3(Matrix3 matrix3)
316   : mMatrix3( matrix3 )
317   {
318   }
319
320   Matrix3 operator()( const Matrix3& current )
321   {
322     return mMatrix3;
323   }
324
325   Matrix3 mMatrix3;
326 };
327
328 struct TestConstraintMatrix
329 {
330   TestConstraintMatrix(Matrix matrix)
331   : mMatrix( matrix )
332   {
333   }
334
335   Matrix operator()( const Matrix& current )
336   {
337     return mMatrix;
338   }
339
340   Matrix mMatrix;
341 };
342
343 struct MoveAwayWithFadeConstraint
344 {
345   MoveAwayWithFadeConstraint( float distance )
346   : mDistance( distance )
347   {
348   }
349
350   Vector3 operator()( const Vector3& current,
351                       const PropertyInput& color )
352   {
353     return Vector3( current.x,
354                     current.y,
355                     -mDistance * (1.0f - color.GetVector4().a) );
356   }
357
358   float mDistance;
359 };
360
361 struct TestBottomRightAlignConstraint
362 {
363   Vector3 operator()( const Vector3& current,
364                       const PropertyInput& parentSize )
365   {
366     return Vector3( parentSize.GetVector3().x, parentSize.GetVector3().y, 0.0f );
367   }
368 };
369
370 struct MeanPositionConstraint1
371 {
372   Vector3 operator()( const Vector3& current,
373                       const PropertyInput& position1 )
374   {
375     return Vector3( position1.GetVector3() );
376   }
377 };
378
379 struct MeanPositionConstraint2
380 {
381   Vector3 operator()( const Vector3& current,
382                       const PropertyInput& position1,
383                       const PropertyInput& position2 )
384   {
385     Vector3 meanValue = position1.GetVector3() +
386                         position2.GetVector3();
387
388     return meanValue * 0.5f; // div 2
389   }
390 };
391
392 struct MeanPositionConstraint3
393 {
394   Vector3 operator()( const Vector3& current,
395                       const PropertyInput& position1,
396                       const PropertyInput& position2,
397                       const PropertyInput& position3 )
398   {
399     Vector3 meanValue = position1.GetVector3() +
400                         position2.GetVector3() +
401                         position3.GetVector3();
402
403     return meanValue * (1.0f / 3.0f); // div 3
404   }
405 };
406
407 struct MeanPositionConstraint4
408 {
409   Vector3 operator()( const Vector3& current,
410                       const PropertyInput& position1,
411                       const PropertyInput& position2,
412                       const PropertyInput& position3,
413                       const PropertyInput& position4 )
414   {
415     Vector3 meanValue = position1.GetVector3() +
416                         position2.GetVector3() +
417                         position3.GetVector3() +
418                         position4.GetVector3();
419
420     return meanValue * 0.25f; // div 4
421   }
422 };
423
424 struct MeanPositionConstraint5
425 {
426   Vector3 operator()( const Vector3& current,
427                       const PropertyInput& position1,
428                       const PropertyInput& position2,
429                       const PropertyInput& position3,
430                       const PropertyInput& position4,
431                       const PropertyInput& position5 )
432   {
433     Vector3 meanValue = position1.GetVector3() +
434                         position2.GetVector3() +
435                         position3.GetVector3() +
436                         position4.GetVector3() +
437                         position5.GetVector3();
438
439     return meanValue * 0.2f; // div 5
440   }
441 };
442
443 struct MeanPositionConstraint6
444 {
445   Vector3 operator()( const Vector3& current,
446                       const PropertyInput& position1,
447                       const PropertyInput& position2,
448                       const PropertyInput& position3,
449                       const PropertyInput& position4,
450                       const PropertyInput& position5,
451                       const PropertyInput& position6 )
452   {
453     Vector3 meanValue = position1.GetVector3() +
454                         position2.GetVector3() +
455                         position3.GetVector3() +
456                         position4.GetVector3() +
457                         position5.GetVector3() +
458                         position6.GetVector3();
459
460     return meanValue * (1.0f / 6.0f); // div 6
461   }
462 };
463
464 struct TestRelativeConstraintFloat
465 {
466   TestRelativeConstraintFloat(float scale)
467   : mScale(scale)
468   {
469   }
470
471   float operator()( const float& current, const PropertyInput& relative )
472   {
473     return relative.GetFloat() * mScale;
474   }
475
476   float mScale;
477 };
478
479 struct TestRelativeConstraintVector3
480 {
481   TestRelativeConstraintVector3(float scale)
482   : mScale(scale)
483   {
484   }
485
486   Vector3 operator()( const Vector3& current, const PropertyInput& relative )
487   {
488     return relative.GetVector3() * mScale;
489   }
490
491   float mScale;
492 };
493
494 } // anonymous namespace
495
496
497
498
499
500
501 int UtcDaliConstraintNewBoolean(void)
502 {
503   TestApplication application;
504
505   Actor actor = Actor::New();
506
507   // Register a boolean property
508   bool startValue(false);
509   Property::Index index = actor.RegisterProperty( "test-property", startValue );
510   Stage::GetCurrent().Add(actor);
511   DALI_TEST_CHECK( actor.GetProperty<bool>(index) == startValue );
512
513   /**
514    * Test that the Constraint is correctly applied on a clean Node
515    */
516   application.SendNotification();
517   application.Render(0);
518   DALI_TEST_CHECK( actor.GetProperty<bool>(index) == startValue );
519   application.Render(0);
520   DALI_TEST_CHECK( actor.GetProperty<bool>(index) == startValue );
521   application.Render(0);
522   DALI_TEST_CHECK( actor.GetProperty<bool>(index) == startValue );
523
524   // Apply constraint
525
526   Constraint constraint = Constraint::New<bool>( index, TestAlwaysTrueConstraint() );
527
528   actor.ApplyConstraint( constraint );
529   DALI_TEST_EQUALS( actor.GetProperty<bool>(index), false, TEST_LOCATION );
530
531   application.SendNotification();
532   application.Render(0);
533
534   // Constraint should be fully applied
535   DALI_TEST_EQUALS( actor.GetProperty<bool>(index), true, TEST_LOCATION );
536
537   // Check that nothing has changed after a couple of buffer swaps
538   application.Render(0);
539   DALI_TEST_EQUALS( actor.GetProperty<bool>(index), true, TEST_LOCATION );
540   application.Render(0);
541   DALI_TEST_EQUALS( actor.GetProperty<bool>(index), true, TEST_LOCATION );
542
543   // Try to fight with the constraint - this shouldn't work!
544   actor.SetProperty( index, false );
545
546   application.SendNotification();
547   application.Render(0);
548
549   // Check that nothing has changed after a couple of buffer swaps
550   application.Render(0);
551   DALI_TEST_EQUALS( actor.GetProperty<bool>(index), true, TEST_LOCATION );
552   application.Render(0);
553   DALI_TEST_EQUALS( actor.GetProperty<bool>(index), true, TEST_LOCATION );
554
555   // Remove the constraint, then set new value
556   actor.RemoveConstraints();
557   actor.SetProperty( index, false );
558
559   // Constraint should have been removed
560   application.SendNotification();
561   application.Render(0);
562   DALI_TEST_EQUALS( actor.GetProperty<bool>(index), false, TEST_LOCATION );
563   application.Render(0);
564   DALI_TEST_EQUALS( actor.GetProperty<bool>(index), false, TEST_LOCATION );
565   END_TEST;
566 }
567
568 int UtcDaliConstraintNewFloat(void)
569 {
570   TestApplication application;
571
572   Actor actor = Actor::New();
573
574   // Register a float property
575   float startValue(1.0f);
576   Property::Index index = actor.RegisterProperty( "test-property", startValue );
577   Stage::GetCurrent().Add(actor);
578   DALI_TEST_CHECK( actor.GetProperty<float>(index) == startValue );
579
580   /**
581    * Test that the Constraint is correctly applied on a clean Node
582    */
583   application.SendNotification();
584   application.Render(0);
585   DALI_TEST_CHECK( actor.GetProperty<float>(index) == startValue );
586   application.Render(0);
587   DALI_TEST_CHECK( actor.GetProperty<float>(index) == startValue );
588   application.Render(0);
589   DALI_TEST_CHECK( actor.GetProperty<float>(index) == startValue );
590
591   // Apply constraint
592
593   float minValue( 2.0f );
594   Constraint constraint = Constraint::New<float>( index, TestAlwaysEqualOrGreaterThanConstraint( minValue ) );
595
596   actor.ApplyConstraint( constraint );
597   DALI_TEST_EQUALS( actor.GetProperty<float>(index), startValue, TEST_LOCATION );
598
599   application.SendNotification();
600   application.Render(0);
601
602   // Constraint should be fully applied
603   DALI_TEST_EQUALS( actor.GetProperty<float>(index), minValue, TEST_LOCATION );
604
605   // Check that nothing has changed after a couple of buffer swaps
606   application.Render(0);
607   DALI_TEST_EQUALS( actor.GetProperty<float>(index), minValue, TEST_LOCATION );
608   application.Render(0);
609   DALI_TEST_EQUALS( actor.GetProperty<float>(index), minValue, TEST_LOCATION );
610
611   // Set to greater than 2.0f, the constraint will allow this
612   actor.SetProperty( index, 3.0f );
613
614   application.SendNotification();
615   application.Render(0);
616
617   DALI_TEST_EQUALS( actor.GetProperty<float>(index), 3.0f, TEST_LOCATION );
618
619   // Check that nothing has changed after a couple of buffer swaps
620   application.Render(0);
621   DALI_TEST_EQUALS( actor.GetProperty<float>(index), 3.0f, TEST_LOCATION );
622   application.Render(0);
623   DALI_TEST_EQUALS( actor.GetProperty<float>(index), 3.0f, TEST_LOCATION );
624
625   // Set to less than 2.0f, the constraint will NOT allow this
626   actor.SetProperty( index, 1.0f );
627
628   application.SendNotification();
629   application.Render(0);
630
631   DALI_TEST_EQUALS( actor.GetProperty<float>(index), minValue/*not 1.0f*/, TEST_LOCATION );
632
633   // Check that nothing has changed after a couple of buffer swaps
634   application.Render(0);
635   DALI_TEST_EQUALS( actor.GetProperty<float>(index), minValue, TEST_LOCATION );
636   application.Render(0);
637   DALI_TEST_EQUALS( actor.GetProperty<float>(index), minValue, TEST_LOCATION );
638
639   // Remove the constraint, then set new value
640   actor.RemoveConstraints();
641   actor.SetProperty( index, 1.0f );
642
643   // Constraint should have been removed
644   application.SendNotification();
645   application.Render(0);
646   DALI_TEST_EQUALS( actor.GetProperty<float>(index), 1.0f, TEST_LOCATION );
647   application.Render(0);
648   DALI_TEST_EQUALS( actor.GetProperty<float>(index), 1.0f, TEST_LOCATION );
649   END_TEST;
650 }
651
652 int UtcDaliConstraintNewVector2(void)
653 {
654   TestApplication application;
655
656   Actor actor = Actor::New();
657
658   // Register a Vector2 property
659   Vector2 startValue( 1.0f, 1.0f );
660   Property::Index index = actor.RegisterProperty( "test-property", startValue );
661   Stage::GetCurrent().Add(actor);
662   DALI_TEST_CHECK( actor.GetProperty<Vector2>(index) == startValue );
663
664   /**
665    * Test that the Constraint is correctly applied on a clean Node
666    */
667   application.SendNotification();
668   application.Render(0);
669   DALI_TEST_CHECK( actor.GetProperty<Vector2>(index) == startValue );
670   application.Render(0);
671   DALI_TEST_CHECK( actor.GetProperty<Vector2>(index) == startValue );
672   application.Render(0);
673   DALI_TEST_CHECK( actor.GetProperty<Vector2>(index) == startValue );
674
675   // Apply constraint
676
677   Vector2 minValue( 2.0f, 2.0f );
678   Constraint constraint = Constraint::New<Vector2>( index, TestAlwaysEqualOrGreaterThanConstraintVector2( minValue ) );
679
680   actor.ApplyConstraint( constraint );
681   DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), startValue, TEST_LOCATION );
682
683   application.SendNotification();
684   application.Render(0);
685
686   // Constraint should be fully applied
687   DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), minValue, TEST_LOCATION );
688
689   // Check that nothing has changed after a couple of buffer swaps
690   application.Render(0);
691   DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), minValue, TEST_LOCATION );
692   application.Render(0);
693   DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), minValue, TEST_LOCATION );
694
695   // Set to greater than 2.0f, the constraint will allow this
696   Vector2 greaterValue( 3.0f, 3.0f );
697   actor.SetProperty( index, greaterValue );
698
699   application.SendNotification();
700   application.Render(0);
701
702   DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), greaterValue, TEST_LOCATION );
703
704   // Check that nothing has changed after a couple of buffer swaps
705   application.Render(0);
706   DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), greaterValue, TEST_LOCATION );
707   application.Render(0);
708   DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), greaterValue, TEST_LOCATION );
709
710   // Set to less than 2.0f, the constraint will NOT allow this
711   Vector2 lesserValue( 1.0f, 1.0f );
712   actor.SetProperty( index, lesserValue );
713
714   application.SendNotification();
715   application.Render(0);
716
717   DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), minValue/*not lesserValue*/, TEST_LOCATION );
718
719   // Check that nothing has changed after a couple of buffer swaps
720   application.Render(0);
721   DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), minValue, TEST_LOCATION );
722   application.Render(0);
723   DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), minValue, TEST_LOCATION );
724
725   // Remove the constraint, then set new value
726   actor.RemoveConstraints();
727   actor.SetProperty( index, lesserValue );
728
729   // Constraint should have been removed
730   application.SendNotification();
731   application.Render(0);
732   DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), lesserValue, TEST_LOCATION );
733   application.Render(0);
734   DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), lesserValue, TEST_LOCATION );
735   END_TEST;
736 }
737
738 int UtcDaliConstraintNewVector3(void)
739 {
740   TestApplication application;
741
742   Actor actor = Actor::New();
743
744   // Register a Vector3 property
745   Vector3 startValue(1.0f, 1.0f, 1.0f);
746   Property::Index index = actor.RegisterProperty( "test-property", startValue );
747   Stage::GetCurrent().Add(actor);
748   DALI_TEST_CHECK( actor.GetProperty<Vector3>(index) == startValue );
749
750   /**
751    * Test that the Constraint is correctly applied on a clean Node
752    */
753   application.SendNotification();
754   application.Render(0);
755   DALI_TEST_CHECK( actor.GetProperty<Vector3>(index) == startValue );
756   application.Render(0);
757   DALI_TEST_CHECK( actor.GetProperty<Vector3>(index) == startValue );
758   application.Render(0);
759   DALI_TEST_CHECK( actor.GetProperty<Vector3>(index) == startValue );
760
761   // Apply constraint
762
763   Vector3 minValue( 2.0f, 2.0f, 2.0f );
764   Constraint constraint = Constraint::New<Vector3>( index, TestAlwaysEqualOrGreaterThanConstraintVector3( minValue ) );
765
766   actor.ApplyConstraint( constraint );
767   DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), startValue, TEST_LOCATION );
768
769   application.SendNotification();
770   application.Render(0);
771
772   // Constraint should be fully applied
773   DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), minValue, TEST_LOCATION );
774
775   // Check that nothing has changed after a couple of buffer swaps
776   application.Render(0);
777   DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), minValue, TEST_LOCATION );
778   application.Render(0);
779   DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), minValue, TEST_LOCATION );
780
781   // Set to greater than 2.0f, the constraint will allow this
782   Vector3 greaterValue( 3.0f, 3.0f, 3.0f );
783   actor.SetProperty( index, greaterValue );
784
785   application.SendNotification();
786   application.Render(0);
787
788   DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), greaterValue, TEST_LOCATION );
789
790   // Check that nothing has changed after a couple of buffer swaps
791   application.Render(0);
792   DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), greaterValue, TEST_LOCATION );
793   application.Render(0);
794   DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), greaterValue, TEST_LOCATION );
795
796   // Set to less than 2.0f, the constraint will NOT allow this
797   Vector3 lesserValue( 1.0f, 1.0f, 1.0f );
798   actor.SetProperty( index, lesserValue );
799
800   application.SendNotification();
801   application.Render(0);
802
803   DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), minValue/*not lesserValue*/, TEST_LOCATION );
804
805   // Check that nothing has changed after a couple of buffer swaps
806   application.Render(0);
807   DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), minValue, TEST_LOCATION );
808   application.Render(0);
809   DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), minValue, TEST_LOCATION );
810
811   // Remove the constraint, then set new value
812   actor.RemoveConstraints();
813   actor.SetProperty( index, lesserValue );
814
815   // Constraint should have been removed
816   application.SendNotification();
817   application.Render(0);
818   DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), lesserValue, TEST_LOCATION );
819   application.Render(0);
820   DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), lesserValue, TEST_LOCATION );
821   END_TEST;
822 }
823
824 int UtcDaliConstraintNewVector4(void)
825 {
826   TestApplication application;
827
828   Actor actor = Actor::New();
829
830   // Register a Vector4 property
831   Vector4 startValue( 1.0f, 1.0f, 1.0f, 1.0f );
832   Property::Index index = actor.RegisterProperty( "test-property", startValue );
833   Stage::GetCurrent().Add(actor);
834   DALI_TEST_CHECK( actor.GetProperty<Vector4>(index) == startValue );
835
836   /**
837    * Test that the Constraint is correctly applied on a clean Node
838    */
839   application.SendNotification();
840   application.Render(0);
841   DALI_TEST_CHECK( actor.GetProperty<Vector4>(index) == startValue );
842   application.Render(0);
843   DALI_TEST_CHECK( actor.GetProperty<Vector4>(index) == startValue );
844   application.Render(0);
845   DALI_TEST_CHECK( actor.GetProperty<Vector4>(index) == startValue );
846
847   // Apply constraint
848
849   Vector4 minValue( 2.0f, 2.0f, 2.0f, 2.0f );
850   Constraint constraint = Constraint::New<Vector4>( index, TestAlwaysEqualOrGreaterThanConstraintVector4( minValue ) );
851
852   actor.ApplyConstraint( constraint );
853   DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), startValue, TEST_LOCATION );
854
855   application.SendNotification();
856   application.Render(0);
857
858   // Constraint should be fully applied
859   DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), minValue, TEST_LOCATION );
860
861   // Check that nothing has changed after a couple of buffer swaps
862   application.Render(0);
863   DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), minValue, TEST_LOCATION );
864   application.Render(0);
865   DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), minValue, TEST_LOCATION );
866
867   // Set to greater than 2.0f, the constraint will allow this
868   Vector4 greaterValue( 3.0f, 3.0f, 3.0f, 3.0f );
869   actor.SetProperty( index, greaterValue );
870
871   application.SendNotification();
872   application.Render(0);
873
874   DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), greaterValue, TEST_LOCATION );
875
876   // Check that nothing has changed after a couple of buffer swaps
877   application.Render(0);
878   DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), greaterValue, TEST_LOCATION );
879   application.Render(0);
880   DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), greaterValue, TEST_LOCATION );
881
882   // Set to less than 2.0f, the constraint will NOT allow this
883   Vector4 lesserValue( 1.0f, 1.0f, 1.0f, 1.0f );
884   actor.SetProperty( index, lesserValue );
885
886   application.SendNotification();
887   application.Render(0);
888
889   DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), minValue/*not lesserValue*/, TEST_LOCATION );
890
891   // Check that nothing has changed after a couple of buffer swaps
892   application.Render(0);
893   DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), minValue, TEST_LOCATION );
894   application.Render(0);
895   DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), minValue, TEST_LOCATION );
896
897   // Remove the constraint, then set new value
898   actor.RemoveConstraints();
899   actor.SetProperty( index, lesserValue );
900
901   // Constraint should have been removed
902   application.SendNotification();
903   application.Render(0);
904   DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), lesserValue, TEST_LOCATION );
905   application.Render(0);
906   DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), lesserValue, TEST_LOCATION );
907   END_TEST;
908 }
909
910 int UtcDaliConstraintNewMatrix(void)
911 {
912   try
913   {
914     TestApplication application;
915
916     Actor actor = Actor::New();
917
918     // Register a Matrix property
919     Matrix startValue = Matrix::IDENTITY;
920     Property::Index index = actor.RegisterProperty( "test-property", startValue );
921     DALI_TEST_CHECK( index != Property::INVALID_INDEX );
922     if (index != Property::INVALID_INDEX)
923     {
924       Stage::GetCurrent().Add(actor);
925       DALI_TEST_CHECK( actor.GetProperty<Matrix>(index) == startValue );
926
927       // Apply constraint
928       Matrix constraintLimit;
929       constraintLimit.SetTransformComponents(Vector3::ONE, Quaternion(Radian(Degree(30.0f)), Vector3::YAXIS), Vector3::ZAXIS );
930       Constraint constraint = Constraint::New<Matrix>( index, TestConstraintMatrix(constraintLimit));
931       actor.ApplyConstraint( constraint );
932       DALI_TEST_EQUALS( actor.GetProperty<Matrix>(index), startValue, TEST_LOCATION );
933
934       application.SendNotification();
935       application.Render(0);
936
937       DALI_TEST_EQUALS( actor.GetProperty<Matrix>(index), constraintLimit, TEST_LOCATION );
938     }
939   }
940   catch (Dali::DaliException& e)
941   {
942     tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
943     DALI_TEST_CHECK(0);
944   }
945   END_TEST;
946 }
947
948 int UtcDaliConstraintNewMatrix3(void)
949 {
950   try
951   {
952     TestApplication application;
953
954     Actor actor = Actor::New();
955
956     // Register a Matrix3 property
957     Matrix3 startValue(1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f);
958     Property::Index index = actor.RegisterProperty( "test-property", startValue );
959     DALI_TEST_CHECK( index != Property::INVALID_INDEX );
960     if (index != Property::INVALID_INDEX)
961     {
962       Stage::GetCurrent().Add(actor);
963       DALI_TEST_CHECK( actor.GetProperty<Matrix3>(index) == startValue );
964
965       // Apply constraint
966       Matrix3 constraintLimit(42.0f, 0.0f, 0.0f, 0.0f, 42.0f, 0.0f, 0.0f, 0.0f, 1.0f);
967       Constraint constraint = Constraint::New<Matrix3>( index, TestConstraintMatrix3(constraintLimit));
968       actor.ApplyConstraint( constraint );
969       DALI_TEST_EQUALS( actor.GetProperty<Matrix3>(index), startValue, 0.001f, TEST_LOCATION );
970
971       application.SendNotification();
972       application.Render(0);
973
974       DALI_TEST_EQUALS( actor.GetProperty<Matrix3>(index), constraintLimit, 0.001f, TEST_LOCATION );
975     }
976   }
977   catch (Dali::DaliException& e)
978   {
979     tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str() );
980     DALI_TEST_CHECK(0);
981   }
982   END_TEST;
983 }
984
985 int UtcDaliConstraintNewQuaternion(void)
986 {
987   TestApplication application;
988
989   Actor actor = Actor::New();
990
991   // Register a Quaternion property
992   Quaternion startValue( 0.0f, Vector3::YAXIS );
993   Property::Index index = actor.RegisterProperty( "test-property", startValue );
994   Stage::GetCurrent().Add(actor);
995   DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), startValue, ROTATION_EPSILON, TEST_LOCATION );
996
997   /**
998    * Test that the Constraint is correctly applied on a clean Node
999    */
1000   application.SendNotification();
1001   application.Render(0);
1002   DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), startValue, ROTATION_EPSILON, TEST_LOCATION );
1003   application.Render(0);
1004   DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), startValue, ROTATION_EPSILON, TEST_LOCATION );
1005   application.Render(0);
1006   DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), startValue, ROTATION_EPSILON, TEST_LOCATION );
1007
1008   // Apply constraint
1009
1010   Quaternion constrainedRotation( M_PI*0.25f, Vector3::YAXIS );
1011   Constraint constraint = Constraint::New<Quaternion>( index, TestConstraintRotation( constrainedRotation ) );
1012
1013   actor.ApplyConstraint( constraint );
1014   DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), startValue, ROTATION_EPSILON, TEST_LOCATION );
1015
1016   application.SendNotification();
1017   application.Render(0);
1018
1019   // Constraint should be fully applied
1020   DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), constrainedRotation, ROTATION_EPSILON, TEST_LOCATION );
1021
1022   // Check that nothing has changed after a couple of buffer swaps
1023   application.Render(0);
1024   DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), constrainedRotation, ROTATION_EPSILON, TEST_LOCATION );
1025   application.Render(0);
1026   DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), constrainedRotation, ROTATION_EPSILON, TEST_LOCATION );
1027
1028   // Set to a different rotation, the constraint will NOT allow this
1029   Quaternion differentRotation( M_PI*0.5f, Vector3::YAXIS );
1030   actor.SetProperty( index, differentRotation );
1031
1032   application.SendNotification();
1033   application.Render(0);
1034
1035   DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), constrainedRotation/*not differentRotation*/, ROTATION_EPSILON, TEST_LOCATION );
1036
1037   // Check that nothing has changed after a couple of buffer swaps
1038   application.Render(0);
1039   DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), constrainedRotation, ROTATION_EPSILON, TEST_LOCATION );
1040   application.Render(0);
1041   DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), constrainedRotation, ROTATION_EPSILON, TEST_LOCATION );
1042
1043   // Remove the constraint, then set new value
1044   actor.RemoveConstraints();
1045   actor.SetProperty( index, differentRotation );
1046
1047   // Constraint should have been removed
1048   application.SendNotification();
1049   application.Render(0);
1050   DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), differentRotation, ROTATION_EPSILON, TEST_LOCATION );
1051   application.Render(0);
1052   DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), differentRotation, ROTATION_EPSILON, TEST_LOCATION );
1053   END_TEST;
1054 }
1055
1056 int UtcDaliConstraintNewOffStageBoolean(void)
1057 {
1058   TestApplication application;
1059
1060   Actor actor = Actor::New();
1061
1062   // Register a boolean property
1063   bool startValue(false);
1064   Property::Index index = actor.RegisterProperty( "test-property", startValue );
1065   DALI_TEST_CHECK( actor.GetProperty<bool>(index) == startValue );
1066
1067   // Apply constraint to off-stage Actor
1068   Constraint constraint = Constraint::New<bool>( index, TestAlwaysTrueConstraint() );
1069   actor.ApplyConstraint( constraint );
1070
1071   application.SendNotification();
1072   application.Render(0);
1073   DALI_TEST_EQUALS( actor.GetProperty<bool>(index), false, TEST_LOCATION );
1074
1075   // Add actor to stage
1076   Stage::GetCurrent().Add(actor);
1077   application.SendNotification();
1078   application.Render(0);
1079
1080   // Constraint should be fully applied
1081   DALI_TEST_EQUALS( actor.GetProperty<bool>(index), true, TEST_LOCATION );
1082
1083   // Check that nothing has changed after a couple of buffer swaps
1084   application.Render(0);
1085   DALI_TEST_EQUALS( actor.GetProperty<bool>(index), true, TEST_LOCATION );
1086   application.Render(0);
1087   DALI_TEST_EQUALS( actor.GetProperty<bool>(index), true, TEST_LOCATION );
1088
1089   // Take the actor off-stage
1090   Stage::GetCurrent().Remove(actor);
1091   application.SendNotification();
1092   application.Render(0);
1093   DALI_TEST_EQUALS( actor.GetProperty<bool>(index), true, TEST_LOCATION );
1094
1095   // Set a new value; the constraint will not prevent this
1096   actor.SetProperty( index, false );
1097   application.SendNotification();
1098   application.Render(0);
1099   DALI_TEST_EQUALS( actor.GetProperty<bool>(index), false, TEST_LOCATION );
1100
1101   // Add actor to stage (2nd time)
1102   Stage::GetCurrent().Add(actor);
1103   application.SendNotification();
1104   application.Render(0);
1105
1106   // Constraint should be fully applied (2nd time)
1107   DALI_TEST_EQUALS( actor.GetProperty<bool>(index), true, TEST_LOCATION );
1108
1109   // Check that nothing has changed after a couple of buffer swaps
1110   application.Render(0);
1111   DALI_TEST_EQUALS( actor.GetProperty<bool>(index), true, TEST_LOCATION );
1112   application.Render(0);
1113   DALI_TEST_EQUALS( actor.GetProperty<bool>(index), true, TEST_LOCATION );
1114
1115   // Take the actor off-stage (2nd-time)
1116   Stage::GetCurrent().Remove(actor);
1117   application.SendNotification();
1118   application.Render(0);
1119   DALI_TEST_EQUALS( actor.GetProperty<bool>(index), true, TEST_LOCATION );
1120
1121   // Remove the constraint, and set a new value
1122   actor.RemoveConstraints();
1123   actor.SetProperty( index, false );
1124   application.SendNotification();
1125   application.Render(0);
1126   DALI_TEST_EQUALS( actor.GetProperty<bool>(index), false, TEST_LOCATION );
1127
1128   // Add actor to stage (3rd time)
1129   Stage::GetCurrent().Add(actor);
1130   application.SendNotification();
1131   application.Render(0);
1132
1133   // Constraint should be gone
1134   DALI_TEST_EQUALS( actor.GetProperty<bool>(index), false, TEST_LOCATION );
1135
1136   // Check that nothing has changed after a couple of buffer swaps
1137   application.Render(0);
1138   DALI_TEST_EQUALS( actor.GetProperty<bool>(index), false, TEST_LOCATION );
1139   application.Render(0);
1140   DALI_TEST_EQUALS( actor.GetProperty<bool>(index), false, TEST_LOCATION );
1141   END_TEST;
1142 }
1143
1144 int UtcDaliConstraintNewOffStageFloat(void)
1145 {
1146   TestApplication application;
1147
1148   Actor actor = Actor::New();
1149
1150   // Register a float property
1151   float startValue(1.0f);
1152   Property::Index index = actor.RegisterProperty( "test-property", startValue );
1153   DALI_TEST_CHECK( actor.GetProperty<float>(index) == startValue );
1154
1155   // Apply constraint to off-stage Actor
1156   float constrainedValue( 2.0f );
1157   Constraint constraint = Constraint::New<float>( index, TestConstraintFloat( constrainedValue ) );
1158   actor.ApplyConstraint( constraint );
1159
1160   application.SendNotification();
1161   application.Render(0);
1162   DALI_TEST_EQUALS( actor.GetProperty<float>(index), startValue, TEST_LOCATION );
1163
1164   // Add actor to stage
1165   Stage::GetCurrent().Add(actor);
1166   application.SendNotification();
1167   application.Render(0);
1168
1169   // Constraint should be fully applied
1170   DALI_TEST_EQUALS( actor.GetProperty<float>(index), constrainedValue, TEST_LOCATION );
1171
1172   // Check that nothing has changed after a couple of buffer swaps
1173   application.Render(0);
1174   DALI_TEST_EQUALS( actor.GetProperty<float>(index), constrainedValue, TEST_LOCATION );
1175   application.Render(0);
1176   DALI_TEST_EQUALS( actor.GetProperty<float>(index), constrainedValue, TEST_LOCATION );
1177
1178   // Take the actor off-stage
1179   Stage::GetCurrent().Remove(actor);
1180   application.SendNotification();
1181   application.Render(0);
1182   DALI_TEST_EQUALS( actor.GetProperty<float>(index), constrainedValue, TEST_LOCATION );
1183
1184   // Set back to startValue; the constraint will not prevent this
1185   actor.SetProperty( index, startValue );
1186   application.SendNotification();
1187   application.Render(0);
1188   DALI_TEST_EQUALS( actor.GetProperty<float>(index), startValue, TEST_LOCATION );
1189
1190   // Add actor to stage (2nd time)
1191   Stage::GetCurrent().Add(actor);
1192   application.SendNotification();
1193   application.Render(0);
1194
1195   // Constraint should be fully applied (2nd time)
1196   DALI_TEST_EQUALS( actor.GetProperty<float>(index), constrainedValue, TEST_LOCATION );
1197
1198   // Check that nothing has changed after a couple of buffer swaps
1199   application.Render(0);
1200   DALI_TEST_EQUALS( actor.GetProperty<float>(index), constrainedValue, TEST_LOCATION );
1201   application.Render(0);
1202   DALI_TEST_EQUALS( actor.GetProperty<float>(index), constrainedValue, TEST_LOCATION );
1203
1204   // Take the actor off-stage (2nd-time)
1205   Stage::GetCurrent().Remove(actor);
1206   application.SendNotification();
1207   application.Render(0);
1208   DALI_TEST_EQUALS( actor.GetProperty<float>(index), constrainedValue, TEST_LOCATION );
1209
1210   // Remove the constraint, and set back to startValue
1211   actor.RemoveConstraints();
1212   actor.SetProperty( index, startValue );
1213   application.SendNotification();
1214   application.Render(0);
1215   DALI_TEST_EQUALS( actor.GetProperty<float>(index), startValue, TEST_LOCATION );
1216
1217   // Add actor to stage (3rd time)
1218   Stage::GetCurrent().Add(actor);
1219   application.SendNotification();
1220   application.Render(0);
1221
1222   // Constraint should be gone
1223   DALI_TEST_EQUALS( actor.GetProperty<float>(index), startValue, TEST_LOCATION );
1224
1225   // Check that nothing has changed after a couple of buffer swaps
1226   application.Render(0);
1227   DALI_TEST_EQUALS( actor.GetProperty<float>(index), startValue, TEST_LOCATION );
1228   application.Render(0);
1229   DALI_TEST_EQUALS( actor.GetProperty<float>(index), startValue, TEST_LOCATION );
1230   END_TEST;
1231 }
1232
1233 int UtcDaliConstraintNewOffStageVector2(void)
1234 {
1235   TestApplication application;
1236
1237   Actor actor = Actor::New();
1238
1239   // Register a Vector2 property
1240   Vector2 startValue(1.0f, 1.0f);
1241   Property::Index index = actor.RegisterProperty( "test-property", startValue );
1242   DALI_TEST_CHECK( actor.GetProperty<Vector2>(index) == startValue );
1243
1244   // Apply constraint to off-stage Actor
1245   Vector2 constrainedValue( 2.0f, 2.0f );
1246   Constraint constraint = Constraint::New<Vector2>( index, TestConstraintVector2( constrainedValue ) );
1247   actor.ApplyConstraint( constraint );
1248
1249   application.SendNotification();
1250   application.Render(0);
1251   DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), startValue, TEST_LOCATION );
1252
1253   // Add actor to stage
1254   Stage::GetCurrent().Add(actor);
1255   application.SendNotification();
1256   application.Render(0);
1257
1258   // Constraint should be fully applied
1259   DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), constrainedValue, TEST_LOCATION );
1260
1261   // Check that nothing has changed after a couple of buffer swaps
1262   application.Render(0);
1263   DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), constrainedValue, TEST_LOCATION );
1264   application.Render(0);
1265   DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), constrainedValue, TEST_LOCATION );
1266
1267   // Take the actor off-stage
1268   Stage::GetCurrent().Remove(actor);
1269   application.SendNotification();
1270   application.Render(0);
1271   DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), constrainedValue, TEST_LOCATION );
1272
1273   // Set back to startValue; the constraint will not prevent this
1274   actor.SetProperty( index, startValue );
1275   application.SendNotification();
1276   application.Render(0);
1277   DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), startValue, TEST_LOCATION );
1278
1279   // Add actor to stage (2nd time)
1280   Stage::GetCurrent().Add(actor);
1281   application.SendNotification();
1282   application.Render(0);
1283
1284   // Constraint should be fully applied (2nd time)
1285   DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), constrainedValue, TEST_LOCATION );
1286
1287   // Check that nothing has changed after a couple of buffer swaps
1288   application.Render(0);
1289   DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), constrainedValue, TEST_LOCATION );
1290   application.Render(0);
1291   DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), constrainedValue, TEST_LOCATION );
1292
1293   // Take the actor off-stage (2nd-time)
1294   Stage::GetCurrent().Remove(actor);
1295   application.SendNotification();
1296   application.Render(0);
1297   DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), constrainedValue, TEST_LOCATION );
1298
1299   // Remove the constraint, and set back to startValue
1300   actor.RemoveConstraints();
1301   actor.SetProperty( index, startValue );
1302   application.SendNotification();
1303   application.Render(0);
1304   DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), startValue, TEST_LOCATION );
1305
1306   // Add actor to stage (3rd time)
1307   Stage::GetCurrent().Add(actor);
1308   application.SendNotification();
1309   application.Render(0);
1310
1311   // Constraint should be gone
1312   DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), startValue, TEST_LOCATION );
1313
1314   // Check that nothing has changed after a couple of buffer swaps
1315   application.Render(0);
1316   DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), startValue, TEST_LOCATION );
1317   application.Render(0);
1318   DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), startValue, TEST_LOCATION );
1319   END_TEST;
1320 }
1321
1322 int UtcDaliConstraintNewOffStageVector3(void)
1323 {
1324   TestApplication application;
1325   Vector3 startValue(1.0f, 1.0f, 1.0f);
1326   Vector3 constrainedValue = Vector3( 2.0f, 3.0f, 4.0f );
1327
1328   Actor actor = Actor::New();
1329   // Register a Vector3 property
1330
1331   Property::Index index = actor.RegisterProperty( "test-property", startValue );
1332   DALI_TEST_CHECK( actor.GetProperty<Vector3>(index) == startValue );
1333
1334   // Apply constraint to off-stage Actor
1335   Constraint constraint = Constraint::New<Vector3>( index, TestConstraintVector3( constrainedValue ) );
1336   actor.ApplyConstraint( constraint );
1337
1338   application.SendNotification();
1339   application.Render(0);
1340   DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), startValue, TEST_LOCATION );
1341
1342   // Add actor to stage
1343   Stage::GetCurrent().Add(actor);
1344   application.SendNotification();
1345   application.Render();
1346
1347   // Constraint should be fully applied
1348   DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), constrainedValue, TEST_LOCATION );
1349
1350   // Check that nothing has changed after a couple of buffer swaps
1351   application.Render();
1352   DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), constrainedValue, TEST_LOCATION );
1353   application.Render();
1354   DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), constrainedValue, TEST_LOCATION );
1355
1356   // Take the actor off-stage
1357   Stage::GetCurrent().Remove(actor);
1358   application.SendNotification();
1359   application.Render();
1360   DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), constrainedValue, TEST_LOCATION );
1361
1362   // Set back to startValue; the constraint will not prevent this
1363   Vector3 intermediateValue(5.0f, 6.0f, 7.0f);
1364   actor.SetProperty( index, intermediateValue );
1365   application.SendNotification();
1366   application.Render();
1367   application.Render(); // ensure both buffers are set to intermediateValue
1368   DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), intermediateValue, TEST_LOCATION );
1369
1370   // Add actor to stage (2nd time)
1371   Stage::GetCurrent().Add(actor);
1372   application.SendNotification();
1373   application.Render();
1374
1375   // Constraint should be fully applied (2nd time)
1376   DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), constrainedValue, TEST_LOCATION );
1377
1378   // Check that nothing has changed after a couple of buffer swaps
1379   application.Render();
1380   DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), constrainedValue, TEST_LOCATION );
1381   application.Render();
1382   DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), constrainedValue, TEST_LOCATION );
1383
1384   // Take the actor off-stage (2nd-time)
1385   Stage::GetCurrent().Remove(actor);
1386   application.SendNotification();
1387   application.Render();
1388   DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), constrainedValue, TEST_LOCATION );
1389
1390   // Remove the constraint, and set back to startValue
1391   actor.RemoveConstraints();
1392   actor.SetProperty( index, startValue );
1393   application.SendNotification();
1394   application.Render();
1395   DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), startValue, TEST_LOCATION );
1396
1397   // Add actor to stage (3rd time)
1398   Stage::GetCurrent().Add(actor);
1399   application.SendNotification();
1400   application.Render();
1401
1402   // Constraint should be gone
1403   DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), startValue, TEST_LOCATION );
1404
1405   // Check that nothing has changed after a couple of buffer swaps
1406   application.Render();
1407   DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), startValue, TEST_LOCATION );
1408   application.Render();
1409   DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), startValue, TEST_LOCATION );
1410   END_TEST;
1411 }
1412
1413 int UtcDaliConstraintNewOffStageVector4(void)
1414 {
1415   TestApplication application;
1416
1417   Actor actor = Actor::New();
1418
1419   // Register a Vector4 property
1420   Vector4 startValue(1.0f, 1.0f, 1.0f, 1.0f);
1421   Property::Index index = actor.RegisterProperty( "test-property", startValue );
1422   DALI_TEST_CHECK( actor.GetProperty<Vector4>(index) == startValue );
1423
1424   // Apply constraint to off-stage Actor
1425   Vector4 constrainedValue( 2.0f, 2.0f, 2.0f, 2.0f );
1426   Constraint constraint = Constraint::New<Vector4>( index, TestConstraintVector4( constrainedValue ) );
1427   actor.ApplyConstraint( constraint );
1428
1429   application.SendNotification();
1430   application.Render(0);
1431   DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), startValue, TEST_LOCATION );
1432
1433   // Add actor to stage
1434   Stage::GetCurrent().Add(actor);
1435   application.SendNotification();
1436   application.Render(0);
1437
1438   // Constraint should be fully applied
1439   DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), constrainedValue, TEST_LOCATION );
1440
1441   // Check that nothing has changed after a couple of buffer swaps
1442   application.Render(0);
1443   DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), constrainedValue, TEST_LOCATION );
1444   application.Render(0);
1445   DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), constrainedValue, TEST_LOCATION );
1446
1447   // Take the actor off-stage
1448   Stage::GetCurrent().Remove(actor);
1449   application.SendNotification();
1450   application.Render(0);
1451   DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), constrainedValue, TEST_LOCATION );
1452
1453   // Set back to startValue; the constraint will not prevent this
1454   actor.SetProperty( index, startValue );
1455   application.SendNotification();
1456   application.Render(0);
1457   DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), startValue, TEST_LOCATION );
1458
1459   // Add actor to stage (2nd time)
1460   Stage::GetCurrent().Add(actor);
1461   application.SendNotification();
1462   application.Render(0);
1463
1464   // Constraint should be fully applied (2nd time)
1465   DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), constrainedValue, TEST_LOCATION );
1466
1467   // Check that nothing has changed after a couple of buffer swaps
1468   application.Render(0);
1469   DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), constrainedValue, TEST_LOCATION );
1470   application.Render(0);
1471   DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), constrainedValue, TEST_LOCATION );
1472
1473   // Take the actor off-stage (2nd-time)
1474   Stage::GetCurrent().Remove(actor);
1475   application.SendNotification();
1476   application.Render(0);
1477   DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), constrainedValue, TEST_LOCATION );
1478
1479   // Remove the constraint, and set back to startValue
1480   actor.RemoveConstraints();
1481   actor.SetProperty( index, startValue );
1482   application.SendNotification();
1483   application.Render(0);
1484   DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), startValue, TEST_LOCATION );
1485
1486   // Add actor to stage (3rd time)
1487   Stage::GetCurrent().Add(actor);
1488   application.SendNotification();
1489   application.Render(0);
1490
1491   // Constraint should be gone
1492   DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), startValue, TEST_LOCATION );
1493
1494   // Check that nothing has changed after a couple of buffer swaps
1495   application.Render(0);
1496   DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), startValue, TEST_LOCATION );
1497   application.Render(0);
1498   DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), startValue, TEST_LOCATION );
1499   END_TEST;
1500 }
1501
1502 int UtcDaliConstraintNewOffStageQuaternion(void)
1503 {
1504   TestApplication application;
1505
1506   Actor actor = Actor::New();
1507
1508   // Register a Quaternion property
1509   Quaternion startValue( 0.0f, Vector3::YAXIS );
1510   Property::Index index = actor.RegisterProperty( "test-property", startValue );
1511   DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), startValue, ROTATION_EPSILON, TEST_LOCATION );
1512
1513   // Apply constraint to off-stage Actor
1514   Quaternion constrainedRotation( M_PI*0.25f, Vector3::YAXIS );
1515   Constraint constraint = Constraint::New<Quaternion>( index, TestConstraintRotation( constrainedRotation ) );
1516   actor.ApplyConstraint( constraint );
1517
1518   application.SendNotification();
1519   application.Render(0);
1520   DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), startValue, ROTATION_EPSILON, TEST_LOCATION );
1521
1522   // Add actor to stage
1523   Stage::GetCurrent().Add(actor);
1524   application.SendNotification();
1525   application.Render(0);
1526
1527   // Constraint should be fully applied
1528   DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), constrainedRotation, ROTATION_EPSILON, TEST_LOCATION );
1529
1530   // Check that nothing has changed after a couple of buffer swaps
1531   application.Render(0);
1532   DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), constrainedRotation, ROTATION_EPSILON, TEST_LOCATION );
1533   application.Render(0);
1534   DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), constrainedRotation, ROTATION_EPSILON, TEST_LOCATION );
1535
1536   // Take the actor off-stage
1537   Stage::GetCurrent().Remove(actor);
1538   application.SendNotification();
1539   application.Render(0);
1540   DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), constrainedRotation, ROTATION_EPSILON, TEST_LOCATION );
1541
1542   // Set back to startValue; the constraint will not prevent this
1543   actor.SetProperty( index, startValue );
1544   application.SendNotification();
1545   application.Render(0);
1546   DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), startValue, ROTATION_EPSILON, TEST_LOCATION );
1547
1548   // Add actor to stage (2nd time)
1549   Stage::GetCurrent().Add(actor);
1550   application.SendNotification();
1551   application.Render(0);
1552
1553   // Constraint should be fully applied (2nd time)
1554   DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), constrainedRotation, ROTATION_EPSILON, TEST_LOCATION );
1555
1556   // Check that nothing has changed after a couple of buffer swaps
1557   application.Render(0);
1558   DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), constrainedRotation, ROTATION_EPSILON, TEST_LOCATION );
1559   application.Render(0);
1560   DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), constrainedRotation, ROTATION_EPSILON, TEST_LOCATION );
1561
1562   // Take the actor off-stage (2nd-time)
1563   Stage::GetCurrent().Remove(actor);
1564   application.SendNotification();
1565   application.Render(0);
1566   DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), constrainedRotation, ROTATION_EPSILON, TEST_LOCATION );
1567
1568   // Remove the constraint, and set back to startValue
1569   actor.RemoveConstraints();
1570   actor.SetProperty( index, startValue );
1571   application.SendNotification();
1572   application.Render(0);
1573   DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), startValue, ROTATION_EPSILON, TEST_LOCATION );
1574
1575   // Add actor to stage (3rd time)
1576   Stage::GetCurrent().Add(actor);
1577   application.SendNotification();
1578   application.Render(0);
1579
1580   // Constraint should be gone
1581   DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), startValue, ROTATION_EPSILON, TEST_LOCATION );
1582
1583   // Check that nothing has changed after a couple of buffer swaps
1584   application.Render(0);
1585   DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), startValue, ROTATION_EPSILON, TEST_LOCATION );
1586   application.Render(0);
1587   DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), startValue, ROTATION_EPSILON, TEST_LOCATION );
1588   END_TEST;
1589 }
1590
1591 int UtcDaliConstraintNewLocalInput(void)
1592 {
1593   TestApplication application;
1594
1595   Actor actor = Actor::New();
1596   Stage::GetCurrent().Add(actor);
1597
1598   Vector3 startValue( 0.0f, 0.0f, 0.0f );
1599   float distanceWhenFullyTransparent( 100.0f );
1600
1601   /**
1602    * Test that the Constraint is correctly applied on a clean Node
1603    */
1604   application.SendNotification();
1605   application.Render(0);
1606   DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1607   application.Render(0);
1608   DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1609   application.Render(0);
1610   DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1611
1612   // Apply constraint with a local input property
1613
1614   Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
1615                                                     LocalSource( Actor::COLOR ),
1616                                                     MoveAwayWithFadeConstraint(distanceWhenFullyTransparent) );
1617
1618   actor.ApplyConstraint( constraint );
1619   DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1620
1621   application.SendNotification();
1622   application.Render(0);
1623
1624   // Gradually set the color to fully-transparent; the actor should move back
1625
1626   for ( float progress = 0.0f; progress < 1.1f; progress += 0.1f )
1627   {
1628     actor.SetOpacity( 1.0f - progress );
1629
1630     application.SendNotification();
1631     application.Render(0);
1632     DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), ( startValue - Vector3(0.0f, 0.0f, progress*distanceWhenFullyTransparent) ), POSITION_EPSILON, TEST_LOCATION );
1633   }
1634   DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), ( startValue - Vector3(0.0f, 0.0f, distanceWhenFullyTransparent) ), POSITION_EPSILON, TEST_LOCATION );
1635   END_TEST;
1636 }
1637
1638 int UtcDaliConstraintNewParentInput(void)
1639 {
1640   TestApplication application;
1641
1642   Actor parent = Actor::New();
1643   Vector3 parentStartSize( 100.0f, 100.0f, 0.0f );
1644   parent.SetSize( parentStartSize );
1645   Stage::GetCurrent().Add( parent );
1646
1647   Actor actor = Actor::New();
1648   parent.Add( actor );
1649
1650   Vector3 startValue( 0.0f, 0.0f, 0.0f );
1651
1652   /**
1653    * Test that the Constraint is correctly applied on a clean Node
1654    */
1655   application.SendNotification();
1656   application.Render(0);
1657   DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1658   application.Render(0);
1659   DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1660   application.Render(0);
1661   DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1662
1663   // Apply constraint with a parent input property
1664
1665   Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
1666                                                     ParentSource( Actor::SIZE ),
1667                                                     TestBottomRightAlignConstraint() );
1668
1669   actor.ApplyConstraint( constraint );
1670   DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1671
1672   application.SendNotification();
1673   application.Render(0);
1674
1675   DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), parentStartSize,         TEST_LOCATION );
1676   DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), parent.GetCurrentSize(), TEST_LOCATION );
1677
1678   // Gradually shrink the parent; the actor should move inwards
1679
1680   for ( float progress = 0.0f; progress < 1.1f; progress += 0.1f )
1681   {
1682     Vector3 size( parentStartSize * std::max(0.0f, 1.0f - progress) );
1683     parent.SetSize( size );
1684
1685     application.SendNotification();
1686     application.Render(0);
1687
1688     DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), size,                    POSITION_EPSILON, TEST_LOCATION );
1689     DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), parent.GetCurrentSize(), POSITION_EPSILON, TEST_LOCATION );
1690   }
1691   DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), Vector3::ZERO, POSITION_EPSILON, TEST_LOCATION );
1692   END_TEST;
1693 }
1694
1695 int UtcDaliConstraintNewInput1(void)
1696 {
1697   TestApplication application;
1698
1699   Actor parent = Actor::New();
1700   Vector3 parentStartSize( 100.0f, 100.0f, 0.0f );
1701   parent.SetSize( parentStartSize );
1702   Stage::GetCurrent().Add( parent );
1703
1704   Actor actor = Actor::New();
1705   parent.Add( actor );
1706
1707   Actor sibling1 = Actor::New();
1708   sibling1.SetPosition( Vector3(1.0f, 2.0f, 3.0f) );
1709   parent.Add( sibling1 );
1710
1711   Vector3 startValue( 0.0f, 0.0f, 0.0f );
1712
1713   /**
1714    * Test that the Constraint is correctly applied on a clean Node
1715    */
1716   application.SendNotification();
1717   application.Render(0);
1718   DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1719   application.Render(0);
1720   DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1721   application.Render(0);
1722   DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1723
1724   // Apply constraint with a parent input property
1725
1726   Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
1727                                                     Source( sibling1, Actor::POSITION ),
1728                                                     MeanPositionConstraint1() );
1729
1730   actor.ApplyConstraint( constraint );
1731   DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1732
1733   application.SendNotification();
1734   application.Render(0);
1735   DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), sibling1.GetCurrentPosition(), TEST_LOCATION );
1736
1737   // Check that nothing has changed after a couple of buffer swaps
1738   application.Render(0);
1739   DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), sibling1.GetCurrentPosition(), TEST_LOCATION );
1740   application.Render(0);
1741   DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), sibling1.GetCurrentPosition(), TEST_LOCATION );
1742   END_TEST;
1743 }
1744
1745 int UtcDaliConstraintNewInput2(void)
1746 {
1747   TestApplication application;
1748
1749   Actor parent = Actor::New();
1750   Vector3 parentStartSize( 100.0f, 100.0f, 0.0f );
1751   parent.SetSize( parentStartSize );
1752   Stage::GetCurrent().Add( parent );
1753
1754   Actor actor = Actor::New();
1755   parent.Add( actor );
1756
1757   Actor sibling1 = Actor::New();
1758   sibling1.SetPosition( Vector3(1.0f, 2.0f, 3.0f) );
1759   parent.Add( sibling1 );
1760
1761   Actor sibling2 = Actor::New();
1762   sibling2.SetPosition( Vector3(300.0f, 300.0f, 300.0f) );
1763   parent.Add( sibling2 );
1764
1765   application.SendNotification();
1766   application.Render(0);
1767
1768   Vector3 startValue( 0.0f, 0.0f, 0.0f );
1769   Vector3 meanValue = sibling1.GetCurrentPosition() +
1770                       sibling2.GetCurrentPosition();
1771   meanValue *= (1.0f / 2.0f); // divide by number of siblings
1772
1773   /**
1774    * Test that the Constraint is correctly applied on a clean Node
1775    */
1776   application.SendNotification();
1777   application.Render(0);
1778   DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1779   application.Render(0);
1780   DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1781   application.Render(0);
1782   DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1783
1784   // Apply constraint with a parent input property
1785
1786   Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
1787                                                     Source( sibling1, Actor::POSITION ),
1788                                                     Source( sibling2, Actor::POSITION ),
1789                                                     MeanPositionConstraint2() );
1790
1791   actor.ApplyConstraint( constraint );
1792   DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1793
1794   application.SendNotification();
1795   application.Render(0);
1796   DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION );
1797
1798   // Check that nothing has changed after a couple of buffer swaps
1799   application.Render(0);
1800   DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION );
1801   application.Render(0);
1802   DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION );
1803   END_TEST;
1804 }
1805
1806 int UtcDaliConstraintNewInput3(void)
1807 {
1808   TestApplication application;
1809
1810   Actor parent = Actor::New();
1811   Vector3 parentStartSize( 100.0f, 100.0f, 0.0f );
1812   parent.SetSize( parentStartSize );
1813   Stage::GetCurrent().Add( parent );
1814
1815   Actor actor = Actor::New();
1816   parent.Add( actor );
1817
1818   Actor sibling1 = Actor::New();
1819   sibling1.SetPosition( Vector3(1.0f, 2.0f, 3.0f) );
1820   parent.Add( sibling1 );
1821
1822   Actor sibling2 = Actor::New();
1823   sibling2.SetPosition( Vector3(300.0f, 300.0f, 300.0f) );
1824   parent.Add( sibling2 );
1825
1826   Actor sibling3 = Actor::New();
1827   sibling3.SetPosition( Vector3(-100.0f, -10.0f, -1.0f) );
1828   parent.Add( sibling3 );
1829
1830   application.SendNotification();
1831   application.Render(0);
1832
1833   Vector3 startValue( 0.0f, 0.0f, 0.0f );
1834   Vector3 meanValue = sibling1.GetCurrentPosition() +
1835                       sibling2.GetCurrentPosition() +
1836                       sibling3.GetCurrentPosition();
1837   meanValue *= (1.0f / 3.0f); // divide by number of siblings
1838
1839   /**
1840    * Test that the Constraint is correctly applied on a clean Node
1841    */
1842   application.SendNotification();
1843   application.Render(0);
1844   DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1845   application.Render(0);
1846   DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1847   application.Render(0);
1848   DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1849
1850   // Apply constraint with a parent input property
1851
1852   Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
1853                                                     Source( sibling1, Actor::POSITION ),
1854                                                     Source( sibling2, Actor::POSITION ),
1855                                                     Source( sibling3, Actor::POSITION ),
1856                                                     MeanPositionConstraint3() );
1857
1858   actor.ApplyConstraint( constraint );
1859   DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1860
1861   application.SendNotification();
1862   application.Render(0);
1863   DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION );
1864
1865   // Check that nothing has changed after a couple of buffer swaps
1866   application.Render(0);
1867   DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION );
1868   application.Render(0);
1869   DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION );
1870   END_TEST;
1871 }
1872
1873 int UtcDaliConstraintNewInput4(void)
1874 {
1875   TestApplication application;
1876
1877   Actor parent = Actor::New();
1878   Vector3 parentStartSize( 100.0f, 100.0f, 0.0f );
1879   parent.SetSize( parentStartSize );
1880   parent.SetPosition( 10.0f, 10.0f, 10.0f );
1881   Stage::GetCurrent().Add( parent );
1882
1883   Actor actor = Actor::New();
1884   parent.Add( actor );
1885
1886   Actor sibling1 = Actor::New();
1887   sibling1.SetPosition( Vector3(1.0f, 2.0f, 3.0f) );
1888   parent.Add( sibling1 );
1889
1890   Actor sibling2 = Actor::New();
1891   sibling2.SetPosition( Vector3(300.0f, 300.0f, 300.0f) );
1892   parent.Add( sibling2 );
1893
1894   Actor sibling3 = Actor::New();
1895   sibling3.SetPosition( Vector3(-100.0f, -10.0f, -1.0f) );
1896   parent.Add( sibling3 );
1897
1898   application.SendNotification();
1899   application.Render(0);
1900
1901   Vector3 startValue( 0.0f, 0.0f, 0.0f );
1902   Vector3 meanValue = parent.GetCurrentPosition() +
1903                       sibling1.GetCurrentPosition() +
1904                       sibling2.GetCurrentPosition() +
1905                       sibling3.GetCurrentPosition();
1906   meanValue *= (1.0f / 4.0f); // divide by number of positions
1907
1908   /**
1909    * Test that the Constraint is correctly applied on a clean Node
1910    */
1911   application.SendNotification();
1912   application.Render(0);
1913   DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1914   application.Render(0);
1915   DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1916   application.Render(0);
1917   DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1918
1919   // Apply constraint with a parent input property
1920
1921   Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
1922                                                     Source( sibling1, Actor::POSITION ),
1923                                                     Source( sibling2, Actor::POSITION ),
1924                                                     ParentSource( Actor::POSITION ),
1925                                                     Source( sibling3, Actor::POSITION ),
1926                                                     MeanPositionConstraint4() );
1927
1928   actor.ApplyConstraint( constraint );
1929   DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1930
1931   application.SendNotification();
1932   application.Render(0);
1933   DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION );
1934
1935   // Check that nothing has changed after a couple of buffer swaps
1936   application.Render(0);
1937   DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION );
1938   application.Render(0);
1939   DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION );
1940   END_TEST;
1941 }
1942
1943 int UtcDaliConstraintNewInput5(void)
1944 {
1945   TestApplication application;
1946
1947   Actor parent = Actor::New();
1948   Vector3 parentStartSize( 100.0f, 100.0f, 0.0f );
1949   parent.SetSize( parentStartSize );
1950   parent.SetPosition( 10.0f, 10.0f, 10.0f );
1951   Stage::GetCurrent().Add( parent );
1952
1953   Actor actor = Actor::New();
1954   parent.Add( actor );
1955
1956   Actor sibling1 = Actor::New();
1957   sibling1.SetPosition( Vector3(1.0f, 2.0f, 3.0f) );
1958   parent.Add( sibling1 );
1959
1960   Actor sibling2 = Actor::New();
1961   sibling2.SetPosition( Vector3(300.0f, 300.0f, 300.0f) );
1962   parent.Add( sibling2 );
1963
1964   Actor sibling3 = Actor::New();
1965   sibling3.SetPosition( Vector3(-100.0f, -10.0f, -1.0f) );
1966   parent.Add( sibling3 );
1967
1968   Actor sibling4 = Actor::New();
1969   sibling4.SetPosition( Vector3(-1.0f, 1.0f, 2.0f) );
1970   parent.Add( sibling4 );
1971
1972   application.SendNotification();
1973   application.Render(0);
1974
1975   Vector3 startValue( 0.0f, 0.0f, 0.0f );
1976   Vector3 meanValue = parent.GetCurrentPosition() +
1977                       sibling1.GetCurrentPosition() +
1978                       sibling2.GetCurrentPosition() +
1979                       sibling3.GetCurrentPosition() +
1980                       sibling4.GetCurrentPosition();
1981   meanValue *= (1.0f / 5.0f); // divide by number of positions
1982
1983   /**
1984    * Test that the Constraint is correctly applied on a clean Node
1985    */
1986   application.SendNotification();
1987   application.Render(0);
1988   DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1989   application.Render(0);
1990   DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1991   application.Render(0);
1992   DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1993
1994   // Apply constraint with a parent input property
1995
1996   Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
1997                                                     Source( sibling1, Actor::POSITION ),
1998                                                     Source( sibling2, Actor::POSITION ),
1999                                                     ParentSource( Actor::POSITION ),
2000                                                     Source( sibling3, Actor::POSITION ),
2001                                                     Source( sibling4, Actor::POSITION ),
2002                                                     MeanPositionConstraint5() );
2003
2004   actor.ApplyConstraint( constraint );
2005   DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
2006
2007   application.SendNotification();
2008   application.Render(0);
2009   DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION );
2010
2011   // Check that nothing has changed after a couple of buffer swaps
2012   application.Render(0);
2013   DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION );
2014   application.Render(0);
2015   DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION );
2016   END_TEST;
2017 }
2018
2019 int UtcDaliConstraintNewInput6(void)
2020 {
2021   TestApplication application;
2022
2023   Actor parent = Actor::New();
2024   Vector3 parentStartSize( 100.0f, 100.0f, 0.0f );
2025   parent.SetSize( parentStartSize );
2026   parent.SetPosition( 10.0f, 10.0f, 10.0f );
2027   Stage::GetCurrent().Add( parent );
2028
2029   Actor actor = Actor::New();
2030   parent.Add( actor );
2031
2032   Actor child = Actor::New();
2033   child.SetPosition( Vector3(7.0f, 7.0f, 7.0f) );
2034   actor.Add( child );
2035
2036   Actor sibling1 = Actor::New();
2037   sibling1.SetPosition( Vector3(1.0f, 2.0f, 3.0f) );
2038   parent.Add( sibling1 );
2039
2040   Actor sibling2 = Actor::New();
2041   sibling2.SetPosition( Vector3(300.0f, 300.0f, 300.0f) );
2042   parent.Add( sibling2 );
2043
2044   Actor sibling3 = Actor::New();
2045   sibling3.SetPosition( Vector3(-100.0f, -10.0f, -1.0f) );
2046   parent.Add( sibling3 );
2047
2048   Actor sibling4 = Actor::New();
2049   sibling4.SetPosition( Vector3(-1.0f, 1.0f, 2.0f) );
2050   parent.Add( sibling4 );
2051
2052   application.SendNotification();
2053   application.Render(0);
2054
2055   Vector3 startValue( 0.0f, 0.0f, 0.0f );
2056   Vector3 meanValue = parent.GetCurrentPosition() +
2057                       child.GetCurrentPosition() +
2058                       sibling1.GetCurrentPosition() +
2059                       sibling2.GetCurrentPosition() +
2060                       sibling3.GetCurrentPosition() +
2061                       sibling4.GetCurrentPosition();
2062   meanValue *= (1.0f / 6.0f); // divide by number of positions
2063
2064   /**
2065    * Test that the Constraint is correctly applied on a clean Node
2066    */
2067   application.SendNotification();
2068   application.Render(0);
2069   DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
2070   application.Render(0);
2071   DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
2072   application.Render(0);
2073   DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
2074
2075   // Apply constraint with a parent input property
2076
2077   Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
2078                                                     Source( child, Actor::POSITION ),
2079                                                     Source( sibling1, Actor::POSITION ),
2080                                                     Source( sibling2, Actor::POSITION ),
2081                                                     ParentSource( Actor::POSITION ),
2082                                                     Source( sibling3, Actor::POSITION ),
2083                                                     Source( sibling4, Actor::POSITION ),
2084                                                     MeanPositionConstraint6() );
2085
2086   actor.ApplyConstraint( constraint );
2087   DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
2088
2089   application.SendNotification();
2090   application.Render(0);
2091   DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION );
2092
2093   // Check that nothing has changed after a couple of buffer swaps
2094   application.Render(0);
2095   DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION );
2096   application.Render(0);
2097   DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION );
2098   END_TEST;
2099 }
2100
2101 int UtcDaliConstraintDownCast(void)
2102 {
2103   TestApplication application;
2104   tet_infoline("Testing Dali::Constraint::DownCast()");
2105
2106   Actor actor = Actor::New();
2107
2108   // Register a boolean property
2109   bool startValue(false);
2110   Property::Index index = actor.RegisterProperty( "test-property", startValue );
2111   Constraint constraint = Constraint::New<bool>( index, TestAlwaysTrueConstraint() );
2112
2113   BaseHandle object(constraint);
2114
2115   Constraint constraint2 = Constraint::DownCast(object);
2116   DALI_TEST_CHECK(constraint2);
2117
2118   Constraint constraint3 = DownCast< Constraint >(object);
2119   DALI_TEST_CHECK(constraint3);
2120
2121   BaseHandle unInitializedObject;
2122   Constraint constraint4 = Constraint::DownCast(unInitializedObject);
2123   DALI_TEST_CHECK(!constraint4);
2124
2125   Constraint constraint5 = DownCast< Constraint >(unInitializedObject);
2126   DALI_TEST_CHECK(!constraint5);
2127   END_TEST;
2128 }
2129
2130 int UtcDaliConstraintSetApplyTime(void)
2131 {
2132   TestApplication application;
2133
2134   // Build constraint
2135
2136   Vector4 targetColor(Color::BLACK);
2137   Constraint constraint = Constraint::New<Vector4>( Actor::COLOR, TestColorConstraint(targetColor) );
2138   DALI_TEST_EQUALS(constraint.GetApplyTime(), TimePeriod(0.0f), TEST_LOCATION);
2139
2140   float applySeconds(7.0f);
2141   constraint.SetApplyTime(applySeconds);
2142   DALI_TEST_EQUALS(constraint.GetApplyTime(), TimePeriod(applySeconds), TEST_LOCATION);
2143
2144   // Apply to an actor
2145
2146   Actor actor = Actor::New();
2147   Stage::GetCurrent().Add(actor);
2148
2149   actor.ApplyConstraint( constraint );
2150   DALI_TEST_EQUALS( actor.GetCurrentColor(), Color::WHITE, TEST_LOCATION );
2151
2152   application.SendNotification();
2153   application.Render(static_cast<unsigned int>(applySeconds*200.0f)/* 20% progress */);
2154
2155   // Constraint shouldn't be fully applied yet
2156   Vector4 twentyPercentColor( Color::WHITE.x*0.8f, Color::WHITE.y*0.8f, Color::WHITE.z*0.8f, Color::WHITE.a );
2157   DALI_TEST_EQUALS( actor.GetCurrentColor(), twentyPercentColor, TEST_LOCATION );
2158
2159   // Constraint shouldn't be fully applied yet
2160   application.Render(static_cast<unsigned int>(applySeconds*200.0f)/* 40% progress */);
2161   Vector4 fourtyPercentColor( Color::WHITE.x*0.6f, Color::WHITE.y*0.6f, Color::WHITE.z*0.6f, Color::WHITE.a );
2162   DALI_TEST_EQUALS( actor.GetCurrentColor(), fourtyPercentColor, TEST_LOCATION );
2163
2164   // Constraint shouldn't be fully applied yet
2165   application.Render(static_cast<unsigned int>(applySeconds*200.0f)/* 60% progress */);
2166   Vector4 sixtyPercentColor( Color::WHITE.x*0.4f, Color::WHITE.y*0.4f, Color::WHITE.z*0.4f, Color::WHITE.a );
2167   DALI_TEST_EQUALS( actor.GetCurrentColor(), sixtyPercentColor, TEST_LOCATION );
2168
2169   // Constraint shouldn't be fully applied yet
2170   application.Render(static_cast<unsigned int>(applySeconds*200.0f)/* 80% progress */);
2171   Vector4 eightyPercentColor( Color::WHITE.x*0.2f, Color::WHITE.y*0.2f, Color::WHITE.z*0.2f, Color::WHITE.a );
2172   DALI_TEST_EQUALS( actor.GetCurrentColor(), eightyPercentColor, TEST_LOCATION );
2173
2174   // Constraint should be fully applied
2175   application.Render(static_cast<unsigned int>(applySeconds*200.0f)/* 100% progress */);
2176   DALI_TEST_EQUALS( actor.GetCurrentColor(), targetColor, TEST_LOCATION );
2177
2178   // Constraint should still be fully applied
2179   application.Render(static_cast<unsigned int>(applySeconds*200.0f)/* Still 100% progress */);
2180   DALI_TEST_EQUALS( actor.GetCurrentColor(), targetColor, TEST_LOCATION );
2181
2182   // Check that nothing has changed after a couple of buffer swaps
2183   application.Render(0);
2184   DALI_TEST_EQUALS( actor.GetCurrentColor(), targetColor, TEST_LOCATION );
2185   application.Render(0);
2186   DALI_TEST_EQUALS( actor.GetCurrentColor(), targetColor, TEST_LOCATION );
2187   END_TEST;
2188 }
2189
2190 int UtcDaliConstraintGetApplyTime(void)
2191 {
2192   TestApplication application;
2193
2194   Constraint constraint = Constraint::New<Vector4>( Actor::COLOR, TestConstraint() );
2195   DALI_TEST_EQUALS(constraint.GetApplyTime(), TimePeriod(0.0f), TEST_LOCATION);
2196
2197   float applySeconds(7.0f);
2198   constraint.SetApplyTime(applySeconds);
2199   DALI_TEST_EQUALS(constraint.GetApplyTime(), TimePeriod(applySeconds), TEST_LOCATION);
2200
2201   constraint.SetApplyTime(applySeconds - 3.0f);
2202   DALI_TEST_EQUALS(constraint.GetApplyTime(), TimePeriod(applySeconds - 3.0f), TEST_LOCATION);
2203   END_TEST;
2204 }
2205
2206 int UtcDaliConstraintSetRemoveTime(void)
2207 {
2208   TestApplication application;
2209
2210   Vector3 sourcePosition(0.0f, 0.0f, 0.0f);
2211   Vector3 targetPosition(100.0f, 100.0f, 100.0f);
2212
2213   // Build constraint
2214
2215   Constraint constraint = Constraint::New<Vector3>( Actor::POSITION, TestPositionConstraint(targetPosition) );
2216   DALI_TEST_EQUALS(constraint.GetRemoveTime(), TimePeriod(0.0f), TEST_LOCATION);
2217
2218   float removeSeconds(8.0f);
2219   constraint.SetRemoveTime(removeSeconds);
2220   DALI_TEST_EQUALS(constraint.GetRemoveTime(), TimePeriod(removeSeconds), TEST_LOCATION);
2221
2222   // Apply to an actor
2223
2224   Actor actor = Actor::New();
2225   Stage::GetCurrent().Add(actor);
2226
2227   actor.ApplyConstraint( constraint );
2228   DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION );
2229
2230   application.SendNotification();
2231   application.Render(100u/*0.1 seconds*/);
2232
2233   // Constraint should be fully applied
2234   DALI_TEST_EQUALS( actor.GetCurrentPosition(), targetPosition, TEST_LOCATION );
2235
2236   // Check that nothing has changed after a couple of buffer swaps
2237   application.Render(0);
2238   DALI_TEST_EQUALS( actor.GetCurrentPosition(), targetPosition, TEST_LOCATION );
2239   application.Render(0);
2240   DALI_TEST_EQUALS( actor.GetCurrentPosition(), targetPosition, TEST_LOCATION );
2241
2242   // Remove from the actor, and set to alternative position
2243
2244   actor.RemoveConstraints();
2245
2246   Vector3 thirdPosition(200.0f, 200.0f, 200.0f);
2247   actor.SetPosition(thirdPosition); // Go back to 3rd position
2248
2249   application.SendNotification();
2250   application.Render(static_cast<unsigned int>(removeSeconds*200.0f)/* 20% removal progress */);
2251
2252   // Constraint shouldn't be fully removed yet
2253   Vector3 twentyPercentBack( targetPosition + (thirdPosition - targetPosition)*0.2f );
2254   DALI_TEST_EQUALS( actor.GetCurrentPosition(), twentyPercentBack, TEST_LOCATION );
2255
2256   application.Render(static_cast<unsigned int>(removeSeconds*200.0f)/* 40% removal progress */);
2257
2258   // Constraint shouldn't be fully removed yet
2259   Vector3 fourtyPercentBack( targetPosition + (thirdPosition - targetPosition)*0.4f );
2260   DALI_TEST_EQUALS( actor.GetCurrentPosition(), fourtyPercentBack, TEST_LOCATION );
2261
2262   application.Render(static_cast<unsigned int>(removeSeconds*200.0f)/* 60% removal progress */);
2263
2264   // Constraint shouldn't be fully removed yet
2265   Vector3 sixtyPercentBack( targetPosition + (thirdPosition - targetPosition)*0.6f );
2266   DALI_TEST_EQUALS( actor.GetCurrentPosition(), sixtyPercentBack, TEST_LOCATION );
2267
2268   application.Render(static_cast<unsigned int>(removeSeconds*200.0f)/* 80% removal progress */);
2269
2270   // Constraint shouldn't be fully removed yet
2271   Vector3 eightyPercentBack( targetPosition + (thirdPosition - targetPosition)*0.8f );
2272   DALI_TEST_EQUALS( actor.GetCurrentPosition(), eightyPercentBack, TEST_LOCATION );
2273
2274   // Constraint should be fully removed
2275   application.Render(static_cast<unsigned int>(removeSeconds*200.0f)/* 100% removal progress */);
2276   DALI_TEST_EQUALS( actor.GetCurrentPosition(), thirdPosition, TEST_LOCATION );
2277
2278   // Constraint should still be fully applied
2279   application.Render(static_cast<unsigned int>(removeSeconds*200.0f)/* Still 100% removal progress */);
2280   DALI_TEST_EQUALS( actor.GetCurrentPosition(), thirdPosition, TEST_LOCATION );
2281
2282   // Check that nothing has changed after a couple of buffer swaps
2283   application.Render(0);
2284   DALI_TEST_EQUALS( actor.GetCurrentPosition(), thirdPosition, TEST_LOCATION );
2285   application.Render(0);
2286   DALI_TEST_EQUALS( actor.GetCurrentPosition(), thirdPosition, TEST_LOCATION );
2287   END_TEST;
2288 }
2289
2290 int UtcDaliConstraintGetRemoveTime(void)
2291 {
2292   TestApplication application;
2293
2294   Constraint constraint = Constraint::New<Vector4>( Actor::COLOR, TestConstraint() );
2295   DALI_TEST_EQUALS(constraint.GetRemoveTime(), TimePeriod(0.0f), TEST_LOCATION);
2296   END_TEST;
2297 }
2298
2299 int UtcDaliConstraintSetAlphaFunction(void)
2300 {
2301   TestApplication application;
2302
2303   Vector3 startValue( Vector3::ZERO );
2304   Vector3 targetValue(100.0f, 100.0f, 100.0f);
2305
2306   Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
2307                                                     TestConstraintVector3( targetValue ) );
2308
2309   // Test the alpha-function itself
2310
2311   AlphaFunction func = constraint.GetAlphaFunction();
2312   DALI_TEST_EQUALS(func(0.1f), 0.1f, TEST_LOCATION); // Default is Linear
2313
2314   // Test that the alpha-function is used correctly
2315
2316   Actor actor = Actor::New();
2317   Stage::GetCurrent().Add(actor);
2318
2319   application.SendNotification();
2320   application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2321   DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
2322   application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2323   DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
2324   application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2325   DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
2326
2327   constraint.SetApplyTime( 10.0f );
2328   actor.ApplyConstraint( constraint );
2329
2330   application.SendNotification();
2331   application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2332   DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), (targetValue - startValue) * 0.1f, TEST_LOCATION );
2333   application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2334   DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), (targetValue - startValue) * 0.2f, TEST_LOCATION );
2335   application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2336   DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), (targetValue - startValue) * 0.3f, TEST_LOCATION );
2337   application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2338   DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), (targetValue - startValue) * 0.4f, TEST_LOCATION );
2339   application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2340   DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), (targetValue - startValue) * 0.5f, TEST_LOCATION );
2341   application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2342   DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), (targetValue - startValue) * 0.6f, TEST_LOCATION );
2343   application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2344   DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), (targetValue - startValue) * 0.7f, TEST_LOCATION );
2345   application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2346   DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), (targetValue - startValue) * 0.8f, TEST_LOCATION );
2347   application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2348   DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), (targetValue - startValue) * 0.9f, TEST_LOCATION );
2349   application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2350   DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), (targetValue - startValue), TEST_LOCATION );
2351
2352   // Check that the constrained value is stable
2353   application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2354   DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), (targetValue - startValue), TEST_LOCATION );
2355   application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2356   DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), (targetValue - startValue), TEST_LOCATION );
2357
2358   // Remove the constraint
2359
2360   actor.RemoveConstraints();
2361   actor.SetPosition( startValue );
2362
2363   application.SendNotification();
2364   application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2365   DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
2366   application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2367   DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
2368   application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2369   DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
2370
2371   // Change to non-linear alpha and retest
2372
2373   constraint.SetAlphaFunction(AlphaFunctions::EaseIn);
2374   func = constraint.GetAlphaFunction();
2375   DALI_TEST_CHECK(func(0.1f) < 0.09f);
2376
2377   actor.ApplyConstraint( constraint );
2378
2379   application.SendNotification();
2380   application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2381
2382   DALI_TEST_CHECK( actor.GetProperty<Vector3>( Actor::POSITION ).x > startValue.x );
2383   DALI_TEST_CHECK( actor.GetProperty<Vector3>( Actor::POSITION ).y > startValue.y );
2384   DALI_TEST_CHECK( actor.GetProperty<Vector3>( Actor::POSITION ).z > startValue.z );
2385
2386   Vector3 lessThanTenPercentProgress( (targetValue - startValue) * 0.09f );
2387   DALI_TEST_CHECK( actor.GetProperty<Vector3>( Actor::POSITION ).x < lessThanTenPercentProgress.x );
2388   DALI_TEST_CHECK( actor.GetProperty<Vector3>( Actor::POSITION ).y < lessThanTenPercentProgress.y );
2389   DALI_TEST_CHECK( actor.GetProperty<Vector3>( Actor::POSITION ).z < lessThanTenPercentProgress.z );
2390
2391   application.Render(static_cast<unsigned int>(9000.0f/*9 seconds*/));
2392   DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), (targetValue - startValue), TEST_LOCATION );
2393
2394   // Check that the constrained value is stable
2395   application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2396   DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), (targetValue - startValue), TEST_LOCATION );
2397   application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2398   DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), (targetValue - startValue), TEST_LOCATION );
2399   END_TEST;
2400 }
2401
2402 int UtcDaliConstraintGetAlphaFunction(void)
2403 {
2404   TestApplication application;
2405
2406   Constraint constraint = Constraint::New<Vector4>( Actor::COLOR, TestConstraint() );
2407
2408   AlphaFunction func = constraint.GetAlphaFunction();
2409   DALI_TEST_EQUALS(func(0.5f), 0.5f, TEST_LOCATION); // Default is Linear
2410   END_TEST;
2411 }
2412
2413 int UtcDaliConstraintSetRemoveAction(void)
2414 {
2415   TestApplication application;
2416
2417   Vector3 sourcePosition(0.0f, 0.0f, 0.0f);
2418   Vector3 targetPosition(100.0f, 100.0f, 100.0f);
2419
2420   // Build constraint, with "Discard" remove action
2421
2422   Constraint constraint = Constraint::New<Vector3>( Actor::POSITION, TestPositionConstraint(targetPosition) );
2423   DALI_TEST_EQUALS((unsigned int)constraint.GetRemoveAction(), (unsigned int)Constraint::Bake, TEST_LOCATION);
2424
2425   constraint.SetRemoveAction(Constraint::Discard);
2426   DALI_TEST_EQUALS((unsigned int)constraint.GetRemoveAction(), (unsigned int)Constraint::Discard, TEST_LOCATION);
2427
2428   float removeSeconds(8.0f);
2429   constraint.SetRemoveTime(removeSeconds);
2430   DALI_TEST_EQUALS(constraint.GetRemoveTime(), TimePeriod(removeSeconds), TEST_LOCATION);
2431
2432   // Apply to an actor
2433
2434   Actor actor = Actor::New();
2435   Stage::GetCurrent().Add(actor);
2436
2437   actor.ApplyConstraint( constraint );
2438   DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION );
2439
2440   application.SendNotification();
2441   application.Render(100u/*0.1 seconds*/);
2442
2443   // Constraint should be fully applied
2444   DALI_TEST_EQUALS( actor.GetCurrentPosition(), targetPosition, TEST_LOCATION );
2445
2446   // Check that nothing has changed after a couple of buffer swaps
2447   application.Render(0);
2448   DALI_TEST_EQUALS( actor.GetCurrentPosition(), targetPosition, TEST_LOCATION );
2449   application.Render(0);
2450   DALI_TEST_EQUALS( actor.GetCurrentPosition(), targetPosition, TEST_LOCATION );
2451
2452   // Remove from the actor
2453
2454   actor.RemoveConstraints(); // should go back to source position
2455
2456   application.SendNotification();
2457   application.Render(static_cast<unsigned int>(removeSeconds*200.0f)/* 20% removal progress */);
2458
2459   // Constraint shouldn't be fully removed yet
2460   Vector3 twentyPercentBack( targetPosition * 0.8f );
2461   DALI_TEST_EQUALS( actor.GetCurrentPosition(), twentyPercentBack, TEST_LOCATION );
2462
2463   application.Render(static_cast<unsigned int>(removeSeconds*200.0f)/* 40% removal progress */);
2464
2465   // Constraint shouldn't be fully removed yet
2466   Vector3 fourtyPercentBack( targetPosition * 0.6f );
2467   DALI_TEST_EQUALS( actor.GetCurrentPosition(), fourtyPercentBack, TEST_LOCATION );
2468
2469   application.Render(static_cast<unsigned int>(removeSeconds*200.0f)/* 60% removal progress */);
2470
2471   // Constraint shouldn't be fully removed yet
2472   Vector3 sixtyPercentBack( targetPosition * 0.4f );
2473   DALI_TEST_EQUALS( actor.GetCurrentPosition(), sixtyPercentBack, TEST_LOCATION );
2474
2475   application.Render(static_cast<unsigned int>(removeSeconds*200.0f)/* 80% removal progress */);
2476
2477   // Constraint shouldn't be fully removed yet
2478   Vector3 eightyPercentBack( targetPosition * 0.2f );
2479   DALI_TEST_EQUALS( actor.GetCurrentPosition(), eightyPercentBack, TEST_LOCATION );
2480
2481   // Constraint should be fully removed
2482   application.Render(static_cast<unsigned int>(removeSeconds*200.0f)/* 100% removal progress */);
2483   DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION );
2484
2485   // Constraint should still be fully applied
2486   application.Render(static_cast<unsigned int>(removeSeconds*200.0f)/* Still 100% removal progress */);
2487   DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION );
2488
2489   // Check that nothing has changed after a couple of buffer swaps
2490   application.Render(0);
2491   DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION );
2492   application.Render(0);
2493   DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION );
2494   END_TEST;
2495 }
2496
2497 int UtcDaliConstraintGetRemoveAction(void)
2498 {
2499   TestApplication application;
2500
2501   Constraint constraint = Constraint::New<Vector4>( Actor::COLOR, TestConstraint() );
2502   DALI_TEST_EQUALS((unsigned int)constraint.GetRemoveAction(), (unsigned int)Constraint::Bake, TEST_LOCATION);
2503
2504   constraint.SetRemoveAction(Constraint::Discard);
2505   DALI_TEST_EQUALS((unsigned int)constraint.GetRemoveAction(), (unsigned int)Constraint::Discard, TEST_LOCATION);
2506
2507   constraint.SetRemoveAction(Constraint::Bake);
2508   DALI_TEST_EQUALS((unsigned int)constraint.GetRemoveAction(), (unsigned int)Constraint::Bake, TEST_LOCATION);
2509   END_TEST;
2510 }
2511
2512 /**
2513  * Test a constraint with non-zero apply-time and remove-time, where the constraint is removed during the apply-time
2514  */
2515 int UtcDaliConstraintRemoveDuringApply(void)
2516 {
2517   TestApplication application;
2518
2519   Vector3 sourcePosition(0.0f, 0.0f, 0.0f);
2520   Vector3 targetPosition(100.0f, 100.0f, 100.0f);
2521   Vector3 halfwayPosition(targetPosition * 0.5f);
2522
2523   // Build constraint
2524
2525   Constraint constraint = Constraint::New<Vector3>( Actor::POSITION, TestPositionConstraint(targetPosition) );
2526   DALI_TEST_EQUALS((unsigned int)constraint.GetRemoveAction(), (unsigned int)Constraint::Bake, TEST_LOCATION);
2527
2528   float applySeconds(4.0f);
2529   constraint.SetApplyTime(applySeconds);
2530   DALI_TEST_EQUALS(constraint.GetApplyTime(), TimePeriod(applySeconds), TEST_LOCATION);
2531
2532   float removeSeconds(8.0f);
2533   constraint.SetRemoveTime(removeSeconds);
2534   DALI_TEST_EQUALS(constraint.GetRemoveTime(), TimePeriod(removeSeconds), TEST_LOCATION);
2535
2536   // Apply to an actor
2537
2538   Actor actor = Actor::New();
2539   Stage::GetCurrent().Add(actor);
2540
2541   actor.ApplyConstraint( constraint );
2542   DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION );
2543
2544   application.SendNotification();
2545   application.Render(static_cast<unsigned int>(applySeconds*250.0f)/* 25% progress */);
2546
2547   // Constraint shouldn't be fully applied yet
2548   Vector3 twentyFivePercent( targetPosition * 0.25f );
2549   DALI_TEST_EQUALS( actor.GetCurrentPosition(), twentyFivePercent, TEST_LOCATION );
2550
2551   application.Render(static_cast<unsigned int>(applySeconds*250.0f)/* 50% progress */);
2552
2553   // Constraint shouldn't be fully applied yet
2554   Vector3 fiftyPercent( targetPosition * 0.5f );
2555   DALI_TEST_EQUALS( actor.GetCurrentPosition(), fiftyPercent, TEST_LOCATION );
2556
2557   // Remove from the actor
2558
2559   actor.RemoveConstraints(); // should go back to source position
2560
2561   application.SendNotification();
2562   application.Render(static_cast<unsigned int>(removeSeconds*100.0f)/* 50% - 5% = 45% progress */);
2563
2564   // Constraint shouldn't be fully removed yet
2565   Vector3 fourtyFivePercent( targetPosition * 0.45f );
2566   DALI_TEST_EQUALS( actor.GetCurrentPosition(), fourtyFivePercent, TEST_LOCATION );
2567
2568   application.Render(static_cast<unsigned int>(removeSeconds*400.0f)/* 50% - 25% = 25% progress */);
2569
2570   // Constraint shouldn't be fully removed yet
2571   DALI_TEST_EQUALS( actor.GetCurrentPosition(), twentyFivePercent, TEST_LOCATION );
2572
2573   // Constraint should be fully removed
2574   application.Render(static_cast<unsigned int>(removeSeconds*500.0f)/* 0% progress */);
2575   DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION );
2576
2577   // Constraint should still be fully applied
2578   application.Render(static_cast<unsigned int>(removeSeconds*200.0f)/* Still 0% progress */);
2579   DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION );
2580
2581   // Check that nothing has changed after a couple of buffer swaps
2582   application.Render(0);
2583   DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION );
2584   application.Render(0);
2585   DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION );
2586   END_TEST;
2587 }
2588
2589 /**
2590  * Test a constraint with non-zero apply-time & zero (immediate) remove-time, where the constraint is removed during the apply-time
2591  */
2592 int UtcDaliConstraintImmediateRemoveDuringApply(void)
2593 {
2594   TestApplication application;
2595
2596   Vector3 sourcePosition(0.0f, 0.0f, 0.0f);
2597   Vector3 targetPosition(100.0f, 100.0f, 100.0f);
2598
2599   // Build constraint
2600
2601   Constraint constraint = Constraint::New<Vector3>( Actor::POSITION, TestPositionConstraint(targetPosition) );
2602   DALI_TEST_EQUALS((unsigned int)constraint.GetRemoveAction(), (unsigned int)Constraint::Bake, TEST_LOCATION);
2603
2604   float applySeconds(4.0f);
2605   constraint.SetApplyTime(applySeconds);
2606   DALI_TEST_EQUALS(constraint.GetApplyTime(), TimePeriod(applySeconds), TEST_LOCATION);
2607   DALI_TEST_EQUALS(constraint.GetRemoveTime(), TimePeriod(0.0f), TEST_LOCATION);
2608
2609   // Apply to an actor
2610
2611   Actor actor = Actor::New();
2612   Stage::GetCurrent().Add(actor);
2613
2614   actor.ApplyConstraint( constraint );
2615   DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION );
2616
2617   application.SendNotification();
2618   application.Render(static_cast<unsigned int>(applySeconds*250.0f)/* 25% progress */);
2619
2620   // Constraint shouldn't be fully applied yet
2621   Vector3 twentyFivePercent( targetPosition * 0.25f );
2622   DALI_TEST_EQUALS( actor.GetCurrentPosition(), twentyFivePercent, TEST_LOCATION );
2623
2624   application.Render(static_cast<unsigned int>(applySeconds*250.0f)/* 50% progress */);
2625
2626   // Constraint shouldn't be fully applied yet
2627   Vector3 fiftyPercent( targetPosition * 0.5f );
2628   DALI_TEST_EQUALS( actor.GetCurrentPosition(), fiftyPercent, TEST_LOCATION );
2629
2630   // Remove from the actor
2631
2632   actor.RemoveConstraints(); // should go back to source position
2633   application.SendNotification();
2634
2635   // Constraint should be fully removed
2636   application.Render(static_cast<unsigned int>(200.0f /*0.2 seconds*/));
2637   DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION );
2638
2639   // Constraint should still be fully applied
2640   application.Render(static_cast<unsigned int>(200.0f /*0.2 seconds*/));
2641   DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION );
2642
2643   // Check that nothing has changed after a couple of buffer swaps
2644   application.Render(0);
2645   DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION );
2646   application.Render(0);
2647   DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION );
2648   END_TEST;
2649 }
2650
2651 int UtcDaliConstraintActorSize(void)
2652 {
2653   TestApplication application;
2654
2655   // Build constraint, to make child 20% of parent size
2656
2657   Constraint constraint = Constraint::New<Vector3>( Actor::SIZE,
2658                                                     ParentSource( Actor::SIZE ),
2659                                                     TestRelativeConstraintVector3(0.2f) );
2660   // Apply to a child actor
2661
2662   Actor parent = Actor::New();
2663   Stage::GetCurrent().Add(parent);
2664
2665   Actor child = Actor::New();
2666   parent.Add(child);
2667
2668   child.ApplyConstraint( constraint );
2669   DALI_TEST_EQUALS( child.GetCurrentSize(), Vector3::ZERO, TEST_LOCATION );
2670
2671   // Animate the parent between two sizes
2672
2673   Vector3 targetParentSize(100.0f, 100.0f, 100.0f);
2674
2675   float durationSeconds(10.0f);
2676   Animation animation = Animation::New(durationSeconds);
2677   animation.AnimateTo( Property(parent, Actor::SIZE), targetParentSize );
2678   animation.Play();
2679
2680   application.SendNotification();
2681
2682   application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 25% progress */);
2683   DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize*0.25f, TEST_LOCATION );
2684   DALI_TEST_EQUALS( child.GetCurrentSize(),  targetParentSize*0.25f * 0.2f, TEST_LOCATION );
2685
2686   application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 50% progress */);
2687   DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize*0.5f, TEST_LOCATION );
2688   DALI_TEST_EQUALS( child.GetCurrentSize(),  targetParentSize*0.5f * 0.2f, TEST_LOCATION );
2689
2690   application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 75% progress */);
2691   DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize*0.75f, TEST_LOCATION );
2692   DALI_TEST_EQUALS( child.GetCurrentSize(),  targetParentSize*0.75f * 0.2f, TEST_LOCATION );
2693
2694   application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 100% progress */);
2695   DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize, TEST_LOCATION );
2696   DALI_TEST_EQUALS( child.GetCurrentSize(),  targetParentSize * 0.2f, TEST_LOCATION );
2697
2698   // Check that nothing has changed after a couple of buffer swaps
2699   application.Render(0);
2700   DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize, TEST_LOCATION );
2701   DALI_TEST_EQUALS( child.GetCurrentSize(),  targetParentSize * 0.2f, TEST_LOCATION );
2702   application.Render(0);
2703   DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize, TEST_LOCATION );
2704   DALI_TEST_EQUALS( child.GetCurrentSize(),  targetParentSize * 0.2f, TEST_LOCATION );
2705   END_TEST;
2706 }
2707
2708 int UtcDaliConstraintActorSizeWidth(void)
2709 {
2710   TestApplication application;
2711
2712   // Build constraint, to make child 20% of parent width
2713
2714   Constraint constraint = Constraint::New<float>( Actor::SIZE_WIDTH,
2715                                                   ParentSource( Actor::SIZE_WIDTH ),
2716                                                   TestRelativeConstraintFloat(0.2f) );
2717   // Apply to a child actor
2718
2719   Actor parent = Actor::New();
2720   Stage::GetCurrent().Add(parent);
2721
2722   Actor child = Actor::New();
2723   parent.Add(child);
2724
2725   child.ApplyConstraint( constraint );
2726   DALI_TEST_EQUALS( child.GetCurrentSize(), Vector3::ZERO, TEST_LOCATION );
2727
2728   // Animate the parent between two sizes
2729
2730   Vector3 targetParentSize(80.0f, 90.0f, 100.0f);
2731
2732   float durationSeconds(10.0f);
2733   Animation animation = Animation::New(durationSeconds);
2734   animation.AnimateTo( Property(parent, Actor::SIZE), targetParentSize );
2735   animation.Play();
2736
2737   application.SendNotification();
2738
2739   application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 25% progress */);
2740   DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize*0.25f, TEST_LOCATION );
2741   DALI_TEST_EQUALS( child.GetCurrentSize().width,  targetParentSize.width*0.25f * 0.2f, TEST_LOCATION );
2742   DALI_TEST_EQUALS( child.GetCurrentSize().height, 0.0f, TEST_LOCATION );
2743   DALI_TEST_EQUALS( child.GetCurrentSize().depth,  0.0f, TEST_LOCATION );
2744
2745   application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 50% progress */);
2746   DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize*0.5f, TEST_LOCATION );
2747   DALI_TEST_EQUALS( child.GetCurrentSize().width,  targetParentSize.width*0.5f * 0.2f, TEST_LOCATION );
2748   DALI_TEST_EQUALS( child.GetCurrentSize().height, 0.0f, TEST_LOCATION );
2749   DALI_TEST_EQUALS( child.GetCurrentSize().depth,  0.0f, TEST_LOCATION );
2750
2751   application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 75% progress */);
2752   DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize*0.75f, TEST_LOCATION );
2753   DALI_TEST_EQUALS( child.GetCurrentSize().width,  targetParentSize.width*0.75f * 0.2f, TEST_LOCATION );
2754   DALI_TEST_EQUALS( child.GetCurrentSize().height, 0.0f, TEST_LOCATION );
2755   DALI_TEST_EQUALS( child.GetCurrentSize().depth,  0.0f, TEST_LOCATION );
2756
2757   application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 100% progress */);
2758   DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize, TEST_LOCATION );
2759   DALI_TEST_EQUALS( child.GetCurrentSize().width,  targetParentSize.width * 0.2f, TEST_LOCATION );
2760   DALI_TEST_EQUALS( child.GetCurrentSize().height, 0.0f, TEST_LOCATION );
2761   DALI_TEST_EQUALS( child.GetCurrentSize().depth,  0.0f, TEST_LOCATION );
2762
2763   // Check that nothing has changed after a couple of buffer swaps
2764   application.Render(0);
2765   DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize, TEST_LOCATION );
2766   DALI_TEST_EQUALS( child.GetCurrentSize().width,  targetParentSize.width * 0.2f, TEST_LOCATION );
2767   DALI_TEST_EQUALS( child.GetCurrentSize().height, 0.0f, TEST_LOCATION );
2768   DALI_TEST_EQUALS( child.GetCurrentSize().depth,  0.0f, TEST_LOCATION );
2769
2770   application.Render(0);
2771   DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize, TEST_LOCATION );
2772   DALI_TEST_EQUALS( child.GetCurrentSize().width,  targetParentSize.width * 0.2f, TEST_LOCATION );
2773   DALI_TEST_EQUALS( child.GetCurrentSize().height, 0.0f, TEST_LOCATION );
2774   DALI_TEST_EQUALS( child.GetCurrentSize().depth,  0.0f, TEST_LOCATION );
2775   END_TEST;
2776 }
2777
2778 int UtcDaliConstraintActorSizeHeight(void)
2779 {
2780   TestApplication application;
2781
2782   // Build constraint, to make child 20% of parent height
2783
2784   Constraint constraint = Constraint::New<float>( Actor::SIZE_HEIGHT,
2785                                                   ParentSource( Actor::SIZE_HEIGHT ),
2786                                                   TestRelativeConstraintFloat(0.2f) );
2787   // Apply to a child actor
2788
2789   Actor parent = Actor::New();
2790   Stage::GetCurrent().Add(parent);
2791
2792   Actor child = Actor::New();
2793   parent.Add(child);
2794
2795   child.ApplyConstraint( constraint );
2796   DALI_TEST_EQUALS( child.GetCurrentSize(), Vector3::ZERO, TEST_LOCATION );
2797
2798   // Animate the parent between two sizes
2799
2800   Vector3 targetParentSize(80.0f, 90.0f, 100.0f);
2801
2802   float durationSeconds(10.0f);
2803   Animation animation = Animation::New(durationSeconds);
2804   animation.AnimateTo( Property(parent, Actor::SIZE), targetParentSize );
2805   animation.Play();
2806
2807   application.SendNotification();
2808
2809   application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 25% progress */);
2810   DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize*0.25f, TEST_LOCATION );
2811   DALI_TEST_EQUALS( child.GetCurrentSize().width,  0.0f, TEST_LOCATION );
2812   DALI_TEST_EQUALS( child.GetCurrentSize().height, targetParentSize.height*0.25f * 0.2f, TEST_LOCATION );
2813   DALI_TEST_EQUALS( child.GetCurrentSize().depth,  0.0f, TEST_LOCATION );
2814
2815   application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 50% progress */);
2816   DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize*0.5f, TEST_LOCATION );
2817   DALI_TEST_EQUALS( child.GetCurrentSize().width,  0.0f, TEST_LOCATION );
2818   DALI_TEST_EQUALS( child.GetCurrentSize().height, targetParentSize.height*0.5f * 0.2f, TEST_LOCATION );
2819   DALI_TEST_EQUALS( child.GetCurrentSize().depth,  0.0f, TEST_LOCATION );
2820
2821   application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 75% progress */);
2822   DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize*0.75f, TEST_LOCATION );
2823   DALI_TEST_EQUALS( child.GetCurrentSize().width,  0.0f, TEST_LOCATION );
2824   DALI_TEST_EQUALS( child.GetCurrentSize().height, targetParentSize.height*0.75f * 0.2f, TEST_LOCATION );
2825   DALI_TEST_EQUALS( child.GetCurrentSize().depth,  0.0f, TEST_LOCATION );
2826
2827   application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 100% progress */);
2828   DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize, TEST_LOCATION );
2829   DALI_TEST_EQUALS( child.GetCurrentSize().width,  0.0f, TEST_LOCATION );
2830   DALI_TEST_EQUALS( child.GetCurrentSize().height, targetParentSize.height * 0.2f, TEST_LOCATION );
2831   DALI_TEST_EQUALS( child.GetCurrentSize().depth,  0.0f, TEST_LOCATION );
2832
2833   // Check that nothing has changed after a couple of buffer swaps
2834   application.Render(0);
2835   DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize, TEST_LOCATION );
2836   DALI_TEST_EQUALS( child.GetCurrentSize().width,  0.0f, TEST_LOCATION );
2837   DALI_TEST_EQUALS( child.GetCurrentSize().height, targetParentSize.height * 0.2f, TEST_LOCATION );
2838   DALI_TEST_EQUALS( child.GetCurrentSize().depth,  0.0f, TEST_LOCATION );
2839
2840   application.Render(0);
2841   DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize, TEST_LOCATION );
2842   DALI_TEST_EQUALS( child.GetCurrentSize().width,  0.0f, TEST_LOCATION );
2843   DALI_TEST_EQUALS( child.GetCurrentSize().height, targetParentSize.height * 0.2f, TEST_LOCATION );
2844   DALI_TEST_EQUALS( child.GetCurrentSize().depth,  0.0f, TEST_LOCATION );
2845   END_TEST;
2846 }
2847
2848 int UtcDaliConstraintActorSizeDepth(void)
2849 {
2850   TestApplication application;
2851
2852   // Build constraint, to make child 20% of parent height
2853
2854   Constraint constraint = Constraint::New<float>( Actor::SIZE_DEPTH,
2855                                                   ParentSource( Actor::SIZE_DEPTH ),
2856                                                   TestRelativeConstraintFloat(0.2f) );
2857   // Apply to a child actor
2858
2859   Actor parent = Actor::New();
2860   Stage::GetCurrent().Add(parent);
2861
2862   Actor child = Actor::New();
2863   parent.Add(child);
2864
2865   child.ApplyConstraint( constraint );
2866   DALI_TEST_EQUALS( child.GetCurrentSize(), Vector3::ZERO, TEST_LOCATION );
2867
2868   // Animate the parent between two sizes
2869
2870   Vector3 targetParentSize(80.0f, 90.0f, 100.0f);
2871
2872   float durationSeconds(10.0f);
2873   Animation animation = Animation::New(durationSeconds);
2874   animation.AnimateTo( Property(parent, Actor::SIZE), targetParentSize );
2875   animation.Play();
2876
2877   application.SendNotification();
2878
2879   application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 25% progress */);
2880   DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize*0.25f, TEST_LOCATION );
2881   DALI_TEST_EQUALS( child.GetCurrentSize().width,  0.0f, TEST_LOCATION );
2882   DALI_TEST_EQUALS( child.GetCurrentSize().height, 0.0f, TEST_LOCATION );
2883   DALI_TEST_EQUALS( child.GetCurrentSize().depth,  targetParentSize.depth*0.25f * 0.2f, TEST_LOCATION );
2884
2885   application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 50% progress */);
2886   DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize*0.5f, TEST_LOCATION );
2887   DALI_TEST_EQUALS( child.GetCurrentSize().width,  0.0f, TEST_LOCATION );
2888   DALI_TEST_EQUALS( child.GetCurrentSize().height, 0.0f, TEST_LOCATION );
2889   DALI_TEST_EQUALS( child.GetCurrentSize().depth,  targetParentSize.depth*0.5f * 0.2f, TEST_LOCATION );
2890
2891   application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 75% progress */);
2892   DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize*0.75f, TEST_LOCATION );
2893   DALI_TEST_EQUALS( child.GetCurrentSize().width,  0.0f, TEST_LOCATION );
2894   DALI_TEST_EQUALS( child.GetCurrentSize().height, 0.0f, TEST_LOCATION );
2895   DALI_TEST_EQUALS( child.GetCurrentSize().depth,  targetParentSize.depth*0.75f * 0.2f, TEST_LOCATION );
2896
2897   application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 100% progress */);
2898   DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize, TEST_LOCATION );
2899   DALI_TEST_EQUALS( child.GetCurrentSize().width,  0.0f, TEST_LOCATION );
2900   DALI_TEST_EQUALS( child.GetCurrentSize().height, 0.0f, TEST_LOCATION );
2901   DALI_TEST_EQUALS( child.GetCurrentSize().depth,  targetParentSize.depth * 0.2f, TEST_LOCATION );
2902
2903   // Check that nothing has changed after a couple of buffer swaps
2904   application.Render(0);
2905   DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize, TEST_LOCATION );
2906   DALI_TEST_EQUALS( child.GetCurrentSize().width,  0.0f, TEST_LOCATION );
2907   DALI_TEST_EQUALS( child.GetCurrentSize().height, 0.0f, TEST_LOCATION );
2908   DALI_TEST_EQUALS( child.GetCurrentSize().depth,  targetParentSize.depth * 0.2f, TEST_LOCATION );
2909
2910   application.Render(0);
2911   DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize, TEST_LOCATION );
2912   DALI_TEST_EQUALS( child.GetCurrentSize().width,  0.0f, TEST_LOCATION );
2913   DALI_TEST_EQUALS( child.GetCurrentSize().height, 0.0f, TEST_LOCATION );
2914   DALI_TEST_EQUALS( child.GetCurrentSize().depth,  targetParentSize.depth * 0.2f, TEST_LOCATION );
2915   END_TEST;
2916 }
2917
2918 int UtcDaliConstraintInputWorldPosition(void)
2919 {
2920   TestApplication application;
2921
2922   Actor parent = Actor::New();
2923   Vector3 parentPosition( 10.0f, 10.0f, 10.0f );
2924   parent.SetPosition( parentPosition );
2925   parent.SetParentOrigin( ParentOrigin::CENTER );
2926   parent.SetAnchorPoint( AnchorPoint::CENTER );
2927   Stage::GetCurrent().Add( parent );
2928
2929   Actor child = Actor::New();
2930   child.SetParentOrigin( ParentOrigin::CENTER );
2931   child.SetAnchorPoint( AnchorPoint::CENTER );
2932   Vector3 childPosition( 10.0f, 10.0f, 10.0f );
2933   child.SetPosition( childPosition );
2934   parent.Add( child );
2935
2936   Actor trackingActor = Actor::New();
2937   trackingActor.SetParentOrigin( ParentOrigin::CENTER );
2938   trackingActor.SetAnchorPoint( AnchorPoint::CENTER );
2939   Stage::GetCurrent().Add( trackingActor );
2940
2941   // The actors should not have a world position yet
2942   DALI_TEST_EQUALS( parent.GetCurrentWorldPosition(), Vector3::ZERO, TEST_LOCATION );
2943   DALI_TEST_EQUALS( child.GetCurrentWorldPosition(), Vector3::ZERO, TEST_LOCATION );
2944   DALI_TEST_EQUALS( trackingActor.GetCurrentWorldPosition(), Vector3::ZERO, TEST_LOCATION );
2945
2946   application.SendNotification();
2947   application.Render(0);
2948
2949   DALI_TEST_EQUALS( parent.GetCurrentPosition(), parentPosition, TEST_LOCATION );
2950   DALI_TEST_EQUALS( child.GetCurrentPosition(), childPosition, TEST_LOCATION );
2951   DALI_TEST_EQUALS( trackingActor.GetCurrentPosition(), Vector3::ZERO, TEST_LOCATION );
2952
2953   DALI_TEST_EQUALS( parent.GetCurrentWorldPosition(), parentPosition, TEST_LOCATION );
2954   Vector3 previousPosition( parentPosition + childPosition );
2955   DALI_TEST_EQUALS( child.GetCurrentWorldPosition(), previousPosition, TEST_LOCATION );
2956   DALI_TEST_EQUALS( trackingActor.GetCurrentWorldPosition(), Vector3::ZERO, TEST_LOCATION );
2957
2958   // Build constraint, to make actor track the world-position of another actor
2959   // Note that the world-position is always from the previous frame, so the tracking actor will lag behind
2960
2961   Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
2962                                                     Source( child, Actor::WORLD_POSITION ),
2963                                                     EqualToConstraint() );
2964
2965   trackingActor.ApplyConstraint( constraint );
2966
2967   application.SendNotification();
2968   application.Render(0);
2969
2970   DALI_TEST_EQUALS( trackingActor.GetCurrentPosition(), previousPosition, TEST_LOCATION );
2971
2972   // Move the actors and try again
2973   Vector3 relativePosition( 5, 5, 5 );
2974   parent.MoveBy( relativePosition );
2975
2976   application.SendNotification();
2977   application.Render(0);
2978
2979   DALI_TEST_EQUALS( parent.GetCurrentPosition(), parentPosition + relativePosition, TEST_LOCATION );
2980   DALI_TEST_EQUALS( child.GetCurrentPosition(), childPosition, TEST_LOCATION );
2981
2982   // The tracking actor lags behind
2983   DALI_TEST_EQUALS( trackingActor.GetCurrentPosition(), previousPosition, TEST_LOCATION );
2984
2985   DALI_TEST_EQUALS( parent.GetCurrentWorldPosition(), parentPosition + relativePosition, TEST_LOCATION );
2986   previousPosition = Vector3( parentPosition + childPosition + relativePosition );
2987   DALI_TEST_EQUALS( child.GetCurrentWorldPosition(), previousPosition, TEST_LOCATION );
2988
2989   // Allow the tracking actor to catch up
2990   application.SendNotification();
2991   application.Render(0);
2992
2993   DALI_TEST_EQUALS( parent.GetCurrentPosition(), parentPosition + relativePosition, TEST_LOCATION );
2994   DALI_TEST_EQUALS( child.GetCurrentPosition(), childPosition, TEST_LOCATION );
2995
2996   // The tracking actor catches up!
2997   DALI_TEST_EQUALS( trackingActor.GetCurrentPosition(), previousPosition, TEST_LOCATION );
2998   DALI_TEST_EQUALS( parent.GetCurrentWorldPosition(), parentPosition + relativePosition, TEST_LOCATION );
2999   DALI_TEST_EQUALS( child.GetCurrentWorldPosition(), previousPosition, TEST_LOCATION );
3000   END_TEST;
3001 }
3002
3003 int UtcDaliConstraintInputWorldRotation(void)
3004 {
3005   TestApplication application;
3006
3007   Actor parent = Actor::New();
3008   Radian rotationAngle( Degree(90.0f) );
3009   Quaternion rotation( rotationAngle, Vector3::YAXIS );
3010   parent.SetRotation( rotation );
3011   Stage::GetCurrent().Add( parent );
3012
3013   Actor child = Actor::New();
3014   child.SetRotation( rotation );
3015   parent.Add( child );
3016
3017   Actor trackingActor = Actor::New();
3018   Stage::GetCurrent().Add( trackingActor );
3019
3020   // The actors should not have a world rotation yet
3021   DALI_TEST_EQUALS( parent.GetCurrentWorldRotation(), Quaternion(0.0f, Vector3::YAXIS), 0.001, TEST_LOCATION );
3022   DALI_TEST_EQUALS( child.GetCurrentWorldRotation(), Quaternion(0.0f, Vector3::YAXIS), 0.001, TEST_LOCATION );
3023
3024   application.SendNotification();
3025   application.Render(0);
3026
3027   DALI_TEST_EQUALS( parent.GetCurrentRotation(), rotation, 0.001, TEST_LOCATION );
3028   DALI_TEST_EQUALS( child.GetCurrentRotation(), rotation, 0.001, TEST_LOCATION );
3029   DALI_TEST_EQUALS( trackingActor.GetCurrentRotation(), Quaternion(0.0f, Vector3::YAXIS), 0.001, TEST_LOCATION );
3030
3031   DALI_TEST_EQUALS( parent.GetCurrentWorldRotation(), Quaternion( rotationAngle, Vector3::YAXIS ), 0.001, TEST_LOCATION );
3032   Quaternion previousRotation( rotationAngle * 2.0f, Vector3::YAXIS );
3033   DALI_TEST_EQUALS( child.GetCurrentWorldRotation(), previousRotation, 0.001, TEST_LOCATION );
3034
3035   // Build constraint, to make actor track the world-rotation of another actor
3036   // Note that the world-rotation is always from the previous frame, so the tracking actor will lag behind
3037
3038   Constraint constraint = Constraint::New<Quaternion>( Actor::ROTATION,
3039                                                        Source( child, Actor::WORLD_ROTATION ),
3040                                                        EqualToQuaternion() );
3041
3042   trackingActor.ApplyConstraint( constraint );
3043
3044   application.SendNotification();
3045   application.Render(0);
3046
3047   DALI_TEST_EQUALS( trackingActor.GetCurrentRotation(), previousRotation, 0.001, TEST_LOCATION );
3048
3049   // Rotate the actors and try again
3050   parent.RotateBy( rotation );
3051
3052   application.SendNotification();
3053   application.Render(0);
3054
3055   DALI_TEST_EQUALS( parent.GetCurrentRotation(), rotation * rotation, 0.001, TEST_LOCATION );
3056   DALI_TEST_EQUALS( child.GetCurrentRotation(), rotation, 0.001, TEST_LOCATION );
3057
3058   // The tracking actor lags behind
3059   DALI_TEST_EQUALS( trackingActor.GetCurrentRotation(), previousRotation, 0.001, TEST_LOCATION );
3060
3061   DALI_TEST_EQUALS( parent.GetCurrentWorldRotation(), Quaternion( rotationAngle * 2.0f, Vector3::YAXIS ), 0.001, TEST_LOCATION );
3062   previousRotation = Quaternion( rotationAngle * 3.0f, Vector3::YAXIS );
3063   DALI_TEST_EQUALS( child.GetCurrentWorldRotation(), previousRotation, 0.001, TEST_LOCATION );
3064
3065   // Allow the tracking actor to catch up
3066   application.SendNotification();
3067   application.Render(0);
3068
3069   DALI_TEST_EQUALS( parent.GetCurrentRotation(), rotation * rotation, 0.001, TEST_LOCATION );
3070   DALI_TEST_EQUALS( child.GetCurrentRotation(), rotation, 0.001, TEST_LOCATION );
3071
3072   // The tracking actor catches up!
3073   DALI_TEST_EQUALS( trackingActor.GetCurrentRotation(), previousRotation, 0.001, TEST_LOCATION );
3074   DALI_TEST_EQUALS( parent.GetCurrentWorldRotation(), Quaternion( rotationAngle * 2.0f, Vector3::YAXIS ), 0.001, TEST_LOCATION );
3075   DALI_TEST_EQUALS( child.GetCurrentWorldRotation(), previousRotation, 0.001, TEST_LOCATION );
3076   END_TEST;
3077 }
3078
3079 int UtcDaliConstraintInputWorldScale(void)
3080 {
3081   TestApplication application;
3082
3083   Actor parent = Actor::New();
3084   Vector3 parentScale( 2.0f, 2.0f, 2.0f );
3085   parent.SetScale( parentScale );
3086   Stage::GetCurrent().Add( parent );
3087
3088   Actor child = Actor::New();
3089   Vector3 childScale( 1.0f, 2.0f, 3.0f );
3090   child.SetScale( childScale );
3091   parent.Add( child );
3092
3093   Actor trackingActor = Actor::New();
3094   Stage::GetCurrent().Add( trackingActor );
3095
3096   // The actors should not have a world scale yet
3097   DALI_TEST_EQUALS( parent.GetCurrentWorldScale(), Vector3::ONE, TEST_LOCATION );
3098   DALI_TEST_EQUALS( child.GetCurrentWorldScale(), Vector3::ONE, TEST_LOCATION );
3099   DALI_TEST_EQUALS( trackingActor.GetCurrentWorldScale(), Vector3::ONE, TEST_LOCATION );
3100
3101   application.SendNotification();
3102   application.Render(0);
3103
3104   DALI_TEST_EQUALS( parent.GetCurrentScale(), parentScale, TEST_LOCATION );
3105   DALI_TEST_EQUALS( child.GetCurrentScale(), childScale, TEST_LOCATION );
3106   DALI_TEST_EQUALS( trackingActor.GetCurrentScale(), Vector3::ONE, TEST_LOCATION );
3107
3108   DALI_TEST_EQUALS( parent.GetCurrentWorldScale(), parentScale, TEST_LOCATION );
3109   Vector3 previousScale( parentScale * childScale );
3110   DALI_TEST_EQUALS( child.GetCurrentWorldScale(), previousScale, TEST_LOCATION );
3111   DALI_TEST_EQUALS( trackingActor.GetCurrentScale(), Vector3::ONE, TEST_LOCATION );
3112
3113   // Build constraint, to make actor track the world-scale of another actor
3114   // Note that the world-scale is always from the previous frame, so the tracking actor will lag behind
3115
3116   Constraint constraint = Constraint::New<Vector3>( Actor::SCALE,
3117                                                     Source( child, Actor::WORLD_SCALE ),
3118                                                     EqualToConstraint() );
3119
3120   trackingActor.ApplyConstraint( constraint );
3121
3122   application.SendNotification();
3123   application.Render(0);
3124
3125   DALI_TEST_EQUALS( trackingActor.GetCurrentScale(), previousScale, TEST_LOCATION );
3126
3127   // Scale the actors and try again
3128   Vector3 relativeScale( 3, 3, 3 );
3129   parent.ScaleBy( relativeScale );
3130
3131   application.SendNotification();
3132   application.Render(0);
3133
3134   DALI_TEST_EQUALS( parent.GetCurrentScale(), parentScale * relativeScale, TEST_LOCATION );
3135   DALI_TEST_EQUALS( child.GetCurrentScale(), childScale, TEST_LOCATION );
3136
3137   // The tracking actor lags behind
3138   DALI_TEST_EQUALS( trackingActor.GetCurrentScale(), previousScale, TEST_LOCATION );
3139
3140   DALI_TEST_EQUALS( parent.GetCurrentWorldScale(), parentScale * relativeScale, TEST_LOCATION );
3141   previousScale = Vector3( parentScale * childScale * relativeScale );
3142   DALI_TEST_EQUALS( child.GetCurrentWorldScale(), previousScale, TEST_LOCATION );
3143
3144   // Allow the tracking actor to catch up
3145   application.SendNotification();
3146   application.Render(0);
3147
3148   DALI_TEST_EQUALS( parent.GetCurrentScale(), parentScale * relativeScale, TEST_LOCATION );
3149   DALI_TEST_EQUALS( child.GetCurrentScale(), childScale, TEST_LOCATION );
3150
3151   // The tracking actor catches up!
3152   DALI_TEST_EQUALS( trackingActor.GetCurrentScale(), previousScale, TEST_LOCATION );
3153   DALI_TEST_EQUALS( parent.GetCurrentWorldScale(), parentScale * relativeScale, TEST_LOCATION );
3154   DALI_TEST_EQUALS( child.GetCurrentWorldScale(), previousScale, TEST_LOCATION );
3155   END_TEST;
3156 }
3157
3158 int UtcDaliConstraintInputWorldColor(void)
3159 {
3160   TestApplication application;
3161
3162   Actor parent = Actor::New();
3163   Vector4 parentColor( 1.0f, 0.5f, 0.0f, 1.0f );
3164   parent.SetColor( parentColor );
3165   Stage::GetCurrent().Add( parent );
3166
3167   Actor child = Actor::New();
3168   Vector4 childColor( 0.5f, 0.5f, 0.5f, 1.0f );
3169   child.SetColor( childColor );
3170   parent.Add( child );
3171
3172   Actor trackingActor = Actor::New();
3173   Stage::GetCurrent().Add( trackingActor );
3174
3175   // The actors should not have a world color yet
3176   DALI_TEST_EQUALS( parent.GetCurrentWorldColor(), Color::WHITE, TEST_LOCATION );
3177   DALI_TEST_EQUALS( child.GetCurrentWorldColor(), Color::WHITE, TEST_LOCATION );
3178
3179   application.SendNotification();
3180   application.Render(0);
3181
3182   DALI_TEST_EQUALS( parent.GetCurrentColor(), parentColor, TEST_LOCATION );
3183   DALI_TEST_EQUALS( child.GetCurrentColor(), childColor, TEST_LOCATION );
3184   DALI_TEST_EQUALS( trackingActor.GetCurrentColor(), Color::WHITE, TEST_LOCATION );
3185
3186   DALI_TEST_EQUALS( parent.GetCurrentWorldColor(), parentColor, TEST_LOCATION );
3187   Vector4 previousColor( childColor );
3188   previousColor.a *= parentColor.a;
3189   DALI_TEST_EQUALS( child.GetCurrentWorldColor(), previousColor, TEST_LOCATION );
3190
3191   // Build constraint, to make actor track the world-color of another actor
3192   // Note that the world-color is always from the previous frame, so the tracking actor will lag behind
3193
3194   Constraint constraint = Constraint::New<Vector4>( Actor::COLOR,
3195                                                     Source( child, Actor::WORLD_COLOR ),
3196                                                     EqualToVector4() );
3197
3198   trackingActor.ApplyConstraint( constraint );
3199
3200   application.SendNotification();
3201   application.Render(0);
3202
3203   DALI_TEST_EQUALS( trackingActor.GetCurrentColor(), previousColor, TEST_LOCATION );
3204
3205   // Set the color and try again
3206   Vector4 newChildColor( 0.75f, 0.75f, 0.75f, 1.0f );
3207   child.SetColor( newChildColor );
3208
3209   application.SendNotification();
3210   application.Render(0);
3211
3212   DALI_TEST_EQUALS( parent.GetCurrentColor(), parentColor, TEST_LOCATION );
3213   DALI_TEST_EQUALS( child.GetCurrentColor(), newChildColor, TEST_LOCATION );
3214
3215   // The tracking actor lags behind
3216   DALI_TEST_EQUALS( trackingActor.GetCurrentColor(), previousColor, TEST_LOCATION );
3217
3218   DALI_TEST_EQUALS( parent.GetCurrentWorldColor(), parentColor, TEST_LOCATION );
3219   previousColor = Vector3( newChildColor );
3220   DALI_TEST_EQUALS( child.GetCurrentWorldColor(), previousColor, TEST_LOCATION );
3221
3222   // Allow the tracking actor to catch up
3223   application.SendNotification();
3224   application.Render(0);
3225
3226   DALI_TEST_EQUALS( parent.GetCurrentColor(), parentColor, TEST_LOCATION );
3227   DALI_TEST_EQUALS( child.GetCurrentColor(), newChildColor, TEST_LOCATION );
3228
3229   // The tracking actor catches up!
3230   DALI_TEST_EQUALS( trackingActor.GetCurrentColor(), previousColor, TEST_LOCATION );
3231   DALI_TEST_EQUALS( parent.GetCurrentWorldColor(), parentColor, TEST_LOCATION );
3232   DALI_TEST_EQUALS( child.GetCurrentWorldColor(), previousColor, TEST_LOCATION );
3233   END_TEST;
3234 }
3235
3236 int UtcDaliConstraintInvalidInputProperty(void)
3237 {
3238   TestApplication application;
3239   Actor actor = Actor::New();
3240   Constraint constraint = Constraint::New<Vector3>( Actor::POSITION, LocalSource( PROPERTY_REGISTRATION_START_INDEX ), MultiplyConstraint() );
3241
3242   Stage::GetCurrent().Add( actor );
3243
3244   // Cannot use type registered properties as input to constraints
3245   try
3246   {
3247     actor.ApplyConstraint( constraint );
3248     tet_result( TET_FAIL );
3249   }
3250   catch ( DaliException& e )
3251   {
3252     DALI_TEST_ASSERT( e, "mTargetProxy->IsPropertyAConstraintInput( source.propertyIndex )", TEST_LOCATION );
3253   }
3254   END_TEST;
3255 }
3256
3257 int UtcDaliBuiltinConstraintParentSize(void)
3258 {
3259   TestApplication application;
3260
3261   Actor parent = Actor::New();
3262   Vector3 parentSize(9,9,9);
3263   parent.SetSize( parentSize );
3264   Stage::GetCurrent().Add( parent );
3265
3266   Actor actor = Actor::New();
3267   parent.Add( actor );
3268
3269   Vector3 startValue( Vector3::ZERO );
3270
3271   application.SendNotification();
3272   application.Render(0);
3273   DALI_TEST_CHECK( actor.GetCurrentSize() == startValue );
3274
3275   // Apply constraint
3276
3277   Constraint constraint = Constraint::New<Vector3>( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() );
3278   actor.ApplyConstraint( constraint );
3279
3280   application.SendNotification();
3281   application.Render(0);
3282
3283   // Constraint should be fully applied
3284   DALI_TEST_EQUALS( actor.GetCurrentSize(), parentSize, TEST_LOCATION );
3285
3286   // This should be ignored
3287   actor.SetSize( startValue );
3288
3289   // Check that nothing has changed after a couple of buffer swaps
3290   application.SendNotification();
3291   application.Render(0);
3292   DALI_TEST_EQUALS( actor.GetCurrentSize(), parentSize, TEST_LOCATION );
3293   application.Render(0);
3294   DALI_TEST_EQUALS( actor.GetCurrentSize(), parentSize, TEST_LOCATION );
3295
3296   // Remove the constraint, then set new value
3297   actor.RemoveConstraints();
3298   actor.SetSize( startValue );
3299
3300   // Constraint should have been removed
3301   application.SendNotification();
3302   application.Render(0);
3303   DALI_TEST_EQUALS( actor.GetCurrentSize(), startValue, TEST_LOCATION );
3304   application.Render(0);
3305   DALI_TEST_EQUALS( actor.GetCurrentSize(), startValue, TEST_LOCATION );
3306   END_TEST;
3307 }
3308
3309 int UtcDaliBuiltinConstraintParentSizeRelative(void)
3310 {
3311   TestApplication application;
3312
3313   Actor parent = Actor::New();
3314   Vector3 parentSize(9,9,9);
3315   parent.SetSize( parentSize );
3316   Stage::GetCurrent().Add( parent );
3317
3318   Actor actor = Actor::New();
3319   parent.Add( actor );
3320
3321   Vector3 startValue( Vector3::ZERO );
3322   Vector3 scale(2,3,4);
3323   Vector3 endValue( parentSize * scale );
3324
3325   application.SendNotification();
3326   application.Render(0);
3327   DALI_TEST_CHECK( actor.GetCurrentSize() == startValue );
3328
3329   // Apply constraint
3330
3331   Constraint constraint = Constraint::New<Vector3>( Actor::SIZE, ParentSource( Actor::SIZE ), RelativeToConstraint( scale ) );
3332   actor.ApplyConstraint( constraint );
3333
3334   application.SendNotification();
3335   application.Render(0);
3336
3337   // Constraint should be fully applied
3338   DALI_TEST_EQUALS( actor.GetCurrentSize(), endValue, TEST_LOCATION );
3339
3340   // This should be ignored
3341   actor.SetSize( startValue );
3342
3343   // Check that nothing has changed after a couple of buffer swaps
3344   application.SendNotification();
3345   application.Render(0);
3346   DALI_TEST_EQUALS( actor.GetCurrentSize(), endValue, TEST_LOCATION );
3347   application.Render(0);
3348   DALI_TEST_EQUALS( actor.GetCurrentSize(), endValue, TEST_LOCATION );
3349
3350   // Remove the constraint, then set new value
3351   actor.RemoveConstraints();
3352   actor.SetSize( startValue );
3353
3354   // Constraint should have been removed
3355   application.SendNotification();
3356   application.Render(0);
3357   DALI_TEST_EQUALS( actor.GetCurrentSize(), startValue, TEST_LOCATION );
3358   application.Render(0);
3359   DALI_TEST_EQUALS( actor.GetCurrentSize(), startValue, TEST_LOCATION );
3360   END_TEST;
3361 }
3362
3363 int UtcDaliBuiltinConstraintScaleToFitConstraint(void)
3364 {
3365   TestApplication application;
3366
3367   Actor parent = Actor::New();
3368   Vector3 startParentSize( 10, 10, 10 );
3369   parent.SetSize( startParentSize );
3370   Stage::GetCurrent().Add( parent );
3371
3372   Actor actor = Actor::New();
3373   Vector3 startChildSize( 5, 5, 5 );
3374   actor.SetSize( startChildSize );
3375   parent.Add( actor );
3376
3377   Vector3 endChildSize( 8, 8, 8 );
3378   Vector3 endParentSize( 4, 4, 4 );
3379   Vector3 startChildScale( 2, 2, 2 ); // startParentSize / startChildSize
3380   Vector3 intermediateChildScale( 1.25, 1.25, 1.25 ); // startParentSize / endChildSize
3381   Vector3 endChildScale( 0.5, 0.5, 0.5 ); // endParentSize / endChildSize
3382
3383   application.SendNotification();
3384   application.Render(0);
3385   DALI_TEST_CHECK( actor.GetCurrentSize() == startChildSize );
3386
3387   // Apply constraint
3388
3389   Constraint constraint = Constraint::New<Vector3>( Actor::SCALE,
3390                                                     LocalSource( Actor::SIZE ),
3391                                                     ParentSource( Actor::SIZE ),
3392                                                     ScaleToFitConstraint() );
3393   actor.ApplyConstraint( constraint );
3394
3395   application.SendNotification();
3396   application.Render(0);
3397
3398   // Constraint should be fully applied, but parent size is larger than child
3399   DALI_TEST_EQUALS( actor.GetCurrentSize(), startChildSize, TEST_LOCATION );
3400   DALI_TEST_EQUALS( actor.GetCurrentScale(), startChildScale, TEST_LOCATION );
3401
3402   // This should be allowed (still less than parent size)
3403   actor.SetSize( endChildSize );
3404
3405   application.SendNotification();
3406   application.Render(0);
3407   DALI_TEST_EQUALS( actor.GetCurrentSize(), endChildSize, TEST_LOCATION );
3408   DALI_TEST_EQUALS( actor.GetCurrentScale(), intermediateChildScale, TEST_LOCATION );
3409
3410   // Reduce the parent size
3411   parent.SetSize( endParentSize );
3412
3413   application.SendNotification();
3414   application.Render(0);
3415
3416   // Constraint should be fully applied
3417   DALI_TEST_EQUALS( actor.GetCurrentSize(), endChildSize, TEST_LOCATION );
3418   DALI_TEST_EQUALS( actor.GetCurrentScale(), endChildScale, TEST_LOCATION );
3419   application.Render(0);
3420   DALI_TEST_EQUALS( actor.GetCurrentSize(), endChildSize, TEST_LOCATION );
3421   DALI_TEST_EQUALS( actor.GetCurrentScale(), endChildScale, TEST_LOCATION );
3422   END_TEST;
3423 }
3424
3425 int UtcDaliBuiltinConstraintScaleToFitKeepAspectRatio(void)
3426 {
3427   TestApplication application;
3428
3429   Actor parent = Actor::New();
3430   Vector3 parentSize1( 10, 10, 10 );
3431   parent.SetSize( parentSize1 );
3432   Stage::GetCurrent().Add( parent );
3433
3434   Actor actor = Actor::New();
3435   Vector3 childSize( 4, 5, 5 );
3436   actor.SetSize( childSize );
3437   parent.Add( actor );
3438
3439   application.SendNotification();
3440   application.Render(0);
3441   Vector3 childScale1( 1.0f, 1.0f, 1.0f );
3442   DALI_TEST_EQUALS( actor.GetCurrentScale(), childScale1, TEST_LOCATION );
3443
3444   // Apply constraint
3445
3446   Constraint constraint = Constraint::New<Vector3>( Actor::SCALE,
3447                                                     LocalSource( Actor::SIZE ),
3448                                                     ParentSource( Actor::SIZE ),
3449                                                     ScaleToFitKeepAspectRatioConstraint() );
3450   actor.ApplyConstraint( constraint );
3451
3452   application.SendNotification();
3453   application.Render(0);
3454
3455   // Constraint should be fully applied, but parent size is larger than child
3456   Vector3 childScale2( 2.0f, 2.0f, 2.0f );
3457   DALI_TEST_EQUALS( actor.GetCurrentScale(), childScale2, TEST_LOCATION );
3458
3459   // change parent size
3460   Vector3 parentSize2( 40, 50, 50 );
3461   parent.SetSize( parentSize2 );
3462
3463   application.SendNotification();
3464   application.Render(0);
3465
3466   // Constraint should be fully applied, but parent size is larger than child
3467   Vector3 childScale3( 10.0f, 10.0f, 10.0f );
3468   DALI_TEST_EQUALS( actor.GetCurrentScale(), childScale3, TEST_LOCATION );
3469   END_TEST;
3470 }
3471
3472 int UtcDaliBuiltinConstraintScaleToFillKeepAspectRatio(void)
3473 {
3474   TestApplication application;
3475
3476   Actor parent = Actor::New();
3477   Vector3 parentSize1( 10, 10, 10 );
3478   parent.SetSize( parentSize1 );
3479   Stage::GetCurrent().Add( parent );
3480
3481   Actor actor = Actor::New();
3482   Vector3 childSize( 4, 5, 5 );
3483   actor.SetSize( childSize );
3484   parent.Add( actor );
3485
3486   application.SendNotification();
3487   application.Render(0);
3488   Vector3 childScale1( 1.0f, 1.0f, 1.0f );
3489   DALI_TEST_EQUALS( actor.GetCurrentScale(), childScale1, TEST_LOCATION );
3490
3491   // Apply constraint
3492
3493   Constraint constraint = Constraint::New<Vector3>( Actor::SCALE,
3494                                                     LocalSource( Actor::SIZE ),
3495                                                     ParentSource( Actor::SIZE ),
3496                                                     ScaleToFillKeepAspectRatioConstraint() );
3497   actor.ApplyConstraint( constraint );
3498
3499   application.SendNotification();
3500   application.Render(0);
3501
3502   // Constraint should be fully applied, but parent size is larger than child
3503   float val = 10.f / 4.f;
3504   Vector3 childScale2( val, val, val );
3505   DALI_TEST_EQUALS( actor.GetCurrentScale(), childScale2, TEST_LOCATION );
3506
3507   // change parent size
3508   Vector3 parentSize2( 40, 50, 50 );
3509   parent.SetSize( parentSize2 );
3510
3511   application.SendNotification();
3512   application.Render(0);
3513
3514   // Constraint should be fully applied, but parent size is larger than child
3515   Vector3 childScale3( 10.0f, 10.0f, 10.0f );
3516   DALI_TEST_EQUALS( actor.GetCurrentScale(), childScale3, TEST_LOCATION );
3517   END_TEST;
3518 }
3519
3520 int UtcDaliBuiltinConstraintScaleToFillXYKeepAspectRatio(void)
3521 {
3522   TestApplication application;
3523
3524   Actor parent = Actor::New();
3525   Vector3 parentSize1( 10, 10, 10 );
3526   parent.SetSize( parentSize1 );
3527   Stage::GetCurrent().Add( parent );
3528
3529   Actor actor = Actor::New();
3530   Vector3 childSize( 4, 5, 5 );
3531   actor.SetSize( childSize );
3532   parent.Add( actor );
3533
3534   application.SendNotification();
3535   application.Render(0);
3536   Vector3 childScale1( 1.0f, 1.0f, 1.0f );
3537   DALI_TEST_EQUALS( actor.GetCurrentScale(), childScale1, TEST_LOCATION );
3538
3539   // Apply constraint
3540
3541   Constraint constraint = Constraint::New<Vector3>( Actor::SCALE,
3542                                                     LocalSource( Actor::SIZE ),
3543                                                     ParentSource( Actor::SIZE ),
3544                                                     ScaleToFillXYKeepAspectRatioConstraint() );
3545   actor.ApplyConstraint( constraint );
3546
3547   application.SendNotification();
3548   application.Render(0);
3549
3550   // Constraint should be fully applied, but parent size is larger than child
3551   float val = 10.f / 4.f;
3552   Vector3 childScale2( val, val, val );
3553   DALI_TEST_EQUALS( actor.GetCurrentScale(), childScale2, TEST_LOCATION );
3554
3555   // change parent size
3556   Vector3 parentSize2( 40, 50, 50 );
3557   parent.SetSize( parentSize2 );
3558
3559   application.SendNotification();
3560   application.Render(0);
3561
3562   // Constraint should be fully applied, but parent size is larger than child
3563   Vector3 childScale3( 10.0f, 10.0f, 10.0f );
3564   DALI_TEST_EQUALS( actor.GetCurrentScale(), childScale3, TEST_LOCATION );
3565   END_TEST;
3566 }
3567
3568 int UtcDaliBuiltinConstraintShrinkInsideKeepAspectRatioConstraint(void)
3569 {
3570   TestApplication application;
3571
3572   Actor parent = Actor::New();
3573   Vector3 parentSize1( 10, 10, 10 );
3574   parent.SetSize( parentSize1 );
3575   Stage::GetCurrent().Add( parent );
3576
3577   Actor actor = Actor::New();
3578   Vector3 childSize( 4, 5, 5 );
3579   actor.SetSize( childSize );
3580   parent.Add( actor );
3581
3582   application.SendNotification();
3583   application.Render(0);
3584   Vector3 childScale1( 1.0f, 1.0f, 1.0f );
3585   DALI_TEST_EQUALS( actor.GetCurrentScale(), childScale1, TEST_LOCATION );
3586
3587   // Apply constraint
3588
3589   Constraint constraint = Constraint::New<Vector3>( Actor::SCALE,
3590                                                     LocalSource( Actor::SIZE ),
3591                                                     ParentSource( Actor::SIZE ),
3592                                                     ShrinkInsideKeepAspectRatioConstraint() );
3593   actor.ApplyConstraint( constraint );
3594
3595   application.SendNotification();
3596   application.Render(0);
3597
3598   // Constraint should be fully applied, but parent size is larger than child
3599   Vector3 childScale2( 1.0f, 1.0f, 1.0f );
3600   DALI_TEST_EQUALS( actor.GetCurrentScale(), childScale2, TEST_LOCATION );
3601
3602   // change parent size
3603   Vector3 parentSize2( 40, 50, 50 );
3604   parent.SetSize( parentSize2 );
3605
3606   application.SendNotification();
3607   application.Render(0);
3608
3609   // Constraint should be fully applied, but parent size is larger than child
3610   Vector3 childScale3( 1.0f, 1.0f, 1.0f );
3611   DALI_TEST_EQUALS( actor.GetCurrentScale(), childScale3, TEST_LOCATION );
3612   END_TEST;
3613 }
3614
3615 int UtcDaliBuiltinConstraintMultiplyConstraint(void)
3616 {
3617   TestApplication application;
3618
3619   Actor actor1 = Actor::New();
3620   Vector3 startPosition( 10, 10, 10 );
3621   actor1.SetPosition( startPosition );
3622   Stage::GetCurrent().Add( actor1 );
3623
3624   Actor actor2 = Actor::New();
3625   Vector3 startSize( 100, 100, 100 );
3626   actor2.SetSize( startSize );
3627   Stage::GetCurrent().Add( actor2 );
3628
3629   application.SendNotification();
3630   application.Render(0);
3631   DALI_TEST_CHECK( actor1.GetCurrentPosition() == startPosition );
3632   DALI_TEST_CHECK( actor2.GetCurrentSize()     == startSize );
3633
3634   // Apply constraint - multiply actor1 size by actor2 position
3635
3636   Constraint constraint = Constraint::New<Vector3>( Actor::SIZE,
3637                                                     Source( actor1, Actor::POSITION ),
3638                                                     MultiplyConstraint() );
3639   constraint.SetRemoveAction( Constraint::Discard );
3640   actor2.ApplyConstraint( constraint );
3641
3642   application.SendNotification();
3643   application.Render(0);
3644
3645   // Constraint should be fully applied
3646   Vector3 size( startSize * startPosition );
3647   DALI_TEST_EQUALS( actor2.GetCurrentSize(), size, TEST_LOCATION );
3648
3649   // Change the multiply input
3650   Vector3 endPosition( 2, 2, 2 );
3651   actor1.SetPosition( endPosition );
3652
3653   application.SendNotification();
3654   application.Render(0);
3655
3656   // Constraint should be fully applied
3657   size = Vector3( startSize * endPosition );
3658   DALI_TEST_EQUALS( actor2.GetCurrentSize(), size, TEST_LOCATION );
3659   application.Render(0);
3660   DALI_TEST_EQUALS( actor2.GetCurrentSize(), size, TEST_LOCATION );
3661   END_TEST;
3662 }
3663
3664 int UtcDaliBuiltinConstraintDivideConstraint(void)
3665 {
3666   TestApplication application;
3667
3668   Actor actor1 = Actor::New();
3669   Vector3 startPosition( 10, 10, 10 );
3670   actor1.SetPosition( startPosition );
3671   Stage::GetCurrent().Add( actor1 );
3672
3673   Actor actor2 = Actor::New();
3674   Vector3 startSize( 100, 100, 100 );
3675   actor2.SetSize( startSize );
3676   Stage::GetCurrent().Add( actor2 );
3677
3678   application.SendNotification();
3679   application.Render(0);
3680   DALI_TEST_CHECK( actor1.GetCurrentPosition() == startPosition );
3681   DALI_TEST_CHECK( actor2.GetCurrentSize()     == startSize );
3682
3683   // Apply constraint - divide actor1 size by actor2 position
3684
3685   Constraint constraint = Constraint::New<Vector3>( Actor::SIZE,
3686                                                     Source( actor1, Actor::POSITION ),
3687                                                     DivideConstraint() );
3688   constraint.SetRemoveAction( Constraint::Discard );
3689   actor2.ApplyConstraint( constraint );
3690
3691   application.SendNotification();
3692   application.Render(0);
3693
3694   // Constraint should be fully applied
3695   Vector3 size( 10, 10, 10 ); // startSize / startPosition
3696   DALI_TEST_EQUALS( actor2.GetCurrentSize(), size, TEST_LOCATION );
3697
3698   // Change the divide input
3699   Vector3 endPosition( 2, 2, 2 );
3700   actor1.SetPosition( endPosition );
3701
3702   application.SendNotification();
3703   application.Render(0);
3704
3705   // Constraint should be fully applied
3706   size = Vector3( 50, 50, 50 ); // startSize / endPosition
3707   DALI_TEST_EQUALS( actor2.GetCurrentSize(), size, TEST_LOCATION );
3708   application.Render(0);
3709   DALI_TEST_EQUALS( actor2.GetCurrentSize(), size, TEST_LOCATION );
3710   END_TEST;
3711 }
3712
3713 int UtcDaliBuiltinConstraintEqualToConstraint(void)
3714 {
3715   TestApplication application;
3716
3717   Actor actor1 = Actor::New();
3718   Vector3 startPosition( 10, 10, 10 );
3719   actor1.SetPosition( startPosition );
3720   Stage::GetCurrent().Add( actor1 );
3721
3722   Actor actor2 = Actor::New();
3723   Vector3 startSize( 100, 100, 100 );
3724   actor2.SetSize( startSize );
3725   Stage::GetCurrent().Add( actor2 );
3726
3727   application.SendNotification();
3728   application.Render(0);
3729   DALI_TEST_CHECK( actor1.GetCurrentPosition() == startPosition );
3730   DALI_TEST_CHECK( actor2.GetCurrentSize()     == startSize );
3731
3732   // Apply constraint - actor1 size == actor2 position
3733
3734   Constraint constraint = Constraint::New<Vector3>( Actor::SIZE,
3735                                                     Source( actor1, Actor::POSITION ),
3736                                                     EqualToConstraint() );
3737   constraint.SetRemoveAction( Constraint::Discard );
3738   actor2.ApplyConstraint( constraint );
3739
3740   application.SendNotification();
3741   application.Render(0);
3742
3743   // Constraint should be fully applied
3744   DALI_TEST_EQUALS( actor2.GetCurrentSize(), startPosition, TEST_LOCATION );
3745
3746   // Change the input
3747   Vector3 endPosition( 2, 2, 2 );
3748   actor1.SetPosition( endPosition );
3749
3750   application.SendNotification();
3751   application.Render(0);
3752
3753   // Constraint should be fully applied
3754   DALI_TEST_EQUALS( actor2.GetCurrentSize(), endPosition, TEST_LOCATION );
3755   application.Render(0);
3756   DALI_TEST_EQUALS( actor2.GetCurrentSize(), endPosition, TEST_LOCATION );
3757
3758   //
3759   // Check float variant of constraint
3760   //
3761   float startOpacity(1.0f);
3762   float endOpacity(0.2f);
3763   actor1.SetOpacity( startOpacity );
3764   actor2.SetOpacity( startOpacity );
3765
3766   application.SendNotification();
3767   application.Render(0);
3768   DALI_TEST_EQUALS( actor1.GetCurrentOpacity(), startOpacity, TEST_LOCATION );
3769   DALI_TEST_EQUALS( actor2.GetCurrentOpacity(), startOpacity, TEST_LOCATION );
3770
3771   Constraint constraint2 = Constraint::New<float>( Actor::COLOR_ALPHA,
3772                                                   Source( actor1, Actor::COLOR_ALPHA ),
3773                                                   EqualToConstraint() );
3774   constraint2.SetRemoveAction( Constraint::Discard );
3775   actor2.ApplyConstraint( constraint2 );
3776
3777   actor1.SetOpacity(endOpacity);
3778
3779   application.SendNotification();
3780   application.Render(0);
3781
3782   DALI_TEST_EQUALS( actor2.GetCurrentOpacity(), endOpacity, 0.000001f, TEST_LOCATION );
3783
3784   //
3785   // Check Vector4 variant of constraint
3786   //
3787   actor1.SetColor( Color::GREEN );
3788   actor2.SetColor( Color::RED );
3789
3790   application.SendNotification();
3791   application.Render(0);
3792   DALI_TEST_CHECK( actor1.GetCurrentColor() == Color::GREEN );
3793   DALI_TEST_CHECK( actor2.GetCurrentColor() == Color::RED );
3794
3795   Constraint constraint3 = Constraint::New<Vector4>( Actor::COLOR,
3796                                                     Source( actor1, Actor::COLOR ),
3797                                                     EqualToConstraint() );
3798   constraint3.SetRemoveAction( Constraint::Discard );
3799   actor2.ApplyConstraint( constraint3 );
3800   application.SendNotification();
3801   application.Render(0);
3802   DALI_TEST_CHECK( actor2.GetCurrentColor() == Color::GREEN );
3803
3804   //
3805   // Check Quaternion variant of constraint
3806   //
3807   Quaternion q1 = Quaternion( Math::PI_2, Vector3::XAXIS );
3808   Quaternion q2 = Quaternion( Math::PI_4, Vector3::YAXIS );
3809   actor1.SetRotation( q1 );
3810   actor2.SetRotation( q2 );
3811
3812   application.SendNotification();
3813   application.Render(0);
3814   DALI_TEST_EQUALS( actor1.GetCurrentRotation(), q1, 0.01, TEST_LOCATION );
3815   DALI_TEST_EQUALS( actor2.GetCurrentRotation(), q2, 0.01, TEST_LOCATION );
3816
3817   Constraint constraint4 = Constraint::New<Quaternion>( Actor::ROTATION,
3818                                                     Source( actor1, Actor::ROTATION ),
3819                                                     EqualToConstraint() );
3820   constraint4.SetRemoveAction( Constraint::Discard );
3821   actor2.ApplyConstraint( constraint4 );
3822   application.SendNotification();
3823   application.Render(0);
3824   DALI_TEST_EQUALS( actor2.GetCurrentRotation(), q1, 0.01, TEST_LOCATION );
3825
3826   //
3827   // Check Matrix3 variant
3828   //
3829   EqualToConstraint equalToConstraint;
3830
3831   Matrix3 a;
3832   a.AsFloat()[0] = 1.f;
3833   Matrix3 b;
3834   b.AsFloat()[0] = 2.f;
3835   PropertyInputAbstraction pi(b);
3836
3837   Matrix3 c = equalToConstraint(a,pi);
3838   DALI_TEST_EQUALS( c.AsFloat()[0], b.AsFloat()[0], 0.01, TEST_LOCATION);
3839   END_TEST;
3840 }
3841
3842 int UtcDaliBuiltinConstraintRelativeToConstraint(void)
3843 {
3844   TestApplication application;
3845
3846   Actor actor1 = Actor::New();
3847   Vector3 startPosition( 10, 10, 10 );
3848   actor1.SetPosition( startPosition );
3849   Stage::GetCurrent().Add( actor1 );
3850
3851   Actor actor2 = Actor::New();
3852   Vector3 startSize( 100, 100, 100 );
3853   actor2.SetSize( startSize );
3854   Stage::GetCurrent().Add( actor2 );
3855
3856   application.SendNotification();
3857   application.Render(0);
3858   DALI_TEST_CHECK( actor1.GetCurrentPosition() == startPosition );
3859   DALI_TEST_CHECK( actor2.GetCurrentSize()     == startSize );
3860
3861   // Apply constraint - actor1 size == actor2 position
3862
3863   RelativeToConstraint( 0.f );
3864   Vector3 scale( 0.5, 0.6, 0.7 );
3865   Constraint constraint = Constraint::New<Vector3>( Actor::SIZE,
3866                                                     Source( actor1, Actor::POSITION ),
3867                                                     RelativeToConstraint( scale ) );
3868   constraint.SetRemoveAction( Constraint::Discard );
3869   actor2.ApplyConstraint( constraint );
3870
3871   application.SendNotification();
3872   application.Render(0);
3873
3874   // Constraint should be fully applied
3875   DALI_TEST_EQUALS( actor2.GetCurrentSize(), scale * startPosition, TEST_LOCATION );
3876
3877   // Change the input
3878   Vector3 endPosition( 2, 2, 2 );
3879   actor1.SetPosition( endPosition );
3880
3881   application.SendNotification();
3882   application.Render(0);
3883
3884   // Constraint should be fully applied
3885   DALI_TEST_EQUALS( actor2.GetCurrentSize(), scale * endPosition, TEST_LOCATION );
3886   application.Render(0);
3887   DALI_TEST_EQUALS( actor2.GetCurrentSize(), scale * endPosition, TEST_LOCATION );
3888
3889   //
3890   // Check float variant of constraint
3891   //
3892   float scale2( 0.5f );
3893   float startOpacity(1.0f);
3894   actor1.SetOpacity( startOpacity );
3895   actor2.SetOpacity( startOpacity );
3896
3897   application.SendNotification();
3898   application.Render(0);
3899   DALI_TEST_EQUALS( actor1.GetCurrentOpacity(), startOpacity, TEST_LOCATION );
3900   DALI_TEST_EQUALS( actor2.GetCurrentOpacity(), startOpacity, TEST_LOCATION );
3901
3902   Constraint constraint2 = Constraint::New<float>( Actor::COLOR_ALPHA,
3903                                                   Source( actor1, Actor::COLOR_ALPHA ),
3904                                                   RelativeToConstraintFloat(scale2) );
3905   constraint2.SetRemoveAction( Constraint::Discard );
3906   actor2.ApplyConstraint(constraint2);
3907   application.SendNotification();
3908   application.Render(0);
3909
3910   DALI_TEST_EQUALS( actor2.GetCurrentOpacity(), startOpacity * scale2, TEST_LOCATION );
3911   END_TEST;
3912 }
3913
3914 int UtcDaliBuiltinConstraintInverseOfConstraint(void)
3915 {
3916   TestApplication application;
3917
3918   Actor actor1 = Actor::New();
3919   Vector3 startPosition( 10, 10, 10 );
3920   actor1.SetPosition( startPosition );
3921   Stage::GetCurrent().Add( actor1 );
3922
3923   Actor actor2 = Actor::New();
3924   Vector3 startSize( 100, 100, 100 );
3925   actor2.SetSize( startSize );
3926   Stage::GetCurrent().Add( actor2 );
3927
3928   application.SendNotification();
3929   application.Render(0);
3930   DALI_TEST_CHECK( actor1.GetCurrentPosition() == startPosition );
3931   DALI_TEST_CHECK( actor2.GetCurrentSize()     == startSize );
3932
3933   // Apply constraint - actor1 size == ( 1 / actor2 position )
3934
3935   Constraint constraint = Constraint::New<Vector3>( Actor::SIZE,
3936                                                     Source( actor1, Actor::POSITION ),
3937                                                     InverseOfConstraint() );
3938   constraint.SetRemoveAction( Constraint::Discard );
3939   actor2.ApplyConstraint( constraint );
3940
3941   application.SendNotification();
3942   application.Render(0);
3943
3944   // Constraint should be fully applied
3945   Vector3 size( 0.1, 0.1, 0.1 ); // 1 / startPosition
3946   DALI_TEST_EQUALS( actor2.GetCurrentSize(), size, 0.00001f, TEST_LOCATION );
3947
3948   // Change the input
3949   Vector3 endPosition( 2, 2, 2 );
3950   actor1.SetPosition( endPosition );
3951
3952   application.SendNotification();
3953   application.Render(0);
3954
3955   // Constraint should be fully applied
3956   size = Vector3( 0.5, 0.5, 0.5 ); // 1 / endPosition
3957   DALI_TEST_EQUALS( actor2.GetCurrentSize(), size, TEST_LOCATION );
3958   application.Render(0);
3959   DALI_TEST_EQUALS( actor2.GetCurrentSize(), size, TEST_LOCATION );
3960   END_TEST;
3961 }
3962
3963 int UtcDaliBuiltinConstraintFunctions(void)
3964 {
3965   TestApplication application;
3966
3967   {
3968     SourceWidthFixedHeight sourceWidthFixedHeight( 10.f );
3969     Vector3 current;
3970     {
3971       Vector3 reference(1, 10, 0);
3972       Vector3 value = sourceWidthFixedHeight( current, PropertyInputAbstraction(Vector3::ONE) );
3973       DALI_TEST_EQUALS( reference, value, TEST_LOCATION );
3974     }
3975     {
3976       Vector3 reference(10, 10, 0);
3977       Vector3 value = sourceWidthFixedHeight( current, PropertyInputAbstraction(Vector3::ONE*10.f) );
3978       DALI_TEST_EQUALS( reference, value, TEST_LOCATION );
3979     }
3980     {
3981       Vector3 reference(10,10,0);
3982       Vector3 value = sourceWidthFixedHeight( current, PropertyInputAbstraction(Vector3::ONE*10.f) );
3983       DALI_TEST_EQUALS( reference, value, TEST_LOCATION );
3984     }
3985   }
3986
3987   {
3988     SourceHeightFixedWidth sourceHeightFixedWidth( 10.f );
3989     Vector3 current;
3990     {
3991       Vector3 reference(10,1,0);
3992       Vector3 value = sourceHeightFixedWidth( current, PropertyInputAbstraction(Vector3::ONE) );
3993       DALI_TEST_EQUALS( reference, value, TEST_LOCATION );
3994     }
3995     {
3996       Vector3 reference(10,10,0);
3997       Vector3 value = sourceHeightFixedWidth( current, PropertyInputAbstraction(Vector3::ONE*10.f) );
3998       DALI_TEST_EQUALS( reference, value, TEST_LOCATION );
3999     }
4000     {
4001       Vector3 reference(10,100,0);
4002       Vector3 value = sourceHeightFixedWidth( current, PropertyInputAbstraction(Vector3::ONE*100.f) );
4003       DALI_TEST_EQUALS( reference, value, TEST_LOCATION );
4004     }
4005   }
4006
4007   { // LookAt
4008     Quaternion current(0, Vector3::YAXIS);
4009     PropertyInputAbstraction target(Vector3::ZAXIS);
4010     PropertyInputAbstraction targetRotation(Vector3::YAXIS);
4011     PropertyInputAbstraction camera(Vector3::ZERO);
4012
4013     {
4014       Quaternion reference(1., 0., 0., 0.);
4015       Quaternion value = LookAt( current, target, camera, targetRotation );
4016       DALI_TEST_EQUALS( reference, value, 0.001, TEST_LOCATION );
4017     }
4018
4019     {
4020       OrientedLookAt orientedLookAt(90.f);
4021       Quaternion reference(.525322, 0., 0., 0.850904);
4022       Quaternion value = orientedLookAt( current, target, camera, targetRotation );
4023       DALI_TEST_EQUALS( reference, value, 0.001, TEST_LOCATION );
4024     }
4025   }
4026
4027   END_TEST;
4028 }