2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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.
20 #include <dali/dali.h>
21 #include <dali-test-suite-utils.h>
25 void utc_dali_constraint_startup(void)
27 test_return_value = TET_UNDEF;
30 void utc_dali_constraint_cleanup(void)
32 test_return_value = TET_PASS;
39 struct EqualToQuaternion
45 Quaternion operator()( const Quaternion& current, const PropertyInput& property )
47 return property.GetQuaternion();
57 Vector4 operator()( const Vector4& current, const PropertyInput& property )
59 return property.GetVector4();
63 class PropertyInputAbstraction : public Dali::PropertyInput
66 PropertyInputAbstraction(const bool& val) : mType(Dali::Property::BOOLEAN), mBoolData( val ) {}
67 PropertyInputAbstraction(const float& val) : mType(Dali::Property::FLOAT), mFloatData( val ) {}
68 PropertyInputAbstraction(const Vector2& val) : mType(Dali::Property::VECTOR2), mVector2Data( val ) {}
69 PropertyInputAbstraction(const Vector3& val) : mType(Dali::Property::VECTOR3), mVector3Data( val ) {}
70 PropertyInputAbstraction(const Vector4& val) : mType(Dali::Property::VECTOR4), mVector4Data( val ) {}
71 PropertyInputAbstraction(const Matrix3& val) : mType(Dali::Property::MATRIX3), mMatrix3Data( val ) {}
72 PropertyInputAbstraction(const Matrix& val) : mType(Dali::Property::MATRIX), mMatrixData( val ) {}
73 PropertyInputAbstraction(const Quaternion& val) : mType(Dali::Property::ROTATION), mQuaternionData( val ) {}
75 ~PropertyInputAbstraction() {}
77 Dali::Property::Type GetType() const { return mType; }
79 const bool& GetBoolean() const { return mBoolData; }
81 const float& GetFloat() const { return mFloatData; }
83 const Vector2& GetVector2() const { return mVector2Data; }
84 const Vector3& GetVector3() const { return mVector3Data; }
85 const Vector4& GetVector4() const { return mVector4Data; }
87 const Matrix3& GetMatrix3() const { return mMatrix3Data; }
88 const Matrix& GetMatrix() const { return mMatrixData; }
90 const Quaternion& GetQuaternion() const { return mQuaternionData; }
93 Dali::Property::Type mType;
101 Quaternion mQuaternionData;
104 static const float POSITION_EPSILON = 0.0001f;
105 static const float ROTATION_EPSILON = 0.0001f;
107 struct TestConstraint
109 Vector4 operator()(const Vector4& color)
111 return Vector4(color.x, color.y, color.z, 0.1f);
115 struct TestConstraintToVector3
117 TestConstraintToVector3(Vector3 target)
122 Vector3 operator()(const Vector3& current)
130 struct TestColorConstraint
132 TestColorConstraint(Vector4 target)
137 Vector4 operator()(const Vector4& color)
145 struct TestPositionConstraint
147 TestPositionConstraint(Vector3 target)
152 Vector3 operator()(const Vector3& position)
161 struct TestAlwaysTrueConstraint
163 bool operator()( const bool& current )
169 struct TestAlwaysEqualOrGreaterThanConstraint
171 TestAlwaysEqualOrGreaterThanConstraint( float value )
176 float operator()( const float& current )
178 return ( current < mValue ) ? mValue : current;
184 struct TestAlwaysEqualOrGreaterThanConstraintVector2
186 TestAlwaysEqualOrGreaterThanConstraintVector2( Vector2 value )
191 Vector2 operator()( const Vector2& current )
193 return Vector2( ( current.x < mValue.x ) ? mValue.x : current.x,
194 ( current.y < mValue.y ) ? mValue.y : current.y
201 struct TestAlwaysEqualOrGreaterThanConstraintVector3
203 TestAlwaysEqualOrGreaterThanConstraintVector3( Vector3 value )
208 Vector3 operator()( const Vector3& current )
210 return Vector3( ( current.x < mValue.x ) ? mValue.x : current.x,
211 ( current.y < mValue.y ) ? mValue.y : current.y,
212 ( current.z < mValue.z ) ? mValue.z : current.z
219 struct TestAlwaysEqualOrGreaterThanConstraintVector4
221 TestAlwaysEqualOrGreaterThanConstraintVector4( Vector4 value )
226 Vector4 operator()( const Vector4& current )
228 return Vector4( ( current.x < mValue.x ) ? mValue.x : current.x,
229 ( current.y < mValue.y ) ? mValue.y : current.y,
230 ( current.z < mValue.z ) ? mValue.z : current.z,
231 ( current.w < mValue.w ) ? mValue.w : current.w
238 struct TestConstraintFloat
240 TestConstraintFloat( float value )
245 float operator()( const float& current )
253 struct TestConstraintVector2
255 TestConstraintVector2( Vector2 value )
260 Vector2 operator()( const Vector2& current )
268 struct TestConstraintVector3
270 TestConstraintVector3( Vector3 value )
275 Vector3 operator()( const Vector3& current )
283 struct TestConstraintVector4
285 TestConstraintVector4( Vector4 value )
290 Vector4 operator()( const Vector4& current )
298 struct TestConstraintRotation
300 TestConstraintRotation( Quaternion rotation )
301 : mRotation( rotation )
305 Quaternion operator()( const Quaternion& current )
310 Quaternion mRotation;
313 struct TestConstraintMatrix3
315 TestConstraintMatrix3(Matrix3 matrix3)
316 : mMatrix3( matrix3 )
320 Matrix3 operator()( const Matrix3& current )
328 struct TestConstraintMatrix
330 TestConstraintMatrix(Matrix matrix)
335 Matrix operator()( const Matrix& current )
343 struct MoveAwayWithFadeConstraint
345 MoveAwayWithFadeConstraint( float distance )
346 : mDistance( distance )
350 Vector3 operator()( const Vector3& current,
351 const PropertyInput& color )
353 return Vector3( current.x,
355 -mDistance * (1.0f - color.GetVector4().a) );
361 struct TestBottomRightAlignConstraint
363 Vector3 operator()( const Vector3& current,
364 const PropertyInput& parentSize )
366 return Vector3( parentSize.GetVector3().x, parentSize.GetVector3().y, 0.0f );
370 struct MeanPositionConstraint1
372 Vector3 operator()( const Vector3& current,
373 const PropertyInput& position1 )
375 return Vector3( position1.GetVector3() );
379 struct MeanPositionConstraint2
381 Vector3 operator()( const Vector3& current,
382 const PropertyInput& position1,
383 const PropertyInput& position2 )
385 Vector3 meanValue = position1.GetVector3() +
386 position2.GetVector3();
388 return meanValue * 0.5f; // div 2
392 struct MeanPositionConstraint3
394 Vector3 operator()( const Vector3& current,
395 const PropertyInput& position1,
396 const PropertyInput& position2,
397 const PropertyInput& position3 )
399 Vector3 meanValue = position1.GetVector3() +
400 position2.GetVector3() +
401 position3.GetVector3();
403 return meanValue * (1.0f / 3.0f); // div 3
407 struct MeanPositionConstraint4
409 Vector3 operator()( const Vector3& current,
410 const PropertyInput& position1,
411 const PropertyInput& position2,
412 const PropertyInput& position3,
413 const PropertyInput& position4 )
415 Vector3 meanValue = position1.GetVector3() +
416 position2.GetVector3() +
417 position3.GetVector3() +
418 position4.GetVector3();
420 return meanValue * 0.25f; // div 4
424 struct MeanPositionConstraint5
426 Vector3 operator()( const Vector3& current,
427 const PropertyInput& position1,
428 const PropertyInput& position2,
429 const PropertyInput& position3,
430 const PropertyInput& position4,
431 const PropertyInput& position5 )
433 Vector3 meanValue = position1.GetVector3() +
434 position2.GetVector3() +
435 position3.GetVector3() +
436 position4.GetVector3() +
437 position5.GetVector3();
439 return meanValue * 0.2f; // div 5
443 struct MeanPositionConstraint6
445 Vector3 operator()( const Vector3& current,
446 const PropertyInput& position1,
447 const PropertyInput& position2,
448 const PropertyInput& position3,
449 const PropertyInput& position4,
450 const PropertyInput& position5,
451 const PropertyInput& position6 )
453 Vector3 meanValue = position1.GetVector3() +
454 position2.GetVector3() +
455 position3.GetVector3() +
456 position4.GetVector3() +
457 position5.GetVector3() +
458 position6.GetVector3();
460 return meanValue * (1.0f / 6.0f); // div 6
464 struct TestRelativeConstraintFloat
466 TestRelativeConstraintFloat(float scale)
471 float operator()( const float& current, const PropertyInput& relative )
473 return relative.GetFloat() * mScale;
479 struct TestRelativeConstraintVector3
481 TestRelativeConstraintVector3(float scale)
486 Vector3 operator()( const Vector3& current, const PropertyInput& relative )
488 return relative.GetVector3() * mScale;
494 } // anonymous namespace
501 int UtcDaliConstraintNewBoolean(void)
503 TestApplication application;
505 Actor actor = Actor::New();
507 // Register a boolean property
508 bool startValue(false);
509 Property::Index index = actor.RegisterProperty( "test-property", startValue );
510 Stage::GetCurrent().Add(actor);
511 DALI_TEST_CHECK( actor.GetProperty<bool>(index) == startValue );
514 * Test that the Constraint is correctly applied on a clean Node
516 application.SendNotification();
517 application.Render(0);
518 DALI_TEST_CHECK( actor.GetProperty<bool>(index) == startValue );
519 application.Render(0);
520 DALI_TEST_CHECK( actor.GetProperty<bool>(index) == startValue );
521 application.Render(0);
522 DALI_TEST_CHECK( actor.GetProperty<bool>(index) == startValue );
526 Constraint constraint = Constraint::New<bool>( index, TestAlwaysTrueConstraint() );
528 actor.ApplyConstraint( constraint );
529 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), false, TEST_LOCATION );
531 application.SendNotification();
532 application.Render(0);
534 // Constraint should be fully applied
535 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), true, TEST_LOCATION );
537 // Check that nothing has changed after a couple of buffer swaps
538 application.Render(0);
539 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), true, TEST_LOCATION );
540 application.Render(0);
541 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), true, TEST_LOCATION );
543 // Try to fight with the constraint - this shouldn't work!
544 actor.SetProperty( index, false );
546 application.SendNotification();
547 application.Render(0);
549 // Check that nothing has changed after a couple of buffer swaps
550 application.Render(0);
551 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), true, TEST_LOCATION );
552 application.Render(0);
553 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), true, TEST_LOCATION );
555 // Remove the constraint, then set new value
556 actor.RemoveConstraints();
557 actor.SetProperty( index, false );
559 // Constraint should have been removed
560 application.SendNotification();
561 application.Render(0);
562 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), false, TEST_LOCATION );
563 application.Render(0);
564 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), false, TEST_LOCATION );
568 int UtcDaliConstraintNewFloat(void)
570 TestApplication application;
572 Actor actor = Actor::New();
574 // Register a float property
575 float startValue(1.0f);
576 Property::Index index = actor.RegisterProperty( "test-property", startValue );
577 Stage::GetCurrent().Add(actor);
578 DALI_TEST_CHECK( actor.GetProperty<float>(index) == startValue );
581 * Test that the Constraint is correctly applied on a clean Node
583 application.SendNotification();
584 application.Render(0);
585 DALI_TEST_CHECK( actor.GetProperty<float>(index) == startValue );
586 application.Render(0);
587 DALI_TEST_CHECK( actor.GetProperty<float>(index) == startValue );
588 application.Render(0);
589 DALI_TEST_CHECK( actor.GetProperty<float>(index) == startValue );
593 float minValue( 2.0f );
594 Constraint constraint = Constraint::New<float>( index, TestAlwaysEqualOrGreaterThanConstraint( minValue ) );
596 actor.ApplyConstraint( constraint );
597 DALI_TEST_EQUALS( actor.GetProperty<float>(index), startValue, TEST_LOCATION );
599 application.SendNotification();
600 application.Render(0);
602 // Constraint should be fully applied
603 DALI_TEST_EQUALS( actor.GetProperty<float>(index), minValue, TEST_LOCATION );
605 // Check that nothing has changed after a couple of buffer swaps
606 application.Render(0);
607 DALI_TEST_EQUALS( actor.GetProperty<float>(index), minValue, TEST_LOCATION );
608 application.Render(0);
609 DALI_TEST_EQUALS( actor.GetProperty<float>(index), minValue, TEST_LOCATION );
611 // Set to greater than 2.0f, the constraint will allow this
612 actor.SetProperty( index, 3.0f );
614 application.SendNotification();
615 application.Render(0);
617 DALI_TEST_EQUALS( actor.GetProperty<float>(index), 3.0f, TEST_LOCATION );
619 // Check that nothing has changed after a couple of buffer swaps
620 application.Render(0);
621 DALI_TEST_EQUALS( actor.GetProperty<float>(index), 3.0f, TEST_LOCATION );
622 application.Render(0);
623 DALI_TEST_EQUALS( actor.GetProperty<float>(index), 3.0f, TEST_LOCATION );
625 // Set to less than 2.0f, the constraint will NOT allow this
626 actor.SetProperty( index, 1.0f );
628 application.SendNotification();
629 application.Render(0);
631 DALI_TEST_EQUALS( actor.GetProperty<float>(index), minValue/*not 1.0f*/, TEST_LOCATION );
633 // Check that nothing has changed after a couple of buffer swaps
634 application.Render(0);
635 DALI_TEST_EQUALS( actor.GetProperty<float>(index), minValue, TEST_LOCATION );
636 application.Render(0);
637 DALI_TEST_EQUALS( actor.GetProperty<float>(index), minValue, TEST_LOCATION );
639 // Remove the constraint, then set new value
640 actor.RemoveConstraints();
641 actor.SetProperty( index, 1.0f );
643 // Constraint should have been removed
644 application.SendNotification();
645 application.Render(0);
646 DALI_TEST_EQUALS( actor.GetProperty<float>(index), 1.0f, TEST_LOCATION );
647 application.Render(0);
648 DALI_TEST_EQUALS( actor.GetProperty<float>(index), 1.0f, TEST_LOCATION );
652 int UtcDaliConstraintNewVector2(void)
654 TestApplication application;
656 Actor actor = Actor::New();
658 // Register a Vector2 property
659 Vector2 startValue( 1.0f, 1.0f );
660 Property::Index index = actor.RegisterProperty( "test-property", startValue );
661 Stage::GetCurrent().Add(actor);
662 DALI_TEST_CHECK( actor.GetProperty<Vector2>(index) == startValue );
665 * Test that the Constraint is correctly applied on a clean Node
667 application.SendNotification();
668 application.Render(0);
669 DALI_TEST_CHECK( actor.GetProperty<Vector2>(index) == startValue );
670 application.Render(0);
671 DALI_TEST_CHECK( actor.GetProperty<Vector2>(index) == startValue );
672 application.Render(0);
673 DALI_TEST_CHECK( actor.GetProperty<Vector2>(index) == startValue );
677 Vector2 minValue( 2.0f, 2.0f );
678 Constraint constraint = Constraint::New<Vector2>( index, TestAlwaysEqualOrGreaterThanConstraintVector2( minValue ) );
680 actor.ApplyConstraint( constraint );
681 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), startValue, TEST_LOCATION );
683 application.SendNotification();
684 application.Render(0);
686 // Constraint should be fully applied
687 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), minValue, TEST_LOCATION );
689 // Check that nothing has changed after a couple of buffer swaps
690 application.Render(0);
691 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), minValue, TEST_LOCATION );
692 application.Render(0);
693 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), minValue, TEST_LOCATION );
695 // Set to greater than 2.0f, the constraint will allow this
696 Vector2 greaterValue( 3.0f, 3.0f );
697 actor.SetProperty( index, greaterValue );
699 application.SendNotification();
700 application.Render(0);
702 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), greaterValue, TEST_LOCATION );
704 // Check that nothing has changed after a couple of buffer swaps
705 application.Render(0);
706 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), greaterValue, TEST_LOCATION );
707 application.Render(0);
708 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), greaterValue, TEST_LOCATION );
710 // Set to less than 2.0f, the constraint will NOT allow this
711 Vector2 lesserValue( 1.0f, 1.0f );
712 actor.SetProperty( index, lesserValue );
714 application.SendNotification();
715 application.Render(0);
717 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), minValue/*not lesserValue*/, TEST_LOCATION );
719 // Check that nothing has changed after a couple of buffer swaps
720 application.Render(0);
721 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), minValue, TEST_LOCATION );
722 application.Render(0);
723 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), minValue, TEST_LOCATION );
725 // Remove the constraint, then set new value
726 actor.RemoveConstraints();
727 actor.SetProperty( index, lesserValue );
729 // Constraint should have been removed
730 application.SendNotification();
731 application.Render(0);
732 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), lesserValue, TEST_LOCATION );
733 application.Render(0);
734 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), lesserValue, TEST_LOCATION );
738 int UtcDaliConstraintNewVector3(void)
740 TestApplication application;
742 Actor actor = Actor::New();
744 // Register a Vector3 property
745 Vector3 startValue(1.0f, 1.0f, 1.0f);
746 Property::Index index = actor.RegisterProperty( "test-property", startValue );
747 Stage::GetCurrent().Add(actor);
748 DALI_TEST_CHECK( actor.GetProperty<Vector3>(index) == startValue );
751 * Test that the Constraint is correctly applied on a clean Node
753 application.SendNotification();
754 application.Render(0);
755 DALI_TEST_CHECK( actor.GetProperty<Vector3>(index) == startValue );
756 application.Render(0);
757 DALI_TEST_CHECK( actor.GetProperty<Vector3>(index) == startValue );
758 application.Render(0);
759 DALI_TEST_CHECK( actor.GetProperty<Vector3>(index) == startValue );
763 Vector3 minValue( 2.0f, 2.0f, 2.0f );
764 Constraint constraint = Constraint::New<Vector3>( index, TestAlwaysEqualOrGreaterThanConstraintVector3( minValue ) );
766 actor.ApplyConstraint( constraint );
767 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), startValue, TEST_LOCATION );
769 application.SendNotification();
770 application.Render(0);
772 // Constraint should be fully applied
773 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), minValue, TEST_LOCATION );
775 // Check that nothing has changed after a couple of buffer swaps
776 application.Render(0);
777 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), minValue, TEST_LOCATION );
778 application.Render(0);
779 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), minValue, TEST_LOCATION );
781 // Set to greater than 2.0f, the constraint will allow this
782 Vector3 greaterValue( 3.0f, 3.0f, 3.0f );
783 actor.SetProperty( index, greaterValue );
785 application.SendNotification();
786 application.Render(0);
788 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), greaterValue, TEST_LOCATION );
790 // Check that nothing has changed after a couple of buffer swaps
791 application.Render(0);
792 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), greaterValue, TEST_LOCATION );
793 application.Render(0);
794 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), greaterValue, TEST_LOCATION );
796 // Set to less than 2.0f, the constraint will NOT allow this
797 Vector3 lesserValue( 1.0f, 1.0f, 1.0f );
798 actor.SetProperty( index, lesserValue );
800 application.SendNotification();
801 application.Render(0);
803 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), minValue/*not lesserValue*/, TEST_LOCATION );
805 // Check that nothing has changed after a couple of buffer swaps
806 application.Render(0);
807 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), minValue, TEST_LOCATION );
808 application.Render(0);
809 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), minValue, TEST_LOCATION );
811 // Remove the constraint, then set new value
812 actor.RemoveConstraints();
813 actor.SetProperty( index, lesserValue );
815 // Constraint should have been removed
816 application.SendNotification();
817 application.Render(0);
818 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), lesserValue, TEST_LOCATION );
819 application.Render(0);
820 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), lesserValue, TEST_LOCATION );
824 int UtcDaliConstraintNewVector4(void)
826 TestApplication application;
828 Actor actor = Actor::New();
830 // Register a Vector4 property
831 Vector4 startValue( 1.0f, 1.0f, 1.0f, 1.0f );
832 Property::Index index = actor.RegisterProperty( "test-property", startValue );
833 Stage::GetCurrent().Add(actor);
834 DALI_TEST_CHECK( actor.GetProperty<Vector4>(index) == startValue );
837 * Test that the Constraint is correctly applied on a clean Node
839 application.SendNotification();
840 application.Render(0);
841 DALI_TEST_CHECK( actor.GetProperty<Vector4>(index) == startValue );
842 application.Render(0);
843 DALI_TEST_CHECK( actor.GetProperty<Vector4>(index) == startValue );
844 application.Render(0);
845 DALI_TEST_CHECK( actor.GetProperty<Vector4>(index) == startValue );
849 Vector4 minValue( 2.0f, 2.0f, 2.0f, 2.0f );
850 Constraint constraint = Constraint::New<Vector4>( index, TestAlwaysEqualOrGreaterThanConstraintVector4( minValue ) );
852 actor.ApplyConstraint( constraint );
853 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), startValue, TEST_LOCATION );
855 application.SendNotification();
856 application.Render(0);
858 // Constraint should be fully applied
859 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), minValue, TEST_LOCATION );
861 // Check that nothing has changed after a couple of buffer swaps
862 application.Render(0);
863 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), minValue, TEST_LOCATION );
864 application.Render(0);
865 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), minValue, TEST_LOCATION );
867 // Set to greater than 2.0f, the constraint will allow this
868 Vector4 greaterValue( 3.0f, 3.0f, 3.0f, 3.0f );
869 actor.SetProperty( index, greaterValue );
871 application.SendNotification();
872 application.Render(0);
874 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), greaterValue, TEST_LOCATION );
876 // Check that nothing has changed after a couple of buffer swaps
877 application.Render(0);
878 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), greaterValue, TEST_LOCATION );
879 application.Render(0);
880 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), greaterValue, TEST_LOCATION );
882 // Set to less than 2.0f, the constraint will NOT allow this
883 Vector4 lesserValue( 1.0f, 1.0f, 1.0f, 1.0f );
884 actor.SetProperty( index, lesserValue );
886 application.SendNotification();
887 application.Render(0);
889 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), minValue/*not lesserValue*/, TEST_LOCATION );
891 // Check that nothing has changed after a couple of buffer swaps
892 application.Render(0);
893 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), minValue, TEST_LOCATION );
894 application.Render(0);
895 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), minValue, TEST_LOCATION );
897 // Remove the constraint, then set new value
898 actor.RemoveConstraints();
899 actor.SetProperty( index, lesserValue );
901 // Constraint should have been removed
902 application.SendNotification();
903 application.Render(0);
904 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), lesserValue, TEST_LOCATION );
905 application.Render(0);
906 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), lesserValue, TEST_LOCATION );
910 int UtcDaliConstraintNewMatrix(void)
914 TestApplication application;
916 Actor actor = Actor::New();
918 // Register a Matrix property
919 Matrix startValue = Matrix::IDENTITY;
920 Property::Index index = actor.RegisterProperty( "test-property", startValue );
921 DALI_TEST_CHECK( index != Property::INVALID_INDEX );
922 if (index != Property::INVALID_INDEX)
924 Stage::GetCurrent().Add(actor);
925 DALI_TEST_CHECK( actor.GetProperty<Matrix>(index) == startValue );
928 Matrix constraintLimit;
929 constraintLimit.SetTransformComponents(Vector3::ONE, Quaternion(Radian(Degree(30.0f)), Vector3::YAXIS), Vector3::ZAXIS );
930 Constraint constraint = Constraint::New<Matrix>( index, TestConstraintMatrix(constraintLimit));
931 actor.ApplyConstraint( constraint );
932 DALI_TEST_EQUALS( actor.GetProperty<Matrix>(index), startValue, TEST_LOCATION );
934 application.SendNotification();
935 application.Render(0);
937 DALI_TEST_EQUALS( actor.GetProperty<Matrix>(index), constraintLimit, TEST_LOCATION );
940 catch (Dali::DaliException& e)
942 tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
948 int UtcDaliConstraintNewMatrix3(void)
952 TestApplication application;
954 Actor actor = Actor::New();
956 // Register a Matrix3 property
957 Matrix3 startValue(1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f);
958 Property::Index index = actor.RegisterProperty( "test-property", startValue );
959 DALI_TEST_CHECK( index != Property::INVALID_INDEX );
960 if (index != Property::INVALID_INDEX)
962 Stage::GetCurrent().Add(actor);
963 DALI_TEST_CHECK( actor.GetProperty<Matrix3>(index) == startValue );
966 Matrix3 constraintLimit(42.0f, 0.0f, 0.0f, 0.0f, 42.0f, 0.0f, 0.0f, 0.0f, 1.0f);
967 Constraint constraint = Constraint::New<Matrix3>( index, TestConstraintMatrix3(constraintLimit));
968 actor.ApplyConstraint( constraint );
969 DALI_TEST_EQUALS( actor.GetProperty<Matrix3>(index), startValue, 0.001f, TEST_LOCATION );
971 application.SendNotification();
972 application.Render(0);
974 DALI_TEST_EQUALS( actor.GetProperty<Matrix3>(index), constraintLimit, 0.001f, TEST_LOCATION );
977 catch (Dali::DaliException& e)
979 tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str() );
985 int UtcDaliConstraintNewQuaternion(void)
987 TestApplication application;
989 Actor actor = Actor::New();
991 // Register a Quaternion property
992 Quaternion startValue( 0.0f, Vector3::YAXIS );
993 Property::Index index = actor.RegisterProperty( "test-property", startValue );
994 Stage::GetCurrent().Add(actor);
995 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), startValue, ROTATION_EPSILON, TEST_LOCATION );
998 * Test that the Constraint is correctly applied on a clean Node
1000 application.SendNotification();
1001 application.Render(0);
1002 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), startValue, ROTATION_EPSILON, TEST_LOCATION );
1003 application.Render(0);
1004 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), startValue, ROTATION_EPSILON, TEST_LOCATION );
1005 application.Render(0);
1006 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), startValue, ROTATION_EPSILON, TEST_LOCATION );
1010 Quaternion constrainedRotation( M_PI*0.25f, Vector3::YAXIS );
1011 Constraint constraint = Constraint::New<Quaternion>( index, TestConstraintRotation( constrainedRotation ) );
1013 actor.ApplyConstraint( constraint );
1014 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), startValue, ROTATION_EPSILON, TEST_LOCATION );
1016 application.SendNotification();
1017 application.Render(0);
1019 // Constraint should be fully applied
1020 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), constrainedRotation, ROTATION_EPSILON, TEST_LOCATION );
1022 // Check that nothing has changed after a couple of buffer swaps
1023 application.Render(0);
1024 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), constrainedRotation, ROTATION_EPSILON, TEST_LOCATION );
1025 application.Render(0);
1026 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), constrainedRotation, ROTATION_EPSILON, TEST_LOCATION );
1028 // Set to a different rotation, the constraint will NOT allow this
1029 Quaternion differentRotation( M_PI*0.5f, Vector3::YAXIS );
1030 actor.SetProperty( index, differentRotation );
1032 application.SendNotification();
1033 application.Render(0);
1035 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), constrainedRotation/*not differentRotation*/, ROTATION_EPSILON, TEST_LOCATION );
1037 // Check that nothing has changed after a couple of buffer swaps
1038 application.Render(0);
1039 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), constrainedRotation, ROTATION_EPSILON, TEST_LOCATION );
1040 application.Render(0);
1041 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), constrainedRotation, ROTATION_EPSILON, TEST_LOCATION );
1043 // Remove the constraint, then set new value
1044 actor.RemoveConstraints();
1045 actor.SetProperty( index, differentRotation );
1047 // Constraint should have been removed
1048 application.SendNotification();
1049 application.Render(0);
1050 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), differentRotation, ROTATION_EPSILON, TEST_LOCATION );
1051 application.Render(0);
1052 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), differentRotation, ROTATION_EPSILON, TEST_LOCATION );
1056 int UtcDaliConstraintNewOffStageBoolean(void)
1058 TestApplication application;
1060 Actor actor = Actor::New();
1062 // Register a boolean property
1063 bool startValue(false);
1064 Property::Index index = actor.RegisterProperty( "test-property", startValue );
1065 DALI_TEST_CHECK( actor.GetProperty<bool>(index) == startValue );
1067 // Apply constraint to off-stage Actor
1068 Constraint constraint = Constraint::New<bool>( index, TestAlwaysTrueConstraint() );
1069 actor.ApplyConstraint( constraint );
1071 application.SendNotification();
1072 application.Render(0);
1073 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), false, TEST_LOCATION );
1075 // Add actor to stage
1076 Stage::GetCurrent().Add(actor);
1077 application.SendNotification();
1078 application.Render(0);
1080 // Constraint should be fully applied
1081 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), true, TEST_LOCATION );
1083 // Check that nothing has changed after a couple of buffer swaps
1084 application.Render(0);
1085 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), true, TEST_LOCATION );
1086 application.Render(0);
1087 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), true, TEST_LOCATION );
1089 // Take the actor off-stage
1090 Stage::GetCurrent().Remove(actor);
1091 application.SendNotification();
1092 application.Render(0);
1093 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), true, TEST_LOCATION );
1095 // Set a new value; the constraint will not prevent this
1096 actor.SetProperty( index, false );
1097 application.SendNotification();
1098 application.Render(0);
1099 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), false, TEST_LOCATION );
1101 // Add actor to stage (2nd time)
1102 Stage::GetCurrent().Add(actor);
1103 application.SendNotification();
1104 application.Render(0);
1106 // Constraint should be fully applied (2nd time)
1107 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), true, TEST_LOCATION );
1109 // Check that nothing has changed after a couple of buffer swaps
1110 application.Render(0);
1111 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), true, TEST_LOCATION );
1112 application.Render(0);
1113 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), true, TEST_LOCATION );
1115 // Take the actor off-stage (2nd-time)
1116 Stage::GetCurrent().Remove(actor);
1117 application.SendNotification();
1118 application.Render(0);
1119 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), true, TEST_LOCATION );
1121 // Remove the constraint, and set a new value
1122 actor.RemoveConstraints();
1123 actor.SetProperty( index, false );
1124 application.SendNotification();
1125 application.Render(0);
1126 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), false, TEST_LOCATION );
1128 // Add actor to stage (3rd time)
1129 Stage::GetCurrent().Add(actor);
1130 application.SendNotification();
1131 application.Render(0);
1133 // Constraint should be gone
1134 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), false, TEST_LOCATION );
1136 // Check that nothing has changed after a couple of buffer swaps
1137 application.Render(0);
1138 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), false, TEST_LOCATION );
1139 application.Render(0);
1140 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), false, TEST_LOCATION );
1144 int UtcDaliConstraintNewOffStageFloat(void)
1146 TestApplication application;
1148 Actor actor = Actor::New();
1150 // Register a float property
1151 float startValue(1.0f);
1152 Property::Index index = actor.RegisterProperty( "test-property", startValue );
1153 DALI_TEST_CHECK( actor.GetProperty<float>(index) == startValue );
1155 // Apply constraint to off-stage Actor
1156 float constrainedValue( 2.0f );
1157 Constraint constraint = Constraint::New<float>( index, TestConstraintFloat( constrainedValue ) );
1158 actor.ApplyConstraint( constraint );
1160 application.SendNotification();
1161 application.Render(0);
1162 DALI_TEST_EQUALS( actor.GetProperty<float>(index), startValue, TEST_LOCATION );
1164 // Add actor to stage
1165 Stage::GetCurrent().Add(actor);
1166 application.SendNotification();
1167 application.Render(0);
1169 // Constraint should be fully applied
1170 DALI_TEST_EQUALS( actor.GetProperty<float>(index), constrainedValue, TEST_LOCATION );
1172 // Check that nothing has changed after a couple of buffer swaps
1173 application.Render(0);
1174 DALI_TEST_EQUALS( actor.GetProperty<float>(index), constrainedValue, TEST_LOCATION );
1175 application.Render(0);
1176 DALI_TEST_EQUALS( actor.GetProperty<float>(index), constrainedValue, TEST_LOCATION );
1178 // Take the actor off-stage
1179 Stage::GetCurrent().Remove(actor);
1180 application.SendNotification();
1181 application.Render(0);
1182 DALI_TEST_EQUALS( actor.GetProperty<float>(index), constrainedValue, TEST_LOCATION );
1184 // Set back to startValue; the constraint will not prevent this
1185 actor.SetProperty( index, startValue );
1186 application.SendNotification();
1187 application.Render(0);
1188 DALI_TEST_EQUALS( actor.GetProperty<float>(index), startValue, TEST_LOCATION );
1190 // Add actor to stage (2nd time)
1191 Stage::GetCurrent().Add(actor);
1192 application.SendNotification();
1193 application.Render(0);
1195 // Constraint should be fully applied (2nd time)
1196 DALI_TEST_EQUALS( actor.GetProperty<float>(index), constrainedValue, TEST_LOCATION );
1198 // Check that nothing has changed after a couple of buffer swaps
1199 application.Render(0);
1200 DALI_TEST_EQUALS( actor.GetProperty<float>(index), constrainedValue, TEST_LOCATION );
1201 application.Render(0);
1202 DALI_TEST_EQUALS( actor.GetProperty<float>(index), constrainedValue, TEST_LOCATION );
1204 // Take the actor off-stage (2nd-time)
1205 Stage::GetCurrent().Remove(actor);
1206 application.SendNotification();
1207 application.Render(0);
1208 DALI_TEST_EQUALS( actor.GetProperty<float>(index), constrainedValue, TEST_LOCATION );
1210 // Remove the constraint, and set back to startValue
1211 actor.RemoveConstraints();
1212 actor.SetProperty( index, startValue );
1213 application.SendNotification();
1214 application.Render(0);
1215 DALI_TEST_EQUALS( actor.GetProperty<float>(index), startValue, TEST_LOCATION );
1217 // Add actor to stage (3rd time)
1218 Stage::GetCurrent().Add(actor);
1219 application.SendNotification();
1220 application.Render(0);
1222 // Constraint should be gone
1223 DALI_TEST_EQUALS( actor.GetProperty<float>(index), startValue, TEST_LOCATION );
1225 // Check that nothing has changed after a couple of buffer swaps
1226 application.Render(0);
1227 DALI_TEST_EQUALS( actor.GetProperty<float>(index), startValue, TEST_LOCATION );
1228 application.Render(0);
1229 DALI_TEST_EQUALS( actor.GetProperty<float>(index), startValue, TEST_LOCATION );
1233 int UtcDaliConstraintNewOffStageVector2(void)
1235 TestApplication application;
1237 Actor actor = Actor::New();
1239 // Register a Vector2 property
1240 Vector2 startValue(1.0f, 1.0f);
1241 Property::Index index = actor.RegisterProperty( "test-property", startValue );
1242 DALI_TEST_CHECK( actor.GetProperty<Vector2>(index) == startValue );
1244 // Apply constraint to off-stage Actor
1245 Vector2 constrainedValue( 2.0f, 2.0f );
1246 Constraint constraint = Constraint::New<Vector2>( index, TestConstraintVector2( constrainedValue ) );
1247 actor.ApplyConstraint( constraint );
1249 application.SendNotification();
1250 application.Render(0);
1251 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), startValue, TEST_LOCATION );
1253 // Add actor to stage
1254 Stage::GetCurrent().Add(actor);
1255 application.SendNotification();
1256 application.Render(0);
1258 // Constraint should be fully applied
1259 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), constrainedValue, TEST_LOCATION );
1261 // Check that nothing has changed after a couple of buffer swaps
1262 application.Render(0);
1263 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), constrainedValue, TEST_LOCATION );
1264 application.Render(0);
1265 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), constrainedValue, TEST_LOCATION );
1267 // Take the actor off-stage
1268 Stage::GetCurrent().Remove(actor);
1269 application.SendNotification();
1270 application.Render(0);
1271 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), constrainedValue, TEST_LOCATION );
1273 // Set back to startValue; the constraint will not prevent this
1274 actor.SetProperty( index, startValue );
1275 application.SendNotification();
1276 application.Render(0);
1277 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), startValue, TEST_LOCATION );
1279 // Add actor to stage (2nd time)
1280 Stage::GetCurrent().Add(actor);
1281 application.SendNotification();
1282 application.Render(0);
1284 // Constraint should be fully applied (2nd time)
1285 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), constrainedValue, TEST_LOCATION );
1287 // Check that nothing has changed after a couple of buffer swaps
1288 application.Render(0);
1289 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), constrainedValue, TEST_LOCATION );
1290 application.Render(0);
1291 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), constrainedValue, TEST_LOCATION );
1293 // Take the actor off-stage (2nd-time)
1294 Stage::GetCurrent().Remove(actor);
1295 application.SendNotification();
1296 application.Render(0);
1297 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), constrainedValue, TEST_LOCATION );
1299 // Remove the constraint, and set back to startValue
1300 actor.RemoveConstraints();
1301 actor.SetProperty( index, startValue );
1302 application.SendNotification();
1303 application.Render(0);
1304 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), startValue, TEST_LOCATION );
1306 // Add actor to stage (3rd time)
1307 Stage::GetCurrent().Add(actor);
1308 application.SendNotification();
1309 application.Render(0);
1311 // Constraint should be gone
1312 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), startValue, TEST_LOCATION );
1314 // Check that nothing has changed after a couple of buffer swaps
1315 application.Render(0);
1316 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), startValue, TEST_LOCATION );
1317 application.Render(0);
1318 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), startValue, TEST_LOCATION );
1322 int UtcDaliConstraintNewOffStageVector3(void)
1324 TestApplication application;
1325 Vector3 startValue(1.0f, 1.0f, 1.0f);
1326 Vector3 constrainedValue = Vector3( 2.0f, 3.0f, 4.0f );
1328 Actor actor = Actor::New();
1329 // Register a Vector3 property
1331 Property::Index index = actor.RegisterProperty( "test-property", startValue );
1332 DALI_TEST_CHECK( actor.GetProperty<Vector3>(index) == startValue );
1334 // Apply constraint to off-stage Actor
1335 Constraint constraint = Constraint::New<Vector3>( index, TestConstraintVector3( constrainedValue ) );
1336 actor.ApplyConstraint( constraint );
1338 application.SendNotification();
1339 application.Render(0);
1340 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), startValue, TEST_LOCATION );
1342 // Add actor to stage
1343 Stage::GetCurrent().Add(actor);
1344 application.SendNotification();
1345 application.Render();
1347 // Constraint should be fully applied
1348 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), constrainedValue, TEST_LOCATION );
1350 // Check that nothing has changed after a couple of buffer swaps
1351 application.Render();
1352 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), constrainedValue, TEST_LOCATION );
1353 application.Render();
1354 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), constrainedValue, TEST_LOCATION );
1356 // Take the actor off-stage
1357 Stage::GetCurrent().Remove(actor);
1358 application.SendNotification();
1359 application.Render();
1360 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), constrainedValue, TEST_LOCATION );
1362 // Set back to startValue; the constraint will not prevent this
1363 Vector3 intermediateValue(5.0f, 6.0f, 7.0f);
1364 actor.SetProperty( index, intermediateValue );
1365 application.SendNotification();
1366 application.Render();
1367 application.Render(); // ensure both buffers are set to intermediateValue
1368 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), intermediateValue, TEST_LOCATION );
1370 // Add actor to stage (2nd time)
1371 Stage::GetCurrent().Add(actor);
1372 application.SendNotification();
1373 application.Render();
1375 // Constraint should be fully applied (2nd time)
1376 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), constrainedValue, TEST_LOCATION );
1378 // Check that nothing has changed after a couple of buffer swaps
1379 application.Render();
1380 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), constrainedValue, TEST_LOCATION );
1381 application.Render();
1382 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), constrainedValue, TEST_LOCATION );
1384 // Take the actor off-stage (2nd-time)
1385 Stage::GetCurrent().Remove(actor);
1386 application.SendNotification();
1387 application.Render();
1388 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), constrainedValue, TEST_LOCATION );
1390 // Remove the constraint, and set back to startValue
1391 actor.RemoveConstraints();
1392 actor.SetProperty( index, startValue );
1393 application.SendNotification();
1394 application.Render();
1395 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), startValue, TEST_LOCATION );
1397 // Add actor to stage (3rd time)
1398 Stage::GetCurrent().Add(actor);
1399 application.SendNotification();
1400 application.Render();
1402 // Constraint should be gone
1403 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), startValue, TEST_LOCATION );
1405 // Check that nothing has changed after a couple of buffer swaps
1406 application.Render();
1407 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), startValue, TEST_LOCATION );
1408 application.Render();
1409 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), startValue, TEST_LOCATION );
1413 int UtcDaliConstraintNewOffStageVector4(void)
1415 TestApplication application;
1417 Actor actor = Actor::New();
1419 // Register a Vector4 property
1420 Vector4 startValue(1.0f, 1.0f, 1.0f, 1.0f);
1421 Property::Index index = actor.RegisterProperty( "test-property", startValue );
1422 DALI_TEST_CHECK( actor.GetProperty<Vector4>(index) == startValue );
1424 // Apply constraint to off-stage Actor
1425 Vector4 constrainedValue( 2.0f, 2.0f, 2.0f, 2.0f );
1426 Constraint constraint = Constraint::New<Vector4>( index, TestConstraintVector4( constrainedValue ) );
1427 actor.ApplyConstraint( constraint );
1429 application.SendNotification();
1430 application.Render(0);
1431 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), startValue, TEST_LOCATION );
1433 // Add actor to stage
1434 Stage::GetCurrent().Add(actor);
1435 application.SendNotification();
1436 application.Render(0);
1438 // Constraint should be fully applied
1439 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), constrainedValue, TEST_LOCATION );
1441 // Check that nothing has changed after a couple of buffer swaps
1442 application.Render(0);
1443 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), constrainedValue, TEST_LOCATION );
1444 application.Render(0);
1445 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), constrainedValue, TEST_LOCATION );
1447 // Take the actor off-stage
1448 Stage::GetCurrent().Remove(actor);
1449 application.SendNotification();
1450 application.Render(0);
1451 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), constrainedValue, TEST_LOCATION );
1453 // Set back to startValue; the constraint will not prevent this
1454 actor.SetProperty( index, startValue );
1455 application.SendNotification();
1456 application.Render(0);
1457 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), startValue, TEST_LOCATION );
1459 // Add actor to stage (2nd time)
1460 Stage::GetCurrent().Add(actor);
1461 application.SendNotification();
1462 application.Render(0);
1464 // Constraint should be fully applied (2nd time)
1465 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), constrainedValue, TEST_LOCATION );
1467 // Check that nothing has changed after a couple of buffer swaps
1468 application.Render(0);
1469 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), constrainedValue, TEST_LOCATION );
1470 application.Render(0);
1471 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), constrainedValue, TEST_LOCATION );
1473 // Take the actor off-stage (2nd-time)
1474 Stage::GetCurrent().Remove(actor);
1475 application.SendNotification();
1476 application.Render(0);
1477 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), constrainedValue, TEST_LOCATION );
1479 // Remove the constraint, and set back to startValue
1480 actor.RemoveConstraints();
1481 actor.SetProperty( index, startValue );
1482 application.SendNotification();
1483 application.Render(0);
1484 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), startValue, TEST_LOCATION );
1486 // Add actor to stage (3rd time)
1487 Stage::GetCurrent().Add(actor);
1488 application.SendNotification();
1489 application.Render(0);
1491 // Constraint should be gone
1492 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), startValue, TEST_LOCATION );
1494 // Check that nothing has changed after a couple of buffer swaps
1495 application.Render(0);
1496 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), startValue, TEST_LOCATION );
1497 application.Render(0);
1498 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), startValue, TEST_LOCATION );
1502 int UtcDaliConstraintNewOffStageQuaternion(void)
1504 TestApplication application;
1506 Actor actor = Actor::New();
1508 // Register a Quaternion property
1509 Quaternion startValue( 0.0f, Vector3::YAXIS );
1510 Property::Index index = actor.RegisterProperty( "test-property", startValue );
1511 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), startValue, ROTATION_EPSILON, TEST_LOCATION );
1513 // Apply constraint to off-stage Actor
1514 Quaternion constrainedRotation( M_PI*0.25f, Vector3::YAXIS );
1515 Constraint constraint = Constraint::New<Quaternion>( index, TestConstraintRotation( constrainedRotation ) );
1516 actor.ApplyConstraint( constraint );
1518 application.SendNotification();
1519 application.Render(0);
1520 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), startValue, ROTATION_EPSILON, TEST_LOCATION );
1522 // Add actor to stage
1523 Stage::GetCurrent().Add(actor);
1524 application.SendNotification();
1525 application.Render(0);
1527 // Constraint should be fully applied
1528 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), constrainedRotation, ROTATION_EPSILON, TEST_LOCATION );
1530 // Check that nothing has changed after a couple of buffer swaps
1531 application.Render(0);
1532 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), constrainedRotation, ROTATION_EPSILON, TEST_LOCATION );
1533 application.Render(0);
1534 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), constrainedRotation, ROTATION_EPSILON, TEST_LOCATION );
1536 // Take the actor off-stage
1537 Stage::GetCurrent().Remove(actor);
1538 application.SendNotification();
1539 application.Render(0);
1540 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), constrainedRotation, ROTATION_EPSILON, TEST_LOCATION );
1542 // Set back to startValue; the constraint will not prevent this
1543 actor.SetProperty( index, startValue );
1544 application.SendNotification();
1545 application.Render(0);
1546 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), startValue, ROTATION_EPSILON, TEST_LOCATION );
1548 // Add actor to stage (2nd time)
1549 Stage::GetCurrent().Add(actor);
1550 application.SendNotification();
1551 application.Render(0);
1553 // Constraint should be fully applied (2nd time)
1554 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), constrainedRotation, ROTATION_EPSILON, TEST_LOCATION );
1556 // Check that nothing has changed after a couple of buffer swaps
1557 application.Render(0);
1558 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), constrainedRotation, ROTATION_EPSILON, TEST_LOCATION );
1559 application.Render(0);
1560 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), constrainedRotation, ROTATION_EPSILON, TEST_LOCATION );
1562 // Take the actor off-stage (2nd-time)
1563 Stage::GetCurrent().Remove(actor);
1564 application.SendNotification();
1565 application.Render(0);
1566 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), constrainedRotation, ROTATION_EPSILON, TEST_LOCATION );
1568 // Remove the constraint, and set back to startValue
1569 actor.RemoveConstraints();
1570 actor.SetProperty( index, startValue );
1571 application.SendNotification();
1572 application.Render(0);
1573 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), startValue, ROTATION_EPSILON, TEST_LOCATION );
1575 // Add actor to stage (3rd time)
1576 Stage::GetCurrent().Add(actor);
1577 application.SendNotification();
1578 application.Render(0);
1580 // Constraint should be gone
1581 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), startValue, ROTATION_EPSILON, TEST_LOCATION );
1583 // Check that nothing has changed after a couple of buffer swaps
1584 application.Render(0);
1585 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), startValue, ROTATION_EPSILON, TEST_LOCATION );
1586 application.Render(0);
1587 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), startValue, ROTATION_EPSILON, TEST_LOCATION );
1591 int UtcDaliConstraintNewLocalInput(void)
1593 TestApplication application;
1595 Actor actor = Actor::New();
1596 Stage::GetCurrent().Add(actor);
1598 Vector3 startValue( 0.0f, 0.0f, 0.0f );
1599 float distanceWhenFullyTransparent( 100.0f );
1602 * Test that the Constraint is correctly applied on a clean Node
1604 application.SendNotification();
1605 application.Render(0);
1606 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1607 application.Render(0);
1608 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1609 application.Render(0);
1610 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1612 // Apply constraint with a local input property
1614 Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
1615 LocalSource( Actor::COLOR ),
1616 MoveAwayWithFadeConstraint(distanceWhenFullyTransparent) );
1618 actor.ApplyConstraint( constraint );
1619 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1621 application.SendNotification();
1622 application.Render(0);
1624 // Gradually set the color to fully-transparent; the actor should move back
1626 for ( float progress = 0.0f; progress < 1.1f; progress += 0.1f )
1628 actor.SetOpacity( 1.0f - progress );
1630 application.SendNotification();
1631 application.Render(0);
1632 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), ( startValue - Vector3(0.0f, 0.0f, progress*distanceWhenFullyTransparent) ), POSITION_EPSILON, TEST_LOCATION );
1634 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), ( startValue - Vector3(0.0f, 0.0f, distanceWhenFullyTransparent) ), POSITION_EPSILON, TEST_LOCATION );
1638 int UtcDaliConstraintNewParentInput(void)
1640 TestApplication application;
1642 Actor parent = Actor::New();
1643 Vector3 parentStartSize( 100.0f, 100.0f, 0.0f );
1644 parent.SetSize( parentStartSize );
1645 Stage::GetCurrent().Add( parent );
1647 Actor actor = Actor::New();
1648 parent.Add( actor );
1650 Vector3 startValue( 0.0f, 0.0f, 0.0f );
1653 * Test that the Constraint is correctly applied on a clean Node
1655 application.SendNotification();
1656 application.Render(0);
1657 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1658 application.Render(0);
1659 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1660 application.Render(0);
1661 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1663 // Apply constraint with a parent input property
1665 Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
1666 ParentSource( Actor::SIZE ),
1667 TestBottomRightAlignConstraint() );
1669 actor.ApplyConstraint( constraint );
1670 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1672 application.SendNotification();
1673 application.Render(0);
1675 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), parentStartSize, TEST_LOCATION );
1676 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), parent.GetCurrentSize(), TEST_LOCATION );
1678 // Gradually shrink the parent; the actor should move inwards
1680 for ( float progress = 0.0f; progress < 1.1f; progress += 0.1f )
1682 Vector3 size( parentStartSize * std::max(0.0f, 1.0f - progress) );
1683 parent.SetSize( size );
1685 application.SendNotification();
1686 application.Render(0);
1688 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), size, POSITION_EPSILON, TEST_LOCATION );
1689 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), parent.GetCurrentSize(), POSITION_EPSILON, TEST_LOCATION );
1691 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), Vector3::ZERO, POSITION_EPSILON, TEST_LOCATION );
1695 int UtcDaliConstraintNewInput1(void)
1697 TestApplication application;
1699 Actor parent = Actor::New();
1700 Vector3 parentStartSize( 100.0f, 100.0f, 0.0f );
1701 parent.SetSize( parentStartSize );
1702 Stage::GetCurrent().Add( parent );
1704 Actor actor = Actor::New();
1705 parent.Add( actor );
1707 Actor sibling1 = Actor::New();
1708 sibling1.SetPosition( Vector3(1.0f, 2.0f, 3.0f) );
1709 parent.Add( sibling1 );
1711 Vector3 startValue( 0.0f, 0.0f, 0.0f );
1714 * Test that the Constraint is correctly applied on a clean Node
1716 application.SendNotification();
1717 application.Render(0);
1718 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1719 application.Render(0);
1720 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1721 application.Render(0);
1722 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1724 // Apply constraint with a parent input property
1726 Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
1727 Source( sibling1, Actor::POSITION ),
1728 MeanPositionConstraint1() );
1730 actor.ApplyConstraint( constraint );
1731 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1733 application.SendNotification();
1734 application.Render(0);
1735 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), sibling1.GetCurrentPosition(), TEST_LOCATION );
1737 // Check that nothing has changed after a couple of buffer swaps
1738 application.Render(0);
1739 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), sibling1.GetCurrentPosition(), TEST_LOCATION );
1740 application.Render(0);
1741 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), sibling1.GetCurrentPosition(), TEST_LOCATION );
1745 int UtcDaliConstraintNewInput2(void)
1747 TestApplication application;
1749 Actor parent = Actor::New();
1750 Vector3 parentStartSize( 100.0f, 100.0f, 0.0f );
1751 parent.SetSize( parentStartSize );
1752 Stage::GetCurrent().Add( parent );
1754 Actor actor = Actor::New();
1755 parent.Add( actor );
1757 Actor sibling1 = Actor::New();
1758 sibling1.SetPosition( Vector3(1.0f, 2.0f, 3.0f) );
1759 parent.Add( sibling1 );
1761 Actor sibling2 = Actor::New();
1762 sibling2.SetPosition( Vector3(300.0f, 300.0f, 300.0f) );
1763 parent.Add( sibling2 );
1765 application.SendNotification();
1766 application.Render(0);
1768 Vector3 startValue( 0.0f, 0.0f, 0.0f );
1769 Vector3 meanValue = sibling1.GetCurrentPosition() +
1770 sibling2.GetCurrentPosition();
1771 meanValue *= (1.0f / 2.0f); // divide by number of siblings
1774 * Test that the Constraint is correctly applied on a clean Node
1776 application.SendNotification();
1777 application.Render(0);
1778 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1779 application.Render(0);
1780 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1781 application.Render(0);
1782 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1784 // Apply constraint with a parent input property
1786 Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
1787 Source( sibling1, Actor::POSITION ),
1788 Source( sibling2, Actor::POSITION ),
1789 MeanPositionConstraint2() );
1791 actor.ApplyConstraint( constraint );
1792 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1794 application.SendNotification();
1795 application.Render(0);
1796 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION );
1798 // Check that nothing has changed after a couple of buffer swaps
1799 application.Render(0);
1800 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION );
1801 application.Render(0);
1802 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION );
1806 int UtcDaliConstraintNewInput3(void)
1808 TestApplication application;
1810 Actor parent = Actor::New();
1811 Vector3 parentStartSize( 100.0f, 100.0f, 0.0f );
1812 parent.SetSize( parentStartSize );
1813 Stage::GetCurrent().Add( parent );
1815 Actor actor = Actor::New();
1816 parent.Add( actor );
1818 Actor sibling1 = Actor::New();
1819 sibling1.SetPosition( Vector3(1.0f, 2.0f, 3.0f) );
1820 parent.Add( sibling1 );
1822 Actor sibling2 = Actor::New();
1823 sibling2.SetPosition( Vector3(300.0f, 300.0f, 300.0f) );
1824 parent.Add( sibling2 );
1826 Actor sibling3 = Actor::New();
1827 sibling3.SetPosition( Vector3(-100.0f, -10.0f, -1.0f) );
1828 parent.Add( sibling3 );
1830 application.SendNotification();
1831 application.Render(0);
1833 Vector3 startValue( 0.0f, 0.0f, 0.0f );
1834 Vector3 meanValue = sibling1.GetCurrentPosition() +
1835 sibling2.GetCurrentPosition() +
1836 sibling3.GetCurrentPosition();
1837 meanValue *= (1.0f / 3.0f); // divide by number of siblings
1840 * Test that the Constraint is correctly applied on a clean Node
1842 application.SendNotification();
1843 application.Render(0);
1844 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1845 application.Render(0);
1846 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1847 application.Render(0);
1848 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1850 // Apply constraint with a parent input property
1852 Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
1853 Source( sibling1, Actor::POSITION ),
1854 Source( sibling2, Actor::POSITION ),
1855 Source( sibling3, Actor::POSITION ),
1856 MeanPositionConstraint3() );
1858 actor.ApplyConstraint( constraint );
1859 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1861 application.SendNotification();
1862 application.Render(0);
1863 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION );
1865 // Check that nothing has changed after a couple of buffer swaps
1866 application.Render(0);
1867 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION );
1868 application.Render(0);
1869 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION );
1873 int UtcDaliConstraintNewInput4(void)
1875 TestApplication application;
1877 Actor parent = Actor::New();
1878 Vector3 parentStartSize( 100.0f, 100.0f, 0.0f );
1879 parent.SetSize( parentStartSize );
1880 parent.SetPosition( 10.0f, 10.0f, 10.0f );
1881 Stage::GetCurrent().Add( parent );
1883 Actor actor = Actor::New();
1884 parent.Add( actor );
1886 Actor sibling1 = Actor::New();
1887 sibling1.SetPosition( Vector3(1.0f, 2.0f, 3.0f) );
1888 parent.Add( sibling1 );
1890 Actor sibling2 = Actor::New();
1891 sibling2.SetPosition( Vector3(300.0f, 300.0f, 300.0f) );
1892 parent.Add( sibling2 );
1894 Actor sibling3 = Actor::New();
1895 sibling3.SetPosition( Vector3(-100.0f, -10.0f, -1.0f) );
1896 parent.Add( sibling3 );
1898 application.SendNotification();
1899 application.Render(0);
1901 Vector3 startValue( 0.0f, 0.0f, 0.0f );
1902 Vector3 meanValue = parent.GetCurrentPosition() +
1903 sibling1.GetCurrentPosition() +
1904 sibling2.GetCurrentPosition() +
1905 sibling3.GetCurrentPosition();
1906 meanValue *= (1.0f / 4.0f); // divide by number of positions
1909 * Test that the Constraint is correctly applied on a clean Node
1911 application.SendNotification();
1912 application.Render(0);
1913 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1914 application.Render(0);
1915 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1916 application.Render(0);
1917 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1919 // Apply constraint with a parent input property
1921 Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
1922 Source( sibling1, Actor::POSITION ),
1923 Source( sibling2, Actor::POSITION ),
1924 ParentSource( Actor::POSITION ),
1925 Source( sibling3, Actor::POSITION ),
1926 MeanPositionConstraint4() );
1928 actor.ApplyConstraint( constraint );
1929 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1931 application.SendNotification();
1932 application.Render(0);
1933 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION );
1935 // Check that nothing has changed after a couple of buffer swaps
1936 application.Render(0);
1937 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION );
1938 application.Render(0);
1939 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION );
1943 int UtcDaliConstraintNewInput5(void)
1945 TestApplication application;
1947 Actor parent = Actor::New();
1948 Vector3 parentStartSize( 100.0f, 100.0f, 0.0f );
1949 parent.SetSize( parentStartSize );
1950 parent.SetPosition( 10.0f, 10.0f, 10.0f );
1951 Stage::GetCurrent().Add( parent );
1953 Actor actor = Actor::New();
1954 parent.Add( actor );
1956 Actor sibling1 = Actor::New();
1957 sibling1.SetPosition( Vector3(1.0f, 2.0f, 3.0f) );
1958 parent.Add( sibling1 );
1960 Actor sibling2 = Actor::New();
1961 sibling2.SetPosition( Vector3(300.0f, 300.0f, 300.0f) );
1962 parent.Add( sibling2 );
1964 Actor sibling3 = Actor::New();
1965 sibling3.SetPosition( Vector3(-100.0f, -10.0f, -1.0f) );
1966 parent.Add( sibling3 );
1968 Actor sibling4 = Actor::New();
1969 sibling4.SetPosition( Vector3(-1.0f, 1.0f, 2.0f) );
1970 parent.Add( sibling4 );
1972 application.SendNotification();
1973 application.Render(0);
1975 Vector3 startValue( 0.0f, 0.0f, 0.0f );
1976 Vector3 meanValue = parent.GetCurrentPosition() +
1977 sibling1.GetCurrentPosition() +
1978 sibling2.GetCurrentPosition() +
1979 sibling3.GetCurrentPosition() +
1980 sibling4.GetCurrentPosition();
1981 meanValue *= (1.0f / 5.0f); // divide by number of positions
1984 * Test that the Constraint is correctly applied on a clean Node
1986 application.SendNotification();
1987 application.Render(0);
1988 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1989 application.Render(0);
1990 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1991 application.Render(0);
1992 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1994 // Apply constraint with a parent input property
1996 Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
1997 Source( sibling1, Actor::POSITION ),
1998 Source( sibling2, Actor::POSITION ),
1999 ParentSource( Actor::POSITION ),
2000 Source( sibling3, Actor::POSITION ),
2001 Source( sibling4, Actor::POSITION ),
2002 MeanPositionConstraint5() );
2004 actor.ApplyConstraint( constraint );
2005 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
2007 application.SendNotification();
2008 application.Render(0);
2009 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION );
2011 // Check that nothing has changed after a couple of buffer swaps
2012 application.Render(0);
2013 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION );
2014 application.Render(0);
2015 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION );
2019 int UtcDaliConstraintNewInput6(void)
2021 TestApplication application;
2023 Actor parent = Actor::New();
2024 Vector3 parentStartSize( 100.0f, 100.0f, 0.0f );
2025 parent.SetSize( parentStartSize );
2026 parent.SetPosition( 10.0f, 10.0f, 10.0f );
2027 Stage::GetCurrent().Add( parent );
2029 Actor actor = Actor::New();
2030 parent.Add( actor );
2032 Actor child = Actor::New();
2033 child.SetPosition( Vector3(7.0f, 7.0f, 7.0f) );
2036 Actor sibling1 = Actor::New();
2037 sibling1.SetPosition( Vector3(1.0f, 2.0f, 3.0f) );
2038 parent.Add( sibling1 );
2040 Actor sibling2 = Actor::New();
2041 sibling2.SetPosition( Vector3(300.0f, 300.0f, 300.0f) );
2042 parent.Add( sibling2 );
2044 Actor sibling3 = Actor::New();
2045 sibling3.SetPosition( Vector3(-100.0f, -10.0f, -1.0f) );
2046 parent.Add( sibling3 );
2048 Actor sibling4 = Actor::New();
2049 sibling4.SetPosition( Vector3(-1.0f, 1.0f, 2.0f) );
2050 parent.Add( sibling4 );
2052 application.SendNotification();
2053 application.Render(0);
2055 Vector3 startValue( 0.0f, 0.0f, 0.0f );
2056 Vector3 meanValue = parent.GetCurrentPosition() +
2057 child.GetCurrentPosition() +
2058 sibling1.GetCurrentPosition() +
2059 sibling2.GetCurrentPosition() +
2060 sibling3.GetCurrentPosition() +
2061 sibling4.GetCurrentPosition();
2062 meanValue *= (1.0f / 6.0f); // divide by number of positions
2065 * Test that the Constraint is correctly applied on a clean Node
2067 application.SendNotification();
2068 application.Render(0);
2069 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
2070 application.Render(0);
2071 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
2072 application.Render(0);
2073 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
2075 // Apply constraint with a parent input property
2077 Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
2078 Source( child, Actor::POSITION ),
2079 Source( sibling1, Actor::POSITION ),
2080 Source( sibling2, Actor::POSITION ),
2081 ParentSource( Actor::POSITION ),
2082 Source( sibling3, Actor::POSITION ),
2083 Source( sibling4, Actor::POSITION ),
2084 MeanPositionConstraint6() );
2086 actor.ApplyConstraint( constraint );
2087 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
2089 application.SendNotification();
2090 application.Render(0);
2091 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION );
2093 // Check that nothing has changed after a couple of buffer swaps
2094 application.Render(0);
2095 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION );
2096 application.Render(0);
2097 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION );
2101 int UtcDaliConstraintDownCast(void)
2103 TestApplication application;
2104 tet_infoline("Testing Dali::Constraint::DownCast()");
2106 Actor actor = Actor::New();
2108 // Register a boolean property
2109 bool startValue(false);
2110 Property::Index index = actor.RegisterProperty( "test-property", startValue );
2111 Constraint constraint = Constraint::New<bool>( index, TestAlwaysTrueConstraint() );
2113 BaseHandle object(constraint);
2115 Constraint constraint2 = Constraint::DownCast(object);
2116 DALI_TEST_CHECK(constraint2);
2118 Constraint constraint3 = DownCast< Constraint >(object);
2119 DALI_TEST_CHECK(constraint3);
2121 BaseHandle unInitializedObject;
2122 Constraint constraint4 = Constraint::DownCast(unInitializedObject);
2123 DALI_TEST_CHECK(!constraint4);
2125 Constraint constraint5 = DownCast< Constraint >(unInitializedObject);
2126 DALI_TEST_CHECK(!constraint5);
2130 int UtcDaliConstraintSetApplyTime(void)
2132 TestApplication application;
2136 Vector4 targetColor(Color::BLACK);
2137 Constraint constraint = Constraint::New<Vector4>( Actor::COLOR, TestColorConstraint(targetColor) );
2138 DALI_TEST_EQUALS(constraint.GetApplyTime(), TimePeriod(0.0f), TEST_LOCATION);
2140 float applySeconds(7.0f);
2141 constraint.SetApplyTime(applySeconds);
2142 DALI_TEST_EQUALS(constraint.GetApplyTime(), TimePeriod(applySeconds), TEST_LOCATION);
2144 // Apply to an actor
2146 Actor actor = Actor::New();
2147 Stage::GetCurrent().Add(actor);
2149 actor.ApplyConstraint( constraint );
2150 DALI_TEST_EQUALS( actor.GetCurrentColor(), Color::WHITE, TEST_LOCATION );
2152 application.SendNotification();
2153 application.Render(static_cast<unsigned int>(applySeconds*200.0f)/* 20% progress */);
2155 // Constraint shouldn't be fully applied yet
2156 Vector4 twentyPercentColor( Color::WHITE.x*0.8f, Color::WHITE.y*0.8f, Color::WHITE.z*0.8f, Color::WHITE.a );
2157 DALI_TEST_EQUALS( actor.GetCurrentColor(), twentyPercentColor, TEST_LOCATION );
2159 // Constraint shouldn't be fully applied yet
2160 application.Render(static_cast<unsigned int>(applySeconds*200.0f)/* 40% progress */);
2161 Vector4 fourtyPercentColor( Color::WHITE.x*0.6f, Color::WHITE.y*0.6f, Color::WHITE.z*0.6f, Color::WHITE.a );
2162 DALI_TEST_EQUALS( actor.GetCurrentColor(), fourtyPercentColor, TEST_LOCATION );
2164 // Constraint shouldn't be fully applied yet
2165 application.Render(static_cast<unsigned int>(applySeconds*200.0f)/* 60% progress */);
2166 Vector4 sixtyPercentColor( Color::WHITE.x*0.4f, Color::WHITE.y*0.4f, Color::WHITE.z*0.4f, Color::WHITE.a );
2167 DALI_TEST_EQUALS( actor.GetCurrentColor(), sixtyPercentColor, TEST_LOCATION );
2169 // Constraint shouldn't be fully applied yet
2170 application.Render(static_cast<unsigned int>(applySeconds*200.0f)/* 80% progress */);
2171 Vector4 eightyPercentColor( Color::WHITE.x*0.2f, Color::WHITE.y*0.2f, Color::WHITE.z*0.2f, Color::WHITE.a );
2172 DALI_TEST_EQUALS( actor.GetCurrentColor(), eightyPercentColor, TEST_LOCATION );
2174 // Constraint should be fully applied
2175 application.Render(static_cast<unsigned int>(applySeconds*200.0f)/* 100% progress */);
2176 DALI_TEST_EQUALS( actor.GetCurrentColor(), targetColor, TEST_LOCATION );
2178 // Constraint should still be fully applied
2179 application.Render(static_cast<unsigned int>(applySeconds*200.0f)/* Still 100% progress */);
2180 DALI_TEST_EQUALS( actor.GetCurrentColor(), targetColor, TEST_LOCATION );
2182 // Check that nothing has changed after a couple of buffer swaps
2183 application.Render(0);
2184 DALI_TEST_EQUALS( actor.GetCurrentColor(), targetColor, TEST_LOCATION );
2185 application.Render(0);
2186 DALI_TEST_EQUALS( actor.GetCurrentColor(), targetColor, TEST_LOCATION );
2190 int UtcDaliConstraintGetApplyTime(void)
2192 TestApplication application;
2194 Constraint constraint = Constraint::New<Vector4>( Actor::COLOR, TestConstraint() );
2195 DALI_TEST_EQUALS(constraint.GetApplyTime(), TimePeriod(0.0f), TEST_LOCATION);
2197 float applySeconds(7.0f);
2198 constraint.SetApplyTime(applySeconds);
2199 DALI_TEST_EQUALS(constraint.GetApplyTime(), TimePeriod(applySeconds), TEST_LOCATION);
2201 constraint.SetApplyTime(applySeconds - 3.0f);
2202 DALI_TEST_EQUALS(constraint.GetApplyTime(), TimePeriod(applySeconds - 3.0f), TEST_LOCATION);
2206 int UtcDaliConstraintSetRemoveTime(void)
2208 TestApplication application;
2210 Vector3 sourcePosition(0.0f, 0.0f, 0.0f);
2211 Vector3 targetPosition(100.0f, 100.0f, 100.0f);
2215 Constraint constraint = Constraint::New<Vector3>( Actor::POSITION, TestPositionConstraint(targetPosition) );
2216 DALI_TEST_EQUALS(constraint.GetRemoveTime(), TimePeriod(0.0f), TEST_LOCATION);
2218 float removeSeconds(8.0f);
2219 constraint.SetRemoveTime(removeSeconds);
2220 DALI_TEST_EQUALS(constraint.GetRemoveTime(), TimePeriod(removeSeconds), TEST_LOCATION);
2222 // Apply to an actor
2224 Actor actor = Actor::New();
2225 Stage::GetCurrent().Add(actor);
2227 actor.ApplyConstraint( constraint );
2228 DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION );
2230 application.SendNotification();
2231 application.Render(100u/*0.1 seconds*/);
2233 // Constraint should be fully applied
2234 DALI_TEST_EQUALS( actor.GetCurrentPosition(), targetPosition, TEST_LOCATION );
2236 // Check that nothing has changed after a couple of buffer swaps
2237 application.Render(0);
2238 DALI_TEST_EQUALS( actor.GetCurrentPosition(), targetPosition, TEST_LOCATION );
2239 application.Render(0);
2240 DALI_TEST_EQUALS( actor.GetCurrentPosition(), targetPosition, TEST_LOCATION );
2242 // Remove from the actor, and set to alternative position
2244 actor.RemoveConstraints();
2246 Vector3 thirdPosition(200.0f, 200.0f, 200.0f);
2247 actor.SetPosition(thirdPosition); // Go back to 3rd position
2249 application.SendNotification();
2250 application.Render(static_cast<unsigned int>(removeSeconds*200.0f)/* 20% removal progress */);
2252 // Constraint shouldn't be fully removed yet
2253 Vector3 twentyPercentBack( targetPosition + (thirdPosition - targetPosition)*0.2f );
2254 DALI_TEST_EQUALS( actor.GetCurrentPosition(), twentyPercentBack, TEST_LOCATION );
2256 application.Render(static_cast<unsigned int>(removeSeconds*200.0f)/* 40% removal progress */);
2258 // Constraint shouldn't be fully removed yet
2259 Vector3 fourtyPercentBack( targetPosition + (thirdPosition - targetPosition)*0.4f );
2260 DALI_TEST_EQUALS( actor.GetCurrentPosition(), fourtyPercentBack, TEST_LOCATION );
2262 application.Render(static_cast<unsigned int>(removeSeconds*200.0f)/* 60% removal progress */);
2264 // Constraint shouldn't be fully removed yet
2265 Vector3 sixtyPercentBack( targetPosition + (thirdPosition - targetPosition)*0.6f );
2266 DALI_TEST_EQUALS( actor.GetCurrentPosition(), sixtyPercentBack, TEST_LOCATION );
2268 application.Render(static_cast<unsigned int>(removeSeconds*200.0f)/* 80% removal progress */);
2270 // Constraint shouldn't be fully removed yet
2271 Vector3 eightyPercentBack( targetPosition + (thirdPosition - targetPosition)*0.8f );
2272 DALI_TEST_EQUALS( actor.GetCurrentPosition(), eightyPercentBack, TEST_LOCATION );
2274 // Constraint should be fully removed
2275 application.Render(static_cast<unsigned int>(removeSeconds*200.0f)/* 100% removal progress */);
2276 DALI_TEST_EQUALS( actor.GetCurrentPosition(), thirdPosition, TEST_LOCATION );
2278 // Constraint should still be fully applied
2279 application.Render(static_cast<unsigned int>(removeSeconds*200.0f)/* Still 100% removal progress */);
2280 DALI_TEST_EQUALS( actor.GetCurrentPosition(), thirdPosition, TEST_LOCATION );
2282 // Check that nothing has changed after a couple of buffer swaps
2283 application.Render(0);
2284 DALI_TEST_EQUALS( actor.GetCurrentPosition(), thirdPosition, TEST_LOCATION );
2285 application.Render(0);
2286 DALI_TEST_EQUALS( actor.GetCurrentPosition(), thirdPosition, TEST_LOCATION );
2290 int UtcDaliConstraintGetRemoveTime(void)
2292 TestApplication application;
2294 Constraint constraint = Constraint::New<Vector4>( Actor::COLOR, TestConstraint() );
2295 DALI_TEST_EQUALS(constraint.GetRemoveTime(), TimePeriod(0.0f), TEST_LOCATION);
2299 int UtcDaliConstraintSetAlphaFunction(void)
2301 TestApplication application;
2303 Vector3 startValue( Vector3::ZERO );
2304 Vector3 targetValue(100.0f, 100.0f, 100.0f);
2306 Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
2307 TestConstraintVector3( targetValue ) );
2309 // Test the alpha-function itself
2311 AlphaFunction func = constraint.GetAlphaFunction();
2312 DALI_TEST_EQUALS(func(0.1f), 0.1f, TEST_LOCATION); // Default is Linear
2314 // Test that the alpha-function is used correctly
2316 Actor actor = Actor::New();
2317 Stage::GetCurrent().Add(actor);
2319 application.SendNotification();
2320 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2321 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
2322 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2323 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
2324 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2325 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
2327 constraint.SetApplyTime( 10.0f );
2328 actor.ApplyConstraint( constraint );
2330 application.SendNotification();
2331 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2332 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), (targetValue - startValue) * 0.1f, TEST_LOCATION );
2333 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2334 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), (targetValue - startValue) * 0.2f, TEST_LOCATION );
2335 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2336 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), (targetValue - startValue) * 0.3f, TEST_LOCATION );
2337 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2338 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), (targetValue - startValue) * 0.4f, TEST_LOCATION );
2339 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2340 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), (targetValue - startValue) * 0.5f, TEST_LOCATION );
2341 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2342 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), (targetValue - startValue) * 0.6f, TEST_LOCATION );
2343 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2344 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), (targetValue - startValue) * 0.7f, TEST_LOCATION );
2345 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2346 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), (targetValue - startValue) * 0.8f, TEST_LOCATION );
2347 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2348 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), (targetValue - startValue) * 0.9f, TEST_LOCATION );
2349 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2350 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), (targetValue - startValue), TEST_LOCATION );
2352 // Check that the constrained value is stable
2353 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2354 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), (targetValue - startValue), TEST_LOCATION );
2355 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2356 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), (targetValue - startValue), TEST_LOCATION );
2358 // Remove the constraint
2360 actor.RemoveConstraints();
2361 actor.SetPosition( startValue );
2363 application.SendNotification();
2364 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2365 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
2366 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2367 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
2368 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2369 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
2371 // Change to non-linear alpha and retest
2373 constraint.SetAlphaFunction(AlphaFunctions::EaseIn);
2374 func = constraint.GetAlphaFunction();
2375 DALI_TEST_CHECK(func(0.1f) < 0.09f);
2377 actor.ApplyConstraint( constraint );
2379 application.SendNotification();
2380 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2382 DALI_TEST_CHECK( actor.GetProperty<Vector3>( Actor::POSITION ).x > startValue.x );
2383 DALI_TEST_CHECK( actor.GetProperty<Vector3>( Actor::POSITION ).y > startValue.y );
2384 DALI_TEST_CHECK( actor.GetProperty<Vector3>( Actor::POSITION ).z > startValue.z );
2386 Vector3 lessThanTenPercentProgress( (targetValue - startValue) * 0.09f );
2387 DALI_TEST_CHECK( actor.GetProperty<Vector3>( Actor::POSITION ).x < lessThanTenPercentProgress.x );
2388 DALI_TEST_CHECK( actor.GetProperty<Vector3>( Actor::POSITION ).y < lessThanTenPercentProgress.y );
2389 DALI_TEST_CHECK( actor.GetProperty<Vector3>( Actor::POSITION ).z < lessThanTenPercentProgress.z );
2391 application.Render(static_cast<unsigned int>(9000.0f/*9 seconds*/));
2392 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), (targetValue - startValue), TEST_LOCATION );
2394 // Check that the constrained value is stable
2395 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2396 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), (targetValue - startValue), TEST_LOCATION );
2397 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2398 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), (targetValue - startValue), TEST_LOCATION );
2402 int UtcDaliConstraintGetAlphaFunction(void)
2404 TestApplication application;
2406 Constraint constraint = Constraint::New<Vector4>( Actor::COLOR, TestConstraint() );
2408 AlphaFunction func = constraint.GetAlphaFunction();
2409 DALI_TEST_EQUALS(func(0.5f), 0.5f, TEST_LOCATION); // Default is Linear
2413 int UtcDaliConstraintSetRemoveAction(void)
2415 TestApplication application;
2417 Vector3 sourcePosition(0.0f, 0.0f, 0.0f);
2418 Vector3 targetPosition(100.0f, 100.0f, 100.0f);
2420 // Build constraint, with "Discard" remove action
2422 Constraint constraint = Constraint::New<Vector3>( Actor::POSITION, TestPositionConstraint(targetPosition) );
2423 DALI_TEST_EQUALS((unsigned int)constraint.GetRemoveAction(), (unsigned int)Constraint::Bake, TEST_LOCATION);
2425 constraint.SetRemoveAction(Constraint::Discard);
2426 DALI_TEST_EQUALS((unsigned int)constraint.GetRemoveAction(), (unsigned int)Constraint::Discard, TEST_LOCATION);
2428 float removeSeconds(8.0f);
2429 constraint.SetRemoveTime(removeSeconds);
2430 DALI_TEST_EQUALS(constraint.GetRemoveTime(), TimePeriod(removeSeconds), TEST_LOCATION);
2432 // Apply to an actor
2434 Actor actor = Actor::New();
2435 Stage::GetCurrent().Add(actor);
2437 actor.ApplyConstraint( constraint );
2438 DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION );
2440 application.SendNotification();
2441 application.Render(100u/*0.1 seconds*/);
2443 // Constraint should be fully applied
2444 DALI_TEST_EQUALS( actor.GetCurrentPosition(), targetPosition, TEST_LOCATION );
2446 // Check that nothing has changed after a couple of buffer swaps
2447 application.Render(0);
2448 DALI_TEST_EQUALS( actor.GetCurrentPosition(), targetPosition, TEST_LOCATION );
2449 application.Render(0);
2450 DALI_TEST_EQUALS( actor.GetCurrentPosition(), targetPosition, TEST_LOCATION );
2452 // Remove from the actor
2454 actor.RemoveConstraints(); // should go back to source position
2456 application.SendNotification();
2457 application.Render(static_cast<unsigned int>(removeSeconds*200.0f)/* 20% removal progress */);
2459 // Constraint shouldn't be fully removed yet
2460 Vector3 twentyPercentBack( targetPosition * 0.8f );
2461 DALI_TEST_EQUALS( actor.GetCurrentPosition(), twentyPercentBack, TEST_LOCATION );
2463 application.Render(static_cast<unsigned int>(removeSeconds*200.0f)/* 40% removal progress */);
2465 // Constraint shouldn't be fully removed yet
2466 Vector3 fourtyPercentBack( targetPosition * 0.6f );
2467 DALI_TEST_EQUALS( actor.GetCurrentPosition(), fourtyPercentBack, TEST_LOCATION );
2469 application.Render(static_cast<unsigned int>(removeSeconds*200.0f)/* 60% removal progress */);
2471 // Constraint shouldn't be fully removed yet
2472 Vector3 sixtyPercentBack( targetPosition * 0.4f );
2473 DALI_TEST_EQUALS( actor.GetCurrentPosition(), sixtyPercentBack, TEST_LOCATION );
2475 application.Render(static_cast<unsigned int>(removeSeconds*200.0f)/* 80% removal progress */);
2477 // Constraint shouldn't be fully removed yet
2478 Vector3 eightyPercentBack( targetPosition * 0.2f );
2479 DALI_TEST_EQUALS( actor.GetCurrentPosition(), eightyPercentBack, TEST_LOCATION );
2481 // Constraint should be fully removed
2482 application.Render(static_cast<unsigned int>(removeSeconds*200.0f)/* 100% removal progress */);
2483 DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION );
2485 // Constraint should still be fully applied
2486 application.Render(static_cast<unsigned int>(removeSeconds*200.0f)/* Still 100% removal progress */);
2487 DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION );
2489 // Check that nothing has changed after a couple of buffer swaps
2490 application.Render(0);
2491 DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION );
2492 application.Render(0);
2493 DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION );
2497 int UtcDaliConstraintGetRemoveAction(void)
2499 TestApplication application;
2501 Constraint constraint = Constraint::New<Vector4>( Actor::COLOR, TestConstraint() );
2502 DALI_TEST_EQUALS((unsigned int)constraint.GetRemoveAction(), (unsigned int)Constraint::Bake, TEST_LOCATION);
2504 constraint.SetRemoveAction(Constraint::Discard);
2505 DALI_TEST_EQUALS((unsigned int)constraint.GetRemoveAction(), (unsigned int)Constraint::Discard, TEST_LOCATION);
2507 constraint.SetRemoveAction(Constraint::Bake);
2508 DALI_TEST_EQUALS((unsigned int)constraint.GetRemoveAction(), (unsigned int)Constraint::Bake, TEST_LOCATION);
2513 * Test a constraint with non-zero apply-time and remove-time, where the constraint is removed during the apply-time
2515 int UtcDaliConstraintRemoveDuringApply(void)
2517 TestApplication application;
2519 Vector3 sourcePosition(0.0f, 0.0f, 0.0f);
2520 Vector3 targetPosition(100.0f, 100.0f, 100.0f);
2521 Vector3 halfwayPosition(targetPosition * 0.5f);
2525 Constraint constraint = Constraint::New<Vector3>( Actor::POSITION, TestPositionConstraint(targetPosition) );
2526 DALI_TEST_EQUALS((unsigned int)constraint.GetRemoveAction(), (unsigned int)Constraint::Bake, TEST_LOCATION);
2528 float applySeconds(4.0f);
2529 constraint.SetApplyTime(applySeconds);
2530 DALI_TEST_EQUALS(constraint.GetApplyTime(), TimePeriod(applySeconds), TEST_LOCATION);
2532 float removeSeconds(8.0f);
2533 constraint.SetRemoveTime(removeSeconds);
2534 DALI_TEST_EQUALS(constraint.GetRemoveTime(), TimePeriod(removeSeconds), TEST_LOCATION);
2536 // Apply to an actor
2538 Actor actor = Actor::New();
2539 Stage::GetCurrent().Add(actor);
2541 actor.ApplyConstraint( constraint );
2542 DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION );
2544 application.SendNotification();
2545 application.Render(static_cast<unsigned int>(applySeconds*250.0f)/* 25% progress */);
2547 // Constraint shouldn't be fully applied yet
2548 Vector3 twentyFivePercent( targetPosition * 0.25f );
2549 DALI_TEST_EQUALS( actor.GetCurrentPosition(), twentyFivePercent, TEST_LOCATION );
2551 application.Render(static_cast<unsigned int>(applySeconds*250.0f)/* 50% progress */);
2553 // Constraint shouldn't be fully applied yet
2554 Vector3 fiftyPercent( targetPosition * 0.5f );
2555 DALI_TEST_EQUALS( actor.GetCurrentPosition(), fiftyPercent, TEST_LOCATION );
2557 // Remove from the actor
2559 actor.RemoveConstraints(); // should go back to source position
2561 application.SendNotification();
2562 application.Render(static_cast<unsigned int>(removeSeconds*100.0f)/* 50% - 5% = 45% progress */);
2564 // Constraint shouldn't be fully removed yet
2565 Vector3 fourtyFivePercent( targetPosition * 0.45f );
2566 DALI_TEST_EQUALS( actor.GetCurrentPosition(), fourtyFivePercent, TEST_LOCATION );
2568 application.Render(static_cast<unsigned int>(removeSeconds*400.0f)/* 50% - 25% = 25% progress */);
2570 // Constraint shouldn't be fully removed yet
2571 DALI_TEST_EQUALS( actor.GetCurrentPosition(), twentyFivePercent, TEST_LOCATION );
2573 // Constraint should be fully removed
2574 application.Render(static_cast<unsigned int>(removeSeconds*500.0f)/* 0% progress */);
2575 DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION );
2577 // Constraint should still be fully applied
2578 application.Render(static_cast<unsigned int>(removeSeconds*200.0f)/* Still 0% progress */);
2579 DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION );
2581 // Check that nothing has changed after a couple of buffer swaps
2582 application.Render(0);
2583 DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION );
2584 application.Render(0);
2585 DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION );
2590 * Test a constraint with non-zero apply-time & zero (immediate) remove-time, where the constraint is removed during the apply-time
2592 int UtcDaliConstraintImmediateRemoveDuringApply(void)
2594 TestApplication application;
2596 Vector3 sourcePosition(0.0f, 0.0f, 0.0f);
2597 Vector3 targetPosition(100.0f, 100.0f, 100.0f);
2601 Constraint constraint = Constraint::New<Vector3>( Actor::POSITION, TestPositionConstraint(targetPosition) );
2602 DALI_TEST_EQUALS((unsigned int)constraint.GetRemoveAction(), (unsigned int)Constraint::Bake, TEST_LOCATION);
2604 float applySeconds(4.0f);
2605 constraint.SetApplyTime(applySeconds);
2606 DALI_TEST_EQUALS(constraint.GetApplyTime(), TimePeriod(applySeconds), TEST_LOCATION);
2607 DALI_TEST_EQUALS(constraint.GetRemoveTime(), TimePeriod(0.0f), TEST_LOCATION);
2609 // Apply to an actor
2611 Actor actor = Actor::New();
2612 Stage::GetCurrent().Add(actor);
2614 actor.ApplyConstraint( constraint );
2615 DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION );
2617 application.SendNotification();
2618 application.Render(static_cast<unsigned int>(applySeconds*250.0f)/* 25% progress */);
2620 // Constraint shouldn't be fully applied yet
2621 Vector3 twentyFivePercent( targetPosition * 0.25f );
2622 DALI_TEST_EQUALS( actor.GetCurrentPosition(), twentyFivePercent, TEST_LOCATION );
2624 application.Render(static_cast<unsigned int>(applySeconds*250.0f)/* 50% progress */);
2626 // Constraint shouldn't be fully applied yet
2627 Vector3 fiftyPercent( targetPosition * 0.5f );
2628 DALI_TEST_EQUALS( actor.GetCurrentPosition(), fiftyPercent, TEST_LOCATION );
2630 // Remove from the actor
2632 actor.RemoveConstraints(); // should go back to source position
2633 application.SendNotification();
2635 // Constraint should be fully removed
2636 application.Render(static_cast<unsigned int>(200.0f /*0.2 seconds*/));
2637 DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION );
2639 // Constraint should still be fully applied
2640 application.Render(static_cast<unsigned int>(200.0f /*0.2 seconds*/));
2641 DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION );
2643 // Check that nothing has changed after a couple of buffer swaps
2644 application.Render(0);
2645 DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION );
2646 application.Render(0);
2647 DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION );
2651 int UtcDaliConstraintActorSize(void)
2653 TestApplication application;
2655 // Build constraint, to make child 20% of parent size
2657 Constraint constraint = Constraint::New<Vector3>( Actor::SIZE,
2658 ParentSource( Actor::SIZE ),
2659 TestRelativeConstraintVector3(0.2f) );
2660 // Apply to a child actor
2662 Actor parent = Actor::New();
2663 Stage::GetCurrent().Add(parent);
2665 Actor child = Actor::New();
2668 child.ApplyConstraint( constraint );
2669 DALI_TEST_EQUALS( child.GetCurrentSize(), Vector3::ZERO, TEST_LOCATION );
2671 // Animate the parent between two sizes
2673 Vector3 targetParentSize(100.0f, 100.0f, 100.0f);
2675 float durationSeconds(10.0f);
2676 Animation animation = Animation::New(durationSeconds);
2677 animation.AnimateTo( Property(parent, Actor::SIZE), targetParentSize );
2680 application.SendNotification();
2682 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 25% progress */);
2683 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize*0.25f, TEST_LOCATION );
2684 DALI_TEST_EQUALS( child.GetCurrentSize(), targetParentSize*0.25f * 0.2f, TEST_LOCATION );
2686 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 50% progress */);
2687 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize*0.5f, TEST_LOCATION );
2688 DALI_TEST_EQUALS( child.GetCurrentSize(), targetParentSize*0.5f * 0.2f, TEST_LOCATION );
2690 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 75% progress */);
2691 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize*0.75f, TEST_LOCATION );
2692 DALI_TEST_EQUALS( child.GetCurrentSize(), targetParentSize*0.75f * 0.2f, TEST_LOCATION );
2694 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 100% progress */);
2695 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize, TEST_LOCATION );
2696 DALI_TEST_EQUALS( child.GetCurrentSize(), targetParentSize * 0.2f, TEST_LOCATION );
2698 // Check that nothing has changed after a couple of buffer swaps
2699 application.Render(0);
2700 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize, TEST_LOCATION );
2701 DALI_TEST_EQUALS( child.GetCurrentSize(), targetParentSize * 0.2f, TEST_LOCATION );
2702 application.Render(0);
2703 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize, TEST_LOCATION );
2704 DALI_TEST_EQUALS( child.GetCurrentSize(), targetParentSize * 0.2f, TEST_LOCATION );
2708 int UtcDaliConstraintActorSizeWidth(void)
2710 TestApplication application;
2712 // Build constraint, to make child 20% of parent width
2714 Constraint constraint = Constraint::New<float>( Actor::SIZE_WIDTH,
2715 ParentSource( Actor::SIZE_WIDTH ),
2716 TestRelativeConstraintFloat(0.2f) );
2717 // Apply to a child actor
2719 Actor parent = Actor::New();
2720 Stage::GetCurrent().Add(parent);
2722 Actor child = Actor::New();
2725 child.ApplyConstraint( constraint );
2726 DALI_TEST_EQUALS( child.GetCurrentSize(), Vector3::ZERO, TEST_LOCATION );
2728 // Animate the parent between two sizes
2730 Vector3 targetParentSize(80.0f, 90.0f, 100.0f);
2732 float durationSeconds(10.0f);
2733 Animation animation = Animation::New(durationSeconds);
2734 animation.AnimateTo( Property(parent, Actor::SIZE), targetParentSize );
2737 application.SendNotification();
2739 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 25% progress */);
2740 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize*0.25f, TEST_LOCATION );
2741 DALI_TEST_EQUALS( child.GetCurrentSize().width, targetParentSize.width*0.25f * 0.2f, TEST_LOCATION );
2742 DALI_TEST_EQUALS( child.GetCurrentSize().height, 0.0f, TEST_LOCATION );
2743 DALI_TEST_EQUALS( child.GetCurrentSize().depth, 0.0f, TEST_LOCATION );
2745 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 50% progress */);
2746 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize*0.5f, TEST_LOCATION );
2747 DALI_TEST_EQUALS( child.GetCurrentSize().width, targetParentSize.width*0.5f * 0.2f, TEST_LOCATION );
2748 DALI_TEST_EQUALS( child.GetCurrentSize().height, 0.0f, TEST_LOCATION );
2749 DALI_TEST_EQUALS( child.GetCurrentSize().depth, 0.0f, TEST_LOCATION );
2751 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 75% progress */);
2752 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize*0.75f, TEST_LOCATION );
2753 DALI_TEST_EQUALS( child.GetCurrentSize().width, targetParentSize.width*0.75f * 0.2f, TEST_LOCATION );
2754 DALI_TEST_EQUALS( child.GetCurrentSize().height, 0.0f, TEST_LOCATION );
2755 DALI_TEST_EQUALS( child.GetCurrentSize().depth, 0.0f, TEST_LOCATION );
2757 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 100% progress */);
2758 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize, TEST_LOCATION );
2759 DALI_TEST_EQUALS( child.GetCurrentSize().width, targetParentSize.width * 0.2f, TEST_LOCATION );
2760 DALI_TEST_EQUALS( child.GetCurrentSize().height, 0.0f, TEST_LOCATION );
2761 DALI_TEST_EQUALS( child.GetCurrentSize().depth, 0.0f, TEST_LOCATION );
2763 // Check that nothing has changed after a couple of buffer swaps
2764 application.Render(0);
2765 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize, TEST_LOCATION );
2766 DALI_TEST_EQUALS( child.GetCurrentSize().width, targetParentSize.width * 0.2f, TEST_LOCATION );
2767 DALI_TEST_EQUALS( child.GetCurrentSize().height, 0.0f, TEST_LOCATION );
2768 DALI_TEST_EQUALS( child.GetCurrentSize().depth, 0.0f, TEST_LOCATION );
2770 application.Render(0);
2771 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize, TEST_LOCATION );
2772 DALI_TEST_EQUALS( child.GetCurrentSize().width, targetParentSize.width * 0.2f, TEST_LOCATION );
2773 DALI_TEST_EQUALS( child.GetCurrentSize().height, 0.0f, TEST_LOCATION );
2774 DALI_TEST_EQUALS( child.GetCurrentSize().depth, 0.0f, TEST_LOCATION );
2778 int UtcDaliConstraintActorSizeHeight(void)
2780 TestApplication application;
2782 // Build constraint, to make child 20% of parent height
2784 Constraint constraint = Constraint::New<float>( Actor::SIZE_HEIGHT,
2785 ParentSource( Actor::SIZE_HEIGHT ),
2786 TestRelativeConstraintFloat(0.2f) );
2787 // Apply to a child actor
2789 Actor parent = Actor::New();
2790 Stage::GetCurrent().Add(parent);
2792 Actor child = Actor::New();
2795 child.ApplyConstraint( constraint );
2796 DALI_TEST_EQUALS( child.GetCurrentSize(), Vector3::ZERO, TEST_LOCATION );
2798 // Animate the parent between two sizes
2800 Vector3 targetParentSize(80.0f, 90.0f, 100.0f);
2802 float durationSeconds(10.0f);
2803 Animation animation = Animation::New(durationSeconds);
2804 animation.AnimateTo( Property(parent, Actor::SIZE), targetParentSize );
2807 application.SendNotification();
2809 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 25% progress */);
2810 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize*0.25f, TEST_LOCATION );
2811 DALI_TEST_EQUALS( child.GetCurrentSize().width, 0.0f, TEST_LOCATION );
2812 DALI_TEST_EQUALS( child.GetCurrentSize().height, targetParentSize.height*0.25f * 0.2f, TEST_LOCATION );
2813 DALI_TEST_EQUALS( child.GetCurrentSize().depth, 0.0f, TEST_LOCATION );
2815 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 50% progress */);
2816 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize*0.5f, TEST_LOCATION );
2817 DALI_TEST_EQUALS( child.GetCurrentSize().width, 0.0f, TEST_LOCATION );
2818 DALI_TEST_EQUALS( child.GetCurrentSize().height, targetParentSize.height*0.5f * 0.2f, TEST_LOCATION );
2819 DALI_TEST_EQUALS( child.GetCurrentSize().depth, 0.0f, TEST_LOCATION );
2821 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 75% progress */);
2822 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize*0.75f, TEST_LOCATION );
2823 DALI_TEST_EQUALS( child.GetCurrentSize().width, 0.0f, TEST_LOCATION );
2824 DALI_TEST_EQUALS( child.GetCurrentSize().height, targetParentSize.height*0.75f * 0.2f, TEST_LOCATION );
2825 DALI_TEST_EQUALS( child.GetCurrentSize().depth, 0.0f, TEST_LOCATION );
2827 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 100% progress */);
2828 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize, TEST_LOCATION );
2829 DALI_TEST_EQUALS( child.GetCurrentSize().width, 0.0f, TEST_LOCATION );
2830 DALI_TEST_EQUALS( child.GetCurrentSize().height, targetParentSize.height * 0.2f, TEST_LOCATION );
2831 DALI_TEST_EQUALS( child.GetCurrentSize().depth, 0.0f, TEST_LOCATION );
2833 // Check that nothing has changed after a couple of buffer swaps
2834 application.Render(0);
2835 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize, TEST_LOCATION );
2836 DALI_TEST_EQUALS( child.GetCurrentSize().width, 0.0f, TEST_LOCATION );
2837 DALI_TEST_EQUALS( child.GetCurrentSize().height, targetParentSize.height * 0.2f, TEST_LOCATION );
2838 DALI_TEST_EQUALS( child.GetCurrentSize().depth, 0.0f, TEST_LOCATION );
2840 application.Render(0);
2841 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize, TEST_LOCATION );
2842 DALI_TEST_EQUALS( child.GetCurrentSize().width, 0.0f, TEST_LOCATION );
2843 DALI_TEST_EQUALS( child.GetCurrentSize().height, targetParentSize.height * 0.2f, TEST_LOCATION );
2844 DALI_TEST_EQUALS( child.GetCurrentSize().depth, 0.0f, TEST_LOCATION );
2848 int UtcDaliConstraintActorSizeDepth(void)
2850 TestApplication application;
2852 // Build constraint, to make child 20% of parent height
2854 Constraint constraint = Constraint::New<float>( Actor::SIZE_DEPTH,
2855 ParentSource( Actor::SIZE_DEPTH ),
2856 TestRelativeConstraintFloat(0.2f) );
2857 // Apply to a child actor
2859 Actor parent = Actor::New();
2860 Stage::GetCurrent().Add(parent);
2862 Actor child = Actor::New();
2865 child.ApplyConstraint( constraint );
2866 DALI_TEST_EQUALS( child.GetCurrentSize(), Vector3::ZERO, TEST_LOCATION );
2868 // Animate the parent between two sizes
2870 Vector3 targetParentSize(80.0f, 90.0f, 100.0f);
2872 float durationSeconds(10.0f);
2873 Animation animation = Animation::New(durationSeconds);
2874 animation.AnimateTo( Property(parent, Actor::SIZE), targetParentSize );
2877 application.SendNotification();
2879 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 25% progress */);
2880 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize*0.25f, TEST_LOCATION );
2881 DALI_TEST_EQUALS( child.GetCurrentSize().width, 0.0f, TEST_LOCATION );
2882 DALI_TEST_EQUALS( child.GetCurrentSize().height, 0.0f, TEST_LOCATION );
2883 DALI_TEST_EQUALS( child.GetCurrentSize().depth, targetParentSize.depth*0.25f * 0.2f, TEST_LOCATION );
2885 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 50% progress */);
2886 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize*0.5f, TEST_LOCATION );
2887 DALI_TEST_EQUALS( child.GetCurrentSize().width, 0.0f, TEST_LOCATION );
2888 DALI_TEST_EQUALS( child.GetCurrentSize().height, 0.0f, TEST_LOCATION );
2889 DALI_TEST_EQUALS( child.GetCurrentSize().depth, targetParentSize.depth*0.5f * 0.2f, TEST_LOCATION );
2891 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 75% progress */);
2892 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize*0.75f, TEST_LOCATION );
2893 DALI_TEST_EQUALS( child.GetCurrentSize().width, 0.0f, TEST_LOCATION );
2894 DALI_TEST_EQUALS( child.GetCurrentSize().height, 0.0f, TEST_LOCATION );
2895 DALI_TEST_EQUALS( child.GetCurrentSize().depth, targetParentSize.depth*0.75f * 0.2f, TEST_LOCATION );
2897 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 100% progress */);
2898 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize, TEST_LOCATION );
2899 DALI_TEST_EQUALS( child.GetCurrentSize().width, 0.0f, TEST_LOCATION );
2900 DALI_TEST_EQUALS( child.GetCurrentSize().height, 0.0f, TEST_LOCATION );
2901 DALI_TEST_EQUALS( child.GetCurrentSize().depth, targetParentSize.depth * 0.2f, TEST_LOCATION );
2903 // Check that nothing has changed after a couple of buffer swaps
2904 application.Render(0);
2905 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize, TEST_LOCATION );
2906 DALI_TEST_EQUALS( child.GetCurrentSize().width, 0.0f, TEST_LOCATION );
2907 DALI_TEST_EQUALS( child.GetCurrentSize().height, 0.0f, TEST_LOCATION );
2908 DALI_TEST_EQUALS( child.GetCurrentSize().depth, targetParentSize.depth * 0.2f, TEST_LOCATION );
2910 application.Render(0);
2911 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize, TEST_LOCATION );
2912 DALI_TEST_EQUALS( child.GetCurrentSize().width, 0.0f, TEST_LOCATION );
2913 DALI_TEST_EQUALS( child.GetCurrentSize().height, 0.0f, TEST_LOCATION );
2914 DALI_TEST_EQUALS( child.GetCurrentSize().depth, targetParentSize.depth * 0.2f, TEST_LOCATION );
2918 int UtcDaliConstraintInputWorldPosition(void)
2920 TestApplication application;
2922 Actor parent = Actor::New();
2923 Vector3 parentPosition( 10.0f, 10.0f, 10.0f );
2924 parent.SetPosition( parentPosition );
2925 parent.SetParentOrigin( ParentOrigin::CENTER );
2926 parent.SetAnchorPoint( AnchorPoint::CENTER );
2927 Stage::GetCurrent().Add( parent );
2929 Actor child = Actor::New();
2930 child.SetParentOrigin( ParentOrigin::CENTER );
2931 child.SetAnchorPoint( AnchorPoint::CENTER );
2932 Vector3 childPosition( 10.0f, 10.0f, 10.0f );
2933 child.SetPosition( childPosition );
2934 parent.Add( child );
2936 Actor trackingActor = Actor::New();
2937 trackingActor.SetParentOrigin( ParentOrigin::CENTER );
2938 trackingActor.SetAnchorPoint( AnchorPoint::CENTER );
2939 Stage::GetCurrent().Add( trackingActor );
2941 // The actors should not have a world position yet
2942 DALI_TEST_EQUALS( parent.GetCurrentWorldPosition(), Vector3::ZERO, TEST_LOCATION );
2943 DALI_TEST_EQUALS( child.GetCurrentWorldPosition(), Vector3::ZERO, TEST_LOCATION );
2944 DALI_TEST_EQUALS( trackingActor.GetCurrentWorldPosition(), Vector3::ZERO, TEST_LOCATION );
2946 application.SendNotification();
2947 application.Render(0);
2949 DALI_TEST_EQUALS( parent.GetCurrentPosition(), parentPosition, TEST_LOCATION );
2950 DALI_TEST_EQUALS( child.GetCurrentPosition(), childPosition, TEST_LOCATION );
2951 DALI_TEST_EQUALS( trackingActor.GetCurrentPosition(), Vector3::ZERO, TEST_LOCATION );
2953 DALI_TEST_EQUALS( parent.GetCurrentWorldPosition(), parentPosition, TEST_LOCATION );
2954 Vector3 previousPosition( parentPosition + childPosition );
2955 DALI_TEST_EQUALS( child.GetCurrentWorldPosition(), previousPosition, TEST_LOCATION );
2956 DALI_TEST_EQUALS( trackingActor.GetCurrentWorldPosition(), Vector3::ZERO, TEST_LOCATION );
2958 // Build constraint, to make actor track the world-position of another actor
2959 // Note that the world-position is always from the previous frame, so the tracking actor will lag behind
2961 Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
2962 Source( child, Actor::WORLD_POSITION ),
2963 EqualToConstraint() );
2965 trackingActor.ApplyConstraint( constraint );
2967 application.SendNotification();
2968 application.Render(0);
2970 DALI_TEST_EQUALS( trackingActor.GetCurrentPosition(), previousPosition, TEST_LOCATION );
2972 // Move the actors and try again
2973 Vector3 relativePosition( 5, 5, 5 );
2974 parent.MoveBy( relativePosition );
2976 application.SendNotification();
2977 application.Render(0);
2979 DALI_TEST_EQUALS( parent.GetCurrentPosition(), parentPosition + relativePosition, TEST_LOCATION );
2980 DALI_TEST_EQUALS( child.GetCurrentPosition(), childPosition, TEST_LOCATION );
2982 // The tracking actor lags behind
2983 DALI_TEST_EQUALS( trackingActor.GetCurrentPosition(), previousPosition, TEST_LOCATION );
2985 DALI_TEST_EQUALS( parent.GetCurrentWorldPosition(), parentPosition + relativePosition, TEST_LOCATION );
2986 previousPosition = Vector3( parentPosition + childPosition + relativePosition );
2987 DALI_TEST_EQUALS( child.GetCurrentWorldPosition(), previousPosition, TEST_LOCATION );
2989 // Allow the tracking actor to catch up
2990 application.SendNotification();
2991 application.Render(0);
2993 DALI_TEST_EQUALS( parent.GetCurrentPosition(), parentPosition + relativePosition, TEST_LOCATION );
2994 DALI_TEST_EQUALS( child.GetCurrentPosition(), childPosition, TEST_LOCATION );
2996 // The tracking actor catches up!
2997 DALI_TEST_EQUALS( trackingActor.GetCurrentPosition(), previousPosition, TEST_LOCATION );
2998 DALI_TEST_EQUALS( parent.GetCurrentWorldPosition(), parentPosition + relativePosition, TEST_LOCATION );
2999 DALI_TEST_EQUALS( child.GetCurrentWorldPosition(), previousPosition, TEST_LOCATION );
3003 int UtcDaliConstraintInputWorldRotation(void)
3005 TestApplication application;
3007 Actor parent = Actor::New();
3008 Radian rotationAngle( Degree(90.0f) );
3009 Quaternion rotation( rotationAngle, Vector3::YAXIS );
3010 parent.SetRotation( rotation );
3011 Stage::GetCurrent().Add( parent );
3013 Actor child = Actor::New();
3014 child.SetRotation( rotation );
3015 parent.Add( child );
3017 Actor trackingActor = Actor::New();
3018 Stage::GetCurrent().Add( trackingActor );
3020 // The actors should not have a world rotation yet
3021 DALI_TEST_EQUALS( parent.GetCurrentWorldRotation(), Quaternion(0.0f, Vector3::YAXIS), 0.001, TEST_LOCATION );
3022 DALI_TEST_EQUALS( child.GetCurrentWorldRotation(), Quaternion(0.0f, Vector3::YAXIS), 0.001, TEST_LOCATION );
3024 application.SendNotification();
3025 application.Render(0);
3027 DALI_TEST_EQUALS( parent.GetCurrentRotation(), rotation, 0.001, TEST_LOCATION );
3028 DALI_TEST_EQUALS( child.GetCurrentRotation(), rotation, 0.001, TEST_LOCATION );
3029 DALI_TEST_EQUALS( trackingActor.GetCurrentRotation(), Quaternion(0.0f, Vector3::YAXIS), 0.001, TEST_LOCATION );
3031 DALI_TEST_EQUALS( parent.GetCurrentWorldRotation(), Quaternion( rotationAngle, Vector3::YAXIS ), 0.001, TEST_LOCATION );
3032 Quaternion previousRotation( rotationAngle * 2.0f, Vector3::YAXIS );
3033 DALI_TEST_EQUALS( child.GetCurrentWorldRotation(), previousRotation, 0.001, TEST_LOCATION );
3035 // Build constraint, to make actor track the world-rotation of another actor
3036 // Note that the world-rotation is always from the previous frame, so the tracking actor will lag behind
3038 Constraint constraint = Constraint::New<Quaternion>( Actor::ROTATION,
3039 Source( child, Actor::WORLD_ROTATION ),
3040 EqualToQuaternion() );
3042 trackingActor.ApplyConstraint( constraint );
3044 application.SendNotification();
3045 application.Render(0);
3047 DALI_TEST_EQUALS( trackingActor.GetCurrentRotation(), previousRotation, 0.001, TEST_LOCATION );
3049 // Rotate the actors and try again
3050 parent.RotateBy( rotation );
3052 application.SendNotification();
3053 application.Render(0);
3055 DALI_TEST_EQUALS( parent.GetCurrentRotation(), rotation * rotation, 0.001, TEST_LOCATION );
3056 DALI_TEST_EQUALS( child.GetCurrentRotation(), rotation, 0.001, TEST_LOCATION );
3058 // The tracking actor lags behind
3059 DALI_TEST_EQUALS( trackingActor.GetCurrentRotation(), previousRotation, 0.001, TEST_LOCATION );
3061 DALI_TEST_EQUALS( parent.GetCurrentWorldRotation(), Quaternion( rotationAngle * 2.0f, Vector3::YAXIS ), 0.001, TEST_LOCATION );
3062 previousRotation = Quaternion( rotationAngle * 3.0f, Vector3::YAXIS );
3063 DALI_TEST_EQUALS( child.GetCurrentWorldRotation(), previousRotation, 0.001, TEST_LOCATION );
3065 // Allow the tracking actor to catch up
3066 application.SendNotification();
3067 application.Render(0);
3069 DALI_TEST_EQUALS( parent.GetCurrentRotation(), rotation * rotation, 0.001, TEST_LOCATION );
3070 DALI_TEST_EQUALS( child.GetCurrentRotation(), rotation, 0.001, TEST_LOCATION );
3072 // The tracking actor catches up!
3073 DALI_TEST_EQUALS( trackingActor.GetCurrentRotation(), previousRotation, 0.001, TEST_LOCATION );
3074 DALI_TEST_EQUALS( parent.GetCurrentWorldRotation(), Quaternion( rotationAngle * 2.0f, Vector3::YAXIS ), 0.001, TEST_LOCATION );
3075 DALI_TEST_EQUALS( child.GetCurrentWorldRotation(), previousRotation, 0.001, TEST_LOCATION );
3079 int UtcDaliConstraintInputWorldScale(void)
3081 TestApplication application;
3083 Actor parent = Actor::New();
3084 Vector3 parentScale( 2.0f, 2.0f, 2.0f );
3085 parent.SetScale( parentScale );
3086 Stage::GetCurrent().Add( parent );
3088 Actor child = Actor::New();
3089 Vector3 childScale( 1.0f, 2.0f, 3.0f );
3090 child.SetScale( childScale );
3091 parent.Add( child );
3093 Actor trackingActor = Actor::New();
3094 Stage::GetCurrent().Add( trackingActor );
3096 // The actors should not have a world scale yet
3097 DALI_TEST_EQUALS( parent.GetCurrentWorldScale(), Vector3::ONE, TEST_LOCATION );
3098 DALI_TEST_EQUALS( child.GetCurrentWorldScale(), Vector3::ONE, TEST_LOCATION );
3099 DALI_TEST_EQUALS( trackingActor.GetCurrentWorldScale(), Vector3::ONE, TEST_LOCATION );
3101 application.SendNotification();
3102 application.Render(0);
3104 DALI_TEST_EQUALS( parent.GetCurrentScale(), parentScale, TEST_LOCATION );
3105 DALI_TEST_EQUALS( child.GetCurrentScale(), childScale, TEST_LOCATION );
3106 DALI_TEST_EQUALS( trackingActor.GetCurrentScale(), Vector3::ONE, TEST_LOCATION );
3108 DALI_TEST_EQUALS( parent.GetCurrentWorldScale(), parentScale, TEST_LOCATION );
3109 Vector3 previousScale( parentScale * childScale );
3110 DALI_TEST_EQUALS( child.GetCurrentWorldScale(), previousScale, TEST_LOCATION );
3111 DALI_TEST_EQUALS( trackingActor.GetCurrentScale(), Vector3::ONE, TEST_LOCATION );
3113 // Build constraint, to make actor track the world-scale of another actor
3114 // Note that the world-scale is always from the previous frame, so the tracking actor will lag behind
3116 Constraint constraint = Constraint::New<Vector3>( Actor::SCALE,
3117 Source( child, Actor::WORLD_SCALE ),
3118 EqualToConstraint() );
3120 trackingActor.ApplyConstraint( constraint );
3122 application.SendNotification();
3123 application.Render(0);
3125 DALI_TEST_EQUALS( trackingActor.GetCurrentScale(), previousScale, TEST_LOCATION );
3127 // Scale the actors and try again
3128 Vector3 relativeScale( 3, 3, 3 );
3129 parent.ScaleBy( relativeScale );
3131 application.SendNotification();
3132 application.Render(0);
3134 DALI_TEST_EQUALS( parent.GetCurrentScale(), parentScale * relativeScale, TEST_LOCATION );
3135 DALI_TEST_EQUALS( child.GetCurrentScale(), childScale, TEST_LOCATION );
3137 // The tracking actor lags behind
3138 DALI_TEST_EQUALS( trackingActor.GetCurrentScale(), previousScale, TEST_LOCATION );
3140 DALI_TEST_EQUALS( parent.GetCurrentWorldScale(), parentScale * relativeScale, TEST_LOCATION );
3141 previousScale = Vector3( parentScale * childScale * relativeScale );
3142 DALI_TEST_EQUALS( child.GetCurrentWorldScale(), previousScale, TEST_LOCATION );
3144 // Allow the tracking actor to catch up
3145 application.SendNotification();
3146 application.Render(0);
3148 DALI_TEST_EQUALS( parent.GetCurrentScale(), parentScale * relativeScale, TEST_LOCATION );
3149 DALI_TEST_EQUALS( child.GetCurrentScale(), childScale, TEST_LOCATION );
3151 // The tracking actor catches up!
3152 DALI_TEST_EQUALS( trackingActor.GetCurrentScale(), previousScale, TEST_LOCATION );
3153 DALI_TEST_EQUALS( parent.GetCurrentWorldScale(), parentScale * relativeScale, TEST_LOCATION );
3154 DALI_TEST_EQUALS( child.GetCurrentWorldScale(), previousScale, TEST_LOCATION );
3158 int UtcDaliConstraintInputWorldColor(void)
3160 TestApplication application;
3162 Actor parent = Actor::New();
3163 Vector4 parentColor( 1.0f, 0.5f, 0.0f, 1.0f );
3164 parent.SetColor( parentColor );
3165 Stage::GetCurrent().Add( parent );
3167 Actor child = Actor::New();
3168 Vector4 childColor( 0.5f, 0.5f, 0.5f, 1.0f );
3169 child.SetColor( childColor );
3170 parent.Add( child );
3172 Actor trackingActor = Actor::New();
3173 Stage::GetCurrent().Add( trackingActor );
3175 // The actors should not have a world color yet
3176 DALI_TEST_EQUALS( parent.GetCurrentWorldColor(), Color::WHITE, TEST_LOCATION );
3177 DALI_TEST_EQUALS( child.GetCurrentWorldColor(), Color::WHITE, TEST_LOCATION );
3179 application.SendNotification();
3180 application.Render(0);
3182 DALI_TEST_EQUALS( parent.GetCurrentColor(), parentColor, TEST_LOCATION );
3183 DALI_TEST_EQUALS( child.GetCurrentColor(), childColor, TEST_LOCATION );
3184 DALI_TEST_EQUALS( trackingActor.GetCurrentColor(), Color::WHITE, TEST_LOCATION );
3186 DALI_TEST_EQUALS( parent.GetCurrentWorldColor(), parentColor, TEST_LOCATION );
3187 Vector4 previousColor( childColor );
3188 previousColor.a *= parentColor.a;
3189 DALI_TEST_EQUALS( child.GetCurrentWorldColor(), previousColor, TEST_LOCATION );
3191 // Build constraint, to make actor track the world-color of another actor
3192 // Note that the world-color is always from the previous frame, so the tracking actor will lag behind
3194 Constraint constraint = Constraint::New<Vector4>( Actor::COLOR,
3195 Source( child, Actor::WORLD_COLOR ),
3198 trackingActor.ApplyConstraint( constraint );
3200 application.SendNotification();
3201 application.Render(0);
3203 DALI_TEST_EQUALS( trackingActor.GetCurrentColor(), previousColor, TEST_LOCATION );
3205 // Set the color and try again
3206 Vector4 newChildColor( 0.75f, 0.75f, 0.75f, 1.0f );
3207 child.SetColor( newChildColor );
3209 application.SendNotification();
3210 application.Render(0);
3212 DALI_TEST_EQUALS( parent.GetCurrentColor(), parentColor, TEST_LOCATION );
3213 DALI_TEST_EQUALS( child.GetCurrentColor(), newChildColor, TEST_LOCATION );
3215 // The tracking actor lags behind
3216 DALI_TEST_EQUALS( trackingActor.GetCurrentColor(), previousColor, TEST_LOCATION );
3218 DALI_TEST_EQUALS( parent.GetCurrentWorldColor(), parentColor, TEST_LOCATION );
3219 previousColor = Vector3( newChildColor );
3220 DALI_TEST_EQUALS( child.GetCurrentWorldColor(), previousColor, TEST_LOCATION );
3222 // Allow the tracking actor to catch up
3223 application.SendNotification();
3224 application.Render(0);
3226 DALI_TEST_EQUALS( parent.GetCurrentColor(), parentColor, TEST_LOCATION );
3227 DALI_TEST_EQUALS( child.GetCurrentColor(), newChildColor, TEST_LOCATION );
3229 // The tracking actor catches up!
3230 DALI_TEST_EQUALS( trackingActor.GetCurrentColor(), previousColor, TEST_LOCATION );
3231 DALI_TEST_EQUALS( parent.GetCurrentWorldColor(), parentColor, TEST_LOCATION );
3232 DALI_TEST_EQUALS( child.GetCurrentWorldColor(), previousColor, TEST_LOCATION );
3236 int UtcDaliConstraintInvalidInputProperty(void)
3238 TestApplication application;
3239 Actor actor = Actor::New();
3240 Constraint constraint = Constraint::New<Vector3>( Actor::POSITION, LocalSource( PROPERTY_REGISTRATION_START_INDEX ), MultiplyConstraint() );
3242 Stage::GetCurrent().Add( actor );
3244 // Cannot use type registered properties as input to constraints
3247 actor.ApplyConstraint( constraint );
3248 tet_result( TET_FAIL );
3250 catch ( DaliException& e )
3252 DALI_TEST_ASSERT( e, "mTargetProxy->IsPropertyAConstraintInput( source.propertyIndex )", TEST_LOCATION );
3257 int UtcDaliBuiltinConstraintParentSize(void)
3259 TestApplication application;
3261 Actor parent = Actor::New();
3262 Vector3 parentSize(9,9,9);
3263 parent.SetSize( parentSize );
3264 Stage::GetCurrent().Add( parent );
3266 Actor actor = Actor::New();
3267 parent.Add( actor );
3269 Vector3 startValue( Vector3::ZERO );
3271 application.SendNotification();
3272 application.Render(0);
3273 DALI_TEST_CHECK( actor.GetCurrentSize() == startValue );
3277 Constraint constraint = Constraint::New<Vector3>( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() );
3278 actor.ApplyConstraint( constraint );
3280 application.SendNotification();
3281 application.Render(0);
3283 // Constraint should be fully applied
3284 DALI_TEST_EQUALS( actor.GetCurrentSize(), parentSize, TEST_LOCATION );
3286 // This should be ignored
3287 actor.SetSize( startValue );
3289 // Check that nothing has changed after a couple of buffer swaps
3290 application.SendNotification();
3291 application.Render(0);
3292 DALI_TEST_EQUALS( actor.GetCurrentSize(), parentSize, TEST_LOCATION );
3293 application.Render(0);
3294 DALI_TEST_EQUALS( actor.GetCurrentSize(), parentSize, TEST_LOCATION );
3296 // Remove the constraint, then set new value
3297 actor.RemoveConstraints();
3298 actor.SetSize( startValue );
3300 // Constraint should have been removed
3301 application.SendNotification();
3302 application.Render(0);
3303 DALI_TEST_EQUALS( actor.GetCurrentSize(), startValue, TEST_LOCATION );
3304 application.Render(0);
3305 DALI_TEST_EQUALS( actor.GetCurrentSize(), startValue, TEST_LOCATION );
3309 int UtcDaliBuiltinConstraintParentSizeRelative(void)
3311 TestApplication application;
3313 Actor parent = Actor::New();
3314 Vector3 parentSize(9,9,9);
3315 parent.SetSize( parentSize );
3316 Stage::GetCurrent().Add( parent );
3318 Actor actor = Actor::New();
3319 parent.Add( actor );
3321 Vector3 startValue( Vector3::ZERO );
3322 Vector3 scale(2,3,4);
3323 Vector3 endValue( parentSize * scale );
3325 application.SendNotification();
3326 application.Render(0);
3327 DALI_TEST_CHECK( actor.GetCurrentSize() == startValue );
3331 Constraint constraint = Constraint::New<Vector3>( Actor::SIZE, ParentSource( Actor::SIZE ), RelativeToConstraint( scale ) );
3332 actor.ApplyConstraint( constraint );
3334 application.SendNotification();
3335 application.Render(0);
3337 // Constraint should be fully applied
3338 DALI_TEST_EQUALS( actor.GetCurrentSize(), endValue, TEST_LOCATION );
3340 // This should be ignored
3341 actor.SetSize( startValue );
3343 // Check that nothing has changed after a couple of buffer swaps
3344 application.SendNotification();
3345 application.Render(0);
3346 DALI_TEST_EQUALS( actor.GetCurrentSize(), endValue, TEST_LOCATION );
3347 application.Render(0);
3348 DALI_TEST_EQUALS( actor.GetCurrentSize(), endValue, TEST_LOCATION );
3350 // Remove the constraint, then set new value
3351 actor.RemoveConstraints();
3352 actor.SetSize( startValue );
3354 // Constraint should have been removed
3355 application.SendNotification();
3356 application.Render(0);
3357 DALI_TEST_EQUALS( actor.GetCurrentSize(), startValue, TEST_LOCATION );
3358 application.Render(0);
3359 DALI_TEST_EQUALS( actor.GetCurrentSize(), startValue, TEST_LOCATION );
3363 int UtcDaliBuiltinConstraintScaleToFitConstraint(void)
3365 TestApplication application;
3367 Actor parent = Actor::New();
3368 Vector3 startParentSize( 10, 10, 10 );
3369 parent.SetSize( startParentSize );
3370 Stage::GetCurrent().Add( parent );
3372 Actor actor = Actor::New();
3373 Vector3 startChildSize( 5, 5, 5 );
3374 actor.SetSize( startChildSize );
3375 parent.Add( actor );
3377 Vector3 endChildSize( 8, 8, 8 );
3378 Vector3 endParentSize( 4, 4, 4 );
3379 Vector3 startChildScale( 2, 2, 2 ); // startParentSize / startChildSize
3380 Vector3 intermediateChildScale( 1.25, 1.25, 1.25 ); // startParentSize / endChildSize
3381 Vector3 endChildScale( 0.5, 0.5, 0.5 ); // endParentSize / endChildSize
3383 application.SendNotification();
3384 application.Render(0);
3385 DALI_TEST_CHECK( actor.GetCurrentSize() == startChildSize );
3389 Constraint constraint = Constraint::New<Vector3>( Actor::SCALE,
3390 LocalSource( Actor::SIZE ),
3391 ParentSource( Actor::SIZE ),
3392 ScaleToFitConstraint() );
3393 actor.ApplyConstraint( constraint );
3395 application.SendNotification();
3396 application.Render(0);
3398 // Constraint should be fully applied, but parent size is larger than child
3399 DALI_TEST_EQUALS( actor.GetCurrentSize(), startChildSize, TEST_LOCATION );
3400 DALI_TEST_EQUALS( actor.GetCurrentScale(), startChildScale, TEST_LOCATION );
3402 // This should be allowed (still less than parent size)
3403 actor.SetSize( endChildSize );
3405 application.SendNotification();
3406 application.Render(0);
3407 DALI_TEST_EQUALS( actor.GetCurrentSize(), endChildSize, TEST_LOCATION );
3408 DALI_TEST_EQUALS( actor.GetCurrentScale(), intermediateChildScale, TEST_LOCATION );
3410 // Reduce the parent size
3411 parent.SetSize( endParentSize );
3413 application.SendNotification();
3414 application.Render(0);
3416 // Constraint should be fully applied
3417 DALI_TEST_EQUALS( actor.GetCurrentSize(), endChildSize, TEST_LOCATION );
3418 DALI_TEST_EQUALS( actor.GetCurrentScale(), endChildScale, TEST_LOCATION );
3419 application.Render(0);
3420 DALI_TEST_EQUALS( actor.GetCurrentSize(), endChildSize, TEST_LOCATION );
3421 DALI_TEST_EQUALS( actor.GetCurrentScale(), endChildScale, TEST_LOCATION );
3425 int UtcDaliBuiltinConstraintScaleToFitKeepAspectRatio(void)
3427 TestApplication application;
3429 Actor parent = Actor::New();
3430 Vector3 parentSize1( 10, 10, 10 );
3431 parent.SetSize( parentSize1 );
3432 Stage::GetCurrent().Add( parent );
3434 Actor actor = Actor::New();
3435 Vector3 childSize( 4, 5, 5 );
3436 actor.SetSize( childSize );
3437 parent.Add( actor );
3439 application.SendNotification();
3440 application.Render(0);
3441 Vector3 childScale1( 1.0f, 1.0f, 1.0f );
3442 DALI_TEST_EQUALS( actor.GetCurrentScale(), childScale1, TEST_LOCATION );
3446 Constraint constraint = Constraint::New<Vector3>( Actor::SCALE,
3447 LocalSource( Actor::SIZE ),
3448 ParentSource( Actor::SIZE ),
3449 ScaleToFitKeepAspectRatioConstraint() );
3450 actor.ApplyConstraint( constraint );
3452 application.SendNotification();
3453 application.Render(0);
3455 // Constraint should be fully applied, but parent size is larger than child
3456 Vector3 childScale2( 2.0f, 2.0f, 2.0f );
3457 DALI_TEST_EQUALS( actor.GetCurrentScale(), childScale2, TEST_LOCATION );
3459 // change parent size
3460 Vector3 parentSize2( 40, 50, 50 );
3461 parent.SetSize( parentSize2 );
3463 application.SendNotification();
3464 application.Render(0);
3466 // Constraint should be fully applied, but parent size is larger than child
3467 Vector3 childScale3( 10.0f, 10.0f, 10.0f );
3468 DALI_TEST_EQUALS( actor.GetCurrentScale(), childScale3, TEST_LOCATION );
3472 int UtcDaliBuiltinConstraintScaleToFillKeepAspectRatio(void)
3474 TestApplication application;
3476 Actor parent = Actor::New();
3477 Vector3 parentSize1( 10, 10, 10 );
3478 parent.SetSize( parentSize1 );
3479 Stage::GetCurrent().Add( parent );
3481 Actor actor = Actor::New();
3482 Vector3 childSize( 4, 5, 5 );
3483 actor.SetSize( childSize );
3484 parent.Add( actor );
3486 application.SendNotification();
3487 application.Render(0);
3488 Vector3 childScale1( 1.0f, 1.0f, 1.0f );
3489 DALI_TEST_EQUALS( actor.GetCurrentScale(), childScale1, TEST_LOCATION );
3493 Constraint constraint = Constraint::New<Vector3>( Actor::SCALE,
3494 LocalSource( Actor::SIZE ),
3495 ParentSource( Actor::SIZE ),
3496 ScaleToFillKeepAspectRatioConstraint() );
3497 actor.ApplyConstraint( constraint );
3499 application.SendNotification();
3500 application.Render(0);
3502 // Constraint should be fully applied, but parent size is larger than child
3503 float val = 10.f / 4.f;
3504 Vector3 childScale2( val, val, val );
3505 DALI_TEST_EQUALS( actor.GetCurrentScale(), childScale2, TEST_LOCATION );
3507 // change parent size
3508 Vector3 parentSize2( 40, 50, 50 );
3509 parent.SetSize( parentSize2 );
3511 application.SendNotification();
3512 application.Render(0);
3514 // Constraint should be fully applied, but parent size is larger than child
3515 Vector3 childScale3( 10.0f, 10.0f, 10.0f );
3516 DALI_TEST_EQUALS( actor.GetCurrentScale(), childScale3, TEST_LOCATION );
3520 int UtcDaliBuiltinConstraintScaleToFillXYKeepAspectRatio(void)
3522 TestApplication application;
3524 Actor parent = Actor::New();
3525 Vector3 parentSize1( 10, 10, 10 );
3526 parent.SetSize( parentSize1 );
3527 Stage::GetCurrent().Add( parent );
3529 Actor actor = Actor::New();
3530 Vector3 childSize( 4, 5, 5 );
3531 actor.SetSize( childSize );
3532 parent.Add( actor );
3534 application.SendNotification();
3535 application.Render(0);
3536 Vector3 childScale1( 1.0f, 1.0f, 1.0f );
3537 DALI_TEST_EQUALS( actor.GetCurrentScale(), childScale1, TEST_LOCATION );
3541 Constraint constraint = Constraint::New<Vector3>( Actor::SCALE,
3542 LocalSource( Actor::SIZE ),
3543 ParentSource( Actor::SIZE ),
3544 ScaleToFillXYKeepAspectRatioConstraint() );
3545 actor.ApplyConstraint( constraint );
3547 application.SendNotification();
3548 application.Render(0);
3550 // Constraint should be fully applied, but parent size is larger than child
3551 float val = 10.f / 4.f;
3552 Vector3 childScale2( val, val, val );
3553 DALI_TEST_EQUALS( actor.GetCurrentScale(), childScale2, TEST_LOCATION );
3555 // change parent size
3556 Vector3 parentSize2( 40, 50, 50 );
3557 parent.SetSize( parentSize2 );
3559 application.SendNotification();
3560 application.Render(0);
3562 // Constraint should be fully applied, but parent size is larger than child
3563 Vector3 childScale3( 10.0f, 10.0f, 10.0f );
3564 DALI_TEST_EQUALS( actor.GetCurrentScale(), childScale3, TEST_LOCATION );
3568 int UtcDaliBuiltinConstraintShrinkInsideKeepAspectRatioConstraint(void)
3570 TestApplication application;
3572 Actor parent = Actor::New();
3573 Vector3 parentSize1( 10, 10, 10 );
3574 parent.SetSize( parentSize1 );
3575 Stage::GetCurrent().Add( parent );
3577 Actor actor = Actor::New();
3578 Vector3 childSize( 4, 5, 5 );
3579 actor.SetSize( childSize );
3580 parent.Add( actor );
3582 application.SendNotification();
3583 application.Render(0);
3584 Vector3 childScale1( 1.0f, 1.0f, 1.0f );
3585 DALI_TEST_EQUALS( actor.GetCurrentScale(), childScale1, TEST_LOCATION );
3589 Constraint constraint = Constraint::New<Vector3>( Actor::SCALE,
3590 LocalSource( Actor::SIZE ),
3591 ParentSource( Actor::SIZE ),
3592 ShrinkInsideKeepAspectRatioConstraint() );
3593 actor.ApplyConstraint( constraint );
3595 application.SendNotification();
3596 application.Render(0);
3598 // Constraint should be fully applied, but parent size is larger than child
3599 Vector3 childScale2( 1.0f, 1.0f, 1.0f );
3600 DALI_TEST_EQUALS( actor.GetCurrentScale(), childScale2, TEST_LOCATION );
3602 // change parent size
3603 Vector3 parentSize2( 40, 50, 50 );
3604 parent.SetSize( parentSize2 );
3606 application.SendNotification();
3607 application.Render(0);
3609 // Constraint should be fully applied, but parent size is larger than child
3610 Vector3 childScale3( 1.0f, 1.0f, 1.0f );
3611 DALI_TEST_EQUALS( actor.GetCurrentScale(), childScale3, TEST_LOCATION );
3615 int UtcDaliBuiltinConstraintMultiplyConstraint(void)
3617 TestApplication application;
3619 Actor actor1 = Actor::New();
3620 Vector3 startPosition( 10, 10, 10 );
3621 actor1.SetPosition( startPosition );
3622 Stage::GetCurrent().Add( actor1 );
3624 Actor actor2 = Actor::New();
3625 Vector3 startSize( 100, 100, 100 );
3626 actor2.SetSize( startSize );
3627 Stage::GetCurrent().Add( actor2 );
3629 application.SendNotification();
3630 application.Render(0);
3631 DALI_TEST_CHECK( actor1.GetCurrentPosition() == startPosition );
3632 DALI_TEST_CHECK( actor2.GetCurrentSize() == startSize );
3634 // Apply constraint - multiply actor1 size by actor2 position
3636 Constraint constraint = Constraint::New<Vector3>( Actor::SIZE,
3637 Source( actor1, Actor::POSITION ),
3638 MultiplyConstraint() );
3639 constraint.SetRemoveAction( Constraint::Discard );
3640 actor2.ApplyConstraint( constraint );
3642 application.SendNotification();
3643 application.Render(0);
3645 // Constraint should be fully applied
3646 Vector3 size( startSize * startPosition );
3647 DALI_TEST_EQUALS( actor2.GetCurrentSize(), size, TEST_LOCATION );
3649 // Change the multiply input
3650 Vector3 endPosition( 2, 2, 2 );
3651 actor1.SetPosition( endPosition );
3653 application.SendNotification();
3654 application.Render(0);
3656 // Constraint should be fully applied
3657 size = Vector3( startSize * endPosition );
3658 DALI_TEST_EQUALS( actor2.GetCurrentSize(), size, TEST_LOCATION );
3659 application.Render(0);
3660 DALI_TEST_EQUALS( actor2.GetCurrentSize(), size, TEST_LOCATION );
3664 int UtcDaliBuiltinConstraintDivideConstraint(void)
3666 TestApplication application;
3668 Actor actor1 = Actor::New();
3669 Vector3 startPosition( 10, 10, 10 );
3670 actor1.SetPosition( startPosition );
3671 Stage::GetCurrent().Add( actor1 );
3673 Actor actor2 = Actor::New();
3674 Vector3 startSize( 100, 100, 100 );
3675 actor2.SetSize( startSize );
3676 Stage::GetCurrent().Add( actor2 );
3678 application.SendNotification();
3679 application.Render(0);
3680 DALI_TEST_CHECK( actor1.GetCurrentPosition() == startPosition );
3681 DALI_TEST_CHECK( actor2.GetCurrentSize() == startSize );
3683 // Apply constraint - divide actor1 size by actor2 position
3685 Constraint constraint = Constraint::New<Vector3>( Actor::SIZE,
3686 Source( actor1, Actor::POSITION ),
3687 DivideConstraint() );
3688 constraint.SetRemoveAction( Constraint::Discard );
3689 actor2.ApplyConstraint( constraint );
3691 application.SendNotification();
3692 application.Render(0);
3694 // Constraint should be fully applied
3695 Vector3 size( 10, 10, 10 ); // startSize / startPosition
3696 DALI_TEST_EQUALS( actor2.GetCurrentSize(), size, TEST_LOCATION );
3698 // Change the divide input
3699 Vector3 endPosition( 2, 2, 2 );
3700 actor1.SetPosition( endPosition );
3702 application.SendNotification();
3703 application.Render(0);
3705 // Constraint should be fully applied
3706 size = Vector3( 50, 50, 50 ); // startSize / endPosition
3707 DALI_TEST_EQUALS( actor2.GetCurrentSize(), size, TEST_LOCATION );
3708 application.Render(0);
3709 DALI_TEST_EQUALS( actor2.GetCurrentSize(), size, TEST_LOCATION );
3713 int UtcDaliBuiltinConstraintEqualToConstraint(void)
3715 TestApplication application;
3717 Actor actor1 = Actor::New();
3718 Vector3 startPosition( 10, 10, 10 );
3719 actor1.SetPosition( startPosition );
3720 Stage::GetCurrent().Add( actor1 );
3722 Actor actor2 = Actor::New();
3723 Vector3 startSize( 100, 100, 100 );
3724 actor2.SetSize( startSize );
3725 Stage::GetCurrent().Add( actor2 );
3727 application.SendNotification();
3728 application.Render(0);
3729 DALI_TEST_CHECK( actor1.GetCurrentPosition() == startPosition );
3730 DALI_TEST_CHECK( actor2.GetCurrentSize() == startSize );
3732 // Apply constraint - actor1 size == actor2 position
3734 Constraint constraint = Constraint::New<Vector3>( Actor::SIZE,
3735 Source( actor1, Actor::POSITION ),
3736 EqualToConstraint() );
3737 constraint.SetRemoveAction( Constraint::Discard );
3738 actor2.ApplyConstraint( constraint );
3740 application.SendNotification();
3741 application.Render(0);
3743 // Constraint should be fully applied
3744 DALI_TEST_EQUALS( actor2.GetCurrentSize(), startPosition, TEST_LOCATION );
3747 Vector3 endPosition( 2, 2, 2 );
3748 actor1.SetPosition( endPosition );
3750 application.SendNotification();
3751 application.Render(0);
3753 // Constraint should be fully applied
3754 DALI_TEST_EQUALS( actor2.GetCurrentSize(), endPosition, TEST_LOCATION );
3755 application.Render(0);
3756 DALI_TEST_EQUALS( actor2.GetCurrentSize(), endPosition, TEST_LOCATION );
3759 // Check float variant of constraint
3761 float startOpacity(1.0f);
3762 float endOpacity(0.2f);
3763 actor1.SetOpacity( startOpacity );
3764 actor2.SetOpacity( startOpacity );
3766 application.SendNotification();
3767 application.Render(0);
3768 DALI_TEST_EQUALS( actor1.GetCurrentOpacity(), startOpacity, TEST_LOCATION );
3769 DALI_TEST_EQUALS( actor2.GetCurrentOpacity(), startOpacity, TEST_LOCATION );
3771 Constraint constraint2 = Constraint::New<float>( Actor::COLOR_ALPHA,
3772 Source( actor1, Actor::COLOR_ALPHA ),
3773 EqualToConstraint() );
3774 constraint2.SetRemoveAction( Constraint::Discard );
3775 actor2.ApplyConstraint( constraint2 );
3777 actor1.SetOpacity(endOpacity);
3779 application.SendNotification();
3780 application.Render(0);
3782 DALI_TEST_EQUALS( actor2.GetCurrentOpacity(), endOpacity, 0.000001f, TEST_LOCATION );
3785 // Check Vector4 variant of constraint
3787 actor1.SetColor( Color::GREEN );
3788 actor2.SetColor( Color::RED );
3790 application.SendNotification();
3791 application.Render(0);
3792 DALI_TEST_CHECK( actor1.GetCurrentColor() == Color::GREEN );
3793 DALI_TEST_CHECK( actor2.GetCurrentColor() == Color::RED );
3795 Constraint constraint3 = Constraint::New<Vector4>( Actor::COLOR,
3796 Source( actor1, Actor::COLOR ),
3797 EqualToConstraint() );
3798 constraint3.SetRemoveAction( Constraint::Discard );
3799 actor2.ApplyConstraint( constraint3 );
3800 application.SendNotification();
3801 application.Render(0);
3802 DALI_TEST_CHECK( actor2.GetCurrentColor() == Color::GREEN );
3805 // Check Quaternion variant of constraint
3807 Quaternion q1 = Quaternion( Math::PI_2, Vector3::XAXIS );
3808 Quaternion q2 = Quaternion( Math::PI_4, Vector3::YAXIS );
3809 actor1.SetRotation( q1 );
3810 actor2.SetRotation( q2 );
3812 application.SendNotification();
3813 application.Render(0);
3814 DALI_TEST_EQUALS( actor1.GetCurrentRotation(), q1, 0.01, TEST_LOCATION );
3815 DALI_TEST_EQUALS( actor2.GetCurrentRotation(), q2, 0.01, TEST_LOCATION );
3817 Constraint constraint4 = Constraint::New<Quaternion>( Actor::ROTATION,
3818 Source( actor1, Actor::ROTATION ),
3819 EqualToConstraint() );
3820 constraint4.SetRemoveAction( Constraint::Discard );
3821 actor2.ApplyConstraint( constraint4 );
3822 application.SendNotification();
3823 application.Render(0);
3824 DALI_TEST_EQUALS( actor2.GetCurrentRotation(), q1, 0.01, TEST_LOCATION );
3827 // Check Matrix3 variant
3829 EqualToConstraint equalToConstraint;
3832 a.AsFloat()[0] = 1.f;
3834 b.AsFloat()[0] = 2.f;
3835 PropertyInputAbstraction pi(b);
3837 Matrix3 c = equalToConstraint(a,pi);
3838 DALI_TEST_EQUALS( c.AsFloat()[0], b.AsFloat()[0], 0.01, TEST_LOCATION);
3842 int UtcDaliBuiltinConstraintRelativeToConstraint(void)
3844 TestApplication application;
3846 Actor actor1 = Actor::New();
3847 Vector3 startPosition( 10, 10, 10 );
3848 actor1.SetPosition( startPosition );
3849 Stage::GetCurrent().Add( actor1 );
3851 Actor actor2 = Actor::New();
3852 Vector3 startSize( 100, 100, 100 );
3853 actor2.SetSize( startSize );
3854 Stage::GetCurrent().Add( actor2 );
3856 application.SendNotification();
3857 application.Render(0);
3858 DALI_TEST_CHECK( actor1.GetCurrentPosition() == startPosition );
3859 DALI_TEST_CHECK( actor2.GetCurrentSize() == startSize );
3861 // Apply constraint - actor1 size == actor2 position
3863 RelativeToConstraint( 0.f );
3864 Vector3 scale( 0.5, 0.6, 0.7 );
3865 Constraint constraint = Constraint::New<Vector3>( Actor::SIZE,
3866 Source( actor1, Actor::POSITION ),
3867 RelativeToConstraint( scale ) );
3868 constraint.SetRemoveAction( Constraint::Discard );
3869 actor2.ApplyConstraint( constraint );
3871 application.SendNotification();
3872 application.Render(0);
3874 // Constraint should be fully applied
3875 DALI_TEST_EQUALS( actor2.GetCurrentSize(), scale * startPosition, TEST_LOCATION );
3878 Vector3 endPosition( 2, 2, 2 );
3879 actor1.SetPosition( endPosition );
3881 application.SendNotification();
3882 application.Render(0);
3884 // Constraint should be fully applied
3885 DALI_TEST_EQUALS( actor2.GetCurrentSize(), scale * endPosition, TEST_LOCATION );
3886 application.Render(0);
3887 DALI_TEST_EQUALS( actor2.GetCurrentSize(), scale * endPosition, TEST_LOCATION );
3890 // Check float variant of constraint
3892 float scale2( 0.5f );
3893 float startOpacity(1.0f);
3894 actor1.SetOpacity( startOpacity );
3895 actor2.SetOpacity( startOpacity );
3897 application.SendNotification();
3898 application.Render(0);
3899 DALI_TEST_EQUALS( actor1.GetCurrentOpacity(), startOpacity, TEST_LOCATION );
3900 DALI_TEST_EQUALS( actor2.GetCurrentOpacity(), startOpacity, TEST_LOCATION );
3902 Constraint constraint2 = Constraint::New<float>( Actor::COLOR_ALPHA,
3903 Source( actor1, Actor::COLOR_ALPHA ),
3904 RelativeToConstraintFloat(scale2) );
3905 constraint2.SetRemoveAction( Constraint::Discard );
3906 actor2.ApplyConstraint(constraint2);
3907 application.SendNotification();
3908 application.Render(0);
3910 DALI_TEST_EQUALS( actor2.GetCurrentOpacity(), startOpacity * scale2, TEST_LOCATION );
3914 int UtcDaliBuiltinConstraintInverseOfConstraint(void)
3916 TestApplication application;
3918 Actor actor1 = Actor::New();
3919 Vector3 startPosition( 10, 10, 10 );
3920 actor1.SetPosition( startPosition );
3921 Stage::GetCurrent().Add( actor1 );
3923 Actor actor2 = Actor::New();
3924 Vector3 startSize( 100, 100, 100 );
3925 actor2.SetSize( startSize );
3926 Stage::GetCurrent().Add( actor2 );
3928 application.SendNotification();
3929 application.Render(0);
3930 DALI_TEST_CHECK( actor1.GetCurrentPosition() == startPosition );
3931 DALI_TEST_CHECK( actor2.GetCurrentSize() == startSize );
3933 // Apply constraint - actor1 size == ( 1 / actor2 position )
3935 Constraint constraint = Constraint::New<Vector3>( Actor::SIZE,
3936 Source( actor1, Actor::POSITION ),
3937 InverseOfConstraint() );
3938 constraint.SetRemoveAction( Constraint::Discard );
3939 actor2.ApplyConstraint( constraint );
3941 application.SendNotification();
3942 application.Render(0);
3944 // Constraint should be fully applied
3945 Vector3 size( 0.1, 0.1, 0.1 ); // 1 / startPosition
3946 DALI_TEST_EQUALS( actor2.GetCurrentSize(), size, 0.00001f, TEST_LOCATION );
3949 Vector3 endPosition( 2, 2, 2 );
3950 actor1.SetPosition( endPosition );
3952 application.SendNotification();
3953 application.Render(0);
3955 // Constraint should be fully applied
3956 size = Vector3( 0.5, 0.5, 0.5 ); // 1 / endPosition
3957 DALI_TEST_EQUALS( actor2.GetCurrentSize(), size, TEST_LOCATION );
3958 application.Render(0);
3959 DALI_TEST_EQUALS( actor2.GetCurrentSize(), size, TEST_LOCATION );
3963 int UtcDaliBuiltinConstraintFunctions(void)
3965 TestApplication application;
3968 SourceWidthFixedHeight sourceWidthFixedHeight( 10.f );
3971 Vector3 reference(1, 10, 0);
3972 Vector3 value = sourceWidthFixedHeight( current, PropertyInputAbstraction(Vector3::ONE) );
3973 DALI_TEST_EQUALS( reference, value, TEST_LOCATION );
3976 Vector3 reference(10, 10, 0);
3977 Vector3 value = sourceWidthFixedHeight( current, PropertyInputAbstraction(Vector3::ONE*10.f) );
3978 DALI_TEST_EQUALS( reference, value, TEST_LOCATION );
3981 Vector3 reference(10,10,0);
3982 Vector3 value = sourceWidthFixedHeight( current, PropertyInputAbstraction(Vector3::ONE*10.f) );
3983 DALI_TEST_EQUALS( reference, value, TEST_LOCATION );
3988 SourceHeightFixedWidth sourceHeightFixedWidth( 10.f );
3991 Vector3 reference(10,1,0);
3992 Vector3 value = sourceHeightFixedWidth( current, PropertyInputAbstraction(Vector3::ONE) );
3993 DALI_TEST_EQUALS( reference, value, TEST_LOCATION );
3996 Vector3 reference(10,10,0);
3997 Vector3 value = sourceHeightFixedWidth( current, PropertyInputAbstraction(Vector3::ONE*10.f) );
3998 DALI_TEST_EQUALS( reference, value, TEST_LOCATION );
4001 Vector3 reference(10,100,0);
4002 Vector3 value = sourceHeightFixedWidth( current, PropertyInputAbstraction(Vector3::ONE*100.f) );
4003 DALI_TEST_EQUALS( reference, value, TEST_LOCATION );
4008 Quaternion current(0, Vector3::YAXIS);
4009 PropertyInputAbstraction target(Vector3::ZAXIS);
4010 PropertyInputAbstraction targetRotation(Vector3::YAXIS);
4011 PropertyInputAbstraction camera(Vector3::ZERO);
4014 Quaternion reference(1., 0., 0., 0.);
4015 Quaternion value = LookAt( current, target, camera, targetRotation );
4016 DALI_TEST_EQUALS( reference, value, 0.001, TEST_LOCATION );
4020 OrientedLookAt orientedLookAt(90.f);
4021 Quaternion reference(.525322, 0., 0., 0.850904);
4022 Quaternion value = orientedLookAt( current, target, camera, targetRotation );
4023 DALI_TEST_EQUALS( reference, value, 0.001, TEST_LOCATION );