From 4f9686042fd5087cacde39bfca21c4d779784e2d Mon Sep 17 00:00:00 2001 From: David Steele Date: Tue, 6 Dec 2016 18:52:16 +0000 Subject: [PATCH] Adding Devel Property Registration macro And missing test cases. Change-Id: I47626b6dd9ef2eca4fbbfb482c3c6073612b7f5b --- automated-tests/src/dali/CMakeLists.txt | 1 + .../dali-test-suite-utils/test-custom-actor.cpp | 525 ++++++++++++ .../dali/dali-test-suite-utils/test-custom-actor.h | 502 ++++++++++++ automated-tests/src/dali/utc-Dali-CustomActor.cpp | 910 ++------------------- dali/devel-api/file.list | 1 + dali/devel-api/object/property-helper-devel.h | 87 ++ 6 files changed, 1206 insertions(+), 820 deletions(-) create mode 100644 automated-tests/src/dali/dali-test-suite-utils/test-custom-actor.cpp create mode 100644 automated-tests/src/dali/dali-test-suite-utils/test-custom-actor.h create mode 100644 dali/devel-api/object/property-helper-devel.h diff --git a/automated-tests/src/dali/CMakeLists.txt b/automated-tests/src/dali/CMakeLists.txt index ce223b7..b30287e 100644 --- a/automated-tests/src/dali/CMakeLists.txt +++ b/automated-tests/src/dali/CMakeLists.txt @@ -102,6 +102,7 @@ LIST(APPEND TC_SOURCES dali-test-suite-utils/mesh-builder.cpp dali-test-suite-utils/dali-test-suite-utils.cpp dali-test-suite-utils/test-actor-utils.cpp + dali-test-suite-utils/test-custom-actor.cpp dali-test-suite-utils/test-harness.cpp dali-test-suite-utils/test-application.cpp dali-test-suite-utils/test-gesture-manager.cpp diff --git a/automated-tests/src/dali/dali-test-suite-utils/test-custom-actor.cpp b/automated-tests/src/dali/dali-test-suite-utils/test-custom-actor.cpp new file mode 100644 index 0000000..1463118 --- /dev/null +++ b/automated-tests/src/dali/dali-test-suite-utils/test-custom-actor.cpp @@ -0,0 +1,525 @@ +#include "test-custom-actor.h" + +using namespace Dali; + +std::vector< std::string > MasterCallStack; +bool gOnRelayout = false; + +namespace Test +{ +namespace Impl +{ +struct TestCustomActor; +} + + +TestCustomActor TestCustomActor::New() +{ + Impl::TestCustomActor* impl = new Impl::TestCustomActor; + TestCustomActor custom( *impl ); // takes ownership + + impl->Initialize(); + + return custom; +} + +TestCustomActor TestCustomActor::NewNegoSize() +{ + Impl::TestCustomActor* impl = new Impl::TestCustomActor( true ); + TestCustomActor custom( *impl ); // takes ownership + custom.SetName( "SizeNegotiationActor" ); + + impl->Initialize(); + + return custom; +} + +TestCustomActor TestCustomActor::NewVariant1( Actor childToAdd ) +{ + Impl::TestCustomActor* impl = new Impl::TestCustomActorVariant1( childToAdd ); + TestCustomActor custom( *impl ); // takes ownership + + impl->Initialize(); + + return custom; +} + +TestCustomActor TestCustomActor::NewVariant2() +{ + Impl::TestCustomActor* impl = new Impl::TestCustomActorVariant2(); + TestCustomActor custom( *impl ); // takes ownership + + impl->Initialize(); + + return custom; +} + +TestCustomActor TestCustomActor::NewVariant3( Actor childToAdd ) +{ + Impl::TestCustomActor* impl = new Impl::TestCustomActorVariant3( childToAdd ); + TestCustomActor custom( *impl ); // takes ownership + + impl->Initialize(); + + return custom; +} + +TestCustomActor TestCustomActor::NewVariant4() +{ + Impl::TestCustomActor* impl = new Impl::TestCustomActorVariant4(); + TestCustomActor custom( *impl ); // takes ownership + + impl->Initialize(); + + return custom; +} + +TestCustomActor TestCustomActor::NewVariant5() +{ + Impl::TestCustomActor* impl = new Impl::TestCustomActorVariant5(); + TestCustomActor custom( *impl ); // takes ownership + + impl->Initialize(); + + return custom; +} + +TestCustomActor TestCustomActor::NewVariant6() +{ + Impl::TestCustomActor* impl = new Impl::TestCustomActorVariant6(); + TestCustomActor custom( *impl ); // takes ownership + + impl->Initialize(); + + return custom; +} + +TestCustomActor TestCustomActor::NewVariant7( const char* name ) +{ + Impl::TestCustomActor* impl = new Impl::TestCustomActorVariant7(); + TestCustomActor custom( *impl ); // takes ownership + + impl->Initialize( name ); + + return custom; +} + +TestCustomActor TestCustomActor::NewVariant8( Actor rival ) +{ + Impl::TestCustomActor* impl = new Impl::TestCustomActorVariant8( rival ); + TestCustomActor custom( *impl ); // takes ownership + + impl->Initialize(); + + return custom; +} + +TestCustomActor::~TestCustomActor() +{ +} + +Impl::TestCustomActor& TestCustomActor::GetImpl() +{ + return static_cast(GetImplementation()); +} + +std::vector< std::string >& TestCustomActor::GetMethodsCalled() +{ + return GetImpl().mMethodsCalled; +} + +void TestCustomActor::ResetCallStack() +{ + GetImpl().ResetCallStack(); +} + +void TestCustomActor::SetDaliProperty(std::string s) +{ + GetImpl().SetDaliProperty(s); +} + +Vector3 TestCustomActor::GetSize() +{ + return GetImpl().mSizeSet; +} + +Vector3 TestCustomActor::GetTargetSize() +{ + return GetImpl().mTargetSize; +} + +Vector3 TestCustomActor::GetNaturalSize() +{ + return Vector3( 0.0f, 0.0f, 0.0f ); +} + +float TestCustomActor::GetHeightForWidth( float width ) +{ + return 0.0f; +} + +float TestCustomActor::GetWidthForHeight( float height ) +{ + return 0.0f; +} + +void TestCustomActor::OnRelayout( const Vector2& size, RelayoutContainer& container ) +{ +} + +void TestCustomActor::OnLayoutNegotiated( float size, Dimension::Type dimension ) +{ +} + +void TestCustomActor::OnCalculateRelayoutSize( Dimension::Type dimension ) +{ +} + +void TestCustomActor::TestRelayoutRequest() +{ + GetImpl().TestRelayoutRequest(); +} + +float TestCustomActor::TestGetHeightForWidthBase( float width ) +{ + return GetImpl().TestGetHeightForWidthBase( width ); +} + +float TestCustomActor::TestGetWidthForHeightBase( float height ) +{ + return GetImpl().TestGetWidthForHeightBase( height ); +} + +float TestCustomActor::TestCalculateChildSizeBase( const Dali::Actor& child, Dimension::Type dimension ) +{ + return GetImpl().TestCalculateChildSizeBase( child, dimension ); +} + +bool TestCustomActor::TestRelayoutDependentOnChildrenBase( Dimension::Type dimension ) +{ + return GetImpl().TestRelayoutDependentOnChildrenBase( dimension ); +} + +unsigned int TestCustomActor::GetDepth() +{ + return GetImpl().mDepth; +} + +TestCustomActor::TestCustomActor() +{ +} + +TestCustomActor::TestCustomActor( Impl::TestCustomActor& impl ) +: CustomActor( impl ) +{ +} + +TestCustomActor::TestCustomActor( Dali::Internal::CustomActor* internal ) +: CustomActor( internal ) +{ +} + +TestCustomActor TestCustomActor::DownCast( BaseHandle handle ) +{ + TestCustomActor actor; + CustomActor custom = Dali::CustomActor::DownCast(handle); + if(custom) + { + CustomActorImpl& customImpl = custom.GetImplementation(); + + Test::Impl::TestCustomActor* impl = dynamic_cast(&customImpl); + if( impl ) + { + actor = TestCustomActor(customImpl.GetOwner()); + } + } + return actor; +} + +namespace Impl +{ + +TestCustomActor::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::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 + */ +TestCustomActor::~TestCustomActor() +{ +} + +void TestCustomActor::Initialize( const char* name ) +{ + mDaliProperty = Self().RegisterProperty( "Dali", std::string("no"), Property::READ_WRITE); + + OnInitialize( name ); +} + +void TestCustomActor::OnInitialize( const char* name ) {} + +/** + * Resets the call stack + */ +void TestCustomActor::ResetCallStack() +{ + mSizeSet = Vector3(); + mTargetSize = Vector3(); + mMethodsCalled.clear(); +} + +void TestCustomActor::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 +void TestCustomActor::OnStageConnection( int depth ) +{ + AddToCallStacks("OnStageConnection"); + mDepth = depth; +} +void TestCustomActor::OnStageDisconnection() +{ + AddToCallStacks("OnStageDisconnection"); +} +void TestCustomActor::OnChildAdd(Actor& child) +{ + AddToCallStacks("OnChildAdd"); +} +void TestCustomActor::OnChildRemove(Actor& child) +{ + AddToCallStacks("OnChildRemove"); +} +void TestCustomActor::OnPropertySet( Property::Index index, Property::Value propertyValue ) +{ + AddToCallStacks("OnPropertySet"); +} +void TestCustomActor::OnSizeSet(const Vector3& targetSize) +{ + mSizeSet = targetSize; + AddToCallStacks("OnSizeSet"); +} +void TestCustomActor::OnSizeAnimation(Animation& animation, const Vector3& targetSize) +{ + mTargetSize = targetSize; + AddToCallStacks("OnSizeAnimation"); +} +bool TestCustomActor::OnTouchEvent(const TouchEvent& event) +{ + AddToCallStacks("OnTouchEvent"); + return true; +} +bool TestCustomActor::OnHoverEvent(const HoverEvent& event) +{ + AddToCallStacks("OnHoverEvent"); + return true; +} +bool TestCustomActor::OnWheelEvent(const WheelEvent& event) +{ + AddToCallStacks("OnWheelEvent"); + return true; +} +bool TestCustomActor::OnKeyEvent(const KeyEvent& event) +{ + AddToCallStacks("OnKeyEvent"); + return true; +} +void TestCustomActor::OnKeyInputFocusGained() +{ + AddToCallStacks("OnKeyInputFocusGained"); +} +void TestCustomActor::OnKeyInputFocusLost() +{ + AddToCallStacks("OnKeyInputFocusLost"); +} +Vector3 TestCustomActor::GetNaturalSize() +{ + return Vector3( 0.0f, 0.0f, 0.0f ); +} + +float TestCustomActor::GetHeightForWidth( float width ) +{ + return 0.0f; +} + +float TestCustomActor::GetWidthForHeight( float height ) +{ + return 0.0f; +} + +void TestCustomActor::OnRelayout( const Vector2& size, RelayoutContainer& container ) +{ + gOnRelayout = true; +} + +void TestCustomActor::OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension ) +{ +} + +void TestCustomActor::OnCalculateRelayoutSize( Dimension::Type dimension ) +{ +} + +float TestCustomActor::CalculateChildSize( const Dali::Actor& child, Dimension::Type dimension ) +{ + return 0.0f; +} + +void TestCustomActor::OnLayoutNegotiated( float size, Dimension::Type dimension ) +{ +} + +bool TestCustomActor::RelayoutDependentOnChildren( Dimension::Type dimension ) +{ + return false; +} + +void TestCustomActor::SetDaliProperty(std::string s) +{ + Self().SetProperty(mDaliProperty, s); +} +void TestCustomActor::TestRelayoutRequest() +{ + RelayoutRequest(); +} + +float TestCustomActor::TestGetHeightForWidthBase( float width ) +{ + return GetHeightForWidthBase( width ); +} + +float TestCustomActor::TestGetWidthForHeightBase( float height ) +{ + return GetWidthForHeightBase( height ); +} + +float TestCustomActor::TestCalculateChildSizeBase( const Dali::Actor& child, Dimension::Type dimension ) +{ + return CalculateChildSizeBase( child, dimension ); +} + +bool TestCustomActor::TestRelayoutDependentOnChildrenBase( Dimension::Type dimension ) +{ + return RelayoutDependentOnChildrenBase( dimension ); +} + +void TestCustomActor::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value ) +{ + Test::TestCustomActor actor = Test::TestCustomActor::DownCast( Dali::BaseHandle( object ) ); + + if ( actor ) + { + TestCustomActor& actorImpl = GetImpl(actor); + switch(index) + { + case Test::TestCustomActor::Property::TEST_PROPERTY1: + { + actorImpl.prop1 = value.Get(); + break; + } + case Test::TestCustomActor::Property::TEST_PROPERTY2: + { + actorImpl.prop2 = value.Get(); + break; + } + case Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY3: + { + actorImpl.develProp3 = value.Get(); + break; + } + case Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY4: + { + actorImpl.develProp4 = value.Get(); + break; + } + case Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY5: + { + actorImpl.develProp5 = value.Get(); + break; + } + } + } +} + +Property::Value TestCustomActor::GetProperty( BaseObject* object, Property::Index index ) +{ + Test::TestCustomActor actor = Test::TestCustomActor::DownCast( Dali::BaseHandle( object ) ); + + if ( actor ) + { + TestCustomActor& actorImpl = GetImpl(actor); + switch(index) + { + case Test::TestCustomActor::Property::TEST_PROPERTY1: + { + return Property::Value(actorImpl.prop1); + } + case Test::TestCustomActor::Property::TEST_PROPERTY2: + { + return Property::Value(actorImpl.prop2); + } + case Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY3: + { + return Property::Value(actorImpl.develProp3); + } + case Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY4: + { + return Property::Value(actorImpl.develProp4); + } + case Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY5: + { + return Property::Value(actorImpl.develProp5); + } + } + } + return Property::Value(); +} + + +BaseHandle CreateActor() +{ + return Test::TestCustomActor::New(); +} + +DALI_TYPE_REGISTRATION_BEGIN( Test::TestCustomActor, Dali::CustomActor, CreateActor ); + +DALI_PROPERTY_REGISTRATION( Test, TestCustomActor, "testProperty1", FLOAT, TEST_PROPERTY1) +DALI_PROPERTY_REGISTRATION( Test, TestCustomActor, "testProperty2", VECTOR4, TEST_PROPERTY2) +DALI_DEVEL_PROPERTY_REGISTRATION( Test, TestCustomActor, "develTestProperty3", VECTOR4, DEVEL_TEST_PROPERTY3) +DALI_DEVEL_PROPERTY_REGISTRATION( Test, TestCustomActor, "develTestProperty4", INTEGER, DEVEL_TEST_PROPERTY4) +DALI_DEVEL_PROPERTY_REGISTRATION( Test, TestCustomActor, "develTestProperty5", FLOAT, DEVEL_TEST_PROPERTY5) + +DALI_TYPE_REGISTRATION_END() + +} // Impl +} // Test namespace diff --git a/automated-tests/src/dali/dali-test-suite-utils/test-custom-actor.h b/automated-tests/src/dali/dali-test-suite-utils/test-custom-actor.h new file mode 100644 index 0000000..cbe4ab5 --- /dev/null +++ b/automated-tests/src/dali/dali-test-suite-utils/test-custom-actor.h @@ -0,0 +1,502 @@ +#ifndef TEST_CUSTOM_ACTOR_H +#define TEST_CUSTOM_ACTOR_H + +#include +#include + +extern std::vector< std::string > MasterCallStack; +extern bool gOnRelayout; + +namespace Test +{ +namespace Impl +{ +struct TestCustomActor; +} + +/** + * Test custom actor handle + */ +class TestCustomActor : public Dali::CustomActor +{ +public: + enum PropertyRange + { + PROPERTY_START_INDEX = Dali::PROPERTY_REGISTRATION_START_INDEX, + PROPERTY_END_INDEX = PROPERTY_START_INDEX + 1000 + }; + + struct Property + { + enum Type + { + TEST_PROPERTY1 = PROPERTY_START_INDEX, + TEST_PROPERTY2 + }; + }; + + TestCustomActor(); + static TestCustomActor New(); + static TestCustomActor NewNegoSize(); + static TestCustomActor NewVariant1( Actor childToAdd ); + static TestCustomActor NewVariant2(); + static TestCustomActor NewVariant3( Actor childToAdd ); + static TestCustomActor NewVariant4(); + static TestCustomActor NewVariant5(); + static TestCustomActor NewVariant6(); + static TestCustomActor NewVariant7( const char* name ); + static TestCustomActor NewVariant8( Actor rival ); + static TestCustomActor DownCast( Dali::BaseHandle handle ); + + virtual ~TestCustomActor(); + Impl::TestCustomActor& GetImpl(); + + std::vector< std::string >& GetMethodsCalled(); + void ResetCallStack(); + void SetDaliProperty(std::string s); + Dali::Vector3 GetSize(); + Dali::Vector3 GetTargetSize(); + virtual Dali::Vector3 GetNaturalSize(); + virtual float GetHeightForWidth( float width ); + virtual float GetWidthForHeight( float height ); + virtual void OnRelayout( const Dali::Vector2& size, Dali::RelayoutContainer& container ); + virtual void OnLayoutNegotiated( float size, Dali::Dimension::Type dimension ); + virtual void OnCalculateRelayoutSize( Dali::Dimension::Type dimension ); + void TestRelayoutRequest(); + float TestGetHeightForWidthBase( float width ); + float TestGetWidthForHeightBase( float height ); + float TestCalculateChildSizeBase( const Dali::Actor& child, Dali::Dimension::Type dimension ); + bool TestRelayoutDependentOnChildrenBase( Dali::Dimension::Type dimension ); + unsigned int GetDepth(); + +private: + TestCustomActor( Impl::TestCustomActor& impl ); + explicit TestCustomActor(Dali::Internal::CustomActor* internal); +}; + + +namespace DevelTestCustomActor +{ +namespace Property +{ +enum Type +{ + TEST_PROPERTY1 = Test::TestCustomActor::Property::TEST_PROPERTY1, + TEST_PROPERTY2 = Test::TestCustomActor::Property::TEST_PROPERTY2, + DEVEL_TEST_PROPERTY3 = TEST_PROPERTY2+1, + DEVEL_TEST_PROPERTY4 = TEST_PROPERTY2+2, + DEVEL_TEST_PROPERTY5 = TEST_PROPERTY2+3 +}; + +} // Namespace Property +} // Namespace DevelTestCustomActor + + +// TypeRegistry needs custom actor Implementations to have the same name (namespaces are ignored so we use one here) +namespace Impl +{ + +struct TestCustomActor : public Dali::CustomActorImpl +{ +public: + /** + * Constructor + */ + TestCustomActor(); + TestCustomActor(bool nego); + virtual ~TestCustomActor(); + void Initialize( const char* name = NULL ); + virtual void OnInitialize( const char* name ); + void ResetCallStack(); + void AddToCallStacks( const char* method ); + virtual void OnStageConnection( int depth ); + virtual void OnStageDisconnection(); + virtual void OnChildAdd(Dali::Actor& child); + virtual void OnChildRemove(Dali::Actor& child); + virtual void OnPropertySet( Dali::Property::Index index, Dali::Property::Value propertyValue ); + virtual void OnSizeSet(const Dali::Vector3& targetSize); + virtual void OnSizeAnimation(Dali::Animation& animation, const Dali::Vector3& targetSize); + virtual bool OnTouchEvent(const Dali::TouchEvent& event); + virtual bool OnHoverEvent(const Dali::HoverEvent& event); + virtual bool OnWheelEvent(const Dali::WheelEvent& event); + virtual bool OnKeyEvent(const Dali::KeyEvent& event); + virtual void OnKeyInputFocusGained(); + virtual void OnKeyInputFocusLost(); + virtual Dali::Vector3 GetNaturalSize(); + virtual float GetHeightForWidth( float width ); + virtual float GetWidthForHeight( float height ); + virtual void OnRelayout( const Dali::Vector2& size, Dali::RelayoutContainer& container ); + virtual void OnSetResizePolicy( Dali::ResizePolicy::Type policy, Dali::Dimension::Type dimension ); + virtual void OnCalculateRelayoutSize( Dali::Dimension::Type dimension ); + virtual float CalculateChildSize( const Dali::Actor& child, Dali::Dimension::Type dimension ); + virtual void OnLayoutNegotiated( float size, Dali::Dimension::Type dimension ); + virtual bool RelayoutDependentOnChildren( Dali::Dimension::Type dimension = Dali::Dimension::ALL_DIMENSIONS ); + static void SetProperty( Dali::BaseObject* object, Dali::Property::Index index, const Dali::Property::Value& value ); + static Dali::Property::Value GetProperty( Dali::BaseObject* object, Dali::Property::Index index ); + + void SetDaliProperty(std::string s); + void TestRelayoutRequest(); + float TestGetHeightForWidthBase( float width ); + float TestGetWidthForHeightBase( float height ); + float TestCalculateChildSizeBase( const Dali::Actor& child, Dali::Dimension::Type dimension ); + bool TestRelayoutDependentOnChildrenBase( Dali::Dimension::Type dimension ); + +public: + Dali::Property::Index mDaliProperty; + std::vector< std::string > mMethodsCalled; + Dali::Vector3 mSizeSet; + Dali::Vector3 mTargetSize; + bool mNego; + unsigned int mDepth; + + float prop1; + Dali::Vector4 prop2; + Dali::Vector4 develProp3; + int develProp4; + float develProp5; +}; + +inline TestCustomActor& GetImpl( Test::TestCustomActor& handle ) +{ + DALI_ASSERT_ALWAYS( handle ); + Dali::RefObject& object = handle.GetImplementation(); + return static_cast( object ); +} + +inline const TestCustomActor& GetImpl( const Test::TestCustomActor& handle ) +{ + DALI_ASSERT_ALWAYS( handle ); + const Dali::RefObject& object = handle.GetImplementation(); + return static_cast( object ); +} + + +/** + * Variant which adds a new child during OnStageConnection + */ +struct TestCustomActorVariant1 : public TestCustomActor +{ + /** + * Constructor + */ + TestCustomActorVariant1( Dali::Actor childToAdd ) + : mChildToAdd( childToAdd ) + { + } + + // From CustomActorImpl + virtual void OnStageConnection( int depth ) + { + // Chain up first + TestCustomActor::OnStageConnection( depth ); + + // Add the child + Self().Add( mChildToAdd ); + } + + Dali::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(); i #include #include - +#include #include "dali-test-suite-utils/dali-test-suite-utils.h" +#include "test-custom-actor.h" using namespace Dali; @@ -39,774 +40,10 @@ 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; -BaseHandle CreateActor() -{ - return TestCustomActor::New(); -} - -Dali::TypeRegistration mType( typeid(TestCustomActor), typeid(Dali::CustomActor), CreateActor ); - -} // anon namespace - int UtcDaliCustomActorDestructor(void) { @@ -822,7 +59,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 +72,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 +117,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 +157,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 +249,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 +340,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 +390,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 +452,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 +505,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 +563,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 +611,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 +652,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 +681,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 +765,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 +833,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 +848,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,7 +871,7 @@ 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 ); @@ -1652,7 +889,7 @@ 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 +922,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 +955,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 +983,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 +997,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 +1014,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 +1067,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,7 +1088,7 @@ 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; @@ -1869,7 +1106,7 @@ 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; @@ -1887,7 +1124,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); @@ -1906,7 +1143,7 @@ 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; @@ -1958,7 +1195,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 +1222,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 +1254,36 @@ 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 ); + + END_TEST; +} diff --git a/dali/devel-api/file.list b/dali/devel-api/file.list index fa9844f..9d0f677 100644 --- a/dali/devel-api/file.list +++ b/dali/devel-api/file.list @@ -48,6 +48,7 @@ devel_api_core_object_header_files = \ $(devel_api_src_dir)/object/csharp-type-info.h \ $(devel_api_src_dir)/object/csharp-type-registry.h \ $(devel_api_src_dir)/object/handle-devel.h \ + $(devel_api_src_dir)/object/property-helper-devel.h \ $(devel_api_src_dir)/object/weak-handle.h devel_api_core_rendering_header_files = \ diff --git a/dali/devel-api/object/property-helper-devel.h b/dali/devel-api/object/property-helper-devel.h new file mode 100644 index 0000000..0008960 --- /dev/null +++ b/dali/devel-api/object/property-helper-devel.h @@ -0,0 +1,87 @@ +#ifndef __DALI_PROPERTY_HELPER_DEVEL_H__ +#define __DALI_PROPERTY_HELPER_DEVEL_H__ + +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +// INTERNAL INCLUDES +#include + +/** + * @brief These macros are used internally by the property macros. + * Use the the property macros in the section below this one (without the _INTERNAL postfix) when defining properties. + * These internal macros exist as to perform the compile-time check on the enumeration order, the __COUNTER__ macro is used twice. + * Using it twice within the same macro would result in two different values. + */ +#define DALI_DEVEL_PROPERTY_REGISTRATION_INTERNAL( count, typeRegistrationObject, objectNamespace, objectType, develNamespace, text, valueType, enumIndex ) \ + Dali::PropertyRegistration DALI_TOKEN_PASTE( property, count ) ( typeRegistrationObject, text, objectNamespace:: develNamespace ::Property::enumIndex, Dali::Property::valueType, &objectType::SetProperty, &objectType::GetProperty ); \ + DALI_COMPILE_TIME_ASSERT( ( objectNamespace:: develNamespace ::Property::enumIndex - objectNamespace::objectType::PROPERTY_START_INDEX ) == count ); + +/** + * @brief These macros are used to define properties for implementations of CustomActor. + * + * These macros should be used when defining devel properties + * They provide the following benefits: + * - A standard and consistent way to define properties. + * - Concise definition promotes readability, especially with large numbers of properties. + * - Provides a built-in compile-time check. This checks the order of the properties within the enumeration match the order of the property macros. Note: This check is not performed for animatable properties. + * - Enforces how properties are enumerated in the object handles header file. + * + * Note: The compile-type check will produce the following message on failure: + * error: invalid application of 'sizeof' to incomplete type 'Dali::CompileTimeAssertBool' + * + * Macro usage example: + * + * Within the your object's implementation cpp: + * @code + * #include + * ... + * DALI_TYPE_REGISTRATION_BEGIN( MyApp::MyCustomActor, Dali::CustomActor, Create ) + * DALI_DEVEL_PROPERTY_REGISTRATION( MyApp, MyCustomActor, "myProperty", INTEGER, MY_DEVEL_PROPERTY ) + * DALI_TYPE_REGISTRATION_END() + * @endcode + * + * Within your handle's header: + * + * @code + * #include + * + * + * ///< @brief The start and end property ranges for this control. + * enum PropertyRange + * { + * PROPERTY_START_INDEX = Dali::PROPERTY_REGISTRATION_START_INDEX, + * PROPERTY_END_INDEX = PROPERTY_START_INDEX + 1000 + * }; + * + * ///< @brief An enumeration of properties belonging to the Button class. + * struct Property + * { + * enum + * { + * MY_PROPERTY = PROPERTY_START_INDEX ///< @brief name "myProperty", type Integer + * }; + * }; + * @endcode + * + * Using these macros have certain prerequisites on how the property enumeration is defined. + * Please see the Programming Guide (within the generated Doxygen) for full details. + */ +#define DALI_DEVEL_PROPERTY_REGISTRATION( objectNamespace, objectType, text, valueType, enumIndex ) \ + DALI_DEVEL_PROPERTY_REGISTRATION_INTERNAL( __COUNTER__, typeRegistration, objectNamespace, objectType, DALI_TOKEN_PASTE( Devel, objectType ), text, valueType, enumIndex ) + +#endif // __DALI_PROPERTY_HELPER_DEVEL_H__ -- 2.7.4