/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2019 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.
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::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;
- }
- } // switch(type)
-
-} // CheckTypeName
-
template <typename T>
struct CheckCopyCtorP
{
END_TEST;
}
+int UtcDaliPropertyValueConstructorsExtentsTypeP(void)
+{
+ Property::Value value( Property::EXTENTS );
+
+ DALI_TEST_CHECK( value.GetType() == Property::EXTENTS );
+ DALI_TEST_CHECK( value.Get<Extents>() == Extents( 0u, 0u, 0u, 0u ) );
+
+ END_TEST;
+}
+
+int UtcDaliPropertyValueConstructorsExtentsType2P(void)
+{
+ Property::Value value( Property::VECTOR4 );
+
+ DALI_TEST_CHECK( value.GetType() == Property::VECTOR4 );
+ DALI_TEST_CHECK( value.Get<Extents>() == Extents( 0u, 0u, 0u, 0u ) );
+
+ END_TEST;
+}
+
int UtcDaliPropertyValueCopyConstructorP(void)
{
Property::Value value;
END_TEST;
}
+int UtcDaliPropertyValueMoveConstructor(void)
+{
+ Property::Value value1( Vector4::ONE );
+ DALI_TEST_EQUALS( Property::VECTOR4, value1.GetType(), TEST_LOCATION );
+
+ Vector4 valueVector;
+ DALI_TEST_EQUALS( true, value1.Get( valueVector ), TEST_LOCATION ); // Able to convert
+ DALI_TEST_EQUALS( valueVector, Vector4::ONE, TEST_LOCATION );
+
+ Property::Value value2( std::move( value1 ) );
+ DALI_TEST_EQUALS( Property::NONE, value1.GetType(), TEST_LOCATION );
+ DALI_TEST_EQUALS( false, value1.Get( valueVector ), TEST_LOCATION ); // Unable to convert, but no crash either
+ DALI_TEST_EQUALS( Property::VECTOR4, value2.GetType(), TEST_LOCATION );
+ DALI_TEST_EQUALS( true, value2.Get( valueVector ), TEST_LOCATION ); // Able to convert
+ DALI_TEST_EQUALS( valueVector, Vector4::ONE, TEST_LOCATION );
+
+ END_TEST;
+}
+
+int UtcDaliPropertyValueMoveConstructorArray(void)
+{
+ Property::Array array;
+ array.PushBack( 1 );
+ array.PushBack( 2 );
+ array.PushBack( 3 );
+ DALI_TEST_EQUALS( 3u, array.Size(), TEST_LOCATION );
+
+ Property::Value value( std::move( array ) );
+ DALI_TEST_ASSERTION( array.Size(), "Cannot use an object previously used as an r-value" ); // Our local variable should become invalid
+
+ Property::Array* arrayPtr = value.GetArray();
+ DALI_TEST_CHECK( arrayPtr );
+ DALI_TEST_EQUALS( 3u, arrayPtr->Size(), TEST_LOCATION );
+
+ END_TEST;
+}
+
+int UtcDaliPropertyValueMoveConstructorMap(void)
+{
+ Property::Map map;
+ map[ 1 ] = 1;
+ map[ 2 ] = 2;
+ map[ 3 ] = 3;
+ DALI_TEST_EQUALS( 3u, map.Count(), TEST_LOCATION );
+
+ Property::Value value( std::move( map ) );
+ DALI_TEST_ASSERTION( map.Count(), "Cannot use an object previously used as an r-value" ); // Our local variable should become invalid
+
+ Property::Map* mapPtr = value.GetMap();
+ DALI_TEST_CHECK( mapPtr );
+ DALI_TEST_EQUALS( 3u, mapPtr->Count(), TEST_LOCATION );
+
+ END_TEST;
+}
+
int UtcDaliPropertyValueAssignmentSelfP(void)
{
Property::Value value;
END_TEST;
}
+int UtcDaliPropertyValueAssignmentOperatorExtentsP(void)
+{
+ Property::Value value;
+ value = Property::Value( Extents( 4, 3, 2, 1 ) ); // mismatch
+ DALI_TEST_CHECK( Extents( 4, 3, 2, 1 ) == value.Get<Extents>() );
+ Property::Value copy( Property::EXTENTS );
+ copy = value; // match
+ Extents copyExtents;
+ copy.Get(copyExtents);
+ DALI_TEST_CHECK( Extents( 4, 3, 2, 1 ) == copyExtents );
+ END_TEST;
+}
+
+int UtcDaliPropertyValueMoveAssignmentOperator(void)
+{
+ Property::Value value1( Vector4::ONE );
+ DALI_TEST_EQUALS( Property::VECTOR4, value1.GetType(), TEST_LOCATION );
+
+ Vector4 valueVector;
+ DALI_TEST_EQUALS( true, value1.Get( valueVector ), TEST_LOCATION ); // Able to convert
+ DALI_TEST_EQUALS( valueVector, Vector4::ONE, TEST_LOCATION );
+
+ Property::Value value2;
+ value2 = std::move( value1 );
+ DALI_TEST_EQUALS( Property::NONE, value1.GetType(), TEST_LOCATION );
+ DALI_TEST_EQUALS( false, value1.Get( valueVector ), TEST_LOCATION ); // Unable to convert, but no crash either
+ DALI_TEST_EQUALS( Property::VECTOR4, value2.GetType(), TEST_LOCATION );
+ DALI_TEST_EQUALS( true, value2.Get( valueVector ), TEST_LOCATION ); // Able to convert
+ DALI_TEST_EQUALS( valueVector, Vector4::ONE, TEST_LOCATION );
+
+ // Change to another value type
+ value2 = std::move( Property::Value( 1.0f ) );
+ DALI_TEST_EQUALS( false, value2.Get( valueVector ), TEST_LOCATION ); // Should not be able to convert to a Vector4 now
+ float valueFloat;
+ DALI_TEST_EQUALS( true, value2.Get( valueFloat ), TEST_LOCATION ); // Should be able to convert to a float now
+ DALI_TEST_EQUALS( valueFloat, 1.0f, TEST_LOCATION );
+
+ // Ensure self assignment doesn't do anything silly
+ value2 = std::move( value2 );
+ DALI_TEST_EQUALS( true, value2.Get( valueFloat ), TEST_LOCATION );
+ DALI_TEST_EQUALS( valueFloat, 1.0f, TEST_LOCATION );
+
+ END_TEST;
+}
+
int UtcDaliPropertyValueGetTypeP(void)
{
Property::Value value;
END_TEST;
}
+int UtcDaliPropertyValueGetVector2fromVector3P(void)
+{
+ Property::Value value( Vector3(1.f,2.f,3.f) );
+ Vector2 result;
+ DALI_TEST_EQUALS( Vector2(1.0f,2.0f), value.Get< Vector2 >(), TEST_LOCATION );
+ DALI_TEST_EQUALS( true, value.Get( result ), TEST_LOCATION );
+ DALI_TEST_EQUALS( Vector2(1.0f,2.0f), result, TEST_LOCATION );
+ END_TEST;
+}
+
+int UtcDaliPropertyValueGetVector2fromVector4P(void)
+{
+ Property::Value value( Vector4(1.f,2.f,3.f,4.f) );
+ Vector2 result;
+ DALI_TEST_EQUALS( Vector2(1.0f,2.0f), value.Get< Vector2 >(), TEST_LOCATION );
+ DALI_TEST_EQUALS( true, value.Get( result ), TEST_LOCATION );
+ DALI_TEST_EQUALS( Vector2(1.0f,2.0f), result, TEST_LOCATION );
+ END_TEST;
+}
+
int UtcDaliPropertyValueGetVector2N(void)
{
Property::Value value;
END_TEST;
}
+int UtcDaliPropertyValueGetVector3FromVector2P(void)
+{
+ Property::Value value( Vector2(1.0f,2.0f) );
+ Vector3 result(99.f,88.f,77.f);
+ DALI_TEST_EQUALS( Vector3(1.0f,2.0f,0.f), value.Get< Vector3 >(), TEST_LOCATION );
+ DALI_TEST_EQUALS( true, value.Get( result ), TEST_LOCATION );
+ DALI_TEST_EQUALS( Vector3(1.0f,2.0f,0.f), result, TEST_LOCATION );
+ END_TEST;
+}
+
+int UtcDaliPropertyValueGetVector3FromVector4P(void)
+{
+ Property::Value value( Vector4(4.f,3.f,2.f,1.f) );
+ Vector3 result;
+ DALI_TEST_EQUALS( Vector3(4.f,3.f,2.f), value.Get< Vector3 >(), TEST_LOCATION );
+ DALI_TEST_EQUALS( true, value.Get( result ), TEST_LOCATION );
+ DALI_TEST_EQUALS( Vector3(4.f,3.f,2.f), result, TEST_LOCATION );
+ END_TEST;
+}
+
int UtcDaliPropertyValueGetVector3N(void)
{
Property::Value value;
END_TEST;
}
+int UtcDaliPropertyValueGetVector4FromVector2P(void)
+{
+ Property::Value value( Vector2(-1.f,-3.f) );
+ Vector4 result(99.f,88.f,77.f,66.f);
+ DALI_TEST_EQUALS( Vector4(-1.f,-3.f,0.f,0.f), value.Get< Vector4 >(), TEST_LOCATION );
+ DALI_TEST_EQUALS( true, value.Get( result ), TEST_LOCATION );
+ DALI_TEST_EQUALS( Vector4(-1.f,-3.f,0.f,0.f), result, TEST_LOCATION );
+ END_TEST;
+}
+
+int UtcDaliPropertyValueGetVector4FromVector3P(void)
+{
+ Property::Value value( Vector3(1.f,2.f,-1.f) );
+ Vector4 result(99.f,88.f,77.f,66.f);
+ DALI_TEST_EQUALS( Vector4(1.f,2.f,-1.f,0.f), value.Get< Vector4 >(), TEST_LOCATION );
+ DALI_TEST_EQUALS( true, value.Get( result ), TEST_LOCATION );
+ DALI_TEST_EQUALS( Vector4(1.f,2.f,-1.f,0.f), result, TEST_LOCATION );
+ END_TEST;
+}
+
int UtcDaliPropertyValueGetVector4N(void)
{
Property::Value value;
END_TEST;
}
+int UtcDaliPropertyValueGetExtentsP(void)
+{
+ Property::Value value( Extents( 1u, 2u, 3u, 4u ) );
+ Extents result( 4u, 3u, 2u, 1u );
+ DALI_TEST_EQUALS( Extents( 1u, 2u, 3u, 4u ), value.Get<Extents>(), TEST_LOCATION );
+ DALI_TEST_EQUALS( true, value.Get( result ), TEST_LOCATION );
+ DALI_TEST_EQUALS( Extents( 1u, 2u, 3u, 4u ), result, TEST_LOCATION );
+ END_TEST;
+}
+
+int UtcDaliPropertyValueEnum(void)
+{
+ enum class E { zero, e };
+ Property::Value value( E::e );
+ DALI_TEST_EQUALS( static_cast<int>(E::e), static_cast<int>(value.Get<E>()), TEST_LOCATION );
+ DALI_TEST_EQUALS( static_cast<int>(E::e), value.Get<int>(), TEST_LOCATION );
+ E result;
+ DALI_TEST_EQUALS( true, value.Get( result ), TEST_LOCATION );
+ DALI_TEST_EQUALS( static_cast<int>(E::e), static_cast<int>(result), TEST_LOCATION );
+ int result2;
+ DALI_TEST_EQUALS( true, value.Get( result2 ), TEST_LOCATION );
+ DALI_TEST_EQUALS( static_cast<int>(E::e), result2, TEST_LOCATION );
+ END_TEST;
+}
+
int UtcDaliPropertyValueOutputStream(void)
{
TestApplication application;
Property::Value empty;
std::ostringstream stream;
stream << empty;
- DALI_TEST_EQUALS( stream.str(), "empty type", TEST_LOCATION );
+ DALI_TEST_EQUALS( stream.str(), "undefined type", TEST_LOCATION );
}
{
value = Property::Value( Matrix3::IDENTITY );
std::ostringstream stream;
stream << value;
- DALI_TEST_CHECK( stream.str() == "[ [1, 0, 0], [0, 1, 0], [0, 0, 1] ]" );
+ 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] ]" );
+ DALI_TEST_CHECK( stream.str() == "[ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ]" );
}
{
DALI_TEST_CHECK( !stream.str().compare("Map(3) = {color:[1, 0.5, 1, 1], timePeriod:Map(2) = {key:value, duration:10}, texCoords:Array(4) = [[1, 0], [0, 1], [1, 0], [0, 0.5]]}"));
}
+ {
+ value = Property::Value( Extents( 1u, 2u, 3u, 4u ) );
+ std::ostringstream stream;
+ stream << value;
+ DALI_TEST_CHECK( stream.str() == "[1, 2, 3, 4]" );
+ }
END_TEST;
}