(Properties) Ensure TypeInfo is set when creating Type via TypeInfo 93/20293/1
authorAdeel Kazmi <adeel.kazmi@samsung.com>
Thu, 3 Apr 2014 14:30:24 +0000 (15:30 +0100)
committerDavid Steele <david.steele@partner.samsung.com>
Thu, 1 May 2014 14:38:26 +0000 (15:38 +0100)
[Problem]  When created named types, the wrong type-info is used
           when setting/getting properties.
[Cause]    Gets the type-info related to the current type as it
           does not know how it was created.
[Solution] Set the type-info when creating the object.

Change-Id: I3942ccf7c2c3ba36601dae1c4dd79f64a3c64e2c
Signed-off-by: Adeel Kazmi <adeel.kazmi@samsung.com>
automated-tests/src/dali-unmanaged/utc-Dali-TypeRegistry.cpp
dali/internal/event/common/proxy-object.cpp
dali/internal/event/common/proxy-object.h
dali/internal/event/common/type-info-impl.cpp

index 2e7265a..12a8eb3 100644 (file)
@@ -467,6 +467,16 @@ public:
   }
 };
 
+BaseHandle CreateNamedActorType()
+{
+  Actor actor = Actor::New();
+  actor.SetName( "NamedActor" );
+  return actor;
+}
+
+TypeRegistration namedActorType( "MyNamedActor", typeid(Dali::Actor), CreateNamedActorType );
+PropertyRegistration namedActorPropertyOne( namedActorType, "prop-name", PROPERTY_REGISTRATION_START_INDEX, Property::BOOLEAN, &SetProperty, &GetProperty );
+
 } // Anonymous namespace
 
 
@@ -1109,3 +1119,27 @@ int UtcDaliTapGestureDetectorTypeRegistry(void)
   DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
   END_TEST;
 }
+
+int UtcDaliTypeRegistryNamedType(void)
+{
+  TestApplication application;
+  TypeRegistry typeRegistry = TypeRegistry::Get();
+
+  // Create a normal actor
+  BaseHandle actorHandle = typeRegistry.GetTypeInfo( "Actor" ).CreateInstance();
+  DALI_TEST_CHECK( actorHandle );
+  Actor actor( Actor::DownCast( actorHandle ) );
+  DALI_TEST_CHECK( actor );
+  unsigned int actorPropertyCount( actor.GetPropertyCount() );
+
+  // Create Named Actor Type
+  BaseHandle namedHandle = typeRegistry.GetTypeInfo( "MyNamedActor" ).CreateInstance();
+  DALI_TEST_CHECK( namedHandle );
+  Actor namedActor( Actor::DownCast( namedHandle ) );
+  DALI_TEST_CHECK( namedActor );
+  unsigned int namedActorPropertyCount( namedActor.GetPropertyCount() );
+
+  DALI_TEST_CHECK( namedActorPropertyCount > actorPropertyCount );
+  END_TEST;
+}
+
index c1fe6c9..7a65d44 100644 (file)
@@ -1006,7 +1006,10 @@ void ProxyObject::RemoveConstraints()
   }
 }
 
-
+void ProxyObject::SetTypeInfo( TypeInfo* typeInfo )
+{
+  mTypeInfo = typeInfo;
+}
 
 ProxyObject::~ProxyObject()
 {
index 4f4bfd3..f409117 100644 (file)
@@ -281,6 +281,14 @@ public: // Constraints
    */
   void RemoveConstraints( unsigned int tag );
 
+public: // Called by TypeInfo
+
+  /**
+   * Called by TypeInfo to set the type-info that this proxy-object is created by.
+   * @param[in] typeInfo The TypeInfo that creates this proxy-object.
+   */
+  void SetTypeInfo( TypeInfo* typeInfo );
+
 protected:
 
   /**
index 5a237d9..9dcbedd 100644 (file)
@@ -24,6 +24,7 @@
 // INTERNAL INCLUDES
 #include <dali/integration-api/debug.h>
 #include <dali/internal/event/common/type-registry-impl.h>
+#include <dali/internal/event/common/proxy-object.h>
 
 using std::find_if;
 
@@ -98,6 +99,17 @@ BaseHandle TypeInfo::CreateInstance()
   if(mCreate)
   {
     ret = mCreate();
+
+    if ( ret )
+    {
+      BaseObject& handle = ret.GetBaseObject();
+      ProxyObject *proxyObject = dynamic_cast<Internal::ProxyObject*>(&handle);
+
+      if ( proxyObject )
+      {
+        proxyObject->SetTypeInfo( this );
+      }
+    }
   }
   return ret;
 }