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