Remove error message when we set/get AnimatableProperty 25/321825/2
authorEunki Hong <eunkiki.hong@samsung.com>
Fri, 28 Mar 2025 14:48:11 +0000 (23:48 +0900)
committerEunki Hong <eunkiki.hong@samsung.com>
Fri, 28 Mar 2025 15:17:50 +0000 (00:17 +0900)
We only need to call setFunc/getFunc only if it exist.
Until now, it check as error if sefFunc/getFunc not exist.

Change-Id: I534e9dd2f7b76e9a50db1935931eea99cc1b70ca
Signed-off-by: Eunki Hong <eunkiki.hong@samsung.com>
automated-tests/src/dali/utc-Dali-TypeRegistry.cpp
dali/internal/event/common/type-info-impl.cpp

index c1899a621de2f45f66dae17758e8aa487994cfaf..3e1eb862fa7121844603370c499a01ad87997c76 100644 (file)
@@ -112,6 +112,11 @@ Property::Value GetProperty(BaseObject* object, Property::Index propertyIndex)
   getPropertyCalled = true;
   return Property::Value(true);
 }
+Property::Value GetPropertyWithEmptyValueReturn(BaseObject* object, Property::Index propertyIndex)
+{
+  getPropertyCalled = true;
+  return Property::Value();
+}
 
 /*******************************************************************************
  *
@@ -1698,6 +1703,132 @@ int UtcDaliTypeRegistryAnimatablePropertyComponentRegistrationN(void)
   END_TEST;
 }
 
+int UtcDaliTypeRegistryAnimatablePropertyRegistrationWithSetGetFunctionP(void)
+{
+  TestApplication application;
+  TypeRegistry    typeRegistry = TypeRegistry::Get();
+
+  // Check property count before property registration
+  TypeInfo typeInfo = typeRegistry.GetTypeInfo(typeid(MyTestCustomActor));
+  DALI_TEST_CHECK(typeInfo);
+  BaseHandle handle = typeInfo.CreateInstance();
+  DALI_TEST_CHECK(handle);
+  Actor customActor = Actor::DownCast(handle);
+  DALI_TEST_CHECK(customActor);
+  application.GetScene().Add(customActor);
+
+  unsigned int customPropertyCount(customActor.GetPropertyCount());
+
+  // Register animatable property
+  std::string                    animatablePropertyName("animatableProp1");
+  int                            animatablePropertyIndex(ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX);
+  Property::Type                 animatablePropertyType(Property::FLOAT);
+  AnimatablePropertyRegistration animatableProperty(customType1, animatablePropertyName, animatablePropertyIndex, animatablePropertyType, &SetProperty, &GetPropertyWithEmptyValueReturn);
+
+  // Check property count after registration
+  DALI_TEST_EQUALS(customPropertyCount + 1u, customActor.GetPropertyCount(), TEST_LOCATION);
+
+  // Set the animatable property value
+  DALI_TEST_CHECK(!setPropertyCalled);
+  customActor.SetProperty(animatablePropertyIndex, 25.0f);
+  DALI_TEST_CHECK(setPropertyCalled);
+  setPropertyCalled = false;
+
+  // Render and notify
+  application.SendNotification();
+  application.Render();
+
+  // Check the animatable property value
+  DALI_TEST_CHECK(!getPropertyCalled);
+  DALI_TEST_EQUALS(customActor.GetProperty<float>(animatablePropertyIndex), 25.f, TEST_LOCATION);
+  DALI_TEST_CHECK(getPropertyCalled);
+  getPropertyCalled = false;
+
+  // check that the property is animatable
+  Animation animation = Animation::New(0.2f);
+  animation.AnimateTo(Property(customActor, animatablePropertyIndex), 15.f, AlphaFunction::LINEAR);
+  animation.Play();
+
+  // TODO : This behavior might be changed in future! For now, AnimateTo or Play didn't call setFunc/getFunc
+  DALI_TEST_CHECK(!setPropertyCalled);
+  DALI_TEST_CHECK(!getPropertyCalled);
+
+  // Target value should change straight away
+  DALI_TEST_EQUALS(customActor.GetProperty<float>(animatablePropertyIndex), 15.0f, TEST_LOCATION);
+  DALI_TEST_CHECK(getPropertyCalled);
+  getPropertyCalled = false;
+
+  // Render and notify, animation play for 0.05 seconds
+  application.SendNotification();
+  application.Render(50);
+  DALI_TEST_EQUALS(0.25f, animation.GetCurrentProgress(), TEST_LOCATION);
+  DALI_TEST_EQUALS(customActor.GetCurrentProperty<float>(animatablePropertyIndex), 22.5f, TEST_LOCATION);
+
+  // TODO : This behavior might be changed in future! For now, GetCurrentProperty didn't call getFunc
+  DALI_TEST_CHECK(!getPropertyCalled);
+
+  // Render and notify, animation play for another 0.1 seconds
+  application.SendNotification();
+  application.Render(100);
+  DALI_TEST_EQUALS(0.75f, animation.GetCurrentProgress(), TEST_LOCATION);
+  DALI_TEST_EQUALS(customActor.GetCurrentProperty<float>(animatablePropertyIndex), 17.5f, TEST_LOCATION);
+
+  DALI_TEST_CHECK(!getPropertyCalled);
+
+  END_TEST;
+}
+
+int UtcDaliTypeRegistryAnimatablePropertyRegistrationWithSetGetFunctionN01(void)
+{
+  TestApplication application;
+  TypeRegistry    typeRegistry = TypeRegistry::Get();
+
+  // Attempt to register an animatable property type out-of-bounds index (less than)
+  try
+  {
+    AnimatablePropertyRegistration property1(customType1, "animPropName", ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX - 1, Property::BOOLEAN, &SetProperty, &GetProperty);
+    tet_result(TET_FAIL);
+  }
+  catch(DaliException& e)
+  {
+    DALI_TEST_ASSERT(e, "(index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX) && (index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX)", TEST_LOCATION);
+  }
+
+  // Attempt to register an animatable property type out-of-bounds index (greater than)
+  try
+  {
+    AnimatablePropertyRegistration property1(customType1, "animPropName", ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX + 1, Property::BOOLEAN, &SetProperty, &GetProperty);
+    tet_result(TET_FAIL);
+  }
+  catch(DaliException& e)
+  {
+    DALI_TEST_ASSERT(e, "(index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX) && (index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX)", TEST_LOCATION);
+  }
+
+  END_TEST;
+}
+
+int UtcDaliTypeRegistryAnimatablePropertyRegistrationWithSetGetFunctionN02(void)
+{
+  TestApplication application;
+  TypeRegistry    typeRegistry = TypeRegistry::Get();
+
+  AnimatablePropertyRegistration property1(customType1, "animPropName", ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 1, Property::BOOLEAN, &SetProperty, &GetProperty);
+
+  // Attempt to register an animatable property with the same index
+  try
+  {
+    AnimatablePropertyRegistration property1(customType1, "animPropName2", ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 1, Property::BOOLEAN, &SetProperty, &GetProperty);
+    tet_result(TET_FAIL);
+  }
+  catch(DaliException& e)
+  {
+    DALI_TEST_ASSERT(e, "!\"Property index already added to Type\"", TEST_LOCATION);
+  }
+
+  END_TEST;
+}
+
 int UtcDaliTypeRegistryChildPropertyRegistrationP(void)
 {
   TestApplication application;
index 4a1657c727db4219cd7ff0ade2be6921a29b48d3..434473956f31dc9301c44538f41e651bdbbb1e1a 100644 (file)
@@ -895,9 +895,12 @@ Property::Value TypeInfo::GetPropertyDefaultValue(Property::Index index) const
 void TypeInfo::SetAnimatableProperty(BaseObject* object, Property::Index index, Property::Value value) const
 {
   const auto& iter = mRegisteredProperties.Get(static_cast<std::uint32_t>(index));
-  if(iter != mRegisteredProperties.end() && iter->second.setFunc)
+  if(iter != mRegisteredProperties.end())
   {
-    iter->second.setFunc(object, index, value);
+    if(iter->second.setFunc)
+    {
+      iter->second.setFunc(object, index, value);
+    }
   }
   else if(GetBaseType(mBaseType, mTypeRegistry, mBaseTypeName))
   {
@@ -988,9 +991,12 @@ void TypeInfo::SetProperty(BaseObject* object, const std::string& name, Property
 Property::Value TypeInfo::GetAnimatableProperty(const BaseObject* object, Property::Index index) const
 {
   const auto& iter = mRegisteredProperties.Get(static_cast<std::uint32_t>(index));
-  if(iter != mRegisteredProperties.end() && iter->second.getFunc)
+  if(iter != mRegisteredProperties.end())
   {
-    return iter->second.getFunc(const_cast<BaseObject*>(object), index);
+    if(iter->second.getFunc)
+    {
+      return iter->second.getFunc(const_cast<BaseObject*>(object), index);
+    }
   }
   else if(GetBaseType(mBaseType, mTypeRegistry, mBaseTypeName))
   {