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