Merge Handle & Constrainable
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-Handle.cpp
index 8587420..cf49f4a 100644 (file)
@@ -36,6 +36,15 @@ void handle_test_cleanup(void)
 namespace
 {
 
+/// Allows the creation of a BaseObject
+class BaseObjectType : public BaseObject
+{
+public:
+  BaseObjectType()
+  {
+  }
+};
+
 Handle ImplicitCopyConstructor(Handle passedByValue)
 {
   // object + copy + passedByValue, ref count == 3
@@ -405,12 +414,13 @@ int UtcDaliHandleIsPropertyAConstraintInput(void)
   DALI_TEST_CHECK( false == actor.IsPropertyAConstraintInput( Actor::NAME ) );
   DALI_TEST_CHECK( false == actor.IsPropertyAConstraintInput( Actor::SENSITIVE ) );
   DALI_TEST_CHECK( false == actor.IsPropertyAConstraintInput( Actor::LEAVE_REQUIRED ) );
-  DALI_TEST_CHECK( false == actor.IsPropertyAConstraintInput( Actor::INHERIT_SHADER_EFFECT ) );
   DALI_TEST_CHECK( false == actor.IsPropertyAConstraintInput( Actor::INHERIT_ROTATION ) );
   DALI_TEST_CHECK( false == actor.IsPropertyAConstraintInput( Actor::INHERIT_SCALE ) );
   DALI_TEST_CHECK( false == actor.IsPropertyAConstraintInput( Actor::COLOR_MODE ) );
   DALI_TEST_CHECK( false == actor.IsPropertyAConstraintInput( Actor::POSITION_INHERITANCE ) );
   DALI_TEST_CHECK( false == actor.IsPropertyAConstraintInput( Actor::DRAW_MODE ) );
+  DALI_TEST_CHECK( false == actor.IsPropertyAConstraintInput( Actor::SIZE_MODE ) );
+  DALI_TEST_CHECK( false == actor.IsPropertyAConstraintInput( Actor::SIZE_MODE_FACTOR ) );
 
   END_TEST;
 }
@@ -435,6 +445,7 @@ int UtcDaliHandleGetPropertyType(void)
   // Register some dynamic properties
   Property::Index boolIndex     = actor.RegisterProperty( "bool-property",     bool(true) );
   Property::Index floatIndex    = actor.RegisterProperty( "float-property",    float(123.0f) );
+  Property::Index intIndex      = actor.RegisterProperty( "int-property",      123 );
   Property::Index vector2Index  = actor.RegisterProperty( "vector2-property",  Vector2(1.0f, 2.0f) );
   Property::Index vector3Index  = actor.RegisterProperty( "vector3-property",  Vector3(1.0f, 2.0f, 3.0f) );
   Property::Index vector4Index  = actor.RegisterProperty( "vector4-property",  Vector4(1.0f, 2.0f, 3.0f, 4.0f) );
@@ -442,6 +453,7 @@ int UtcDaliHandleGetPropertyType(void)
 
   DALI_TEST_CHECK( Property::BOOLEAN  == actor.GetPropertyType( boolIndex ) );
   DALI_TEST_CHECK( Property::FLOAT    == actor.GetPropertyType( floatIndex ) );
+  DALI_TEST_CHECK( Property::INTEGER  == actor.GetPropertyType( intIndex ) );
   DALI_TEST_CHECK( Property::VECTOR2  == actor.GetPropertyType( vector2Index ) );
   DALI_TEST_CHECK( Property::VECTOR3  == actor.GetPropertyType( vector3Index ) );
   DALI_TEST_CHECK( Property::VECTOR4  == actor.GetPropertyType( vector4Index ) );
@@ -454,6 +466,7 @@ int UtcDaliHandleGetPropertyType(void)
   Property::Index nonAnimV4Index = actor.RegisterProperty( "v4", Vector4(1.f, 2.f, 3.f, 4.f), Property::READ_WRITE);
   Property::Index nonAnimBooleanIndex = actor.RegisterProperty( "bool", true, Property::READ_WRITE);
   Property::Index nonAnimFloatIndex = actor.RegisterProperty( "float", 0.f, Property::READ_WRITE);
+  Property::Index nonAnimIntegerIndex = actor.RegisterProperty( "int", 0, Property::READ_WRITE);
   Property::Index nonAnimUnsignedIntIndex = actor.RegisterProperty( "unsinged-int", unsingedIntTest, Property::READ_WRITE);
 
   DALI_TEST_CHECK( nonAnimStringIndex  != Property::INVALID_INDEX );
@@ -462,6 +475,7 @@ int UtcDaliHandleGetPropertyType(void)
   DALI_TEST_CHECK( nonAnimV4Index      != Property::INVALID_INDEX );
   DALI_TEST_CHECK( nonAnimBooleanIndex != Property::INVALID_INDEX );
   DALI_TEST_CHECK( nonAnimFloatIndex   != Property::INVALID_INDEX );
+  DALI_TEST_CHECK( nonAnimIntegerIndex != Property::INVALID_INDEX );
   DALI_TEST_CHECK( nonAnimUnsignedIntIndex != Property::INVALID_INDEX );
 
   DALI_TEST_CHECK( Property::STRING   == actor.GetPropertyType( nonAnimStringIndex ) );
@@ -470,6 +484,7 @@ int UtcDaliHandleGetPropertyType(void)
   DALI_TEST_CHECK( Property::VECTOR4  == actor.GetPropertyType( nonAnimV4Index ) );
   DALI_TEST_CHECK( Property::BOOLEAN  == actor.GetPropertyType( nonAnimBooleanIndex ) );
   DALI_TEST_CHECK( Property::FLOAT    == actor.GetPropertyType( nonAnimFloatIndex ) );
+  DALI_TEST_CHECK( Property::INTEGER  == actor.GetPropertyType( nonAnimIntegerIndex ) );
   DALI_TEST_CHECK( Property::UNSIGNED_INTEGER == actor.GetPropertyType( nonAnimUnsignedIntIndex ) );
 
   DALI_TEST_CHECK( !actor.IsPropertyAnimatable( nonAnimStringIndex ) );
@@ -478,6 +493,7 @@ int UtcDaliHandleGetPropertyType(void)
   DALI_TEST_CHECK( !actor.IsPropertyAnimatable( nonAnimV4Index ) );
   DALI_TEST_CHECK( !actor.IsPropertyAnimatable( nonAnimBooleanIndex ) );
   DALI_TEST_CHECK( !actor.IsPropertyAnimatable( nonAnimFloatIndex ) );
+  DALI_TEST_CHECK( !actor.IsPropertyAnimatable( nonAnimIntegerIndex ) );
   DALI_TEST_CHECK( !actor.IsPropertyAnimatable( nonAnimUnsignedIntIndex ) );
 
   DALI_TEST_EQUALS( "yes" , actor.GetProperty( nonAnimStringIndex ).Get<std::string>(), TEST_LOCATION );
@@ -486,6 +502,7 @@ int UtcDaliHandleGetPropertyType(void)
   DALI_TEST_EQUALS( Vector4(1.f, 2.f, 3.f, 4.f) , actor.GetProperty( nonAnimV4Index ).Get<Vector4>(), TEST_LOCATION );
   DALI_TEST_EQUALS( true, actor.GetProperty( nonAnimBooleanIndex ).Get<bool>(), TEST_LOCATION );
   DALI_TEST_EQUALS( 0.f, actor.GetProperty( nonAnimFloatIndex ).Get<float>(), TEST_LOCATION );
+  DALI_TEST_EQUALS( 0, actor.GetProperty( nonAnimIntegerIndex ).Get<int>(), TEST_LOCATION );
   DALI_TEST_EQUALS( unsingedIntTest, actor.GetProperty( nonAnimUnsignedIntIndex ).Get<unsigned int>(), TEST_LOCATION );
 
   END_TEST;
@@ -528,7 +545,7 @@ int UtcDaliHandleNonAnimtableProperties(void)
     exception = true;
   }
 
-  DALI_TEST_CHECK(exception);
+  DALI_TEST_CHECK(!exception);// trying to set a read-only property is a no-op
 
   DALI_TEST_EQUALS( 0.f, actor.GetProperty( readonly ).Get<float>(), TEST_LOCATION );
 
@@ -615,7 +632,7 @@ int UtcDaliHandleNonAnimtableCompositeProperties(void)
   valueMap.SetValue("key", 5.f);
   valueMap.SetValue("2key", "a string");
 
-  DALI_TEST_EQUALS( true, valueMap.HasKey("key"),         TEST_LOCATION);
+  DALI_TEST_EQUALS( true, valueMap.HasKey("key"),        TEST_LOCATION);
   DALI_TEST_EQUALS( "key", valueMap.GetKey(0),           TEST_LOCATION);
 
   DALI_TEST_EQUALS( true, valueMap.HasKey("2key"),       TEST_LOCATION);
@@ -627,8 +644,8 @@ int UtcDaliHandleNonAnimtableCompositeProperties(void)
   valueMap.SetItem(0, Property::Value("a string"));
   valueMap.SetItem(1, Property::Value(5.f));
 
-  DALI_TEST_EQUALS( 5.f,         valueMap.GetValue("2key").Get<float>(),         TEST_LOCATION);
-  DALI_TEST_EQUALS( "a string",  valueMap.GetValue("key").Get<std::string>(),  TEST_LOCATION);
+  DALI_TEST_EQUALS( 5.f,         valueMap.GetValue("2key").Get<float>(),        TEST_LOCATION);
+  DALI_TEST_EQUALS( "a string",  valueMap.GetValue("key").Get<std::string>(),   TEST_LOCATION);
 
   // ordered map
   valueMap = Property::Value(Property::MAP);
@@ -650,7 +667,7 @@ int UtcDaliHandleNonAnimtableCompositeProperties(void)
   catch (Dali::DaliException& e)
   {
     exception = true;
-    tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
+    DALI_TEST_PRINT_ASSERT( e );
   }
 
   DALI_TEST_EQUALS(exception, true, TEST_LOCATION);
@@ -708,16 +725,8 @@ int UtcDaliHandleSetProperty02(void)
 
   DALI_TEST_CHECK( !actor.IsPropertyWritable( Actor::WORLD_POSITION ) );
 
-  try
-  {
-    // World position is not writable
-    actor.SetProperty( Actor::WORLD_POSITION, Vector3(1,2,3) );
-  }
-  catch (Dali::DaliException& e)
-  {
-    tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
-    DALI_TEST_ASSERT(e, "IsDefaultPropertyWritable(index) && \"Property is read-only\"", TEST_LOCATION);
-  }
+  // World position is not writable so this is a no-op and should not crash
+  actor.SetProperty( Actor::WORLD_POSITION, Vector3(1,2,3) );
 
   END_TEST;
 }
@@ -772,6 +781,22 @@ int UtcDaliHandleDownCast(void)
   END_TEST;
 }
 
+int UtcDaliHandleDownCastNegative(void)
+{
+  TestApplication application;
+
+  // BaseObject is NOT an Object, so this DownCast should fail
+  BaseHandle handle( new BaseObjectType );
+  Handle customHandle1 = Handle::DownCast( handle );
+  DALI_TEST_CHECK( ! customHandle1 );
+
+  // A DownCast on an empty handle will also fail
+  Handle empty;
+  Handle customHandle2 = Handle::DownCast( empty );
+  DALI_TEST_CHECK( ! customHandle2 );
+  END_TEST;
+}
+
 int UtcDaliHandleCreateProperty(void)
 {
   TestApplication application;
@@ -948,7 +973,7 @@ int UtcDaliHandleGetPropertyGet(void)
   value = Property::Value(Property::MAP);
   value.SetValue("key", "value");
   value.Get(map);
-  DALI_TEST_CHECK( map[0].first == "key" );
+  DALI_TEST_CHECK( map.GetKey(0) == "key" );
 
   END_TEST;
 }
@@ -965,3 +990,82 @@ int UtcDaliHandleGetPropertyIndices(void)
   DALI_TEST_EQUALS( indices.size(), actor.GetPropertyCount(), TEST_LOCATION );
   END_TEST;
 }
+
+int UtcDaliHandleRegisterPropertyTypes(void)
+{
+  TestApplication application;
+
+  struct PropertyTypeAnimatable
+  {
+    const char * name;
+    Property::Value value;
+    bool animatable;
+  };
+
+  Property::Array array;
+  Property::Map map;
+
+  PropertyTypeAnimatable properties[] =
+  {
+    { "Property::BOOLEAN",          true,              true  },
+    { "Property::FLOAT",            1.0f,              true  },
+    { "Property::INTEGER",          1,                 true  },
+    { "Property::UNSIGNED_INTEGER", 1u,                false },
+    { "Property::VECTOR2",          Vector2::ONE,      true  },
+    { "Property::VECTOR3",          Vector3::ONE,      true  },
+    { "Property::VECTOR4",          Vector4::ONE,      true  },
+    { "Property::MATRIX3",          Matrix3::IDENTITY, true  },
+    { "Property::MATRIX",           Matrix::IDENTITY,  true  },
+    { "Property::RECTANGLE",        Rect<int>(),       false },
+    { "Property::ROTATION",         AngleAxis(),       true  },
+    { "Property::STRING",           std::string("Me"), false },
+    { "Property::ARRAY",            array,             false },
+    { "Property::MAP",              map,               false },
+  };
+  unsigned int numOfProperties( sizeof( properties ) / sizeof( properties[0] ) );
+
+  for ( unsigned int i = 0; i < numOfProperties; ++i )
+  {
+    tet_printf( "Testing: %s\n", properties[i].name );
+
+    bool exception = false;
+    try
+    {
+      Actor actor = Actor::New();
+      actor.RegisterProperty( "man-from-delmonte", properties[i].value );
+    }
+    catch (Dali::DaliException& e)
+    {
+      exception = true;
+    }
+
+    DALI_TEST_CHECK( properties[i].animatable != exception );
+  }
+  END_TEST;
+}
+
+int UtcDaliHandleCustomProperty(void)
+{
+  TestApplication application;
+
+  Handle handle = Handle::New();
+
+  float startValue(1.0f);
+  Property::Index index = handle.RegisterProperty( "test-property", startValue );
+  DALI_TEST_CHECK( handle.GetProperty<float>(index) == startValue );
+
+  application.SendNotification();
+  application.Render(0);
+  DALI_TEST_CHECK( handle.GetProperty<float>(index) == startValue );
+  application.Render(0);
+  DALI_TEST_CHECK( handle.GetProperty<float>(index) == startValue );
+
+  handle.SetProperty( index, 5.0f );
+
+  application.SendNotification();
+  application.Render(0);
+  DALI_TEST_CHECK( handle.GetProperty<float>(index) == 5.0f );
+  application.Render(0);
+  DALI_TEST_CHECK( handle.GetProperty<float>(index) == 5.0f );
+  END_TEST;
+}