[dali_1.2.7] Merge branch 'devel/master'
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-PropertyMap.cpp
index 6fb550d..7283e1c 100644 (file)
@@ -109,22 +109,27 @@ int UtcDaliPropertyMapConstOperator(void)
   END_TEST;
 }
 
-// deprecated API, only retrieve the value from string-value pairs
 int UtcDaliPropertyMapGetValue(void)
 {
   Property::Map map;
   map[ "hello" ] = 1;
   map[ "world" ] = 2;
+  map[ Actor::Property::COLOR ] = Color::MAGENTA;
 
   Property::Value& value = map.GetValue( 0 );
   DALI_TEST_CHECK( value.Get<int>() == 1 );
   value = 10; // Allows the actual changing of the value as we have a ref
   DALI_TEST_CHECK( map[ "hello" ].Get<int>() == 10 );
 
+  Property::Value& value2 = map.GetValue( 2 );
+  DALI_TEST_CHECK( value2.Get<Vector4>() == Color::MAGENTA );
+  value2 = Color::CYAN;
+  DALI_TEST_EQUALS( map[ Actor::Property::COLOR].Get<Vector4>(), Color::CYAN, TEST_LOCATION);
+
   // Out of bounds
   try
   {
-    map.GetValue( 2 );
+    map.GetValue( 3 );
     tet_result( TET_FAIL );
   }
   catch ( DaliException& e )
@@ -141,11 +146,12 @@ int UtcDaliPropertyMapGetKey(void)
   Property::Map map;
   map[ "hello" ] = 1;
   map[ "world" ] = 2;
+  map[ Actor::Property::COLOR ] = Color::MAGENTA;
 
   DALI_TEST_CHECK( map.GetKey( 0 ) == "hello" );
   DALI_TEST_CHECK( map.GetKey( 1 ) == "world" );
 
-  // Out of bounds
+  // Wrong type
   try
   {
     map.GetKey( 2 );
@@ -156,22 +162,59 @@ int UtcDaliPropertyMapGetKey(void)
     DALI_TEST_ASSERT( e, "position", TEST_LOCATION );
   }
 
+  // Out of bounds
+  try
+  {
+    map.GetKey( 3 );
+    tet_result( TET_FAIL );
+  }
+  catch ( DaliException& e )
+  {
+    DALI_TEST_ASSERT( e, "position", TEST_LOCATION );
+  }
+
+  END_TEST;
+}
+
+
+int UtcDaliPropertyMapGetKeyAt(void)
+{
+  Property::Map map;
+  map[ "hello" ] = 1;
+  map[ "world" ] = 2;
+  map[ Actor::Property::COLOR ] = Color::MAGENTA;
+
+  DALI_TEST_CHECK( map.GetKeyAt( 0 ) == "hello" );
+  DALI_TEST_CHECK( map.GetKeyAt( 1 ) == "world" );
+  DALI_TEST_CHECK( map.GetKeyAt( 2 ) == Actor::Property::COLOR );
+
+  // Out of bounds
+  try
+  {
+    map.GetKey( 3 );
+    tet_result( TET_FAIL );
+  }
+  catch ( DaliException& e )
+  {
+    DALI_TEST_ASSERT( e, "position", TEST_LOCATION );
+  }
+
   END_TEST;
 }
 
-// deprecated API, only retrieve the string-value pairs
 int UtcDaliPropertyMapGetPair(void)
 {
   Property::Map map;
   map[ "hello" ] = 1;
   map[ "world" ] = 2;
+  map[ Actor::Property::COLOR ] = Color::MAGENTA;
 
   DALI_TEST_CHECK( map.GetPair( 0 ).first == "hello" );
   DALI_TEST_CHECK( map.GetPair( 0 ).second.Get< int >() == 1 );
   DALI_TEST_CHECK( map.GetPair( 1 ).first == "world" );
   DALI_TEST_CHECK( map.GetPair( 1 ).second.Get< int >() == 2 );
 
-  // Out of bounds
+  // Wrong Type
   try
   {
     map.GetPair( 2 );
@@ -182,6 +225,45 @@ int UtcDaliPropertyMapGetPair(void)
     DALI_TEST_ASSERT( e, "position", TEST_LOCATION );
   }
 
+  // Out of bounds
+  try
+  {
+    map.GetPair( 3 );
+    tet_result( TET_FAIL );
+  }
+  catch ( DaliException& e )
+  {
+    DALI_TEST_ASSERT( e, "position", TEST_LOCATION );
+  }
+
+  END_TEST;
+}
+
+int UtcDaliPropertyMapGetKeyValue(void)
+{
+  Property::Map map;
+  map[ "hello" ] = 1;
+  map[ "world" ] = 2;
+  map[ Actor::Property::COLOR ] = Color::MAGENTA;
+
+  DALI_TEST_CHECK( map.GetKeyValue( 0 ).first == "hello" );
+  DALI_TEST_CHECK( map.GetKeyValue( 0 ).second.Get< int >() == 1 );
+  DALI_TEST_CHECK( map.GetKeyValue( 1 ).first == "world" );
+  DALI_TEST_CHECK( map.GetKeyValue( 1 ).second.Get< int >() == 2 );
+  DALI_TEST_CHECK( map.GetKeyValue( 2 ).first == Actor::Property::COLOR );
+  DALI_TEST_CHECK( map.GetKeyValue( 2 ).second.Get< Vector4 >() == Color::MAGENTA );
+
+  // Out of bounds
+  try
+  {
+    map.GetPair( 3 );
+    tet_result( TET_FAIL );
+  }
+  catch ( DaliException& e )
+  {
+    DALI_TEST_ASSERT( e, "position", TEST_LOCATION );
+  }
+
   END_TEST;
 }
 
@@ -533,3 +615,74 @@ int UtcDaliPropertyMapOstream02(void)
 
   END_TEST;
 }
+
+int UtcDaliPropertyKeyConstructorP(void)
+{
+  Property::Key key1( "aKey" );
+  DALI_TEST_EQUALS( key1.type, Property::Key::STRING, TEST_LOCATION );
+  DALI_TEST_EQUALS( key1.stringKey, "aKey", TEST_LOCATION );
+  DALI_TEST_EQUALS( key1.indexKey, Property::INVALID_INDEX, TEST_LOCATION );
+
+  Property::Key key2( Actor::Property::COLOR );
+  DALI_TEST_EQUALS( key2.type, Property::Key::INDEX, TEST_LOCATION );
+  DALI_TEST_EQUALS( key2.indexKey, (Dali::Property::Index)Actor::Property::COLOR, TEST_LOCATION );
+  END_TEST;
+}
+
+int UtcDaliPropertyKeyEqualityOperatorP(void)
+{
+  Property::Key key1( "aKey" );
+  Property::Key key2( 113 );
+
+  DALI_TEST_CHECK( key1 == "aKey" );
+  DALI_TEST_CHECK( ! (key1 == "notTheKey") );
+  DALI_TEST_CHECK( ! (key1 == 1) );
+
+  DALI_TEST_CHECK( key2 == 113 );
+  DALI_TEST_CHECK( ! (key2 == 0) );
+  DALI_TEST_CHECK( ! (key2 == "One hundred and thirteen" ) );
+
+  DALI_TEST_CHECK( ! (key1 == key2) );
+  DALI_TEST_CHECK( key1 != key2 );
+
+  Property::Key key1B( "aKey" );
+  Property::Key key2B( 113 );
+
+  DALI_TEST_CHECK( key1 == key1B );
+  DALI_TEST_CHECK( key2 == key2B );
+
+  END_TEST;
+}
+
+int UtcDaliPropertyKeyInequalityOperatorP(void)
+{
+  Property::Key key1( "aKey" );
+  Property::Key key2( 113 );
+
+  DALI_TEST_CHECK( key1 != "notTheKey" );
+  DALI_TEST_CHECK( key1 != 1 );
+
+  DALI_TEST_CHECK( key2 != 0 );
+  DALI_TEST_CHECK( key2 != "One hundred and thirteen" );
+
+  DALI_TEST_CHECK( key1 != key2 );
+
+  END_TEST;
+}
+
+
+int UtcDaliPropertyKeyOutputStream(void)
+{
+  Property::Key key1( "aKey" );
+  Property::Key key2( 113 );
+
+  std::ostringstream oss;
+  oss << key1;
+  DALI_TEST_EQUALS( oss.str(), "aKey", TEST_LOCATION );
+
+  std::ostringstream oss2;
+  oss2 << key2;
+  DALI_TEST_EQUALS( oss2.str(), "113", TEST_LOCATION );
+
+  END_TEST;
+}