Merge "Use TextureSet instead when sorting render items." into devel/master
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-TypeRegistry.cpp
index 9f0aced..8362803 100644 (file)
@@ -20,6 +20,7 @@
 #include <limits>
 #include <dali/public-api/dali-core.h>
 #include <dali-test-suite-utils.h>
+#include <dali/internal/event/common/type-info-impl.h>
 #include <dali/integration-api/events/long-press-gesture-event.h>
 #include <dali/integration-api/events/pan-gesture-event.h>
 #include <dali/integration-api/events/pinch-gesture-event.h>
@@ -356,6 +357,16 @@ class MyTestCustomActor2 : public CustomActor
 {
 public:
 
+  struct Property
+  {
+    enum
+    {
+      P1=Dali::PROPERTY_REGISTRATION_START_INDEX,
+      P2
+    };
+  };
+
+
   MyTestCustomActor2()
   {
   }
@@ -404,6 +415,60 @@ private:
 
 static TypeRegistration customTypeInit( typeid(MyTestCustomActor2), typeid(Dali::CustomActor), CreateCustomInit, true );
 
+PropertyRegistration P1( customTypeInit, "propertyOne", MyTestCustomActor2::Property::P1, Property::INTEGER, &SetProperty, &GetProperty );
+PropertyRegistration P2( customTypeInit, "propertyTwo", MyTestCustomActor2::Property::P2, Property::STRING, &SetProperty, &GetProperty );
+
+
+class MyTestCustomActor3 : public CustomActor
+{
+public:
+  MyTestCustomActor3()
+  {
+  }
+
+  static MyTestCustomActor3 New()
+  {
+    return MyTestCustomActor3(); // takes ownership
+  }
+
+  virtual ~MyTestCustomActor3()
+  {
+  }
+
+  static MyTestCustomActor3 DownCast( BaseHandle handle )
+  {
+    MyTestCustomActor3 result;
+
+    CustomActor custom = Dali::CustomActor::DownCast( handle );
+    if ( custom )
+    {
+      CustomActorImpl& customImpl = custom.GetImplementation();
+
+      Impl::MyTestCustomActor* impl = dynamic_cast<Impl::MyTestCustomActor*>(&customImpl);
+
+      if (impl)
+      {
+        result = MyTestCustomActor3(customImpl.GetOwner());
+      }
+    }
+
+    return result;
+  }
+
+private:
+
+  MyTestCustomActor3(Internal::CustomActor* internal)
+  : CustomActor(internal)
+  {
+  }
+
+  MyTestCustomActor3( Impl::MyTestCustomActor& impl )
+  : CustomActor( impl )
+  {
+  }
+};
+
+static TypeRegistration customTypeBadInit( typeid(MyTestCustomActor3), typeid(Dali::CustomActor), NULL, false );
 
 BaseHandle CreateCustom(void)
 {
@@ -779,7 +844,6 @@ int UtcDaliTypeRegistryTypeRegistrationForNamedTypeP(void)
   END_TEST;
 }
 
-// Note: No negative test case for UtcDaliTypeRegistryRegisteredName can be implemented.
 int UtcDaliTypeRegistryRegisteredNameP(void)
 {
   TestApplication application;
@@ -797,6 +861,32 @@ int UtcDaliTypeRegistryRegisteredNameP(void)
   END_TEST;
 }
 
+
+int UtcDaliTypeRegistryRegisteredNameN(void)
+{
+  TestApplication application;
+
+  DALI_TEST_CHECK( scriptedName == scriptedType.RegisteredName() );
+
+  TypeInfo baseType = TypeRegistry::Get().GetTypeInfo( scriptedName );
+  DALI_TEST_CHECK( baseType );
+
+  // should cause an assert because we're registering same type twice
+  // once statically at the start of this file, then again now
+  try
+  {
+    TypeRegistration scriptedType( scriptedName, typeid(Dali::CustomActor), CreateCustomNamedInit );
+    tet_result( TET_FAIL );
+  }
+  catch ( DaliException& e )
+  {
+    DALI_TEST_ASSERT( e, "Duplicate type name for Type Registation", TEST_LOCATION );
+  }
+
+  END_TEST;
+}
+
+
 int UtcDaliTypeRegistrySignalConnectorTypeP(void)
 {
   ResetFunctorCounts();
@@ -976,7 +1066,10 @@ int UtcDaliTypeRegistryPropertyRegistrationP(void)
   // Check property count of type-info is 1
   Property::IndexContainer indices;
   typeInfo.GetPropertyIndices( indices );
+
+  size_t typePropertyCount = typeInfo.GetPropertyCount();
   DALI_TEST_EQUALS( indices.Size(), 1u, TEST_LOCATION );
+  DALI_TEST_EQUALS( indices.Size(), typePropertyCount, TEST_LOCATION );
 
   // Ensure indices returned from actor and customActor differ by two
   Actor actor = Actor::New();
@@ -1424,11 +1517,23 @@ int UtcDaliTypeRegistryChildPropertyRegistrationP(void)
   // Check property count are not changed because the child properties will not be created for the parent
   DALI_TEST_EQUALS( initialPropertyCount, customActor.GetPropertyCount(), TEST_LOCATION );
 
+  // check the child property type
+  Internal::TypeInfo& typeInfoImpl = GetImplementation( typeInfo );
+  Property::Type type = typeInfoImpl.GetChildPropertyType( typeInfoImpl.GetChildPropertyIndex("childProp4") );
+  DALI_TEST_EQUALS( type, Property::INTEGER, TEST_LOCATION );
+
+
   // Create a child actor
   Actor childActor = Actor::New();
   DALI_TEST_CHECK( childActor );
   unsigned int initialChildActorPropertyCount( childActor.GetPropertyCount() );
 
+  // The type of child properties should be Property::None as the child hasn't registered any child property yet.
+  DALI_TEST_EQUALS( childActor.GetPropertyType( propertyIndex ), Property::NONE, TEST_LOCATION );
+  DALI_TEST_EQUALS( childActor.GetPropertyType( propertyIndex2 ), Property::NONE, TEST_LOCATION );
+  DALI_TEST_EQUALS( childActor.GetPropertyType( propertyIndex3 ), Property::NONE, TEST_LOCATION );
+  DALI_TEST_EQUALS( childActor.GetPropertyType( propertyIndex4 ), Property::NONE, TEST_LOCATION );
+
   // Set the value for the first child property when the child actor doesn't have a parent yet
   childActor.SetProperty(propertyIndex, true);
 
@@ -1577,6 +1682,7 @@ int UtcDaliTypeRegistryChildPropertyRegistrationP(void)
   // Should return the child property index by given its name
   DALI_TEST_EQUALS( childActor.GetPropertyIndex( newPropertyName ), newPropertyIndex, TEST_LOCATION );
 
+
   END_TEST;
 }
 
@@ -1713,7 +1819,7 @@ int UtcDaliPropertyRegistrationAddSameIndex(void)
   END_TEST;
 }
 
-int UtcDaliPropertyRegistrationPropertyWritable(void)
+int UtcDaliPropertyRegistrationPropertyWritableP(void)
 {
   TestApplication application;
   int propertyIndex1 = PROPERTY_REGISTRATION_START_INDEX + 200;
@@ -1734,9 +1840,36 @@ int UtcDaliPropertyRegistrationPropertyWritable(void)
   // Check whether properties are writable
   DALI_TEST_CHECK(   customActor.IsPropertyWritable( propertyIndex1 ) );
   DALI_TEST_CHECK( ! customActor.IsPropertyWritable( propertyIndex2 ) );
+
+
+  // Check the property is writable in the type registry
+  Internal::TypeInfo& typeInfoImpl = GetImplementation( typeInfo );
+
+  DALI_TEST_EQUALS( typeInfoImpl.IsPropertyWritable( propertyIndex1 ), true, TEST_LOCATION );
+
   END_TEST;
 }
 
+int UtcDaliPropertyRegistrationPropertyWritableN(void)
+{
+  // Currently Actors don't register properties with the type registry
+
+  TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( typeid(MyTestCustomActor) );
+  Internal::TypeInfo& typeInfoImpl = GetImplementation( typeInfo );
+
+  try
+  {
+    typeInfoImpl.IsPropertyWritable( Actor::Property::COLOR);
+    tet_result( TET_FAIL );
+
+  }
+  catch ( DaliException& e )
+  {
+     DALI_TEST_ASSERT( e, "Cannot find property index", TEST_LOCATION );
+  }
+  END_TEST;
+
+}
 int UtcDaliPropertyRegistrationPropertyAnimatable(void)
 {
   TestApplication application;
@@ -2018,6 +2151,25 @@ int UtcDaliTypeInfoGetActionNameP(void)
 
   DALI_TEST_EQUALS( name, "show", TEST_LOCATION );
 
+
+  TypeInfo typeInfo2 = typeRegistry.GetTypeInfo( "MyTestCustomActor" );
+
+  //  search for show action in base class, given a derived class
+  bool foundChildAction = false;
+  for( std::size_t i = 0; i < typeInfo2.GetActionCount(); i++ )
+  {
+
+       std::string name = typeInfo2.GetActionName( i );
+       if( name == "show")
+       {
+         foundChildAction = true;
+       }
+
+  }
+
+  DALI_TEST_EQUALS( foundChildAction, true, TEST_LOCATION );
+
+
   END_TEST;
 }
 
@@ -2052,6 +2204,23 @@ int UtcDaliTypeInfoGetSignalNameP(void)
 
   DALI_TEST_EQUALS( name, "touched", TEST_LOCATION );
 
+  TypeInfo typeInfo2 = typeRegistry.GetTypeInfo( "MyTestCustomActor" );
+
+  //  search for signal in base class, given a derived class
+  bool foundSignal = false;
+  for( std::size_t i = 0; i < typeInfo2.GetSignalCount(); i++ )
+  {
+
+       std::string name = typeInfo2.GetSignalName( i );
+       if( name == "touched")
+       {
+         foundSignal = true;
+       }
+
+  }
+
+  DALI_TEST_EQUALS( foundSignal, true, TEST_LOCATION );
+
   END_TEST;
 }
 
@@ -2071,3 +2240,68 @@ int UtcDaliTypeInfoGetSignalNameN(void)
 
   END_TEST;
 }
+
+
+int UtcDaliTypeInfoGetCreatorP(void)
+{
+  TestApplication application;
+  TypeRegistry typeRegistry = TypeRegistry::Get();
+
+  TypeInfo typeInfo = typeRegistry.GetTypeInfo( "Actor" );
+  DALI_TEST_CHECK( typeInfo );
+
+  TypeInfo::CreateFunction createFn = typeInfo.GetCreator();
+  DALI_TEST_EQUALS( createFn != NULL, true, TEST_LOCATION );
+  if( createFn )
+  {
+    // try calling it:
+    BaseHandle handle = createFn();
+    DALI_TEST_EQUALS( (bool)handle, true, TEST_LOCATION );
+  }
+
+  END_TEST;
+}
+
+int UtcDaliTypeInfoGetCreatorN(void)
+{
+  TestApplication application;
+  TypeRegistry typeRegistry = TypeRegistry::Get();
+
+  TypeInfo typeInfo = typeRegistry.GetTypeInfo( "MyTestCustomActor3" );
+  DALI_TEST_CHECK( typeInfo );
+
+  TypeInfo::CreateFunction createFn = typeInfo.GetCreator();
+  DALI_TEST_EQUALS( createFn == NULL, true, TEST_LOCATION );
+
+  END_TEST;
+}
+
+int UtcDaliTypeInfoGetPropertyCountP1(void)
+{
+  TestApplication application;
+  TypeRegistry typeRegistry = TypeRegistry::Get();
+
+  TypeInfo typeInfo = typeRegistry.GetTypeInfo( "Actor" );
+  DALI_TEST_CHECK( typeInfo );
+  size_t actorPropertyCount = typeInfo.GetPropertyCount();
+
+  DALI_TEST_EQUALS( actorPropertyCount == 0 , true, TEST_LOCATION ); // No event only props
+  END_TEST;
+}
+
+int UtcDaliTypeInfoGetPropertyCountP2(void)
+{
+  TestApplication application;
+  TypeRegistry typeRegistry = TypeRegistry::Get();
+
+  TypeInfo typeInfo = typeRegistry.GetTypeInfo( "MyTestCustomActor2" );
+  DALI_TEST_CHECK( typeInfo );
+  size_t propertyCount = typeInfo.GetPropertyCount();
+  Property::IndexContainer indices;
+  typeInfo.GetPropertyIndices( indices );
+
+  DALI_TEST_EQUALS( propertyCount > 0 && propertyCount <= indices.Size(), true, TEST_LOCATION );
+  DALI_TEST_EQUALS( propertyCount == 2, true, TEST_LOCATION );
+
+  END_TEST;
+}