From 6fd8f4ce7bb532dce3571abd792eff2842a32a5a Mon Sep 17 00:00:00 2001 From: Adeel Kazmi Date: Mon, 18 May 2015 18:39:46 +0100 Subject: [PATCH] Added Test cases for Constraints Change-Id: I0d6b2d1c243e7a722dcd40a4c06bc904b541c47b --- automated-tests/src/dali/CMakeLists.txt | 4 + .../src/dali/utc-Dali-ActiveConstraint.cpp | 329 -- automated-tests/src/dali/utc-Dali-Constraint.cpp | 4333 ++++---------------- .../src/dali/utc-Dali-ConstraintFunction.cpp | 347 ++ .../src/dali/utc-Dali-ConstraintSource.cpp | 146 + automated-tests/src/dali/utc-Dali-Constraints.cpp | 398 ++ 6 files changed, 1650 insertions(+), 3907 deletions(-) delete mode 100644 automated-tests/src/dali/utc-Dali-ActiveConstraint.cpp create mode 100644 automated-tests/src/dali/utc-Dali-ConstraintFunction.cpp create mode 100644 automated-tests/src/dali/utc-Dali-ConstraintSource.cpp create mode 100644 automated-tests/src/dali/utc-Dali-Constraints.cpp diff --git a/automated-tests/src/dali/CMakeLists.txt b/automated-tests/src/dali/CMakeLists.txt index 7caf86a..111e874 100644 --- a/automated-tests/src/dali/CMakeLists.txt +++ b/automated-tests/src/dali/CMakeLists.txt @@ -17,6 +17,10 @@ SET(TC_SOURCES utc-Dali-BufferImage.cpp utc-Dali-CameraActor.cpp utc-Dali-Constrainer.cpp + utc-Dali-Constraint.cpp + utc-Dali-ConstraintFunction.cpp + utc-Dali-Constraints.cpp + utc-Dali-ConstraintSource.cpp utc-Dali-Context.cpp utc-Dali-ConnectionTracker.cpp utc-Dali-CustomActor.cpp diff --git a/automated-tests/src/dali/utc-Dali-ActiveConstraint.cpp b/automated-tests/src/dali/utc-Dali-ActiveConstraint.cpp deleted file mode 100644 index 0c765bd..0000000 --- a/automated-tests/src/dali/utc-Dali-ActiveConstraint.cpp +++ /dev/null @@ -1,329 +0,0 @@ -/* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include -#include -#include -#include - -using namespace Dali; - -void utc_dali_active_constraint_startup(void) -{ - test_return_value = TET_UNDEF; -} - -void utc_dali_active_constraint_cleanup(void) -{ - test_return_value = TET_PASS; -} - -namespace -{ - -static const Vector3 TEST_CONSTRAINT_TARGET = Vector3( 10.0f, 10.0f, 10.0f ); - -struct TestConstraintVector3 -{ - Vector3 operator()( const Vector3& current ) - { - return TEST_CONSTRAINT_TARGET; - } -}; - -static bool constraintSignalled=false; -static void ConstraintCallback( ActiveConstraint& constraint ) -{ - constraintSignalled = true; -} - -} // anon namespace - -int UtcDaliConstraintGetTargetObject(void) -{ - TestApplication application; - - // Apply a constraint to an actor - - Constraint constraint = Constraint::New( Actor::Property::SIZE, TestConstraintVector3() ); - - Actor actor = Actor::New(); - - ActiveConstraint active = actor.ApplyConstraint( constraint ); - - // Retrieve the actor back from the active-constraint - - Handle object = active.GetTargetObject(); - - DALI_TEST_CHECK( object ); - - DALI_TEST_CHECK( object.GetObjectPtr() == actor.GetObjectPtr() ); - - // Throw-away the actor, and check GetTargetObject returns NULL - - object.Reset(); - actor.Reset(); - - object = active.GetTargetObject(); - - DALI_TEST_CHECK( !object ); - END_TEST; -} - -int UtcDaliConstraintGetTargetProperty(void) -{ - TestApplication application; - - // Apply a constraint to an actor - - Constraint constraint = Constraint::New( Actor::Property::SIZE, TestConstraintVector3() ); - - Actor actor = Actor::New(); - - ActiveConstraint active = actor.ApplyConstraint( constraint ); - - // Check the property index - - Property::Index index = active.GetTargetProperty(); - - DALI_TEST_CHECK( Actor::Property::SIZE == index ); - END_TEST; -} - -int UtcDaliConstraintSetWeight(void) -{ - TestApplication application; - - // Apply a constraint to an actor - - Constraint constraint = Constraint::New( Actor::Property::SIZE, TestConstraintVector3() ); - - Actor actor = Actor::New(); - Stage::GetCurrent().Add( actor ); - - ActiveConstraint active = actor.ApplyConstraint( constraint ); - - // Apply the constraint manually - - active.SetWeight( 0.0f ); // start at zero - - application.SendNotification(); - application.Render(static_cast(1000.0f)); // 1 elapsed second - - DALI_TEST_EQUALS( actor.GetCurrentSize(), Vector3::ZERO, TEST_LOCATION ); - - float weight( 0.25f ); - active.SetWeight( weight ); - application.SendNotification(); - application.Render(static_cast(1000.0f)); // 1 elapsed second - DALI_TEST_EQUALS( actor.GetCurrentSize(), TEST_CONSTRAINT_TARGET * weight, TEST_LOCATION ); - - weight = 0.5f; - active.SetWeight( weight ); - application.SendNotification(); - application.Render(static_cast(1000.0f)); // 2 elapsed seconds - DALI_TEST_EQUALS( actor.GetCurrentSize(), TEST_CONSTRAINT_TARGET * weight, TEST_LOCATION ); - - weight = 0.75f; - active.SetWeight( weight ); - application.SendNotification(); - application.Render(static_cast(1000.0f)); // 2 elapsed seconds - DALI_TEST_EQUALS( actor.GetCurrentSize(), TEST_CONSTRAINT_TARGET * weight, TEST_LOCATION ); - - weight = 1.0f; - active.SetWeight( weight ); - application.SendNotification(); - application.Render(static_cast(1000.0f)); // 2 elapsed seconds - DALI_TEST_EQUALS( actor.GetCurrentSize(), TEST_CONSTRAINT_TARGET, TEST_LOCATION ); - END_TEST; -} - -int UtcDaliConstraintGetCurrentWeight(void) -{ - TestApplication application; - - // Apply a constraint to an actor - - Constraint constraint = Constraint::New( Actor::Property::SIZE, TestConstraintVector3() ); - - Actor actor = Actor::New(); - - ActiveConstraint active = actor.ApplyConstraint( constraint ); - - // Check default weight - - DALI_TEST_CHECK( ActiveConstraint::DEFAULT_WEIGHT == active.GetCurrentWeight() ); - END_TEST; -} - -int UtcDaliConstraintSignalApplied(void) -{ - TestApplication application; - - // Apply a constraint to an actor - - Constraint constraint = Constraint::New( Actor::Property::SIZE, TestConstraintVector3() ); - - float duration( 10.0f ); - constraint.SetApplyTime( duration ); - - Actor actor = Actor::New(); - Stage::GetCurrent().Add( actor ); - - ActiveConstraint active = actor.ApplyConstraint( constraint ); - - // Check signal is received after duration - - bool constraintCheck( false ); - ConstraintAppliedCheck appliedCheck( constraintCheck ); - - active.AppliedSignal().Connect( &application, appliedCheck ); - - application.SendNotification(); - application.Render(static_cast(1000.0f)); // 1 elapsed second - - // Check signal has not fired - application.SendNotification(); - appliedCheck.CheckSignalNotReceived(); - - application.Render(static_cast(4000.0f)); // 5 elapsed seconds - - // Check signal has not fired - application.SendNotification(); - appliedCheck.CheckSignalNotReceived(); - - application.Render(static_cast(5000.0f - 1.0f)); // <10 elapsed seconds - - // Check signal has not fired - application.SendNotification(); - appliedCheck.CheckSignalNotReceived(); - - application.Render(static_cast(2.0f)); // >10 elapsed seconds - - // Signal should have fired - application.SendNotification(); - appliedCheck.CheckSignalReceived(); - END_TEST; -} - -int UtcDaliConstraintRemove(void) -{ - TestApplication application; - - // Apply a constraint to an actor - - Constraint constraint = Constraint::New( Actor::Property::SIZE, TestConstraintVector3() ); - - float duration( 1.0f ); - constraint.SetApplyTime( duration ); - - Actor actor = Actor::New(); - const Vector3 startSize( 1, 2, 3 ); - actor.SetSize( startSize ); - Stage::GetCurrent().Add( actor ); - - ActiveConstraint active = actor.ApplyConstraint( constraint ); - - application.SendNotification(); - application.Render(static_cast(0.0f)); // 0 elapsed seconds - - DALI_TEST_CHECK( 0 == active.GetCurrentWeight() ); - DALI_TEST_CHECK( startSize == actor.GetCurrentSize() ); - - bool constraintCheck( false ); - ConstraintAppliedCheck appliedCheck( constraintCheck ); - - active.AppliedSignal().Connect( &application, appliedCheck ); - - application.SendNotification(); - application.Render(static_cast(2000.0f)); // 2 elapsed seconds - - application.SendNotification(); - appliedCheck.CheckSignalReceived(); - - DALI_TEST_CHECK( ActiveConstraint::DEFAULT_WEIGHT == active.GetCurrentWeight() ); - DALI_TEST_CHECK( TEST_CONSTRAINT_TARGET == actor.GetCurrentSize() ); - - // This should be NOOP while constraint is applied - actor.SetSize( startSize ); - application.SendNotification(); - application.Render(static_cast(1000.0f)); - DALI_TEST_CHECK( ActiveConstraint::DEFAULT_WEIGHT == active.GetCurrentWeight() ); - DALI_TEST_CHECK( TEST_CONSTRAINT_TARGET == actor.GetCurrentSize() ); - - // Remove constraint & try again - actor.RemoveConstraint( active ); - actor.SetSize( startSize ); - application.SendNotification(); - application.Render(static_cast(1000.0f)); - DALI_TEST_CHECK( ActiveConstraint::DEFAULT_WEIGHT == active.GetCurrentWeight() ); - DALI_TEST_CHECK( startSize == actor.GetCurrentSize() ); - - // Try setting the weight after removal - active.SetProperty( ActiveConstraint::Property::WEIGHT, 0.5f ); - application.SendNotification(); - application.Render(static_cast(1000.0f)); - DALI_TEST_CHECK( 0.5f == active.GetCurrentWeight() ); - END_TEST; -} - -int UtcDaliConstraintCallback(void) -{ - TestApplication application; - Constraint constraint = Constraint::New( Actor::Property::SIZE, TestConstraintVector3() ); - constraint.SetApplyTime(2.0f); - Actor actor = Actor::New(); - ActiveConstraint active = actor.ApplyConstraint( constraint ); - active.AppliedSignal().Connect( ConstraintCallback ); - application.SendNotification(); - application.Render(0); - application.Render(1000); - application.SendNotification(); - DALI_TEST_CHECK( ! constraintSignalled ); - application.Render(1016); - application.SendNotification(); - - DALI_TEST_CHECK( constraintSignalled ); - END_TEST; -} - -int UtcDaliConstraintProperties(void) -{ - TestApplication application; - - Constraint constraint = Constraint::New( Actor::Property::SIZE, TestConstraintVector3() ); - Actor actor = Actor::New(); - ActiveConstraint active = actor.ApplyConstraint( constraint ); - - Property::IndexContainer indices; - active.GetPropertyIndices( indices ); - DALI_TEST_CHECK( ! indices.empty() ); - DALI_TEST_EQUALS( indices.size(), active.GetPropertyCount(), TEST_LOCATION ); - - // Valid property - DALI_TEST_EQUALS( active.GetPropertyName( 0 ), "weight", TEST_LOCATION ); - DALI_TEST_EQUALS( active.GetPropertyIndex( "weight" ), 0, TEST_LOCATION ); - DALI_TEST_CHECK( active.IsPropertyWritable( 0 ) ); - DALI_TEST_CHECK( active.IsPropertyAnimatable( 0 ) ); - DALI_TEST_EQUALS( active.GetPropertyType( 0 ), Property::FLOAT, TEST_LOCATION ); - DALI_TEST_CHECK( active.GetCurrentWeight() != 21312.0f ); - active.SetProperty( 0, 21312.0f ); - DALI_TEST_EQUALS( active.GetCurrentWeight(), 21312.0f, TEST_LOCATION ); - DALI_TEST_EQUALS( active.GetProperty< float >( 0 ), 21312.0f, TEST_LOCATION ); - - END_TEST; -} diff --git a/automated-tests/src/dali/utc-Dali-Constraint.cpp b/automated-tests/src/dali/utc-Dali-Constraint.cpp index c4c8106..e1b8ac0 100644 --- a/automated-tests/src/dali/utc-Dali-Constraint.cpp +++ b/automated-tests/src/dali/utc-Dali-Constraint.cpp @@ -23,6 +23,7 @@ using namespace Dali; +/////////////////////////////////////////////////////////////////////////////// void utc_dali_constraint_startup(void) { test_return_value = TET_UNDEF; @@ -32,3947 +33,1123 @@ void utc_dali_constraint_cleanup(void) { test_return_value = TET_PASS; } +/////////////////////////////////////////////////////////////////////////////// - +/////////////////////////////////////////////////////////////////////////////// namespace { -struct EqualToQuaternion -{ - EqualToQuaternion() - { - } - - Quaternion operator()( const Quaternion& current, const PropertyInput& property ) - { - return property.GetQuaternion(); - } -}; - -struct EqualToVector4 -{ - EqualToVector4() - { - } - - Vector4 operator()( const Vector4& current, const PropertyInput& property ) - { - return property.GetVector4(); - } -}; - -class PropertyInputAbstraction : public Dali::PropertyInput -{ -public: - PropertyInputAbstraction(const bool& val) : mType(Dali::Property::BOOLEAN), mBoolData( val ) {} - PropertyInputAbstraction(const int& val) : mType(Dali::Property::INTEGER), mIntData( val ) {} - PropertyInputAbstraction(const unsigned int& val) : mType(Dali::Property::UNSIGNED_INTEGER), mUIntData( val ) {} - PropertyInputAbstraction(const float& val) : mType(Dali::Property::FLOAT), mFloatData( val ) {} - PropertyInputAbstraction(const Vector2& val) : mType(Dali::Property::VECTOR2), mVector2Data( val ) {} - PropertyInputAbstraction(const Vector3& val) : mType(Dali::Property::VECTOR3), mVector3Data( val ) {} - PropertyInputAbstraction(const Vector4& val) : mType(Dali::Property::VECTOR4), mVector4Data( val ) {} - PropertyInputAbstraction(const Matrix3& val) : mType(Dali::Property::MATRIX3), mMatrix3Data( val ) {} - PropertyInputAbstraction(const Matrix& val) : mType(Dali::Property::MATRIX), mMatrixData( val ) {} - PropertyInputAbstraction(const Quaternion& val) : mType(Dali::Property::ROTATION), mQuaternionData( val ) {} - - ~PropertyInputAbstraction() {} - - Dali::Property::Type GetType() const { return mType; } - - const bool& GetBoolean() const { return mBoolData; } - - const int& GetInteger() const { return mIntData; } - const unsigned int& GetUnsignedInteger() const { return mUIntData; } - - const float& GetFloat() const { return mFloatData; } - const Vector2& GetVector2() const { return mVector2Data; } - const Vector3& GetVector3() const { return mVector3Data; } - const Vector4& GetVector4() const { return mVector4Data; } - - const Matrix3& GetMatrix3() const { return mMatrix3Data; } - const Matrix& GetMatrix() const { return mMatrixData; } - - const Quaternion& GetQuaternion() const { return mQuaternionData; } - -private: - Dali::Property::Type mType; - bool mBoolData; - int mIntData; - unsigned int mUIntData; - float mFloatData; - Vector2 mVector2Data; - Vector3 mVector3Data; - Vector4 mVector4Data; - Matrix3 mMatrix3Data; - Matrix mMatrixData; - Quaternion mQuaternionData; -}; - -static const float POSITION_EPSILON = 0.0001f; -static const float ROTATION_EPSILON = 0.0001f; - -struct TestConstraint -{ - Vector4 operator()(const Vector4& color) - { - return Vector4(color.x, color.y, color.z, 0.1f); - } -}; - -struct TestConstraintToVector3 -{ - TestConstraintToVector3(Vector3 target) - : mTarget(target) - { - } - - Vector3 operator()(const Vector3& current) - { - return mTarget; - } - - Vector3 mTarget; -}; - -struct TestColorConstraint -{ - TestColorConstraint(Vector4 target) - : mTarget(target) - { - } - - Vector4 operator()(const Vector4& color) - { - return mTarget; - } - - Vector4 mTarget; -}; - -struct TestPositionConstraint -{ - TestPositionConstraint(Vector3 target) - : mTarget(target) - { - } - - Vector3 operator()(const Vector3& position) - { - return mTarget; - } - - Vector3 mTarget; -}; - - -struct TestAlwaysTrueConstraint -{ - bool operator()( const bool& current ) - { - return true; - } -}; - -struct TestAlwaysEqualOrGreaterThanConstraintFloat -{ - TestAlwaysEqualOrGreaterThanConstraintFloat( float value ) - : mValue( value ) - { - } - - float operator()( const float& current ) - { - return ( current < mValue ) ? mValue : current; - } - - float mValue; -}; - -struct TestAlwaysEqualOrGreaterThanConstraintInteger +/** + * A function to use for a constraint, no data collected. + */ +template< typename T > +void BasicFunction( T& /* current */, const PropertyInputContainer& /* inputs */ ) { - TestAlwaysEqualOrGreaterThanConstraintInteger( int value ) - : mValue( value ) - { - } - - int operator()( const int& current ) - { - return ( current < mValue ) ? mValue : current; - } - - int mValue; -}; +} -struct TestAlwaysEqualOrGreaterThanConstraintUnsignedInteger +/** + * A functor which sets a given boolean when the functor is called. + */ +template< typename T > +struct BasicCalledFunctor { - TestAlwaysEqualOrGreaterThanConstraintUnsignedInteger( unsigned int value ) - : mValue( value ) - { - } + BasicCalledFunctor( bool& functorCalled ) : mCalled( functorCalled ) { } - unsigned int operator()( unsigned const int& current ) + void operator()( T& /* current */, const PropertyInputContainer& /* inputs */ ) { - return ( current < mValue ) ? mValue : current; + mCalled = true; } - unsigned int mValue; + bool& mCalled; }; -struct TestAlwaysEqualOrGreaterThanConstraintVector2 +/** + * A functor which increments a given integer when the functor is called. + */ +template< typename T > +struct CalledCountFunctor { - TestAlwaysEqualOrGreaterThanConstraintVector2( Vector2 value ) - : mValue( value ) - { - } + CalledCountFunctor( int& callCount ) : mCallCount( callCount ) { } - Vector2 operator()( const Vector2& current ) + void operator()( T& /* current */, const PropertyInputContainer& /* inputs */ ) { - return Vector2( ( current.x < mValue.x ) ? mValue.x : current.x, - ( current.y < mValue.y ) ? mValue.y : current.y - ); + ++mCallCount; } - Vector2 mValue; + int& mCallCount; }; -struct TestAlwaysEqualOrGreaterThanConstraintVector3 +/** + * A functor which sets the given value as the value required when the functor is called. + */ +template< typename T > +struct SetValueFunctor { - TestAlwaysEqualOrGreaterThanConstraintVector3( Vector3 value ) - : mValue( value ) - { - } + SetValueFunctor( const T& value ) : mValue( value ) { } - Vector3 operator()( const Vector3& current ) + void operator()( T& current, const PropertyInputContainer& /* inputs */ ) { - return Vector3( ( current.x < mValue.x ) ? mValue.x : current.x, - ( current.y < mValue.y ) ? mValue.y : current.y, - ( current.z < mValue.z ) ? mValue.z : current.z - ); + current = mValue; } - Vector3 mValue; + T mValue; }; -struct TestAlwaysEqualOrGreaterThanConstraintVector4 -{ - TestAlwaysEqualOrGreaterThanConstraintVector4( Vector4 value ) - : mValue( value ) - { - } - - Vector4 operator()( const Vector4& current ) - { - return Vector4( ( current.x < mValue.x ) ? mValue.x : current.x, - ( current.y < mValue.y ) ? mValue.y : current.y, - ( current.z < mValue.z ) ? mValue.z : current.z, - ( current.w < mValue.w ) ? mValue.w : current.w - ); - } - - Vector4 mValue; -}; +} // unnamed namespace +/////////////////////////////////////////////////////////////////////////////// -struct TestConstraintFloat +/////////////////////////////////////////////////////////////////////////////// +// Constraint::New( +// Handle, +// Property::Index, +// void( *function )( T&, const PropertyInputContainer& ) ) +/////////////////////////////////////////////////////////////////////////////// +namespace UtcDaliConstraintNewFunction { - TestConstraintFloat( float value ) - : mValue( value ) - { - } - - float operator()( const float& current ) - { - return mValue; - } - - float mValue; -}; - -struct TestConstraintInteger +bool gConstraintFunctionCalled = false; +void ConstraintFunction( Vector3& /* current */, const PropertyInputContainer& /* inputs */ ) { - TestConstraintInteger( int value ) - : mValue( value ) - { - } - - int operator()( const int& current ) - { - return mValue; - } - - int mValue; -}; + gConstraintFunctionCalled = true; +} +} // namespace UtcDaliConstraintNewFunction -struct TestConstraintUnsignedInteger +int UtcDaliConstraintNewFunctionP(void) { - TestConstraintUnsignedInteger( int value ) - : mValue( value ) - { - } + // Ensure that we can create a constraint using a C function and that it is called. - unsigned int operator()( const unsigned int& current ) - { - return mValue; - } + TestApplication application; + UtcDaliConstraintNewFunction::gConstraintFunctionCalled = false; - unsigned int mValue; -}; + Actor actor = Actor::New(); + Stage::GetCurrent().Add( actor ); -struct TestConstraintVector2 -{ - TestConstraintVector2( Vector2 value ) - : mValue( value ) - { - } + application.SendNotification(); + application.Render(); - Vector2 operator()( const Vector2& current ) - { - return mValue; - } + DALI_TEST_EQUALS( UtcDaliConstraintNewFunction::gConstraintFunctionCalled, false, TEST_LOCATION ); - Vector2 mValue; -}; + // Add a constraint + Constraint constraint = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, &UtcDaliConstraintNewFunction::ConstraintFunction ); + DALI_TEST_CHECK( constraint ); + constraint.Apply(); -struct TestConstraintVector3 -{ - TestConstraintVector3( Vector3 value ) - : mValue( value ) - { - } + application.SendNotification(); + application.Render(); - Vector3 operator()( const Vector3& current ) - { - return mValue; - } + DALI_TEST_EQUALS( UtcDaliConstraintNewFunction::gConstraintFunctionCalled, true, TEST_LOCATION ); - Vector3 mValue; -}; + END_TEST; +} -struct TestConstraintVector4 +int UtcDaliConstraintNewFunctionN(void) { - TestConstraintVector4( Vector4 value ) - : mValue( value ) - { - } - - Vector4 operator()( const Vector4& current ) - { - return mValue; - } + // Create a constraint with an uninitialised handle - Vector4 mValue; -}; + TestApplication application; -struct TestConstraintRotation -{ - TestConstraintRotation( Quaternion rotation ) - : mRotation( rotation ) + // Add a constraint with an uninitialised handle + try { + Constraint constraint = Constraint::New< Vector3 >( Actor(), Actor::Property::POSITION, &UtcDaliConstraintNewFunction::ConstraintFunction ); + DALI_TEST_CHECK( false ); // Should not reach here } - - Quaternion operator()( const Quaternion& current ) + catch ( ... ) { - return mRotation; + DALI_TEST_CHECK( true ); // Should assert! } - Quaternion mRotation; -}; + END_TEST; +} +/////////////////////////////////////////////////////////////////////////////// -struct TestConstraintMatrix3 +/////////////////////////////////////////////////////////////////////////////// +// Constraint::New( +// Handle, +// Property::Index, +// const T& object ) +/////////////////////////////////////////////////////////////////////////////// +int UtcDaliConstraintNewFunctorP(void) { - TestConstraintMatrix3(Matrix3 matrix3) - : mMatrix3( matrix3 ) - { - } + // Ensure that we can create a constraint using a functor and that it is called. - Matrix3 operator()( const Matrix3& current ) - { - return mMatrix3; - } + TestApplication application; + bool functorCalled = false; - Matrix3 mMatrix3; -}; + Actor actor = Actor::New(); + Stage::GetCurrent().Add( actor ); -struct TestConstraintMatrix -{ - TestConstraintMatrix(Matrix matrix) - : mMatrix( matrix ) - { - } + application.SendNotification(); + application.Render(); - Matrix operator()( const Matrix& current ) - { - return mMatrix; - } + DALI_TEST_EQUALS( functorCalled, false, TEST_LOCATION ); - Matrix mMatrix; -}; + // Add a constraint + Constraint constraint = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, BasicCalledFunctor< Vector3 >( functorCalled ) ); + DALI_TEST_CHECK( constraint ); + constraint.Apply(); -struct MoveAwayWithFadeConstraint -{ - MoveAwayWithFadeConstraint( float distance ) - : mDistance( distance ) - { - } + application.SendNotification(); + application.Render(); - Vector3 operator()( const Vector3& current, - const PropertyInput& color ) - { - return Vector3( current.x, - current.y, - -mDistance * (1.0f - color.GetVector4().a) ); - } + DALI_TEST_EQUALS( functorCalled, true, TEST_LOCATION ); - float mDistance; -}; + END_TEST; +} -struct TestBottomRightAlignConstraint +int UtcDaliConstraintNewFunctorN(void) { - Vector3 operator()( const Vector3& current, - const PropertyInput& parentSize ) - { - return Vector3( parentSize.GetVector3().x, parentSize.GetVector3().y, 0.0f ); - } -}; + // Create a constraint with an uninitialised handle -struct MeanPositionConstraint1 -{ - Vector3 operator()( const Vector3& current, - const PropertyInput& position1 ) - { - return Vector3( position1.GetVector3() ); - } -}; + TestApplication application; + bool functorCalled = false; -struct MeanPositionConstraint2 -{ - Vector3 operator()( const Vector3& current, - const PropertyInput& position1, - const PropertyInput& position2 ) + // Add a constraint with an uninitialised handle + try { - Vector3 meanValue = position1.GetVector3() + - position2.GetVector3(); - - return meanValue * 0.5f; // div 2 + Constraint constraint = Constraint::New< Vector3 >( Actor(), Actor::Property::POSITION, BasicCalledFunctor< Vector3 >( functorCalled ) ); + DALI_TEST_CHECK( false ); // Should not reach here } -}; - -struct MeanPositionConstraint3 -{ - Vector3 operator()( const Vector3& current, - const PropertyInput& position1, - const PropertyInput& position2, - const PropertyInput& position3 ) + catch ( ... ) { - Vector3 meanValue = position1.GetVector3() + - position2.GetVector3() + - position3.GetVector3(); - - return meanValue * (1.0f / 3.0f); // div 3 + DALI_TEST_CHECK( true ); // Should assert! } -}; - -struct MeanPositionConstraint4 -{ - Vector3 operator()( const Vector3& current, - const PropertyInput& position1, - const PropertyInput& position2, - const PropertyInput& position3, - const PropertyInput& position4 ) - { - Vector3 meanValue = position1.GetVector3() + - position2.GetVector3() + - position3.GetVector3() + - position4.GetVector3(); - return meanValue * 0.25f; // div 4 - } -}; + END_TEST; +} +/////////////////////////////////////////////////////////////////////////////// -struct MeanPositionConstraint5 +/////////////////////////////////////////////////////////////////////////////// +// Constraint::New( +// Handle, +// Property::Index, +// const T& object, +// void ( T::*memberFunction ) ( P&, const PropertyInputContainer& ) ) +/////////////////////////////////////////////////////////////////////////////// +namespace UtcDaliConstraintNewFunctorMember { - Vector3 operator()( const Vector3& current, - const PropertyInput& position1, - const PropertyInput& position2, - const PropertyInput& position3, - const PropertyInput& position4, - const PropertyInput& position5 ) - { - Vector3 meanValue = position1.GetVector3() + - position2.GetVector3() + - position3.GetVector3() + - position4.GetVector3() + - position5.GetVector3(); - - return meanValue * 0.2f; // div 5 - } -}; - -struct MeanPositionConstraint6 +struct Functor { - Vector3 operator()( const Vector3& current, - const PropertyInput& position1, - const PropertyInput& position2, - const PropertyInput& position3, - const PropertyInput& position4, - const PropertyInput& position5, - const PropertyInput& position6 ) + Functor( bool& positionCalled, bool& scaleCalled ) + : mPositionCalled( positionCalled ), + mScaleCalled( scaleCalled ) { - Vector3 meanValue = position1.GetVector3() + - position2.GetVector3() + - position3.GetVector3() + - position4.GetVector3() + - position5.GetVector3() + - position6.GetVector3(); - - return meanValue * (1.0f / 6.0f); // div 6 } -}; -struct TestRelativeConstraintFloat -{ - TestRelativeConstraintFloat(float scale) - : mScale(scale) + void Position( Vector3& /* current */, const PropertyInputContainer& /* inputs */ ) { + mPositionCalled = true; } - float operator()( const float& current, const PropertyInput& relative ) + void Scale( Vector3& /* current */, const PropertyInputContainer& /* inputs */ ) { - return relative.GetFloat() * mScale; + mScaleCalled = true; } - float mScale; + bool& mPositionCalled; + bool& mScaleCalled; }; +} // namespace UtcDaliConstraintNewFunctorMember -struct TestRelativeConstraintVector3 +int UtcDaliConstraintNewFunctorMemberP(void) { - TestRelativeConstraintVector3(float scale) - : mScale(scale) - { - } - - Vector3 operator()( const Vector3& current, const PropertyInput& relative ) - { - return relative.GetVector3() * mScale; - } - - float mScale; -}; + // Ensure that we can create a constraint using a functor and that it is called. -} // anonymous namespace - - - - - - -int UtcDaliConstraintNewBoolean(void) -{ TestApplication application; + bool positionFunctorCalled = false; + bool sizeFunctorCalled = false; Actor actor = Actor::New(); + Stage::GetCurrent().Add( actor ); - // Register a boolean property - bool startValue(false); - Property::Index index = actor.RegisterProperty( "test-property", startValue ); - Stage::GetCurrent().Add(actor); - DALI_TEST_CHECK( actor.GetProperty(index) == startValue ); - - /** - * Test that the Constraint is correctly applied on a clean Node - */ application.SendNotification(); - application.Render(0); - DALI_TEST_CHECK( actor.GetProperty(index) == startValue ); - application.Render(0); - DALI_TEST_CHECK( actor.GetProperty(index) == startValue ); - application.Render(0); - DALI_TEST_CHECK( actor.GetProperty(index) == startValue ); - - // Apply constraint + application.Render(); - Constraint constraint = Constraint::New( index, TestAlwaysTrueConstraint() ); + DALI_TEST_EQUALS( positionFunctorCalled, false, TEST_LOCATION ); + DALI_TEST_EQUALS( sizeFunctorCalled, false, TEST_LOCATION ); - actor.ApplyConstraint( constraint ); - DALI_TEST_EQUALS( actor.GetProperty(index), false, TEST_LOCATION ); + // Add a constraint that calls Functor::Position + Constraint constraint = Constraint::New< Vector3 >( + actor, + Actor::Property::POSITION, + UtcDaliConstraintNewFunctorMember::Functor( positionFunctorCalled, sizeFunctorCalled ), + &UtcDaliConstraintNewFunctorMember::Functor::Position ); + DALI_TEST_CHECK( constraint ); + constraint.Apply(); application.SendNotification(); - application.Render(0); - - // Constraint should be fully applied - DALI_TEST_EQUALS( actor.GetProperty(index), true, TEST_LOCATION ); + application.Render(); - // Check that nothing has changed after a couple of buffer swaps - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), true, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), true, TEST_LOCATION ); + DALI_TEST_EQUALS( positionFunctorCalled, true, TEST_LOCATION ); + DALI_TEST_EQUALS( sizeFunctorCalled, false, TEST_LOCATION ); - // Try to fight with the constraint - this shouldn't work! - actor.SetProperty( index, false ); + // Add another constraint that calls Functor::Size + Constraint constraint2 = Constraint::New< Vector3 >( + actor, + Actor::Property::SCALE, + UtcDaliConstraintNewFunctorMember::Functor( positionFunctorCalled, sizeFunctorCalled ), + &UtcDaliConstraintNewFunctorMember::Functor::Scale ); + DALI_TEST_CHECK( constraint2 ); + constraint2.Apply(); application.SendNotification(); - application.Render(0); - - // Check that nothing has changed after a couple of buffer swaps - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), true, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), true, TEST_LOCATION ); + application.Render(); - // Remove the constraint, then set new value - actor.RemoveConstraints(); - actor.SetProperty( index, false ); + DALI_TEST_EQUALS( positionFunctorCalled, true, TEST_LOCATION ); + DALI_TEST_EQUALS( sizeFunctorCalled, true, TEST_LOCATION ); - // Constraint should have been removed - application.SendNotification(); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), false, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), false, TEST_LOCATION ); END_TEST; -} - -int UtcDaliConstraintNewFloat(void) -{ - TestApplication application; - - Actor actor = Actor::New(); - - // Register a float property - float startValue(1.0f); - Property::Index index = actor.RegisterProperty( "test-property", startValue ); - Stage::GetCurrent().Add(actor); - DALI_TEST_CHECK( actor.GetProperty(index) == startValue ); - - /** - * Test that the Constraint is correctly applied on a clean Node - */ - application.SendNotification(); - application.Render(0); - DALI_TEST_CHECK( actor.GetProperty(index) == startValue ); - application.Render(0); - DALI_TEST_CHECK( actor.GetProperty(index) == startValue ); - application.Render(0); - DALI_TEST_CHECK( actor.GetProperty(index) == startValue ); - - // Apply constraint - - float minValue( 2.0f ); - Constraint constraint = Constraint::New( index, TestAlwaysEqualOrGreaterThanConstraintFloat( minValue ) ); - - actor.ApplyConstraint( constraint ); - DALI_TEST_EQUALS( actor.GetProperty(index), startValue, TEST_LOCATION ); - - application.SendNotification(); - application.Render(0); - - // Constraint should be fully applied - DALI_TEST_EQUALS( actor.GetProperty(index), minValue, TEST_LOCATION ); - - // Check that nothing has changed after a couple of buffer swaps - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), minValue, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), minValue, TEST_LOCATION ); - - // Set to greater than 2.0f, the constraint will allow this - actor.SetProperty( index, 3.0f ); - - application.SendNotification(); - application.Render(0); - - DALI_TEST_EQUALS( actor.GetProperty(index), 3.0f, TEST_LOCATION ); - - // Check that nothing has changed after a couple of buffer swaps - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), 3.0f, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), 3.0f, TEST_LOCATION ); - - // Set to less than 2.0f, the constraint will NOT allow this - actor.SetProperty( index, 1.0f ); - - application.SendNotification(); - application.Render(0); - - DALI_TEST_EQUALS( actor.GetProperty(index), minValue/*not 1.0f*/, TEST_LOCATION ); - - // Check that nothing has changed after a couple of buffer swaps - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), minValue, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), minValue, TEST_LOCATION ); - - // Remove the constraint, then set new value - actor.RemoveConstraints(); - actor.SetProperty( index, 1.0f ); - - // Constraint should have been removed - application.SendNotification(); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), 1.0f, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), 1.0f, TEST_LOCATION ); - END_TEST; -} - -int UtcDaliConstraintNewInteger(void) -{ - TestApplication application; - - Actor actor = Actor::New(); - - // Register an integer property - int startValue( 1 ); - Property::Index index = actor.RegisterProperty( "test-property", startValue ); - Stage::GetCurrent().Add(actor); - DALI_TEST_CHECK( actor.GetProperty(index) == startValue ); - - /** - * Test that the Constraint is correctly applied on a clean Node - */ - application.SendNotification(); - application.Render(0); - DALI_TEST_CHECK( actor.GetProperty(index) == startValue ); - application.Render(0); - DALI_TEST_CHECK( actor.GetProperty(index) == startValue ); - application.Render(0); - DALI_TEST_CHECK( actor.GetProperty(index) == startValue ); - - // Apply constraint - - int minValue( 2 ); - Constraint constraint = Constraint::New( index, TestAlwaysEqualOrGreaterThanConstraintInteger( minValue ) ); - - actor.ApplyConstraint( constraint ); - DALI_TEST_EQUALS( actor.GetProperty(index), startValue, TEST_LOCATION ); - - application.SendNotification(); - application.Render(0); - - // Constraint should be fully applied - DALI_TEST_EQUALS( actor.GetProperty(index), minValue, TEST_LOCATION ); - - // Check that nothing has changed after a couple of buffer swaps - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), minValue, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), minValue, TEST_LOCATION ); - - // Set to greater than 2f, the constraint will allow this - actor.SetProperty( index, 3 ); - - application.SendNotification(); - application.Render(0); - - DALI_TEST_EQUALS( actor.GetProperty(index), 3, TEST_LOCATION ); - - // Check that nothing has changed after a couple of buffer swaps - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), 3, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), 3, TEST_LOCATION ); - - // Set to less than 2, the constraint will NOT allow this - actor.SetProperty( index, 1 ); - - application.SendNotification(); - application.Render(0); - - DALI_TEST_EQUALS( actor.GetProperty(index), minValue/*not 1*/, TEST_LOCATION ); - - // Check that nothing has changed after a couple of buffer swaps - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), minValue, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), minValue, TEST_LOCATION ); - - // Remove the constraint, then set new value - actor.RemoveConstraints(); - actor.SetProperty( index, 1 ); - - // Constraint should have been removed - application.SendNotification(); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), 1, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), 1, TEST_LOCATION ); - END_TEST; - -} - -int UtcDaliConstraintNewUnsignedInteger(void) -{ - TestApplication application; - - Actor actor = Actor::New(); - - // Register an integer property - unsigned int startValue( 1u ); - Property::Index index = actor.RegisterProperty( "test-property", startValue ); - Stage::GetCurrent().Add(actor); - DALI_TEST_CHECK( actor.GetProperty(index) == startValue ); - - /** - * Test that the Constraint is correctly applied on a clean Node - */ - application.SendNotification(); - application.Render(0); - DALI_TEST_CHECK( actor.GetProperty(index) == startValue ); - application.Render(0); - DALI_TEST_CHECK( actor.GetProperty(index) == startValue ); - application.Render(0); - DALI_TEST_CHECK( actor.GetProperty(index) == startValue ); - - // Apply constraint - - unsigned int minValue( 2 ); - Constraint constraint = Constraint::New( index, TestAlwaysEqualOrGreaterThanConstraintUnsignedInteger( minValue ) ); - - actor.ApplyConstraint( constraint ); - DALI_TEST_EQUALS( actor.GetProperty(index), startValue, TEST_LOCATION ); - - application.SendNotification(); - application.Render(0); - - // Constraint should be fully applied - DALI_TEST_EQUALS( actor.GetProperty(index), minValue, TEST_LOCATION ); - - // Check that nothing has changed after a couple of buffer swaps - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), minValue, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), minValue, TEST_LOCATION ); - - // Set to greater than 2f, the constraint will allow this - actor.SetProperty( index, 3u ); - - application.SendNotification(); - application.Render(0); - - DALI_TEST_EQUALS( actor.GetProperty(index), 3, TEST_LOCATION ); - - // Check that nothing has changed after a couple of buffer swaps - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), 3, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), 3, TEST_LOCATION ); - - // Set to less than 2, the constraint will NOT allow this - actor.SetProperty( index, 1u ); - - application.SendNotification(); - application.Render(0); - - DALI_TEST_EQUALS( actor.GetProperty(index), minValue/*not 1*/, TEST_LOCATION ); - - // Check that nothing has changed after a couple of buffer swaps - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), minValue, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), minValue, TEST_LOCATION ); - - // Remove the constraint, then set new value - actor.RemoveConstraints(); - actor.SetProperty( index, 1u ); - - // Constraint should have been removed - application.SendNotification(); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), 1, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), 1, TEST_LOCATION ); - END_TEST; -} - - -int UtcDaliConstraintNewVector2(void) -{ - TestApplication application; - - Actor actor = Actor::New(); - - // Register a Vector2 property - Vector2 startValue( 1.0f, 1.0f ); - Property::Index index = actor.RegisterProperty( "test-property", startValue ); - Stage::GetCurrent().Add(actor); - DALI_TEST_CHECK( actor.GetProperty(index) == startValue ); - - /** - * Test that the Constraint is correctly applied on a clean Node - */ - application.SendNotification(); - application.Render(0); - DALI_TEST_CHECK( actor.GetProperty(index) == startValue ); - application.Render(0); - DALI_TEST_CHECK( actor.GetProperty(index) == startValue ); - application.Render(0); - DALI_TEST_CHECK( actor.GetProperty(index) == startValue ); - - // Apply constraint - - Vector2 minValue( 2.0f, 2.0f ); - Constraint constraint = Constraint::New( index, TestAlwaysEqualOrGreaterThanConstraintVector2( minValue ) ); - - actor.ApplyConstraint( constraint ); - DALI_TEST_EQUALS( actor.GetProperty(index), startValue, TEST_LOCATION ); - - application.SendNotification(); - application.Render(0); - - // Constraint should be fully applied - DALI_TEST_EQUALS( actor.GetProperty(index), minValue, TEST_LOCATION ); - - // Check that nothing has changed after a couple of buffer swaps - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), minValue, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), minValue, TEST_LOCATION ); - - // Set to greater than 2.0f, the constraint will allow this - Vector2 greaterValue( 3.0f, 3.0f ); - actor.SetProperty( index, greaterValue ); - - application.SendNotification(); - application.Render(0); - - DALI_TEST_EQUALS( actor.GetProperty(index), greaterValue, TEST_LOCATION ); - - // Check that nothing has changed after a couple of buffer swaps - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), greaterValue, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), greaterValue, TEST_LOCATION ); - - // Set to less than 2.0f, the constraint will NOT allow this - Vector2 lesserValue( 1.0f, 1.0f ); - actor.SetProperty( index, lesserValue ); - - application.SendNotification(); - application.Render(0); - - DALI_TEST_EQUALS( actor.GetProperty(index), minValue/*not lesserValue*/, TEST_LOCATION ); - - // Check that nothing has changed after a couple of buffer swaps - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), minValue, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), minValue, TEST_LOCATION ); - - // Remove the constraint, then set new value - actor.RemoveConstraints(); - actor.SetProperty( index, lesserValue ); - - // Constraint should have been removed - application.SendNotification(); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), lesserValue, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), lesserValue, TEST_LOCATION ); - END_TEST; -} - -int UtcDaliConstraintNewVector3(void) -{ - TestApplication application; - - Actor actor = Actor::New(); - - // Register a Vector3 property - Vector3 startValue(1.0f, 1.0f, 1.0f); - Property::Index index = actor.RegisterProperty( "test-property", startValue ); - Stage::GetCurrent().Add(actor); - DALI_TEST_CHECK( actor.GetProperty(index) == startValue ); - - /** - * Test that the Constraint is correctly applied on a clean Node - */ - application.SendNotification(); - application.Render(0); - DALI_TEST_CHECK( actor.GetProperty(index) == startValue ); - application.Render(0); - DALI_TEST_CHECK( actor.GetProperty(index) == startValue ); - application.Render(0); - DALI_TEST_CHECK( actor.GetProperty(index) == startValue ); - - // Apply constraint - - Vector3 minValue( 2.0f, 2.0f, 2.0f ); - Constraint constraint = Constraint::New( index, TestAlwaysEqualOrGreaterThanConstraintVector3( minValue ) ); - - actor.ApplyConstraint( constraint ); - DALI_TEST_EQUALS( actor.GetProperty(index), startValue, TEST_LOCATION ); - - application.SendNotification(); - application.Render(0); - - // Constraint should be fully applied - DALI_TEST_EQUALS( actor.GetProperty(index), minValue, TEST_LOCATION ); - - // Check that nothing has changed after a couple of buffer swaps - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), minValue, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), minValue, TEST_LOCATION ); - - // Set to greater than 2.0f, the constraint will allow this - Vector3 greaterValue( 3.0f, 3.0f, 3.0f ); - actor.SetProperty( index, greaterValue ); - - application.SendNotification(); - application.Render(0); - - DALI_TEST_EQUALS( actor.GetProperty(index), greaterValue, TEST_LOCATION ); - - // Check that nothing has changed after a couple of buffer swaps - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), greaterValue, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), greaterValue, TEST_LOCATION ); - - // Set to less than 2.0f, the constraint will NOT allow this - Vector3 lesserValue( 1.0f, 1.0f, 1.0f ); - actor.SetProperty( index, lesserValue ); - - application.SendNotification(); - application.Render(0); - - DALI_TEST_EQUALS( actor.GetProperty(index), minValue/*not lesserValue*/, TEST_LOCATION ); - - // Check that nothing has changed after a couple of buffer swaps - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), minValue, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), minValue, TEST_LOCATION ); - - // Remove the constraint, then set new value - actor.RemoveConstraints(); - actor.SetProperty( index, lesserValue ); - - // Constraint should have been removed - application.SendNotification(); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), lesserValue, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), lesserValue, TEST_LOCATION ); - END_TEST; -} - -int UtcDaliConstraintNewVector4(void) -{ - TestApplication application; - - Actor actor = Actor::New(); - - // Register a Vector4 property - Vector4 startValue( 1.0f, 1.0f, 1.0f, 1.0f ); - Property::Index index = actor.RegisterProperty( "test-property", startValue ); - Stage::GetCurrent().Add(actor); - DALI_TEST_CHECK( actor.GetProperty(index) == startValue ); - - /** - * Test that the Constraint is correctly applied on a clean Node - */ - application.SendNotification(); - application.Render(0); - DALI_TEST_CHECK( actor.GetProperty(index) == startValue ); - application.Render(0); - DALI_TEST_CHECK( actor.GetProperty(index) == startValue ); - application.Render(0); - DALI_TEST_CHECK( actor.GetProperty(index) == startValue ); - - // Apply constraint - - Vector4 minValue( 2.0f, 2.0f, 2.0f, 2.0f ); - Constraint constraint = Constraint::New( index, TestAlwaysEqualOrGreaterThanConstraintVector4( minValue ) ); - - actor.ApplyConstraint( constraint ); - DALI_TEST_EQUALS( actor.GetProperty(index), startValue, TEST_LOCATION ); - - application.SendNotification(); - application.Render(0); - - // Constraint should be fully applied - DALI_TEST_EQUALS( actor.GetProperty(index), minValue, TEST_LOCATION ); - - // Check that nothing has changed after a couple of buffer swaps - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), minValue, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), minValue, TEST_LOCATION ); - - // Set to greater than 2.0f, the constraint will allow this - Vector4 greaterValue( 3.0f, 3.0f, 3.0f, 3.0f ); - actor.SetProperty( index, greaterValue ); - - application.SendNotification(); - application.Render(0); - - DALI_TEST_EQUALS( actor.GetProperty(index), greaterValue, TEST_LOCATION ); - - // Check that nothing has changed after a couple of buffer swaps - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), greaterValue, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), greaterValue, TEST_LOCATION ); - - // Set to less than 2.0f, the constraint will NOT allow this - Vector4 lesserValue( 1.0f, 1.0f, 1.0f, 1.0f ); - actor.SetProperty( index, lesserValue ); - - application.SendNotification(); - application.Render(0); - - DALI_TEST_EQUALS( actor.GetProperty(index), minValue/*not lesserValue*/, TEST_LOCATION ); - - // Check that nothing has changed after a couple of buffer swaps - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), minValue, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), minValue, TEST_LOCATION ); - - // Remove the constraint, then set new value - actor.RemoveConstraints(); - actor.SetProperty( index, lesserValue ); - - // Constraint should have been removed - application.SendNotification(); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), lesserValue, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), lesserValue, TEST_LOCATION ); - END_TEST; -} - -int UtcDaliConstraintNewMatrix(void) -{ - try - { - TestApplication application; - - Actor actor = Actor::New(); - - // Register a Matrix property - Matrix startValue = Matrix::IDENTITY; - Property::Index index = actor.RegisterProperty( "test-property", startValue ); - DALI_TEST_CHECK( index != Property::INVALID_INDEX ); - if (index != Property::INVALID_INDEX) - { - Stage::GetCurrent().Add(actor); - DALI_TEST_CHECK( actor.GetProperty(index) == startValue ); - - // Apply constraint - Matrix constraintLimit; - constraintLimit.SetTransformComponents(Vector3::ONE, Quaternion(Radian(Degree(30.0f)), Vector3::YAXIS), Vector3::ZAXIS ); - Constraint constraint = Constraint::New( index, TestConstraintMatrix(constraintLimit)); - actor.ApplyConstraint( constraint ); - DALI_TEST_EQUALS( actor.GetProperty(index), startValue, TEST_LOCATION ); - - application.SendNotification(); - application.Render(0); - - DALI_TEST_EQUALS( actor.GetProperty(index), constraintLimit, TEST_LOCATION ); - } - } - catch (Dali::DaliException& e) - { - DALI_TEST_PRINT_ASSERT( e ); - DALI_TEST_CHECK(0); - } - END_TEST; -} - -int UtcDaliConstraintNewMatrix3(void) -{ - try - { - TestApplication application; - - Actor actor = Actor::New(); - - // Register a Matrix3 property - Matrix3 startValue(1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f); - Property::Index index = actor.RegisterProperty( "test-property", startValue ); - DALI_TEST_CHECK( index != Property::INVALID_INDEX ); - if (index != Property::INVALID_INDEX) - { - Stage::GetCurrent().Add(actor); - DALI_TEST_CHECK( actor.GetProperty(index) == startValue ); - - // Apply constraint - Matrix3 constraintLimit(42.0f, 0.0f, 0.0f, 0.0f, 42.0f, 0.0f, 0.0f, 0.0f, 1.0f); - Constraint constraint = Constraint::New( index, TestConstraintMatrix3(constraintLimit)); - actor.ApplyConstraint( constraint ); - DALI_TEST_EQUALS( actor.GetProperty(index), startValue, 0.001f, TEST_LOCATION ); - - application.SendNotification(); - application.Render(0); - - DALI_TEST_EQUALS( actor.GetProperty(index), constraintLimit, 0.001f, TEST_LOCATION ); - } - } - catch (Dali::DaliException& e) - { - DALI_TEST_PRINT_ASSERT( e ); - DALI_TEST_CHECK(0); - } - END_TEST; -} - -int UtcDaliConstraintNewQuaternion(void) -{ - TestApplication application; - - Actor actor = Actor::New(); - - // Register a Quaternion property - Quaternion startValue( 0.0f, Vector3::YAXIS ); - Property::Index index = actor.RegisterProperty( "test-property", startValue ); - Stage::GetCurrent().Add(actor); - DALI_TEST_EQUALS( actor.GetProperty(index), startValue, ROTATION_EPSILON, TEST_LOCATION ); - - /** - * Test that the Constraint is correctly applied on a clean Node - */ - application.SendNotification(); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), startValue, ROTATION_EPSILON, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), startValue, ROTATION_EPSILON, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), startValue, ROTATION_EPSILON, TEST_LOCATION ); - - // Apply constraint - - Quaternion constrainedRotation( M_PI*0.25f, Vector3::YAXIS ); - Constraint constraint = Constraint::New( index, TestConstraintRotation( constrainedRotation ) ); - - actor.ApplyConstraint( constraint ); - DALI_TEST_EQUALS( actor.GetProperty(index), startValue, ROTATION_EPSILON, TEST_LOCATION ); - - application.SendNotification(); - application.Render(0); - - // Constraint should be fully applied - DALI_TEST_EQUALS( actor.GetProperty(index), constrainedRotation, ROTATION_EPSILON, TEST_LOCATION ); - - // Check that nothing has changed after a couple of buffer swaps - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), constrainedRotation, ROTATION_EPSILON, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), constrainedRotation, ROTATION_EPSILON, TEST_LOCATION ); - - // Set to a different rotation, the constraint will NOT allow this - Quaternion differentRotation( M_PI*0.5f, Vector3::YAXIS ); - actor.SetProperty( index, differentRotation ); - - application.SendNotification(); - application.Render(0); - - DALI_TEST_EQUALS( actor.GetProperty(index), constrainedRotation/*not differentRotation*/, ROTATION_EPSILON, TEST_LOCATION ); - - // Check that nothing has changed after a couple of buffer swaps - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), constrainedRotation, ROTATION_EPSILON, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), constrainedRotation, ROTATION_EPSILON, TEST_LOCATION ); - - // Remove the constraint, then set new value - actor.RemoveConstraints(); - actor.SetProperty( index, differentRotation ); - - // Constraint should have been removed - application.SendNotification(); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), differentRotation, ROTATION_EPSILON, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), differentRotation, ROTATION_EPSILON, TEST_LOCATION ); - END_TEST; -} - -int UtcDaliConstraintNewOffStageBoolean(void) -{ - TestApplication application; - - Actor actor = Actor::New(); - - // Register a boolean property - bool startValue(false); - Property::Index index = actor.RegisterProperty( "test-property", startValue ); - DALI_TEST_CHECK( actor.GetProperty(index) == startValue ); - - // Apply constraint to off-stage Actor - Constraint constraint = Constraint::New( index, TestAlwaysTrueConstraint() ); - actor.ApplyConstraint( constraint ); - - application.SendNotification(); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), false, TEST_LOCATION ); - - // Add actor to stage - Stage::GetCurrent().Add(actor); - application.SendNotification(); - application.Render(0); - - // Constraint should be fully applied - DALI_TEST_EQUALS( actor.GetProperty(index), true, TEST_LOCATION ); - - // Check that nothing has changed after a couple of buffer swaps - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), true, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), true, TEST_LOCATION ); - - // Take the actor off-stage - Stage::GetCurrent().Remove(actor); - application.SendNotification(); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), true, TEST_LOCATION ); - - // Set a new value; the constraint will not prevent this - actor.SetProperty( index, false ); - application.SendNotification(); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), false, TEST_LOCATION ); - - // Add actor to stage (2nd time) - Stage::GetCurrent().Add(actor); - application.SendNotification(); - application.Render(0); - - // Constraint should be fully applied (2nd time) - DALI_TEST_EQUALS( actor.GetProperty(index), true, TEST_LOCATION ); - - // Check that nothing has changed after a couple of buffer swaps - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), true, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), true, TEST_LOCATION ); - - // Take the actor off-stage (2nd-time) - Stage::GetCurrent().Remove(actor); - application.SendNotification(); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), true, TEST_LOCATION ); - - // Remove the constraint, and set a new value - actor.RemoveConstraints(); - actor.SetProperty( index, false ); - application.SendNotification(); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), false, TEST_LOCATION ); - - // Add actor to stage (3rd time) - Stage::GetCurrent().Add(actor); - application.SendNotification(); - application.Render(0); - - // Constraint should be gone - DALI_TEST_EQUALS( actor.GetProperty(index), false, TEST_LOCATION ); - - // Check that nothing has changed after a couple of buffer swaps - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), false, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), false, TEST_LOCATION ); - END_TEST; -} - -int UtcDaliConstraintNewOffStageFloat(void) -{ - TestApplication application; - - Actor actor = Actor::New(); - - // Register a float property - float startValue(1.0f); - Property::Index index = actor.RegisterProperty( "test-property", startValue ); - DALI_TEST_CHECK( actor.GetProperty(index) == startValue ); - - // Apply constraint to off-stage Actor - float constrainedValue( 2.0f ); - Constraint constraint = Constraint::New( index, TestConstraintFloat( constrainedValue ) ); - actor.ApplyConstraint( constraint ); - - application.SendNotification(); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), startValue, TEST_LOCATION ); - - // Add actor to stage - Stage::GetCurrent().Add(actor); - application.SendNotification(); - application.Render(0); - - // Constraint should be fully applied - DALI_TEST_EQUALS( actor.GetProperty(index), constrainedValue, TEST_LOCATION ); - - // Check that nothing has changed after a couple of buffer swaps - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), constrainedValue, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), constrainedValue, TEST_LOCATION ); - - // Take the actor off-stage - Stage::GetCurrent().Remove(actor); - application.SendNotification(); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), constrainedValue, TEST_LOCATION ); - - // Set back to startValue; the constraint will not prevent this - actor.SetProperty( index, startValue ); - application.SendNotification(); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), startValue, TEST_LOCATION ); - - // Add actor to stage (2nd time) - Stage::GetCurrent().Add(actor); - application.SendNotification(); - application.Render(0); - - // Constraint should be fully applied (2nd time) - DALI_TEST_EQUALS( actor.GetProperty(index), constrainedValue, TEST_LOCATION ); - - // Check that nothing has changed after a couple of buffer swaps - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), constrainedValue, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), constrainedValue, TEST_LOCATION ); - - // Take the actor off-stage (2nd-time) - Stage::GetCurrent().Remove(actor); - application.SendNotification(); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), constrainedValue, TEST_LOCATION ); - - // Remove the constraint, and set back to startValue - actor.RemoveConstraints(); - actor.SetProperty( index, startValue ); - application.SendNotification(); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), startValue, TEST_LOCATION ); - - // Add actor to stage (3rd time) - Stage::GetCurrent().Add(actor); - application.SendNotification(); - application.Render(0); - - // Constraint should be gone - DALI_TEST_EQUALS( actor.GetProperty(index), startValue, TEST_LOCATION ); - - // Check that nothing has changed after a couple of buffer swaps - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), startValue, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), startValue, TEST_LOCATION ); - END_TEST; -} - -int UtcDaliConstraintNewOffStageInteger(void) -{ - TestApplication application; - - Actor actor = Actor::New(); - - // Register an integer property - int startValue(1); - Property::Index index = actor.RegisterProperty( "test-property", startValue ); - DALI_TEST_CHECK( actor.GetProperty(index) == startValue ); - - // Apply constraint to off-stage Actor - int constrainedValue( 2 ); - Constraint constraint = Constraint::New( index, TestConstraintInteger( constrainedValue ) ); - actor.ApplyConstraint( constraint ); - - application.SendNotification(); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), startValue, TEST_LOCATION ); - - // Add actor to stage - Stage::GetCurrent().Add(actor); - application.SendNotification(); - application.Render(0); - - // Constraint should be fully applied - DALI_TEST_EQUALS( actor.GetProperty(index), constrainedValue, TEST_LOCATION ); - - // Check that nothing has changed after a couple of buffer swaps - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), constrainedValue, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), constrainedValue, TEST_LOCATION ); - - // Take the actor off-stage - Stage::GetCurrent().Remove(actor); - application.SendNotification(); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), constrainedValue, TEST_LOCATION ); - - // Set back to startValue; the constraint will not prevent this - actor.SetProperty( index, startValue ); - application.SendNotification(); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), startValue, TEST_LOCATION ); - - // Add actor to stage (2nd time) - Stage::GetCurrent().Add(actor); - application.SendNotification(); - application.Render(0); - - // Constraint should be fully applied (2nd time) - DALI_TEST_EQUALS( actor.GetProperty(index), constrainedValue, TEST_LOCATION ); - - // Check that nothing has changed after a couple of buffer swaps - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), constrainedValue, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), constrainedValue, TEST_LOCATION ); - - // Take the actor off-stage (2nd-time) - Stage::GetCurrent().Remove(actor); - application.SendNotification(); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), constrainedValue, TEST_LOCATION ); - - // Remove the constraint, and set back to startValue - actor.RemoveConstraints(); - actor.SetProperty( index, startValue ); - application.SendNotification(); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), startValue, TEST_LOCATION ); - - // Add actor to stage (3rd time) - Stage::GetCurrent().Add(actor); - application.SendNotification(); - application.Render(0); - - // Constraint should be gone - DALI_TEST_EQUALS( actor.GetProperty(index), startValue, TEST_LOCATION ); - - // Check that nothing has changed after a couple of buffer swaps - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), startValue, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), startValue, TEST_LOCATION ); - END_TEST; -} - -int UtcDaliConstraintNewOffStageUnsignedInteger(void) -{ - TestApplication application; - - Actor actor = Actor::New(); - - // Register an integer property - unsigned int startValue(1); - Property::Index index = actor.RegisterProperty( "test-property", startValue ); - DALI_TEST_CHECK( actor.GetProperty(index) == startValue ); - - // Apply constraint to off-stage Actor - unsigned int constrainedValue( 2 ); - Constraint constraint = Constraint::New( index, TestConstraintUnsignedInteger( constrainedValue ) ); - actor.ApplyConstraint( constraint ); - - application.SendNotification(); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), startValue, TEST_LOCATION ); - - // Add actor to stage - Stage::GetCurrent().Add(actor); - application.SendNotification(); - application.Render(0); - - // Constraint should be fully applied - DALI_TEST_EQUALS( actor.GetProperty(index), constrainedValue, TEST_LOCATION ); - - // Check that nothing has changed after a couple of buffer swaps - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), constrainedValue, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), constrainedValue, TEST_LOCATION ); - - // Take the actor off-stage - Stage::GetCurrent().Remove(actor); - application.SendNotification(); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), constrainedValue, TEST_LOCATION ); - - // Set back to startValue; the constraint will not prevent this - actor.SetProperty( index, startValue ); - application.SendNotification(); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), startValue, TEST_LOCATION ); - - // Add actor to stage (2nd time) - Stage::GetCurrent().Add(actor); - application.SendNotification(); - application.Render(0); - - // Constraint should be fully applied (2nd time) - DALI_TEST_EQUALS( actor.GetProperty(index), constrainedValue, TEST_LOCATION ); - - // Check that nothing has changed after a couple of buffer swaps - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), constrainedValue, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), constrainedValue, TEST_LOCATION ); - - // Take the actor off-stage (2nd-time) - Stage::GetCurrent().Remove(actor); - application.SendNotification(); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), constrainedValue, TEST_LOCATION ); - - // Remove the constraint, and set back to startValue - actor.RemoveConstraints(); - actor.SetProperty( index, startValue ); - application.SendNotification(); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), startValue, TEST_LOCATION ); - - // Add actor to stage (3rd time) - Stage::GetCurrent().Add(actor); - application.SendNotification(); - application.Render(0); - - // Constraint should be gone - DALI_TEST_EQUALS( actor.GetProperty(index), startValue, TEST_LOCATION ); - - // Check that nothing has changed after a couple of buffer swaps - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), startValue, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), startValue, TEST_LOCATION ); - END_TEST; -} - - -int UtcDaliConstraintNewOffStageVector2(void) -{ - TestApplication application; - - Actor actor = Actor::New(); - - // Register a Vector2 property - Vector2 startValue(1.0f, 1.0f); - Property::Index index = actor.RegisterProperty( "test-property", startValue ); - DALI_TEST_CHECK( actor.GetProperty(index) == startValue ); - - // Apply constraint to off-stage Actor - Vector2 constrainedValue( 2.0f, 2.0f ); - Constraint constraint = Constraint::New( index, TestConstraintVector2( constrainedValue ) ); - actor.ApplyConstraint( constraint ); - - application.SendNotification(); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), startValue, TEST_LOCATION ); - - // Add actor to stage - Stage::GetCurrent().Add(actor); - application.SendNotification(); - application.Render(0); - - // Constraint should be fully applied - DALI_TEST_EQUALS( actor.GetProperty(index), constrainedValue, TEST_LOCATION ); - - // Check that nothing has changed after a couple of buffer swaps - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), constrainedValue, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), constrainedValue, TEST_LOCATION ); - - // Take the actor off-stage - Stage::GetCurrent().Remove(actor); - application.SendNotification(); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), constrainedValue, TEST_LOCATION ); - - // Set back to startValue; the constraint will not prevent this - actor.SetProperty( index, startValue ); - application.SendNotification(); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), startValue, TEST_LOCATION ); - - // Add actor to stage (2nd time) - Stage::GetCurrent().Add(actor); - application.SendNotification(); - application.Render(0); - - // Constraint should be fully applied (2nd time) - DALI_TEST_EQUALS( actor.GetProperty(index), constrainedValue, TEST_LOCATION ); - - // Check that nothing has changed after a couple of buffer swaps - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), constrainedValue, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), constrainedValue, TEST_LOCATION ); - - // Take the actor off-stage (2nd-time) - Stage::GetCurrent().Remove(actor); - application.SendNotification(); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), constrainedValue, TEST_LOCATION ); - - // Remove the constraint, and set back to startValue - actor.RemoveConstraints(); - actor.SetProperty( index, startValue ); - application.SendNotification(); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), startValue, TEST_LOCATION ); - - // Add actor to stage (3rd time) - Stage::GetCurrent().Add(actor); - application.SendNotification(); - application.Render(0); - - // Constraint should be gone - DALI_TEST_EQUALS( actor.GetProperty(index), startValue, TEST_LOCATION ); - - // Check that nothing has changed after a couple of buffer swaps - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), startValue, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), startValue, TEST_LOCATION ); - END_TEST; -} - -int UtcDaliConstraintNewOffStageVector3(void) -{ - TestApplication application; - Vector3 startValue(1.0f, 1.0f, 1.0f); - Vector3 constrainedValue = Vector3( 2.0f, 3.0f, 4.0f ); - - Actor actor = Actor::New(); - // Register a Vector3 property - - Property::Index index = actor.RegisterProperty( "test-property", startValue ); - DALI_TEST_CHECK( actor.GetProperty(index) == startValue ); - - // Apply constraint to off-stage Actor - Constraint constraint = Constraint::New( index, TestConstraintVector3( constrainedValue ) ); - actor.ApplyConstraint( constraint ); - - application.SendNotification(); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), startValue, TEST_LOCATION ); - - // Add actor to stage - Stage::GetCurrent().Add(actor); - application.SendNotification(); - application.Render(); - - // Constraint should be fully applied - DALI_TEST_EQUALS( actor.GetProperty(index), constrainedValue, TEST_LOCATION ); - - // Check that nothing has changed after a couple of buffer swaps - application.Render(); - DALI_TEST_EQUALS( actor.GetProperty(index), constrainedValue, TEST_LOCATION ); - application.Render(); - DALI_TEST_EQUALS( actor.GetProperty(index), constrainedValue, TEST_LOCATION ); - - // Take the actor off-stage - Stage::GetCurrent().Remove(actor); - application.SendNotification(); - application.Render(); - DALI_TEST_EQUALS( actor.GetProperty(index), constrainedValue, TEST_LOCATION ); - - // Set back to startValue; the constraint will not prevent this - Vector3 intermediateValue(5.0f, 6.0f, 7.0f); - actor.SetProperty( index, intermediateValue ); - application.SendNotification(); - application.Render(); - application.Render(); // ensure both buffers are set to intermediateValue - DALI_TEST_EQUALS( actor.GetProperty(index), intermediateValue, TEST_LOCATION ); - - // Add actor to stage (2nd time) - Stage::GetCurrent().Add(actor); - application.SendNotification(); - application.Render(); - - // Constraint should be fully applied (2nd time) - DALI_TEST_EQUALS( actor.GetProperty(index), constrainedValue, TEST_LOCATION ); - - // Check that nothing has changed after a couple of buffer swaps - application.Render(); - DALI_TEST_EQUALS( actor.GetProperty(index), constrainedValue, TEST_LOCATION ); - application.Render(); - DALI_TEST_EQUALS( actor.GetProperty(index), constrainedValue, TEST_LOCATION ); - - // Take the actor off-stage (2nd-time) - Stage::GetCurrent().Remove(actor); - application.SendNotification(); - application.Render(); - DALI_TEST_EQUALS( actor.GetProperty(index), constrainedValue, TEST_LOCATION ); - - // Remove the constraint, and set back to startValue - actor.RemoveConstraints(); - actor.SetProperty( index, startValue ); - application.SendNotification(); - application.Render(); - DALI_TEST_EQUALS( actor.GetProperty(index), startValue, TEST_LOCATION ); - - // Add actor to stage (3rd time) - Stage::GetCurrent().Add(actor); - application.SendNotification(); - application.Render(); - - // Constraint should be gone - DALI_TEST_EQUALS( actor.GetProperty(index), startValue, TEST_LOCATION ); - - // Check that nothing has changed after a couple of buffer swaps - application.Render(); - DALI_TEST_EQUALS( actor.GetProperty(index), startValue, TEST_LOCATION ); - application.Render(); - DALI_TEST_EQUALS( actor.GetProperty(index), startValue, TEST_LOCATION ); - END_TEST; -} - -int UtcDaliConstraintNewOffStageVector4(void) -{ - TestApplication application; - - Actor actor = Actor::New(); - - // Register a Vector4 property - Vector4 startValue(1.0f, 1.0f, 1.0f, 1.0f); - Property::Index index = actor.RegisterProperty( "test-property", startValue ); - DALI_TEST_CHECK( actor.GetProperty(index) == startValue ); - - // Apply constraint to off-stage Actor - Vector4 constrainedValue( 2.0f, 2.0f, 2.0f, 2.0f ); - Constraint constraint = Constraint::New( index, TestConstraintVector4( constrainedValue ) ); - actor.ApplyConstraint( constraint ); - - application.SendNotification(); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), startValue, TEST_LOCATION ); - - // Add actor to stage - Stage::GetCurrent().Add(actor); - application.SendNotification(); - application.Render(0); - - // Constraint should be fully applied - DALI_TEST_EQUALS( actor.GetProperty(index), constrainedValue, TEST_LOCATION ); - - // Check that nothing has changed after a couple of buffer swaps - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), constrainedValue, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), constrainedValue, TEST_LOCATION ); - - // Take the actor off-stage - Stage::GetCurrent().Remove(actor); - application.SendNotification(); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), constrainedValue, TEST_LOCATION ); - - // Set back to startValue; the constraint will not prevent this - actor.SetProperty( index, startValue ); - application.SendNotification(); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), startValue, TEST_LOCATION ); - - // Add actor to stage (2nd time) - Stage::GetCurrent().Add(actor); - application.SendNotification(); - application.Render(0); - - // Constraint should be fully applied (2nd time) - DALI_TEST_EQUALS( actor.GetProperty(index), constrainedValue, TEST_LOCATION ); - - // Check that nothing has changed after a couple of buffer swaps - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), constrainedValue, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), constrainedValue, TEST_LOCATION ); - - // Take the actor off-stage (2nd-time) - Stage::GetCurrent().Remove(actor); - application.SendNotification(); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), constrainedValue, TEST_LOCATION ); - - // Remove the constraint, and set back to startValue - actor.RemoveConstraints(); - actor.SetProperty( index, startValue ); - application.SendNotification(); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), startValue, TEST_LOCATION ); - - // Add actor to stage (3rd time) - Stage::GetCurrent().Add(actor); - application.SendNotification(); - application.Render(0); - - // Constraint should be gone - DALI_TEST_EQUALS( actor.GetProperty(index), startValue, TEST_LOCATION ); - - // Check that nothing has changed after a couple of buffer swaps - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), startValue, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), startValue, TEST_LOCATION ); - END_TEST; -} - -int UtcDaliConstraintNewOffStageQuaternion(void) -{ - TestApplication application; - - Actor actor = Actor::New(); - - // Register a Quaternion property - Quaternion startValue( 0.0f, Vector3::YAXIS ); - Property::Index index = actor.RegisterProperty( "test-property", startValue ); - DALI_TEST_EQUALS( actor.GetProperty(index), startValue, ROTATION_EPSILON, TEST_LOCATION ); - - // Apply constraint to off-stage Actor - Quaternion constrainedRotation( M_PI*0.25f, Vector3::YAXIS ); - Constraint constraint = Constraint::New( index, TestConstraintRotation( constrainedRotation ) ); - actor.ApplyConstraint( constraint ); - - application.SendNotification(); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), startValue, ROTATION_EPSILON, TEST_LOCATION ); - - // Add actor to stage - Stage::GetCurrent().Add(actor); - application.SendNotification(); - application.Render(0); - - // Constraint should be fully applied - DALI_TEST_EQUALS( actor.GetProperty(index), constrainedRotation, ROTATION_EPSILON, TEST_LOCATION ); - - // Check that nothing has changed after a couple of buffer swaps - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), constrainedRotation, ROTATION_EPSILON, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), constrainedRotation, ROTATION_EPSILON, TEST_LOCATION ); - - // Take the actor off-stage - Stage::GetCurrent().Remove(actor); - application.SendNotification(); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), constrainedRotation, ROTATION_EPSILON, TEST_LOCATION ); - - // Set back to startValue; the constraint will not prevent this - actor.SetProperty( index, startValue ); - application.SendNotification(); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), startValue, ROTATION_EPSILON, TEST_LOCATION ); - - // Add actor to stage (2nd time) - Stage::GetCurrent().Add(actor); - application.SendNotification(); - application.Render(0); - - // Constraint should be fully applied (2nd time) - DALI_TEST_EQUALS( actor.GetProperty(index), constrainedRotation, ROTATION_EPSILON, TEST_LOCATION ); - - // Check that nothing has changed after a couple of buffer swaps - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), constrainedRotation, ROTATION_EPSILON, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), constrainedRotation, ROTATION_EPSILON, TEST_LOCATION ); - - // Take the actor off-stage (2nd-time) - Stage::GetCurrent().Remove(actor); - application.SendNotification(); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), constrainedRotation, ROTATION_EPSILON, TEST_LOCATION ); - - // Remove the constraint, and set back to startValue - actor.RemoveConstraints(); - actor.SetProperty( index, startValue ); - application.SendNotification(); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), startValue, ROTATION_EPSILON, TEST_LOCATION ); - - // Add actor to stage (3rd time) - Stage::GetCurrent().Add(actor); - application.SendNotification(); - application.Render(0); - - // Constraint should be gone - DALI_TEST_EQUALS( actor.GetProperty(index), startValue, ROTATION_EPSILON, TEST_LOCATION ); - - // Check that nothing has changed after a couple of buffer swaps - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), startValue, ROTATION_EPSILON, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), startValue, ROTATION_EPSILON, TEST_LOCATION ); - END_TEST; -} - -int UtcDaliConstraintNewLocalInput(void) -{ - TestApplication application; - - Actor actor = Actor::New(); - Stage::GetCurrent().Add(actor); - - Vector3 startValue( 0.0f, 0.0f, 0.0f ); - float distanceWhenFullyTransparent( 100.0f ); - - /** - * Test that the Constraint is correctly applied on a clean Node - */ - application.SendNotification(); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::POSITION ), startValue, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::POSITION ), startValue, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::POSITION ), startValue, TEST_LOCATION ); - - // Apply constraint with a local input property - - Constraint constraint = Constraint::New( Actor::Property::POSITION, - LocalSource( Actor::Property::COLOR ), - MoveAwayWithFadeConstraint(distanceWhenFullyTransparent) ); - - actor.ApplyConstraint( constraint ); - DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::POSITION ), startValue, TEST_LOCATION ); - - application.SendNotification(); - application.Render(0); - - // Gradually set the color to fully-transparent; the actor should move back - - for ( float progress = 0.0f; progress < 1.1f; progress += 0.1f ) - { - actor.SetOpacity( 1.0f - progress ); - - application.SendNotification(); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::POSITION ), ( startValue - Vector3(0.0f, 0.0f, progress*distanceWhenFullyTransparent) ), POSITION_EPSILON, TEST_LOCATION ); - } - DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::POSITION ), ( startValue - Vector3(0.0f, 0.0f, distanceWhenFullyTransparent) ), POSITION_EPSILON, TEST_LOCATION ); - END_TEST; -} - -int UtcDaliConstraintNewParentInput(void) -{ - TestApplication application; - - Actor parent = Actor::New(); - Vector3 parentStartSize( 100.0f, 100.0f, 0.0f ); - parent.SetSize( parentStartSize ); - Stage::GetCurrent().Add( parent ); - - Actor actor = Actor::New(); - parent.Add( actor ); - - Vector3 startValue( 0.0f, 0.0f, 0.0f ); - - /** - * Test that the Constraint is correctly applied on a clean Node - */ - application.SendNotification(); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::POSITION ), startValue, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::POSITION ), startValue, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::POSITION ), startValue, TEST_LOCATION ); - - // Apply constraint with a parent input property - - Constraint constraint = Constraint::New( Actor::Property::POSITION, - ParentSource( Actor::Property::SIZE ), - TestBottomRightAlignConstraint() ); - - actor.ApplyConstraint( constraint ); - DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::POSITION ), startValue, TEST_LOCATION ); - - application.SendNotification(); - application.Render(0); - - DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::POSITION ), parentStartSize, TEST_LOCATION ); - DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::POSITION ), parent.GetCurrentSize(), TEST_LOCATION ); - - // Gradually shrink the parent; the actor should move inwards - - for ( float progress = 0.0f; progress < 1.1f; progress += 0.1f ) - { - Vector3 size( parentStartSize * std::max(0.0f, 1.0f - progress) ); - parent.SetSize( size ); - - application.SendNotification(); - application.Render(0); - - DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::POSITION ), size, POSITION_EPSILON, TEST_LOCATION ); - DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::POSITION ), parent.GetCurrentSize(), POSITION_EPSILON, TEST_LOCATION ); - } - DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::POSITION ), Vector3::ZERO, POSITION_EPSILON, TEST_LOCATION ); - END_TEST; -} - -int UtcDaliConstraintNewInput1(void) -{ - TestApplication application; - - Actor parent = Actor::New(); - Vector3 parentStartSize( 100.0f, 100.0f, 0.0f ); - parent.SetSize( parentStartSize ); - Stage::GetCurrent().Add( parent ); - - Actor actor = Actor::New(); - parent.Add( actor ); - - Actor sibling1 = Actor::New(); - sibling1.SetPosition( Vector3(1.0f, 2.0f, 3.0f) ); - parent.Add( sibling1 ); - - Vector3 startValue( 0.0f, 0.0f, 0.0f ); - - /** - * Test that the Constraint is correctly applied on a clean Node - */ - application.SendNotification(); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::POSITION ), startValue, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::POSITION ), startValue, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::POSITION ), startValue, TEST_LOCATION ); - - // Apply constraint with a parent input property - - Constraint constraint = Constraint::New( Actor::Property::POSITION, - Source( sibling1, Actor::Property::POSITION ), - MeanPositionConstraint1() ); - - actor.ApplyConstraint( constraint ); - DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::POSITION ), startValue, TEST_LOCATION ); - - application.SendNotification(); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::POSITION ), sibling1.GetCurrentPosition(), TEST_LOCATION ); - - // Check that nothing has changed after a couple of buffer swaps - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::POSITION ), sibling1.GetCurrentPosition(), TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::POSITION ), sibling1.GetCurrentPosition(), TEST_LOCATION ); - END_TEST; -} - -int UtcDaliConstraintNewInput2(void) -{ - TestApplication application; - - Actor parent = Actor::New(); - Vector3 parentStartSize( 100.0f, 100.0f, 0.0f ); - parent.SetSize( parentStartSize ); - Stage::GetCurrent().Add( parent ); - - Actor actor = Actor::New(); - parent.Add( actor ); - - Actor sibling1 = Actor::New(); - sibling1.SetPosition( Vector3(1.0f, 2.0f, 3.0f) ); - parent.Add( sibling1 ); - - Actor sibling2 = Actor::New(); - sibling2.SetPosition( Vector3(300.0f, 300.0f, 300.0f) ); - parent.Add( sibling2 ); - - application.SendNotification(); - application.Render(0); - - Vector3 startValue( 0.0f, 0.0f, 0.0f ); - Vector3 meanValue = sibling1.GetCurrentPosition() + - sibling2.GetCurrentPosition(); - meanValue *= (1.0f / 2.0f); // divide by number of siblings - - /** - * Test that the Constraint is correctly applied on a clean Node - */ - application.SendNotification(); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::POSITION ), startValue, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::POSITION ), startValue, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::POSITION ), startValue, TEST_LOCATION ); - - // Apply constraint with a parent input property - - Constraint constraint = Constraint::New( Actor::Property::POSITION, - Source( sibling1, Actor::Property::POSITION ), - Source( sibling2, Actor::Property::POSITION ), - MeanPositionConstraint2() ); - - actor.ApplyConstraint( constraint ); - DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::POSITION ), startValue, TEST_LOCATION ); - - application.SendNotification(); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION ); - - // Check that nothing has changed after a couple of buffer swaps - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION ); - END_TEST; -} - -int UtcDaliConstraintNewInput3(void) -{ - TestApplication application; - - Actor parent = Actor::New(); - Vector3 parentStartSize( 100.0f, 100.0f, 0.0f ); - parent.SetSize( parentStartSize ); - Stage::GetCurrent().Add( parent ); - - Actor actor = Actor::New(); - parent.Add( actor ); - - Actor sibling1 = Actor::New(); - sibling1.SetPosition( Vector3(1.0f, 2.0f, 3.0f) ); - parent.Add( sibling1 ); - - Actor sibling2 = Actor::New(); - sibling2.SetPosition( Vector3(300.0f, 300.0f, 300.0f) ); - parent.Add( sibling2 ); - - Actor sibling3 = Actor::New(); - sibling3.SetPosition( Vector3(-100.0f, -10.0f, -1.0f) ); - parent.Add( sibling3 ); - - application.SendNotification(); - application.Render(0); - - Vector3 startValue( 0.0f, 0.0f, 0.0f ); - Vector3 meanValue = sibling1.GetCurrentPosition() + - sibling2.GetCurrentPosition() + - sibling3.GetCurrentPosition(); - meanValue *= (1.0f / 3.0f); // divide by number of siblings - - /** - * Test that the Constraint is correctly applied on a clean Node - */ - application.SendNotification(); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::POSITION ), startValue, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::POSITION ), startValue, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::POSITION ), startValue, TEST_LOCATION ); - - // Apply constraint with a parent input property - - Constraint constraint = Constraint::New( Actor::Property::POSITION, - Source( sibling1, Actor::Property::POSITION ), - Source( sibling2, Actor::Property::POSITION ), - Source( sibling3, Actor::Property::POSITION ), - MeanPositionConstraint3() ); - - actor.ApplyConstraint( constraint ); - DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::POSITION ), startValue, TEST_LOCATION ); - - application.SendNotification(); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION ); - - // Check that nothing has changed after a couple of buffer swaps - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION ); - END_TEST; -} - -int UtcDaliConstraintNewInput4(void) -{ - TestApplication application; - - Actor parent = Actor::New(); - Vector3 parentStartSize( 100.0f, 100.0f, 0.0f ); - parent.SetSize( parentStartSize ); - parent.SetPosition( 10.0f, 10.0f, 10.0f ); - Stage::GetCurrent().Add( parent ); - - Actor actor = Actor::New(); - parent.Add( actor ); - - Actor sibling1 = Actor::New(); - sibling1.SetPosition( Vector3(1.0f, 2.0f, 3.0f) ); - parent.Add( sibling1 ); - - Actor sibling2 = Actor::New(); - sibling2.SetPosition( Vector3(300.0f, 300.0f, 300.0f) ); - parent.Add( sibling2 ); - - Actor sibling3 = Actor::New(); - sibling3.SetPosition( Vector3(-100.0f, -10.0f, -1.0f) ); - parent.Add( sibling3 ); - - application.SendNotification(); - application.Render(0); - - Vector3 startValue( 0.0f, 0.0f, 0.0f ); - Vector3 meanValue = parent.GetCurrentPosition() + - sibling1.GetCurrentPosition() + - sibling2.GetCurrentPosition() + - sibling3.GetCurrentPosition(); - meanValue *= (1.0f / 4.0f); // divide by number of positions - - /** - * Test that the Constraint is correctly applied on a clean Node - */ - application.SendNotification(); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::POSITION ), startValue, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::POSITION ), startValue, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::POSITION ), startValue, TEST_LOCATION ); - - // Apply constraint with a parent input property - - Constraint constraint = Constraint::New( Actor::Property::POSITION, - Source( sibling1, Actor::Property::POSITION ), - Source( sibling2, Actor::Property::POSITION ), - ParentSource( Actor::Property::POSITION ), - Source( sibling3, Actor::Property::POSITION ), - MeanPositionConstraint4() ); - - actor.ApplyConstraint( constraint ); - DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::POSITION ), startValue, TEST_LOCATION ); - - application.SendNotification(); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION ); - - // Check that nothing has changed after a couple of buffer swaps - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION ); - END_TEST; -} - -int UtcDaliConstraintNewInput5(void) -{ - TestApplication application; - - Actor parent = Actor::New(); - Vector3 parentStartSize( 100.0f, 100.0f, 0.0f ); - parent.SetSize( parentStartSize ); - parent.SetPosition( 10.0f, 10.0f, 10.0f ); - Stage::GetCurrent().Add( parent ); - - Actor actor = Actor::New(); - parent.Add( actor ); - - Actor sibling1 = Actor::New(); - sibling1.SetPosition( Vector3(1.0f, 2.0f, 3.0f) ); - parent.Add( sibling1 ); - - Actor sibling2 = Actor::New(); - sibling2.SetPosition( Vector3(300.0f, 300.0f, 300.0f) ); - parent.Add( sibling2 ); - - Actor sibling3 = Actor::New(); - sibling3.SetPosition( Vector3(-100.0f, -10.0f, -1.0f) ); - parent.Add( sibling3 ); - - Actor sibling4 = Actor::New(); - sibling4.SetPosition( Vector3(-1.0f, 1.0f, 2.0f) ); - parent.Add( sibling4 ); - - application.SendNotification(); - application.Render(0); - - Vector3 startValue( 0.0f, 0.0f, 0.0f ); - Vector3 meanValue = parent.GetCurrentPosition() + - sibling1.GetCurrentPosition() + - sibling2.GetCurrentPosition() + - sibling3.GetCurrentPosition() + - sibling4.GetCurrentPosition(); - meanValue *= (1.0f / 5.0f); // divide by number of positions - - /** - * Test that the Constraint is correctly applied on a clean Node - */ - application.SendNotification(); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::POSITION ), startValue, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::POSITION ), startValue, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::POSITION ), startValue, TEST_LOCATION ); - - // Apply constraint with a parent input property - - Constraint constraint = Constraint::New( Actor::Property::POSITION, - Source( sibling1, Actor::Property::POSITION ), - Source( sibling2, Actor::Property::POSITION ), - ParentSource( Actor::Property::POSITION ), - Source( sibling3, Actor::Property::POSITION ), - Source( sibling4, Actor::Property::POSITION ), - MeanPositionConstraint5() ); - - actor.ApplyConstraint( constraint ); - DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::POSITION ), startValue, TEST_LOCATION ); - - application.SendNotification(); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION ); - - // Check that nothing has changed after a couple of buffer swaps - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION ); - END_TEST; -} - -int UtcDaliConstraintNewInput6(void) -{ - TestApplication application; - - Actor parent = Actor::New(); - Vector3 parentStartSize( 100.0f, 100.0f, 0.0f ); - parent.SetSize( parentStartSize ); - parent.SetPosition( 10.0f, 10.0f, 10.0f ); - Stage::GetCurrent().Add( parent ); - - Actor actor = Actor::New(); - parent.Add( actor ); - - Actor child = Actor::New(); - child.SetPosition( Vector3(7.0f, 7.0f, 7.0f) ); - actor.Add( child ); - - Actor sibling1 = Actor::New(); - sibling1.SetPosition( Vector3(1.0f, 2.0f, 3.0f) ); - parent.Add( sibling1 ); - - Actor sibling2 = Actor::New(); - sibling2.SetPosition( Vector3(300.0f, 300.0f, 300.0f) ); - parent.Add( sibling2 ); - - Actor sibling3 = Actor::New(); - sibling3.SetPosition( Vector3(-100.0f, -10.0f, -1.0f) ); - parent.Add( sibling3 ); - - Actor sibling4 = Actor::New(); - sibling4.SetPosition( Vector3(-1.0f, 1.0f, 2.0f) ); - parent.Add( sibling4 ); - - application.SendNotification(); - application.Render(0); - - Vector3 startValue( 0.0f, 0.0f, 0.0f ); - Vector3 meanValue = parent.GetCurrentPosition() + - child.GetCurrentPosition() + - sibling1.GetCurrentPosition() + - sibling2.GetCurrentPosition() + - sibling3.GetCurrentPosition() + - sibling4.GetCurrentPosition(); - meanValue *= (1.0f / 6.0f); // divide by number of positions - - /** - * Test that the Constraint is correctly applied on a clean Node - */ - application.SendNotification(); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::POSITION ), startValue, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::POSITION ), startValue, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::POSITION ), startValue, TEST_LOCATION ); - - // Apply constraint with a parent input property - - Constraint constraint = Constraint::New( Actor::Property::POSITION, - Source( child, Actor::Property::POSITION ), - Source( sibling1, Actor::Property::POSITION ), - Source( sibling2, Actor::Property::POSITION ), - ParentSource( Actor::Property::POSITION ), - Source( sibling3, Actor::Property::POSITION ), - Source( sibling4, Actor::Property::POSITION ), - MeanPositionConstraint6() ); - - actor.ApplyConstraint( constraint ); - DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::POSITION ), startValue, TEST_LOCATION ); - - application.SendNotification(); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION ); - - // Check that nothing has changed after a couple of buffer swaps - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::POSITION ), meanValue, POSITION_EPSILON, TEST_LOCATION ); - END_TEST; -} - -int UtcDaliConstraintDownCast(void) -{ - TestApplication application; - tet_infoline("Testing Dali::Constraint::DownCast()"); - - Actor actor = Actor::New(); - - // Register a boolean property - bool startValue(false); - Property::Index index = actor.RegisterProperty( "test-property", startValue ); - Constraint constraint = Constraint::New( index, TestAlwaysTrueConstraint() ); - - BaseHandle object(constraint); - - Constraint constraint2 = Constraint::DownCast(object); - DALI_TEST_CHECK(constraint2); - - Constraint constraint3 = DownCast< Constraint >(object); - DALI_TEST_CHECK(constraint3); - - BaseHandle unInitializedObject; - Constraint constraint4 = Constraint::DownCast(unInitializedObject); - DALI_TEST_CHECK(!constraint4); - - Constraint constraint5 = DownCast< Constraint >(unInitializedObject); - DALI_TEST_CHECK(!constraint5); - END_TEST; -} - -int UtcDaliConstraintSetApplyTime(void) -{ - TestApplication application; - - // Build constraint - - Vector4 targetColor(Color::BLACK); - Constraint constraint = Constraint::New( Actor::Property::COLOR, TestColorConstraint(targetColor) ); - DALI_TEST_EQUALS(constraint.GetApplyTime(), TimePeriod(0.0f), TEST_LOCATION); - - float applySeconds(7.0f); - constraint.SetApplyTime(applySeconds); - DALI_TEST_EQUALS(constraint.GetApplyTime(), TimePeriod(applySeconds), TEST_LOCATION); - - // Apply to an actor - - Actor actor = Actor::New(); - Stage::GetCurrent().Add(actor); - - actor.ApplyConstraint( constraint ); - DALI_TEST_EQUALS( actor.GetCurrentColor(), Color::WHITE, TEST_LOCATION ); - - application.SendNotification(); - application.Render(static_cast(applySeconds*200.0f)/* 20% progress */); - - // Constraint shouldn't be fully applied yet - Vector4 twentyPercentColor( Color::WHITE.x*0.8f, Color::WHITE.y*0.8f, Color::WHITE.z*0.8f, Color::WHITE.a ); - DALI_TEST_EQUALS( actor.GetCurrentColor(), twentyPercentColor, TEST_LOCATION ); - - // Constraint shouldn't be fully applied yet - application.Render(static_cast(applySeconds*200.0f)/* 40% progress */); - Vector4 fourtyPercentColor( Color::WHITE.x*0.6f, Color::WHITE.y*0.6f, Color::WHITE.z*0.6f, Color::WHITE.a ); - DALI_TEST_EQUALS( actor.GetCurrentColor(), fourtyPercentColor, TEST_LOCATION ); - - // Constraint shouldn't be fully applied yet - application.Render(static_cast(applySeconds*200.0f)/* 60% progress */); - Vector4 sixtyPercentColor( Color::WHITE.x*0.4f, Color::WHITE.y*0.4f, Color::WHITE.z*0.4f, Color::WHITE.a ); - DALI_TEST_EQUALS( actor.GetCurrentColor(), sixtyPercentColor, TEST_LOCATION ); - - // Constraint shouldn't be fully applied yet - application.Render(static_cast(applySeconds*200.0f)/* 80% progress */); - Vector4 eightyPercentColor( Color::WHITE.x*0.2f, Color::WHITE.y*0.2f, Color::WHITE.z*0.2f, Color::WHITE.a ); - DALI_TEST_EQUALS( actor.GetCurrentColor(), eightyPercentColor, TEST_LOCATION ); - - // Constraint should be fully applied - application.Render(static_cast(applySeconds*200.0f)/* 100% progress */); - DALI_TEST_EQUALS( actor.GetCurrentColor(), targetColor, TEST_LOCATION ); - - // Constraint should still be fully applied - application.Render(static_cast(applySeconds*200.0f)/* Still 100% progress */); - DALI_TEST_EQUALS( actor.GetCurrentColor(), targetColor, TEST_LOCATION ); - - // Check that nothing has changed after a couple of buffer swaps - application.Render(0); - DALI_TEST_EQUALS( actor.GetCurrentColor(), targetColor, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor.GetCurrentColor(), targetColor, TEST_LOCATION ); - END_TEST; -} - -int UtcDaliConstraintGetApplyTime(void) -{ - TestApplication application; - - Constraint constraint = Constraint::New( Actor::Property::COLOR, TestConstraint() ); - DALI_TEST_EQUALS(constraint.GetApplyTime(), TimePeriod(0.0f), TEST_LOCATION); - - float applySeconds(7.0f); - constraint.SetApplyTime(applySeconds); - DALI_TEST_EQUALS(constraint.GetApplyTime(), TimePeriod(applySeconds), TEST_LOCATION); - - constraint.SetApplyTime(applySeconds - 3.0f); - DALI_TEST_EQUALS(constraint.GetApplyTime(), TimePeriod(applySeconds - 3.0f), TEST_LOCATION); - END_TEST; -} - -int UtcDaliConstraintSetAlphaFunction(void) -{ - TestApplication application; - - Vector3 startValue( Vector3::ZERO ); - Vector3 targetValue(100.0f, 100.0f, 100.0f); - - Constraint constraint = Constraint::New( Actor::Property::POSITION, - TestConstraintVector3( targetValue ) ); - - // Test the alpha-function itself - - AlphaFunction func = constraint.GetAlphaFunction(); - DALI_TEST_EQUALS(func.GetBuiltinFunction(), AlphaFunction::DEFAULT, TEST_LOCATION); // Default is Linear - - // Test that the alpha-function is used correctly - - Actor actor = Actor::New(); - Stage::GetCurrent().Add(actor); - - application.SendNotification(); - application.Render(static_cast(1000.0f/*1 second*/)); - DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::POSITION ), startValue, TEST_LOCATION ); - application.Render(static_cast(1000.0f/*1 second*/)); - DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::POSITION ), startValue, TEST_LOCATION ); - application.Render(static_cast(1000.0f/*1 second*/)); - DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::POSITION ), startValue, TEST_LOCATION ); - - constraint.SetApplyTime( 10.0f ); - actor.ApplyConstraint( constraint ); - - application.SendNotification(); - application.Render(static_cast(1000.0f/*1 second*/)); - DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::POSITION ), (targetValue - startValue) * 0.1f, TEST_LOCATION ); - application.Render(static_cast(1000.0f/*1 second*/)); - DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::POSITION ), (targetValue - startValue) * 0.2f, TEST_LOCATION ); - application.Render(static_cast(1000.0f/*1 second*/)); - DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::POSITION ), (targetValue - startValue) * 0.3f, TEST_LOCATION ); - application.Render(static_cast(1000.0f/*1 second*/)); - DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::POSITION ), (targetValue - startValue) * 0.4f, TEST_LOCATION ); - application.Render(static_cast(1000.0f/*1 second*/)); - DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::POSITION ), (targetValue - startValue) * 0.5f, TEST_LOCATION ); - application.Render(static_cast(1000.0f/*1 second*/)); - DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::POSITION ), (targetValue - startValue) * 0.6f, TEST_LOCATION ); - application.Render(static_cast(1000.0f/*1 second*/)); - DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::POSITION ), (targetValue - startValue) * 0.7f, TEST_LOCATION ); - application.Render(static_cast(1000.0f/*1 second*/)); - DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::POSITION ), (targetValue - startValue) * 0.8f, TEST_LOCATION ); - application.Render(static_cast(1000.0f/*1 second*/)); - DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::POSITION ), (targetValue - startValue) * 0.9f, TEST_LOCATION ); - application.Render(static_cast(1000.0f/*1 second*/)); - DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::POSITION ), (targetValue - startValue), TEST_LOCATION ); - - // Check that the constrained value is stable - application.Render(static_cast(1000.0f/*1 second*/)); - DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::POSITION ), (targetValue - startValue), TEST_LOCATION ); - application.Render(static_cast(1000.0f/*1 second*/)); - DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::POSITION ), (targetValue - startValue), TEST_LOCATION ); - - // Remove the constraint - - actor.RemoveConstraints(); - actor.SetPosition( startValue ); - - application.SendNotification(); - application.Render(static_cast(1000.0f/*1 second*/)); - DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::POSITION ), startValue, TEST_LOCATION ); - application.Render(static_cast(1000.0f/*1 second*/)); - DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::POSITION ), startValue, TEST_LOCATION ); - application.Render(static_cast(1000.0f/*1 second*/)); - DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::POSITION ), startValue, TEST_LOCATION ); - - // Change to non-linear alpha and retest - - constraint.SetAlphaFunction(AlphaFunction::EASE_IN); - func = constraint.GetAlphaFunction(); - DALI_TEST_EQUALS(func.GetBuiltinFunction(), AlphaFunction::EASE_IN, TEST_LOCATION); - - actor.ApplyConstraint( constraint ); - - application.SendNotification(); - application.Render(static_cast(1000.0f/*1 second*/)); - - DALI_TEST_CHECK( actor.GetProperty( Actor::Property::POSITION ).x > startValue.x ); - DALI_TEST_CHECK( actor.GetProperty( Actor::Property::POSITION ).y > startValue.y ); - DALI_TEST_CHECK( actor.GetProperty( Actor::Property::POSITION ).z > startValue.z ); - - Vector3 lessThanTenPercentProgress( (targetValue - startValue) * 0.09f ); - DALI_TEST_CHECK( actor.GetProperty( Actor::Property::POSITION ).x < lessThanTenPercentProgress.x ); - DALI_TEST_CHECK( actor.GetProperty( Actor::Property::POSITION ).y < lessThanTenPercentProgress.y ); - DALI_TEST_CHECK( actor.GetProperty( Actor::Property::POSITION ).z < lessThanTenPercentProgress.z ); - - application.Render(static_cast(9000.0f/*9 seconds*/)); - DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::POSITION ), (targetValue - startValue), TEST_LOCATION ); - - // Check that the constrained value is stable - application.Render(static_cast(1000.0f/*1 second*/)); - DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::POSITION ), (targetValue - startValue), TEST_LOCATION ); - application.Render(static_cast(1000.0f/*1 second*/)); - DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::POSITION ), (targetValue - startValue), TEST_LOCATION ); - END_TEST; -} - -int UtcDaliConstraintGetAlphaFunction(void) -{ - TestApplication application; - - Constraint constraint = Constraint::New( Actor::Property::COLOR, TestConstraint() ); - - AlphaFunction func = constraint.GetAlphaFunction(); - DALI_TEST_EQUALS(func.GetBuiltinFunction(), AlphaFunction::DEFAULT, TEST_LOCATION); - END_TEST; -} - -int UtcDaliConstraintSetRemoveAction(void) -{ - TestApplication application; - - Vector3 sourcePosition(0.0f, 0.0f, 0.0f); - Vector3 targetPosition(100.0f, 100.0f, 100.0f); - - // Build constraint, with "Discard" remove action - - Constraint constraint = Constraint::New( Actor::Property::POSITION, TestPositionConstraint(targetPosition) ); - DALI_TEST_EQUALS((unsigned int)constraint.GetRemoveAction(), (unsigned int)Constraint::Bake, TEST_LOCATION); - - constraint.SetRemoveAction(Constraint::Discard); - DALI_TEST_EQUALS((unsigned int)constraint.GetRemoveAction(), (unsigned int)Constraint::Discard, TEST_LOCATION); - - // Apply to an actor - - Actor actor = Actor::New(); - Stage::GetCurrent().Add(actor); - - actor.ApplyConstraint( constraint ); - DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION ); - - application.SendNotification(); - application.Render(100u/*0.1 seconds*/); - - // Constraint should be fully applied - DALI_TEST_EQUALS( actor.GetCurrentPosition(), targetPosition, TEST_LOCATION ); - - // Check that nothing has changed after a couple of buffer swaps - application.Render(0); - DALI_TEST_EQUALS( actor.GetCurrentPosition(), targetPosition, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor.GetCurrentPosition(), targetPosition, TEST_LOCATION ); - - // Remove from the actor - actor.RemoveConstraints(); // should go back to source position - - application.SendNotification(); - application.Render(static_cast(1000.0f)); - - // Constraint should be fully removed - DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION ); - - // Constraint should still be fully removed - application.Render(static_cast(1000.0f)/* Still 100% removal progress */); - DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION ); - - // Check that nothing has changed after a couple of buffer swaps - application.Render(0); - DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION ); - END_TEST; -} - -int UtcDaliConstraintGetRemoveAction(void) -{ - TestApplication application; - - Constraint constraint = Constraint::New( Actor::Property::COLOR, TestConstraint() ); - DALI_TEST_EQUALS((unsigned int)constraint.GetRemoveAction(), (unsigned int)Constraint::Bake, TEST_LOCATION); - - constraint.SetRemoveAction(Constraint::Discard); - DALI_TEST_EQUALS((unsigned int)constraint.GetRemoveAction(), (unsigned int)Constraint::Discard, TEST_LOCATION); - - constraint.SetRemoveAction(Constraint::Bake); - DALI_TEST_EQUALS((unsigned int)constraint.GetRemoveAction(), (unsigned int)Constraint::Bake, TEST_LOCATION); - END_TEST; -} - -/** - * Test a constraint with non-zero apply-time & zero (immediate) remove-time, where the constraint is removed during the apply-time - */ -int UtcDaliConstraintImmediateRemoveDuringApply(void) -{ - TestApplication application; - - Vector3 sourcePosition(0.0f, 0.0f, 0.0f); - Vector3 targetPosition(100.0f, 100.0f, 100.0f); - - // Build constraint - - Constraint constraint = Constraint::New( Actor::Property::POSITION, TestPositionConstraint(targetPosition) ); - DALI_TEST_EQUALS((unsigned int)constraint.GetRemoveAction(), (unsigned int)Constraint::Bake, TEST_LOCATION); - - float applySeconds(4.0f); - constraint.SetApplyTime(applySeconds); - DALI_TEST_EQUALS(constraint.GetApplyTime(), TimePeriod(applySeconds), TEST_LOCATION); - - // Apply to an actor - - Actor actor = Actor::New(); - Stage::GetCurrent().Add(actor); - - actor.ApplyConstraint( constraint ); - DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION ); - - application.SendNotification(); - application.Render(static_cast(applySeconds*250.0f)/* 25% progress */); - - // Constraint shouldn't be fully applied yet - Vector3 twentyFivePercent( targetPosition * 0.25f ); - DALI_TEST_EQUALS( actor.GetCurrentPosition(), twentyFivePercent, TEST_LOCATION ); - - application.Render(static_cast(applySeconds*250.0f)/* 50% progress */); - - // Constraint shouldn't be fully applied yet - Vector3 fiftyPercent( targetPosition * 0.5f ); - DALI_TEST_EQUALS( actor.GetCurrentPosition(), fiftyPercent, TEST_LOCATION ); - - // Remove from the actor - - actor.RemoveConstraints(); // should go back to source position - application.SendNotification(); - - // Constraint should be fully removed - application.Render(static_cast(200.0f /*0.2 seconds*/)); - DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION ); - - // Constraint should still be fully applied - application.Render(static_cast(200.0f /*0.2 seconds*/)); - DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION ); - - // Check that nothing has changed after a couple of buffer swaps - application.Render(0); - DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor.GetCurrentPosition(), sourcePosition, TEST_LOCATION ); - END_TEST; -} - -int UtcDaliConstraintActorSize(void) -{ - TestApplication application; - - // Build constraint, to make child 20% of parent size - - Constraint constraint = Constraint::New( Actor::Property::SIZE, - ParentSource( Actor::Property::SIZE ), - TestRelativeConstraintVector3(0.2f) ); - // Apply to a child actor - - Actor parent = Actor::New(); - Stage::GetCurrent().Add(parent); - - Actor child = Actor::New(); - parent.Add(child); - - child.ApplyConstraint( constraint ); - DALI_TEST_EQUALS( child.GetCurrentSize(), Vector3::ZERO, TEST_LOCATION ); - - // Animate the parent between two sizes - - Vector3 targetParentSize(100.0f, 100.0f, 100.0f); - - float durationSeconds(10.0f); - Animation animation = Animation::New(durationSeconds); - animation.AnimateTo( Property(parent, Actor::Property::SIZE), targetParentSize ); - animation.Play(); - - application.SendNotification(); - - application.Render(static_cast(durationSeconds*250.0f)/* 25% progress */); - DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize*0.25f, TEST_LOCATION ); - DALI_TEST_EQUALS( child.GetCurrentSize(), targetParentSize*0.25f * 0.2f, TEST_LOCATION ); - - application.Render(static_cast(durationSeconds*250.0f)/* 50% progress */); - DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize*0.5f, TEST_LOCATION ); - DALI_TEST_EQUALS( child.GetCurrentSize(), targetParentSize*0.5f * 0.2f, TEST_LOCATION ); - - application.Render(static_cast(durationSeconds*250.0f)/* 75% progress */); - DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize*0.75f, TEST_LOCATION ); - DALI_TEST_EQUALS( child.GetCurrentSize(), targetParentSize*0.75f * 0.2f, TEST_LOCATION ); - - application.Render(static_cast(durationSeconds*250.0f)/* 100% progress */); - DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize, TEST_LOCATION ); - DALI_TEST_EQUALS( child.GetCurrentSize(), targetParentSize * 0.2f, TEST_LOCATION ); - - // Check that nothing has changed after a couple of buffer swaps - application.Render(0); - DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize, TEST_LOCATION ); - DALI_TEST_EQUALS( child.GetCurrentSize(), targetParentSize * 0.2f, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize, TEST_LOCATION ); - DALI_TEST_EQUALS( child.GetCurrentSize(), targetParentSize * 0.2f, TEST_LOCATION ); - END_TEST; -} - -int UtcDaliConstraintActorSizeWidth(void) -{ - TestApplication application; - - // Build constraint, to make child 20% of parent width - - Constraint constraint = Constraint::New( Actor::Property::SIZE_WIDTH, - ParentSource( Actor::Property::SIZE_WIDTH ), - TestRelativeConstraintFloat(0.2f) ); - // Apply to a child actor - - Actor parent = Actor::New(); - Stage::GetCurrent().Add(parent); - - Actor child = Actor::New(); - parent.Add(child); - - child.ApplyConstraint( constraint ); - DALI_TEST_EQUALS( child.GetCurrentSize(), Vector3::ZERO, TEST_LOCATION ); - - // Animate the parent between two sizes - - Vector3 targetParentSize(80.0f, 90.0f, 100.0f); - - float durationSeconds(10.0f); - Animation animation = Animation::New(durationSeconds); - animation.AnimateTo( Property(parent, Actor::Property::SIZE), targetParentSize ); - animation.Play(); - - application.SendNotification(); - - application.Render(static_cast(durationSeconds*250.0f)/* 25% progress */); - DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize*0.25f, TEST_LOCATION ); - DALI_TEST_EQUALS( child.GetCurrentSize().width, targetParentSize.width*0.25f * 0.2f, TEST_LOCATION ); - DALI_TEST_EQUALS( child.GetCurrentSize().height, 0.0f, TEST_LOCATION ); - DALI_TEST_EQUALS( child.GetCurrentSize().depth, 0.0f, TEST_LOCATION ); - - application.Render(static_cast(durationSeconds*250.0f)/* 50% progress */); - DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize*0.5f, TEST_LOCATION ); - DALI_TEST_EQUALS( child.GetCurrentSize().width, targetParentSize.width*0.5f * 0.2f, TEST_LOCATION ); - DALI_TEST_EQUALS( child.GetCurrentSize().height, 0.0f, TEST_LOCATION ); - DALI_TEST_EQUALS( child.GetCurrentSize().depth, 0.0f, TEST_LOCATION ); - - application.Render(static_cast(durationSeconds*250.0f)/* 75% progress */); - DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize*0.75f, TEST_LOCATION ); - DALI_TEST_EQUALS( child.GetCurrentSize().width, targetParentSize.width*0.75f * 0.2f, TEST_LOCATION ); - DALI_TEST_EQUALS( child.GetCurrentSize().height, 0.0f, TEST_LOCATION ); - DALI_TEST_EQUALS( child.GetCurrentSize().depth, 0.0f, TEST_LOCATION ); - - application.Render(static_cast(durationSeconds*250.0f)/* 100% progress */); - DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize, TEST_LOCATION ); - DALI_TEST_EQUALS( child.GetCurrentSize().width, targetParentSize.width * 0.2f, TEST_LOCATION ); - DALI_TEST_EQUALS( child.GetCurrentSize().height, 0.0f, TEST_LOCATION ); - DALI_TEST_EQUALS( child.GetCurrentSize().depth, 0.0f, TEST_LOCATION ); - - // Check that nothing has changed after a couple of buffer swaps - application.Render(0); - DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize, TEST_LOCATION ); - DALI_TEST_EQUALS( child.GetCurrentSize().width, targetParentSize.width * 0.2f, TEST_LOCATION ); - DALI_TEST_EQUALS( child.GetCurrentSize().height, 0.0f, TEST_LOCATION ); - DALI_TEST_EQUALS( child.GetCurrentSize().depth, 0.0f, TEST_LOCATION ); - - application.Render(0); - DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize, TEST_LOCATION ); - DALI_TEST_EQUALS( child.GetCurrentSize().width, targetParentSize.width * 0.2f, TEST_LOCATION ); - DALI_TEST_EQUALS( child.GetCurrentSize().height, 0.0f, TEST_LOCATION ); - DALI_TEST_EQUALS( child.GetCurrentSize().depth, 0.0f, TEST_LOCATION ); - END_TEST; -} - -int UtcDaliConstraintActorSizeHeight(void) -{ - TestApplication application; - - // Build constraint, to make child 20% of parent height - - Constraint constraint = Constraint::New( Actor::Property::SIZE_HEIGHT, - ParentSource( Actor::Property::SIZE_HEIGHT ), - TestRelativeConstraintFloat(0.2f) ); - // Apply to a child actor - - Actor parent = Actor::New(); - Stage::GetCurrent().Add(parent); - - Actor child = Actor::New(); - parent.Add(child); - - child.ApplyConstraint( constraint ); - DALI_TEST_EQUALS( child.GetCurrentSize(), Vector3::ZERO, TEST_LOCATION ); - - // Animate the parent between two sizes - - Vector3 targetParentSize(80.0f, 90.0f, 100.0f); - - float durationSeconds(10.0f); - Animation animation = Animation::New(durationSeconds); - animation.AnimateTo( Property(parent, Actor::Property::SIZE), targetParentSize ); - animation.Play(); - - application.SendNotification(); - - application.Render(static_cast(durationSeconds*250.0f)/* 25% progress */); - DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize*0.25f, TEST_LOCATION ); - DALI_TEST_EQUALS( child.GetCurrentSize().width, 0.0f, TEST_LOCATION ); - DALI_TEST_EQUALS( child.GetCurrentSize().height, targetParentSize.height*0.25f * 0.2f, TEST_LOCATION ); - DALI_TEST_EQUALS( child.GetCurrentSize().depth, 0.0f, TEST_LOCATION ); - - application.Render(static_cast(durationSeconds*250.0f)/* 50% progress */); - DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize*0.5f, TEST_LOCATION ); - DALI_TEST_EQUALS( child.GetCurrentSize().width, 0.0f, TEST_LOCATION ); - DALI_TEST_EQUALS( child.GetCurrentSize().height, targetParentSize.height*0.5f * 0.2f, TEST_LOCATION ); - DALI_TEST_EQUALS( child.GetCurrentSize().depth, 0.0f, TEST_LOCATION ); - - application.Render(static_cast(durationSeconds*250.0f)/* 75% progress */); - DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize*0.75f, TEST_LOCATION ); - DALI_TEST_EQUALS( child.GetCurrentSize().width, 0.0f, TEST_LOCATION ); - DALI_TEST_EQUALS( child.GetCurrentSize().height, targetParentSize.height*0.75f * 0.2f, TEST_LOCATION ); - DALI_TEST_EQUALS( child.GetCurrentSize().depth, 0.0f, TEST_LOCATION ); - - application.Render(static_cast(durationSeconds*250.0f)/* 100% progress */); - DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize, TEST_LOCATION ); - DALI_TEST_EQUALS( child.GetCurrentSize().width, 0.0f, TEST_LOCATION ); - DALI_TEST_EQUALS( child.GetCurrentSize().height, targetParentSize.height * 0.2f, TEST_LOCATION ); - DALI_TEST_EQUALS( child.GetCurrentSize().depth, 0.0f, TEST_LOCATION ); - - // Check that nothing has changed after a couple of buffer swaps - application.Render(0); - DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize, TEST_LOCATION ); - DALI_TEST_EQUALS( child.GetCurrentSize().width, 0.0f, TEST_LOCATION ); - DALI_TEST_EQUALS( child.GetCurrentSize().height, targetParentSize.height * 0.2f, TEST_LOCATION ); - DALI_TEST_EQUALS( child.GetCurrentSize().depth, 0.0f, TEST_LOCATION ); - - application.Render(0); - DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize, TEST_LOCATION ); - DALI_TEST_EQUALS( child.GetCurrentSize().width, 0.0f, TEST_LOCATION ); - DALI_TEST_EQUALS( child.GetCurrentSize().height, targetParentSize.height * 0.2f, TEST_LOCATION ); - DALI_TEST_EQUALS( child.GetCurrentSize().depth, 0.0f, TEST_LOCATION ); - END_TEST; -} - -int UtcDaliConstraintActorSizeDepth(void) -{ - TestApplication application; - - // Build constraint, to make child 20% of parent height - - Constraint constraint = Constraint::New( Actor::Property::SIZE_DEPTH, - ParentSource( Actor::Property::SIZE_DEPTH ), - TestRelativeConstraintFloat(0.2f) ); - // Apply to a child actor - - Actor parent = Actor::New(); - Stage::GetCurrent().Add(parent); - - Actor child = Actor::New(); - parent.Add(child); - - child.ApplyConstraint( constraint ); - DALI_TEST_EQUALS( child.GetCurrentSize(), Vector3::ZERO, TEST_LOCATION ); - - // Animate the parent between two sizes +} - Vector3 targetParentSize(80.0f, 90.0f, 100.0f); +int UtcDaliConstraintNewFunctorMemberN(void) +{ + // Create a constraint with an uninitialised handle - float durationSeconds(10.0f); - Animation animation = Animation::New(durationSeconds); - animation.AnimateTo( Property(parent, Actor::Property::SIZE), targetParentSize ); - animation.Play(); + TestApplication application; + bool positionFunctorCalled = false; + bool sizeFunctorCalled = false; - application.SendNotification(); + // Add a constraint with an uninitialised handle + try + { + Constraint constraint = Constraint::New< Vector3 >( + Actor(), + Actor::Property::POSITION, + UtcDaliConstraintNewFunctorMember::Functor( positionFunctorCalled, sizeFunctorCalled ), + &UtcDaliConstraintNewFunctorMember::Functor::Position ); + DALI_TEST_CHECK( false ); // Should not reach here + } + catch ( Dali::DaliException& e ) + { + DALI_TEST_CHECK( true ); // Should assert! + } - application.Render(static_cast(durationSeconds*250.0f)/* 25% progress */); - DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize*0.25f, TEST_LOCATION ); - DALI_TEST_EQUALS( child.GetCurrentSize().width, 0.0f, TEST_LOCATION ); - DALI_TEST_EQUALS( child.GetCurrentSize().height, 0.0f, TEST_LOCATION ); - DALI_TEST_EQUALS( child.GetCurrentSize().depth, targetParentSize.depth*0.25f * 0.2f, TEST_LOCATION ); - - application.Render(static_cast(durationSeconds*250.0f)/* 50% progress */); - DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize*0.5f, TEST_LOCATION ); - DALI_TEST_EQUALS( child.GetCurrentSize().width, 0.0f, TEST_LOCATION ); - DALI_TEST_EQUALS( child.GetCurrentSize().height, 0.0f, TEST_LOCATION ); - DALI_TEST_EQUALS( child.GetCurrentSize().depth, targetParentSize.depth*0.5f * 0.2f, TEST_LOCATION ); - - application.Render(static_cast(durationSeconds*250.0f)/* 75% progress */); - DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize*0.75f, TEST_LOCATION ); - DALI_TEST_EQUALS( child.GetCurrentSize().width, 0.0f, TEST_LOCATION ); - DALI_TEST_EQUALS( child.GetCurrentSize().height, 0.0f, TEST_LOCATION ); - DALI_TEST_EQUALS( child.GetCurrentSize().depth, targetParentSize.depth*0.75f * 0.2f, TEST_LOCATION ); - - application.Render(static_cast(durationSeconds*250.0f)/* 100% progress */); - DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize, TEST_LOCATION ); - DALI_TEST_EQUALS( child.GetCurrentSize().width, 0.0f, TEST_LOCATION ); - DALI_TEST_EQUALS( child.GetCurrentSize().height, 0.0f, TEST_LOCATION ); - DALI_TEST_EQUALS( child.GetCurrentSize().depth, targetParentSize.depth * 0.2f, TEST_LOCATION ); - - // Check that nothing has changed after a couple of buffer swaps - application.Render(0); - DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize, TEST_LOCATION ); - DALI_TEST_EQUALS( child.GetCurrentSize().width, 0.0f, TEST_LOCATION ); - DALI_TEST_EQUALS( child.GetCurrentSize().height, 0.0f, TEST_LOCATION ); - DALI_TEST_EQUALS( child.GetCurrentSize().depth, targetParentSize.depth * 0.2f, TEST_LOCATION ); - - application.Render(0); - DALI_TEST_EQUALS( parent.GetCurrentSize(), targetParentSize, TEST_LOCATION ); - DALI_TEST_EQUALS( child.GetCurrentSize().width, 0.0f, TEST_LOCATION ); - DALI_TEST_EQUALS( child.GetCurrentSize().height, 0.0f, TEST_LOCATION ); - DALI_TEST_EQUALS( child.GetCurrentSize().depth, targetParentSize.depth * 0.2f, TEST_LOCATION ); END_TEST; } +/////////////////////////////////////////////////////////////////////////////// -int UtcDaliConstraintInputWorldPosition(void) +/////////////////////////////////////////////////////////////////////////////// +// Constraint::Clone +/////////////////////////////////////////////////////////////////////////////// +int UtcDaliConstraintCloneP(void) { + // Ensure we can clone for another actor and it's called appropriately + TestApplication application; + int calledCount = 0; + + Actor actor = Actor::New(); + Actor clone = Actor::New(); - Actor parent = Actor::New(); - Vector3 parentPosition( 10.0f, 10.0f, 10.0f ); - parent.SetPosition( parentPosition ); - parent.SetParentOrigin( ParentOrigin::CENTER ); - parent.SetAnchorPoint( AnchorPoint::CENTER ); - Stage::GetCurrent().Add( parent ); - - Actor child = Actor::New(); - child.SetParentOrigin( ParentOrigin::CENTER ); - child.SetAnchorPoint( AnchorPoint::CENTER ); - Vector3 childPosition( 10.0f, 10.0f, 10.0f ); - child.SetPosition( childPosition ); - parent.Add( child ); - - Actor trackingActor = Actor::New(); - trackingActor.SetParentOrigin( ParentOrigin::CENTER ); - trackingActor.SetAnchorPoint( AnchorPoint::CENTER ); - Stage::GetCurrent().Add( trackingActor ); - - // The actors should not have a world position yet - DALI_TEST_EQUALS( parent.GetCurrentWorldPosition(), Vector3::ZERO, TEST_LOCATION ); - DALI_TEST_EQUALS( child.GetCurrentWorldPosition(), Vector3::ZERO, TEST_LOCATION ); - DALI_TEST_EQUALS( trackingActor.GetCurrentWorldPosition(), Vector3::ZERO, TEST_LOCATION ); + Stage stage = Stage::GetCurrent(); + stage.Add( actor ); + stage.Add( clone ); application.SendNotification(); - application.Render(0); + application.Render(); + + DALI_TEST_EQUALS( calledCount, 0, TEST_LOCATION ); - DALI_TEST_EQUALS( parent.GetCurrentPosition(), parentPosition, TEST_LOCATION ); - DALI_TEST_EQUALS( child.GetCurrentPosition(), childPosition, TEST_LOCATION ); - DALI_TEST_EQUALS( trackingActor.GetCurrentPosition(), Vector3::ZERO, TEST_LOCATION ); + // Add a constraint to actor + Constraint constraint = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, CalledCountFunctor< Vector3 >( calledCount ) ); + DALI_TEST_CHECK( constraint ); + constraint.Apply(); - DALI_TEST_EQUALS( parent.GetCurrentWorldPosition(), parentPosition, TEST_LOCATION ); - Vector3 previousPosition( parentPosition + childPosition ); - DALI_TEST_EQUALS( child.GetCurrentWorldPosition(), previousPosition, TEST_LOCATION ); - DALI_TEST_EQUALS( trackingActor.GetCurrentWorldPosition(), Vector3::ZERO, TEST_LOCATION ); + // Create a clone but don't apply + Constraint constraintClone = constraint.Clone( clone ); - // Build constraint, to make actor track the world-position of another actor - // Note that the world-position is always from the previous frame, so the tracking actor will lag behind + application.SendNotification(); + application.Render(); - Constraint constraint = Constraint::New( Actor::Property::POSITION, - Source( child, Actor::Property::WORLD_POSITION ), - EqualToConstraint() ); + DALI_TEST_EQUALS( calledCount, 1, TEST_LOCATION ); - trackingActor.ApplyConstraint( constraint ); + // Reset + calledCount = 0; + // Ensure constraint isn't called again if scene doesn't change application.SendNotification(); - application.Render(0); + application.Render(); - DALI_TEST_EQUALS( trackingActor.GetCurrentPosition(), previousPosition, TEST_LOCATION ); + DALI_TEST_EQUALS( calledCount, 0, TEST_LOCATION ); - // Move the actors and try again - Vector3 relativePosition( 5, 5, 5 ); - parent.TranslateBy( relativePosition ); + // Apply the clone constraint + constraintClone.Apply(); application.SendNotification(); - application.Render(0); + application.Render(); - DALI_TEST_EQUALS( parent.GetCurrentPosition(), parentPosition + relativePosition, TEST_LOCATION ); - DALI_TEST_EQUALS( child.GetCurrentPosition(), childPosition, TEST_LOCATION ); + // Should only be called once for the new constraint clone ONLY + DALI_TEST_EQUALS( calledCount, 1, TEST_LOCATION ); - // The tracking actor lags behind - DALI_TEST_EQUALS( trackingActor.GetCurrentPosition(), previousPosition, TEST_LOCATION ); + // Reset + calledCount = 0; - DALI_TEST_EQUALS( parent.GetCurrentWorldPosition(), parentPosition + relativePosition, TEST_LOCATION ); - previousPosition = Vector3( parentPosition + childPosition + relativePosition ); - DALI_TEST_EQUALS( child.GetCurrentWorldPosition(), previousPosition, TEST_LOCATION ); + // Change the position of both actors + actor.SetPosition( 100.0f, 100.0f ); + clone.SetPosition( 100.0f, 100.0f ); - // Allow the tracking actor to catch up application.SendNotification(); - application.Render(0); + application.Render(); - DALI_TEST_EQUALS( parent.GetCurrentPosition(), parentPosition + relativePosition, TEST_LOCATION ); - DALI_TEST_EQUALS( child.GetCurrentPosition(), childPosition, TEST_LOCATION ); + // Functor should have been called twice + DALI_TEST_EQUALS( calledCount, 2, TEST_LOCATION ); - // The tracking actor catches up! - DALI_TEST_EQUALS( trackingActor.GetCurrentPosition(), previousPosition, TEST_LOCATION ); - DALI_TEST_EQUALS( parent.GetCurrentWorldPosition(), parentPosition + relativePosition, TEST_LOCATION ); - DALI_TEST_EQUALS( child.GetCurrentWorldPosition(), previousPosition, TEST_LOCATION ); END_TEST; } -int UtcDaliConstraintInputWorldRotation(void) +int UtcDaliConstraintCloneN(void) { - TestApplication application; + // Attempt to clone an uninitialised constraint should cause an assert - Actor parent = Actor::New(); - Radian rotationAngle( Degree(90.0f) ); - Quaternion rotation( rotationAngle, Vector3::YAXIS ); - parent.SetOrientation( rotation ); - Stage::GetCurrent().Add( parent ); - - Actor child = Actor::New(); - child.SetOrientation( rotation ); - parent.Add( child ); + TestApplication application; - Actor trackingActor = Actor::New(); - Stage::GetCurrent().Add( trackingActor ); + Constraint constraint; - // The actors should not have a world rotation yet - DALI_TEST_EQUALS( parent.GetCurrentWorldOrientation(), Quaternion(0.0f, Vector3::YAXIS), 0.001, TEST_LOCATION ); - DALI_TEST_EQUALS( child.GetCurrentWorldOrientation(), Quaternion(0.0f, Vector3::YAXIS), 0.001, TEST_LOCATION ); + try + { + Actor actor = Actor::New(); + Constraint clone = constraint.Clone( actor ); + DALI_TEST_CHECK( false ); + } + catch ( ... ) + { + DALI_TEST_CHECK( true ); + } - application.SendNotification(); - application.Render(0); + END_TEST; +} - DALI_TEST_EQUALS( parent.GetCurrentOrientation(), rotation, 0.001, TEST_LOCATION ); - DALI_TEST_EQUALS( child.GetCurrentOrientation(), rotation, 0.001, TEST_LOCATION ); - DALI_TEST_EQUALS( trackingActor.GetCurrentOrientation(), Quaternion(0.0f, Vector3::YAXIS), 0.001, TEST_LOCATION ); +namespace UtcDaliConstraintClone +{ +void Function( Vector3& /* current */, const PropertyInputContainer& inputs ) +{ + DALI_TEST_EQUALS( inputs[0]->GetType(), Property::VECTOR3, TEST_LOCATION ); + DALI_TEST_EQUALS( inputs[1]->GetType(), Property::ROTATION, TEST_LOCATION ); + DALI_TEST_EQUALS( inputs[2]->GetType(), Property::VECTOR4, TEST_LOCATION ); + DALI_TEST_EQUALS( inputs[3]->GetType(), Property::BOOLEAN, TEST_LOCATION ); +} +} // namespace UtcDaliConstraintClone - DALI_TEST_EQUALS( parent.GetCurrentWorldOrientation(), Quaternion( rotationAngle, Vector3::YAXIS ), 0.001, TEST_LOCATION ); - Quaternion previousRotation( rotationAngle * 2.0f, Vector3::YAXIS ); - DALI_TEST_EQUALS( child.GetCurrentWorldOrientation(), previousRotation, 0.001, TEST_LOCATION ); +int UtcDaliConstraintCloneCheckSourcesAndSetters(void) +{ + // Ensure all sources, the tag and remove-action are cloned appropriately - // Build constraint, to make actor track the world-rotation of another actor - // Note that the world-rotation is always from the previous frame, so the tracking actor will lag behind + TestApplication application; - Constraint constraint = Constraint::New( Actor::Property::ORIENTATION, - Source( child, Actor::Property::WORLD_ORIENTATION ), - EqualToQuaternion() ); + Actor actor = Actor::New(); + Actor clone = Actor::New(); - trackingActor.ApplyConstraint( constraint ); + Stage stage = Stage::GetCurrent(); + stage.Add( actor ); + stage.Add( clone ); application.SendNotification(); - application.Render(0); + application.Render(); - DALI_TEST_EQUALS( trackingActor.GetCurrentOrientation(), previousRotation, 0.001, TEST_LOCATION ); + // Create a constraint, DON'T Apply it though + Constraint constraint = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, &UtcDaliConstraintClone::Function ); + constraint.AddSource( LocalSource( Actor::Property::SIZE ) ); + constraint.AddSource( LocalSource( Actor::Property::ORIENTATION ) ); + constraint.AddSource( LocalSource( Actor::Property::COLOR ) ); + constraint.AddSource( LocalSource( Actor::Property::VISIBLE ) ); + constraint.SetRemoveAction( Constraint::Discard ); + constraint.SetTag( 123 ); - // Rotate the actors and try again - parent.RotateBy( rotation ); + // Clone the constraint & apply the clone + Constraint constraintClone = constraint.Clone( clone ); + constraintClone.Apply(); application.SendNotification(); - application.Render(0); + application.Render(); - DALI_TEST_EQUALS( parent.GetCurrentOrientation(), rotation * rotation, 0.001, TEST_LOCATION ); - DALI_TEST_EQUALS( child.GetCurrentOrientation(), rotation, 0.001, TEST_LOCATION ); + DALI_TEST_EQUALS( constraint.GetRemoveAction(), constraintClone.GetRemoveAction(), TEST_LOCATION ); + DALI_TEST_EQUALS( constraint.GetTag(), constraintClone.GetTag(), TEST_LOCATION ); - // The tracking actor lags behind - DALI_TEST_EQUALS( trackingActor.GetCurrentOrientation(), previousRotation, 0.001, TEST_LOCATION ); + END_TEST; +} +/////////////////////////////////////////////////////////////////////////////// - DALI_TEST_EQUALS( parent.GetCurrentWorldOrientation(), Quaternion( rotationAngle * 2.0f, Vector3::YAXIS ), 0.001, TEST_LOCATION ); - previousRotation = Quaternion( rotationAngle * 3.0f, Vector3::YAXIS ); - DALI_TEST_EQUALS( child.GetCurrentWorldOrientation(), previousRotation, 0.001, TEST_LOCATION ); +/////////////////////////////////////////////////////////////////////////////// +// Constraint::Constraint( const Constraint& ) +// Constraint::operator= +/////////////////////////////////////////////////////////////////////////////// +int UtcDaliConstraintCopyAndAssignment(void) +{ + // Ensure copy constructor & assignment operators work - // Allow the tracking actor to catch up - application.SendNotification(); - application.Render(0); + TestApplication application; + + Actor actor = Actor::New(); + Stage::GetCurrent().Add( actor ); - DALI_TEST_EQUALS( parent.GetCurrentOrientation(), rotation * rotation, 0.001, TEST_LOCATION ); - DALI_TEST_EQUALS( child.GetCurrentOrientation(), rotation, 0.001, TEST_LOCATION ); + Constraint constraint = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, &BasicFunction< Vector3 > ); + Constraint copied( constraint ); + Constraint assigned; + DALI_TEST_CHECK( constraint == copied ); + DALI_TEST_CHECK( copied != assigned ); + + assigned = constraint; + DALI_TEST_CHECK( constraint == assigned ); - // The tracking actor catches up! - DALI_TEST_EQUALS( trackingActor.GetCurrentOrientation(), previousRotation, 0.001, TEST_LOCATION ); - DALI_TEST_EQUALS( parent.GetCurrentWorldOrientation(), Quaternion( rotationAngle * 2.0f, Vector3::YAXIS ), 0.001, TEST_LOCATION ); - DALI_TEST_EQUALS( child.GetCurrentWorldOrientation(), previousRotation, 0.001, TEST_LOCATION ); END_TEST; } +/////////////////////////////////////////////////////////////////////////////// -int UtcDaliConstraintInputWorldScale(void) +/////////////////////////////////////////////////////////////////////////////// +// Constraint::DownCast +/////////////////////////////////////////////////////////////////////////////// +int UtcDaliConstraintDownCast(void) { + // Ensure DownCast works as expected + TestApplication application; - Actor parent = Actor::New(); - Vector3 parentScale( 2.0f, 2.0f, 2.0f ); - parent.SetScale( parentScale ); - Stage::GetCurrent().Add( parent ); + Actor actor = Actor::New(); + Constraint constraint = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, &BasicFunction< Vector3 > ); - Actor child = Actor::New(); - Vector3 childScale( 1.0f, 2.0f, 3.0f ); - child.SetScale( childScale ); - parent.Add( child ); + // Another BaseHandle type + Constraint downCast = Constraint::DownCast( actor ); + DALI_TEST_CHECK( ! downCast ); - Actor trackingActor = Actor::New(); - Stage::GetCurrent().Add( trackingActor ); + // A constraint + downCast = Constraint::DownCast( constraint ); + DALI_TEST_CHECK( downCast ); - // The actors should not have a world scale yet - DALI_TEST_EQUALS( parent.GetCurrentWorldScale(), Vector3::ONE, TEST_LOCATION ); - DALI_TEST_EQUALS( child.GetCurrentWorldScale(), Vector3::ONE, TEST_LOCATION ); - DALI_TEST_EQUALS( trackingActor.GetCurrentWorldScale(), Vector3::ONE, TEST_LOCATION ); + // An empty constraint + downCast = Constraint::DownCast( Constraint() ); + DALI_TEST_CHECK( ! downCast ); - application.SendNotification(); - application.Render(0); + END_TEST; +} +/////////////////////////////////////////////////////////////////////////////// - DALI_TEST_EQUALS( parent.GetCurrentScale(), parentScale, TEST_LOCATION ); - DALI_TEST_EQUALS( child.GetCurrentScale(), childScale, TEST_LOCATION ); - DALI_TEST_EQUALS( trackingActor.GetCurrentScale(), Vector3::ONE, TEST_LOCATION ); +/////////////////////////////////////////////////////////////////////////////// +// Constraint::GetTargetObject +/////////////////////////////////////////////////////////////////////////////// +int UtcDaliConstraintGetTargetObjectP(void) +{ + TestApplication application; - DALI_TEST_EQUALS( parent.GetCurrentWorldScale(), parentScale, TEST_LOCATION ); - Vector3 previousScale( parentScale * childScale ); - DALI_TEST_EQUALS( child.GetCurrentWorldScale(), previousScale, TEST_LOCATION ); - DALI_TEST_EQUALS( trackingActor.GetCurrentScale(), Vector3::ONE, TEST_LOCATION ); + Actor actor = Actor::New(); + Constraint constraint = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, &BasicFunction< Vector3 > ); + DALI_TEST_CHECK( constraint.GetTargetObject() == actor ); - // Build constraint, to make actor track the world-scale of another actor - // Note that the world-scale is always from the previous frame, so the tracking actor will lag behind + Actor actor2 = Actor::New(); + DALI_TEST_CHECK( constraint.GetTargetObject() != actor2 ); - Constraint constraint = Constraint::New( Actor::Property::SCALE, - Source( child, Actor::Property::WORLD_SCALE ), - EqualToConstraint() ); + END_TEST; +} - trackingActor.ApplyConstraint( constraint ); +int UtcDaliConstraintGetTargetObjectN(void) +{ + // Attempt to retrieve from uninitialised constraint - application.SendNotification(); - application.Render(0); + TestApplication application; - DALI_TEST_EQUALS( trackingActor.GetCurrentScale(), previousScale, TEST_LOCATION ); + Constraint constraint; + try + { + Handle handle = constraint.GetTargetObject(); + DALI_TEST_CHECK( false ); // Should not reach here! + } + catch( ... ) + { + DALI_TEST_CHECK( true ); + } - // Scale the actors and try again - Vector3 relativeScale( 3, 3, 3 ); - parent.ScaleBy( relativeScale ); + END_TEST; +} +/////////////////////////////////////////////////////////////////////////////// - application.SendNotification(); - application.Render(0); +/////////////////////////////////////////////////////////////////////////////// +// Constraint::GetTargetProperty +/////////////////////////////////////////////////////////////////////////////// +int UtcDaliConstraintGetTargetPropertyP(void) +{ + TestApplication application; - DALI_TEST_EQUALS( parent.GetCurrentScale(), parentScale * relativeScale, TEST_LOCATION ); - DALI_TEST_EQUALS( child.GetCurrentScale(), childScale, TEST_LOCATION ); + Actor actor = Actor::New(); + Constraint constraint = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, &BasicFunction< Vector3 > ); + DALI_TEST_EQUALS( constraint.GetTargetProperty(), Actor::Property::POSITION, TEST_LOCATION ); - // The tracking actor lags behind - DALI_TEST_EQUALS( trackingActor.GetCurrentScale(), previousScale, TEST_LOCATION ); + END_TEST; +} - DALI_TEST_EQUALS( parent.GetCurrentWorldScale(), parentScale * relativeScale, TEST_LOCATION ); - previousScale = Vector3( parentScale * childScale * relativeScale ); - DALI_TEST_EQUALS( child.GetCurrentWorldScale(), previousScale, TEST_LOCATION ); +int UtcDaliConstraintGetTargetPropertyN(void) +{ + // Attempt to retrieve from uninitialised constraint - // Allow the tracking actor to catch up - application.SendNotification(); - application.Render(0); + TestApplication application; - DALI_TEST_EQUALS( parent.GetCurrentScale(), parentScale * relativeScale, TEST_LOCATION ); - DALI_TEST_EQUALS( child.GetCurrentScale(), childScale, TEST_LOCATION ); + Constraint constraint; + try + { + Property::Index propertyIndex = constraint.GetTargetProperty(); + ( void )propertyIndex; + DALI_TEST_CHECK( false ); // Should not reach here! + } + catch( ... ) + { + DALI_TEST_CHECK( true ); + } - // The tracking actor catches up! - DALI_TEST_EQUALS( trackingActor.GetCurrentScale(), previousScale, TEST_LOCATION ); - DALI_TEST_EQUALS( parent.GetCurrentWorldScale(), parentScale * relativeScale, TEST_LOCATION ); - DALI_TEST_EQUALS( child.GetCurrentWorldScale(), previousScale, TEST_LOCATION ); END_TEST; } +/////////////////////////////////////////////////////////////////////////////// -int UtcDaliConstraintInputWorldColor(void) +/////////////////////////////////////////////////////////////////////////////// +// Constraint::SetTag +// Constraint::GetTag +/////////////////////////////////////////////////////////////////////////////// +int UtcDaliConstraintTagP(void) { TestApplication application; - Actor parent = Actor::New(); - Vector4 parentColor( 1.0f, 0.5f, 0.0f, 1.0f ); - parent.SetColor( parentColor ); - Stage::GetCurrent().Add( parent ); + Actor actor = Actor::New(); + Constraint constraint = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, &BasicFunction< Vector3 > ); + DALI_TEST_EQUALS( constraint.GetTag(), 0, TEST_LOCATION ); + + const int tag = 123; + constraint.SetTag( tag ); + DALI_TEST_EQUALS( constraint.GetTag(), tag, TEST_LOCATION ); - Actor child = Actor::New(); - Vector4 childColor( 0.5f, 0.5f, 0.5f, 1.0f ); - child.SetColor( childColor ); - parent.Add( child ); + END_TEST; +} - Actor trackingActor = Actor::New(); - Stage::GetCurrent().Add( trackingActor ); +int UtcDaliConstraintSetTagN(void) +{ + // Attempt to set from uninitialised constraint - // The actors should not have a world color yet - DALI_TEST_EQUALS( parent.GetCurrentWorldColor(), Color::WHITE, TEST_LOCATION ); - DALI_TEST_EQUALS( child.GetCurrentWorldColor(), Color::WHITE, TEST_LOCATION ); + TestApplication application; - application.SendNotification(); - application.Render(0); + Constraint constraint; + try + { + constraint.SetTag( 123 ); + DALI_TEST_CHECK( false ); // Should not reach here! + } + catch( ... ) + { + DALI_TEST_CHECK( true ); + } - DALI_TEST_EQUALS( parent.GetCurrentColor(), parentColor, TEST_LOCATION ); - DALI_TEST_EQUALS( child.GetCurrentColor(), childColor, TEST_LOCATION ); - DALI_TEST_EQUALS( trackingActor.GetCurrentColor(), Color::WHITE, TEST_LOCATION ); + END_TEST; +} - DALI_TEST_EQUALS( parent.GetCurrentWorldColor(), parentColor, TEST_LOCATION ); - Vector4 previousColor( childColor ); - previousColor.a *= parentColor.a; - DALI_TEST_EQUALS( child.GetCurrentWorldColor(), previousColor, TEST_LOCATION ); +int UtcDaliConstraintGetTagN(void) +{ + // Attempt to retrieve from uninitialised constraint - // Build constraint, to make actor track the world-color of another actor - // Note that the world-color is always from the previous frame, so the tracking actor will lag behind + TestApplication application; - Constraint constraint = Constraint::New( Actor::Property::COLOR, - Source( child, Actor::Property::WORLD_COLOR ), - EqualToVector4() ); + Constraint constraint; + try + { + int tag = constraint.GetTag(); + ( void )tag; + DALI_TEST_CHECK( false ); // Should not reach here! + } + catch( ... ) + { + DALI_TEST_CHECK( true ); + } - trackingActor.ApplyConstraint( constraint ); + END_TEST; +} - application.SendNotification(); - application.Render(0); +/////////////////////////////////////////////////////////////////////////////// - DALI_TEST_EQUALS( trackingActor.GetCurrentColor(), previousColor, TEST_LOCATION ); +/////////////////////////////////////////////////////////////////////////////// +// Constraint::SetRemoveAction +// Constraint::GetRemoveAction +/////////////////////////////////////////////////////////////////////////////// +int UtcDaliConstraintRemoveActionP(void) +{ + TestApplication application; - // Set the color and try again - Vector4 newChildColor( 0.75f, 0.75f, 0.75f, 1.0f ); - child.SetColor( newChildColor ); + Actor actor = Actor::New(); + Constraint constraint = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, &BasicFunction< Vector3 > ); + DALI_TEST_EQUALS( constraint.GetRemoveAction(), Constraint::DEFAULT_REMOVE_ACTION, TEST_LOCATION ); - application.SendNotification(); - application.Render(0); + constraint.SetRemoveAction( Constraint::Discard ); + DALI_TEST_EQUALS( constraint.GetRemoveAction(), Constraint::Discard, TEST_LOCATION ); - DALI_TEST_EQUALS( parent.GetCurrentColor(), parentColor, TEST_LOCATION ); - DALI_TEST_EQUALS( child.GetCurrentColor(), newChildColor, TEST_LOCATION ); + constraint.SetRemoveAction( Constraint::Bake ); + DALI_TEST_EQUALS( constraint.GetRemoveAction(), Constraint::Bake, TEST_LOCATION ); - // The tracking actor lags behind - DALI_TEST_EQUALS( trackingActor.GetCurrentColor(), previousColor, TEST_LOCATION ); + END_TEST; +} - DALI_TEST_EQUALS( parent.GetCurrentWorldColor(), parentColor, TEST_LOCATION ); - previousColor = Vector3( newChildColor ); - DALI_TEST_EQUALS( child.GetCurrentWorldColor(), previousColor, TEST_LOCATION ); +int UtcDaliConstraintSetRemoveActionN(void) +{ + // Attempt to set from uninitialised constraint - // Allow the tracking actor to catch up - application.SendNotification(); - application.Render(0); + TestApplication application; - DALI_TEST_EQUALS( parent.GetCurrentColor(), parentColor, TEST_LOCATION ); - DALI_TEST_EQUALS( child.GetCurrentColor(), newChildColor, TEST_LOCATION ); + Constraint constraint; + try + { + constraint.SetRemoveAction( Constraint::Discard ); + DALI_TEST_CHECK( false ); // Should not reach here! + } + catch( ... ) + { + DALI_TEST_CHECK( true ); + } - // The tracking actor catches up! - DALI_TEST_EQUALS( trackingActor.GetCurrentColor(), previousColor, TEST_LOCATION ); - DALI_TEST_EQUALS( parent.GetCurrentWorldColor(), parentColor, TEST_LOCATION ); - DALI_TEST_EQUALS( child.GetCurrentWorldColor(), previousColor, TEST_LOCATION ); END_TEST; } -int UtcDaliConstraintInvalidInputProperty(void) +int UtcDaliConstraintGetRemoveActionN(void) { - TestApplication application; - Actor actor = Actor::New(); - Constraint constraint = Constraint::New( Actor::Property::POSITION, LocalSource( PROPERTY_REGISTRATION_START_INDEX ), EqualToConstraint() ); + // Attempt to retrieve from uninitialised constraint - Stage::GetCurrent().Add( actor ); + TestApplication application; - // Cannot use type registered properties as input to constraints + Constraint constraint; try { - actor.ApplyConstraint( constraint ); - tet_result( TET_FAIL ); + Constraint::RemoveAction removeAction = constraint.GetRemoveAction(); + ( void )removeAction; + DALI_TEST_CHECK( false ); // Should not reach here! } - catch ( DaliException& e ) + catch( ... ) { - DALI_TEST_ASSERT( e, "mTargetObject->IsPropertyAConstraintInput( source.propertyIndex )", TEST_LOCATION ); + DALI_TEST_CHECK( true ); } + END_TEST; } -int UtcDaliBuiltinConstraintParentSize(void) +int UtcDaliConstraintBakeRemoveAction(void) { - TestApplication application; + // Ensure value is baked when constraint is removed - Actor parent = Actor::New(); - Vector3 parentSize(9,9,9); - parent.SetSize( parentSize ); - Stage::GetCurrent().Add( parent ); + TestApplication application; Actor actor = Actor::New(); - parent.Add( actor ); - - Vector3 startValue( Vector3::ZERO ); + Stage::GetCurrent().Add( actor ); application.SendNotification(); - application.Render(0); - DALI_TEST_CHECK( actor.GetCurrentSize() == startValue ); + application.Render(); - // Apply constraint + // Should not equal position by default + Vector3 position( 10.0f, 20.0f, 30.0f ); + DALI_TEST_CHECK( actor.GetCurrentPosition() != position ); - Constraint constraint = Constraint::New( Actor::Property::SIZE, ParentSource( Actor::Property::SIZE ), EqualToConstraint() ); - actor.ApplyConstraint( constraint ); + // Create a constraint that constrains to position + Constraint constraint = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, SetValueFunctor< Vector3 >( position ) ); + constraint.SetRemoveAction( Constraint::Bake ); + constraint.Apply(); application.SendNotification(); - application.Render(0); + application.Render(); - // Constraint should be fully applied - DALI_TEST_EQUALS( actor.GetCurrentSize(), parentSize, TEST_LOCATION ); + DALI_TEST_EQUALS( actor.GetCurrentPosition(), position, TEST_LOCATION ); - // This should be ignored - actor.SetSize( startValue ); + // Remove the constraint, it should still be at position + constraint.Remove(); - // Check that nothing has changed after a couple of buffer swaps application.SendNotification(); - application.Render(0); - DALI_TEST_EQUALS( actor.GetCurrentSize(), parentSize, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor.GetCurrentSize(), parentSize, TEST_LOCATION ); + application.Render(); - // Remove the constraint, then set new value - actor.RemoveConstraints(); - actor.SetSize( startValue ); + DALI_TEST_EQUALS( actor.GetCurrentPosition(), position, TEST_LOCATION ); - // Constraint should have been removed - application.SendNotification(); - application.Render(0); - DALI_TEST_EQUALS( actor.GetCurrentSize(), startValue, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor.GetCurrentSize(), startValue, TEST_LOCATION ); END_TEST; } -int UtcDaliBuiltinConstraintParentSizeRelative(void) +int UtcDaliConstraintDiscardRemoveAction(void) { - TestApplication application; + // Ensure value is baked when constraint is removed - Actor parent = Actor::New(); - Vector3 parentSize(9,9,9); - parent.SetSize( parentSize ); - Stage::GetCurrent().Add( parent ); + TestApplication application; Actor actor = Actor::New(); - parent.Add( actor ); - - Vector3 startValue( Vector3::ZERO ); - Vector3 scale(2,3,4); - Vector3 endValue( parentSize * scale ); + Stage::GetCurrent().Add( actor ); application.SendNotification(); - application.Render(0); - DALI_TEST_CHECK( actor.GetCurrentSize() == startValue ); + application.Render(); - // Apply constraint + // Get and store current position + Vector3 originalPosition = actor.GetCurrentPosition(); - Constraint constraint = Constraint::New( Actor::Property::SIZE, ParentSource( Actor::Property::SIZE ), RelativeToConstraint( scale ) ); - actor.ApplyConstraint( constraint ); + // Should not equal position by default + Vector3 position( 10.0f, 20.0f, 30.0f ); + DALI_TEST_CHECK( actor.GetCurrentPosition() != position ); + + // Create a constraint that constrains to position + Constraint constraint = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, SetValueFunctor< Vector3 >( position ) ); + constraint.SetRemoveAction( Constraint::Discard ); + constraint.Apply(); application.SendNotification(); - application.Render(0); + application.Render(); - // Constraint should be fully applied - DALI_TEST_EQUALS( actor.GetCurrentSize(), endValue, TEST_LOCATION ); + DALI_TEST_EQUALS( actor.GetCurrentPosition(), position, TEST_LOCATION ); - // This should be ignored - actor.SetSize( startValue ); + // Remove the constraint, it should still be at position + constraint.Remove(); - // Check that nothing has changed after a couple of buffer swaps application.SendNotification(); - application.Render(0); - DALI_TEST_EQUALS( actor.GetCurrentSize(), endValue, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor.GetCurrentSize(), endValue, TEST_LOCATION ); + application.Render(); - // Remove the constraint, then set new value - actor.RemoveConstraints(); - actor.SetSize( startValue ); + DALI_TEST_EQUALS( actor.GetCurrentPosition(), originalPosition, TEST_LOCATION ); + DALI_TEST_CHECK( actor.GetCurrentPosition() != position ); - // Constraint should have been removed - application.SendNotification(); - application.Render(0); - DALI_TEST_EQUALS( actor.GetCurrentSize(), startValue, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor.GetCurrentSize(), startValue, TEST_LOCATION ); END_TEST; } -int UtcDaliBuiltinConstraintScaleToFitConstraint(void) +/////////////////////////////////////////////////////////////////////////////// + +/////////////////////////////////////////////////////////////////////////////// +// Constraint::Apply +// Constraint::Remove +/////////////////////////////////////////////////////////////////////////////// +int UtcDaliConstraintApplyRemove(void) { - TestApplication application; + // Ensure constraint functors are called appropriately - Actor parent = Actor::New(); - Vector3 startParentSize( 10, 10, 10 ); - parent.SetSize( startParentSize ); - Stage::GetCurrent().Add( parent ); + TestApplication application; + bool functorCalled = false; Actor actor = Actor::New(); - Vector3 startChildSize( 5, 5, 5 ); - actor.SetSize( startChildSize ); - parent.Add( actor ); - - Vector3 endChildSize( 8, 8, 8 ); - Vector3 endParentSize( 4, 4, 4 ); - Vector3 startChildScale( 2, 2, 2 ); // startParentSize / startChildSize - Vector3 intermediateChildScale( 1.25, 1.25, 1.25 ); // startParentSize / endChildSize - Vector3 endChildScale( 0.5, 0.5, 0.5 ); // endParentSize / endChildSize + Stage::GetCurrent().Add( actor ); application.SendNotification(); - application.Render(0); - DALI_TEST_CHECK( actor.GetCurrentSize() == startChildSize ); + application.Render(); - // Apply constraint + DALI_TEST_EQUALS( functorCalled, false, TEST_LOCATION ); - Constraint constraint = Constraint::New( Actor::Property::SCALE, - LocalSource( Actor::Property::SIZE ), - ParentSource( Actor::Property::SIZE ), - ScaleToFitConstraint() ); - actor.ApplyConstraint( constraint ); + // Create a constraint and apply, functor should be called + Constraint constraint = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, BasicCalledFunctor< Vector3 >( functorCalled ) ); + constraint.Apply(); application.SendNotification(); - application.Render(0); + application.Render(); - // Constraint should be fully applied, but parent size is larger than child - DALI_TEST_EQUALS( actor.GetCurrentSize(), startChildSize, TEST_LOCATION ); - DALI_TEST_EQUALS( actor.GetCurrentScale(), startChildScale, TEST_LOCATION ); + DALI_TEST_EQUALS( functorCalled, true, TEST_LOCATION ); - // This should be allowed (still less than parent size) - actor.SetSize( endChildSize ); + // Reset + functorCalled = false; + + // Remove the constraint, functor should not be called + constraint.Remove(); application.SendNotification(); - application.Render(0); - DALI_TEST_EQUALS( actor.GetCurrentSize(), endChildSize, TEST_LOCATION ); - DALI_TEST_EQUALS( actor.GetCurrentScale(), intermediateChildScale, TEST_LOCATION ); + application.Render(); - // Reduce the parent size - parent.SetSize( endParentSize ); + DALI_TEST_EQUALS( functorCalled, false, TEST_LOCATION ); + + // Re-apply the constraint, functor should be called again + constraint.Apply(); application.SendNotification(); - application.Render(0); - - // Constraint should be fully applied - DALI_TEST_EQUALS( actor.GetCurrentSize(), endChildSize, TEST_LOCATION ); - DALI_TEST_EQUALS( actor.GetCurrentScale(), endChildScale, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor.GetCurrentSize(), endChildSize, TEST_LOCATION ); - DALI_TEST_EQUALS( actor.GetCurrentScale(), endChildScale, TEST_LOCATION ); + application.Render(); + + DALI_TEST_EQUALS( functorCalled, true, TEST_LOCATION ); + END_TEST; } -int UtcDaliBuiltinConstraintScaleToFitKeepAspectRatio(void) +int UtcDaliConstraintApplyBeforeAddedToStage(void) { - TestApplication application; + // Constraint gets applied to an off-stage actor. + // Constraint should be automatically applied when the actor is added to the stage and not before - Actor parent = Actor::New(); - Vector3 parentSize1( 10, 10, 10 ); - parent.SetSize( parentSize1 ); - Stage::GetCurrent().Add( parent ); + TestApplication application; + bool functorCalled = false; + // Create an actor and a constraint and apply, DON'T add to stage just yet Actor actor = Actor::New(); - Vector3 childSize( 4, 5, 5 ); - actor.SetSize( childSize ); - parent.Add( actor ); + Constraint constraint = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, BasicCalledFunctor< Vector3 >( functorCalled ) ); + constraint.Apply(); + + application.SendNotification(); + application.Render(); + + // Should NOT be called + DALI_TEST_EQUALS( functorCalled, false, TEST_LOCATION ); + + // Add actor to stage + Stage::GetCurrent().Add( actor ); application.SendNotification(); - application.Render(0); - Vector3 childScale1( 1.0f, 1.0f, 1.0f ); - DALI_TEST_EQUALS( actor.GetCurrentScale(), childScale1, TEST_LOCATION ); + application.Render(); + + // Should now be called + DALI_TEST_EQUALS( functorCalled, true, TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliConstraintApplyAndRemoveBeforeAddedToStage(void) +{ + // Constraint gets applied to an off-stage actor, then gets removed before it's added to the stage + // Constraint should NOT be called at all - // Apply constraint + TestApplication application; + bool functorCalled = false; - Constraint constraint = Constraint::New( Actor::Property::SCALE, - LocalSource( Actor::Property::SIZE ), - ParentSource( Actor::Property::SIZE ), - ScaleToFitKeepAspectRatioConstraint() ); - actor.ApplyConstraint( constraint ); + // Create an actor and a constraint and apply, DON'T add to stage just yet + Actor actor = Actor::New(); + Constraint constraint = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, BasicCalledFunctor< Vector3 >( functorCalled ) ); + constraint.Apply(); application.SendNotification(); - application.Render(0); + application.Render(); + + // Should NOT be called + DALI_TEST_EQUALS( functorCalled, false, TEST_LOCATION ); - // Constraint should be fully applied, but parent size is larger than child - Vector3 childScale2( 2.0f, 2.0f, 2.0f ); - DALI_TEST_EQUALS( actor.GetCurrentScale(), childScale2, TEST_LOCATION ); + // Remove the constraint + constraint.Remove(); - // change parent size - Vector3 parentSize2( 40, 50, 50 ); - parent.SetSize( parentSize2 ); + // Add actor to stage + Stage::GetCurrent().Add( actor ); application.SendNotification(); - application.Render(0); + application.Render(); + + // Still should NOT be called + DALI_TEST_EQUALS( functorCalled, false, TEST_LOCATION ); - // Constraint should be fully applied, but parent size is larger than child - Vector3 childScale3( 10.0f, 10.0f, 10.0f ); - DALI_TEST_EQUALS( actor.GetCurrentScale(), childScale3, TEST_LOCATION ); END_TEST; } - -int UtcDaliBuiltinConstraintScaleToFillXYKeepAspectRatio(void) +int UtcDaliConstraintApplyActorStagedUnstaged(void) { - TestApplication application; + // Apply a constraint to an actor which is staged and unstaged. + // Functor should only be called while the actor is staged. - Actor parent = Actor::New(); - Vector3 parentSize1( 10, 10, 10 ); - parent.SetSize( parentSize1 ); - Stage::GetCurrent().Add( parent ); + TestApplication application; + bool functorCalled = false; + // Create an actor and add to stage Actor actor = Actor::New(); - Vector3 childSize( 4, 5, 5 ); - actor.SetSize( childSize ); - parent.Add( actor ); + Stage stage = Stage::GetCurrent(); + stage.Add( actor ); + + // Create a constraint and apply + Constraint constraint = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, BasicCalledFunctor< Vector3 >( functorCalled ) ); + constraint.Apply(); application.SendNotification(); - application.Render(0); - Vector3 childScale1( 1.0f, 1.0f, 1.0f ); - DALI_TEST_EQUALS( actor.GetCurrentScale(), childScale1, TEST_LOCATION ); + application.Render(); - // Apply constraint + // Constraint should be called + DALI_TEST_EQUALS( functorCalled, true, TEST_LOCATION ); - Constraint constraint = Constraint::New( Actor::Property::SCALE, - LocalSource( Actor::Property::SIZE ), - ParentSource( Actor::Property::SIZE ), - ScaleToFillXYKeepAspectRatioConstraint() ); - actor.ApplyConstraint( constraint ); + // Reset + functorCalled = false; + + // Remove actor from stage + stage.Remove( actor ); application.SendNotification(); - application.Render(0); + application.Render(); - // Constraint should be fully applied, but parent size is larger than child - float val = 10.f / 4.f; - Vector3 childScale2( val, val, val ); - DALI_TEST_EQUALS( actor.GetCurrentScale(), childScale2, TEST_LOCATION ); + // Constraint should NOT be called + DALI_TEST_EQUALS( functorCalled, false, TEST_LOCATION ); - // change parent size - Vector3 parentSize2( 40, 50, 50 ); - parent.SetSize( parentSize2 ); + // Re-add to stage + stage.Add( actor ); application.SendNotification(); - application.Render(0); + application.Render(); + + // Constraint should be called + DALI_TEST_EQUALS( functorCalled, true, TEST_LOCATION ); - // Constraint should be fully applied, but parent size is larger than child - Vector3 childScale3( 10.0f, 10.0f, 10.0f ); - DALI_TEST_EQUALS( actor.GetCurrentScale(), childScale3, TEST_LOCATION ); END_TEST; } -int UtcDaliBuiltinConstraintEqualToConstraint(void) +int UtcDaliConstraintApplySeveralTimes(void) { + // Apply the same constraint several times. + // Should not cause any problems (subsequent attempts should be no-ops) + TestApplication application; + int count = 0; + + // Create an actor and add to stage + Actor actor = Actor::New(); + Stage stage = Stage::GetCurrent(); + stage.Add( actor ); - Actor actor1 = Actor::New(); - Vector3 startPosition( 10, 10, 10 ); - actor1.SetPosition( startPosition ); - Stage::GetCurrent().Add( actor1 ); + // Create a constraint and apply + Constraint constraint = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, CalledCountFunctor< Vector3 >( count ) ); + constraint.Apply(); - Actor actor2 = Actor::New(); - Vector3 startSize( 100, 100, 100 ); - actor2.SetSize( startSize ); - Stage::GetCurrent().Add( actor2 ); + // Apply again + constraint.Apply(); // no-op application.SendNotification(); - application.Render(0); - DALI_TEST_CHECK( actor1.GetCurrentPosition() == startPosition ); - DALI_TEST_CHECK( actor2.GetCurrentSize() == startSize ); + application.Render(); - // Apply constraint - actor1 size == actor2 position + // Should only have been called once + DALI_TEST_EQUALS( count, 1, TEST_LOCATION ); - Constraint constraint = Constraint::New( Actor::Property::SIZE, - Source( actor1, Actor::Property::POSITION ), - EqualToConstraint() ); - constraint.SetRemoveAction( Constraint::Discard ); - actor2.ApplyConstraint( constraint ); + // Reset + count = 0; + + // Apply again + constraint.Apply(); // no-op application.SendNotification(); - application.Render(0); + application.Render(); - // Constraint should be fully applied - DALI_TEST_EQUALS( actor2.GetCurrentSize(), startPosition, TEST_LOCATION ); + // Constraint should not have been called as the input-properties (none) have not changed for the constraint + DALI_TEST_EQUALS( count, 0, TEST_LOCATION ); - // Change the input - Vector3 endPosition( 2, 2, 2 ); - actor1.SetPosition( endPosition ); + // Reset + count = 0; + + // Change the position property, apply again + actor.SetPosition( 10.0f, 10.0f ); + constraint.Apply(); application.SendNotification(); - application.Render(0); + application.Render(); - // Constraint should be fully applied - DALI_TEST_EQUALS( actor2.GetCurrentSize(), endPosition, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor2.GetCurrentSize(), endPosition, TEST_LOCATION ); + // Constraint should have been called once + DALI_TEST_EQUALS( count, 1, TEST_LOCATION ); - // - // Check float variant of constraint - // - float startOpacity(1.0f); - float endOpacity(0.2f); - actor1.SetOpacity( startOpacity ); - actor2.SetOpacity( startOpacity ); + END_TEST; +} - application.SendNotification(); - application.Render(0); - DALI_TEST_EQUALS( actor1.GetCurrentOpacity(), startOpacity, TEST_LOCATION ); - DALI_TEST_EQUALS( actor2.GetCurrentOpacity(), startOpacity, TEST_LOCATION ); +/////////////////////////////////////////////////////////////////////////////// - Constraint constraint2 = Constraint::New( Actor::Property::COLOR_ALPHA, - Source( actor1, Actor::Property::COLOR_ALPHA ), - EqualToConstraint() ); - constraint2.SetRemoveAction( Constraint::Discard ); - actor2.ApplyConstraint( constraint2 ); +/////////////////////////////////////////////////////////////////////////////// +// Constraint::AddSource +/////////////////////////////////////////////////////////////////////////////// +namespace UtcDaliConstraintAddSource +{ +void Function( Vector3& /* current */, const PropertyInputContainer& inputs ) +{ + DALI_TEST_EQUALS( inputs.Size(), 4u, TEST_LOCATION ); + DALI_TEST_EQUALS( inputs[0]->GetType(), Property::VECTOR3, TEST_LOCATION ); + DALI_TEST_EQUALS( inputs[1]->GetType(), Property::ROTATION, TEST_LOCATION ); + DALI_TEST_EQUALS( inputs[2]->GetType(), Property::VECTOR4, TEST_LOCATION ); + DALI_TEST_EQUALS( inputs[3]->GetType(), Property::BOOLEAN, TEST_LOCATION ); +} +} // namespace UtcDaliConstraintAddSource - actor1.SetOpacity(endOpacity); +int UtcDaliConstraintAddSourceP(void) +{ + // Ensure all sources are in the correct order in the functor - application.SendNotification(); - application.Render(0); + TestApplication application; - DALI_TEST_EQUALS( actor2.GetCurrentOpacity(), endOpacity, 0.000001f, TEST_LOCATION ); + Actor actor = Actor::New(); + Stage::GetCurrent().Add( actor ); - // - // Check Vector4 variant of constraint - // - actor1.SetColor( Color::GREEN ); - actor2.SetColor( Color::RED ); + // Create a constraint, add sources + Constraint constraint = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, &UtcDaliConstraintAddSource::Function ); + constraint.AddSource( LocalSource( Actor::Property::SIZE ) ); + constraint.AddSource( LocalSource( Actor::Property::ORIENTATION ) ); + constraint.AddSource( LocalSource( Actor::Property::COLOR ) ); + constraint.AddSource( LocalSource( Actor::Property::VISIBLE ) ); + constraint.Apply(); application.SendNotification(); - application.Render(0); - DALI_TEST_CHECK( actor1.GetCurrentColor() == Color::GREEN ); - DALI_TEST_CHECK( actor2.GetCurrentColor() == Color::RED ); - - Constraint constraint3 = Constraint::New( Actor::Property::COLOR, - Source( actor1, Actor::Property::COLOR ), - EqualToConstraint() ); - constraint3.SetRemoveAction( Constraint::Discard ); - actor2.ApplyConstraint( constraint3 ); - application.SendNotification(); - application.Render(0); - DALI_TEST_CHECK( actor2.GetCurrentColor() == Color::GREEN ); - - // - // Check Quaternion variant of constraint - // - Quaternion q1 = Quaternion( Math::PI_2, Vector3::XAXIS ); - Quaternion q2 = Quaternion( Math::PI_4, Vector3::YAXIS ); - actor1.SetOrientation( q1 ); - actor2.SetOrientation( q2 ); + application.Render(); - application.SendNotification(); - application.Render(0); - DALI_TEST_EQUALS( actor1.GetCurrentOrientation(), q1, 0.01, TEST_LOCATION ); - DALI_TEST_EQUALS( actor2.GetCurrentOrientation(), q2, 0.01, TEST_LOCATION ); - - Constraint constraint4 = Constraint::New( Actor::Property::ORIENTATION, - Source( actor1, Actor::Property::ORIENTATION ), - EqualToConstraint() ); - constraint4.SetRemoveAction( Constraint::Discard ); - actor2.ApplyConstraint( constraint4 ); - application.SendNotification(); - application.Render(0); - DALI_TEST_EQUALS( actor2.GetCurrentOrientation(), q1, 0.01, TEST_LOCATION ); - - // - // Check Matrix3 variant - // - EqualToConstraint equalToConstraint; - - Matrix3 a; - a.AsFloat()[0] = 1.f; - Matrix3 b; - b.AsFloat()[0] = 2.f; - PropertyInputAbstraction pi(b); - - Matrix3 c = equalToConstraint(a,pi); - DALI_TEST_EQUALS( c.AsFloat()[0], b.AsFloat()[0], 0.01, TEST_LOCATION); END_TEST; } -int UtcDaliBuiltinConstraintRelativeToConstraint(void) +int UtcDaliConstraintAddSourceN(void) { - TestApplication application; + // Attempt to set from uninitialised constraint - Actor actor1 = Actor::New(); - Vector3 startPosition( 10, 10, 10 ); - actor1.SetPosition( startPosition ); - Stage::GetCurrent().Add( actor1 ); + TestApplication application; - Actor actor2 = Actor::New(); - Vector3 startSize( 100, 100, 100 ); - actor2.SetSize( startSize ); - Stage::GetCurrent().Add( actor2 ); + Constraint constraint; + try + { + constraint.AddSource( LocalSource( Actor::Property::POSITION ) ); + DALI_TEST_CHECK( false ); // Should not reach here! + } + catch( ... ) + { + DALI_TEST_CHECK( true ); + } - application.SendNotification(); - application.Render(0); - DALI_TEST_CHECK( actor1.GetCurrentPosition() == startPosition ); - DALI_TEST_CHECK( actor2.GetCurrentSize() == startSize ); + END_TEST; +} +/////////////////////////////////////////////////////////////////////////////// - // Apply constraint - actor1 size == actor2 position +/////////////////////////////////////////////////////////////////////////////// +namespace TestChaining +{ - RelativeToConstraint( 0.f ); - Vector3 scale( 0.5, 0.6, 0.7 ); - Constraint constraint = Constraint::New( Actor::Property::SIZE, - Source( actor1, Actor::Property::POSITION ), - RelativeToConstraint( scale ) ); - constraint.SetRemoveAction( Constraint::Discard ); - actor2.ApplyConstraint( constraint ); +const Vector3 gFunction1Output( Vector3::ONE ); +void Function1( Vector3& current, const PropertyInputContainer& /* inputs */ ) +{ + // current is original position + DALI_TEST_EQUALS( current, Vector3::ZERO, TEST_LOCATION ); + current = gFunction1Output; +} - application.SendNotification(); - application.Render(0); +const Vector3 gFunction2Output( 10.0f, 20.0f, 30.0f ); +void Function2( Vector3& current, const PropertyInputContainer& /* inputs */ ) +{ + // current is output from Function1 + DALI_TEST_EQUALS( current, gFunction1Output, TEST_LOCATION ); - // Constraint should be fully applied - DALI_TEST_EQUALS( actor2.GetCurrentSize(), scale * startPosition, TEST_LOCATION ); + current = gFunction2Output; +} - // Change the input - Vector3 endPosition( 2, 2, 2 ); - actor1.SetPosition( endPosition ); +const Vector3 gFunction3Output( 10.0f, 20.0f, 30.0f ); +void Function3( Vector3& current, const PropertyInputContainer& /* inputs */ ) +{ + // current is output from Function2 + DALI_TEST_EQUALS( current, gFunction2Output, TEST_LOCATION ); - application.SendNotification(); - application.Render(0); + current = gFunction3Output; +} - // Constraint should be fully applied - DALI_TEST_EQUALS( actor2.GetCurrentSize(), scale * endPosition, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( actor2.GetCurrentSize(), scale * endPosition, TEST_LOCATION ); +const Vector3 gFunction4Output( 10.0f, 20.0f, 30.0f ); +void Function4( Vector3& current, const PropertyInputContainer& /* inputs */ ) +{ + // current is output from Function3 + DALI_TEST_EQUALS( current, gFunction3Output, TEST_LOCATION ); - // - // Check float variant of constraint - // - float scale2( 0.5f ); - float startOpacity(1.0f); - actor1.SetOpacity( startOpacity ); - actor2.SetOpacity( startOpacity ); + current = gFunction4Output; +} - application.SendNotification(); - application.Render(0); - DALI_TEST_EQUALS( actor1.GetCurrentOpacity(), startOpacity, TEST_LOCATION ); - DALI_TEST_EQUALS( actor2.GetCurrentOpacity(), startOpacity, TEST_LOCATION ); - - Constraint constraint2 = Constraint::New( Actor::Property::COLOR_ALPHA, - Source( actor1, Actor::Property::COLOR_ALPHA ), - RelativeToConstraintFloat(scale2) ); - constraint2.SetRemoveAction( Constraint::Discard ); - actor2.ApplyConstraint(constraint2); - application.SendNotification(); - application.Render(0); +void Function5( Vector3& current, const PropertyInputContainer& /* inputs */ ) +{ + // current is output from Function4 + DALI_TEST_EQUALS( current, gFunction4Output, TEST_LOCATION ); - DALI_TEST_EQUALS( actor2.GetCurrentOpacity(), startOpacity * scale2, TEST_LOCATION ); - END_TEST; + current = Vector3::ZERO; } -int UtcDaliBuiltinConstraintFunctions(void) +} // namespace TestChaining + +int UtcDaliConstraintChaining(void) { + // Apply several constraints to the same property and ensure the functors are called in the correct order. + TestApplication application; - { - SourceWidthFixedHeight sourceWidthFixedHeight( 10.f ); - Vector3 current; - { - Vector3 reference(1, 10, 0); - Vector3 value = sourceWidthFixedHeight( current, PropertyInputAbstraction(Vector3::ONE) ); - DALI_TEST_EQUALS( reference, value, TEST_LOCATION ); - } - { - Vector3 reference(10, 10, 0); - Vector3 value = sourceWidthFixedHeight( current, PropertyInputAbstraction(Vector3::ONE*10.f) ); - DALI_TEST_EQUALS( reference, value, TEST_LOCATION ); - } - { - Vector3 reference(10,10,0); - Vector3 value = sourceWidthFixedHeight( current, PropertyInputAbstraction(Vector3::ONE*10.f) ); - DALI_TEST_EQUALS( reference, value, TEST_LOCATION ); - } - } + Actor actor = Actor::New(); + Stage::GetCurrent().Add( actor ); - { // LookAt - Quaternion current(0, Vector3::YAXIS); - PropertyInputAbstraction target(Vector3::ZAXIS); - PropertyInputAbstraction targetRotation(Vector3::YAXIS); - PropertyInputAbstraction camera(Vector3::ZERO); + Constraint constraint1 = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, &TestChaining::Function1 ); + Constraint constraint2 = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, &TestChaining::Function2 ); + Constraint constraint3 = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, &TestChaining::Function3 ); + Constraint constraint4 = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, &TestChaining::Function4 ); + Constraint constraint5 = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, &TestChaining::Function5 ); - { - Quaternion reference(1., 0., 0., 0.); - Quaternion value = LookAt( current, target, camera, targetRotation ); - DALI_TEST_EQUALS( reference, value, 0.001, TEST_LOCATION ); - } + constraint1.Apply(); + constraint2.Apply(); + constraint3.Apply(); + constraint4.Apply(); + constraint5.Apply(); - } + application.SendNotification(); + application.Render(); END_TEST; } +/////////////////////////////////////////////////////////////////////////////// diff --git a/automated-tests/src/dali/utc-Dali-ConstraintFunction.cpp b/automated-tests/src/dali/utc-Dali-ConstraintFunction.cpp new file mode 100644 index 0000000..d7ad79b --- /dev/null +++ b/automated-tests/src/dali/utc-Dali-ConstraintFunction.cpp @@ -0,0 +1,347 @@ +/* + * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include + +#include +#include +#include + +using namespace Dali; + +/////////////////////////////////////////////////////////////////////////////// +void utc_dali_constraint_function_startup(void) +{ + test_return_value = TET_UNDEF; +} + +void utc_dali_constraint_function_cleanup(void) +{ + test_return_value = TET_PASS; +} +/////////////////////////////////////////////////////////////////////////////// + +/////////////////////////////////////////////////////////////////////////////// +namespace +{ +bool gFunctionCalled = false; + +template< typename T > +void TestCallbackFunction( T& /* current*/ , const PropertyInputContainer& /* inputs */ ) +{ + gFunctionCalled = true; +} + +template< typename T > +struct TestCallbackFunctor +{ + TestCallbackFunctor( bool& functorCalled ) : mFunctorCalled( functorCalled ) { } + + void operator()( T& /* current*/ , const PropertyInputContainer& /* inputs */ ) + { + mFunctorCalled = true; + } + + bool& mFunctorCalled; +}; + +template< typename T > +struct TestFunctorMethod +{ + TestFunctorMethod( bool& functorCalled ) : mFunctorCalled( functorCalled ) { } + + void Method( T& /* current*/ , const PropertyInputContainer& /* inputs */ ) + { + mFunctorCalled = true; + } + + bool& mFunctorCalled; +}; + +} // unnamed namespace +/////////////////////////////////////////////////////////////////////////////// + +/////////////////////////////////////////////////////////////////////////////// +// Constraint::Function::Function( void( *function )( P&, const PropertyInputContainer& ) ) +/////////////////////////////////////////////////////////////////////////////// +namespace +{ +template< typename T > +void TestFunctionConstructor() +{ + gFunctionCalled = false; + Constraint::Function< T > function( &TestCallbackFunction< T > ); + T current; + PropertyInputContainer inputs; + + DALI_TEST_EQUALS( gFunctionCalled, false, TEST_LOCATION ); + CallbackBase::Execute< T&, const PropertyInputContainer& >( function, current, inputs ); + DALI_TEST_EQUALS( gFunctionCalled, true, TEST_LOCATION ); +} +} // unnamed namespace + +int UtcDaliConstraintFunctionWithFunction(void) +{ + TestFunctionConstructor< bool >(); + TestFunctionConstructor< int >(); + TestFunctionConstructor< unsigned int >(); + TestFunctionConstructor< float >(); + TestFunctionConstructor< Vector2 >(); + TestFunctionConstructor< Vector3 >(); + TestFunctionConstructor< Vector4 >(); + TestFunctionConstructor< Quaternion >(); + TestFunctionConstructor< Matrix >(); + TestFunctionConstructor< Matrix3 >(); + END_TEST; +} +/////////////////////////////////////////////////////////////////////////////// + +/////////////////////////////////////////////////////////////////////////////// +// Constraint::Function::Function( const T& object ) +/////////////////////////////////////////////////////////////////////////////// +namespace +{ +template< typename T > +void TestFunctorConstructor() +{ + bool called = false; + TestCallbackFunctor< T > functor( called ); + Constraint::Function< T > callback( functor ); + T current; + PropertyInputContainer inputs; + + DALI_TEST_EQUALS( called, false, TEST_LOCATION ); + CallbackBase::Execute< T&, const PropertyInputContainer& >( callback, current, inputs ); + DALI_TEST_EQUALS( called, true, TEST_LOCATION ); +} +} // unnamed namespace + +int UtcDaliConstraintFunctionWithFunctor(void) +{ + TestFunctorConstructor< bool >(); + TestFunctorConstructor< int >(); + TestFunctorConstructor< unsigned int >(); + TestFunctorConstructor< float >(); + TestFunctorConstructor< Vector2 >(); + TestFunctorConstructor< Vector3 >(); + TestFunctorConstructor< Vector4 >(); + TestFunctorConstructor< Quaternion >(); + TestFunctorConstructor< Matrix >(); + TestFunctorConstructor< Matrix3 >(); + END_TEST; +} +/////////////////////////////////////////////////////////////////////////////// + +/////////////////////////////////////////////////////////////////////////////// +// Constraint::Function::Function( const T& object, void ( T::*memberFunction ) ( P&, const PropertyInputContainer& ) ) +/////////////////////////////////////////////////////////////////////////////// +namespace +{ +template< typename T > +void TestFunctorMethodConstructor() +{ + bool called = false; + TestFunctorMethod< T > functor( called ); + Constraint::Function< T > callback( functor, &TestFunctorMethod< T >::Method ); + T current; + PropertyInputContainer inputs; + + DALI_TEST_EQUALS( called, false, TEST_LOCATION ); + CallbackBase::Execute< T&, const PropertyInputContainer& >( callback, current, inputs ); + DALI_TEST_EQUALS( called, true, TEST_LOCATION ); +} +} // unnamed namespace + +int UtcDaliConstraintFunctionWithMethodFunctor(void) +{ + TestFunctorMethodConstructor< bool >(); + TestFunctorMethodConstructor< int >(); + TestFunctorMethodConstructor< unsigned int >(); + TestFunctorMethodConstructor< float >(); + TestFunctorMethodConstructor< Vector2 >(); + TestFunctorMethodConstructor< Vector3 >(); + TestFunctorMethodConstructor< Vector4 >(); + TestFunctorMethodConstructor< Quaternion >(); + TestFunctorMethodConstructor< Matrix >(); + TestFunctorMethodConstructor< Matrix3 >(); + END_TEST; +} +/////////////////////////////////////////////////////////////////////////////// + +/////////////////////////////////////////////////////////////////////////////// +// Constraint::Function::Clone +/////////////////////////////////////////////////////////////////////////////// +namespace +{ +template< typename T > +void TestFunctionClone() +{ + gFunctionCalled = false; + Constraint::Function< T > callback( &TestCallbackFunction< T > ); + CallbackBase* clone = callback.Clone(); + + T current; + PropertyInputContainer inputs; + + DALI_TEST_EQUALS( gFunctionCalled, false, TEST_LOCATION ); + CallbackBase::Execute< T&, const PropertyInputContainer& >( *clone, current, inputs ); + DALI_TEST_EQUALS( gFunctionCalled, true, TEST_LOCATION ); + delete clone; +} + +template< typename T > +void TestFunctorClone() +{ + bool called = false; + TestCallbackFunctor< T > functor( called ); + Constraint::Function< T > callback( functor ); + CallbackBase* clone = callback.Clone(); + + T current; + PropertyInputContainer inputs; + + DALI_TEST_EQUALS( called, false, TEST_LOCATION ); + CallbackBase::Execute< T&, const PropertyInputContainer& >( *clone, current, inputs ); + DALI_TEST_EQUALS( called, true, TEST_LOCATION ); + delete clone; +} + +template< typename T > +void TestMethodFunctorClone() +{ + bool called = false; + TestFunctorMethod< T > functor( called ); + Constraint::Function< T > callback( functor, &TestFunctorMethod< T >::Method ); + CallbackBase* clone = callback.Clone(); + + T current; + PropertyInputContainer inputs; + + DALI_TEST_EQUALS( called, false, TEST_LOCATION ); + CallbackBase::Execute< T&, const PropertyInputContainer& >( *clone, current, inputs ); + DALI_TEST_EQUALS( called, true, TEST_LOCATION ); + delete clone; +} + +} // unnamed namespace + +int UtcDaliConstraintFunctionFunctionClone(void) +{ + TestFunctionClone< bool >(); + TestFunctionClone< int >(); + TestFunctionClone< unsigned int >(); + TestFunctionClone< float >(); + TestFunctionClone< Vector2 >(); + TestFunctionClone< Vector3 >(); + TestFunctionClone< Vector4 >(); + TestFunctionClone< Quaternion >(); + TestFunctionClone< Matrix >(); + TestFunctionClone< Matrix3 >(); + END_TEST; +} + +int UtcDaliConstraintFunctionFunctorClone(void) +{ + TestFunctorClone< bool >(); + TestFunctorClone< int >(); + TestFunctorClone< unsigned int >(); + TestFunctorClone< float >(); + TestFunctorClone< Vector2 >(); + TestFunctorClone< Vector3 >(); + TestFunctorClone< Vector4 >(); + TestFunctorClone< Quaternion >(); + TestFunctorClone< Matrix >(); + TestFunctorClone< Matrix3 >(); + END_TEST; +} + +int UtcDaliConstraintFunctionMethodFunctorClone(void) +{ + TestMethodFunctorClone< bool >(); + TestMethodFunctorClone< int >(); + TestMethodFunctorClone< unsigned int >(); + TestMethodFunctorClone< float >(); + TestMethodFunctorClone< Vector2 >(); + TestMethodFunctorClone< Vector3 >(); + TestMethodFunctorClone< Vector4 >(); + TestMethodFunctorClone< Quaternion >(); + TestMethodFunctorClone< Matrix >(); + TestMethodFunctorClone< Matrix3 >(); + END_TEST; +} +/////////////////////////////////////////////////////////////////////////////// + +/////////////////////////////////////////////////////////////////////////////// +namespace +{ +struct CountFunctor +{ + CountFunctor( int& count ) + : mCount( count ) + { + ++mCount; + } + + CountFunctor( const CountFunctor& other ) + : mCount( other.mCount ) + { + ++mCount; + } + + CountFunctor& operator=( const CountFunctor& other ) + { + return *this; + } + + ~CountFunctor() + { + --mCount; + } + + void operator()( bool& /* current*/ , const PropertyInputContainer& /* inputs */ ) + { + } + + int& mCount; +}; +} // unnamed namespace + +int UtcDaliConstraintFunctionEnsureMemoryCleanup(void) +{ + // Functors are new'd in Constraint::Function, so check that all memory is released at the end + + int count = 0; + + { + CountFunctor functor( count ); + Constraint::Function< bool > callback1( functor ); + Constraint::Function< bool > callback2( functor ); + Constraint::Function< bool > callback3( functor ); + Constraint::Function< bool > callback4( functor ); + Constraint::Function< bool > callback5( functor ); + Constraint::Function< bool > callback6( functor ); + Constraint::Function< bool > callback7( functor ); + Constraint::Function< bool > callback8( functor ); + Constraint::Function< bool > callback9( functor ); + DALI_TEST_EQUALS( count, 10, TEST_LOCATION ); + } + + DALI_TEST_EQUALS( count, 0, TEST_LOCATION ); + + END_TEST; +} +/////////////////////////////////////////////////////////////////////////////// diff --git a/automated-tests/src/dali/utc-Dali-ConstraintSource.cpp b/automated-tests/src/dali/utc-Dali-ConstraintSource.cpp new file mode 100644 index 0000000..7c69e21 --- /dev/null +++ b/automated-tests/src/dali/utc-Dali-ConstraintSource.cpp @@ -0,0 +1,146 @@ +/* + * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include + +#include +#include +#include + +using namespace Dali; + +/////////////////////////////////////////////////////////////////////////////// +void utc_dali_constraint_source_startup(void) +{ + test_return_value = TET_UNDEF; +} + +void utc_dali_constraint_source_cleanup(void) +{ + test_return_value = TET_PASS; +} +/////////////////////////////////////////////////////////////////////////////// + +/////////////////////////////////////////////////////////////////////////////// +// LocalSource +/////////////////////////////////////////////////////////////////////////////// +int UtcDaliLocalSource(void) +{ + LocalSource source( Actor::Property::POSITION ); + + DALI_TEST_EQUALS( source.propertyIndex, Actor::Property::POSITION, TEST_LOCATION ); + + END_TEST; +} + +/////////////////////////////////////////////////////////////////////////////// + +/////////////////////////////////////////////////////////////////////////////// +// ParentSource +/////////////////////////////////////////////////////////////////////////////// +int UtcDaliParentSource(void) +{ + ParentSource source( Actor::Property::POSITION ); + + DALI_TEST_EQUALS( source.propertyIndex, Actor::Property::POSITION, TEST_LOCATION ); + + END_TEST; +} + +/////////////////////////////////////////////////////////////////////////////// + +/////////////////////////////////////////////////////////////////////////////// +// Source +/////////////////////////////////////////////////////////////////////////////// +int UtcDaliSource1(void) +{ + Actor actor; + Source source( actor, Actor::Property::SIZE ); + + DALI_TEST_CHECK( ! source.object ); + DALI_TEST_EQUALS( source.propertyIndex, Actor::Property::SIZE, TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliSource2(void) +{ + TestApplication application; + + Actor actor = Actor::New(); + + Source source( actor, Actor::Property::SIZE ); + DALI_TEST_EQUALS( source.object, actor, TEST_LOCATION ); + DALI_TEST_EQUALS( source.propertyIndex, Actor::Property::SIZE, TEST_LOCATION ); + + END_TEST; +} +/////////////////////////////////////////////////////////////////////////////// + +/////////////////////////////////////////////////////////////////////////////// +// ConstraintSource +/////////////////////////////////////////////////////////////////////////////// +int UtcDaliConstraintSourceWithSource1(void) +{ + Actor actor; + + ConstraintSource source( Source( actor, Actor::Property::PARENT_ORIGIN ) ); + DALI_TEST_CHECK( ! source.object ); + DALI_TEST_EQUALS( source.propertyIndex, Actor::Property::PARENT_ORIGIN, TEST_LOCATION ); + DALI_TEST_EQUALS( source.sourceType, OBJECT_PROPERTY, TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliConstraintSourceWithSource2(void) +{ + TestApplication application; + + Actor actor = Actor::New(); + + ConstraintSource source( Source( actor, Actor::Property::PARENT_ORIGIN ) ); + DALI_TEST_EQUALS( source.object, actor, TEST_LOCATION ); + DALI_TEST_EQUALS( source.propertyIndex, Actor::Property::PARENT_ORIGIN, TEST_LOCATION ); + DALI_TEST_EQUALS( source.sourceType, OBJECT_PROPERTY, TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliConstraintSourceWithLocalSource(void) +{ + Actor actor; + + ConstraintSource source( LocalSource( Actor::Property::PARENT_ORIGIN ) ); + DALI_TEST_CHECK( ! source.object ); + DALI_TEST_EQUALS( source.propertyIndex, Actor::Property::PARENT_ORIGIN, TEST_LOCATION ); + DALI_TEST_EQUALS( source.sourceType, LOCAL_PROPERTY, TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliConstraintSourceWithParentSource(void) +{ + Actor actor; + + ConstraintSource source( ParentSource( Actor::Property::PARENT_ORIGIN ) ); + DALI_TEST_CHECK( ! source.object ); + DALI_TEST_EQUALS( source.propertyIndex, Actor::Property::PARENT_ORIGIN, TEST_LOCATION ); + DALI_TEST_EQUALS( source.sourceType, PARENT_PROPERTY, TEST_LOCATION ); + + END_TEST; +} +/////////////////////////////////////////////////////////////////////////////// diff --git a/automated-tests/src/dali/utc-Dali-Constraints.cpp b/automated-tests/src/dali/utc-Dali-Constraints.cpp new file mode 100644 index 0000000..c11cac3 --- /dev/null +++ b/automated-tests/src/dali/utc-Dali-Constraints.cpp @@ -0,0 +1,398 @@ +/* + * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include + +#include +#include +#include + +using namespace Dali; + +/////////////////////////////////////////////////////////////////////////////// +void utc_dali_constraints_startup(void) +{ + test_return_value = TET_UNDEF; +} + +void utc_dali_constraints_cleanup(void) +{ + test_return_value = TET_PASS; +} +/////////////////////////////////////////////////////////////////////////////// + +/////////////////////////////////////////////////////////////////////////////// +namespace +{ + +struct PropertyInputImpl : public PropertyInput +{ +public: + + // Constants + static const bool BOOLEAN_VALUE; + static const float FLOAT_VALUE; + static const int INTEGER_VALUE; + static const unsigned int UNSIGNED_INTEGER_VALUE; + static const Vector2 VECTOR2_VALUE; + static const Vector3 VECTOR3_VALUE; + static const Vector4 VECTOR4_VALUE; + static const Matrix3 MATRIX3_VALUE; + static const Matrix MATRIX_VALUE; + static const Quaternion QUATERNION_VALUE; + + // Construction & Destruction + PropertyInputImpl( Property::Type type ) : mType( type ) { } + virtual ~PropertyInputImpl() { } + + // Methods + Property::Type GetType() const { return mType; } + + // Virtual Methods + virtual const bool& GetBoolean() const { return BOOLEAN_VALUE; } + virtual const float& GetFloat() const { return FLOAT_VALUE; } + virtual const int& GetInteger() const { return INTEGER_VALUE; } + virtual const unsigned int& GetUnsignedInteger() const { return UNSIGNED_INTEGER_VALUE; } + virtual const Vector2& GetVector2() const { return VECTOR2_VALUE; } + virtual const Vector3& GetVector3() const { return VECTOR3_VALUE; } + virtual const Vector4& GetVector4() const { return VECTOR4_VALUE; } + virtual const Matrix3& GetMatrix3() const { return MATRIX3_VALUE; } + virtual const Matrix& GetMatrix() const { return MATRIX_VALUE; } + virtual const Quaternion& GetQuaternion() const { return QUATERNION_VALUE; } + + // Data + Property::Type mType; +}; + +const bool PropertyInputImpl::BOOLEAN_VALUE = true; +const float PropertyInputImpl::FLOAT_VALUE = 123.0f; +const int PropertyInputImpl::INTEGER_VALUE = 456; +const unsigned int PropertyInputImpl::UNSIGNED_INTEGER_VALUE = 789u; +const Vector2 PropertyInputImpl::VECTOR2_VALUE = Vector2( 10.0f, 20.0f ); +const Vector3 PropertyInputImpl::VECTOR3_VALUE = Vector3( 30.0f, 40.0f, 50.0f ); +const Vector4 PropertyInputImpl::VECTOR4_VALUE = Vector4( 60.0f, 70.0f, 80.0f, 90.0f ); +const Matrix3 PropertyInputImpl::MATRIX3_VALUE ( 1.0f, 2.0f, 3.0f, + 4.0f, 5.0f, 6.0f, + 7.0f, 8.0f, 9.0f ); +const Matrix PropertyInputImpl::MATRIX_VALUE = Matrix::IDENTITY; +const Quaternion PropertyInputImpl::QUATERNION_VALUE ( 1.0f, 2.0f, 3.0f, 4.0f ); + +struct Vector3PropertyInput : public PropertyInputImpl +{ +public: + + // Construction & Destruction + Vector3PropertyInput( Vector3& value ) + : PropertyInputImpl( Property::VECTOR3 ), + mValue( value ) + { + } + + ~Vector3PropertyInput() + { + } + + const Vector3& GetVector3() const + { + return mValue; + } + + // Data + Vector3& mValue; +}; + +struct QuaternionPropertyInput : public PropertyInputImpl +{ +public: + + // Construction & Destruction + QuaternionPropertyInput( Quaternion& value ) + : PropertyInputImpl( Property::ROTATION ), + mValue( value ) + { + } + + ~QuaternionPropertyInput() + { + } + + const Quaternion& GetQuaternion() const + { + return mValue; + } + + // Data + Quaternion& mValue; +}; + +} // unnamed namespace +/////////////////////////////////////////////////////////////////////////////// + +/////////////////////////////////////////////////////////////////////////////// +// EqualToConstraint +/////////////////////////////////////////////////////////////////////////////// +int UtcDaliConstraintsEqualToConstraintFloat(void) +{ + PropertyInputContainer inputs; + PropertyInputImpl input( Property::FLOAT ); + inputs.PushBack( &input ); + + float value = 0.0f; + DALI_TEST_CHECK( value != PropertyInputImpl::FLOAT_VALUE ); + + EqualToConstraint constraint; + constraint( value, inputs ); + + DALI_TEST_EQUALS( value, PropertyInputImpl::FLOAT_VALUE, TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliConstraintsEqualToConstraintVector2(void) +{ + PropertyInputContainer inputs; + PropertyInputImpl input( Property::VECTOR2 ); + inputs.PushBack( &input ); + + Vector2 value; + DALI_TEST_CHECK( value != PropertyInputImpl::VECTOR2_VALUE ); + + EqualToConstraint constraint; + constraint( value, inputs ); + + DALI_TEST_EQUALS( value, PropertyInputImpl::VECTOR2_VALUE, TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliConstraintsEqualToConstraintVector3(void) +{ + PropertyInputContainer inputs; + PropertyInputImpl input( Property::VECTOR3 ); + inputs.PushBack( &input ); + + Vector3 value; + DALI_TEST_CHECK( value != PropertyInputImpl::VECTOR3_VALUE ); + + EqualToConstraint constraint; + constraint( value, inputs ); + + DALI_TEST_EQUALS( value, PropertyInputImpl::VECTOR3_VALUE, TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliConstraintsEqualToConstraintVector4(void) +{ + PropertyInputContainer inputs; + PropertyInputImpl input( Property::VECTOR4 ); + inputs.PushBack( &input ); + + Vector4 value; + DALI_TEST_CHECK( value != PropertyInputImpl::VECTOR4_VALUE ); + + EqualToConstraint constraint; + constraint( value, inputs ); + + DALI_TEST_EQUALS( value, PropertyInputImpl::VECTOR4_VALUE, TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliConstraintsEqualToConstraintQuaternion(void) +{ + PropertyInputContainer inputs; + PropertyInputImpl input( Property::ROTATION ); + inputs.PushBack( &input ); + + Quaternion value; + DALI_TEST_CHECK( value != PropertyInputImpl::QUATERNION_VALUE ); + + EqualToConstraint constraint; + constraint( value, inputs ); + + DALI_TEST_EQUALS( value, PropertyInputImpl::QUATERNION_VALUE, TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliConstraintsEqualToConstraintMatrix3(void) +{ + PropertyInputContainer inputs; + PropertyInputImpl input( Property::MATRIX3 ); + inputs.PushBack( &input ); + + Matrix3 value; + DALI_TEST_CHECK( value != PropertyInputImpl::MATRIX3_VALUE ); + + EqualToConstraint constraint; + constraint( value, inputs ); + + DALI_TEST_EQUALS( value, PropertyInputImpl::MATRIX3_VALUE, 0.1f, TEST_LOCATION); + + END_TEST; +} + +int UtcDaliConstraintsEqualToConstraintMatrix(void) +{ + PropertyInputContainer inputs; + PropertyInputImpl input( Property::MATRIX ); + inputs.PushBack( &input ); + + Matrix value; + DALI_TEST_CHECK( value != PropertyInputImpl::MATRIX_VALUE ); + + EqualToConstraint constraint; + constraint( value, inputs ); + + DALI_TEST_EQUALS( value, PropertyInputImpl::MATRIX_VALUE, TEST_LOCATION ); + + END_TEST; +} +/////////////////////////////////////////////////////////////////////////////// + +/////////////////////////////////////////////////////////////////////////////// +// RelativeToConstraint +/////////////////////////////////////////////////////////////////////////////// +int UtcDaliConstraintsRelativeToConstraintUsingFloat(void) +{ + PropertyInputContainer inputs; + PropertyInputImpl input( Property::VECTOR3 ); + inputs.PushBack( &input ); + + Vector3 value; + DALI_TEST_EQUALS( value, Vector3::ZERO, TEST_LOCATION ); + + const float scale( 4.0f ); + RelativeToConstraint constraint( scale ); + constraint( value, inputs ); + + DALI_TEST_EQUALS( value, PropertyInputImpl::VECTOR3_VALUE * scale, TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliConstraintsRelativeToConstraintUsingVector3(void) +{ + PropertyInputContainer inputs; + PropertyInputImpl input( Property::VECTOR3 ); + inputs.PushBack( &input ); + + Vector3 value; + DALI_TEST_EQUALS( value, Vector3::ZERO, TEST_LOCATION ); + + const Vector3 scale( 4.0f, 5.0f, 6.0f ); + RelativeToConstraint constraint( scale ); + constraint( value, inputs ); + + DALI_TEST_EQUALS( value, PropertyInputImpl::VECTOR3_VALUE * scale, TEST_LOCATION ); + + END_TEST; +} +/////////////////////////////////////////////////////////////////////////////// + +/////////////////////////////////////////////////////////////////////////////// +// RelativeToConstraintFloat +/////////////////////////////////////////////////////////////////////////////// +int UtcDaliConstraintsRelativeToConstraintFloat(void) +{ + PropertyInputContainer inputs; + PropertyInputImpl input( Property::VECTOR3 ); + inputs.PushBack( &input ); + + const float scale( 4.0f ); + + float value = 0.0f; + DALI_TEST_CHECK( value != PropertyInputImpl::FLOAT_VALUE * scale ); + + RelativeToConstraintFloat constraint( scale ); + constraint( value, inputs ); + + DALI_TEST_EQUALS( value, PropertyInputImpl::FLOAT_VALUE * scale, TEST_LOCATION ); + + END_TEST; +} +/////////////////////////////////////////////////////////////////////////////// + +/////////////////////////////////////////////////////////////////////////////// +// LookAt +/////////////////////////////////////////////////////////////////////////////// +int UtcDaliConstraintsLookAt(void) +{ + TestApplication application; + + Actor actor = Actor::New(); + DALI_TEST_EQUALS( actor.GetCurrentWorldOrientation(), Quaternion::IDENTITY, TEST_LOCATION ); + + Vector3 targetPosition; + Vector3 cameraPosition; + Quaternion targetOrientation; + + Vector3PropertyInput targetPositionProperty( targetPosition ); + Vector3PropertyInput cameraPositionProperty( cameraPosition ); + QuaternionPropertyInput targetOrientationProperty( targetOrientation ); + + PropertyInputContainer inputs; + inputs.PushBack( &targetPositionProperty ); + inputs.PushBack( &cameraPositionProperty ); + inputs.PushBack( &targetOrientationProperty ); + + Quaternion current; + + // 180 degrees round y + targetPosition = Vector3::ZERO; + cameraPosition = Vector3( 0.0f, 0.0f, 1.0f ); + targetOrientation = Quaternion::IDENTITY; + Quaternion lookAtOrientation( Quaternion( Radian( Math::PI ), Vector3::YAXIS ) ); + LookAt( current, inputs ); + DALI_TEST_EQUALS( current, lookAtOrientation, TEST_LOCATION ); + + // 180 degrees round y * -45 degrees round x + targetPosition = Vector3::ZERO; + cameraPosition = Vector3( 0.0f, -1.0f, 1.0f ); + targetOrientation = Quaternion::IDENTITY; + lookAtOrientation = Quaternion( Radian( Math::PI ), Vector3::YAXIS ) * Quaternion( Radian( Math::PI * 0.25f ), -Vector3::XAXIS ); + LookAt( current, inputs ); + DALI_TEST_EQUALS( current, lookAtOrientation, Math::MACHINE_EPSILON_10, TEST_LOCATION ); + + // 180 degrees round y * -45 degrees round x at different points + targetPosition = Vector3( 0.0f, 1.0f, -1.0f ); + cameraPosition = Vector3::ZERO; + targetOrientation = Quaternion::IDENTITY; + lookAtOrientation = Quaternion( Radian( Math::PI ), Vector3::YAXIS ) * Quaternion( Radian( Math::PI * 0.25f ), -Vector3::XAXIS ); + LookAt( current, inputs ); + DALI_TEST_EQUALS( current, lookAtOrientation, Math::MACHINE_EPSILON_10, TEST_LOCATION ); + + // 225 degrees round y + targetPosition = Vector3( -1.0f, 0.0f, 0.0f ); + cameraPosition = Vector3( 0.0f, 0.0f, 1.0f ); + targetOrientation = Quaternion::IDENTITY; + lookAtOrientation = Quaternion( Radian( Math::PI * 1.25), Vector3::YAXIS ); + LookAt( current, inputs ); + DALI_TEST_EQUALS( current, lookAtOrientation, Math::MACHINE_EPSILON_10, TEST_LOCATION ); + + // 180 degrees round y * -45 degrees round x, Up Vector: 180 degrees + targetPosition = Vector3::ZERO; + cameraPosition = Vector3( 0.0f, -1.0f, 1.0f ); + targetOrientation = Quaternion( Radian( Math::PI ), Vector3::ZAXIS ); + lookAtOrientation = Quaternion( Radian( Math::PI ), Vector3::YAXIS ) * Quaternion( Radian( Math::PI * 0.25f ), -Vector3::XAXIS ) * Quaternion( Radian( Math::PI ), -Vector3::ZAXIS ); + LookAt( current, inputs ); + DALI_TEST_EQUALS( current, lookAtOrientation, Math::MACHINE_EPSILON_10, TEST_LOCATION ); + + END_TEST; +} +/////////////////////////////////////////////////////////////////////////////// -- 2.7.4