/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2019 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.
static const float ROTATION_EPSILON = 0.0001f;
static const float VECTOR4_EPSILON = 0.0001f;
+static const float VECTOR3_EPSILON = 0.0001f;
// Functor to test whether a Finish signal is emitted
struct AnimationFinishCheck
END_TEST;
}
-int UtcDaliAnimationSetEndActioN(void)
+int UtcDaliAnimationSetEndActionN(void)
{
TestApplication application;
END_TEST;
}
-int UtcDaliAnimationPlayOffStageP(void)
+int UtcDaliAnimationPlayOffStageDiscardP(void)
{
// Test that an animation can be played, when the actor is off-stage.
// When the actor is added to the stage, it should appear at the current position
Actor actor = Actor::New();
Vector3 basePosition(Vector3::ZERO);
DALI_TEST_EQUALS( actor.GetCurrentPosition(), basePosition, TEST_LOCATION );
- // Not added to the stage!
+ // Not added to the stage yet!
// Build the animation
float durationSeconds(1.0f);
// We didn't expect the animation to finish yet
application.SendNotification();
finishCheck.CheckSignalNotReceived();
- DALI_TEST_EQUALS( actor.GetCurrentPosition(), Vector3::ZERO/*off-stage*/, TEST_LOCATION );
+ DALI_TEST_EQUALS( actor.GetCurrentPosition(), Vector3(20,20,20), TEST_LOCATION );
+
+ // Add to the stage
+ Stage::GetCurrent().Add(actor);
+
+ application.SendNotification();
+ application.Render(static_cast<unsigned int>(durationSeconds*200.0f)/* 40% progress */);
+
+ // We didn't expect the animation to finish yet
+ application.SendNotification();
+ finishCheck.CheckSignalNotReceived();
+ DALI_TEST_EQUALS( actor.GetCurrentPosition(), Vector3(40,40,40)/*on-stage*/, TEST_LOCATION );
+
+ // Remove from the stage
+ Stage::GetCurrent().Remove(actor);
+
+ application.SendNotification();
+ application.Render(static_cast<unsigned int>(durationSeconds*200.0f)/* 60% progress */);
+
+ // We didn't expect the animation to finish yet
+ application.SendNotification();
+ finishCheck.CheckSignalNotReceived();
+ DALI_TEST_EQUALS( actor.GetCurrentPosition(), Vector3::ZERO/*back to start position as disconnect behaviour is discard*/, TEST_LOCATION );
+ // Check that nothing has changed after a couple of buffer swaps
+ application.Render(0);
+ DALI_TEST_EQUALS( actor.GetCurrentPosition(), Vector3::ZERO, TEST_LOCATION );
+ application.Render(0);
+ DALI_TEST_EQUALS( actor.GetCurrentPosition(), Vector3::ZERO, TEST_LOCATION );
+ application.Render(0);
+ DALI_TEST_EQUALS( actor.GetCurrentPosition(), Vector3::ZERO, TEST_LOCATION );
+
+ // Add to the stage
+ Stage::GetCurrent().Add(actor);
+
+ application.SendNotification();
+ application.Render(static_cast<unsigned int>(durationSeconds*200.0f)/* 80% progress */);
+
+ // We didn't expect the animation to finish yet
+ application.SendNotification();
+ finishCheck.CheckSignalNotReceived();
+ DALI_TEST_EQUALS( actor.GetCurrentPosition(), Vector3(80,80,80), TEST_LOCATION );
+
+ application.SendNotification();
+ application.Render(static_cast<unsigned int>(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 UtcDaliAnimationPlayOffStageBakeFinalP(void)
+{
+ // Test that an animation can be played, when the actor is off-stage.
+ // When the actor is added to the stage, it should appear at the current position
+ // i.e. where it would have been anyway, if on-stage from the beginning.
+
+ TestApplication application;
+
+ Actor actor = Actor::New();
+ Vector3 basePosition(Vector3::ZERO);
+ DALI_TEST_EQUALS( actor.GetCurrentPosition(), basePosition, TEST_LOCATION );
+ // Not added to the stage!
+
+ // Build the animation
+ float durationSeconds(1.0f);
+ Animation animation = Animation::New(durationSeconds);
+ Vector3 targetPosition(100.0f, 100.0f, 100.0f);
+ animation.AnimateTo(Property(actor, Actor::Property::POSITION), targetPosition, AlphaFunction::LINEAR);
+
+ // Start the animation
+ animation.Play();
+
+ bool signalReceived(false);
+ AnimationFinishCheck finishCheck(signalReceived);
+ animation.FinishedSignal().Connect(&application, finishCheck);
+
+ application.SendNotification();
+ application.Render(static_cast<unsigned int>(durationSeconds*200.0f)/* 20% progress */);
+
+ // We didn't expect the animation to finish yet
+ application.SendNotification();
+ finishCheck.CheckSignalNotReceived();
+ DALI_TEST_EQUALS( actor.GetCurrentPosition(), Vector3(20,20,20), TEST_LOCATION );
// Add to the stage
Stage::GetCurrent().Add(actor);
// We didn't expect the animation to finish yet
application.SendNotification();
finishCheck.CheckSignalNotReceived();
- Vector3 expectedPosition(basePosition + (targetPosition - basePosition)*0.4f);
- DALI_TEST_EQUALS( actor.GetCurrentPosition(), expectedPosition/*on-stage*/, TEST_LOCATION );
+ DALI_TEST_EQUALS( actor.GetCurrentPosition(), Vector3(40,40,40)/*on-stage*/, TEST_LOCATION );
// Remove from the stage
Stage::GetCurrent().Remove(actor);
// We didn't expect the animation to finish yet
application.SendNotification();
finishCheck.CheckSignalNotReceived();
- DALI_TEST_EQUALS( actor.GetCurrentPosition(), Vector3::ZERO/*back to start position*/, TEST_LOCATION );
+ DALI_TEST_EQUALS( actor.GetCurrentPosition(), targetPosition /*bake final*/, TEST_LOCATION );
+
+ // Add to the stage
+ Stage::GetCurrent().Add(actor);
+
+ application.SendNotification();
+ application.Render(static_cast<unsigned int>(durationSeconds*200.0f)/* 80% progress */);
+
+ // We didn't expect the animation to finish yet
+ application.SendNotification();
+ finishCheck.CheckSignalNotReceived();
+ DALI_TEST_EQUALS( actor.GetCurrentPosition(), targetPosition /*bake final removed the */, TEST_LOCATION );
+
+ application.SendNotification();
+ application.Render(static_cast<unsigned int>(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 UtcDaliAnimationPlayOffStageBakeP(void)
+{
+ // Test that an animation can be played, when the actor is off-stage.
+ // When the actor is added to the stage, it should appear at the current position
+ // i.e. where it would have been anyway, if on-stage from the beginning.
+
+ TestApplication application;
+
+ Actor actor = Actor::New();
+ Vector3 basePosition(Vector3::ZERO);
+ DALI_TEST_EQUALS( actor.GetCurrentPosition(), basePosition, TEST_LOCATION );
+ // Not added to the stage!
+
+ // Build the animation
+ float durationSeconds(1.0f);
+ Animation animation = Animation::New(durationSeconds);
+ animation.SetDisconnectAction( Animation::Bake );
+ Vector3 targetPosition(100.0f, 100.0f, 100.0f);
+ animation.AnimateTo(Property(actor, Actor::Property::POSITION), targetPosition, AlphaFunction::LINEAR);
+
+ // Start the animation
+ animation.Play();
+
+ bool signalReceived(false);
+ AnimationFinishCheck finishCheck(signalReceived);
+ animation.FinishedSignal().Connect(&application, finishCheck);
+
+ application.SendNotification();
+ application.Render(static_cast<unsigned int>(durationSeconds*200.0f)/* 20% progress */);
+
+ // We didn't expect the animation to finish yet
+ application.SendNotification();
+ finishCheck.CheckSignalNotReceived();
+ DALI_TEST_EQUALS( actor.GetCurrentPosition(), Vector3(20,20,20), TEST_LOCATION );
// Add to the stage
Stage::GetCurrent().Add(actor);
application.SendNotification();
+ application.Render(static_cast<unsigned int>(durationSeconds*200.0f)/* 40% progress */);
+
+ // We didn't expect the animation to finish yet
+ application.SendNotification();
+ finishCheck.CheckSignalNotReceived();
+ DALI_TEST_EQUALS( actor.GetCurrentPosition(), Vector3(40,40,40)/*on-stage*/, TEST_LOCATION );
+
+ // Remove from the stage
+ Stage::GetCurrent().Remove(actor); // baked here
+
+ application.SendNotification();
+ // this render is a no-op in this case as animator is disabled while off stage
+ application.Render(static_cast<unsigned int>(durationSeconds*200.0f)/* 60% progress */);
+ // We didn't expect the animation to finish yet
+ application.SendNotification();
+ finishCheck.CheckSignalNotReceived();
+ DALI_TEST_EQUALS( actor.GetCurrentPosition(), Vector3(40,40,40) /*baked value*/, TEST_LOCATION );
+
+ // Add back to the stage
+ Stage::GetCurrent().Add(actor);
+
+ application.SendNotification();
application.Render(static_cast<unsigned int>(durationSeconds*200.0f)/* 80% progress */);
+ DALI_TEST_EQUALS( actor.GetCurrentPosition(), Vector3(88,88,88) /* animation restarted at 40,40,40 + 80%*60 */, TEST_LOCATION );
+ application.Render(static_cast<unsigned int>(0.0f) );
+ DALI_TEST_EQUALS( actor.GetCurrentPosition(), Vector3(88,88,88) /*baked value*/, TEST_LOCATION );
+ application.Render(static_cast<unsigned int>(0.0f) );
+ DALI_TEST_EQUALS( actor.GetCurrentPosition(), Vector3(88,88,88) /*baked value*/, TEST_LOCATION );
+
+ // Remove from the stage
+ Stage::GetCurrent().Remove(actor); // baked here
+
+ application.SendNotification();
+ // this render is a no-op in this case as animator is disabled while off stage
+ application.Render(static_cast<unsigned int>(durationSeconds*200.0f)/* 100% progress */);
+ DALI_TEST_EQUALS( actor.GetCurrentPosition(), Vector3(88,88,88) /*baked value*/, TEST_LOCATION );
+ application.Render(static_cast<unsigned int>(0.0f) );
+ DALI_TEST_EQUALS( actor.GetCurrentPosition(), Vector3(88,88,88) /*baked value*/, TEST_LOCATION );
+ application.Render(static_cast<unsigned int>(0.0f) );
+ DALI_TEST_EQUALS( actor.GetCurrentPosition(), Vector3(88,88,88) /*baked value*/, TEST_LOCATION );
+
+ // Add back to the stage
+ Stage::GetCurrent().Add(actor);
// We didn't expect the animation to finish yet
application.SendNotification();
finishCheck.CheckSignalNotReceived();
- expectedPosition = Vector3(basePosition + (targetPosition - basePosition)*0.8f);
- DALI_TEST_EQUALS( actor.GetCurrentPosition(), expectedPosition, TEST_LOCATION );
+ DALI_TEST_EQUALS( actor.GetCurrentPosition(), Vector3(88,88,88) , TEST_LOCATION );
application.SendNotification();
application.Render(static_cast<unsigned int>(durationSeconds*200.0f) + 1u/*just beyond the animation duration*/);
// 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;
Animation animation = Animation::New(durationSeconds);
Vector3 targetParentOrigin(ParentOrigin::BOTTOM_RIGHT);
- try
+ DALI_TEST_ASSERTION(
{
animation.AnimateTo( Property(actor, Actor::Property::PARENT_ORIGIN), targetParentOrigin );
- }
- catch (Dali::DaliException& e)
- {
- DALI_TEST_PRINT_ASSERT( e );
- DALI_TEST_ASSERT(e, "IsPropertyAnimatable( index )", TEST_LOCATION);
- }
+ }, "Property is not animatable" );
+
END_TEST;
}
-int UtcDaliAnimationAnimateToActorParentOriginXP(void)
+int UtcDaliAnimationAnimateToActorParentOriginXN(void)
{
TestApplication application;
Animation animation = Animation::New(durationSeconds);
float targetX(1.0f);
- try
+ DALI_TEST_ASSERTION(
{
animation.AnimateTo( Property(actor, Actor::Property::PARENT_ORIGIN_X), targetX );
- }
- catch (Dali::DaliException& e)
- {
- DALI_TEST_PRINT_ASSERT( e );
- DALI_TEST_ASSERT(e, "IsPropertyAnimatable( index )", TEST_LOCATION);
- }
+ }, "Property is not animatable" );
+
END_TEST;
}
-int UtcDaliAnimationAnimateToActorParentOriginYP(void)
+int UtcDaliAnimationAnimateToActorParentOriginYN(void)
{
TestApplication application;
Animation animation = Animation::New(durationSeconds);
float targetY(1.0f);
- try
+ DALI_TEST_ASSERTION(
{
animation.AnimateTo( Property(actor, Actor::Property::PARENT_ORIGIN_Y), targetY );
- }
- catch (Dali::DaliException& e)
- {
- DALI_TEST_PRINT_ASSERT( e );
- DALI_TEST_ASSERT(e, "IsPropertyAnimatable( index )", TEST_LOCATION);
- }
+ }, "Property is not animatable" );
+
END_TEST;
}
-int UtcDaliAnimationAnimateToActorParentOriginZP(void)
+int UtcDaliAnimationAnimateToActorParentOriginZN(void)
{
TestApplication application;
Animation animation = Animation::New(durationSeconds);
float targetZ(1.0f);
- try
+ DALI_TEST_ASSERTION(
{
animation.AnimateTo( Property(actor, Actor::Property::PARENT_ORIGIN_Z), targetZ );
- }
- catch (Dali::DaliException& e)
- {
- DALI_TEST_PRINT_ASSERT( e );
- DALI_TEST_ASSERT(e, "IsPropertyAnimatable( index )", TEST_LOCATION);
- }
+ }, "Property is not animatable" );
+
END_TEST;
}
-int UtcDaliAnimationAnimateToActorAnchorPointP(void)
+int UtcDaliAnimationAnimateToActorAnchorPointN(void)
{
TestApplication application;
Animation animation = Animation::New(durationSeconds);
Vector3 targetAnchorPoint(AnchorPoint::TOP_LEFT);
- try
+ DALI_TEST_ASSERTION(
{
animation.AnimateTo( Property(actor, Actor::Property::ANCHOR_POINT), targetAnchorPoint);
- }
- catch (Dali::DaliException& e)
- {
- DALI_TEST_PRINT_ASSERT( e );
- DALI_TEST_ASSERT(e, "IsPropertyAnimatable( index )", TEST_LOCATION);
- }
+ }, "Property is not animatable" );
+
END_TEST;
}
-int UtcDaliAnimationAnimateToActorAnchorPointXP(void)
+int UtcDaliAnimationAnimateToActorAnchorPointXN(void)
{
TestApplication application;
Animation animation = Animation::New(durationSeconds);
float targetX(1.0f);
- try
+ DALI_TEST_ASSERTION(
{
animation.AnimateTo( Property(actor, Actor::Property::ANCHOR_POINT_X), targetX );
- }
- catch (Dali::DaliException& e)
- {
- DALI_TEST_PRINT_ASSERT( e );
- DALI_TEST_ASSERT(e, "IsPropertyAnimatable( index )", TEST_LOCATION);
- }
+ }, "Property is not animatable" );
+
END_TEST;
}
-int UtcDaliAnimationAnimateToActorAnchorPointYP(void)
+int UtcDaliAnimationAnimateToActorAnchorPointYN(void)
{
TestApplication application;
Animation animation = Animation::New(durationSeconds);
float targetY(0.0f);
- try
+ DALI_TEST_ASSERTION(
{
animation.AnimateTo( Property(actor, Actor::Property::ANCHOR_POINT_Y), targetY );
- }
- catch (Dali::DaliException& e)
- {
- DALI_TEST_PRINT_ASSERT( e );
- DALI_TEST_ASSERT(e, "IsPropertyAnimatable( index )", TEST_LOCATION);
- }
+ }, "Property is not animatable" );
+
END_TEST;
}
-int UtcDaliAnimationAnimateToActorAnchorPointZP(void)
+int UtcDaliAnimationAnimateToActorAnchorPointZN(void)
{
TestApplication application;
Animation animation = Animation::New(durationSeconds);
float targetZ(100.0f);
- try
+ DALI_TEST_ASSERTION(
{
animation.AnimateTo( Property(actor, Actor::Property::ANCHOR_POINT_Z), targetZ );
- }
- catch (Dali::DaliException& e)
- {
- DALI_TEST_PRINT_ASSERT( e );
- DALI_TEST_ASSERT(e, "IsPropertyAnimatable( index )", TEST_LOCATION);
- }
+ }, "Property is not animatable" );
+
END_TEST;
}
END_TEST;
}
-int UtcDaliAnimationKeyFrames02P(void)
+int UtcDaliAnimationKeyFrames02N(void)
{
TestApplication application;
DALI_TEST_EQUALS(keyFrames.GetType(), Property::FLOAT, TEST_LOCATION);
- try
+ DALI_TEST_ASSERTION(
{
keyFrames.Add(1.9f, false);
- }
- catch (Dali::DaliException& e)
- {
- DALI_TEST_PRINT_ASSERT( e );
- DALI_TEST_ASSERT(e, "mType == value.GetType()", TEST_LOCATION);
- }
+ }, "mType == value.GetType()" );
+
END_TEST;
}
-int UtcDaliAnimationKeyFrames03P(void)
+int UtcDaliAnimationKeyFrames03N(void)
{
TestApplication application;
DALI_TEST_EQUALS(keyFrames.GetType(), Property::BOOLEAN, TEST_LOCATION);
- try
+ DALI_TEST_ASSERTION(
{
keyFrames.Add(0.7f, Vector3(1.0f, 1.0f, 1.0f));
- }
- catch (Dali::DaliException& e)
- {
- DALI_TEST_PRINT_ASSERT( e );
- DALI_TEST_ASSERT(e, "mType == value.GetType()", TEST_LOCATION);
- }
+ }, "mType == value.GetType()" );
+
END_TEST;
}
-int UtcDaliAnimationKeyFrames04P(void)
+int UtcDaliAnimationKeyFrames04N(void)
{
TestApplication application;
DALI_TEST_EQUALS(keyFrames.GetType(), Property::VECTOR2, TEST_LOCATION);
- try
+ DALI_TEST_ASSERTION(
{
keyFrames.Add(0.7f, Vector3(1.0f, 1.0f, 1.0f));
- }
- catch (Dali::DaliException& e)
- {
- DALI_TEST_PRINT_ASSERT( e );
- DALI_TEST_ASSERT(e, "mType == value.GetType()", TEST_LOCATION);
- }
+ }, "mType == value.GetType()" );
+
END_TEST;
}
-int UtcDaliAnimationKeyFrames05P(void)
+int UtcDaliAnimationKeyFrames05N(void)
{
TestApplication application;
DALI_TEST_EQUALS(keyFrames.GetType(), Property::VECTOR3, TEST_LOCATION);
- try
+ DALI_TEST_ASSERTION(
{
keyFrames.Add(0.7f, 1.0f);
- }
- catch (Dali::DaliException& e)
- {
- DALI_TEST_PRINT_ASSERT( e );
- DALI_TEST_ASSERT(e, "mType == value.GetType()", TEST_LOCATION);
- }
+ }, "mType == value.GetType()" );
+
END_TEST;
}
-int UtcDaliAnimationKeyFrames06P(void)
+int UtcDaliAnimationKeyFrames06N(void)
{
TestApplication application;
DALI_TEST_EQUALS(keyFrames.GetType(), Property::VECTOR4, TEST_LOCATION);
- try
+ DALI_TEST_ASSERTION(
{
keyFrames.Add(0.7f, Quaternion(Radian(1.717f), Vector3::XAXIS));
- }
- catch (Dali::DaliException& e)
- {
- DALI_TEST_PRINT_ASSERT( e );
- DALI_TEST_ASSERT(e, "mType == value.GetType()", TEST_LOCATION);
- }
+ }, "mType == value.GetType()" );
+
END_TEST;
}
-int UtcDaliAnimationKeyFrames07P(void)
+int UtcDaliAnimationKeyFrames07N(void)
{
TestApplication application;
DALI_TEST_EQUALS(keyFrames.GetType(), Property::ROTATION, TEST_LOCATION);
- try
+ DALI_TEST_ASSERTION(
{
keyFrames.Add(0.7f, 1.1f);
- }
- catch (Dali::DaliException& e)
- {
- DALI_TEST_PRINT_ASSERT( e );
- DALI_TEST_ASSERT(e, "mType == value.GetType()", TEST_LOCATION);
- }
+ }, "mType == value.GetType()" );
+
END_TEST;
}
Stage::GetCurrent().Add(actor);
DALI_TEST_EQUALS( actor.GetProperty<int>(index), startValue, TEST_LOCATION );
- try
+ DALI_TEST_ASSERTION(
{
// Build the animation
Animation animation = Animation::New( 2.0f );
std::string relativeValue = "relative string";
animation.AnimateBy( Property(actor, index), relativeValue );
tet_result(TET_FAIL);
- }
- catch ( Dali::DaliException& e )
- {
- DALI_TEST_ASSERT( e, "Animated value and Property type don't match", TEST_LOCATION );
- }
-
+ }, "Target value is not animatable" );
END_TEST;
}
Stage::GetCurrent().Add(actor);
DALI_TEST_EQUALS( actor.GetProperty<int>(index), startValue, TEST_LOCATION );
- try
+ DALI_TEST_ASSERTION(
{
// Build the animation
Animation animation = Animation::New( 2.0f );
std::string relativeValue = "relative string";
animation.AnimateTo( Property(actor, index), relativeValue );
-
- tet_result(TET_FAIL);
- }
- catch ( Dali::DaliException& e )
- {
- DALI_TEST_ASSERT( e, "Animated value and Property type don't match", TEST_LOCATION );
- }
+ }, "Target value is not animatable" );
END_TEST;
}
Stage::GetCurrent().Add(actor);
DALI_TEST_EQUALS( actor.GetProperty<int>(index), startValue, TEST_LOCATION );
- try
+ DALI_TEST_ASSERTION(
{
// Build the animation
KeyFrames keyFrames = KeyFrames::New();
keyFrames.Add( 0.0f, std::string("relative string1") );
keyFrames.Add( 1.0f, std::string("relative string2") );
// no need to really create the animation as keyframes do the check
-
- tet_result(TET_FAIL);
- }
- catch ( Dali::DaliException& e )
- {
- DALI_TEST_ASSERT( e, "Type not animateable", TEST_LOCATION );
- }
+ }, "Property type is not animatable" );
END_TEST;
}
END_TEST;
}
+
+int UtcDaliAnimationAnimateByInvalidParameters(void)
+{
+ TestApplication application;
+
+ Actor actor = Actor::New();
+ Stage::GetCurrent().Add(actor);
+
+ // Create the animation
+ Animation animation = Animation::New(1.0f);
+
+ DALI_TEST_ASSERTION(
+ {
+ // non animateable property (STRING)
+ animation.AnimateBy( Property( actor, Actor::Property::LAYOUT_DIRECTION ), Property::Value( "new direction" ) );
+ }, "Property type is not animatable" );
+
+ DALI_TEST_ASSERTION(
+ {
+ // non animateable property (MATRIX)
+ Property::Index index = actor.RegisterProperty( "Foobar", Property::Value( Dali::Matrix() ), Property::ANIMATABLE );
+ animation.AnimateBy( Property( actor, index ), Property::Value( Property::MATRIX ) );
+ }, "Property type is not animatable" );
+
+ // AnimateBy
+ DALI_TEST_ASSERTION(
+ {
+ // non animateable target (NONE)
+ animation.AnimateBy( Property( actor, Actor::Property::POSITION ), Property::Value() );
+ }, "Target value is not animatable" );
+
+ DALI_TEST_ASSERTION(
+ {
+ // non animateable target (STRING)
+ animation.AnimateBy( Property( actor, Actor::Property::POSITION ), Property::Value("foo") );
+ }, "Target value is not animatable" );
+
+ DALI_TEST_ASSERTION(
+ {
+ // not mathing properties (VECTOR3, FLOAT)
+ animation.AnimateBy( Property( actor, Actor::Property::POSITION ), Property::Value( 10.f ) );
+ }, "Property and target types don't match" );
+
+ DALI_TEST_ASSERTION(
+ {
+ // not mathing properties (VECTOR3.A, VECTOR2)
+ animation.AnimateBy( Property( actor, Actor::Property::COLOR_ALPHA ), Property::Value( Property::VECTOR2 ) );
+ }, "Property and target types don't match" );
+
+ DALI_TEST_ASSERTION(
+ {
+ // negative duration
+ animation.AnimateBy( Property( actor, Actor::Property::POSITION ), Property::Value( Vector3(1,2,3) ), TimePeriod(-1) );
+ }, "Duration must be >=0" );
+
+ END_TEST;
+}
+
+int UtcDaliAnimationAnimateToInvalidParameters(void)
+{
+ TestApplication application;
+
+ Actor actor = Actor::New();
+ Stage::GetCurrent().Add(actor);
+
+ // Create the animation
+ Animation animation = Animation::New(1.0f);
+
+ // AnimateTo
+ DALI_TEST_ASSERTION(
+ {
+ // non animateable property (MAP)
+ Property::Index index = actor.RegisterProperty( "Foobar", Property::Value( Property::MAP ), Property::ANIMATABLE );
+ animation.AnimateTo( Property( actor, index ), Property::Value( Property::MAP ) );
+ }, "Property type is not animatable" );
+
+ DALI_TEST_ASSERTION(
+ {
+ // non animateable target (NONE)
+ animation.AnimateTo( Property( actor, Actor::Property::CLIPPING_MODE ), Property::Value() );
+ }, "Property type is not animatable" );
+
+ DALI_TEST_ASSERTION(
+ {
+ // non animateable target (ARRAY)
+ animation.AnimateTo( Property( actor, Actor::Property::POSITION ), Property::Value( Property::ARRAY ) );
+ }, "Target value is not animatable" );
+
+ DALI_TEST_ASSERTION(
+ {
+ // non animateable target (RECTANGLE)
+ animation.AnimateBy( Property( actor, Actor::Property::POSITION ), Property::Value( Rect<int32_t>() ) );
+ }, "Target value is not animatable" );
+
+ DALI_TEST_ASSERTION(
+ {
+ // not mathing properties (FLOAT, INT)
+ animation.AnimateTo( Property( actor, Actor::Property::SCALE_Y ), Property::Value(10) );
+ }, "Property and target types don't match" );
+
+ DALI_TEST_ASSERTION(
+ {
+ // not mathing properties (VECTOR3, VECTOR2)
+ animation.AnimateTo( Property( actor, Actor::Property::COLOR ), Property::Value( Property::VECTOR2 ) );
+ }, "Property and target types don't match" );
+
+ DALI_TEST_ASSERTION(
+ {
+ // negative duration
+ animation.AnimateTo( Property( actor, Actor::Property::POSITION ), Property::Value( Vector3(1,2,3) ), TimePeriod(-1) );
+ }, "Duration must be >=0" );
+
+ END_TEST;
+}
+
+int UtcDaliAnimationAnimateBetweenInvalidParameters(void)
+{
+ TestApplication application;
+
+ Actor actor = Actor::New();
+ Stage::GetCurrent().Add(actor);
+
+ // Create the animation
+ Animation animation = Animation::New(1.0f);
+
+ // AnimateBetween
+ DALI_TEST_ASSERTION(
+ {
+ // non animateable property (ARRAY)
+ Property::Index index = actor.RegisterProperty( "Foobar", Property::Value( Property::ARRAY ), Property::ANIMATABLE );
+ KeyFrames keyframes = KeyFrames::New();
+ keyframes.Add( 0.5f, Property::Value( Property::ARRAY ) );
+ animation.AnimateBetween( Property( actor, index ), keyframes );
+ }, "Property type is not animatable" );
+
+ DALI_TEST_ASSERTION(
+ {
+ // non animateable target (NONE)
+ KeyFrames keyframes = KeyFrames::New();
+ keyframes.Add( 0.5f, Property::Value() );
+ animation.AnimateBetween( Property( actor, Actor::Property::CLIPPING_MODE ), keyframes );
+ }, "Property type is not animatable" );
+
+ DALI_TEST_ASSERTION(
+ {
+ // non animateable target (EXTENTS)
+ KeyFrames keyframes = KeyFrames::New();
+ keyframes.Add( 0.5f, Property::Value( Property::EXTENTS ) ); // throws
+ animation.AnimateBetween( Property( actor, Actor::Property::POSITION ), keyframes );
+ }, "Property type is not animatable" );
+
+ DALI_TEST_ASSERTION(
+ {
+ // non animateable target (RECTANGLE)
+ KeyFrames keyframes = KeyFrames::New();
+ keyframes.Add( 0.5f, Property::Value( Property::MAP ) ); // throws
+ animation.AnimateBetween( Property( actor, Actor::Property::POSITION ), keyframes );
+ }, "Property type is not animatable" );
+
+ DALI_TEST_ASSERTION(
+ {
+ // not mathing properties (VECTOR2, VECTOR4)
+ KeyFrames keyframes = KeyFrames::New();
+ keyframes.Add( 0.5f, Property::Value( Vector4( 1, 2, 3, 4 ) ) );
+ animation.AnimateBetween( Property( actor, Actor::Property::MAXIMUM_SIZE ), keyframes );
+ }, "Property and target types don't match" );
+
+ DALI_TEST_ASSERTION(
+ {
+ // negative duration
+ KeyFrames keyframes = KeyFrames::New();
+ keyframes.Add( 0.5f, Property::Value(Vector3( 1, 2, 3 ) ) );
+ animation.AnimateBetween( Property( actor, Actor::Property::POSITION ), keyframes, TimePeriod(-1) );
+ }, "Duration must be >=0" );
+
+ END_TEST;
+}
+
+namespace // Purposefully left this in the middle as the values in this namespace are only used for the subsequent two test cases
+{
+enum TestFunction
+{
+ STOP,
+ CLEAR
+};
+
+void CheckPropertyValuesWhenCallingAnimationMethod( TestFunction functionToTest, const char * testName )
+{
+ tet_printf( "Testing %s\n", testName );
+
+ // When an Animation::Stop() or Animation::Clear() is called, the event-side property needs to be updated appropriately
+ // This test checks that that is being done
+
+ const float durationSeconds( 1.0f );
+ unsigned int halfAnimationDuration( static_cast< unsigned int >( durationSeconds * 1000.0f * 0.5f ) );
+ const Vector3 originalPosition( Vector3::ZERO );
+ const Vector3 targetPosition( 10.0f, 10.0f, 10.0f );
+ const Vector3 halfWayToTarget( targetPosition * 0.5f );
+
+ struct ExpectedValue
+ {
+ Animation::EndAction endAction;
+ Vector3 expectedGetPropertyValue;
+ };
+
+ ExpectedValue expectedValueTable[] =
+ {
+ { Animation::Bake, halfWayToTarget }, // When baking, the current value is the final value.
+ { Animation::BakeFinal, targetPosition }, // When BakeFinal, we should jump to the final value when clearing or stopping.
+ { Animation::Discard, originalPosition }, // When discarding, we should jump back to the original value when clearing or stopping.
+ };
+ const auto expectedValueTableCount = sizeof( expectedValueTable ) / sizeof( ExpectedValue );
+
+ for( auto i = 0u; i < expectedValueTableCount; ++i )
+ {
+ TestApplication application;
+
+ Actor actor = Actor::New();
+ Stage::GetCurrent().Add(actor);
+
+ // Build the animation
+ Animation animation = Animation::New( durationSeconds );
+ animation.SetEndAction( expectedValueTable[ i ].endAction );
+ animation.AnimateTo( Property( actor, Actor::Property::POSITION ), targetPosition, AlphaFunction::LINEAR );
+
+ // Start the animation
+ animation.Play();
+
+ application.SendNotification();
+ application.Render( halfAnimationDuration );
+
+ // Stop or Clear the animation early, both have the same effect
+ if( functionToTest == TestFunction::STOP )
+ {
+ animation.Stop();
+ }
+ else
+ {
+ animation.Clear();
+ }
+
+ // The event side property should be set the expected value immediately, the update side property will still only be halfway as we haven't run an update yet
+ DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::POSITION ).Get< Vector3 >(), expectedValueTable[ i ].expectedGetPropertyValue, VECTOR3_EPSILON, TEST_LOCATION );
+ DALI_TEST_EQUALS( actor.GetCurrentProperty( Actor::Property::POSITION ).Get< Vector3 >(), halfWayToTarget, VECTOR3_EPSILON, TEST_LOCATION );
+
+ // After one frame, both values should match regardless of the End Action
+ application.SendNotification();
+ application.Render();
+
+ DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::POSITION ).Get< Vector3 >(), expectedValueTable[ i ].expectedGetPropertyValue, VECTOR3_EPSILON, TEST_LOCATION );
+ DALI_TEST_EQUALS( actor.GetCurrentProperty( Actor::Property::POSITION ).Get< Vector3 >(), expectedValueTable[ i ].expectedGetPropertyValue, VECTOR3_EPSILON, TEST_LOCATION );
+ }
+}
+} // unnamed namespace
+
+int UtcDaliAnimationStopPropertyValue(void)
+{
+ CheckPropertyValuesWhenCallingAnimationMethod( TestFunction::STOP, "UtcDaliAnimationStopPropertyValue" );
+ END_TEST;
+}
+
+int UtcDaliAnimationClearPropertyValue(void)
+{
+ CheckPropertyValuesWhenCallingAnimationMethod( TestFunction::CLEAR, "UtcDaliAnimationStopPropertyValue" );
+ END_TEST;
+}
+
+int UtcDaliAnimationPausePropertyValue(void)
+{
+ const float durationSeconds( 1.0f );
+ unsigned int halfAnimationDuration( static_cast< unsigned int >( durationSeconds * 1000.0f * 0.5f ) );
+ const Vector3 originalPosition( Vector3::ZERO );
+ const Vector3 targetPosition( 10.0f, 10.0f, 10.0f );
+ const Vector3 halfWayToTarget( targetPosition * 0.5f );
+
+ Animation::EndAction endActions[] =
+ {
+ Animation::Bake,
+ Animation::BakeFinal,
+ Animation::Discard,
+ };
+ const auto endActionCount = sizeof( endActions ) / sizeof( endActions[0] );
+
+ // For all end actions, when pausing, we stay at the current value
+ for( auto i = 0u; i < endActionCount; ++i )
+ {
+ TestApplication application;
+
+ Actor actor = Actor::New();
+ Stage::GetCurrent().Add(actor);
+
+ // Build the animation
+ Animation animation = Animation::New( durationSeconds );
+ animation.SetEndAction( endActions[ i ] );
+ animation.AnimateTo( Property( actor, Actor::Property::POSITION ), targetPosition, AlphaFunction::LINEAR );
+
+ // Start the animation
+ animation.Play();
+
+ application.SendNotification();
+ application.Render( halfAnimationDuration );
+
+ // Puase the animation early
+ animation.Pause();
+
+ // The event side property should be set the current value immediately, the update side property will still only be halfway
+ DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::POSITION ).Get< Vector3 >(), halfWayToTarget, VECTOR3_EPSILON, TEST_LOCATION );
+ DALI_TEST_EQUALS( actor.GetCurrentProperty( Actor::Property::POSITION ).Get< Vector3 >(), halfWayToTarget, VECTOR3_EPSILON, TEST_LOCATION );
+
+ // After one frame, both values should match regardless of the End Action
+ application.SendNotification();
+ application.Render();
+
+ DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::POSITION ).Get< Vector3 >(), halfWayToTarget, VECTOR3_EPSILON, TEST_LOCATION );
+ DALI_TEST_EQUALS( actor.GetCurrentProperty( Actor::Property::POSITION ).Get< Vector3 >(), halfWayToTarget, VECTOR3_EPSILON, TEST_LOCATION );
+ }
+
+ END_TEST;
+}
+
+int UtcDaliAnimationPlayFromWithLoopCount(void)
+{
+ TestApplication application;
+
+ auto actor = Actor::New();
+ Stage::GetCurrent().Add( actor );
+
+ auto animation = Animation::New( 1.0f );
+ animation.AnimateTo( Property( actor, Actor::Property::POSITION_X ), 100.0f );
+ animation.SetLoopCount( 2 );
+ animation.Play();
+
+ application.SendNotification();
+ application.Render( 1001 );
+
+ // One loop completed
+
+ application.Render( 2005 );
+ application.SendNotification();
+
+ // 2 loops should have completed
+ DALI_TEST_EQUALS( animation.GetCurrentLoop(), 2u, TEST_LOCATION );
+
+ // Another render needs to occur after all the loops end
+ application.SendNotification();
+ application.Render( 1000 );
+
+ // Stop the animation and use PlayFrom, previously we got an Assert here
+ animation.Stop();
+ animation.PlayFrom( 0.5f );
+
+ application.SendNotification();
+ application.Render( 1000 );
+
+ DALI_TEST_EQUALS( animation.GetState(), Animation::PLAYING, TEST_LOCATION );
+
+ END_TEST;
+}
+
+int UtcDaliAnimationCombineToAndByWithStop(void)
+{
+ tet_infoline( "Ensure the Y Position is not modified when animating the X position using AnimateTo and AnimateBy");
+
+ TestApplication application;
+
+ auto actor = Actor::New();
+ actor.SetPosition( 100.0f, 100.0f );
+ Stage::GetCurrent().Add( actor );
+
+ auto animation = Animation::New( 1.0f );
+ const float origY = actor.GetProperty( Actor::Property::POSITION_Y ).Get< float >();
+ animation.AnimateTo( Property( actor, Actor::Property::POSITION ), Vector3( 150.0f, origY, 0.0f ), TimePeriod( 1.0f ) );
+ animation.AnimateBy( Property( actor, Actor::Property::POSITION ), Vector3( -30.0f, 0.0f, 0.0f ), TimePeriod( 1.0f, 1.0f ) );
+ animation.Play();
+
+ application.SendNotification();
+ application.Render( 500 );
+
+ application.SendNotification();
+ application.Render( 500 );
+
+ application.SendNotification();
+ application.Render( 500 );
+
+ // Stop and clear the animation using the current values
+ animation.Stop();
+ animation.Clear();
+
+ // Check the y position, it should be the same as before
+ DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::POSITION_Y).Get< float >(), origY, TEST_LOCATION );
+
+ END_TEST;
+}
+
+int UtcDaliAnimationCountAndGetAnimationAt(void)
+{
+ tet_infoline( "UtcDaliAnimationCountAndGetAnimationAt");
+
+ TestApplication application;
+
+ auto actor = Actor::New();
+ actor.SetPosition( 100.0f, 100.0f );
+ Stage::GetCurrent().Add( actor );
+
+ auto animation = Animation::New( 1.0f );
+ const float origY = actor.GetProperty( Actor::Property::POSITION_Y ).Get< float >();
+ animation.AnimateTo( Property( actor, Actor::Property::POSITION ), Vector3( 150.0f, origY, 0.0f ), TimePeriod( 1.0f ) );
+ animation.Play();
+
+ application.SendNotification();
+ application.Render( 500 );
+
+ uint32_t animationCount = Dali::DevelAnimation::GetAnimationCount();
+ DALI_TEST_EQUALS( animationCount, 1, TEST_LOCATION );
+
+ DALI_TEST_CHECK( !Dali::DevelAnimation::GetAnimationAt( 5 ) );
+
+ Dali::Animation animationReturned = Dali::DevelAnimation::GetAnimationAt( 0 );
+ DALI_TEST_EQUALS( animationReturned.GetState(), Dali::Animation::State::PLAYING, TEST_LOCATION );
+
+ DALI_TEST_EQUALS( animation.GetDuration(), animationReturned.GetDuration(), TEST_LOCATION );
+ DALI_TEST_EQUALS( animation.GetLoopCount(), animationReturned.GetLoopCount(), TEST_LOCATION );
+ DALI_TEST_EQUALS( animation.IsLooping(), animationReturned.IsLooping(), TEST_LOCATION );
+ DALI_TEST_EQUALS( animation.GetEndAction(), animationReturned.GetEndAction(), TEST_LOCATION );
+ DALI_TEST_EQUALS( animation.GetState(), animationReturned.GetState(), TEST_LOCATION );
+
+ // Stop and clear the animation using the current values
+ animation.Stop();
+ animation.Clear();
+
+ END_TEST;
+}