X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=automated-tests%2Fsrc%2Fdali%2Futc-Dali-Handle.cpp;h=6c6c607396d99886eab9bd31afca127128b091a4;hb=e08e2992259823c5f9832ad959ffa510b0445a6c;hp=1ff33c1c506b7d7f3904d2baf1e5ab30da3ddcb3;hpb=bb2b21e96ce1b0ab4209d24f435f4e6889d80283;p=platform%2Fcore%2Fuifw%2Fdali-core.git diff --git a/automated-tests/src/dali/utc-Dali-Handle.cpp b/automated-tests/src/dali/utc-Dali-Handle.cpp index 1ff33c1..6c6c607 100644 --- a/automated-tests/src/dali/utc-Dali-Handle.cpp +++ b/automated-tests/src/dali/utc-Dali-Handle.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2018 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. @@ -19,7 +19,12 @@ #include #include +#include +#include #include "dali-test-suite-utils/dali-test-suite-utils.h" +#include "dali-test-suite-utils/test-custom-actor.h" + +#include using namespace Dali; @@ -57,94 +62,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 @@ -156,6 +73,7 @@ int UtcDaliHandleConstructorVoid(void) Handle object; DALI_TEST_CHECK(!object); + END_TEST; } @@ -236,7 +154,7 @@ int UtcDaliHandleGetPropertyCount(void) int defaultPropertyCount( actor.GetPropertyCount() ); // Register a dynamic property - actor.RegisterProperty( "test-property", float(123.0f) ); + actor.RegisterProperty( "testProperty", float(123.0f) ); DALI_TEST_CHECK( (defaultPropertyCount + 1u) == actor.GetPropertyCount() ); END_TEST; } @@ -247,31 +165,106 @@ int UtcDaliHandleGetPropertyName(void) TestApplication application; Actor actor = Actor::New(); - DALI_TEST_CHECK( "parent-origin" == actor.GetPropertyName( Actor::Property::PARENT_ORIGIN ) ); + DALI_TEST_CHECK( "parentOrigin" == actor.GetPropertyName( Actor::Property::PARENT_ORIGIN ) ); // Register a dynamic property - std::string name("this-name-should-match"); + std::string name("thisNameShouldMatch"); Property::Index index = actor.RegisterProperty( name, float(123.0f) ); DALI_TEST_CHECK( name == actor.GetPropertyName( index ) ); END_TEST; } -int UtcDaliHandleGetPropertyIndex(void) +int UtcDaliHandleGetPropertyIndex01(void) { tet_infoline("Positive Test Dali::Handle::GetPropertyIndex()"); TestApplication application; Actor actor = Actor::New(); - DALI_TEST_CHECK( Actor::Property::PARENT_ORIGIN == actor.GetPropertyIndex("parent-origin") ); + DALI_TEST_CHECK( Actor::Property::PARENT_ORIGIN == actor.GetPropertyIndex("parentOrigin") ); // Register a dynamic property - std::string name("this-name-should-match"); + std::string name("thisNameShouldMatch"); Property::Index index = actor.RegisterProperty( name, float(123.0f) ); DALI_TEST_CHECK( index == actor.GetPropertyIndex( name ) ); END_TEST; } +int UtcDaliHandleGetPropertyIndex02(void) +{ + tet_infoline("Positive Test Dali::Handle::GetPropertyIndex() int key"); + TestApplication application; + + Stage stage = Stage::GetCurrent(); + + Actor actor = Actor::New(); + stage.Add( actor ); + + const unsigned int defaultPropertyCount = actor.GetPropertyCount(); + + application.SendNotification(); + application.Render(); + + Property::Index key1 = CORE_PROPERTY_MAX_INDEX+1; + Property::Index key2 = CORE_PROPERTY_MAX_INDEX+2; + + const Vector4 testColor(0.5f, 0.2f, 0.9f, 1.0f); + const float withFlake(99.f); + + Property::Index index1 = actor.RegisterProperty( "MyPropertyOne", Vector3::ONE ); + Property::Index index2 = DevelHandle::RegisterProperty( actor, key1, "sideColor", testColor); + Property::Index index3 = actor.RegisterProperty( "MyPropertyTwo", Vector3::ONE ); + Property::Index index4 = DevelHandle::RegisterProperty( actor, key2, "iceCream", withFlake ); + Property::Index index5 = actor.RegisterProperty( "MyPropertyThree", Vector3::ONE ); + + application.SendNotification(); + application.Render(); + + // Test that we can get the property index from the integer key + Property::Index testIndex1 = DevelHandle::GetPropertyIndex( actor, key1 ); + Property::Index testIndex2 = DevelHandle::GetPropertyIndex( actor, key2 ); + + DALI_TEST_EQUALS( index2, testIndex1, TEST_LOCATION ); + DALI_TEST_EQUALS( index4, testIndex2, TEST_LOCATION ); + + // Test that we keep the same indices on the named properties + Property::Index testIndex = actor.GetPropertyIndex("MyPropertyOne"); + DALI_TEST_EQUALS(testIndex, index1, TEST_LOCATION); + testIndex = actor.GetPropertyIndex("MyPropertyTwo"); + DALI_TEST_EQUALS(testIndex, index3, TEST_LOCATION); + testIndex = actor.GetPropertyIndex("MyPropertyThree"); + DALI_TEST_EQUALS(testIndex, index5, TEST_LOCATION); + testIndex = actor.GetPropertyIndex("sideColor"); + DALI_TEST_EQUALS(testIndex, index2, TEST_LOCATION); + testIndex = actor.GetPropertyIndex("iceCream"); + DALI_TEST_EQUALS(testIndex, index4, TEST_LOCATION); + + DALI_TEST_EQUALS(defaultPropertyCount+5, actor.GetPropertyCount(), TEST_LOCATION); + END_TEST; +} + +int UtcDaliHandleGetPropertyIndex03(void) +{ + TestApplication application; + + Actor actor = Actor::New(); + + std::string myName("croydon"); + Property::Index intKey = CORE_PROPERTY_MAX_INDEX+1; + Property::Value value( Color::GREEN ); + Property::Index myIndex = DevelHandle::RegisterProperty( actor, intKey, myName, value ); + + DALI_TEST_EQUALS( myIndex, DevelHandle::GetPropertyIndex( actor, intKey ), TEST_LOCATION ); + + Property::Key key1(myName); + Property::Key key2(intKey); + + DALI_TEST_EQUALS( myIndex, DevelHandle::GetPropertyIndex( actor, key1 ), TEST_LOCATION ); + DALI_TEST_EQUALS( myIndex, DevelHandle::GetPropertyIndex( actor, key2 ), TEST_LOCATION ); + END_TEST; +} + + int UtcDaliHandleIsPropertyWritable(void) { tet_infoline("Positive Test Dali::Handle::IsPropertyWritable()"); @@ -307,6 +300,7 @@ int UtcDaliHandleIsPropertyWritable(void) DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::COLOR_GREEN ) ); DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::COLOR_BLUE ) ); DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::COLOR_ALPHA ) ); + DALI_TEST_CHECK( true == actor.IsPropertyWritable( DevelActor::Property::OPACITY ) ); // World-properties are not writable: DALI_TEST_CHECK( false == actor.IsPropertyWritable( Actor::Property::WORLD_POSITION ) ); @@ -355,6 +349,7 @@ int UtcDaliHandleIsPropertyAnimatable(void) DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::COLOR_GREEN ) ); DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::COLOR_BLUE ) ); DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::COLOR_ALPHA ) ); + DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( DevelActor::Property::OPACITY ) ); // World-properties can not be animated DALI_TEST_CHECK( false == actor.IsPropertyAnimatable( Actor::Property::WORLD_POSITION ) ); @@ -402,6 +397,7 @@ int UtcDaliHandleIsPropertyAConstraintInput(void) DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::COLOR_GREEN ) ); DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::COLOR_BLUE ) ); DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::COLOR_ALPHA ) ); + DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( DevelActor::Property::OPACITY ) ); DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::WORLD_POSITION ) ); DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::WORLD_ORIENTATION ) ); DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::WORLD_SCALE ) ); @@ -417,9 +413,7 @@ int UtcDaliHandleIsPropertyAConstraintInput(void) DALI_TEST_CHECK( false == actor.IsPropertyAConstraintInput( Actor::Property::INHERIT_ORIENTATION ) ); DALI_TEST_CHECK( false == actor.IsPropertyAConstraintInput( Actor::Property::INHERIT_SCALE ) ); DALI_TEST_CHECK( false == actor.IsPropertyAConstraintInput( Actor::Property::COLOR_MODE ) ); - DALI_TEST_CHECK( false == actor.IsPropertyAConstraintInput( Actor::Property::POSITION_INHERITANCE ) ); DALI_TEST_CHECK( false == actor.IsPropertyAConstraintInput( Actor::Property::DRAW_MODE ) ); - DALI_TEST_CHECK( false == actor.IsPropertyAConstraintInput( Actor::Property::SIZE_MODE ) ); DALI_TEST_CHECK( false == actor.IsPropertyAConstraintInput( Actor::Property::SIZE_MODE_FACTOR ) ); END_TEST; @@ -430,7 +424,6 @@ int UtcDaliHandleGetPropertyType(void) { tet_infoline("Positive Test Dali::Handle::GetPropertyType()"); TestApplication application; - unsigned int unsingedIntTest = 33; Actor actor = Actor::New(); DALI_TEST_CHECK( Property::VECTOR3 == actor.GetPropertyType( Actor::Property::PARENT_ORIGIN ) ); @@ -443,13 +436,13 @@ int UtcDaliHandleGetPropertyType(void) DALI_TEST_CHECK( Property::VECTOR4 == actor.GetPropertyType( Actor::Property::COLOR ) ); // 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) ); - Property::Index rotationIndex = actor.RegisterProperty( "rotation-property", AngleAxis(Degree(180.0f), Vector3::YAXIS) ); + Property::Index boolIndex = actor.RegisterProperty( "boolProperty", bool(true) ); + Property::Index floatIndex = actor.RegisterProperty( "floatProperty", float(123.0f) ); + Property::Index intIndex = actor.RegisterProperty( "intProperty", 123 ); + Property::Index vector2Index = actor.RegisterProperty( "vector2Property", Vector2(1.0f, 2.0f) ); + Property::Index vector3Index = actor.RegisterProperty( "vector3Property", Vector3(1.0f, 2.0f, 3.0f) ); + Property::Index vector4Index = actor.RegisterProperty( "vector4Property", Vector4(1.0f, 2.0f, 3.0f, 4.0f) ); + Property::Index rotationIndex = actor.RegisterProperty( "rotationProperty", AngleAxis(Degree(180.0f), Vector3::YAXIS) ); DALI_TEST_CHECK( Property::BOOLEAN == actor.GetPropertyType( boolIndex ) ); DALI_TEST_CHECK( Property::FLOAT == actor.GetPropertyType( floatIndex ) ); @@ -460,14 +453,13 @@ int UtcDaliHandleGetPropertyType(void) DALI_TEST_CHECK( Property::ROTATION == actor.GetPropertyType( rotationIndex ) ); // Non animatable properties - Property::Index nonAnimStringIndex = actor.RegisterProperty( "man-from-delmonte", std::string("yes"), Property::READ_WRITE); + Property::Index nonAnimStringIndex = actor.RegisterProperty( "manFromDelmonte", std::string("yes"), Property::READ_WRITE); Property::Index nonAnimV2Index = actor.RegisterProperty( "v2", Vector2(1.f, 2.f), Property::READ_WRITE); Property::Index nonAnimV3Index = actor.RegisterProperty( "v3", Vector3(1.f, 2.f, 3.f), Property::READ_WRITE); 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 ); DALI_TEST_CHECK( nonAnimV2Index != Property::INVALID_INDEX ); @@ -476,7 +468,6 @@ int UtcDaliHandleGetPropertyType(void) 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 ) ); DALI_TEST_CHECK( Property::VECTOR2 == actor.GetPropertyType( nonAnimV2Index ) ); @@ -485,7 +476,6 @@ int UtcDaliHandleGetPropertyType(void) 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 ) ); DALI_TEST_CHECK( !actor.IsPropertyAnimatable( nonAnimV2Index ) ); @@ -494,7 +484,6 @@ int UtcDaliHandleGetPropertyType(void) 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(), TEST_LOCATION ); DALI_TEST_EQUALS( Vector2(1.f, 2.f) , actor.GetProperty( nonAnimV2Index ).Get(), TEST_LOCATION ); @@ -503,29 +492,21 @@ int UtcDaliHandleGetPropertyType(void) DALI_TEST_EQUALS( true, actor.GetProperty( nonAnimBooleanIndex ).Get(), TEST_LOCATION ); DALI_TEST_EQUALS( 0.f, actor.GetProperty( nonAnimFloatIndex ).Get(), TEST_LOCATION ); DALI_TEST_EQUALS( 0, actor.GetProperty( nonAnimIntegerIndex ).Get(), TEST_LOCATION ); - DALI_TEST_EQUALS( unsingedIntTest, actor.GetProperty( nonAnimUnsignedIntIndex ).Get(), TEST_LOCATION ); END_TEST; } -int UtcDaliHandleNonAnimtableProperties(void) +int UtcDaliHandleNonAnimatableProperties(void) { tet_infoline("Test Non Animatable Properties"); TestApplication application; Actor actor = Actor::New(); - Property::Index nonAnimStringIndex = actor.RegisterProperty( "man-from-delmonte", std::string("no"), Property::READ_WRITE); + Property::Index nonAnimStringIndex = actor.RegisterProperty( "manFromDelmonte", std::string("no"), Property::READ_WRITE); //// modify writable? - try - { - actor.SetProperty( nonAnimStringIndex, Property::Value("yes") ); - } - catch (Dali::DaliException& e) - { - DALI_TEST_CHECK(!"exception"); - } + actor.SetProperty( nonAnimStringIndex, Property::Value("yes") ); DALI_TEST_CHECK( "yes" == actor.GetProperty( nonAnimStringIndex ).Get() ); @@ -535,17 +516,8 @@ int UtcDaliHandleNonAnimtableProperties(void) DALI_TEST_CHECK(!actor.IsPropertyAnimatable(readonly)); DALI_TEST_CHECK(!actor.IsPropertyWritable(readonly)); - bool exception = false; - try - { - actor.SetProperty( readonly, Property::Value(1.f) ); - } - catch (Dali::DaliException& e) - { - exception = true; - } - - DALI_TEST_CHECK(!exception);// trying to set a read-only property is a no-op + actor.SetProperty( readonly, Property::Value(1.f) ); + // trying to set a read-only property is a no-op DALI_TEST_EQUALS( 0.f, actor.GetProperty( readonly ).Get(), TEST_LOCATION ); @@ -555,38 +527,21 @@ int UtcDaliHandleNonAnimtableProperties(void) DALI_TEST_CHECK(actor.IsPropertyAnimatable(write_anim)); DALI_TEST_CHECK(actor.IsPropertyWritable(write_anim)); - exception = false; - try - { - actor.SetProperty( write_anim, Property::Value(1.f) ); - } - catch (Dali::DaliException& e) - { - exception = true; - } - - DALI_TEST_CHECK(!exception); + actor.SetProperty( write_anim, Property::Value(1.f) ); - //// animate a non animatable property is a noop? + //// animate a non animatable property throws float durationSeconds(2.0f); Animation animation = Animation::New(durationSeconds); bool relativeValue(true); - - exception = false; - try { - animation.AnimateBy(Property(actor, nonAnimStringIndex), relativeValue, AlphaFunctions::EaseIn); - animation.Play(); - application.SendNotification(); - application.Render(static_cast(durationSeconds*0100.0f)/* some progress */); + animation.AnimateBy(Property(actor, nonAnimStringIndex), relativeValue, AlphaFunction::EASE_IN); } - catch (Dali::DaliException& e) + catch ( Dali::DaliException& e ) { - exception = true; + DALI_TEST_ASSERT( e, "Property type is not animatable", TEST_LOCATION ); } - DALI_TEST_CHECK(!exception); DALI_TEST_EQUALS( "yes", actor.GetProperty( nonAnimStringIndex ).Get(), TEST_LOCATION ); END_TEST; @@ -600,69 +555,34 @@ int UtcDaliHandleNonAnimtableCompositeProperties(void) Actor actor = Actor::New(); Property::Value value(Property::ARRAY); - Property::Array anArray; - DALI_TEST_CHECK( Property::Value(anArray).GetType() == Property::ARRAY ); // 2nd constructor - - value.AppendItem( Property::Value( 0.f ) ); - value.AppendItem( "a string" ); - value.SetItem(0, Property::Value( 5.f )); // exercise SetItem + Property::Array* array = value.GetArray(); + DALI_TEST_CHECK( array ); - int index = value.AppendItem( Vector3(1,2,3) ); + array->PushBack( Property::Value( 0.1f ) ); + array->PushBack( "a string" ); + array->PushBack( Property::Value( Vector3(1,2,3) ) ); - DALI_TEST_EQUALS( 2, index, TEST_LOCATION); - DALI_TEST_EQUALS( 3, value.GetSize(), TEST_LOCATION); + DALI_TEST_EQUALS( 3u, array->Count(), TEST_LOCATION ); - Property::Index propertyIndex = actor.RegisterProperty( "composite", value, Property::READ_WRITE); + Property::Index propertyIndex = actor.RegisterProperty( "composite", value, Property::READ_WRITE ); Property::Value out = actor.GetProperty( propertyIndex ); + Property::Array* outArray = out.GetArray(); + DALI_TEST_CHECK( outArray != NULL ); - DALI_TEST_CHECK( Property::FLOAT == out.GetItem(0).GetType()); - DALI_TEST_CHECK( Property::STRING == out.GetItem(1).GetType()); - DALI_TEST_CHECK( Property::VECTOR3 == out.GetItem(2).GetType()); - - DALI_TEST_EQUALS( 5.f, out.GetItem(0).Get(), TEST_LOCATION); - DALI_TEST_EQUALS( "a string", out.GetItem(1).Get(), TEST_LOCATION); - DALI_TEST_EQUALS( Vector3(1,2,3), out.GetItem(2).Get(), TEST_LOCATION); - - // Property Maps - Property::Value valueMap(Property::MAP); - Property::Map aKindofMap; - DALI_TEST_CHECK( Property::Value(aKindofMap).GetType() == Property::MAP ); // 2nd constructor - - valueMap.SetValue("key", 5.f); - valueMap.SetValue("2key", "a string"); - - 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); - DALI_TEST_EQUALS( "2key", valueMap.GetKey(1), TEST_LOCATION); - - DALI_TEST_EQUALS( 5.f, valueMap.GetValue("key").Get(), TEST_LOCATION); - DALI_TEST_EQUALS( "a string", valueMap.GetValue("2key").Get(), TEST_LOCATION); + DALI_TEST_CHECK( Property::FLOAT == outArray->GetElementAt(0).GetType()); + DALI_TEST_CHECK( Property::STRING == outArray->GetElementAt(1).GetType()); + DALI_TEST_CHECK( Property::VECTOR3 == outArray->GetElementAt(2).GetType()); - valueMap.SetItem(0, Property::Value("a string")); - valueMap.SetItem(1, Property::Value(5.f)); - - DALI_TEST_EQUALS( 5.f, valueMap.GetValue("2key").Get(), TEST_LOCATION); - DALI_TEST_EQUALS( "a string", valueMap.GetValue("key").Get(), TEST_LOCATION); - - // ordered map - valueMap = Property::Value(Property::MAP); - - valueMap.SetValue("key", 5.f); - valueMap.SetValue("2key", "a string"); - - DALI_TEST_EQUALS( 5.f, valueMap.GetItem(0).Get(), TEST_LOCATION); - DALI_TEST_EQUALS( "a string", valueMap.GetItem(1).Get(), TEST_LOCATION); - - DALI_TEST_EQUALS( 2, valueMap.GetSize(), TEST_LOCATION); + DALI_TEST_EQUALS( 0.1f, outArray->GetElementAt(0).Get(), TEST_LOCATION); + DALI_TEST_EQUALS( "a string", outArray->GetElementAt(1).Get(), TEST_LOCATION); + DALI_TEST_EQUALS( Vector3(1,2,3), outArray->GetElementAt(2).Get(), TEST_LOCATION); // composite types not animatable bool exception = false; try { - /* Property::Index mapPropertyIndex = */ actor.RegisterProperty( "compositemap", value, Property::ANIMATABLE); + actor.RegisterProperty( "compositemap", value, Property::ANIMATABLE); } catch (Dali::DaliException& e) { @@ -674,29 +594,18 @@ int UtcDaliHandleNonAnimtableCompositeProperties(void) // Map of maps Property::Value mapOfMaps(Property::MAP); + Property::Map* map = mapOfMaps.GetMap(); - mapOfMaps.SetValue( "key", Property::Value(Property::MAP) ); - mapOfMaps.SetValue( "2key", "a string" ); - - DALI_TEST_EQUALS( "a string", mapOfMaps.GetValue("2key").Get(), TEST_LOCATION); - - mapOfMaps.GetValue("key").SetValue("subkey", 5.f); - - DALI_TEST_EQUALS( true, mapOfMaps.GetValue("key").HasKey("subkey"), TEST_LOCATION); - DALI_TEST_EQUALS( 5.f, mapOfMaps.GetValue("key").GetValue("subkey").Get(), TEST_LOCATION); + map->Insert( "key", Property::Value(Property::MAP) ); + map->Insert( "2key", "a string" ); - // list of maps - Property::Value listOfMaps(Property::ARRAY); + DALI_TEST_EQUALS( "a string", (*map)["2key"].Get(), TEST_LOCATION); - listOfMaps.AppendItem( Property::Value(Property::MAP) ); - listOfMaps.AppendItem( Property::Value(Property::MAP) ); - - listOfMaps.GetItem(0).SetValue("key", 5.f); - listOfMaps.GetItem(1).SetValue("key",10.f); - - DALI_TEST_EQUALS( 5.f, listOfMaps.GetItem(0).GetValue("key").Get(), TEST_LOCATION ); - DALI_TEST_EQUALS( 10.f, listOfMaps.GetItem(1).GetValue("key").Get(), TEST_LOCATION ); + Property::Map* innerMap = map->Find("key")->GetMap(); + innerMap->Insert( "subkey", 5.f ); + DALI_TEST_CHECK( NULL != map->Find("key")->GetMap()->Find("subkey") ); + DALI_TEST_EQUALS( 5.f, map->Find("key")->GetMap()->Find("subkey")->Get(), TEST_LOCATION); END_TEST; } @@ -731,17 +640,93 @@ int UtcDaliHandleSetProperty02(void) END_TEST; } -int UtcDaliHandleRegisterProperty(void) +int UtcDaliHandleRegisterProperty01(void) { tet_infoline("Positive Test Dali::Handle::RegisterProperty()"); TestApplication application; + Stage stage = Stage::GetCurrent(); + Actor actor = Actor::New(); - DALI_TEST_CHECK( ParentOrigin::TOP_LEFT == actor.GetProperty( Actor::Property::PARENT_ORIGIN ).Get() ); + stage.Add( actor ); + + const unsigned int defaultPropertyCount = actor.GetPropertyCount(); + + application.SendNotification(); + application.Render(); + + Property::Index index1 = actor.RegisterProperty( "MyProperty", Vector3::ONE ); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( actor.GetPropertyCount(), defaultPropertyCount + 1, TEST_LOCATION ); + DALI_TEST_EQUALS( actor.GetProperty< Vector3 >( index1 ), Vector3::ONE, TEST_LOCATION ); + + // No new property should be registered when we call the below function + Property::Index index2 = actor.RegisterProperty( "MyProperty", Vector3::ZAXIS ); + + application.SendNotification(); + application.Render(); + + + DALI_TEST_EQUALS( index1, index2, TEST_LOCATION ); // We should have the same index as per the first registration + DALI_TEST_EQUALS( actor.GetPropertyCount(), defaultPropertyCount + 1, TEST_LOCATION ); // Property count should be the same + DALI_TEST_EQUALS( actor.GetProperty< Vector3 >( index2 ), Vector3::ZAXIS, TEST_LOCATION ); // Value should be what we sent on second RegisterProperty call + + END_TEST; +} + +int UtcDaliHandleRegisterProperty02(void) +{ + tet_infoline("Positive Test Dali::Handle::RegisterProperty() int key"); + TestApplication application; + + Stage stage = Stage::GetCurrent(); + + Actor actor = Actor::New(); + stage.Add( actor ); + + const unsigned int defaultPropertyCount = actor.GetPropertyCount(); + + application.SendNotification(); + application.Render(); + + Property::Index key1 = CORE_PROPERTY_MAX_INDEX+1; + Property::Index key2 = CORE_PROPERTY_MAX_INDEX+2; + + const Vector4 testColor(0.5f, 0.2f, 0.9f, 1.0f); + const float withFlake(99.f); + + Property::Index index1 = actor.RegisterProperty( "MyPropertyOne", Vector3::ONE ); + Property::Index index2 = DevelHandle::RegisterProperty( actor, key1, "sideColor", testColor); + Property::Index index3 = DevelHandle::RegisterProperty( actor, key2, "iceCream", withFlake ); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( actor.GetPropertyCount(), defaultPropertyCount + 3, TEST_LOCATION ); + DALI_TEST_EQUALS( actor.GetProperty< Vector3 >( index1 ), Vector3::ONE, TEST_LOCATION ); + DALI_TEST_EQUALS( actor.GetProperty< Vector4 >( index2 ), testColor, TEST_LOCATION ); + DALI_TEST_EQUALS( actor.GetProperty< float >( index3 ), withFlake, TEST_LOCATION ); + + // No new property should be registered when we call the below functions + Property::Index testIndex2 = actor.RegisterProperty( "iceCream", 2200.f ); + Property::Index testIndex1 = actor.RegisterProperty( "sideColor", Color::BLACK ); + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( index2, testIndex1, TEST_LOCATION ); // We should have the same index as per the first registration + DALI_TEST_EQUALS( index3, testIndex2, TEST_LOCATION ); // We should have the same index as per the first registration + DALI_TEST_EQUALS( actor.GetPropertyCount(), defaultPropertyCount + 3, TEST_LOCATION ); // Property count should be the same + DALI_TEST_EQUALS( actor.GetProperty< Vector4 >( index2 ), Color::BLACK, TEST_LOCATION ); // Value should be what we sent on second RegisterProperty call + DALI_TEST_EQUALS( actor.GetProperty< float >( index3 ), 2200.f, TEST_LOCATION ); END_TEST; } + + int UtcDaliHandleGetProperty(void) { tet_infoline("Positive Test Dali::Handle::GetProperty()"); @@ -797,197 +782,35 @@ 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) +int UtcDaliHandleGetPropertyIndices(void) { TestApplication application; - tet_infoline("Testing PropertyTypes::GetName()"); + Property::IndexContainer indices; - Property::Value value; + // Actor + Actor actor = Actor::New(); + actor.GetPropertyIndices( indices ); + int numDefaultProperties = indices.Size(); + DALI_TEST_CHECK( numDefaultProperties > 0 ); + DALI_TEST_EQUALS( numDefaultProperties, actor.GetPropertyCount(), TEST_LOCATION ); - 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 ); + const Vector4 testColor(0.5f, 0.2f, 0.9f, 1.0f); + const float withFlake(99.f); - 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::Index key1 = CORE_PROPERTY_MAX_INDEX+1; + Property::Index key2 = CORE_PROPERTY_MAX_INDEX+2; - Property::Map map; - value = Property::Value(Property::MAP); - value.SetValue("key", "value"); - value.Get(map); - DALI_TEST_CHECK( map.GetKey(0) == "key" ); + actor.RegisterProperty( "MyPropertyOne", Vector3::ONE ); + DevelHandle::RegisterProperty( actor, key1, "sideColor", testColor); + actor.RegisterProperty( "MyPropertyTwo", 1234 ); + Property::Index index4 = DevelHandle::RegisterProperty( actor, key2, "iceCream", withFlake ); + actor.RegisterProperty( "MyPropertyThree", Vector2(.2f,.7f) ); - END_TEST; -} + actor.GetPropertyIndices( indices ); -int UtcDaliHandleGetPropertyIndices(void) -{ - TestApplication application; - Property::IndexContainer indices; + DALI_TEST_EQUALS( indices.Size(), numDefaultProperties + 5, TEST_LOCATION ); + DALI_TEST_EQUALS( indices[indices.Size()-2], index4, TEST_LOCATION ); - // Actor - Actor actor = Actor::New(); - actor.GetPropertyIndices( indices ); - DALI_TEST_CHECK( ! indices.empty() ); - DALI_TEST_EQUALS( indices.size(), actor.GetPropertyCount(), TEST_LOCATION ); END_TEST; } @@ -1010,7 +833,6 @@ int UtcDaliHandleRegisterPropertyTypes(void) { "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 }, @@ -1022,6 +844,7 @@ int UtcDaliHandleRegisterPropertyTypes(void) { "Property::ARRAY", array, false }, { "Property::MAP", map, false }, }; + unsigned int numOfProperties( sizeof( properties ) / sizeof( properties[0] ) ); for ( unsigned int i = 0; i < numOfProperties; ++i ) @@ -1032,7 +855,7 @@ int UtcDaliHandleRegisterPropertyTypes(void) try { Actor actor = Actor::New(); - actor.RegisterProperty( "man-from-delmonte", properties[i].value ); + actor.RegisterProperty( "manFromDelmonte", properties[i].value ); } catch (Dali::DaliException& e) { @@ -1051,7 +874,7 @@ int UtcDaliHandleCustomProperty(void) Handle handle = Handle::New(); float startValue(1.0f); - Property::Index index = handle.RegisterProperty( "test-property", startValue ); + Property::Index index = handle.RegisterProperty( "testProperty", startValue ); DALI_TEST_CHECK( handle.GetProperty(index) == startValue ); application.SendNotification(); @@ -1069,3 +892,777 @@ int UtcDaliHandleCustomProperty(void) DALI_TEST_CHECK( handle.GetProperty(index) == 5.0f ); END_TEST; } + +int UtcDaliHandleCustomPropertyNone(void) +{ + TestApplication application; + + Handle handle = Handle::New(); + + Property::Value value( Property::NONE ); + Property::Index index = handle.RegisterProperty( "testProperty", value, Property::READ_WRITE); + + // Negative test i.e. setting a property of type NONE is meaningless + handle.SetProperty( index, 5.0f ); + + DALI_TEST_CHECK( true ); // got here without crashing + + END_TEST; +} + +int UtcDaliHandleCustomPropertyIntToFloat(void) +{ + TestApplication application; + + Handle handle = Handle::New(); + + float startValue(5.0f); + Property::Index index = handle.RegisterProperty( "testProperty", startValue ); + DALI_TEST_CHECK( handle.GetProperty(index) == startValue ); + + application.SendNotification(); + application.Render(0); + DALI_TEST_CHECK( handle.GetProperty(index) == startValue ); + + handle.SetProperty( index, int(1) ); + + application.SendNotification(); + application.Render(0); + DALI_TEST_CHECK( handle.GetProperty(index) == 1.0f ); + END_TEST; +} + +int UtcDaliHandleCustomPropertyFloatToInt(void) +{ + TestApplication application; + + Handle handle = Handle::New(); + + int startValue(5); + Property::Index index = handle.RegisterProperty( "testProperty", startValue ); + DALI_TEST_CHECK( handle.GetProperty(index) == startValue ); + + application.SendNotification(); + application.Render(0); + DALI_TEST_CHECK( handle.GetProperty(index) == startValue ); + + handle.SetProperty( index, float(1.5) ); + + application.SendNotification(); + application.Render(0); + DALI_TEST_CHECK( handle.GetProperty(index) == 1 ); + END_TEST; +} + +int UtcDaliHandleCustomPropertyInvalidToRect(void) +{ + TestApplication application; + + Handle handle = Handle::New(); + + Rect startValue(1,2,3,4); + Property::Index index = handle.RegisterProperty( "testProperty", startValue, Property::READ_WRITE); + DALI_TEST_EQUALS( handle.GetProperty< Rect >( index ), startValue, TEST_LOCATION ); + + application.SendNotification(); + application.Render(0); + DALI_TEST_EQUALS( handle.GetProperty< Rect >( index ), startValue, TEST_LOCATION ); + + // Negative test i.e. there is no conversion from float to Rect + handle.SetProperty( index, float(1.5) ); + + application.SendNotification(); + application.Render(0); + DALI_TEST_EQUALS( handle.GetProperty< Rect >( index ), startValue, TEST_LOCATION ); + + // Positive test (sanity check) + Rect endValue(5,6,7,8); + handle.SetProperty( index, endValue ); + DALI_TEST_EQUALS( handle.GetProperty< Rect >( index ), endValue, TEST_LOCATION ); + + application.SendNotification(); + application.Render(0); + DALI_TEST_EQUALS( handle.GetProperty< Rect >( index ), endValue, TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliHandleCustomPropertyInvalidToString(void) +{ + TestApplication application; + + Handle handle = Handle::New(); + + std::string startValue( "Libraries gave us power" ); + Property::Index index = handle.RegisterProperty( "testProperty", startValue, Property::READ_WRITE); + DALI_TEST_EQUALS( handle.GetProperty< std::string >( index ), startValue, TEST_LOCATION ); + + application.SendNotification(); + application.Render(0); + DALI_TEST_EQUALS( handle.GetProperty< std::string >( index ), startValue, TEST_LOCATION ); + + // No conversion from Vector3 to std::string, therefore this should be a NOOP + handle.SetProperty( index, Vector3(1,2,3) ); + + application.SendNotification(); + application.Render(0); + DALI_TEST_EQUALS( handle.GetProperty< std::string >( index ), startValue, TEST_LOCATION ); + + // Positive test (sanity check) + std::string endValue( "Then work came and made us free" ); + handle.SetProperty( index, endValue ); + DALI_TEST_EQUALS( handle.GetProperty< std::string >( index ), endValue, TEST_LOCATION ); + + application.SendNotification(); + application.Render(0); + DALI_TEST_EQUALS( handle.GetProperty< std::string >( index ), endValue, TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliHandleCustomPropertyInvalidToArray(void) +{ + TestApplication application; + + Handle handle = Handle::New(); + + Property::Value value( Property::ARRAY ); + std::string startValue( "The future teaches you to be alone" ); + value.GetArray()->PushBack( startValue ); + + Property::Index index = handle.RegisterProperty( "testProperty", value, Property::READ_WRITE); + Property::Array check1 = handle.GetProperty< Property::Array >( index ); + DALI_TEST_EQUALS( check1.GetElementAt(0).Get(), startValue, TEST_LOCATION ); + + application.SendNotification(); + application.Render(0); + Property::Array check2 = handle.GetProperty< Property::Array >( index ); + DALI_TEST_EQUALS( check2.GetElementAt(0).Get(), startValue, TEST_LOCATION ); + + // No conversion from int to ARRAY, therefore this should be a NOOP + handle.SetProperty( index, int(2) ); + + application.SendNotification(); + application.Render(0); + Property::Array check3 = handle.GetProperty< Property::Array >( index ); + DALI_TEST_EQUALS( check3.GetElementAt(0).Get(), startValue, TEST_LOCATION ); + + // Positive test (sanity check) + Property::Value value2(Property::ARRAY); + std::string endValue( "The present to be afraid and cold" ); + value2.GetArray()->PushBack( endValue ); + handle.SetProperty( index, value2 ); + + Property::Array check4 = handle.GetProperty< Property::Array >( index ); + DALI_TEST_EQUALS( check4.GetElementAt(0).Get(), endValue, TEST_LOCATION ); + + application.SendNotification(); + application.Render(0); + Property::Array check5 = handle.GetProperty< Property::Array >( index ); + DALI_TEST_EQUALS( check5.GetElementAt(0).Get(), endValue, TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliHandleCustomPropertyInvalidToMap(void) +{ + TestApplication application; + + Handle handle = Handle::New(); + + Property::Value value( Property::MAP ); + std::string startValue( "Culture sucks down words" ); + value.GetMap()->Insert( "1", startValue ); + + Property::Index index = handle.RegisterProperty( "testProperty", value, Property::READ_WRITE ); + Property::Value* check1 = handle.GetProperty< Property::Map >( index ).Find("1"); + DALI_TEST_CHECK( NULL != check1 ); + + // No conversion from float to MAP, therefore this should be a NOOP + handle.SetProperty( index, float(3.0) ); + + // Positive test (sanity check) + Property::Value value2( Property::MAP ); + std::string endValue( "Itemise loathing and feed yourself smiles" ); + value.GetMap()->Insert( "1", endValue ); + handle.SetProperty( index, value2 ); + + END_TEST; +} + +int UtcDaliHandleCustomPropertyInvalidToExtents(void) +{ + TestApplication application; + + Handle handle = Handle::New(); + + Extents startValue(1,2,3,4); + Property::Index index = handle.RegisterProperty( "testProperty", startValue, Property::READ_WRITE); + DALI_TEST_EQUALS( handle.GetProperty< Extents >( index ), startValue, TEST_LOCATION ); + + application.SendNotification(); + application.Render(0); + DALI_TEST_EQUALS( handle.GetProperty< Extents >( index ), startValue, TEST_LOCATION ); + + // Negative test i.e. there is no conversion from float to Extents + handle.SetProperty( index, float(1.5) ); + + application.SendNotification(); + application.Render(0); + DALI_TEST_EQUALS( handle.GetProperty< Extents >( index ), startValue, TEST_LOCATION ); + + // Positive test (sanity check) + Extents endValue(5,6,7,8); + handle.SetProperty( index, endValue ); + DALI_TEST_EQUALS( handle.GetProperty< Extents >( index ), endValue, TEST_LOCATION ); + + application.SendNotification(); + application.Render(0); + DALI_TEST_EQUALS( handle.GetProperty< Extents >( index ), endValue, TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliHandleCustomPropertyInvalidToBool(void) +{ + TestApplication application; + + Handle handle = Handle::New(); + + bool startValue(true); + Property::Index index = handle.RegisterProperty( "testProperty", startValue, Property::READ_WRITE); + DALI_TEST_EQUALS( handle.GetProperty< bool >( index ), startValue, TEST_LOCATION ); + + application.SendNotification(); + application.Render(0); + DALI_TEST_EQUALS( handle.GetProperty< bool >( index ), startValue, TEST_LOCATION ); + + // Negative test i.e. there is no conversion from float to bool + handle.SetProperty( index, float(0.0) ); + + application.SendNotification(); + application.Render(0); + DALI_TEST_EQUALS( handle.GetProperty< bool >( index ), startValue, TEST_LOCATION ); + + // Positive test (sanity check) + bool endValue(false); + handle.SetProperty( index, endValue ); + DALI_TEST_EQUALS( handle.GetProperty< bool >( index ), endValue, TEST_LOCATION ); + + application.SendNotification(); + application.Render(0); + DALI_TEST_EQUALS( handle.GetProperty< bool >( index ), endValue, TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliHandleCustomPropertyInvalidToInt(void) +{ + TestApplication application; + + Handle handle = Handle::New(); + + int startValue(5); + Property::Index index = handle.RegisterProperty( "testProperty", startValue ); + DALI_TEST_CHECK( handle.GetProperty(index) == startValue ); + + application.SendNotification(); + application.Render(0); + DALI_TEST_CHECK( handle.GetProperty(index) == startValue ); + + // Negative test i.e. there is no conversion from Vector3 to int + handle.SetProperty( index, Vector3(1,2,3) ); + + application.SendNotification(); + application.Render(0); + DALI_TEST_CHECK( handle.GetProperty(index) == startValue ); + END_TEST; +} + +int UtcDaliHandleCustomPropertyInvalidToFloat(void) +{ + TestApplication application; + + Handle handle = Handle::New(); + + float startValue(5.0); + Property::Index index = handle.RegisterProperty( "testProperty", startValue ); + DALI_TEST_CHECK( handle.GetProperty(index) == startValue ); + + application.SendNotification(); + application.Render(0); + DALI_TEST_CHECK( handle.GetProperty(index) == startValue ); + + // Negative test i.e. there is no conversion from Vector3 to float + handle.SetProperty( index, Vector3(1,2,3) ); + + application.SendNotification(); + application.Render(0); + DALI_TEST_CHECK( handle.GetProperty(index) == startValue ); + END_TEST; +} + +int UtcDaliHandleCustomPropertyInvalidToRotation(void) +{ + TestApplication application; + + Handle handle = Handle::New(); + + Quaternion startValue( Radian(0.785f), Vector3(1.0f, 1.0f, 0.0f)); + Property::Index index = handle.RegisterProperty( "testProperty", startValue ); + DALI_TEST_CHECK( handle.GetProperty(index) == startValue ); + + application.SendNotification(); + application.Render(0); + DALI_TEST_CHECK( handle.GetProperty(index) == startValue ); + + // Negative test i.e. there is no conversion from float to Quaternion + handle.SetProperty( index, float(7.0) ); + + application.SendNotification(); + application.Render(0); + DALI_TEST_CHECK( handle.GetProperty(index) == startValue ); + + // Positive test (sanity check) + Quaternion endValue( Radian(0.785f), Vector3(1.0f, 1.0f, 0.0f)); + handle.SetProperty( index, endValue ); + DALI_TEST_CHECK( handle.GetProperty(index) == endValue ); + + END_TEST; +} + +int UtcDaliHandleCustomPropertyInvalidToMatrix(void) +{ + TestApplication application; + + Handle handle = Handle::New(); + + Quaternion rotation( Radian(0.785f), Vector3(1.0f, 1.0f, 0.0f)); + Matrix startValue(rotation); + Property::Index index = handle.RegisterProperty( "testProperty", startValue ); + DALI_TEST_CHECK( handle.GetProperty(index) == startValue ); + + application.SendNotification(); + application.Render(0); + DALI_TEST_CHECK( handle.GetProperty(index) == startValue ); + + // Negative test i.e. there is no conversion from float to Matrix + handle.SetProperty( index, float(7.0) ); + + application.SendNotification(); + application.Render(0); + DALI_TEST_CHECK( handle.GetProperty(index) == startValue ); + + // Positive test (sanity check) + Quaternion endRotation( Radian(0.785f), Vector3(1.0f, 1.0f, 0.0f)); + Matrix endValue(endRotation); + handle.SetProperty( index, endValue ); + DALI_TEST_CHECK( handle.GetProperty(index) == endValue ); + + END_TEST; +} + +int UtcDaliHandleCustomPropertyInvalidToMatrix3(void) +{ + TestApplication application; + + Handle handle = Handle::New(); + + Matrix3 startValue(11,12,13, + 21,22,23, + 31,32,33); + + Property::Index index = handle.RegisterProperty( "testProperty", startValue ); + DALI_TEST_CHECK( handle.GetProperty(index) == startValue ); + + application.SendNotification(); + application.Render(0); + DALI_TEST_CHECK( handle.GetProperty(index) == startValue ); + + // Negative test i.e. there is no conversion from float to Matrix3 + handle.SetProperty( index, float(7.0) ); + + application.SendNotification(); + application.Render(0); + DALI_TEST_CHECK( handle.GetProperty(index) == startValue ); + + // Positive test (sanity check) + Matrix3 endValue(31,32,33, + 21,22,23, + 11,12,13); + handle.SetProperty( index, endValue ); + DALI_TEST_CHECK( handle.GetProperty(index) == endValue ); + + END_TEST; +} + +int UtcDaliHandleWeightNew(void) +{ + TestApplication application; + + Handle handle = WeightObject::New(); + DALI_TEST_CHECK( handle.GetProperty(WeightObject::WEIGHT) == 0.0f ); + + // process the message so scene object is added to update manager + application.SendNotification(); + application.Render(0); + + // no message to release scene object in this scenario + + END_TEST; +} + +int UtcDaliHandleWeightNew2(void) +{ + TestApplication application; + + // scope for the weight object + { + Handle handle = WeightObject::New(); + DALI_TEST_CHECK( handle.GetProperty(WeightObject::WEIGHT) == 0.0f ); + + // process the message so scene object is added to update manager + application.SendNotification(); + application.Render(0); + } + // handle out of scope so object gets destroyed + // process the message so update manager destroys the scene object + application.SendNotification(); + application.Render(0); + + END_TEST; +} + +int UtcDaliHandleSetTypeInfo(void) +{ + TestApplication application; + TypeRegistry typeRegistry = TypeRegistry::Get(); + + TypeInfo typeInfo = typeRegistry.GetTypeInfo( "Actor" ); + DALI_TEST_CHECK( typeInfo ); + + Actor actor = Actor::DownCast(typeInfo.CreateInstance()); + DALI_TEST_CHECK( actor ); + + DevelHandle::SetTypeInfo(actor, typeInfo); + + TypeInfo newTypeInfo; + bool success = actor.GetTypeInfo( newTypeInfo ); + DALI_TEST_CHECK( success ); + + DALI_TEST_CHECK(typeInfo.GetName() == newTypeInfo.GetName()); + DALI_TEST_CHECK(typeInfo.GetBaseName() == newTypeInfo.GetBaseName()); + + END_TEST; +} + +int UtcDaliHandleCustomPropertySynchronousGetSet(void) +{ + TestApplication application; + + tet_infoline( "Create a custom property and set the value ensuring it can be retrieved synchronously" ); + + Actor actor = Actor::New(); + Stage::GetCurrent().Add( actor ); + + tet_infoline( "Create the custom property with an initial value" ); + float startValue(1.0f); + Property::Index index = actor.RegisterProperty( "testProperty", startValue ); + DALI_TEST_EQUALS( actor.GetProperty< float >( index ), startValue, TEST_LOCATION ); + + tet_infoline( "Set the value, retrieve it and ensure both the synchronous and the async version work" ); + actor.SetProperty( index, 5.0f ); + DALI_TEST_EQUALS( actor.GetProperty< float >( index ), 5.0f, TEST_LOCATION ); + DALI_TEST_EQUALS( actor.GetCurrentProperty< float >( index ), startValue, TEST_LOCATION ); + + tet_infoline( "Render and retrieve values again" ); + application.SendNotification(); + application.Render(0); + + DALI_TEST_EQUALS( actor.GetProperty< float >( index ), 5.0f, TEST_LOCATION ); + DALI_TEST_EQUALS( actor.GetCurrentProperty< float >( index ), 5.0f, TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliHandleCustomPropertyGetType(void) +{ + TestApplication application; + + tet_infoline( "Create a custom property and retrieve its type" ); + + Handle handle = Handle::New(); + Property::Index index = handle.RegisterProperty( "testProperty", 1.0f ); + DALI_TEST_EQUALS( handle.GetPropertyType( index ), Property::FLOAT, TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliHandleCustomPropertyAccessMode(void) +{ + TestApplication application; + + tet_infoline( "Create a custom property and retrieve whether it's animatable etc." ); + + Handle handle = Handle::New(); + Property::Index index = handle.RegisterProperty( "testProperty", 1.0f ); + DALI_TEST_EQUALS( handle.IsPropertyAnimatable( index ), true, TEST_LOCATION ); + DALI_TEST_EQUALS( handle.IsPropertyWritable( index ), true, TEST_LOCATION ); + + index = handle.RegisterProperty( "testProperty2", 1.0f, Property::READ_ONLY ); + DALI_TEST_EQUALS( handle.IsPropertyAnimatable( index ), false, TEST_LOCATION ); + DALI_TEST_EQUALS( handle.IsPropertyWritable( index ), false, TEST_LOCATION ); + + index = handle.RegisterProperty( "testProperty3", 1.0f, Property::READ_WRITE ); + DALI_TEST_EQUALS( handle.IsPropertyAnimatable( index ), false, TEST_LOCATION ); + DALI_TEST_EQUALS( handle.IsPropertyWritable( index ), true, TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliHandleGetCurrentProperty(void) +{ + TestApplication application; + + tet_infoline( "Get a default and non-animatable custom property using the GetCurrentProperty API" ); + + Actor actor = Actor::New(); + Stage::GetCurrent().Add( actor ); + DALI_TEST_EQUALS( actor.GetCurrentProperty< bool >( Actor::Property::VISIBLE ), true, TEST_LOCATION ); + + Property::Index index = actor.RegisterProperty( "testProperty3", 1.0f, Property::READ_WRITE ); + DALI_TEST_EQUALS( actor.GetProperty< float >( index ), 1.0f, TEST_LOCATION ); + DALI_TEST_EQUALS( actor.GetCurrentProperty< float >( index ), 1.0f, TEST_LOCATION ); + + actor.SetProperty( index, 2.0f ); + DALI_TEST_EQUALS( actor.GetProperty< float >( index ), 2.0f, TEST_LOCATION ); + DALI_TEST_EQUALS( actor.GetCurrentProperty< float >( index ), 2.0f, TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliHandleDoesCustomPropertyExistP1(void) +{ + TestApplication application; // Needs type registry + + tet_infoline( "Test if a registered custom property exists on object" ); + + Actor actor = Actor::New(); + auto propertyIndex = actor.RegisterProperty("customProperty1", 1.0f); + + DALI_TEST_EQUALS( DevelHandle::DoesCustomPropertyExist( actor, propertyIndex ), true, TEST_LOCATION ); + END_TEST; +} + +int UtcDaliHandleDoesCustomPropertyExistN1(void) +{ + TestApplication application; // Needs type registry + + tet_infoline( "Test if a registered custom property does not exist on object" ); + + Actor actor = Actor::New(); + auto propertyIndex = actor.RegisterProperty("customProperty1", 1.0f); + + DALI_TEST_EQUALS( DevelHandle::DoesCustomPropertyExist( actor, propertyIndex+1 ), false, TEST_LOCATION ); + END_TEST; +} + +int UtcDaliHandleDoesCustomPropertyExistN2(void) +{ + TestApplication application; // Needs type registry + + tet_infoline( "Test that a default property does not show as a custom property on object" ); + + Actor actor = Actor::New(); + DALI_TEST_EQUALS( DevelHandle::DoesCustomPropertyExist( actor, Actor::Property::POSITION ), false, TEST_LOCATION ); + END_TEST; +} + +int UtcDaliHandleDoesCustomPropertyExistN3(void) +{ + TestApplication application; // Needs type registry + + tet_infoline( "Test that a child property does not exist on actor after parenting to container" ); + TypeRegistry typeRegistry = TypeRegistry::Get(); + + auto customActorTypeInfo = typeRegistry.GetTypeInfo( typeid(Test::TestCustomActor) ); + + const Property::Index CHILD_PROPERTY( CHILD_PROPERTY_REGISTRATION_START_INDEX ); + const char* CHILD_PROPERTY_NAME( "childProperty" ); + + ChildPropertyRegistration( customActorTypeInfo.GetName(), CHILD_PROPERTY_NAME, CHILD_PROPERTY, Property::INTEGER ); + + auto container = Test::TestCustomActor::New(); + Stage::GetCurrent().Add( container ); + auto child = Actor::New(); + container.Add( child ); // Resolve child properties (if any) + + DALI_TEST_EQUALS( DevelHandle::DoesCustomPropertyExist( child, CHILD_PROPERTY ), false, TEST_LOCATION ); + END_TEST; +} + +int UtcDaliHandleDoesCustomPropertyExistP2(void) +{ + TestApplication application; // Needs type registry + + tet_infoline( "Test that a child property exists after being set" ); + TypeRegistry typeRegistry = TypeRegistry::Get(); + + auto customActorTypeInfo = typeRegistry.GetTypeInfo( typeid(Test::TestCustomActor) ); + + const Property::Index CHILD_PROPERTY( CHILD_PROPERTY_REGISTRATION_START_INDEX ); + const char* CHILD_PROPERTY_NAME( "childProperty" ); + + ChildPropertyRegistration( customActorTypeInfo.GetName(), CHILD_PROPERTY_NAME, CHILD_PROPERTY, Property::INTEGER ); + + auto container = Test::TestCustomActor::New(); + Stage::GetCurrent().Add( container ); + auto child = Actor::New(); + container.Add( child ); // Resolve child properties (if any) + child.SetProperty( CHILD_PROPERTY, 2 ); + + DALI_TEST_EQUALS( DevelHandle::DoesCustomPropertyExist( child, CHILD_PROPERTY ), true, TEST_LOCATION ); + DALI_TEST_EQUALS( child.GetProperty( CHILD_PROPERTY ), 2, TEST_LOCATION ); + END_TEST; +} + +int UtcDaliHandleDoesCustomPropertyExistP3(void) +{ + TestApplication application; // Needs type registry + + tet_infoline( "Test that a child property is re-indexed after registration, and that it exists" ); + TypeRegistry typeRegistry = TypeRegistry::Get(); + + auto customActorTypeInfo = typeRegistry.GetTypeInfo( typeid(Test::TestCustomActor) ); + + const Property::Index CHILD_PROPERTY( CHILD_PROPERTY_REGISTRATION_START_INDEX ); + const char* CHILD_PROPERTY_NAME( "childProperty" ); + + ChildPropertyRegistration( customActorTypeInfo.GetName(), CHILD_PROPERTY_NAME, CHILD_PROPERTY, Property::INTEGER ); + + auto container = Test::TestCustomActor::New(); + Stage::GetCurrent().Add( container ); + auto child = Actor::New(); + child.RegisterProperty( CHILD_PROPERTY_NAME, Property::Value(3) ); + container.Add( child ); // Resolve child properties (if any) + + DALI_TEST_EQUALS( DevelHandle::DoesCustomPropertyExist( child, CHILD_PROPERTY ), true, TEST_LOCATION ); + DALI_TEST_EQUALS( child.GetProperty( CHILD_PROPERTY ), 3, TEST_LOCATION ); + END_TEST; +} + +namespace +{ + +struct PropertySetSignalCheck +{ + PropertySetSignalCheck(bool& signalReceived, Property::Value& value) + : mSignalReceived(signalReceived), + mValue(value) + { + } + + void operator()(Handle& handle, Property::Index index, Property::Value value) + { + mSignalReceived = true; + mValue = value; + } + + void Reset() + { + mSignalReceived = false; + } + + void CheckSignalReceived() + { + if (!mSignalReceived) + { + tet_printf("Expected Property Set signal was not received\n"); + tet_result(TET_FAIL); + } + else + { + tet_result(TET_PASS); + } + } + + bool& mSignalReceived; // owned by individual tests + Property::Value& mValue; +}; + +} // anon namespace + +int UtcDaliHandlePropertySetSignal01(void) +{ + TestApplication app; + + bool signalReceived(false); + Property::Value value; + PropertySetSignalCheck propertySetCheck(signalReceived, value); + + tet_infoline( "Test that setting a default property triggers a signal" ); + + auto actor = Actor::New(); + DevelHandle::PropertySetSignal(actor).Connect(&app, propertySetCheck); + + actor.SetProperty( Actor::Property::POSITION, Vector3::XAXIS ); + propertySetCheck.CheckSignalReceived(); + + END_TEST; +} + + +int UtcDaliHandlePropertySetSignal02(void) +{ + TestApplication app; + + bool signalReceived(false); + Property::Value value; + PropertySetSignalCheck propertySetCheck(signalReceived, value); + + tet_infoline( "Test that setting a custom property triggers a signal" ); + + auto actor = Actor::New(); + DevelHandle::PropertySetSignal(actor).Connect(&app, propertySetCheck); + + auto propertyIndex = actor.RegisterProperty("propName", 3.0f); + actor.SetProperty( propertyIndex, 5.0f ); + propertySetCheck.CheckSignalReceived(); + DALI_TEST_EQUALS( propertySetCheck.mValue, Property::Value( 5.0f ), 0.001f, TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliHandlePropertySetSignal03(void) +{ + TestApplication app; + TypeRegistry typeRegistry = TypeRegistry::Get(); + + bool signalReceived(false); + Property::Value value; + PropertySetSignalCheck propertySetCheck(signalReceived, value); + + tet_infoline( "Test that setting a child property triggers a signal" ); + + auto customActorTypeInfo = typeRegistry.GetTypeInfo( typeid(Test::TestCustomActor) ); + + const Property::Index CHILD_PROPERTY( CHILD_PROPERTY_REGISTRATION_START_INDEX ); + const char* CHILD_PROPERTY_NAME( "childProperty" ); + + ChildPropertyRegistration( customActorTypeInfo.GetName(), CHILD_PROPERTY_NAME, CHILD_PROPERTY, Property::INTEGER ); + + auto container = Test::TestCustomActor::New(); + Stage::GetCurrent().Add( container ); + auto child = Actor::New(); + child.RegisterProperty( CHILD_PROPERTY_NAME, Property::Value(3) ); + DevelHandle::PropertySetSignal(child).Connect(&app, propertySetCheck); + container.Add( child ); // Resolve child properties (if any) + + DALI_TEST_EQUALS( DevelHandle::DoesCustomPropertyExist( child, CHILD_PROPERTY ), true, TEST_LOCATION ); + DALI_TEST_EQUALS( child.GetProperty( CHILD_PROPERTY ), 3, TEST_LOCATION ); + + child.SetProperty( CHILD_PROPERTY, 29 ); + propertySetCheck.CheckSignalReceived(); + DALI_TEST_EQUALS( propertySetCheck.mValue, Property::Value( 29 ), TEST_LOCATION ); + END_TEST; +}