X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=automated-tests%2Fsrc%2Fdali%2Futc-Dali-CustomActor.cpp;h=ce6d317ef10500465da14fd0577c9b6333062a21;hb=ea0b5e20c8be3552da9203124457b225d2dee766;hp=c32c8e7c024a362e679aabaf4661a3236b1e7404;hpb=d6b6f3dc4093047e8622685d4c4dc9bc257cb449;p=platform%2Fcore%2Fuifw%2Fdali-core.git diff --git a/automated-tests/src/dali/utc-Dali-CustomActor.cpp b/automated-tests/src/dali/utc-Dali-CustomActor.cpp index c32c8e7..ce6d317 100644 --- a/automated-tests/src/dali/utc-Dali-CustomActor.cpp +++ b/automated-tests/src/dali/utc-Dali-CustomActor.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * Copyright (c) 2017 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. @@ -19,793 +19,31 @@ #include #include +#include #include #include #include #include +#include +#include "dali-test-suite-utils/dali-test-suite-utils.h" +#include "test-custom-actor.h" -#include "dali-test-suite-utils/dali-test-suite-utils.h" - -using namespace Dali; - - -void custom_actor_test_startup(void) -{ - test_return_value = TET_UNDEF; -} - -void custom_actor_test_cleanup(void) -{ - test_return_value = TET_PASS; -} - -namespace -{ - -std::vector< std::string > MasterCallStack; -bool gOnRelayout = false; - -} // anon namespace - -// TypeRegistry needs custom actor Implementations to have the same name (namespaces are ignored so we use one here) -namespace Impl -{ - -struct TestCustomActor : public CustomActorImpl -{ - /** - * Constructor - */ - TestCustomActor() - : CustomActorImpl( ActorFlags( REQUIRES_TOUCH_EVENTS | REQUIRES_WHEEL_EVENTS | REQUIRES_HOVER_EVENTS | DISABLE_SIZE_NEGOTIATION ) ), - mDaliProperty( Property::INVALID_INDEX ), - mSizeSet( Vector3::ZERO ), - mTargetSize( Vector3::ZERO ), - mNego( false ), - mDepth(0u) - { - } - - TestCustomActor(bool nego) - : CustomActorImpl( ActorFlags( REQUIRES_TOUCH_EVENTS | REQUIRES_WHEEL_EVENTS | REQUIRES_HOVER_EVENTS ) ), - mDaliProperty( Property::INVALID_INDEX ), - mSizeSet( Vector3::ZERO ), - mTargetSize( Vector3::ZERO ), - mNego( nego ) - { - } - /** - * Destructor - */ - virtual ~TestCustomActor() - { - } - - void Initialize( const char* name = NULL ) - { - mDaliProperty = Self().RegisterProperty( "Dali", std::string("no"), Property::READ_WRITE); - - OnInitialize( name ); - } - - virtual void OnInitialize( const char* name ) {} - - /** - * Resets the call stack - */ - void ResetCallStack() - { - mSizeSet = Vector3(); - mTargetSize = Vector3(); - mMethodsCalled.clear(); - } - - void AddToCallStacks( const char* method ) - { - mMethodsCalled.push_back( method ); - - // Combine Actor name with method string - std::string nameAndMethod( Self().GetName() ); - if ( 0 == nameAndMethod.size() ) - { - nameAndMethod = "Unknown: "; - } - else - { - nameAndMethod += ": "; - } - nameAndMethod += method; - - MasterCallStack.push_back( nameAndMethod ); - } - - // From CustomActorImpl - virtual void OnStageConnection( int depth ) - { - AddToCallStacks("OnStageConnection"); - mDepth = depth; - } - virtual void OnStageDisconnection() - { - AddToCallStacks("OnStageDisconnection"); - } - virtual void OnChildAdd(Actor& child) - { - AddToCallStacks("OnChildAdd"); - } - virtual void OnChildRemove(Actor& child) - { - AddToCallStacks("OnChildRemove"); - } - virtual void OnPropertySet( Property::Index index, Property::Value propertyValue ) - { - AddToCallStacks("OnPropertySet"); - } - virtual void OnSizeSet(const Vector3& targetSize) - { - mSizeSet = targetSize; - AddToCallStacks("OnSizeSet"); - } - virtual void OnSizeAnimation(Animation& animation, const Vector3& targetSize) - { - mTargetSize = targetSize; - AddToCallStacks("OnSizeAnimation"); - } - virtual bool OnTouchEvent(const TouchEvent& event) - { - AddToCallStacks("OnTouchEvent"); - return true; - } - virtual bool OnHoverEvent(const HoverEvent& event) - { - AddToCallStacks("OnHoverEvent"); - return true; - } - virtual bool OnWheelEvent(const WheelEvent& event) - { - AddToCallStacks("OnWheelEvent"); - return true; - } - virtual bool OnKeyEvent(const KeyEvent& event) - { - AddToCallStacks("OnKeyEvent"); - return true; - } - virtual void OnKeyInputFocusGained() - { - AddToCallStacks("OnKeyInputFocusGained"); - } - virtual void OnKeyInputFocusLost() - { - AddToCallStacks("OnKeyInputFocusLost"); - } - virtual Vector3 GetNaturalSize() - { - return Vector3( 0.0f, 0.0f, 0.0f ); - } - - virtual float GetHeightForWidth( float width ) - { - return 0.0f; - } - - virtual float GetWidthForHeight( float height ) - { - return 0.0f; - } - - virtual void OnRelayout( const Vector2& size, RelayoutContainer& container ) - { - gOnRelayout = true; - } - - virtual void OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension ) - { - } - - virtual void OnCalculateRelayoutSize( Dimension::Type dimension ) - { - } - - virtual float CalculateChildSize( const Dali::Actor& child, Dimension::Type dimension ) - { - return 0.0f; - } - - virtual void OnLayoutNegotiated( float size, Dimension::Type dimension ) - { - } - - virtual bool RelayoutDependentOnChildren( Dimension::Type dimension = Dimension::ALL_DIMENSIONS ) - { - return false; - } - - void SetDaliProperty(std::string s) - { - Self().SetProperty(mDaliProperty, s); - } - void TestRelayoutRequest() - { - RelayoutRequest(); - } - - float TestGetHeightForWidthBase( float width ) - { - return GetHeightForWidthBase( width ); - } - - float TestGetWidthForHeightBase( float height ) - { - return GetWidthForHeightBase( height ); - } - - float TestCalculateChildSizeBase( const Dali::Actor& child, Dimension::Type dimension ) - { - return CalculateChildSizeBase( child, dimension ); - } - - bool TestRelayoutDependentOnChildrenBase( Dimension::Type dimension ) - { - return RelayoutDependentOnChildrenBase( dimension ); - } - - Property::Index mDaliProperty; - std::vector< std::string > mMethodsCalled; - Vector3 mSizeSet; - Vector3 mTargetSize; - bool mNego; - unsigned int mDepth; -}; - -/** - * Variant which adds a new child during OnStageConnection - */ -struct TestCustomActorVariant1 : public TestCustomActor -{ - /** - * Constructor - */ - TestCustomActorVariant1( Actor childToAdd ) - : mChildToAdd( childToAdd ) - { - } - - // From CustomActorImpl - virtual void OnStageConnection( int depth ) - { - // Chain up first - TestCustomActor::OnStageConnection( depth ); - - // Add the child - Self().Add( mChildToAdd ); - } - - Actor mChildToAdd; -}; - -/** - * Variant which removes children during OnStageConnection - */ -struct TestCustomActorVariant2 : public TestCustomActor -{ - /** - * Constructor - */ - TestCustomActorVariant2() - { - } - - // From CustomActorImpl - virtual void OnStageConnection( int depth ) - { - // Chain up first - TestCustomActor::OnStageConnection( depth ); - - // Remove all the children - for( unsigned int i=0, num=Self().GetChildCount(); iInitialize(); - - return custom; - } - - static TestCustomActor NewNegoSize() - { - Impl::TestCustomActor* impl = new Impl::TestCustomActor( true ); - TestCustomActor custom( *impl ); // takes ownership - custom.SetName( "SizeNegotiationActor" ); - - impl->Initialize(); - - return custom; - } - - static TestCustomActor NewVariant1( Actor childToAdd ) - { - Impl::TestCustomActor* impl = new Impl::TestCustomActorVariant1( childToAdd ); - TestCustomActor custom( *impl ); // takes ownership - - impl->Initialize(); - - return custom; - } - - static TestCustomActor NewVariant2() - { - Impl::TestCustomActor* impl = new Impl::TestCustomActorVariant2(); - TestCustomActor custom( *impl ); // takes ownership - - impl->Initialize(); - - return custom; - } - - static TestCustomActor NewVariant3( Actor childToAdd ) - { - Impl::TestCustomActor* impl = new Impl::TestCustomActorVariant3( childToAdd ); - TestCustomActor custom( *impl ); // takes ownership - - impl->Initialize(); - - return custom; - } - - static TestCustomActor NewVariant4() - { - Impl::TestCustomActor* impl = new Impl::TestCustomActorVariant4(); - TestCustomActor custom( *impl ); // takes ownership - - impl->Initialize(); - - return custom; - } - - static TestCustomActor NewVariant5() - { - Impl::TestCustomActor* impl = new Impl::TestCustomActorVariant5(); - TestCustomActor custom( *impl ); // takes ownership - - impl->Initialize(); - - return custom; - } - - static TestCustomActor NewVariant6() - { - Impl::TestCustomActor* impl = new Impl::TestCustomActorVariant6(); - TestCustomActor custom( *impl ); // takes ownership - - impl->Initialize(); - - return custom; - } - - static TestCustomActor NewVariant7( const char* name ) - { - Impl::TestCustomActor* impl = new Impl::TestCustomActorVariant7(); - TestCustomActor custom( *impl ); // takes ownership - - impl->Initialize( name ); - - return custom; - } - - static TestCustomActor NewVariant8( Actor rival ) - { - Impl::TestCustomActor* impl = new Impl::TestCustomActorVariant8( rival ); - TestCustomActor custom( *impl ); // takes ownership - - impl->Initialize(); - - return custom; - } - - virtual ~TestCustomActor() - { - } - - Impl::TestCustomActor& GetImpl() - { - return static_cast(GetImplementation()); - } - - std::vector< std::string >& GetMethodsCalled() - { - return GetImpl().mMethodsCalled; - } - - void ResetCallStack() - { - GetImpl().ResetCallStack(); - } - - void SetDaliProperty(std::string s) - { - GetImpl().SetDaliProperty(s); - } - - Vector3 GetSize() - { - return GetImpl().mSizeSet; - } - - Vector3 GetTargetSize() - { - return GetImpl().mTargetSize; - } - - virtual Vector3 GetNaturalSize() - { - return Vector3( 0.0f, 0.0f, 0.0f ); - } - - virtual float GetHeightForWidth( float width ) - { - return 0.0f; - } - - virtual float GetWidthForHeight( float height ) - { - return 0.0f; - } - - virtual void OnRelayout( const Vector2& size, RelayoutContainer& container ) - { - } - - virtual void OnLayoutNegotiated( float size, Dimension::Type dimension ) - { - } - - virtual void OnCalculateRelayoutSize( Dimension::Type dimension ) - { - } - - void TestRelayoutRequest() - { - GetImpl().TestRelayoutRequest(); - } - - float TestGetHeightForWidthBase( float width ) - { - return GetImpl().TestGetHeightForWidthBase( width ); - } - - float TestGetWidthForHeightBase( float height ) - { - return GetImpl().TestGetWidthForHeightBase( height ); - } - - float TestCalculateChildSizeBase( const Dali::Actor& child, Dimension::Type dimension ) - { - return GetImpl().TestCalculateChildSizeBase( child, dimension ); - } - - bool TestRelayoutDependentOnChildrenBase( Dimension::Type dimension ) - { - return GetImpl().TestRelayoutDependentOnChildrenBase( dimension ); - } - - unsigned int GetDepth() - { - return GetImpl().mDepth; - } -private: - - TestCustomActor( Impl::TestCustomActor& impl ) : CustomActor( impl ) - { - } -}; - +using namespace Dali; -using namespace Dali; +void custom_actor_test_startup(void) +{ + test_return_value = TET_UNDEF; +} -BaseHandle CreateActor() +void custom_actor_test_cleanup(void) { - return TestCustomActor::New(); + test_return_value = TET_PASS; } -Dali::TypeRegistration mType( typeid(TestCustomActor), typeid(Dali::CustomActor), CreateActor ); -} // anon namespace + +using namespace Dali; int UtcDaliCustomActorDestructor(void) @@ -822,7 +60,7 @@ int UtcDaliCustomActorDestructor(void) int UtcDaliCustomActorImplDestructor(void) { TestApplication application; - CustomActorImpl* actor = new Impl::TestCustomActor(); + CustomActorImpl* actor = new Test::Impl::TestCustomActor(); CustomActor customActor( *actor ); // Will automatically unref at the end of this function DALI_TEST_CHECK( true ); @@ -835,7 +73,7 @@ int UtcDaliCustomActorDownCast(void) TestApplication application; tet_infoline("Testing Dali::CustomActor::DownCast()"); - TestCustomActor custom = TestCustomActor::New(); + Test::TestCustomActor custom = Test::TestCustomActor::New(); Actor anActor = Actor::New(); anActor.Add( custom ); @@ -880,7 +118,7 @@ int UtcDaliCustomActorOnStageConnectionDisconnection(void) TestApplication application; tet_infoline("Testing Dali::CustomActor::OnStageConnection() & OnStageDisconnection"); - TestCustomActor custom = TestCustomActor::New(); + Test::TestCustomActor custom = Test::TestCustomActor::New(); DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION ); // add the custom actor to stage @@ -920,26 +158,26 @@ int UtcDaliCustomActorOnStageConnectionOrder(void) * OnStageConnection should be received for A, B, D, E, C, and finally F */ - TestCustomActor actorA = TestCustomActor::New(); + Test::TestCustomActor actorA = Test::TestCustomActor::New(); actorA.SetName( "ActorA" ); - TestCustomActor actorB = TestCustomActor::New(); + Test::TestCustomActor actorB = Test::TestCustomActor::New(); actorB.SetName( "ActorB" ); actorA.Add( actorB ); - TestCustomActor actorC = TestCustomActor::New(); + Test::TestCustomActor actorC = Test::TestCustomActor::New(); actorC.SetName( "ActorC" ); actorA.Add( actorC ); - TestCustomActor actorD = TestCustomActor::New(); + Test::TestCustomActor actorD = Test::TestCustomActor::New(); actorD.SetName( "ActorD" ); actorB.Add( actorD ); - TestCustomActor actorE = TestCustomActor::New(); + Test::TestCustomActor actorE = Test::TestCustomActor::New(); actorE.SetName( "ActorE" ); actorB.Add( actorE ); - TestCustomActor actorF = TestCustomActor::New(); + Test::TestCustomActor actorF = Test::TestCustomActor::New(); actorF.SetName( "ActorF" ); actorC.Add( actorF ); @@ -1012,27 +250,27 @@ int UtcDaliCustomActorOnStageDisconnectionOrder(void) * OnStageDisconnection should be received for D, E, B, F, C, and finally A. */ - TestCustomActor actorA = TestCustomActor::New(); + Test::TestCustomActor actorA = Test::TestCustomActor::New(); actorA.SetName( "ActorA" ); stage.Add( actorA ); - TestCustomActor actorB = TestCustomActor::New(); + Test::TestCustomActor actorB = Test::TestCustomActor::New(); actorB.SetName( "ActorB" ); actorA.Add( actorB ); - TestCustomActor actorC = TestCustomActor::New(); + Test::TestCustomActor actorC = Test::TestCustomActor::New(); actorC.SetName( "ActorC" ); actorA.Add( actorC ); - TestCustomActor actorD = TestCustomActor::New(); + Test::TestCustomActor actorD = Test::TestCustomActor::New(); actorD.SetName( "ActorD" ); actorB.Add( actorD ); - TestCustomActor actorE = TestCustomActor::New(); + Test::TestCustomActor actorE = Test::TestCustomActor::New(); actorE.SetName( "ActorE" ); actorB.Add( actorE ); - TestCustomActor actorF = TestCustomActor::New(); + Test::TestCustomActor actorF = Test::TestCustomActor::New(); actorF.SetName( "ActorF" ); actorC.Add( actorF ); @@ -1103,10 +341,10 @@ int UtcDaliCustomActorAddDuringOnStageConnection(void) * The actorB is provided as the child */ - TestCustomActor actorB = TestCustomActor::New(); + Test::TestCustomActor actorB = Test::TestCustomActor::New(); actorB.SetName( "ActorB" ); - TestCustomActor actorA = TestCustomActor::NewVariant1( actorB ); + Test::TestCustomActor actorA = Test::TestCustomActor::NewVariant1( actorB ); actorA.SetName( "ActorA" ); stage.Add( actorA ); @@ -1153,14 +391,14 @@ int UtcDaliCustomActorRemoveDuringOnStageConnection(void) * Actors B & C are provided as the children */ - TestCustomActor actorA = TestCustomActor::NewVariant2(); + Test::TestCustomActor actorA = Test::TestCustomActor::NewVariant2(); actorA.SetName( "ActorA" ); - TestCustomActor actorB = TestCustomActor::New(); + Test::TestCustomActor actorB = Test::TestCustomActor::New(); actorB.SetName( "ActorB" ); actorA.Add( actorB ); - TestCustomActor actorC = TestCustomActor::New(); + Test::TestCustomActor actorC = Test::TestCustomActor::New(); actorC.SetName( "ActorC" ); actorA.Add( actorC ); @@ -1215,10 +453,10 @@ int UtcDaliCustomActorAddDuringOnStageDisconnection(void) * The actorB is provided as the child */ - TestCustomActor actorB = TestCustomActor::New(); + Test::TestCustomActor actorB = Test::TestCustomActor::New(); actorB.SetName( "ActorB" ); - TestCustomActor actorA = TestCustomActor::NewVariant3( actorB ); + Test::TestCustomActor actorA = Test::TestCustomActor::NewVariant3( actorB ); actorA.SetName( "ActorA" ); stage.Add( actorA ); @@ -1268,11 +506,11 @@ int UtcDaliCustomActorRemoveDuringOnStageDisconnection(void) * The actorB is provided as the child */ - TestCustomActor actorA = TestCustomActor::NewVariant4(); + Test::TestCustomActor actorA = Test::TestCustomActor::NewVariant4(); actorA.SetName( "ActorA" ); stage.Add( actorA ); - TestCustomActor actorB = TestCustomActor::New(); + Test::TestCustomActor actorB = Test::TestCustomActor::New(); actorB.SetName( "ActorB" ); actorA.Add( actorB ); @@ -1326,10 +564,10 @@ int UtcDaliCustomActorRemoveParentDuringOnStageConnection(void) * The child actor is interrupting the parent's connection to stage, therefore the parent should not get an OnStageDisconnection() */ - TestCustomActor actorA = TestCustomActor::New(); + Test::TestCustomActor actorA = Test::TestCustomActor::New(); actorA.SetName( "ActorA" ); - TestCustomActor actorB = TestCustomActor::NewVariant5(); + Test::TestCustomActor actorB = Test::TestCustomActor::NewVariant5(); actorB.SetName( "ActorB" ); actorA.Add( actorB ); @@ -1374,11 +612,11 @@ int UtcDaliCustomActorAddParentDuringOnStageDisconnection(void) * The child actor is interrupting the disconnection, such that parent should not get a OnStageDisconnection() */ - TestCustomActor actorA = TestCustomActor::New(); + Test::TestCustomActor actorA = Test::TestCustomActor::New(); actorA.SetName( "ActorA" ); stage.Add( actorA ); - TestCustomActor actorB = TestCustomActor::NewVariant6(); + Test::TestCustomActor actorB = Test::TestCustomActor::NewVariant6(); actorB.SetName( "ActorB" ); actorA.Add( actorB ); @@ -1415,7 +653,7 @@ int UtcDaliCustomActorOnChildAddRemove(void) TestApplication application; tet_infoline("Testing Dali::CustomActor::OnChildAdd() & OnChildRemove()"); - TestCustomActor custom = TestCustomActor::New(); + Test::TestCustomActor custom = Test::TestCustomActor::New(); DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION ); Actor aChild = Actor::New(); @@ -1444,10 +682,10 @@ int UtcDaliCustomActorReparentDuringOnChildAdd(void) * The actorB is the child of actorA */ - TestCustomActor actorA = TestCustomActor::NewVariant7( "ActorA" ); + Test::TestCustomActor actorA = Test::TestCustomActor::NewVariant7( "ActorA" ); stage.Add( actorA ); - TestCustomActor actorB = TestCustomActor::New(); + Test::TestCustomActor actorB = Test::TestCustomActor::New(); actorB.SetName( "ActorB" ); actorA.Add( actorB ); @@ -1528,11 +766,11 @@ int UtcDaliCustomActorRemoveDuringOnChildRemove(void) * This should be a NOOP since the reparenting has not occured yet */ - TestCustomActor actorB = TestCustomActor::New(); + Test::TestCustomActor actorB = Test::TestCustomActor::New(); actorB.SetName( "ActorB" ); stage.Add( actorB ); - TestCustomActor actorA = TestCustomActor::NewVariant8( actorB ); + Test::TestCustomActor actorA = Test::TestCustomActor::NewVariant8( actorB ); actorA.SetName( "ActorA" ); stage.Add( actorA ); @@ -1596,7 +834,7 @@ int UtcDaliCustomActorOnPropertySet(void) TestApplication application; tet_infoline("Testing Dali::CustomActor::OnPropertySet()"); - TestCustomActor custom = TestCustomActor::New(); + Test::TestCustomActor custom = Test::TestCustomActor::New(); DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION ); custom.SetDaliProperty("yes"); @@ -1611,7 +849,7 @@ int UtcDaliCustomActorOnSizeSet(void) TestApplication application; tet_infoline("Testing Dali::CustomActor::OnSizeSet()"); - TestCustomActor custom = TestCustomActor::New(); + Test::TestCustomActor custom = Test::TestCustomActor::New(); DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION ); custom.SetSize( Vector2( 9.0f, 10.0f ) ); @@ -1634,11 +872,16 @@ int UtcDaliCustomActorOnSizeAnimation(void) TestApplication application; tet_infoline("Testing Dali::CustomActor::OnSizeAnimation()"); - TestCustomActor custom = TestCustomActor::New(); + Test::TestCustomActor custom = Test::TestCustomActor::New(); DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION ); Animation anim = Animation::New( 1.0f ); anim.AnimateTo( Property( custom, Actor::Property::SIZE ), Vector3( 8.0f, 9.0f, 10.0f ) ); + anim.Play(); + + application.SendNotification(); + application.Render( static_cast( 1000.0f ) ); + DALI_TEST_EQUALS( 1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION ); DALI_TEST_EQUALS( "OnSizeAnimation", custom.GetMethodsCalled()[ 0 ], TEST_LOCATION ); DALI_TEST_EQUALS( 8.0f, custom.GetTargetSize().width, TEST_LOCATION ); @@ -1647,12 +890,44 @@ int UtcDaliCustomActorOnSizeAnimation(void) END_TEST; } +int UtcDaliCustomActorSizeComponentAnimation(void) +{ + TestApplication application; + tet_infoline("Testing Size component animation"); + + Test::TestCustomActor custom = Test::TestCustomActor::New(); + float intialWidth( 10.0f ); + + DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION ); + custom.SetSize( intialWidth, 10.0f); // First method + + Animation anim = Animation::New( 1.0f ); + + DALI_TEST_EQUALS( 1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION ); + + anim.AnimateTo( Property( custom, Actor::Property::SIZE_WIDTH ), 20.0f ); + + DALI_TEST_EQUALS( 1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION ); + + anim.Play(); // Triggers second method ( OnSizeAnimation ) + + application.SendNotification(); + application.Render( static_cast( 1000.0f ) ); + + DALI_TEST_EQUALS( 2, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION ); + + DALI_TEST_EQUALS( "OnSizeAnimation", custom.GetMethodsCalled()[ 1 ], TEST_LOCATION ); + + END_TEST; + +} + int UtcDaliCustomActorOnTouchEvent(void) { TestApplication application; tet_infoline("Testing Dali::CustomActor::OnTouchEvent()"); - TestCustomActor custom = TestCustomActor::New(); + Test::TestCustomActor custom = Test::TestCustomActor::New(); DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION ); // set size for custom actor @@ -1685,7 +960,7 @@ int UtcDaliCustomActorOnHoverEvent(void) TestApplication application; tet_infoline("Testing Dali::CustomActor::OnHoverEvent()"); - TestCustomActor custom = TestCustomActor::New(); + Test::TestCustomActor custom = Test::TestCustomActor::New(); DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION ); // set size for custom actor @@ -1718,7 +993,7 @@ int UtcDaliCustomActorOnWheelEvent(void) TestApplication application; tet_infoline("Testing Dali::CustomActor::OnWheelEvent()"); - TestCustomActor custom = TestCustomActor::New(); + Test::TestCustomActor custom = Test::TestCustomActor::New(); DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION ); // set size for custom actor @@ -1746,7 +1021,7 @@ int UtcDaliCustomActorOnWheelEvent(void) int UtcDaliCustomActorImplOnPropertySet(void) { TestApplication application; - CustomActorImpl* impl = new Impl::SimpleTestCustomActor(); + CustomActorImpl* impl = new Test::Impl::SimpleTestCustomActor(); CustomActor customActor( *impl ); // Will automatically unref at the end of this function impl->OnPropertySet( 0, 0 ); @@ -1760,11 +1035,11 @@ int UtcDaliCustomActorGetImplementation(void) { TestApplication application; - TestCustomActor custom = TestCustomActor::New(); + Test::TestCustomActor custom = Test::TestCustomActor::New(); CustomActorImpl& impl = custom.GetImplementation(); impl.GetOwner(); // Test - const TestCustomActor constCustom = TestCustomActor::New(); + const Test::TestCustomActor constCustom = Test::TestCustomActor::New(); const CustomActorImpl& constImpl = constCustom.GetImplementation(); constImpl.GetOwner(); // Test @@ -1777,7 +1052,7 @@ int UtcDaliCustomActorDoAction(void) TestApplication application; tet_infoline("Testing Dali::CustomActor::DoAction()"); - TestCustomActor custom = TestCustomActor::New(); + Test::TestCustomActor custom = Test::TestCustomActor::New(); BaseHandle customActorObject = custom; @@ -1830,7 +1105,7 @@ int UtcDaliCustomActorImplRelayoutRequest(void) DALI_TEST_CHECK( gOnRelayout == false ); - TestCustomActor custom = TestCustomActor::NewNegoSize(); + Test::TestCustomActor custom = Test::TestCustomActor::NewNegoSize(); Stage::GetCurrent().Add(custom); application.SendNotification(); @@ -1851,15 +1126,14 @@ int UtcDaliCustomActorImplRelayoutRequest(void) int UtcDaliCustomActorImplGetHeightForWidthBase(void) { TestApplication application; - TestCustomActor custom = TestCustomActor::NewNegoSize(); + Test::TestCustomActor custom = Test::TestCustomActor::NewNegoSize(); float width = 300.0f; - float v = 0.0f; application.SendNotification(); application.Render(); - v = custom.TestGetHeightForWidthBase( width ); + float v = custom.TestGetHeightForWidthBase( width ); DALI_TEST_CHECK( v == width ); @@ -1869,15 +1143,14 @@ int UtcDaliCustomActorImplGetHeightForWidthBase(void) int UtcDaliCustomActorImplGetWidthForHeightBase(void) { TestApplication application; - TestCustomActor custom = TestCustomActor::NewNegoSize(); + Test::TestCustomActor custom = Test::TestCustomActor::NewNegoSize(); float height = 300.0f; - float v = 0.0f; application.SendNotification(); application.Render(); - v = custom.TestGetWidthForHeightBase( height ); + float v = custom.TestGetWidthForHeightBase( height ); DALI_TEST_CHECK( v == height ); @@ -1887,7 +1160,7 @@ int UtcDaliCustomActorImplGetWidthForHeightBase(void) int UtcDaliCustomActorImplCalculateChildSizeBase(void) { TestApplication application; - TestCustomActor custom = TestCustomActor::NewNegoSize(); + Test::TestCustomActor custom = Test::TestCustomActor::NewNegoSize(); Actor child = Actor::New(); child.SetResizePolicy(Dali::ResizePolicy::FIXED, Dali::Dimension::ALL_DIMENSIONS); @@ -1896,8 +1169,7 @@ int UtcDaliCustomActorImplCalculateChildSizeBase(void) application.SendNotification(); application.Render(); - float v = 9.99f; - v = custom.TestCalculateChildSizeBase( child, Dali::Dimension::ALL_DIMENSIONS ); + float v = custom.TestCalculateChildSizeBase( child, Dali::Dimension::ALL_DIMENSIONS ); DALI_TEST_CHECK( v == 0.0f ); END_TEST; @@ -1906,22 +1178,22 @@ int UtcDaliCustomActorImplCalculateChildSizeBase(void) int UtcDaliCustomActorImplRelayoutDependentOnChildrenBase(void) { TestApplication application; - TestCustomActor custom = TestCustomActor::NewNegoSize(); + Test::TestCustomActor custom = Test::TestCustomActor::NewNegoSize(); custom.SetResizePolicy(Dali::ResizePolicy::FIT_TO_CHILDREN, Dali::Dimension::ALL_DIMENSIONS); - bool v = false; + bool v = custom.TestRelayoutDependentOnChildrenBase( Dali::Dimension::ALL_DIMENSIONS ); + DALI_TEST_CHECK( v == true ); - v = custom.TestRelayoutDependentOnChildrenBase( Dali::Dimension::ALL_DIMENSIONS ); application.SendNotification(); application.Render(); - DALI_TEST_CHECK( v == true ); - custom.SetResizePolicy(Dali::ResizePolicy::FIXED, Dali::Dimension::ALL_DIMENSIONS); v = custom.TestRelayoutDependentOnChildrenBase( Dali::Dimension::WIDTH ); + DALI_TEST_CHECK( v == false ); + + // why is this here? application.SendNotification(); application.Render(); - DALI_TEST_CHECK( v == false ); END_TEST; } @@ -1958,7 +1230,7 @@ int UtcDaliCustomActorGetExtensionP(void) { TestApplication application; - TestCustomActor custom = TestCustomActor::NewVariant5(); + Test::TestCustomActor custom = Test::TestCustomActor::NewVariant5(); DALI_TEST_CHECK( NULL == custom.GetImplementation().GetExtension() ); @@ -1985,22 +1257,22 @@ int UtcDaliCustomActorOnConnectionDepth(void) * OnStageConnection should return 1 for A, 2 for B and C, and 3 for D, E and F. */ - TestCustomActor actorA = TestCustomActor::New(); + Test::TestCustomActor actorA = Test::TestCustomActor::New(); stage.Add( actorA ); - TestCustomActor actorB = TestCustomActor::New(); + Test::TestCustomActor actorB = Test::TestCustomActor::New(); actorA.Add( actorB ); - TestCustomActor actorC = TestCustomActor::New(); + Test::TestCustomActor actorC = Test::TestCustomActor::New(); actorA.Add( actorC ); - TestCustomActor actorD = TestCustomActor::New(); + Test::TestCustomActor actorD = Test::TestCustomActor::New(); actorB.Add( actorD ); - TestCustomActor actorE = TestCustomActor::New(); + Test::TestCustomActor actorE = Test::TestCustomActor::New(); actorB.Add( actorE ); - TestCustomActor actorF = TestCustomActor::New(); + Test::TestCustomActor actorF = Test::TestCustomActor::New(); actorC.Add( actorF ); // Excercise the message passing to Update thread @@ -2017,3 +1289,257 @@ int UtcDaliCustomActorOnConnectionDepth(void) END_TEST; } + + +int UtcDaliCustomActorSetGetProperty(void) +{ + TestApplication application; // Need the type registry + + Test::TestCustomActor actor = Test::TestCustomActor::New(); + Stage::GetCurrent().Add( actor ); + + actor.SetProperty( Test::TestCustomActor::Property::TEST_PROPERTY1, 0.5f ); + actor.SetProperty( Test::TestCustomActor::Property::TEST_PROPERTY2, Color::WHITE ); + actor.SetProperty( Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY3, Color::BLUE ); + actor.SetProperty( Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY4, 20 ); + actor.SetProperty( Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY5, 40.0f ); + + Property::Value value = actor.GetProperty( Test::TestCustomActor::Property::TEST_PROPERTY1 ); + DALI_TEST_EQUALS( value.Get(), 0.5f, 0.001f, TEST_LOCATION ); + + value = actor.GetProperty( Test::TestCustomActor::Property::TEST_PROPERTY2 ); + DALI_TEST_EQUALS( value.Get(), Color::WHITE, 0.001f, TEST_LOCATION ); + + + value = actor.GetProperty( Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY3 ); + DALI_TEST_EQUALS( value.Get(), Color::BLUE, 0.001f, TEST_LOCATION ); + + value = actor.GetProperty( Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY4 ); + DALI_TEST_EQUALS( value.Get(), 20, TEST_LOCATION ); + + value = actor.GetProperty( Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY5 ); + DALI_TEST_EQUALS( value.Get(), 40.0f, 0.001f, TEST_LOCATION ); + + // Get read-only property + value = actor.GetProperty( Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY6 ); + DALI_TEST_EQUALS( value.Get(), 10.0f, 0.001f, TEST_LOCATION ); + + // Attempt to set read-only property and then ensure value hasn't changed + actor.SetProperty( Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY6, 40.0f ); + DALI_TEST_EQUALS( value.Get(), 10.0f, 0.001f, TEST_LOCATION ); + + END_TEST; +} + +int utcDaliActorGetTypeInfo(void) +{ + TestApplication application; + tet_infoline( "Get the type info of a derived actor" ); + + Test::TestCustomActor customActor = Test::TestCustomActor::New(); + + Dali::TypeInfo typeInfo = Dali::DevelCustomActor::GetTypeInfo( customActor ); + + DALI_TEST_EQUALS( typeInfo.GetName(), std::string("TestCustomActor"), TEST_LOCATION ); + + END_TEST; +} + +namespace Impl +{ +/** + * A custom actor that is not type registered on purpose + */ +struct UnregisteredCustomActor : public Dali::CustomActorImpl +{ + UnregisteredCustomActor() : CustomActorImpl( ACTOR_BEHAVIOUR_DEFAULT ) + { } + virtual ~UnregisteredCustomActor() + { } + virtual void OnStageConnection( int32_t depth ) + { } + virtual void OnStageDisconnection() + { } + virtual void OnChildAdd(Actor& child) + { } + virtual void OnChildRemove(Actor& child) + { } + virtual void OnPropertySet( Property::Index index, Property::Value propertyValue ) + { } + virtual void OnSizeSet(const Vector3& targetSize) + { } + virtual void OnSizeAnimation(Animation& animation, const Vector3& targetSize) + { } + virtual bool OnTouchEvent(const TouchEvent& event) DALI_DEPRECATED_API + { return false; } + virtual bool OnHoverEvent(const HoverEvent& event) + { return false; } + virtual bool OnKeyEvent(const KeyEvent& event) + { return false; } + virtual bool OnWheelEvent(const WheelEvent& event) + { return false; } + virtual void OnRelayout( const Vector2& size, RelayoutContainer& container ) + { } + virtual void OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension ) + { } + virtual Vector3 GetNaturalSize() + { return Vector3(); } + virtual float CalculateChildSize( const Dali::Actor& child, Dimension::Type dimension ) + { return 0.f; } + virtual float GetHeightForWidth( float width ) + { return 0.f; } + virtual float GetWidthForHeight( float height ) + { return 0.f; } + virtual bool RelayoutDependentOnChildren( Dimension::Type dimension = Dimension::ALL_DIMENSIONS ) + { return false; } + virtual void OnCalculateRelayoutSize( Dimension::Type dimension ) + { } + virtual void OnLayoutNegotiated( float size, Dimension::Type dimension ) + { } +}; +} +struct UnregisteredCustomActor : public Dali::CustomActor +{ + static UnregisteredCustomActor New() + { + Impl::UnregisteredCustomActor* impl = new Impl::UnregisteredCustomActor; + UnregisteredCustomActor custom( *impl ); // takes ownership + return custom; + } + UnregisteredCustomActor() + { } + ~UnregisteredCustomActor() + { } + UnregisteredCustomActor( Internal::CustomActor* impl ) + : CustomActor( impl ) + { } + UnregisteredCustomActor( Impl::UnregisteredCustomActor& impl ) + : CustomActor( impl ) + { } + static UnregisteredCustomActor DownCast( BaseHandle handle ) + { + UnregisteredCustomActor hndl; + CustomActor custom = Dali::CustomActor::DownCast( handle ); + if( custom ) + { + CustomActorImpl& customImpl = custom.GetImplementation(); + + Impl::UnregisteredCustomActor* impl = dynamic_cast( &customImpl ); + + if( impl ) + { + hndl = UnregisteredCustomActor( customImpl.GetOwner() ); + } + } + return hndl; + } +}; + +int UtcDaliCustomActorSetGetActorPropertyActionSignal(void) +{ + TestApplication application; // Need the type registry + + auto custom = UnregisteredCustomActor::New(); + Stage::GetCurrent().Add( custom ); + + // should have all actor properties + DALI_TEST_EQUALS( custom.GetPropertyType( Actor::Property::COLOR ), Property::VECTOR4, TEST_LOCATION ); + auto actorHandle = Actor::New(); + DALI_TEST_EQUALS( custom.GetPropertyCount(), actorHandle.GetPropertyCount(), TEST_LOCATION ); + + DALI_TEST_EQUALS( custom.IsVisible(), true, TEST_LOCATION ); + custom.SetProperty( Actor::Property::VISIBLE, false ); + application.SendNotification(); + application.Render(); // IsVisible returns scene value + DALI_TEST_EQUALS( custom.IsVisible(), false, TEST_LOCATION ); + + // should have custom actor typename (as it has not registered itself) + DALI_TEST_EQUALS( "CustomActor", custom.GetTypeName(), TEST_LOCATION ); + + // should have actor actions + custom.DoAction( "show", Property::Map() ); + DALI_TEST_EQUALS( custom.GetProperty( Actor::Property::VISIBLE ).Get(), true, TEST_LOCATION ); + + Animation animation = Animation::New(0.01f); // very short animation + // should be able to animate actor property + animation.AnimateTo( Property( custom, Actor::Property::POSITION ), Vector3( 100.0f, 150.0f, 200.0f ) ); + animation.Play(); + + application.SendNotification(); + application.Render(1000.f); + + DALI_TEST_EQUALS( Vector3( 100.0f, 150.0f, 200.0f ), custom.GetProperty( Actor::Property::POSITION ).Get(), TEST_LOCATION ); + DALI_TEST_EQUALS( Vector3( 100.0f, 150.0f, 200.0f ), custom.GetCurrentPosition(), TEST_LOCATION ); + + Dali::WeakHandle weakRef( custom ); + // should have actor signals + custom.ConnectSignal( &application, "offStage", + [weakRef]() + { + DALI_TEST_EQUALS( weakRef.GetHandle().OnStage(), false, TEST_LOCATION ); + } ); + + Stage::GetCurrent().Remove( custom ); + Stage::GetCurrent().Add( custom ); + + END_TEST; +} + +namespace Impl +{ +struct DerivedCustomActor : public UnregisteredCustomActor +{ }; +} + +struct DerivedCustomActor : public UnregisteredCustomActor +{ + static DerivedCustomActor New() + { + Impl::DerivedCustomActor* impl = new Impl::DerivedCustomActor; + DerivedCustomActor custom( *impl ); // takes ownership + return custom; + } + DerivedCustomActor() + { } + ~DerivedCustomActor() + { } + DerivedCustomActor( Internal::CustomActor* impl ) + : UnregisteredCustomActor( impl ) + { } + DerivedCustomActor( Impl::UnregisteredCustomActor& impl ) + : UnregisteredCustomActor( impl ) + { } +}; + +// register custom +DALI_TYPE_REGISTRATION_BEGIN( DerivedCustomActor, UnregisteredCustomActor, nullptr ); +DALI_TYPE_REGISTRATION_END() + +int UtcDaliCustomActorPropertyRegistrationDefaultValue(void) +{ + TestApplication application; // Need the type registry + + // register our base and add a property with default value for it + Dali::TypeRegistration typeRegistration( typeid( UnregisteredCustomActor ), typeid( Dali::CustomActor ), nullptr ); + + auto derived = DerivedCustomActor::New(); + Stage::GetCurrent().Add( derived ); + + // should have all actor properties + DALI_TEST_EQUALS( derived.GetPropertyType( Actor::Property::WORLD_MATRIX ), Property::MATRIX, TEST_LOCATION ); + auto actorHandle = Actor::New(); + DALI_TEST_EQUALS( derived.GetPropertyCount(), actorHandle.GetPropertyCount(), TEST_LOCATION ); + + // add a property in base class + AnimatablePropertyRegistration( typeRegistration, "Foobar", ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX, 10.f ); + + // should be one more property now + DALI_TEST_EQUALS( derived.GetPropertyCount(), actorHandle.GetPropertyCount() + 1, TEST_LOCATION ); + // check that the default value is set for base class + DALI_TEST_EQUALS( UnregisteredCustomActor::New().GetProperty(ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX).Get(), 10.f, TEST_LOCATION ); + // check that the default value is set for the derived instance as well + DALI_TEST_EQUALS( derived.GetProperty(ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX).Get(), 10.f, TEST_LOCATION ); + + END_TEST; +} +