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