Add a helper for read-only properties 06/132006/2
authorAdeel Kazmi <adeel.kazmi@samsung.com>
Wed, 31 May 2017 14:17:26 +0000 (15:17 +0100)
committerAdeel Kazmi <adeel.kazmi@samsung.com>
Wed, 31 May 2017 14:23:15 +0000 (15:23 +0100)
Change-Id: I927f26296470cd27d4bd5f9168ac15c5dace0335

automated-tests/src/dali/dali-test-suite-utils/test-custom-actor.cpp
automated-tests/src/dali/dali-test-suite-utils/test-custom-actor.h
automated-tests/src/dali/utc-Dali-CustomActor.cpp
dali/devel-api/object/property-helper-devel.h

index 1463118..758579e 100644 (file)
@@ -245,7 +245,8 @@ TestCustomActor::TestCustomActor()
   mSizeSet( Vector3::ZERO ),
   mTargetSize( Vector3::ZERO ),
   mNego( false ),
-  mDepth(0u)
+  mDepth(0u),
+  develProp6( 10.0f )
 {
 }
 
@@ -254,7 +255,8 @@ TestCustomActor::TestCustomActor(bool nego)
   mDaliProperty( Property::INVALID_INDEX ),
   mSizeSet( Vector3::ZERO ),
   mTargetSize( Vector3::ZERO ),
-  mNego( nego )
+  mNego( nego ),
+  develProp6( 10.0f )
 {
 }
 /**
@@ -500,6 +502,10 @@ Property::Value TestCustomActor::GetProperty( BaseObject* object, Property::Inde
       {
         return Property::Value(actorImpl.develProp5);
       }
+      case Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY6:
+      {
+        return Property::Value(actorImpl.develProp6);
+      }
     }
   }
   return Property::Value();
@@ -518,6 +524,7 @@ DALI_PROPERTY_REGISTRATION( Test, TestCustomActor, "testProperty2", VECTOR4, TES
 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_DEVEL_PROPERTY_REGISTRATION_READ_ONLY( Test, TestCustomActor, "develTestProperty6", FLOAT, DEVEL_TEST_PROPERTY6)
 
 DALI_TYPE_REGISTRATION_END()
 
index c79b4b1..8af0693 100644 (file)
@@ -85,7 +85,8 @@ enum Type
   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
+  DEVEL_TEST_PROPERTY5 = TEST_PROPERTY2+3,
+  DEVEL_TEST_PROPERTY6 = TEST_PROPERTY2+4
 };
 
 } // Namespace Property
@@ -154,6 +155,7 @@ public:
   Dali::Vector4 develProp3;
   int           develProp4;
   float         develProp5;
+  float         develProp6;
 };
 
 inline TestCustomActor& GetImpl( Test::TestCustomActor& handle )
index db7fca7..0449f34 100644 (file)
@@ -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.
@@ -1319,5 +1319,13 @@ int UtcDaliCustomActorSetGetProperty(void)
   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;
 }
index 0008960..67a744b 100644 (file)
@@ -2,7 +2,7 @@
 #define __DALI_PROPERTY_HELPER_DEVEL_H__
 
 /*
- * 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.
   DALI_COMPILE_TIME_ASSERT( ( objectNamespace:: develNamespace ::Property::enumIndex - objectNamespace::objectType::PROPERTY_START_INDEX ) == count );
 
 /**
+ * @copydoc DALI_DEVEL_PROPERTY_REGISTRATION_INTERNAL
+ */
+#define DALI_DEVEL_PROPERTY_REGISTRATION_INTERNAL_READ_ONLY( count, typeRegistrationObject, objectNamespace, objectType, develNamespace, text, valueType, enumIndex ) \
+  Dali::PropertyRegistration DALI_TOKEN_PASTE( property, count ) ( typeRegistrationObject, text, objectNamespace:: develNamespace ::Property::enumIndex, Dali::Property::valueType, NULL, &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
 #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  )
 
+/**
+ * @copydoc DALI_DEVEL_PROPERTY_REGISTRATION
+ *
+ * @note For Read Only properties
+ */
+#define DALI_DEVEL_PROPERTY_REGISTRATION_READ_ONLY( objectNamespace, objectType, text, valueType, enumIndex ) \
+  DALI_DEVEL_PROPERTY_REGISTRATION_INTERNAL_READ_ONLY( __COUNTER__, typeRegistration, objectNamespace, objectType, DALI_TOKEN_PASTE( Devel, objectType ), text, valueType, enumIndex  )
+
 #endif // __DALI_PROPERTY_HELPER_DEVEL_H__