2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
21 #include <dali/dali.h>
22 #include <dali-test-suite-utils.h>
26 void utc_dali_constraint_startup(void)
28 test_return_value = TET_UNDEF;
31 void utc_dali_constraint_cleanup(void)
33 test_return_value = TET_PASS;
40 struct EqualToQuaternion
46 Quaternion operator()( const Quaternion& current, const PropertyInput& property )
48 return property.GetQuaternion();
58 Vector4 operator()( const Vector4& current, const PropertyInput& property )
60 return property.GetVector4();
64 class PropertyInputAbstraction : public Dali::PropertyInput
67 PropertyInputAbstraction(const bool& val) : mType(Dali::Property::BOOLEAN), mBoolData( val ) {}
68 PropertyInputAbstraction(const float& val) : mType(Dali::Property::FLOAT), mFloatData( val ) {}
69 PropertyInputAbstraction(const Vector2& val) : mType(Dali::Property::VECTOR2), mVector2Data( val ) {}
70 PropertyInputAbstraction(const Vector3& val) : mType(Dali::Property::VECTOR3), mVector3Data( val ) {}
71 PropertyInputAbstraction(const Vector4& val) : mType(Dali::Property::VECTOR4), mVector4Data( val ) {}
72 PropertyInputAbstraction(const Matrix3& val) : mType(Dali::Property::MATRIX3), mMatrix3Data( val ) {}
73 PropertyInputAbstraction(const Matrix& val) : mType(Dali::Property::MATRIX), mMatrixData( val ) {}
74 PropertyInputAbstraction(const Quaternion& val) : mType(Dali::Property::ROTATION), mQuaternionData( val ) {}
76 ~PropertyInputAbstraction() {}
78 Dali::Property::Type GetType() const { return mType; }
80 const bool& GetBoolean() const { return mBoolData; }
82 const float& GetFloat() const { return mFloatData; }
84 const Vector2& GetVector2() const { return mVector2Data; }
85 const Vector3& GetVector3() const { return mVector3Data; }
86 const Vector4& GetVector4() const { return mVector4Data; }
88 const Matrix3& GetMatrix3() const { return mMatrix3Data; }
89 const Matrix& GetMatrix() const { return mMatrixData; }
91 const Quaternion& GetQuaternion() const { return mQuaternionData; }
94 Dali::Property::Type mType;
100 Matrix3 mMatrix3Data;
102 Quaternion mQuaternionData;
105 static const float POSITION_EPSILON = 0.0001f;
106 static const float ROTATION_EPSILON = 0.0001f;
108 struct TestConstraint
110 Vector4 operator()(const Vector4& color)
112 return Vector4(color.x, color.y, color.z, 0.1f);
116 struct TestConstraintToVector3
118 TestConstraintToVector3(Vector3 target)
123 Vector3 operator()(const Vector3& current)
131 struct TestColorConstraint
133 TestColorConstraint(Vector4 target)
138 Vector4 operator()(const Vector4& color)
146 struct TestPositionConstraint
148 TestPositionConstraint(Vector3 target)
153 Vector3 operator()(const Vector3& position)
162 struct TestAlwaysTrueConstraint
164 bool operator()( const bool& current )
170 struct TestAlwaysEqualOrGreaterThanConstraint
172 TestAlwaysEqualOrGreaterThanConstraint( float value )
177 float operator()( const float& current )
179 return ( current < mValue ) ? mValue : current;
185 struct TestAlwaysEqualOrGreaterThanConstraintVector2
187 TestAlwaysEqualOrGreaterThanConstraintVector2( Vector2 value )
192 Vector2 operator()( const Vector2& current )
194 return Vector2( ( current.x < mValue.x ) ? mValue.x : current.x,
195 ( current.y < mValue.y ) ? mValue.y : current.y
202 struct TestAlwaysEqualOrGreaterThanConstraintVector3
204 TestAlwaysEqualOrGreaterThanConstraintVector3( Vector3 value )
209 Vector3 operator()( const Vector3& current )
211 return Vector3( ( current.x < mValue.x ) ? mValue.x : current.x,
212 ( current.y < mValue.y ) ? mValue.y : current.y,
213 ( current.z < mValue.z ) ? mValue.z : current.z
220 struct TestAlwaysEqualOrGreaterThanConstraintVector4
222 TestAlwaysEqualOrGreaterThanConstraintVector4( Vector4 value )
227 Vector4 operator()( const Vector4& current )
229 return Vector4( ( current.x < mValue.x ) ? mValue.x : current.x,
230 ( current.y < mValue.y ) ? mValue.y : current.y,
231 ( current.z < mValue.z ) ? mValue.z : current.z,
232 ( current.w < mValue.w ) ? mValue.w : current.w
239 struct TestConstraintFloat
241 TestConstraintFloat( float value )
246 float operator()( const float& current )
254 struct TestConstraintVector2
256 TestConstraintVector2( Vector2 value )
261 Vector2 operator()( const Vector2& current )
269 struct TestConstraintVector3
271 TestConstraintVector3( Vector3 value )
276 Vector3 operator()( const Vector3& current )
284 struct TestConstraintVector4
286 TestConstraintVector4( Vector4 value )
291 Vector4 operator()( const Vector4& current )
299 struct TestConstraintRotation
301 TestConstraintRotation( Quaternion rotation )
302 : mRotation( rotation )
306 Quaternion operator()( const Quaternion& current )
311 Quaternion mRotation;
314 struct TestConstraintMatrix3
316 TestConstraintMatrix3(Matrix3 matrix3)
317 : mMatrix3( matrix3 )
321 Matrix3 operator()( const Matrix3& current )
329 struct TestConstraintMatrix
331 TestConstraintMatrix(Matrix matrix)
336 Matrix operator()( const Matrix& current )
344 struct MoveAwayWithFadeConstraint
346 MoveAwayWithFadeConstraint( float distance )
347 : mDistance( distance )
351 Vector3 operator()( const Vector3& current,
352 const PropertyInput& color )
354 return Vector3( current.x,
356 -mDistance * (1.0f - color.GetVector4().a) );
362 struct TestBottomRightAlignConstraint
364 Vector3 operator()( const Vector3& current,
365 const PropertyInput& parentSize )
367 return Vector3( parentSize.GetVector3().x, parentSize.GetVector3().y, 0.0f );
371 struct MeanPositionConstraint1
373 Vector3 operator()( const Vector3& current,
374 const PropertyInput& position1 )
376 return Vector3( position1.GetVector3() );
380 struct MeanPositionConstraint2
382 Vector3 operator()( const Vector3& current,
383 const PropertyInput& position1,
384 const PropertyInput& position2 )
386 Vector3 meanValue = position1.GetVector3() +
387 position2.GetVector3();
389 return meanValue * 0.5f; // div 2
393 struct MeanPositionConstraint3
395 Vector3 operator()( const Vector3& current,
396 const PropertyInput& position1,
397 const PropertyInput& position2,
398 const PropertyInput& position3 )
400 Vector3 meanValue = position1.GetVector3() +
401 position2.GetVector3() +
402 position3.GetVector3();
404 return meanValue * (1.0f / 3.0f); // div 3
408 struct MeanPositionConstraint4
410 Vector3 operator()( const Vector3& current,
411 const PropertyInput& position1,
412 const PropertyInput& position2,
413 const PropertyInput& position3,
414 const PropertyInput& position4 )
416 Vector3 meanValue = position1.GetVector3() +
417 position2.GetVector3() +
418 position3.GetVector3() +
419 position4.GetVector3();
421 return meanValue * 0.25f; // div 4
425 struct MeanPositionConstraint5
427 Vector3 operator()( const Vector3& current,
428 const PropertyInput& position1,
429 const PropertyInput& position2,
430 const PropertyInput& position3,
431 const PropertyInput& position4,
432 const PropertyInput& position5 )
434 Vector3 meanValue = position1.GetVector3() +
435 position2.GetVector3() +
436 position3.GetVector3() +
437 position4.GetVector3() +
438 position5.GetVector3();
440 return meanValue * 0.2f; // div 5
444 struct MeanPositionConstraint6
446 Vector3 operator()( const Vector3& current,
447 const PropertyInput& position1,
448 const PropertyInput& position2,
449 const PropertyInput& position3,
450 const PropertyInput& position4,
451 const PropertyInput& position5,
452 const PropertyInput& position6 )
454 Vector3 meanValue = position1.GetVector3() +
455 position2.GetVector3() +
456 position3.GetVector3() +
457 position4.GetVector3() +
458 position5.GetVector3() +
459 position6.GetVector3();
461 return meanValue * (1.0f / 6.0f); // div 6
465 struct TestRelativeConstraintFloat
467 TestRelativeConstraintFloat(float scale)
472 float operator()( const float& current, const PropertyInput& relative )
474 return relative.GetFloat() * mScale;
480 struct TestRelativeConstraintVector3
482 TestRelativeConstraintVector3(float scale)
487 Vector3 operator()( const Vector3& current, const PropertyInput& relative )
489 return relative.GetVector3() * mScale;
495 } // anonymous namespace
502 int UtcDaliConstraintNewBoolean(void)
504 TestApplication application;
506 Actor actor = Actor::New();
508 // Register a boolean property
509 bool startValue(false);
510 Property::Index index = actor.RegisterProperty( "test-property", startValue );
511 Stage::GetCurrent().Add(actor);
512 DALI_TEST_CHECK( actor.GetProperty<bool>(index) == startValue );
515 * Test that the Constraint is correctly applied on a clean Node
517 application.SendNotification();
518 application.Render(0);
519 DALI_TEST_CHECK( actor.GetProperty<bool>(index) == startValue );
520 application.Render(0);
521 DALI_TEST_CHECK( actor.GetProperty<bool>(index) == startValue );
522 application.Render(0);
523 DALI_TEST_CHECK( actor.GetProperty<bool>(index) == startValue );
527 Constraint constraint = Constraint::New<bool>( index, TestAlwaysTrueConstraint() );
529 actor.ApplyConstraint( constraint );
530 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), false, TEST_LOCATION );
532 application.SendNotification();
533 application.Render(0);
535 // Constraint should be fully applied
536 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), true, TEST_LOCATION );
538 // Check that nothing has changed after a couple of buffer swaps
539 application.Render(0);
540 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), true, TEST_LOCATION );
541 application.Render(0);
542 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), true, TEST_LOCATION );
544 // Try to fight with the constraint - this shouldn't work!
545 actor.SetProperty( index, false );
547 application.SendNotification();
548 application.Render(0);
550 // Check that nothing has changed after a couple of buffer swaps
551 application.Render(0);
552 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), true, TEST_LOCATION );
553 application.Render(0);
554 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), true, TEST_LOCATION );
556 // Remove the constraint, then set new value
557 actor.RemoveConstraints();
558 actor.SetProperty( index, false );
560 // Constraint should have been removed
561 application.SendNotification();
562 application.Render(0);
563 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), false, TEST_LOCATION );
564 application.Render(0);
565 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), false, TEST_LOCATION );
569 int UtcDaliConstraintNewFloat(void)
571 TestApplication application;
573 Actor actor = Actor::New();
575 // Register a float property
576 float startValue(1.0f);
577 Property::Index index = actor.RegisterProperty( "test-property", startValue );
578 Stage::GetCurrent().Add(actor);
579 DALI_TEST_CHECK( actor.GetProperty<float>(index) == startValue );
582 * Test that the Constraint is correctly applied on a clean Node
584 application.SendNotification();
585 application.Render(0);
586 DALI_TEST_CHECK( actor.GetProperty<float>(index) == startValue );
587 application.Render(0);
588 DALI_TEST_CHECK( actor.GetProperty<float>(index) == startValue );
589 application.Render(0);
590 DALI_TEST_CHECK( actor.GetProperty<float>(index) == startValue );
594 float minValue( 2.0f );
595 Constraint constraint = Constraint::New<float>( index, TestAlwaysEqualOrGreaterThanConstraint( minValue ) );
597 actor.ApplyConstraint( constraint );
598 DALI_TEST_EQUALS( actor.GetProperty<float>(index), startValue, TEST_LOCATION );
600 application.SendNotification();
601 application.Render(0);
603 // Constraint should be fully applied
604 DALI_TEST_EQUALS( actor.GetProperty<float>(index), minValue, TEST_LOCATION );
606 // Check that nothing has changed after a couple of buffer swaps
607 application.Render(0);
608 DALI_TEST_EQUALS( actor.GetProperty<float>(index), minValue, TEST_LOCATION );
609 application.Render(0);
610 DALI_TEST_EQUALS( actor.GetProperty<float>(index), minValue, TEST_LOCATION );
612 // Set to greater than 2.0f, the constraint will allow this
613 actor.SetProperty( index, 3.0f );
615 application.SendNotification();
616 application.Render(0);
618 DALI_TEST_EQUALS( actor.GetProperty<float>(index), 3.0f, TEST_LOCATION );
620 // Check that nothing has changed after a couple of buffer swaps
621 application.Render(0);
622 DALI_TEST_EQUALS( actor.GetProperty<float>(index), 3.0f, TEST_LOCATION );
623 application.Render(0);
624 DALI_TEST_EQUALS( actor.GetProperty<float>(index), 3.0f, TEST_LOCATION );
626 // Set to less than 2.0f, the constraint will NOT allow this
627 actor.SetProperty( index, 1.0f );
629 application.SendNotification();
630 application.Render(0);
632 DALI_TEST_EQUALS( actor.GetProperty<float>(index), minValue/*not 1.0f*/, TEST_LOCATION );
634 // Check that nothing has changed after a couple of buffer swaps
635 application.Render(0);
636 DALI_TEST_EQUALS( actor.GetProperty<float>(index), minValue, TEST_LOCATION );
637 application.Render(0);
638 DALI_TEST_EQUALS( actor.GetProperty<float>(index), minValue, TEST_LOCATION );
640 // Remove the constraint, then set new value
641 actor.RemoveConstraints();
642 actor.SetProperty( index, 1.0f );
644 // Constraint should have been removed
645 application.SendNotification();
646 application.Render(0);
647 DALI_TEST_EQUALS( actor.GetProperty<float>(index), 1.0f, TEST_LOCATION );
648 application.Render(0);
649 DALI_TEST_EQUALS( actor.GetProperty<float>(index), 1.0f, TEST_LOCATION );
653 int UtcDaliConstraintNewVector2(void)
655 TestApplication application;
657 Actor actor = Actor::New();
659 // Register a Vector2 property
660 Vector2 startValue( 1.0f, 1.0f );
661 Property::Index index = actor.RegisterProperty( "test-property", startValue );
662 Stage::GetCurrent().Add(actor);
663 DALI_TEST_CHECK( actor.GetProperty<Vector2>(index) == startValue );
666 * Test that the Constraint is correctly applied on a clean Node
668 application.SendNotification();
669 application.Render(0);
670 DALI_TEST_CHECK( actor.GetProperty<Vector2>(index) == startValue );
671 application.Render(0);
672 DALI_TEST_CHECK( actor.GetProperty<Vector2>(index) == startValue );
673 application.Render(0);
674 DALI_TEST_CHECK( actor.GetProperty<Vector2>(index) == startValue );
678 Vector2 minValue( 2.0f, 2.0f );
679 Constraint constraint = Constraint::New<Vector2>( index, TestAlwaysEqualOrGreaterThanConstraintVector2( minValue ) );
681 actor.ApplyConstraint( constraint );
682 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), startValue, TEST_LOCATION );
684 application.SendNotification();
685 application.Render(0);
687 // Constraint should be fully applied
688 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), minValue, TEST_LOCATION );
690 // Check that nothing has changed after a couple of buffer swaps
691 application.Render(0);
692 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), minValue, TEST_LOCATION );
693 application.Render(0);
694 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), minValue, TEST_LOCATION );
696 // Set to greater than 2.0f, the constraint will allow this
697 Vector2 greaterValue( 3.0f, 3.0f );
698 actor.SetProperty( index, greaterValue );
700 application.SendNotification();
701 application.Render(0);
703 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), greaterValue, TEST_LOCATION );
705 // Check that nothing has changed after a couple of buffer swaps
706 application.Render(0);
707 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), greaterValue, TEST_LOCATION );
708 application.Render(0);
709 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), greaterValue, TEST_LOCATION );
711 // Set to less than 2.0f, the constraint will NOT allow this
712 Vector2 lesserValue( 1.0f, 1.0f );
713 actor.SetProperty( index, lesserValue );
715 application.SendNotification();
716 application.Render(0);
718 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), minValue/*not lesserValue*/, TEST_LOCATION );
720 // Check that nothing has changed after a couple of buffer swaps
721 application.Render(0);
722 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), minValue, TEST_LOCATION );
723 application.Render(0);
724 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), minValue, TEST_LOCATION );
726 // Remove the constraint, then set new value
727 actor.RemoveConstraints();
728 actor.SetProperty( index, lesserValue );
730 // Constraint should have been removed
731 application.SendNotification();
732 application.Render(0);
733 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), lesserValue, TEST_LOCATION );
734 application.Render(0);
735 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), lesserValue, TEST_LOCATION );
739 int UtcDaliConstraintNewVector3(void)
741 TestApplication application;
743 Actor actor = Actor::New();
745 // Register a Vector3 property
746 Vector3 startValue(1.0f, 1.0f, 1.0f);
747 Property::Index index = actor.RegisterProperty( "test-property", startValue );
748 Stage::GetCurrent().Add(actor);
749 DALI_TEST_CHECK( actor.GetProperty<Vector3>(index) == startValue );
752 * Test that the Constraint is correctly applied on a clean Node
754 application.SendNotification();
755 application.Render(0);
756 DALI_TEST_CHECK( actor.GetProperty<Vector3>(index) == startValue );
757 application.Render(0);
758 DALI_TEST_CHECK( actor.GetProperty<Vector3>(index) == startValue );
759 application.Render(0);
760 DALI_TEST_CHECK( actor.GetProperty<Vector3>(index) == startValue );
764 Vector3 minValue( 2.0f, 2.0f, 2.0f );
765 Constraint constraint = Constraint::New<Vector3>( index, TestAlwaysEqualOrGreaterThanConstraintVector3( minValue ) );
767 actor.ApplyConstraint( constraint );
768 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), startValue, TEST_LOCATION );
770 application.SendNotification();
771 application.Render(0);
773 // Constraint should be fully applied
774 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), minValue, TEST_LOCATION );
776 // Check that nothing has changed after a couple of buffer swaps
777 application.Render(0);
778 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), minValue, TEST_LOCATION );
779 application.Render(0);
780 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), minValue, TEST_LOCATION );
782 // Set to greater than 2.0f, the constraint will allow this
783 Vector3 greaterValue( 3.0f, 3.0f, 3.0f );
784 actor.SetProperty( index, greaterValue );
786 application.SendNotification();
787 application.Render(0);
789 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), greaterValue, TEST_LOCATION );
791 // Check that nothing has changed after a couple of buffer swaps
792 application.Render(0);
793 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), greaterValue, TEST_LOCATION );
794 application.Render(0);
795 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), greaterValue, TEST_LOCATION );
797 // Set to less than 2.0f, the constraint will NOT allow this
798 Vector3 lesserValue( 1.0f, 1.0f, 1.0f );
799 actor.SetProperty( index, lesserValue );
801 application.SendNotification();
802 application.Render(0);
804 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), minValue/*not lesserValue*/, TEST_LOCATION );
806 // Check that nothing has changed after a couple of buffer swaps
807 application.Render(0);
808 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), minValue, TEST_LOCATION );
809 application.Render(0);
810 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), minValue, TEST_LOCATION );
812 // Remove the constraint, then set new value
813 actor.RemoveConstraints();
814 actor.SetProperty( index, lesserValue );
816 // Constraint should have been removed
817 application.SendNotification();
818 application.Render(0);
819 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), lesserValue, TEST_LOCATION );
820 application.Render(0);
821 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), lesserValue, TEST_LOCATION );
825 int UtcDaliConstraintNewVector4(void)
827 TestApplication application;
829 Actor actor = Actor::New();
831 // Register a Vector4 property
832 Vector4 startValue( 1.0f, 1.0f, 1.0f, 1.0f );
833 Property::Index index = actor.RegisterProperty( "test-property", startValue );
834 Stage::GetCurrent().Add(actor);
835 DALI_TEST_CHECK( actor.GetProperty<Vector4>(index) == startValue );
838 * Test that the Constraint is correctly applied on a clean Node
840 application.SendNotification();
841 application.Render(0);
842 DALI_TEST_CHECK( actor.GetProperty<Vector4>(index) == startValue );
843 application.Render(0);
844 DALI_TEST_CHECK( actor.GetProperty<Vector4>(index) == startValue );
845 application.Render(0);
846 DALI_TEST_CHECK( actor.GetProperty<Vector4>(index) == startValue );
850 Vector4 minValue( 2.0f, 2.0f, 2.0f, 2.0f );
851 Constraint constraint = Constraint::New<Vector4>( index, TestAlwaysEqualOrGreaterThanConstraintVector4( minValue ) );
853 actor.ApplyConstraint( constraint );
854 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), startValue, TEST_LOCATION );
856 application.SendNotification();
857 application.Render(0);
859 // Constraint should be fully applied
860 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), minValue, TEST_LOCATION );
862 // Check that nothing has changed after a couple of buffer swaps
863 application.Render(0);
864 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), minValue, TEST_LOCATION );
865 application.Render(0);
866 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), minValue, TEST_LOCATION );
868 // Set to greater than 2.0f, the constraint will allow this
869 Vector4 greaterValue( 3.0f, 3.0f, 3.0f, 3.0f );
870 actor.SetProperty( index, greaterValue );
872 application.SendNotification();
873 application.Render(0);
875 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), greaterValue, TEST_LOCATION );
877 // Check that nothing has changed after a couple of buffer swaps
878 application.Render(0);
879 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), greaterValue, TEST_LOCATION );
880 application.Render(0);
881 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), greaterValue, TEST_LOCATION );
883 // Set to less than 2.0f, the constraint will NOT allow this
884 Vector4 lesserValue( 1.0f, 1.0f, 1.0f, 1.0f );
885 actor.SetProperty( index, lesserValue );
887 application.SendNotification();
888 application.Render(0);
890 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), minValue/*not lesserValue*/, TEST_LOCATION );
892 // Check that nothing has changed after a couple of buffer swaps
893 application.Render(0);
894 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), minValue, TEST_LOCATION );
895 application.Render(0);
896 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), minValue, TEST_LOCATION );
898 // Remove the constraint, then set new value
899 actor.RemoveConstraints();
900 actor.SetProperty( index, lesserValue );
902 // Constraint should have been removed
903 application.SendNotification();
904 application.Render(0);
905 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), lesserValue, TEST_LOCATION );
906 application.Render(0);
907 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), lesserValue, TEST_LOCATION );
911 int UtcDaliConstraintNewMatrix(void)
915 TestApplication application;
917 Actor actor = Actor::New();
919 // Register a Matrix property
920 Matrix startValue = Matrix::IDENTITY;
921 Property::Index index = actor.RegisterProperty( "test-property", startValue );
922 DALI_TEST_CHECK( index != Property::INVALID_INDEX );
923 if (index != Property::INVALID_INDEX)
925 Stage::GetCurrent().Add(actor);
926 DALI_TEST_CHECK( actor.GetProperty<Matrix>(index) == startValue );
929 Matrix constraintLimit;
930 constraintLimit.SetTransformComponents(Vector3::ONE, Quaternion(Radian(Degree(30.0f)), Vector3::YAXIS), Vector3::ZAXIS );
931 Constraint constraint = Constraint::New<Matrix>( index, TestConstraintMatrix(constraintLimit));
932 actor.ApplyConstraint( constraint );
933 DALI_TEST_EQUALS( actor.GetProperty<Matrix>(index), startValue, TEST_LOCATION );
935 application.SendNotification();
936 application.Render(0);
938 DALI_TEST_EQUALS( actor.GetProperty<Matrix>(index), constraintLimit, TEST_LOCATION );
941 catch (Dali::DaliException& e)
943 tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
949 int UtcDaliConstraintNewMatrix3(void)
953 TestApplication application;
955 Actor actor = Actor::New();
957 // Register a Matrix3 property
958 Matrix3 startValue(1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f);
959 Property::Index index = actor.RegisterProperty( "test-property", startValue );
960 DALI_TEST_CHECK( index != Property::INVALID_INDEX );
961 if (index != Property::INVALID_INDEX)
963 Stage::GetCurrent().Add(actor);
964 DALI_TEST_CHECK( actor.GetProperty<Matrix3>(index) == startValue );
967 Matrix3 constraintLimit(42.0f, 0.0f, 0.0f, 0.0f, 42.0f, 0.0f, 0.0f, 0.0f, 1.0f);
968 Constraint constraint = Constraint::New<Matrix3>( index, TestConstraintMatrix3(constraintLimit));
969 actor.ApplyConstraint( constraint );
970 DALI_TEST_EQUALS( actor.GetProperty<Matrix3>(index), startValue, 0.001f, TEST_LOCATION );
972 application.SendNotification();
973 application.Render(0);
975 DALI_TEST_EQUALS( actor.GetProperty<Matrix3>(index), constraintLimit, 0.001f, TEST_LOCATION );
978 catch (Dali::DaliException& e)
980 tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str() );
986 int UtcDaliConstraintNewQuaternion(void)
988 TestApplication application;
990 Actor actor = Actor::New();
992 // Register a Quaternion property
993 Quaternion startValue( 0.0f, Vector3::YAXIS );
994 Property::Index index = actor.RegisterProperty( "test-property", startValue );
995 Stage::GetCurrent().Add(actor);
996 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), startValue, ROTATION_EPSILON, TEST_LOCATION );
999 * Test that the Constraint is correctly applied on a clean Node
1001 application.SendNotification();
1002 application.Render(0);
1003 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), startValue, ROTATION_EPSILON, TEST_LOCATION );
1004 application.Render(0);
1005 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), startValue, ROTATION_EPSILON, TEST_LOCATION );
1006 application.Render(0);
1007 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), startValue, ROTATION_EPSILON, TEST_LOCATION );
1011 Quaternion constrainedRotation( M_PI*0.25f, Vector3::YAXIS );
1012 Constraint constraint = Constraint::New<Quaternion>( index, TestConstraintRotation( constrainedRotation ) );
1014 actor.ApplyConstraint( constraint );
1015 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), startValue, ROTATION_EPSILON, TEST_LOCATION );
1017 application.SendNotification();
1018 application.Render(0);
1020 // Constraint should be fully applied
1021 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), constrainedRotation, ROTATION_EPSILON, TEST_LOCATION );
1023 // Check that nothing has changed after a couple of buffer swaps
1024 application.Render(0);
1025 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), constrainedRotation, ROTATION_EPSILON, TEST_LOCATION );
1026 application.Render(0);
1027 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), constrainedRotation, ROTATION_EPSILON, TEST_LOCATION );
1029 // Set to a different rotation, the constraint will NOT allow this
1030 Quaternion differentRotation( M_PI*0.5f, Vector3::YAXIS );
1031 actor.SetProperty( index, differentRotation );
1033 application.SendNotification();
1034 application.Render(0);
1036 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), constrainedRotation/*not differentRotation*/, ROTATION_EPSILON, TEST_LOCATION );
1038 // Check that nothing has changed after a couple of buffer swaps
1039 application.Render(0);
1040 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), constrainedRotation, ROTATION_EPSILON, TEST_LOCATION );
1041 application.Render(0);
1042 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), constrainedRotation, ROTATION_EPSILON, TEST_LOCATION );
1044 // Remove the constraint, then set new value
1045 actor.RemoveConstraints();
1046 actor.SetProperty( index, differentRotation );
1048 // Constraint should have been removed
1049 application.SendNotification();
1050 application.Render(0);
1051 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), differentRotation, ROTATION_EPSILON, TEST_LOCATION );
1052 application.Render(0);
1053 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), differentRotation, ROTATION_EPSILON, TEST_LOCATION );
1057 int UtcDaliConstraintNewOffStageBoolean(void)
1059 TestApplication application;
1061 Actor actor = Actor::New();
1063 // Register a boolean property
1064 bool startValue(false);
1065 Property::Index index = actor.RegisterProperty( "test-property", startValue );
1066 DALI_TEST_CHECK( actor.GetProperty<bool>(index) == startValue );
1068 // Apply constraint to off-stage Actor
1069 Constraint constraint = Constraint::New<bool>( index, TestAlwaysTrueConstraint() );
1070 actor.ApplyConstraint( constraint );
1072 application.SendNotification();
1073 application.Render(0);
1074 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), false, TEST_LOCATION );
1076 // Add actor to stage
1077 Stage::GetCurrent().Add(actor);
1078 application.SendNotification();
1079 application.Render(0);
1081 // Constraint should be fully applied
1082 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), true, TEST_LOCATION );
1084 // Check that nothing has changed after a couple of buffer swaps
1085 application.Render(0);
1086 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), true, TEST_LOCATION );
1087 application.Render(0);
1088 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), true, TEST_LOCATION );
1090 // Take the actor off-stage
1091 Stage::GetCurrent().Remove(actor);
1092 application.SendNotification();
1093 application.Render(0);
1094 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), true, TEST_LOCATION );
1096 // Set a new value; the constraint will not prevent this
1097 actor.SetProperty( index, false );
1098 application.SendNotification();
1099 application.Render(0);
1100 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), false, TEST_LOCATION );
1102 // Add actor to stage (2nd time)
1103 Stage::GetCurrent().Add(actor);
1104 application.SendNotification();
1105 application.Render(0);
1107 // Constraint should be fully applied (2nd time)
1108 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), true, TEST_LOCATION );
1110 // Check that nothing has changed after a couple of buffer swaps
1111 application.Render(0);
1112 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), true, TEST_LOCATION );
1113 application.Render(0);
1114 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), true, TEST_LOCATION );
1116 // Take the actor off-stage (2nd-time)
1117 Stage::GetCurrent().Remove(actor);
1118 application.SendNotification();
1119 application.Render(0);
1120 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), true, TEST_LOCATION );
1122 // Remove the constraint, and set a new value
1123 actor.RemoveConstraints();
1124 actor.SetProperty( index, false );
1125 application.SendNotification();
1126 application.Render(0);
1127 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), false, TEST_LOCATION );
1129 // Add actor to stage (3rd time)
1130 Stage::GetCurrent().Add(actor);
1131 application.SendNotification();
1132 application.Render(0);
1134 // Constraint should be gone
1135 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), false, TEST_LOCATION );
1137 // Check that nothing has changed after a couple of buffer swaps
1138 application.Render(0);
1139 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), false, TEST_LOCATION );
1140 application.Render(0);
1141 DALI_TEST_EQUALS( actor.GetProperty<bool>(index), false, TEST_LOCATION );
1145 int UtcDaliConstraintNewOffStageFloat(void)
1147 TestApplication application;
1149 Actor actor = Actor::New();
1151 // Register a float property
1152 float startValue(1.0f);
1153 Property::Index index = actor.RegisterProperty( "test-property", startValue );
1154 DALI_TEST_CHECK( actor.GetProperty<float>(index) == startValue );
1156 // Apply constraint to off-stage Actor
1157 float constrainedValue( 2.0f );
1158 Constraint constraint = Constraint::New<float>( index, TestConstraintFloat( constrainedValue ) );
1159 actor.ApplyConstraint( constraint );
1161 application.SendNotification();
1162 application.Render(0);
1163 DALI_TEST_EQUALS( actor.GetProperty<float>(index), startValue, TEST_LOCATION );
1165 // Add actor to stage
1166 Stage::GetCurrent().Add(actor);
1167 application.SendNotification();
1168 application.Render(0);
1170 // Constraint should be fully applied
1171 DALI_TEST_EQUALS( actor.GetProperty<float>(index), constrainedValue, TEST_LOCATION );
1173 // Check that nothing has changed after a couple of buffer swaps
1174 application.Render(0);
1175 DALI_TEST_EQUALS( actor.GetProperty<float>(index), constrainedValue, TEST_LOCATION );
1176 application.Render(0);
1177 DALI_TEST_EQUALS( actor.GetProperty<float>(index), constrainedValue, TEST_LOCATION );
1179 // Take the actor off-stage
1180 Stage::GetCurrent().Remove(actor);
1181 application.SendNotification();
1182 application.Render(0);
1183 DALI_TEST_EQUALS( actor.GetProperty<float>(index), constrainedValue, TEST_LOCATION );
1185 // Set back to startValue; the constraint will not prevent this
1186 actor.SetProperty( index, startValue );
1187 application.SendNotification();
1188 application.Render(0);
1189 DALI_TEST_EQUALS( actor.GetProperty<float>(index), startValue, TEST_LOCATION );
1191 // Add actor to stage (2nd time)
1192 Stage::GetCurrent().Add(actor);
1193 application.SendNotification();
1194 application.Render(0);
1196 // Constraint should be fully applied (2nd time)
1197 DALI_TEST_EQUALS( actor.GetProperty<float>(index), constrainedValue, TEST_LOCATION );
1199 // Check that nothing has changed after a couple of buffer swaps
1200 application.Render(0);
1201 DALI_TEST_EQUALS( actor.GetProperty<float>(index), constrainedValue, TEST_LOCATION );
1202 application.Render(0);
1203 DALI_TEST_EQUALS( actor.GetProperty<float>(index), constrainedValue, TEST_LOCATION );
1205 // Take the actor off-stage (2nd-time)
1206 Stage::GetCurrent().Remove(actor);
1207 application.SendNotification();
1208 application.Render(0);
1209 DALI_TEST_EQUALS( actor.GetProperty<float>(index), constrainedValue, TEST_LOCATION );
1211 // Remove the constraint, and set back to startValue
1212 actor.RemoveConstraints();
1213 actor.SetProperty( index, startValue );
1214 application.SendNotification();
1215 application.Render(0);
1216 DALI_TEST_EQUALS( actor.GetProperty<float>(index), startValue, TEST_LOCATION );
1218 // Add actor to stage (3rd time)
1219 Stage::GetCurrent().Add(actor);
1220 application.SendNotification();
1221 application.Render(0);
1223 // Constraint should be gone
1224 DALI_TEST_EQUALS( actor.GetProperty<float>(index), startValue, TEST_LOCATION );
1226 // Check that nothing has changed after a couple of buffer swaps
1227 application.Render(0);
1228 DALI_TEST_EQUALS( actor.GetProperty<float>(index), startValue, TEST_LOCATION );
1229 application.Render(0);
1230 DALI_TEST_EQUALS( actor.GetProperty<float>(index), startValue, TEST_LOCATION );
1234 int UtcDaliConstraintNewOffStageVector2(void)
1236 TestApplication application;
1238 Actor actor = Actor::New();
1240 // Register a Vector2 property
1241 Vector2 startValue(1.0f, 1.0f);
1242 Property::Index index = actor.RegisterProperty( "test-property", startValue );
1243 DALI_TEST_CHECK( actor.GetProperty<Vector2>(index) == startValue );
1245 // Apply constraint to off-stage Actor
1246 Vector2 constrainedValue( 2.0f, 2.0f );
1247 Constraint constraint = Constraint::New<Vector2>( index, TestConstraintVector2( constrainedValue ) );
1248 actor.ApplyConstraint( constraint );
1250 application.SendNotification();
1251 application.Render(0);
1252 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), startValue, TEST_LOCATION );
1254 // Add actor to stage
1255 Stage::GetCurrent().Add(actor);
1256 application.SendNotification();
1257 application.Render(0);
1259 // Constraint should be fully applied
1260 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), constrainedValue, TEST_LOCATION );
1262 // Check that nothing has changed after a couple of buffer swaps
1263 application.Render(0);
1264 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), constrainedValue, TEST_LOCATION );
1265 application.Render(0);
1266 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), constrainedValue, TEST_LOCATION );
1268 // Take the actor off-stage
1269 Stage::GetCurrent().Remove(actor);
1270 application.SendNotification();
1271 application.Render(0);
1272 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), constrainedValue, TEST_LOCATION );
1274 // Set back to startValue; the constraint will not prevent this
1275 actor.SetProperty( index, startValue );
1276 application.SendNotification();
1277 application.Render(0);
1278 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), startValue, TEST_LOCATION );
1280 // Add actor to stage (2nd time)
1281 Stage::GetCurrent().Add(actor);
1282 application.SendNotification();
1283 application.Render(0);
1285 // Constraint should be fully applied (2nd time)
1286 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), constrainedValue, TEST_LOCATION );
1288 // Check that nothing has changed after a couple of buffer swaps
1289 application.Render(0);
1290 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), constrainedValue, TEST_LOCATION );
1291 application.Render(0);
1292 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), constrainedValue, TEST_LOCATION );
1294 // Take the actor off-stage (2nd-time)
1295 Stage::GetCurrent().Remove(actor);
1296 application.SendNotification();
1297 application.Render(0);
1298 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), constrainedValue, TEST_LOCATION );
1300 // Remove the constraint, and set back to startValue
1301 actor.RemoveConstraints();
1302 actor.SetProperty( index, startValue );
1303 application.SendNotification();
1304 application.Render(0);
1305 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), startValue, TEST_LOCATION );
1307 // Add actor to stage (3rd time)
1308 Stage::GetCurrent().Add(actor);
1309 application.SendNotification();
1310 application.Render(0);
1312 // Constraint should be gone
1313 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), startValue, TEST_LOCATION );
1315 // Check that nothing has changed after a couple of buffer swaps
1316 application.Render(0);
1317 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), startValue, TEST_LOCATION );
1318 application.Render(0);
1319 DALI_TEST_EQUALS( actor.GetProperty<Vector2>(index), startValue, TEST_LOCATION );
1323 int UtcDaliConstraintNewOffStageVector3(void)
1325 TestApplication application;
1326 Vector3 startValue(1.0f, 1.0f, 1.0f);
1327 Vector3 constrainedValue = Vector3( 2.0f, 3.0f, 4.0f );
1329 Actor actor = Actor::New();
1330 // Register a Vector3 property
1332 Property::Index index = actor.RegisterProperty( "test-property", startValue );
1333 DALI_TEST_CHECK( actor.GetProperty<Vector3>(index) == startValue );
1335 // Apply constraint to off-stage Actor
1336 Constraint constraint = Constraint::New<Vector3>( index, TestConstraintVector3( constrainedValue ) );
1337 actor.ApplyConstraint( constraint );
1339 application.SendNotification();
1340 application.Render(0);
1341 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), startValue, TEST_LOCATION );
1343 // Add actor to stage
1344 Stage::GetCurrent().Add(actor);
1345 application.SendNotification();
1346 application.Render();
1348 // Constraint should be fully applied
1349 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), constrainedValue, TEST_LOCATION );
1351 // Check that nothing has changed after a couple of buffer swaps
1352 application.Render();
1353 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), constrainedValue, TEST_LOCATION );
1354 application.Render();
1355 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), constrainedValue, TEST_LOCATION );
1357 // Take the actor off-stage
1358 Stage::GetCurrent().Remove(actor);
1359 application.SendNotification();
1360 application.Render();
1361 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), constrainedValue, TEST_LOCATION );
1363 // Set back to startValue; the constraint will not prevent this
1364 Vector3 intermediateValue(5.0f, 6.0f, 7.0f);
1365 actor.SetProperty( index, intermediateValue );
1366 application.SendNotification();
1367 application.Render();
1368 application.Render(); // ensure both buffers are set to intermediateValue
1369 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), intermediateValue, TEST_LOCATION );
1371 // Add actor to stage (2nd time)
1372 Stage::GetCurrent().Add(actor);
1373 application.SendNotification();
1374 application.Render();
1376 // Constraint should be fully applied (2nd time)
1377 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), constrainedValue, TEST_LOCATION );
1379 // Check that nothing has changed after a couple of buffer swaps
1380 application.Render();
1381 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), constrainedValue, TEST_LOCATION );
1382 application.Render();
1383 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), constrainedValue, TEST_LOCATION );
1385 // Take the actor off-stage (2nd-time)
1386 Stage::GetCurrent().Remove(actor);
1387 application.SendNotification();
1388 application.Render();
1389 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), constrainedValue, TEST_LOCATION );
1391 // Remove the constraint, and set back to startValue
1392 actor.RemoveConstraints();
1393 actor.SetProperty( index, startValue );
1394 application.SendNotification();
1395 application.Render();
1396 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), startValue, TEST_LOCATION );
1398 // Add actor to stage (3rd time)
1399 Stage::GetCurrent().Add(actor);
1400 application.SendNotification();
1401 application.Render();
1403 // Constraint should be gone
1404 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), startValue, TEST_LOCATION );
1406 // Check that nothing has changed after a couple of buffer swaps
1407 application.Render();
1408 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), startValue, TEST_LOCATION );
1409 application.Render();
1410 DALI_TEST_EQUALS( actor.GetProperty<Vector3>(index), startValue, TEST_LOCATION );
1414 int UtcDaliConstraintNewOffStageVector4(void)
1416 TestApplication application;
1418 Actor actor = Actor::New();
1420 // Register a Vector4 property
1421 Vector4 startValue(1.0f, 1.0f, 1.0f, 1.0f);
1422 Property::Index index = actor.RegisterProperty( "test-property", startValue );
1423 DALI_TEST_CHECK( actor.GetProperty<Vector4>(index) == startValue );
1425 // Apply constraint to off-stage Actor
1426 Vector4 constrainedValue( 2.0f, 2.0f, 2.0f, 2.0f );
1427 Constraint constraint = Constraint::New<Vector4>( index, TestConstraintVector4( constrainedValue ) );
1428 actor.ApplyConstraint( constraint );
1430 application.SendNotification();
1431 application.Render(0);
1432 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), startValue, TEST_LOCATION );
1434 // Add actor to stage
1435 Stage::GetCurrent().Add(actor);
1436 application.SendNotification();
1437 application.Render(0);
1439 // Constraint should be fully applied
1440 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), constrainedValue, TEST_LOCATION );
1442 // Check that nothing has changed after a couple of buffer swaps
1443 application.Render(0);
1444 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), constrainedValue, TEST_LOCATION );
1445 application.Render(0);
1446 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), constrainedValue, TEST_LOCATION );
1448 // Take the actor off-stage
1449 Stage::GetCurrent().Remove(actor);
1450 application.SendNotification();
1451 application.Render(0);
1452 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), constrainedValue, TEST_LOCATION );
1454 // Set back to startValue; the constraint will not prevent this
1455 actor.SetProperty( index, startValue );
1456 application.SendNotification();
1457 application.Render(0);
1458 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), startValue, TEST_LOCATION );
1460 // Add actor to stage (2nd time)
1461 Stage::GetCurrent().Add(actor);
1462 application.SendNotification();
1463 application.Render(0);
1465 // Constraint should be fully applied (2nd time)
1466 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), constrainedValue, TEST_LOCATION );
1468 // Check that nothing has changed after a couple of buffer swaps
1469 application.Render(0);
1470 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), constrainedValue, TEST_LOCATION );
1471 application.Render(0);
1472 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), constrainedValue, TEST_LOCATION );
1474 // Take the actor off-stage (2nd-time)
1475 Stage::GetCurrent().Remove(actor);
1476 application.SendNotification();
1477 application.Render(0);
1478 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), constrainedValue, TEST_LOCATION );
1480 // Remove the constraint, and set back to startValue
1481 actor.RemoveConstraints();
1482 actor.SetProperty( index, startValue );
1483 application.SendNotification();
1484 application.Render(0);
1485 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), startValue, TEST_LOCATION );
1487 // Add actor to stage (3rd time)
1488 Stage::GetCurrent().Add(actor);
1489 application.SendNotification();
1490 application.Render(0);
1492 // Constraint should be gone
1493 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), startValue, TEST_LOCATION );
1495 // Check that nothing has changed after a couple of buffer swaps
1496 application.Render(0);
1497 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), startValue, TEST_LOCATION );
1498 application.Render(0);
1499 DALI_TEST_EQUALS( actor.GetProperty<Vector4>(index), startValue, TEST_LOCATION );
1503 int UtcDaliConstraintNewOffStageQuaternion(void)
1505 TestApplication application;
1507 Actor actor = Actor::New();
1509 // Register a Quaternion property
1510 Quaternion startValue( 0.0f, Vector3::YAXIS );
1511 Property::Index index = actor.RegisterProperty( "test-property", startValue );
1512 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), startValue, ROTATION_EPSILON, TEST_LOCATION );
1514 // Apply constraint to off-stage Actor
1515 Quaternion constrainedRotation( M_PI*0.25f, Vector3::YAXIS );
1516 Constraint constraint = Constraint::New<Quaternion>( index, TestConstraintRotation( constrainedRotation ) );
1517 actor.ApplyConstraint( constraint );
1519 application.SendNotification();
1520 application.Render(0);
1521 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), startValue, ROTATION_EPSILON, TEST_LOCATION );
1523 // Add actor to stage
1524 Stage::GetCurrent().Add(actor);
1525 application.SendNotification();
1526 application.Render(0);
1528 // Constraint should be fully applied
1529 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), constrainedRotation, ROTATION_EPSILON, TEST_LOCATION );
1531 // Check that nothing has changed after a couple of buffer swaps
1532 application.Render(0);
1533 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), constrainedRotation, ROTATION_EPSILON, TEST_LOCATION );
1534 application.Render(0);
1535 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), constrainedRotation, ROTATION_EPSILON, TEST_LOCATION );
1537 // Take the actor off-stage
1538 Stage::GetCurrent().Remove(actor);
1539 application.SendNotification();
1540 application.Render(0);
1541 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), constrainedRotation, ROTATION_EPSILON, TEST_LOCATION );
1543 // Set back to startValue; the constraint will not prevent this
1544 actor.SetProperty( index, startValue );
1545 application.SendNotification();
1546 application.Render(0);
1547 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), startValue, ROTATION_EPSILON, TEST_LOCATION );
1549 // Add actor to stage (2nd time)
1550 Stage::GetCurrent().Add(actor);
1551 application.SendNotification();
1552 application.Render(0);
1554 // Constraint should be fully applied (2nd time)
1555 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), constrainedRotation, ROTATION_EPSILON, TEST_LOCATION );
1557 // Check that nothing has changed after a couple of buffer swaps
1558 application.Render(0);
1559 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), constrainedRotation, ROTATION_EPSILON, TEST_LOCATION );
1560 application.Render(0);
1561 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), constrainedRotation, ROTATION_EPSILON, TEST_LOCATION );
1563 // Take the actor off-stage (2nd-time)
1564 Stage::GetCurrent().Remove(actor);
1565 application.SendNotification();
1566 application.Render(0);
1567 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), constrainedRotation, ROTATION_EPSILON, TEST_LOCATION );
1569 // Remove the constraint, and set back to startValue
1570 actor.RemoveConstraints();
1571 actor.SetProperty( index, startValue );
1572 application.SendNotification();
1573 application.Render(0);
1574 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), startValue, ROTATION_EPSILON, TEST_LOCATION );
1576 // Add actor to stage (3rd time)
1577 Stage::GetCurrent().Add(actor);
1578 application.SendNotification();
1579 application.Render(0);
1581 // Constraint should be gone
1582 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), startValue, ROTATION_EPSILON, TEST_LOCATION );
1584 // Check that nothing has changed after a couple of buffer swaps
1585 application.Render(0);
1586 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), startValue, ROTATION_EPSILON, TEST_LOCATION );
1587 application.Render(0);
1588 DALI_TEST_EQUALS( actor.GetProperty<Quaternion>(index), startValue, ROTATION_EPSILON, TEST_LOCATION );
1592 int UtcDaliConstraintNewLocalInput(void)
1594 TestApplication application;
1596 Actor actor = Actor::New();
1597 Stage::GetCurrent().Add(actor);
1599 Vector3 startValue( 0.0f, 0.0f, 0.0f );
1600 float distanceWhenFullyTransparent( 100.0f );
1603 * Test that the Constraint is correctly applied on a clean Node
1605 application.SendNotification();
1606 application.Render(0);
1607 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1608 application.Render(0);
1609 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1610 application.Render(0);
1611 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1613 // Apply constraint with a local input property
1615 Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
1616 LocalSource( Actor::COLOR ),
1617 MoveAwayWithFadeConstraint(distanceWhenFullyTransparent) );
1619 actor.ApplyConstraint( constraint );
1620 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1622 application.SendNotification();
1623 application.Render(0);
1625 // Gradually set the color to fully-transparent; the actor should move back
1627 for ( float progress = 0.0f; progress < 1.1f; progress += 0.1f )
1629 actor.SetOpacity( 1.0f - progress );
1631 application.SendNotification();
1632 application.Render(0);
1633 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), ( startValue - Vector3(0.0f, 0.0f, progress*distanceWhenFullyTransparent) ), POSITION_EPSILON, TEST_LOCATION );
1635 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), ( startValue - Vector3(0.0f, 0.0f, distanceWhenFullyTransparent) ), POSITION_EPSILON, TEST_LOCATION );
1639 int UtcDaliConstraintNewParentInput(void)
1641 TestApplication application;
1643 Actor parent = Actor::New();
1644 Vector3 parentStartSize( 100.0f, 100.0f, 0.0f );
1645 parent.SetSize( parentStartSize );
1646 Stage::GetCurrent().Add( parent );
1648 Actor actor = Actor::New();
1649 parent.Add( actor );
1651 Vector3 startValue( 0.0f, 0.0f, 0.0f );
1654 * Test that the Constraint is correctly applied on a clean Node
1656 application.SendNotification();
1657 application.Render(0);
1658 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1659 application.Render(0);
1660 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1661 application.Render(0);
1662 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1664 // Apply constraint with a parent input property
1666 Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
1667 ParentSource( Actor::SIZE ),
1668 TestBottomRightAlignConstraint() );
1670 actor.ApplyConstraint( constraint );
1671 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1673 application.SendNotification();
1674 application.Render(0);
1676 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), parentStartSize, TEST_LOCATION );
1677 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), parent.GetCurrentSize(), TEST_LOCATION );
1679 // Gradually shrink the parent; the actor should move inwards
1681 for ( float progress = 0.0f; progress < 1.1f; progress += 0.1f )
1683 Vector3 size( parentStartSize * std::max(0.0f, 1.0f - progress) );
1684 parent.SetSize( size );
1686 application.SendNotification();
1687 application.Render(0);
1689 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), size, POSITION_EPSILON, TEST_LOCATION );
1690 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), parent.GetCurrentSize(), POSITION_EPSILON, TEST_LOCATION );
1692 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), Vector3::ZERO, POSITION_EPSILON, TEST_LOCATION );
1696 int UtcDaliConstraintNewInput1(void)
1698 TestApplication application;
1700 Actor parent = Actor::New();
1701 Vector3 parentStartSize( 100.0f, 100.0f, 0.0f );
1702 parent.SetSize( parentStartSize );
1703 Stage::GetCurrent().Add( parent );
1705 Actor actor = Actor::New();
1706 parent.Add( actor );
1708 Actor sibling1 = Actor::New();
1709 sibling1.SetPosition( Vector3(1.0f, 2.0f, 3.0f) );
1710 parent.Add( sibling1 );
1712 Vector3 startValue( 0.0f, 0.0f, 0.0f );
1715 * Test that the Constraint is correctly applied on a clean Node
1717 application.SendNotification();
1718 application.Render(0);
1719 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1720 application.Render(0);
1721 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1722 application.Render(0);
1723 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1725 // Apply constraint with a parent input property
1727 Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
1728 Source( sibling1, Actor::POSITION ),
1729 MeanPositionConstraint1() );
1731 actor.ApplyConstraint( constraint );
1732 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1734 application.SendNotification();
1735 application.Render(0);
1736 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), sibling1.GetCurrentPosition(), TEST_LOCATION );
1738 // Check that nothing has changed after a couple of buffer swaps
1739 application.Render(0);
1740 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), sibling1.GetCurrentPosition(), TEST_LOCATION );
1741 application.Render(0);
1742 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), sibling1.GetCurrentPosition(), TEST_LOCATION );
1746 int UtcDaliConstraintNewInput2(void)
1748 TestApplication application;
1750 Actor parent = Actor::New();
1751 Vector3 parentStartSize( 100.0f, 100.0f, 0.0f );
1752 parent.SetSize( parentStartSize );
1753 Stage::GetCurrent().Add( parent );
1755 Actor actor = Actor::New();
1756 parent.Add( actor );
1758 Actor sibling1 = Actor::New();
1759 sibling1.SetPosition( Vector3(1.0f, 2.0f, 3.0f) );
1760 parent.Add( sibling1 );
1762 Actor sibling2 = Actor::New();
1763 sibling2.SetPosition( Vector3(300.0f, 300.0f, 300.0f) );
1764 parent.Add( sibling2 );
1766 application.SendNotification();
1767 application.Render(0);
1769 Vector3 startValue( 0.0f, 0.0f, 0.0f );
1770 Vector3 meanValue = sibling1.GetCurrentPosition() +
1771 sibling2.GetCurrentPosition();
1772 meanValue *= (1.0f / 2.0f); // divide by number of siblings
1775 * Test that the Constraint is correctly applied on a clean Node
1777 application.SendNotification();
1778 application.Render(0);
1779 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1780 application.Render(0);
1781 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1782 application.Render(0);
1783 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1785 // Apply constraint with a parent input property
1787 Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
1788 Source( sibling1, Actor::POSITION ),
1789 Source( sibling2, Actor::POSITION ),
1790 MeanPositionConstraint2() );
1792 actor.ApplyConstraint( constraint );
1793 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1795 application.SendNotification();
1796 application.Render(0);
1797 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION );
1799 // Check that nothing has changed after a couple of buffer swaps
1800 application.Render(0);
1801 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION );
1802 application.Render(0);
1803 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION );
1807 int UtcDaliConstraintNewInput3(void)
1809 TestApplication application;
1811 Actor parent = Actor::New();
1812 Vector3 parentStartSize( 100.0f, 100.0f, 0.0f );
1813 parent.SetSize( parentStartSize );
1814 Stage::GetCurrent().Add( parent );
1816 Actor actor = Actor::New();
1817 parent.Add( actor );
1819 Actor sibling1 = Actor::New();
1820 sibling1.SetPosition( Vector3(1.0f, 2.0f, 3.0f) );
1821 parent.Add( sibling1 );
1823 Actor sibling2 = Actor::New();
1824 sibling2.SetPosition( Vector3(300.0f, 300.0f, 300.0f) );
1825 parent.Add( sibling2 );
1827 Actor sibling3 = Actor::New();
1828 sibling3.SetPosition( Vector3(-100.0f, -10.0f, -1.0f) );
1829 parent.Add( sibling3 );
1831 application.SendNotification();
1832 application.Render(0);
1834 Vector3 startValue( 0.0f, 0.0f, 0.0f );
1835 Vector3 meanValue = sibling1.GetCurrentPosition() +
1836 sibling2.GetCurrentPosition() +
1837 sibling3.GetCurrentPosition();
1838 meanValue *= (1.0f / 3.0f); // divide by number of siblings
1841 * Test that the Constraint is correctly applied on a clean Node
1843 application.SendNotification();
1844 application.Render(0);
1845 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1846 application.Render(0);
1847 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1848 application.Render(0);
1849 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1851 // Apply constraint with a parent input property
1853 Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
1854 Source( sibling1, Actor::POSITION ),
1855 Source( sibling2, Actor::POSITION ),
1856 Source( sibling3, Actor::POSITION ),
1857 MeanPositionConstraint3() );
1859 actor.ApplyConstraint( constraint );
1860 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1862 application.SendNotification();
1863 application.Render(0);
1864 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION );
1866 // Check that nothing has changed after a couple of buffer swaps
1867 application.Render(0);
1868 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION );
1869 application.Render(0);
1870 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION );
1874 int UtcDaliConstraintNewInput4(void)
1876 TestApplication application;
1878 Actor parent = Actor::New();
1879 Vector3 parentStartSize( 100.0f, 100.0f, 0.0f );
1880 parent.SetSize( parentStartSize );
1881 parent.SetPosition( 10.0f, 10.0f, 10.0f );
1882 Stage::GetCurrent().Add( parent );
1884 Actor actor = Actor::New();
1885 parent.Add( actor );
1887 Actor sibling1 = Actor::New();
1888 sibling1.SetPosition( Vector3(1.0f, 2.0f, 3.0f) );
1889 parent.Add( sibling1 );
1891 Actor sibling2 = Actor::New();
1892 sibling2.SetPosition( Vector3(300.0f, 300.0f, 300.0f) );
1893 parent.Add( sibling2 );
1895 Actor sibling3 = Actor::New();
1896 sibling3.SetPosition( Vector3(-100.0f, -10.0f, -1.0f) );
1897 parent.Add( sibling3 );
1899 application.SendNotification();
1900 application.Render(0);
1902 Vector3 startValue( 0.0f, 0.0f, 0.0f );
1903 Vector3 meanValue = parent.GetCurrentPosition() +
1904 sibling1.GetCurrentPosition() +
1905 sibling2.GetCurrentPosition() +
1906 sibling3.GetCurrentPosition();
1907 meanValue *= (1.0f / 4.0f); // divide by number of positions
1910 * Test that the Constraint is correctly applied on a clean Node
1912 application.SendNotification();
1913 application.Render(0);
1914 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1915 application.Render(0);
1916 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1917 application.Render(0);
1918 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1920 // Apply constraint with a parent input property
1922 Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
1923 Source( sibling1, Actor::POSITION ),
1924 Source( sibling2, Actor::POSITION ),
1925 ParentSource( Actor::POSITION ),
1926 Source( sibling3, Actor::POSITION ),
1927 MeanPositionConstraint4() );
1929 actor.ApplyConstraint( constraint );
1930 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1932 application.SendNotification();
1933 application.Render(0);
1934 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION );
1936 // Check that nothing has changed after a couple of buffer swaps
1937 application.Render(0);
1938 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION );
1939 application.Render(0);
1940 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION );
1944 int UtcDaliConstraintNewInput5(void)
1946 TestApplication application;
1948 Actor parent = Actor::New();
1949 Vector3 parentStartSize( 100.0f, 100.0f, 0.0f );
1950 parent.SetSize( parentStartSize );
1951 parent.SetPosition( 10.0f, 10.0f, 10.0f );
1952 Stage::GetCurrent().Add( parent );
1954 Actor actor = Actor::New();
1955 parent.Add( actor );
1957 Actor sibling1 = Actor::New();
1958 sibling1.SetPosition( Vector3(1.0f, 2.0f, 3.0f) );
1959 parent.Add( sibling1 );
1961 Actor sibling2 = Actor::New();
1962 sibling2.SetPosition( Vector3(300.0f, 300.0f, 300.0f) );
1963 parent.Add( sibling2 );
1965 Actor sibling3 = Actor::New();
1966 sibling3.SetPosition( Vector3(-100.0f, -10.0f, -1.0f) );
1967 parent.Add( sibling3 );
1969 Actor sibling4 = Actor::New();
1970 sibling4.SetPosition( Vector3(-1.0f, 1.0f, 2.0f) );
1971 parent.Add( sibling4 );
1973 application.SendNotification();
1974 application.Render(0);
1976 Vector3 startValue( 0.0f, 0.0f, 0.0f );
1977 Vector3 meanValue = parent.GetCurrentPosition() +
1978 sibling1.GetCurrentPosition() +
1979 sibling2.GetCurrentPosition() +
1980 sibling3.GetCurrentPosition() +
1981 sibling4.GetCurrentPosition();
1982 meanValue *= (1.0f / 5.0f); // divide by number of positions
1985 * Test that the Constraint is correctly applied on a clean Node
1987 application.SendNotification();
1988 application.Render(0);
1989 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1990 application.Render(0);
1991 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1992 application.Render(0);
1993 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
1995 // Apply constraint with a parent input property
1997 Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
1998 Source( sibling1, Actor::POSITION ),
1999 Source( sibling2, Actor::POSITION ),
2000 ParentSource( Actor::POSITION ),
2001 Source( sibling3, Actor::POSITION ),
2002 Source( sibling4, Actor::POSITION ),
2003 MeanPositionConstraint5() );
2005 actor.ApplyConstraint( constraint );
2006 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
2008 application.SendNotification();
2009 application.Render(0);
2010 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION );
2012 // Check that nothing has changed after a couple of buffer swaps
2013 application.Render(0);
2014 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION );
2015 application.Render(0);
2016 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION );
2020 int UtcDaliConstraintNewInput6(void)
2022 TestApplication application;
2024 Actor parent = Actor::New();
2025 Vector3 parentStartSize( 100.0f, 100.0f, 0.0f );
2026 parent.SetSize( parentStartSize );
2027 parent.SetPosition( 10.0f, 10.0f, 10.0f );
2028 Stage::GetCurrent().Add( parent );
2030 Actor actor = Actor::New();
2031 parent.Add( actor );
2033 Actor child = Actor::New();
2034 child.SetPosition( Vector3(7.0f, 7.0f, 7.0f) );
2037 Actor sibling1 = Actor::New();
2038 sibling1.SetPosition( Vector3(1.0f, 2.0f, 3.0f) );
2039 parent.Add( sibling1 );
2041 Actor sibling2 = Actor::New();
2042 sibling2.SetPosition( Vector3(300.0f, 300.0f, 300.0f) );
2043 parent.Add( sibling2 );
2045 Actor sibling3 = Actor::New();
2046 sibling3.SetPosition( Vector3(-100.0f, -10.0f, -1.0f) );
2047 parent.Add( sibling3 );
2049 Actor sibling4 = Actor::New();
2050 sibling4.SetPosition( Vector3(-1.0f, 1.0f, 2.0f) );
2051 parent.Add( sibling4 );
2053 application.SendNotification();
2054 application.Render(0);
2056 Vector3 startValue( 0.0f, 0.0f, 0.0f );
2057 Vector3 meanValue = parent.GetCurrentPosition() +
2058 child.GetCurrentPosition() +
2059 sibling1.GetCurrentPosition() +
2060 sibling2.GetCurrentPosition() +
2061 sibling3.GetCurrentPosition() +
2062 sibling4.GetCurrentPosition();
2063 meanValue *= (1.0f / 6.0f); // divide by number of positions
2066 * Test that the Constraint is correctly applied on a clean Node
2068 application.SendNotification();
2069 application.Render(0);
2070 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
2071 application.Render(0);
2072 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
2073 application.Render(0);
2074 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
2076 // Apply constraint with a parent input property
2078 Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
2079 Source( child, Actor::POSITION ),
2080 Source( sibling1, Actor::POSITION ),
2081 Source( sibling2, Actor::POSITION ),
2082 ParentSource( Actor::POSITION ),
2083 Source( sibling3, Actor::POSITION ),
2084 Source( sibling4, Actor::POSITION ),
2085 MeanPositionConstraint6() );
2087 actor.ApplyConstraint( constraint );
2088 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
2090 application.SendNotification();
2091 application.Render(0);
2092 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION );
2094 // Check that nothing has changed after a couple of buffer swaps
2095 application.Render(0);
2096 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION );
2097 application.Render(0);
2098 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION );
2102 int UtcDaliConstraintDownCast(void)
2104 TestApplication application;
2105 tet_infoline("Testing Dali::Constraint::DownCast()");
2107 Actor actor = Actor::New();
2109 // Register a boolean property
2110 bool startValue(false);
2111 Property::Index index = actor.RegisterProperty( "test-property", startValue );
2112 Constraint constraint = Constraint::New<bool>( index, TestAlwaysTrueConstraint() );
2114 BaseHandle object(constraint);
2116 Constraint constraint2 = Constraint::DownCast(object);
2117 DALI_TEST_CHECK(constraint2);
2119 Constraint constraint3 = DownCast< Constraint >(object);
2120 DALI_TEST_CHECK(constraint3);
2122 BaseHandle unInitializedObject;
2123 Constraint constraint4 = Constraint::DownCast(unInitializedObject);
2124 DALI_TEST_CHECK(!constraint4);
2126 Constraint constraint5 = DownCast< Constraint >(unInitializedObject);
2127 DALI_TEST_CHECK(!constraint5);
2131 int UtcDaliConstraintSetApplyTime(void)
2133 TestApplication application;
2137 Vector4 targetColor(Color::BLACK);
2138 Constraint constraint = Constraint::New<Vector4>( Actor::COLOR, TestColorConstraint(targetColor) );
2139 DALI_TEST_EQUALS(constraint.GetApplyTime(), TimePeriod(0.0f), TEST_LOCATION);
2141 float applySeconds(7.0f);
2142 constraint.SetApplyTime(applySeconds);
2143 DALI_TEST_EQUALS(constraint.GetApplyTime(), TimePeriod(applySeconds), TEST_LOCATION);
2145 // Apply to an actor
2147 Actor actor = Actor::New();
2148 Stage::GetCurrent().Add(actor);
2150 actor.ApplyConstraint( constraint );
2151 DALI_TEST_EQUALS( actor.GetCurrentColor(), Color::WHITE, TEST_LOCATION );
2153 application.SendNotification();
2154 application.Render(static_cast<unsigned int>(applySeconds*200.0f)/* 20% progress */);
2156 // Constraint shouldn't be fully applied yet
2157 Vector4 twentyPercentColor( Color::WHITE.x*0.8f, Color::WHITE.y*0.8f, Color::WHITE.z*0.8f, Color::WHITE.a );
2158 DALI_TEST_EQUALS( actor.GetCurrentColor(), twentyPercentColor, TEST_LOCATION );
2160 // Constraint shouldn't be fully applied yet
2161 application.Render(static_cast<unsigned int>(applySeconds*200.0f)/* 40% progress */);
2162 Vector4 fourtyPercentColor( Color::WHITE.x*0.6f, Color::WHITE.y*0.6f, Color::WHITE.z*0.6f, Color::WHITE.a );
2163 DALI_TEST_EQUALS( actor.GetCurrentColor(), fourtyPercentColor, TEST_LOCATION );
2165 // Constraint shouldn't be fully applied yet
2166 application.Render(static_cast<unsigned int>(applySeconds*200.0f)/* 60% progress */);
2167 Vector4 sixtyPercentColor( Color::WHITE.x*0.4f, Color::WHITE.y*0.4f, Color::WHITE.z*0.4f, Color::WHITE.a );
2168 DALI_TEST_EQUALS( actor.GetCurrentColor(), sixtyPercentColor, TEST_LOCATION );
2170 // Constraint shouldn't be fully applied yet
2171 application.Render(static_cast<unsigned int>(applySeconds*200.0f)/* 80% progress */);
2172 Vector4 eightyPercentColor( Color::WHITE.x*0.2f, Color::WHITE.y*0.2f, Color::WHITE.z*0.2f, Color::WHITE.a );
2173 DALI_TEST_EQUALS( actor.GetCurrentColor(), eightyPercentColor, TEST_LOCATION );
2175 // Constraint should be fully applied
2176 application.Render(static_cast<unsigned int>(applySeconds*200.0f)/* 100% progress */);
2177 DALI_TEST_EQUALS( actor.GetCurrentColor(), targetColor, TEST_LOCATION );
2179 // Constraint should still be fully applied
2180 application.Render(static_cast<unsigned int>(applySeconds*200.0f)/* Still 100% progress */);
2181 DALI_TEST_EQUALS( actor.GetCurrentColor(), targetColor, TEST_LOCATION );
2183 // Check that nothing has changed after a couple of buffer swaps
2184 application.Render(0);
2185 DALI_TEST_EQUALS( actor.GetCurrentColor(), targetColor, TEST_LOCATION );
2186 application.Render(0);
2187 DALI_TEST_EQUALS( actor.GetCurrentColor(), targetColor, TEST_LOCATION );
2191 int UtcDaliConstraintGetApplyTime(void)
2193 TestApplication application;
2195 Constraint constraint = Constraint::New<Vector4>( Actor::COLOR, TestConstraint() );
2196 DALI_TEST_EQUALS(constraint.GetApplyTime(), TimePeriod(0.0f), TEST_LOCATION);
2198 float applySeconds(7.0f);
2199 constraint.SetApplyTime(applySeconds);
2200 DALI_TEST_EQUALS(constraint.GetApplyTime(), TimePeriod(applySeconds), TEST_LOCATION);
2202 constraint.SetApplyTime(applySeconds - 3.0f);
2203 DALI_TEST_EQUALS(constraint.GetApplyTime(), TimePeriod(applySeconds - 3.0f), TEST_LOCATION);
2207 int UtcDaliConstraintSetRemoveTime(void)
2209 TestApplication application;
2211 Vector3 sourcePosition(0.0f, 0.0f, 0.0f);
2212 Vector3 targetPosition(100.0f, 100.0f, 100.0f);
2216 Constraint constraint = Constraint::New<Vector3>( Actor::POSITION, TestPositionConstraint(targetPosition) );
2217 DALI_TEST_EQUALS(constraint.GetRemoveTime(), TimePeriod(0.0f), TEST_LOCATION);
2219 float removeSeconds(8.0f);
2220 constraint.SetRemoveTime(removeSeconds);
2221 DALI_TEST_EQUALS(constraint.GetRemoveTime(), TimePeriod(removeSeconds), TEST_LOCATION);
2223 // Apply to an actor
2225 Actor actor = Actor::New();
2226 Stage::GetCurrent().Add(actor);
2228 actor.ApplyConstraint( constraint );
2229 DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION );
2231 application.SendNotification();
2232 application.Render(100u/*0.1 seconds*/);
2234 // Constraint should be fully applied
2235 DALI_TEST_EQUALS( actor.GetCurrentPosition(), targetPosition, TEST_LOCATION );
2237 // Check that nothing has changed after a couple of buffer swaps
2238 application.Render(0);
2239 DALI_TEST_EQUALS( actor.GetCurrentPosition(), targetPosition, TEST_LOCATION );
2240 application.Render(0);
2241 DALI_TEST_EQUALS( actor.GetCurrentPosition(), targetPosition, TEST_LOCATION );
2243 // Remove from the actor, and set to alternative position
2245 actor.RemoveConstraints();
2247 Vector3 thirdPosition(200.0f, 200.0f, 200.0f);
2248 actor.SetPosition(thirdPosition); // Go back to 3rd position
2250 application.SendNotification();
2251 application.Render(static_cast<unsigned int>(removeSeconds*200.0f)/* 20% removal progress */);
2253 // Constraint shouldn't be fully removed yet
2254 Vector3 twentyPercentBack( targetPosition + (thirdPosition - targetPosition)*0.2f );
2255 DALI_TEST_EQUALS( actor.GetCurrentPosition(), twentyPercentBack, TEST_LOCATION );
2257 application.Render(static_cast<unsigned int>(removeSeconds*200.0f)/* 40% removal progress */);
2259 // Constraint shouldn't be fully removed yet
2260 Vector3 fourtyPercentBack( targetPosition + (thirdPosition - targetPosition)*0.4f );
2261 DALI_TEST_EQUALS( actor.GetCurrentPosition(), fourtyPercentBack, TEST_LOCATION );
2263 application.Render(static_cast<unsigned int>(removeSeconds*200.0f)/* 60% removal progress */);
2265 // Constraint shouldn't be fully removed yet
2266 Vector3 sixtyPercentBack( targetPosition + (thirdPosition - targetPosition)*0.6f );
2267 DALI_TEST_EQUALS( actor.GetCurrentPosition(), sixtyPercentBack, TEST_LOCATION );
2269 application.Render(static_cast<unsigned int>(removeSeconds*200.0f)/* 80% removal progress */);
2271 // Constraint shouldn't be fully removed yet
2272 Vector3 eightyPercentBack( targetPosition + (thirdPosition - targetPosition)*0.8f );
2273 DALI_TEST_EQUALS( actor.GetCurrentPosition(), eightyPercentBack, TEST_LOCATION );
2275 // Constraint should be fully removed
2276 application.Render(static_cast<unsigned int>(removeSeconds*200.0f)/* 100% removal progress */);
2277 DALI_TEST_EQUALS( actor.GetCurrentPosition(), thirdPosition, TEST_LOCATION );
2279 // Constraint should still be fully applied
2280 application.Render(static_cast<unsigned int>(removeSeconds*200.0f)/* Still 100% removal progress */);
2281 DALI_TEST_EQUALS( actor.GetCurrentPosition(), thirdPosition, TEST_LOCATION );
2283 // Check that nothing has changed after a couple of buffer swaps
2284 application.Render(0);
2285 DALI_TEST_EQUALS( actor.GetCurrentPosition(), thirdPosition, TEST_LOCATION );
2286 application.Render(0);
2287 DALI_TEST_EQUALS( actor.GetCurrentPosition(), thirdPosition, TEST_LOCATION );
2291 int UtcDaliConstraintGetRemoveTime(void)
2293 TestApplication application;
2295 Constraint constraint = Constraint::New<Vector4>( Actor::COLOR, TestConstraint() );
2296 DALI_TEST_EQUALS(constraint.GetRemoveTime(), TimePeriod(0.0f), TEST_LOCATION);
2300 int UtcDaliConstraintSetAlphaFunction(void)
2302 TestApplication application;
2304 Vector3 startValue( Vector3::ZERO );
2305 Vector3 targetValue(100.0f, 100.0f, 100.0f);
2307 Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
2308 TestConstraintVector3( targetValue ) );
2310 // Test the alpha-function itself
2312 AlphaFunction func = constraint.GetAlphaFunction();
2313 DALI_TEST_EQUALS(func(0.1f), 0.1f, TEST_LOCATION); // Default is Linear
2315 // Test that the alpha-function is used correctly
2317 Actor actor = Actor::New();
2318 Stage::GetCurrent().Add(actor);
2320 application.SendNotification();
2321 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2322 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
2323 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2324 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
2325 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2326 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
2328 constraint.SetApplyTime( 10.0f );
2329 actor.ApplyConstraint( constraint );
2331 application.SendNotification();
2332 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2333 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), (targetValue - startValue) * 0.1f, TEST_LOCATION );
2334 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2335 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), (targetValue - startValue) * 0.2f, TEST_LOCATION );
2336 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2337 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), (targetValue - startValue) * 0.3f, TEST_LOCATION );
2338 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2339 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), (targetValue - startValue) * 0.4f, TEST_LOCATION );
2340 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2341 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), (targetValue - startValue) * 0.5f, TEST_LOCATION );
2342 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2343 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), (targetValue - startValue) * 0.6f, TEST_LOCATION );
2344 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2345 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), (targetValue - startValue) * 0.7f, TEST_LOCATION );
2346 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2347 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), (targetValue - startValue) * 0.8f, TEST_LOCATION );
2348 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2349 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), (targetValue - startValue) * 0.9f, TEST_LOCATION );
2350 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2351 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), (targetValue - startValue), TEST_LOCATION );
2353 // Check that the constrained value is stable
2354 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2355 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), (targetValue - startValue), TEST_LOCATION );
2356 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2357 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), (targetValue - startValue), TEST_LOCATION );
2359 // Remove the constraint
2361 actor.RemoveConstraints();
2362 actor.SetPosition( startValue );
2364 application.SendNotification();
2365 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2366 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
2367 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2368 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
2369 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2370 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), startValue, TEST_LOCATION );
2372 // Change to non-linear alpha and retest
2374 constraint.SetAlphaFunction(AlphaFunctions::EaseIn);
2375 func = constraint.GetAlphaFunction();
2376 DALI_TEST_CHECK(func(0.1f) < 0.09f);
2378 actor.ApplyConstraint( constraint );
2380 application.SendNotification();
2381 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2383 DALI_TEST_CHECK( actor.GetProperty<Vector3>( Actor::POSITION ).x > startValue.x );
2384 DALI_TEST_CHECK( actor.GetProperty<Vector3>( Actor::POSITION ).y > startValue.y );
2385 DALI_TEST_CHECK( actor.GetProperty<Vector3>( Actor::POSITION ).z > startValue.z );
2387 Vector3 lessThanTenPercentProgress( (targetValue - startValue) * 0.09f );
2388 DALI_TEST_CHECK( actor.GetProperty<Vector3>( Actor::POSITION ).x < lessThanTenPercentProgress.x );
2389 DALI_TEST_CHECK( actor.GetProperty<Vector3>( Actor::POSITION ).y < lessThanTenPercentProgress.y );
2390 DALI_TEST_CHECK( actor.GetProperty<Vector3>( Actor::POSITION ).z < lessThanTenPercentProgress.z );
2392 application.Render(static_cast<unsigned int>(9000.0f/*9 seconds*/));
2393 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), (targetValue - startValue), TEST_LOCATION );
2395 // Check that the constrained value is stable
2396 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2397 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), (targetValue - startValue), TEST_LOCATION );
2398 application.Render(static_cast<unsigned int>(1000.0f/*1 second*/));
2399 DALI_TEST_EQUALS( actor.GetProperty<Vector3>( Actor::POSITION ), (targetValue - startValue), TEST_LOCATION );
2403 int UtcDaliConstraintGetAlphaFunction(void)
2405 TestApplication application;
2407 Constraint constraint = Constraint::New<Vector4>( Actor::COLOR, TestConstraint() );
2409 AlphaFunction func = constraint.GetAlphaFunction();
2410 DALI_TEST_EQUALS(func(0.5f), 0.5f, TEST_LOCATION); // Default is Linear
2414 int UtcDaliConstraintSetRemoveAction(void)
2416 TestApplication application;
2418 Vector3 sourcePosition(0.0f, 0.0f, 0.0f);
2419 Vector3 targetPosition(100.0f, 100.0f, 100.0f);
2421 // Build constraint, with "Discard" remove action
2423 Constraint constraint = Constraint::New<Vector3>( Actor::POSITION, TestPositionConstraint(targetPosition) );
2424 DALI_TEST_EQUALS((unsigned int)constraint.GetRemoveAction(), (unsigned int)Constraint::Bake, TEST_LOCATION);
2426 constraint.SetRemoveAction(Constraint::Discard);
2427 DALI_TEST_EQUALS((unsigned int)constraint.GetRemoveAction(), (unsigned int)Constraint::Discard, TEST_LOCATION);
2429 float removeSeconds(8.0f);
2430 constraint.SetRemoveTime(removeSeconds);
2431 DALI_TEST_EQUALS(constraint.GetRemoveTime(), TimePeriod(removeSeconds), TEST_LOCATION);
2433 // Apply to an actor
2435 Actor actor = Actor::New();
2436 Stage::GetCurrent().Add(actor);
2438 actor.ApplyConstraint( constraint );
2439 DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION );
2441 application.SendNotification();
2442 application.Render(100u/*0.1 seconds*/);
2444 // Constraint should be fully applied
2445 DALI_TEST_EQUALS( actor.GetCurrentPosition(), targetPosition, TEST_LOCATION );
2447 // Check that nothing has changed after a couple of buffer swaps
2448 application.Render(0);
2449 DALI_TEST_EQUALS( actor.GetCurrentPosition(), targetPosition, TEST_LOCATION );
2450 application.Render(0);
2451 DALI_TEST_EQUALS( actor.GetCurrentPosition(), targetPosition, TEST_LOCATION );
2453 // Remove from the actor
2455 actor.RemoveConstraints(); // should go back to source position
2457 application.SendNotification();
2458 application.Render(static_cast<unsigned int>(removeSeconds*200.0f)/* 20% removal progress */);
2460 // Constraint shouldn't be fully removed yet
2461 Vector3 twentyPercentBack( targetPosition * 0.8f );
2462 DALI_TEST_EQUALS( actor.GetCurrentPosition(), twentyPercentBack, TEST_LOCATION );
2464 application.Render(static_cast<unsigned int>(removeSeconds*200.0f)/* 40% removal progress */);
2466 // Constraint shouldn't be fully removed yet
2467 Vector3 fourtyPercentBack( targetPosition * 0.6f );
2468 DALI_TEST_EQUALS( actor.GetCurrentPosition(), fourtyPercentBack, TEST_LOCATION );
2470 application.Render(static_cast<unsigned int>(removeSeconds*200.0f)/* 60% removal progress */);
2472 // Constraint shouldn't be fully removed yet
2473 Vector3 sixtyPercentBack( targetPosition * 0.4f );
2474 DALI_TEST_EQUALS( actor.GetCurrentPosition(), sixtyPercentBack, TEST_LOCATION );
2476 application.Render(static_cast<unsigned int>(removeSeconds*200.0f)/* 80% removal progress */);
2478 // Constraint shouldn't be fully removed yet
2479 Vector3 eightyPercentBack( targetPosition * 0.2f );
2480 DALI_TEST_EQUALS( actor.GetCurrentPosition(), eightyPercentBack, TEST_LOCATION );
2482 // Constraint should be fully removed
2483 application.Render(static_cast<unsigned int>(removeSeconds*200.0f)/* 100% removal progress */);
2484 DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION );
2486 // Constraint should still be fully applied
2487 application.Render(static_cast<unsigned int>(removeSeconds*200.0f)/* Still 100% removal progress */);
2488 DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION );
2490 // Check that nothing has changed after a couple of buffer swaps
2491 application.Render(0);
2492 DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION );
2493 application.Render(0);
2494 DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION );
2498 int UtcDaliConstraintGetRemoveAction(void)
2500 TestApplication application;
2502 Constraint constraint = Constraint::New<Vector4>( Actor::COLOR, TestConstraint() );
2503 DALI_TEST_EQUALS((unsigned int)constraint.GetRemoveAction(), (unsigned int)Constraint::Bake, TEST_LOCATION);
2505 constraint.SetRemoveAction(Constraint::Discard);
2506 DALI_TEST_EQUALS((unsigned int)constraint.GetRemoveAction(), (unsigned int)Constraint::Discard, TEST_LOCATION);
2508 constraint.SetRemoveAction(Constraint::Bake);
2509 DALI_TEST_EQUALS((unsigned int)constraint.GetRemoveAction(), (unsigned int)Constraint::Bake, TEST_LOCATION);
2514 * Test a constraint with non-zero apply-time and remove-time, where the constraint is removed during the apply-time
2516 int UtcDaliConstraintRemoveDuringApply(void)
2518 TestApplication application;
2520 Vector3 sourcePosition(0.0f, 0.0f, 0.0f);
2521 Vector3 targetPosition(100.0f, 100.0f, 100.0f);
2522 Vector3 halfwayPosition(targetPosition * 0.5f);
2526 Constraint constraint = Constraint::New<Vector3>( Actor::POSITION, TestPositionConstraint(targetPosition) );
2527 DALI_TEST_EQUALS((unsigned int)constraint.GetRemoveAction(), (unsigned int)Constraint::Bake, TEST_LOCATION);
2529 float applySeconds(4.0f);
2530 constraint.SetApplyTime(applySeconds);
2531 DALI_TEST_EQUALS(constraint.GetApplyTime(), TimePeriod(applySeconds), TEST_LOCATION);
2533 float removeSeconds(8.0f);
2534 constraint.SetRemoveTime(removeSeconds);
2535 DALI_TEST_EQUALS(constraint.GetRemoveTime(), TimePeriod(removeSeconds), TEST_LOCATION);
2537 // Apply to an actor
2539 Actor actor = Actor::New();
2540 Stage::GetCurrent().Add(actor);
2542 actor.ApplyConstraint( constraint );
2543 DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION );
2545 application.SendNotification();
2546 application.Render(static_cast<unsigned int>(applySeconds*250.0f)/* 25% progress */);
2548 // Constraint shouldn't be fully applied yet
2549 Vector3 twentyFivePercent( targetPosition * 0.25f );
2550 DALI_TEST_EQUALS( actor.GetCurrentPosition(), twentyFivePercent, TEST_LOCATION );
2552 application.Render(static_cast<unsigned int>(applySeconds*250.0f)/* 50% progress */);
2554 // Constraint shouldn't be fully applied yet
2555 Vector3 fiftyPercent( targetPosition * 0.5f );
2556 DALI_TEST_EQUALS( actor.GetCurrentPosition(), fiftyPercent, TEST_LOCATION );
2558 // Remove from the actor
2560 actor.RemoveConstraints(); // should go back to source position
2562 application.SendNotification();
2563 application.Render(static_cast<unsigned int>(removeSeconds*100.0f)/* 50% - 5% = 45% progress */);
2565 // Constraint shouldn't be fully removed yet
2566 Vector3 fourtyFivePercent( targetPosition * 0.45f );
2567 DALI_TEST_EQUALS( actor.GetCurrentPosition(), fourtyFivePercent, TEST_LOCATION );
2569 application.Render(static_cast<unsigned int>(removeSeconds*400.0f)/* 50% - 25% = 25% progress */);
2571 // Constraint shouldn't be fully removed yet
2572 DALI_TEST_EQUALS( actor.GetCurrentPosition(), twentyFivePercent, TEST_LOCATION );
2574 // Constraint should be fully removed
2575 application.Render(static_cast<unsigned int>(removeSeconds*500.0f)/* 0% progress */);
2576 DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION );
2578 // Constraint should still be fully applied
2579 application.Render(static_cast<unsigned int>(removeSeconds*200.0f)/* Still 0% progress */);
2580 DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION );
2582 // Check that nothing has changed after a couple of buffer swaps
2583 application.Render(0);
2584 DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION );
2585 application.Render(0);
2586 DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION );
2591 * Test a constraint with non-zero apply-time & zero (immediate) remove-time, where the constraint is removed during the apply-time
2593 int UtcDaliConstraintImmediateRemoveDuringApply(void)
2595 TestApplication application;
2597 Vector3 sourcePosition(0.0f, 0.0f, 0.0f);
2598 Vector3 targetPosition(100.0f, 100.0f, 100.0f);
2602 Constraint constraint = Constraint::New<Vector3>( Actor::POSITION, TestPositionConstraint(targetPosition) );
2603 DALI_TEST_EQUALS((unsigned int)constraint.GetRemoveAction(), (unsigned int)Constraint::Bake, TEST_LOCATION);
2605 float applySeconds(4.0f);
2606 constraint.SetApplyTime(applySeconds);
2607 DALI_TEST_EQUALS(constraint.GetApplyTime(), TimePeriod(applySeconds), TEST_LOCATION);
2608 DALI_TEST_EQUALS(constraint.GetRemoveTime(), TimePeriod(0.0f), TEST_LOCATION);
2610 // Apply to an actor
2612 Actor actor = Actor::New();
2613 Stage::GetCurrent().Add(actor);
2615 actor.ApplyConstraint( constraint );
2616 DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION );
2618 application.SendNotification();
2619 application.Render(static_cast<unsigned int>(applySeconds*250.0f)/* 25% progress */);
2621 // Constraint shouldn't be fully applied yet
2622 Vector3 twentyFivePercent( targetPosition * 0.25f );
2623 DALI_TEST_EQUALS( actor.GetCurrentPosition(), twentyFivePercent, TEST_LOCATION );
2625 application.Render(static_cast<unsigned int>(applySeconds*250.0f)/* 50% progress */);
2627 // Constraint shouldn't be fully applied yet
2628 Vector3 fiftyPercent( targetPosition * 0.5f );
2629 DALI_TEST_EQUALS( actor.GetCurrentPosition(), fiftyPercent, TEST_LOCATION );
2631 // Remove from the actor
2633 actor.RemoveConstraints(); // should go back to source position
2634 application.SendNotification();
2636 // Constraint should be fully removed
2637 application.Render(static_cast<unsigned int>(200.0f /*0.2 seconds*/));
2638 DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION );
2640 // Constraint should still be fully applied
2641 application.Render(static_cast<unsigned int>(200.0f /*0.2 seconds*/));
2642 DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION );
2644 // Check that nothing has changed after a couple of buffer swaps
2645 application.Render(0);
2646 DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION );
2647 application.Render(0);
2648 DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION );
2652 int UtcDaliConstraintActorSize(void)
2654 TestApplication application;
2656 // Build constraint, to make child 20% of parent size
2658 Constraint constraint = Constraint::New<Vector3>( Actor::SIZE,
2659 ParentSource( Actor::SIZE ),
2660 TestRelativeConstraintVector3(0.2f) );
2661 // Apply to a child actor
2663 Actor parent = Actor::New();
2664 Stage::GetCurrent().Add(parent);
2666 Actor child = Actor::New();
2669 child.ApplyConstraint( constraint );
2670 DALI_TEST_EQUALS( child.GetCurrentSize(), Vector3::ZERO, TEST_LOCATION );
2672 // Animate the parent between two sizes
2674 Vector3 targetParentSize(100.0f, 100.0f, 100.0f);
2676 float durationSeconds(10.0f);
2677 Animation animation = Animation::New(durationSeconds);
2678 animation.AnimateTo( Property(parent, Actor::SIZE), targetParentSize );
2681 application.SendNotification();
2683 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 25% progress */);
2684 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize*0.25f, TEST_LOCATION );
2685 DALI_TEST_EQUALS( child.GetCurrentSize(), targetParentSize*0.25f * 0.2f, TEST_LOCATION );
2687 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 50% progress */);
2688 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize*0.5f, TEST_LOCATION );
2689 DALI_TEST_EQUALS( child.GetCurrentSize(), targetParentSize*0.5f * 0.2f, TEST_LOCATION );
2691 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 75% progress */);
2692 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize*0.75f, TEST_LOCATION );
2693 DALI_TEST_EQUALS( child.GetCurrentSize(), targetParentSize*0.75f * 0.2f, TEST_LOCATION );
2695 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 100% progress */);
2696 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize, TEST_LOCATION );
2697 DALI_TEST_EQUALS( child.GetCurrentSize(), targetParentSize * 0.2f, TEST_LOCATION );
2699 // Check that nothing has changed after a couple of buffer swaps
2700 application.Render(0);
2701 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize, TEST_LOCATION );
2702 DALI_TEST_EQUALS( child.GetCurrentSize(), targetParentSize * 0.2f, TEST_LOCATION );
2703 application.Render(0);
2704 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize, TEST_LOCATION );
2705 DALI_TEST_EQUALS( child.GetCurrentSize(), targetParentSize * 0.2f, TEST_LOCATION );
2709 int UtcDaliConstraintActorSizeWidth(void)
2711 TestApplication application;
2713 // Build constraint, to make child 20% of parent width
2715 Constraint constraint = Constraint::New<float>( Actor::SIZE_WIDTH,
2716 ParentSource( Actor::SIZE_WIDTH ),
2717 TestRelativeConstraintFloat(0.2f) );
2718 // Apply to a child actor
2720 Actor parent = Actor::New();
2721 Stage::GetCurrent().Add(parent);
2723 Actor child = Actor::New();
2726 child.ApplyConstraint( constraint );
2727 DALI_TEST_EQUALS( child.GetCurrentSize(), Vector3::ZERO, TEST_LOCATION );
2729 // Animate the parent between two sizes
2731 Vector3 targetParentSize(80.0f, 90.0f, 100.0f);
2733 float durationSeconds(10.0f);
2734 Animation animation = Animation::New(durationSeconds);
2735 animation.AnimateTo( Property(parent, Actor::SIZE), targetParentSize );
2738 application.SendNotification();
2740 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 25% progress */);
2741 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize*0.25f, TEST_LOCATION );
2742 DALI_TEST_EQUALS( child.GetCurrentSize().width, targetParentSize.width*0.25f * 0.2f, TEST_LOCATION );
2743 DALI_TEST_EQUALS( child.GetCurrentSize().height, 0.0f, TEST_LOCATION );
2744 DALI_TEST_EQUALS( child.GetCurrentSize().depth, 0.0f, TEST_LOCATION );
2746 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 50% progress */);
2747 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize*0.5f, TEST_LOCATION );
2748 DALI_TEST_EQUALS( child.GetCurrentSize().width, targetParentSize.width*0.5f * 0.2f, TEST_LOCATION );
2749 DALI_TEST_EQUALS( child.GetCurrentSize().height, 0.0f, TEST_LOCATION );
2750 DALI_TEST_EQUALS( child.GetCurrentSize().depth, 0.0f, TEST_LOCATION );
2752 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 75% progress */);
2753 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize*0.75f, TEST_LOCATION );
2754 DALI_TEST_EQUALS( child.GetCurrentSize().width, targetParentSize.width*0.75f * 0.2f, TEST_LOCATION );
2755 DALI_TEST_EQUALS( child.GetCurrentSize().height, 0.0f, TEST_LOCATION );
2756 DALI_TEST_EQUALS( child.GetCurrentSize().depth, 0.0f, TEST_LOCATION );
2758 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 100% progress */);
2759 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize, TEST_LOCATION );
2760 DALI_TEST_EQUALS( child.GetCurrentSize().width, targetParentSize.width * 0.2f, TEST_LOCATION );
2761 DALI_TEST_EQUALS( child.GetCurrentSize().height, 0.0f, TEST_LOCATION );
2762 DALI_TEST_EQUALS( child.GetCurrentSize().depth, 0.0f, TEST_LOCATION );
2764 // Check that nothing has changed after a couple of buffer swaps
2765 application.Render(0);
2766 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize, TEST_LOCATION );
2767 DALI_TEST_EQUALS( child.GetCurrentSize().width, targetParentSize.width * 0.2f, TEST_LOCATION );
2768 DALI_TEST_EQUALS( child.GetCurrentSize().height, 0.0f, TEST_LOCATION );
2769 DALI_TEST_EQUALS( child.GetCurrentSize().depth, 0.0f, TEST_LOCATION );
2771 application.Render(0);
2772 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize, TEST_LOCATION );
2773 DALI_TEST_EQUALS( child.GetCurrentSize().width, targetParentSize.width * 0.2f, TEST_LOCATION );
2774 DALI_TEST_EQUALS( child.GetCurrentSize().height, 0.0f, TEST_LOCATION );
2775 DALI_TEST_EQUALS( child.GetCurrentSize().depth, 0.0f, TEST_LOCATION );
2779 int UtcDaliConstraintActorSizeHeight(void)
2781 TestApplication application;
2783 // Build constraint, to make child 20% of parent height
2785 Constraint constraint = Constraint::New<float>( Actor::SIZE_HEIGHT,
2786 ParentSource( Actor::SIZE_HEIGHT ),
2787 TestRelativeConstraintFloat(0.2f) );
2788 // Apply to a child actor
2790 Actor parent = Actor::New();
2791 Stage::GetCurrent().Add(parent);
2793 Actor child = Actor::New();
2796 child.ApplyConstraint( constraint );
2797 DALI_TEST_EQUALS( child.GetCurrentSize(), Vector3::ZERO, TEST_LOCATION );
2799 // Animate the parent between two sizes
2801 Vector3 targetParentSize(80.0f, 90.0f, 100.0f);
2803 float durationSeconds(10.0f);
2804 Animation animation = Animation::New(durationSeconds);
2805 animation.AnimateTo( Property(parent, Actor::SIZE), targetParentSize );
2808 application.SendNotification();
2810 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 25% progress */);
2811 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize*0.25f, TEST_LOCATION );
2812 DALI_TEST_EQUALS( child.GetCurrentSize().width, 0.0f, TEST_LOCATION );
2813 DALI_TEST_EQUALS( child.GetCurrentSize().height, targetParentSize.height*0.25f * 0.2f, TEST_LOCATION );
2814 DALI_TEST_EQUALS( child.GetCurrentSize().depth, 0.0f, TEST_LOCATION );
2816 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 50% progress */);
2817 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize*0.5f, TEST_LOCATION );
2818 DALI_TEST_EQUALS( child.GetCurrentSize().width, 0.0f, TEST_LOCATION );
2819 DALI_TEST_EQUALS( child.GetCurrentSize().height, targetParentSize.height*0.5f * 0.2f, TEST_LOCATION );
2820 DALI_TEST_EQUALS( child.GetCurrentSize().depth, 0.0f, TEST_LOCATION );
2822 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 75% progress */);
2823 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize*0.75f, TEST_LOCATION );
2824 DALI_TEST_EQUALS( child.GetCurrentSize().width, 0.0f, TEST_LOCATION );
2825 DALI_TEST_EQUALS( child.GetCurrentSize().height, targetParentSize.height*0.75f * 0.2f, TEST_LOCATION );
2826 DALI_TEST_EQUALS( child.GetCurrentSize().depth, 0.0f, TEST_LOCATION );
2828 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 100% progress */);
2829 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize, TEST_LOCATION );
2830 DALI_TEST_EQUALS( child.GetCurrentSize().width, 0.0f, TEST_LOCATION );
2831 DALI_TEST_EQUALS( child.GetCurrentSize().height, targetParentSize.height * 0.2f, TEST_LOCATION );
2832 DALI_TEST_EQUALS( child.GetCurrentSize().depth, 0.0f, TEST_LOCATION );
2834 // Check that nothing has changed after a couple of buffer swaps
2835 application.Render(0);
2836 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize, TEST_LOCATION );
2837 DALI_TEST_EQUALS( child.GetCurrentSize().width, 0.0f, TEST_LOCATION );
2838 DALI_TEST_EQUALS( child.GetCurrentSize().height, targetParentSize.height * 0.2f, TEST_LOCATION );
2839 DALI_TEST_EQUALS( child.GetCurrentSize().depth, 0.0f, TEST_LOCATION );
2841 application.Render(0);
2842 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize, TEST_LOCATION );
2843 DALI_TEST_EQUALS( child.GetCurrentSize().width, 0.0f, TEST_LOCATION );
2844 DALI_TEST_EQUALS( child.GetCurrentSize().height, targetParentSize.height * 0.2f, TEST_LOCATION );
2845 DALI_TEST_EQUALS( child.GetCurrentSize().depth, 0.0f, TEST_LOCATION );
2849 int UtcDaliConstraintActorSizeDepth(void)
2851 TestApplication application;
2853 // Build constraint, to make child 20% of parent height
2855 Constraint constraint = Constraint::New<float>( Actor::SIZE_DEPTH,
2856 ParentSource( Actor::SIZE_DEPTH ),
2857 TestRelativeConstraintFloat(0.2f) );
2858 // Apply to a child actor
2860 Actor parent = Actor::New();
2861 Stage::GetCurrent().Add(parent);
2863 Actor child = Actor::New();
2866 child.ApplyConstraint( constraint );
2867 DALI_TEST_EQUALS( child.GetCurrentSize(), Vector3::ZERO, TEST_LOCATION );
2869 // Animate the parent between two sizes
2871 Vector3 targetParentSize(80.0f, 90.0f, 100.0f);
2873 float durationSeconds(10.0f);
2874 Animation animation = Animation::New(durationSeconds);
2875 animation.AnimateTo( Property(parent, Actor::SIZE), targetParentSize );
2878 application.SendNotification();
2880 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 25% progress */);
2881 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize*0.25f, TEST_LOCATION );
2882 DALI_TEST_EQUALS( child.GetCurrentSize().width, 0.0f, TEST_LOCATION );
2883 DALI_TEST_EQUALS( child.GetCurrentSize().height, 0.0f, TEST_LOCATION );
2884 DALI_TEST_EQUALS( child.GetCurrentSize().depth, targetParentSize.depth*0.25f * 0.2f, TEST_LOCATION );
2886 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 50% progress */);
2887 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize*0.5f, TEST_LOCATION );
2888 DALI_TEST_EQUALS( child.GetCurrentSize().width, 0.0f, TEST_LOCATION );
2889 DALI_TEST_EQUALS( child.GetCurrentSize().height, 0.0f, TEST_LOCATION );
2890 DALI_TEST_EQUALS( child.GetCurrentSize().depth, targetParentSize.depth*0.5f * 0.2f, TEST_LOCATION );
2892 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 75% progress */);
2893 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize*0.75f, TEST_LOCATION );
2894 DALI_TEST_EQUALS( child.GetCurrentSize().width, 0.0f, TEST_LOCATION );
2895 DALI_TEST_EQUALS( child.GetCurrentSize().height, 0.0f, TEST_LOCATION );
2896 DALI_TEST_EQUALS( child.GetCurrentSize().depth, targetParentSize.depth*0.75f * 0.2f, TEST_LOCATION );
2898 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 100% progress */);
2899 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize, TEST_LOCATION );
2900 DALI_TEST_EQUALS( child.GetCurrentSize().width, 0.0f, TEST_LOCATION );
2901 DALI_TEST_EQUALS( child.GetCurrentSize().height, 0.0f, TEST_LOCATION );
2902 DALI_TEST_EQUALS( child.GetCurrentSize().depth, targetParentSize.depth * 0.2f, TEST_LOCATION );
2904 // Check that nothing has changed after a couple of buffer swaps
2905 application.Render(0);
2906 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize, TEST_LOCATION );
2907 DALI_TEST_EQUALS( child.GetCurrentSize().width, 0.0f, TEST_LOCATION );
2908 DALI_TEST_EQUALS( child.GetCurrentSize().height, 0.0f, TEST_LOCATION );
2909 DALI_TEST_EQUALS( child.GetCurrentSize().depth, targetParentSize.depth * 0.2f, TEST_LOCATION );
2911 application.Render(0);
2912 DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize, TEST_LOCATION );
2913 DALI_TEST_EQUALS( child.GetCurrentSize().width, 0.0f, TEST_LOCATION );
2914 DALI_TEST_EQUALS( child.GetCurrentSize().height, 0.0f, TEST_LOCATION );
2915 DALI_TEST_EQUALS( child.GetCurrentSize().depth, targetParentSize.depth * 0.2f, TEST_LOCATION );
2919 int UtcDaliConstraintInputWorldPosition(void)
2921 TestApplication application;
2923 Actor parent = Actor::New();
2924 Vector3 parentPosition( 10.0f, 10.0f, 10.0f );
2925 parent.SetPosition( parentPosition );
2926 parent.SetParentOrigin( ParentOrigin::CENTER );
2927 parent.SetAnchorPoint( AnchorPoint::CENTER );
2928 Stage::GetCurrent().Add( parent );
2930 Actor child = Actor::New();
2931 child.SetParentOrigin( ParentOrigin::CENTER );
2932 child.SetAnchorPoint( AnchorPoint::CENTER );
2933 Vector3 childPosition( 10.0f, 10.0f, 10.0f );
2934 child.SetPosition( childPosition );
2935 parent.Add( child );
2937 Actor trackingActor = Actor::New();
2938 trackingActor.SetParentOrigin( ParentOrigin::CENTER );
2939 trackingActor.SetAnchorPoint( AnchorPoint::CENTER );
2940 Stage::GetCurrent().Add( trackingActor );
2942 // The actors should not have a world position yet
2943 DALI_TEST_EQUALS( parent.GetCurrentWorldPosition(), Vector3::ZERO, TEST_LOCATION );
2944 DALI_TEST_EQUALS( child.GetCurrentWorldPosition(), Vector3::ZERO, TEST_LOCATION );
2945 DALI_TEST_EQUALS( trackingActor.GetCurrentWorldPosition(), Vector3::ZERO, TEST_LOCATION );
2947 application.SendNotification();
2948 application.Render(0);
2950 DALI_TEST_EQUALS( parent.GetCurrentPosition(), parentPosition, TEST_LOCATION );
2951 DALI_TEST_EQUALS( child.GetCurrentPosition(), childPosition, TEST_LOCATION );
2952 DALI_TEST_EQUALS( trackingActor.GetCurrentPosition(), Vector3::ZERO, TEST_LOCATION );
2954 DALI_TEST_EQUALS( parent.GetCurrentWorldPosition(), parentPosition, TEST_LOCATION );
2955 Vector3 previousPosition( parentPosition + childPosition );
2956 DALI_TEST_EQUALS( child.GetCurrentWorldPosition(), previousPosition, TEST_LOCATION );
2957 DALI_TEST_EQUALS( trackingActor.GetCurrentWorldPosition(), Vector3::ZERO, TEST_LOCATION );
2959 // Build constraint, to make actor track the world-position of another actor
2960 // Note that the world-position is always from the previous frame, so the tracking actor will lag behind
2962 Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
2963 Source( child, Actor::WORLD_POSITION ),
2964 EqualToConstraint() );
2966 trackingActor.ApplyConstraint( constraint );
2968 application.SendNotification();
2969 application.Render(0);
2971 DALI_TEST_EQUALS( trackingActor.GetCurrentPosition(), previousPosition, TEST_LOCATION );
2973 // Move the actors and try again
2974 Vector3 relativePosition( 5, 5, 5 );
2975 parent.MoveBy( relativePosition );
2977 application.SendNotification();
2978 application.Render(0);
2980 DALI_TEST_EQUALS( parent.GetCurrentPosition(), parentPosition + relativePosition, TEST_LOCATION );
2981 DALI_TEST_EQUALS( child.GetCurrentPosition(), childPosition, TEST_LOCATION );
2983 // The tracking actor lags behind
2984 DALI_TEST_EQUALS( trackingActor.GetCurrentPosition(), previousPosition, TEST_LOCATION );
2986 DALI_TEST_EQUALS( parent.GetCurrentWorldPosition(), parentPosition + relativePosition, TEST_LOCATION );
2987 previousPosition = Vector3( parentPosition + childPosition + relativePosition );
2988 DALI_TEST_EQUALS( child.GetCurrentWorldPosition(), previousPosition, TEST_LOCATION );
2990 // Allow the tracking actor to catch up
2991 application.SendNotification();
2992 application.Render(0);
2994 DALI_TEST_EQUALS( parent.GetCurrentPosition(), parentPosition + relativePosition, TEST_LOCATION );
2995 DALI_TEST_EQUALS( child.GetCurrentPosition(), childPosition, TEST_LOCATION );
2997 // The tracking actor catches up!
2998 DALI_TEST_EQUALS( trackingActor.GetCurrentPosition(), previousPosition, TEST_LOCATION );
2999 DALI_TEST_EQUALS( parent.GetCurrentWorldPosition(), parentPosition + relativePosition, TEST_LOCATION );
3000 DALI_TEST_EQUALS( child.GetCurrentWorldPosition(), previousPosition, TEST_LOCATION );
3004 int UtcDaliConstraintInputWorldRotation(void)
3006 TestApplication application;
3008 Actor parent = Actor::New();
3009 Radian rotationAngle( Degree(90.0f) );
3010 Quaternion rotation( rotationAngle, Vector3::YAXIS );
3011 parent.SetRotation( rotation );
3012 Stage::GetCurrent().Add( parent );
3014 Actor child = Actor::New();
3015 child.SetRotation( rotation );
3016 parent.Add( child );
3018 Actor trackingActor = Actor::New();
3019 Stage::GetCurrent().Add( trackingActor );
3021 // The actors should not have a world rotation yet
3022 DALI_TEST_EQUALS( parent.GetCurrentWorldRotation(), Quaternion(0.0f, Vector3::YAXIS), 0.001, TEST_LOCATION );
3023 DALI_TEST_EQUALS( child.GetCurrentWorldRotation(), Quaternion(0.0f, Vector3::YAXIS), 0.001, TEST_LOCATION );
3025 application.SendNotification();
3026 application.Render(0);
3028 DALI_TEST_EQUALS( parent.GetCurrentRotation(), rotation, 0.001, TEST_LOCATION );
3029 DALI_TEST_EQUALS( child.GetCurrentRotation(), rotation, 0.001, TEST_LOCATION );
3030 DALI_TEST_EQUALS( trackingActor.GetCurrentRotation(), Quaternion(0.0f, Vector3::YAXIS), 0.001, TEST_LOCATION );
3032 DALI_TEST_EQUALS( parent.GetCurrentWorldRotation(), Quaternion( rotationAngle, Vector3::YAXIS ), 0.001, TEST_LOCATION );
3033 Quaternion previousRotation( rotationAngle * 2.0f, Vector3::YAXIS );
3034 DALI_TEST_EQUALS( child.GetCurrentWorldRotation(), previousRotation, 0.001, TEST_LOCATION );
3036 // Build constraint, to make actor track the world-rotation of another actor
3037 // Note that the world-rotation is always from the previous frame, so the tracking actor will lag behind
3039 Constraint constraint = Constraint::New<Quaternion>( Actor::ROTATION,
3040 Source( child, Actor::WORLD_ROTATION ),
3041 EqualToQuaternion() );
3043 trackingActor.ApplyConstraint( constraint );
3045 application.SendNotification();
3046 application.Render(0);
3048 DALI_TEST_EQUALS( trackingActor.GetCurrentRotation(), previousRotation, 0.001, TEST_LOCATION );
3050 // Rotate the actors and try again
3051 parent.RotateBy( rotation );
3053 application.SendNotification();
3054 application.Render(0);
3056 DALI_TEST_EQUALS( parent.GetCurrentRotation(), rotation * rotation, 0.001, TEST_LOCATION );
3057 DALI_TEST_EQUALS( child.GetCurrentRotation(), rotation, 0.001, TEST_LOCATION );
3059 // The tracking actor lags behind
3060 DALI_TEST_EQUALS( trackingActor.GetCurrentRotation(), previousRotation, 0.001, TEST_LOCATION );
3062 DALI_TEST_EQUALS( parent.GetCurrentWorldRotation(), Quaternion( rotationAngle * 2.0f, Vector3::YAXIS ), 0.001, TEST_LOCATION );
3063 previousRotation = Quaternion( rotationAngle * 3.0f, Vector3::YAXIS );
3064 DALI_TEST_EQUALS( child.GetCurrentWorldRotation(), previousRotation, 0.001, TEST_LOCATION );
3066 // Allow the tracking actor to catch up
3067 application.SendNotification();
3068 application.Render(0);
3070 DALI_TEST_EQUALS( parent.GetCurrentRotation(), rotation * rotation, 0.001, TEST_LOCATION );
3071 DALI_TEST_EQUALS( child.GetCurrentRotation(), rotation, 0.001, TEST_LOCATION );
3073 // The tracking actor catches up!
3074 DALI_TEST_EQUALS( trackingActor.GetCurrentRotation(), previousRotation, 0.001, TEST_LOCATION );
3075 DALI_TEST_EQUALS( parent.GetCurrentWorldRotation(), Quaternion( rotationAngle * 2.0f, Vector3::YAXIS ), 0.001, TEST_LOCATION );
3076 DALI_TEST_EQUALS( child.GetCurrentWorldRotation(), previousRotation, 0.001, TEST_LOCATION );
3080 int UtcDaliConstraintInputWorldScale(void)
3082 TestApplication application;
3084 Actor parent = Actor::New();
3085 Vector3 parentScale( 2.0f, 2.0f, 2.0f );
3086 parent.SetScale( parentScale );
3087 Stage::GetCurrent().Add( parent );
3089 Actor child = Actor::New();
3090 Vector3 childScale( 1.0f, 2.0f, 3.0f );
3091 child.SetScale( childScale );
3092 parent.Add( child );
3094 Actor trackingActor = Actor::New();
3095 Stage::GetCurrent().Add( trackingActor );
3097 // The actors should not have a world scale yet
3098 DALI_TEST_EQUALS( parent.GetCurrentWorldScale(), Vector3::ONE, TEST_LOCATION );
3099 DALI_TEST_EQUALS( child.GetCurrentWorldScale(), Vector3::ONE, TEST_LOCATION );
3100 DALI_TEST_EQUALS( trackingActor.GetCurrentWorldScale(), Vector3::ONE, TEST_LOCATION );
3102 application.SendNotification();
3103 application.Render(0);
3105 DALI_TEST_EQUALS( parent.GetCurrentScale(), parentScale, TEST_LOCATION );
3106 DALI_TEST_EQUALS( child.GetCurrentScale(), childScale, TEST_LOCATION );
3107 DALI_TEST_EQUALS( trackingActor.GetCurrentScale(), Vector3::ONE, TEST_LOCATION );
3109 DALI_TEST_EQUALS( parent.GetCurrentWorldScale(), parentScale, TEST_LOCATION );
3110 Vector3 previousScale( parentScale * childScale );
3111 DALI_TEST_EQUALS( child.GetCurrentWorldScale(), previousScale, TEST_LOCATION );
3112 DALI_TEST_EQUALS( trackingActor.GetCurrentScale(), Vector3::ONE, TEST_LOCATION );
3114 // Build constraint, to make actor track the world-scale of another actor
3115 // Note that the world-scale is always from the previous frame, so the tracking actor will lag behind
3117 Constraint constraint = Constraint::New<Vector3>( Actor::SCALE,
3118 Source( child, Actor::WORLD_SCALE ),
3119 EqualToConstraint() );
3121 trackingActor.ApplyConstraint( constraint );
3123 application.SendNotification();
3124 application.Render(0);
3126 DALI_TEST_EQUALS( trackingActor.GetCurrentScale(), previousScale, TEST_LOCATION );
3128 // Scale the actors and try again
3129 Vector3 relativeScale( 3, 3, 3 );
3130 parent.ScaleBy( relativeScale );
3132 application.SendNotification();
3133 application.Render(0);
3135 DALI_TEST_EQUALS( parent.GetCurrentScale(), parentScale * relativeScale, TEST_LOCATION );
3136 DALI_TEST_EQUALS( child.GetCurrentScale(), childScale, TEST_LOCATION );
3138 // The tracking actor lags behind
3139 DALI_TEST_EQUALS( trackingActor.GetCurrentScale(), previousScale, TEST_LOCATION );
3141 DALI_TEST_EQUALS( parent.GetCurrentWorldScale(), parentScale * relativeScale, TEST_LOCATION );
3142 previousScale = Vector3( parentScale * childScale * relativeScale );
3143 DALI_TEST_EQUALS( child.GetCurrentWorldScale(), previousScale, TEST_LOCATION );
3145 // Allow the tracking actor to catch up
3146 application.SendNotification();
3147 application.Render(0);
3149 DALI_TEST_EQUALS( parent.GetCurrentScale(), parentScale * relativeScale, TEST_LOCATION );
3150 DALI_TEST_EQUALS( child.GetCurrentScale(), childScale, TEST_LOCATION );
3152 // The tracking actor catches up!
3153 DALI_TEST_EQUALS( trackingActor.GetCurrentScale(), previousScale, TEST_LOCATION );
3154 DALI_TEST_EQUALS( parent.GetCurrentWorldScale(), parentScale * relativeScale, TEST_LOCATION );
3155 DALI_TEST_EQUALS( child.GetCurrentWorldScale(), previousScale, TEST_LOCATION );
3159 int UtcDaliConstraintInputWorldColor(void)
3161 TestApplication application;
3163 Actor parent = Actor::New();
3164 Vector4 parentColor( 1.0f, 0.5f, 0.0f, 1.0f );
3165 parent.SetColor( parentColor );
3166 Stage::GetCurrent().Add( parent );
3168 Actor child = Actor::New();
3169 Vector4 childColor( 0.5f, 0.5f, 0.5f, 1.0f );
3170 child.SetColor( childColor );
3171 parent.Add( child );
3173 Actor trackingActor = Actor::New();
3174 Stage::GetCurrent().Add( trackingActor );
3176 // The actors should not have a world color yet
3177 DALI_TEST_EQUALS( parent.GetCurrentWorldColor(), Color::WHITE, TEST_LOCATION );
3178 DALI_TEST_EQUALS( child.GetCurrentWorldColor(), Color::WHITE, TEST_LOCATION );
3180 application.SendNotification();
3181 application.Render(0);
3183 DALI_TEST_EQUALS( parent.GetCurrentColor(), parentColor, TEST_LOCATION );
3184 DALI_TEST_EQUALS( child.GetCurrentColor(), childColor, TEST_LOCATION );
3185 DALI_TEST_EQUALS( trackingActor.GetCurrentColor(), Color::WHITE, TEST_LOCATION );
3187 DALI_TEST_EQUALS( parent.GetCurrentWorldColor(), parentColor, TEST_LOCATION );
3188 Vector4 previousColor( childColor );
3189 previousColor.a *= parentColor.a;
3190 DALI_TEST_EQUALS( child.GetCurrentWorldColor(), previousColor, TEST_LOCATION );
3192 // Build constraint, to make actor track the world-color of another actor
3193 // Note that the world-color is always from the previous frame, so the tracking actor will lag behind
3195 Constraint constraint = Constraint::New<Vector4>( Actor::COLOR,
3196 Source( child, Actor::WORLD_COLOR ),
3199 trackingActor.ApplyConstraint( constraint );
3201 application.SendNotification();
3202 application.Render(0);
3204 DALI_TEST_EQUALS( trackingActor.GetCurrentColor(), previousColor, TEST_LOCATION );
3206 // Set the color and try again
3207 Vector4 newChildColor( 0.75f, 0.75f, 0.75f, 1.0f );
3208 child.SetColor( newChildColor );
3210 application.SendNotification();
3211 application.Render(0);
3213 DALI_TEST_EQUALS( parent.GetCurrentColor(), parentColor, TEST_LOCATION );
3214 DALI_TEST_EQUALS( child.GetCurrentColor(), newChildColor, TEST_LOCATION );
3216 // The tracking actor lags behind
3217 DALI_TEST_EQUALS( trackingActor.GetCurrentColor(), previousColor, TEST_LOCATION );
3219 DALI_TEST_EQUALS( parent.GetCurrentWorldColor(), parentColor, TEST_LOCATION );
3220 previousColor = Vector3( newChildColor );
3221 DALI_TEST_EQUALS( child.GetCurrentWorldColor(), previousColor, TEST_LOCATION );
3223 // Allow the tracking actor to catch up
3224 application.SendNotification();
3225 application.Render(0);
3227 DALI_TEST_EQUALS( parent.GetCurrentColor(), parentColor, TEST_LOCATION );
3228 DALI_TEST_EQUALS( child.GetCurrentColor(), newChildColor, TEST_LOCATION );
3230 // The tracking actor catches up!
3231 DALI_TEST_EQUALS( trackingActor.GetCurrentColor(), previousColor, TEST_LOCATION );
3232 DALI_TEST_EQUALS( parent.GetCurrentWorldColor(), parentColor, TEST_LOCATION );
3233 DALI_TEST_EQUALS( child.GetCurrentWorldColor(), previousColor, TEST_LOCATION );
3237 int UtcDaliConstraintInvalidInputProperty(void)
3239 TestApplication application;
3240 Actor actor = Actor::New();
3241 Constraint constraint = Constraint::New<Vector3>( Actor::POSITION, LocalSource( PROPERTY_REGISTRATION_START_INDEX ), MultiplyConstraint() );
3243 Stage::GetCurrent().Add( actor );
3245 // Cannot use type registered properties as input to constraints
3248 actor.ApplyConstraint( constraint );
3249 tet_result( TET_FAIL );
3251 catch ( DaliException& e )
3253 DALI_TEST_ASSERT( e, "mTargetProxy->IsPropertyAConstraintInput( source.propertyIndex )", TEST_LOCATION );
3258 int UtcDaliBuiltinConstraintParentSize(void)
3260 TestApplication application;
3262 Actor parent = Actor::New();
3263 Vector3 parentSize(9,9,9);
3264 parent.SetSize( parentSize );
3265 Stage::GetCurrent().Add( parent );
3267 Actor actor = Actor::New();
3268 parent.Add( actor );
3270 Vector3 startValue( Vector3::ZERO );
3272 application.SendNotification();
3273 application.Render(0);
3274 DALI_TEST_CHECK( actor.GetCurrentSize() == startValue );
3278 Constraint constraint = Constraint::New<Vector3>( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() );
3279 actor.ApplyConstraint( constraint );
3281 application.SendNotification();
3282 application.Render(0);
3284 // Constraint should be fully applied
3285 DALI_TEST_EQUALS( actor.GetCurrentSize(), parentSize, TEST_LOCATION );
3287 // This should be ignored
3288 actor.SetSize( startValue );
3290 // Check that nothing has changed after a couple of buffer swaps
3291 application.SendNotification();
3292 application.Render(0);
3293 DALI_TEST_EQUALS( actor.GetCurrentSize(), parentSize, TEST_LOCATION );
3294 application.Render(0);
3295 DALI_TEST_EQUALS( actor.GetCurrentSize(), parentSize, TEST_LOCATION );
3297 // Remove the constraint, then set new value
3298 actor.RemoveConstraints();
3299 actor.SetSize( startValue );
3301 // Constraint should have been removed
3302 application.SendNotification();
3303 application.Render(0);
3304 DALI_TEST_EQUALS( actor.GetCurrentSize(), startValue, TEST_LOCATION );
3305 application.Render(0);
3306 DALI_TEST_EQUALS( actor.GetCurrentSize(), startValue, TEST_LOCATION );
3310 int UtcDaliBuiltinConstraintParentSizeRelative(void)
3312 TestApplication application;
3314 Actor parent = Actor::New();
3315 Vector3 parentSize(9,9,9);
3316 parent.SetSize( parentSize );
3317 Stage::GetCurrent().Add( parent );
3319 Actor actor = Actor::New();
3320 parent.Add( actor );
3322 Vector3 startValue( Vector3::ZERO );
3323 Vector3 scale(2,3,4);
3324 Vector3 endValue( parentSize * scale );
3326 application.SendNotification();
3327 application.Render(0);
3328 DALI_TEST_CHECK( actor.GetCurrentSize() == startValue );
3332 Constraint constraint = Constraint::New<Vector3>( Actor::SIZE, ParentSource( Actor::SIZE ), RelativeToConstraint( scale ) );
3333 actor.ApplyConstraint( constraint );
3335 application.SendNotification();
3336 application.Render(0);
3338 // Constraint should be fully applied
3339 DALI_TEST_EQUALS( actor.GetCurrentSize(), endValue, TEST_LOCATION );
3341 // This should be ignored
3342 actor.SetSize( startValue );
3344 // Check that nothing has changed after a couple of buffer swaps
3345 application.SendNotification();
3346 application.Render(0);
3347 DALI_TEST_EQUALS( actor.GetCurrentSize(), endValue, TEST_LOCATION );
3348 application.Render(0);
3349 DALI_TEST_EQUALS( actor.GetCurrentSize(), endValue, TEST_LOCATION );
3351 // Remove the constraint, then set new value
3352 actor.RemoveConstraints();
3353 actor.SetSize( startValue );
3355 // Constraint should have been removed
3356 application.SendNotification();
3357 application.Render(0);
3358 DALI_TEST_EQUALS( actor.GetCurrentSize(), startValue, TEST_LOCATION );
3359 application.Render(0);
3360 DALI_TEST_EQUALS( actor.GetCurrentSize(), startValue, TEST_LOCATION );
3364 int UtcDaliBuiltinConstraintScaleToFitConstraint(void)
3366 TestApplication application;
3368 Actor parent = Actor::New();
3369 Vector3 startParentSize( 10, 10, 10 );
3370 parent.SetSize( startParentSize );
3371 Stage::GetCurrent().Add( parent );
3373 Actor actor = Actor::New();
3374 Vector3 startChildSize( 5, 5, 5 );
3375 actor.SetSize( startChildSize );
3376 parent.Add( actor );
3378 Vector3 endChildSize( 8, 8, 8 );
3379 Vector3 endParentSize( 4, 4, 4 );
3380 Vector3 startChildScale( 2, 2, 2 ); // startParentSize / startChildSize
3381 Vector3 intermediateChildScale( 1.25, 1.25, 1.25 ); // startParentSize / endChildSize
3382 Vector3 endChildScale( 0.5, 0.5, 0.5 ); // endParentSize / endChildSize
3384 application.SendNotification();
3385 application.Render(0);
3386 DALI_TEST_CHECK( actor.GetCurrentSize() == startChildSize );
3390 Constraint constraint = Constraint::New<Vector3>( Actor::SCALE,
3391 LocalSource( Actor::SIZE ),
3392 ParentSource( Actor::SIZE ),
3393 ScaleToFitConstraint() );
3394 actor.ApplyConstraint( constraint );
3396 application.SendNotification();
3397 application.Render(0);
3399 // Constraint should be fully applied, but parent size is larger than child
3400 DALI_TEST_EQUALS( actor.GetCurrentSize(), startChildSize, TEST_LOCATION );
3401 DALI_TEST_EQUALS( actor.GetCurrentScale(), startChildScale, TEST_LOCATION );
3403 // This should be allowed (still less than parent size)
3404 actor.SetSize( endChildSize );
3406 application.SendNotification();
3407 application.Render(0);
3408 DALI_TEST_EQUALS( actor.GetCurrentSize(), endChildSize, TEST_LOCATION );
3409 DALI_TEST_EQUALS( actor.GetCurrentScale(), intermediateChildScale, TEST_LOCATION );
3411 // Reduce the parent size
3412 parent.SetSize( endParentSize );
3414 application.SendNotification();
3415 application.Render(0);
3417 // Constraint should be fully applied
3418 DALI_TEST_EQUALS( actor.GetCurrentSize(), endChildSize, TEST_LOCATION );
3419 DALI_TEST_EQUALS( actor.GetCurrentScale(), endChildScale, TEST_LOCATION );
3420 application.Render(0);
3421 DALI_TEST_EQUALS( actor.GetCurrentSize(), endChildSize, TEST_LOCATION );
3422 DALI_TEST_EQUALS( actor.GetCurrentScale(), endChildScale, TEST_LOCATION );
3426 int UtcDaliBuiltinConstraintScaleToFitKeepAspectRatio(void)
3428 TestApplication application;
3430 Actor parent = Actor::New();
3431 Vector3 parentSize1( 10, 10, 10 );
3432 parent.SetSize( parentSize1 );
3433 Stage::GetCurrent().Add( parent );
3435 Actor actor = Actor::New();
3436 Vector3 childSize( 4, 5, 5 );
3437 actor.SetSize( childSize );
3438 parent.Add( actor );
3440 application.SendNotification();
3441 application.Render(0);
3442 Vector3 childScale1( 1.0f, 1.0f, 1.0f );
3443 DALI_TEST_EQUALS( actor.GetCurrentScale(), childScale1, TEST_LOCATION );
3447 Constraint constraint = Constraint::New<Vector3>( Actor::SCALE,
3448 LocalSource( Actor::SIZE ),
3449 ParentSource( Actor::SIZE ),
3450 ScaleToFitKeepAspectRatioConstraint() );
3451 actor.ApplyConstraint( constraint );
3453 application.SendNotification();
3454 application.Render(0);
3456 // Constraint should be fully applied, but parent size is larger than child
3457 Vector3 childScale2( 2.0f, 2.0f, 2.0f );
3458 DALI_TEST_EQUALS( actor.GetCurrentScale(), childScale2, TEST_LOCATION );
3460 // change parent size
3461 Vector3 parentSize2( 40, 50, 50 );
3462 parent.SetSize( parentSize2 );
3464 application.SendNotification();
3465 application.Render(0);
3467 // Constraint should be fully applied, but parent size is larger than child
3468 Vector3 childScale3( 10.0f, 10.0f, 10.0f );
3469 DALI_TEST_EQUALS( actor.GetCurrentScale(), childScale3, TEST_LOCATION );
3473 int UtcDaliBuiltinConstraintScaleToFillKeepAspectRatio(void)
3475 TestApplication application;
3477 Actor parent = Actor::New();
3478 Vector3 parentSize1( 10, 10, 10 );
3479 parent.SetSize( parentSize1 );
3480 Stage::GetCurrent().Add( parent );
3482 Actor actor = Actor::New();
3483 Vector3 childSize( 4, 5, 5 );
3484 actor.SetSize( childSize );
3485 parent.Add( actor );
3487 application.SendNotification();
3488 application.Render(0);
3489 Vector3 childScale1( 1.0f, 1.0f, 1.0f );
3490 DALI_TEST_EQUALS( actor.GetCurrentScale(), childScale1, TEST_LOCATION );
3494 Constraint constraint = Constraint::New<Vector3>( Actor::SCALE,
3495 LocalSource( Actor::SIZE ),
3496 ParentSource( Actor::SIZE ),
3497 ScaleToFillKeepAspectRatioConstraint() );
3498 actor.ApplyConstraint( constraint );
3500 application.SendNotification();
3501 application.Render(0);
3503 // Constraint should be fully applied, but parent size is larger than child
3504 float val = 10.f / 4.f;
3505 Vector3 childScale2( val, val, val );
3506 DALI_TEST_EQUALS( actor.GetCurrentScale(), childScale2, TEST_LOCATION );
3508 // change parent size
3509 Vector3 parentSize2( 40, 50, 50 );
3510 parent.SetSize( parentSize2 );
3512 application.SendNotification();
3513 application.Render(0);
3515 // Constraint should be fully applied, but parent size is larger than child
3516 Vector3 childScale3( 10.0f, 10.0f, 10.0f );
3517 DALI_TEST_EQUALS( actor.GetCurrentScale(), childScale3, TEST_LOCATION );
3521 int UtcDaliBuiltinConstraintScaleToFillXYKeepAspectRatio(void)
3523 TestApplication application;
3525 Actor parent = Actor::New();
3526 Vector3 parentSize1( 10, 10, 10 );
3527 parent.SetSize( parentSize1 );
3528 Stage::GetCurrent().Add( parent );
3530 Actor actor = Actor::New();
3531 Vector3 childSize( 4, 5, 5 );
3532 actor.SetSize( childSize );
3533 parent.Add( actor );
3535 application.SendNotification();
3536 application.Render(0);
3537 Vector3 childScale1( 1.0f, 1.0f, 1.0f );
3538 DALI_TEST_EQUALS( actor.GetCurrentScale(), childScale1, TEST_LOCATION );
3542 Constraint constraint = Constraint::New<Vector3>( Actor::SCALE,
3543 LocalSource( Actor::SIZE ),
3544 ParentSource( Actor::SIZE ),
3545 ScaleToFillXYKeepAspectRatioConstraint() );
3546 actor.ApplyConstraint( constraint );
3548 application.SendNotification();
3549 application.Render(0);
3551 // Constraint should be fully applied, but parent size is larger than child
3552 float val = 10.f / 4.f;
3553 Vector3 childScale2( val, val, val );
3554 DALI_TEST_EQUALS( actor.GetCurrentScale(), childScale2, TEST_LOCATION );
3556 // change parent size
3557 Vector3 parentSize2( 40, 50, 50 );
3558 parent.SetSize( parentSize2 );
3560 application.SendNotification();
3561 application.Render(0);
3563 // Constraint should be fully applied, but parent size is larger than child
3564 Vector3 childScale3( 10.0f, 10.0f, 10.0f );
3565 DALI_TEST_EQUALS( actor.GetCurrentScale(), childScale3, TEST_LOCATION );
3569 int UtcDaliBuiltinConstraintShrinkInsideKeepAspectRatioConstraint(void)
3571 TestApplication application;
3573 Actor parent = Actor::New();
3574 Vector3 parentSize1( 10, 10, 10 );
3575 parent.SetSize( parentSize1 );
3576 Stage::GetCurrent().Add( parent );
3578 Actor actor = Actor::New();
3579 Vector3 childSize( 4, 5, 5 );
3580 actor.SetSize( childSize );
3581 parent.Add( actor );
3583 application.SendNotification();
3584 application.Render(0);
3585 Vector3 childScale1( 1.0f, 1.0f, 1.0f );
3586 DALI_TEST_EQUALS( actor.GetCurrentScale(), childScale1, TEST_LOCATION );
3590 Constraint constraint = Constraint::New<Vector3>( Actor::SCALE,
3591 LocalSource( Actor::SIZE ),
3592 ParentSource( Actor::SIZE ),
3593 ShrinkInsideKeepAspectRatioConstraint() );
3594 actor.ApplyConstraint( constraint );
3596 application.SendNotification();
3597 application.Render(0);
3599 // Constraint should be fully applied, but parent size is larger than child
3600 Vector3 childScale2( 1.0f, 1.0f, 1.0f );
3601 DALI_TEST_EQUALS( actor.GetCurrentScale(), childScale2, TEST_LOCATION );
3603 // change parent size
3604 Vector3 parentSize2( 40, 50, 50 );
3605 parent.SetSize( parentSize2 );
3607 application.SendNotification();
3608 application.Render(0);
3610 // Constraint should be fully applied, but parent size is larger than child
3611 Vector3 childScale3( 1.0f, 1.0f, 1.0f );
3612 DALI_TEST_EQUALS( actor.GetCurrentScale(), childScale3, TEST_LOCATION );
3616 int UtcDaliBuiltinConstraintMultiplyConstraint(void)
3618 TestApplication application;
3620 Actor actor1 = Actor::New();
3621 Vector3 startPosition( 10, 10, 10 );
3622 actor1.SetPosition( startPosition );
3623 Stage::GetCurrent().Add( actor1 );
3625 Actor actor2 = Actor::New();
3626 Vector3 startSize( 100, 100, 100 );
3627 actor2.SetSize( startSize );
3628 Stage::GetCurrent().Add( actor2 );
3630 application.SendNotification();
3631 application.Render(0);
3632 DALI_TEST_CHECK( actor1.GetCurrentPosition() == startPosition );
3633 DALI_TEST_CHECK( actor2.GetCurrentSize() == startSize );
3635 // Apply constraint - multiply actor1 size by actor2 position
3637 Constraint constraint = Constraint::New<Vector3>( Actor::SIZE,
3638 Source( actor1, Actor::POSITION ),
3639 MultiplyConstraint() );
3640 constraint.SetRemoveAction( Constraint::Discard );
3641 actor2.ApplyConstraint( constraint );
3643 application.SendNotification();
3644 application.Render(0);
3646 // Constraint should be fully applied
3647 Vector3 size( startSize * startPosition );
3648 DALI_TEST_EQUALS( actor2.GetCurrentSize(), size, TEST_LOCATION );
3650 // Change the multiply input
3651 Vector3 endPosition( 2, 2, 2 );
3652 actor1.SetPosition( endPosition );
3654 application.SendNotification();
3655 application.Render(0);
3657 // Constraint should be fully applied
3658 size = Vector3( startSize * endPosition );
3659 DALI_TEST_EQUALS( actor2.GetCurrentSize(), size, TEST_LOCATION );
3660 application.Render(0);
3661 DALI_TEST_EQUALS( actor2.GetCurrentSize(), size, TEST_LOCATION );
3665 int UtcDaliBuiltinConstraintDivideConstraint(void)
3667 TestApplication application;
3669 Actor actor1 = Actor::New();
3670 Vector3 startPosition( 10, 10, 10 );
3671 actor1.SetPosition( startPosition );
3672 Stage::GetCurrent().Add( actor1 );
3674 Actor actor2 = Actor::New();
3675 Vector3 startSize( 100, 100, 100 );
3676 actor2.SetSize( startSize );
3677 Stage::GetCurrent().Add( actor2 );
3679 application.SendNotification();
3680 application.Render(0);
3681 DALI_TEST_CHECK( actor1.GetCurrentPosition() == startPosition );
3682 DALI_TEST_CHECK( actor2.GetCurrentSize() == startSize );
3684 // Apply constraint - divide actor1 size by actor2 position
3686 Constraint constraint = Constraint::New<Vector3>( Actor::SIZE,
3687 Source( actor1, Actor::POSITION ),
3688 DivideConstraint() );
3689 constraint.SetRemoveAction( Constraint::Discard );
3690 actor2.ApplyConstraint( constraint );
3692 application.SendNotification();
3693 application.Render(0);
3695 // Constraint should be fully applied
3696 Vector3 size( 10, 10, 10 ); // startSize / startPosition
3697 DALI_TEST_EQUALS( actor2.GetCurrentSize(), size, TEST_LOCATION );
3699 // Change the divide input
3700 Vector3 endPosition( 2, 2, 2 );
3701 actor1.SetPosition( endPosition );
3703 application.SendNotification();
3704 application.Render(0);
3706 // Constraint should be fully applied
3707 size = Vector3( 50, 50, 50 ); // startSize / endPosition
3708 DALI_TEST_EQUALS( actor2.GetCurrentSize(), size, TEST_LOCATION );
3709 application.Render(0);
3710 DALI_TEST_EQUALS( actor2.GetCurrentSize(), size, TEST_LOCATION );
3714 int UtcDaliBuiltinConstraintEqualToConstraint(void)
3716 TestApplication application;
3718 Actor actor1 = Actor::New();
3719 Vector3 startPosition( 10, 10, 10 );
3720 actor1.SetPosition( startPosition );
3721 Stage::GetCurrent().Add( actor1 );
3723 Actor actor2 = Actor::New();
3724 Vector3 startSize( 100, 100, 100 );
3725 actor2.SetSize( startSize );
3726 Stage::GetCurrent().Add( actor2 );
3728 application.SendNotification();
3729 application.Render(0);
3730 DALI_TEST_CHECK( actor1.GetCurrentPosition() == startPosition );
3731 DALI_TEST_CHECK( actor2.GetCurrentSize() == startSize );
3733 // Apply constraint - actor1 size == actor2 position
3735 Constraint constraint = Constraint::New<Vector3>( Actor::SIZE,
3736 Source( actor1, Actor::POSITION ),
3737 EqualToConstraint() );
3738 constraint.SetRemoveAction( Constraint::Discard );
3739 actor2.ApplyConstraint( constraint );
3741 application.SendNotification();
3742 application.Render(0);
3744 // Constraint should be fully applied
3745 DALI_TEST_EQUALS( actor2.GetCurrentSize(), startPosition, TEST_LOCATION );
3748 Vector3 endPosition( 2, 2, 2 );
3749 actor1.SetPosition( endPosition );
3751 application.SendNotification();
3752 application.Render(0);
3754 // Constraint should be fully applied
3755 DALI_TEST_EQUALS( actor2.GetCurrentSize(), endPosition, TEST_LOCATION );
3756 application.Render(0);
3757 DALI_TEST_EQUALS( actor2.GetCurrentSize(), endPosition, TEST_LOCATION );
3760 // Check float variant of constraint
3762 float startOpacity(1.0f);
3763 float endOpacity(0.2f);
3764 actor1.SetOpacity( startOpacity );
3765 actor2.SetOpacity( startOpacity );
3767 application.SendNotification();
3768 application.Render(0);
3769 DALI_TEST_EQUALS( actor1.GetCurrentOpacity(), startOpacity, TEST_LOCATION );
3770 DALI_TEST_EQUALS( actor2.GetCurrentOpacity(), startOpacity, TEST_LOCATION );
3772 Constraint constraint2 = Constraint::New<float>( Actor::COLOR_ALPHA,
3773 Source( actor1, Actor::COLOR_ALPHA ),
3774 EqualToConstraint() );
3775 constraint2.SetRemoveAction( Constraint::Discard );
3776 actor2.ApplyConstraint( constraint2 );
3778 actor1.SetOpacity(endOpacity);
3780 application.SendNotification();
3781 application.Render(0);
3783 DALI_TEST_EQUALS( actor2.GetCurrentOpacity(), endOpacity, 0.000001f, TEST_LOCATION );
3786 // Check Vector4 variant of constraint
3788 actor1.SetColor( Color::GREEN );
3789 actor2.SetColor( Color::RED );
3791 application.SendNotification();
3792 application.Render(0);
3793 DALI_TEST_CHECK( actor1.GetCurrentColor() == Color::GREEN );
3794 DALI_TEST_CHECK( actor2.GetCurrentColor() == Color::RED );
3796 Constraint constraint3 = Constraint::New<Vector4>( Actor::COLOR,
3797 Source( actor1, Actor::COLOR ),
3798 EqualToConstraint() );
3799 constraint3.SetRemoveAction( Constraint::Discard );
3800 actor2.ApplyConstraint( constraint3 );
3801 application.SendNotification();
3802 application.Render(0);
3803 DALI_TEST_CHECK( actor2.GetCurrentColor() == Color::GREEN );
3806 // Check Quaternion variant of constraint
3808 Quaternion q1 = Quaternion( Math::PI_2, Vector3::XAXIS );
3809 Quaternion q2 = Quaternion( Math::PI_4, Vector3::YAXIS );
3810 actor1.SetRotation( q1 );
3811 actor2.SetRotation( q2 );
3813 application.SendNotification();
3814 application.Render(0);
3815 DALI_TEST_EQUALS( actor1.GetCurrentRotation(), q1, 0.01, TEST_LOCATION );
3816 DALI_TEST_EQUALS( actor2.GetCurrentRotation(), q2, 0.01, TEST_LOCATION );
3818 Constraint constraint4 = Constraint::New<Quaternion>( Actor::ROTATION,
3819 Source( actor1, Actor::ROTATION ),
3820 EqualToConstraint() );
3821 constraint4.SetRemoveAction( Constraint::Discard );
3822 actor2.ApplyConstraint( constraint4 );
3823 application.SendNotification();
3824 application.Render(0);
3825 DALI_TEST_EQUALS( actor2.GetCurrentRotation(), q1, 0.01, TEST_LOCATION );
3828 // Check Matrix3 variant
3830 EqualToConstraint equalToConstraint;
3833 a.AsFloat()[0] = 1.f;
3835 b.AsFloat()[0] = 2.f;
3836 PropertyInputAbstraction pi(b);
3838 Matrix3 c = equalToConstraint(a,pi);
3839 DALI_TEST_EQUALS( c.AsFloat()[0], b.AsFloat()[0], 0.01, TEST_LOCATION);
3843 int UtcDaliBuiltinConstraintRelativeToConstraint(void)
3845 TestApplication application;
3847 Actor actor1 = Actor::New();
3848 Vector3 startPosition( 10, 10, 10 );
3849 actor1.SetPosition( startPosition );
3850 Stage::GetCurrent().Add( actor1 );
3852 Actor actor2 = Actor::New();
3853 Vector3 startSize( 100, 100, 100 );
3854 actor2.SetSize( startSize );
3855 Stage::GetCurrent().Add( actor2 );
3857 application.SendNotification();
3858 application.Render(0);
3859 DALI_TEST_CHECK( actor1.GetCurrentPosition() == startPosition );
3860 DALI_TEST_CHECK( actor2.GetCurrentSize() == startSize );
3862 // Apply constraint - actor1 size == actor2 position
3864 RelativeToConstraint( 0.f );
3865 Vector3 scale( 0.5, 0.6, 0.7 );
3866 Constraint constraint = Constraint::New<Vector3>( Actor::SIZE,
3867 Source( actor1, Actor::POSITION ),
3868 RelativeToConstraint( scale ) );
3869 constraint.SetRemoveAction( Constraint::Discard );
3870 actor2.ApplyConstraint( constraint );
3872 application.SendNotification();
3873 application.Render(0);
3875 // Constraint should be fully applied
3876 DALI_TEST_EQUALS( actor2.GetCurrentSize(), scale * startPosition, TEST_LOCATION );
3879 Vector3 endPosition( 2, 2, 2 );
3880 actor1.SetPosition( endPosition );
3882 application.SendNotification();
3883 application.Render(0);
3885 // Constraint should be fully applied
3886 DALI_TEST_EQUALS( actor2.GetCurrentSize(), scale * endPosition, TEST_LOCATION );
3887 application.Render(0);
3888 DALI_TEST_EQUALS( actor2.GetCurrentSize(), scale * endPosition, TEST_LOCATION );
3891 // Check float variant of constraint
3893 float scale2( 0.5f );
3894 float startOpacity(1.0f);
3895 actor1.SetOpacity( startOpacity );
3896 actor2.SetOpacity( startOpacity );
3898 application.SendNotification();
3899 application.Render(0);
3900 DALI_TEST_EQUALS( actor1.GetCurrentOpacity(), startOpacity, TEST_LOCATION );
3901 DALI_TEST_EQUALS( actor2.GetCurrentOpacity(), startOpacity, TEST_LOCATION );
3903 Constraint constraint2 = Constraint::New<float>( Actor::COLOR_ALPHA,
3904 Source( actor1, Actor::COLOR_ALPHA ),
3905 RelativeToConstraintFloat(scale2) );
3906 constraint2.SetRemoveAction( Constraint::Discard );
3907 actor2.ApplyConstraint(constraint2);
3908 application.SendNotification();
3909 application.Render(0);
3911 DALI_TEST_EQUALS( actor2.GetCurrentOpacity(), startOpacity * scale2, TEST_LOCATION );
3915 int UtcDaliBuiltinConstraintInverseOfConstraint(void)
3917 TestApplication application;
3919 Actor actor1 = Actor::New();
3920 Vector3 startPosition( 10, 10, 10 );
3921 actor1.SetPosition( startPosition );
3922 Stage::GetCurrent().Add( actor1 );
3924 Actor actor2 = Actor::New();
3925 Vector3 startSize( 100, 100, 100 );
3926 actor2.SetSize( startSize );
3927 Stage::GetCurrent().Add( actor2 );
3929 application.SendNotification();
3930 application.Render(0);
3931 DALI_TEST_CHECK( actor1.GetCurrentPosition() == startPosition );
3932 DALI_TEST_CHECK( actor2.GetCurrentSize() == startSize );
3934 // Apply constraint - actor1 size == ( 1 / actor2 position )
3936 Constraint constraint = Constraint::New<Vector3>( Actor::SIZE,
3937 Source( actor1, Actor::POSITION ),
3938 InverseOfConstraint() );
3939 constraint.SetRemoveAction( Constraint::Discard );
3940 actor2.ApplyConstraint( constraint );
3942 application.SendNotification();
3943 application.Render(0);
3945 // Constraint should be fully applied
3946 Vector3 size( 0.1, 0.1, 0.1 ); // 1 / startPosition
3947 DALI_TEST_EQUALS( actor2.GetCurrentSize(), size, 0.00001f, TEST_LOCATION );
3950 Vector3 endPosition( 2, 2, 2 );
3951 actor1.SetPosition( endPosition );
3953 application.SendNotification();
3954 application.Render(0);
3956 // Constraint should be fully applied
3957 size = Vector3( 0.5, 0.5, 0.5 ); // 1 / endPosition
3958 DALI_TEST_EQUALS( actor2.GetCurrentSize(), size, TEST_LOCATION );
3959 application.Render(0);
3960 DALI_TEST_EQUALS( actor2.GetCurrentSize(), size, TEST_LOCATION );
3964 int UtcDaliBuiltinConstraintFunctions(void)
3966 TestApplication application;
3969 SourceWidthFixedHeight sourceWidthFixedHeight( 10.f );
3972 Vector3 reference(1, 10, 0);
3973 Vector3 value = sourceWidthFixedHeight( current, PropertyInputAbstraction(Vector3::ONE) );
3974 DALI_TEST_EQUALS( reference, value, TEST_LOCATION );
3977 Vector3 reference(10, 10, 0);
3978 Vector3 value = sourceWidthFixedHeight( current, PropertyInputAbstraction(Vector3::ONE*10.f) );
3979 DALI_TEST_EQUALS( reference, value, TEST_LOCATION );
3982 Vector3 reference(10,10,0);
3983 Vector3 value = sourceWidthFixedHeight( current, PropertyInputAbstraction(Vector3::ONE*10.f) );
3984 DALI_TEST_EQUALS( reference, value, TEST_LOCATION );
3989 SourceHeightFixedWidth sourceHeightFixedWidth( 10.f );
3992 Vector3 reference(10,1,0);
3993 Vector3 value = sourceHeightFixedWidth( current, PropertyInputAbstraction(Vector3::ONE) );
3994 DALI_TEST_EQUALS( reference, value, TEST_LOCATION );
3997 Vector3 reference(10,10,0);
3998 Vector3 value = sourceHeightFixedWidth( current, PropertyInputAbstraction(Vector3::ONE*10.f) );
3999 DALI_TEST_EQUALS( reference, value, TEST_LOCATION );
4002 Vector3 reference(10,100,0);
4003 Vector3 value = sourceHeightFixedWidth( current, PropertyInputAbstraction(Vector3::ONE*100.f) );
4004 DALI_TEST_EQUALS( reference, value, TEST_LOCATION );
4009 Quaternion current(0, Vector3::YAXIS);
4010 PropertyInputAbstraction target(Vector3::ZAXIS);
4011 PropertyInputAbstraction targetRotation(Vector3::YAXIS);
4012 PropertyInputAbstraction camera(Vector3::ZERO);
4015 Quaternion reference(1., 0., 0., 0.);
4016 Quaternion value = LookAt( current, target, camera, targetRotation );
4017 DALI_TEST_EQUALS( reference, value, 0.001, TEST_LOCATION );
4021 OrientedLookAt orientedLookAt(90.f);
4022 Quaternion reference(.525322, 0., 0., 0.850904);
4023 Quaternion value = orientedLookAt( current, target, camera, targetRotation );
4024 DALI_TEST_EQUALS( reference, value, 0.001, TEST_LOCATION );