END_TEST;
}
-
Note that **there must be no extra whitespace in the method signature** (i.e., it must violate our coding convention and follow __exactly__ this pattern: `int UtcDaliMyTestcaseName(void)`), as it's parsed by an awk script to auto-generate the testcase arrays in the main header file.
You can contine to use the TET api, e.g. `tet_infoline`, `tet_result` and our test check methods `DALI_TEST_CHECK`, `DALI_TEST_EQUALS`, etc.
If you are adding new test files, then you need to add the filename to the SET(TC_SOURCES...
section of CMakeLists.txt (this is also parsed by an awk script prior to building)
+Good Practices
+--------------
+Use DALI_TEST_EQUALS to test actual value against expected value, like this:
+
+ DALI_TEST_EQUALS( actor.GetProperty< float >( Actor::Property::COLOR_ALPHA ), 0.9f, TEST_LOCATION );
+
+This will speed up debugging in case the test some day fails. There is also a variant to test that value is greater than expected:
+
+ DALI_TEST_GREATER( textureBindIndex[1], textureBindIndex[2], TEST_LOCATION );
+
+When doing negative tests where your code uses DALI_ASSERT_ALWAYS, use the DALI_TEST_ASSERTION macro, like below:
+
+ DALI_TEST_ASSERTION(
+ {
+ animation.AnimateTo( Property( actor, Actor::Property::PARENT_ORIGIN ), targetParentOrigin );
+ }, "IsPropertyAnimatable( index )" );
+
+This macro will catch the DALi Exception and check that the correct assert message was included. It will also fail the test in case the assert did not occur. It also reduces the amount of false positive error logging whilst the is being thrown making it easier to see the real errors.
+
+Note, DALI_ASSERT_DEBUG cannot be tested as tests execute against release version of the code.
+
+Use additional scope to control the life of stack allocated objects, such as DALi handles
+
+ // try reparenting an orphaned child
+ {
+ Actor temporaryParent = Actor::New();
+ temporaryParent.Add( child );
+ DALI_TEST_EQUALS( parent2.GetChildCount(), 0u, TEST_LOCATION );
+ }
+ // temporaryParent has now died, reparent the orphaned child
+ parent2.Add( child );
+ DALI_TEST_EQUALS( parent2.GetChildCount(), 1u, TEST_LOCATION );
+
+Always test the output of your test by making your code fail!!!
+
Debugging
=========
tet_printf("Assertion %s failed at %s\n", e.condition, e.location );
}
+/**
+ * Test that given piece of code triggers the right assertion
+ * Fails the test if the assert didn't occur.
+ * Turns off logging during the execution of the code to avoid excessive false positive log output from the assertions
+ * @param expressions code to execute
+ * @param assertstring the substring expected in the assert
+ */
+#define DALI_TEST_ASSERTION( expressions, assertstring ) \
+try \
+{ \
+ TestApplication::EnableLogging( false ); \
+ expressions; \
+ TestApplication::EnableLogging( true ); \
+ fprintf(stderr, "Test failed in %s, expected assert: '%s' didn't occur\n", __FILELINE__, assertstring ); \
+ tet_result(TET_FAIL); \
+ throw("TET_FAIL"); } \
+catch( Dali::DaliException& e ) \
+{ \
+ DALI_TEST_ASSERT( e, assertstring, TEST_LOCATION ); \
+}
+
// Functor to test whether an Applied signal is emitted
struct ConstraintAppliedCheck
{
namespace Dali
{
+bool TestApplication::mLoggingEnabled = true;
TestApplication::TestApplication( uint32_t surfaceWidth,
uint32_t surfaceHeight,
{
if( start )
{
- fprintf(stderr, "INFO: Trace Start: %s", tag);
+ fprintf(stderr, "INFO: Trace Start: %s\n", tag);
}
else
{
- fprintf(stderr, "INFO: Trace End: %s", tag);
+ fprintf(stderr, "INFO: Trace End: %s\n", tag);
}
}
void TestApplication::LogMessage(Dali::Integration::Log::DebugPriority level, std::string& message)
{
- switch(level)
+ if( mLoggingEnabled )
{
- case Dali::Integration::Log::DebugInfo:
- fprintf(stderr, "INFO: %s", message.c_str());
- break;
- case Dali::Integration::Log::DebugWarning:
- fprintf(stderr, "WARN: %s", message.c_str());
- break;
- case Dali::Integration::Log::DebugError:
- fprintf(stderr, "ERROR: %s", message.c_str());
- break;
- default:
- fprintf(stderr, "DEFAULT: %s", message.c_str());
- break;
+ switch(level)
+ {
+ case Dali::Integration::Log::DebugInfo:
+ fprintf(stderr, "INFO: %s", message.c_str());
+ break;
+ case Dali::Integration::Log::DebugWarning:
+ fprintf(stderr, "WARN: %s", message.c_str());
+ break;
+ case Dali::Integration::Log::DebugError:
+ fprintf(stderr, "ERROR: %s", message.c_str());
+ break;
+ default:
+ fprintf(stderr, "DEFAULT: %s", message.c_str());
+ break;
+ }
}
}
void ResetContext();
bool GetRenderNeedsUpdate();
uint32_t Wait( uint32_t durationToWait );
+ static void EnableLogging( bool enabled )
+ {
+ mLoggingEnabled = enabled;
+ }
private:
void DoUpdate( uint32_t intervalMilliseconds, const char* location=NULL );
struct { uint32_t x; uint32_t y; } mDpi;
uint32_t mLastVSyncTime;
ResourcePolicy::DataRetention mDataRetentionPolicy;
+ static bool mLoggingEnabled;
};
} // Dali
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);
- }
+ }, "IsPropertyAnimatable( index )" );
+
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);
- }
+ }, "IsPropertyAnimatable( index )" );
+
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);
- }
+ }, "IsPropertyAnimatable( index )" );
+
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);
- }
+ }, "IsPropertyAnimatable( index )" );
+
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);
- }
+ }, "IsPropertyAnimatable( index )" );
+
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);
- }
+ }, "IsPropertyAnimatable( index )" );
+
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);
- }
+ }, "IsPropertyAnimatable( index )" );
+
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);
- }
+ }, "IsPropertyAnimatable( index )" );
+
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;
+}
}
catch ( Dali::DaliException& e )
{
- DALI_TEST_ASSERT( e, "Animated value and Property type don't match", TEST_LOCATION );
+ DALI_TEST_ASSERT( e, "Property type is not animatable", TEST_LOCATION );
}
DALI_TEST_EQUALS( "yes", actor.GetProperty( nonAnimStringIndex ).Get<std::string>(), TEST_LOCATION );
const Dali::Animation::Interpolation DEFAULT_INTERPOLATION( Dali::Animation::Linear );
const Dali::AlphaFunction DEFAULT_ALPHA_FUNCTION( Dali::AlphaFunction::DEFAULT );
-} // anon namespace
+/**
+ * Helper to tell if a property is animatable (if we have animators for it)
+ *
+ * @param type type to check
+ * @return true if animatable
+ */
+inline bool IsAnimatable( Property::Type type )
+{
+ bool animatable = false;
+ switch( type )
+ {
+ case Property::BOOLEAN :
+ case Property::FLOAT :
+ case Property::INTEGER :
+ case Property::VECTOR2 :
+ case Property::VECTOR3 :
+ case Property::VECTOR4 :
+ case Property::ROTATION :
+ {
+ animatable = true;
+ break;
+ }
+ case Property::MATRIX : // matrix is allowed as a scene graph property but there's no animators for it
+ case Property::MATRIX3 : // matrix3 is allowed as a scene graph property but there's no animators for it
+ case Property::NONE :
+ case Property::RECTANGLE :
+ case Property::STRING :
+ case Property::ARRAY :
+ case Property::MAP :
+ case Property::EXTENTS :
+ {
+ break;
+ }
+ }
+ return animatable;
+}
+
+/**
+ * Helper to validate animation input values
+ *
+ * @param propertyType type of the property that is being animated
+ * @param destinationType type of the target
+ * @param period time period of the animation
+ */
+void ValidateParameters( Property::Type propertyType, Property::Type destinationType, const TimePeriod& period )
+{
+ // destination value has to be animatable
+ DALI_ASSERT_ALWAYS( IsAnimatable( propertyType ) && "Property type is not animatable" );
+ DALI_ASSERT_ALWAYS( IsAnimatable( destinationType ) && "Target value is not animatable" );
+ DALI_ASSERT_ALWAYS( propertyType == destinationType && "Property and target types don't match" );
+ DALI_ASSERT_ALWAYS( period.durationSeconds >= 0 && "Duration must be >=0" );
+}
+
+} // anonymous namespace
AnimationPtr Animation::New(float durationSeconds)
SetLoopCount( on ? 0 : 1 );
}
-void Animation::SetLoopCount(int count)
+void Animation::SetLoopCount(int32_t count)
{
// Cache for public getters
mLoopCount = count;
SetLoopingMessage( mEventThreadServices, *mAnimation, mLoopCount );
}
-int Animation::GetLoopCount()
+int32_t Animation::GetLoopCount()
{
return mLoopCount;
}
-int Animation::GetCurrentLoop()
+int32_t Animation::GetCurrentLoop()
{
return mCurrentLoop;
}
mPlaylist.OnClear( *this );
}
-void Animation::AnimateBy(Property& target, Property::Value& relativeValue)
+void Animation::AnimateBy( Property& target, Property::Value& relativeValue )
{
- AnimateBy(target, relativeValue, mDefaultAlpha, TimePeriod(mDurationSeconds));
+ AnimateBy( target, relativeValue, mDefaultAlpha, TimePeriod(mDurationSeconds) );
}
-void Animation::AnimateBy(Property& target, Property::Value& relativeValue, AlphaFunction alpha)
+void Animation::AnimateBy( Property& target, Property::Value& relativeValue, AlphaFunction alpha )
{
- AnimateBy(target, relativeValue, alpha, TimePeriod(mDurationSeconds));
+ AnimateBy( target, relativeValue, alpha, TimePeriod(mDurationSeconds) );
}
-void Animation::AnimateBy(Property& target, Property::Value& relativeValue, TimePeriod period)
+void Animation::AnimateBy( Property& target, Property::Value& relativeValue, TimePeriod period )
{
- AnimateBy(target, relativeValue, mDefaultAlpha, period);
+ AnimateBy( target, relativeValue, mDefaultAlpha, period );
}
-void Animation::AnimateBy(Property& target, Property::Value& relativeValue, AlphaFunction alpha, TimePeriod period)
+void Animation::AnimateBy( Property& target, Property::Value& relativeValue, AlphaFunction alpha, TimePeriod period )
{
Object& object = GetImplementation(target.object);
- const Property::Type targetType = object.GetPropertyType(target.propertyIndex);
+ const Property::Type propertyType = object.GetPropertyType( target.propertyIndex );
const Property::Type destinationType = relativeValue.GetType();
- if ( object.GetPropertyComponentIndex( target.propertyIndex ) != Property::INVALID_COMPONENT_INDEX )
- {
- DALI_ASSERT_ALWAYS(Property::FLOAT == destinationType && "Animated value and Property type don't match");
- }
- else
- {
- DALI_ASSERT_ALWAYS(targetType == destinationType && "Animated value and Property type don't match");
- }
+ // validate animation parameters, if component index is set then use float as checked type
+ ValidateParameters( (target.componentIndex == Property::INVALID_COMPONENT_INDEX) ? propertyType : Property::FLOAT,
+ destinationType, period );
ExtendDuration(period);
connectorPair.animatorType = Animation::BY;
mConnectorTargetValues.push_back( connectorPair );
- switch ( targetType )
+ // using destination type so component animation gets correct type
+ switch ( destinationType )
{
case Property::BOOLEAN:
{
case Property::INTEGER:
{
- AddAnimatorConnector( AnimatorConnector<int>::New( object,
- target.propertyIndex,
- target.componentIndex,
- new AnimateByInteger(relativeValue.Get<int>()),
- alpha,
- period ) );
+ AddAnimatorConnector( AnimatorConnector<int32_t>::New( object,
+ target.propertyIndex,
+ target.componentIndex,
+ new AnimateByInteger(relativeValue.Get<int32_t>()),
+ alpha,
+ period ) );
break;
}
}
}
-void Animation::AnimateTo(Property& target, Property::Value& destinationValue)
-{
- AnimateTo(target, destinationValue, mDefaultAlpha, TimePeriod(mDurationSeconds));
-}
-
-void Animation::AnimateTo(Property& target, Property::Value& destinationValue, AlphaFunction alpha)
+void Animation::AnimateTo( Property& target, Property::Value& destinationValue )
{
- AnimateTo(target, destinationValue, alpha, TimePeriod(mDurationSeconds));
+ AnimateTo( target, destinationValue, mDefaultAlpha, TimePeriod(mDurationSeconds) );
}
-void Animation::AnimateTo(Property& target, Property::Value& destinationValue, TimePeriod period)
+void Animation::AnimateTo( Property& target, Property::Value& destinationValue, AlphaFunction alpha )
{
- AnimateTo(target, destinationValue, mDefaultAlpha, period);
+ AnimateTo( target, destinationValue, alpha, TimePeriod(mDurationSeconds));
}
-void Animation::AnimateTo(Property& target, Property::Value& destinationValue, AlphaFunction alpha, TimePeriod period)
+void Animation::AnimateTo( Property& target, Property::Value& destinationValue, TimePeriod period )
{
- Object& object = GetImplementation(target.object);
-
- AnimateTo( object, target.propertyIndex, target.componentIndex, destinationValue, alpha, period );
+ AnimateTo( target, destinationValue, mDefaultAlpha, period );
}
-void Animation::AnimateTo(Object& targetObject, Property::Index targetPropertyIndex, int componentIndex, Property::Value& destinationValue, AlphaFunction alpha, TimePeriod period)
+void Animation::AnimateTo( Property& target, Property::Value& destinationValue, AlphaFunction alpha, TimePeriod period )
{
- Property::Type targetType = targetObject.GetPropertyType(targetPropertyIndex);
- if( componentIndex != Property::INVALID_COMPONENT_INDEX )
- {
- if( ( targetType == Property::VECTOR2 ) ||
- ( targetType == Property::VECTOR3 ) ||
- ( targetType == Property::VECTOR4 ) )
- {
- targetType = Property::FLOAT;
- }
- }
+ Object& object = GetImplementation( target.object );
+ const Property::Type propertyType = object.GetPropertyType( target.propertyIndex );
const Property::Type destinationType = destinationValue.GetType();
- DALI_ASSERT_ALWAYS( targetType == destinationType && "Animated value and Property type don't match" );
+
+ // validate animation parameters, if component index is set then use float as checked type
+ ValidateParameters( (target.componentIndex == Property::INVALID_COMPONENT_INDEX) ? propertyType : Property::FLOAT,
+ destinationType, period );
ExtendDuration( period );
connectorPair.animatorType = Animation::TO;
mConnectorTargetValues.push_back( connectorPair );
+ // using destination type so component animation gets correct type
switch ( destinationType )
{
case Property::BOOLEAN:
{
- AddAnimatorConnector( AnimatorConnector<bool>::New( targetObject,
- targetPropertyIndex,
- componentIndex,
+ AddAnimatorConnector( AnimatorConnector<bool>::New( object,
+ target.propertyIndex,
+ target.componentIndex,
new AnimateToBoolean( destinationValue.Get<bool>() ),
alpha,
period ) );
case Property::INTEGER:
{
- AddAnimatorConnector( AnimatorConnector<int>::New( targetObject,
- targetPropertyIndex,
- componentIndex,
- new AnimateToInteger( destinationValue.Get<int>() ),
- alpha,
- period ) );
+ AddAnimatorConnector( AnimatorConnector<int32_t>::New( object,
+ target.propertyIndex,
+ target.componentIndex,
+ new AnimateToInteger( destinationValue.Get<int32_t>() ),
+ alpha,
+ period ) );
break;
}
case Property::FLOAT:
{
- AddAnimatorConnector( AnimatorConnector<float>::New( targetObject,
- targetPropertyIndex,
- componentIndex,
+ AddAnimatorConnector( AnimatorConnector<float>::New( object,
+ target.propertyIndex,
+ target.componentIndex,
new AnimateToFloat( destinationValue.Get<float>() ),
alpha,
period ) );
case Property::VECTOR2:
{
- AddAnimatorConnector( AnimatorConnector<Vector2>::New( targetObject,
- targetPropertyIndex,
- componentIndex,
+ AddAnimatorConnector( AnimatorConnector<Vector2>::New( object,
+ target.propertyIndex,
+ target.componentIndex,
new AnimateToVector2( destinationValue.Get<Vector2>() ),
alpha,
period ) );
case Property::VECTOR3:
{
- AddAnimatorConnector( AnimatorConnector<Vector3>::New( targetObject,
- targetPropertyIndex,
- componentIndex,
+ AddAnimatorConnector( AnimatorConnector<Vector3>::New( object,
+ target.propertyIndex,
+ target.componentIndex,
new AnimateToVector3( destinationValue.Get<Vector3>() ),
alpha,
period ) );
case Property::VECTOR4:
{
- AddAnimatorConnector( AnimatorConnector<Vector4>::New( targetObject,
- targetPropertyIndex,
- componentIndex,
+ AddAnimatorConnector( AnimatorConnector<Vector4>::New( object,
+ target.propertyIndex,
+ target.componentIndex,
new AnimateToVector4( destinationValue.Get<Vector4>() ),
alpha,
period ) );
case Property::ROTATION:
{
- AddAnimatorConnector( AnimatorConnector<Quaternion>::New( targetObject,
- targetPropertyIndex,
- componentIndex,
+ AddAnimatorConnector( AnimatorConnector<Quaternion>::New( object,
+ target.propertyIndex,
+ target.componentIndex,
new RotateToQuaternion( destinationValue.Get<Quaternion>() ),
alpha,
period ) );
}
}
-void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames)
+void Animation::AnimateBetween( Property target, const KeyFrames& keyFrames )
{
- AnimateBetween(target, keyFrames, mDefaultAlpha, TimePeriod(mDurationSeconds), DEFAULT_INTERPOLATION );
+ AnimateBetween( target, keyFrames, mDefaultAlpha, TimePeriod(mDurationSeconds), DEFAULT_INTERPOLATION );
}
-void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, Interpolation interpolation )
+void Animation::AnimateBetween( Property target, const KeyFrames& keyFrames, Interpolation interpolation )
{
- AnimateBetween(target, keyFrames, mDefaultAlpha, TimePeriod(mDurationSeconds), interpolation );
+ AnimateBetween( target, keyFrames, mDefaultAlpha, TimePeriod(mDurationSeconds), interpolation );
}
-void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, TimePeriod period)
+void Animation::AnimateBetween( Property target, const KeyFrames& keyFrames, TimePeriod period )
{
- AnimateBetween(target, keyFrames, mDefaultAlpha, period, DEFAULT_INTERPOLATION);
+ AnimateBetween( target, keyFrames, mDefaultAlpha, period, DEFAULT_INTERPOLATION );
}
-void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, TimePeriod period, Interpolation interpolation)
+void Animation::AnimateBetween( Property target, const KeyFrames& keyFrames, TimePeriod period, Interpolation interpolation )
{
- AnimateBetween(target, keyFrames, mDefaultAlpha, period, interpolation);
+ AnimateBetween( target, keyFrames, mDefaultAlpha, period, interpolation );
}
-void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, AlphaFunction alpha)
+void Animation::AnimateBetween( Property target, const KeyFrames& keyFrames, AlphaFunction alpha )
{
- AnimateBetween(target, keyFrames, alpha, TimePeriod(mDurationSeconds), DEFAULT_INTERPOLATION);
+ AnimateBetween( target, keyFrames, alpha, TimePeriod(mDurationSeconds), DEFAULT_INTERPOLATION );
}
-void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, AlphaFunction alpha, Interpolation interpolation)
+void Animation::AnimateBetween( Property target, const KeyFrames& keyFrames, AlphaFunction alpha, Interpolation interpolation )
{
- AnimateBetween(target, keyFrames, alpha, TimePeriod(mDurationSeconds), interpolation);
+ AnimateBetween( target, keyFrames, alpha, TimePeriod(mDurationSeconds), interpolation );
}
-void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, AlphaFunction alpha, TimePeriod period)
+void Animation::AnimateBetween( Property target, const KeyFrames& keyFrames, AlphaFunction alpha, TimePeriod period )
{
- AnimateBetween(target, keyFrames, alpha, period, DEFAULT_INTERPOLATION);
+ AnimateBetween( target, keyFrames, alpha, period, DEFAULT_INTERPOLATION );
}
-void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, AlphaFunction alpha, TimePeriod period, Interpolation interpolation)
+void Animation::AnimateBetween( Property target, const KeyFrames& keyFrames, AlphaFunction alpha, TimePeriod period, Interpolation interpolation )
{
Object& object = GetImplementation( target.object );
+ const Property::Type propertyType = object.GetPropertyType( target.propertyIndex );
+ const Property::Type destinationType = keyFrames.GetType();
+
+ // validate animation parameters, if component index is set then use float as checked type
+ ValidateParameters( (target.componentIndex == Property::INVALID_COMPONENT_INDEX) ? propertyType : Property::FLOAT,
+ destinationType, period );
ExtendDuration( period );
connectorPair.animatorType = BETWEEN;
mConnectorTargetValues.push_back( connectorPair );
- switch(keyFrames.GetType())
+ // using destination type so component animation gets correct type
+ switch( destinationType )
{
case Dali::Property::BOOLEAN:
{
const KeyFrameInteger* kf;
GetSpecialization(keyFrames, kf);
KeyFrameIntegerPtr kfCopy = KeyFrameInteger::Clone(*kf);
- AddAnimatorConnector( AnimatorConnector<int>::New( object,
+ AddAnimatorConnector( AnimatorConnector<int32_t>::New( object,
target.propertyIndex,
target.componentIndex,
new KeyFrameIntegerFunctor(kfCopy,interpolation),
bool Animation::HasFinished()
{
bool hasFinished(false);
- const int playedCount(mAnimation->GetPlayedCount());
+ const int32_t playedCount(mAnimation->GetPlayedCount());
// If the play count has been incremented, then another notification is required
mCurrentLoop = mAnimation->GetCurrentLoop();
#define __DALI_INTERNAL_ANIMATION_H__
/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 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.
/**
* @copydoc Dali::Animation::SetLoopCount()
*/
- void SetLoopCount(int count);
+ void SetLoopCount(int32_t count);
/**
* @copydoc Dali::Animation::GetLoopCount()
*/
- int GetLoopCount();
+ int32_t GetLoopCount();
/**
* @copydoc Dali::Animation::GetCurrentLoop()
*/
- int GetCurrentLoop();
+ int32_t GetCurrentLoop();
/**
* @copydoc Dali::Animation::IsLooping()
void AnimateTo(Property& target, Property::Value& destinationValue, AlphaFunction alpha, TimePeriod period);
/**
- * Animate a property to a destination value.
- * @param [in] targetObject The target object to animate.
- * @param [in] targetPropertyIndex The index of the target property.
- * @param [in] componentIndex Index to a sub component of a property, for use with Vector2, Vector3 and Vector4
- * @param [in] destinationValue The destination value.
- * @param [in] alpha The alpha function to apply.
- * @param [in] period The effect will occur during this time period.
- */
- void AnimateTo(Object& targetObject, Property::Index targetPropertyIndex, int componentIndex, Property::Value& destinationValue, AlphaFunction alpha, TimePeriod period);
-
- /**
* @copydoc Dali::Animation::AnimateBetween(Property target, KeyFrames& keyFrames)
*/
void AnimateBetween(Property target, const KeyFrames& keyFrames);
float mDurationSeconds;
float mSpeedFactor;
- int mNotificationCount; ///< Keep track of how many Finished signals have been emitted.
- int mLoopCount;
- int mCurrentLoop;
+ int32_t mNotificationCount; ///< Keep track of how many Finished signals have been emitted.
+ int32_t mLoopCount;
+ int32_t mCurrentLoop;
EndAction mEndAction;
EndAction mDisconnectAction;
AlphaFunction mDefaultAlpha;
/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 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.
}
default:
{
- DALI_ABORT( "Type not animateable" );
+ DALI_ABORT( "Property type is not animatable" );
break;
}
}
case Property::EXTENTS:
case Property::NONE:
{
- DALI_ASSERT_ALWAYS( !"PropertyType is not animatable" );
+ DALI_ASSERT_ALWAYS( !"Property type is not animatable" );
break;
}
}