2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 #include <dali/public-api/dali-core.h>
22 #include <dali-test-suite-utils.h>
26 void utc_dali_constraint_startup(void)
28 test_return_value = TET_UNDEF;
31 void utc_dali_constraint_cleanup(void)
33 test_return_value = TET_PASS;
40 struct EqualToQuaternion
46 Quaternion operator()( const Quaternion& current, const PropertyInput& property )
48 return property.GetQuaternion();
58 Vector4 operator()( const Vector4& current, const PropertyInput& property )
60 return property.GetVector4();
64 class PropertyInputAbstraction : public Dali::PropertyInput
67 PropertyInputAbstraction(const bool& val) : mType(Dali::Property::BOOLEAN), mBoolData( val ) {}
68 PropertyInputAbstraction(const int& val) : mType(Dali::Property::INTEGER), mIntData( val ) {}
69 PropertyInputAbstraction(const unsigned int& val) : mType(Dali::Property::UNSIGNED_INTEGER), mUIntData( val ) {}
70 PropertyInputAbstraction(const float& val) : mType(Dali::Property::FLOAT), mFloatData( val ) {}
71 PropertyInputAbstraction(const Vector2& val) : mType(Dali::Property::VECTOR2), mVector2Data( val ) {}
72 PropertyInputAbstraction(const Vector3& val) : mType(Dali::Property::VECTOR3), mVector3Data( val ) {}
73 PropertyInputAbstraction(const Vector4& val) : mType(Dali::Property::VECTOR4), mVector4Data( val ) {}
74 PropertyInputAbstraction(const Matrix3& val) : mType(Dali::Property::MATRIX3), mMatrix3Data( val ) {}
75 PropertyInputAbstraction(const Matrix& val) : mType(Dali::Property::MATRIX), mMatrixData( val ) {}
76 PropertyInputAbstraction(const Quaternion& val) : mType(Dali::Property::ROTATION), mQuaternionData( val ) {}
78 ~PropertyInputAbstraction() {}
80 Dali::Property::Type GetType() const { return mType; }
82 const bool& GetBoolean() const { return mBoolData; }
84 const int& GetInteger() const { return mIntData; }
85 const unsigned int& GetUnsignedInteger() const { return mUIntData; }
87 const float& GetFloat() const { return mFloatData; }
88 const Vector2& GetVector2() const { return mVector2Data; }
89 const Vector3& GetVector3() const { return mVector3Data; }
90 const Vector4& GetVector4() const { return mVector4Data; }
92 const Matrix3& GetMatrix3() const { return mMatrix3Data; }
93 const Matrix& GetMatrix() const { return mMatrixData; }
95 const Quaternion& GetQuaternion() const { return mQuaternionData; }
98 Dali::Property::Type mType;
101 unsigned int mUIntData;
103 Vector2 mVector2Data;
104 Vector3 mVector3Data;
105 Vector4 mVector4Data;
106 Matrix3 mMatrix3Data;
108 Quaternion mQuaternionData;
111 static const float POSITION_EPSILON = 0.0001f;
112 static const float ROTATION_EPSILON = 0.0001f;
114 struct TestConstraint
116 Vector4 operator()(const Vector4& color)
118 return Vector4(color.x, color.y, color.z, 0.1f);
122 struct TestConstraintToVector3
124 TestConstraintToVector3(Vector3 target)
129 Vector3 operator()(const Vector3& current)
137 struct TestColorConstraint
139 TestColorConstraint(Vector4 target)
144 Vector4 operator()(const Vector4& color)
152 struct TestPositionConstraint
154 TestPositionConstraint(Vector3 target)
159 Vector3 operator()(const Vector3& position)
168 struct TestAlwaysTrueConstraint
170 bool operator()( const bool& current )
176 struct TestAlwaysEqualOrGreaterThanConstraintFloat
178 TestAlwaysEqualOrGreaterThanConstraintFloat( float value )
183 float operator()( const float& current )
185 return ( current < mValue ) ? mValue : current;
191 struct TestAlwaysEqualOrGreaterThanConstraintInteger
193 TestAlwaysEqualOrGreaterThanConstraintInteger( int value )
198 int operator()( const int& current )
200 return ( current < mValue ) ? mValue : current;
206 struct TestAlwaysEqualOrGreaterThanConstraintUnsignedInteger
208 TestAlwaysEqualOrGreaterThanConstraintUnsignedInteger( unsigned int value )
213 unsigned int operator()( unsigned const int& current )
215 return ( current < mValue ) ? mValue : current;
221 struct TestAlwaysEqualOrGreaterThanConstraintVector2
223 TestAlwaysEqualOrGreaterThanConstraintVector2( Vector2 value )
228 Vector2 operator()( const Vector2& current )
230 return Vector2( ( current.x < mValue.x ) ? mValue.x : current.x,
231 ( current.y < mValue.y ) ? mValue.y : current.y
238 struct TestAlwaysEqualOrGreaterThanConstraintVector3
240 TestAlwaysEqualOrGreaterThanConstraintVector3( Vector3 value )
245 Vector3 operator()( const Vector3& current )
247 return Vector3( ( current.x < mValue.x ) ? mValue.x : current.x,
248 ( current.y < mValue.y ) ? mValue.y : current.y,
249 ( current.z < mValue.z ) ? mValue.z : current.z
256 struct TestAlwaysEqualOrGreaterThanConstraintVector4
258 TestAlwaysEqualOrGreaterThanConstraintVector4( Vector4 value )
263 Vector4 operator()( const Vector4& current )
265 return Vector4( ( current.x < mValue.x ) ? mValue.x : current.x,
266 ( current.y < mValue.y ) ? mValue.y : current.y,
267 ( current.z < mValue.z ) ? mValue.z : current.z,
268 ( current.w < mValue.w ) ? mValue.w : current.w
275 struct TestConstraintFloat
277 TestConstraintFloat( float value )
282 float operator()( const float& current )
290 struct TestConstraintInteger
292 TestConstraintInteger( int value )
297 int operator()( const int& current )
305 struct TestConstraintUnsignedInteger
307 TestConstraintUnsignedInteger( int value )
312 unsigned int operator()( const unsigned int& current )
320 struct TestConstraintVector2
322 TestConstraintVector2( Vector2 value )
327 Vector2 operator()( const Vector2& current )
335 struct TestConstraintVector3
337 TestConstraintVector3( Vector3 value )
342 Vector3 operator()( const Vector3& current )
350 struct TestConstraintVector4
352 TestConstraintVector4( Vector4 value )
357 Vector4 operator()( const Vector4& current )
365 struct TestConstraintRotation
367 TestConstraintRotation( Quaternion rotation )
368 : mRotation( rotation )
372 Quaternion operator()( const Quaternion& current )
377 Quaternion mRotation;
380 struct TestConstraintMatrix3
382 TestConstraintMatrix3(Matrix3 matrix3)
383 : mMatrix3( matrix3 )
387 Matrix3 operator()( const Matrix3& current )
395 struct TestConstraintMatrix
397 TestConstraintMatrix(Matrix matrix)
402 Matrix operator()( const Matrix& current )
410 struct MoveAwayWithFadeConstraint
412 MoveAwayWithFadeConstraint( float distance )
413 : mDistance( distance )
417 Vector3 operator()( const Vector3& current,
418 const PropertyInput& color )
420 return Vector3( current.x,
422 -mDistance * (1.0f - color.GetVector4().a) );
428 struct TestBottomRightAlignConstraint
430 Vector3 operator()( const Vector3& current,
431 const PropertyInput& parentSize )
433 return Vector3( parentSize.GetVector3().x, parentSize.GetVector3().y, 0.0f );
437 struct MeanPositionConstraint1
439 Vector3 operator()( const Vector3& current,
440 const PropertyInput& position1 )
442 return Vector3( position1.GetVector3() );
446 struct MeanPositionConstraint2
448 Vector3 operator()( const Vector3& current,
449 const PropertyInput& position1,
450 const PropertyInput& position2 )
452 Vector3 meanValue = position1.GetVector3() +
453 position2.GetVector3();
455 return meanValue * 0.5f; // div 2
459 struct MeanPositionConstraint3
461 Vector3 operator()( const Vector3& current,
462 const PropertyInput& position1,
463 const PropertyInput& position2,
464 const PropertyInput& position3 )
466 Vector3 meanValue = position1.GetVector3() +
467 position2.GetVector3() +
468 position3.GetVector3();
470 return meanValue * (1.0f / 3.0f); // div 3
474 struct MeanPositionConstraint4
476 Vector3 operator()( const Vector3& current,
477 const PropertyInput& position1,
478 const PropertyInput& position2,
479 const PropertyInput& position3,
480 const PropertyInput& position4 )
482 Vector3 meanValue = position1.GetVector3() +
483 position2.GetVector3() +
484 position3.GetVector3() +
485 position4.GetVector3();
487 return meanValue * 0.25f; // div 4
491 struct MeanPositionConstraint5
493 Vector3 operator()( const Vector3& current,
494 const PropertyInput& position1,
495 const PropertyInput& position2,
496 const PropertyInput& position3,
497 const PropertyInput& position4,
498 const PropertyInput& position5 )
500 Vector3 meanValue = position1.GetVector3() +
501 position2.GetVector3() +
502 position3.GetVector3() +
503 position4.GetVector3() +
504 position5.GetVector3();
506 return meanValue * 0.2f; // div 5
510 struct MeanPositionConstraint6
512 Vector3 operator()( const Vector3& current,
513 const PropertyInput& position1,
514 const PropertyInput& position2,
515 const PropertyInput& position3,
516 const PropertyInput& position4,
517 const PropertyInput& position5,
518 const PropertyInput& position6 )
520 Vector3 meanValue = position1.GetVector3() +
521 position2.GetVector3() +
522 position3.GetVector3() +
523 position4.GetVector3() +
524 position5.GetVector3() +
525 position6.GetVector3();
527 return meanValue * (1.0f / 6.0f); // div 6
531 struct TestRelativeConstraintFloat
533 TestRelativeConstraintFloat(float scale)
538 float operator()( const float& current, const PropertyInput& relative )
540 return relative.GetFloat() * mScale;
546 struct TestRelativeConstraintVector3
548 TestRelativeConstraintVector3(float scale)
553 Vector3 operator()( const Vector3& current, const PropertyInput& relative )
555 return relative.GetVector3() * mScale;
561 } // anonymous namespace
568 int UtcDaliConstraintNewBoolean(void)
570 TestApplication application;
572 Actor actor = Actor::New();
574 // Register a boolean property
575 bool startValue(false);
576 Property::Index index = actor.RegisterProperty( "test-property", startValue );
577 Stage::GetCurrent().Add(actor);
578 DALI_TEST_CHECK( actor.GetProperty<bool>(index) == startValue );
581 * Test that the Constraint is correctly applied on a clean Node
583 application.SendNotification();
584 application.Render(0);
585 DALI_TEST_CHECK( actor.GetProperty<bool>(index) == startValue );
586 application.Render(0);
587 DALI_TEST_CHECK( actor.GetProperty<bool>(index) == startValue );
588 application.Render(0);
589 DALI_TEST_CHECK( actor.GetProperty<bool>(index) == startValue );
593 Constraint constraint = Constraint::New<bool>( index, TestAlwaysTrueConstraint() );
595 actor.ApplyConstraint( constraint );
596 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), false, TEST_LOCATION );
598 application.SendNotification();
599 application.Render(0);
601 // Constraint should be fully applied
602 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), true, TEST_LOCATION );
604 // Check that nothing has changed after a couple of buffer swaps
605 application.Render(0);
606 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), true, TEST_LOCATION );
607 application.Render(0);
608 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), true, TEST_LOCATION );
610 // Try to fight with the constraint - this shouldn't work!
611 actor.SetProperty( index, false );
613 application.SendNotification();
614 application.Render(0);
616 // Check that nothing has changed after a couple of buffer swaps
617 application.Render(0);
618 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), true, TEST_LOCATION );
619 application.Render(0);
620 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), true, TEST_LOCATION );
622 // Remove the constraint, then set new value
623 actor.RemoveConstraints();
624 actor.SetProperty( index, false );
626 // Constraint should have been removed
627 application.SendNotification();
628 application.Render(0);
629 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), false, TEST_LOCATION );
630 application.Render(0);
631 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), false, TEST_LOCATION );
635 int UtcDaliConstraintNewFloat(void)
637 TestApplication application;
639 Actor actor = Actor::New();
641 // Register a float property
642 float startValue(1.0f);
643 Property::Index index = actor.RegisterProperty( "test-property", startValue );
644 Stage::GetCurrent().Add(actor);
645 DALI_TEST_CHECK( actor.GetProperty<float>(index) == startValue );
648 * Test that the Constraint is correctly applied on a clean Node
650 application.SendNotification();
651 application.Render(0);
652 DALI_TEST_CHECK( actor.GetProperty<float>(index) == startValue );
653 application.Render(0);
654 DALI_TEST_CHECK( actor.GetProperty<float>(index) == startValue );
655 application.Render(0);
656 DALI_TEST_CHECK( actor.GetProperty<float>(index) == startValue );
660 float minValue( 2.0f );
661 Constraint constraint = Constraint::New<float>( index, TestAlwaysEqualOrGreaterThanConstraintFloat( minValue ) );
663 actor.ApplyConstraint( constraint );
664 DALI_TEST_EQUALS( actor.GetProperty<float>(index), startValue, TEST_LOCATION );
666 application.SendNotification();
667 application.Render(0);
669 // Constraint should be fully applied
670 DALI_TEST_EQUALS( actor.GetProperty<float>(index), minValue, TEST_LOCATION );
672 // Check that nothing has changed after a couple of buffer swaps
673 application.Render(0);
674 DALI_TEST_EQUALS( actor.GetProperty<float>(index), minValue, TEST_LOCATION );
675 application.Render(0);
676 DALI_TEST_EQUALS( actor.GetProperty<float>(index), minValue, TEST_LOCATION );
678 // Set to greater than 2.0f, the constraint will allow this
679 actor.SetProperty( index, 3.0f );
681 application.SendNotification();
682 application.Render(0);
684 DALI_TEST_EQUALS( actor.GetProperty<float>(index), 3.0f, TEST_LOCATION );
686 // Check that nothing has changed after a couple of buffer swaps
687 application.Render(0);
688 DALI_TEST_EQUALS( actor.GetProperty<float>(index), 3.0f, TEST_LOCATION );
689 application.Render(0);
690 DALI_TEST_EQUALS( actor.GetProperty<float>(index), 3.0f, TEST_LOCATION );
692 // Set to less than 2.0f, the constraint will NOT allow this
693 actor.SetProperty( index, 1.0f );
695 application.SendNotification();
696 application.Render(0);
698 DALI_TEST_EQUALS( actor.GetProperty<float>(index), minValue/*not 1.0f*/, TEST_LOCATION );
700 // Check that nothing has changed after a couple of buffer swaps
701 application.Render(0);
702 DALI_TEST_EQUALS( actor.GetProperty<float>(index), minValue, TEST_LOCATION );
703 application.Render(0);
704 DALI_TEST_EQUALS( actor.GetProperty<float>(index), minValue, TEST_LOCATION );
706 // Remove the constraint, then set new value
707 actor.RemoveConstraints();
708 actor.SetProperty( index, 1.0f );
710 // Constraint should have been removed
711 application.SendNotification();
712 application.Render(0);
713 DALI_TEST_EQUALS( actor.GetProperty<float>(index), 1.0f, TEST_LOCATION );
714 application.Render(0);
715 DALI_TEST_EQUALS( actor.GetProperty<float>(index), 1.0f, TEST_LOCATION );
719 int UtcDaliConstraintNewInteger(void)
721 TestApplication application;
723 Actor actor = Actor::New();
725 // Register an integer property
727 Property::Index index = actor.RegisterProperty( "test-property", startValue );
728 Stage::GetCurrent().Add(actor);
729 DALI_TEST_CHECK( actor.GetProperty<int>(index) == startValue );
732 * Test that the Constraint is correctly applied on a clean Node
734 application.SendNotification();
735 application.Render(0);
736 DALI_TEST_CHECK( actor.GetProperty<int>(index) == startValue );
737 application.Render(0);
738 DALI_TEST_CHECK( actor.GetProperty<int>(index) == startValue );
739 application.Render(0);
740 DALI_TEST_CHECK( actor.GetProperty<int>(index) == startValue );
745 Constraint constraint = Constraint::New<int>( index, TestAlwaysEqualOrGreaterThanConstraintInteger( minValue ) );
747 actor.ApplyConstraint( constraint );
748 DALI_TEST_EQUALS( actor.GetProperty<int>(index), startValue, TEST_LOCATION );
750 application.SendNotification();
751 application.Render(0);
753 // Constraint should be fully applied
754 DALI_TEST_EQUALS( actor.GetProperty<int>(index), minValue, TEST_LOCATION );
756 // Check that nothing has changed after a couple of buffer swaps
757 application.Render(0);
758 DALI_TEST_EQUALS( actor.GetProperty<int>(index), minValue, TEST_LOCATION );
759 application.Render(0);
760 DALI_TEST_EQUALS( actor.GetProperty<int>(index), minValue, TEST_LOCATION );
762 // Set to greater than 2f, the constraint will allow this
763 actor.SetProperty( index, 3 );
765 application.SendNotification();
766 application.Render(0);
768 DALI_TEST_EQUALS( actor.GetProperty<int>(index), 3, TEST_LOCATION );
770 // Check that nothing has changed after a couple of buffer swaps
771 application.Render(0);
772 DALI_TEST_EQUALS( actor.GetProperty<int>(index), 3, TEST_LOCATION );
773 application.Render(0);
774 DALI_TEST_EQUALS( actor.GetProperty<int>(index), 3, TEST_LOCATION );
776 // Set to less than 2, the constraint will NOT allow this
777 actor.SetProperty( index, 1 );
779 application.SendNotification();
780 application.Render(0);
782 DALI_TEST_EQUALS( actor.GetProperty<int>(index), minValue/*not 1*/, TEST_LOCATION );
784 // Check that nothing has changed after a couple of buffer swaps
785 application.Render(0);
786 DALI_TEST_EQUALS( actor.GetProperty<int>(index), minValue, TEST_LOCATION );
787 application.Render(0);
788 DALI_TEST_EQUALS( actor.GetProperty<int>(index), minValue, TEST_LOCATION );
790 // Remove the constraint, then set new value
791 actor.RemoveConstraints();
792 actor.SetProperty( index, 1 );
794 // Constraint should have been removed
795 application.SendNotification();
796 application.Render(0);
797 DALI_TEST_EQUALS( actor.GetProperty<int>(index), 1, TEST_LOCATION );
798 application.Render(0);
799 DALI_TEST_EQUALS( actor.GetProperty<int>(index), 1, TEST_LOCATION );
804 int UtcDaliConstraintNewUnsignedInteger(void)
806 TestApplication application;
808 Actor actor = Actor::New();
810 // Register an integer property
811 unsigned int startValue( 1u );
812 Property::Index index = actor.RegisterProperty( "test-property", startValue );
813 Stage::GetCurrent().Add(actor);
814 DALI_TEST_CHECK( actor.GetProperty<unsigned int>(index) == startValue );
817 * Test that the Constraint is correctly applied on a clean Node
819 application.SendNotification();
820 application.Render(0);
821 DALI_TEST_CHECK( actor.GetProperty<unsigned int>(index) == startValue );
822 application.Render(0);
823 DALI_TEST_CHECK( actor.GetProperty<unsigned int>(index) == startValue );
824 application.Render(0);
825 DALI_TEST_CHECK( actor.GetProperty<unsigned int>(index) == startValue );
829 unsigned int minValue( 2 );
830 Constraint constraint = Constraint::New<unsigned int>( index, TestAlwaysEqualOrGreaterThanConstraintUnsignedInteger( minValue ) );
832 actor.ApplyConstraint( constraint );
833 DALI_TEST_EQUALS( actor.GetProperty<unsigned int>(index), startValue, TEST_LOCATION );
835 application.SendNotification();
836 application.Render(0);
838 // Constraint should be fully applied
839 DALI_TEST_EQUALS( actor.GetProperty<unsigned int>(index), minValue, TEST_LOCATION );
841 // Check that nothing has changed after a couple of buffer swaps
842 application.Render(0);
843 DALI_TEST_EQUALS( actor.GetProperty<unsigned int>(index), minValue, TEST_LOCATION );
844 application.Render(0);
845 DALI_TEST_EQUALS( actor.GetProperty<unsigned int>(index), minValue, TEST_LOCATION );
847 // Set to greater than 2f, the constraint will allow this
848 actor.SetProperty( index, 3u );
850 application.SendNotification();
851 application.Render(0);
853 DALI_TEST_EQUALS( actor.GetProperty<unsigned int>(index), 3, TEST_LOCATION );
855 // Check that nothing has changed after a couple of buffer swaps
856 application.Render(0);
857 DALI_TEST_EQUALS( actor.GetProperty<unsigned int>(index), 3, TEST_LOCATION );
858 application.Render(0);
859 DALI_TEST_EQUALS( actor.GetProperty<unsigned int>(index), 3, TEST_LOCATION );
861 // Set to less than 2, the constraint will NOT allow this
862 actor.SetProperty( index, 1u );
864 application.SendNotification();
865 application.Render(0);
867 DALI_TEST_EQUALS( actor.GetProperty<unsigned int>(index), minValue/*not 1*/, TEST_LOCATION );
869 // Check that nothing has changed after a couple of buffer swaps
870 application.Render(0);
871 DALI_TEST_EQUALS( actor.GetProperty<unsigned int>(index), minValue, TEST_LOCATION );
872 application.Render(0);
873 DALI_TEST_EQUALS( actor.GetProperty<unsigned int>(index), minValue, TEST_LOCATION );
875 // Remove the constraint, then set new value
876 actor.RemoveConstraints();
877 actor.SetProperty( index, 1u );
879 // Constraint should have been removed
880 application.SendNotification();
881 application.Render(0);
882 DALI_TEST_EQUALS( actor.GetProperty<unsigned int>(index), 1, TEST_LOCATION );
883 application.Render(0);
884 DALI_TEST_EQUALS( actor.GetProperty<unsigned int>(index), 1, TEST_LOCATION );
889 int UtcDaliConstraintNewVector2(void)
891 TestApplication application;
893 Actor actor = Actor::New();
895 // Register a Vector2 property
896 Vector2 startValue( 1.0f, 1.0f );
897 Property::Index index = actor.RegisterProperty( "test-property", startValue );
898 Stage::GetCurrent().Add(actor);
899 DALI_TEST_CHECK( actor.GetProperty<Vector2>(index) == startValue );
902 * Test that the Constraint is correctly applied on a clean Node
904 application.SendNotification();
905 application.Render(0);
906 DALI_TEST_CHECK( actor.GetProperty<Vector2>(index) == startValue );
907 application.Render(0);
908 DALI_TEST_CHECK( actor.GetProperty<Vector2>(index) == startValue );
909 application.Render(0);
910 DALI_TEST_CHECK( actor.GetProperty<Vector2>(index) == startValue );
914 Vector2 minValue( 2.0f, 2.0f );
915 Constraint constraint = Constraint::New<Vector2>( index, TestAlwaysEqualOrGreaterThanConstraintVector2( minValue ) );
917 actor.ApplyConstraint( constraint );
918 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), startValue, TEST_LOCATION );
920 application.SendNotification();
921 application.Render(0);
923 // Constraint should be fully applied
924 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), minValue, TEST_LOCATION );
926 // Check that nothing has changed after a couple of buffer swaps
927 application.Render(0);
928 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), minValue, TEST_LOCATION );
929 application.Render(0);
930 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), minValue, TEST_LOCATION );
932 // Set to greater than 2.0f, the constraint will allow this
933 Vector2 greaterValue( 3.0f, 3.0f );
934 actor.SetProperty( index, greaterValue );
936 application.SendNotification();
937 application.Render(0);
939 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), greaterValue, TEST_LOCATION );
941 // Check that nothing has changed after a couple of buffer swaps
942 application.Render(0);
943 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), greaterValue, TEST_LOCATION );
944 application.Render(0);
945 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), greaterValue, TEST_LOCATION );
947 // Set to less than 2.0f, the constraint will NOT allow this
948 Vector2 lesserValue( 1.0f, 1.0f );
949 actor.SetProperty( index, lesserValue );
951 application.SendNotification();
952 application.Render(0);
954 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), minValue/*not lesserValue*/, TEST_LOCATION );
956 // Check that nothing has changed after a couple of buffer swaps
957 application.Render(0);
958 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), minValue, TEST_LOCATION );
959 application.Render(0);
960 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), minValue, TEST_LOCATION );
962 // Remove the constraint, then set new value
963 actor.RemoveConstraints();
964 actor.SetProperty( index, lesserValue );
966 // Constraint should have been removed
967 application.SendNotification();
968 application.Render(0);
969 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), lesserValue, TEST_LOCATION );
970 application.Render(0);
971 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), lesserValue, TEST_LOCATION );
975 int UtcDaliConstraintNewVector3(void)
977 TestApplication application;
979 Actor actor = Actor::New();
981 // Register a Vector3 property
982 Vector3 startValue(1.0f, 1.0f, 1.0f);
983 Property::Index index = actor.RegisterProperty( "test-property", startValue );
984 Stage::GetCurrent().Add(actor);
985 DALI_TEST_CHECK( actor.GetProperty<Vector3>(index) == startValue );
988 * Test that the Constraint is correctly applied on a clean Node
990 application.SendNotification();
991 application.Render(0);
992 DALI_TEST_CHECK( actor.GetProperty<Vector3>(index) == startValue );
993 application.Render(0);
994 DALI_TEST_CHECK( actor.GetProperty<Vector3>(index) == startValue );
995 application.Render(0);
996 DALI_TEST_CHECK( actor.GetProperty<Vector3>(index) == startValue );
1000 Vector3 minValue( 2.0f, 2.0f, 2.0f );
1001 Constraint constraint = Constraint::New<Vector3>( index, TestAlwaysEqualOrGreaterThanConstraintVector3( minValue ) );
1003 actor.ApplyConstraint( constraint );
1004 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), startValue, TEST_LOCATION );
1006 application.SendNotification();
1007 application.Render(0);
1009 // Constraint should be fully applied
1010 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), minValue, TEST_LOCATION );
1012 // Check that nothing has changed after a couple of buffer swaps
1013 application.Render(0);
1014 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), minValue, TEST_LOCATION );
1015 application.Render(0);
1016 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), minValue, TEST_LOCATION );
1018 // Set to greater than 2.0f, the constraint will allow this
1019 Vector3 greaterValue( 3.0f, 3.0f, 3.0f );
1020 actor.SetProperty( index, greaterValue );
1022 application.SendNotification();
1023 application.Render(0);
1025 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), greaterValue, TEST_LOCATION );
1027 // Check that nothing has changed after a couple of buffer swaps
1028 application.Render(0);
1029 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), greaterValue, TEST_LOCATION );
1030 application.Render(0);
1031 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), greaterValue, TEST_LOCATION );
1033 // Set to less than 2.0f, the constraint will NOT allow this
1034 Vector3 lesserValue( 1.0f, 1.0f, 1.0f );
1035 actor.SetProperty( index, lesserValue );
1037 application.SendNotification();
1038 application.Render(0);
1040 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), minValue/*not lesserValue*/, TEST_LOCATION );
1042 // Check that nothing has changed after a couple of buffer swaps
1043 application.Render(0);
1044 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), minValue, TEST_LOCATION );
1045 application.Render(0);
1046 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), minValue, TEST_LOCATION );
1048 // Remove the constraint, then set new value
1049 actor.RemoveConstraints();
1050 actor.SetProperty( index, lesserValue );
1052 // Constraint should have been removed
1053 application.SendNotification();
1054 application.Render(0);
1055 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), lesserValue, TEST_LOCATION );
1056 application.Render(0);
1057 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), lesserValue, TEST_LOCATION );
1061 int UtcDaliConstraintNewVector4(void)
1063 TestApplication application;
1065 Actor actor = Actor::New();
1067 // Register a Vector4 property
1068 Vector4 startValue( 1.0f, 1.0f, 1.0f, 1.0f );
1069 Property::Index index = actor.RegisterProperty( "test-property", startValue );
1070 Stage::GetCurrent().Add(actor);
1071 DALI_TEST_CHECK( actor.GetProperty<Vector4>(index) == startValue );
1074 * Test that the Constraint is correctly applied on a clean Node
1076 application.SendNotification();
1077 application.Render(0);
1078 DALI_TEST_CHECK( actor.GetProperty<Vector4>(index) == startValue );
1079 application.Render(0);
1080 DALI_TEST_CHECK( actor.GetProperty<Vector4>(index) == startValue );
1081 application.Render(0);
1082 DALI_TEST_CHECK( actor.GetProperty<Vector4>(index) == startValue );
1086 Vector4 minValue( 2.0f, 2.0f, 2.0f, 2.0f );
1087 Constraint constraint = Constraint::New<Vector4>( index, TestAlwaysEqualOrGreaterThanConstraintVector4( minValue ) );
1089 actor.ApplyConstraint( constraint );
1090 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), startValue, TEST_LOCATION );
1092 application.SendNotification();
1093 application.Render(0);
1095 // Constraint should be fully applied
1096 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), minValue, TEST_LOCATION );
1098 // Check that nothing has changed after a couple of buffer swaps
1099 application.Render(0);
1100 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), minValue, TEST_LOCATION );
1101 application.Render(0);
1102 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), minValue, TEST_LOCATION );
1104 // Set to greater than 2.0f, the constraint will allow this
1105 Vector4 greaterValue( 3.0f, 3.0f, 3.0f, 3.0f );
1106 actor.SetProperty( index, greaterValue );
1108 application.SendNotification();
1109 application.Render(0);
1111 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), greaterValue, TEST_LOCATION );
1113 // Check that nothing has changed after a couple of buffer swaps
1114 application.Render(0);
1115 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), greaterValue, TEST_LOCATION );
1116 application.Render(0);
1117 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), greaterValue, TEST_LOCATION );
1119 // Set to less than 2.0f, the constraint will NOT allow this
1120 Vector4 lesserValue( 1.0f, 1.0f, 1.0f, 1.0f );
1121 actor.SetProperty( index, lesserValue );
1123 application.SendNotification();
1124 application.Render(0);
1126 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), minValue/*not lesserValue*/, TEST_LOCATION );
1128 // Check that nothing has changed after a couple of buffer swaps
1129 application.Render(0);
1130 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), minValue, TEST_LOCATION );
1131 application.Render(0);
1132 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), minValue, TEST_LOCATION );
1134 // Remove the constraint, then set new value
1135 actor.RemoveConstraints();
1136 actor.SetProperty( index, lesserValue );
1138 // Constraint should have been removed
1139 application.SendNotification();
1140 application.Render(0);
1141 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), lesserValue, TEST_LOCATION );
1142 application.Render(0);
1143 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), lesserValue, TEST_LOCATION );
1147 int UtcDaliConstraintNewMatrix(void)
1151 TestApplication application;
1153 Actor actor = Actor::New();
1155 // Register a Matrix property
1156 Matrix startValue = Matrix::IDENTITY;
1157 Property::Index index = actor.RegisterProperty( "test-property", startValue );
1158 DALI_TEST_CHECK( index != Property::INVALID_INDEX );
1159 if (index != Property::INVALID_INDEX)
1161 Stage::GetCurrent().Add(actor);
1162 DALI_TEST_CHECK( actor.GetProperty<Matrix>(index) == startValue );
1165 Matrix constraintLimit;
1166 constraintLimit.SetTransformComponents(Vector3::ONE, Quaternion(Radian(Degree(30.0f)), Vector3::YAXIS), Vector3::ZAXIS );
1167 Constraint constraint = Constraint::New<Matrix>( index, TestConstraintMatrix(constraintLimit));
1168 actor.ApplyConstraint( constraint );
1169 DALI_TEST_EQUALS( actor.GetProperty<Matrix>(index), startValue, TEST_LOCATION );
1171 application.SendNotification();
1172 application.Render(0);
1174 DALI_TEST_EQUALS( actor.GetProperty<Matrix>(index), constraintLimit, TEST_LOCATION );
1177 catch (Dali::DaliException& e)
1179 DALI_TEST_PRINT_ASSERT( e );
1185 int UtcDaliConstraintNewMatrix3(void)
1189 TestApplication application;
1191 Actor actor = Actor::New();
1193 // Register a Matrix3 property
1194 Matrix3 startValue(1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f);
1195 Property::Index index = actor.RegisterProperty( "test-property", startValue );
1196 DALI_TEST_CHECK( index != Property::INVALID_INDEX );
1197 if (index != Property::INVALID_INDEX)
1199 Stage::GetCurrent().Add(actor);
1200 DALI_TEST_CHECK( actor.GetProperty<Matrix3>(index) == startValue );
1203 Matrix3 constraintLimit(42.0f, 0.0f, 0.0f, 0.0f, 42.0f, 0.0f, 0.0f, 0.0f, 1.0f);
1204 Constraint constraint = Constraint::New<Matrix3>( index, TestConstraintMatrix3(constraintLimit));
1205 actor.ApplyConstraint( constraint );
1206 DALI_TEST_EQUALS( actor.GetProperty<Matrix3>(index), startValue, 0.001f, TEST_LOCATION );
1208 application.SendNotification();
1209 application.Render(0);
1211 DALI_TEST_EQUALS( actor.GetProperty<Matrix3>(index), constraintLimit, 0.001f, TEST_LOCATION );
1214 catch (Dali::DaliException& e)
1216 DALI_TEST_PRINT_ASSERT( e );
1222 int UtcDaliConstraintNewQuaternion(void)
1224 TestApplication application;
1226 Actor actor = Actor::New();
1228 // Register a Quaternion property
1229 Quaternion startValue( 0.0f, Vector3::YAXIS );
1230 Property::Index index = actor.RegisterProperty( "test-property", startValue );
1231 Stage::GetCurrent().Add(actor);
1232 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), startValue, ROTATION_EPSILON, TEST_LOCATION );
1235 * Test that the Constraint is correctly applied on a clean Node
1237 application.SendNotification();
1238 application.Render(0);
1239 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), startValue, ROTATION_EPSILON, TEST_LOCATION );
1240 application.Render(0);
1241 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), startValue, ROTATION_EPSILON, TEST_LOCATION );
1242 application.Render(0);
1243 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), startValue, ROTATION_EPSILON, TEST_LOCATION );
1247 Quaternion constrainedRotation( M_PI*0.25f, Vector3::YAXIS );
1248 Constraint constraint = Constraint::New<Quaternion>( index, TestConstraintRotation( constrainedRotation ) );
1250 actor.ApplyConstraint( constraint );
1251 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), startValue, ROTATION_EPSILON, TEST_LOCATION );
1253 application.SendNotification();
1254 application.Render(0);
1256 // Constraint should be fully applied
1257 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), constrainedRotation, ROTATION_EPSILON, TEST_LOCATION );
1259 // Check that nothing has changed after a couple of buffer swaps
1260 application.Render(0);
1261 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), constrainedRotation, ROTATION_EPSILON, TEST_LOCATION );
1262 application.Render(0);
1263 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), constrainedRotation, ROTATION_EPSILON, TEST_LOCATION );
1265 // Set to a different rotation, the constraint will NOT allow this
1266 Quaternion differentRotation( M_PI*0.5f, Vector3::YAXIS );
1267 actor.SetProperty( index, differentRotation );
1269 application.SendNotification();
1270 application.Render(0);
1272 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), constrainedRotation/*not differentRotation*/, ROTATION_EPSILON, TEST_LOCATION );
1274 // Check that nothing has changed after a couple of buffer swaps
1275 application.Render(0);
1276 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), constrainedRotation, ROTATION_EPSILON, TEST_LOCATION );
1277 application.Render(0);
1278 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), constrainedRotation, ROTATION_EPSILON, TEST_LOCATION );
1280 // Remove the constraint, then set new value
1281 actor.RemoveConstraints();
1282 actor.SetProperty( index, differentRotation );
1284 // Constraint should have been removed
1285 application.SendNotification();
1286 application.Render(0);
1287 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), differentRotation, ROTATION_EPSILON, TEST_LOCATION );
1288 application.Render(0);
1289 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), differentRotation, ROTATION_EPSILON, TEST_LOCATION );
1293 int UtcDaliConstraintNewOffStageBoolean(void)
1295 TestApplication application;
1297 Actor actor = Actor::New();
1299 // Register a boolean property
1300 bool startValue(false);
1301 Property::Index index = actor.RegisterProperty( "test-property", startValue );
1302 DALI_TEST_CHECK( actor.GetProperty<bool>(index) == startValue );
1304 // Apply constraint to off-stage Actor
1305 Constraint constraint = Constraint::New<bool>( index, TestAlwaysTrueConstraint() );
1306 actor.ApplyConstraint( constraint );
1308 application.SendNotification();
1309 application.Render(0);
1310 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), false, TEST_LOCATION );
1312 // Add actor to stage
1313 Stage::GetCurrent().Add(actor);
1314 application.SendNotification();
1315 application.Render(0);
1317 // Constraint should be fully applied
1318 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), true, TEST_LOCATION );
1320 // Check that nothing has changed after a couple of buffer swaps
1321 application.Render(0);
1322 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), true, TEST_LOCATION );
1323 application.Render(0);
1324 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), true, TEST_LOCATION );
1326 // Take the actor off-stage
1327 Stage::GetCurrent().Remove(actor);
1328 application.SendNotification();
1329 application.Render(0);
1330 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), true, TEST_LOCATION );
1332 // Set a new value; the constraint will not prevent this
1333 actor.SetProperty( index, false );
1334 application.SendNotification();
1335 application.Render(0);
1336 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), false, TEST_LOCATION );
1338 // Add actor to stage (2nd time)
1339 Stage::GetCurrent().Add(actor);
1340 application.SendNotification();
1341 application.Render(0);
1343 // Constraint should be fully applied (2nd time)
1344 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), true, TEST_LOCATION );
1346 // Check that nothing has changed after a couple of buffer swaps
1347 application.Render(0);
1348 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), true, TEST_LOCATION );
1349 application.Render(0);
1350 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), true, TEST_LOCATION );
1352 // Take the actor off-stage (2nd-time)
1353 Stage::GetCurrent().Remove(actor);
1354 application.SendNotification();
1355 application.Render(0);
1356 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), true, TEST_LOCATION );
1358 // Remove the constraint, and set a new value
1359 actor.RemoveConstraints();
1360 actor.SetProperty( index, false );
1361 application.SendNotification();
1362 application.Render(0);
1363 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), false, TEST_LOCATION );
1365 // Add actor to stage (3rd time)
1366 Stage::GetCurrent().Add(actor);
1367 application.SendNotification();
1368 application.Render(0);
1370 // Constraint should be gone
1371 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), false, TEST_LOCATION );
1373 // Check that nothing has changed after a couple of buffer swaps
1374 application.Render(0);
1375 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), false, TEST_LOCATION );
1376 application.Render(0);
1377 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), false, TEST_LOCATION );
1381 int UtcDaliConstraintNewOffStageFloat(void)
1383 TestApplication application;
1385 Actor actor = Actor::New();
1387 // Register a float property
1388 float startValue(1.0f);
1389 Property::Index index = actor.RegisterProperty( "test-property", startValue );
1390 DALI_TEST_CHECK( actor.GetProperty<float>(index) == startValue );
1392 // Apply constraint to off-stage Actor
1393 float constrainedValue( 2.0f );
1394 Constraint constraint = Constraint::New<float>( index, TestConstraintFloat( constrainedValue ) );
1395 actor.ApplyConstraint( constraint );
1397 application.SendNotification();
1398 application.Render(0);
1399 DALI_TEST_EQUALS( actor.GetProperty<float>(index), startValue, TEST_LOCATION );
1401 // Add actor to stage
1402 Stage::GetCurrent().Add(actor);
1403 application.SendNotification();
1404 application.Render(0);
1406 // Constraint should be fully applied
1407 DALI_TEST_EQUALS( actor.GetProperty<float>(index), constrainedValue, TEST_LOCATION );
1409 // Check that nothing has changed after a couple of buffer swaps
1410 application.Render(0);
1411 DALI_TEST_EQUALS( actor.GetProperty<float>(index), constrainedValue, TEST_LOCATION );
1412 application.Render(0);
1413 DALI_TEST_EQUALS( actor.GetProperty<float>(index), constrainedValue, TEST_LOCATION );
1415 // Take the actor off-stage
1416 Stage::GetCurrent().Remove(actor);
1417 application.SendNotification();
1418 application.Render(0);
1419 DALI_TEST_EQUALS( actor.GetProperty<float>(index), constrainedValue, TEST_LOCATION );
1421 // Set back to startValue; the constraint will not prevent this
1422 actor.SetProperty( index, startValue );
1423 application.SendNotification();
1424 application.Render(0);
1425 DALI_TEST_EQUALS( actor.GetProperty<float>(index), startValue, TEST_LOCATION );
1427 // Add actor to stage (2nd time)
1428 Stage::GetCurrent().Add(actor);
1429 application.SendNotification();
1430 application.Render(0);
1432 // Constraint should be fully applied (2nd time)
1433 DALI_TEST_EQUALS( actor.GetProperty<float>(index), constrainedValue, TEST_LOCATION );
1435 // Check that nothing has changed after a couple of buffer swaps
1436 application.Render(0);
1437 DALI_TEST_EQUALS( actor.GetProperty<float>(index), constrainedValue, TEST_LOCATION );
1438 application.Render(0);
1439 DALI_TEST_EQUALS( actor.GetProperty<float>(index), constrainedValue, TEST_LOCATION );
1441 // Take the actor off-stage (2nd-time)
1442 Stage::GetCurrent().Remove(actor);
1443 application.SendNotification();
1444 application.Render(0);
1445 DALI_TEST_EQUALS( actor.GetProperty<float>(index), constrainedValue, TEST_LOCATION );
1447 // Remove the constraint, and set back to startValue
1448 actor.RemoveConstraints();
1449 actor.SetProperty( index, startValue );
1450 application.SendNotification();
1451 application.Render(0);
1452 DALI_TEST_EQUALS( actor.GetProperty<float>(index), startValue, TEST_LOCATION );
1454 // Add actor to stage (3rd time)
1455 Stage::GetCurrent().Add(actor);
1456 application.SendNotification();
1457 application.Render(0);
1459 // Constraint should be gone
1460 DALI_TEST_EQUALS( actor.GetProperty<float>(index), startValue, TEST_LOCATION );
1462 // Check that nothing has changed after a couple of buffer swaps
1463 application.Render(0);
1464 DALI_TEST_EQUALS( actor.GetProperty<float>(index), startValue, TEST_LOCATION );
1465 application.Render(0);
1466 DALI_TEST_EQUALS( actor.GetProperty<float>(index), startValue, TEST_LOCATION );
1470 int UtcDaliConstraintNewOffStageInteger(void)
1472 TestApplication application;
1474 Actor actor = Actor::New();
1476 // Register an integer property
1478 Property::Index index = actor.RegisterProperty( "test-property", startValue );
1479 DALI_TEST_CHECK( actor.GetProperty<int>(index) == startValue );
1481 // Apply constraint to off-stage Actor
1482 int constrainedValue( 2 );
1483 Constraint constraint = Constraint::New<int>( index, TestConstraintInteger( constrainedValue ) );
1484 actor.ApplyConstraint( constraint );
1486 application.SendNotification();
1487 application.Render(0);
1488 DALI_TEST_EQUALS( actor.GetProperty<int>(index), startValue, TEST_LOCATION );
1490 // Add actor to stage
1491 Stage::GetCurrent().Add(actor);
1492 application.SendNotification();
1493 application.Render(0);
1495 // Constraint should be fully applied
1496 DALI_TEST_EQUALS( actor.GetProperty<int>(index), constrainedValue, TEST_LOCATION );
1498 // Check that nothing has changed after a couple of buffer swaps
1499 application.Render(0);
1500 DALI_TEST_EQUALS( actor.GetProperty<int>(index), constrainedValue, TEST_LOCATION );
1501 application.Render(0);
1502 DALI_TEST_EQUALS( actor.GetProperty<int>(index), constrainedValue, TEST_LOCATION );
1504 // Take the actor off-stage
1505 Stage::GetCurrent().Remove(actor);
1506 application.SendNotification();
1507 application.Render(0);
1508 DALI_TEST_EQUALS( actor.GetProperty<int>(index), constrainedValue, TEST_LOCATION );
1510 // Set back to startValue; the constraint will not prevent this
1511 actor.SetProperty( index, startValue );
1512 application.SendNotification();
1513 application.Render(0);
1514 DALI_TEST_EQUALS( actor.GetProperty<int>(index), startValue, TEST_LOCATION );
1516 // Add actor to stage (2nd time)
1517 Stage::GetCurrent().Add(actor);
1518 application.SendNotification();
1519 application.Render(0);
1521 // Constraint should be fully applied (2nd time)
1522 DALI_TEST_EQUALS( actor.GetProperty<int>(index), constrainedValue, TEST_LOCATION );
1524 // Check that nothing has changed after a couple of buffer swaps
1525 application.Render(0);
1526 DALI_TEST_EQUALS( actor.GetProperty<int>(index), constrainedValue, TEST_LOCATION );
1527 application.Render(0);
1528 DALI_TEST_EQUALS( actor.GetProperty<int>(index), constrainedValue, TEST_LOCATION );
1530 // Take the actor off-stage (2nd-time)
1531 Stage::GetCurrent().Remove(actor);
1532 application.SendNotification();
1533 application.Render(0);
1534 DALI_TEST_EQUALS( actor.GetProperty<int>(index), constrainedValue, TEST_LOCATION );
1536 // Remove the constraint, and set back to startValue
1537 actor.RemoveConstraints();
1538 actor.SetProperty( index, startValue );
1539 application.SendNotification();
1540 application.Render(0);
1541 DALI_TEST_EQUALS( actor.GetProperty<int>(index), startValue, TEST_LOCATION );
1543 // Add actor to stage (3rd time)
1544 Stage::GetCurrent().Add(actor);
1545 application.SendNotification();
1546 application.Render(0);
1548 // Constraint should be gone
1549 DALI_TEST_EQUALS( actor.GetProperty<int>(index), startValue, TEST_LOCATION );
1551 // Check that nothing has changed after a couple of buffer swaps
1552 application.Render(0);
1553 DALI_TEST_EQUALS( actor.GetProperty<int>(index), startValue, TEST_LOCATION );
1554 application.Render(0);
1555 DALI_TEST_EQUALS( actor.GetProperty<int>(index), startValue, TEST_LOCATION );
1559 int UtcDaliConstraintNewOffStageUnsignedInteger(void)
1561 TestApplication application;
1563 Actor actor = Actor::New();
1565 // Register an integer property
1566 unsigned int startValue(1);
1567 Property::Index index = actor.RegisterProperty( "test-property", startValue );
1568 DALI_TEST_CHECK( actor.GetProperty<unsigned int>(index) == startValue );
1570 // Apply constraint to off-stage Actor
1571 unsigned int constrainedValue( 2 );
1572 Constraint constraint = Constraint::New<unsigned int>( index, TestConstraintUnsignedInteger( constrainedValue ) );
1573 actor.ApplyConstraint( constraint );
1575 application.SendNotification();
1576 application.Render(0);
1577 DALI_TEST_EQUALS( actor.GetProperty<unsigned int>(index), startValue, TEST_LOCATION );
1579 // Add actor to stage
1580 Stage::GetCurrent().Add(actor);
1581 application.SendNotification();
1582 application.Render(0);
1584 // Constraint should be fully applied
1585 DALI_TEST_EQUALS( actor.GetProperty<unsigned int>(index), constrainedValue, TEST_LOCATION );
1587 // Check that nothing has changed after a couple of buffer swaps
1588 application.Render(0);
1589 DALI_TEST_EQUALS( actor.GetProperty<unsigned int>(index), constrainedValue, TEST_LOCATION );
1590 application.Render(0);
1591 DALI_TEST_EQUALS( actor.GetProperty<unsigned int>(index), constrainedValue, TEST_LOCATION );
1593 // Take the actor off-stage
1594 Stage::GetCurrent().Remove(actor);
1595 application.SendNotification();
1596 application.Render(0);
1597 DALI_TEST_EQUALS( actor.GetProperty<unsigned int>(index), constrainedValue, TEST_LOCATION );
1599 // Set back to startValue; the constraint will not prevent this
1600 actor.SetProperty( index, startValue );
1601 application.SendNotification();
1602 application.Render(0);
1603 DALI_TEST_EQUALS( actor.GetProperty<unsigned int>(index), startValue, TEST_LOCATION );
1605 // Add actor to stage (2nd time)
1606 Stage::GetCurrent().Add(actor);
1607 application.SendNotification();
1608 application.Render(0);
1610 // Constraint should be fully applied (2nd time)
1611 DALI_TEST_EQUALS( actor.GetProperty<unsigned int>(index), constrainedValue, TEST_LOCATION );
1613 // Check that nothing has changed after a couple of buffer swaps
1614 application.Render(0);
1615 DALI_TEST_EQUALS( actor.GetProperty<unsigned int>(index), constrainedValue, TEST_LOCATION );
1616 application.Render(0);
1617 DALI_TEST_EQUALS( actor.GetProperty<unsigned int>(index), constrainedValue, TEST_LOCATION );
1619 // Take the actor off-stage (2nd-time)
1620 Stage::GetCurrent().Remove(actor);
1621 application.SendNotification();
1622 application.Render(0);
1623 DALI_TEST_EQUALS( actor.GetProperty<unsigned int>(index), constrainedValue, TEST_LOCATION );
1625 // Remove the constraint, and set back to startValue
1626 actor.RemoveConstraints();
1627 actor.SetProperty( index, startValue );
1628 application.SendNotification();
1629 application.Render(0);
1630 DALI_TEST_EQUALS( actor.GetProperty<unsigned int>(index), startValue, TEST_LOCATION );
1632 // Add actor to stage (3rd time)
1633 Stage::GetCurrent().Add(actor);
1634 application.SendNotification();
1635 application.Render(0);
1637 // Constraint should be gone
1638 DALI_TEST_EQUALS( actor.GetProperty<unsigned int>(index), startValue, TEST_LOCATION );
1640 // Check that nothing has changed after a couple of buffer swaps
1641 application.Render(0);
1642 DALI_TEST_EQUALS( actor.GetProperty<unsigned int>(index), startValue, TEST_LOCATION );
1643 application.Render(0);
1644 DALI_TEST_EQUALS( actor.GetProperty<unsigned int>(index), startValue, TEST_LOCATION );
1649 int UtcDaliConstraintNewOffStageVector2(void)
1651 TestApplication application;
1653 Actor actor = Actor::New();
1655 // Register a Vector2 property
1656 Vector2 startValue(1.0f, 1.0f);
1657 Property::Index index = actor.RegisterProperty( "test-property", startValue );
1658 DALI_TEST_CHECK( actor.GetProperty<Vector2>(index) == startValue );
1660 // Apply constraint to off-stage Actor
1661 Vector2 constrainedValue( 2.0f, 2.0f );
1662 Constraint constraint = Constraint::New<Vector2>( index, TestConstraintVector2( constrainedValue ) );
1663 actor.ApplyConstraint( constraint );
1665 application.SendNotification();
1666 application.Render(0);
1667 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), startValue, TEST_LOCATION );
1669 // Add actor to stage
1670 Stage::GetCurrent().Add(actor);
1671 application.SendNotification();
1672 application.Render(0);
1674 // Constraint should be fully applied
1675 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), constrainedValue, TEST_LOCATION );
1677 // Check that nothing has changed after a couple of buffer swaps
1678 application.Render(0);
1679 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), constrainedValue, TEST_LOCATION );
1680 application.Render(0);
1681 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), constrainedValue, TEST_LOCATION );
1683 // Take the actor off-stage
1684 Stage::GetCurrent().Remove(actor);
1685 application.SendNotification();
1686 application.Render(0);
1687 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), constrainedValue, TEST_LOCATION );
1689 // Set back to startValue; the constraint will not prevent this
1690 actor.SetProperty( index, startValue );
1691 application.SendNotification();
1692 application.Render(0);
1693 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), startValue, TEST_LOCATION );
1695 // Add actor to stage (2nd time)
1696 Stage::GetCurrent().Add(actor);
1697 application.SendNotification();
1698 application.Render(0);
1700 // Constraint should be fully applied (2nd time)
1701 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), constrainedValue, TEST_LOCATION );
1703 // Check that nothing has changed after a couple of buffer swaps
1704 application.Render(0);
1705 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), constrainedValue, TEST_LOCATION );
1706 application.Render(0);
1707 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), constrainedValue, TEST_LOCATION );
1709 // Take the actor off-stage (2nd-time)
1710 Stage::GetCurrent().Remove(actor);
1711 application.SendNotification();
1712 application.Render(0);
1713 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), constrainedValue, TEST_LOCATION );
1715 // Remove the constraint, and set back to startValue
1716 actor.RemoveConstraints();
1717 actor.SetProperty( index, startValue );
1718 application.SendNotification();
1719 application.Render(0);
1720 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), startValue, TEST_LOCATION );
1722 // Add actor to stage (3rd time)
1723 Stage::GetCurrent().Add(actor);
1724 application.SendNotification();
1725 application.Render(0);
1727 // Constraint should be gone
1728 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), startValue, TEST_LOCATION );
1730 // Check that nothing has changed after a couple of buffer swaps
1731 application.Render(0);
1732 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), startValue, TEST_LOCATION );
1733 application.Render(0);
1734 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), startValue, TEST_LOCATION );
1738 int UtcDaliConstraintNewOffStageVector3(void)
1740 TestApplication application;
1741 Vector3 startValue(1.0f, 1.0f, 1.0f);
1742 Vector3 constrainedValue = Vector3( 2.0f, 3.0f, 4.0f );
1744 Actor actor = Actor::New();
1745 // Register a Vector3 property
1747 Property::Index index = actor.RegisterProperty( "test-property", startValue );
1748 DALI_TEST_CHECK( actor.GetProperty<Vector3>(index) == startValue );
1750 // Apply constraint to off-stage Actor
1751 Constraint constraint = Constraint::New<Vector3>( index, TestConstraintVector3( constrainedValue ) );
1752 actor.ApplyConstraint( constraint );
1754 application.SendNotification();
1755 application.Render(0);
1756 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), startValue, TEST_LOCATION );
1758 // Add actor to stage
1759 Stage::GetCurrent().Add(actor);
1760 application.SendNotification();
1761 application.Render();
1763 // Constraint should be fully applied
1764 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), constrainedValue, TEST_LOCATION );
1766 // Check that nothing has changed after a couple of buffer swaps
1767 application.Render();
1768 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), constrainedValue, TEST_LOCATION );
1769 application.Render();
1770 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), constrainedValue, TEST_LOCATION );
1772 // Take the actor off-stage
1773 Stage::GetCurrent().Remove(actor);
1774 application.SendNotification();
1775 application.Render();
1776 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), constrainedValue, TEST_LOCATION );
1778 // Set back to startValue; the constraint will not prevent this
1779 Vector3 intermediateValue(5.0f, 6.0f, 7.0f);
1780 actor.SetProperty( index, intermediateValue );
1781 application.SendNotification();
1782 application.Render();
1783 application.Render(); // ensure both buffers are set to intermediateValue
1784 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), intermediateValue, TEST_LOCATION );
1786 // Add actor to stage (2nd time)
1787 Stage::GetCurrent().Add(actor);
1788 application.SendNotification();
1789 application.Render();
1791 // Constraint should be fully applied (2nd time)
1792 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), constrainedValue, TEST_LOCATION );
1794 // Check that nothing has changed after a couple of buffer swaps
1795 application.Render();
1796 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), constrainedValue, TEST_LOCATION );
1797 application.Render();
1798 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), constrainedValue, TEST_LOCATION );
1800 // Take the actor off-stage (2nd-time)
1801 Stage::GetCurrent().Remove(actor);
1802 application.SendNotification();
1803 application.Render();
1804 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), constrainedValue, TEST_LOCATION );
1806 // Remove the constraint, and set back to startValue
1807 actor.RemoveConstraints();
1808 actor.SetProperty( index, startValue );
1809 application.SendNotification();
1810 application.Render();
1811 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), startValue, TEST_LOCATION );
1813 // Add actor to stage (3rd time)
1814 Stage::GetCurrent().Add(actor);
1815 application.SendNotification();
1816 application.Render();
1818 // Constraint should be gone
1819 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), startValue, TEST_LOCATION );
1821 // Check that nothing has changed after a couple of buffer swaps
1822 application.Render();
1823 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), startValue, TEST_LOCATION );
1824 application.Render();
1825 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), startValue, TEST_LOCATION );
1829 int UtcDaliConstraintNewOffStageVector4(void)
1831 TestApplication application;
1833 Actor actor = Actor::New();
1835 // Register a Vector4 property
1836 Vector4 startValue(1.0f, 1.0f, 1.0f, 1.0f);
1837 Property::Index index = actor.RegisterProperty( "test-property", startValue );
1838 DALI_TEST_CHECK( actor.GetProperty<Vector4>(index) == startValue );
1840 // Apply constraint to off-stage Actor
1841 Vector4 constrainedValue( 2.0f, 2.0f, 2.0f, 2.0f );
1842 Constraint constraint = Constraint::New<Vector4>( index, TestConstraintVector4( constrainedValue ) );
1843 actor.ApplyConstraint( constraint );
1845 application.SendNotification();
1846 application.Render(0);
1847 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), startValue, TEST_LOCATION );
1849 // Add actor to stage
1850 Stage::GetCurrent().Add(actor);
1851 application.SendNotification();
1852 application.Render(0);
1854 // Constraint should be fully applied
1855 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), constrainedValue, TEST_LOCATION );
1857 // Check that nothing has changed after a couple of buffer swaps
1858 application.Render(0);
1859 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), constrainedValue, TEST_LOCATION );
1860 application.Render(0);
1861 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), constrainedValue, TEST_LOCATION );
1863 // Take the actor off-stage
1864 Stage::GetCurrent().Remove(actor);
1865 application.SendNotification();
1866 application.Render(0);
1867 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), constrainedValue, TEST_LOCATION );
1869 // Set back to startValue; the constraint will not prevent this
1870 actor.SetProperty( index, startValue );
1871 application.SendNotification();
1872 application.Render(0);
1873 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), startValue, TEST_LOCATION );
1875 // Add actor to stage (2nd time)
1876 Stage::GetCurrent().Add(actor);
1877 application.SendNotification();
1878 application.Render(0);
1880 // Constraint should be fully applied (2nd time)
1881 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), constrainedValue, TEST_LOCATION );
1883 // Check that nothing has changed after a couple of buffer swaps
1884 application.Render(0);
1885 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), constrainedValue, TEST_LOCATION );
1886 application.Render(0);
1887 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), constrainedValue, TEST_LOCATION );
1889 // Take the actor off-stage (2nd-time)
1890 Stage::GetCurrent().Remove(actor);
1891 application.SendNotification();
1892 application.Render(0);
1893 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), constrainedValue, TEST_LOCATION );
1895 // Remove the constraint, and set back to startValue
1896 actor.RemoveConstraints();
1897 actor.SetProperty( index, startValue );
1898 application.SendNotification();
1899 application.Render(0);
1900 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), startValue, TEST_LOCATION );
1902 // Add actor to stage (3rd time)
1903 Stage::GetCurrent().Add(actor);
1904 application.SendNotification();
1905 application.Render(0);
1907 // Constraint should be gone
1908 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), startValue, TEST_LOCATION );
1910 // Check that nothing has changed after a couple of buffer swaps
1911 application.Render(0);
1912 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), startValue, TEST_LOCATION );
1913 application.Render(0);
1914 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), startValue, TEST_LOCATION );
1918 int UtcDaliConstraintNewOffStageQuaternion(void)
1920 TestApplication application;
1922 Actor actor = Actor::New();
1924 // Register a Quaternion property
1925 Quaternion startValue( 0.0f, Vector3::YAXIS );
1926 Property::Index index = actor.RegisterProperty( "test-property", startValue );
1927 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), startValue, ROTATION_EPSILON, TEST_LOCATION );
1929 // Apply constraint to off-stage Actor
1930 Quaternion constrainedRotation( M_PI*0.25f, Vector3::YAXIS );
1931 Constraint constraint = Constraint::New<Quaternion>( index, TestConstraintRotation( constrainedRotation ) );
1932 actor.ApplyConstraint( constraint );
1934 application.SendNotification();
1935 application.Render(0);
1936 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), startValue, ROTATION_EPSILON, TEST_LOCATION );
1938 // Add actor to stage
1939 Stage::GetCurrent().Add(actor);
1940 application.SendNotification();
1941 application.Render(0);
1943 // Constraint should be fully applied
1944 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), constrainedRotation, ROTATION_EPSILON, TEST_LOCATION );
1946 // Check that nothing has changed after a couple of buffer swaps
1947 application.Render(0);
1948 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), constrainedRotation, ROTATION_EPSILON, TEST_LOCATION );
1949 application.Render(0);
1950 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), constrainedRotation, ROTATION_EPSILON, TEST_LOCATION );
1952 // Take the actor off-stage
1953 Stage::GetCurrent().Remove(actor);
1954 application.SendNotification();
1955 application.Render(0);
1956 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), constrainedRotation, ROTATION_EPSILON, TEST_LOCATION );
1958 // Set back to startValue; the constraint will not prevent this
1959 actor.SetProperty( index, startValue );
1960 application.SendNotification();
1961 application.Render(0);
1962 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), startValue, ROTATION_EPSILON, TEST_LOCATION );
1964 // Add actor to stage (2nd time)
1965 Stage::GetCurrent().Add(actor);
1966 application.SendNotification();
1967 application.Render(0);
1969 // Constraint should be fully applied (2nd time)
1970 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), constrainedRotation, ROTATION_EPSILON, TEST_LOCATION );
1972 // Check that nothing has changed after a couple of buffer swaps
1973 application.Render(0);
1974 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), constrainedRotation, ROTATION_EPSILON, TEST_LOCATION );
1975 application.Render(0);
1976 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), constrainedRotation, ROTATION_EPSILON, TEST_LOCATION );
1978 // Take the actor off-stage (2nd-time)
1979 Stage::GetCurrent().Remove(actor);
1980 application.SendNotification();
1981 application.Render(0);
1982 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), constrainedRotation, ROTATION_EPSILON, TEST_LOCATION );
1984 // Remove the constraint, and set back to startValue
1985 actor.RemoveConstraints();
1986 actor.SetProperty( index, startValue );
1987 application.SendNotification();
1988 application.Render(0);
1989 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), startValue, ROTATION_EPSILON, TEST_LOCATION );
1991 // Add actor to stage (3rd time)
1992 Stage::GetCurrent().Add(actor);
1993 application.SendNotification();
1994 application.Render(0);
1996 // Constraint should be gone
1997 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), startValue, ROTATION_EPSILON, TEST_LOCATION );
1999 // Check that nothing has changed after a couple of buffer swaps
2000 application.Render(0);
2001 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), startValue, ROTATION_EPSILON, TEST_LOCATION );
2002 application.Render(0);
2003 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), startValue, ROTATION_EPSILON, TEST_LOCATION );
2007 int UtcDaliConstraintNewLocalInput(void)
2009 TestApplication application;
2011 Actor actor = Actor::New();
2012 Stage::GetCurrent().Add(actor);
2014 Vector3 startValue( 0.0f, 0.0f, 0.0f );
2015 float distanceWhenFullyTransparent( 100.0f );
2018 * Test that the Constraint is correctly applied on a clean Node
2020 application.SendNotification();
2021 application.Render(0);
2022 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::Property::POSITION ), startValue, TEST_LOCATION );
2023 application.Render(0);
2024 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::Property::POSITION ), startValue, TEST_LOCATION );
2025 application.Render(0);
2026 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::Property::POSITION ), startValue, TEST_LOCATION );
2028 // Apply constraint with a local input property
2030 Constraint constraint = Constraint::New<Vector3>( Actor::Property::POSITION,
2031 LocalSource( Actor::Property::COLOR ),
2032 MoveAwayWithFadeConstraint(distanceWhenFullyTransparent) );
2034 actor.ApplyConstraint( constraint );
2035 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::Property::POSITION ), startValue, TEST_LOCATION );
2037 application.SendNotification();
2038 application.Render(0);
2040 // Gradually set the color to fully-transparent; the actor should move back
2042 for ( float progress = 0.0f; progress < 1.1f; progress += 0.1f )
2044 actor.SetOpacity( 1.0f - progress );
2046 application.SendNotification();
2047 application.Render(0);
2048 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::Property::POSITION ), ( startValue - Vector3(0.0f, 0.0f, progress*distanceWhenFullyTransparent) ), POSITION_EPSILON, TEST_LOCATION );
2050 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::Property::POSITION ), ( startValue - Vector3(0.0f, 0.0f, distanceWhenFullyTransparent) ), POSITION_EPSILON, TEST_LOCATION );
2054 int UtcDaliConstraintNewParentInput(void)
2056 TestApplication application;
2058 Actor parent = Actor::New();
2059 Vector3 parentStartSize( 100.0f, 100.0f, 0.0f );
2060 parent.SetSize( parentStartSize );
2061 Stage::GetCurrent().Add( parent );
2063 Actor actor = Actor::New();
2064 parent.Add( actor );
2066 Vector3 startValue( 0.0f, 0.0f, 0.0f );
2069 * Test that the Constraint is correctly applied on a clean Node
2071 application.SendNotification();
2072 application.Render(0);
2073 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::Property::POSITION ), startValue, TEST_LOCATION );
2074 application.Render(0);
2075 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::Property::POSITION ), startValue, TEST_LOCATION );
2076 application.Render(0);
2077 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::Property::POSITION ), startValue, TEST_LOCATION );
2079 // Apply constraint with a parent input property
2081 Constraint constraint = Constraint::New<Vector3>( Actor::Property::POSITION,
2082 ParentSource( Actor::Property::SIZE ),
2083 TestBottomRightAlignConstraint() );
2085 actor.ApplyConstraint( constraint );
2086 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::Property::POSITION ), startValue, TEST_LOCATION );
2088 application.SendNotification();
2089 application.Render(0);
2091 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::Property::POSITION ), parentStartSize, TEST_LOCATION );
2092 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::Property::POSITION ), parent.GetCurrentSize(), TEST_LOCATION );
2094 // Gradually shrink the parent; the actor should move inwards
2096 for ( float progress = 0.0f; progress < 1.1f; progress += 0.1f )
2098 Vector3 size( parentStartSize * std::max(0.0f, 1.0f - progress) );
2099 parent.SetSize( size );
2101 application.SendNotification();
2102 application.Render(0);
2104 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::Property::POSITION ), size, POSITION_EPSILON, TEST_LOCATION );
2105 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::Property::POSITION ), parent.GetCurrentSize(), POSITION_EPSILON, TEST_LOCATION );
2107 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::Property::POSITION ), Vector3::ZERO, POSITION_EPSILON, TEST_LOCATION );
2111 int UtcDaliConstraintNewInput1(void)
2113 TestApplication application;
2115 Actor parent = Actor::New();
2116 Vector3 parentStartSize( 100.0f, 100.0f, 0.0f );
2117 parent.SetSize( parentStartSize );
2118 Stage::GetCurrent().Add( parent );
2120 Actor actor = Actor::New();
2121 parent.Add( actor );
2123 Actor sibling1 = Actor::New();
2124 sibling1.SetPosition( Vector3(1.0f, 2.0f, 3.0f) );
2125 parent.Add( sibling1 );
2127 Vector3 startValue( 0.0f, 0.0f, 0.0f );
2130 * Test that the Constraint is correctly applied on a clean Node
2132 application.SendNotification();
2133 application.Render(0);
2134 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::Property::POSITION ), startValue, TEST_LOCATION );
2135 application.Render(0);
2136 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::Property::POSITION ), startValue, TEST_LOCATION );
2137 application.Render(0);
2138 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::Property::POSITION ), startValue, TEST_LOCATION );
2140 // Apply constraint with a parent input property
2142 Constraint constraint = Constraint::New<Vector3>( Actor::Property::POSITION,
2143 Source( sibling1, Actor::Property::POSITION ),
2144 MeanPositionConstraint1() );
2146 actor.ApplyConstraint( constraint );
2147 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::Property::POSITION ), startValue, TEST_LOCATION );
2149 application.SendNotification();
2150 application.Render(0);
2151 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::Property::POSITION ), sibling1.GetCurrentPosition(), TEST_LOCATION );
2153 // Check that nothing has changed after a couple of buffer swaps
2154 application.Render(0);
2155 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::Property::POSITION ), sibling1.GetCurrentPosition(), TEST_LOCATION );
2156 application.Render(0);
2157 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::Property::POSITION ), sibling1.GetCurrentPosition(), TEST_LOCATION );
2161 int UtcDaliConstraintNewInput2(void)
2163 TestApplication application;
2165 Actor parent = Actor::New();
2166 Vector3 parentStartSize( 100.0f, 100.0f, 0.0f );
2167 parent.SetSize( parentStartSize );
2168 Stage::GetCurrent().Add( parent );
2170 Actor actor = Actor::New();
2171 parent.Add( actor );
2173 Actor sibling1 = Actor::New();
2174 sibling1.SetPosition( Vector3(1.0f, 2.0f, 3.0f) );
2175 parent.Add( sibling1 );
2177 Actor sibling2 = Actor::New();
2178 sibling2.SetPosition( Vector3(300.0f, 300.0f, 300.0f) );
2179 parent.Add( sibling2 );
2181 application.SendNotification();
2182 application.Render(0);
2184 Vector3 startValue( 0.0f, 0.0f, 0.0f );
2185 Vector3 meanValue = sibling1.GetCurrentPosition() +
2186 sibling2.GetCurrentPosition();
2187 meanValue *= (1.0f / 2.0f); // divide by number of siblings
2190 * Test that the Constraint is correctly applied on a clean Node
2192 application.SendNotification();
2193 application.Render(0);
2194 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::Property::POSITION ), startValue, TEST_LOCATION );
2195 application.Render(0);
2196 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::Property::POSITION ), startValue, TEST_LOCATION );
2197 application.Render(0);
2198 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::Property::POSITION ), startValue, TEST_LOCATION );
2200 // Apply constraint with a parent input property
2202 Constraint constraint = Constraint::New<Vector3>( Actor::Property::POSITION,
2203 Source( sibling1, Actor::Property::POSITION ),
2204 Source( sibling2, Actor::Property::POSITION ),
2205 MeanPositionConstraint2() );
2207 actor.ApplyConstraint( constraint );
2208 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::Property::POSITION ), startValue, TEST_LOCATION );
2210 application.SendNotification();
2211 application.Render(0);
2212 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::Property::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION );
2214 // Check that nothing has changed after a couple of buffer swaps
2215 application.Render(0);
2216 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::Property::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION );
2217 application.Render(0);
2218 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::Property::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION );
2222 int UtcDaliConstraintNewInput3(void)
2224 TestApplication application;
2226 Actor parent = Actor::New();
2227 Vector3 parentStartSize( 100.0f, 100.0f, 0.0f );
2228 parent.SetSize( parentStartSize );
2229 Stage::GetCurrent().Add( parent );
2231 Actor actor = Actor::New();
2232 parent.Add( actor );
2234 Actor sibling1 = Actor::New();
2235 sibling1.SetPosition( Vector3(1.0f, 2.0f, 3.0f) );
2236 parent.Add( sibling1 );
2238 Actor sibling2 = Actor::New();
2239 sibling2.SetPosition( Vector3(300.0f, 300.0f, 300.0f) );
2240 parent.Add( sibling2 );
2242 Actor sibling3 = Actor::New();
2243 sibling3.SetPosition( Vector3(-100.0f, -10.0f, -1.0f) );
2244 parent.Add( sibling3 );
2246 application.SendNotification();
2247 application.Render(0);
2249 Vector3 startValue( 0.0f, 0.0f, 0.0f );
2250 Vector3 meanValue = sibling1.GetCurrentPosition() +
2251 sibling2.GetCurrentPosition() +
2252 sibling3.GetCurrentPosition();
2253 meanValue *= (1.0f / 3.0f); // divide by number of siblings
2256 * Test that the Constraint is correctly applied on a clean Node
2258 application.SendNotification();
2259 application.Render(0);
2260 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::Property::POSITION ), startValue, TEST_LOCATION );
2261 application.Render(0);
2262 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::Property::POSITION ), startValue, TEST_LOCATION );
2263 application.Render(0);
2264 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::Property::POSITION ), startValue, TEST_LOCATION );
2266 // Apply constraint with a parent input property
2268 Constraint constraint = Constraint::New<Vector3>( Actor::Property::POSITION,
2269 Source( sibling1, Actor::Property::POSITION ),
2270 Source( sibling2, Actor::Property::POSITION ),
2271 Source( sibling3, Actor::Property::POSITION ),
2272 MeanPositionConstraint3() );
2274 actor.ApplyConstraint( constraint );
2275 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::Property::POSITION ), startValue, TEST_LOCATION );
2277 application.SendNotification();
2278 application.Render(0);
2279 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::Property::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION );
2281 // Check that nothing has changed after a couple of buffer swaps
2282 application.Render(0);
2283 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::Property::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION );
2284 application.Render(0);
2285 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::Property::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION );
2289 int UtcDaliConstraintNewInput4(void)
2291 TestApplication application;
2293 Actor parent = Actor::New();
2294 Vector3 parentStartSize( 100.0f, 100.0f, 0.0f );
2295 parent.SetSize( parentStartSize );
2296 parent.SetPosition( 10.0f, 10.0f, 10.0f );
2297 Stage::GetCurrent().Add( parent );
2299 Actor actor = Actor::New();
2300 parent.Add( actor );
2302 Actor sibling1 = Actor::New();
2303 sibling1.SetPosition( Vector3(1.0f, 2.0f, 3.0f) );
2304 parent.Add( sibling1 );
2306 Actor sibling2 = Actor::New();
2307 sibling2.SetPosition( Vector3(300.0f, 300.0f, 300.0f) );
2308 parent.Add( sibling2 );
2310 Actor sibling3 = Actor::New();
2311 sibling3.SetPosition( Vector3(-100.0f, -10.0f, -1.0f) );
2312 parent.Add( sibling3 );
2314 application.SendNotification();
2315 application.Render(0);
2317 Vector3 startValue( 0.0f, 0.0f, 0.0f );
2318 Vector3 meanValue = parent.GetCurrentPosition() +
2319 sibling1.GetCurrentPosition() +
2320 sibling2.GetCurrentPosition() +
2321 sibling3.GetCurrentPosition();
2322 meanValue *= (1.0f / 4.0f); // divide by number of positions
2325 * Test that the Constraint is correctly applied on a clean Node
2327 application.SendNotification();
2328 application.Render(0);
2329 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::Property::POSITION ), startValue, TEST_LOCATION );
2330 application.Render(0);
2331 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::Property::POSITION ), startValue, TEST_LOCATION );
2332 application.Render(0);
2333 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::Property::POSITION ), startValue, TEST_LOCATION );
2335 // Apply constraint with a parent input property
2337 Constraint constraint = Constraint::New<Vector3>( Actor::Property::POSITION,
2338 Source( sibling1, Actor::Property::POSITION ),
2339 Source( sibling2, Actor::Property::POSITION ),
2340 ParentSource( Actor::Property::POSITION ),
2341 Source( sibling3, Actor::Property::POSITION ),
2342 MeanPositionConstraint4() );
2344 actor.ApplyConstraint( constraint );
2345 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::Property::POSITION ), startValue, TEST_LOCATION );
2347 application.SendNotification();
2348 application.Render(0);
2349 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::Property::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION );
2351 // Check that nothing has changed after a couple of buffer swaps
2352 application.Render(0);
2353 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::Property::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION );
2354 application.Render(0);
2355 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::Property::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION );
2359 int UtcDaliConstraintNewInput5(void)
2361 TestApplication application;
2363 Actor parent = Actor::New();
2364 Vector3 parentStartSize( 100.0f, 100.0f, 0.0f );
2365 parent.SetSize( parentStartSize );
2366 parent.SetPosition( 10.0f, 10.0f, 10.0f );
2367 Stage::GetCurrent().Add( parent );
2369 Actor actor = Actor::New();
2370 parent.Add( actor );
2372 Actor sibling1 = Actor::New();
2373 sibling1.SetPosition( Vector3(1.0f, 2.0f, 3.0f) );
2374 parent.Add( sibling1 );
2376 Actor sibling2 = Actor::New();
2377 sibling2.SetPosition( Vector3(300.0f, 300.0f, 300.0f) );
2378 parent.Add( sibling2 );
2380 Actor sibling3 = Actor::New();
2381 sibling3.SetPosition( Vector3(-100.0f, -10.0f, -1.0f) );
2382 parent.Add( sibling3 );
2384 Actor sibling4 = Actor::New();
2385 sibling4.SetPosition( Vector3(-1.0f, 1.0f, 2.0f) );
2386 parent.Add( sibling4 );
2388 application.SendNotification();
2389 application.Render(0);
2391 Vector3 startValue( 0.0f, 0.0f, 0.0f );
2392 Vector3 meanValue = parent.GetCurrentPosition() +
2393 sibling1.GetCurrentPosition() +
2394 sibling2.GetCurrentPosition() +
2395 sibling3.GetCurrentPosition() +
2396 sibling4.GetCurrentPosition();
2397 meanValue *= (1.0f / 5.0f); // divide by number of positions
2400 * Test that the Constraint is correctly applied on a clean Node
2402 application.SendNotification();
2403 application.Render(0);
2404 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::Property::POSITION ), startValue, TEST_LOCATION );
2405 application.Render(0);
2406 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::Property::POSITION ), startValue, TEST_LOCATION );
2407 application.Render(0);
2408 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::Property::POSITION ), startValue, TEST_LOCATION );
2410 // Apply constraint with a parent input property
2412 Constraint constraint = Constraint::New<Vector3>( Actor::Property::POSITION,
2413 Source( sibling1, Actor::Property::POSITION ),
2414 Source( sibling2, Actor::Property::POSITION ),
2415 ParentSource( Actor::Property::POSITION ),
2416 Source( sibling3, Actor::Property::POSITION ),
2417 Source( sibling4, Actor::Property::POSITION ),
2418 MeanPositionConstraint5() );
2420 actor.ApplyConstraint( constraint );
2421 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::Property::POSITION ), startValue, TEST_LOCATION );
2423 application.SendNotification();
2424 application.Render(0);
2425 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::Property::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION );
2427 // Check that nothing has changed after a couple of buffer swaps
2428 application.Render(0);
2429 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::Property::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION );
2430 application.Render(0);
2431 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::Property::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION );
2435 int UtcDaliConstraintNewInput6(void)
2437 TestApplication application;
2439 Actor parent = Actor::New();
2440 Vector3 parentStartSize( 100.0f, 100.0f, 0.0f );
2441 parent.SetSize( parentStartSize );
2442 parent.SetPosition( 10.0f, 10.0f, 10.0f );
2443 Stage::GetCurrent().Add( parent );
2445 Actor actor = Actor::New();
2446 parent.Add( actor );
2448 Actor child = Actor::New();
2449 child.SetPosition( Vector3(7.0f, 7.0f, 7.0f) );
2452 Actor sibling1 = Actor::New();
2453 sibling1.SetPosition( Vector3(1.0f, 2.0f, 3.0f) );
2454 parent.Add( sibling1 );
2456 Actor sibling2 = Actor::New();
2457 sibling2.SetPosition( Vector3(300.0f, 300.0f, 300.0f) );
2458 parent.Add( sibling2 );
2460 Actor sibling3 = Actor::New();
2461 sibling3.SetPosition( Vector3(-100.0f, -10.0f, -1.0f) );
2462 parent.Add( sibling3 );
2464 Actor sibling4 = Actor::New();
2465 sibling4.SetPosition( Vector3(-1.0f, 1.0f, 2.0f) );
2466 parent.Add( sibling4 );
2468 application.SendNotification();
2469 application.Render(0);
2471 Vector3 startValue( 0.0f, 0.0f, 0.0f );
2472 Vector3 meanValue = parent.GetCurrentPosition() +
2473 child.GetCurrentPosition() +
2474 sibling1.GetCurrentPosition() +
2475 sibling2.GetCurrentPosition() +
2476 sibling3.GetCurrentPosition() +
2477 sibling4.GetCurrentPosition();
2478 meanValue *= (1.0f / 6.0f); // divide by number of positions
2481 * Test that the Constraint is correctly applied on a clean Node
2483 application.SendNotification();
2484 application.Render(0);
2485 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::Property::POSITION ), startValue, TEST_LOCATION );
2486 application.Render(0);
2487 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::Property::POSITION ), startValue, TEST_LOCATION );
2488 application.Render(0);
2489 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::Property::POSITION ), startValue, TEST_LOCATION );
2491 // Apply constraint with a parent input property
2493 Constraint constraint = Constraint::New<Vector3>( Actor::Property::POSITION,
2494 Source( child, Actor::Property::POSITION ),
2495 Source( sibling1, Actor::Property::POSITION ),
2496 Source( sibling2, Actor::Property::POSITION ),
2497 ParentSource( Actor::Property::POSITION ),
2498 Source( sibling3, Actor::Property::POSITION ),
2499 Source( sibling4, Actor::Property::POSITION ),
2500 MeanPositionConstraint6() );
2502 actor.ApplyConstraint( constraint );
2503 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::Property::POSITION ), startValue, TEST_LOCATION );
2505 application.SendNotification();
2506 application.Render(0);
2507 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::Property::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION );
2509 // Check that nothing has changed after a couple of buffer swaps
2510 application.Render(0);
2511 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::Property::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION );
2512 application.Render(0);
2513 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::Property::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION );
2517 int UtcDaliConstraintDownCast(void)
2519 TestApplication application;
2520 tet_infoline("Testing Dali::Constraint::DownCast()");
2522 Actor actor = Actor::New();
2524 // Register a boolean property
2525 bool startValue(false);
2526 Property::Index index = actor.RegisterProperty( "test-property", startValue );
2527 Constraint constraint = Constraint::New<bool>( index, TestAlwaysTrueConstraint() );
2529 BaseHandle object(constraint);
2531 Constraint constraint2 = Constraint::DownCast(object);
2532 DALI_TEST_CHECK(constraint2);
2534 Constraint constraint3 = DownCast< Constraint >(object);
2535 DALI_TEST_CHECK(constraint3);
2537 BaseHandle unInitializedObject;
2538 Constraint constraint4 = Constraint::DownCast(unInitializedObject);
2539 DALI_TEST_CHECK(!constraint4);
2541 Constraint constraint5 = DownCast< Constraint >(unInitializedObject);
2542 DALI_TEST_CHECK(!constraint5);
2546 int UtcDaliConstraintSetApplyTime(void)
2548 TestApplication application;
2552 Vector4 targetColor(Color::BLACK);
2553 Constraint constraint = Constraint::New<Vector4>( Actor::Property::COLOR, TestColorConstraint(targetColor) );
2554 DALI_TEST_EQUALS(constraint.GetApplyTime(), TimePeriod(0.0f), TEST_LOCATION);
2556 float applySeconds(7.0f);
2557 constraint.SetApplyTime(applySeconds);
2558 DALI_TEST_EQUALS(constraint.GetApplyTime(), TimePeriod(applySeconds), TEST_LOCATION);
2560 // Apply to an actor
2562 Actor actor = Actor::New();
2563 Stage::GetCurrent().Add(actor);
2565 actor.ApplyConstraint( constraint );
2566 DALI_TEST_EQUALS( actor.GetCurrentColor(), Color::WHITE, TEST_LOCATION );
2568 application.SendNotification();
2569 application.Render(static_cast<unsigned int>(applySeconds*200.0f)/* 20% progress */);
2571 // Constraint shouldn't be fully applied yet
2572 Vector4 twentyPercentColor( Color::WHITE.x*0.8f, Color::WHITE.y*0.8f, Color::WHITE.z*0.8f, Color::WHITE.a );
2573 DALI_TEST_EQUALS( actor.GetCurrentColor(), twentyPercentColor, TEST_LOCATION );
2575 // Constraint shouldn't be fully applied yet
2576 application.Render(static_cast<unsigned int>(applySeconds*200.0f)/* 40% progress */);
2577 Vector4 fourtyPercentColor( Color::WHITE.x*0.6f, Color::WHITE.y*0.6f, Color::WHITE.z*0.6f, Color::WHITE.a );
2578 DALI_TEST_EQUALS( actor.GetCurrentColor(), fourtyPercentColor, TEST_LOCATION );
2580 // Constraint shouldn't be fully applied yet
2581 application.Render(static_cast<unsigned int>(applySeconds*200.0f)/* 60% progress */);
2582 Vector4 sixtyPercentColor( Color::WHITE.x*0.4f, Color::WHITE.y*0.4f, Color::WHITE.z*0.4f, Color::WHITE.a );
2583 DALI_TEST_EQUALS( actor.GetCurrentColor(), sixtyPercentColor, TEST_LOCATION );
2585 // Constraint shouldn't be fully applied yet
2586 application.Render(static_cast<unsigned int>(applySeconds*200.0f)/* 80% progress */);
2587 Vector4 eightyPercentColor( Color::WHITE.x*0.2f, Color::WHITE.y*0.2f, Color::WHITE.z*0.2f, Color::WHITE.a );
2588 DALI_TEST_EQUALS( actor.GetCurrentColor(), eightyPercentColor, TEST_LOCATION );
2590 // Constraint should be fully applied
2591 application.Render(static_cast<unsigned int>(applySeconds*200.0f)/* 100% progress */);
2592 DALI_TEST_EQUALS( actor.GetCurrentColor(), targetColor, TEST_LOCATION );
2594 // Constraint should still be fully applied
2595 application.Render(static_cast<unsigned int>(applySeconds*200.0f)/* Still 100% progress */);
2596 DALI_TEST_EQUALS( actor.GetCurrentColor(), targetColor, TEST_LOCATION );
2598 // Check that nothing has changed after a couple of buffer swaps
2599 application.Render(0);
2600 DALI_TEST_EQUALS( actor.GetCurrentColor(), targetColor, TEST_LOCATION );
2601 application.Render(0);
2602 DALI_TEST_EQUALS( actor.GetCurrentColor(), targetColor, TEST_LOCATION );
2606 int UtcDaliConstraintGetApplyTime(void)
2608 TestApplication application;
2610 Constraint constraint = Constraint::New<Vector4>( Actor::Property::COLOR, TestConstraint() );
2611 DALI_TEST_EQUALS(constraint.GetApplyTime(), TimePeriod(0.0f), TEST_LOCATION);
2613 float applySeconds(7.0f);
2614 constraint.SetApplyTime(applySeconds);
2615 DALI_TEST_EQUALS(constraint.GetApplyTime(), TimePeriod(applySeconds), TEST_LOCATION);
2617 constraint.SetApplyTime(applySeconds - 3.0f);
2618 DALI_TEST_EQUALS(constraint.GetApplyTime(), TimePeriod(applySeconds - 3.0f), TEST_LOCATION);
2622 int UtcDaliConstraintSetAlphaFunction(void)
2624 TestApplication application;
2626 Vector3 startValue( Vector3::ZERO );
2627 Vector3 targetValue(100.0f, 100.0f, 100.0f);
2629 Constraint constraint = Constraint::New<Vector3>( Actor::Property::POSITION,
2630 TestConstraintVector3( targetValue ) );
2632 // Test the alpha-function itself
2634 AlphaFunction func = constraint.GetAlphaFunction();
2635 DALI_TEST_EQUALS(func(0.1f), 0.1f, TEST_LOCATION); // Default is Linear
2637 // Test that the alpha-function is used correctly
2639 Actor actor = Actor::New();
2640 Stage::GetCurrent().Add(actor);
2642 application.SendNotification();
2643 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2644 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::Property::POSITION ), startValue, TEST_LOCATION );
2645 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2646 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::Property::POSITION ), startValue, TEST_LOCATION );
2647 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2648 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::Property::POSITION ), startValue, TEST_LOCATION );
2650 constraint.SetApplyTime( 10.0f );
2651 actor.ApplyConstraint( constraint );
2653 application.SendNotification();
2654 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2655 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::Property::POSITION ), (targetValue - startValue) * 0.1f, TEST_LOCATION );
2656 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2657 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::Property::POSITION ), (targetValue - startValue) * 0.2f, TEST_LOCATION );
2658 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2659 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::Property::POSITION ), (targetValue - startValue) * 0.3f, TEST_LOCATION );
2660 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2661 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::Property::POSITION ), (targetValue - startValue) * 0.4f, TEST_LOCATION );
2662 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2663 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::Property::POSITION ), (targetValue - startValue) * 0.5f, TEST_LOCATION );
2664 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2665 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::Property::POSITION ), (targetValue - startValue) * 0.6f, TEST_LOCATION );
2666 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2667 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::Property::POSITION ), (targetValue - startValue) * 0.7f, TEST_LOCATION );
2668 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2669 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::Property::POSITION ), (targetValue - startValue) * 0.8f, TEST_LOCATION );
2670 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2671 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::Property::POSITION ), (targetValue - startValue) * 0.9f, TEST_LOCATION );
2672 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2673 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::Property::POSITION ), (targetValue - startValue), TEST_LOCATION );
2675 // Check that the constrained value is stable
2676 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2677 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::Property::POSITION ), (targetValue - startValue), TEST_LOCATION );
2678 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2679 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::Property::POSITION ), (targetValue - startValue), TEST_LOCATION );
2681 // Remove the constraint
2683 actor.RemoveConstraints();
2684 actor.SetPosition( startValue );
2686 application.SendNotification();
2687 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2688 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::Property::POSITION ), startValue, TEST_LOCATION );
2689 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2690 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::Property::POSITION ), startValue, TEST_LOCATION );
2691 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2692 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::Property::POSITION ), startValue, TEST_LOCATION );
2694 // Change to non-linear alpha and retest
2696 constraint.SetAlphaFunction(AlphaFunctions::EaseIn);
2697 func = constraint.GetAlphaFunction();
2698 DALI_TEST_CHECK(func(0.1f) < 0.09f);
2700 actor.ApplyConstraint( constraint );
2702 application.SendNotification();
2703 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2705 DALI_TEST_CHECK( actor.GetProperty<Vector3>( Actor::Property::POSITION ).x > startValue.x );
2706 DALI_TEST_CHECK( actor.GetProperty<Vector3>( Actor::Property::POSITION ).y > startValue.y );
2707 DALI_TEST_CHECK( actor.GetProperty<Vector3>( Actor::Property::POSITION ).z > startValue.z );
2709 Vector3 lessThanTenPercentProgress( (targetValue - startValue) * 0.09f );
2710 DALI_TEST_CHECK( actor.GetProperty<Vector3>( Actor::Property::POSITION ).x < lessThanTenPercentProgress.x );
2711 DALI_TEST_CHECK( actor.GetProperty<Vector3>( Actor::Property::POSITION ).y < lessThanTenPercentProgress.y );
2712 DALI_TEST_CHECK( actor.GetProperty<Vector3>( Actor::Property::POSITION ).z < lessThanTenPercentProgress.z );
2714 application.Render(static_cast<unsigned int>(9000.0f/*9 seconds*/));
2715 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::Property::POSITION ), (targetValue - startValue), TEST_LOCATION );
2717 // Check that the constrained value is stable
2718 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2719 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::Property::POSITION ), (targetValue - startValue), TEST_LOCATION );
2720 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2721 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::Property::POSITION ), (targetValue - startValue), TEST_LOCATION );
2725 int UtcDaliConstraintGetAlphaFunction(void)
2727 TestApplication application;
2729 Constraint constraint = Constraint::New<Vector4>( Actor::Property::COLOR, TestConstraint() );
2731 AlphaFunction func = constraint.GetAlphaFunction();
2732 DALI_TEST_EQUALS(func(0.5f), 0.5f, TEST_LOCATION); // Default is Linear
2736 int UtcDaliConstraintSetRemoveAction(void)
2738 TestApplication application;
2740 Vector3 sourcePosition(0.0f, 0.0f, 0.0f);
2741 Vector3 targetPosition(100.0f, 100.0f, 100.0f);
2743 // Build constraint, with "Discard" remove action
2745 Constraint constraint = Constraint::New<Vector3>( Actor::Property::POSITION, TestPositionConstraint(targetPosition) );
2746 DALI_TEST_EQUALS((unsigned int)constraint.GetRemoveAction(), (unsigned int)Constraint::Bake, TEST_LOCATION);
2748 constraint.SetRemoveAction(Constraint::Discard);
2749 DALI_TEST_EQUALS((unsigned int)constraint.GetRemoveAction(), (unsigned int)Constraint::Discard, TEST_LOCATION);
2751 // Apply to an actor
2753 Actor actor = Actor::New();
2754 Stage::GetCurrent().Add(actor);
2756 actor.ApplyConstraint( constraint );
2757 DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION );
2759 application.SendNotification();
2760 application.Render(100u/*0.1 seconds*/);
2762 // Constraint should be fully applied
2763 DALI_TEST_EQUALS( actor.GetCurrentPosition(), targetPosition, TEST_LOCATION );
2765 // Check that nothing has changed after a couple of buffer swaps
2766 application.Render(0);
2767 DALI_TEST_EQUALS( actor.GetCurrentPosition(), targetPosition, TEST_LOCATION );
2768 application.Render(0);
2769 DALI_TEST_EQUALS( actor.GetCurrentPosition(), targetPosition, TEST_LOCATION );
2771 // Remove from the actor
2772 actor.RemoveConstraints(); // should go back to source position
2774 application.SendNotification();
2775 application.Render(static_cast<unsigned int>(1000.0f));
2777 // Constraint should be fully removed
2778 DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION );
2780 // Constraint should still be fully removed
2781 application.Render(static_cast<unsigned int>(1000.0f)/* Still 100% removal progress */);
2782 DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION );
2784 // Check that nothing has changed after a couple of buffer swaps
2785 application.Render(0);
2786 DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION );
2787 application.Render(0);
2788 DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION );
2792 int UtcDaliConstraintGetRemoveAction(void)
2794 TestApplication application;
2796 Constraint constraint = Constraint::New<Vector4>( Actor::Property::COLOR, TestConstraint() );
2797 DALI_TEST_EQUALS((unsigned int)constraint.GetRemoveAction(), (unsigned int)Constraint::Bake, TEST_LOCATION);
2799 constraint.SetRemoveAction(Constraint::Discard);
2800 DALI_TEST_EQUALS((unsigned int)constraint.GetRemoveAction(), (unsigned int)Constraint::Discard, TEST_LOCATION);
2802 constraint.SetRemoveAction(Constraint::Bake);
2803 DALI_TEST_EQUALS((unsigned int)constraint.GetRemoveAction(), (unsigned int)Constraint::Bake, TEST_LOCATION);
2808 * Test a constraint with non-zero apply-time & zero (immediate) remove-time, where the constraint is removed during the apply-time
2810 int UtcDaliConstraintImmediateRemoveDuringApply(void)
2812 TestApplication application;
2814 Vector3 sourcePosition(0.0f, 0.0f, 0.0f);
2815 Vector3 targetPosition(100.0f, 100.0f, 100.0f);
2819 Constraint constraint = Constraint::New<Vector3>( Actor::Property::POSITION, TestPositionConstraint(targetPosition) );
2820 DALI_TEST_EQUALS((unsigned int)constraint.GetRemoveAction(), (unsigned int)Constraint::Bake, TEST_LOCATION);
2822 float applySeconds(4.0f);
2823 constraint.SetApplyTime(applySeconds);
2824 DALI_TEST_EQUALS(constraint.GetApplyTime(), TimePeriod(applySeconds), TEST_LOCATION);
2826 // Apply to an actor
2828 Actor actor = Actor::New();
2829 Stage::GetCurrent().Add(actor);
2831 actor.ApplyConstraint( constraint );
2832 DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION );
2834 application.SendNotification();
2835 application.Render(static_cast<unsigned int>(applySeconds*250.0f)/* 25% progress */);
2837 // Constraint shouldn't be fully applied yet
2838 Vector3 twentyFivePercent( targetPosition * 0.25f );
2839 DALI_TEST_EQUALS( actor.GetCurrentPosition(), twentyFivePercent, TEST_LOCATION );
2841 application.Render(static_cast<unsigned int>(applySeconds*250.0f)/* 50% progress */);
2843 // Constraint shouldn't be fully applied yet
2844 Vector3 fiftyPercent( targetPosition * 0.5f );
2845 DALI_TEST_EQUALS( actor.GetCurrentPosition(), fiftyPercent, TEST_LOCATION );
2847 // Remove from the actor
2849 actor.RemoveConstraints(); // should go back to source position
2850 application.SendNotification();
2852 // Constraint should be fully removed
2853 application.Render(static_cast<unsigned int>(200.0f /*0.2 seconds*/));
2854 DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION );
2856 // Constraint should still be fully applied
2857 application.Render(static_cast<unsigned int>(200.0f /*0.2 seconds*/));
2858 DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION );
2860 // Check that nothing has changed after a couple of buffer swaps
2861 application.Render(0);
2862 DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION );
2863 application.Render(0);
2864 DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION );
2868 int UtcDaliConstraintActorSize(void)
2870 TestApplication application;
2872 // Build constraint, to make child 20% of parent size
2874 Constraint constraint = Constraint::New<Vector3>( Actor::Property::SIZE,
2875 ParentSource( Actor::Property::SIZE ),
2876 TestRelativeConstraintVector3(0.2f) );
2877 // Apply to a child actor
2879 Actor parent = Actor::New();
2880 Stage::GetCurrent().Add(parent);
2882 Actor child = Actor::New();
2885 child.ApplyConstraint( constraint );
2886 DALI_TEST_EQUALS( child.GetCurrentSize(), Vector3::ZERO, TEST_LOCATION );
2888 // Animate the parent between two sizes
2890 Vector3 targetParentSize(100.0f, 100.0f, 100.0f);
2892 float durationSeconds(10.0f);
2893 Animation animation = Animation::New(durationSeconds);
2894 animation.AnimateTo( Property(parent, Actor::Property::SIZE), targetParentSize );
2897 application.SendNotification();
2899 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 25% progress */);
2900 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize*0.25f, TEST_LOCATION );
2901 DALI_TEST_EQUALS( child.GetCurrentSize(), targetParentSize*0.25f * 0.2f, TEST_LOCATION );
2903 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 50% progress */);
2904 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize*0.5f, TEST_LOCATION );
2905 DALI_TEST_EQUALS( child.GetCurrentSize(), targetParentSize*0.5f * 0.2f, TEST_LOCATION );
2907 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 75% progress */);
2908 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize*0.75f, TEST_LOCATION );
2909 DALI_TEST_EQUALS( child.GetCurrentSize(), targetParentSize*0.75f * 0.2f, TEST_LOCATION );
2911 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 100% progress */);
2912 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize, TEST_LOCATION );
2913 DALI_TEST_EQUALS( child.GetCurrentSize(), targetParentSize * 0.2f, TEST_LOCATION );
2915 // Check that nothing has changed after a couple of buffer swaps
2916 application.Render(0);
2917 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize, TEST_LOCATION );
2918 DALI_TEST_EQUALS( child.GetCurrentSize(), targetParentSize * 0.2f, TEST_LOCATION );
2919 application.Render(0);
2920 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize, TEST_LOCATION );
2921 DALI_TEST_EQUALS( child.GetCurrentSize(), targetParentSize * 0.2f, TEST_LOCATION );
2925 int UtcDaliConstraintActorSizeWidth(void)
2927 TestApplication application;
2929 // Build constraint, to make child 20% of parent width
2931 Constraint constraint = Constraint::New<float>( Actor::Property::SIZE_WIDTH,
2932 ParentSource( Actor::Property::SIZE_WIDTH ),
2933 TestRelativeConstraintFloat(0.2f) );
2934 // Apply to a child actor
2936 Actor parent = Actor::New();
2937 Stage::GetCurrent().Add(parent);
2939 Actor child = Actor::New();
2942 child.ApplyConstraint( constraint );
2943 DALI_TEST_EQUALS( child.GetCurrentSize(), Vector3::ZERO, TEST_LOCATION );
2945 // Animate the parent between two sizes
2947 Vector3 targetParentSize(80.0f, 90.0f, 100.0f);
2949 float durationSeconds(10.0f);
2950 Animation animation = Animation::New(durationSeconds);
2951 animation.AnimateTo( Property(parent, Actor::Property::SIZE), targetParentSize );
2954 application.SendNotification();
2956 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 25% progress */);
2957 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize*0.25f, TEST_LOCATION );
2958 DALI_TEST_EQUALS( child.GetCurrentSize().width, targetParentSize.width*0.25f * 0.2f, TEST_LOCATION );
2959 DALI_TEST_EQUALS( child.GetCurrentSize().height, 0.0f, TEST_LOCATION );
2960 DALI_TEST_EQUALS( child.GetCurrentSize().depth, 0.0f, TEST_LOCATION );
2962 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 50% progress */);
2963 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize*0.5f, TEST_LOCATION );
2964 DALI_TEST_EQUALS( child.GetCurrentSize().width, targetParentSize.width*0.5f * 0.2f, TEST_LOCATION );
2965 DALI_TEST_EQUALS( child.GetCurrentSize().height, 0.0f, TEST_LOCATION );
2966 DALI_TEST_EQUALS( child.GetCurrentSize().depth, 0.0f, TEST_LOCATION );
2968 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 75% progress */);
2969 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize*0.75f, TEST_LOCATION );
2970 DALI_TEST_EQUALS( child.GetCurrentSize().width, targetParentSize.width*0.75f * 0.2f, TEST_LOCATION );
2971 DALI_TEST_EQUALS( child.GetCurrentSize().height, 0.0f, TEST_LOCATION );
2972 DALI_TEST_EQUALS( child.GetCurrentSize().depth, 0.0f, TEST_LOCATION );
2974 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 100% progress */);
2975 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize, TEST_LOCATION );
2976 DALI_TEST_EQUALS( child.GetCurrentSize().width, targetParentSize.width * 0.2f, TEST_LOCATION );
2977 DALI_TEST_EQUALS( child.GetCurrentSize().height, 0.0f, TEST_LOCATION );
2978 DALI_TEST_EQUALS( child.GetCurrentSize().depth, 0.0f, TEST_LOCATION );
2980 // Check that nothing has changed after a couple of buffer swaps
2981 application.Render(0);
2982 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize, TEST_LOCATION );
2983 DALI_TEST_EQUALS( child.GetCurrentSize().width, targetParentSize.width * 0.2f, TEST_LOCATION );
2984 DALI_TEST_EQUALS( child.GetCurrentSize().height, 0.0f, TEST_LOCATION );
2985 DALI_TEST_EQUALS( child.GetCurrentSize().depth, 0.0f, TEST_LOCATION );
2987 application.Render(0);
2988 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize, TEST_LOCATION );
2989 DALI_TEST_EQUALS( child.GetCurrentSize().width, targetParentSize.width * 0.2f, TEST_LOCATION );
2990 DALI_TEST_EQUALS( child.GetCurrentSize().height, 0.0f, TEST_LOCATION );
2991 DALI_TEST_EQUALS( child.GetCurrentSize().depth, 0.0f, TEST_LOCATION );
2995 int UtcDaliConstraintActorSizeHeight(void)
2997 TestApplication application;
2999 // Build constraint, to make child 20% of parent height
3001 Constraint constraint = Constraint::New<float>( Actor::Property::SIZE_HEIGHT,
3002 ParentSource( Actor::Property::SIZE_HEIGHT ),
3003 TestRelativeConstraintFloat(0.2f) );
3004 // Apply to a child actor
3006 Actor parent = Actor::New();
3007 Stage::GetCurrent().Add(parent);
3009 Actor child = Actor::New();
3012 child.ApplyConstraint( constraint );
3013 DALI_TEST_EQUALS( child.GetCurrentSize(), Vector3::ZERO, TEST_LOCATION );
3015 // Animate the parent between two sizes
3017 Vector3 targetParentSize(80.0f, 90.0f, 100.0f);
3019 float durationSeconds(10.0f);
3020 Animation animation = Animation::New(durationSeconds);
3021 animation.AnimateTo( Property(parent, Actor::Property::SIZE), targetParentSize );
3024 application.SendNotification();
3026 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 25% progress */);
3027 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize*0.25f, TEST_LOCATION );
3028 DALI_TEST_EQUALS( child.GetCurrentSize().width, 0.0f, TEST_LOCATION );
3029 DALI_TEST_EQUALS( child.GetCurrentSize().height, targetParentSize.height*0.25f * 0.2f, TEST_LOCATION );
3030 DALI_TEST_EQUALS( child.GetCurrentSize().depth, 0.0f, TEST_LOCATION );
3032 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 50% progress */);
3033 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize*0.5f, TEST_LOCATION );
3034 DALI_TEST_EQUALS( child.GetCurrentSize().width, 0.0f, TEST_LOCATION );
3035 DALI_TEST_EQUALS( child.GetCurrentSize().height, targetParentSize.height*0.5f * 0.2f, TEST_LOCATION );
3036 DALI_TEST_EQUALS( child.GetCurrentSize().depth, 0.0f, TEST_LOCATION );
3038 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 75% progress */);
3039 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize*0.75f, TEST_LOCATION );
3040 DALI_TEST_EQUALS( child.GetCurrentSize().width, 0.0f, TEST_LOCATION );
3041 DALI_TEST_EQUALS( child.GetCurrentSize().height, targetParentSize.height*0.75f * 0.2f, TEST_LOCATION );
3042 DALI_TEST_EQUALS( child.GetCurrentSize().depth, 0.0f, TEST_LOCATION );
3044 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 100% progress */);
3045 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize, TEST_LOCATION );
3046 DALI_TEST_EQUALS( child.GetCurrentSize().width, 0.0f, TEST_LOCATION );
3047 DALI_TEST_EQUALS( child.GetCurrentSize().height, targetParentSize.height * 0.2f, TEST_LOCATION );
3048 DALI_TEST_EQUALS( child.GetCurrentSize().depth, 0.0f, TEST_LOCATION );
3050 // Check that nothing has changed after a couple of buffer swaps
3051 application.Render(0);
3052 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize, TEST_LOCATION );
3053 DALI_TEST_EQUALS( child.GetCurrentSize().width, 0.0f, TEST_LOCATION );
3054 DALI_TEST_EQUALS( child.GetCurrentSize().height, targetParentSize.height * 0.2f, TEST_LOCATION );
3055 DALI_TEST_EQUALS( child.GetCurrentSize().depth, 0.0f, TEST_LOCATION );
3057 application.Render(0);
3058 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize, TEST_LOCATION );
3059 DALI_TEST_EQUALS( child.GetCurrentSize().width, 0.0f, TEST_LOCATION );
3060 DALI_TEST_EQUALS( child.GetCurrentSize().height, targetParentSize.height * 0.2f, TEST_LOCATION );
3061 DALI_TEST_EQUALS( child.GetCurrentSize().depth, 0.0f, TEST_LOCATION );
3065 int UtcDaliConstraintActorSizeDepth(void)
3067 TestApplication application;
3069 // Build constraint, to make child 20% of parent height
3071 Constraint constraint = Constraint::New<float>( Actor::Property::SIZE_DEPTH,
3072 ParentSource( Actor::Property::SIZE_DEPTH ),
3073 TestRelativeConstraintFloat(0.2f) );
3074 // Apply to a child actor
3076 Actor parent = Actor::New();
3077 Stage::GetCurrent().Add(parent);
3079 Actor child = Actor::New();
3082 child.ApplyConstraint( constraint );
3083 DALI_TEST_EQUALS( child.GetCurrentSize(), Vector3::ZERO, TEST_LOCATION );
3085 // Animate the parent between two sizes
3087 Vector3 targetParentSize(80.0f, 90.0f, 100.0f);
3089 float durationSeconds(10.0f);
3090 Animation animation = Animation::New(durationSeconds);
3091 animation.AnimateTo( Property(parent, Actor::Property::SIZE), targetParentSize );
3094 application.SendNotification();
3096 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 25% progress */);
3097 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize*0.25f, TEST_LOCATION );
3098 DALI_TEST_EQUALS( child.GetCurrentSize().width, 0.0f, TEST_LOCATION );
3099 DALI_TEST_EQUALS( child.GetCurrentSize().height, 0.0f, TEST_LOCATION );
3100 DALI_TEST_EQUALS( child.GetCurrentSize().depth, targetParentSize.depth*0.25f * 0.2f, TEST_LOCATION );
3102 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 50% progress */);
3103 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize*0.5f, TEST_LOCATION );
3104 DALI_TEST_EQUALS( child.GetCurrentSize().width, 0.0f, TEST_LOCATION );
3105 DALI_TEST_EQUALS( child.GetCurrentSize().height, 0.0f, TEST_LOCATION );
3106 DALI_TEST_EQUALS( child.GetCurrentSize().depth, targetParentSize.depth*0.5f * 0.2f, TEST_LOCATION );
3108 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 75% progress */);
3109 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize*0.75f, TEST_LOCATION );
3110 DALI_TEST_EQUALS( child.GetCurrentSize().width, 0.0f, TEST_LOCATION );
3111 DALI_TEST_EQUALS( child.GetCurrentSize().height, 0.0f, TEST_LOCATION );
3112 DALI_TEST_EQUALS( child.GetCurrentSize().depth, targetParentSize.depth*0.75f * 0.2f, TEST_LOCATION );
3114 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 100% progress */);
3115 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize, TEST_LOCATION );
3116 DALI_TEST_EQUALS( child.GetCurrentSize().width, 0.0f, TEST_LOCATION );
3117 DALI_TEST_EQUALS( child.GetCurrentSize().height, 0.0f, TEST_LOCATION );
3118 DALI_TEST_EQUALS( child.GetCurrentSize().depth, targetParentSize.depth * 0.2f, TEST_LOCATION );
3120 // Check that nothing has changed after a couple of buffer swaps
3121 application.Render(0);
3122 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize, TEST_LOCATION );
3123 DALI_TEST_EQUALS( child.GetCurrentSize().width, 0.0f, TEST_LOCATION );
3124 DALI_TEST_EQUALS( child.GetCurrentSize().height, 0.0f, TEST_LOCATION );
3125 DALI_TEST_EQUALS( child.GetCurrentSize().depth, targetParentSize.depth * 0.2f, TEST_LOCATION );
3127 application.Render(0);
3128 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize, TEST_LOCATION );
3129 DALI_TEST_EQUALS( child.GetCurrentSize().width, 0.0f, TEST_LOCATION );
3130 DALI_TEST_EQUALS( child.GetCurrentSize().height, 0.0f, TEST_LOCATION );
3131 DALI_TEST_EQUALS( child.GetCurrentSize().depth, targetParentSize.depth * 0.2f, TEST_LOCATION );
3135 int UtcDaliConstraintInputWorldPosition(void)
3137 TestApplication application;
3139 Actor parent = Actor::New();
3140 Vector3 parentPosition( 10.0f, 10.0f, 10.0f );
3141 parent.SetPosition( parentPosition );
3142 parent.SetParentOrigin( ParentOrigin::CENTER );
3143 parent.SetAnchorPoint( AnchorPoint::CENTER );
3144 Stage::GetCurrent().Add( parent );
3146 Actor child = Actor::New();
3147 child.SetParentOrigin( ParentOrigin::CENTER );
3148 child.SetAnchorPoint( AnchorPoint::CENTER );
3149 Vector3 childPosition( 10.0f, 10.0f, 10.0f );
3150 child.SetPosition( childPosition );
3151 parent.Add( child );
3153 Actor trackingActor = Actor::New();
3154 trackingActor.SetParentOrigin( ParentOrigin::CENTER );
3155 trackingActor.SetAnchorPoint( AnchorPoint::CENTER );
3156 Stage::GetCurrent().Add( trackingActor );
3158 // The actors should not have a world position yet
3159 DALI_TEST_EQUALS( parent.GetCurrentWorldPosition(), Vector3::ZERO, TEST_LOCATION );
3160 DALI_TEST_EQUALS( child.GetCurrentWorldPosition(), Vector3::ZERO, TEST_LOCATION );
3161 DALI_TEST_EQUALS( trackingActor.GetCurrentWorldPosition(), Vector3::ZERO, TEST_LOCATION );
3163 application.SendNotification();
3164 application.Render(0);
3166 DALI_TEST_EQUALS( parent.GetCurrentPosition(), parentPosition, TEST_LOCATION );
3167 DALI_TEST_EQUALS( child.GetCurrentPosition(), childPosition, TEST_LOCATION );
3168 DALI_TEST_EQUALS( trackingActor.GetCurrentPosition(), Vector3::ZERO, TEST_LOCATION );
3170 DALI_TEST_EQUALS( parent.GetCurrentWorldPosition(), parentPosition, TEST_LOCATION );
3171 Vector3 previousPosition( parentPosition + childPosition );
3172 DALI_TEST_EQUALS( child.GetCurrentWorldPosition(), previousPosition, TEST_LOCATION );
3173 DALI_TEST_EQUALS( trackingActor.GetCurrentWorldPosition(), Vector3::ZERO, TEST_LOCATION );
3175 // Build constraint, to make actor track the world-position of another actor
3176 // Note that the world-position is always from the previous frame, so the tracking actor will lag behind
3178 Constraint constraint = Constraint::New<Vector3>( Actor::Property::POSITION,
3179 Source( child, Actor::Property::WORLD_POSITION ),
3180 EqualToConstraint() );
3182 trackingActor.ApplyConstraint( constraint );
3184 application.SendNotification();
3185 application.Render(0);
3187 DALI_TEST_EQUALS( trackingActor.GetCurrentPosition(), previousPosition, TEST_LOCATION );
3189 // Move the actors and try again
3190 Vector3 relativePosition( 5, 5, 5 );
3191 parent.TranslateBy( relativePosition );
3193 application.SendNotification();
3194 application.Render(0);
3196 DALI_TEST_EQUALS( parent.GetCurrentPosition(), parentPosition + relativePosition, TEST_LOCATION );
3197 DALI_TEST_EQUALS( child.GetCurrentPosition(), childPosition, TEST_LOCATION );
3199 // The tracking actor lags behind
3200 DALI_TEST_EQUALS( trackingActor.GetCurrentPosition(), previousPosition, TEST_LOCATION );
3202 DALI_TEST_EQUALS( parent.GetCurrentWorldPosition(), parentPosition + relativePosition, TEST_LOCATION );
3203 previousPosition = Vector3( parentPosition + childPosition + relativePosition );
3204 DALI_TEST_EQUALS( child.GetCurrentWorldPosition(), previousPosition, TEST_LOCATION );
3206 // Allow the tracking actor to catch up
3207 application.SendNotification();
3208 application.Render(0);
3210 DALI_TEST_EQUALS( parent.GetCurrentPosition(), parentPosition + relativePosition, TEST_LOCATION );
3211 DALI_TEST_EQUALS( child.GetCurrentPosition(), childPosition, TEST_LOCATION );
3213 // The tracking actor catches up!
3214 DALI_TEST_EQUALS( trackingActor.GetCurrentPosition(), previousPosition, TEST_LOCATION );
3215 DALI_TEST_EQUALS( parent.GetCurrentWorldPosition(), parentPosition + relativePosition, TEST_LOCATION );
3216 DALI_TEST_EQUALS( child.GetCurrentWorldPosition(), previousPosition, TEST_LOCATION );
3220 int UtcDaliConstraintInputWorldRotation(void)
3222 TestApplication application;
3224 Actor parent = Actor::New();
3225 Radian rotationAngle( Degree(90.0f) );
3226 Quaternion rotation( rotationAngle, Vector3::YAXIS );
3227 parent.SetOrientation( rotation );
3228 Stage::GetCurrent().Add( parent );
3230 Actor child = Actor::New();
3231 child.SetOrientation( rotation );
3232 parent.Add( child );
3234 Actor trackingActor = Actor::New();
3235 Stage::GetCurrent().Add( trackingActor );
3237 // The actors should not have a world rotation yet
3238 DALI_TEST_EQUALS( parent.GetCurrentWorldOrientation(), Quaternion(0.0f, Vector3::YAXIS), 0.001, TEST_LOCATION );
3239 DALI_TEST_EQUALS( child.GetCurrentWorldOrientation(), Quaternion(0.0f, Vector3::YAXIS), 0.001, TEST_LOCATION );
3241 application.SendNotification();
3242 application.Render(0);
3244 DALI_TEST_EQUALS( parent.GetCurrentOrientation(), rotation, 0.001, TEST_LOCATION );
3245 DALI_TEST_EQUALS( child.GetCurrentOrientation(), rotation, 0.001, TEST_LOCATION );
3246 DALI_TEST_EQUALS( trackingActor.GetCurrentOrientation(), Quaternion(0.0f, Vector3::YAXIS), 0.001, TEST_LOCATION );
3248 DALI_TEST_EQUALS( parent.GetCurrentWorldOrientation(), Quaternion( rotationAngle, Vector3::YAXIS ), 0.001, TEST_LOCATION );
3249 Quaternion previousRotation( rotationAngle * 2.0f, Vector3::YAXIS );
3250 DALI_TEST_EQUALS( child.GetCurrentWorldOrientation(), previousRotation, 0.001, TEST_LOCATION );
3252 // Build constraint, to make actor track the world-rotation of another actor
3253 // Note that the world-rotation is always from the previous frame, so the tracking actor will lag behind
3255 Constraint constraint = Constraint::New<Quaternion>( Actor::Property::ORIENTATION,
3256 Source( child, Actor::Property::WORLD_ORIENTATION ),
3257 EqualToQuaternion() );
3259 trackingActor.ApplyConstraint( constraint );
3261 application.SendNotification();
3262 application.Render(0);
3264 DALI_TEST_EQUALS( trackingActor.GetCurrentOrientation(), previousRotation, 0.001, TEST_LOCATION );
3266 // Rotate the actors and try again
3267 parent.RotateBy( rotation );
3269 application.SendNotification();
3270 application.Render(0);
3272 DALI_TEST_EQUALS( parent.GetCurrentOrientation(), rotation * rotation, 0.001, TEST_LOCATION );
3273 DALI_TEST_EQUALS( child.GetCurrentOrientation(), rotation, 0.001, TEST_LOCATION );
3275 // The tracking actor lags behind
3276 DALI_TEST_EQUALS( trackingActor.GetCurrentOrientation(), previousRotation, 0.001, TEST_LOCATION );
3278 DALI_TEST_EQUALS( parent.GetCurrentWorldOrientation(), Quaternion( rotationAngle * 2.0f, Vector3::YAXIS ), 0.001, TEST_LOCATION );
3279 previousRotation = Quaternion( rotationAngle * 3.0f, Vector3::YAXIS );
3280 DALI_TEST_EQUALS( child.GetCurrentWorldOrientation(), previousRotation, 0.001, TEST_LOCATION );
3282 // Allow the tracking actor to catch up
3283 application.SendNotification();
3284 application.Render(0);
3286 DALI_TEST_EQUALS( parent.GetCurrentOrientation(), rotation * rotation, 0.001, TEST_LOCATION );
3287 DALI_TEST_EQUALS( child.GetCurrentOrientation(), rotation, 0.001, TEST_LOCATION );
3289 // The tracking actor catches up!
3290 DALI_TEST_EQUALS( trackingActor.GetCurrentOrientation(), previousRotation, 0.001, TEST_LOCATION );
3291 DALI_TEST_EQUALS( parent.GetCurrentWorldOrientation(), Quaternion( rotationAngle * 2.0f, Vector3::YAXIS ), 0.001, TEST_LOCATION );
3292 DALI_TEST_EQUALS( child.GetCurrentWorldOrientation(), previousRotation, 0.001, TEST_LOCATION );
3296 int UtcDaliConstraintInputWorldScale(void)
3298 TestApplication application;
3300 Actor parent = Actor::New();
3301 Vector3 parentScale( 2.0f, 2.0f, 2.0f );
3302 parent.SetScale( parentScale );
3303 Stage::GetCurrent().Add( parent );
3305 Actor child = Actor::New();
3306 Vector3 childScale( 1.0f, 2.0f, 3.0f );
3307 child.SetScale( childScale );
3308 parent.Add( child );
3310 Actor trackingActor = Actor::New();
3311 Stage::GetCurrent().Add( trackingActor );
3313 // The actors should not have a world scale yet
3314 DALI_TEST_EQUALS( parent.GetCurrentWorldScale(), Vector3::ONE, TEST_LOCATION );
3315 DALI_TEST_EQUALS( child.GetCurrentWorldScale(), Vector3::ONE, TEST_LOCATION );
3316 DALI_TEST_EQUALS( trackingActor.GetCurrentWorldScale(), Vector3::ONE, TEST_LOCATION );
3318 application.SendNotification();
3319 application.Render(0);
3321 DALI_TEST_EQUALS( parent.GetCurrentScale(), parentScale, TEST_LOCATION );
3322 DALI_TEST_EQUALS( child.GetCurrentScale(), childScale, TEST_LOCATION );
3323 DALI_TEST_EQUALS( trackingActor.GetCurrentScale(), Vector3::ONE, TEST_LOCATION );
3325 DALI_TEST_EQUALS( parent.GetCurrentWorldScale(), parentScale, TEST_LOCATION );
3326 Vector3 previousScale( parentScale * childScale );
3327 DALI_TEST_EQUALS( child.GetCurrentWorldScale(), previousScale, TEST_LOCATION );
3328 DALI_TEST_EQUALS( trackingActor.GetCurrentScale(), Vector3::ONE, TEST_LOCATION );
3330 // Build constraint, to make actor track the world-scale of another actor
3331 // Note that the world-scale is always from the previous frame, so the tracking actor will lag behind
3333 Constraint constraint = Constraint::New<Vector3>( Actor::Property::SCALE,
3334 Source( child, Actor::Property::WORLD_SCALE ),
3335 EqualToConstraint() );
3337 trackingActor.ApplyConstraint( constraint );
3339 application.SendNotification();
3340 application.Render(0);
3342 DALI_TEST_EQUALS( trackingActor.GetCurrentScale(), previousScale, TEST_LOCATION );
3344 // Scale the actors and try again
3345 Vector3 relativeScale( 3, 3, 3 );
3346 parent.ScaleBy( relativeScale );
3348 application.SendNotification();
3349 application.Render(0);
3351 DALI_TEST_EQUALS( parent.GetCurrentScale(), parentScale * relativeScale, TEST_LOCATION );
3352 DALI_TEST_EQUALS( child.GetCurrentScale(), childScale, TEST_LOCATION );
3354 // The tracking actor lags behind
3355 DALI_TEST_EQUALS( trackingActor.GetCurrentScale(), previousScale, TEST_LOCATION );
3357 DALI_TEST_EQUALS( parent.GetCurrentWorldScale(), parentScale * relativeScale, TEST_LOCATION );
3358 previousScale = Vector3( parentScale * childScale * relativeScale );
3359 DALI_TEST_EQUALS( child.GetCurrentWorldScale(), previousScale, TEST_LOCATION );
3361 // Allow the tracking actor to catch up
3362 application.SendNotification();
3363 application.Render(0);
3365 DALI_TEST_EQUALS( parent.GetCurrentScale(), parentScale * relativeScale, TEST_LOCATION );
3366 DALI_TEST_EQUALS( child.GetCurrentScale(), childScale, TEST_LOCATION );
3368 // The tracking actor catches up!
3369 DALI_TEST_EQUALS( trackingActor.GetCurrentScale(), previousScale, TEST_LOCATION );
3370 DALI_TEST_EQUALS( parent.GetCurrentWorldScale(), parentScale * relativeScale, TEST_LOCATION );
3371 DALI_TEST_EQUALS( child.GetCurrentWorldScale(), previousScale, TEST_LOCATION );
3375 int UtcDaliConstraintInputWorldColor(void)
3377 TestApplication application;
3379 Actor parent = Actor::New();
3380 Vector4 parentColor( 1.0f, 0.5f, 0.0f, 1.0f );
3381 parent.SetColor( parentColor );
3382 Stage::GetCurrent().Add( parent );
3384 Actor child = Actor::New();
3385 Vector4 childColor( 0.5f, 0.5f, 0.5f, 1.0f );
3386 child.SetColor( childColor );
3387 parent.Add( child );
3389 Actor trackingActor = Actor::New();
3390 Stage::GetCurrent().Add( trackingActor );
3392 // The actors should not have a world color yet
3393 DALI_TEST_EQUALS( parent.GetCurrentWorldColor(), Color::WHITE, TEST_LOCATION );
3394 DALI_TEST_EQUALS( child.GetCurrentWorldColor(), Color::WHITE, TEST_LOCATION );
3396 application.SendNotification();
3397 application.Render(0);
3399 DALI_TEST_EQUALS( parent.GetCurrentColor(), parentColor, TEST_LOCATION );
3400 DALI_TEST_EQUALS( child.GetCurrentColor(), childColor, TEST_LOCATION );
3401 DALI_TEST_EQUALS( trackingActor.GetCurrentColor(), Color::WHITE, TEST_LOCATION );
3403 DALI_TEST_EQUALS( parent.GetCurrentWorldColor(), parentColor, TEST_LOCATION );
3404 Vector4 previousColor( childColor );
3405 previousColor.a *= parentColor.a;
3406 DALI_TEST_EQUALS( child.GetCurrentWorldColor(), previousColor, TEST_LOCATION );
3408 // Build constraint, to make actor track the world-color of another actor
3409 // Note that the world-color is always from the previous frame, so the tracking actor will lag behind
3411 Constraint constraint = Constraint::New<Vector4>( Actor::Property::COLOR,
3412 Source( child, Actor::Property::WORLD_COLOR ),
3415 trackingActor.ApplyConstraint( constraint );
3417 application.SendNotification();
3418 application.Render(0);
3420 DALI_TEST_EQUALS( trackingActor.GetCurrentColor(), previousColor, TEST_LOCATION );
3422 // Set the color and try again
3423 Vector4 newChildColor( 0.75f, 0.75f, 0.75f, 1.0f );
3424 child.SetColor( newChildColor );
3426 application.SendNotification();
3427 application.Render(0);
3429 DALI_TEST_EQUALS( parent.GetCurrentColor(), parentColor, TEST_LOCATION );
3430 DALI_TEST_EQUALS( child.GetCurrentColor(), newChildColor, TEST_LOCATION );
3432 // The tracking actor lags behind
3433 DALI_TEST_EQUALS( trackingActor.GetCurrentColor(), previousColor, TEST_LOCATION );
3435 DALI_TEST_EQUALS( parent.GetCurrentWorldColor(), parentColor, TEST_LOCATION );
3436 previousColor = Vector3( newChildColor );
3437 DALI_TEST_EQUALS( child.GetCurrentWorldColor(), previousColor, TEST_LOCATION );
3439 // Allow the tracking actor to catch up
3440 application.SendNotification();
3441 application.Render(0);
3443 DALI_TEST_EQUALS( parent.GetCurrentColor(), parentColor, TEST_LOCATION );
3444 DALI_TEST_EQUALS( child.GetCurrentColor(), newChildColor, TEST_LOCATION );
3446 // The tracking actor catches up!
3447 DALI_TEST_EQUALS( trackingActor.GetCurrentColor(), previousColor, TEST_LOCATION );
3448 DALI_TEST_EQUALS( parent.GetCurrentWorldColor(), parentColor, TEST_LOCATION );
3449 DALI_TEST_EQUALS( child.GetCurrentWorldColor(), previousColor, TEST_LOCATION );
3453 int UtcDaliConstraintInvalidInputProperty(void)
3455 TestApplication application;
3456 Actor actor = Actor::New();
3457 Constraint constraint = Constraint::New<Vector3>( Actor::Property::POSITION, LocalSource( PROPERTY_REGISTRATION_START_INDEX ), EqualToConstraint() );
3459 Stage::GetCurrent().Add( actor );
3461 // Cannot use type registered properties as input to constraints
3464 actor.ApplyConstraint( constraint );
3465 tet_result( TET_FAIL );
3467 catch ( DaliException& e )
3469 DALI_TEST_ASSERT( e, "mTargetObject->IsPropertyAConstraintInput( source.propertyIndex )", TEST_LOCATION );
3474 int UtcDaliBuiltinConstraintParentSize(void)
3476 TestApplication application;
3478 Actor parent = Actor::New();
3479 Vector3 parentSize(9,9,9);
3480 parent.SetSize( parentSize );
3481 Stage::GetCurrent().Add( parent );
3483 Actor actor = Actor::New();
3484 parent.Add( actor );
3486 Vector3 startValue( Vector3::ZERO );
3488 application.SendNotification();
3489 application.Render(0);
3490 DALI_TEST_CHECK( actor.GetCurrentSize() == startValue );
3494 Constraint constraint = Constraint::New<Vector3>( Actor::Property::SIZE, ParentSource( Actor::Property::SIZE ), EqualToConstraint() );
3495 actor.ApplyConstraint( constraint );
3497 application.SendNotification();
3498 application.Render(0);
3500 // Constraint should be fully applied
3501 DALI_TEST_EQUALS( actor.GetCurrentSize(), parentSize, TEST_LOCATION );
3503 // This should be ignored
3504 actor.SetSize( startValue );
3506 // Check that nothing has changed after a couple of buffer swaps
3507 application.SendNotification();
3508 application.Render(0);
3509 DALI_TEST_EQUALS( actor.GetCurrentSize(), parentSize, TEST_LOCATION );
3510 application.Render(0);
3511 DALI_TEST_EQUALS( actor.GetCurrentSize(), parentSize, TEST_LOCATION );
3513 // Remove the constraint, then set new value
3514 actor.RemoveConstraints();
3515 actor.SetSize( startValue );
3517 // Constraint should have been removed
3518 application.SendNotification();
3519 application.Render(0);
3520 DALI_TEST_EQUALS( actor.GetCurrentSize(), startValue, TEST_LOCATION );
3521 application.Render(0);
3522 DALI_TEST_EQUALS( actor.GetCurrentSize(), startValue, TEST_LOCATION );
3526 int UtcDaliBuiltinConstraintParentSizeRelative(void)
3528 TestApplication application;
3530 Actor parent = Actor::New();
3531 Vector3 parentSize(9,9,9);
3532 parent.SetSize( parentSize );
3533 Stage::GetCurrent().Add( parent );
3535 Actor actor = Actor::New();
3536 parent.Add( actor );
3538 Vector3 startValue( Vector3::ZERO );
3539 Vector3 scale(2,3,4);
3540 Vector3 endValue( parentSize * scale );
3542 application.SendNotification();
3543 application.Render(0);
3544 DALI_TEST_CHECK( actor.GetCurrentSize() == startValue );
3548 Constraint constraint = Constraint::New<Vector3>( Actor::Property::SIZE, ParentSource( Actor::Property::SIZE ), RelativeToConstraint( scale ) );
3549 actor.ApplyConstraint( constraint );
3551 application.SendNotification();
3552 application.Render(0);
3554 // Constraint should be fully applied
3555 DALI_TEST_EQUALS( actor.GetCurrentSize(), endValue, TEST_LOCATION );
3557 // This should be ignored
3558 actor.SetSize( startValue );
3560 // Check that nothing has changed after a couple of buffer swaps
3561 application.SendNotification();
3562 application.Render(0);
3563 DALI_TEST_EQUALS( actor.GetCurrentSize(), endValue, TEST_LOCATION );
3564 application.Render(0);
3565 DALI_TEST_EQUALS( actor.GetCurrentSize(), endValue, TEST_LOCATION );
3567 // Remove the constraint, then set new value
3568 actor.RemoveConstraints();
3569 actor.SetSize( startValue );
3571 // Constraint should have been removed
3572 application.SendNotification();
3573 application.Render(0);
3574 DALI_TEST_EQUALS( actor.GetCurrentSize(), startValue, TEST_LOCATION );
3575 application.Render(0);
3576 DALI_TEST_EQUALS( actor.GetCurrentSize(), startValue, TEST_LOCATION );
3580 int UtcDaliBuiltinConstraintScaleToFitConstraint(void)
3582 TestApplication application;
3584 Actor parent = Actor::New();
3585 Vector3 startParentSize( 10, 10, 10 );
3586 parent.SetSize( startParentSize );
3587 Stage::GetCurrent().Add( parent );
3589 Actor actor = Actor::New();
3590 Vector3 startChildSize( 5, 5, 5 );
3591 actor.SetSize( startChildSize );
3592 parent.Add( actor );
3594 Vector3 endChildSize( 8, 8, 8 );
3595 Vector3 endParentSize( 4, 4, 4 );
3596 Vector3 startChildScale( 2, 2, 2 ); // startParentSize / startChildSize
3597 Vector3 intermediateChildScale( 1.25, 1.25, 1.25 ); // startParentSize / endChildSize
3598 Vector3 endChildScale( 0.5, 0.5, 0.5 ); // endParentSize / endChildSize
3600 application.SendNotification();
3601 application.Render(0);
3602 DALI_TEST_CHECK( actor.GetCurrentSize() == startChildSize );
3606 Constraint constraint = Constraint::New<Vector3>( Actor::Property::SCALE,
3607 LocalSource( Actor::Property::SIZE ),
3608 ParentSource( Actor::Property::SIZE ),
3609 ScaleToFitConstraint() );
3610 actor.ApplyConstraint( constraint );
3612 application.SendNotification();
3613 application.Render(0);
3615 // Constraint should be fully applied, but parent size is larger than child
3616 DALI_TEST_EQUALS( actor.GetCurrentSize(), startChildSize, TEST_LOCATION );
3617 DALI_TEST_EQUALS( actor.GetCurrentScale(), startChildScale, TEST_LOCATION );
3619 // This should be allowed (still less than parent size)
3620 actor.SetSize( endChildSize );
3622 application.SendNotification();
3623 application.Render(0);
3624 DALI_TEST_EQUALS( actor.GetCurrentSize(), endChildSize, TEST_LOCATION );
3625 DALI_TEST_EQUALS( actor.GetCurrentScale(), intermediateChildScale, TEST_LOCATION );
3627 // Reduce the parent size
3628 parent.SetSize( endParentSize );
3630 application.SendNotification();
3631 application.Render(0);
3633 // Constraint should be fully applied
3634 DALI_TEST_EQUALS( actor.GetCurrentSize(), endChildSize, TEST_LOCATION );
3635 DALI_TEST_EQUALS( actor.GetCurrentScale(), endChildScale, TEST_LOCATION );
3636 application.Render(0);
3637 DALI_TEST_EQUALS( actor.GetCurrentSize(), endChildSize, TEST_LOCATION );
3638 DALI_TEST_EQUALS( actor.GetCurrentScale(), endChildScale, TEST_LOCATION );
3642 int UtcDaliBuiltinConstraintScaleToFitKeepAspectRatio(void)
3644 TestApplication application;
3646 Actor parent = Actor::New();
3647 Vector3 parentSize1( 10, 10, 10 );
3648 parent.SetSize( parentSize1 );
3649 Stage::GetCurrent().Add( parent );
3651 Actor actor = Actor::New();
3652 Vector3 childSize( 4, 5, 5 );
3653 actor.SetSize( childSize );
3654 parent.Add( actor );
3656 application.SendNotification();
3657 application.Render(0);
3658 Vector3 childScale1( 1.0f, 1.0f, 1.0f );
3659 DALI_TEST_EQUALS( actor.GetCurrentScale(), childScale1, TEST_LOCATION );
3663 Constraint constraint = Constraint::New<Vector3>( Actor::Property::SCALE,
3664 LocalSource( Actor::Property::SIZE ),
3665 ParentSource( Actor::Property::SIZE ),
3666 ScaleToFitKeepAspectRatioConstraint() );
3667 actor.ApplyConstraint( constraint );
3669 application.SendNotification();
3670 application.Render(0);
3672 // Constraint should be fully applied, but parent size is larger than child
3673 Vector3 childScale2( 2.0f, 2.0f, 2.0f );
3674 DALI_TEST_EQUALS( actor.GetCurrentScale(), childScale2, TEST_LOCATION );
3676 // change parent size
3677 Vector3 parentSize2( 40, 50, 50 );
3678 parent.SetSize( parentSize2 );
3680 application.SendNotification();
3681 application.Render(0);
3683 // Constraint should be fully applied, but parent size is larger than child
3684 Vector3 childScale3( 10.0f, 10.0f, 10.0f );
3685 DALI_TEST_EQUALS( actor.GetCurrentScale(), childScale3, TEST_LOCATION );
3690 int UtcDaliBuiltinConstraintScaleToFillXYKeepAspectRatio(void)
3692 TestApplication application;
3694 Actor parent = Actor::New();
3695 Vector3 parentSize1( 10, 10, 10 );
3696 parent.SetSize( parentSize1 );
3697 Stage::GetCurrent().Add( parent );
3699 Actor actor = Actor::New();
3700 Vector3 childSize( 4, 5, 5 );
3701 actor.SetSize( childSize );
3702 parent.Add( actor );
3704 application.SendNotification();
3705 application.Render(0);
3706 Vector3 childScale1( 1.0f, 1.0f, 1.0f );
3707 DALI_TEST_EQUALS( actor.GetCurrentScale(), childScale1, TEST_LOCATION );
3711 Constraint constraint = Constraint::New<Vector3>( Actor::Property::SCALE,
3712 LocalSource( Actor::Property::SIZE ),
3713 ParentSource( Actor::Property::SIZE ),
3714 ScaleToFillXYKeepAspectRatioConstraint() );
3715 actor.ApplyConstraint( constraint );
3717 application.SendNotification();
3718 application.Render(0);
3720 // Constraint should be fully applied, but parent size is larger than child
3721 float val = 10.f / 4.f;
3722 Vector3 childScale2( val, val, val );
3723 DALI_TEST_EQUALS( actor.GetCurrentScale(), childScale2, TEST_LOCATION );
3725 // change parent size
3726 Vector3 parentSize2( 40, 50, 50 );
3727 parent.SetSize( parentSize2 );
3729 application.SendNotification();
3730 application.Render(0);
3732 // Constraint should be fully applied, but parent size is larger than child
3733 Vector3 childScale3( 10.0f, 10.0f, 10.0f );
3734 DALI_TEST_EQUALS( actor.GetCurrentScale(), childScale3, TEST_LOCATION );
3738 int UtcDaliBuiltinConstraintEqualToConstraint(void)
3740 TestApplication application;
3742 Actor actor1 = Actor::New();
3743 Vector3 startPosition( 10, 10, 10 );
3744 actor1.SetPosition( startPosition );
3745 Stage::GetCurrent().Add( actor1 );
3747 Actor actor2 = Actor::New();
3748 Vector3 startSize( 100, 100, 100 );
3749 actor2.SetSize( startSize );
3750 Stage::GetCurrent().Add( actor2 );
3752 application.SendNotification();
3753 application.Render(0);
3754 DALI_TEST_CHECK( actor1.GetCurrentPosition() == startPosition );
3755 DALI_TEST_CHECK( actor2.GetCurrentSize() == startSize );
3757 // Apply constraint - actor1 size == actor2 position
3759 Constraint constraint = Constraint::New<Vector3>( Actor::Property::SIZE,
3760 Source( actor1, Actor::Property::POSITION ),
3761 EqualToConstraint() );
3762 constraint.SetRemoveAction( Constraint::Discard );
3763 actor2.ApplyConstraint( constraint );
3765 application.SendNotification();
3766 application.Render(0);
3768 // Constraint should be fully applied
3769 DALI_TEST_EQUALS( actor2.GetCurrentSize(), startPosition, TEST_LOCATION );
3772 Vector3 endPosition( 2, 2, 2 );
3773 actor1.SetPosition( endPosition );
3775 application.SendNotification();
3776 application.Render(0);
3778 // Constraint should be fully applied
3779 DALI_TEST_EQUALS( actor2.GetCurrentSize(), endPosition, TEST_LOCATION );
3780 application.Render(0);
3781 DALI_TEST_EQUALS( actor2.GetCurrentSize(), endPosition, TEST_LOCATION );
3784 // Check float variant of constraint
3786 float startOpacity(1.0f);
3787 float endOpacity(0.2f);
3788 actor1.SetOpacity( startOpacity );
3789 actor2.SetOpacity( startOpacity );
3791 application.SendNotification();
3792 application.Render(0);
3793 DALI_TEST_EQUALS( actor1.GetCurrentOpacity(), startOpacity, TEST_LOCATION );
3794 DALI_TEST_EQUALS( actor2.GetCurrentOpacity(), startOpacity, TEST_LOCATION );
3796 Constraint constraint2 = Constraint::New<float>( Actor::Property::COLOR_ALPHA,
3797 Source( actor1, Actor::Property::COLOR_ALPHA ),
3798 EqualToConstraint() );
3799 constraint2.SetRemoveAction( Constraint::Discard );
3800 actor2.ApplyConstraint( constraint2 );
3802 actor1.SetOpacity(endOpacity);
3804 application.SendNotification();
3805 application.Render(0);
3807 DALI_TEST_EQUALS( actor2.GetCurrentOpacity(), endOpacity, 0.000001f, TEST_LOCATION );
3810 // Check Vector4 variant of constraint
3812 actor1.SetColor( Color::GREEN );
3813 actor2.SetColor( Color::RED );
3815 application.SendNotification();
3816 application.Render(0);
3817 DALI_TEST_CHECK( actor1.GetCurrentColor() == Color::GREEN );
3818 DALI_TEST_CHECK( actor2.GetCurrentColor() == Color::RED );
3820 Constraint constraint3 = Constraint::New<Vector4>( Actor::Property::COLOR,
3821 Source( actor1, Actor::Property::COLOR ),
3822 EqualToConstraint() );
3823 constraint3.SetRemoveAction( Constraint::Discard );
3824 actor2.ApplyConstraint( constraint3 );
3825 application.SendNotification();
3826 application.Render(0);
3827 DALI_TEST_CHECK( actor2.GetCurrentColor() == Color::GREEN );
3830 // Check Quaternion variant of constraint
3832 Quaternion q1 = Quaternion( Math::PI_2, Vector3::XAXIS );
3833 Quaternion q2 = Quaternion( Math::PI_4, Vector3::YAXIS );
3834 actor1.SetOrientation( q1 );
3835 actor2.SetOrientation( q2 );
3837 application.SendNotification();
3838 application.Render(0);
3839 DALI_TEST_EQUALS( actor1.GetCurrentOrientation(), q1, 0.01, TEST_LOCATION );
3840 DALI_TEST_EQUALS( actor2.GetCurrentOrientation(), q2, 0.01, TEST_LOCATION );
3842 Constraint constraint4 = Constraint::New<Quaternion>( Actor::Property::ORIENTATION,
3843 Source( actor1, Actor::Property::ORIENTATION ),
3844 EqualToConstraint() );
3845 constraint4.SetRemoveAction( Constraint::Discard );
3846 actor2.ApplyConstraint( constraint4 );
3847 application.SendNotification();
3848 application.Render(0);
3849 DALI_TEST_EQUALS( actor2.GetCurrentOrientation(), q1, 0.01, TEST_LOCATION );
3852 // Check Matrix3 variant
3854 EqualToConstraint equalToConstraint;
3857 a.AsFloat()[0] = 1.f;
3859 b.AsFloat()[0] = 2.f;
3860 PropertyInputAbstraction pi(b);
3862 Matrix3 c = equalToConstraint(a,pi);
3863 DALI_TEST_EQUALS( c.AsFloat()[0], b.AsFloat()[0], 0.01, TEST_LOCATION);
3867 int UtcDaliBuiltinConstraintRelativeToConstraint(void)
3869 TestApplication application;
3871 Actor actor1 = Actor::New();
3872 Vector3 startPosition( 10, 10, 10 );
3873 actor1.SetPosition( startPosition );
3874 Stage::GetCurrent().Add( actor1 );
3876 Actor actor2 = Actor::New();
3877 Vector3 startSize( 100, 100, 100 );
3878 actor2.SetSize( startSize );
3879 Stage::GetCurrent().Add( actor2 );
3881 application.SendNotification();
3882 application.Render(0);
3883 DALI_TEST_CHECK( actor1.GetCurrentPosition() == startPosition );
3884 DALI_TEST_CHECK( actor2.GetCurrentSize() == startSize );
3886 // Apply constraint - actor1 size == actor2 position
3888 RelativeToConstraint( 0.f );
3889 Vector3 scale( 0.5, 0.6, 0.7 );
3890 Constraint constraint = Constraint::New<Vector3>( Actor::Property::SIZE,
3891 Source( actor1, Actor::Property::POSITION ),
3892 RelativeToConstraint( scale ) );
3893 constraint.SetRemoveAction( Constraint::Discard );
3894 actor2.ApplyConstraint( constraint );
3896 application.SendNotification();
3897 application.Render(0);
3899 // Constraint should be fully applied
3900 DALI_TEST_EQUALS( actor2.GetCurrentSize(), scale * startPosition, TEST_LOCATION );
3903 Vector3 endPosition( 2, 2, 2 );
3904 actor1.SetPosition( endPosition );
3906 application.SendNotification();
3907 application.Render(0);
3909 // Constraint should be fully applied
3910 DALI_TEST_EQUALS( actor2.GetCurrentSize(), scale * endPosition, TEST_LOCATION );
3911 application.Render(0);
3912 DALI_TEST_EQUALS( actor2.GetCurrentSize(), scale * endPosition, TEST_LOCATION );
3915 // Check float variant of constraint
3917 float scale2( 0.5f );
3918 float startOpacity(1.0f);
3919 actor1.SetOpacity( startOpacity );
3920 actor2.SetOpacity( startOpacity );
3922 application.SendNotification();
3923 application.Render(0);
3924 DALI_TEST_EQUALS( actor1.GetCurrentOpacity(), startOpacity, TEST_LOCATION );
3925 DALI_TEST_EQUALS( actor2.GetCurrentOpacity(), startOpacity, TEST_LOCATION );
3927 Constraint constraint2 = Constraint::New<float>( Actor::Property::COLOR_ALPHA,
3928 Source( actor1, Actor::Property::COLOR_ALPHA ),
3929 RelativeToConstraintFloat(scale2) );
3930 constraint2.SetRemoveAction( Constraint::Discard );
3931 actor2.ApplyConstraint(constraint2);
3932 application.SendNotification();
3933 application.Render(0);
3935 DALI_TEST_EQUALS( actor2.GetCurrentOpacity(), startOpacity * scale2, TEST_LOCATION );
3939 int UtcDaliBuiltinConstraintFunctions(void)
3941 TestApplication application;
3944 SourceWidthFixedHeight sourceWidthFixedHeight( 10.f );
3947 Vector3 reference(1, 10, 0);
3948 Vector3 value = sourceWidthFixedHeight( current, PropertyInputAbstraction(Vector3::ONE) );
3949 DALI_TEST_EQUALS( reference, value, TEST_LOCATION );
3952 Vector3 reference(10, 10, 0);
3953 Vector3 value = sourceWidthFixedHeight( current, PropertyInputAbstraction(Vector3::ONE*10.f) );
3954 DALI_TEST_EQUALS( reference, value, TEST_LOCATION );
3957 Vector3 reference(10,10,0);
3958 Vector3 value = sourceWidthFixedHeight( current, PropertyInputAbstraction(Vector3::ONE*10.f) );
3959 DALI_TEST_EQUALS( reference, value, TEST_LOCATION );
3964 Quaternion current(0, Vector3::YAXIS);
3965 PropertyInputAbstraction target(Vector3::ZAXIS);
3966 PropertyInputAbstraction targetRotation(Vector3::YAXIS);
3967 PropertyInputAbstraction camera(Vector3::ZERO);
3970 Quaternion reference(1., 0., 0., 0.);
3971 Quaternion value = LookAt( current, target, camera, targetRotation );
3972 DALI_TEST_EQUALS( reference, value, 0.001, TEST_LOCATION );