X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=automated-tests%2Fsrc%2Fdali%2Futc-Dali-Animation.cpp;h=3d1a11f1ad399f6a3f6cc4b7d0d65b591e20e450;hb=46589d84c800e9ce26845d77a57df023e3df6922;hp=537abb8e764a5347eff393bcdd1cb7e652275853;hpb=4c0a88c52820b7471e15465ac7caf3c7165a0790;p=platform%2Fcore%2Fuifw%2Fdali-core.git diff --git a/automated-tests/src/dali/utc-Dali-Animation.cpp b/automated-tests/src/dali/utc-Dali-Animation.cpp index 537abb8..3d1a11f 100644 --- a/automated-tests/src/dali/utc-Dali-Animation.cpp +++ b/automated-tests/src/dali/utc-Dali-Animation.cpp @@ -19,7 +19,7 @@ #include #include -#include +#include #include using std::max; @@ -110,6 +110,23 @@ struct AnimateFloatTestFunctor float mEnd; }; +struct AnimateIntegerTestFunctor +{ + AnimateIntegerTestFunctor( int start, int end ) + : mStart( start ), + mEnd( end ) + { + } + + int operator()( float alpha, const int& current ) + { + return static_cast( mStart + ((mEnd - mStart) * alpha ) + 0.5f ); + } + + int mStart; + int mEnd; +}; + struct AnimateVector2TestFunctor { AnimateVector2TestFunctor( Vector2 start, Vector2 end ) @@ -626,6 +643,183 @@ int UtcDaliAnimationPlay(void) END_TEST; } +int UtcDaliAnimationSetSpeedFactor(void) +{ + TestApplication application; + + Actor actor = Actor::New(); + Stage::GetCurrent().Add(actor); + + // Build the animation + float durationSeconds(1.0f); + Animation animation = Animation::New(durationSeconds); + + const Vector3 initialPosition(0.0f, 0.0f, 0.0f); + const Vector3 targetPosition(100.0f, 100.0f, 100.0f); + + KeyFrames keyframes = KeyFrames::New(); + keyframes.Add( 0.0f, initialPosition); + keyframes.Add( 1.0f, targetPosition ); + animation.AnimateBetween( Property(actor, Actor::POSITION), keyframes, AlphaFunctions::Linear); + + //Set speed to be x2 + animation.SetSpeedFactor(2.0f); + + // Start the animation + animation.Play(); + + bool signalReceived(false); + AnimationFinishCheck finishCheck(signalReceived); + animation.FinishedSignal().Connect(&application, finishCheck); + + application.SendNotification(); + application.Render(static_cast(durationSeconds*200.0f)/* 40% progress */); + + // We didn't expect the animation to finish yet + application.SendNotification(); + finishCheck.CheckSignalNotReceived(); + DALI_TEST_EQUALS( actor.GetCurrentPosition(), (targetPosition * 0.4f), TEST_LOCATION ); + + application.Render(static_cast(durationSeconds*200.0f)/* 80% progress */); + + // We didn't expect the animation to finish yet + application.SendNotification(); + finishCheck.CheckSignalNotReceived(); + DALI_TEST_EQUALS( actor.GetCurrentPosition(), (targetPosition * 0.8f), TEST_LOCATION ); + + application.Render(static_cast(durationSeconds*100.0f) + 1u/*just beyond half the duration*/); + + // We did expect the animation to finish + application.SendNotification(); + finishCheck.CheckSignalReceived(); + 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( targetPosition, actor.GetCurrentPosition(), TEST_LOCATION ); + application.Render(0); + DALI_TEST_EQUALS( targetPosition, actor.GetCurrentPosition(), TEST_LOCATION ); + + finishCheck.Reset(); + + //Test -1 speed factor. Animation will play in reverse at normal speed + animation.SetSpeedFactor( -1.0f ); + + // Start the animation + animation.Play(); + + application.SendNotification(); + application.Render(static_cast(durationSeconds*200.0f)/* 80% progress */); + + // We didn't expect the animation to finish yet + application.SendNotification(); + finishCheck.CheckSignalNotReceived(); + DALI_TEST_EQUALS( actor.GetCurrentPosition(), (targetPosition * 0.8f), TEST_LOCATION ); + + application.Render(static_cast(durationSeconds*200.0f)/* 60% progress */); + + // We didn't expect the animation to finish yet + application.SendNotification(); + finishCheck.CheckSignalNotReceived(); + DALI_TEST_EQUALS( actor.GetCurrentPosition(), (targetPosition * 0.6f), TEST_LOCATION ); + + application.Render(static_cast(durationSeconds*200.0f)/* 40% progress */); + + // We didn't expect the animation to finish yet + application.SendNotification(); + finishCheck.CheckSignalNotReceived(); + DALI_TEST_EQUALS( actor.GetCurrentPosition(), (targetPosition * 0.4f), TEST_LOCATION ); + + application.Render(static_cast(durationSeconds*200.0f)/* 20% progress */); + + // We didn't expect the animation to finish yet + application.SendNotification(); + finishCheck.CheckSignalNotReceived(); + DALI_TEST_EQUALS( actor.GetCurrentPosition(), (targetPosition * 0.2f), TEST_LOCATION ); + + application.Render(static_cast(durationSeconds*200.0f) + 1u/*just beyond the animation duration*/); + + // We did expect the animation to finish + application.SendNotification(); + finishCheck.CheckSignalReceived(); + DALI_TEST_EQUALS( actor.GetCurrentPosition(), initialPosition, TEST_LOCATION ); + + // Check that nothing has changed after a couple of buffer swaps + application.Render(0); + DALI_TEST_EQUALS( initialPosition, actor.GetCurrentPosition(), TEST_LOCATION ); + application.Render(0); + DALI_TEST_EQUALS( initialPosition, actor.GetCurrentPosition(), TEST_LOCATION ); + + + //Test change speed factor on the fly + finishCheck.Reset(); + + //Set speed to be half of normal speed + animation.SetSpeedFactor( 0.5f ); + + // Start the animation + animation.Play(); + + application.SendNotification(); + application.Render(static_cast(durationSeconds*200.0f)/* 10% progress */); + + // We didn't expect the animation to finish yet + application.SendNotification(); + finishCheck.CheckSignalNotReceived(); + DALI_TEST_EQUALS( actor.GetCurrentPosition(), (targetPosition * 0.1f), TEST_LOCATION ); + + application.Render(static_cast(durationSeconds*200.0f)/* 20% progress */); + + // We didn't expect the animation to finish yet + application.SendNotification(); + finishCheck.CheckSignalNotReceived(); + DALI_TEST_EQUALS( actor.GetCurrentPosition(), (targetPosition * 0.2f), TEST_LOCATION ); + + application.Render(static_cast(durationSeconds*200.0f)/* 30% progress */); + + // We didn't expect the animation to finish yet + application.SendNotification(); + finishCheck.CheckSignalNotReceived(); + DALI_TEST_EQUALS( actor.GetCurrentPosition(), (targetPosition * 0.3f), TEST_LOCATION ); + + //Change speed factor while animation still playing. + animation.SetSpeedFactor(-1.0f); + application.SendNotification(); + application.Render(static_cast(durationSeconds*200.0f)/* 10% progress */); + + // We didn't expect the animation to finish yet + application.SendNotification(); + finishCheck.CheckSignalNotReceived(); + DALI_TEST_EQUALS( actor.GetCurrentPosition(), (targetPosition * 0.1f), TEST_LOCATION ); + + application.Render(static_cast(durationSeconds*100.0f) + 1u/*just beyond the animation duration*/); + + // We did expect the animation to finish + application.SendNotification(); + finishCheck.CheckSignalReceived(); + DALI_TEST_EQUALS( actor.GetCurrentPosition(), initialPosition, TEST_LOCATION ); + + // Check that nothing has changed after a couple of buffer swaps + application.Render(0); + DALI_TEST_EQUALS( initialPosition, actor.GetCurrentPosition(), TEST_LOCATION ); + application.Render(0); + DALI_TEST_EQUALS( initialPosition, actor.GetCurrentPosition(), TEST_LOCATION ); + END_TEST; +} + +int UtcDaliAnimationGetSpeedFactor(void) +{ + TestApplication application; + + Animation animation = Animation::New(1.0f); + animation.SetSpeedFactor(0.5f); + DALI_TEST_EQUALS(animation.GetSpeedFactor(), 0.5f, TEST_LOCATION); + + animation.SetSpeedFactor(-2.5f); + DALI_TEST_EQUALS(animation.GetSpeedFactor(), -2.5f, TEST_LOCATION); + END_TEST; +} + int UtcDaliAnimationPlayOffStage(void) { // Test that an animation can be played, when the actor is off-stage. @@ -853,7 +1047,7 @@ int UtcDaliAnimationPlayStopDiscardHandle(void) END_TEST; } -int UtcDaliAnimationPause(void) +int UtcDaliAnimationPlayFrom(void) { TestApplication application; @@ -866,50 +1060,40 @@ int UtcDaliAnimationPause(void) Vector3 targetPosition(100.0f, 100.0f, 100.0f); animation.MoveTo(actor, targetPosition, AlphaFunctions::Linear); - Vector3 fiftyPercentProgress(targetPosition * 0.5f); + //PlayFrom with an argument outside the range [0..1] will be ignored + animation.PlayFrom(-1.0f); + application.SendNotification(); + DALI_TEST_EQUALS(0.0f, animation.GetCurrentProgress(), TEST_LOCATION ); - // Start the animation - animation.Play(); + animation.PlayFrom(100.0f); + application.SendNotification(); + DALI_TEST_EQUALS(0.0f, animation.GetCurrentProgress(), TEST_LOCATION ); + + // Start the animation from 40% progress + animation.PlayFrom( 0.4f ); bool signalReceived(false); AnimationFinishCheck finishCheck(signalReceived); animation.FinishedSignal().Connect(&application, finishCheck); application.SendNotification(); - application.Render(static_cast(durationSeconds*500.0f)/* 50% progress */); + application.Render(static_cast(durationSeconds*200.0f)/* 60% progress */); // We didn't expect the animation to finish yet application.SendNotification(); finishCheck.CheckSignalNotReceived(); - DALI_TEST_EQUALS( actor.GetCurrentPosition(), fiftyPercentProgress, TEST_LOCATION ); - - // Pause the animation - animation.Pause(); - application.SendNotification(); - - // Loop 5 times - for (int i=0; i<5; ++i) - { - application.Render(static_cast(durationSeconds*500.0f)); - - // We didn't expect the animation to finish yet - application.SendNotification(); - finishCheck.CheckSignalNotReceived(); - DALI_TEST_EQUALS( actor.GetCurrentPosition(), fiftyPercentProgress/* Still 50% progress when paused */, TEST_LOCATION ); - } + DALI_TEST_EQUALS( actor.GetCurrentPosition(), (targetPosition * 0.6f), TEST_LOCATION ); - // Keep going - animation.Play(); + animation.Play(); // Test that calling play has no effect, when animation is already playing application.SendNotification(); - application.Render(static_cast(durationSeconds*490.0f)/*slightly less than the animation duration*/); + application.Render(static_cast(durationSeconds*200.0f)/* 80% progress */); // We didn't expect the animation to finish yet application.SendNotification(); finishCheck.CheckSignalNotReceived(); + DALI_TEST_EQUALS( actor.GetCurrentPosition(), (targetPosition * 0.8f), TEST_LOCATION ); - application.SendNotification(); - application.Render(static_cast(durationSeconds*10.0f) + 1u/*just beyond the animation duration*/); - + application.Render(static_cast(durationSeconds*200.0f) + 1u/*just beyond the animation duration*/); // We did expect the animation to finish application.SendNotification(); finishCheck.CheckSignalReceived(); @@ -923,7 +1107,7 @@ int UtcDaliAnimationPause(void) END_TEST; } -int UtcDaliAnimationStop(void) +int UtcDaliAnimationSetCurrentProgress(void) { TestApplication application; @@ -931,50 +1115,87 @@ int UtcDaliAnimationStop(void) Stage::GetCurrent().Add(actor); // Build the animation - float durationSeconds(1.0f); - Animation animation = Animation::New(durationSeconds); - Vector3 targetPosition(100.0f, 100.0f, 100.0f); - animation.MoveTo(actor, targetPosition, AlphaFunctions::Linear); + Animation animation = Animation::New(0.0f); + animation.Play(); - Vector3 fiftyPercentProgress(targetPosition * 0.5f); + //Test GetCurrentProgress return 0.0 as the duration is 0.0 + DALI_TEST_EQUALS( 0.0f, animation.GetCurrentProgress(), TEST_LOCATION ); - // Start the animation - animation.Play(); + animation.SetCurrentProgress( 0.5f ); + application.SendNotification(); + application.Render(static_cast(100.0f)); + + //Progress should still be 0.0 + DALI_TEST_EQUALS( 0.0f, animation.GetCurrentProgress(), TEST_LOCATION ); + + //Set duration + float durationSeconds(1.0f); + animation.SetDuration(durationSeconds); + application.SendNotification(); bool signalReceived(false); AnimationFinishCheck finishCheck(signalReceived); animation.FinishedSignal().Connect(&application, finishCheck); + application.SendNotification(); + Vector3 targetPosition(100.0f, 100.0f, 100.0f); + animation.MoveTo(actor, targetPosition, AlphaFunctions::Linear); + + //Trying to set the current cursor outside the range [0..1] is ignored + animation.SetCurrentProgress( -1.0f); application.SendNotification(); - application.Render(static_cast(durationSeconds*500.0f)/* 50% progress */); + DALI_TEST_EQUALS( 0.0f, animation.GetCurrentProgress(), TEST_LOCATION ); + + animation.SetCurrentProgress( 100.0f); + application.SendNotification(); + DALI_TEST_EQUALS( 0.0f, animation.GetCurrentProgress(), TEST_LOCATION ); + + // Start the animation from 40% progress + animation.SetCurrentProgress( 0.4f ); + animation.Play(); + + application.SendNotification(); + application.Render(static_cast(durationSeconds*200.0f)/* 60% progress */); // We didn't expect the animation to finish yet application.SendNotification(); finishCheck.CheckSignalNotReceived(); - DALI_TEST_EQUALS( actor.GetCurrentPosition(), fiftyPercentProgress, TEST_LOCATION ); + DALI_TEST_EQUALS( actor.GetCurrentPosition(), (targetPosition * 0.6f), TEST_LOCATION ); + DALI_TEST_EQUALS( 0.6f, animation.GetCurrentProgress(), TEST_LOCATION ); - // Stop the animation - animation.Stop(); + animation.Play(); // Test that calling play has no effect, when animation is already playing application.SendNotification(); - // Loop 5 times - for (int i=0; i<5; ++i) - { - application.Render(static_cast(durationSeconds*500.0f)); + //Set the progress to 70% + animation.SetCurrentProgress( 0.7f ); + application.SendNotification(); + application.Render(static_cast(durationSeconds*100.0f)/* 80% progress */); + DALI_TEST_EQUALS( 0.8f, animation.GetCurrentProgress(), TEST_LOCATION ); - // We did expect the animation to finish - application.SendNotification(); - finishCheck.CheckSignalReceived(); - DALI_TEST_EQUALS( actor.GetCurrentPosition(), fiftyPercentProgress/* Still 50% progress when stopped */, TEST_LOCATION ); - } + + application.SendNotification(); + finishCheck.CheckSignalNotReceived(); + DALI_TEST_EQUALS( actor.GetCurrentPosition(), (targetPosition * 0.8f), TEST_LOCATION ); + DALI_TEST_EQUALS( 0.8f, animation.GetCurrentProgress(), TEST_LOCATION ); + + // + + application.Render(static_cast(durationSeconds*200.0f) + 1u/*just beyond the animation duration*/); + // We did expect the animation to finish + application.SendNotification(); + finishCheck.CheckSignalReceived(); + 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( targetPosition, actor.GetCurrentPosition(), TEST_LOCATION ); + application.Render(0); + DALI_TEST_EQUALS( targetPosition, actor.GetCurrentPosition(), TEST_LOCATION ); END_TEST; } -int UtcDaliAnimationStopSetPosition(void) +int UtcDaliAnimationPlayRange(void) { - // Test that Animation::Stop & Actor::SetPosition can be used in conjunction - // i.e. to check that the animation does not interfere with the position set. - TestApplication application; Actor actor = Actor::New(); @@ -984,7 +1205,266 @@ int UtcDaliAnimationStopSetPosition(void) float durationSeconds(1.0f); Animation animation = Animation::New(durationSeconds); Vector3 targetPosition(100.0f, 100.0f, 100.0f); - animation.MoveTo(actor, targetPosition, AlphaFunctions::Linear); + KeyFrames keyframes = KeyFrames::New(); + keyframes.Add( 0.0f , Vector3(0.0f,0.0f,0.0f ) ); + keyframes.Add( 1.0f , Vector3(100.0f,100.0f,100.0f ) ); + + animation.AnimateBetween( Property( actor, Actor::POSITION), keyframes ); + + // Set range between 0.4 and 0.8 + animation.SetPlayRange( Vector2(0.4f,0.8f) ); + animation.Play(); + + bool signalReceived(false); + AnimationFinishCheck finishCheck(signalReceived); + animation.FinishedSignal().Connect(&application, finishCheck); + + //Test that setting progress outside the range doesn't work + animation.SetCurrentProgress( 0.9f ); + application.SendNotification(); + application.Render(0); + DALI_TEST_EQUALS( animation.GetCurrentProgress(), 0.4f, TEST_LOCATION ); + animation.SetCurrentProgress( 0.2f ); + application.SendNotification(); + application.Render(0); + DALI_TEST_EQUALS( animation.GetCurrentProgress(), 0.4f, TEST_LOCATION ); + + application.SendNotification(); + application.Render(static_cast(durationSeconds*200.0f)/* 60% progress */); + + // We didn't expect the animation to finish yet + application.SendNotification(); + finishCheck.CheckSignalNotReceived(); + DALI_TEST_EQUALS( actor.GetCurrentPosition(), (targetPosition * 0.6f), TEST_LOCATION ); + + animation.Play(); // Test that calling play has no effect, when animation is already playing + application.SendNotification(); + application.Render(static_cast(durationSeconds*200.0f) + 1u/* 80% progress */); + + // We did expect the animation to finish + application.SendNotification(); + finishCheck.CheckSignalReceived(); + DALI_TEST_EQUALS( actor.GetCurrentPosition(), (targetPosition * 0.8f), TEST_LOCATION ); + + // Check that nothing has changed after a couple of buffer swaps + application.Render(0); + DALI_TEST_EQUALS( targetPosition * 0.8f, actor.GetCurrentPosition(), TEST_LOCATION ); + application.Render(0); + DALI_TEST_EQUALS( targetPosition * 0.8f, actor.GetCurrentPosition(), TEST_LOCATION ); + + + //Loop inside the range + finishCheck.Reset(); + animation.SetLooping( true ); + animation.Play(); + application.SendNotification(); + float intervalSeconds = 0.1f; + float progress = 0.4f; + for (int iterations = 0; iterations < 10; ++iterations ) + { + application.Render(static_cast(durationSeconds*intervalSeconds*1000.0f)); + + progress += intervalSeconds; + if (progress > 0.8f) + { + progress = progress - 0.4f; + } + + DALI_TEST_EQUALS( targetPosition*progress, actor.GetCurrentPosition(), 0.001f, TEST_LOCATION ); + } + + // We didn't expect the animation to finish yet + application.SendNotification(); + finishCheck.CheckSignalNotReceived(); + + + //Test change range on the fly + animation.SetPlayRange( Vector2( 0.2f, 0.9f ) ); + application.SendNotification(); + + for (int iterations = 0; iterations < 10; ++iterations ) + { + application.Render(static_cast(durationSeconds*intervalSeconds*1000.0f)); + + progress += intervalSeconds; + if (progress > 0.9f) + { + progress = progress - 0.7f; + } + + DALI_TEST_EQUALS( targetPosition*progress, actor.GetCurrentPosition(), 0.001f, TEST_LOCATION ); + } + + END_TEST; +} + +int UtcDaliAnimationSetPlayRange(void) +{ + TestApplication application; + + Actor actor = Actor::New(); + Stage::GetCurrent().Add(actor); + + // Build the animation + Animation animation = Animation::New(0); + application.SendNotification(); + + //If PlayRange not specified it should be 0.0-1.0 by default + DALI_TEST_EQUALS( Vector2(0.0,1.0), animation.GetPlayRange(), TEST_LOCATION ); + + //PlayRange out of bounds + animation.SetPlayRange( Vector2(-1.0f,1.0f) ); + application.SendNotification(); + DALI_TEST_EQUALS( Vector2(0.0f,1.0f), animation.GetPlayRange(), TEST_LOCATION ); + animation.SetPlayRange( Vector2(0.0f,2.0f) ); + application.SendNotification(); + DALI_TEST_EQUALS( Vector2(0.0f,1.0f), animation.GetPlayRange(), TEST_LOCATION ); + + //If playRange is not in the correct order it has to be ordered + animation.SetPlayRange( Vector2(0.8f,0.2f) ); + application.SendNotification(); + DALI_TEST_EQUALS( Vector2(0.2f,0.8f), animation.GetPlayRange(), TEST_LOCATION ); + + // Set range between 0.4 and 0.8 + animation.SetPlayRange( Vector2(0.4f,0.8f) ); + application.SendNotification(); + DALI_TEST_EQUALS( Vector2(0.4f,0.8f), animation.GetPlayRange(), TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliAnimationPause(void) +{ + TestApplication application; + + Actor actor = Actor::New(); + Stage::GetCurrent().Add(actor); + + // Build the animation + float durationSeconds(1.0f); + Animation animation = Animation::New(durationSeconds); + Vector3 targetPosition(100.0f, 100.0f, 100.0f); + animation.MoveTo(actor, targetPosition, AlphaFunctions::Linear); + + Vector3 fiftyPercentProgress(targetPosition * 0.5f); + + // Start the animation + animation.Play(); + + bool signalReceived(false); + AnimationFinishCheck finishCheck(signalReceived); + animation.FinishedSignal().Connect(&application, finishCheck); + + application.SendNotification(); + application.Render(static_cast(durationSeconds*500.0f)/* 50% progress */); + + // We didn't expect the animation to finish yet + application.SendNotification(); + finishCheck.CheckSignalNotReceived(); + DALI_TEST_EQUALS( actor.GetCurrentPosition(), fiftyPercentProgress, TEST_LOCATION ); + + // Pause the animation + animation.Pause(); + application.SendNotification(); + + // Loop 5 times + for (int i=0; i<5; ++i) + { + application.Render(static_cast(durationSeconds*500.0f)); + + // We didn't expect the animation to finish yet + application.SendNotification(); + finishCheck.CheckSignalNotReceived(); + DALI_TEST_EQUALS( actor.GetCurrentPosition(), fiftyPercentProgress/* Still 50% progress when paused */, TEST_LOCATION ); + } + + // Keep going + animation.Play(); + application.SendNotification(); + application.Render(static_cast(durationSeconds*490.0f)/*slightly less than the animation duration*/); + + // We didn't expect the animation to finish yet + application.SendNotification(); + finishCheck.CheckSignalNotReceived(); + + application.SendNotification(); + application.Render(static_cast(durationSeconds*10.0f) + 1u/*just beyond the animation duration*/); + + // We did expect the animation to finish + application.SendNotification(); + finishCheck.CheckSignalReceived(); + 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( targetPosition, actor.GetCurrentPosition(), TEST_LOCATION ); + application.Render(0); + DALI_TEST_EQUALS( targetPosition, actor.GetCurrentPosition(), TEST_LOCATION ); + END_TEST; +} + +int UtcDaliAnimationStop(void) +{ + TestApplication application; + + Actor actor = Actor::New(); + Stage::GetCurrent().Add(actor); + + // Build the animation + float durationSeconds(1.0f); + Animation animation = Animation::New(durationSeconds); + Vector3 targetPosition(100.0f, 100.0f, 100.0f); + animation.MoveTo(actor, targetPosition, AlphaFunctions::Linear); + + Vector3 fiftyPercentProgress(targetPosition * 0.5f); + + // Start the animation + animation.Play(); + + bool signalReceived(false); + AnimationFinishCheck finishCheck(signalReceived); + animation.FinishedSignal().Connect(&application, finishCheck); + + application.SendNotification(); + application.Render(static_cast(durationSeconds*500.0f)/* 50% progress */); + + // We didn't expect the animation to finish yet + application.SendNotification(); + finishCheck.CheckSignalNotReceived(); + DALI_TEST_EQUALS( actor.GetCurrentPosition(), fiftyPercentProgress, TEST_LOCATION ); + + // Stop the animation + animation.Stop(); + application.SendNotification(); + + // Loop 5 times + for (int i=0; i<5; ++i) + { + application.Render(static_cast(durationSeconds*500.0f)); + + // We did expect the animation to finish + application.SendNotification(); + finishCheck.CheckSignalReceived(); + DALI_TEST_EQUALS( actor.GetCurrentPosition(), fiftyPercentProgress/* Still 50% progress when stopped */, TEST_LOCATION ); + } + END_TEST; +} + +int UtcDaliAnimationStopSetPosition(void) +{ + // Test that Animation::Stop & Actor::SetPosition can be used in conjunction + // i.e. to check that the animation does not interfere with the position set. + + TestApplication application; + + Actor actor = Actor::New(); + Stage::GetCurrent().Add(actor); + + // Build the animation + float durationSeconds(1.0f); + Animation animation = Animation::New(durationSeconds); + Vector3 targetPosition(100.0f, 100.0f, 100.0f); + animation.MoveTo(actor, targetPosition, AlphaFunctions::Linear); Vector3 fiftyPercentProgress(targetPosition * 0.5f); @@ -1450,26 +1930,256 @@ int UtcDaliAnimationAnimateByFloat(void) END_TEST; } -int UtcDaliAnimationAnimateByFloatAlphaFunction(void) +int UtcDaliAnimationAnimateByFloatAlphaFunction(void) +{ + TestApplication application; + + Actor actor = Actor::New(); + + // Register a float property + float startValue(10.0f); + Property::Index index = actor.RegisterProperty( "test-property", startValue ); + Stage::GetCurrent().Add(actor); + DALI_TEST_EQUALS( actor.GetProperty(index), startValue, TEST_LOCATION ); + + // Build the animation + float durationSeconds(1.0f); + Animation animation = Animation::New(durationSeconds); + float targetValue(90.0f); + float relativeValue(targetValue - startValue); + animation.AnimateBy(Property(actor, index), relativeValue, AlphaFunctions::EaseOut); + + float ninetyFivePercentProgress(startValue + relativeValue*0.95f); + + // Start the animation + animation.Play(); + + bool signalReceived(false); + AnimationFinishCheck finishCheck(signalReceived); + animation.FinishedSignal().Connect(&application, finishCheck); + + application.SendNotification(); + application.Render(static_cast(durationSeconds*950.0f)/* 95% progress */); + + // We didn't expect the animation to finish yet + application.SendNotification(); + finishCheck.CheckSignalNotReceived(); + + // The position should have moved more, than with a linear alpha function + float current(actor.GetProperty(index)); + DALI_TEST_CHECK( current > ninetyFivePercentProgress ); + + application.SendNotification(); + application.Render(static_cast(durationSeconds*50.0f) + 1u/*just beyond the animation duration*/); + + // We did expect the animation to finish + application.SendNotification(); + finishCheck.CheckSignalReceived(); + DALI_TEST_EQUALS( actor.GetProperty(index), targetValue, TEST_LOCATION ); + + // Check that nothing has changed after a couple of buffer swaps + application.Render(0); + DALI_TEST_EQUALS( actor.GetProperty(index), targetValue, TEST_LOCATION ); + application.Render(0); + DALI_TEST_EQUALS( actor.GetProperty(index), targetValue, TEST_LOCATION ); + END_TEST; +} + +int UtcDaliAnimationAnimateByFloatTimePeriod(void) +{ + TestApplication application; + + Actor actor = Actor::New(); + + // Register a float property + float startValue(10.0f); + Property::Index index = actor.RegisterProperty( "test-property", startValue ); + Stage::GetCurrent().Add(actor); + DALI_TEST_EQUALS( actor.GetProperty(index), startValue, TEST_LOCATION ); + + // Build the animation + float durationSeconds(1.0f); + Animation animation = Animation::New(durationSeconds); + float targetValue(30.0f); + float relativeValue(targetValue - startValue); + float delay = 0.5f; + animation.AnimateBy(Property(actor, index), + relativeValue, + TimePeriod(delay, durationSeconds - delay)); + + // Start the animation + animation.Play(); + + bool signalReceived(false); + AnimationFinishCheck finishCheck(signalReceived); + animation.FinishedSignal().Connect(&application, finishCheck); + + application.SendNotification(); + application.Render(static_cast(durationSeconds*500.0f)/* 50% animation progress, 0% animator progress */); + + // We didn't expect the animation to finish yet + application.SendNotification(); + finishCheck.CheckSignalNotReceived(); + DALI_TEST_EQUALS( actor.GetProperty(index), startValue, TEST_LOCATION ); + + application.SendNotification(); + application.Render(static_cast(durationSeconds*250.0f)/* 75% animation progress, 50% animator progress */); + + // We didn't expect the animation to finish yet + application.SendNotification(); + finishCheck.CheckSignalNotReceived(); + DALI_TEST_EQUALS( actor.GetProperty(index), startValue+(relativeValue*0.5f), TEST_LOCATION ); + + application.SendNotification(); + application.Render(static_cast(durationSeconds*250.0f) + 1u/*just beyond the animation duration*/); + + // We did expect the animation to finish + application.SendNotification(); + finishCheck.CheckSignalReceived(); + DALI_TEST_EQUALS( actor.GetProperty(index), targetValue, TEST_LOCATION ); + + // Check that nothing has changed after a couple of buffer swaps + application.Render(0); + DALI_TEST_EQUALS( actor.GetProperty(index), targetValue, TEST_LOCATION ); + application.Render(0); + DALI_TEST_EQUALS( actor.GetProperty(index), targetValue, TEST_LOCATION ); + END_TEST; +} + +int UtcDaliAnimationAnimateByFloatAlphaFunctionTimePeriod(void) +{ + TestApplication application; + + Actor actor = Actor::New(); + + // Register a float property + float startValue(10.0f); + Property::Index index = actor.RegisterProperty( "test-property", startValue ); + Stage::GetCurrent().Add(actor); + DALI_TEST_EQUALS( actor.GetProperty(index), startValue, TEST_LOCATION ); + + // Build the animation + float durationSeconds(1.0f); + Animation animation = Animation::New(durationSeconds); + float targetValue(30.0f); + float relativeValue(targetValue - startValue); + float delay = 0.5f; + animation.AnimateBy(Property(actor, index), + relativeValue, + AlphaFunctions::Linear, + TimePeriod(delay, durationSeconds - delay)); + + // Start the animation + animation.Play(); + + bool signalReceived(false); + AnimationFinishCheck finishCheck(signalReceived); + animation.FinishedSignal().Connect(&application, finishCheck); + + application.SendNotification(); + application.Render(static_cast(durationSeconds*500.0f)/* 50% animation progress, 0% animator progress */); + + // We didn't expect the animation to finish yet + application.SendNotification(); + finishCheck.CheckSignalNotReceived(); + DALI_TEST_EQUALS( actor.GetProperty(index), startValue, TEST_LOCATION ); + + application.SendNotification(); + application.Render(static_cast(durationSeconds*250.0f)/* 75% animation progress, 50% animator progress */); + + // We didn't expect the animation to finish yet + application.SendNotification(); + finishCheck.CheckSignalNotReceived(); + DALI_TEST_EQUALS( actor.GetProperty(index), startValue+(relativeValue*0.5f), TEST_LOCATION ); + + application.SendNotification(); + application.Render(static_cast(durationSeconds*250.0f) + 1u/*just beyond the animation duration*/); + + // We did expect the animation to finish + application.SendNotification(); + finishCheck.CheckSignalReceived(); + DALI_TEST_EQUALS( actor.GetProperty(index), targetValue, TEST_LOCATION ); + + // Check that nothing has changed after a couple of buffer swaps + application.Render(0); + DALI_TEST_EQUALS( actor.GetProperty(index), targetValue, TEST_LOCATION ); + application.Render(0); + DALI_TEST_EQUALS( actor.GetProperty(index), targetValue, TEST_LOCATION ); + END_TEST; +} + +int UtcDaliAnimationAnimateByInteger(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_EQUALS( actor.GetProperty(index), startValue, TEST_LOCATION ); + + // Build the animation + float durationSeconds(2.0f); + Animation animation = Animation::New(durationSeconds); + int targetValue(50); + int relativeValue(targetValue - startValue); + animation.AnimateBy(Property(actor, index), relativeValue); + + int ninetyFivePercentProgress(static_cast(startValue + relativeValue*0.95f + 0.5f)); + + // Start the animation + animation.Play(); + + bool signalReceived(false); + AnimationFinishCheck finishCheck(signalReceived); + animation.FinishedSignal().Connect(&application, finishCheck); + + application.SendNotification(); + application.Render(static_cast(durationSeconds*950.0f)/* 95% progress */); + + // We didn't expect the animation to finish yet + application.SendNotification(); + finishCheck.CheckSignalNotReceived(); + DALI_TEST_EQUALS( actor.GetProperty(index), ninetyFivePercentProgress, TEST_LOCATION ); + + application.SendNotification(); + application.Render(static_cast(durationSeconds*50.0f) + 1u/*just beyond the animation duration*/); + + // We did expect the animation to finish + application.SendNotification(); + finishCheck.CheckSignalReceived(); + DALI_TEST_EQUALS( actor.GetProperty(index), targetValue, TEST_LOCATION ); + + // Check that nothing has changed after a couple of buffer swaps + application.Render(0); + DALI_TEST_EQUALS( actor.GetProperty(index), targetValue, TEST_LOCATION ); + application.Render(0); + DALI_TEST_EQUALS( actor.GetProperty(index), targetValue, TEST_LOCATION ); + END_TEST; +} + +int UtcDaliAnimationAnimateByIntegerAlphaFunction(void) { TestApplication application; Actor actor = Actor::New(); - // Register a float property - float startValue(10.0f); + // Register an integer property + int startValue(1); Property::Index index = actor.RegisterProperty( "test-property", startValue ); Stage::GetCurrent().Add(actor); - DALI_TEST_EQUALS( actor.GetProperty(index), startValue, TEST_LOCATION ); + DALI_TEST_EQUALS( actor.GetProperty(index), startValue, TEST_LOCATION ); // Build the animation float durationSeconds(1.0f); Animation animation = Animation::New(durationSeconds); - float targetValue(90.0f); - float relativeValue(targetValue - startValue); + int targetValue(90); + int relativeValue(targetValue - startValue); animation.AnimateBy(Property(actor, index), relativeValue, AlphaFunctions::EaseOut); - float ninetyFivePercentProgress(startValue + relativeValue*0.95f); + int ninetyFivePercentProgress(static_cast(startValue + relativeValue*0.95f + 0.5f)); // Start the animation animation.Play(); @@ -1486,7 +2196,7 @@ int UtcDaliAnimationAnimateByFloatAlphaFunction(void) finishCheck.CheckSignalNotReceived(); // The position should have moved more, than with a linear alpha function - float current(actor.GetProperty(index)); + int current(actor.GetProperty(index)); DALI_TEST_CHECK( current > ninetyFivePercentProgress ); application.SendNotification(); @@ -1495,33 +2205,33 @@ int UtcDaliAnimationAnimateByFloatAlphaFunction(void) // We did expect the animation to finish application.SendNotification(); finishCheck.CheckSignalReceived(); - DALI_TEST_EQUALS( actor.GetProperty(index), targetValue, TEST_LOCATION ); + DALI_TEST_EQUALS( actor.GetProperty(index), targetValue, TEST_LOCATION ); // Check that nothing has changed after a couple of buffer swaps application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), targetValue, TEST_LOCATION ); + DALI_TEST_EQUALS( actor.GetProperty(index), targetValue, TEST_LOCATION ); application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), targetValue, TEST_LOCATION ); + DALI_TEST_EQUALS( actor.GetProperty(index), targetValue, TEST_LOCATION ); END_TEST; } -int UtcDaliAnimationAnimateByFloatTimePeriod(void) +int UtcDaliAnimationAnimateByIntegerTimePeriod(void) { TestApplication application; Actor actor = Actor::New(); - // Register a float property - float startValue(10.0f); + // Register an integer property + int startValue(10); Property::Index index = actor.RegisterProperty( "test-property", startValue ); Stage::GetCurrent().Add(actor); - DALI_TEST_EQUALS( actor.GetProperty(index), startValue, TEST_LOCATION ); + DALI_TEST_EQUALS( actor.GetProperty(index), startValue, TEST_LOCATION ); // Build the animation float durationSeconds(1.0f); Animation animation = Animation::New(durationSeconds); - float targetValue(30.0f); - float relativeValue(targetValue - startValue); + int targetValue(30); + int relativeValue(targetValue - startValue); float delay = 0.5f; animation.AnimateBy(Property(actor, index), relativeValue, @@ -1540,7 +2250,7 @@ int UtcDaliAnimationAnimateByFloatTimePeriod(void) // We didn't expect the animation to finish yet application.SendNotification(); finishCheck.CheckSignalNotReceived(); - DALI_TEST_EQUALS( actor.GetProperty(index), startValue, TEST_LOCATION ); + DALI_TEST_EQUALS( actor.GetProperty(index), startValue, TEST_LOCATION ); application.SendNotification(); application.Render(static_cast(durationSeconds*250.0f)/* 75% animation progress, 50% animator progress */); @@ -1548,7 +2258,7 @@ int UtcDaliAnimationAnimateByFloatTimePeriod(void) // We didn't expect the animation to finish yet application.SendNotification(); finishCheck.CheckSignalNotReceived(); - DALI_TEST_EQUALS( actor.GetProperty(index), startValue+(relativeValue*0.5f), TEST_LOCATION ); + DALI_TEST_EQUALS( actor.GetProperty(index), static_cast(startValue+(relativeValue*0.5f)+0.5f), TEST_LOCATION ); application.SendNotification(); application.Render(static_cast(durationSeconds*250.0f) + 1u/*just beyond the animation duration*/); @@ -1556,33 +2266,33 @@ int UtcDaliAnimationAnimateByFloatTimePeriod(void) // We did expect the animation to finish application.SendNotification(); finishCheck.CheckSignalReceived(); - DALI_TEST_EQUALS( actor.GetProperty(index), targetValue, TEST_LOCATION ); + DALI_TEST_EQUALS( actor.GetProperty(index), targetValue, TEST_LOCATION ); // Check that nothing has changed after a couple of buffer swaps application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), targetValue, TEST_LOCATION ); + DALI_TEST_EQUALS( actor.GetProperty(index), targetValue, TEST_LOCATION ); application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), targetValue, TEST_LOCATION ); + DALI_TEST_EQUALS( actor.GetProperty(index), targetValue, TEST_LOCATION ); END_TEST; } -int UtcDaliAnimationAnimateByFloatAlphaFunctionTimePeriod(void) +int UtcDaliAnimationAnimateByIntegerAlphaFunctionTimePeriod(void) { TestApplication application; Actor actor = Actor::New(); - // Register a float property - float startValue(10.0f); + // Register an integer property + int startValue(10); Property::Index index = actor.RegisterProperty( "test-property", startValue ); Stage::GetCurrent().Add(actor); - DALI_TEST_EQUALS( actor.GetProperty(index), startValue, TEST_LOCATION ); + DALI_TEST_EQUALS( actor.GetProperty(index), startValue, TEST_LOCATION ); // Build the animation float durationSeconds(1.0f); Animation animation = Animation::New(durationSeconds); - float targetValue(30.0f); - float relativeValue(targetValue - startValue); + int targetValue(30); + int relativeValue(targetValue - startValue); float delay = 0.5f; animation.AnimateBy(Property(actor, index), relativeValue, @@ -1602,7 +2312,7 @@ int UtcDaliAnimationAnimateByFloatAlphaFunctionTimePeriod(void) // We didn't expect the animation to finish yet application.SendNotification(); finishCheck.CheckSignalNotReceived(); - DALI_TEST_EQUALS( actor.GetProperty(index), startValue, TEST_LOCATION ); + DALI_TEST_EQUALS( actor.GetProperty(index), startValue, TEST_LOCATION ); application.SendNotification(); application.Render(static_cast(durationSeconds*250.0f)/* 75% animation progress, 50% animator progress */); @@ -1610,7 +2320,7 @@ int UtcDaliAnimationAnimateByFloatAlphaFunctionTimePeriod(void) // We didn't expect the animation to finish yet application.SendNotification(); finishCheck.CheckSignalNotReceived(); - DALI_TEST_EQUALS( actor.GetProperty(index), startValue+(relativeValue*0.5f), TEST_LOCATION ); + DALI_TEST_EQUALS( actor.GetProperty(index), static_cast(startValue+(relativeValue*0.5f)+0.5f), TEST_LOCATION ); application.SendNotification(); application.Render(static_cast(durationSeconds*250.0f) + 1u/*just beyond the animation duration*/); @@ -1618,13 +2328,13 @@ int UtcDaliAnimationAnimateByFloatAlphaFunctionTimePeriod(void) // We did expect the animation to finish application.SendNotification(); finishCheck.CheckSignalReceived(); - DALI_TEST_EQUALS( actor.GetProperty(index), targetValue, TEST_LOCATION ); + DALI_TEST_EQUALS( actor.GetProperty(index), targetValue, TEST_LOCATION ); // Check that nothing has changed after a couple of buffer swaps application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), targetValue, TEST_LOCATION ); + DALI_TEST_EQUALS( actor.GetProperty(index), targetValue, TEST_LOCATION ); application.Render(0); - DALI_TEST_EQUALS( actor.GetProperty(index), targetValue, TEST_LOCATION ); + DALI_TEST_EQUALS( actor.GetProperty(index), targetValue, TEST_LOCATION ); END_TEST; } @@ -2698,36 +3408,257 @@ int UtcDaliAnimationAnimateToBooleanAlphaFunction(void) // We did expect the animation to finish application.SendNotification(); finishCheck.CheckSignalReceived(); - DALI_TEST_CHECK( actor.GetProperty(index) == finalValue ); - - // Check that nothing has changed after a couple of buffer swaps - application.Render(0); - DALI_TEST_CHECK( actor.GetProperty(index) == finalValue ); - application.Render(0); - DALI_TEST_CHECK( actor.GetProperty(index) == finalValue ); + DALI_TEST_CHECK( actor.GetProperty(index) == finalValue ); + + // Check that nothing has changed after a couple of buffer swaps + application.Render(0); + DALI_TEST_CHECK( actor.GetProperty(index) == finalValue ); + application.Render(0); + DALI_TEST_CHECK( actor.GetProperty(index) == finalValue ); + END_TEST; +} + +int UtcDaliAnimationAnimateToBooleanTimePeriod(void) +{ + TestApplication application; + + Actor actor = Actor::New(); + + // 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 ); + + // Build the animation + float durationSeconds(2.0f); + Animation animation = Animation::New(durationSeconds); + bool finalValue( !startValue ); + float animatorDurationSeconds(durationSeconds * 0.5f); + animation.AnimateTo( Property(actor, index), + finalValue, + TimePeriod( animatorDurationSeconds ) ); + + // Start the animation + animation.Play(); + + bool signalReceived(false); + AnimationFinishCheck finishCheck(signalReceived); + animation.FinishedSignal().Connect(&application, finishCheck); + + application.SendNotification(); + application.Render(static_cast(animatorDurationSeconds*950.0f)/* 95% animator progress */); + + // We didn't expect the animation to finish yet + application.SendNotification(); + finishCheck.CheckSignalNotReceived(); + DALI_TEST_CHECK( actor.GetProperty(index) == startValue ); + + application.SendNotification(); + application.Render(static_cast(animatorDurationSeconds*50.0f) + 1u/*just beyond the animator duration*/); + + // We didn't expect the animation to finish yet... + application.SendNotification(); + finishCheck.CheckSignalNotReceived(); + + // ...however we should have reached the final value + DALI_TEST_CHECK( actor.GetProperty(index) == finalValue ); + + application.SendNotification(); + application.Render(static_cast(animatorDurationSeconds*1000.0f)/*just beyond the animation duration*/); + + // We did expect the animation to finish + application.SendNotification(); + finishCheck.CheckSignalReceived(); + DALI_TEST_CHECK( actor.GetProperty(index) == finalValue ); + + // Check that nothing has changed after a couple of buffer swaps + application.Render(0); + DALI_TEST_CHECK( actor.GetProperty(index) == finalValue ); + application.Render(0); + DALI_TEST_CHECK( actor.GetProperty(index) == finalValue ); + END_TEST; +} + +int UtcDaliAnimationAnimateToBooleanAlphaFunctionTimePeriod(void) +{ + TestApplication application; + + Actor actor = Actor::New(); + + // 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 ); + + // Build the animation + float durationSeconds(2.0f); + Animation animation = Animation::New(durationSeconds); + bool finalValue( !startValue ); + float animatorDurationSeconds(durationSeconds * 0.5f); + animation.AnimateTo( Property(actor, index), + finalValue, + AlphaFunctions::Linear, + TimePeriod( animatorDurationSeconds ) ); + + // Start the animation + animation.Play(); + + bool signalReceived(false); + AnimationFinishCheck finishCheck(signalReceived); + animation.FinishedSignal().Connect(&application, finishCheck); + + application.SendNotification(); + application.Render(static_cast(animatorDurationSeconds*950.0f)/* 95% animator progress */); + + // We didn't expect the animation to finish yet + application.SendNotification(); + finishCheck.CheckSignalNotReceived(); + DALI_TEST_CHECK( actor.GetProperty(index) == startValue ); + + application.SendNotification(); + application.Render(static_cast(animatorDurationSeconds*50.0f) + 1u/*just beyond the animator duration*/); + + // We didn't expect the animation to finish yet... + application.SendNotification(); + finishCheck.CheckSignalNotReceived(); + + // ...however we should have reached the final value + DALI_TEST_CHECK( actor.GetProperty(index) == finalValue ); + + application.SendNotification(); + application.Render(static_cast(animatorDurationSeconds*1000.0f)/*just beyond the animation duration*/); + + // We did expect the animation to finish + application.SendNotification(); + finishCheck.CheckSignalReceived(); + DALI_TEST_CHECK( actor.GetProperty(index) == finalValue ); + + // Check that nothing has changed after a couple of buffer swaps + application.Render(0); + DALI_TEST_CHECK( actor.GetProperty(index) == finalValue ); + application.Render(0); + DALI_TEST_CHECK( actor.GetProperty(index) == finalValue ); + END_TEST; +} + +int UtcDaliAnimationAnimateToFloat(void) +{ + TestApplication application; + + Actor actor = Actor::New(); + + // Register a float property + float startValue(10.0f); + Property::Index index = actor.RegisterProperty( "test-property", startValue ); + Stage::GetCurrent().Add(actor); + DALI_TEST_EQUALS( actor.GetProperty(index), startValue, TEST_LOCATION ); + + // Build the animation + float durationSeconds(2.0f); + Animation animation = Animation::New(durationSeconds); + float targetValue(50.0f); + float relativeValue(targetValue - startValue); + animation.AnimateTo(Property(actor, "test-property"), targetValue); + + float ninetyFivePercentProgress(startValue + relativeValue*0.95f); + + // Start the animation + animation.Play(); + + bool signalReceived(false); + AnimationFinishCheck finishCheck(signalReceived); + animation.FinishedSignal().Connect(&application, finishCheck); + + application.SendNotification(); + application.Render(static_cast(durationSeconds*950.0f)/* 95% progress */); + + // We didn't expect the animation to finish yet + application.SendNotification(); + finishCheck.CheckSignalNotReceived(); + DALI_TEST_EQUALS( actor.GetProperty(index), ninetyFivePercentProgress, TEST_LOCATION ); + + application.SendNotification(); + application.Render(static_cast(durationSeconds*50.0f) + 1u/*just beyond the animation duration*/); + + // We did expect the animation to finish + application.SendNotification(); + finishCheck.CheckSignalReceived(); + DALI_TEST_EQUALS( actor.GetProperty(index), targetValue, TEST_LOCATION ); + END_TEST; +} + +int UtcDaliAnimationAnimateToFloatAlphaFunction(void) +{ + TestApplication application; + + Actor actor = Actor::New(); + + // Register a float property + float startValue(10.0f); + Property::Index index = actor.RegisterProperty( "test-property", startValue ); + Stage::GetCurrent().Add(actor); + DALI_TEST_EQUALS( actor.GetProperty(index), startValue, TEST_LOCATION ); + + // Build the animation + float durationSeconds(1.0f); + Animation animation = Animation::New(durationSeconds); + float targetValue(90.0f); + float relativeValue(targetValue - startValue); + animation.AnimateTo(Property(actor, index), targetValue, AlphaFunctions::EaseOut); + + float ninetyFivePercentProgress(startValue + relativeValue*0.95f); + + // Start the animation + animation.Play(); + + bool signalReceived(false); + AnimationFinishCheck finishCheck(signalReceived); + animation.FinishedSignal().Connect(&application, finishCheck); + + application.SendNotification(); + application.Render(static_cast(durationSeconds*950.0f)/* 95% progress */); + + // We didn't expect the animation to finish yet + application.SendNotification(); + finishCheck.CheckSignalNotReceived(); + + // The position should have moved more, than with a linear alpha function + float current(actor.GetProperty(index)); + DALI_TEST_CHECK( current > ninetyFivePercentProgress ); + + application.SendNotification(); + application.Render(static_cast(durationSeconds*50.0f) + 1u/*just beyond the animation duration*/); + + // We did expect the animation to finish + application.SendNotification(); + finishCheck.CheckSignalReceived(); + DALI_TEST_EQUALS( actor.GetProperty(index), targetValue, TEST_LOCATION ); END_TEST; } -int UtcDaliAnimationAnimateToBooleanTimePeriod(void) +int UtcDaliAnimationAnimateToFloatTimePeriod(void) { TestApplication application; Actor actor = Actor::New(); - // Register a boolean property - bool startValue(false); + // Register a float property + float startValue(10.0f); Property::Index index = actor.RegisterProperty( "test-property", startValue ); Stage::GetCurrent().Add(actor); - DALI_TEST_CHECK( actor.GetProperty(index) == startValue ); + DALI_TEST_EQUALS( actor.GetProperty(index), startValue, TEST_LOCATION ); // Build the animation - float durationSeconds(2.0f); + float durationSeconds(1.0f); Animation animation = Animation::New(durationSeconds); - bool finalValue( !startValue ); - float animatorDurationSeconds(durationSeconds * 0.5f); - animation.AnimateTo( Property(actor, index), - finalValue, - TimePeriod( animatorDurationSeconds ) ); + float targetValue(30.0f); + float relativeValue(targetValue - startValue); + float delay = 0.5f; + animation.AnimateTo(Property(actor, index), + targetValue, + TimePeriod(delay, durationSeconds - delay)); // Start the animation animation.Play(); @@ -2737,60 +3668,53 @@ int UtcDaliAnimationAnimateToBooleanTimePeriod(void) animation.FinishedSignal().Connect(&application, finishCheck); application.SendNotification(); - application.Render(static_cast(animatorDurationSeconds*950.0f)/* 95% animator progress */); + application.Render(static_cast(durationSeconds*500.0f)/* 50% animation progress, 0% animator progress */); // We didn't expect the animation to finish yet application.SendNotification(); finishCheck.CheckSignalNotReceived(); - DALI_TEST_CHECK( actor.GetProperty(index) == startValue ); + DALI_TEST_EQUALS( actor.GetProperty(index), startValue, TEST_LOCATION ); application.SendNotification(); - application.Render(static_cast(animatorDurationSeconds*50.0f) + 1u/*just beyond the animator duration*/); + application.Render(static_cast(durationSeconds*250.0f)/* 75% animation progress, 50% animator progress */); - // We didn't expect the animation to finish yet... + // We didn't expect the animation to finish yet application.SendNotification(); finishCheck.CheckSignalNotReceived(); - - // ...however we should have reached the final value - DALI_TEST_CHECK( actor.GetProperty(index) == finalValue ); + DALI_TEST_EQUALS( actor.GetProperty(index), startValue+(relativeValue*0.5f), TEST_LOCATION ); application.SendNotification(); - application.Render(static_cast(animatorDurationSeconds*1000.0f)/*just beyond the animation duration*/); + application.Render(static_cast(durationSeconds*250.0f) + 1u/*just beyond the animation duration*/); // We did expect the animation to finish application.SendNotification(); finishCheck.CheckSignalReceived(); - DALI_TEST_CHECK( actor.GetProperty(index) == finalValue ); - - // Check that nothing has changed after a couple of buffer swaps - application.Render(0); - DALI_TEST_CHECK( actor.GetProperty(index) == finalValue ); - application.Render(0); - DALI_TEST_CHECK( actor.GetProperty(index) == finalValue ); + DALI_TEST_EQUALS( actor.GetProperty(index), targetValue, TEST_LOCATION ); END_TEST; } -int UtcDaliAnimationAnimateToBooleanAlphaFunctionTimePeriod(void) +int UtcDaliAnimationAnimateToFloatAlphaFunctionTimePeriod(void) { TestApplication application; Actor actor = Actor::New(); - // Register a boolean property - bool startValue(false); + // Register a float property + float startValue(10.0f); Property::Index index = actor.RegisterProperty( "test-property", startValue ); Stage::GetCurrent().Add(actor); - DALI_TEST_CHECK( actor.GetProperty(index) == startValue ); + DALI_TEST_EQUALS( actor.GetProperty(index), startValue, TEST_LOCATION ); // Build the animation - float durationSeconds(2.0f); + float durationSeconds(1.0f); Animation animation = Animation::New(durationSeconds); - bool finalValue( !startValue ); - float animatorDurationSeconds(durationSeconds * 0.5f); - animation.AnimateTo( Property(actor, index), - finalValue, - AlphaFunctions::Linear, - TimePeriod( animatorDurationSeconds ) ); + float targetValue(30.0f); + float relativeValue(targetValue - startValue); + float delay = 0.5f; + animation.AnimateTo(Property(actor, index), + targetValue, + AlphaFunctions::Linear, + TimePeriod(delay, durationSeconds - delay)); // Start the animation animation.Play(); @@ -2800,59 +3724,51 @@ int UtcDaliAnimationAnimateToBooleanAlphaFunctionTimePeriod(void) animation.FinishedSignal().Connect(&application, finishCheck); application.SendNotification(); - application.Render(static_cast(animatorDurationSeconds*950.0f)/* 95% animator progress */); + application.Render(static_cast(durationSeconds*500.0f)/* 50% animation progress, 0% animator progress */); // We didn't expect the animation to finish yet application.SendNotification(); finishCheck.CheckSignalNotReceived(); - DALI_TEST_CHECK( actor.GetProperty(index) == startValue ); + DALI_TEST_EQUALS( actor.GetProperty(index), startValue, TEST_LOCATION ); application.SendNotification(); - application.Render(static_cast(animatorDurationSeconds*50.0f) + 1u/*just beyond the animator duration*/); + application.Render(static_cast(durationSeconds*250.0f)/* 75% animation progress, 50% animator progress */); - // We didn't expect the animation to finish yet... + // We didn't expect the animation to finish yet application.SendNotification(); finishCheck.CheckSignalNotReceived(); - - // ...however we should have reached the final value - DALI_TEST_CHECK( actor.GetProperty(index) == finalValue ); + DALI_TEST_EQUALS( actor.GetProperty(index), startValue+(relativeValue*0.5f), TEST_LOCATION ); application.SendNotification(); - application.Render(static_cast(animatorDurationSeconds*1000.0f)/*just beyond the animation duration*/); + application.Render(static_cast(durationSeconds*250.0f) + 1u/*just beyond the animation duration*/); // We did expect the animation to finish application.SendNotification(); finishCheck.CheckSignalReceived(); - DALI_TEST_CHECK( actor.GetProperty(index) == finalValue ); - - // Check that nothing has changed after a couple of buffer swaps - application.Render(0); - DALI_TEST_CHECK( actor.GetProperty(index) == finalValue ); - application.Render(0); - DALI_TEST_CHECK( actor.GetProperty(index) == finalValue ); + DALI_TEST_EQUALS( actor.GetProperty(index), targetValue, TEST_LOCATION ); END_TEST; } -int UtcDaliAnimationAnimateToFloat(void) +int UtcDaliAnimationAnimateToInteger(void) { TestApplication application; Actor actor = Actor::New(); - // Register a float property - float startValue(10.0f); + // Register an integer property + int startValue(10); Property::Index index = actor.RegisterProperty( "test-property", startValue ); Stage::GetCurrent().Add(actor); - DALI_TEST_EQUALS( actor.GetProperty(index), startValue, TEST_LOCATION ); + DALI_TEST_EQUALS( actor.GetProperty(index), startValue, TEST_LOCATION ); // Build the animation float durationSeconds(2.0f); Animation animation = Animation::New(durationSeconds); - float targetValue(50.0f); - float relativeValue(targetValue - startValue); + int targetValue(50); + int relativeValue(targetValue - startValue); animation.AnimateTo(Property(actor, "test-property"), targetValue); - float ninetyFivePercentProgress(startValue + relativeValue*0.95f); + int ninetyFivePercentProgress(static_cast(startValue + relativeValue*0.95f + 0.5f)); // Start the animation animation.Play(); @@ -2867,7 +3783,7 @@ int UtcDaliAnimationAnimateToFloat(void) // We didn't expect the animation to finish yet application.SendNotification(); finishCheck.CheckSignalNotReceived(); - DALI_TEST_EQUALS( actor.GetProperty(index), ninetyFivePercentProgress, TEST_LOCATION ); + DALI_TEST_EQUALS( actor.GetProperty(index), ninetyFivePercentProgress, TEST_LOCATION ); application.SendNotification(); application.Render(static_cast(durationSeconds*50.0f) + 1u/*just beyond the animation duration*/); @@ -2875,30 +3791,30 @@ int UtcDaliAnimationAnimateToFloat(void) // We did expect the animation to finish application.SendNotification(); finishCheck.CheckSignalReceived(); - DALI_TEST_EQUALS( actor.GetProperty(index), targetValue, TEST_LOCATION ); + DALI_TEST_EQUALS( actor.GetProperty(index), targetValue, TEST_LOCATION ); END_TEST; } -int UtcDaliAnimationAnimateToFloatAlphaFunction(void) +int UtcDaliAnimationAnimateToIntegerAlphaFunction(void) { TestApplication application; Actor actor = Actor::New(); - // Register a float property - float startValue(10.0f); + // Register an integer property + int startValue(10); Property::Index index = actor.RegisterProperty( "test-property", startValue ); Stage::GetCurrent().Add(actor); - DALI_TEST_EQUALS( actor.GetProperty(index), startValue, TEST_LOCATION ); + DALI_TEST_EQUALS( actor.GetProperty(index), startValue, TEST_LOCATION ); // Build the animation float durationSeconds(1.0f); Animation animation = Animation::New(durationSeconds); - float targetValue(90.0f); - float relativeValue(targetValue - startValue); + int targetValue(90); + int relativeValue(targetValue - startValue); animation.AnimateTo(Property(actor, index), targetValue, AlphaFunctions::EaseOut); - float ninetyFivePercentProgress(startValue + relativeValue*0.95f); + int ninetyFivePercentProgress(static_cast(startValue + relativeValue*0.95f + 0.5f)); // Start the animation animation.Play(); @@ -2915,7 +3831,7 @@ int UtcDaliAnimationAnimateToFloatAlphaFunction(void) finishCheck.CheckSignalNotReceived(); // The position should have moved more, than with a linear alpha function - float current(actor.GetProperty(index)); + int current(actor.GetProperty(index)); DALI_TEST_CHECK( current > ninetyFivePercentProgress ); application.SendNotification(); @@ -2924,27 +3840,27 @@ int UtcDaliAnimationAnimateToFloatAlphaFunction(void) // We did expect the animation to finish application.SendNotification(); finishCheck.CheckSignalReceived(); - DALI_TEST_EQUALS( actor.GetProperty(index), targetValue, TEST_LOCATION ); + DALI_TEST_EQUALS( actor.GetProperty(index), targetValue, TEST_LOCATION ); END_TEST; } -int UtcDaliAnimationAnimateToFloatTimePeriod(void) +int UtcDaliAnimationAnimateToIntegerTimePeriod(void) { TestApplication application; Actor actor = Actor::New(); - // Register a float property - float startValue(10.0f); + // Register an integer property + int startValue(10); Property::Index index = actor.RegisterProperty( "test-property", startValue ); Stage::GetCurrent().Add(actor); - DALI_TEST_EQUALS( actor.GetProperty(index), startValue, TEST_LOCATION ); + DALI_TEST_EQUALS( actor.GetProperty(index), startValue, TEST_LOCATION ); // Build the animation float durationSeconds(1.0f); Animation animation = Animation::New(durationSeconds); - float targetValue(30.0f); - float relativeValue(targetValue - startValue); + int targetValue(30); + int relativeValue(targetValue - startValue); float delay = 0.5f; animation.AnimateTo(Property(actor, index), targetValue, @@ -2963,7 +3879,7 @@ int UtcDaliAnimationAnimateToFloatTimePeriod(void) // We didn't expect the animation to finish yet application.SendNotification(); finishCheck.CheckSignalNotReceived(); - DALI_TEST_EQUALS( actor.GetProperty(index), startValue, TEST_LOCATION ); + DALI_TEST_EQUALS( actor.GetProperty(index), startValue, TEST_LOCATION ); application.SendNotification(); application.Render(static_cast(durationSeconds*250.0f)/* 75% animation progress, 50% animator progress */); @@ -2971,7 +3887,7 @@ int UtcDaliAnimationAnimateToFloatTimePeriod(void) // We didn't expect the animation to finish yet application.SendNotification(); finishCheck.CheckSignalNotReceived(); - DALI_TEST_EQUALS( actor.GetProperty(index), startValue+(relativeValue*0.5f), TEST_LOCATION ); + DALI_TEST_EQUALS( actor.GetProperty(index), static_cast(startValue+(relativeValue*0.5f)+0.5f), TEST_LOCATION ); application.SendNotification(); application.Render(static_cast(durationSeconds*250.0f) + 1u/*just beyond the animation duration*/); @@ -2979,27 +3895,27 @@ int UtcDaliAnimationAnimateToFloatTimePeriod(void) // We did expect the animation to finish application.SendNotification(); finishCheck.CheckSignalReceived(); - DALI_TEST_EQUALS( actor.GetProperty(index), targetValue, TEST_LOCATION ); + DALI_TEST_EQUALS( actor.GetProperty(index), targetValue, TEST_LOCATION ); END_TEST; } -int UtcDaliAnimationAnimateToFloatAlphaFunctionTimePeriod(void) +int UtcDaliAnimationAnimateToIntegerAlphaFunctionTimePeriod(void) { TestApplication application; Actor actor = Actor::New(); - // Register a float property - float startValue(10.0f); + // Register an integer property + int startValue(10); Property::Index index = actor.RegisterProperty( "test-property", startValue ); Stage::GetCurrent().Add(actor); - DALI_TEST_EQUALS( actor.GetProperty(index), startValue, TEST_LOCATION ); + DALI_TEST_EQUALS( actor.GetProperty(index), startValue, TEST_LOCATION ); // Build the animation float durationSeconds(1.0f); Animation animation = Animation::New(durationSeconds); - float targetValue(30.0f); - float relativeValue(targetValue - startValue); + int targetValue(30); + int relativeValue(targetValue - startValue); float delay = 0.5f; animation.AnimateTo(Property(actor, index), targetValue, @@ -3019,7 +3935,7 @@ int UtcDaliAnimationAnimateToFloatAlphaFunctionTimePeriod(void) // We didn't expect the animation to finish yet application.SendNotification(); finishCheck.CheckSignalNotReceived(); - DALI_TEST_EQUALS( actor.GetProperty(index), startValue, TEST_LOCATION ); + DALI_TEST_EQUALS( actor.GetProperty(index), startValue, TEST_LOCATION ); application.SendNotification(); application.Render(static_cast(durationSeconds*250.0f)/* 75% animation progress, 50% animator progress */); @@ -3027,7 +3943,7 @@ int UtcDaliAnimationAnimateToFloatAlphaFunctionTimePeriod(void) // We didn't expect the animation to finish yet application.SendNotification(); finishCheck.CheckSignalNotReceived(); - DALI_TEST_EQUALS( actor.GetProperty(index), startValue+(relativeValue*0.5f), TEST_LOCATION ); + DALI_TEST_EQUALS( actor.GetProperty(index), static_cast(startValue+(relativeValue*0.5f)+0.5f), TEST_LOCATION ); application.SendNotification(); application.Render(static_cast(durationSeconds*250.0f) + 1u/*just beyond the animation duration*/); @@ -3035,7 +3951,7 @@ int UtcDaliAnimationAnimateToFloatAlphaFunctionTimePeriod(void) // We did expect the animation to finish application.SendNotification(); finishCheck.CheckSignalReceived(); - DALI_TEST_EQUALS( actor.GetProperty(index), targetValue, TEST_LOCATION ); + DALI_TEST_EQUALS( actor.GetProperty(index), targetValue, TEST_LOCATION ); END_TEST; } @@ -8219,6 +9135,66 @@ int UtcDaliAnimationAnimateFloat(void) END_TEST; } +int UtcDaliAnimationAnimateInteger(void) +{ + TestApplication application; + + Actor actor = Actor::New(); + Stage::GetCurrent().Add(actor); + + // Register an integer property + int startValue(10); + Property::Index index = actor.RegisterProperty( "test-property", startValue ); + DALI_TEST_EQUALS( actor.GetProperty(index), startValue, TEST_LOCATION ); + + // Build the animation + float durationSeconds(10.0f); + Animation animation = Animation::New(durationSeconds); + int targetPosition(0); + AnimateIntegerTestFunctor func( 100, targetPosition ); + animation.Animate( Property(actor, index), func ); + + // Start the animation + animation.Play(); + + bool signalReceived(false); + AnimationFinishCheck finishCheck(signalReceived); + animation.FinishedSignal().Connect(&application, finishCheck); + + application.SendNotification(); + application.Render(static_cast(durationSeconds*250.0f)/* 25% progress */); + + // We didn't expect the animation to finish yet + application.SendNotification(); + finishCheck.CheckSignalNotReceived(); + DALI_TEST_EQUALS( actor.GetProperty(index), 75, TEST_LOCATION ); + + application.SendNotification(); + application.Render(static_cast(durationSeconds*250.0f)/* 50% progress */); + + // We didn't expect the animation to finish yet + application.SendNotification(); + finishCheck.CheckSignalNotReceived(); + DALI_TEST_EQUALS( actor.GetProperty(index), 50, TEST_LOCATION ); + + application.SendNotification(); + application.Render(static_cast(durationSeconds*250.0f)/* 75% progress */); + + // We didn't expect the animation to finish yet + application.SendNotification(); + finishCheck.CheckSignalNotReceived(); + DALI_TEST_EQUALS( actor.GetProperty(index), 25, TEST_LOCATION ); + + application.SendNotification(); + application.Render(static_cast(durationSeconds*250.0f) + 1u/*just beyond the animation duration*/); + + // We did expect the animation to finish + application.SendNotification(); + finishCheck.CheckSignalReceived(); + DALI_TEST_EQUALS( actor.GetProperty(index), targetPosition, TEST_LOCATION ); + END_TEST; +} + int UtcDaliAnimationAnimateVector2(void) { TestApplication application; @@ -8947,4 +9923,117 @@ int UtcDaliAnimationUpdateManager(void) END_TEST; } +int UtcDaliAnimationSignalOrder(void) +{ + TestApplication application; + + Actor actor = Actor::New(); + Stage::GetCurrent().Add( actor ); + + // Build the animations + Animation animation1 = Animation::New( 0.0f ); // finishes first frame + Animation animation2 = Animation::New( 0.02f ); // finishes in 20 ms + + bool signal1Received = false; + animation1.FinishedSignal().Connect( &application, AnimationFinishCheck( signal1Received ) ); + + bool signal2Received = false; + animation2.FinishedSignal().Connect( &application, AnimationFinishCheck( signal2Received ) ); + + // Apply animations to actor + animation1.AnimateTo( Property(actor, Actor::POSITION), Vector3( 3.0f, 2.0f, 1.0f ), AlphaFunctions::Linear ); + animation1.Play(); + animation2.AnimateTo( Property(actor, Actor::SIZE ), Vector3( 10.0f, 20.0f, 30.0f ), AlphaFunctions::Linear ); + animation2.Play(); + + DALI_TEST_EQUALS( signal1Received, false, TEST_LOCATION ); + DALI_TEST_EQUALS( signal2Received, false, TEST_LOCATION ); + + application.SendNotification(); + application.UpdateOnly( 10 ); // 10ms progress + + // no notifications yet + DALI_TEST_EQUALS( signal1Received, false, TEST_LOCATION ); + DALI_TEST_EQUALS( signal2Received, false, TEST_LOCATION ); + + application.SendNotification(); + + // first completed + DALI_TEST_EQUALS( signal1Received, true, TEST_LOCATION ); + DALI_TEST_EQUALS( signal2Received, false, TEST_LOCATION ); + signal1Received = false; + + // 1st animation is complete now, do another update with no ProcessEvents in between + application.UpdateOnly( 20 ); // 20ms progress + + // ProcessEvents + application.SendNotification(); + + // 2nd should complete now + DALI_TEST_EQUALS( signal1Received, false, TEST_LOCATION ); + DALI_TEST_EQUALS( signal2Received, true, TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliAnimationExtendDuration(void) +{ + TestApplication application; + + Actor actor = Actor::New(); + + // Register a float property + float startValue(10.0f); + Property::Index index = actor.RegisterProperty( "test-property", startValue ); + Stage::GetCurrent().Add(actor); + DALI_TEST_EQUALS( actor.GetProperty(index), startValue, TEST_LOCATION ); + + // Build the animation + float initialDurationSeconds(1.0f); + float animatorDelay = 5.0f; + float animatorDurationSeconds(5.0f); + float extendedDurationSeconds(animatorDelay+animatorDurationSeconds); + Animation animation = Animation::New(initialDurationSeconds); + float targetValue(30.0f); + float relativeValue(targetValue - startValue); + + animation.AnimateTo(Property(actor, index), + targetValue, + TimePeriod(animatorDelay, animatorDurationSeconds)); + + // The duration should have been extended + DALI_TEST_EQUALS( animation.GetDuration(), extendedDurationSeconds, TEST_LOCATION ); + + // Start the animation + animation.Play(); + + bool signalReceived(false); + AnimationFinishCheck finishCheck(signalReceived); + animation.FinishedSignal().Connect(&application, finishCheck); + + application.SendNotification(); + application.Render(static_cast(extendedDurationSeconds*500.0f)/* 50% animation progress, 0% animator progress */); + + // We didn't expect the animation to finish yet + application.SendNotification(); + finishCheck.CheckSignalNotReceived(); + DALI_TEST_EQUALS( actor.GetProperty(index), startValue, TEST_LOCATION ); + + application.SendNotification(); + application.Render(static_cast(extendedDurationSeconds*250.0f)/* 75% animation progress, 50% animator progress */); + + // We didn't expect the animation to finish yet + application.SendNotification(); + finishCheck.CheckSignalNotReceived(); + DALI_TEST_EQUALS( actor.GetProperty(index), startValue+(relativeValue*0.5f), TEST_LOCATION ); + + application.SendNotification(); + application.Render(static_cast(extendedDurationSeconds*250.0f) + 1u/*just beyond the animation duration*/); + + // We did expect the animation to finish + application.SendNotification(); + finishCheck.CheckSignalReceived(); + DALI_TEST_EQUALS( actor.GetProperty(index), targetValue, TEST_LOCATION ); + END_TEST; +}