Cleaning up the property framework; removal of duplicate methods and incorrect assers
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-Handle.cpp
index 50448e6..fdfb01f 100644 (file)
@@ -1,23 +1,24 @@
-//
-// Copyright (c) 2014 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Flora License, Version 1.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//     http://floralicense.org/license/
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an AS IS BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
+/*
+ * Copyright (c) 2014 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
 
 #include <iostream>
 
 #include <stdlib.h>
-#include <dali/dali.h>
+#include <dali/public-api/dali-core.h>
 #include "dali-test-suite-utils/dali-test-suite-utils.h"
 
 using namespace Dali;
@@ -404,7 +405,6 @@ 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 ) );
@@ -434,6 +434,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) );
@@ -441,6 +442,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 ) );
@@ -453,6 +455,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 );
@@ -461,6 +464,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 ) );
@@ -469,6 +473,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 ) );
@@ -477,6 +482,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 );
@@ -485,6 +491,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;
@@ -527,7 +534,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 );
 
@@ -649,7 +656,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);
@@ -707,16 +714,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;
 }
@@ -947,7 +946,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;
 }
@@ -964,3 +963,56 @@ 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;
+}