+ 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 OnSceneConnection(int32_t depth)
+ {
+ }
+ virtual void OnSceneDisconnection()
+ {
+ }
+ virtual void OnChildAdd(Actor& child)
+ {
+ }
+ virtual void OnChildRemove(Actor& child)
+ {
+ }
+ virtual void OnPropertySet(Property::Index index, const Property::Value& propertyValue)
+ {
+ }
+ virtual void OnSizeSet(const Vector3& targetSize)
+ {
+ }
+ virtual void OnSizeAnimation(Animation& animation, const Vector3& targetSize)
+ {
+ }
+ virtual bool OnHoverEvent(const HoverEvent& 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)
+ {
+ }
+};
+} // namespace Impl
+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();
+ application.GetScene().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.GetCurrentProperty<bool>(Actor::Property::VISIBLE), true, TEST_LOCATION);
+ custom.SetProperty(Actor::Property::VISIBLE, false);
+ application.SendNotification();
+ application.Render(); // IsVisible returns scene value
+ DALI_TEST_EQUALS(custom.GetCurrentProperty<bool>(Actor::Property::VISIBLE), 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.GetCurrentProperty<Vector3>(Actor::Property::POSITION), TEST_LOCATION);
+
+ Dali::WeakHandle<UnregisteredCustomActor> weakRef(custom);
+ // should have actor signals
+ custom.ConnectSignal(&application, "offScene", [weakRef]() {
+ DALI_TEST_EQUALS(weakRef.GetHandle().GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE), false, TEST_LOCATION);
+ });
+
+ application.GetScene().Remove(custom);
+ application.GetScene().Add(custom);
+
+ END_TEST;
+}
+
+namespace Impl
+{
+struct DerivedCustomActor : public UnregisteredCustomActor
+{
+};
+} // namespace Impl
+
+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();
+ application.GetScene().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;
+}
+
+int UtcDaliCustomActorComponentPropertyConstraintsP(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();
+ application.GetScene().Add(derived);
+
+ // should have all actor properties
+ auto actorHandle = Actor::New();
+ DALI_TEST_EQUALS(derived.GetPropertyCount(), actorHandle.GetPropertyCount(), TEST_LOCATION);
+
+ // add a property in base class
+ const Property::Index foobarIndex = ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX;
+ const Property::Index fooIndex = foobarIndex + 1;
+ const Property::Index barIndex = foobarIndex + 2;
+
+ AnimatablePropertyRegistration(typeRegistration, "Foobar", foobarIndex, Vector2(10.0f, 20.0f));
+ AnimatablePropertyComponentRegistration(typeRegistration, "Foobar.x", fooIndex, foobarIndex, 0);
+ AnimatablePropertyComponentRegistration(typeRegistration, "Foobar.y", barIndex, foobarIndex, 1);
+
+ tet_infoline("Test the default values of the registered property");
+ // should be more properties now
+ DALI_TEST_EQUALS(derived.GetPropertyCount(), actorHandle.GetPropertyCount() + 3, TEST_LOCATION);
+ // check that the default value is set for base class
+ DALI_TEST_EQUALS(UnregisteredCustomActor::New().GetProperty(foobarIndex).Get<Vector2>(), Vector2(10.f, 20.0f), 0.0001f, TEST_LOCATION);
+ // check that the default value is set for the derived instance as well
+ DALI_TEST_EQUALS(derived.GetProperty(foobarIndex).Get<Vector2>(), Vector2(10.f, 20.0f), 0.0001f, TEST_LOCATION);
+
+ tet_infoline("Test that the components of the registered property can be constrained");
+
+ // Try constraining the properties
+ Constraint fooCons = Constraint::New<float>(derived, fooIndex, &Test::Doubler);
+ fooCons.AddSource(LocalSource(Actor::Property::POSITION_X));
+ fooCons.Apply();
+ Constraint barCons = Constraint::New<float>(derived, barIndex, &Test::Doubler);
+ barCons.AddSource(LocalSource(fooIndex));
+ barCons.Apply();
+
+ for(int i = 1; i < 10; ++i)
+ {
+ derived[Actor::Property::POSITION_X] = i * 1.0f;
+ application.SendNotification();
+ application.Render();
+ DALI_TEST_EQUALS(derived.GetCurrentProperty(foobarIndex).Get<Vector2>(), Vector2(i * 2.0f, i * 4.0f), 0.0001f, TEST_LOCATION);
+ }
+
+ // Add a Vector3 property and its components for completeness
+ const Property::Index vec3PropIndex = barIndex + 1;
+ const Property::Index vec3xPropIndex = vec3PropIndex + 1;
+ const Property::Index vec3yPropIndex = vec3PropIndex + 2;
+ const Property::Index vec3zPropIndex = vec3PropIndex + 3;
+
+ AnimatablePropertyRegistration(typeRegistration, "vec3Prop", vec3PropIndex, Vector3(10.0f, 20.0f, 30.0f));
+ AnimatablePropertyComponentRegistration(typeRegistration, "vec3Prop.x", vec3xPropIndex, vec3PropIndex, 0);
+ AnimatablePropertyComponentRegistration(typeRegistration, "vec3Prop.y", vec3yPropIndex, vec3PropIndex, 1);
+ AnimatablePropertyComponentRegistration(typeRegistration, "vec3Prop.z", vec3zPropIndex, vec3PropIndex, 2);
+
+ tet_infoline("Test the default values of the registered vec3 property");
+ // should be more properties now
+ DALI_TEST_EQUALS(derived.GetPropertyCount(), actorHandle.GetPropertyCount() + 7, TEST_LOCATION);
+ // check that the default value is set for base class
+ DALI_TEST_EQUALS(UnregisteredCustomActor::New().GetProperty(vec3PropIndex).Get<Vector3>(), Vector3(10.f, 20.0f, 30.0f), 0.0001f, TEST_LOCATION);
+ // check that the default value is set for the derived instance as well
+ DALI_TEST_EQUALS(derived.GetProperty(vec3PropIndex).Get<Vector3>(), Vector3(10.f, 20.0f, 30.0f), 0.0001f, TEST_LOCATION);
+
+ tet_infoline("Test that the components of the registered property can be constrained");
+
+ // Try constraining the properties
+ Constraint vec3xConstraint = Constraint::New<float>(derived, vec3xPropIndex, &Test::Doubler);
+ vec3xConstraint.AddSource(LocalSource(Actor::Property::POSITION_X));
+ vec3xConstraint.Apply();
+ Constraint vec3yConstraint = Constraint::New<float>(derived, vec3yPropIndex, &Test::Doubler);
+ vec3yConstraint.AddSource(LocalSource(vec3xPropIndex));
+ vec3yConstraint.Apply();
+ Constraint vec3zConstraint = Constraint::New<float>(derived, vec3zPropIndex, &Test::Doubler);
+ vec3zConstraint.AddSource(LocalSource(vec3yPropIndex));
+ vec3zConstraint.Apply();
+
+ for(int i = 1; i < 10; ++i)
+ {
+ derived[Actor::Property::POSITION_X] = i * 1.0f;
+ application.SendNotification();
+ application.Render();
+ DALI_TEST_EQUALS(derived.GetCurrentProperty(vec3PropIndex).Get<Vector3>(), Vector3(i * 2.0f, i * 4.0f, i * 8.0f), 0.0001f, TEST_LOCATION);
+ }