From: Nick Holland Date: Mon, 23 Mar 2015 09:21:49 +0000 (+0000) Subject: Output stream insert support added to property value X-Git-Tag: accepted/tizen/common/20150407.101656~13 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F43%2F37243%2F6;p=platform%2Fcore%2Fuifw%2Fdali-core.git Output stream insert support added to property value Change-Id: If7bcca7975c75c6d59c6bd5fbe5b94c7a564d71c --- diff --git a/automated-tests/src/dali/CMakeLists.txt b/automated-tests/src/dali/CMakeLists.txt index 4d1fc2b..645ce4a 100644 --- a/automated-tests/src/dali/CMakeLists.txt +++ b/automated-tests/src/dali/CMakeLists.txt @@ -65,6 +65,7 @@ SET(TC_SOURCES utc-Dali-Pixel.cpp utc-Dali-PropertyMap.cpp utc-Dali-PropertyNotification.cpp + utc-Dali-PropertyValue.cpp utc-Dali-Quaternion.cpp utc-Dali-Radian.cpp utc-Dali-Random.cpp diff --git a/automated-tests/src/dali/utc-Dali-Handle.cpp b/automated-tests/src/dali/utc-Dali-Handle.cpp index 1ff33c1..e25dd4b 100644 --- a/automated-tests/src/dali/utc-Dali-Handle.cpp +++ b/automated-tests/src/dali/utc-Dali-Handle.cpp @@ -57,94 +57,6 @@ Handle ImplicitCopyConstructor(Handle passedByValue) return passedByValue; } -void CheckTypeName(const Property::Type& type) -{ - switch(type) - { - case Property::NONE: - { - DALI_TEST_CHECK( "NONE" == std::string(PropertyTypes::GetName( type ) ) ); - break; - } - case Property::BOOLEAN: - { - DALI_TEST_CHECK( "BOOLEAN" == std::string(PropertyTypes::GetName( type ) ) ); - break; - } - case Property::FLOAT: - { - DALI_TEST_CHECK( "FLOAT" == std::string(PropertyTypes::GetName( type ) ) ); - break; - } - case Property::INTEGER: - { - DALI_TEST_CHECK( "INTEGER" == std::string(PropertyTypes::GetName( type ) ) ); - break; - } - case Property::UNSIGNED_INTEGER: - { - DALI_TEST_CHECK( "UNSIGNED_INTEGER" == std::string(PropertyTypes::GetName( type ) ) ); - break; - } - case Property::VECTOR2: - { - DALI_TEST_CHECK( "VECTOR2" == std::string(PropertyTypes::GetName( type ) ) ); - break; - } - case Property::VECTOR3: - { - DALI_TEST_CHECK( "VECTOR3" == std::string(PropertyTypes::GetName( type ) ) ); - break; - } - case Property::VECTOR4: - { - DALI_TEST_CHECK( "VECTOR4" == std::string(PropertyTypes::GetName( type ) ) ); - break; - } - case Property::MATRIX3: - { - DALI_TEST_CHECK( "MATRIX3" == std::string(PropertyTypes::GetName( type ) ) ); - break; - } - case Property::MATRIX: - { - DALI_TEST_CHECK( "MATRIX" == std::string(PropertyTypes::GetName( type ) ) ); - break; - } - case Property::RECTANGLE: - { - DALI_TEST_CHECK( "RECTANGLE" == std::string(PropertyTypes::GetName( type ) ) ); - break; - } - case Property::ROTATION: - { - DALI_TEST_CHECK( "ROTATION" == std::string(PropertyTypes::GetName( type ) ) ); - break; - } - case Property::STRING: - { - DALI_TEST_CHECK( "STRING" == std::string(PropertyTypes::GetName( type ) ) ); - break; - } - case Property::ARRAY: - { - DALI_TEST_CHECK( "ARRAY" == std::string(PropertyTypes::GetName( type ) ) ); - break; - } - case Property::MAP: - { - DALI_TEST_CHECK( "MAP" == std::string(PropertyTypes::GetName( type ) ) ); - break; - } - case Property::TYPE_COUNT: - { - DALI_TEST_CHECK( "NONE" == std::string(PropertyTypes::GetName( type ) ) ); - break; - } - } // switch(type) - -} // CheckTypeName - } // anon namespace @@ -797,187 +709,6 @@ int UtcDaliHandleDownCastNegative(void) END_TEST; } -int UtcDaliHandleCreateProperty(void) -{ - TestApplication application; - tet_infoline("Testing PropertyTypes::GetName()"); - - Property::Type type = Property::NONE; - CheckTypeName(type); - // Value(Value&) ctor and Value(Type&) ctor - DALI_TEST_CHECK( Property::Value(Property::Value(type)).GetType() == type ); - DALI_TEST_CHECK( Property::NONE == type ); - - // PropertyTypes - type = Property::BOOLEAN; - CheckTypeName(type); - DALI_TEST_CHECK( Property::Value(Property::Value(type)).GetType() == type ); - DALI_TEST_CHECK( PropertyTypes::Get() == type ); - - type = Property::FLOAT; - CheckTypeName(type); - DALI_TEST_CHECK( Property::Value(Property::Value(type)).GetType() == type ); - DALI_TEST_CHECK( PropertyTypes::Get() == type ); - - type = Property::INTEGER; - CheckTypeName(type); - DALI_TEST_CHECK( Property::Value(Property::Value(type)).GetType() == type ); - DALI_TEST_CHECK( PropertyTypes::Get() == type ); - - type = Property::UNSIGNED_INTEGER; - CheckTypeName(type); - DALI_TEST_CHECK( Property::Value(Property::Value(type)).GetType() == type ); - DALI_TEST_CHECK( PropertyTypes::Get() == type ); - - type = Property::VECTOR2; - CheckTypeName(type); - DALI_TEST_CHECK( Property::Value(Property::Value(type)).GetType() == type ); - DALI_TEST_CHECK( PropertyTypes::Get() == type ); - - type = Property::VECTOR3; - CheckTypeName(type); - DALI_TEST_CHECK( Property::Value(Property::Value(type)).GetType() == type ); - DALI_TEST_CHECK( PropertyTypes::Get() == type ); - - type = Property::VECTOR4; - CheckTypeName(type); - DALI_TEST_CHECK( Property::Value(Property::Value(type)).GetType() == type ); - DALI_TEST_CHECK( PropertyTypes::Get() == type ); - - type = Property::MATRIX3; - CheckTypeName(type); - DALI_TEST_CHECK( Property::Value(Property::Value(type)).GetType() == type ); - DALI_TEST_CHECK( PropertyTypes::Get() == type ); - - type = Property::MATRIX; - CheckTypeName(type); - DALI_TEST_CHECK( Property::Value(Property::Value(type)).GetType() == type ); - DALI_TEST_CHECK( PropertyTypes::Get() == type ); - - typedef Dali::Rect Rectangle; - type = Property::RECTANGLE; - CheckTypeName(type); - DALI_TEST_CHECK( Property::Value(Property::Value(type)).GetType() == type ); - DALI_TEST_CHECK( PropertyTypes::Get() == type ); - - type = Property::ROTATION; - CheckTypeName(type); - DALI_TEST_CHECK( Property::Value(Property::Value(type)).GetType() == type ); - DALI_TEST_CHECK( PropertyTypes::Get() == type ); - - type = Property::ROTATION; - CheckTypeName(type); - DALI_TEST_CHECK( Property::Value(Property::Value(type)).GetType() == type ); - DALI_TEST_CHECK( PropertyTypes::Get() == type ); - - type = Property::STRING; - CheckTypeName(type); - DALI_TEST_CHECK( Property::Value(Property::Value(type)).GetType() == type ); - DALI_TEST_CHECK( PropertyTypes::Get() == type ); - - type = Property::ARRAY; - CheckTypeName(type); - DALI_TEST_CHECK( Property::Value(Property::Value(type)).GetType() == type ); - DALI_TEST_CHECK( PropertyTypes::Get() == type ); - - type = Property::MAP; - CheckTypeName(type); - DALI_TEST_CHECK( Property::Value(Property::Value(type)).GetType() == type ); - DALI_TEST_CHECK( PropertyTypes::Get() == type ); - END_TEST; -} - -int UtcDaliHandleGetPropertyGet(void) -{ - TestApplication application; - tet_infoline("Testing PropertyTypes::GetName()"); - - Property::Value value; - - bool b = false; - value = Property::Value(true); - value.Get(b); - DALI_TEST_CHECK( true == b ); - - float f = 5.f; - value = Property::Value(10.f); - value.Get(f); - DALI_TEST_CHECK( Dali::Equals(10.f, f) ); - - int i = 5; - value = Property::Value(10); - value.Get(i); - DALI_TEST_CHECK( 10 == i ); - - unsigned int ui = 5; - value = Property::Value(10U); - value.Get(ui); - DALI_TEST_CHECK( 10 == ui ); - - Vector2 v2 = Vector2(0,0); - value = Property::Value( Vector2(1,1) ); - value.Get(v2); - DALI_TEST_CHECK( Vector2(1,1) == v2 ); - - Vector3 v3 = Vector3(0.f,0.f,0.f); - value = Property::Value( Vector3(1.f,1.f,1.f) ); - value.Get(v3); - DALI_TEST_CHECK( Vector3(1.f,1.f,1.f) == v3 ); - - Vector4 v4 = Vector4(0,0,0,0); - value = Property::Value( Vector4(1,1,1,1) ); - value.Get(v4); - DALI_TEST_CHECK( Vector4(1,1,1,1) == v4 ); - - Matrix3 m3 = Matrix3(0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f); - value = Property::Value( Matrix3::IDENTITY ); - value.Get(m3); - DALI_TEST_CHECK( Matrix3::IDENTITY == m3 ); - - Matrix m = Matrix(true); - value = Property::Value( Matrix::IDENTITY ); - value.Get(m); - DALI_TEST_CHECK( Matrix::IDENTITY == m ); - - typedef Dali::Rect Rectangle; - Rectangle r = Rectangle(0,0,0,0); - value = Property::Value( Rectangle(1,1,1,1) ); - value.Get(r); - DALI_TEST_CHECK( Rectangle(1,1,1,1) == r ); - - Quaternion q = Quaternion(0,0,0,0); - value = Property::Value( Quaternion(1,1,1,1) ); - value.Get(q); - DALI_TEST_CHECK( Quaternion(1,1,1,1) == q ); - - AngleAxis aa = AngleAxis( Degree(0), Vector3(0.f,0.f,0.f) ); - value = Property::Value( AngleAxis( Radian(Math::PI_2), Vector3::XAXIS )); - value.Get(aa); - Quaternion r8(Radian(Degree(aa.angle)), aa.axis); - DALI_TEST_EQUALS(r8, Quaternion(Math::PI_2, Vector3::XAXIS), 0.001, TEST_LOCATION); - - std::string s = "no"; - value = Property::Value("yes"); - value.Get(s); - DALI_TEST_CHECK( "yes" == s ); - - Property::Array array; - value = Property::Value(Property::ARRAY); - value.AppendItem(10); - value.Get(array); - int getItem = 0; - array[0].Get(getItem); - DALI_TEST_CHECK( getItem == 10 ); - - Property::Map map; - value = Property::Value(Property::MAP); - value.SetValue("key", "value"); - value.Get(map); - DALI_TEST_CHECK( map.GetKey(0) == "key" ); - - END_TEST; -} - int UtcDaliHandleGetPropertyIndices(void) { TestApplication application; diff --git a/automated-tests/src/dali/utc-Dali-PropertyValue.cpp b/automated-tests/src/dali/utc-Dali-PropertyValue.cpp new file mode 100644 index 0000000..c6d462f --- /dev/null +++ b/automated-tests/src/dali/utc-Dali-PropertyValue.cpp @@ -0,0 +1,660 @@ +/* + * Copyright (c) 2015 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 +#include +#include +#include +#include + +using namespace Dali; + +namespace +{ + +void CheckTypeName(const Property::Type& type) +{ + switch(type) + { + case Property::NONE: + { + DALI_TEST_CHECK( "NONE" == std::string(PropertyTypes::GetName( type ) ) ); + break; + } + case Property::BOOLEAN: + { + DALI_TEST_CHECK( "BOOLEAN" == std::string(PropertyTypes::GetName( type ) ) ); + break; + } + case Property::FLOAT: + { + DALI_TEST_CHECK( "FLOAT" == std::string(PropertyTypes::GetName( type ) ) ); + break; + } + case Property::INTEGER: + { + DALI_TEST_CHECK( "INTEGER" == std::string(PropertyTypes::GetName( type ) ) ); + break; + } + case Property::UNSIGNED_INTEGER: + { + DALI_TEST_CHECK( "UNSIGNED_INTEGER" == std::string(PropertyTypes::GetName( type ) ) ); + break; + } + case Property::VECTOR2: + { + DALI_TEST_CHECK( "VECTOR2" == std::string(PropertyTypes::GetName( type ) ) ); + break; + } + case Property::VECTOR3: + { + DALI_TEST_CHECK( "VECTOR3" == std::string(PropertyTypes::GetName( type ) ) ); + break; + } + case Property::VECTOR4: + { + DALI_TEST_CHECK( "VECTOR4" == std::string(PropertyTypes::GetName( type ) ) ); + break; + } + case Property::MATRIX3: + { + DALI_TEST_CHECK( "MATRIX3" == std::string(PropertyTypes::GetName( type ) ) ); + break; + } + case Property::MATRIX: + { + DALI_TEST_CHECK( "MATRIX" == std::string(PropertyTypes::GetName( type ) ) ); + break; + } + case Property::RECTANGLE: + { + DALI_TEST_CHECK( "RECTANGLE" == std::string(PropertyTypes::GetName( type ) ) ); + break; + } + case Property::ROTATION: + { + DALI_TEST_CHECK( "ROTATION" == std::string(PropertyTypes::GetName( type ) ) ); + break; + } + case Property::STRING: + { + DALI_TEST_CHECK( "STRING" == std::string(PropertyTypes::GetName( type ) ) ); + break; + } + case Property::ARRAY: + { + DALI_TEST_CHECK( "ARRAY" == std::string(PropertyTypes::GetName( type ) ) ); + break; + } + case Property::MAP: + { + DALI_TEST_CHECK( "MAP" == std::string(PropertyTypes::GetName( type ) ) ); + break; + } + case Property::TYPE_COUNT: + { + DALI_TEST_CHECK( "NONE" == std::string(PropertyTypes::GetName( type ) ) ); + break; + } + } // switch(type) + +} // CheckTypeName + +} // unnamed namespace + +void utc_dali_property_value_startup(void) +{ + test_return_value = TET_UNDEF; +} + +void utc_dali_property_value_cleanup(void) +{ + test_return_value = TET_PASS; +} + +int UtcDaliPropertyValueConstructors01(void) +{ + // Testing PropertyValue construction using Property::Type + // also testing the PropertyTypes::GetName is correct for each type + + TestApplication application; + tet_infoline("Testing Property::Value construction using Property::Type"); + + Property::Value value; + DALI_TEST_CHECK( value.GetType() == Property::NONE ); + + Property::Type type = Property::NONE; + CheckTypeName(type); + // Value(Value&) ctor and Value(Type&) ctor + DALI_TEST_CHECK( Property::Value(Property::Value(type)).GetType() == type ); + DALI_TEST_CHECK( Property::NONE == type ); + + // PropertyTypes + type = Property::BOOLEAN; + CheckTypeName(type); + DALI_TEST_CHECK( Property::Value(Property::Value(type)).GetType() == type ); + DALI_TEST_CHECK( PropertyTypes::Get() == type ); + + type = Property::FLOAT; + CheckTypeName(type); + DALI_TEST_CHECK( Property::Value(Property::Value(type)).GetType() == type ); + DALI_TEST_CHECK( PropertyTypes::Get() == type ); + + type = Property::INTEGER; + CheckTypeName(type); + DALI_TEST_CHECK( Property::Value(Property::Value(type)).GetType() == type ); + DALI_TEST_CHECK( PropertyTypes::Get() == type ); + + type = Property::UNSIGNED_INTEGER; + CheckTypeName(type); + DALI_TEST_CHECK( Property::Value(Property::Value(type)).GetType() == type ); + DALI_TEST_CHECK( PropertyTypes::Get() == type ); + + type = Property::VECTOR2; + CheckTypeName(type); + DALI_TEST_CHECK( Property::Value(Property::Value(type)).GetType() == type ); + DALI_TEST_CHECK( PropertyTypes::Get() == type ); + + type = Property::VECTOR3; + CheckTypeName(type); + DALI_TEST_CHECK( Property::Value(Property::Value(type)).GetType() == type ); + DALI_TEST_CHECK( PropertyTypes::Get() == type ); + + type = Property::VECTOR4; + CheckTypeName(type); + DALI_TEST_CHECK( Property::Value(Property::Value(type)).GetType() == type ); + DALI_TEST_CHECK( PropertyTypes::Get() == type ); + + type = Property::MATRIX3; + CheckTypeName(type); + DALI_TEST_CHECK( Property::Value(Property::Value(type)).GetType() == type ); + DALI_TEST_CHECK( PropertyTypes::Get() == type ); + + type = Property::MATRIX; + CheckTypeName(type); + DALI_TEST_CHECK( Property::Value(Property::Value(type)).GetType() == type ); + DALI_TEST_CHECK( PropertyTypes::Get() == type ); + + typedef Dali::Rect Rectangle; + type = Property::RECTANGLE; + CheckTypeName(type); + DALI_TEST_CHECK( Property::Value(Property::Value(type)).GetType() == type ); + DALI_TEST_CHECK( PropertyTypes::Get() == type ); + + type = Property::ROTATION; + CheckTypeName(type); + DALI_TEST_CHECK( Property::Value(Property::Value(type)).GetType() == type ); + DALI_TEST_CHECK( PropertyTypes::Get() == type ); + + type = Property::ROTATION; + CheckTypeName(type); + DALI_TEST_CHECK( Property::Value(Property::Value(type)).GetType() == type ); + DALI_TEST_CHECK( PropertyTypes::Get() == type ); + + type = Property::STRING; + CheckTypeName(type); + DALI_TEST_CHECK( Property::Value(Property::Value(type)).GetType() == type ); + DALI_TEST_CHECK( PropertyTypes::Get() == type ); + + type = Property::ARRAY; + CheckTypeName(type); + DALI_TEST_CHECK( Property::Value(Property::Value(type)).GetType() == type ); + DALI_TEST_CHECK( PropertyTypes::Get() == type ); + + type = Property::MAP; + CheckTypeName(type); + DALI_TEST_CHECK( Property::Value(Property::Value(type)).GetType() == type ); + DALI_TEST_CHECK( PropertyTypes::Get() == type ); + END_TEST; + +} + +int UtcDaliPropertyValueConstructors02(void) +{ + // Testing PropertyValue construction using value / reference types + // also testing the PropertyTypes::Get return same value as constructed + + TestApplication application; + tet_infoline("Testing Property::Value construction using values / references"); + + Property::Value value; + + bool b = false; + value = Property::Value(true); + value.Get(b); + DALI_TEST_CHECK( true == b ); + + float f = 5.f; + value = Property::Value(10.f); + value.Get(f); + DALI_TEST_CHECK( Dali::Equals(10.f, f) ); + + int i = 5; + value = Property::Value(10); + value.Get(i); + DALI_TEST_CHECK( 10 == i ); + + unsigned int ui = 5; + value = Property::Value(10U); + value.Get(ui); + DALI_TEST_CHECK( 10 == ui ); + + Vector2 v2 = Vector2(0,0); + value = Property::Value( Vector2(1,1) ); + value.Get(v2); + DALI_TEST_CHECK( Vector2(1,1) == v2 ); + + Vector3 v3 = Vector3(0.f,0.f,0.f); + value = Property::Value( Vector3(1.f,1.f,1.f) ); + value.Get(v3); + DALI_TEST_CHECK( Vector3(1.f,1.f,1.f) == v3 ); + + Vector4 v4 = Vector4(0,0,0,0); + value = Property::Value( Vector4(1,1,1,1) ); + value.Get(v4); + DALI_TEST_CHECK( Vector4(1,1,1,1) == v4 ); + + Matrix3 m3 = Matrix3(0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f); + value = Property::Value( Matrix3::IDENTITY ); + value.Get(m3); + DALI_TEST_CHECK( Matrix3::IDENTITY == m3 ); + + Matrix m = Matrix(true); + value = Property::Value( Matrix::IDENTITY ); + value.Get(m); + DALI_TEST_CHECK( Matrix::IDENTITY == m ); + + typedef Dali::Rect Rectangle; + Rectangle r = Rectangle(0,0,0,0); + value = Property::Value( Rectangle(1,1,1,1) ); + value.Get(r); + DALI_TEST_CHECK( Rectangle(1,1,1,1) == r ); + + Quaternion q = Quaternion(0,0,0,0); + value = Property::Value( Quaternion(1,1,1,1) ); + value.Get(q); + DALI_TEST_CHECK( Quaternion(1,1,1,1) == q ); + + AngleAxis aa = AngleAxis( Degree(0), Vector3(0.f,0.f,0.f) ); + value = Property::Value( AngleAxis( Radian(Math::PI_2), Vector3::XAXIS )); + value.Get(aa); + Quaternion r8(Radian(Degree(aa.angle)), aa.axis); + DALI_TEST_EQUALS(r8, Quaternion(Math::PI_2, Vector3::XAXIS), 0.001, TEST_LOCATION); + + std::string s = "no"; + value = Property::Value("yes"); + value.Get(s); + DALI_TEST_CHECK( "yes" == s ); + + Property::Array array; + value = Property::Value(Property::ARRAY); + value.AppendItem(10); + value.Get(array); + int getItem = 0; + array[0].Get(getItem); + DALI_TEST_CHECK( getItem == 10 ); + + Property::Map map; + value = Property::Value(Property::MAP); + value.SetValue("key", "value"); + value.Get(map); + DALI_TEST_CHECK( map.GetKey(0) == "key" ); + + END_TEST; +} + + +int UtcDaliPropertyValueCopyConstructors01(void) +{ + TestApplication application; + tet_infoline("Testing Property::Value copy construction using values / references"); + + Property::Value value; + + value = Property::Value(true); + { + Property::Value copy( value ); + DALI_TEST_CHECK( true == copy.Get() ); + } + + value = Property::Value(10.f); + { + Property::Value copy( value ); + DALI_TEST_CHECK( Dali::Equals(10.f, copy.Get() ) ); + } + + value = Property::Value(10); + { + Property::Value copy( value ); + DALI_TEST_CHECK( 10 == copy.Get() ); + } + + value = Property::Value(10U); + { + Property::Value copy( value ); + DALI_TEST_CHECK( 10 == copy.Get< unsigned int>() ); + } + + value = Property::Value( Vector2(1,1) ); + { + Property::Value copy( value ); + DALI_TEST_CHECK( Vector2(1,1) == copy.Get() ); + } + + value = Property::Value( Vector3(1.f,1.f,1.f) ); + { + Property::Value copy( value ); + DALI_TEST_CHECK( Vector3(1.f,1.f,1.f) == copy.Get() ); + } + + value = Property::Value( Vector4(1,1,1,1) ); + { + Property::Value copy( value ); + DALI_TEST_CHECK( Vector4(1,1,1,1) == copy.Get() ); + } + + value = Property::Value( Matrix3::IDENTITY ); + { + Property::Value copy( value ); + DALI_TEST_CHECK( Matrix3::IDENTITY == copy.Get() ); + } + + value = Property::Value( Matrix::IDENTITY ); + { + Property::Value copy( value ); + DALI_TEST_CHECK( Matrix::IDENTITY == copy.Get() ); + } + + typedef Dali::Rect Rectangle; + + value = Property::Value( Rectangle(1,1,1,1) ); + { + Property::Value copy( value ); + Rectangle copyRect; + copy.Get(copyRect); + DALI_TEST_CHECK( Rectangle(1,1,1,1) == copyRect); + } + + value = Property::Value( Quaternion(1,1,1,1) ); + { + Property::Value copy( value ); + DALI_TEST_CHECK( Quaternion(1,1,1,1) == copy.Get() ); + } + + value = Property::Value( AngleAxis( Radian(Math::PI_2), Vector3::XAXIS )); + { + Property::Value copy( value ); + DALI_TEST_CHECK( value.Get().axis == copy.Get().axis ); + DALI_TEST_CHECK( value.Get().angle == copy.Get().angle ); + } + + value = Property::Value("yes"); + { + Property::Value copy( value ); + DALI_TEST_CHECK( "yes" == copy.Get() ); + } + + Property::Array array; + value = Property::Value(Property::ARRAY); + value.AppendItem(10); + { + Property::Value copy( value ); + copy.Get( array ); + int getItem = 0; + array[0].Get( getItem ); + DALI_TEST_CHECK( getItem == 10 ); + } + Property::Map map; + value = Property::Value(Property::MAP); + value.SetValue("key", "value"); + { + Property::Value copy( value ); + copy.Get( map ); + DALI_TEST_CHECK( map.GetKey(0) == "key" ); + } + + END_TEST; +} + + +int UtcDaliPropertyValueAssignmentOperator01(void) +{ + // Testing Property Value assignment + TestApplication application; + tet_infoline("Testing Property::Value assignment operator"); + + Property::Value value; + + + value = Property::Value(true); + { + Property::Value copy( false ); + copy = value; + DALI_TEST_CHECK( true == copy.Get() ); + } + + value = Property::Value(10.f); + { + Property::Value copy(false); + copy = value; + DALI_TEST_CHECK( Dali::Equals(10.f, copy.Get() ) ); + } + + value = Property::Value(10); + { + Property::Value copy(false); + copy = value; + DALI_TEST_CHECK( 10 == copy.Get() ); + } + + value = Property::Value(10U); + { + Property::Value copy(false); + copy = value; + DALI_TEST_CHECK( 10 == copy.Get< unsigned int>() ); + } + + value = Property::Value( Vector2(1,1) ); + { + Property::Value copy(false); + copy = value; + DALI_TEST_CHECK( Vector2(1,1) == copy.Get() ); + } + + value = Property::Value( Vector3(1.f,1.f,1.f) ); + { + Property::Value copy(false); + copy = value; + DALI_TEST_CHECK( Vector3(1.f,1.f,1.f) == copy.Get() ); + } + + value = Property::Value( Vector4(1,1,1,1) ); + { + Property::Value copy(false); + copy = value; + DALI_TEST_CHECK( Vector4(1,1,1,1) == copy.Get() ); + } + + value = Property::Value( Matrix3::IDENTITY ); + { + Property::Value copy(false); + copy = value; + DALI_TEST_CHECK( Matrix3::IDENTITY == copy.Get() ); + } + + value = Property::Value( Matrix::IDENTITY ); + { + Property::Value copy(false); + copy = value; + DALI_TEST_CHECK( Matrix::IDENTITY == copy.Get() ); + } + + typedef Dali::Rect Rectangle; + + value = Property::Value( Rectangle(1,1,1,1) ); + { + Property::Value copy(false); + copy = value; + Rectangle copyRect; + copy.Get(copyRect); + DALI_TEST_CHECK( Rectangle(1,1,1,1) == copyRect); + } + + value = Property::Value( Quaternion(1,1,1,1) ); + { + Property::Value copy(false); + copy = value; + DALI_TEST_CHECK( Quaternion(1,1,1,1) == copy.Get() ); + } + + value = Property::Value( AngleAxis( Radian(Math::PI_2), Vector3::XAXIS )); + { + Property::Value copy(false); + copy = value; + DALI_TEST_CHECK( value.Get().axis == copy.Get().axis ); + DALI_TEST_CHECK( value.Get().angle == copy.Get().angle ); + } + + value = Property::Value("yes"); + { + Property::Value copy(false); + copy = value; + DALI_TEST_CHECK( "yes" == copy.Get() ); + } + + Property::Array array; + value = Property::Value(Property::ARRAY); + value.AppendItem(10); + { + Property::Value copy(false); + copy = value; + copy.Get( array ); + int getItem = 0; + array[0].Get( getItem ); + DALI_TEST_CHECK( getItem == 10 ); + } + Property::Map map; + value = Property::Value(Property::MAP); + value.SetValue("key", "value"); + { + Property::Value copy(false); + copy = value; + copy.Get( map ); + DALI_TEST_CHECK( map.GetKey(0) == "key" ); + } + + END_TEST; +} + + +int UtcDaliPropertyValueOutputStream(void) +{ + TestApplication application; + tet_infoline("Testing Property::Value output stream"); + typedef Dali::Rect Rectangle; + + Property::Value value(true); + { + std::ostringstream stream; + stream << value; + DALI_TEST_CHECK( stream.str() == "1") + } + + { + value = Property::Value(20.2f); + std::ostringstream stream; + stream << value; + DALI_TEST_CHECK( stream.str() == "20.2") + } + + { + value = Property::Value(-25); + std::ostringstream stream; + stream << value; + DALI_TEST_CHECK( stream.str() == "-25") + } + + { + value = Property::Value(25U); + std::ostringstream stream; + stream << value; + DALI_TEST_CHECK( stream.str() == "25") + } + + { + value = Property::Value( Vector2(1.f,1.f) ); + std::ostringstream stream; + stream << value; + DALI_TEST_CHECK( stream.str() == "[1, 1]"); + } + + { + value = Property::Value( Vector3(1.f,1.f,1.f) ); + std::ostringstream stream; + stream << value; + DALI_TEST_CHECK( stream.str() == "[1, 1, 1]"); + } + + { + value = Property::Value( Matrix3::IDENTITY ); + std::ostringstream stream; + stream << value; + DALI_TEST_CHECK( stream.str() == "[ [1, 0, 0], [0, 1, 0], [0, 0, 1] ]"); + } + + { + value = Property::Value( Matrix::IDENTITY ); + std::ostringstream stream; + stream << value; + DALI_TEST_CHECK( stream.str() == "[ [1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1] ]"); + } + + { + value = Property::Value( Rectangle(1,2,3,4) ); + std::ostringstream stream; + stream << value; + DALI_TEST_CHECK( stream.str() == "[1, 2, 3, 4]"); + } + + { + value = Property::Value( AngleAxis( Radian(1.2f), Vector3::XAXIS )); + std::ostringstream stream; + stream << value; + tet_printf("angle axis = %s \n", stream.str().c_str() ); + DALI_TEST_CHECK( stream.str() == "[1.2, -0, 0, 0]"); + } + + // Maps and arrays currently not supported, we just check a message is output + { + Property::Map map; + value = Property::Value( map ); + std::ostringstream stream; + stream << value; + DALI_TEST_CHECK( !stream.str().empty() ); + } + { + Property::Array array; + value = Property::Value( array ); + std::ostringstream stream; + stream << value; + DALI_TEST_CHECK( !stream.str().empty() ); + } + + + END_TEST; + +} diff --git a/dali/public-api/math/matrix.h b/dali/public-api/math/matrix.h index 15b8d7d..d483684 100644 --- a/dali/public-api/math/matrix.h +++ b/dali/public-api/math/matrix.h @@ -18,7 +18,11 @@ * */ +// EXTERNAL INCLUDES +#include + // INTERNAL INCLUDES +#include #include namespace Dali diff --git a/dali/public-api/math/rect.h b/dali/public-api/math/rect.h index 44ac5ed..89e815c 100644 --- a/dali/public-api/math/rect.h +++ b/dali/public-api/math/rect.h @@ -20,6 +20,7 @@ // EXTERNAL INCLUDES #include +#include // INTERNAL INCLUDES #include @@ -264,6 +265,44 @@ inline bool Rect::IsEmpty() const fabsf(height) <= GetRangedEpsilon(height, height)); } +/** + * @brief Convert the value of the rectangle into a string and insert in to an output stream. + * + * @param [in] stream The output stream operator. + * @param [in] rectangle the rectangle to output + * @return The output stream operator. + */ +inline std::ostream& operator<< (std::ostream& stream, const Rect& rectangle) +{ + return stream << "[" << rectangle.x << ", " << rectangle.y << ", " << rectangle.width << ", " << rectangle.height << "]"; +} + +/** + * @brief Convert the value of the rectangle into a string and insert in to an output stream. + * + * @param [in] stream The output stream operator. + * @param [in] rectangle the rectangle to output + * @return The output stream operator. + */ +inline std::ostream& operator<< (std::ostream& stream, const Rect& rectangle) +{ + return stream << "[" << rectangle.x << ", " << rectangle.y << ", " << rectangle.width << ", " << rectangle.height << "]"; +} + +/** + * @brief Convert the value of the rectangle into a string and insert in to an output stream. + * + * @param [in] stream The output stream operator. + * @param [in] rectangle the rectangle to output + * @return The output stream operator. + */ +inline std::ostream& operator<< (std::ostream& stream, const Rect& rectangle) +{ + return stream << "[" << rectangle.x << ", " << rectangle.y << ", " << rectangle.width << ", " << rectangle.height << "]"; +} + + + } // namespace Dali #endif // __DALI_RECT_H__ diff --git a/dali/public-api/math/vector2.cpp b/dali/public-api/math/vector2.cpp index d5475d0..52500ef 100644 --- a/dali/public-api/math/vector2.cpp +++ b/dali/public-api/math/vector2.cpp @@ -20,7 +20,6 @@ // EXTERNAL INCLUDES #include -#include // INTERNAL INCLUDES #include diff --git a/dali/public-api/math/vector2.h b/dali/public-api/math/vector2.h index dd1e7ab..7e4c552 100644 --- a/dali/public-api/math/vector2.h +++ b/dali/public-api/math/vector2.h @@ -19,7 +19,7 @@ */ // EXTERNAL INCLUDES -#include +#include // INTERNAL INCLUDES #include diff --git a/dali/public-api/math/vector3.h b/dali/public-api/math/vector3.h index 22d18bb..7531f2a 100644 --- a/dali/public-api/math/vector3.h +++ b/dali/public-api/math/vector3.h @@ -19,7 +19,7 @@ */ // EXTERNAL INCLUDES -#include +#include // INTERNAL INCLUDES #include diff --git a/dali/public-api/math/vector4.h b/dali/public-api/math/vector4.h index 6cfc206..132e7d1 100644 --- a/dali/public-api/math/vector4.h +++ b/dali/public-api/math/vector4.h @@ -19,7 +19,7 @@ */ // EXTERNAL INCLUDES -#include +#include // INTERNAL INCLUDES #include diff --git a/dali/public-api/object/property-types.cpp b/dali/public-api/object/property-types.cpp index 6ad7d73..49e5cda 100644 --- a/dali/public-api/object/property-types.cpp +++ b/dali/public-api/object/property-types.cpp @@ -47,7 +47,7 @@ namespace PropertyTypes { DALI_EXPORT_API -const char* GetName(Property::Type type) +const char* const GetName(Property::Type type) { if (type < Property::TYPE_COUNT) { diff --git a/dali/public-api/object/property-types.h b/dali/public-api/object/property-types.h index 2c1df6d..35d6541 100644 --- a/dali/public-api/object/property-types.h +++ b/dali/public-api/object/property-types.h @@ -46,7 +46,7 @@ namespace PropertyTypes * @param [in] type The property type. * @return The name of this type. */ -DALI_IMPORT_API const char* GetName(Property::Type type); +DALI_IMPORT_API const char* const GetName(Property::Type type); /** * @brief Retrieve an enumerated property type. diff --git a/dali/public-api/object/property-value.cpp b/dali/public-api/object/property-value.cpp index 2d91f3e..4e429f2 100644 --- a/dali/public-api/object/property-value.cpp +++ b/dali/public-api/object/property-value.cpp @@ -975,5 +975,108 @@ int Property::Value::GetSize() const return ret; } +std::ostream& operator<< (std::ostream& stream, const Property::Value& value ) +{ + + const Property::Value::Impl& impl( *value.mImpl ); + + switch( impl.mType ) + { + case Dali::Property::STRING: + { + stream << AnyCast(impl.mValue).c_str(); + break; + } + case Dali::Property::VECTOR2: + { + stream << AnyCast(impl.mValue); + break; + } + case Dali::Property::VECTOR3: + { + stream << AnyCast(impl.mValue); + break; + } + case Dali::Property::VECTOR4: + { + stream << AnyCast(impl.mValue); + break; + } + case Dali::Property::MATRIX: + { + stream << AnyCast(impl.mValue); + break; + } + case Dali::Property::BOOLEAN: + { + stream << AnyCast(impl.mValue); + break; + } + case Dali::Property::FLOAT: + { + stream << AnyCast(impl.mValue); + break; + } + case Dali::Property::INTEGER: + { + stream << AnyCast(impl.mValue); + break; + } + case Dali::Property::UNSIGNED_INTEGER: + { + stream << AnyCast(impl.mValue); + break; + } + case Dali::Property::RECTANGLE: + { + Dali::Rect rect; // Propery Value rectangles are currently integer based + value.Get( rect ); + stream << rect; + break; + } + case Dali::Property::MATRIX3: + { + stream << AnyCast(impl.mValue); + break; + } + case Dali::Property::ROTATION: + { + // @todo this may change to Quaternion + Dali::Quaternion q; + value.Get( q ); + Dali::Vector4 v4 = q.EulerAngles(); + stream << v4; + break; + } + + case Dali::Property::ARRAY: + { + // @todo Need to think about the best way to support array + // E.g Do we want to create a JSON style array like: + // [ {"property-name-0":"property-value-0", "property-name-1":"property-value-1"} ] + stream << "ARRAY unsupported"; + break; + } + case Dali::Property::MAP: + { + Dali::Property::Map map; + value.Get( map ); + stream << "Map containing " << map.Count() << " elements"; + break; + } + case Dali::Property::TYPE_COUNT: + { + stream << "unsupported TYPE_COUNT"; + break; + } + default: + { + stream << "unsupported type = " << value.GetType(); + break; + } + } + return stream; +} + } // namespace Dali diff --git a/dali/public-api/object/property-value.h b/dali/public-api/object/property-value.h index 55746bf..f45fa49 100644 --- a/dali/public-api/object/property-value.h +++ b/dali/public-api/object/property-value.h @@ -18,6 +18,9 @@ * */ +// EXTERNAL INCLUDES +#include + // INTERNAL INCLUDES #include #include @@ -40,6 +43,8 @@ class DALI_IMPORT_API Property::Value { public: + friend std::ostream& operator<< (std::ostream& ouputStream, const Property::Value& value); + /** * @brief Default constructor. * @@ -417,6 +422,16 @@ private: Impl* mImpl; ///< Pointer to the implementation }; +/** + * @brief Convert the value of the property into a string and append to an output stream. + * + * @param [in] ouputStream The output stream operator. + * @param [in] value The value to insert + * @return The output stream operator. + */ +DALI_IMPORT_API std::ostream& operator<< (std::ostream& ouputStream, const Property::Value& value); + + } // namespace Dali #endif // __DALI_PROPERTY_VALUE_H__