+
+int UtcDaliCustomActorCustomActor(void)
+{
+ Dali::CustomActor customA;
+ Dali::CustomActor customB( customA );
+
+ DALI_TEST_CHECK( customA == customB );
+
+ END_TEST;
+}
+
+int UtcDaliCustomActorImplRelayoutRequest(void)
+{
+ TestApplication application;
+
+ DALI_TEST_CHECK( gOnRelayout == false );
+
+ Test::TestCustomActor custom = Test::TestCustomActor::NewNegoSize();
+ Stage::GetCurrent().Add(custom);
+
+ application.SendNotification();
+ application.Render();
+
+ DALI_TEST_CHECK( gOnRelayout == true );
+ gOnRelayout = false;
+
+ custom.TestRelayoutRequest();
+ application.SendNotification();
+ application.Render();
+
+ DALI_TEST_CHECK( gOnRelayout == true );
+
+ END_TEST;
+}
+
+int UtcDaliCustomActorImplGetHeightForWidthBase(void)
+{
+ TestApplication application;
+ Test::TestCustomActor custom = Test::TestCustomActor::NewNegoSize();
+
+ float width = 300.0f;
+
+ application.SendNotification();
+ application.Render();
+
+ float v = custom.TestGetHeightForWidthBase( width );
+
+ DALI_TEST_CHECK( v == width );
+
+ END_TEST;
+}
+
+int UtcDaliCustomActorImplGetWidthForHeightBase(void)
+{
+ TestApplication application;
+ Test::TestCustomActor custom = Test::TestCustomActor::NewNegoSize();
+
+ float height = 300.0f;
+
+ application.SendNotification();
+ application.Render();
+
+ float v = custom.TestGetWidthForHeightBase( height );
+
+ DALI_TEST_CHECK( v == height );
+
+ END_TEST;
+}
+
+int UtcDaliCustomActorImplCalculateChildSizeBase(void)
+{
+ TestApplication application;
+ Test::TestCustomActor custom = Test::TestCustomActor::NewNegoSize();
+
+ Actor child = Actor::New();
+ child.SetResizePolicy(Dali::ResizePolicy::FIXED, Dali::Dimension::ALL_DIMENSIONS);
+ child.SetSize(150, 150);
+
+ application.SendNotification();
+ application.Render();
+
+ float v = custom.TestCalculateChildSizeBase( child, Dali::Dimension::ALL_DIMENSIONS );
+ DALI_TEST_CHECK( v == 0.0f );
+
+ END_TEST;
+}
+
+int UtcDaliCustomActorImplRelayoutDependentOnChildrenBase(void)
+{
+ TestApplication application;
+ Test::TestCustomActor custom = Test::TestCustomActor::NewNegoSize();
+ custom.SetResizePolicy(Dali::ResizePolicy::FIT_TO_CHILDREN, Dali::Dimension::ALL_DIMENSIONS);
+
+ bool v = custom.TestRelayoutDependentOnChildrenBase( Dali::Dimension::ALL_DIMENSIONS );
+ DALI_TEST_CHECK( v == true );
+
+ application.SendNotification();
+ application.Render();
+
+ 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();
+
+ END_TEST;
+}
+
+int UtcDaliCustomActorTypeRegistry(void)
+{
+ TestApplication application;
+
+ // Register Type
+ TypeInfo type;
+ type = TypeRegistry::Get().GetTypeInfo( "CustomActor" );
+ DALI_TEST_CHECK( type );
+ BaseHandle handle = type.CreateInstance();
+
+ std::string name;
+ std::string exception;
+
+ try
+ {
+ name = handle.GetTypeName();
+ tet_result(TET_FAIL);
+ }
+ catch( DaliException& e )
+ {
+ exception = e.condition;
+ DALI_TEST_EQUALS( exception, "handle && \"BaseObject handle is empty\"", TEST_LOCATION );
+ }
+
+ END_TEST;
+}
+
+
+int UtcDaliCustomActorGetExtensionP(void)
+{
+ TestApplication application;
+
+ Test::TestCustomActor custom = Test::TestCustomActor::NewVariant5();
+
+ DALI_TEST_CHECK( NULL == custom.GetImplementation().GetExtension() );
+
+ END_TEST;
+}
+
+int UtcDaliCustomActorOnConnectionDepth(void)
+{
+ TestApplication application;
+ tet_infoline("Testing Dali::CustomActor::OnStageConnection() hierarchy depth");
+
+ Stage stage = Stage::GetCurrent();
+
+ /* Build tree of actors:
+ *
+ * Depth
+ *
+ * A (parent) 1
+ * / \
+ * B C 2
+ * / \ \
+ * D E F 3
+ *
+ * OnStageConnection should return 1 for A, 2 for B and C, and 3 for D, E and F.
+ */
+
+ Test::TestCustomActor actorA = Test::TestCustomActor::New();
+ stage.Add( actorA );
+
+ Test::TestCustomActor actorB = Test::TestCustomActor::New();
+ actorA.Add( actorB );
+
+ Test::TestCustomActor actorC = Test::TestCustomActor::New();
+ actorA.Add( actorC );
+
+ Test::TestCustomActor actorD = Test::TestCustomActor::New();
+ actorB.Add( actorD );
+
+ Test::TestCustomActor actorE = Test::TestCustomActor::New();
+ actorB.Add( actorE );
+
+ Test::TestCustomActor actorF = Test::TestCustomActor::New();
+ actorC.Add( actorF );
+
+ // Excercise the message passing to Update thread
+ application.SendNotification();
+ application.Render();
+ application.Render();
+
+ DALI_TEST_EQUALS( 1u, actorA.GetDepth(), TEST_LOCATION );
+ DALI_TEST_EQUALS( 2u, actorB.GetDepth(), TEST_LOCATION );
+ DALI_TEST_EQUALS( 2u, actorC.GetDepth(), TEST_LOCATION );
+ DALI_TEST_EQUALS( 3u, actorD.GetDepth(), TEST_LOCATION );
+ DALI_TEST_EQUALS( 3u, actorE.GetDepth(), TEST_LOCATION );
+ DALI_TEST_EQUALS( 3u, actorF.GetDepth(), TEST_LOCATION );
+
+ 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<float>(), 0.5f, 0.001f, TEST_LOCATION );
+
+ value = actor.GetProperty( Test::TestCustomActor::Property::TEST_PROPERTY2 );
+ DALI_TEST_EQUALS( value.Get<Vector4>(), Color::WHITE, 0.001f, TEST_LOCATION );
+
+
+ value = actor.GetProperty( Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY3 );
+ DALI_TEST_EQUALS( value.Get<Vector4>(), Color::BLUE, 0.001f, TEST_LOCATION );
+
+ value = actor.GetProperty( Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY4 );
+ DALI_TEST_EQUALS( value.Get<int>(), 20, TEST_LOCATION );
+
+ value = actor.GetProperty( Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY5 );
+ DALI_TEST_EQUALS( value.Get<float>(), 40.0f, 0.001f, TEST_LOCATION );
+
+ // Get read-only property
+ value = actor.GetProperty( Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY6 );
+ DALI_TEST_EQUALS( value.Get<float>(), 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<float>(), 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<Impl::UnregisteredCustomActor*>( &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<bool>(), 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<Vector3>(), TEST_LOCATION );
+ DALI_TEST_EQUALS( Vector3( 100.0f, 150.0f, 200.0f ), custom.GetCurrentPosition(), TEST_LOCATION );
+
+ Dali::WeakHandle<UnregisteredCustomActor> 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<float>(), 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<float>(), 10.f, TEST_LOCATION );
+
+ END_TEST;
+}
+