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 tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
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 tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str() );
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 UtcDaliConstraintSetRemoveTime(void)
2417 TestApplication application;
2419 Vector3 sourcePosition(0.0f, 0.0f, 0.0f);
2420 Vector3 targetPosition(100.0f, 100.0f, 100.0f);
2424 Constraint constraint = Constraint::New<Vector3>( Actor::POSITION, TestPositionConstraint(targetPosition) );
2425 DALI_TEST_EQUALS(constraint.GetRemoveTime(), TimePeriod(0.0f), TEST_LOCATION);
2427 float removeSeconds(8.0f);
2428 constraint.SetRemoveTime(removeSeconds);
2429 DALI_TEST_EQUALS(constraint.GetRemoveTime(), TimePeriod(removeSeconds), TEST_LOCATION);
2431 // Apply to an actor
2433 Actor actor = Actor::New();
2434 Stage::GetCurrent().Add(actor);
2436 actor.ApplyConstraint( constraint );
2437 DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION );
2439 application.SendNotification();
2440 application.Render(100u/*0.1 seconds*/);
2442 // Constraint should be fully applied
2443 DALI_TEST_EQUALS( actor.GetCurrentPosition(), targetPosition, TEST_LOCATION );
2445 // Check that nothing has changed after a couple of buffer swaps
2446 application.Render(0);
2447 DALI_TEST_EQUALS( actor.GetCurrentPosition(), targetPosition, TEST_LOCATION );
2448 application.Render(0);
2449 DALI_TEST_EQUALS( actor.GetCurrentPosition(), targetPosition, TEST_LOCATION );
2451 // Remove from the actor, and set to alternative position
2453 actor.RemoveConstraints();
2455 Vector3 thirdPosition(200.0f, 200.0f, 200.0f);
2456 actor.SetPosition(thirdPosition); // Go back to 3rd position
2458 application.SendNotification();
2459 application.Render(static_cast<unsigned int>(removeSeconds*200.0f)/* 20% removal progress */);
2461 // Constraint shouldn't be fully removed yet
2462 Vector3 twentyPercentBack( targetPosition + (thirdPosition - targetPosition)*0.2f );
2463 DALI_TEST_EQUALS( actor.GetCurrentPosition(), twentyPercentBack, TEST_LOCATION );
2465 application.Render(static_cast<unsigned int>(removeSeconds*200.0f)/* 40% removal progress */);
2467 // Constraint shouldn't be fully removed yet
2468 Vector3 fourtyPercentBack( targetPosition + (thirdPosition - targetPosition)*0.4f );
2469 DALI_TEST_EQUALS( actor.GetCurrentPosition(), fourtyPercentBack, TEST_LOCATION );
2471 application.Render(static_cast<unsigned int>(removeSeconds*200.0f)/* 60% removal progress */);
2473 // Constraint shouldn't be fully removed yet
2474 Vector3 sixtyPercentBack( targetPosition + (thirdPosition - targetPosition)*0.6f );
2475 DALI_TEST_EQUALS( actor.GetCurrentPosition(), sixtyPercentBack, TEST_LOCATION );
2477 application.Render(static_cast<unsigned int>(removeSeconds*200.0f)/* 80% removal progress */);
2479 // Constraint shouldn't be fully removed yet
2480 Vector3 eightyPercentBack( targetPosition + (thirdPosition - targetPosition)*0.8f );
2481 DALI_TEST_EQUALS( actor.GetCurrentPosition(), eightyPercentBack, TEST_LOCATION );
2483 // Constraint should be fully removed
2484 application.Render(static_cast<unsigned int>(removeSeconds*200.0f)/* 100% removal progress */);
2485 DALI_TEST_EQUALS( actor.GetCurrentPosition(), thirdPosition, TEST_LOCATION );
2487 // Constraint should still be fully applied
2488 application.Render(static_cast<unsigned int>(removeSeconds*200.0f)/* Still 100% removal progress */);
2489 DALI_TEST_EQUALS( actor.GetCurrentPosition(), thirdPosition, TEST_LOCATION );
2491 // Check that nothing has changed after a couple of buffer swaps
2492 application.Render(0);
2493 DALI_TEST_EQUALS( actor.GetCurrentPosition(), thirdPosition, TEST_LOCATION );
2494 application.Render(0);
2495 DALI_TEST_EQUALS( actor.GetCurrentPosition(), thirdPosition, TEST_LOCATION );
2499 int UtcDaliConstraintGetRemoveTime(void)
2501 TestApplication application;
2503 Constraint constraint = Constraint::New<Vector4>( Actor::COLOR, TestConstraint() );
2504 DALI_TEST_EQUALS(constraint.GetRemoveTime(), TimePeriod(0.0f), TEST_LOCATION);
2508 int UtcDaliConstraintSetAlphaFunction(void)
2510 TestApplication application;
2512 Vector3 startValue( Vector3::ZERO );
2513 Vector3 targetValue(100.0f, 100.0f, 100.0f);
2515 Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
2516 TestConstraintVector3( targetValue ) );
2518 // Test the alpha-function itself
2520 AlphaFunction func = constraint.GetAlphaFunction();
2521 DALI_TEST_EQUALS(func(0.1f), 0.1f, TEST_LOCATION); // Default is Linear
2523 // Test that the alpha-function is used correctly
2525 Actor actor = Actor::New();
2526 Stage::GetCurrent().Add(actor);
2528 application.SendNotification();
2529 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2530 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
2531 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2532 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
2533 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2534 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
2536 constraint.SetApplyTime( 10.0f );
2537 actor.ApplyConstraint( constraint );
2539 application.SendNotification();
2540 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2541 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), (targetValue - startValue) * 0.1f, TEST_LOCATION );
2542 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2543 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), (targetValue - startValue) * 0.2f, TEST_LOCATION );
2544 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2545 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), (targetValue - startValue) * 0.3f, TEST_LOCATION );
2546 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2547 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), (targetValue - startValue) * 0.4f, TEST_LOCATION );
2548 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2549 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), (targetValue - startValue) * 0.5f, TEST_LOCATION );
2550 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2551 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), (targetValue - startValue) * 0.6f, TEST_LOCATION );
2552 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2553 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), (targetValue - startValue) * 0.7f, TEST_LOCATION );
2554 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2555 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), (targetValue - startValue) * 0.8f, TEST_LOCATION );
2556 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2557 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), (targetValue - startValue) * 0.9f, TEST_LOCATION );
2558 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2559 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), (targetValue - startValue), TEST_LOCATION );
2561 // Check that the constrained value is stable
2562 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2563 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), (targetValue - startValue), TEST_LOCATION );
2564 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2565 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), (targetValue - startValue), TEST_LOCATION );
2567 // Remove the constraint
2569 actor.RemoveConstraints();
2570 actor.SetPosition( startValue );
2572 application.SendNotification();
2573 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2574 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
2575 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2576 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
2577 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2578 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
2580 // Change to non-linear alpha and retest
2582 constraint.SetAlphaFunction(AlphaFunctions::EaseIn);
2583 func = constraint.GetAlphaFunction();
2584 DALI_TEST_CHECK(func(0.1f) < 0.09f);
2586 actor.ApplyConstraint( constraint );
2588 application.SendNotification();
2589 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2591 DALI_TEST_CHECK( actor.GetProperty<Vector3>( Actor::POSITION ).x > startValue.x );
2592 DALI_TEST_CHECK( actor.GetProperty<Vector3>( Actor::POSITION ).y > startValue.y );
2593 DALI_TEST_CHECK( actor.GetProperty<Vector3>( Actor::POSITION ).z > startValue.z );
2595 Vector3 lessThanTenPercentProgress( (targetValue - startValue) * 0.09f );
2596 DALI_TEST_CHECK( actor.GetProperty<Vector3>( Actor::POSITION ).x < lessThanTenPercentProgress.x );
2597 DALI_TEST_CHECK( actor.GetProperty<Vector3>( Actor::POSITION ).y < lessThanTenPercentProgress.y );
2598 DALI_TEST_CHECK( actor.GetProperty<Vector3>( Actor::POSITION ).z < lessThanTenPercentProgress.z );
2600 application.Render(static_cast<unsigned int>(9000.0f/*9 seconds*/));
2601 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), (targetValue - startValue), TEST_LOCATION );
2603 // Check that the constrained value is stable
2604 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2605 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), (targetValue - startValue), TEST_LOCATION );
2606 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2607 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), (targetValue - startValue), TEST_LOCATION );
2611 int UtcDaliConstraintGetAlphaFunction(void)
2613 TestApplication application;
2615 Constraint constraint = Constraint::New<Vector4>( Actor::COLOR, TestConstraint() );
2617 AlphaFunction func = constraint.GetAlphaFunction();
2618 DALI_TEST_EQUALS(func(0.5f), 0.5f, TEST_LOCATION); // Default is Linear
2622 int UtcDaliConstraintSetRemoveAction(void)
2624 TestApplication application;
2626 Vector3 sourcePosition(0.0f, 0.0f, 0.0f);
2627 Vector3 targetPosition(100.0f, 100.0f, 100.0f);
2629 // Build constraint, with "Discard" remove action
2631 Constraint constraint = Constraint::New<Vector3>( Actor::POSITION, TestPositionConstraint(targetPosition) );
2632 DALI_TEST_EQUALS((unsigned int)constraint.GetRemoveAction(), (unsigned int)Constraint::Bake, TEST_LOCATION);
2634 constraint.SetRemoveAction(Constraint::Discard);
2635 DALI_TEST_EQUALS((unsigned int)constraint.GetRemoveAction(), (unsigned int)Constraint::Discard, TEST_LOCATION);
2637 float removeSeconds(8.0f);
2638 constraint.SetRemoveTime(removeSeconds);
2639 DALI_TEST_EQUALS(constraint.GetRemoveTime(), TimePeriod(removeSeconds), TEST_LOCATION);
2641 // Apply to an actor
2643 Actor actor = Actor::New();
2644 Stage::GetCurrent().Add(actor);
2646 actor.ApplyConstraint( constraint );
2647 DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION );
2649 application.SendNotification();
2650 application.Render(100u/*0.1 seconds*/);
2652 // Constraint should be fully applied
2653 DALI_TEST_EQUALS( actor.GetCurrentPosition(), targetPosition, TEST_LOCATION );
2655 // Check that nothing has changed after a couple of buffer swaps
2656 application.Render(0);
2657 DALI_TEST_EQUALS( actor.GetCurrentPosition(), targetPosition, TEST_LOCATION );
2658 application.Render(0);
2659 DALI_TEST_EQUALS( actor.GetCurrentPosition(), targetPosition, TEST_LOCATION );
2661 // Remove from the actor
2663 actor.RemoveConstraints(); // should go back to source position
2665 application.SendNotification();
2666 application.Render(static_cast<unsigned int>(removeSeconds*200.0f)/* 20% removal progress */);
2668 // Constraint shouldn't be fully removed yet
2669 Vector3 twentyPercentBack( targetPosition * 0.8f );
2670 DALI_TEST_EQUALS( actor.GetCurrentPosition(), twentyPercentBack, TEST_LOCATION );
2672 application.Render(static_cast<unsigned int>(removeSeconds*200.0f)/* 40% removal progress */);
2674 // Constraint shouldn't be fully removed yet
2675 Vector3 fourtyPercentBack( targetPosition * 0.6f );
2676 DALI_TEST_EQUALS( actor.GetCurrentPosition(), fourtyPercentBack, TEST_LOCATION );
2678 application.Render(static_cast<unsigned int>(removeSeconds*200.0f)/* 60% removal progress */);
2680 // Constraint shouldn't be fully removed yet
2681 Vector3 sixtyPercentBack( targetPosition * 0.4f );
2682 DALI_TEST_EQUALS( actor.GetCurrentPosition(), sixtyPercentBack, TEST_LOCATION );
2684 application.Render(static_cast<unsigned int>(removeSeconds*200.0f)/* 80% removal progress */);
2686 // Constraint shouldn't be fully removed yet
2687 Vector3 eightyPercentBack( targetPosition * 0.2f );
2688 DALI_TEST_EQUALS( actor.GetCurrentPosition(), eightyPercentBack, TEST_LOCATION );
2690 // Constraint should be fully removed
2691 application.Render(static_cast<unsigned int>(removeSeconds*200.0f)/* 100% removal progress */);
2692 DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION );
2694 // Constraint should still be fully applied
2695 application.Render(static_cast<unsigned int>(removeSeconds*200.0f)/* Still 100% removal progress */);
2696 DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION );
2698 // Check that nothing has changed after a couple of buffer swaps
2699 application.Render(0);
2700 DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION );
2701 application.Render(0);
2702 DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION );
2706 int UtcDaliConstraintGetRemoveAction(void)
2708 TestApplication application;
2710 Constraint constraint = Constraint::New<Vector4>( Actor::COLOR, TestConstraint() );
2711 DALI_TEST_EQUALS((unsigned int)constraint.GetRemoveAction(), (unsigned int)Constraint::Bake, TEST_LOCATION);
2713 constraint.SetRemoveAction(Constraint::Discard);
2714 DALI_TEST_EQUALS((unsigned int)constraint.GetRemoveAction(), (unsigned int)Constraint::Discard, TEST_LOCATION);
2716 constraint.SetRemoveAction(Constraint::Bake);
2717 DALI_TEST_EQUALS((unsigned int)constraint.GetRemoveAction(), (unsigned int)Constraint::Bake, TEST_LOCATION);
2722 * Test a constraint with non-zero apply-time and remove-time, where the constraint is removed during the apply-time
2724 int UtcDaliConstraintRemoveDuringApply(void)
2726 TestApplication application;
2728 Vector3 sourcePosition(0.0f, 0.0f, 0.0f);
2729 Vector3 targetPosition(100.0f, 100.0f, 100.0f);
2730 Vector3 halfwayPosition(targetPosition * 0.5f);
2734 Constraint constraint = Constraint::New<Vector3>( Actor::POSITION, TestPositionConstraint(targetPosition) );
2735 DALI_TEST_EQUALS((unsigned int)constraint.GetRemoveAction(), (unsigned int)Constraint::Bake, TEST_LOCATION);
2737 float applySeconds(4.0f);
2738 constraint.SetApplyTime(applySeconds);
2739 DALI_TEST_EQUALS(constraint.GetApplyTime(), TimePeriod(applySeconds), TEST_LOCATION);
2741 float removeSeconds(8.0f);
2742 constraint.SetRemoveTime(removeSeconds);
2743 DALI_TEST_EQUALS(constraint.GetRemoveTime(), TimePeriod(removeSeconds), TEST_LOCATION);
2745 // Apply to an actor
2747 Actor actor = Actor::New();
2748 Stage::GetCurrent().Add(actor);
2750 actor.ApplyConstraint( constraint );
2751 DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION );
2753 application.SendNotification();
2754 application.Render(static_cast<unsigned int>(applySeconds*250.0f)/* 25% progress */);
2756 // Constraint shouldn't be fully applied yet
2757 Vector3 twentyFivePercent( targetPosition * 0.25f );
2758 DALI_TEST_EQUALS( actor.GetCurrentPosition(), twentyFivePercent, TEST_LOCATION );
2760 application.Render(static_cast<unsigned int>(applySeconds*250.0f)/* 50% progress */);
2762 // Constraint shouldn't be fully applied yet
2763 Vector3 fiftyPercent( targetPosition * 0.5f );
2764 DALI_TEST_EQUALS( actor.GetCurrentPosition(), fiftyPercent, TEST_LOCATION );
2766 // Remove from the actor
2768 actor.RemoveConstraints(); // should go back to source position
2770 application.SendNotification();
2771 application.Render(static_cast<unsigned int>(removeSeconds*100.0f)/* 50% - 5% = 45% progress */);
2773 // Constraint shouldn't be fully removed yet
2774 Vector3 fourtyFivePercent( targetPosition * 0.45f );
2775 DALI_TEST_EQUALS( actor.GetCurrentPosition(), fourtyFivePercent, TEST_LOCATION );
2777 application.Render(static_cast<unsigned int>(removeSeconds*400.0f)/* 50% - 25% = 25% progress */);
2779 // Constraint shouldn't be fully removed yet
2780 DALI_TEST_EQUALS( actor.GetCurrentPosition(), twentyFivePercent, TEST_LOCATION );
2782 // Constraint should be fully removed
2783 application.Render(static_cast<unsigned int>(removeSeconds*500.0f)/* 0% progress */);
2784 DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION );
2786 // Constraint should still be fully applied
2787 application.Render(static_cast<unsigned int>(removeSeconds*200.0f)/* Still 0% progress */);
2788 DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION );
2790 // Check that nothing has changed after a couple of buffer swaps
2791 application.Render(0);
2792 DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION );
2793 application.Render(0);
2794 DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION );
2799 * Test a constraint with non-zero apply-time & zero (immediate) remove-time, where the constraint is removed during the apply-time
2801 int UtcDaliConstraintImmediateRemoveDuringApply(void)
2803 TestApplication application;
2805 Vector3 sourcePosition(0.0f, 0.0f, 0.0f);
2806 Vector3 targetPosition(100.0f, 100.0f, 100.0f);
2810 Constraint constraint = Constraint::New<Vector3>( Actor::POSITION, TestPositionConstraint(targetPosition) );
2811 DALI_TEST_EQUALS((unsigned int)constraint.GetRemoveAction(), (unsigned int)Constraint::Bake, TEST_LOCATION);
2813 float applySeconds(4.0f);
2814 constraint.SetApplyTime(applySeconds);
2815 DALI_TEST_EQUALS(constraint.GetApplyTime(), TimePeriod(applySeconds), TEST_LOCATION);
2816 DALI_TEST_EQUALS(constraint.GetRemoveTime(), TimePeriod(0.0f), TEST_LOCATION);
2818 // Apply to an actor
2820 Actor actor = Actor::New();
2821 Stage::GetCurrent().Add(actor);
2823 actor.ApplyConstraint( constraint );
2824 DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION );
2826 application.SendNotification();
2827 application.Render(static_cast<unsigned int>(applySeconds*250.0f)/* 25% progress */);
2829 // Constraint shouldn't be fully applied yet
2830 Vector3 twentyFivePercent( targetPosition * 0.25f );
2831 DALI_TEST_EQUALS( actor.GetCurrentPosition(), twentyFivePercent, TEST_LOCATION );
2833 application.Render(static_cast<unsigned int>(applySeconds*250.0f)/* 50% progress */);
2835 // Constraint shouldn't be fully applied yet
2836 Vector3 fiftyPercent( targetPosition * 0.5f );
2837 DALI_TEST_EQUALS( actor.GetCurrentPosition(), fiftyPercent, TEST_LOCATION );
2839 // Remove from the actor
2841 actor.RemoveConstraints(); // should go back to source position
2842 application.SendNotification();
2844 // Constraint should be fully removed
2845 application.Render(static_cast<unsigned int>(200.0f /*0.2 seconds*/));
2846 DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION );
2848 // Constraint should still be fully applied
2849 application.Render(static_cast<unsigned int>(200.0f /*0.2 seconds*/));
2850 DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION );
2852 // Check that nothing has changed after a couple of buffer swaps
2853 application.Render(0);
2854 DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION );
2855 application.Render(0);
2856 DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION );
2860 int UtcDaliConstraintActorSize(void)
2862 TestApplication application;
2864 // Build constraint, to make child 20% of parent size
2866 Constraint constraint = Constraint::New<Vector3>( Actor::SIZE,
2867 ParentSource( Actor::SIZE ),
2868 TestRelativeConstraintVector3(0.2f) );
2869 // Apply to a child actor
2871 Actor parent = Actor::New();
2872 Stage::GetCurrent().Add(parent);
2874 Actor child = Actor::New();
2877 child.ApplyConstraint( constraint );
2878 DALI_TEST_EQUALS( child.GetCurrentSize(), Vector3::ZERO, TEST_LOCATION );
2880 // Animate the parent between two sizes
2882 Vector3 targetParentSize(100.0f, 100.0f, 100.0f);
2884 float durationSeconds(10.0f);
2885 Animation animation = Animation::New(durationSeconds);
2886 animation.AnimateTo( Property(parent, Actor::SIZE), targetParentSize );
2889 application.SendNotification();
2891 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 25% progress */);
2892 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize*0.25f, TEST_LOCATION );
2893 DALI_TEST_EQUALS( child.GetCurrentSize(), targetParentSize*0.25f * 0.2f, TEST_LOCATION );
2895 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 50% progress */);
2896 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize*0.5f, TEST_LOCATION );
2897 DALI_TEST_EQUALS( child.GetCurrentSize(), targetParentSize*0.5f * 0.2f, TEST_LOCATION );
2899 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 75% progress */);
2900 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize*0.75f, TEST_LOCATION );
2901 DALI_TEST_EQUALS( child.GetCurrentSize(), targetParentSize*0.75f * 0.2f, TEST_LOCATION );
2903 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 100% progress */);
2904 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize, TEST_LOCATION );
2905 DALI_TEST_EQUALS( child.GetCurrentSize(), targetParentSize * 0.2f, TEST_LOCATION );
2907 // Check that nothing has changed after a couple of buffer swaps
2908 application.Render(0);
2909 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize, TEST_LOCATION );
2910 DALI_TEST_EQUALS( child.GetCurrentSize(), targetParentSize * 0.2f, TEST_LOCATION );
2911 application.Render(0);
2912 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize, TEST_LOCATION );
2913 DALI_TEST_EQUALS( child.GetCurrentSize(), targetParentSize * 0.2f, TEST_LOCATION );
2917 int UtcDaliConstraintActorSizeWidth(void)
2919 TestApplication application;
2921 // Build constraint, to make child 20% of parent width
2923 Constraint constraint = Constraint::New<float>( Actor::SIZE_WIDTH,
2924 ParentSource( Actor::SIZE_WIDTH ),
2925 TestRelativeConstraintFloat(0.2f) );
2926 // Apply to a child actor
2928 Actor parent = Actor::New();
2929 Stage::GetCurrent().Add(parent);
2931 Actor child = Actor::New();
2934 child.ApplyConstraint( constraint );
2935 DALI_TEST_EQUALS( child.GetCurrentSize(), Vector3::ZERO, TEST_LOCATION );
2937 // Animate the parent between two sizes
2939 Vector3 targetParentSize(80.0f, 90.0f, 100.0f);
2941 float durationSeconds(10.0f);
2942 Animation animation = Animation::New(durationSeconds);
2943 animation.AnimateTo( Property(parent, Actor::SIZE), targetParentSize );
2946 application.SendNotification();
2948 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 25% progress */);
2949 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize*0.25f, TEST_LOCATION );
2950 DALI_TEST_EQUALS( child.GetCurrentSize().width, targetParentSize.width*0.25f * 0.2f, TEST_LOCATION );
2951 DALI_TEST_EQUALS( child.GetCurrentSize().height, 0.0f, TEST_LOCATION );
2952 DALI_TEST_EQUALS( child.GetCurrentSize().depth, 0.0f, TEST_LOCATION );
2954 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 50% progress */);
2955 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize*0.5f, TEST_LOCATION );
2956 DALI_TEST_EQUALS( child.GetCurrentSize().width, targetParentSize.width*0.5f * 0.2f, TEST_LOCATION );
2957 DALI_TEST_EQUALS( child.GetCurrentSize().height, 0.0f, TEST_LOCATION );
2958 DALI_TEST_EQUALS( child.GetCurrentSize().depth, 0.0f, TEST_LOCATION );
2960 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 75% progress */);
2961 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize*0.75f, TEST_LOCATION );
2962 DALI_TEST_EQUALS( child.GetCurrentSize().width, targetParentSize.width*0.75f * 0.2f, TEST_LOCATION );
2963 DALI_TEST_EQUALS( child.GetCurrentSize().height, 0.0f, TEST_LOCATION );
2964 DALI_TEST_EQUALS( child.GetCurrentSize().depth, 0.0f, TEST_LOCATION );
2966 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 100% progress */);
2967 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize, TEST_LOCATION );
2968 DALI_TEST_EQUALS( child.GetCurrentSize().width, targetParentSize.width * 0.2f, TEST_LOCATION );
2969 DALI_TEST_EQUALS( child.GetCurrentSize().height, 0.0f, TEST_LOCATION );
2970 DALI_TEST_EQUALS( child.GetCurrentSize().depth, 0.0f, TEST_LOCATION );
2972 // Check that nothing has changed after a couple of buffer swaps
2973 application.Render(0);
2974 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize, TEST_LOCATION );
2975 DALI_TEST_EQUALS( child.GetCurrentSize().width, targetParentSize.width * 0.2f, TEST_LOCATION );
2976 DALI_TEST_EQUALS( child.GetCurrentSize().height, 0.0f, TEST_LOCATION );
2977 DALI_TEST_EQUALS( child.GetCurrentSize().depth, 0.0f, TEST_LOCATION );
2979 application.Render(0);
2980 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize, TEST_LOCATION );
2981 DALI_TEST_EQUALS( child.GetCurrentSize().width, targetParentSize.width * 0.2f, TEST_LOCATION );
2982 DALI_TEST_EQUALS( child.GetCurrentSize().height, 0.0f, TEST_LOCATION );
2983 DALI_TEST_EQUALS( child.GetCurrentSize().depth, 0.0f, TEST_LOCATION );
2987 int UtcDaliConstraintActorSizeHeight(void)
2989 TestApplication application;
2991 // Build constraint, to make child 20% of parent height
2993 Constraint constraint = Constraint::New<float>( Actor::SIZE_HEIGHT,
2994 ParentSource( Actor::SIZE_HEIGHT ),
2995 TestRelativeConstraintFloat(0.2f) );
2996 // Apply to a child actor
2998 Actor parent = Actor::New();
2999 Stage::GetCurrent().Add(parent);
3001 Actor child = Actor::New();
3004 child.ApplyConstraint( constraint );
3005 DALI_TEST_EQUALS( child.GetCurrentSize(), Vector3::ZERO, TEST_LOCATION );
3007 // Animate the parent between two sizes
3009 Vector3 targetParentSize(80.0f, 90.0f, 100.0f);
3011 float durationSeconds(10.0f);
3012 Animation animation = Animation::New(durationSeconds);
3013 animation.AnimateTo( Property(parent, Actor::SIZE), targetParentSize );
3016 application.SendNotification();
3018 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 25% progress */);
3019 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize*0.25f, TEST_LOCATION );
3020 DALI_TEST_EQUALS( child.GetCurrentSize().width, 0.0f, TEST_LOCATION );
3021 DALI_TEST_EQUALS( child.GetCurrentSize().height, targetParentSize.height*0.25f * 0.2f, TEST_LOCATION );
3022 DALI_TEST_EQUALS( child.GetCurrentSize().depth, 0.0f, TEST_LOCATION );
3024 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 50% progress */);
3025 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize*0.5f, TEST_LOCATION );
3026 DALI_TEST_EQUALS( child.GetCurrentSize().width, 0.0f, TEST_LOCATION );
3027 DALI_TEST_EQUALS( child.GetCurrentSize().height, targetParentSize.height*0.5f * 0.2f, TEST_LOCATION );
3028 DALI_TEST_EQUALS( child.GetCurrentSize().depth, 0.0f, TEST_LOCATION );
3030 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 75% progress */);
3031 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize*0.75f, TEST_LOCATION );
3032 DALI_TEST_EQUALS( child.GetCurrentSize().width, 0.0f, TEST_LOCATION );
3033 DALI_TEST_EQUALS( child.GetCurrentSize().height, targetParentSize.height*0.75f * 0.2f, TEST_LOCATION );
3034 DALI_TEST_EQUALS( child.GetCurrentSize().depth, 0.0f, TEST_LOCATION );
3036 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 100% progress */);
3037 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize, TEST_LOCATION );
3038 DALI_TEST_EQUALS( child.GetCurrentSize().width, 0.0f, TEST_LOCATION );
3039 DALI_TEST_EQUALS( child.GetCurrentSize().height, targetParentSize.height * 0.2f, TEST_LOCATION );
3040 DALI_TEST_EQUALS( child.GetCurrentSize().depth, 0.0f, TEST_LOCATION );
3042 // Check that nothing has changed after a couple of buffer swaps
3043 application.Render(0);
3044 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize, TEST_LOCATION );
3045 DALI_TEST_EQUALS( child.GetCurrentSize().width, 0.0f, TEST_LOCATION );
3046 DALI_TEST_EQUALS( child.GetCurrentSize().height, targetParentSize.height * 0.2f, TEST_LOCATION );
3047 DALI_TEST_EQUALS( child.GetCurrentSize().depth, 0.0f, TEST_LOCATION );
3049 application.Render(0);
3050 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize, TEST_LOCATION );
3051 DALI_TEST_EQUALS( child.GetCurrentSize().width, 0.0f, TEST_LOCATION );
3052 DALI_TEST_EQUALS( child.GetCurrentSize().height, targetParentSize.height * 0.2f, TEST_LOCATION );
3053 DALI_TEST_EQUALS( child.GetCurrentSize().depth, 0.0f, TEST_LOCATION );
3057 int UtcDaliConstraintActorSizeDepth(void)
3059 TestApplication application;
3061 // Build constraint, to make child 20% of parent height
3063 Constraint constraint = Constraint::New<float>( Actor::SIZE_DEPTH,
3064 ParentSource( Actor::SIZE_DEPTH ),
3065 TestRelativeConstraintFloat(0.2f) );
3066 // Apply to a child actor
3068 Actor parent = Actor::New();
3069 Stage::GetCurrent().Add(parent);
3071 Actor child = Actor::New();
3074 child.ApplyConstraint( constraint );
3075 DALI_TEST_EQUALS( child.GetCurrentSize(), Vector3::ZERO, TEST_LOCATION );
3077 // Animate the parent between two sizes
3079 Vector3 targetParentSize(80.0f, 90.0f, 100.0f);
3081 float durationSeconds(10.0f);
3082 Animation animation = Animation::New(durationSeconds);
3083 animation.AnimateTo( Property(parent, Actor::SIZE), targetParentSize );
3086 application.SendNotification();
3088 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 25% progress */);
3089 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize*0.25f, TEST_LOCATION );
3090 DALI_TEST_EQUALS( child.GetCurrentSize().width, 0.0f, TEST_LOCATION );
3091 DALI_TEST_EQUALS( child.GetCurrentSize().height, 0.0f, TEST_LOCATION );
3092 DALI_TEST_EQUALS( child.GetCurrentSize().depth, targetParentSize.depth*0.25f * 0.2f, TEST_LOCATION );
3094 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 50% progress */);
3095 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize*0.5f, TEST_LOCATION );
3096 DALI_TEST_EQUALS( child.GetCurrentSize().width, 0.0f, TEST_LOCATION );
3097 DALI_TEST_EQUALS( child.GetCurrentSize().height, 0.0f, TEST_LOCATION );
3098 DALI_TEST_EQUALS( child.GetCurrentSize().depth, targetParentSize.depth*0.5f * 0.2f, TEST_LOCATION );
3100 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 75% progress */);
3101 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize*0.75f, TEST_LOCATION );
3102 DALI_TEST_EQUALS( child.GetCurrentSize().width, 0.0f, TEST_LOCATION );
3103 DALI_TEST_EQUALS( child.GetCurrentSize().height, 0.0f, TEST_LOCATION );
3104 DALI_TEST_EQUALS( child.GetCurrentSize().depth, targetParentSize.depth*0.75f * 0.2f, TEST_LOCATION );
3106 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 100% progress */);
3107 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize, TEST_LOCATION );
3108 DALI_TEST_EQUALS( child.GetCurrentSize().width, 0.0f, TEST_LOCATION );
3109 DALI_TEST_EQUALS( child.GetCurrentSize().height, 0.0f, TEST_LOCATION );
3110 DALI_TEST_EQUALS( child.GetCurrentSize().depth, targetParentSize.depth * 0.2f, TEST_LOCATION );
3112 // Check that nothing has changed after a couple of buffer swaps
3113 application.Render(0);
3114 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize, TEST_LOCATION );
3115 DALI_TEST_EQUALS( child.GetCurrentSize().width, 0.0f, TEST_LOCATION );
3116 DALI_TEST_EQUALS( child.GetCurrentSize().height, 0.0f, TEST_LOCATION );
3117 DALI_TEST_EQUALS( child.GetCurrentSize().depth, targetParentSize.depth * 0.2f, TEST_LOCATION );
3119 application.Render(0);
3120 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize, TEST_LOCATION );
3121 DALI_TEST_EQUALS( child.GetCurrentSize().width, 0.0f, TEST_LOCATION );
3122 DALI_TEST_EQUALS( child.GetCurrentSize().height, 0.0f, TEST_LOCATION );
3123 DALI_TEST_EQUALS( child.GetCurrentSize().depth, targetParentSize.depth * 0.2f, TEST_LOCATION );
3127 int UtcDaliConstraintInputWorldPosition(void)
3129 TestApplication application;
3131 Actor parent = Actor::New();
3132 Vector3 parentPosition( 10.0f, 10.0f, 10.0f );
3133 parent.SetPosition( parentPosition );
3134 parent.SetParentOrigin( ParentOrigin::CENTER );
3135 parent.SetAnchorPoint( AnchorPoint::CENTER );
3136 Stage::GetCurrent().Add( parent );
3138 Actor child = Actor::New();
3139 child.SetParentOrigin( ParentOrigin::CENTER );
3140 child.SetAnchorPoint( AnchorPoint::CENTER );
3141 Vector3 childPosition( 10.0f, 10.0f, 10.0f );
3142 child.SetPosition( childPosition );
3143 parent.Add( child );
3145 Actor trackingActor = Actor::New();
3146 trackingActor.SetParentOrigin( ParentOrigin::CENTER );
3147 trackingActor.SetAnchorPoint( AnchorPoint::CENTER );
3148 Stage::GetCurrent().Add( trackingActor );
3150 // The actors should not have a world position yet
3151 DALI_TEST_EQUALS( parent.GetCurrentWorldPosition(), Vector3::ZERO, TEST_LOCATION );
3152 DALI_TEST_EQUALS( child.GetCurrentWorldPosition(), Vector3::ZERO, TEST_LOCATION );
3153 DALI_TEST_EQUALS( trackingActor.GetCurrentWorldPosition(), Vector3::ZERO, TEST_LOCATION );
3155 application.SendNotification();
3156 application.Render(0);
3158 DALI_TEST_EQUALS( parent.GetCurrentPosition(), parentPosition, TEST_LOCATION );
3159 DALI_TEST_EQUALS( child.GetCurrentPosition(), childPosition, TEST_LOCATION );
3160 DALI_TEST_EQUALS( trackingActor.GetCurrentPosition(), Vector3::ZERO, TEST_LOCATION );
3162 DALI_TEST_EQUALS( parent.GetCurrentWorldPosition(), parentPosition, TEST_LOCATION );
3163 Vector3 previousPosition( parentPosition + childPosition );
3164 DALI_TEST_EQUALS( child.GetCurrentWorldPosition(), previousPosition, TEST_LOCATION );
3165 DALI_TEST_EQUALS( trackingActor.GetCurrentWorldPosition(), Vector3::ZERO, TEST_LOCATION );
3167 // Build constraint, to make actor track the world-position of another actor
3168 // Note that the world-position is always from the previous frame, so the tracking actor will lag behind
3170 Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
3171 Source( child, Actor::WORLD_POSITION ),
3172 EqualToConstraint() );
3174 trackingActor.ApplyConstraint( constraint );
3176 application.SendNotification();
3177 application.Render(0);
3179 DALI_TEST_EQUALS( trackingActor.GetCurrentPosition(), previousPosition, TEST_LOCATION );
3181 // Move the actors and try again
3182 Vector3 relativePosition( 5, 5, 5 );
3183 parent.MoveBy( relativePosition );
3185 application.SendNotification();
3186 application.Render(0);
3188 DALI_TEST_EQUALS( parent.GetCurrentPosition(), parentPosition + relativePosition, TEST_LOCATION );
3189 DALI_TEST_EQUALS( child.GetCurrentPosition(), childPosition, TEST_LOCATION );
3191 // The tracking actor lags behind
3192 DALI_TEST_EQUALS( trackingActor.GetCurrentPosition(), previousPosition, TEST_LOCATION );
3194 DALI_TEST_EQUALS( parent.GetCurrentWorldPosition(), parentPosition + relativePosition, TEST_LOCATION );
3195 previousPosition = Vector3( parentPosition + childPosition + relativePosition );
3196 DALI_TEST_EQUALS( child.GetCurrentWorldPosition(), previousPosition, TEST_LOCATION );
3198 // Allow the tracking actor to catch up
3199 application.SendNotification();
3200 application.Render(0);
3202 DALI_TEST_EQUALS( parent.GetCurrentPosition(), parentPosition + relativePosition, TEST_LOCATION );
3203 DALI_TEST_EQUALS( child.GetCurrentPosition(), childPosition, TEST_LOCATION );
3205 // The tracking actor catches up!
3206 DALI_TEST_EQUALS( trackingActor.GetCurrentPosition(), previousPosition, TEST_LOCATION );
3207 DALI_TEST_EQUALS( parent.GetCurrentWorldPosition(), parentPosition + relativePosition, TEST_LOCATION );
3208 DALI_TEST_EQUALS( child.GetCurrentWorldPosition(), previousPosition, TEST_LOCATION );
3212 int UtcDaliConstraintInputWorldRotation(void)
3214 TestApplication application;
3216 Actor parent = Actor::New();
3217 Radian rotationAngle( Degree(90.0f) );
3218 Quaternion rotation( rotationAngle, Vector3::YAXIS );
3219 parent.SetRotation( rotation );
3220 Stage::GetCurrent().Add( parent );
3222 Actor child = Actor::New();
3223 child.SetRotation( rotation );
3224 parent.Add( child );
3226 Actor trackingActor = Actor::New();
3227 Stage::GetCurrent().Add( trackingActor );
3229 // The actors should not have a world rotation yet
3230 DALI_TEST_EQUALS( parent.GetCurrentWorldRotation(), Quaternion(0.0f, Vector3::YAXIS), 0.001, TEST_LOCATION );
3231 DALI_TEST_EQUALS( child.GetCurrentWorldRotation(), Quaternion(0.0f, Vector3::YAXIS), 0.001, TEST_LOCATION );
3233 application.SendNotification();
3234 application.Render(0);
3236 DALI_TEST_EQUALS( parent.GetCurrentRotation(), rotation, 0.001, TEST_LOCATION );
3237 DALI_TEST_EQUALS( child.GetCurrentRotation(), rotation, 0.001, TEST_LOCATION );
3238 DALI_TEST_EQUALS( trackingActor.GetCurrentRotation(), Quaternion(0.0f, Vector3::YAXIS), 0.001, TEST_LOCATION );
3240 DALI_TEST_EQUALS( parent.GetCurrentWorldRotation(), Quaternion( rotationAngle, Vector3::YAXIS ), 0.001, TEST_LOCATION );
3241 Quaternion previousRotation( rotationAngle * 2.0f, Vector3::YAXIS );
3242 DALI_TEST_EQUALS( child.GetCurrentWorldRotation(), previousRotation, 0.001, TEST_LOCATION );
3244 // Build constraint, to make actor track the world-rotation of another actor
3245 // Note that the world-rotation is always from the previous frame, so the tracking actor will lag behind
3247 Constraint constraint = Constraint::New<Quaternion>( Actor::ROTATION,
3248 Source( child, Actor::WORLD_ROTATION ),
3249 EqualToQuaternion() );
3251 trackingActor.ApplyConstraint( constraint );
3253 application.SendNotification();
3254 application.Render(0);
3256 DALI_TEST_EQUALS( trackingActor.GetCurrentRotation(), previousRotation, 0.001, TEST_LOCATION );
3258 // Rotate the actors and try again
3259 parent.RotateBy( rotation );
3261 application.SendNotification();
3262 application.Render(0);
3264 DALI_TEST_EQUALS( parent.GetCurrentRotation(), rotation * rotation, 0.001, TEST_LOCATION );
3265 DALI_TEST_EQUALS( child.GetCurrentRotation(), rotation, 0.001, TEST_LOCATION );
3267 // The tracking actor lags behind
3268 DALI_TEST_EQUALS( trackingActor.GetCurrentRotation(), previousRotation, 0.001, TEST_LOCATION );
3270 DALI_TEST_EQUALS( parent.GetCurrentWorldRotation(), Quaternion( rotationAngle * 2.0f, Vector3::YAXIS ), 0.001, TEST_LOCATION );
3271 previousRotation = Quaternion( rotationAngle * 3.0f, Vector3::YAXIS );
3272 DALI_TEST_EQUALS( child.GetCurrentWorldRotation(), previousRotation, 0.001, TEST_LOCATION );
3274 // Allow the tracking actor to catch up
3275 application.SendNotification();
3276 application.Render(0);
3278 DALI_TEST_EQUALS( parent.GetCurrentRotation(), rotation * rotation, 0.001, TEST_LOCATION );
3279 DALI_TEST_EQUALS( child.GetCurrentRotation(), rotation, 0.001, TEST_LOCATION );
3281 // The tracking actor catches up!
3282 DALI_TEST_EQUALS( trackingActor.GetCurrentRotation(), previousRotation, 0.001, TEST_LOCATION );
3283 DALI_TEST_EQUALS( parent.GetCurrentWorldRotation(), Quaternion( rotationAngle * 2.0f, Vector3::YAXIS ), 0.001, TEST_LOCATION );
3284 DALI_TEST_EQUALS( child.GetCurrentWorldRotation(), previousRotation, 0.001, TEST_LOCATION );
3288 int UtcDaliConstraintInputWorldScale(void)
3290 TestApplication application;
3292 Actor parent = Actor::New();
3293 Vector3 parentScale( 2.0f, 2.0f, 2.0f );
3294 parent.SetScale( parentScale );
3295 Stage::GetCurrent().Add( parent );
3297 Actor child = Actor::New();
3298 Vector3 childScale( 1.0f, 2.0f, 3.0f );
3299 child.SetScale( childScale );
3300 parent.Add( child );
3302 Actor trackingActor = Actor::New();
3303 Stage::GetCurrent().Add( trackingActor );
3305 // The actors should not have a world scale yet
3306 DALI_TEST_EQUALS( parent.GetCurrentWorldScale(), Vector3::ONE, TEST_LOCATION );
3307 DALI_TEST_EQUALS( child.GetCurrentWorldScale(), Vector3::ONE, TEST_LOCATION );
3308 DALI_TEST_EQUALS( trackingActor.GetCurrentWorldScale(), Vector3::ONE, TEST_LOCATION );
3310 application.SendNotification();
3311 application.Render(0);
3313 DALI_TEST_EQUALS( parent.GetCurrentScale(), parentScale, TEST_LOCATION );
3314 DALI_TEST_EQUALS( child.GetCurrentScale(), childScale, TEST_LOCATION );
3315 DALI_TEST_EQUALS( trackingActor.GetCurrentScale(), Vector3::ONE, TEST_LOCATION );
3317 DALI_TEST_EQUALS( parent.GetCurrentWorldScale(), parentScale, TEST_LOCATION );
3318 Vector3 previousScale( parentScale * childScale );
3319 DALI_TEST_EQUALS( child.GetCurrentWorldScale(), previousScale, TEST_LOCATION );
3320 DALI_TEST_EQUALS( trackingActor.GetCurrentScale(), Vector3::ONE, TEST_LOCATION );
3322 // Build constraint, to make actor track the world-scale of another actor
3323 // Note that the world-scale is always from the previous frame, so the tracking actor will lag behind
3325 Constraint constraint = Constraint::New<Vector3>( Actor::SCALE,
3326 Source( child, Actor::WORLD_SCALE ),
3327 EqualToConstraint() );
3329 trackingActor.ApplyConstraint( constraint );
3331 application.SendNotification();
3332 application.Render(0);
3334 DALI_TEST_EQUALS( trackingActor.GetCurrentScale(), previousScale, TEST_LOCATION );
3336 // Scale the actors and try again
3337 Vector3 relativeScale( 3, 3, 3 );
3338 parent.ScaleBy( relativeScale );
3340 application.SendNotification();
3341 application.Render(0);
3343 DALI_TEST_EQUALS( parent.GetCurrentScale(), parentScale * relativeScale, TEST_LOCATION );
3344 DALI_TEST_EQUALS( child.GetCurrentScale(), childScale, TEST_LOCATION );
3346 // The tracking actor lags behind
3347 DALI_TEST_EQUALS( trackingActor.GetCurrentScale(), previousScale, TEST_LOCATION );
3349 DALI_TEST_EQUALS( parent.GetCurrentWorldScale(), parentScale * relativeScale, TEST_LOCATION );
3350 previousScale = Vector3( parentScale * childScale * relativeScale );
3351 DALI_TEST_EQUALS( child.GetCurrentWorldScale(), previousScale, TEST_LOCATION );
3353 // Allow the tracking actor to catch up
3354 application.SendNotification();
3355 application.Render(0);
3357 DALI_TEST_EQUALS( parent.GetCurrentScale(), parentScale * relativeScale, TEST_LOCATION );
3358 DALI_TEST_EQUALS( child.GetCurrentScale(), childScale, TEST_LOCATION );
3360 // The tracking actor catches up!
3361 DALI_TEST_EQUALS( trackingActor.GetCurrentScale(), previousScale, TEST_LOCATION );
3362 DALI_TEST_EQUALS( parent.GetCurrentWorldScale(), parentScale * relativeScale, TEST_LOCATION );
3363 DALI_TEST_EQUALS( child.GetCurrentWorldScale(), previousScale, TEST_LOCATION );
3367 int UtcDaliConstraintInputWorldColor(void)
3369 TestApplication application;
3371 Actor parent = Actor::New();
3372 Vector4 parentColor( 1.0f, 0.5f, 0.0f, 1.0f );
3373 parent.SetColor( parentColor );
3374 Stage::GetCurrent().Add( parent );
3376 Actor child = Actor::New();
3377 Vector4 childColor( 0.5f, 0.5f, 0.5f, 1.0f );
3378 child.SetColor( childColor );
3379 parent.Add( child );
3381 Actor trackingActor = Actor::New();
3382 Stage::GetCurrent().Add( trackingActor );
3384 // The actors should not have a world color yet
3385 DALI_TEST_EQUALS( parent.GetCurrentWorldColor(), Color::WHITE, TEST_LOCATION );
3386 DALI_TEST_EQUALS( child.GetCurrentWorldColor(), Color::WHITE, TEST_LOCATION );
3388 application.SendNotification();
3389 application.Render(0);
3391 DALI_TEST_EQUALS( parent.GetCurrentColor(), parentColor, TEST_LOCATION );
3392 DALI_TEST_EQUALS( child.GetCurrentColor(), childColor, TEST_LOCATION );
3393 DALI_TEST_EQUALS( trackingActor.GetCurrentColor(), Color::WHITE, TEST_LOCATION );
3395 DALI_TEST_EQUALS( parent.GetCurrentWorldColor(), parentColor, TEST_LOCATION );
3396 Vector4 previousColor( childColor );
3397 previousColor.a *= parentColor.a;
3398 DALI_TEST_EQUALS( child.GetCurrentWorldColor(), previousColor, TEST_LOCATION );
3400 // Build constraint, to make actor track the world-color of another actor
3401 // Note that the world-color is always from the previous frame, so the tracking actor will lag behind
3403 Constraint constraint = Constraint::New<Vector4>( Actor::COLOR,
3404 Source( child, Actor::WORLD_COLOR ),
3407 trackingActor.ApplyConstraint( constraint );
3409 application.SendNotification();
3410 application.Render(0);
3412 DALI_TEST_EQUALS( trackingActor.GetCurrentColor(), previousColor, TEST_LOCATION );
3414 // Set the color and try again
3415 Vector4 newChildColor( 0.75f, 0.75f, 0.75f, 1.0f );
3416 child.SetColor( newChildColor );
3418 application.SendNotification();
3419 application.Render(0);
3421 DALI_TEST_EQUALS( parent.GetCurrentColor(), parentColor, TEST_LOCATION );
3422 DALI_TEST_EQUALS( child.GetCurrentColor(), newChildColor, TEST_LOCATION );
3424 // The tracking actor lags behind
3425 DALI_TEST_EQUALS( trackingActor.GetCurrentColor(), previousColor, TEST_LOCATION );
3427 DALI_TEST_EQUALS( parent.GetCurrentWorldColor(), parentColor, TEST_LOCATION );
3428 previousColor = Vector3( newChildColor );
3429 DALI_TEST_EQUALS( child.GetCurrentWorldColor(), previousColor, TEST_LOCATION );
3431 // Allow the tracking actor to catch up
3432 application.SendNotification();
3433 application.Render(0);
3435 DALI_TEST_EQUALS( parent.GetCurrentColor(), parentColor, TEST_LOCATION );
3436 DALI_TEST_EQUALS( child.GetCurrentColor(), newChildColor, TEST_LOCATION );
3438 // The tracking actor catches up!
3439 DALI_TEST_EQUALS( trackingActor.GetCurrentColor(), previousColor, TEST_LOCATION );
3440 DALI_TEST_EQUALS( parent.GetCurrentWorldColor(), parentColor, TEST_LOCATION );
3441 DALI_TEST_EQUALS( child.GetCurrentWorldColor(), previousColor, TEST_LOCATION );
3445 int UtcDaliConstraintInvalidInputProperty(void)
3447 TestApplication application;
3448 Actor actor = Actor::New();
3449 Constraint constraint = Constraint::New<Vector3>( Actor::POSITION, LocalSource( PROPERTY_REGISTRATION_START_INDEX ), MultiplyConstraint() );
3451 Stage::GetCurrent().Add( actor );
3453 // Cannot use type registered properties as input to constraints
3456 actor.ApplyConstraint( constraint );
3457 tet_result( TET_FAIL );
3459 catch ( DaliException& e )
3461 DALI_TEST_ASSERT( e, "mTargetProxy->IsPropertyAConstraintInput( source.propertyIndex )", TEST_LOCATION );
3466 int UtcDaliBuiltinConstraintParentSize(void)
3468 TestApplication application;
3470 Actor parent = Actor::New();
3471 Vector3 parentSize(9,9,9);
3472 parent.SetSize( parentSize );
3473 Stage::GetCurrent().Add( parent );
3475 Actor actor = Actor::New();
3476 parent.Add( actor );
3478 Vector3 startValue( Vector3::ZERO );
3480 application.SendNotification();
3481 application.Render(0);
3482 DALI_TEST_CHECK( actor.GetCurrentSize() == startValue );
3486 Constraint constraint = Constraint::New<Vector3>( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() );
3487 actor.ApplyConstraint( constraint );
3489 application.SendNotification();
3490 application.Render(0);
3492 // Constraint should be fully applied
3493 DALI_TEST_EQUALS( actor.GetCurrentSize(), parentSize, TEST_LOCATION );
3495 // This should be ignored
3496 actor.SetSize( startValue );
3498 // Check that nothing has changed after a couple of buffer swaps
3499 application.SendNotification();
3500 application.Render(0);
3501 DALI_TEST_EQUALS( actor.GetCurrentSize(), parentSize, TEST_LOCATION );
3502 application.Render(0);
3503 DALI_TEST_EQUALS( actor.GetCurrentSize(), parentSize, TEST_LOCATION );
3505 // Remove the constraint, then set new value
3506 actor.RemoveConstraints();
3507 actor.SetSize( startValue );
3509 // Constraint should have been removed
3510 application.SendNotification();
3511 application.Render(0);
3512 DALI_TEST_EQUALS( actor.GetCurrentSize(), startValue, TEST_LOCATION );
3513 application.Render(0);
3514 DALI_TEST_EQUALS( actor.GetCurrentSize(), startValue, TEST_LOCATION );
3518 int UtcDaliBuiltinConstraintParentSizeRelative(void)
3520 TestApplication application;
3522 Actor parent = Actor::New();
3523 Vector3 parentSize(9,9,9);
3524 parent.SetSize( parentSize );
3525 Stage::GetCurrent().Add( parent );
3527 Actor actor = Actor::New();
3528 parent.Add( actor );
3530 Vector3 startValue( Vector3::ZERO );
3531 Vector3 scale(2,3,4);
3532 Vector3 endValue( parentSize * scale );
3534 application.SendNotification();
3535 application.Render(0);
3536 DALI_TEST_CHECK( actor.GetCurrentSize() == startValue );
3540 Constraint constraint = Constraint::New<Vector3>( Actor::SIZE, ParentSource( Actor::SIZE ), RelativeToConstraint( scale ) );
3541 actor.ApplyConstraint( constraint );
3543 application.SendNotification();
3544 application.Render(0);
3546 // Constraint should be fully applied
3547 DALI_TEST_EQUALS( actor.GetCurrentSize(), endValue, TEST_LOCATION );
3549 // This should be ignored
3550 actor.SetSize( startValue );
3552 // Check that nothing has changed after a couple of buffer swaps
3553 application.SendNotification();
3554 application.Render(0);
3555 DALI_TEST_EQUALS( actor.GetCurrentSize(), endValue, TEST_LOCATION );
3556 application.Render(0);
3557 DALI_TEST_EQUALS( actor.GetCurrentSize(), endValue, TEST_LOCATION );
3559 // Remove the constraint, then set new value
3560 actor.RemoveConstraints();
3561 actor.SetSize( startValue );
3563 // Constraint should have been removed
3564 application.SendNotification();
3565 application.Render(0);
3566 DALI_TEST_EQUALS( actor.GetCurrentSize(), startValue, TEST_LOCATION );
3567 application.Render(0);
3568 DALI_TEST_EQUALS( actor.GetCurrentSize(), startValue, TEST_LOCATION );
3572 int UtcDaliBuiltinConstraintScaleToFitConstraint(void)
3574 TestApplication application;
3576 Actor parent = Actor::New();
3577 Vector3 startParentSize( 10, 10, 10 );
3578 parent.SetSize( startParentSize );
3579 Stage::GetCurrent().Add( parent );
3581 Actor actor = Actor::New();
3582 Vector3 startChildSize( 5, 5, 5 );
3583 actor.SetSize( startChildSize );
3584 parent.Add( actor );
3586 Vector3 endChildSize( 8, 8, 8 );
3587 Vector3 endParentSize( 4, 4, 4 );
3588 Vector3 startChildScale( 2, 2, 2 ); // startParentSize / startChildSize
3589 Vector3 intermediateChildScale( 1.25, 1.25, 1.25 ); // startParentSize / endChildSize
3590 Vector3 endChildScale( 0.5, 0.5, 0.5 ); // endParentSize / endChildSize
3592 application.SendNotification();
3593 application.Render(0);
3594 DALI_TEST_CHECK( actor.GetCurrentSize() == startChildSize );
3598 Constraint constraint = Constraint::New<Vector3>( Actor::SCALE,
3599 LocalSource( Actor::SIZE ),
3600 ParentSource( Actor::SIZE ),
3601 ScaleToFitConstraint() );
3602 actor.ApplyConstraint( constraint );
3604 application.SendNotification();
3605 application.Render(0);
3607 // Constraint should be fully applied, but parent size is larger than child
3608 DALI_TEST_EQUALS( actor.GetCurrentSize(), startChildSize, TEST_LOCATION );
3609 DALI_TEST_EQUALS( actor.GetCurrentScale(), startChildScale, TEST_LOCATION );
3611 // This should be allowed (still less than parent size)
3612 actor.SetSize( endChildSize );
3614 application.SendNotification();
3615 application.Render(0);
3616 DALI_TEST_EQUALS( actor.GetCurrentSize(), endChildSize, TEST_LOCATION );
3617 DALI_TEST_EQUALS( actor.GetCurrentScale(), intermediateChildScale, TEST_LOCATION );
3619 // Reduce the parent size
3620 parent.SetSize( endParentSize );
3622 application.SendNotification();
3623 application.Render(0);
3625 // Constraint should be fully applied
3626 DALI_TEST_EQUALS( actor.GetCurrentSize(), endChildSize, TEST_LOCATION );
3627 DALI_TEST_EQUALS( actor.GetCurrentScale(), endChildScale, TEST_LOCATION );
3628 application.Render(0);
3629 DALI_TEST_EQUALS( actor.GetCurrentSize(), endChildSize, TEST_LOCATION );
3630 DALI_TEST_EQUALS( actor.GetCurrentScale(), endChildScale, TEST_LOCATION );
3634 int UtcDaliBuiltinConstraintScaleToFitKeepAspectRatio(void)
3636 TestApplication application;
3638 Actor parent = Actor::New();
3639 Vector3 parentSize1( 10, 10, 10 );
3640 parent.SetSize( parentSize1 );
3641 Stage::GetCurrent().Add( parent );
3643 Actor actor = Actor::New();
3644 Vector3 childSize( 4, 5, 5 );
3645 actor.SetSize( childSize );
3646 parent.Add( actor );
3648 application.SendNotification();
3649 application.Render(0);
3650 Vector3 childScale1( 1.0f, 1.0f, 1.0f );
3651 DALI_TEST_EQUALS( actor.GetCurrentScale(), childScale1, TEST_LOCATION );
3655 Constraint constraint = Constraint::New<Vector3>( Actor::SCALE,
3656 LocalSource( Actor::SIZE ),
3657 ParentSource( Actor::SIZE ),
3658 ScaleToFitKeepAspectRatioConstraint() );
3659 actor.ApplyConstraint( constraint );
3661 application.SendNotification();
3662 application.Render(0);
3664 // Constraint should be fully applied, but parent size is larger than child
3665 Vector3 childScale2( 2.0f, 2.0f, 2.0f );
3666 DALI_TEST_EQUALS( actor.GetCurrentScale(), childScale2, TEST_LOCATION );
3668 // change parent size
3669 Vector3 parentSize2( 40, 50, 50 );
3670 parent.SetSize( parentSize2 );
3672 application.SendNotification();
3673 application.Render(0);
3675 // Constraint should be fully applied, but parent size is larger than child
3676 Vector3 childScale3( 10.0f, 10.0f, 10.0f );
3677 DALI_TEST_EQUALS( actor.GetCurrentScale(), childScale3, TEST_LOCATION );
3681 int UtcDaliBuiltinConstraintScaleToFillKeepAspectRatio(void)
3683 TestApplication application;
3685 Actor parent = Actor::New();
3686 Vector3 parentSize1( 10, 10, 10 );
3687 parent.SetSize( parentSize1 );
3688 Stage::GetCurrent().Add( parent );
3690 Actor actor = Actor::New();
3691 Vector3 childSize( 4, 5, 5 );
3692 actor.SetSize( childSize );
3693 parent.Add( actor );
3695 application.SendNotification();
3696 application.Render(0);
3697 Vector3 childScale1( 1.0f, 1.0f, 1.0f );
3698 DALI_TEST_EQUALS( actor.GetCurrentScale(), childScale1, TEST_LOCATION );
3702 Constraint constraint = Constraint::New<Vector3>( Actor::SCALE,
3703 LocalSource( Actor::SIZE ),
3704 ParentSource( Actor::SIZE ),
3705 ScaleToFillKeepAspectRatioConstraint() );
3706 actor.ApplyConstraint( constraint );
3708 application.SendNotification();
3709 application.Render(0);
3711 // Constraint should be fully applied, but parent size is larger than child
3712 float val = 10.f / 4.f;
3713 Vector3 childScale2( val, val, val );
3714 DALI_TEST_EQUALS( actor.GetCurrentScale(), childScale2, TEST_LOCATION );
3716 // change parent size
3717 Vector3 parentSize2( 40, 50, 50 );
3718 parent.SetSize( parentSize2 );
3720 application.SendNotification();
3721 application.Render(0);
3723 // Constraint should be fully applied, but parent size is larger than child
3724 Vector3 childScale3( 10.0f, 10.0f, 10.0f );
3725 DALI_TEST_EQUALS( actor.GetCurrentScale(), childScale3, TEST_LOCATION );
3729 int UtcDaliBuiltinConstraintScaleToFillXYKeepAspectRatio(void)
3731 TestApplication application;
3733 Actor parent = Actor::New();
3734 Vector3 parentSize1( 10, 10, 10 );
3735 parent.SetSize( parentSize1 );
3736 Stage::GetCurrent().Add( parent );
3738 Actor actor = Actor::New();
3739 Vector3 childSize( 4, 5, 5 );
3740 actor.SetSize( childSize );
3741 parent.Add( actor );
3743 application.SendNotification();
3744 application.Render(0);
3745 Vector3 childScale1( 1.0f, 1.0f, 1.0f );
3746 DALI_TEST_EQUALS( actor.GetCurrentScale(), childScale1, TEST_LOCATION );
3750 Constraint constraint = Constraint::New<Vector3>( Actor::SCALE,
3751 LocalSource( Actor::SIZE ),
3752 ParentSource( Actor::SIZE ),
3753 ScaleToFillXYKeepAspectRatioConstraint() );
3754 actor.ApplyConstraint( constraint );
3756 application.SendNotification();
3757 application.Render(0);
3759 // Constraint should be fully applied, but parent size is larger than child
3760 float val = 10.f / 4.f;
3761 Vector3 childScale2( val, val, val );
3762 DALI_TEST_EQUALS( actor.GetCurrentScale(), childScale2, TEST_LOCATION );
3764 // change parent size
3765 Vector3 parentSize2( 40, 50, 50 );
3766 parent.SetSize( parentSize2 );
3768 application.SendNotification();
3769 application.Render(0);
3771 // Constraint should be fully applied, but parent size is larger than child
3772 Vector3 childScale3( 10.0f, 10.0f, 10.0f );
3773 DALI_TEST_EQUALS( actor.GetCurrentScale(), childScale3, TEST_LOCATION );
3777 int UtcDaliBuiltinConstraintShrinkInsideKeepAspectRatioConstraint(void)
3779 TestApplication application;
3781 Actor parent = Actor::New();
3782 Vector3 parentSize1( 10, 10, 10 );
3783 parent.SetSize( parentSize1 );
3784 Stage::GetCurrent().Add( parent );
3786 Actor actor = Actor::New();
3787 Vector3 childSize( 4, 5, 5 );
3788 actor.SetSize( childSize );
3789 parent.Add( actor );
3791 application.SendNotification();
3792 application.Render(0);
3793 Vector3 childScale1( 1.0f, 1.0f, 1.0f );
3794 DALI_TEST_EQUALS( actor.GetCurrentScale(), childScale1, TEST_LOCATION );
3798 Constraint constraint = Constraint::New<Vector3>( Actor::SCALE,
3799 LocalSource( Actor::SIZE ),
3800 ParentSource( Actor::SIZE ),
3801 ShrinkInsideKeepAspectRatioConstraint() );
3802 actor.ApplyConstraint( constraint );
3804 application.SendNotification();
3805 application.Render(0);
3807 // Constraint should be fully applied, but parent size is larger than child
3808 Vector3 childScale2( 1.0f, 1.0f, 1.0f );
3809 DALI_TEST_EQUALS( actor.GetCurrentScale(), childScale2, TEST_LOCATION );
3811 // change parent size
3812 Vector3 parentSize2( 40, 50, 50 );
3813 parent.SetSize( parentSize2 );
3815 application.SendNotification();
3816 application.Render(0);
3818 // Constraint should be fully applied, but parent size is larger than child
3819 Vector3 childScale3( 1.0f, 1.0f, 1.0f );
3820 DALI_TEST_EQUALS( actor.GetCurrentScale(), childScale3, TEST_LOCATION );
3824 int UtcDaliBuiltinConstraintMultiplyConstraint(void)
3826 TestApplication application;
3828 Actor actor1 = Actor::New();
3829 Vector3 startPosition( 10, 10, 10 );
3830 actor1.SetPosition( startPosition );
3831 Stage::GetCurrent().Add( actor1 );
3833 Actor actor2 = Actor::New();
3834 Vector3 startSize( 100, 100, 100 );
3835 actor2.SetSize( startSize );
3836 Stage::GetCurrent().Add( actor2 );
3838 application.SendNotification();
3839 application.Render(0);
3840 DALI_TEST_CHECK( actor1.GetCurrentPosition() == startPosition );
3841 DALI_TEST_CHECK( actor2.GetCurrentSize() == startSize );
3843 // Apply constraint - multiply actor1 size by actor2 position
3845 Constraint constraint = Constraint::New<Vector3>( Actor::SIZE,
3846 Source( actor1, Actor::POSITION ),
3847 MultiplyConstraint() );
3848 constraint.SetRemoveAction( Constraint::Discard );
3849 actor2.ApplyConstraint( constraint );
3851 application.SendNotification();
3852 application.Render(0);
3854 // Constraint should be fully applied
3855 Vector3 size( startSize * startPosition );
3856 DALI_TEST_EQUALS( actor2.GetCurrentSize(), size, TEST_LOCATION );
3858 // Change the multiply input
3859 Vector3 endPosition( 2, 2, 2 );
3860 actor1.SetPosition( endPosition );
3862 application.SendNotification();
3863 application.Render(0);
3865 // Constraint should be fully applied
3866 size = Vector3( startSize * endPosition );
3867 DALI_TEST_EQUALS( actor2.GetCurrentSize(), size, TEST_LOCATION );
3868 application.Render(0);
3869 DALI_TEST_EQUALS( actor2.GetCurrentSize(), size, TEST_LOCATION );
3873 int UtcDaliBuiltinConstraintDivideConstraint(void)
3875 TestApplication application;
3877 Actor actor1 = Actor::New();
3878 Vector3 startPosition( 10, 10, 10 );
3879 actor1.SetPosition( startPosition );
3880 Stage::GetCurrent().Add( actor1 );
3882 Actor actor2 = Actor::New();
3883 Vector3 startSize( 100, 100, 100 );
3884 actor2.SetSize( startSize );
3885 Stage::GetCurrent().Add( actor2 );
3887 application.SendNotification();
3888 application.Render(0);
3889 DALI_TEST_CHECK( actor1.GetCurrentPosition() == startPosition );
3890 DALI_TEST_CHECK( actor2.GetCurrentSize() == startSize );
3892 // Apply constraint - divide actor1 size by actor2 position
3894 Constraint constraint = Constraint::New<Vector3>( Actor::SIZE,
3895 Source( actor1, Actor::POSITION ),
3896 DivideConstraint() );
3897 constraint.SetRemoveAction( Constraint::Discard );
3898 actor2.ApplyConstraint( constraint );
3900 application.SendNotification();
3901 application.Render(0);
3903 // Constraint should be fully applied
3904 Vector3 size( 10, 10, 10 ); // startSize / startPosition
3905 DALI_TEST_EQUALS( actor2.GetCurrentSize(), size, TEST_LOCATION );
3907 // Change the divide input
3908 Vector3 endPosition( 2, 2, 2 );
3909 actor1.SetPosition( endPosition );
3911 application.SendNotification();
3912 application.Render(0);
3914 // Constraint should be fully applied
3915 size = Vector3( 50, 50, 50 ); // startSize / endPosition
3916 DALI_TEST_EQUALS( actor2.GetCurrentSize(), size, TEST_LOCATION );
3917 application.Render(0);
3918 DALI_TEST_EQUALS( actor2.GetCurrentSize(), size, TEST_LOCATION );
3922 int UtcDaliBuiltinConstraintEqualToConstraint(void)
3924 TestApplication application;
3926 Actor actor1 = Actor::New();
3927 Vector3 startPosition( 10, 10, 10 );
3928 actor1.SetPosition( startPosition );
3929 Stage::GetCurrent().Add( actor1 );
3931 Actor actor2 = Actor::New();
3932 Vector3 startSize( 100, 100, 100 );
3933 actor2.SetSize( startSize );
3934 Stage::GetCurrent().Add( actor2 );
3936 application.SendNotification();
3937 application.Render(0);
3938 DALI_TEST_CHECK( actor1.GetCurrentPosition() == startPosition );
3939 DALI_TEST_CHECK( actor2.GetCurrentSize() == startSize );
3941 // Apply constraint - actor1 size == actor2 position
3943 Constraint constraint = Constraint::New<Vector3>( Actor::SIZE,
3944 Source( actor1, Actor::POSITION ),
3945 EqualToConstraint() );
3946 constraint.SetRemoveAction( Constraint::Discard );
3947 actor2.ApplyConstraint( constraint );
3949 application.SendNotification();
3950 application.Render(0);
3952 // Constraint should be fully applied
3953 DALI_TEST_EQUALS( actor2.GetCurrentSize(), startPosition, TEST_LOCATION );
3956 Vector3 endPosition( 2, 2, 2 );
3957 actor1.SetPosition( endPosition );
3959 application.SendNotification();
3960 application.Render(0);
3962 // Constraint should be fully applied
3963 DALI_TEST_EQUALS( actor2.GetCurrentSize(), endPosition, TEST_LOCATION );
3964 application.Render(0);
3965 DALI_TEST_EQUALS( actor2.GetCurrentSize(), endPosition, TEST_LOCATION );
3968 // Check float variant of constraint
3970 float startOpacity(1.0f);
3971 float endOpacity(0.2f);
3972 actor1.SetOpacity( startOpacity );
3973 actor2.SetOpacity( startOpacity );
3975 application.SendNotification();
3976 application.Render(0);
3977 DALI_TEST_EQUALS( actor1.GetCurrentOpacity(), startOpacity, TEST_LOCATION );
3978 DALI_TEST_EQUALS( actor2.GetCurrentOpacity(), startOpacity, TEST_LOCATION );
3980 Constraint constraint2 = Constraint::New<float>( Actor::COLOR_ALPHA,
3981 Source( actor1, Actor::COLOR_ALPHA ),
3982 EqualToConstraint() );
3983 constraint2.SetRemoveAction( Constraint::Discard );
3984 actor2.ApplyConstraint( constraint2 );
3986 actor1.SetOpacity(endOpacity);
3988 application.SendNotification();
3989 application.Render(0);
3991 DALI_TEST_EQUALS( actor2.GetCurrentOpacity(), endOpacity, 0.000001f, TEST_LOCATION );
3994 // Check Vector4 variant of constraint
3996 actor1.SetColor( Color::GREEN );
3997 actor2.SetColor( Color::RED );
3999 application.SendNotification();
4000 application.Render(0);
4001 DALI_TEST_CHECK( actor1.GetCurrentColor() == Color::GREEN );
4002 DALI_TEST_CHECK( actor2.GetCurrentColor() == Color::RED );
4004 Constraint constraint3 = Constraint::New<Vector4>( Actor::COLOR,
4005 Source( actor1, Actor::COLOR ),
4006 EqualToConstraint() );
4007 constraint3.SetRemoveAction( Constraint::Discard );
4008 actor2.ApplyConstraint( constraint3 );
4009 application.SendNotification();
4010 application.Render(0);
4011 DALI_TEST_CHECK( actor2.GetCurrentColor() == Color::GREEN );
4014 // Check Quaternion variant of constraint
4016 Quaternion q1 = Quaternion( Math::PI_2, Vector3::XAXIS );
4017 Quaternion q2 = Quaternion( Math::PI_4, Vector3::YAXIS );
4018 actor1.SetRotation( q1 );
4019 actor2.SetRotation( q2 );
4021 application.SendNotification();
4022 application.Render(0);
4023 DALI_TEST_EQUALS( actor1.GetCurrentRotation(), q1, 0.01, TEST_LOCATION );
4024 DALI_TEST_EQUALS( actor2.GetCurrentRotation(), q2, 0.01, TEST_LOCATION );
4026 Constraint constraint4 = Constraint::New<Quaternion>( Actor::ROTATION,
4027 Source( actor1, Actor::ROTATION ),
4028 EqualToConstraint() );
4029 constraint4.SetRemoveAction( Constraint::Discard );
4030 actor2.ApplyConstraint( constraint4 );
4031 application.SendNotification();
4032 application.Render(0);
4033 DALI_TEST_EQUALS( actor2.GetCurrentRotation(), q1, 0.01, TEST_LOCATION );
4036 // Check Matrix3 variant
4038 EqualToConstraint equalToConstraint;
4041 a.AsFloat()[0] = 1.f;
4043 b.AsFloat()[0] = 2.f;
4044 PropertyInputAbstraction pi(b);
4046 Matrix3 c = equalToConstraint(a,pi);
4047 DALI_TEST_EQUALS( c.AsFloat()[0], b.AsFloat()[0], 0.01, TEST_LOCATION);
4051 int UtcDaliBuiltinConstraintRelativeToConstraint(void)
4053 TestApplication application;
4055 Actor actor1 = Actor::New();
4056 Vector3 startPosition( 10, 10, 10 );
4057 actor1.SetPosition( startPosition );
4058 Stage::GetCurrent().Add( actor1 );
4060 Actor actor2 = Actor::New();
4061 Vector3 startSize( 100, 100, 100 );
4062 actor2.SetSize( startSize );
4063 Stage::GetCurrent().Add( actor2 );
4065 application.SendNotification();
4066 application.Render(0);
4067 DALI_TEST_CHECK( actor1.GetCurrentPosition() == startPosition );
4068 DALI_TEST_CHECK( actor2.GetCurrentSize() == startSize );
4070 // Apply constraint - actor1 size == actor2 position
4072 RelativeToConstraint( 0.f );
4073 Vector3 scale( 0.5, 0.6, 0.7 );
4074 Constraint constraint = Constraint::New<Vector3>( Actor::SIZE,
4075 Source( actor1, Actor::POSITION ),
4076 RelativeToConstraint( scale ) );
4077 constraint.SetRemoveAction( Constraint::Discard );
4078 actor2.ApplyConstraint( constraint );
4080 application.SendNotification();
4081 application.Render(0);
4083 // Constraint should be fully applied
4084 DALI_TEST_EQUALS( actor2.GetCurrentSize(), scale * startPosition, TEST_LOCATION );
4087 Vector3 endPosition( 2, 2, 2 );
4088 actor1.SetPosition( endPosition );
4090 application.SendNotification();
4091 application.Render(0);
4093 // Constraint should be fully applied
4094 DALI_TEST_EQUALS( actor2.GetCurrentSize(), scale * endPosition, TEST_LOCATION );
4095 application.Render(0);
4096 DALI_TEST_EQUALS( actor2.GetCurrentSize(), scale * endPosition, TEST_LOCATION );
4099 // Check float variant of constraint
4101 float scale2( 0.5f );
4102 float startOpacity(1.0f);
4103 actor1.SetOpacity( startOpacity );
4104 actor2.SetOpacity( startOpacity );
4106 application.SendNotification();
4107 application.Render(0);
4108 DALI_TEST_EQUALS( actor1.GetCurrentOpacity(), startOpacity, TEST_LOCATION );
4109 DALI_TEST_EQUALS( actor2.GetCurrentOpacity(), startOpacity, TEST_LOCATION );
4111 Constraint constraint2 = Constraint::New<float>( Actor::COLOR_ALPHA,
4112 Source( actor1, Actor::COLOR_ALPHA ),
4113 RelativeToConstraintFloat(scale2) );
4114 constraint2.SetRemoveAction( Constraint::Discard );
4115 actor2.ApplyConstraint(constraint2);
4116 application.SendNotification();
4117 application.Render(0);
4119 DALI_TEST_EQUALS( actor2.GetCurrentOpacity(), startOpacity * scale2, TEST_LOCATION );
4123 int UtcDaliBuiltinConstraintInverseOfConstraint(void)
4125 TestApplication application;
4127 Actor actor1 = Actor::New();
4128 Vector3 startPosition( 10, 10, 10 );
4129 actor1.SetPosition( startPosition );
4130 Stage::GetCurrent().Add( actor1 );
4132 Actor actor2 = Actor::New();
4133 Vector3 startSize( 100, 100, 100 );
4134 actor2.SetSize( startSize );
4135 Stage::GetCurrent().Add( actor2 );
4137 application.SendNotification();
4138 application.Render(0);
4139 DALI_TEST_CHECK( actor1.GetCurrentPosition() == startPosition );
4140 DALI_TEST_CHECK( actor2.GetCurrentSize() == startSize );
4142 // Apply constraint - actor1 size == ( 1 / actor2 position )
4144 Constraint constraint = Constraint::New<Vector3>( Actor::SIZE,
4145 Source( actor1, Actor::POSITION ),
4146 InverseOfConstraint() );
4147 constraint.SetRemoveAction( Constraint::Discard );
4148 actor2.ApplyConstraint( constraint );
4150 application.SendNotification();
4151 application.Render(0);
4153 // Constraint should be fully applied
4154 Vector3 size( 0.1, 0.1, 0.1 ); // 1 / startPosition
4155 DALI_TEST_EQUALS( actor2.GetCurrentSize(), size, 0.00001f, TEST_LOCATION );
4158 Vector3 endPosition( 2, 2, 2 );
4159 actor1.SetPosition( endPosition );
4161 application.SendNotification();
4162 application.Render(0);
4164 // Constraint should be fully applied
4165 size = Vector3( 0.5, 0.5, 0.5 ); // 1 / endPosition
4166 DALI_TEST_EQUALS( actor2.GetCurrentSize(), size, TEST_LOCATION );
4167 application.Render(0);
4168 DALI_TEST_EQUALS( actor2.GetCurrentSize(), size, TEST_LOCATION );
4172 int UtcDaliBuiltinConstraintFunctions(void)
4174 TestApplication application;
4177 SourceWidthFixedHeight sourceWidthFixedHeight( 10.f );
4180 Vector3 reference(1, 10, 0);
4181 Vector3 value = sourceWidthFixedHeight( current, PropertyInputAbstraction(Vector3::ONE) );
4182 DALI_TEST_EQUALS( reference, value, TEST_LOCATION );
4185 Vector3 reference(10, 10, 0);
4186 Vector3 value = sourceWidthFixedHeight( current, PropertyInputAbstraction(Vector3::ONE*10.f) );
4187 DALI_TEST_EQUALS( reference, value, TEST_LOCATION );
4190 Vector3 reference(10,10,0);
4191 Vector3 value = sourceWidthFixedHeight( current, PropertyInputAbstraction(Vector3::ONE*10.f) );
4192 DALI_TEST_EQUALS( reference, value, TEST_LOCATION );
4197 SourceHeightFixedWidth sourceHeightFixedWidth( 10.f );
4200 Vector3 reference(10,1,0);
4201 Vector3 value = sourceHeightFixedWidth( current, PropertyInputAbstraction(Vector3::ONE) );
4202 DALI_TEST_EQUALS( reference, value, TEST_LOCATION );
4205 Vector3 reference(10,10,0);
4206 Vector3 value = sourceHeightFixedWidth( current, PropertyInputAbstraction(Vector3::ONE*10.f) );
4207 DALI_TEST_EQUALS( reference, value, TEST_LOCATION );
4210 Vector3 reference(10,100,0);
4211 Vector3 value = sourceHeightFixedWidth( current, PropertyInputAbstraction(Vector3::ONE*100.f) );
4212 DALI_TEST_EQUALS( reference, value, TEST_LOCATION );
4217 Quaternion current(0, Vector3::YAXIS);
4218 PropertyInputAbstraction target(Vector3::ZAXIS);
4219 PropertyInputAbstraction targetRotation(Vector3::YAXIS);
4220 PropertyInputAbstraction camera(Vector3::ZERO);
4223 Quaternion reference(1., 0., 0., 0.);
4224 Quaternion value = LookAt( current, target, camera, targetRotation );
4225 DALI_TEST_EQUALS( reference, value, 0.001, TEST_LOCATION );
4229 OrientedLookAt orientedLookAt(90.f);
4230 Quaternion reference(.525322, 0., 0., 0.850904);
4231 Quaternion value = orientedLookAt( current, target, camera, targetRotation );
4232 DALI_TEST_EQUALS( reference, value, 0.001, TEST_LOCATION );