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 float& val) : mType(Dali::Property::FLOAT), mFloatData( val ) {}
69 PropertyInputAbstraction(const int& val) : mType(Dali::Property::INTEGER), mIntData( val ) {}
70 PropertyInputAbstraction(const Vector2& val) : mType(Dali::Property::VECTOR2), mVector2Data( val ) {}
71 PropertyInputAbstraction(const Vector3& val) : mType(Dali::Property::VECTOR3), mVector3Data( val ) {}
72 PropertyInputAbstraction(const Vector4& val) : mType(Dali::Property::VECTOR4), mVector4Data( val ) {}
73 PropertyInputAbstraction(const Matrix3& val) : mType(Dali::Property::MATRIX3), mMatrix3Data( val ) {}
74 PropertyInputAbstraction(const Matrix& val) : mType(Dali::Property::MATRIX), mMatrixData( val ) {}
75 PropertyInputAbstraction(const Quaternion& val) : mType(Dali::Property::ROTATION), mQuaternionData( val ) {}
77 ~PropertyInputAbstraction() {}
79 Dali::Property::Type GetType() const { return mType; }
81 const bool& GetBoolean() const { return mBoolData; }
83 const float& GetFloat() const { return mFloatData; }
85 const int& GetInteger() const { return mIntData; }
87 const Vector2& GetVector2() const { return mVector2Data; }
88 const Vector3& GetVector3() const { return mVector3Data; }
89 const Vector4& GetVector4() const { return mVector4Data; }
91 const Matrix3& GetMatrix3() const { return mMatrix3Data; }
92 const Matrix& GetMatrix() const { return mMatrixData; }
94 const Quaternion& GetQuaternion() const { return mQuaternionData; }
97 Dali::Property::Type mType;
101 Vector2 mVector2Data;
102 Vector3 mVector3Data;
103 Vector4 mVector4Data;
104 Matrix3 mMatrix3Data;
106 Quaternion mQuaternionData;
109 static const float POSITION_EPSILON = 0.0001f;
110 static const float ROTATION_EPSILON = 0.0001f;
112 struct TestConstraint
114 Vector4 operator()(const Vector4& color)
116 return Vector4(color.x, color.y, color.z, 0.1f);
120 struct TestConstraintToVector3
122 TestConstraintToVector3(Vector3 target)
127 Vector3 operator()(const Vector3& current)
135 struct TestColorConstraint
137 TestColorConstraint(Vector4 target)
142 Vector4 operator()(const Vector4& color)
150 struct TestPositionConstraint
152 TestPositionConstraint(Vector3 target)
157 Vector3 operator()(const Vector3& position)
166 struct TestAlwaysTrueConstraint
168 bool operator()( const bool& current )
174 struct TestAlwaysEqualOrGreaterThanConstraintFloat
176 TestAlwaysEqualOrGreaterThanConstraintFloat( float value )
181 float operator()( const float& current )
183 return ( current < mValue ) ? mValue : current;
189 struct TestAlwaysEqualOrGreaterThanConstraintInteger
191 TestAlwaysEqualOrGreaterThanConstraintInteger( int value )
196 int operator()( const int& current )
198 return ( current < mValue ) ? mValue : current;
204 struct TestAlwaysEqualOrGreaterThanConstraintVector2
206 TestAlwaysEqualOrGreaterThanConstraintVector2( Vector2 value )
211 Vector2 operator()( const Vector2& current )
213 return Vector2( ( current.x < mValue.x ) ? mValue.x : current.x,
214 ( current.y < mValue.y ) ? mValue.y : current.y
221 struct TestAlwaysEqualOrGreaterThanConstraintVector3
223 TestAlwaysEqualOrGreaterThanConstraintVector3( Vector3 value )
228 Vector3 operator()( const Vector3& current )
230 return Vector3( ( current.x < mValue.x ) ? mValue.x : current.x,
231 ( current.y < mValue.y ) ? mValue.y : current.y,
232 ( current.z < mValue.z ) ? mValue.z : current.z
239 struct TestAlwaysEqualOrGreaterThanConstraintVector4
241 TestAlwaysEqualOrGreaterThanConstraintVector4( Vector4 value )
246 Vector4 operator()( const Vector4& current )
248 return Vector4( ( current.x < mValue.x ) ? mValue.x : current.x,
249 ( current.y < mValue.y ) ? mValue.y : current.y,
250 ( current.z < mValue.z ) ? mValue.z : current.z,
251 ( current.w < mValue.w ) ? mValue.w : current.w
258 struct TestConstraintFloat
260 TestConstraintFloat( float value )
265 float operator()( const float& current )
273 struct TestConstraintInteger
275 TestConstraintInteger( int value )
280 int operator()( const int& current )
288 struct TestConstraintVector2
290 TestConstraintVector2( Vector2 value )
295 Vector2 operator()( const Vector2& current )
303 struct TestConstraintVector3
305 TestConstraintVector3( Vector3 value )
310 Vector3 operator()( const Vector3& current )
318 struct TestConstraintVector4
320 TestConstraintVector4( Vector4 value )
325 Vector4 operator()( const Vector4& current )
333 struct TestConstraintRotation
335 TestConstraintRotation( Quaternion rotation )
336 : mRotation( rotation )
340 Quaternion operator()( const Quaternion& current )
345 Quaternion mRotation;
348 struct TestConstraintMatrix3
350 TestConstraintMatrix3(Matrix3 matrix3)
351 : mMatrix3( matrix3 )
355 Matrix3 operator()( const Matrix3& current )
363 struct TestConstraintMatrix
365 TestConstraintMatrix(Matrix matrix)
370 Matrix operator()( const Matrix& current )
378 struct MoveAwayWithFadeConstraint
380 MoveAwayWithFadeConstraint( float distance )
381 : mDistance( distance )
385 Vector3 operator()( const Vector3& current,
386 const PropertyInput& color )
388 return Vector3( current.x,
390 -mDistance * (1.0f - color.GetVector4().a) );
396 struct TestBottomRightAlignConstraint
398 Vector3 operator()( const Vector3& current,
399 const PropertyInput& parentSize )
401 return Vector3( parentSize.GetVector3().x, parentSize.GetVector3().y, 0.0f );
405 struct MeanPositionConstraint1
407 Vector3 operator()( const Vector3& current,
408 const PropertyInput& position1 )
410 return Vector3( position1.GetVector3() );
414 struct MeanPositionConstraint2
416 Vector3 operator()( const Vector3& current,
417 const PropertyInput& position1,
418 const PropertyInput& position2 )
420 Vector3 meanValue = position1.GetVector3() +
421 position2.GetVector3();
423 return meanValue * 0.5f; // div 2
427 struct MeanPositionConstraint3
429 Vector3 operator()( const Vector3& current,
430 const PropertyInput& position1,
431 const PropertyInput& position2,
432 const PropertyInput& position3 )
434 Vector3 meanValue = position1.GetVector3() +
435 position2.GetVector3() +
436 position3.GetVector3();
438 return meanValue * (1.0f / 3.0f); // div 3
442 struct MeanPositionConstraint4
444 Vector3 operator()( const Vector3& current,
445 const PropertyInput& position1,
446 const PropertyInput& position2,
447 const PropertyInput& position3,
448 const PropertyInput& position4 )
450 Vector3 meanValue = position1.GetVector3() +
451 position2.GetVector3() +
452 position3.GetVector3() +
453 position4.GetVector3();
455 return meanValue * 0.25f; // div 4
459 struct MeanPositionConstraint5
461 Vector3 operator()( const Vector3& current,
462 const PropertyInput& position1,
463 const PropertyInput& position2,
464 const PropertyInput& position3,
465 const PropertyInput& position4,
466 const PropertyInput& position5 )
468 Vector3 meanValue = position1.GetVector3() +
469 position2.GetVector3() +
470 position3.GetVector3() +
471 position4.GetVector3() +
472 position5.GetVector3();
474 return meanValue * 0.2f; // div 5
478 struct MeanPositionConstraint6
480 Vector3 operator()( const Vector3& current,
481 const PropertyInput& position1,
482 const PropertyInput& position2,
483 const PropertyInput& position3,
484 const PropertyInput& position4,
485 const PropertyInput& position5,
486 const PropertyInput& position6 )
488 Vector3 meanValue = position1.GetVector3() +
489 position2.GetVector3() +
490 position3.GetVector3() +
491 position4.GetVector3() +
492 position5.GetVector3() +
493 position6.GetVector3();
495 return meanValue * (1.0f / 6.0f); // div 6
499 struct TestRelativeConstraintFloat
501 TestRelativeConstraintFloat(float scale)
506 float operator()( const float& current, const PropertyInput& relative )
508 return relative.GetFloat() * mScale;
514 struct TestRelativeConstraintVector3
516 TestRelativeConstraintVector3(float scale)
521 Vector3 operator()( const Vector3& current, const PropertyInput& relative )
523 return relative.GetVector3() * mScale;
529 } // anonymous namespace
536 int UtcDaliConstraintNewBoolean(void)
538 TestApplication application;
540 Actor actor = Actor::New();
542 // Register a boolean property
543 bool startValue(false);
544 Property::Index index = actor.RegisterProperty( "test-property", startValue );
545 Stage::GetCurrent().Add(actor);
546 DALI_TEST_CHECK( actor.GetProperty<bool>(index) == startValue );
549 * Test that the Constraint is correctly applied on a clean Node
551 application.SendNotification();
552 application.Render(0);
553 DALI_TEST_CHECK( actor.GetProperty<bool>(index) == startValue );
554 application.Render(0);
555 DALI_TEST_CHECK( actor.GetProperty<bool>(index) == startValue );
556 application.Render(0);
557 DALI_TEST_CHECK( actor.GetProperty<bool>(index) == startValue );
561 Constraint constraint = Constraint::New<bool>( index, TestAlwaysTrueConstraint() );
563 actor.ApplyConstraint( constraint );
564 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), false, TEST_LOCATION );
566 application.SendNotification();
567 application.Render(0);
569 // Constraint should be fully applied
570 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), true, TEST_LOCATION );
572 // Check that nothing has changed after a couple of buffer swaps
573 application.Render(0);
574 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), true, TEST_LOCATION );
575 application.Render(0);
576 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), true, TEST_LOCATION );
578 // Try to fight with the constraint - this shouldn't work!
579 actor.SetProperty( index, false );
581 application.SendNotification();
582 application.Render(0);
584 // Check that nothing has changed after a couple of buffer swaps
585 application.Render(0);
586 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), true, TEST_LOCATION );
587 application.Render(0);
588 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), true, TEST_LOCATION );
590 // Remove the constraint, then set new value
591 actor.RemoveConstraints();
592 actor.SetProperty( index, false );
594 // Constraint should have been removed
595 application.SendNotification();
596 application.Render(0);
597 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), false, TEST_LOCATION );
598 application.Render(0);
599 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), false, TEST_LOCATION );
603 int UtcDaliConstraintNewFloat(void)
605 TestApplication application;
607 Actor actor = Actor::New();
609 // Register a float property
610 float startValue(1.0f);
611 Property::Index index = actor.RegisterProperty( "test-property", startValue );
612 Stage::GetCurrent().Add(actor);
613 DALI_TEST_CHECK( actor.GetProperty<float>(index) == startValue );
616 * Test that the Constraint is correctly applied on a clean Node
618 application.SendNotification();
619 application.Render(0);
620 DALI_TEST_CHECK( actor.GetProperty<float>(index) == startValue );
621 application.Render(0);
622 DALI_TEST_CHECK( actor.GetProperty<float>(index) == startValue );
623 application.Render(0);
624 DALI_TEST_CHECK( actor.GetProperty<float>(index) == startValue );
628 float minValue( 2.0f );
629 Constraint constraint = Constraint::New<float>( index, TestAlwaysEqualOrGreaterThanConstraintFloat( minValue ) );
631 actor.ApplyConstraint( constraint );
632 DALI_TEST_EQUALS( actor.GetProperty<float>(index), startValue, TEST_LOCATION );
634 application.SendNotification();
635 application.Render(0);
637 // Constraint should be fully applied
638 DALI_TEST_EQUALS( actor.GetProperty<float>(index), minValue, TEST_LOCATION );
640 // Check that nothing has changed after a couple of buffer swaps
641 application.Render(0);
642 DALI_TEST_EQUALS( actor.GetProperty<float>(index), minValue, TEST_LOCATION );
643 application.Render(0);
644 DALI_TEST_EQUALS( actor.GetProperty<float>(index), minValue, TEST_LOCATION );
646 // Set to greater than 2.0f, the constraint will allow this
647 actor.SetProperty( index, 3.0f );
649 application.SendNotification();
650 application.Render(0);
652 DALI_TEST_EQUALS( actor.GetProperty<float>(index), 3.0f, TEST_LOCATION );
654 // Check that nothing has changed after a couple of buffer swaps
655 application.Render(0);
656 DALI_TEST_EQUALS( actor.GetProperty<float>(index), 3.0f, TEST_LOCATION );
657 application.Render(0);
658 DALI_TEST_EQUALS( actor.GetProperty<float>(index), 3.0f, TEST_LOCATION );
660 // Set to less than 2.0f, the constraint will NOT allow this
661 actor.SetProperty( index, 1.0f );
663 application.SendNotification();
664 application.Render(0);
666 DALI_TEST_EQUALS( actor.GetProperty<float>(index), minValue/*not 1.0f*/, TEST_LOCATION );
668 // Check that nothing has changed after a couple of buffer swaps
669 application.Render(0);
670 DALI_TEST_EQUALS( actor.GetProperty<float>(index), minValue, TEST_LOCATION );
671 application.Render(0);
672 DALI_TEST_EQUALS( actor.GetProperty<float>(index), minValue, TEST_LOCATION );
674 // Remove the constraint, then set new value
675 actor.RemoveConstraints();
676 actor.SetProperty( index, 1.0f );
678 // Constraint should have been removed
679 application.SendNotification();
680 application.Render(0);
681 DALI_TEST_EQUALS( actor.GetProperty<float>(index), 1.0f, TEST_LOCATION );
682 application.Render(0);
683 DALI_TEST_EQUALS( actor.GetProperty<float>(index), 1.0f, TEST_LOCATION );
687 int UtcDaliConstraintNewInteger(void)
689 TestApplication application;
691 Actor actor = Actor::New();
693 // Register an integer property
695 Property::Index index = actor.RegisterProperty( "test-property", startValue );
696 Stage::GetCurrent().Add(actor);
697 DALI_TEST_CHECK( actor.GetProperty<int>(index) == startValue );
700 * Test that the Constraint is correctly applied on a clean Node
702 application.SendNotification();
703 application.Render(0);
704 DALI_TEST_CHECK( actor.GetProperty<int>(index) == startValue );
705 application.Render(0);
706 DALI_TEST_CHECK( actor.GetProperty<int>(index) == startValue );
707 application.Render(0);
708 DALI_TEST_CHECK( actor.GetProperty<int>(index) == startValue );
713 Constraint constraint = Constraint::New<int>( index, TestAlwaysEqualOrGreaterThanConstraintInteger( minValue ) );
715 actor.ApplyConstraint( constraint );
716 DALI_TEST_EQUALS( actor.GetProperty<int>(index), startValue, TEST_LOCATION );
718 application.SendNotification();
719 application.Render(0);
721 // Constraint should be fully applied
722 DALI_TEST_EQUALS( actor.GetProperty<int>(index), minValue, TEST_LOCATION );
724 // Check that nothing has changed after a couple of buffer swaps
725 application.Render(0);
726 DALI_TEST_EQUALS( actor.GetProperty<int>(index), minValue, TEST_LOCATION );
727 application.Render(0);
728 DALI_TEST_EQUALS( actor.GetProperty<int>(index), minValue, TEST_LOCATION );
730 // Set to greater than 2f, the constraint will allow this
731 actor.SetProperty( index, 3 );
733 application.SendNotification();
734 application.Render(0);
736 DALI_TEST_EQUALS( actor.GetProperty<int>(index), 3, TEST_LOCATION );
738 // Check that nothing has changed after a couple of buffer swaps
739 application.Render(0);
740 DALI_TEST_EQUALS( actor.GetProperty<int>(index), 3, TEST_LOCATION );
741 application.Render(0);
742 DALI_TEST_EQUALS( actor.GetProperty<int>(index), 3, TEST_LOCATION );
744 // Set to less than 2, the constraint will NOT allow this
745 actor.SetProperty( index, 1 );
747 application.SendNotification();
748 application.Render(0);
750 DALI_TEST_EQUALS( actor.GetProperty<int>(index), minValue/*not 1*/, TEST_LOCATION );
752 // Check that nothing has changed after a couple of buffer swaps
753 application.Render(0);
754 DALI_TEST_EQUALS( actor.GetProperty<int>(index), minValue, TEST_LOCATION );
755 application.Render(0);
756 DALI_TEST_EQUALS( actor.GetProperty<int>(index), minValue, TEST_LOCATION );
758 // Remove the constraint, then set new value
759 actor.RemoveConstraints();
760 actor.SetProperty( index, 1 );
762 // Constraint should have been removed
763 application.SendNotification();
764 application.Render(0);
765 DALI_TEST_EQUALS( actor.GetProperty<int>(index), 1, TEST_LOCATION );
766 application.Render(0);
767 DALI_TEST_EQUALS( actor.GetProperty<int>(index), 1, TEST_LOCATION );
772 int UtcDaliConstraintNewVector2(void)
774 TestApplication application;
776 Actor actor = Actor::New();
778 // Register a Vector2 property
779 Vector2 startValue( 1.0f, 1.0f );
780 Property::Index index = actor.RegisterProperty( "test-property", startValue );
781 Stage::GetCurrent().Add(actor);
782 DALI_TEST_CHECK( actor.GetProperty<Vector2>(index) == startValue );
785 * Test that the Constraint is correctly applied on a clean Node
787 application.SendNotification();
788 application.Render(0);
789 DALI_TEST_CHECK( actor.GetProperty<Vector2>(index) == startValue );
790 application.Render(0);
791 DALI_TEST_CHECK( actor.GetProperty<Vector2>(index) == startValue );
792 application.Render(0);
793 DALI_TEST_CHECK( actor.GetProperty<Vector2>(index) == startValue );
797 Vector2 minValue( 2.0f, 2.0f );
798 Constraint constraint = Constraint::New<Vector2>( index, TestAlwaysEqualOrGreaterThanConstraintVector2( minValue ) );
800 actor.ApplyConstraint( constraint );
801 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), startValue, TEST_LOCATION );
803 application.SendNotification();
804 application.Render(0);
806 // Constraint should be fully applied
807 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), minValue, TEST_LOCATION );
809 // Check that nothing has changed after a couple of buffer swaps
810 application.Render(0);
811 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), minValue, TEST_LOCATION );
812 application.Render(0);
813 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), minValue, TEST_LOCATION );
815 // Set to greater than 2.0f, the constraint will allow this
816 Vector2 greaterValue( 3.0f, 3.0f );
817 actor.SetProperty( index, greaterValue );
819 application.SendNotification();
820 application.Render(0);
822 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), greaterValue, TEST_LOCATION );
824 // Check that nothing has changed after a couple of buffer swaps
825 application.Render(0);
826 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), greaterValue, TEST_LOCATION );
827 application.Render(0);
828 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), greaterValue, TEST_LOCATION );
830 // Set to less than 2.0f, the constraint will NOT allow this
831 Vector2 lesserValue( 1.0f, 1.0f );
832 actor.SetProperty( index, lesserValue );
834 application.SendNotification();
835 application.Render(0);
837 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), minValue/*not lesserValue*/, TEST_LOCATION );
839 // Check that nothing has changed after a couple of buffer swaps
840 application.Render(0);
841 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), minValue, TEST_LOCATION );
842 application.Render(0);
843 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), minValue, TEST_LOCATION );
845 // Remove the constraint, then set new value
846 actor.RemoveConstraints();
847 actor.SetProperty( index, lesserValue );
849 // Constraint should have been removed
850 application.SendNotification();
851 application.Render(0);
852 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), lesserValue, TEST_LOCATION );
853 application.Render(0);
854 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), lesserValue, TEST_LOCATION );
858 int UtcDaliConstraintNewVector3(void)
860 TestApplication application;
862 Actor actor = Actor::New();
864 // Register a Vector3 property
865 Vector3 startValue(1.0f, 1.0f, 1.0f);
866 Property::Index index = actor.RegisterProperty( "test-property", startValue );
867 Stage::GetCurrent().Add(actor);
868 DALI_TEST_CHECK( actor.GetProperty<Vector3>(index) == startValue );
871 * Test that the Constraint is correctly applied on a clean Node
873 application.SendNotification();
874 application.Render(0);
875 DALI_TEST_CHECK( actor.GetProperty<Vector3>(index) == startValue );
876 application.Render(0);
877 DALI_TEST_CHECK( actor.GetProperty<Vector3>(index) == startValue );
878 application.Render(0);
879 DALI_TEST_CHECK( actor.GetProperty<Vector3>(index) == startValue );
883 Vector3 minValue( 2.0f, 2.0f, 2.0f );
884 Constraint constraint = Constraint::New<Vector3>( index, TestAlwaysEqualOrGreaterThanConstraintVector3( minValue ) );
886 actor.ApplyConstraint( constraint );
887 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), startValue, TEST_LOCATION );
889 application.SendNotification();
890 application.Render(0);
892 // Constraint should be fully applied
893 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), minValue, TEST_LOCATION );
895 // Check that nothing has changed after a couple of buffer swaps
896 application.Render(0);
897 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), minValue, TEST_LOCATION );
898 application.Render(0);
899 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), minValue, TEST_LOCATION );
901 // Set to greater than 2.0f, the constraint will allow this
902 Vector3 greaterValue( 3.0f, 3.0f, 3.0f );
903 actor.SetProperty( index, greaterValue );
905 application.SendNotification();
906 application.Render(0);
908 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), greaterValue, TEST_LOCATION );
910 // Check that nothing has changed after a couple of buffer swaps
911 application.Render(0);
912 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), greaterValue, TEST_LOCATION );
913 application.Render(0);
914 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), greaterValue, TEST_LOCATION );
916 // Set to less than 2.0f, the constraint will NOT allow this
917 Vector3 lesserValue( 1.0f, 1.0f, 1.0f );
918 actor.SetProperty( index, lesserValue );
920 application.SendNotification();
921 application.Render(0);
923 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), minValue/*not lesserValue*/, TEST_LOCATION );
925 // Check that nothing has changed after a couple of buffer swaps
926 application.Render(0);
927 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), minValue, TEST_LOCATION );
928 application.Render(0);
929 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), minValue, TEST_LOCATION );
931 // Remove the constraint, then set new value
932 actor.RemoveConstraints();
933 actor.SetProperty( index, lesserValue );
935 // Constraint should have been removed
936 application.SendNotification();
937 application.Render(0);
938 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), lesserValue, TEST_LOCATION );
939 application.Render(0);
940 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), lesserValue, TEST_LOCATION );
944 int UtcDaliConstraintNewVector4(void)
946 TestApplication application;
948 Actor actor = Actor::New();
950 // Register a Vector4 property
951 Vector4 startValue( 1.0f, 1.0f, 1.0f, 1.0f );
952 Property::Index index = actor.RegisterProperty( "test-property", startValue );
953 Stage::GetCurrent().Add(actor);
954 DALI_TEST_CHECK( actor.GetProperty<Vector4>(index) == startValue );
957 * Test that the Constraint is correctly applied on a clean Node
959 application.SendNotification();
960 application.Render(0);
961 DALI_TEST_CHECK( actor.GetProperty<Vector4>(index) == startValue );
962 application.Render(0);
963 DALI_TEST_CHECK( actor.GetProperty<Vector4>(index) == startValue );
964 application.Render(0);
965 DALI_TEST_CHECK( actor.GetProperty<Vector4>(index) == startValue );
969 Vector4 minValue( 2.0f, 2.0f, 2.0f, 2.0f );
970 Constraint constraint = Constraint::New<Vector4>( index, TestAlwaysEqualOrGreaterThanConstraintVector4( minValue ) );
972 actor.ApplyConstraint( constraint );
973 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), startValue, TEST_LOCATION );
975 application.SendNotification();
976 application.Render(0);
978 // Constraint should be fully applied
979 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), minValue, TEST_LOCATION );
981 // Check that nothing has changed after a couple of buffer swaps
982 application.Render(0);
983 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), minValue, TEST_LOCATION );
984 application.Render(0);
985 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), minValue, TEST_LOCATION );
987 // Set to greater than 2.0f, the constraint will allow this
988 Vector4 greaterValue( 3.0f, 3.0f, 3.0f, 3.0f );
989 actor.SetProperty( index, greaterValue );
991 application.SendNotification();
992 application.Render(0);
994 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), greaterValue, TEST_LOCATION );
996 // Check that nothing has changed after a couple of buffer swaps
997 application.Render(0);
998 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), greaterValue, TEST_LOCATION );
999 application.Render(0);
1000 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), greaterValue, TEST_LOCATION );
1002 // Set to less than 2.0f, the constraint will NOT allow this
1003 Vector4 lesserValue( 1.0f, 1.0f, 1.0f, 1.0f );
1004 actor.SetProperty( index, lesserValue );
1006 application.SendNotification();
1007 application.Render(0);
1009 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), minValue/*not lesserValue*/, TEST_LOCATION );
1011 // Check that nothing has changed after a couple of buffer swaps
1012 application.Render(0);
1013 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), minValue, TEST_LOCATION );
1014 application.Render(0);
1015 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), minValue, TEST_LOCATION );
1017 // Remove the constraint, then set new value
1018 actor.RemoveConstraints();
1019 actor.SetProperty( index, lesserValue );
1021 // Constraint should have been removed
1022 application.SendNotification();
1023 application.Render(0);
1024 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), lesserValue, TEST_LOCATION );
1025 application.Render(0);
1026 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), lesserValue, TEST_LOCATION );
1030 int UtcDaliConstraintNewMatrix(void)
1034 TestApplication application;
1036 Actor actor = Actor::New();
1038 // Register a Matrix property
1039 Matrix startValue = Matrix::IDENTITY;
1040 Property::Index index = actor.RegisterProperty( "test-property", startValue );
1041 DALI_TEST_CHECK( index != Property::INVALID_INDEX );
1042 if (index != Property::INVALID_INDEX)
1044 Stage::GetCurrent().Add(actor);
1045 DALI_TEST_CHECK( actor.GetProperty<Matrix>(index) == startValue );
1048 Matrix constraintLimit;
1049 constraintLimit.SetTransformComponents(Vector3::ONE, Quaternion(Radian(Degree(30.0f)), Vector3::YAXIS), Vector3::ZAXIS );
1050 Constraint constraint = Constraint::New<Matrix>( index, TestConstraintMatrix(constraintLimit));
1051 actor.ApplyConstraint( constraint );
1052 DALI_TEST_EQUALS( actor.GetProperty<Matrix>(index), startValue, TEST_LOCATION );
1054 application.SendNotification();
1055 application.Render(0);
1057 DALI_TEST_EQUALS( actor.GetProperty<Matrix>(index), constraintLimit, TEST_LOCATION );
1060 catch (Dali::DaliException& e)
1062 DALI_TEST_PRINT_ASSERT( e );
1068 int UtcDaliConstraintNewMatrix3(void)
1072 TestApplication application;
1074 Actor actor = Actor::New();
1076 // Register a Matrix3 property
1077 Matrix3 startValue(1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f);
1078 Property::Index index = actor.RegisterProperty( "test-property", startValue );
1079 DALI_TEST_CHECK( index != Property::INVALID_INDEX );
1080 if (index != Property::INVALID_INDEX)
1082 Stage::GetCurrent().Add(actor);
1083 DALI_TEST_CHECK( actor.GetProperty<Matrix3>(index) == startValue );
1086 Matrix3 constraintLimit(42.0f, 0.0f, 0.0f, 0.0f, 42.0f, 0.0f, 0.0f, 0.0f, 1.0f);
1087 Constraint constraint = Constraint::New<Matrix3>( index, TestConstraintMatrix3(constraintLimit));
1088 actor.ApplyConstraint( constraint );
1089 DALI_TEST_EQUALS( actor.GetProperty<Matrix3>(index), startValue, 0.001f, TEST_LOCATION );
1091 application.SendNotification();
1092 application.Render(0);
1094 DALI_TEST_EQUALS( actor.GetProperty<Matrix3>(index), constraintLimit, 0.001f, TEST_LOCATION );
1097 catch (Dali::DaliException& e)
1099 DALI_TEST_PRINT_ASSERT( e );
1105 int UtcDaliConstraintNewQuaternion(void)
1107 TestApplication application;
1109 Actor actor = Actor::New();
1111 // Register a Quaternion property
1112 Quaternion startValue( 0.0f, Vector3::YAXIS );
1113 Property::Index index = actor.RegisterProperty( "test-property", startValue );
1114 Stage::GetCurrent().Add(actor);
1115 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), startValue, ROTATION_EPSILON, TEST_LOCATION );
1118 * Test that the Constraint is correctly applied on a clean Node
1120 application.SendNotification();
1121 application.Render(0);
1122 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), startValue, ROTATION_EPSILON, TEST_LOCATION );
1123 application.Render(0);
1124 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), startValue, ROTATION_EPSILON, TEST_LOCATION );
1125 application.Render(0);
1126 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), startValue, ROTATION_EPSILON, TEST_LOCATION );
1130 Quaternion constrainedRotation( M_PI*0.25f, Vector3::YAXIS );
1131 Constraint constraint = Constraint::New<Quaternion>( index, TestConstraintRotation( constrainedRotation ) );
1133 actor.ApplyConstraint( constraint );
1134 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), startValue, ROTATION_EPSILON, TEST_LOCATION );
1136 application.SendNotification();
1137 application.Render(0);
1139 // Constraint should be fully applied
1140 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), constrainedRotation, ROTATION_EPSILON, TEST_LOCATION );
1142 // Check that nothing has changed after a couple of buffer swaps
1143 application.Render(0);
1144 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), constrainedRotation, ROTATION_EPSILON, TEST_LOCATION );
1145 application.Render(0);
1146 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), constrainedRotation, ROTATION_EPSILON, TEST_LOCATION );
1148 // Set to a different rotation, the constraint will NOT allow this
1149 Quaternion differentRotation( M_PI*0.5f, Vector3::YAXIS );
1150 actor.SetProperty( index, differentRotation );
1152 application.SendNotification();
1153 application.Render(0);
1155 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), constrainedRotation/*not differentRotation*/, ROTATION_EPSILON, TEST_LOCATION );
1157 // Check that nothing has changed after a couple of buffer swaps
1158 application.Render(0);
1159 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), constrainedRotation, ROTATION_EPSILON, TEST_LOCATION );
1160 application.Render(0);
1161 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), constrainedRotation, ROTATION_EPSILON, TEST_LOCATION );
1163 // Remove the constraint, then set new value
1164 actor.RemoveConstraints();
1165 actor.SetProperty( index, differentRotation );
1167 // Constraint should have been removed
1168 application.SendNotification();
1169 application.Render(0);
1170 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), differentRotation, ROTATION_EPSILON, TEST_LOCATION );
1171 application.Render(0);
1172 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), differentRotation, ROTATION_EPSILON, TEST_LOCATION );
1176 int UtcDaliConstraintNewOffStageBoolean(void)
1178 TestApplication application;
1180 Actor actor = Actor::New();
1182 // Register a boolean property
1183 bool startValue(false);
1184 Property::Index index = actor.RegisterProperty( "test-property", startValue );
1185 DALI_TEST_CHECK( actor.GetProperty<bool>(index) == startValue );
1187 // Apply constraint to off-stage Actor
1188 Constraint constraint = Constraint::New<bool>( index, TestAlwaysTrueConstraint() );
1189 actor.ApplyConstraint( constraint );
1191 application.SendNotification();
1192 application.Render(0);
1193 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), false, TEST_LOCATION );
1195 // Add actor to stage
1196 Stage::GetCurrent().Add(actor);
1197 application.SendNotification();
1198 application.Render(0);
1200 // Constraint should be fully applied
1201 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), true, TEST_LOCATION );
1203 // Check that nothing has changed after a couple of buffer swaps
1204 application.Render(0);
1205 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), true, TEST_LOCATION );
1206 application.Render(0);
1207 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), true, TEST_LOCATION );
1209 // Take the actor off-stage
1210 Stage::GetCurrent().Remove(actor);
1211 application.SendNotification();
1212 application.Render(0);
1213 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), true, TEST_LOCATION );
1215 // Set a new value; the constraint will not prevent this
1216 actor.SetProperty( index, false );
1217 application.SendNotification();
1218 application.Render(0);
1219 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), false, TEST_LOCATION );
1221 // Add actor to stage (2nd time)
1222 Stage::GetCurrent().Add(actor);
1223 application.SendNotification();
1224 application.Render(0);
1226 // Constraint should be fully applied (2nd time)
1227 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), true, TEST_LOCATION );
1229 // Check that nothing has changed after a couple of buffer swaps
1230 application.Render(0);
1231 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), true, TEST_LOCATION );
1232 application.Render(0);
1233 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), true, TEST_LOCATION );
1235 // Take the actor off-stage (2nd-time)
1236 Stage::GetCurrent().Remove(actor);
1237 application.SendNotification();
1238 application.Render(0);
1239 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), true, TEST_LOCATION );
1241 // Remove the constraint, and set a new value
1242 actor.RemoveConstraints();
1243 actor.SetProperty( index, false );
1244 application.SendNotification();
1245 application.Render(0);
1246 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), false, TEST_LOCATION );
1248 // Add actor to stage (3rd time)
1249 Stage::GetCurrent().Add(actor);
1250 application.SendNotification();
1251 application.Render(0);
1253 // Constraint should be gone
1254 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), false, TEST_LOCATION );
1256 // Check that nothing has changed after a couple of buffer swaps
1257 application.Render(0);
1258 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), false, TEST_LOCATION );
1259 application.Render(0);
1260 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), false, TEST_LOCATION );
1264 int UtcDaliConstraintNewOffStageFloat(void)
1266 TestApplication application;
1268 Actor actor = Actor::New();
1270 // Register a float property
1271 float startValue(1.0f);
1272 Property::Index index = actor.RegisterProperty( "test-property", startValue );
1273 DALI_TEST_CHECK( actor.GetProperty<float>(index) == startValue );
1275 // Apply constraint to off-stage Actor
1276 float constrainedValue( 2.0f );
1277 Constraint constraint = Constraint::New<float>( index, TestConstraintFloat( constrainedValue ) );
1278 actor.ApplyConstraint( constraint );
1280 application.SendNotification();
1281 application.Render(0);
1282 DALI_TEST_EQUALS( actor.GetProperty<float>(index), startValue, TEST_LOCATION );
1284 // Add actor to stage
1285 Stage::GetCurrent().Add(actor);
1286 application.SendNotification();
1287 application.Render(0);
1289 // Constraint should be fully applied
1290 DALI_TEST_EQUALS( actor.GetProperty<float>(index), constrainedValue, TEST_LOCATION );
1292 // Check that nothing has changed after a couple of buffer swaps
1293 application.Render(0);
1294 DALI_TEST_EQUALS( actor.GetProperty<float>(index), constrainedValue, TEST_LOCATION );
1295 application.Render(0);
1296 DALI_TEST_EQUALS( actor.GetProperty<float>(index), constrainedValue, TEST_LOCATION );
1298 // Take the actor off-stage
1299 Stage::GetCurrent().Remove(actor);
1300 application.SendNotification();
1301 application.Render(0);
1302 DALI_TEST_EQUALS( actor.GetProperty<float>(index), constrainedValue, TEST_LOCATION );
1304 // Set back to startValue; the constraint will not prevent this
1305 actor.SetProperty( index, startValue );
1306 application.SendNotification();
1307 application.Render(0);
1308 DALI_TEST_EQUALS( actor.GetProperty<float>(index), startValue, TEST_LOCATION );
1310 // Add actor to stage (2nd time)
1311 Stage::GetCurrent().Add(actor);
1312 application.SendNotification();
1313 application.Render(0);
1315 // Constraint should be fully applied (2nd time)
1316 DALI_TEST_EQUALS( actor.GetProperty<float>(index), constrainedValue, TEST_LOCATION );
1318 // Check that nothing has changed after a couple of buffer swaps
1319 application.Render(0);
1320 DALI_TEST_EQUALS( actor.GetProperty<float>(index), constrainedValue, TEST_LOCATION );
1321 application.Render(0);
1322 DALI_TEST_EQUALS( actor.GetProperty<float>(index), constrainedValue, TEST_LOCATION );
1324 // Take the actor off-stage (2nd-time)
1325 Stage::GetCurrent().Remove(actor);
1326 application.SendNotification();
1327 application.Render(0);
1328 DALI_TEST_EQUALS( actor.GetProperty<float>(index), constrainedValue, TEST_LOCATION );
1330 // Remove the constraint, and set back to startValue
1331 actor.RemoveConstraints();
1332 actor.SetProperty( index, startValue );
1333 application.SendNotification();
1334 application.Render(0);
1335 DALI_TEST_EQUALS( actor.GetProperty<float>(index), startValue, TEST_LOCATION );
1337 // Add actor to stage (3rd time)
1338 Stage::GetCurrent().Add(actor);
1339 application.SendNotification();
1340 application.Render(0);
1342 // Constraint should be gone
1343 DALI_TEST_EQUALS( actor.GetProperty<float>(index), startValue, TEST_LOCATION );
1345 // Check that nothing has changed after a couple of buffer swaps
1346 application.Render(0);
1347 DALI_TEST_EQUALS( actor.GetProperty<float>(index), startValue, TEST_LOCATION );
1348 application.Render(0);
1349 DALI_TEST_EQUALS( actor.GetProperty<float>(index), startValue, TEST_LOCATION );
1353 int UtcDaliConstraintNewOffStageInteger(void)
1355 TestApplication application;
1357 Actor actor = Actor::New();
1359 // Register an integer property
1361 Property::Index index = actor.RegisterProperty( "test-property", startValue );
1362 DALI_TEST_CHECK( actor.GetProperty<int>(index) == startValue );
1364 // Apply constraint to off-stage Actor
1365 int constrainedValue( 2 );
1366 Constraint constraint = Constraint::New<int>( index, TestConstraintInteger( constrainedValue ) );
1367 actor.ApplyConstraint( constraint );
1369 application.SendNotification();
1370 application.Render(0);
1371 DALI_TEST_EQUALS( actor.GetProperty<int>(index), startValue, TEST_LOCATION );
1373 // Add actor to stage
1374 Stage::GetCurrent().Add(actor);
1375 application.SendNotification();
1376 application.Render(0);
1378 // Constraint should be fully applied
1379 DALI_TEST_EQUALS( actor.GetProperty<int>(index), constrainedValue, TEST_LOCATION );
1381 // Check that nothing has changed after a couple of buffer swaps
1382 application.Render(0);
1383 DALI_TEST_EQUALS( actor.GetProperty<int>(index), constrainedValue, TEST_LOCATION );
1384 application.Render(0);
1385 DALI_TEST_EQUALS( actor.GetProperty<int>(index), constrainedValue, TEST_LOCATION );
1387 // Take the actor off-stage
1388 Stage::GetCurrent().Remove(actor);
1389 application.SendNotification();
1390 application.Render(0);
1391 DALI_TEST_EQUALS( actor.GetProperty<int>(index), constrainedValue, TEST_LOCATION );
1393 // Set back to startValue; the constraint will not prevent this
1394 actor.SetProperty( index, startValue );
1395 application.SendNotification();
1396 application.Render(0);
1397 DALI_TEST_EQUALS( actor.GetProperty<int>(index), startValue, TEST_LOCATION );
1399 // Add actor to stage (2nd time)
1400 Stage::GetCurrent().Add(actor);
1401 application.SendNotification();
1402 application.Render(0);
1404 // Constraint should be fully applied (2nd time)
1405 DALI_TEST_EQUALS( actor.GetProperty<int>(index), constrainedValue, TEST_LOCATION );
1407 // Check that nothing has changed after a couple of buffer swaps
1408 application.Render(0);
1409 DALI_TEST_EQUALS( actor.GetProperty<int>(index), constrainedValue, TEST_LOCATION );
1410 application.Render(0);
1411 DALI_TEST_EQUALS( actor.GetProperty<int>(index), constrainedValue, TEST_LOCATION );
1413 // Take the actor off-stage (2nd-time)
1414 Stage::GetCurrent().Remove(actor);
1415 application.SendNotification();
1416 application.Render(0);
1417 DALI_TEST_EQUALS( actor.GetProperty<int>(index), constrainedValue, TEST_LOCATION );
1419 // Remove the constraint, and set back to startValue
1420 actor.RemoveConstraints();
1421 actor.SetProperty( index, startValue );
1422 application.SendNotification();
1423 application.Render(0);
1424 DALI_TEST_EQUALS( actor.GetProperty<int>(index), startValue, TEST_LOCATION );
1426 // Add actor to stage (3rd time)
1427 Stage::GetCurrent().Add(actor);
1428 application.SendNotification();
1429 application.Render(0);
1431 // Constraint should be gone
1432 DALI_TEST_EQUALS( actor.GetProperty<int>(index), startValue, TEST_LOCATION );
1434 // Check that nothing has changed after a couple of buffer swaps
1435 application.Render(0);
1436 DALI_TEST_EQUALS( actor.GetProperty<int>(index), startValue, TEST_LOCATION );
1437 application.Render(0);
1438 DALI_TEST_EQUALS( actor.GetProperty<int>(index), startValue, TEST_LOCATION );
1442 int UtcDaliConstraintNewOffStageVector2(void)
1444 TestApplication application;
1446 Actor actor = Actor::New();
1448 // Register a Vector2 property
1449 Vector2 startValue(1.0f, 1.0f);
1450 Property::Index index = actor.RegisterProperty( "test-property", startValue );
1451 DALI_TEST_CHECK( actor.GetProperty<Vector2>(index) == startValue );
1453 // Apply constraint to off-stage Actor
1454 Vector2 constrainedValue( 2.0f, 2.0f );
1455 Constraint constraint = Constraint::New<Vector2>( index, TestConstraintVector2( constrainedValue ) );
1456 actor.ApplyConstraint( constraint );
1458 application.SendNotification();
1459 application.Render(0);
1460 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), startValue, TEST_LOCATION );
1462 // Add actor to stage
1463 Stage::GetCurrent().Add(actor);
1464 application.SendNotification();
1465 application.Render(0);
1467 // Constraint should be fully applied
1468 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), constrainedValue, TEST_LOCATION );
1470 // Check that nothing has changed after a couple of buffer swaps
1471 application.Render(0);
1472 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), constrainedValue, TEST_LOCATION );
1473 application.Render(0);
1474 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), constrainedValue, TEST_LOCATION );
1476 // Take the actor off-stage
1477 Stage::GetCurrent().Remove(actor);
1478 application.SendNotification();
1479 application.Render(0);
1480 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), constrainedValue, TEST_LOCATION );
1482 // Set back to startValue; the constraint will not prevent this
1483 actor.SetProperty( index, startValue );
1484 application.SendNotification();
1485 application.Render(0);
1486 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), startValue, TEST_LOCATION );
1488 // Add actor to stage (2nd time)
1489 Stage::GetCurrent().Add(actor);
1490 application.SendNotification();
1491 application.Render(0);
1493 // Constraint should be fully applied (2nd time)
1494 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), constrainedValue, TEST_LOCATION );
1496 // Check that nothing has changed after a couple of buffer swaps
1497 application.Render(0);
1498 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), constrainedValue, TEST_LOCATION );
1499 application.Render(0);
1500 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), constrainedValue, TEST_LOCATION );
1502 // Take the actor off-stage (2nd-time)
1503 Stage::GetCurrent().Remove(actor);
1504 application.SendNotification();
1505 application.Render(0);
1506 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), constrainedValue, TEST_LOCATION );
1508 // Remove the constraint, and set back to startValue
1509 actor.RemoveConstraints();
1510 actor.SetProperty( index, startValue );
1511 application.SendNotification();
1512 application.Render(0);
1513 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), startValue, TEST_LOCATION );
1515 // Add actor to stage (3rd time)
1516 Stage::GetCurrent().Add(actor);
1517 application.SendNotification();
1518 application.Render(0);
1520 // Constraint should be gone
1521 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), startValue, TEST_LOCATION );
1523 // Check that nothing has changed after a couple of buffer swaps
1524 application.Render(0);
1525 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), startValue, TEST_LOCATION );
1526 application.Render(0);
1527 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), startValue, TEST_LOCATION );
1531 int UtcDaliConstraintNewOffStageVector3(void)
1533 TestApplication application;
1534 Vector3 startValue(1.0f, 1.0f, 1.0f);
1535 Vector3 constrainedValue = Vector3( 2.0f, 3.0f, 4.0f );
1537 Actor actor = Actor::New();
1538 // Register a Vector3 property
1540 Property::Index index = actor.RegisterProperty( "test-property", startValue );
1541 DALI_TEST_CHECK( actor.GetProperty<Vector3>(index) == startValue );
1543 // Apply constraint to off-stage Actor
1544 Constraint constraint = Constraint::New<Vector3>( index, TestConstraintVector3( constrainedValue ) );
1545 actor.ApplyConstraint( constraint );
1547 application.SendNotification();
1548 application.Render(0);
1549 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), startValue, TEST_LOCATION );
1551 // Add actor to stage
1552 Stage::GetCurrent().Add(actor);
1553 application.SendNotification();
1554 application.Render();
1556 // Constraint should be fully applied
1557 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), constrainedValue, TEST_LOCATION );
1559 // Check that nothing has changed after a couple of buffer swaps
1560 application.Render();
1561 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), constrainedValue, TEST_LOCATION );
1562 application.Render();
1563 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), constrainedValue, TEST_LOCATION );
1565 // Take the actor off-stage
1566 Stage::GetCurrent().Remove(actor);
1567 application.SendNotification();
1568 application.Render();
1569 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), constrainedValue, TEST_LOCATION );
1571 // Set back to startValue; the constraint will not prevent this
1572 Vector3 intermediateValue(5.0f, 6.0f, 7.0f);
1573 actor.SetProperty( index, intermediateValue );
1574 application.SendNotification();
1575 application.Render();
1576 application.Render(); // ensure both buffers are set to intermediateValue
1577 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), intermediateValue, TEST_LOCATION );
1579 // Add actor to stage (2nd time)
1580 Stage::GetCurrent().Add(actor);
1581 application.SendNotification();
1582 application.Render();
1584 // Constraint should be fully applied (2nd time)
1585 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), constrainedValue, TEST_LOCATION );
1587 // Check that nothing has changed after a couple of buffer swaps
1588 application.Render();
1589 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), constrainedValue, TEST_LOCATION );
1590 application.Render();
1591 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), constrainedValue, TEST_LOCATION );
1593 // Take the actor off-stage (2nd-time)
1594 Stage::GetCurrent().Remove(actor);
1595 application.SendNotification();
1596 application.Render();
1597 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), constrainedValue, TEST_LOCATION );
1599 // Remove the constraint, and set back to startValue
1600 actor.RemoveConstraints();
1601 actor.SetProperty( index, startValue );
1602 application.SendNotification();
1603 application.Render();
1604 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), startValue, TEST_LOCATION );
1606 // Add actor to stage (3rd time)
1607 Stage::GetCurrent().Add(actor);
1608 application.SendNotification();
1609 application.Render();
1611 // Constraint should be gone
1612 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), startValue, TEST_LOCATION );
1614 // Check that nothing has changed after a couple of buffer swaps
1615 application.Render();
1616 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), startValue, TEST_LOCATION );
1617 application.Render();
1618 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), startValue, TEST_LOCATION );
1622 int UtcDaliConstraintNewOffStageVector4(void)
1624 TestApplication application;
1626 Actor actor = Actor::New();
1628 // Register a Vector4 property
1629 Vector4 startValue(1.0f, 1.0f, 1.0f, 1.0f);
1630 Property::Index index = actor.RegisterProperty( "test-property", startValue );
1631 DALI_TEST_CHECK( actor.GetProperty<Vector4>(index) == startValue );
1633 // Apply constraint to off-stage Actor
1634 Vector4 constrainedValue( 2.0f, 2.0f, 2.0f, 2.0f );
1635 Constraint constraint = Constraint::New<Vector4>( index, TestConstraintVector4( constrainedValue ) );
1636 actor.ApplyConstraint( constraint );
1638 application.SendNotification();
1639 application.Render(0);
1640 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), startValue, TEST_LOCATION );
1642 // Add actor to stage
1643 Stage::GetCurrent().Add(actor);
1644 application.SendNotification();
1645 application.Render(0);
1647 // Constraint should be fully applied
1648 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), constrainedValue, TEST_LOCATION );
1650 // Check that nothing has changed after a couple of buffer swaps
1651 application.Render(0);
1652 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), constrainedValue, TEST_LOCATION );
1653 application.Render(0);
1654 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), constrainedValue, TEST_LOCATION );
1656 // Take the actor off-stage
1657 Stage::GetCurrent().Remove(actor);
1658 application.SendNotification();
1659 application.Render(0);
1660 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), constrainedValue, TEST_LOCATION );
1662 // Set back to startValue; the constraint will not prevent this
1663 actor.SetProperty( index, startValue );
1664 application.SendNotification();
1665 application.Render(0);
1666 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), startValue, TEST_LOCATION );
1668 // Add actor to stage (2nd time)
1669 Stage::GetCurrent().Add(actor);
1670 application.SendNotification();
1671 application.Render(0);
1673 // Constraint should be fully applied (2nd time)
1674 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), constrainedValue, TEST_LOCATION );
1676 // Check that nothing has changed after a couple of buffer swaps
1677 application.Render(0);
1678 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), constrainedValue, TEST_LOCATION );
1679 application.Render(0);
1680 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), constrainedValue, TEST_LOCATION );
1682 // Take the actor off-stage (2nd-time)
1683 Stage::GetCurrent().Remove(actor);
1684 application.SendNotification();
1685 application.Render(0);
1686 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), constrainedValue, TEST_LOCATION );
1688 // Remove the constraint, and set back to startValue
1689 actor.RemoveConstraints();
1690 actor.SetProperty( index, startValue );
1691 application.SendNotification();
1692 application.Render(0);
1693 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), startValue, TEST_LOCATION );
1695 // Add actor to stage (3rd time)
1696 Stage::GetCurrent().Add(actor);
1697 application.SendNotification();
1698 application.Render(0);
1700 // Constraint should be gone
1701 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), startValue, TEST_LOCATION );
1703 // Check that nothing has changed after a couple of buffer swaps
1704 application.Render(0);
1705 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), startValue, TEST_LOCATION );
1706 application.Render(0);
1707 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), startValue, TEST_LOCATION );
1711 int UtcDaliConstraintNewOffStageQuaternion(void)
1713 TestApplication application;
1715 Actor actor = Actor::New();
1717 // Register a Quaternion property
1718 Quaternion startValue( 0.0f, Vector3::YAXIS );
1719 Property::Index index = actor.RegisterProperty( "test-property", startValue );
1720 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), startValue, ROTATION_EPSILON, TEST_LOCATION );
1722 // Apply constraint to off-stage Actor
1723 Quaternion constrainedRotation( M_PI*0.25f, Vector3::YAXIS );
1724 Constraint constraint = Constraint::New<Quaternion>( index, TestConstraintRotation( constrainedRotation ) );
1725 actor.ApplyConstraint( constraint );
1727 application.SendNotification();
1728 application.Render(0);
1729 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), startValue, ROTATION_EPSILON, TEST_LOCATION );
1731 // Add actor to stage
1732 Stage::GetCurrent().Add(actor);
1733 application.SendNotification();
1734 application.Render(0);
1736 // Constraint should be fully applied
1737 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), constrainedRotation, ROTATION_EPSILON, TEST_LOCATION );
1739 // Check that nothing has changed after a couple of buffer swaps
1740 application.Render(0);
1741 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), constrainedRotation, ROTATION_EPSILON, TEST_LOCATION );
1742 application.Render(0);
1743 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), constrainedRotation, ROTATION_EPSILON, TEST_LOCATION );
1745 // Take the actor off-stage
1746 Stage::GetCurrent().Remove(actor);
1747 application.SendNotification();
1748 application.Render(0);
1749 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), constrainedRotation, ROTATION_EPSILON, TEST_LOCATION );
1751 // Set back to startValue; the constraint will not prevent this
1752 actor.SetProperty( index, startValue );
1753 application.SendNotification();
1754 application.Render(0);
1755 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), startValue, ROTATION_EPSILON, TEST_LOCATION );
1757 // Add actor to stage (2nd time)
1758 Stage::GetCurrent().Add(actor);
1759 application.SendNotification();
1760 application.Render(0);
1762 // Constraint should be fully applied (2nd time)
1763 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), constrainedRotation, ROTATION_EPSILON, TEST_LOCATION );
1765 // Check that nothing has changed after a couple of buffer swaps
1766 application.Render(0);
1767 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), constrainedRotation, ROTATION_EPSILON, TEST_LOCATION );
1768 application.Render(0);
1769 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), constrainedRotation, ROTATION_EPSILON, TEST_LOCATION );
1771 // Take the actor off-stage (2nd-time)
1772 Stage::GetCurrent().Remove(actor);
1773 application.SendNotification();
1774 application.Render(0);
1775 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), constrainedRotation, ROTATION_EPSILON, TEST_LOCATION );
1777 // Remove the constraint, and set back to startValue
1778 actor.RemoveConstraints();
1779 actor.SetProperty( index, startValue );
1780 application.SendNotification();
1781 application.Render(0);
1782 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), startValue, ROTATION_EPSILON, TEST_LOCATION );
1784 // Add actor to stage (3rd time)
1785 Stage::GetCurrent().Add(actor);
1786 application.SendNotification();
1787 application.Render(0);
1789 // Constraint should be gone
1790 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), startValue, ROTATION_EPSILON, TEST_LOCATION );
1792 // Check that nothing has changed after a couple of buffer swaps
1793 application.Render(0);
1794 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), startValue, ROTATION_EPSILON, TEST_LOCATION );
1795 application.Render(0);
1796 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), startValue, ROTATION_EPSILON, TEST_LOCATION );
1800 int UtcDaliConstraintNewLocalInput(void)
1802 TestApplication application;
1804 Actor actor = Actor::New();
1805 Stage::GetCurrent().Add(actor);
1807 Vector3 startValue( 0.0f, 0.0f, 0.0f );
1808 float distanceWhenFullyTransparent( 100.0f );
1811 * Test that the Constraint is correctly applied on a clean Node
1813 application.SendNotification();
1814 application.Render(0);
1815 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1816 application.Render(0);
1817 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1818 application.Render(0);
1819 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1821 // Apply constraint with a local input property
1823 Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
1824 LocalSource( Actor::COLOR ),
1825 MoveAwayWithFadeConstraint(distanceWhenFullyTransparent) );
1827 actor.ApplyConstraint( constraint );
1828 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1830 application.SendNotification();
1831 application.Render(0);
1833 // Gradually set the color to fully-transparent; the actor should move back
1835 for ( float progress = 0.0f; progress < 1.1f; progress += 0.1f )
1837 actor.SetOpacity( 1.0f - progress );
1839 application.SendNotification();
1840 application.Render(0);
1841 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), ( startValue - Vector3(0.0f, 0.0f, progress*distanceWhenFullyTransparent) ), POSITION_EPSILON, TEST_LOCATION );
1843 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), ( startValue - Vector3(0.0f, 0.0f, distanceWhenFullyTransparent) ), POSITION_EPSILON, TEST_LOCATION );
1847 int UtcDaliConstraintNewParentInput(void)
1849 TestApplication application;
1851 Actor parent = Actor::New();
1852 Vector3 parentStartSize( 100.0f, 100.0f, 0.0f );
1853 parent.SetSize( parentStartSize );
1854 Stage::GetCurrent().Add( parent );
1856 Actor actor = Actor::New();
1857 parent.Add( actor );
1859 Vector3 startValue( 0.0f, 0.0f, 0.0f );
1862 * Test that the Constraint is correctly applied on a clean Node
1864 application.SendNotification();
1865 application.Render(0);
1866 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1867 application.Render(0);
1868 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1869 application.Render(0);
1870 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1872 // Apply constraint with a parent input property
1874 Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
1875 ParentSource( Actor::SIZE ),
1876 TestBottomRightAlignConstraint() );
1878 actor.ApplyConstraint( constraint );
1879 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1881 application.SendNotification();
1882 application.Render(0);
1884 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), parentStartSize, TEST_LOCATION );
1885 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), parent.GetCurrentSize(), TEST_LOCATION );
1887 // Gradually shrink the parent; the actor should move inwards
1889 for ( float progress = 0.0f; progress < 1.1f; progress += 0.1f )
1891 Vector3 size( parentStartSize * std::max(0.0f, 1.0f - progress) );
1892 parent.SetSize( size );
1894 application.SendNotification();
1895 application.Render(0);
1897 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), size, POSITION_EPSILON, TEST_LOCATION );
1898 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), parent.GetCurrentSize(), POSITION_EPSILON, TEST_LOCATION );
1900 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), Vector3::ZERO, POSITION_EPSILON, TEST_LOCATION );
1904 int UtcDaliConstraintNewInput1(void)
1906 TestApplication application;
1908 Actor parent = Actor::New();
1909 Vector3 parentStartSize( 100.0f, 100.0f, 0.0f );
1910 parent.SetSize( parentStartSize );
1911 Stage::GetCurrent().Add( parent );
1913 Actor actor = Actor::New();
1914 parent.Add( actor );
1916 Actor sibling1 = Actor::New();
1917 sibling1.SetPosition( Vector3(1.0f, 2.0f, 3.0f) );
1918 parent.Add( sibling1 );
1920 Vector3 startValue( 0.0f, 0.0f, 0.0f );
1923 * Test that the Constraint is correctly applied on a clean Node
1925 application.SendNotification();
1926 application.Render(0);
1927 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1928 application.Render(0);
1929 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1930 application.Render(0);
1931 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1933 // Apply constraint with a parent input property
1935 Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
1936 Source( sibling1, Actor::POSITION ),
1937 MeanPositionConstraint1() );
1939 actor.ApplyConstraint( constraint );
1940 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1942 application.SendNotification();
1943 application.Render(0);
1944 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), sibling1.GetCurrentPosition(), TEST_LOCATION );
1946 // Check that nothing has changed after a couple of buffer swaps
1947 application.Render(0);
1948 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), sibling1.GetCurrentPosition(), TEST_LOCATION );
1949 application.Render(0);
1950 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), sibling1.GetCurrentPosition(), TEST_LOCATION );
1954 int UtcDaliConstraintNewInput2(void)
1956 TestApplication application;
1958 Actor parent = Actor::New();
1959 Vector3 parentStartSize( 100.0f, 100.0f, 0.0f );
1960 parent.SetSize( parentStartSize );
1961 Stage::GetCurrent().Add( parent );
1963 Actor actor = Actor::New();
1964 parent.Add( actor );
1966 Actor sibling1 = Actor::New();
1967 sibling1.SetPosition( Vector3(1.0f, 2.0f, 3.0f) );
1968 parent.Add( sibling1 );
1970 Actor sibling2 = Actor::New();
1971 sibling2.SetPosition( Vector3(300.0f, 300.0f, 300.0f) );
1972 parent.Add( sibling2 );
1974 application.SendNotification();
1975 application.Render(0);
1977 Vector3 startValue( 0.0f, 0.0f, 0.0f );
1978 Vector3 meanValue = sibling1.GetCurrentPosition() +
1979 sibling2.GetCurrentPosition();
1980 meanValue *= (1.0f / 2.0f); // divide by number of siblings
1983 * Test that the Constraint is correctly applied on a clean Node
1985 application.SendNotification();
1986 application.Render(0);
1987 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1988 application.Render(0);
1989 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1990 application.Render(0);
1991 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1993 // Apply constraint with a parent input property
1995 Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
1996 Source( sibling1, Actor::POSITION ),
1997 Source( sibling2, Actor::POSITION ),
1998 MeanPositionConstraint2() );
2000 actor.ApplyConstraint( constraint );
2001 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
2003 application.SendNotification();
2004 application.Render(0);
2005 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION );
2007 // Check that nothing has changed after a couple of buffer swaps
2008 application.Render(0);
2009 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION );
2010 application.Render(0);
2011 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION );
2015 int UtcDaliConstraintNewInput3(void)
2017 TestApplication application;
2019 Actor parent = Actor::New();
2020 Vector3 parentStartSize( 100.0f, 100.0f, 0.0f );
2021 parent.SetSize( parentStartSize );
2022 Stage::GetCurrent().Add( parent );
2024 Actor actor = Actor::New();
2025 parent.Add( actor );
2027 Actor sibling1 = Actor::New();
2028 sibling1.SetPosition( Vector3(1.0f, 2.0f, 3.0f) );
2029 parent.Add( sibling1 );
2031 Actor sibling2 = Actor::New();
2032 sibling2.SetPosition( Vector3(300.0f, 300.0f, 300.0f) );
2033 parent.Add( sibling2 );
2035 Actor sibling3 = Actor::New();
2036 sibling3.SetPosition( Vector3(-100.0f, -10.0f, -1.0f) );
2037 parent.Add( sibling3 );
2039 application.SendNotification();
2040 application.Render(0);
2042 Vector3 startValue( 0.0f, 0.0f, 0.0f );
2043 Vector3 meanValue = sibling1.GetCurrentPosition() +
2044 sibling2.GetCurrentPosition() +
2045 sibling3.GetCurrentPosition();
2046 meanValue *= (1.0f / 3.0f); // divide by number of siblings
2049 * Test that the Constraint is correctly applied on a clean Node
2051 application.SendNotification();
2052 application.Render(0);
2053 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
2054 application.Render(0);
2055 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
2056 application.Render(0);
2057 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
2059 // Apply constraint with a parent input property
2061 Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
2062 Source( sibling1, Actor::POSITION ),
2063 Source( sibling2, Actor::POSITION ),
2064 Source( sibling3, Actor::POSITION ),
2065 MeanPositionConstraint3() );
2067 actor.ApplyConstraint( constraint );
2068 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
2070 application.SendNotification();
2071 application.Render(0);
2072 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION );
2074 // Check that nothing has changed after a couple of buffer swaps
2075 application.Render(0);
2076 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION );
2077 application.Render(0);
2078 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION );
2082 int UtcDaliConstraintNewInput4(void)
2084 TestApplication application;
2086 Actor parent = Actor::New();
2087 Vector3 parentStartSize( 100.0f, 100.0f, 0.0f );
2088 parent.SetSize( parentStartSize );
2089 parent.SetPosition( 10.0f, 10.0f, 10.0f );
2090 Stage::GetCurrent().Add( parent );
2092 Actor actor = Actor::New();
2093 parent.Add( actor );
2095 Actor sibling1 = Actor::New();
2096 sibling1.SetPosition( Vector3(1.0f, 2.0f, 3.0f) );
2097 parent.Add( sibling1 );
2099 Actor sibling2 = Actor::New();
2100 sibling2.SetPosition( Vector3(300.0f, 300.0f, 300.0f) );
2101 parent.Add( sibling2 );
2103 Actor sibling3 = Actor::New();
2104 sibling3.SetPosition( Vector3(-100.0f, -10.0f, -1.0f) );
2105 parent.Add( sibling3 );
2107 application.SendNotification();
2108 application.Render(0);
2110 Vector3 startValue( 0.0f, 0.0f, 0.0f );
2111 Vector3 meanValue = parent.GetCurrentPosition() +
2112 sibling1.GetCurrentPosition() +
2113 sibling2.GetCurrentPosition() +
2114 sibling3.GetCurrentPosition();
2115 meanValue *= (1.0f / 4.0f); // divide by number of positions
2118 * Test that the Constraint is correctly applied on a clean Node
2120 application.SendNotification();
2121 application.Render(0);
2122 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
2123 application.Render(0);
2124 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
2125 application.Render(0);
2126 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
2128 // Apply constraint with a parent input property
2130 Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
2131 Source( sibling1, Actor::POSITION ),
2132 Source( sibling2, Actor::POSITION ),
2133 ParentSource( Actor::POSITION ),
2134 Source( sibling3, Actor::POSITION ),
2135 MeanPositionConstraint4() );
2137 actor.ApplyConstraint( constraint );
2138 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
2140 application.SendNotification();
2141 application.Render(0);
2142 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION );
2144 // Check that nothing has changed after a couple of buffer swaps
2145 application.Render(0);
2146 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION );
2147 application.Render(0);
2148 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION );
2152 int UtcDaliConstraintNewInput5(void)
2154 TestApplication application;
2156 Actor parent = Actor::New();
2157 Vector3 parentStartSize( 100.0f, 100.0f, 0.0f );
2158 parent.SetSize( parentStartSize );
2159 parent.SetPosition( 10.0f, 10.0f, 10.0f );
2160 Stage::GetCurrent().Add( parent );
2162 Actor actor = Actor::New();
2163 parent.Add( actor );
2165 Actor sibling1 = Actor::New();
2166 sibling1.SetPosition( Vector3(1.0f, 2.0f, 3.0f) );
2167 parent.Add( sibling1 );
2169 Actor sibling2 = Actor::New();
2170 sibling2.SetPosition( Vector3(300.0f, 300.0f, 300.0f) );
2171 parent.Add( sibling2 );
2173 Actor sibling3 = Actor::New();
2174 sibling3.SetPosition( Vector3(-100.0f, -10.0f, -1.0f) );
2175 parent.Add( sibling3 );
2177 Actor sibling4 = Actor::New();
2178 sibling4.SetPosition( Vector3(-1.0f, 1.0f, 2.0f) );
2179 parent.Add( sibling4 );
2181 application.SendNotification();
2182 application.Render(0);
2184 Vector3 startValue( 0.0f, 0.0f, 0.0f );
2185 Vector3 meanValue = parent.GetCurrentPosition() +
2186 sibling1.GetCurrentPosition() +
2187 sibling2.GetCurrentPosition() +
2188 sibling3.GetCurrentPosition() +
2189 sibling4.GetCurrentPosition();
2190 meanValue *= (1.0f / 5.0f); // divide by number of positions
2193 * Test that the Constraint is correctly applied on a clean Node
2195 application.SendNotification();
2196 application.Render(0);
2197 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
2198 application.Render(0);
2199 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
2200 application.Render(0);
2201 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
2203 // Apply constraint with a parent input property
2205 Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
2206 Source( sibling1, Actor::POSITION ),
2207 Source( sibling2, Actor::POSITION ),
2208 ParentSource( Actor::POSITION ),
2209 Source( sibling3, Actor::POSITION ),
2210 Source( sibling4, Actor::POSITION ),
2211 MeanPositionConstraint5() );
2213 actor.ApplyConstraint( constraint );
2214 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
2216 application.SendNotification();
2217 application.Render(0);
2218 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION );
2220 // Check that nothing has changed after a couple of buffer swaps
2221 application.Render(0);
2222 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION );
2223 application.Render(0);
2224 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION );
2228 int UtcDaliConstraintNewInput6(void)
2230 TestApplication application;
2232 Actor parent = Actor::New();
2233 Vector3 parentStartSize( 100.0f, 100.0f, 0.0f );
2234 parent.SetSize( parentStartSize );
2235 parent.SetPosition( 10.0f, 10.0f, 10.0f );
2236 Stage::GetCurrent().Add( parent );
2238 Actor actor = Actor::New();
2239 parent.Add( actor );
2241 Actor child = Actor::New();
2242 child.SetPosition( Vector3(7.0f, 7.0f, 7.0f) );
2245 Actor sibling1 = Actor::New();
2246 sibling1.SetPosition( Vector3(1.0f, 2.0f, 3.0f) );
2247 parent.Add( sibling1 );
2249 Actor sibling2 = Actor::New();
2250 sibling2.SetPosition( Vector3(300.0f, 300.0f, 300.0f) );
2251 parent.Add( sibling2 );
2253 Actor sibling3 = Actor::New();
2254 sibling3.SetPosition( Vector3(-100.0f, -10.0f, -1.0f) );
2255 parent.Add( sibling3 );
2257 Actor sibling4 = Actor::New();
2258 sibling4.SetPosition( Vector3(-1.0f, 1.0f, 2.0f) );
2259 parent.Add( sibling4 );
2261 application.SendNotification();
2262 application.Render(0);
2264 Vector3 startValue( 0.0f, 0.0f, 0.0f );
2265 Vector3 meanValue = parent.GetCurrentPosition() +
2266 child.GetCurrentPosition() +
2267 sibling1.GetCurrentPosition() +
2268 sibling2.GetCurrentPosition() +
2269 sibling3.GetCurrentPosition() +
2270 sibling4.GetCurrentPosition();
2271 meanValue *= (1.0f / 6.0f); // divide by number of positions
2274 * Test that the Constraint is correctly applied on a clean Node
2276 application.SendNotification();
2277 application.Render(0);
2278 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
2279 application.Render(0);
2280 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
2281 application.Render(0);
2282 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
2284 // Apply constraint with a parent input property
2286 Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
2287 Source( child, Actor::POSITION ),
2288 Source( sibling1, Actor::POSITION ),
2289 Source( sibling2, Actor::POSITION ),
2290 ParentSource( Actor::POSITION ),
2291 Source( sibling3, Actor::POSITION ),
2292 Source( sibling4, Actor::POSITION ),
2293 MeanPositionConstraint6() );
2295 actor.ApplyConstraint( constraint );
2296 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
2298 application.SendNotification();
2299 application.Render(0);
2300 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION );
2302 // Check that nothing has changed after a couple of buffer swaps
2303 application.Render(0);
2304 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION );
2305 application.Render(0);
2306 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION );
2310 int UtcDaliConstraintDownCast(void)
2312 TestApplication application;
2313 tet_infoline("Testing Dali::Constraint::DownCast()");
2315 Actor actor = Actor::New();
2317 // Register a boolean property
2318 bool startValue(false);
2319 Property::Index index = actor.RegisterProperty( "test-property", startValue );
2320 Constraint constraint = Constraint::New<bool>( index, TestAlwaysTrueConstraint() );
2322 BaseHandle object(constraint);
2324 Constraint constraint2 = Constraint::DownCast(object);
2325 DALI_TEST_CHECK(constraint2);
2327 Constraint constraint3 = DownCast< Constraint >(object);
2328 DALI_TEST_CHECK(constraint3);
2330 BaseHandle unInitializedObject;
2331 Constraint constraint4 = Constraint::DownCast(unInitializedObject);
2332 DALI_TEST_CHECK(!constraint4);
2334 Constraint constraint5 = DownCast< Constraint >(unInitializedObject);
2335 DALI_TEST_CHECK(!constraint5);
2339 int UtcDaliConstraintSetApplyTime(void)
2341 TestApplication application;
2345 Vector4 targetColor(Color::BLACK);
2346 Constraint constraint = Constraint::New<Vector4>( Actor::COLOR, TestColorConstraint(targetColor) );
2347 DALI_TEST_EQUALS(constraint.GetApplyTime(), TimePeriod(0.0f), TEST_LOCATION);
2349 float applySeconds(7.0f);
2350 constraint.SetApplyTime(applySeconds);
2351 DALI_TEST_EQUALS(constraint.GetApplyTime(), TimePeriod(applySeconds), TEST_LOCATION);
2353 // Apply to an actor
2355 Actor actor = Actor::New();
2356 Stage::GetCurrent().Add(actor);
2358 actor.ApplyConstraint( constraint );
2359 DALI_TEST_EQUALS( actor.GetCurrentColor(), Color::WHITE, TEST_LOCATION );
2361 application.SendNotification();
2362 application.Render(static_cast<unsigned int>(applySeconds*200.0f)/* 20% progress */);
2364 // Constraint shouldn't be fully applied yet
2365 Vector4 twentyPercentColor( Color::WHITE.x*0.8f, Color::WHITE.y*0.8f, Color::WHITE.z*0.8f, Color::WHITE.a );
2366 DALI_TEST_EQUALS( actor.GetCurrentColor(), twentyPercentColor, TEST_LOCATION );
2368 // Constraint shouldn't be fully applied yet
2369 application.Render(static_cast<unsigned int>(applySeconds*200.0f)/* 40% progress */);
2370 Vector4 fourtyPercentColor( Color::WHITE.x*0.6f, Color::WHITE.y*0.6f, Color::WHITE.z*0.6f, Color::WHITE.a );
2371 DALI_TEST_EQUALS( actor.GetCurrentColor(), fourtyPercentColor, TEST_LOCATION );
2373 // Constraint shouldn't be fully applied yet
2374 application.Render(static_cast<unsigned int>(applySeconds*200.0f)/* 60% progress */);
2375 Vector4 sixtyPercentColor( Color::WHITE.x*0.4f, Color::WHITE.y*0.4f, Color::WHITE.z*0.4f, Color::WHITE.a );
2376 DALI_TEST_EQUALS( actor.GetCurrentColor(), sixtyPercentColor, TEST_LOCATION );
2378 // Constraint shouldn't be fully applied yet
2379 application.Render(static_cast<unsigned int>(applySeconds*200.0f)/* 80% progress */);
2380 Vector4 eightyPercentColor( Color::WHITE.x*0.2f, Color::WHITE.y*0.2f, Color::WHITE.z*0.2f, Color::WHITE.a );
2381 DALI_TEST_EQUALS( actor.GetCurrentColor(), eightyPercentColor, TEST_LOCATION );
2383 // Constraint should be fully applied
2384 application.Render(static_cast<unsigned int>(applySeconds*200.0f)/* 100% progress */);
2385 DALI_TEST_EQUALS( actor.GetCurrentColor(), targetColor, TEST_LOCATION );
2387 // Constraint should still be fully applied
2388 application.Render(static_cast<unsigned int>(applySeconds*200.0f)/* Still 100% progress */);
2389 DALI_TEST_EQUALS( actor.GetCurrentColor(), targetColor, TEST_LOCATION );
2391 // Check that nothing has changed after a couple of buffer swaps
2392 application.Render(0);
2393 DALI_TEST_EQUALS( actor.GetCurrentColor(), targetColor, TEST_LOCATION );
2394 application.Render(0);
2395 DALI_TEST_EQUALS( actor.GetCurrentColor(), targetColor, TEST_LOCATION );
2399 int UtcDaliConstraintGetApplyTime(void)
2401 TestApplication application;
2403 Constraint constraint = Constraint::New<Vector4>( Actor::COLOR, TestConstraint() );
2404 DALI_TEST_EQUALS(constraint.GetApplyTime(), TimePeriod(0.0f), TEST_LOCATION);
2406 float applySeconds(7.0f);
2407 constraint.SetApplyTime(applySeconds);
2408 DALI_TEST_EQUALS(constraint.GetApplyTime(), TimePeriod(applySeconds), TEST_LOCATION);
2410 constraint.SetApplyTime(applySeconds - 3.0f);
2411 DALI_TEST_EQUALS(constraint.GetApplyTime(), TimePeriod(applySeconds - 3.0f), TEST_LOCATION);
2415 int UtcDaliConstraintSetAlphaFunction(void)
2417 TestApplication application;
2419 Vector3 startValue( Vector3::ZERO );
2420 Vector3 targetValue(100.0f, 100.0f, 100.0f);
2422 Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
2423 TestConstraintVector3( targetValue ) );
2425 // Test the alpha-function itself
2427 AlphaFunction func = constraint.GetAlphaFunction();
2428 DALI_TEST_EQUALS(func(0.1f), 0.1f, TEST_LOCATION); // Default is Linear
2430 // Test that the alpha-function is used correctly
2432 Actor actor = Actor::New();
2433 Stage::GetCurrent().Add(actor);
2435 application.SendNotification();
2436 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2437 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
2438 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2439 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
2440 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2441 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
2443 constraint.SetApplyTime( 10.0f );
2444 actor.ApplyConstraint( constraint );
2446 application.SendNotification();
2447 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2448 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), (targetValue - startValue) * 0.1f, TEST_LOCATION );
2449 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2450 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), (targetValue - startValue) * 0.2f, TEST_LOCATION );
2451 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2452 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), (targetValue - startValue) * 0.3f, TEST_LOCATION );
2453 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2454 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), (targetValue - startValue) * 0.4f, TEST_LOCATION );
2455 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2456 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), (targetValue - startValue) * 0.5f, TEST_LOCATION );
2457 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2458 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), (targetValue - startValue) * 0.6f, TEST_LOCATION );
2459 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2460 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), (targetValue - startValue) * 0.7f, TEST_LOCATION );
2461 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2462 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), (targetValue - startValue) * 0.8f, TEST_LOCATION );
2463 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2464 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), (targetValue - startValue) * 0.9f, TEST_LOCATION );
2465 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2466 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), (targetValue - startValue), TEST_LOCATION );
2468 // Check that the constrained value is stable
2469 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2470 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), (targetValue - startValue), TEST_LOCATION );
2471 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2472 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), (targetValue - startValue), TEST_LOCATION );
2474 // Remove the constraint
2476 actor.RemoveConstraints();
2477 actor.SetPosition( startValue );
2479 application.SendNotification();
2480 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2481 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
2482 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2483 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
2484 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2485 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
2487 // Change to non-linear alpha and retest
2489 constraint.SetAlphaFunction(AlphaFunctions::EaseIn);
2490 func = constraint.GetAlphaFunction();
2491 DALI_TEST_CHECK(func(0.1f) < 0.09f);
2493 actor.ApplyConstraint( constraint );
2495 application.SendNotification();
2496 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2498 DALI_TEST_CHECK( actor.GetProperty<Vector3>( Actor::POSITION ).x > startValue.x );
2499 DALI_TEST_CHECK( actor.GetProperty<Vector3>( Actor::POSITION ).y > startValue.y );
2500 DALI_TEST_CHECK( actor.GetProperty<Vector3>( Actor::POSITION ).z > startValue.z );
2502 Vector3 lessThanTenPercentProgress( (targetValue - startValue) * 0.09f );
2503 DALI_TEST_CHECK( actor.GetProperty<Vector3>( Actor::POSITION ).x < lessThanTenPercentProgress.x );
2504 DALI_TEST_CHECK( actor.GetProperty<Vector3>( Actor::POSITION ).y < lessThanTenPercentProgress.y );
2505 DALI_TEST_CHECK( actor.GetProperty<Vector3>( Actor::POSITION ).z < lessThanTenPercentProgress.z );
2507 application.Render(static_cast<unsigned int>(9000.0f/*9 seconds*/));
2508 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), (targetValue - startValue), TEST_LOCATION );
2510 // Check that the constrained value is stable
2511 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2512 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), (targetValue - startValue), TEST_LOCATION );
2513 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2514 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), (targetValue - startValue), TEST_LOCATION );
2518 int UtcDaliConstraintGetAlphaFunction(void)
2520 TestApplication application;
2522 Constraint constraint = Constraint::New<Vector4>( Actor::COLOR, TestConstraint() );
2524 AlphaFunction func = constraint.GetAlphaFunction();
2525 DALI_TEST_EQUALS(func(0.5f), 0.5f, TEST_LOCATION); // Default is Linear
2529 int UtcDaliConstraintSetRemoveAction(void)
2531 TestApplication application;
2533 Vector3 sourcePosition(0.0f, 0.0f, 0.0f);
2534 Vector3 targetPosition(100.0f, 100.0f, 100.0f);
2536 // Build constraint, with "Discard" remove action
2538 Constraint constraint = Constraint::New<Vector3>( Actor::POSITION, TestPositionConstraint(targetPosition) );
2539 DALI_TEST_EQUALS((unsigned int)constraint.GetRemoveAction(), (unsigned int)Constraint::Bake, TEST_LOCATION);
2541 constraint.SetRemoveAction(Constraint::Discard);
2542 DALI_TEST_EQUALS((unsigned int)constraint.GetRemoveAction(), (unsigned int)Constraint::Discard, TEST_LOCATION);
2544 // Apply to an actor
2546 Actor actor = Actor::New();
2547 Stage::GetCurrent().Add(actor);
2549 actor.ApplyConstraint( constraint );
2550 DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION );
2552 application.SendNotification();
2553 application.Render(100u/*0.1 seconds*/);
2555 // Constraint should be fully applied
2556 DALI_TEST_EQUALS( actor.GetCurrentPosition(), targetPosition, TEST_LOCATION );
2558 // Check that nothing has changed after a couple of buffer swaps
2559 application.Render(0);
2560 DALI_TEST_EQUALS( actor.GetCurrentPosition(), targetPosition, TEST_LOCATION );
2561 application.Render(0);
2562 DALI_TEST_EQUALS( actor.GetCurrentPosition(), targetPosition, TEST_LOCATION );
2564 // Remove from the actor
2565 actor.RemoveConstraints(); // should go back to source position
2567 application.SendNotification();
2568 application.Render(static_cast<unsigned int>(1000.0f));
2570 // Constraint should be fully removed
2571 DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION );
2573 // Constraint should still be fully removed
2574 application.Render(static_cast<unsigned int>(1000.0f)/* Still 100% removal progress */);
2575 DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION );
2577 // Check that nothing has changed after a couple of buffer swaps
2578 application.Render(0);
2579 DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION );
2580 application.Render(0);
2581 DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION );
2585 int UtcDaliConstraintGetRemoveAction(void)
2587 TestApplication application;
2589 Constraint constraint = Constraint::New<Vector4>( Actor::COLOR, TestConstraint() );
2590 DALI_TEST_EQUALS((unsigned int)constraint.GetRemoveAction(), (unsigned int)Constraint::Bake, TEST_LOCATION);
2592 constraint.SetRemoveAction(Constraint::Discard);
2593 DALI_TEST_EQUALS((unsigned int)constraint.GetRemoveAction(), (unsigned int)Constraint::Discard, TEST_LOCATION);
2595 constraint.SetRemoveAction(Constraint::Bake);
2596 DALI_TEST_EQUALS((unsigned int)constraint.GetRemoveAction(), (unsigned int)Constraint::Bake, TEST_LOCATION);
2601 * Test a constraint with non-zero apply-time & zero (immediate) remove-time, where the constraint is removed during the apply-time
2603 int UtcDaliConstraintImmediateRemoveDuringApply(void)
2605 TestApplication application;
2607 Vector3 sourcePosition(0.0f, 0.0f, 0.0f);
2608 Vector3 targetPosition(100.0f, 100.0f, 100.0f);
2612 Constraint constraint = Constraint::New<Vector3>( Actor::POSITION, TestPositionConstraint(targetPosition) );
2613 DALI_TEST_EQUALS((unsigned int)constraint.GetRemoveAction(), (unsigned int)Constraint::Bake, TEST_LOCATION);
2615 float applySeconds(4.0f);
2616 constraint.SetApplyTime(applySeconds);
2617 DALI_TEST_EQUALS(constraint.GetApplyTime(), TimePeriod(applySeconds), TEST_LOCATION);
2619 // Apply to an actor
2621 Actor actor = Actor::New();
2622 Stage::GetCurrent().Add(actor);
2624 actor.ApplyConstraint( constraint );
2625 DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION );
2627 application.SendNotification();
2628 application.Render(static_cast<unsigned int>(applySeconds*250.0f)/* 25% progress */);
2630 // Constraint shouldn't be fully applied yet
2631 Vector3 twentyFivePercent( targetPosition * 0.25f );
2632 DALI_TEST_EQUALS( actor.GetCurrentPosition(), twentyFivePercent, TEST_LOCATION );
2634 application.Render(static_cast<unsigned int>(applySeconds*250.0f)/* 50% progress */);
2636 // Constraint shouldn't be fully applied yet
2637 Vector3 fiftyPercent( targetPosition * 0.5f );
2638 DALI_TEST_EQUALS( actor.GetCurrentPosition(), fiftyPercent, TEST_LOCATION );
2640 // Remove from the actor
2642 actor.RemoveConstraints(); // should go back to source position
2643 application.SendNotification();
2645 // Constraint should be fully removed
2646 application.Render(static_cast<unsigned int>(200.0f /*0.2 seconds*/));
2647 DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION );
2649 // Constraint should still be fully applied
2650 application.Render(static_cast<unsigned int>(200.0f /*0.2 seconds*/));
2651 DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION );
2653 // Check that nothing has changed after a couple of buffer swaps
2654 application.Render(0);
2655 DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION );
2656 application.Render(0);
2657 DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION );
2661 int UtcDaliConstraintActorSize(void)
2663 TestApplication application;
2665 // Build constraint, to make child 20% of parent size
2667 Constraint constraint = Constraint::New<Vector3>( Actor::SIZE,
2668 ParentSource( Actor::SIZE ),
2669 TestRelativeConstraintVector3(0.2f) );
2670 // Apply to a child actor
2672 Actor parent = Actor::New();
2673 Stage::GetCurrent().Add(parent);
2675 Actor child = Actor::New();
2678 child.ApplyConstraint( constraint );
2679 DALI_TEST_EQUALS( child.GetCurrentSize(), Vector3::ZERO, TEST_LOCATION );
2681 // Animate the parent between two sizes
2683 Vector3 targetParentSize(100.0f, 100.0f, 100.0f);
2685 float durationSeconds(10.0f);
2686 Animation animation = Animation::New(durationSeconds);
2687 animation.AnimateTo( Property(parent, Actor::SIZE), targetParentSize );
2690 application.SendNotification();
2692 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 25% progress */);
2693 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize*0.25f, TEST_LOCATION );
2694 DALI_TEST_EQUALS( child.GetCurrentSize(), targetParentSize*0.25f * 0.2f, TEST_LOCATION );
2696 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 50% progress */);
2697 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize*0.5f, TEST_LOCATION );
2698 DALI_TEST_EQUALS( child.GetCurrentSize(), targetParentSize*0.5f * 0.2f, TEST_LOCATION );
2700 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 75% progress */);
2701 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize*0.75f, TEST_LOCATION );
2702 DALI_TEST_EQUALS( child.GetCurrentSize(), targetParentSize*0.75f * 0.2f, TEST_LOCATION );
2704 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 100% progress */);
2705 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize, TEST_LOCATION );
2706 DALI_TEST_EQUALS( child.GetCurrentSize(), targetParentSize * 0.2f, TEST_LOCATION );
2708 // Check that nothing has changed after a couple of buffer swaps
2709 application.Render(0);
2710 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize, TEST_LOCATION );
2711 DALI_TEST_EQUALS( child.GetCurrentSize(), targetParentSize * 0.2f, TEST_LOCATION );
2712 application.Render(0);
2713 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize, TEST_LOCATION );
2714 DALI_TEST_EQUALS( child.GetCurrentSize(), targetParentSize * 0.2f, TEST_LOCATION );
2718 int UtcDaliConstraintActorSizeWidth(void)
2720 TestApplication application;
2722 // Build constraint, to make child 20% of parent width
2724 Constraint constraint = Constraint::New<float>( Actor::SIZE_WIDTH,
2725 ParentSource( Actor::SIZE_WIDTH ),
2726 TestRelativeConstraintFloat(0.2f) );
2727 // Apply to a child actor
2729 Actor parent = Actor::New();
2730 Stage::GetCurrent().Add(parent);
2732 Actor child = Actor::New();
2735 child.ApplyConstraint( constraint );
2736 DALI_TEST_EQUALS( child.GetCurrentSize(), Vector3::ZERO, TEST_LOCATION );
2738 // Animate the parent between two sizes
2740 Vector3 targetParentSize(80.0f, 90.0f, 100.0f);
2742 float durationSeconds(10.0f);
2743 Animation animation = Animation::New(durationSeconds);
2744 animation.AnimateTo( Property(parent, Actor::SIZE), targetParentSize );
2747 application.SendNotification();
2749 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 25% progress */);
2750 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize*0.25f, TEST_LOCATION );
2751 DALI_TEST_EQUALS( child.GetCurrentSize().width, targetParentSize.width*0.25f * 0.2f, TEST_LOCATION );
2752 DALI_TEST_EQUALS( child.GetCurrentSize().height, 0.0f, TEST_LOCATION );
2753 DALI_TEST_EQUALS( child.GetCurrentSize().depth, 0.0f, TEST_LOCATION );
2755 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 50% progress */);
2756 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize*0.5f, TEST_LOCATION );
2757 DALI_TEST_EQUALS( child.GetCurrentSize().width, targetParentSize.width*0.5f * 0.2f, TEST_LOCATION );
2758 DALI_TEST_EQUALS( child.GetCurrentSize().height, 0.0f, TEST_LOCATION );
2759 DALI_TEST_EQUALS( child.GetCurrentSize().depth, 0.0f, TEST_LOCATION );
2761 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 75% progress */);
2762 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize*0.75f, TEST_LOCATION );
2763 DALI_TEST_EQUALS( child.GetCurrentSize().width, targetParentSize.width*0.75f * 0.2f, TEST_LOCATION );
2764 DALI_TEST_EQUALS( child.GetCurrentSize().height, 0.0f, TEST_LOCATION );
2765 DALI_TEST_EQUALS( child.GetCurrentSize().depth, 0.0f, TEST_LOCATION );
2767 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 100% progress */);
2768 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize, TEST_LOCATION );
2769 DALI_TEST_EQUALS( child.GetCurrentSize().width, targetParentSize.width * 0.2f, TEST_LOCATION );
2770 DALI_TEST_EQUALS( child.GetCurrentSize().height, 0.0f, TEST_LOCATION );
2771 DALI_TEST_EQUALS( child.GetCurrentSize().depth, 0.0f, TEST_LOCATION );
2773 // Check that nothing has changed after a couple of buffer swaps
2774 application.Render(0);
2775 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize, TEST_LOCATION );
2776 DALI_TEST_EQUALS( child.GetCurrentSize().width, targetParentSize.width * 0.2f, TEST_LOCATION );
2777 DALI_TEST_EQUALS( child.GetCurrentSize().height, 0.0f, TEST_LOCATION );
2778 DALI_TEST_EQUALS( child.GetCurrentSize().depth, 0.0f, TEST_LOCATION );
2780 application.Render(0);
2781 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize, TEST_LOCATION );
2782 DALI_TEST_EQUALS( child.GetCurrentSize().width, targetParentSize.width * 0.2f, TEST_LOCATION );
2783 DALI_TEST_EQUALS( child.GetCurrentSize().height, 0.0f, TEST_LOCATION );
2784 DALI_TEST_EQUALS( child.GetCurrentSize().depth, 0.0f, TEST_LOCATION );
2788 int UtcDaliConstraintActorSizeHeight(void)
2790 TestApplication application;
2792 // Build constraint, to make child 20% of parent height
2794 Constraint constraint = Constraint::New<float>( Actor::SIZE_HEIGHT,
2795 ParentSource( Actor::SIZE_HEIGHT ),
2796 TestRelativeConstraintFloat(0.2f) );
2797 // Apply to a child actor
2799 Actor parent = Actor::New();
2800 Stage::GetCurrent().Add(parent);
2802 Actor child = Actor::New();
2805 child.ApplyConstraint( constraint );
2806 DALI_TEST_EQUALS( child.GetCurrentSize(), Vector3::ZERO, TEST_LOCATION );
2808 // Animate the parent between two sizes
2810 Vector3 targetParentSize(80.0f, 90.0f, 100.0f);
2812 float durationSeconds(10.0f);
2813 Animation animation = Animation::New(durationSeconds);
2814 animation.AnimateTo( Property(parent, Actor::SIZE), targetParentSize );
2817 application.SendNotification();
2819 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 25% progress */);
2820 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize*0.25f, TEST_LOCATION );
2821 DALI_TEST_EQUALS( child.GetCurrentSize().width, 0.0f, TEST_LOCATION );
2822 DALI_TEST_EQUALS( child.GetCurrentSize().height, targetParentSize.height*0.25f * 0.2f, TEST_LOCATION );
2823 DALI_TEST_EQUALS( child.GetCurrentSize().depth, 0.0f, TEST_LOCATION );
2825 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 50% progress */);
2826 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize*0.5f, TEST_LOCATION );
2827 DALI_TEST_EQUALS( child.GetCurrentSize().width, 0.0f, TEST_LOCATION );
2828 DALI_TEST_EQUALS( child.GetCurrentSize().height, targetParentSize.height*0.5f * 0.2f, TEST_LOCATION );
2829 DALI_TEST_EQUALS( child.GetCurrentSize().depth, 0.0f, TEST_LOCATION );
2831 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 75% progress */);
2832 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize*0.75f, TEST_LOCATION );
2833 DALI_TEST_EQUALS( child.GetCurrentSize().width, 0.0f, TEST_LOCATION );
2834 DALI_TEST_EQUALS( child.GetCurrentSize().height, targetParentSize.height*0.75f * 0.2f, TEST_LOCATION );
2835 DALI_TEST_EQUALS( child.GetCurrentSize().depth, 0.0f, TEST_LOCATION );
2837 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 100% progress */);
2838 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize, TEST_LOCATION );
2839 DALI_TEST_EQUALS( child.GetCurrentSize().width, 0.0f, TEST_LOCATION );
2840 DALI_TEST_EQUALS( child.GetCurrentSize().height, targetParentSize.height * 0.2f, TEST_LOCATION );
2841 DALI_TEST_EQUALS( child.GetCurrentSize().depth, 0.0f, TEST_LOCATION );
2843 // Check that nothing has changed after a couple of buffer swaps
2844 application.Render(0);
2845 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize, TEST_LOCATION );
2846 DALI_TEST_EQUALS( child.GetCurrentSize().width, 0.0f, TEST_LOCATION );
2847 DALI_TEST_EQUALS( child.GetCurrentSize().height, targetParentSize.height * 0.2f, TEST_LOCATION );
2848 DALI_TEST_EQUALS( child.GetCurrentSize().depth, 0.0f, TEST_LOCATION );
2850 application.Render(0);
2851 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize, TEST_LOCATION );
2852 DALI_TEST_EQUALS( child.GetCurrentSize().width, 0.0f, TEST_LOCATION );
2853 DALI_TEST_EQUALS( child.GetCurrentSize().height, targetParentSize.height * 0.2f, TEST_LOCATION );
2854 DALI_TEST_EQUALS( child.GetCurrentSize().depth, 0.0f, TEST_LOCATION );
2858 int UtcDaliConstraintActorSizeDepth(void)
2860 TestApplication application;
2862 // Build constraint, to make child 20% of parent height
2864 Constraint constraint = Constraint::New<float>( Actor::SIZE_DEPTH,
2865 ParentSource( Actor::SIZE_DEPTH ),
2866 TestRelativeConstraintFloat(0.2f) );
2867 // Apply to a child actor
2869 Actor parent = Actor::New();
2870 Stage::GetCurrent().Add(parent);
2872 Actor child = Actor::New();
2875 child.ApplyConstraint( constraint );
2876 DALI_TEST_EQUALS( child.GetCurrentSize(), Vector3::ZERO, TEST_LOCATION );
2878 // Animate the parent between two sizes
2880 Vector3 targetParentSize(80.0f, 90.0f, 100.0f);
2882 float durationSeconds(10.0f);
2883 Animation animation = Animation::New(durationSeconds);
2884 animation.AnimateTo( Property(parent, Actor::SIZE), targetParentSize );
2887 application.SendNotification();
2889 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 25% progress */);
2890 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize*0.25f, TEST_LOCATION );
2891 DALI_TEST_EQUALS( child.GetCurrentSize().width, 0.0f, TEST_LOCATION );
2892 DALI_TEST_EQUALS( child.GetCurrentSize().height, 0.0f, TEST_LOCATION );
2893 DALI_TEST_EQUALS( child.GetCurrentSize().depth, targetParentSize.depth*0.25f * 0.2f, TEST_LOCATION );
2895 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 50% progress */);
2896 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize*0.5f, TEST_LOCATION );
2897 DALI_TEST_EQUALS( child.GetCurrentSize().width, 0.0f, TEST_LOCATION );
2898 DALI_TEST_EQUALS( child.GetCurrentSize().height, 0.0f, TEST_LOCATION );
2899 DALI_TEST_EQUALS( child.GetCurrentSize().depth, targetParentSize.depth*0.5f * 0.2f, TEST_LOCATION );
2901 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 75% progress */);
2902 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize*0.75f, TEST_LOCATION );
2903 DALI_TEST_EQUALS( child.GetCurrentSize().width, 0.0f, TEST_LOCATION );
2904 DALI_TEST_EQUALS( child.GetCurrentSize().height, 0.0f, TEST_LOCATION );
2905 DALI_TEST_EQUALS( child.GetCurrentSize().depth, targetParentSize.depth*0.75f * 0.2f, TEST_LOCATION );
2907 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 100% progress */);
2908 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize, TEST_LOCATION );
2909 DALI_TEST_EQUALS( child.GetCurrentSize().width, 0.0f, TEST_LOCATION );
2910 DALI_TEST_EQUALS( child.GetCurrentSize().height, 0.0f, TEST_LOCATION );
2911 DALI_TEST_EQUALS( child.GetCurrentSize().depth, targetParentSize.depth * 0.2f, TEST_LOCATION );
2913 // Check that nothing has changed after a couple of buffer swaps
2914 application.Render(0);
2915 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize, TEST_LOCATION );
2916 DALI_TEST_EQUALS( child.GetCurrentSize().width, 0.0f, TEST_LOCATION );
2917 DALI_TEST_EQUALS( child.GetCurrentSize().height, 0.0f, TEST_LOCATION );
2918 DALI_TEST_EQUALS( child.GetCurrentSize().depth, targetParentSize.depth * 0.2f, TEST_LOCATION );
2920 application.Render(0);
2921 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize, TEST_LOCATION );
2922 DALI_TEST_EQUALS( child.GetCurrentSize().width, 0.0f, TEST_LOCATION );
2923 DALI_TEST_EQUALS( child.GetCurrentSize().height, 0.0f, TEST_LOCATION );
2924 DALI_TEST_EQUALS( child.GetCurrentSize().depth, targetParentSize.depth * 0.2f, TEST_LOCATION );
2928 int UtcDaliConstraintInputWorldPosition(void)
2930 TestApplication application;
2932 Actor parent = Actor::New();
2933 Vector3 parentPosition( 10.0f, 10.0f, 10.0f );
2934 parent.SetPosition( parentPosition );
2935 parent.SetParentOrigin( ParentOrigin::CENTER );
2936 parent.SetAnchorPoint( AnchorPoint::CENTER );
2937 Stage::GetCurrent().Add( parent );
2939 Actor child = Actor::New();
2940 child.SetParentOrigin( ParentOrigin::CENTER );
2941 child.SetAnchorPoint( AnchorPoint::CENTER );
2942 Vector3 childPosition( 10.0f, 10.0f, 10.0f );
2943 child.SetPosition( childPosition );
2944 parent.Add( child );
2946 Actor trackingActor = Actor::New();
2947 trackingActor.SetParentOrigin( ParentOrigin::CENTER );
2948 trackingActor.SetAnchorPoint( AnchorPoint::CENTER );
2949 Stage::GetCurrent().Add( trackingActor );
2951 // The actors should not have a world position yet
2952 DALI_TEST_EQUALS( parent.GetCurrentWorldPosition(), Vector3::ZERO, TEST_LOCATION );
2953 DALI_TEST_EQUALS( child.GetCurrentWorldPosition(), Vector3::ZERO, TEST_LOCATION );
2954 DALI_TEST_EQUALS( trackingActor.GetCurrentWorldPosition(), Vector3::ZERO, TEST_LOCATION );
2956 application.SendNotification();
2957 application.Render(0);
2959 DALI_TEST_EQUALS( parent.GetCurrentPosition(), parentPosition, TEST_LOCATION );
2960 DALI_TEST_EQUALS( child.GetCurrentPosition(), childPosition, TEST_LOCATION );
2961 DALI_TEST_EQUALS( trackingActor.GetCurrentPosition(), Vector3::ZERO, TEST_LOCATION );
2963 DALI_TEST_EQUALS( parent.GetCurrentWorldPosition(), parentPosition, TEST_LOCATION );
2964 Vector3 previousPosition( parentPosition + childPosition );
2965 DALI_TEST_EQUALS( child.GetCurrentWorldPosition(), previousPosition, TEST_LOCATION );
2966 DALI_TEST_EQUALS( trackingActor.GetCurrentWorldPosition(), Vector3::ZERO, TEST_LOCATION );
2968 // Build constraint, to make actor track the world-position of another actor
2969 // Note that the world-position is always from the previous frame, so the tracking actor will lag behind
2971 Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
2972 Source( child, Actor::WORLD_POSITION ),
2973 EqualToConstraint() );
2975 trackingActor.ApplyConstraint( constraint );
2977 application.SendNotification();
2978 application.Render(0);
2980 DALI_TEST_EQUALS( trackingActor.GetCurrentPosition(), previousPosition, TEST_LOCATION );
2982 // Move the actors and try again
2983 Vector3 relativePosition( 5, 5, 5 );
2984 parent.MoveBy( relativePosition );
2986 application.SendNotification();
2987 application.Render(0);
2989 DALI_TEST_EQUALS( parent.GetCurrentPosition(), parentPosition + relativePosition, TEST_LOCATION );
2990 DALI_TEST_EQUALS( child.GetCurrentPosition(), childPosition, TEST_LOCATION );
2992 // The tracking actor lags behind
2993 DALI_TEST_EQUALS( trackingActor.GetCurrentPosition(), previousPosition, TEST_LOCATION );
2995 DALI_TEST_EQUALS( parent.GetCurrentWorldPosition(), parentPosition + relativePosition, TEST_LOCATION );
2996 previousPosition = Vector3( parentPosition + childPosition + relativePosition );
2997 DALI_TEST_EQUALS( child.GetCurrentWorldPosition(), previousPosition, TEST_LOCATION );
2999 // Allow the tracking actor to catch up
3000 application.SendNotification();
3001 application.Render(0);
3003 DALI_TEST_EQUALS( parent.GetCurrentPosition(), parentPosition + relativePosition, TEST_LOCATION );
3004 DALI_TEST_EQUALS( child.GetCurrentPosition(), childPosition, TEST_LOCATION );
3006 // The tracking actor catches up!
3007 DALI_TEST_EQUALS( trackingActor.GetCurrentPosition(), previousPosition, TEST_LOCATION );
3008 DALI_TEST_EQUALS( parent.GetCurrentWorldPosition(), parentPosition + relativePosition, TEST_LOCATION );
3009 DALI_TEST_EQUALS( child.GetCurrentWorldPosition(), previousPosition, TEST_LOCATION );
3013 int UtcDaliConstraintInputWorldRotation(void)
3015 TestApplication application;
3017 Actor parent = Actor::New();
3018 Radian rotationAngle( Degree(90.0f) );
3019 Quaternion rotation( rotationAngle, Vector3::YAXIS );
3020 parent.SetRotation( rotation );
3021 Stage::GetCurrent().Add( parent );
3023 Actor child = Actor::New();
3024 child.SetRotation( rotation );
3025 parent.Add( child );
3027 Actor trackingActor = Actor::New();
3028 Stage::GetCurrent().Add( trackingActor );
3030 // The actors should not have a world rotation yet
3031 DALI_TEST_EQUALS( parent.GetCurrentWorldRotation(), Quaternion(0.0f, Vector3::YAXIS), 0.001, TEST_LOCATION );
3032 DALI_TEST_EQUALS( child.GetCurrentWorldRotation(), Quaternion(0.0f, Vector3::YAXIS), 0.001, TEST_LOCATION );
3034 application.SendNotification();
3035 application.Render(0);
3037 DALI_TEST_EQUALS( parent.GetCurrentRotation(), rotation, 0.001, TEST_LOCATION );
3038 DALI_TEST_EQUALS( child.GetCurrentRotation(), rotation, 0.001, TEST_LOCATION );
3039 DALI_TEST_EQUALS( trackingActor.GetCurrentRotation(), Quaternion(0.0f, Vector3::YAXIS), 0.001, TEST_LOCATION );
3041 DALI_TEST_EQUALS( parent.GetCurrentWorldRotation(), Quaternion( rotationAngle, Vector3::YAXIS ), 0.001, TEST_LOCATION );
3042 Quaternion previousRotation( rotationAngle * 2.0f, Vector3::YAXIS );
3043 DALI_TEST_EQUALS( child.GetCurrentWorldRotation(), previousRotation, 0.001, TEST_LOCATION );
3045 // Build constraint, to make actor track the world-rotation of another actor
3046 // Note that the world-rotation is always from the previous frame, so the tracking actor will lag behind
3048 Constraint constraint = Constraint::New<Quaternion>( Actor::ROTATION,
3049 Source( child, Actor::WORLD_ROTATION ),
3050 EqualToQuaternion() );
3052 trackingActor.ApplyConstraint( constraint );
3054 application.SendNotification();
3055 application.Render(0);
3057 DALI_TEST_EQUALS( trackingActor.GetCurrentRotation(), previousRotation, 0.001, TEST_LOCATION );
3059 // Rotate the actors and try again
3060 parent.RotateBy( rotation );
3062 application.SendNotification();
3063 application.Render(0);
3065 DALI_TEST_EQUALS( parent.GetCurrentRotation(), rotation * rotation, 0.001, TEST_LOCATION );
3066 DALI_TEST_EQUALS( child.GetCurrentRotation(), rotation, 0.001, TEST_LOCATION );
3068 // The tracking actor lags behind
3069 DALI_TEST_EQUALS( trackingActor.GetCurrentRotation(), previousRotation, 0.001, TEST_LOCATION );
3071 DALI_TEST_EQUALS( parent.GetCurrentWorldRotation(), Quaternion( rotationAngle * 2.0f, Vector3::YAXIS ), 0.001, TEST_LOCATION );
3072 previousRotation = Quaternion( rotationAngle * 3.0f, Vector3::YAXIS );
3073 DALI_TEST_EQUALS( child.GetCurrentWorldRotation(), previousRotation, 0.001, TEST_LOCATION );
3075 // Allow the tracking actor to catch up
3076 application.SendNotification();
3077 application.Render(0);
3079 DALI_TEST_EQUALS( parent.GetCurrentRotation(), rotation * rotation, 0.001, TEST_LOCATION );
3080 DALI_TEST_EQUALS( child.GetCurrentRotation(), rotation, 0.001, TEST_LOCATION );
3082 // The tracking actor catches up!
3083 DALI_TEST_EQUALS( trackingActor.GetCurrentRotation(), previousRotation, 0.001, TEST_LOCATION );
3084 DALI_TEST_EQUALS( parent.GetCurrentWorldRotation(), Quaternion( rotationAngle * 2.0f, Vector3::YAXIS ), 0.001, TEST_LOCATION );
3085 DALI_TEST_EQUALS( child.GetCurrentWorldRotation(), previousRotation, 0.001, TEST_LOCATION );
3089 int UtcDaliConstraintInputWorldScale(void)
3091 TestApplication application;
3093 Actor parent = Actor::New();
3094 Vector3 parentScale( 2.0f, 2.0f, 2.0f );
3095 parent.SetScale( parentScale );
3096 Stage::GetCurrent().Add( parent );
3098 Actor child = Actor::New();
3099 Vector3 childScale( 1.0f, 2.0f, 3.0f );
3100 child.SetScale( childScale );
3101 parent.Add( child );
3103 Actor trackingActor = Actor::New();
3104 Stage::GetCurrent().Add( trackingActor );
3106 // The actors should not have a world scale yet
3107 DALI_TEST_EQUALS( parent.GetCurrentWorldScale(), Vector3::ONE, TEST_LOCATION );
3108 DALI_TEST_EQUALS( child.GetCurrentWorldScale(), Vector3::ONE, TEST_LOCATION );
3109 DALI_TEST_EQUALS( trackingActor.GetCurrentWorldScale(), Vector3::ONE, TEST_LOCATION );
3111 application.SendNotification();
3112 application.Render(0);
3114 DALI_TEST_EQUALS( parent.GetCurrentScale(), parentScale, TEST_LOCATION );
3115 DALI_TEST_EQUALS( child.GetCurrentScale(), childScale, TEST_LOCATION );
3116 DALI_TEST_EQUALS( trackingActor.GetCurrentScale(), Vector3::ONE, TEST_LOCATION );
3118 DALI_TEST_EQUALS( parent.GetCurrentWorldScale(), parentScale, TEST_LOCATION );
3119 Vector3 previousScale( parentScale * childScale );
3120 DALI_TEST_EQUALS( child.GetCurrentWorldScale(), previousScale, TEST_LOCATION );
3121 DALI_TEST_EQUALS( trackingActor.GetCurrentScale(), Vector3::ONE, TEST_LOCATION );
3123 // Build constraint, to make actor track the world-scale of another actor
3124 // Note that the world-scale is always from the previous frame, so the tracking actor will lag behind
3126 Constraint constraint = Constraint::New<Vector3>( Actor::SCALE,
3127 Source( child, Actor::WORLD_SCALE ),
3128 EqualToConstraint() );
3130 trackingActor.ApplyConstraint( constraint );
3132 application.SendNotification();
3133 application.Render(0);
3135 DALI_TEST_EQUALS( trackingActor.GetCurrentScale(), previousScale, TEST_LOCATION );
3137 // Scale the actors and try again
3138 Vector3 relativeScale( 3, 3, 3 );
3139 parent.ScaleBy( relativeScale );
3141 application.SendNotification();
3142 application.Render(0);
3144 DALI_TEST_EQUALS( parent.GetCurrentScale(), parentScale * relativeScale, TEST_LOCATION );
3145 DALI_TEST_EQUALS( child.GetCurrentScale(), childScale, TEST_LOCATION );
3147 // The tracking actor lags behind
3148 DALI_TEST_EQUALS( trackingActor.GetCurrentScale(), previousScale, TEST_LOCATION );
3150 DALI_TEST_EQUALS( parent.GetCurrentWorldScale(), parentScale * relativeScale, TEST_LOCATION );
3151 previousScale = Vector3( parentScale * childScale * relativeScale );
3152 DALI_TEST_EQUALS( child.GetCurrentWorldScale(), previousScale, TEST_LOCATION );
3154 // Allow the tracking actor to catch up
3155 application.SendNotification();
3156 application.Render(0);
3158 DALI_TEST_EQUALS( parent.GetCurrentScale(), parentScale * relativeScale, TEST_LOCATION );
3159 DALI_TEST_EQUALS( child.GetCurrentScale(), childScale, TEST_LOCATION );
3161 // The tracking actor catches up!
3162 DALI_TEST_EQUALS( trackingActor.GetCurrentScale(), previousScale, TEST_LOCATION );
3163 DALI_TEST_EQUALS( parent.GetCurrentWorldScale(), parentScale * relativeScale, TEST_LOCATION );
3164 DALI_TEST_EQUALS( child.GetCurrentWorldScale(), previousScale, TEST_LOCATION );
3168 int UtcDaliConstraintInputWorldColor(void)
3170 TestApplication application;
3172 Actor parent = Actor::New();
3173 Vector4 parentColor( 1.0f, 0.5f, 0.0f, 1.0f );
3174 parent.SetColor( parentColor );
3175 Stage::GetCurrent().Add( parent );
3177 Actor child = Actor::New();
3178 Vector4 childColor( 0.5f, 0.5f, 0.5f, 1.0f );
3179 child.SetColor( childColor );
3180 parent.Add( child );
3182 Actor trackingActor = Actor::New();
3183 Stage::GetCurrent().Add( trackingActor );
3185 // The actors should not have a world color yet
3186 DALI_TEST_EQUALS( parent.GetCurrentWorldColor(), Color::WHITE, TEST_LOCATION );
3187 DALI_TEST_EQUALS( child.GetCurrentWorldColor(), Color::WHITE, TEST_LOCATION );
3189 application.SendNotification();
3190 application.Render(0);
3192 DALI_TEST_EQUALS( parent.GetCurrentColor(), parentColor, TEST_LOCATION );
3193 DALI_TEST_EQUALS( child.GetCurrentColor(), childColor, TEST_LOCATION );
3194 DALI_TEST_EQUALS( trackingActor.GetCurrentColor(), Color::WHITE, TEST_LOCATION );
3196 DALI_TEST_EQUALS( parent.GetCurrentWorldColor(), parentColor, TEST_LOCATION );
3197 Vector4 previousColor( childColor );
3198 previousColor.a *= parentColor.a;
3199 DALI_TEST_EQUALS( child.GetCurrentWorldColor(), previousColor, TEST_LOCATION );
3201 // Build constraint, to make actor track the world-color of another actor
3202 // Note that the world-color is always from the previous frame, so the tracking actor will lag behind
3204 Constraint constraint = Constraint::New<Vector4>( Actor::COLOR,
3205 Source( child, Actor::WORLD_COLOR ),
3208 trackingActor.ApplyConstraint( constraint );
3210 application.SendNotification();
3211 application.Render(0);
3213 DALI_TEST_EQUALS( trackingActor.GetCurrentColor(), previousColor, TEST_LOCATION );
3215 // Set the color and try again
3216 Vector4 newChildColor( 0.75f, 0.75f, 0.75f, 1.0f );
3217 child.SetColor( newChildColor );
3219 application.SendNotification();
3220 application.Render(0);
3222 DALI_TEST_EQUALS( parent.GetCurrentColor(), parentColor, TEST_LOCATION );
3223 DALI_TEST_EQUALS( child.GetCurrentColor(), newChildColor, TEST_LOCATION );
3225 // The tracking actor lags behind
3226 DALI_TEST_EQUALS( trackingActor.GetCurrentColor(), previousColor, TEST_LOCATION );
3228 DALI_TEST_EQUALS( parent.GetCurrentWorldColor(), parentColor, TEST_LOCATION );
3229 previousColor = Vector3( newChildColor );
3230 DALI_TEST_EQUALS( child.GetCurrentWorldColor(), previousColor, TEST_LOCATION );
3232 // Allow the tracking actor to catch up
3233 application.SendNotification();
3234 application.Render(0);
3236 DALI_TEST_EQUALS( parent.GetCurrentColor(), parentColor, TEST_LOCATION );
3237 DALI_TEST_EQUALS( child.GetCurrentColor(), newChildColor, TEST_LOCATION );
3239 // The tracking actor catches up!
3240 DALI_TEST_EQUALS( trackingActor.GetCurrentColor(), previousColor, TEST_LOCATION );
3241 DALI_TEST_EQUALS( parent.GetCurrentWorldColor(), parentColor, TEST_LOCATION );
3242 DALI_TEST_EQUALS( child.GetCurrentWorldColor(), previousColor, TEST_LOCATION );
3246 int UtcDaliConstraintInvalidInputProperty(void)
3248 TestApplication application;
3249 Actor actor = Actor::New();
3250 Constraint constraint = Constraint::New<Vector3>( Actor::POSITION, LocalSource( PROPERTY_REGISTRATION_START_INDEX ), EqualToConstraint() );
3252 Stage::GetCurrent().Add( actor );
3254 // Cannot use type registered properties as input to constraints
3257 actor.ApplyConstraint( constraint );
3258 tet_result( TET_FAIL );
3260 catch ( DaliException& e )
3262 DALI_TEST_ASSERT( e, "mTargetObject->IsPropertyAConstraintInput( source.propertyIndex )", TEST_LOCATION );
3267 int UtcDaliBuiltinConstraintParentSize(void)
3269 TestApplication application;
3271 Actor parent = Actor::New();
3272 Vector3 parentSize(9,9,9);
3273 parent.SetSize( parentSize );
3274 Stage::GetCurrent().Add( parent );
3276 Actor actor = Actor::New();
3277 parent.Add( actor );
3279 Vector3 startValue( Vector3::ZERO );
3281 application.SendNotification();
3282 application.Render(0);
3283 DALI_TEST_CHECK( actor.GetCurrentSize() == startValue );
3287 Constraint constraint = Constraint::New<Vector3>( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() );
3288 actor.ApplyConstraint( constraint );
3290 application.SendNotification();
3291 application.Render(0);
3293 // Constraint should be fully applied
3294 DALI_TEST_EQUALS( actor.GetCurrentSize(), parentSize, TEST_LOCATION );
3296 // This should be ignored
3297 actor.SetSize( startValue );
3299 // Check that nothing has changed after a couple of buffer swaps
3300 application.SendNotification();
3301 application.Render(0);
3302 DALI_TEST_EQUALS( actor.GetCurrentSize(), parentSize, TEST_LOCATION );
3303 application.Render(0);
3304 DALI_TEST_EQUALS( actor.GetCurrentSize(), parentSize, TEST_LOCATION );
3306 // Remove the constraint, then set new value
3307 actor.RemoveConstraints();
3308 actor.SetSize( startValue );
3310 // Constraint should have been removed
3311 application.SendNotification();
3312 application.Render(0);
3313 DALI_TEST_EQUALS( actor.GetCurrentSize(), startValue, TEST_LOCATION );
3314 application.Render(0);
3315 DALI_TEST_EQUALS( actor.GetCurrentSize(), startValue, TEST_LOCATION );
3319 int UtcDaliBuiltinConstraintParentSizeRelative(void)
3321 TestApplication application;
3323 Actor parent = Actor::New();
3324 Vector3 parentSize(9,9,9);
3325 parent.SetSize( parentSize );
3326 Stage::GetCurrent().Add( parent );
3328 Actor actor = Actor::New();
3329 parent.Add( actor );
3331 Vector3 startValue( Vector3::ZERO );
3332 Vector3 scale(2,3,4);
3333 Vector3 endValue( parentSize * scale );
3335 application.SendNotification();
3336 application.Render(0);
3337 DALI_TEST_CHECK( actor.GetCurrentSize() == startValue );
3341 Constraint constraint = Constraint::New<Vector3>( Actor::SIZE, ParentSource( Actor::SIZE ), RelativeToConstraint( scale ) );
3342 actor.ApplyConstraint( constraint );
3344 application.SendNotification();
3345 application.Render(0);
3347 // Constraint should be fully applied
3348 DALI_TEST_EQUALS( actor.GetCurrentSize(), endValue, TEST_LOCATION );
3350 // This should be ignored
3351 actor.SetSize( startValue );
3353 // Check that nothing has changed after a couple of buffer swaps
3354 application.SendNotification();
3355 application.Render(0);
3356 DALI_TEST_EQUALS( actor.GetCurrentSize(), endValue, TEST_LOCATION );
3357 application.Render(0);
3358 DALI_TEST_EQUALS( actor.GetCurrentSize(), endValue, TEST_LOCATION );
3360 // Remove the constraint, then set new value
3361 actor.RemoveConstraints();
3362 actor.SetSize( startValue );
3364 // Constraint should have been removed
3365 application.SendNotification();
3366 application.Render(0);
3367 DALI_TEST_EQUALS( actor.GetCurrentSize(), startValue, TEST_LOCATION );
3368 application.Render(0);
3369 DALI_TEST_EQUALS( actor.GetCurrentSize(), startValue, TEST_LOCATION );
3373 int UtcDaliBuiltinConstraintScaleToFitConstraint(void)
3375 TestApplication application;
3377 Actor parent = Actor::New();
3378 Vector3 startParentSize( 10, 10, 10 );
3379 parent.SetSize( startParentSize );
3380 Stage::GetCurrent().Add( parent );
3382 Actor actor = Actor::New();
3383 Vector3 startChildSize( 5, 5, 5 );
3384 actor.SetSize( startChildSize );
3385 parent.Add( actor );
3387 Vector3 endChildSize( 8, 8, 8 );
3388 Vector3 endParentSize( 4, 4, 4 );
3389 Vector3 startChildScale( 2, 2, 2 ); // startParentSize / startChildSize
3390 Vector3 intermediateChildScale( 1.25, 1.25, 1.25 ); // startParentSize / endChildSize
3391 Vector3 endChildScale( 0.5, 0.5, 0.5 ); // endParentSize / endChildSize
3393 application.SendNotification();
3394 application.Render(0);
3395 DALI_TEST_CHECK( actor.GetCurrentSize() == startChildSize );
3399 Constraint constraint = Constraint::New<Vector3>( Actor::SCALE,
3400 LocalSource( Actor::SIZE ),
3401 ParentSource( Actor::SIZE ),
3402 ScaleToFitConstraint() );
3403 actor.ApplyConstraint( constraint );
3405 application.SendNotification();
3406 application.Render(0);
3408 // Constraint should be fully applied, but parent size is larger than child
3409 DALI_TEST_EQUALS( actor.GetCurrentSize(), startChildSize, TEST_LOCATION );
3410 DALI_TEST_EQUALS( actor.GetCurrentScale(), startChildScale, TEST_LOCATION );
3412 // This should be allowed (still less than parent size)
3413 actor.SetSize( endChildSize );
3415 application.SendNotification();
3416 application.Render(0);
3417 DALI_TEST_EQUALS( actor.GetCurrentSize(), endChildSize, TEST_LOCATION );
3418 DALI_TEST_EQUALS( actor.GetCurrentScale(), intermediateChildScale, TEST_LOCATION );
3420 // Reduce the parent size
3421 parent.SetSize( endParentSize );
3423 application.SendNotification();
3424 application.Render(0);
3426 // Constraint should be fully applied
3427 DALI_TEST_EQUALS( actor.GetCurrentSize(), endChildSize, TEST_LOCATION );
3428 DALI_TEST_EQUALS( actor.GetCurrentScale(), endChildScale, TEST_LOCATION );
3429 application.Render(0);
3430 DALI_TEST_EQUALS( actor.GetCurrentSize(), endChildSize, TEST_LOCATION );
3431 DALI_TEST_EQUALS( actor.GetCurrentScale(), endChildScale, TEST_LOCATION );
3435 int UtcDaliBuiltinConstraintScaleToFitKeepAspectRatio(void)
3437 TestApplication application;
3439 Actor parent = Actor::New();
3440 Vector3 parentSize1( 10, 10, 10 );
3441 parent.SetSize( parentSize1 );
3442 Stage::GetCurrent().Add( parent );
3444 Actor actor = Actor::New();
3445 Vector3 childSize( 4, 5, 5 );
3446 actor.SetSize( childSize );
3447 parent.Add( actor );
3449 application.SendNotification();
3450 application.Render(0);
3451 Vector3 childScale1( 1.0f, 1.0f, 1.0f );
3452 DALI_TEST_EQUALS( actor.GetCurrentScale(), childScale1, TEST_LOCATION );
3456 Constraint constraint = Constraint::New<Vector3>( Actor::SCALE,
3457 LocalSource( Actor::SIZE ),
3458 ParentSource( Actor::SIZE ),
3459 ScaleToFitKeepAspectRatioConstraint() );
3460 actor.ApplyConstraint( constraint );
3462 application.SendNotification();
3463 application.Render(0);
3465 // Constraint should be fully applied, but parent size is larger than child
3466 Vector3 childScale2( 2.0f, 2.0f, 2.0f );
3467 DALI_TEST_EQUALS( actor.GetCurrentScale(), childScale2, TEST_LOCATION );
3469 // change parent size
3470 Vector3 parentSize2( 40, 50, 50 );
3471 parent.SetSize( parentSize2 );
3473 application.SendNotification();
3474 application.Render(0);
3476 // Constraint should be fully applied, but parent size is larger than child
3477 Vector3 childScale3( 10.0f, 10.0f, 10.0f );
3478 DALI_TEST_EQUALS( actor.GetCurrentScale(), childScale3, TEST_LOCATION );
3483 int UtcDaliBuiltinConstraintScaleToFillXYKeepAspectRatio(void)
3485 TestApplication application;
3487 Actor parent = Actor::New();
3488 Vector3 parentSize1( 10, 10, 10 );
3489 parent.SetSize( parentSize1 );
3490 Stage::GetCurrent().Add( parent );
3492 Actor actor = Actor::New();
3493 Vector3 childSize( 4, 5, 5 );
3494 actor.SetSize( childSize );
3495 parent.Add( actor );
3497 application.SendNotification();
3498 application.Render(0);
3499 Vector3 childScale1( 1.0f, 1.0f, 1.0f );
3500 DALI_TEST_EQUALS( actor.GetCurrentScale(), childScale1, TEST_LOCATION );
3504 Constraint constraint = Constraint::New<Vector3>( Actor::SCALE,
3505 LocalSource( Actor::SIZE ),
3506 ParentSource( Actor::SIZE ),
3507 ScaleToFillXYKeepAspectRatioConstraint() );
3508 actor.ApplyConstraint( constraint );
3510 application.SendNotification();
3511 application.Render(0);
3513 // Constraint should be fully applied, but parent size is larger than child
3514 float val = 10.f / 4.f;
3515 Vector3 childScale2( val, val, val );
3516 DALI_TEST_EQUALS( actor.GetCurrentScale(), childScale2, TEST_LOCATION );
3518 // change parent size
3519 Vector3 parentSize2( 40, 50, 50 );
3520 parent.SetSize( parentSize2 );
3522 application.SendNotification();
3523 application.Render(0);
3525 // Constraint should be fully applied, but parent size is larger than child
3526 Vector3 childScale3( 10.0f, 10.0f, 10.0f );
3527 DALI_TEST_EQUALS( actor.GetCurrentScale(), childScale3, TEST_LOCATION );
3531 int UtcDaliBuiltinConstraintEqualToConstraint(void)
3533 TestApplication application;
3535 Actor actor1 = Actor::New();
3536 Vector3 startPosition( 10, 10, 10 );
3537 actor1.SetPosition( startPosition );
3538 Stage::GetCurrent().Add( actor1 );
3540 Actor actor2 = Actor::New();
3541 Vector3 startSize( 100, 100, 100 );
3542 actor2.SetSize( startSize );
3543 Stage::GetCurrent().Add( actor2 );
3545 application.SendNotification();
3546 application.Render(0);
3547 DALI_TEST_CHECK( actor1.GetCurrentPosition() == startPosition );
3548 DALI_TEST_CHECK( actor2.GetCurrentSize() == startSize );
3550 // Apply constraint - actor1 size == actor2 position
3552 Constraint constraint = Constraint::New<Vector3>( Actor::SIZE,
3553 Source( actor1, Actor::POSITION ),
3554 EqualToConstraint() );
3555 constraint.SetRemoveAction( Constraint::Discard );
3556 actor2.ApplyConstraint( constraint );
3558 application.SendNotification();
3559 application.Render(0);
3561 // Constraint should be fully applied
3562 DALI_TEST_EQUALS( actor2.GetCurrentSize(), startPosition, TEST_LOCATION );
3565 Vector3 endPosition( 2, 2, 2 );
3566 actor1.SetPosition( endPosition );
3568 application.SendNotification();
3569 application.Render(0);
3571 // Constraint should be fully applied
3572 DALI_TEST_EQUALS( actor2.GetCurrentSize(), endPosition, TEST_LOCATION );
3573 application.Render(0);
3574 DALI_TEST_EQUALS( actor2.GetCurrentSize(), endPosition, TEST_LOCATION );
3577 // Check float variant of constraint
3579 float startOpacity(1.0f);
3580 float endOpacity(0.2f);
3581 actor1.SetOpacity( startOpacity );
3582 actor2.SetOpacity( startOpacity );
3584 application.SendNotification();
3585 application.Render(0);
3586 DALI_TEST_EQUALS( actor1.GetCurrentOpacity(), startOpacity, TEST_LOCATION );
3587 DALI_TEST_EQUALS( actor2.GetCurrentOpacity(), startOpacity, TEST_LOCATION );
3589 Constraint constraint2 = Constraint::New<float>( Actor::COLOR_ALPHA,
3590 Source( actor1, Actor::COLOR_ALPHA ),
3591 EqualToConstraint() );
3592 constraint2.SetRemoveAction( Constraint::Discard );
3593 actor2.ApplyConstraint( constraint2 );
3595 actor1.SetOpacity(endOpacity);
3597 application.SendNotification();
3598 application.Render(0);
3600 DALI_TEST_EQUALS( actor2.GetCurrentOpacity(), endOpacity, 0.000001f, TEST_LOCATION );
3603 // Check Vector4 variant of constraint
3605 actor1.SetColor( Color::GREEN );
3606 actor2.SetColor( Color::RED );
3608 application.SendNotification();
3609 application.Render(0);
3610 DALI_TEST_CHECK( actor1.GetCurrentColor() == Color::GREEN );
3611 DALI_TEST_CHECK( actor2.GetCurrentColor() == Color::RED );
3613 Constraint constraint3 = Constraint::New<Vector4>( Actor::COLOR,
3614 Source( actor1, Actor::COLOR ),
3615 EqualToConstraint() );
3616 constraint3.SetRemoveAction( Constraint::Discard );
3617 actor2.ApplyConstraint( constraint3 );
3618 application.SendNotification();
3619 application.Render(0);
3620 DALI_TEST_CHECK( actor2.GetCurrentColor() == Color::GREEN );
3623 // Check Quaternion variant of constraint
3625 Quaternion q1 = Quaternion( Math::PI_2, Vector3::XAXIS );
3626 Quaternion q2 = Quaternion( Math::PI_4, Vector3::YAXIS );
3627 actor1.SetRotation( q1 );
3628 actor2.SetRotation( q2 );
3630 application.SendNotification();
3631 application.Render(0);
3632 DALI_TEST_EQUALS( actor1.GetCurrentRotation(), q1, 0.01, TEST_LOCATION );
3633 DALI_TEST_EQUALS( actor2.GetCurrentRotation(), q2, 0.01, TEST_LOCATION );
3635 Constraint constraint4 = Constraint::New<Quaternion>( Actor::ROTATION,
3636 Source( actor1, Actor::ROTATION ),
3637 EqualToConstraint() );
3638 constraint4.SetRemoveAction( Constraint::Discard );
3639 actor2.ApplyConstraint( constraint4 );
3640 application.SendNotification();
3641 application.Render(0);
3642 DALI_TEST_EQUALS( actor2.GetCurrentRotation(), q1, 0.01, TEST_LOCATION );
3645 // Check Matrix3 variant
3647 EqualToConstraint equalToConstraint;
3650 a.AsFloat()[0] = 1.f;
3652 b.AsFloat()[0] = 2.f;
3653 PropertyInputAbstraction pi(b);
3655 Matrix3 c = equalToConstraint(a,pi);
3656 DALI_TEST_EQUALS( c.AsFloat()[0], b.AsFloat()[0], 0.01, TEST_LOCATION);
3660 int UtcDaliBuiltinConstraintRelativeToConstraint(void)
3662 TestApplication application;
3664 Actor actor1 = Actor::New();
3665 Vector3 startPosition( 10, 10, 10 );
3666 actor1.SetPosition( startPosition );
3667 Stage::GetCurrent().Add( actor1 );
3669 Actor actor2 = Actor::New();
3670 Vector3 startSize( 100, 100, 100 );
3671 actor2.SetSize( startSize );
3672 Stage::GetCurrent().Add( actor2 );
3674 application.SendNotification();
3675 application.Render(0);
3676 DALI_TEST_CHECK( actor1.GetCurrentPosition() == startPosition );
3677 DALI_TEST_CHECK( actor2.GetCurrentSize() == startSize );
3679 // Apply constraint - actor1 size == actor2 position
3681 RelativeToConstraint( 0.f );
3682 Vector3 scale( 0.5, 0.6, 0.7 );
3683 Constraint constraint = Constraint::New<Vector3>( Actor::SIZE,
3684 Source( actor1, Actor::POSITION ),
3685 RelativeToConstraint( scale ) );
3686 constraint.SetRemoveAction( Constraint::Discard );
3687 actor2.ApplyConstraint( constraint );
3689 application.SendNotification();
3690 application.Render(0);
3692 // Constraint should be fully applied
3693 DALI_TEST_EQUALS( actor2.GetCurrentSize(), scale * startPosition, TEST_LOCATION );
3696 Vector3 endPosition( 2, 2, 2 );
3697 actor1.SetPosition( endPosition );
3699 application.SendNotification();
3700 application.Render(0);
3702 // Constraint should be fully applied
3703 DALI_TEST_EQUALS( actor2.GetCurrentSize(), scale * endPosition, TEST_LOCATION );
3704 application.Render(0);
3705 DALI_TEST_EQUALS( actor2.GetCurrentSize(), scale * endPosition, TEST_LOCATION );
3708 // Check float variant of constraint
3710 float scale2( 0.5f );
3711 float startOpacity(1.0f);
3712 actor1.SetOpacity( startOpacity );
3713 actor2.SetOpacity( startOpacity );
3715 application.SendNotification();
3716 application.Render(0);
3717 DALI_TEST_EQUALS( actor1.GetCurrentOpacity(), startOpacity, TEST_LOCATION );
3718 DALI_TEST_EQUALS( actor2.GetCurrentOpacity(), startOpacity, TEST_LOCATION );
3720 Constraint constraint2 = Constraint::New<float>( Actor::COLOR_ALPHA,
3721 Source( actor1, Actor::COLOR_ALPHA ),
3722 RelativeToConstraintFloat(scale2) );
3723 constraint2.SetRemoveAction( Constraint::Discard );
3724 actor2.ApplyConstraint(constraint2);
3725 application.SendNotification();
3726 application.Render(0);
3728 DALI_TEST_EQUALS( actor2.GetCurrentOpacity(), startOpacity * scale2, TEST_LOCATION );
3732 int UtcDaliBuiltinConstraintFunctions(void)
3734 TestApplication application;
3737 SourceWidthFixedHeight sourceWidthFixedHeight( 10.f );
3740 Vector3 reference(1, 10, 0);
3741 Vector3 value = sourceWidthFixedHeight( current, PropertyInputAbstraction(Vector3::ONE) );
3742 DALI_TEST_EQUALS( reference, value, TEST_LOCATION );
3745 Vector3 reference(10, 10, 0);
3746 Vector3 value = sourceWidthFixedHeight( current, PropertyInputAbstraction(Vector3::ONE*10.f) );
3747 DALI_TEST_EQUALS( reference, value, TEST_LOCATION );
3750 Vector3 reference(10,10,0);
3751 Vector3 value = sourceWidthFixedHeight( current, PropertyInputAbstraction(Vector3::ONE*10.f) );
3752 DALI_TEST_EQUALS( reference, value, TEST_LOCATION );
3757 Quaternion current(0, Vector3::YAXIS);
3758 PropertyInputAbstraction target(Vector3::ZAXIS);
3759 PropertyInputAbstraction targetRotation(Vector3::YAXIS);
3760 PropertyInputAbstraction camera(Vector3::ZERO);
3763 Quaternion reference(1., 0., 0., 0.);
3764 Quaternion value = LookAt( current, target, camera, targetRotation );
3765 DALI_TEST_EQUALS( reference, value, 0.001, TEST_LOCATION );