X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=automated-tests%2Fsrc%2Fdali-toolkit%2Futc-Dali-Visual.cpp;h=c4df7010ead48f4e9ee4e4a925bf65701ee9c886;hp=6d88a5194b367b1406736419a2170c4a5a42232d;hb=6554dcac017d05a786b1607807b6468ba7c0d666;hpb=d6f1c901d74aef4e66ffb6565bb61de952a090a3 diff --git a/automated-tests/src/dali-toolkit/utc-Dali-Visual.cpp b/automated-tests/src/dali-toolkit/utc-Dali-Visual.cpp index 6d88a51..c4df701 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-Visual.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-Visual.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 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. @@ -18,17 +18,20 @@ #include #include +#include #include -#include -#include -#include #include +#include +#include #include #include -#include +#include #include -#include +#include +#include +#include #include + #include "dummy-control.h" using namespace Dali; @@ -36,25 +39,27 @@ using namespace Dali::Toolkit; namespace { +const char* TEST_GIF_FILE_NAME = TEST_RESOURCE_DIR "/anim.gif"; const char* TEST_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/gallery-small-1.jpg"; -const char* TEST_NPATCH_FILE_NAME = "gallery_image_01.9.jpg"; +const char* TEST_NPATCH_FILE_NAME = TEST_RESOURCE_DIR "/button-up.9.png"; const char* TEST_SVG_FILE_NAME = TEST_RESOURCE_DIR "/svg1.svg"; -const char* TEST_GIF_FILE_NAME = TEST_RESOURCE_DIR "/anim.gif"; const char* TEST_OBJ_FILE_NAME = TEST_RESOURCE_DIR "/Cube.obj"; const char* TEST_MTL_FILE_NAME = TEST_RESOURCE_DIR "/ToyRobot-Metal.mtl"; const char* TEST_RESOURCE_LOCATION = TEST_RESOURCE_DIR "/"; + const std::string DEFAULT_FONT_DIR( "/resources/fonts" ); Property::Map DefaultTransform() { Property::Map transformMap; transformMap - .Add( Toolkit::DevelVisual::Transform::Property::OFFSET, Vector2(0.0f, 0.0f) ) - .Add( Toolkit::DevelVisual::Transform::Property::SIZE, Vector2(1.0f, 1.0f) ) - .Add( Toolkit::DevelVisual::Transform::Property::ORIGIN, Toolkit::Align::CENTER ) - .Add( Toolkit::DevelVisual::Transform::Property::ANCHOR_POINT, Toolkit::Align::CENTER ) - .Add( Toolkit::DevelVisual::Transform::Property::OFFSET_SIZE_MODE, Vector4::ZERO ); + .Add( Toolkit::Visual::Transform::Property::OFFSET, Vector2(0.0f, 0.0f) ) + .Add( Toolkit::Visual::Transform::Property::SIZE, Vector2(1.0f, 1.0f) ) + .Add( Toolkit::Visual::Transform::Property::ORIGIN, Toolkit::Align::TOP_BEGIN ) + .Add( Toolkit::Visual::Transform::Property::ANCHOR_POINT, Toolkit::Align::TOP_BEGIN ) + .Add( Toolkit::Visual::Transform::Property::OFFSET_POLICY, Vector2( Toolkit::Visual::Transform::Policy::RELATIVE, Toolkit::Visual::Transform::Policy::RELATIVE ) ) + .Add( Toolkit::Visual::Transform::Property::SIZE_POLICY, Vector2( Toolkit::Visual::Transform::Policy::RELATIVE, Toolkit::Visual::Transform::Policy::RELATIVE ) ); return transformMap; } @@ -66,18 +71,64 @@ bool DaliTestCheckMaps( const Property::Map& fontStyleMapGet, const Property::Ma { const KeyValuePair& valueGet = fontStyleMapGet.GetKeyValue( index ); - Property::Value* valueSet = fontStyleMapSet.Find( valueGet.first.stringKey ); + Property::Value* valueSet = NULL; + if ( valueGet.first.type == Property::Key::INDEX ) + { + valueSet = fontStyleMapSet.Find( valueGet.first.indexKey ); + } + else + { + // Get Key is a string so searching Set Map for a string key + valueSet = fontStyleMapSet.Find( valueGet.first.stringKey ); + } + if( NULL != valueSet ) { - if( valueGet.second.Get() != valueSet->Get() ) + if( valueSet->GetType() == Dali::Property::STRING && ( valueGet.second.Get() != valueSet->Get() ) ) + { + tet_printf( "Value got : [%s], expected : [%s]", valueGet.second.Get().c_str(), valueSet->Get().c_str() ); + return false; + } + else if( valueSet->GetType() == Dali::Property::BOOLEAN && ( valueGet.second.Get() != valueSet->Get() ) ) + { + tet_printf( "Value got : [%d], expected : [%d]", valueGet.second.Get(), valueSet->Get() ); + return false; + } + else if( valueSet->GetType() == Dali::Property::INTEGER && ( valueGet.second.Get() != valueSet->Get() ) ) { - tet_printf( " Value got : [%s], expected : [%s]", valueGet.second.Get().c_str(), valueSet->Get().c_str() ); + tet_printf( "Value got : [%d], expected : [%d]", valueGet.second.Get(), valueSet->Get() ); + return false; + } + else if( valueSet->GetType() == Dali::Property::FLOAT && ( valueGet.second.Get() != valueSet->Get() ) ) + { + tet_printf( "Value got : [%f], expected : [%f]", valueGet.second.Get(), valueSet->Get() ); + return false; + } + else if( valueSet->GetType() == Dali::Property::VECTOR2 && ( valueGet.second.Get() != valueSet->Get() ) ) + { + Vector2 vector2Get = valueGet.second.Get(); + Vector2 vector2Set = valueSet->Get(); + tet_printf( "Value got : [%f, %f], expected : [%f, %f]", vector2Get.x, vector2Get.y, vector2Set.x, vector2Set.y ); + return false; + } + else if( valueSet->GetType() == Dali::Property::VECTOR4 && ( valueGet.second.Get() != valueSet->Get() ) ) + { + Vector4 vector4Get = valueGet.second.Get(); + Vector4 vector4Set = valueSet->Get(); + tet_printf( "Value got : [%f, %f, %f, %f], expected : [%f, %f, %f, %f]", vector4Get.r, vector4Get.g, vector4Get.b, vector4Get.a, vector4Set.r, vector4Set.g, vector4Set.b, vector4Set.a ); return false; } } else { - tet_printf( " The key %s doesn't exist.", valueGet.first.stringKey.c_str() ); + if ( valueGet.first.type == Property::Key::INDEX ) + { + tet_printf( " The key %d doesn't exist.", valueGet.first.indexKey ); + } + else + { + tet_printf( " The key %s doesn't exist.", valueGet.first.stringKey.c_str() ); + } return false; } } @@ -86,6 +137,20 @@ bool DaliTestCheckMaps( const Property::Map& fontStyleMapGet, const Property::Ma return true; } +void PrepareResourceImage( ToolkitTestApplication& application, unsigned int imageWidth, unsigned int imageHeight, Pixel::Format pixelFormat ) +{ + TestPlatformAbstraction& platform = application.GetPlatform(); + platform.SetClosestImageSize(Vector2( imageWidth, imageHeight)); + + Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_RETAIN ); + Integration::PixelBuffer* pixbuffer = bitmap->GetPackedPixelsProfile()->ReserveBuffer( pixelFormat, imageWidth, imageHeight, imageWidth, imageHeight ); + unsigned int bytesPerPixel = GetBytesPerPixel( pixelFormat ); + unsigned int initialColor = 0xFF; + memset( pixbuffer, initialColor, imageHeight*imageWidth*bytesPerPixel); + + Integration::ResourcePointer resourcePtr(bitmap); + platform.SetSynchronouslyLoadedResource( resourcePtr ); +} } //namespace void dali_visual_startup(void) @@ -105,9 +170,21 @@ static void TestMixColor( Visual::Base visual, Property::Index mixColorIndex, co visual.CreatePropertyMap(map); Property::Value* value = map.Find( mixColorIndex ); DALI_TEST_CHECK( value ); - Vector4 mixColor; - DALI_TEST_CHECK( value->Get( mixColor ) ); - DALI_TEST_EQUALS( mixColor, testColor, 0.001, TEST_LOCATION ); + Vector3 mixColor1; + DALI_TEST_CHECK( value->Get( mixColor1 ) ); + DALI_TEST_EQUALS( mixColor1, Vector3(testColor), 0.001, TEST_LOCATION ); + + value = map.Find( Visual::Property::MIX_COLOR ); + DALI_TEST_CHECK( value ); + Vector4 mixColor2; + DALI_TEST_CHECK( value->Get( mixColor2 ) ); + DALI_TEST_EQUALS( mixColor2, testColor, 0.001, TEST_LOCATION ); + + value = map.Find( Visual::Property::OPACITY ); + DALI_TEST_CHECK( value ); + float opacity; + DALI_TEST_CHECK( value->Get( opacity ) ); + DALI_TEST_EQUALS( opacity, testColor.a, 0.001, TEST_LOCATION ); } @@ -174,7 +251,7 @@ int UtcDaliVisualSetGetDepthIndex(void) propertyMap.Insert(ColorVisual::Property::MIX_COLOR, Color::BLUE); Visual::Base visual = factory.CreateVisual( propertyMap ); - visual.SetDepthIndex( 1.f ); + visual.SetDepthIndex( 1 ); DummyControl dummyControl = DummyControl::New(true); Impl::DummyControl& dummyImpl = static_cast(dummyControl.GetImplementation()); @@ -186,12 +263,12 @@ int UtcDaliVisualSetGetDepthIndex(void) int depthIndex = dummyControl.GetRendererAt(0u).GetProperty( Renderer::Property::DEPTH_INDEX ); DALI_TEST_EQUALS( depthIndex, 1, TEST_LOCATION ); - DALI_TEST_EQUALS( visual.GetDepthIndex(), 1.f, TEST_LOCATION ); + DALI_TEST_EQUALS( visual.GetDepthIndex(), 1, TEST_LOCATION ); - visual.SetDepthIndex( -1.f ); + visual.SetDepthIndex( -1 ); depthIndex = dummyControl.GetRendererAt(0u).GetProperty( Renderer::Property::DEPTH_INDEX ); DALI_TEST_EQUALS( depthIndex, -1, TEST_LOCATION ); - DALI_TEST_EQUALS( visual.GetDepthIndex(), -1.f, TEST_LOCATION ); + DALI_TEST_EQUALS( visual.GetDepthIndex(), -1, TEST_LOCATION ); END_TEST; } @@ -199,7 +276,7 @@ int UtcDaliVisualSetGetDepthIndex(void) int UtcDaliVisualSize(void) { ToolkitTestApplication application; - tet_infoline( "UtcDaliVisualGetNaturalSize" ); + tet_infoline( "UtcDaliVisualSize" ); VisualFactory factory = VisualFactory::Get(); Vector2 controlSize( 20.f, 30.f ); @@ -207,7 +284,7 @@ int UtcDaliVisualSize(void) // color colorVisual Dali::Property::Map map; - map[ Visual::Property::TYPE ] = Visual::COLOR; + map[ Toolkit::Visual::Property::TYPE ] = Visual::COLOR; map[ ColorVisual::Property::MIX_COLOR ] = Color::MAGENTA; Visual::Base colorVisual = factory.CreateVisual( map ); @@ -217,6 +294,7 @@ int UtcDaliVisualSize(void) DALI_TEST_EQUALS( naturalSize, Vector2::ZERO, TEST_LOCATION ); // image visual + PrepareResourceImage( application, 100u, 200u, Pixel::RGBA8888 ); Image image = ResourceImage::New(TEST_IMAGE_FILE_NAME, ImageDimensions(100, 200)); Visual::Base imageVisual = factory.CreateVisual( image ); imageVisual.SetTransformAndSize(DefaultTransform(), controlSize ); @@ -229,7 +307,7 @@ int UtcDaliVisualSize(void) // border visual float borderSize = 5.f; map.Clear(); - map[ Visual::Property::TYPE ] = Visual::BORDER; + map[ Toolkit::Visual::Property::TYPE ] = Visual::BORDER; map[ BorderVisual::Property::COLOR ] = Color::RED; map[ BorderVisual::Property::SIZE ] = borderSize; Visual::Base borderVisual = factory.CreateVisual( map ); @@ -256,6 +334,15 @@ int UtcDaliVisualSize(void) gradientVisual.GetNaturalSize(naturalSize); DALI_TEST_EQUALS( naturalSize, Vector2::ZERO,TEST_LOCATION ); + // animated gradient visual + Vector2 animated_gradient_visual_size(10.f, 10.f); + propertyMap.Clear(); + propertyMap.Insert( Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_GRADIENT ); + Visual::Base animatedGradientVisual = factory.CreateVisual( propertyMap ); + animatedGradientVisual.GetNaturalSize(naturalSize); + animatedGradientVisual.SetTransformAndSize(DefaultTransform(), controlSize ); + DALI_TEST_EQUALS( naturalSize, Vector2::ZERO, TEST_LOCATION ); + // svg visual Visual::Base svgVisual = factory.CreateVisual( TEST_SVG_FILE_NAME, ImageDimensions() ); svgVisual.SetTransformAndSize(DefaultTransform(), controlSize ); @@ -271,19 +358,6 @@ int UtcDaliVisualSize(void) svgVisual2.GetNaturalSize(naturalSize); DALI_TEST_EQUALS( naturalSize, Vector2(100.f, 100.f), TEST_LOCATION ); // Natural size should still be 100, 100 - // Batch Image visual - TestPlatformAbstraction& platform = application.GetPlatform(); - Vector2 testSize(80.f, 160.f); - platform.SetClosestImageSize(testSize); - propertyMap.Clear(); - propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE ); - propertyMap.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME ); - propertyMap.Insert( "batchingEnabled", true ); - Visual::Base batchImageVisual = factory.CreateVisual( propertyMap ); - batchImageVisual.SetTransformAndSize(DefaultTransform(), controlSize ); - batchImageVisual.GetNaturalSize( naturalSize ); - DALI_TEST_EQUALS( naturalSize, Vector2( 80.0f, 160.0f ), TEST_LOCATION ); - // Text visual. // Load some fonts to get the same metrics on different platforms. @@ -296,18 +370,29 @@ int UtcDaliVisualSize(void) fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/tizen/TizenSansRegular.ttf" ); + // Create a TextVisual with a font size of 12 first propertyMap.Clear(); - propertyMap.Insert( Visual::Property::TYPE, DevelVisual::TEXT ); + propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::TEXT ); propertyMap.Insert( TextVisual::Property::ENABLE_MARKUP, true ); propertyMap.Insert( TextVisual::Property::TEXT, "Hello world" ); propertyMap.Insert( TextVisual::Property::MULTI_LINE, true ); - Visual::Base textVisual = factory.CreateVisual( propertyMap ); - textVisual.GetNaturalSize( naturalSize ); - DALI_TEST_EQUALS( naturalSize, Size( 80.f, 20.f ), TEST_LOCATION ); + Visual::Base smallTextVisual = factory.CreateVisual( propertyMap ); + Vector2 smallTextVisualNaturalSize; + smallTextVisual.GetNaturalSize( smallTextVisualNaturalSize ); + + // Then create a TextVisual with a font size of 20 + propertyMap[ TextVisual::Property::TEXT ] = "Hello world"; + Visual::Base largeTextVisual = factory.CreateVisual( propertyMap ); + Vector2 largeTextVisualNaturalSize; + largeTextVisual.GetNaturalSize( largeTextVisualNaturalSize ); - const float height = textVisual.GetHeightForWidth( 40.f ); - DALI_TEST_EQUALS( height, 40.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION ); + // Compare the sizes of the two text visuals, the second one should be bigger as it has a larger point size in the markup. + DALI_TEST_CHECK( smallTextVisualNaturalSize.width < largeTextVisualNaturalSize.width && + smallTextVisualNaturalSize.height < largeTextVisualNaturalSize.height ); + + // The height returned for a particular width should also be greater for the large text visual + DALI_TEST_CHECK( smallTextVisual.GetHeightForWidth( 40.f ) < largeTextVisual.GetHeightForWidth( 40.f ) ); //AnimatedImageVisual Visual::Base animatedImageVisual = factory.CreateVisual( TEST_GIF_FILE_NAME, ImageDimensions() ); @@ -323,7 +408,7 @@ int UtcDaliVisualSize(void) int UtcDaliVisualSetOnOffStage(void) { ToolkitTestApplication application; - tet_infoline( "UtcDaliVisualSetDepthIndex" ); + tet_infoline( "UtcDaliVisualSetOnOffStage" ); VisualFactory factory = VisualFactory::Get(); Property::Map propertyMap; @@ -356,6 +441,64 @@ int UtcDaliVisualSetOnOffStage(void) END_TEST; } +int UtcDaliVisualSetOnOffStage2(void) +{ + ToolkitTestApplication application; + tet_infoline( "UtcDaliVisualSetOnOffStage2" ); + + VisualFactory factory = VisualFactory::Get(); + Property::Map propertyMap; + propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::SVG ); + propertyMap.Insert( ImageVisual::Property::URL, TEST_SVG_FILE_NAME ); + Visual::Base visual = factory.CreateVisual( propertyMap ); + + DummyControl actor = DummyControl::New(true); + Impl::DummyControl& dummyImpl = static_cast(actor.GetImplementation()); + dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual ); + + actor.SetSize(200.f, 200.f); + + application.SendNotification(); + application.Render(0); + DALI_TEST_CHECK( actor.GetRendererCount() == 0u ); + + // First on/off + Stage::GetCurrent().Add( actor ); + + application.SendNotification(); + application.Render(0); + DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION ); + DALI_TEST_CHECK( actor.GetRendererCount() == 1u ); + Renderer renderer = actor.GetRendererAt( 0 ); + auto textures = renderer.GetTextures(); + DALI_TEST_CHECK( textures.GetTextureCount() != 0u ); + + Stage::GetCurrent().Remove( actor ); + + application.SendNotification(); + application.Render(0); + DALI_TEST_CHECK( actor.GetRendererCount() == 0u ); + + // Second on/off + Stage::GetCurrent().Add( actor ); + + application.SendNotification(); + application.Render(0); + DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION ); + DALI_TEST_CHECK( actor.GetRendererCount() == 1u ); + renderer = actor.GetRendererAt( 0 ); + textures = renderer.GetTextures(); + DALI_TEST_CHECK( textures.GetTextureCount() != 0u ); + + Stage::GetCurrent().Remove( actor ); + + application.SendNotification(); + application.Render(0); + DALI_TEST_CHECK( actor.GetRendererCount() == 0u ); + + END_TEST; +} + int UtcDaliVisualGetPropertyMap1(void) { ToolkitTestApplication application; @@ -364,13 +507,13 @@ int UtcDaliVisualGetPropertyMap1(void) VisualFactory factory = VisualFactory::Get(); Property::Map propertyMap; propertyMap.Insert(Visual::Property::TYPE, Visual::COLOR); - propertyMap.Insert(DevelVisual::Property::MIX_COLOR, Color::BLUE); + propertyMap.Insert(Visual::Property::MIX_COLOR, Color::BLUE); Visual::Base colorVisual = factory.CreateVisual( propertyMap ); Property::Map resultMap; colorVisual.CreatePropertyMap( resultMap ); - Property::Value* typeValue = resultMap.Find( Visual::Property::TYPE, Property::INTEGER ); + Property::Value* typeValue = resultMap.Find( Toolkit::Visual::Property::TYPE, Property::INTEGER ); DALI_TEST_CHECK( typeValue ); DALI_TEST_CHECK( typeValue->Get() == Visual::COLOR ); @@ -408,7 +551,7 @@ int UtcDaliVisualGetPropertyMap2(void) borderVisual.CreatePropertyMap( resultMap ); // check the property values from the returned map from visual - Property::Value* typeValue = resultMap.Find( Visual::Property::TYPE, Property::INTEGER ); + Property::Value* typeValue = resultMap.Find( Toolkit::Visual::Property::TYPE, Property::INTEGER ); DALI_TEST_CHECK( typeValue ); DALI_TEST_CHECK( typeValue->Get() == Visual::BORDER ); @@ -425,13 +568,13 @@ int UtcDaliVisualGetPropertyMap2(void) DALI_TEST_CHECK( AAValue->Get() == true ); Property::Map propertyMap1; - propertyMap1[ Visual::Property::TYPE ] = Visual::BORDER; + propertyMap1[ Toolkit::Visual::Property::TYPE ] = Visual::BORDER; propertyMap1[ BorderVisual::Property::COLOR ] = Color::CYAN; propertyMap1[ BorderVisual::Property::SIZE ] = 10.0f; borderVisual = factory.CreateVisual( propertyMap1 ); borderVisual.CreatePropertyMap( resultMap ); - typeValue = resultMap.Find( Visual::Property::TYPE, Property::INTEGER ); + typeValue = resultMap.Find( Toolkit::Visual::Property::TYPE, Property::INTEGER ); DALI_TEST_CHECK( typeValue ); DALI_TEST_CHECK( typeValue->Get() == Visual::BORDER ); @@ -501,7 +644,7 @@ int UtcDaliVisualGetPropertyMap3(void) gradientVisual.CreatePropertyMap( resultMap ); // check the property values from the returned map from visual - Property::Value* value = resultMap.Find( Visual::Property::TYPE, Property::INTEGER ); + Property::Value* value = resultMap.Find( Toolkit::Visual::Property::TYPE, Property::INTEGER ); DALI_TEST_CHECK( value ); DALI_TEST_CHECK( value->Get() == Visual::GRADIENT ); @@ -569,7 +712,7 @@ int UtcDaliVisualGetPropertyMap4(void) gradientVisual.CreatePropertyMap( resultMap ); // check the property values from the returned map from visual - Property::Value* value = resultMap.Find( Visual::Property::TYPE, Property::INTEGER ); + Property::Value* value = resultMap.Find( Toolkit::Visual::Property::TYPE, Property::INTEGER ); DALI_TEST_CHECK( value ); DALI_TEST_CHECK( value->Get() == Visual::GRADIENT ); @@ -616,8 +759,8 @@ int UtcDaliVisualGetPropertyMap5(void) VisualFactory factory = VisualFactory::Get(); Property::Map propertyMap; - propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE ); - propertyMap.Insert( DevelVisual::Property::MIX_COLOR, Color::MAGENTA ); + propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE ); + propertyMap.Insert( Visual::Property::MIX_COLOR, Color::MAGENTA ); propertyMap.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME ); propertyMap.Insert( ImageVisual::Property::DESIRED_WIDTH, 20 ); propertyMap.Insert( ImageVisual::Property::DESIRED_HEIGHT, 30 ); @@ -635,7 +778,7 @@ int UtcDaliVisualGetPropertyMap5(void) imageVisual.CreatePropertyMap( resultMap ); // check the property values from the returned map from visual - Property::Value* value = resultMap.Find( Visual::Property::TYPE, Property::INTEGER ); + Property::Value* value = resultMap.Find( Toolkit::Visual::Property::TYPE, Property::INTEGER ); DALI_TEST_CHECK( value ); DALI_TEST_CHECK( value->Get() == Visual::IMAGE ); @@ -643,7 +786,7 @@ int UtcDaliVisualGetPropertyMap5(void) DALI_TEST_CHECK( value ); DALI_TEST_CHECK( value->Get() == TEST_IMAGE_FILE_NAME ); - value = resultMap.Find( DevelVisual::Property::MIX_COLOR, Property::VECTOR4 ); + value = resultMap.Find( Visual::Property::MIX_COLOR, Property::VECTOR4 ); DALI_TEST_CHECK( value ); DALI_TEST_CHECK( value->Get() == Color::MAGENTA ); @@ -680,11 +823,12 @@ int UtcDaliVisualGetPropertyMap5(void) DALI_TEST_CHECK( value->Get() == true ); // Get an image visual with an image handle, and test the default property values + PrepareResourceImage( application, 100u, 200u, Pixel::RGBA8888 ); Image image = ResourceImage::New(TEST_IMAGE_FILE_NAME, ImageDimensions(100, 200)); imageVisual = factory.CreateVisual(image); imageVisual.CreatePropertyMap( resultMap ); - value = resultMap.Find( Visual::Property::TYPE, Property::INTEGER ); + value = resultMap.Find( Toolkit::Visual::Property::TYPE, Property::INTEGER ); DALI_TEST_CHECK( value ); DALI_TEST_CHECK( value->Get() == Visual::IMAGE ); @@ -732,23 +876,69 @@ int UtcDaliVisualGetPropertyMap6(void) ToolkitTestApplication application; tet_infoline( "UtcDaliVisualGetPropertyMap6: NPatchVisual" ); + Rect< int > border( 1, 1, 1, 1 ); + VisualFactory factory = VisualFactory::Get(); Property::Map propertyMap; - propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE ); + propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::N_PATCH ); propertyMap.Insert( "mixColor", Color::MAGENTA ); propertyMap.Insert( ImageVisual::Property::URL, TEST_NPATCH_FILE_NAME ); propertyMap.Insert( ImageVisual::Property::BORDER_ONLY, true ); + propertyMap.Insert( ImageVisual::Property::BORDER, border ); + propertyMap.Insert( DevelImageVisual::Property::AUXILIARY_IMAGE, "application-icon-30.png" ); + propertyMap.Insert( DevelImageVisual::Property::AUXILIARY_IMAGE_ALPHA, 0.9f ); Visual::Base nPatchVisual = factory.CreateVisual( propertyMap ); Property::Map resultMap; nPatchVisual.CreatePropertyMap( resultMap ); // check the property values from the returned map from visual - Property::Value* value = resultMap.Find( Visual::Property::TYPE, Property::INTEGER ); + Property::Value* value = resultMap.Find( Toolkit::Visual::Property::TYPE, Property::INTEGER ); DALI_TEST_CHECK( value ); - DALI_TEST_CHECK( value->Get() == Visual::IMAGE ); + DALI_TEST_CHECK( value->Get() == Visual::N_PATCH ); + + value = resultMap.Find( Visual::Property::MIX_COLOR, Property::VECTOR4 ); + DALI_TEST_CHECK( value ); + DALI_TEST_CHECK( value->Get() == Color::MAGENTA ); + + value = resultMap.Find( ImageVisual::Property::URL, Property::STRING ); + DALI_TEST_CHECK( value ); + DALI_TEST_CHECK( value->Get() == TEST_NPATCH_FILE_NAME ); + + value = resultMap.Find( ImageVisual::Property::BORDER_ONLY, Property::BOOLEAN ); + DALI_TEST_CHECK( value ); + DALI_TEST_CHECK( value->Get() ); + + value = resultMap.Find( ImageVisual::Property::BORDER, Property::RECTANGLE ); + DALI_TEST_CHECK( value ); + DALI_TEST_CHECK( value->Get< Rect< int > >() == border ); + + value = resultMap.Find( DevelImageVisual::Property::AUXILIARY_IMAGE, Property::STRING ); + DALI_TEST_CHECK( value ); + DALI_TEST_CHECK( value->Get() == "application-icon-30.png" ); + + value = resultMap.Find( DevelImageVisual::Property::AUXILIARY_IMAGE_ALPHA, Property::FLOAT ); + DALI_TEST_CHECK( value ); + DALI_TEST_CHECK( value->Get() == 0.9f ); + + Vector4 border1( 1.0f, 1.0f, 1.0f, 1.0f ); - value = resultMap.Find( DevelVisual::Property::MIX_COLOR, Property::VECTOR4 ); + Property::Map propertyMap1; + propertyMap1.Insert( Toolkit::Visual::Property::TYPE, Visual::N_PATCH ); + propertyMap1.Insert( "mixColor", Color::MAGENTA ); + propertyMap1.Insert( ImageVisual::Property::URL, TEST_NPATCH_FILE_NAME ); + propertyMap1.Insert( ImageVisual::Property::BORDER_ONLY, true ); + propertyMap1.Insert( ImageVisual::Property::BORDER, border1 ); + nPatchVisual = factory.CreateVisual( propertyMap1 ); + + nPatchVisual.CreatePropertyMap( resultMap ); + + // check the property values from the returned map from visual + value = resultMap.Find( Toolkit::Visual::Property::TYPE, Property::INTEGER ); + DALI_TEST_CHECK( value ); + DALI_TEST_CHECK( value->Get() == Visual::N_PATCH ); + + value = resultMap.Find( Visual::Property::MIX_COLOR, Property::VECTOR4 ); DALI_TEST_CHECK( value ); DALI_TEST_CHECK( value->Get() == Color::MAGENTA ); @@ -760,6 +950,9 @@ int UtcDaliVisualGetPropertyMap6(void) DALI_TEST_CHECK( value ); DALI_TEST_CHECK( value->Get() ); + value = resultMap.Find( ImageVisual::Property::BORDER, Property::RECTANGLE ); + DALI_TEST_CHECK( value ); + DALI_TEST_CHECK( value->Get< Rect< int > >() == border ); END_TEST; } @@ -772,30 +965,58 @@ int UtcDaliVisualGetPropertyMap7(void) // request SvgVisual with a property map VisualFactory factory = VisualFactory::Get(); Property::Map propertyMap; - propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE ); - propertyMap.Insert( DevelVisual::Property::MIX_COLOR, Color::WHITE ); + propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::SVG ); + propertyMap.Insert( Visual::Property::MIX_COLOR, Color::WHITE ); propertyMap.Insert( ImageVisual::Property::URL, TEST_SVG_FILE_NAME ); + propertyMap.Insert( ImageVisual::Property::ATLASING, false ); Visual::Base svgVisual = factory.CreateVisual( propertyMap ); Property::Map resultMap; svgVisual.CreatePropertyMap( resultMap ); // check the property values from the returned map from a visual - Property::Value* value = resultMap.Find( Visual::Property::TYPE, Property::INTEGER ); + Property::Value* value = resultMap.Find( Toolkit::Visual::Property::TYPE, Property::INTEGER ); DALI_TEST_CHECK( value ); - DALI_TEST_CHECK( value->Get() == Visual::IMAGE ); + DALI_TEST_CHECK( value->Get() == Visual::SVG ); + + value = resultMap.Find( ImageVisual::Property::URL, Property::STRING ); + DALI_TEST_CHECK( value ); + DALI_TEST_CHECK( value->Get() == TEST_SVG_FILE_NAME ); + + value = resultMap.Find( ImageVisual::Property::ATLASING, Property::BOOLEAN ); + DALI_TEST_CHECK( value ); + DALI_TEST_CHECK( value->Get() == false ); + + // request SvgVisual with a property map 2 + propertyMap.Clear(); + propertyMap[ "visualType" ] = Visual::SVG; + propertyMap[ "mixColor" ] = Color::WHITE; + propertyMap[ "url" ] = TEST_SVG_FILE_NAME; + propertyMap[ "atlasing" ] = true; + Visual::Base svgVisual1 = factory.CreateVisual( propertyMap ); + + resultMap.Clear(); + svgVisual1.CreatePropertyMap( resultMap ); + // check the property values from the returned map from a visual + value = resultMap.Find( Toolkit::Visual::Property::TYPE, Property::INTEGER ); + DALI_TEST_CHECK( value ); + DALI_TEST_CHECK( value->Get() == Visual::SVG ); value = resultMap.Find( ImageVisual::Property::URL, Property::STRING ); DALI_TEST_CHECK( value ); DALI_TEST_CHECK( value->Get() == TEST_SVG_FILE_NAME ); + value = resultMap.Find( ImageVisual::Property::ATLASING, Property::BOOLEAN ); + DALI_TEST_CHECK( value ); + DALI_TEST_CHECK( value->Get() == true ); + // request SvgVisual with an URL Visual::Base svgVisual2 = factory.CreateVisual( TEST_SVG_FILE_NAME, ImageDimensions() ); resultMap.Clear(); svgVisual2.CreatePropertyMap( resultMap ); // check the property values from the returned map from a visual - value = resultMap.Find( Visual::Property::TYPE, Property::INTEGER ); + value = resultMap.Find( Toolkit::Visual::Property::TYPE, Property::INTEGER ); DALI_TEST_CHECK( value ); - DALI_TEST_CHECK( value->Get() == Visual::IMAGE ); + DALI_TEST_CHECK( value->Get() == Visual::SVG ); value = resultMap.Find( ImageVisual::Property::URL, Property::STRING ); DALI_TEST_CHECK( value ); @@ -813,8 +1034,8 @@ int UtcDaliVisualGetPropertyMap8(void) //Request MeshVisual using a property map. VisualFactory factory = VisualFactory::Get(); Property::Map propertyMap; - propertyMap.Insert( Visual::Property::TYPE, Visual::MESH ); - propertyMap.Insert( DevelVisual::Property::MIX_COLOR, Color::BLUE ); + propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::MESH ); + propertyMap.Insert( Visual::Property::MIX_COLOR, Color::BLUE ); propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME ); propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME ); propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_LOCATION ); @@ -824,10 +1045,10 @@ int UtcDaliVisualGetPropertyMap8(void) Property::Map resultMap; meshVisual.CreatePropertyMap( resultMap ); - TestMixColor( meshVisual, DevelVisual::Property::MIX_COLOR, Color::BLUE ); + TestMixColor( meshVisual, Visual::Property::MIX_COLOR, Color::BLUE ); //Check values in the result map are identical to the initial map's values. - Property::Value* value = resultMap.Find( Visual::Property::TYPE, Property::INTEGER ); + Property::Value* value = resultMap.Find( Toolkit::Visual::Property::TYPE, Property::INTEGER ); DALI_TEST_CHECK( value ); DALI_TEST_EQUALS( value->Get(), (int)Visual::MESH, TEST_LOCATION ); @@ -866,7 +1087,7 @@ int UtcDaliVisualGetPropertyMap9(void) //Request PrimitiveVisual using a property map. VisualFactory factory = VisualFactory::Get(); Property::Map propertyMap; - propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE ); + propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::PRIMITIVE ); propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::CUBE ); propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, color ); propertyMap.Insert( PrimitiveVisual::Property::SLICES, 10 ); @@ -885,7 +1106,7 @@ int UtcDaliVisualGetPropertyMap9(void) primitiveVisual.CreatePropertyMap( resultMap ); //Check values in the result map are identical to the initial map's values. - Property::Value* value = resultMap.Find( Visual::Property::TYPE, Property::INTEGER ); + Property::Value* value = resultMap.Find( Toolkit::Visual::Property::TYPE, Property::INTEGER ); DALI_TEST_CHECK( value ); DALI_TEST_EQUALS( value->Get(), (int)Visual::PRIMITIVE, TEST_LOCATION ); @@ -941,45 +1162,6 @@ int UtcDaliVisualGetPropertyMap9(void) END_TEST; } -int UtcDaliVisualGetPropertyMapBatchImageVisual(void) -{ - ToolkitTestApplication application; - tet_infoline( "UtcDaliVisualGetPropertyMapBatchImageVisual:" ); - - VisualFactory factory = VisualFactory::Get(); - Property::Map propertyMap; - propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE ); - propertyMap.Insert( ImageVisual::Property::BATCHING_ENABLED, true ); - propertyMap.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME ); - propertyMap.Insert( ImageVisual::Property::DESIRED_WIDTH, 20 ); - propertyMap.Insert( ImageVisual::Property::DESIRED_HEIGHT, 30 ); - - Visual::Base batchImageVisual = factory.CreateVisual( propertyMap ); - DALI_TEST_CHECK( batchImageVisual ); - - Property::Map resultMap; - batchImageVisual.CreatePropertyMap( resultMap ); - - // Check the property values from the returned map from visual - Property::Value* value = resultMap.Find( Visual::Property::TYPE, Property::INTEGER ); - DALI_TEST_CHECK( value ); - DALI_TEST_CHECK( value->Get() == Visual::IMAGE ); - - value = resultMap.Find( ImageVisual::Property::URL, Property::STRING ); - DALI_TEST_CHECK( value ); - DALI_TEST_CHECK( value->Get() == TEST_IMAGE_FILE_NAME ); - - value = resultMap.Find( ImageVisual::Property::DESIRED_WIDTH, Property::INTEGER ); - DALI_TEST_CHECK( value ); - DALI_TEST_CHECK( value->Get() == 20 ); - - value = resultMap.Find( ImageVisual::Property::DESIRED_HEIGHT, Property::INTEGER ); - DALI_TEST_CHECK( value ); - DALI_TEST_CHECK( value->Get() == 30 ); - - END_TEST; -} - //Text shape visual int UtcDaliVisualGetPropertyMap10(void) { @@ -990,8 +1172,8 @@ int UtcDaliVisualGetPropertyMap10(void) VisualFactory factory = VisualFactory::Get(); Property::Map propertyMap; - propertyMap.Insert( Visual::Property::TYPE, DevelVisual::TEXT ); - propertyMap.Insert( DevelVisual::Property::MIX_COLOR, Color::BLACK ); + propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::TEXT ); + propertyMap.Insert( Visual::Property::MIX_COLOR, Color::BLACK ); propertyMap.Insert( "renderingBackend", static_cast( Toolkit::Text::DEFAULT_RENDERING_BACKEND ) ); propertyMap.Insert( "enableMarkup", false ); propertyMap.Insert( "text", "Hello world" ); @@ -1006,17 +1188,30 @@ int UtcDaliVisualGetPropertyMap10(void) propertyMap.Insert( "horizontalAlignment", "CENTER" ); propertyMap.Insert( "verticalAlignment", "CENTER" ); propertyMap.Insert( "textColor", Color::RED ); + + Property::Map shadowMapSet; + propertyMap.Insert( "shadow", shadowMapSet.Add("color", Color::RED).Add("offset", Vector2(2.0f, 2.0f)).Add("blurRadius", 3.0f) ); + + Property::Map underlineMapSet; + propertyMap.Insert( "underline", underlineMapSet.Add("enable", "true").Add("color", "green").Add("height", "1") ); + + Property::Map outlineMapSet; + propertyMap.Insert( "outline", outlineMapSet.Add("color", Color::YELLOW).Add("width", 1) ); + + Property::Map backgroundMapSet; + propertyMap.Insert( "textBackground", backgroundMapSet.Add("enable", true).Add("color", Color::CYAN) ); + Visual::Base textVisual = factory.CreateVisual( propertyMap ); Property::Map resultMap; textVisual.CreatePropertyMap( resultMap ); //Check values in the result map are identical to the initial map's values. - Property::Value* value = resultMap.Find( Visual::Property::TYPE, Property::INTEGER ); + Property::Value* value = resultMap.Find( Toolkit::Visual::Property::TYPE, Property::INTEGER ); DALI_TEST_CHECK( value ); - DALI_TEST_EQUALS( value->Get(), (int)DevelVisual::TEXT, TEST_LOCATION ); + DALI_TEST_EQUALS( value->Get(), (int)Visual::TEXT, TEST_LOCATION ); - value = resultMap.Find( DevelVisual::Property::MIX_COLOR, Property::VECTOR4 ); + value = resultMap.Find( Visual::Property::MIX_COLOR, Property::VECTOR4 ); DALI_TEST_CHECK( value ); DALI_TEST_EQUALS( value->Get(), Color::BLACK, 0.001f, TEST_LOCATION ); @@ -1043,13 +1238,13 @@ int UtcDaliVisualGetPropertyMap10(void) DALI_TEST_CHECK( value ); DALI_TEST_CHECK( value->Get() ); - value = resultMap.Find( TextVisual::Property::HORIZONTAL_ALIGNMENT, Property::STRING ); + value = resultMap.Find( TextVisual::Property::HORIZONTAL_ALIGNMENT, Property::INTEGER ); DALI_TEST_CHECK( value ); - DALI_TEST_EQUALS( value->Get(), "CENTER", TEST_LOCATION ); + DALI_TEST_EQUALS( value->Get(), (int)Text::HorizontalAlignment::CENTER, TEST_LOCATION ); - value = resultMap.Find( TextVisual::Property::VERTICAL_ALIGNMENT, Property::STRING ); + value = resultMap.Find( TextVisual::Property::VERTICAL_ALIGNMENT, Property::INTEGER ); DALI_TEST_CHECK( value ); - DALI_TEST_EQUALS( value->Get(), "CENTER", TEST_LOCATION ); + DALI_TEST_EQUALS( value->Get(), (int)Text::VerticalAlignment::CENTER, TEST_LOCATION ); value = resultMap.Find( TextVisual::Property::TEXT_COLOR, Property::VECTOR4 ); DALI_TEST_CHECK( value ); @@ -1059,74 +1254,517 @@ int UtcDaliVisualGetPropertyMap10(void) DALI_TEST_CHECK( value ); DALI_TEST_CHECK( !value->Get() ); + value = resultMap.Find( TextVisual::Property::SHADOW, Property::MAP ); + DALI_TEST_CHECK( value ); + + Property::Map shadowMapGet = value->Get(); + DALI_TEST_EQUALS( shadowMapGet.Count(), shadowMapSet.Count(), TEST_LOCATION ); + DALI_TEST_EQUALS( DaliTestCheckMaps( shadowMapGet, shadowMapSet ), true, TEST_LOCATION ); + + value = resultMap.Find( TextVisual::Property::UNDERLINE, Property::MAP ); + DALI_TEST_CHECK( value ); + + Property::Map underlineMapGet = value->Get(); + DALI_TEST_EQUALS( underlineMapGet.Count(), underlineMapSet.Count(), TEST_LOCATION ); + DALI_TEST_EQUALS( DaliTestCheckMaps( underlineMapGet, underlineMapSet ), true, TEST_LOCATION ); + + value = resultMap.Find( DevelTextVisual::Property::OUTLINE, Property::MAP ); + DALI_TEST_CHECK( value ); + + Property::Map outlineMapGet = value->Get(); + DALI_TEST_EQUALS( outlineMapGet.Count(), outlineMapSet.Count(), TEST_LOCATION ); + DALI_TEST_EQUALS( DaliTestCheckMaps( outlineMapGet, outlineMapSet ), true, TEST_LOCATION ); + + value = resultMap.Find( DevelTextVisual::Property::BACKGROUND, Property::MAP ); + DALI_TEST_CHECK( value ); + + Property::Map backgroundMapGet = value->Get(); + DALI_TEST_EQUALS( backgroundMapGet.Count(), backgroundMapSet.Count(), TEST_LOCATION ); + DALI_TEST_EQUALS( DaliTestCheckMaps( backgroundMapGet, backgroundMapSet ), true, TEST_LOCATION ); + END_TEST; } int UtcDaliVisualGetPropertyMap11(void) { ToolkitTestApplication application; - tet_infoline( "UtcDaliVisualGetPropertyMap7: AnimatedImageVisual" ); + tet_infoline( "UtcDaliVisualGetPropertyMap11: AnimatedGradientVisual" ); - // request SvgVisual with a property map VisualFactory factory = VisualFactory::Get(); + DALI_TEST_CHECK( factory ); + Property::Map propertyMap; - Visual::Base svgVisual = factory.CreateVisual( Property::Map() - .Add( Visual::Property::TYPE, Visual::IMAGE ) - .Add( ImageVisual::Property::URL, TEST_GIF_FILE_NAME ) ); + propertyMap.Insert(Visual::Property::TYPE, DevelVisual::ANIMATED_GRADIENT); + + Vector2 start(-0.5f, 0.5f); + Vector2 end (0.5f, -0.0f); + Vector4 start_color(1.0f, 0.7f, 0.5f, 1.0f); + Vector4 end_color (0.7f, 0.5f, 1.0f, 1.0f); + Vector2 rotate_center(0.0f, 0.4f); + float rotate_amount = 1.57f; + float offset = 100.f; + + propertyMap.Insert(DevelAnimatedGradientVisual::Property::GRADIENT_TYPE, DevelAnimatedGradientVisual::GradientType::RADIAL); + propertyMap.Insert(DevelAnimatedGradientVisual::Property::UNIT_TYPE, DevelAnimatedGradientVisual::UnitType::USER_SPACE); + propertyMap.Insert(DevelAnimatedGradientVisual::Property::SPREAD_TYPE, DevelAnimatedGradientVisual::SpreadType::CLAMP); + + propertyMap.Insert(DevelAnimatedGradientVisual::Property::START_POSITION, start); + propertyMap.Insert(DevelAnimatedGradientVisual::Property::END_POSITION, end); + propertyMap.Insert(DevelAnimatedGradientVisual::Property::START_COLOR, start_color); + propertyMap.Insert(DevelAnimatedGradientVisual::Property::END_COLOR, end_color); + propertyMap.Insert(DevelAnimatedGradientVisual::Property::ROTATE_CENTER, rotate_center); + propertyMap.Insert(DevelAnimatedGradientVisual::Property::ROTATE_AMOUNT, rotate_amount); + propertyMap.Insert(DevelAnimatedGradientVisual::Property::OFFSET, offset); + + Visual::Base animatedGradientVisual = factory.CreateVisual(propertyMap); + DALI_TEST_CHECK( animatedGradientVisual ); Property::Map resultMap; - svgVisual.CreatePropertyMap( resultMap ); - // check the property values from the returned map from a visual - Property::Value* value = resultMap.Find( Visual::Property::TYPE, Property::INTEGER ); + animatedGradientVisual.CreatePropertyMap( resultMap ); + + // check the property values from the returned map from visual + Property::Value* value = resultMap.Find( Toolkit::Visual::Property::TYPE, Property::INTEGER ); DALI_TEST_CHECK( value ); - DALI_TEST_CHECK( value->Get() == Visual::IMAGE ); + DALI_TEST_CHECK( value->Get() == DevelVisual::ANIMATED_GRADIENT ); - value = resultMap.Find( ImageVisual::Property::URL, Property::STRING ); + value = resultMap.Find( DevelAnimatedGradientVisual::Property::GRADIENT_TYPE, Property::INTEGER ); DALI_TEST_CHECK( value ); - DALI_TEST_CHECK( value->Get() == TEST_GIF_FILE_NAME ); + DALI_TEST_CHECK( value->Get() == DevelAnimatedGradientVisual::GradientType::RADIAL ); - // request SvgVisual with an URL - Visual::Base svgVisual2 = factory.CreateVisual( TEST_GIF_FILE_NAME, ImageDimensions() ); - resultMap.Clear(); - svgVisual2.CreatePropertyMap( resultMap ); - // check the property values from the returned map from a visual - value = resultMap.Find( Visual::Property::TYPE, Property::INTEGER ); + value = resultMap.Find( DevelAnimatedGradientVisual::Property::UNIT_TYPE, Property::INTEGER ); DALI_TEST_CHECK( value ); - DALI_TEST_CHECK( value->Get() == Visual::IMAGE ); + DALI_TEST_CHECK( value->Get() == DevelAnimatedGradientVisual::UnitType::USER_SPACE ); - value = resultMap.Find( ImageVisual::Property::URL, Property::STRING ); + value = resultMap.Find( DevelAnimatedGradientVisual::Property::SPREAD_TYPE, Property::INTEGER ); + DALI_TEST_CHECK( value ); + DALI_TEST_CHECK( value->Get() == DevelAnimatedGradientVisual::SpreadType::CLAMP ); + + + value = resultMap.Find( DevelAnimatedGradientVisual::Property::START_POSITION, Property::VECTOR2 ); + DALI_TEST_CHECK( value ); + DALI_TEST_EQUALS( value->Get(), start , Math::MACHINE_EPSILON_100, TEST_LOCATION ); + + value = resultMap.Find( DevelAnimatedGradientVisual::Property::END_POSITION, Property::VECTOR2 ); + DALI_TEST_CHECK( value ); + DALI_TEST_EQUALS( value->Get(), end , Math::MACHINE_EPSILON_100, TEST_LOCATION ); + + value = resultMap.Find( DevelAnimatedGradientVisual::Property::START_COLOR, Property::VECTOR4 ); + DALI_TEST_CHECK( value ); + DALI_TEST_EQUALS( value->Get(), start_color , Math::MACHINE_EPSILON_100, TEST_LOCATION ); + + value = resultMap.Find( DevelAnimatedGradientVisual::Property::END_COLOR, Property::VECTOR4 ); + DALI_TEST_CHECK( value ); + DALI_TEST_EQUALS( value->Get(), end_color , Math::MACHINE_EPSILON_100, TEST_LOCATION ); + + value = resultMap.Find( DevelAnimatedGradientVisual::Property::ROTATE_CENTER, Property::VECTOR2 ); DALI_TEST_CHECK( value ); - DALI_TEST_CHECK( value->Get() == TEST_GIF_FILE_NAME ); + DALI_TEST_EQUALS( value->Get(), rotate_center , Math::MACHINE_EPSILON_100, TEST_LOCATION ); + + value = resultMap.Find( DevelAnimatedGradientVisual::Property::ROTATE_AMOUNT, Property::FLOAT ); + DALI_TEST_CHECK( value ); + DALI_TEST_EQUALS( value->Get(), rotate_amount , Math::MACHINE_EPSILON_100, TEST_LOCATION ); + + value = resultMap.Find( DevelAnimatedGradientVisual::Property::OFFSET, Property::FLOAT ); + DALI_TEST_CHECK( value ); + DALI_TEST_EQUALS( value->Get(), offset , Math::MACHINE_EPSILON_100, TEST_LOCATION ); END_TEST; } -int UtcDaliVisualGetPropertyMapBatchImageVisualNoAtlas(void) +int UtcDaliVisualGetPropertyMap12(void) { ToolkitTestApplication application; - tet_infoline( "UtcDaliVisualGetPropertyMapBatchImageVisualNoAtlas:" ); + tet_infoline( "UtcDaliVisualGetPropertyMap12: AnimatedGradientVisual with animation param" ); - VisualFactory factory = VisualFactory::Get(); - Property::Map propertyMap; - propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE ); - propertyMap.Insert( ImageVisual::Property::BATCHING_ENABLED, true ); - propertyMap.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME ); + // Case 1 : Set values by index + { + tet_printf( " - Set Values by Index\n" ); + // NOTE : PropertyMap doesn't optimized even delay < -loop_count * (duration + repeat_delay) so this animation will not run + // _delay = -10.0f is this case. It will progress (10.0f / 1.5f) amount. and 10.0f / 1.5f > 5. + for(float _delay = -10.0f; _delay <= 5.0f; _delay += 5.0f) + { + tet_printf( "test with delay [%f]\n", _delay ); + VisualFactory factory = VisualFactory::Get(); + DALI_TEST_CHECK( factory ); - // Set the desired size to be larger than the atlas limit of 1024x1024. - propertyMap.Insert( ImageVisual::Property::DESIRED_WIDTH, 2048 ); - propertyMap.Insert( ImageVisual::Property::DESIRED_HEIGHT, 2048 ); + Property::Map propertyMap; + Property::Map animationMap; + propertyMap.Insert(Visual::Property::TYPE, DevelVisual::ANIMATED_GRADIENT); - // Create the visual. - Visual::Base batchImageVisual = factory.CreateVisual( propertyMap ); + float duration = 1.1f; + float delay = _delay; + float repeat_delay = 0.4f; - DALI_TEST_CHECK( batchImageVisual ); + int direction = DevelAnimatedGradientVisual::AnimationParameter::DirectionType::BACKWARD; + int loop_count = 5; + int motion = DevelAnimatedGradientVisual::AnimationParameter::MotionType::MIRROR; + int easing = DevelAnimatedGradientVisual::AnimationParameter::EasingType::OUT; - DummyControl dummyControl = DummyControl::New(true); - Impl::DummyControl& dummyImpl = static_cast(dummyControl.GetImplementation()); - dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, batchImageVisual ); - Stage::GetCurrent().Add( dummyControl ); + auto buildAnimatedMap = [&animationMap, &direction, &duration, &delay, &loop_count, &repeat_delay, &motion, &easing](const Property::Value &start, const Property::Value &target)->Property::Map& + { + animationMap.Clear(); + animationMap.Insert(DevelAnimatedGradientVisual::AnimationParameter::Property::START, start); + animationMap.Insert(DevelAnimatedGradientVisual::AnimationParameter::Property::TARGET, target); + animationMap.Insert(DevelAnimatedGradientVisual::AnimationParameter::Property::DIRECTION, direction); + animationMap.Insert(DevelAnimatedGradientVisual::AnimationParameter::Property::DURATION, duration); + animationMap.Insert(DevelAnimatedGradientVisual::AnimationParameter::Property::DELAY, delay); + animationMap.Insert(DevelAnimatedGradientVisual::AnimationParameter::Property::REPEAT, loop_count); + animationMap.Insert(DevelAnimatedGradientVisual::AnimationParameter::Property::REPEAT_DELAY, repeat_delay); + animationMap.Insert(DevelAnimatedGradientVisual::AnimationParameter::Property::MOTION_TYPE, motion); + animationMap.Insert(DevelAnimatedGradientVisual::AnimationParameter::Property::EASING_TYPE, easing); + + return animationMap; + }; + + Vector2 start1(-0.5f, 0.5f); + Vector2 end1 (0.5f, -0.5f); + Vector4 start_color1(1.0f, 0.7f, 0.5f, 1.0f); + Vector4 end_color1 (0.7f, 0.5f, 1.0f, 1.0f); + Vector2 rotate_center1(0.0f, 0.4f); + float rotate_amount1 = 0.0f; + float offset1 = 0.f; + + Vector2 start2(-0.5f, -0.5f); + Vector2 end2 (0.5f, 0.5f); + Vector4 start_color2(0.0f, 0.1f, 0.8f, 1.0f); + Vector4 end_color2 (0.3f, 1.0f, 0.1f, 0.0f); + Vector2 rotate_center2(0.0f, -0.4f); + float rotate_amount2 = 6.2832f; + float offset2 = 2.f; + + propertyMap.Insert(DevelAnimatedGradientVisual::Property::GRADIENT_TYPE, DevelAnimatedGradientVisual::GradientType::LINEAR); + propertyMap.Insert(DevelAnimatedGradientVisual::Property::UNIT_TYPE, DevelAnimatedGradientVisual::UnitType::OBJECT_BOUNDING_BOX); + propertyMap.Insert(DevelAnimatedGradientVisual::Property::SPREAD_TYPE, DevelAnimatedGradientVisual::SpreadType::REPEAT); + + propertyMap.Insert(DevelAnimatedGradientVisual::Property::START_POSITION, buildAnimatedMap(start1 , start2 )); + propertyMap.Insert(DevelAnimatedGradientVisual::Property::END_POSITION, buildAnimatedMap(end1 , end2 )); + propertyMap.Insert(DevelAnimatedGradientVisual::Property::START_COLOR, buildAnimatedMap(start_color1 , start_color2 )); + propertyMap.Insert(DevelAnimatedGradientVisual::Property::END_COLOR, buildAnimatedMap(end_color1 , end_color2 )); + propertyMap.Insert(DevelAnimatedGradientVisual::Property::ROTATE_CENTER, buildAnimatedMap(rotate_center1, rotate_center2)); + propertyMap.Insert(DevelAnimatedGradientVisual::Property::ROTATE_AMOUNT, buildAnimatedMap(rotate_amount1, rotate_amount2)); + propertyMap.Insert(DevelAnimatedGradientVisual::Property::OFFSET, buildAnimatedMap(offset1 , offset2 )); + + Visual::Base animatedGradientVisual = factory.CreateVisual(propertyMap); + DALI_TEST_CHECK( animatedGradientVisual ); + + Property::Map resultMap; + animatedGradientVisual.CreatePropertyMap( resultMap ); + + // check the property values from the returned map from visual + Property::Value* value = resultMap.Find( Toolkit::Visual::Property::TYPE, Property::INTEGER ); + DALI_TEST_CHECK( value ); + DALI_TEST_CHECK( value->Get() == DevelVisual::ANIMATED_GRADIENT ); + + value = resultMap.Find( DevelAnimatedGradientVisual::Property::GRADIENT_TYPE, Property::INTEGER ); + DALI_TEST_CHECK( value ); + DALI_TEST_CHECK( value->Get() == DevelAnimatedGradientVisual::GradientType::LINEAR ); + + value = resultMap.Find( DevelAnimatedGradientVisual::Property::UNIT_TYPE, Property::INTEGER ); + DALI_TEST_CHECK( value ); + DALI_TEST_CHECK( value->Get() == DevelAnimatedGradientVisual::UnitType::OBJECT_BOUNDING_BOX ); + + value = resultMap.Find( DevelAnimatedGradientVisual::Property::SPREAD_TYPE, Property::INTEGER ); + DALI_TEST_CHECK( value ); + DALI_TEST_CHECK( value->Get() == DevelAnimatedGradientVisual::SpreadType::REPEAT ); + + auto checkAnimatedMap = [&value, &resultMap, &direction, &duration, &delay, &loop_count, &repeat_delay, &motion, &easing](const Property::Index &index, const Property::Value &start, const Property::Value &target, int line_num)->void + { + tet_printf("Check value at %d\n", line_num); + value = resultMap.Find( index, Property::MAP ); + DALI_TEST_CHECK( value ); + DALI_TEST_CHECK( value->GetType() == Property::MAP ); + Property::Map *temp_map = value->GetMap(); + DALI_TEST_CHECK( temp_map ); + + auto checkMapValue = [&temp_map](const Property::Index index)->Property::Value + { + Property::Value *res = temp_map->Find( index ); + DALI_TEST_CHECK( res ); + return *res; + }; + + DALI_TEST_EQUALS( checkMapValue(DevelAnimatedGradientVisual::AnimationParameter::Property::START) , start, Math::MACHINE_EPSILON_100, TEST_LOCATION ); + DALI_TEST_EQUALS( checkMapValue(DevelAnimatedGradientVisual::AnimationParameter::Property::TARGET) , target, Math::MACHINE_EPSILON_100, TEST_LOCATION ); + DALI_TEST_EQUALS( checkMapValue(DevelAnimatedGradientVisual::AnimationParameter::Property::DIRECTION) , Property::Value( direction ), Math::MACHINE_EPSILON_100, TEST_LOCATION ); + DALI_TEST_EQUALS( checkMapValue(DevelAnimatedGradientVisual::AnimationParameter::Property::DURATION) , Property::Value( duration ), Math::MACHINE_EPSILON_100, TEST_LOCATION ); + DALI_TEST_EQUALS( checkMapValue(DevelAnimatedGradientVisual::AnimationParameter::Property::DELAY) , Property::Value( delay ), Math::MACHINE_EPSILON_100, TEST_LOCATION ); + DALI_TEST_EQUALS( checkMapValue(DevelAnimatedGradientVisual::AnimationParameter::Property::REPEAT) , Property::Value( loop_count ), Math::MACHINE_EPSILON_100, TEST_LOCATION ); + DALI_TEST_EQUALS( checkMapValue(DevelAnimatedGradientVisual::AnimationParameter::Property::REPEAT_DELAY), Property::Value( repeat_delay ), Math::MACHINE_EPSILON_100, TEST_LOCATION ); + DALI_TEST_EQUALS( checkMapValue(DevelAnimatedGradientVisual::AnimationParameter::Property::MOTION_TYPE) , Property::Value( motion ), Math::MACHINE_EPSILON_100, TEST_LOCATION ); + DALI_TEST_EQUALS( checkMapValue(DevelAnimatedGradientVisual::AnimationParameter::Property::EASING_TYPE) , Property::Value( easing ), Math::MACHINE_EPSILON_100, TEST_LOCATION ); + }; + + // check the animation map data is good + checkAnimatedMap(DevelAnimatedGradientVisual::Property::START_POSITION, start1 , start2 , __LINE__); + checkAnimatedMap(DevelAnimatedGradientVisual::Property::END_POSITION , end1 , end2 , __LINE__); + checkAnimatedMap(DevelAnimatedGradientVisual::Property::START_COLOR , start_color1 , start_color2 , __LINE__); + checkAnimatedMap(DevelAnimatedGradientVisual::Property::END_COLOR , end_color1 , end_color2 , __LINE__); + checkAnimatedMap(DevelAnimatedGradientVisual::Property::ROTATE_CENTER , rotate_center1, rotate_center2, __LINE__); + checkAnimatedMap(DevelAnimatedGradientVisual::Property::ROTATE_AMOUNT , rotate_amount1, rotate_amount2, __LINE__); + checkAnimatedMap(DevelAnimatedGradientVisual::Property::OFFSET , offset1 , offset2 , __LINE__); + } + } + + // Case 2 : Set values by string + { + tet_printf( " - Set Values by String\n" ); + // NOTE : PropertyMap doesn't optimized even delay < -loop_count * (duration + repeat_delay) so this animation will not run + // _delay = -10.0f is this case. It will progress (10.0f / 1.5f) amount. and 10.0f / 1.5f > 5. + for(float _delay = -10.0f; _delay <= 5.0f; _delay += 5.0f) + { + tet_printf( "test with delay [%f]\n", _delay ); + VisualFactory factory = VisualFactory::Get(); + DALI_TEST_CHECK( factory ); + + Property::Map propertyMap; + Property::Map animationMap; + propertyMap.Insert("visualType", "ANIMATED_GRADIENT"); + + float duration = 1.1f; + float delay = _delay; + float repeat_delay = 0.4f; + + int direction = DevelAnimatedGradientVisual::AnimationParameter::DirectionType::BACKWARD; + int loop_count = 5; + int motion = DevelAnimatedGradientVisual::AnimationParameter::MotionType::MIRROR; + int easing = DevelAnimatedGradientVisual::AnimationParameter::EasingType::IN_OUT; + + auto buildAnimatedMap = [&animationMap, &duration, &delay, &loop_count, &repeat_delay](const Property::Value &start, const Property::Value &target)->Property::Map& + { + animationMap.Clear(); + animationMap.Insert("startValue" , start); + animationMap.Insert("targetValue" , target); + animationMap.Insert("directionType", "BACKWARD"); + animationMap.Insert("duration" , duration); + animationMap.Insert("delay" , delay); + animationMap.Insert("repeat" , loop_count); + animationMap.Insert("repeatDelay" , repeat_delay); + animationMap.Insert("motionType" , "MIRROR"); + animationMap.Insert("easingType" , "IN_OUT"); + + return animationMap; + }; + + Vector2 start1(-0.5f, 0.5f); + Vector2 end1 (0.5f, -0.5f); + Vector4 start_color1(1.0f, 0.7f, 0.5f, 1.0f); + Vector4 end_color1 (0.7f, 0.5f, 1.0f, 1.0f); + Vector2 rotate_center1(0.0f, 0.4f); + float rotate_amount1 = 0.0f; + float offset1 = 0.f; + + Vector2 start2(-0.5f, -0.5f); + Vector2 end2 (0.5f, 0.5f); + Vector4 start_color2(0.0f, 0.1f, 0.8f, 1.0f); + Vector4 end_color2 (0.3f, 1.0f, 0.1f, 0.0f); + Vector2 rotate_center2(0.0f, -0.4f); + float rotate_amount2 = 6.2832f; + float offset2 = 2.f; + + // For test mix the type string/index key and string/index value works well. + propertyMap.Insert(DevelAnimatedGradientVisual::Property::GRADIENT_TYPE, "RADIAL"); + propertyMap.Insert(DevelAnimatedGradientVisual::Property::UNIT_TYPE, DevelAnimatedGradientVisual::UnitType::USER_SPACE); + propertyMap.Insert("spreadType" , DevelAnimatedGradientVisual::SpreadType::REFLECT); + + propertyMap.Insert("startPosition", buildAnimatedMap(start1 , start2 )); + propertyMap.Insert("endPosition" , buildAnimatedMap(end1 , end2 )); + propertyMap.Insert("startColor" , buildAnimatedMap(start_color1 , start_color2 )); + propertyMap.Insert("endColor" , buildAnimatedMap(end_color1 , end_color2 )); + propertyMap.Insert("rotateCenter" , buildAnimatedMap(rotate_center1, rotate_center2)); + propertyMap.Insert("rotateAmount" , buildAnimatedMap(rotate_amount1, rotate_amount2)); + propertyMap.Insert("offset" , buildAnimatedMap(offset1 , offset2 )); + + Visual::Base animatedGradientVisual = factory.CreateVisual(propertyMap); + DALI_TEST_CHECK( animatedGradientVisual ); + + Property::Map resultMap; + animatedGradientVisual.CreatePropertyMap( resultMap ); + + // check the property values from the returned map from visual + // Note : resultMap from CreatePropertyMap only contain indexKey + Property::Value* value = resultMap.Find( Toolkit::Visual::Property::TYPE, Property::INTEGER ); + DALI_TEST_CHECK( value ); + DALI_TEST_CHECK( value->Get() == DevelVisual::ANIMATED_GRADIENT ); + + value = resultMap.Find( DevelAnimatedGradientVisual::Property::GRADIENT_TYPE, Property::INTEGER ); + DALI_TEST_CHECK( value ); + DALI_TEST_CHECK( value->Get() == DevelAnimatedGradientVisual::GradientType::RADIAL ); + + value = resultMap.Find( DevelAnimatedGradientVisual::Property::UNIT_TYPE, Property::INTEGER ); + DALI_TEST_CHECK( value ); + DALI_TEST_CHECK( value->Get() == DevelAnimatedGradientVisual::UnitType::USER_SPACE ); + + value = resultMap.Find( DevelAnimatedGradientVisual::Property::SPREAD_TYPE, Property::INTEGER ); + DALI_TEST_CHECK( value ); + DALI_TEST_CHECK( value->Get() == DevelAnimatedGradientVisual::SpreadType::REFLECT ); + + auto checkAnimatedMap = [&value, &resultMap, &direction, &duration, &delay, &loop_count, &repeat_delay, &motion, &easing](const Property::Index &index, const Property::Value &start, const Property::Value &target, int line_num)->void + { + tet_printf("Check value at %d\n", line_num); + value = resultMap.Find( index, Property::MAP ); + DALI_TEST_CHECK( value ); + DALI_TEST_CHECK( value->GetType() == Property::MAP ); + Property::Map *temp_map = value->GetMap(); + DALI_TEST_CHECK( temp_map ); + + auto checkMapValue = [&temp_map](const Property::Index index)->Property::Value + { + Property::Value *res = temp_map->Find( index ); + DALI_TEST_CHECK( res ); + return *res; + }; + + DALI_TEST_EQUALS( checkMapValue(DevelAnimatedGradientVisual::AnimationParameter::Property::START) , start, Math::MACHINE_EPSILON_100, TEST_LOCATION ); + DALI_TEST_EQUALS( checkMapValue(DevelAnimatedGradientVisual::AnimationParameter::Property::TARGET) , target, Math::MACHINE_EPSILON_100, TEST_LOCATION ); + DALI_TEST_EQUALS( checkMapValue(DevelAnimatedGradientVisual::AnimationParameter::Property::DIRECTION) , Property::Value( direction ), Math::MACHINE_EPSILON_100, TEST_LOCATION ); + DALI_TEST_EQUALS( checkMapValue(DevelAnimatedGradientVisual::AnimationParameter::Property::DURATION) , Property::Value( duration ), Math::MACHINE_EPSILON_100, TEST_LOCATION ); + DALI_TEST_EQUALS( checkMapValue(DevelAnimatedGradientVisual::AnimationParameter::Property::DELAY) , Property::Value( delay ), Math::MACHINE_EPSILON_100, TEST_LOCATION ); + DALI_TEST_EQUALS( checkMapValue(DevelAnimatedGradientVisual::AnimationParameter::Property::REPEAT) , Property::Value( loop_count ), Math::MACHINE_EPSILON_100, TEST_LOCATION ); + DALI_TEST_EQUALS( checkMapValue(DevelAnimatedGradientVisual::AnimationParameter::Property::REPEAT_DELAY), Property::Value( repeat_delay ), Math::MACHINE_EPSILON_100, TEST_LOCATION ); + DALI_TEST_EQUALS( checkMapValue(DevelAnimatedGradientVisual::AnimationParameter::Property::MOTION_TYPE) , Property::Value( motion ), Math::MACHINE_EPSILON_100, TEST_LOCATION ); + DALI_TEST_EQUALS( checkMapValue(DevelAnimatedGradientVisual::AnimationParameter::Property::EASING_TYPE) , Property::Value( easing ), Math::MACHINE_EPSILON_100, TEST_LOCATION ); + }; + + // check the animation map data is good + checkAnimatedMap(DevelAnimatedGradientVisual::Property::START_POSITION, start1 , start2 , __LINE__); + checkAnimatedMap(DevelAnimatedGradientVisual::Property::END_POSITION , end1 , end2 , __LINE__); + checkAnimatedMap(DevelAnimatedGradientVisual::Property::START_COLOR , start_color1 , start_color2 , __LINE__); + checkAnimatedMap(DevelAnimatedGradientVisual::Property::END_COLOR , end_color1 , end_color2 , __LINE__); + checkAnimatedMap(DevelAnimatedGradientVisual::Property::ROTATE_CENTER , rotate_center1, rotate_center2, __LINE__); + checkAnimatedMap(DevelAnimatedGradientVisual::Property::ROTATE_AMOUNT , rotate_amount1, rotate_amount2, __LINE__); + checkAnimatedMap(DevelAnimatedGradientVisual::Property::OFFSET , offset1 , offset2 , __LINE__); + } + } + + END_TEST; +} +int UtcDaliVisualGetPropertyMap13(void) +{ + ToolkitTestApplication application; + tet_infoline( "UtcDaliVisualGetPropertyMap13: AnimatedGradientVisual when repeat = 0" ); + + for(int _direction = 0; _direction <= 1; ++_direction) + { + for(float _delay = -10.0f; _delay <= 10.0f; _delay += 10.0f) + { + tet_printf( ((_direction == 0) ? "Forward test with delay [%f]\n" : "Backward test with delay [%f]\n") , _delay ); + VisualFactory factory = VisualFactory::Get(); + DALI_TEST_CHECK( factory ); + + Property::Map propertyMap; + Property::Map animationMap; + propertyMap.Insert(Visual::Property::TYPE, DevelVisual::ANIMATED_GRADIENT); + + float duration = 1.0f; + float delay = _delay; + float repeat_delay = 0.5f; + + int direction = _direction; + int loop_count = 0; // When loop_count is 0, Animation will not be created. + int motion = DevelAnimatedGradientVisual::AnimationParameter::MotionType::LOOP; + int easing = DevelAnimatedGradientVisual::AnimationParameter::EasingType::IN; - DALI_TEST_CHECK( dummyControl.GetRendererCount() == 1u ); + auto buildAnimatedMap = [&animationMap, &direction, &duration, &delay, &loop_count, &repeat_delay, &motion, &easing](const Property::Value &start, const Property::Value &target)->Property::Map& + { + animationMap.Clear(); + animationMap.Insert(DevelAnimatedGradientVisual::AnimationParameter::Property::START, start); + animationMap.Insert(DevelAnimatedGradientVisual::AnimationParameter::Property::TARGET, target); + if(direction == 0)animationMap.Insert(DevelAnimatedGradientVisual::AnimationParameter::Property::DIRECTION, DevelAnimatedGradientVisual::AnimationParameter::DirectionType::FORWARD); + else animationMap.Insert(DevelAnimatedGradientVisual::AnimationParameter::Property::DIRECTION, DevelAnimatedGradientVisual::AnimationParameter::DirectionType::BACKWARD); + animationMap.Insert(DevelAnimatedGradientVisual::AnimationParameter::Property::DIRECTION, direction); + animationMap.Insert(DevelAnimatedGradientVisual::AnimationParameter::Property::DURATION, duration); + animationMap.Insert(DevelAnimatedGradientVisual::AnimationParameter::Property::DELAY, delay); + animationMap.Insert(DevelAnimatedGradientVisual::AnimationParameter::Property::REPEAT, loop_count); + animationMap.Insert(DevelAnimatedGradientVisual::AnimationParameter::Property::REPEAT_DELAY, repeat_delay); + animationMap.Insert(DevelAnimatedGradientVisual::AnimationParameter::Property::MOTION_TYPE, motion); + animationMap.Insert(DevelAnimatedGradientVisual::AnimationParameter::Property::EASING_TYPE, easing); + + return animationMap; + }; + + Vector2 start1(-0.5f, 0.5f); + Vector2 end1 (0.5f, -0.5f); + Vector4 start_color1(1.0f, 0.7f, 0.5f, 1.0f); + Vector4 end_color1 (0.7f, 0.5f, 1.0f, 1.0f); + Vector2 rotate_center1(1.0f, 0.4f); + float rotate_amount1 = 2.0f; + float offset1 = 1.f; + + Vector2 start2(-0.5f, -0.5f); + Vector2 end2 (0.5f, 0.5f); + Vector4 start_color2(0.0f, 0.1f, 0.8f, 1.0f); + Vector4 end_color2 (0.3f, 1.0f, 0.1f, 0.0f); + Vector2 rotate_center2(1.0f, -0.4f); + float rotate_amount2 = 1.0f; + float offset2 = 3.f; + + propertyMap.Insert(DevelAnimatedGradientVisual::Property::GRADIENT_TYPE, DevelAnimatedGradientVisual::GradientType::LINEAR); + propertyMap.Insert(DevelAnimatedGradientVisual::Property::UNIT_TYPE, DevelAnimatedGradientVisual::UnitType::OBJECT_BOUNDING_BOX); + propertyMap.Insert(DevelAnimatedGradientVisual::Property::SPREAD_TYPE, DevelAnimatedGradientVisual::SpreadType::REFLECT); + + propertyMap.Insert(DevelAnimatedGradientVisual::Property::START_POSITION, buildAnimatedMap(start1 , start2 )); + propertyMap.Insert(DevelAnimatedGradientVisual::Property::END_POSITION, buildAnimatedMap(end1 , end2 )); + propertyMap.Insert(DevelAnimatedGradientVisual::Property::START_COLOR, buildAnimatedMap(start_color1 , start_color2 )); + propertyMap.Insert(DevelAnimatedGradientVisual::Property::END_COLOR, buildAnimatedMap(end_color1 , end_color2 )); + propertyMap.Insert(DevelAnimatedGradientVisual::Property::ROTATE_CENTER, buildAnimatedMap(rotate_center1, rotate_center2)); + propertyMap.Insert(DevelAnimatedGradientVisual::Property::ROTATE_AMOUNT, buildAnimatedMap(rotate_amount1, rotate_amount2)); + propertyMap.Insert(DevelAnimatedGradientVisual::Property::OFFSET, buildAnimatedMap(offset1 , offset2 )); + + Visual::Base animatedGradientVisual = factory.CreateVisual(propertyMap); + DALI_TEST_CHECK( animatedGradientVisual ); + + Property::Map resultMap; + animatedGradientVisual.CreatePropertyMap( resultMap ); + + // check the property values from the returned map from visual + Property::Value* value = resultMap.Find( Toolkit::Visual::Property::TYPE, Property::INTEGER ); + DALI_TEST_CHECK( value ); + DALI_TEST_CHECK( value->Get() == DevelVisual::ANIMATED_GRADIENT ); + + value = resultMap.Find( DevelAnimatedGradientVisual::Property::GRADIENT_TYPE, Property::INTEGER ); + DALI_TEST_CHECK( value ); + DALI_TEST_CHECK( value->Get() == DevelAnimatedGradientVisual::GradientType::LINEAR ); + + value = resultMap.Find( DevelAnimatedGradientVisual::Property::UNIT_TYPE, Property::INTEGER ); + DALI_TEST_CHECK( value ); + DALI_TEST_CHECK( value->Get() == DevelAnimatedGradientVisual::UnitType::OBJECT_BOUNDING_BOX ); + + value = resultMap.Find( DevelAnimatedGradientVisual::Property::SPREAD_TYPE, Property::INTEGER ); + DALI_TEST_CHECK( value ); + DALI_TEST_CHECK( value->Get() == DevelAnimatedGradientVisual::SpreadType::REFLECT ); + + // If loop_count = 0, Animation doesn't created. + // Optimized resultMap only have one value, which is target value + // Note: target value will be changed by direction option. + value = resultMap.Find( DevelAnimatedGradientVisual::Property::START_POSITION, Property::VECTOR2 ); + DALI_TEST_CHECK( value ); + DALI_TEST_EQUALS( value->Get(), direction ? start1 : start2 , Math::MACHINE_EPSILON_100, TEST_LOCATION ); + + value = resultMap.Find( DevelAnimatedGradientVisual::Property::END_POSITION, Property::VECTOR2 ); + DALI_TEST_CHECK( value ); + DALI_TEST_EQUALS( value->Get(), direction ? end1 : end2 , Math::MACHINE_EPSILON_100, TEST_LOCATION ); + + value = resultMap.Find( DevelAnimatedGradientVisual::Property::START_COLOR, Property::VECTOR4 ); + DALI_TEST_CHECK( value ); + DALI_TEST_EQUALS( value->Get(), direction ? start_color1 : start_color2 , Math::MACHINE_EPSILON_100, TEST_LOCATION ); + + value = resultMap.Find( DevelAnimatedGradientVisual::Property::END_COLOR, Property::VECTOR4 ); + DALI_TEST_CHECK( value ); + DALI_TEST_EQUALS( value->Get(), direction ? end_color1 : end_color2 , Math::MACHINE_EPSILON_100, TEST_LOCATION ); + + value = resultMap.Find( DevelAnimatedGradientVisual::Property::ROTATE_CENTER, Property::VECTOR2 ); + DALI_TEST_CHECK( value ); + DALI_TEST_EQUALS( value->Get(), direction ? rotate_center1 : rotate_center2 , Math::MACHINE_EPSILON_100, TEST_LOCATION ); + + value = resultMap.Find( DevelAnimatedGradientVisual::Property::ROTATE_AMOUNT, Property::FLOAT ); + DALI_TEST_CHECK( value ); + DALI_TEST_EQUALS( value->Get(), direction ? rotate_amount1 : rotate_amount2 , Math::MACHINE_EPSILON_100, TEST_LOCATION ); + + value = resultMap.Find( DevelAnimatedGradientVisual::Property::OFFSET, Property::FLOAT ); + DALI_TEST_CHECK( value ); + DALI_TEST_EQUALS( value->Get(), direction ? offset1 : offset2 , Math::MACHINE_EPSILON_100, TEST_LOCATION ); + } + } END_TEST; } @@ -1139,7 +1777,7 @@ int UtcDaliVisualAnimateBorderVisual01(void) VisualFactory factory = VisualFactory::Get(); Property::Map propertyMap; propertyMap.Insert(Visual::Property::TYPE, Visual::BORDER); - propertyMap.Insert(DevelVisual::Property::MIX_COLOR, Vector4(1, 1, 1, 0.8f)); + propertyMap.Insert(Visual::Property::MIX_COLOR, Vector4(1, 1, 1, 0.8f)); propertyMap.Insert(BorderVisual::Property::COLOR, Color::BLUE); propertyMap.Insert(BorderVisual::Property::SIZE, 5.f); Visual::Base borderVisual = factory.CreateVisual( propertyMap ); @@ -1147,7 +1785,7 @@ int UtcDaliVisualAnimateBorderVisual01(void) Property::Map map; map["target"] = "testVisual"; map["property"] = "mixColor"; - map["targetValue"] = Vector4(1,1,1,0); + map["targetValue"] = Vector4(1,1,1,0.1); map["animator"] = Property::Map() .Add("alphaFunction", "LINEAR") .Add("timePeriod", Property::Map() @@ -1167,7 +1805,7 @@ int UtcDaliVisualAnimateBorderVisual01(void) Renderer renderer = actor.GetRendererAt(0); Property::Index borderColorIndex = DevelHandle::GetPropertyIndex( renderer, BorderVisual::Property::COLOR ); - Property::Index mixColorIndex = DevelHandle::GetPropertyIndex( renderer, DevelVisual::Property::MIX_COLOR ); + Property::Index mixColorIndex = DevelHandle::GetPropertyIndex( renderer, Visual::Property::MIX_COLOR ); Animation animation = dummyImpl.CreateTransition( transition ); @@ -1180,26 +1818,33 @@ int UtcDaliVisualAnimateBorderVisual01(void) application.Render(0); application.Render(2000u); // halfway point between blue and white - Vector4 color = renderer.GetProperty( borderColorIndex ); + Vector4 color = renderer.GetCurrentProperty< Vector4 >( borderColorIndex ); Vector4 testColor = (Color::BLUE + Color::WHITE)*0.5f; DALI_TEST_EQUALS( color, testColor, TEST_LOCATION ); DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue("borderColor", testColor ), true, TEST_LOCATION ); - color = renderer.GetProperty( mixColorIndex ); - testColor = Vector4( 1,1,1,0.4f ); - DALI_TEST_EQUALS( color, testColor, 0.0001f, TEST_LOCATION ); - DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue("mixColor", testColor ), true, TEST_LOCATION ); + color = renderer.GetCurrentProperty< Vector3 >( mixColorIndex ); + testColor = Vector4( 1,1,1,0.45f ); + DALI_TEST_EQUALS( Vector3(color), Vector3(testColor), 0.0001f, TEST_LOCATION ); + DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue("mixColor", Vector3(testColor) ), true, TEST_LOCATION ); - application.Render(2000u); // halfway point between blue and white + Vector4 uColor; + DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue< Vector4 >( "uColor", uColor ) ); + DALI_TEST_EQUALS( uColor.a, testColor.a, TEST_LOCATION ); - color = renderer.GetProperty( borderColorIndex ); + application.Render(2000u); + + color = renderer.GetCurrentProperty< Vector4 >( borderColorIndex ); DALI_TEST_EQUALS( color, Color::WHITE, TEST_LOCATION ); DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue("borderColor", Color::WHITE ), true, TEST_LOCATION ); - color = renderer.GetProperty( mixColorIndex ); - testColor = Vector4(1,1,1,0); - DALI_TEST_EQUALS( color, testColor, TEST_LOCATION ); - DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue("mixColor", testColor ), true, TEST_LOCATION ); + color = renderer.GetCurrentProperty< Vector3 >( mixColorIndex ); + testColor = Vector4(1,1,1,0.1); + DALI_TEST_EQUALS( Vector3(color), Vector3(testColor), TEST_LOCATION ); + DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue("mixColor", Vector3(testColor) ), true, TEST_LOCATION ); + + DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue< Vector4 >( "uColor", uColor ) ); + DALI_TEST_EQUALS( uColor.a, testColor.a, TEST_LOCATION ); END_TEST; } @@ -1237,13 +1882,13 @@ int UtcDaliVisualAnimateBorderVisual02(void) application.Render(0); application.Render(2000u); // halfway point - float size = renderer.GetProperty( index ); + float size = renderer.GetCurrentProperty< float >( index ); DALI_TEST_EQUALS( size, 7.0f, 0.0001f, TEST_LOCATION ); DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue("borderSize", 7.0f ), true, TEST_LOCATION ); application.Render(2000u); // halfway point between blue and white - size = renderer.GetProperty( index ); + size = renderer.GetCurrentProperty< float >( index ); DALI_TEST_EQUALS( size, 9.0f, 0.0001f, TEST_LOCATION ); DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue("borderSize", 9.0f ), true, TEST_LOCATION ); @@ -1271,33 +1916,33 @@ int UtcDaliVisualAnimateColorVisual(void) DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION); Renderer renderer = actor.GetRendererAt(0); - Property::Index index = DevelHandle::GetPropertyIndex( renderer, ColorVisual::Property::MIX_COLOR ); + Property::Index mixColorIndex = DevelHandle::GetPropertyIndex( renderer, ColorVisual::Property::MIX_COLOR ); Property::Value blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE ); DALI_TEST_EQUALS( blendModeValue.Get(), (int)BlendMode::AUTO, TEST_LOCATION ); Animation animation = Animation::New(4.0f); - animation.AnimateTo( Property(renderer, index), Color::WHITE ); + animation.AnimateTo( Property(renderer, mixColorIndex), Vector3(Color::WHITE) ); animation.Play(); application.SendNotification(); application.Render(0); application.Render(2000u); // halfway point - Vector4 color = renderer.GetProperty( index ); - Vector4 testColor = (Color::BLUE + Color::WHITE)*0.5f; + Vector3 color = renderer.GetCurrentProperty< Vector3 >( mixColorIndex ); + Vector3 testColor = Vector3(Color::BLUE + Color::WHITE)*0.5f; DALI_TEST_EQUALS( color, testColor, TEST_LOCATION ); - DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue("mixColor", testColor ), true, TEST_LOCATION ); + DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue("mixColor", testColor ), true, TEST_LOCATION ); application.Render(2000u); // halfway point between blue and white - color = renderer.GetProperty( index ); - DALI_TEST_EQUALS( color, Color::WHITE, TEST_LOCATION ); + color = renderer.GetCurrentProperty< Vector3 >( mixColorIndex ); + DALI_TEST_EQUALS( color, Vector3(Color::WHITE), TEST_LOCATION ); - DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue("mixColor", Color::WHITE ), true, TEST_LOCATION ); + DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue("mixColor", Vector3(Color::WHITE) ), true, TEST_LOCATION ); - blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE ); + blendModeValue = renderer.GetCurrentProperty( Renderer::Property::BLEND_MODE ); DALI_TEST_EQUALS( blendModeValue.Get(), (int)BlendMode::AUTO, TEST_LOCATION ); END_TEST; @@ -1360,17 +2005,16 @@ int UtcDaliVisualAnimatePrimitiveVisual(void) application.Render(2000u); // halfway point application.SendNotification(); - DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue("uColor", Vector4(0.5f, 0.5f, 0.5f, 1.0f )), true, TEST_LOCATION ); - Vector4 halfwayColor = (INITIAL_MIX_COLOR + TARGET_MIX_COLOR)*0.5; - DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue("mixColor", halfwayColor ), true, TEST_LOCATION ); + DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue("uColor", Vector4(0.5f, 0.5f, 0.5f, halfwayColor.a )), true, TEST_LOCATION ); + DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue("mixColor", Vector3(halfwayColor) ), true, TEST_LOCATION ); application.Render(2001u); // go past end application.SendNotification(); // Trigger signals DALI_TEST_EQUALS( actor.GetCurrentColor(), Color::WHITE, TEST_LOCATION ); - DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue("uColor", Color::WHITE ), true, TEST_LOCATION ); - DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue("mixColor", TARGET_MIX_COLOR ), true, TEST_LOCATION ); + DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue("uColor", Vector4( 1.0f, 1.0f, 1.0f, TARGET_MIX_COLOR.a ) ), true, TEST_LOCATION ); + DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue("mixColor", Vector3(TARGET_MIX_COLOR) ), true, TEST_LOCATION ); blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE ); DALI_TEST_EQUALS( blendModeValue.Get(), (int)BlendMode::AUTO, TEST_LOCATION ); @@ -1381,155 +2025,622 @@ int UtcDaliVisualAnimatePrimitiveVisual(void) END_TEST; } -int UtcDaliVisualAnimateImageVisualMixColor(void) +int UtcDaliVisualAnimatedGradientVisual01(void) { ToolkitTestApplication application; - tet_infoline( "UtcDaliAnimateImageVisual mix color" ); - - application.GetPlatform().SetClosestImageSize( Vector2(100, 100) ); + tet_infoline( "UtcDaliAnimatedGradientVisual with default" ); - VisualFactory factory = VisualFactory::Get(); - Property::Map propertyMap; - propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE); - propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME ); - propertyMap.Insert("mixColor", Color::BLUE); - propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true); - Visual::Base visual = factory.CreateVisual( propertyMap ); - - DummyControl actor = DummyControl::New(true); - Impl::DummyControl& dummyImpl = static_cast(actor.GetImplementation()); - dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual ); + { + VisualFactory factory = VisualFactory::Get(); + Property::Map propertyMap; + propertyMap.Insert(Visual::Property::TYPE, DevelVisual::ANIMATED_GRADIENT); + Visual::Base visual = factory.CreateVisual( propertyMap ); - actor.SetSize(2000, 2000); - actor.SetParentOrigin(ParentOrigin::CENTER); - actor.SetColor(Color::BLACK); - Stage::GetCurrent().Add(actor); + DummyControl actor = DummyControl::New(true); + Impl::DummyControl& dummyImpl = static_cast(actor.GetImplementation()); + dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual ); + actor.SetSize(2000, 2000); + actor.SetParentOrigin(ParentOrigin::CENTER); + actor.SetColor(Color::BLACK); + Stage::GetCurrent().Add(actor); - DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION); + application.SendNotification(); + application.Render(0); + application.SendNotification(); - Renderer renderer = actor.GetRendererAt(0); - Property::Index index = DevelHandle::GetPropertyIndex( renderer, DevelVisual::Property::MIX_COLOR ); - Property::Value blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE ); - DALI_TEST_EQUALS( blendModeValue.Get(), (int)BlendMode::AUTO, TEST_LOCATION ); + DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION); - tet_infoline("Test that the renderer has the mixColor property"); - DALI_TEST_CHECK( index != Property::INVALID_INDEX ); + for(int step_iter = 0; step_iter < 3; step_iter++) + { + application.SendNotification(); + application.Render(0); + application.Render(750u); // step i/4 + application.SendNotification(); + + DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue( "start_point" , Vector2( -0.5f, 0.0f ) ), true, TEST_LOCATION ); + DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue( "end_point" , Vector2( 0.5f, 0.0f ) ), true, TEST_LOCATION ); + DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue( "start_color" , Vector4( 143.0f, 170.0f, 220.0f, 255.0f ) / 255.0f ), true, TEST_LOCATION ); + DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue( "end_color" , Vector4( 255.0f, 163.0f, 163.0f, 255.0f ) / 255.0f ), true, TEST_LOCATION ); + DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue( "rotate_center", Vector2( 0.0f, 0.0f ) ), true, TEST_LOCATION ); + DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue( "rotate_angle" , 0.0f ), true, TEST_LOCATION ); + DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue( "gradient_offset", 0.5f * step_iter + 0.5f ), true, TEST_LOCATION ); + } - const Vector4 TARGET_MIX_COLOR( 1.0f, 0.0f, 0.0f, 0.5f ); + //Not check here. cause gradient_offset value can be 2.0f or 0.0f + application.Render(750u); // go to end + application.SendNotification(); - Property::Map map; - map["target"] = "testVisual"; - map["property"] = "mixColor"; - map["initialValue"] = Color::MAGENTA; - map["targetValue"] = TARGET_MIX_COLOR; - map["animator"] = Property::Map() - .Add("alphaFunction", "LINEAR") - .Add("timePeriod", Property::Map() - .Add("delay", 0.0f) - .Add("duration", 4.0f)); + application.Render(10u); // finish + application.SendNotification(); - Dali::Toolkit::TransitionData transition = TransitionData::New( map ); + actor.Unparent(); + application.SendNotification(); + application.Render(0u); + application.SendNotification(); + } - Animation animation = dummyImpl.CreateTransition( transition ); + END_TEST; +} - blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE ); - DALI_TEST_EQUALS( blendModeValue.Get(), (int)BlendMode::ON, TEST_LOCATION ); +int UtcDaliVisualAnimatedGradientVisual02(void) +{ + ToolkitTestApplication application; + tet_infoline( "UtcDaliAnimatedGradientVisual with full-option" ); - animation.AnimateTo( Property(actor, Actor::Property::COLOR), Color::WHITE ); - animation.Play(); + { + float _delay[4] = {0.0f, -1.35f, 0.15f, -0.4f}; // fract(_delay) must NOT be 1/4, 2/4, 3/4. cause we don't know progress is 1.0f or 0.0f + int _direction[2] = {0, 1}; + int _loop_count[3] = {-1, 0, 1}; + int _motion[2] = {0, 1}; + int _easing[4] = {0, 1, 2, 3}; + + int test_case_max = 4 * 2 * 3 * 2 * 4; + int test_case = 0; + int test_case_d = 7; // 7 is the number of animated properties. + + float _duration = 0.4f; + float _repeat_delay = _duration * 0.25f; // < _duration. cause real_duration = _duration - _repeat_delay; + float noise_maker = 0.0f; + // total testing time = ceil((4*2*3*2*4) / 7) * (_duration(=0.4) * 2 + 0.01) = 22.68 seconds + for( test_case = 0; test_case < test_case_max + test_case_d; test_case += test_case_d ) + { + tet_printf( "test [%d ~ %d / %d]\n" , test_case, test_case + test_case_d - 1, test_case_max); - application.SendNotification(); - application.Render(0); - application.Render(2000u); // halfway point + VisualFactory factory = VisualFactory::Get(); + Property::Map propertyMap; + Property::Map animationMap; + propertyMap.Insert(Visual::Property::TYPE, DevelVisual::ANIMATED_GRADIENT); - DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue("uColor", Vector4(0.5f, 0.5f, 0.5f, 1.0f )), true, TEST_LOCATION ); - DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue("mixColor", Vector4(1.0f, 0.0f, 0.5f, 0.75f )), true, TEST_LOCATION ); + int gradient_type = DevelAnimatedGradientVisual::GradientType::LINEAR; + int unit_type = DevelAnimatedGradientVisual::UnitType::USER_SPACE; + int spread_type = DevelAnimatedGradientVisual::SpreadType::REPEAT; - application.Render(2000u); // halfway point between blue and white + auto buildAnimatedMap = [&animationMap, &_direction, &_duration, &_delay, &_loop_count, &_repeat_delay, &_motion, &_easing, &test_case](const Property::Value &start, const Property::Value &target, int tc_offset)->Property::Map& + { + int tc = (test_case + tc_offset); + int idx_easing = tc % 4; tc /= 4; + int idx_motion = tc % 2; tc /= 2; + int idx_loop_count = tc % 3; tc /= 3; + int idx_direction = tc % 2; tc /= 2; + int idx_delay = tc % 4; tc /= 4; + + float duration = _duration - _repeat_delay; + float repeat_delay = _repeat_delay; + float delay = _delay[idx_delay] * _duration; + int direction = _direction[idx_direction]; + int loop_count = _loop_count[idx_loop_count]; + int motion = _motion[idx_motion]; + int easing = _easing[idx_easing]; + + animationMap.Clear(); + animationMap.Insert( DevelAnimatedGradientVisual::AnimationParameter::Property::START, start ); + animationMap.Insert( DevelAnimatedGradientVisual::AnimationParameter::Property::TARGET, target ); + if( direction == 0 ) + { + animationMap.Insert(DevelAnimatedGradientVisual::AnimationParameter::Property::DIRECTION, DevelAnimatedGradientVisual::AnimationParameter::DirectionType::FORWARD); + } + else + { + animationMap.Insert(DevelAnimatedGradientVisual::AnimationParameter::Property::DIRECTION, DevelAnimatedGradientVisual::AnimationParameter::DirectionType::BACKWARD); + } + animationMap.Insert(DevelAnimatedGradientVisual::AnimationParameter::Property::DURATION, duration); + animationMap.Insert(DevelAnimatedGradientVisual::AnimationParameter::Property::DELAY, delay); + animationMap.Insert(DevelAnimatedGradientVisual::AnimationParameter::Property::REPEAT, loop_count); + animationMap.Insert(DevelAnimatedGradientVisual::AnimationParameter::Property::REPEAT_DELAY, repeat_delay); + if( motion == 0 ) + { + animationMap.Insert(DevelAnimatedGradientVisual::AnimationParameter::Property::MOTION_TYPE, DevelAnimatedGradientVisual::AnimationParameter::MotionType::LOOP); + } + else + { + animationMap.Insert(DevelAnimatedGradientVisual::AnimationParameter::Property::MOTION_TYPE, DevelAnimatedGradientVisual::AnimationParameter::MotionType::MIRROR); + } + if( easing == 0 ) + { + animationMap.Insert(DevelAnimatedGradientVisual::AnimationParameter::Property::EASING_TYPE, DevelAnimatedGradientVisual::AnimationParameter::EasingType::LINEAR); + } + else if( easing == 1 ) + { + animationMap.Insert(DevelAnimatedGradientVisual::AnimationParameter::Property::EASING_TYPE, DevelAnimatedGradientVisual::AnimationParameter::EasingType::IN); + } + else if( easing == 2 ) + { + animationMap.Insert(DevelAnimatedGradientVisual::AnimationParameter::Property::EASING_TYPE, DevelAnimatedGradientVisual::AnimationParameter::EasingType::OUT); + } + else + { + animationMap.Insert(DevelAnimatedGradientVisual::AnimationParameter::Property::EASING_TYPE, DevelAnimatedGradientVisual::AnimationParameter::EasingType::IN_OUT); + } - DALI_TEST_EQUALS( actor.GetCurrentColor(), Color::WHITE, TEST_LOCATION ); - DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue("uColor", Color::WHITE ), true, TEST_LOCATION ); - DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue("mixColor", TARGET_MIX_COLOR), true, TEST_LOCATION ); + return animationMap; + }; + + // Give different values for debuging + noise_maker += 1.0f; + Vector2 start1(-0.5f + noise_maker * 0.1f, 0.5f + noise_maker * 0.1f); + Vector2 end1 (0.5f + noise_maker * 0.1f, -0.5f + noise_maker * 0.1f); + Vector4 start_color1(1.0f, 0.7f, 0.5f, 1.0f); + Vector4 end_color1 (0.7f, 0.5f, 1.0f, 1.0f); + Vector2 rotate_center1(0.0f + noise_maker * 0.1f, 0.4f + noise_maker * 0.1f); + float rotate_amount1 = 0.0f + noise_maker * 0.1f; + float offset1 = 0.f + noise_maker * 0.1f; + + Vector2 start2(0.2f + noise_maker * 0.1f, -0.7f + noise_maker * 0.1f); + Vector2 end2 (0.5f + noise_maker * 0.1f, 0.5f + noise_maker * 0.1f); + Vector4 start_color2(0.0f, 0.1f, 0.8f, 1.0f); + Vector4 end_color2 (0.3f, 1.0f, 0.1f, 0.0f); + Vector2 rotate_center2(0.0f + noise_maker * 0.1f, -0.4f + noise_maker * 0.1f); + float rotate_amount2 = 7.0f + noise_maker * 0.1f; + float offset2 = 2.f + noise_maker * 0.1f; + + propertyMap.Insert(DevelAnimatedGradientVisual::Property::GRADIENT_TYPE, gradient_type); + propertyMap.Insert(DevelAnimatedGradientVisual::Property::UNIT_TYPE, unit_type); + propertyMap.Insert(DevelAnimatedGradientVisual::Property::SPREAD_TYPE, spread_type); + + propertyMap.Insert(DevelAnimatedGradientVisual::Property::START_POSITION, buildAnimatedMap(start1 , start2 ,0)); + propertyMap.Insert(DevelAnimatedGradientVisual::Property::END_POSITION, buildAnimatedMap(end1 , end2 ,1)); + propertyMap.Insert(DevelAnimatedGradientVisual::Property::START_COLOR, buildAnimatedMap(start_color1 , start_color2 ,2)); + propertyMap.Insert(DevelAnimatedGradientVisual::Property::END_COLOR, buildAnimatedMap(end_color1 , end_color2 ,3)); + propertyMap.Insert(DevelAnimatedGradientVisual::Property::ROTATE_CENTER, buildAnimatedMap(rotate_center1, rotate_center2,4)); + propertyMap.Insert(DevelAnimatedGradientVisual::Property::ROTATE_AMOUNT, buildAnimatedMap(rotate_amount1, rotate_amount2,5)); + propertyMap.Insert(DevelAnimatedGradientVisual::Property::OFFSET, buildAnimatedMap(offset1 , offset2 ,6)); + + Visual::Base visual = factory.CreateVisual( propertyMap ); + + DummyControl actor = DummyControl::New( true ); + Impl::DummyControl& dummyImpl = static_cast( actor.GetImplementation() ); + dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual ); + actor.SetSize( 2000, 2000 ); + actor.SetParentOrigin(ParentOrigin::CENTER); + actor.SetColor(Color::BLACK); + Stage::GetCurrent().Add(actor); + + application.SendNotification(); + application.Render( 0 ); + application.SendNotification(); + + DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION); + + application.SendNotification(); + + //Compare between CPU calculated value and Shader Visual calculated value + auto testProperty = [&application, &_direction, &_duration, &_delay, &_loop_count, &_repeat_delay, &_motion, &_easing, &test_case](const char* name, const Property::Value& start, const Property::Value& target, int tc_offset, int value_type, float progress)->void + { + int tc = (test_case + tc_offset); + int idx_easing = tc % 4; tc /= 4; + int idx_motion = tc % 2; tc /= 2; + int idx_loop_count = tc % 3; tc /= 3; + int idx_direction = tc % 2; tc /= 2; + int idx_delay = tc % 4; tc /= 4; + + float duration = _duration - _repeat_delay; + float repeat_delay = _repeat_delay; + float delay = _delay[idx_delay] * _duration; + int direction = _direction[idx_direction]; + int loop_count = _loop_count[idx_loop_count]; + int motion = _motion[idx_motion]; + int easing = _easing[idx_easing]; + + progress -= delay / _duration; + + Property::Value s = start; + Property::Value t = target; + if( direction == 1 ) + { + s = target; + t = start; + } + float x; ///< Animator progress value + if( loop_count == 0 ) + { + x = 1.0f; + } + else if( loop_count > 0 && progress + 0.01f > loop_count ) + { + x = ( motion == 0 ) ? 1.0f : 0.0f; + } + else + { + if( progress < 0.0f ) + { + progress = 0.0f; + } + progress = fmodf( progress, 1.0f ); + progress = Dali::Clamp( (progress * (duration + repeat_delay) - repeat_delay) / duration, 0.0f, 1.0f ); + + x = progress; + if( motion == 1 ) + { + x = progress * 2.0f; + if( x > 1.0f ) + { + x = 2.0f - x; + } + } + + if( easing == 1 ) // EASE_IN + { + x = x*x; + } + else if( easing == 2 ) // EASE_OUT + { + x = 2.0f*x - x*x; + } + else if( easing == 3 ) // EASE_IN_OUT + { + x = x * x * (3.0f - 2.0f * x); + } + } + if( value_type == 0 ) // result type is Float + { + float res; + float cur; + res = s.Get() * (1.0f - x) + t.Get() * (x); + DALI_TEST_EQUALS( application.GetGlAbstraction().GetUniformValue(name, cur), true, TEST_LOCATION ); + DALI_TEST_EQUALS( res, cur, Math::MACHINE_EPSILON_100, TEST_LOCATION ); + } + else if( value_type == 1 ) // result type is Vector2 + { + Vector2 res; + Vector2 cur; + res = s.Get() * (1.0f - x) + t.Get() * (x); + DALI_TEST_EQUALS( application.GetGlAbstraction().GetUniformValue(name, cur), true, TEST_LOCATION ); + DALI_TEST_EQUALS( res, cur, Math::MACHINE_EPSILON_100, TEST_LOCATION ); + } + else if( value_type == 2 ) // result type is Vector3 + { + Vector3 res; + Vector3 cur; + res = s.Get() * (1.0f - x) + t.Get() * (x); + DALI_TEST_EQUALS( application.GetGlAbstraction().GetUniformValue(name, cur), true, TEST_LOCATION ); + DALI_TEST_EQUALS( res, cur, Math::MACHINE_EPSILON_100, TEST_LOCATION ); + } + else // result type is Vector4 + { + Vector4 res; + Vector4 cur; + res = s.Get() * (1.0f - x) + t.Get() * (x); + DALI_TEST_EQUALS( application.GetGlAbstraction().GetUniformValue(name, cur), true, TEST_LOCATION ); + DALI_TEST_EQUALS( res, cur, Math::MACHINE_EPSILON_100, TEST_LOCATION ); + } + }; - TestMixColor( visual, DevelVisual::Property::MIX_COLOR, TARGET_MIX_COLOR ); + float step = 0.0f; + for( int iter = 0; iter < 2; iter++ ) // test 2*duration seconds + { + for( int step_iter = 0; step_iter < 3; step_iter++ ) + { + application.SendNotification(); + application.Render( _duration * 250.f ); // step i/4 + application.SendNotification(); + step += 0.25f; + + testProperty( "start_point" , Property::Value( start1 ) , Property::Value( start2 ) , 0, 1, step ); + testProperty( "end_point" , Property::Value( end1 ) , Property::Value( end2 ) , 1, 1, step ); + testProperty( "start_color" , Property::Value( start_color1 ) , Property::Value( start_color2 ) , 2, 3, step ); + testProperty( "end_color" , Property::Value( end_color1 ) , Property::Value( end_color2 ) , 3, 3, step ); + testProperty( "rotate_center" , Property::Value( rotate_center1 ), Property::Value( rotate_center2 ), 4, 1, step ); + testProperty( "rotate_angle" , Property::Value( rotate_amount1 ), Property::Value( rotate_amount2 ), 5, 0, step ); + testProperty( "gradient_offset", Property::Value( offset1 ) , Property::Value( offset2 ) , 6, 0, step ); + } + application.SendNotification(); + application.Render(_duration * 250.f); // step 4/4 will not test + application.SendNotification(); + step += 0.25f; + } - blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE ); - DALI_TEST_EQUALS( blendModeValue.Get(), (int)BlendMode::ON, TEST_LOCATION ); + application.SendNotification(); + actor.Unparent(); + application.SendNotification(); + application.Render(10.f); // tempral time + application.SendNotification(); + } + } END_TEST; } -int UtcDaliVisualAnimateImageVisualPixelArea(void) +int UtcDaliVisualAnimatedGradientVisual03(void) { ToolkitTestApplication application; - tet_infoline( "UtcDaliAnimateImageVisual pixel area" ); - - application.GetPlatform().SetClosestImageSize( Vector2(100, 100) ); - - VisualFactory factory = VisualFactory::Get(); - Property::Map propertyMap; - propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE); - propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME ); - propertyMap.Insert("mixColor", Color::BLUE); - propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true); - Visual::Base visual = factory.CreateVisual( propertyMap ); - - DummyControl actor = DummyControl::New(true); - Impl::DummyControl& dummyImpl = static_cast(actor.GetImplementation()); - dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual ); - - actor.SetSize(2000, 2000); - actor.SetParentOrigin(ParentOrigin::CENTER); - actor.SetColor(Color::BLACK); - Stage::GetCurrent().Add(actor); - - DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION); - - Renderer renderer = actor.GetRendererAt(0); - Property::Index index = DevelHandle::GetPropertyIndex( renderer, DevelVisual::Property::MIX_COLOR ); - - tet_infoline("Test that the renderer has the mixColor property"); - DALI_TEST_CHECK( index != Property::INVALID_INDEX ); + tet_infoline( "UtcDaliAnimatedGradientVisual with full-option use string key" ); - // TransitionData only takes string keys - Property::Map map; - map["target"] = "testVisual"; - map["property"] = "pixelArea"; - map["initialValue"] = Vector4( 0,0,0,1 ); - map["targetValue"] = Vector4( 0,0,1,1 ); // Animate width from zero to full - map["animator"] = Property::Map() - .Add("alphaFunction", "LINEAR") - .Add("timePeriod", Property::Map() - .Add("delay", 0.0f) - .Add("duration", 4.0f)); - - Dali::Toolkit::TransitionData transition = TransitionData::New( map ); + { + float _delay[4] = {0.0f, -1.35f, 0.15f, -0.4f}; // fract(_delay) must NOT be 1/4, 2/4, 3/4. cause we don't know progress is 1.0f or 0.0f + int _direction[2] = {0, 1}; + int _loop_count[3] = {-1, 0, 1}; + int _motion[2] = {0, 1}; + int _easing[4] = {0, 1, 2, 3}; + + int test_case_max = 4 * 2 * 3 * 2 * 4; + int test_case = 0; + int test_case_d = 7; // 7 is the number of animated properties. + + float _duration = 0.4f; + float _repeat_delay = _duration * 0.25f; // < _duration. cause real_duration = _duration - _repeat_delay; + float noise_maker = 0.2f; + // total testing time = ceil((4*2*3*2*4) / 7) * (_duration(=0.4) * 2 + 0.01) = 22.68 seconds + for( test_case = 0; test_case < test_case_max + test_case_d; test_case += test_case_d ) + { + tet_printf( "test [%d ~ %d / %d]\n" , test_case, test_case + test_case_d - 1, test_case_max); - Animation animation = dummyImpl.CreateTransition( transition ); - animation.AnimateTo( Property(actor, Actor::Property::COLOR), Color::WHITE ); - animation.Play(); + VisualFactory factory = VisualFactory::Get(); + Property::Map propertyMap; + Property::Map animationMap; + propertyMap.Insert(Visual::Property::TYPE, DevelVisual::ANIMATED_GRADIENT); - application.SendNotification(); - application.Render(0); - application.Render(2000u); // halfway point + auto buildAnimatedMap = [&animationMap, &_direction, &_duration, &_delay, &_loop_count, &_repeat_delay, &_motion, &_easing, &test_case](const Property::Value &start, const Property::Value &target, int tc_offset)->Property::Map& + { + int tc = (test_case + tc_offset); + int idx_easing = tc % 4; tc /= 4; + int idx_motion = tc % 2; tc /= 2; + int idx_loop_count = tc % 3; tc /= 3; + int idx_direction = tc % 2; tc /= 2; + int idx_delay = tc % 4; tc /= 4; + + float duration = _duration - _repeat_delay; + float repeat_delay = _repeat_delay; + float delay = _delay[idx_delay] * _duration; + int direction = _direction[idx_direction]; + int loop_count = _loop_count[idx_loop_count]; + int motion = _motion[idx_motion]; + int easing = _easing[idx_easing]; + + animationMap.Clear(); + animationMap.Insert( "startValue", start ); + animationMap.Insert( "targetValue", target ); + if( direction == 0 ) + { + animationMap.Insert("directionType", "FORWARD"); + } + else + { + animationMap.Insert("directionType", "BACKWARD"); + } + animationMap.Insert("duration", duration); + animationMap.Insert("delay", delay); + animationMap.Insert("repeat", loop_count); + animationMap.Insert("repeatDelay", repeat_delay); + if( motion == 0 ) + { + animationMap.Insert("motionType", "LOOP"); + } + else + { + animationMap.Insert("motionType", "MIRROR"); + } + if( easing == 0 ) + { + animationMap.Insert("easingType", "LINEAR"); + } + else if( easing == 1 ) + { + animationMap.Insert("easingType", "IN"); + } + else if( easing == 2 ) + { + animationMap.Insert("easingType", "OUT"); + } + else + { + animationMap.Insert("easingType", "IN_OUT"); + } - DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue("pixelArea", Vector4(0.0f, 0.0f, 0.5f, 1.0f )), true, TEST_LOCATION ); + return animationMap; + }; + + // Give different values for debuging + noise_maker += 0.8f; + Vector2 start1(-0.5f + noise_maker * 0.1f, 0.5f + noise_maker * 0.1f); + Vector2 end1 (0.5f + noise_maker * 0.1f, -0.5f + noise_maker * 0.1f); + Vector4 start_color1(1.0f, 0.7f, 0.5f, 1.0f); + Vector4 end_color1 (0.7f, 0.5f, 1.0f, 1.0f); + Vector2 rotate_center1(0.0f + noise_maker * 0.1f, 0.4f + noise_maker * 0.1f); + float rotate_amount1 = 0.0f + noise_maker * 0.1f; + float offset1 = 0.f + noise_maker * 0.1f; + + Vector2 start2(0.2f + noise_maker * 0.1f, -0.7f + noise_maker * 0.1f); + Vector2 end2 (0.5f + noise_maker * 0.1f, 0.5f + noise_maker * 0.1f); + Vector4 start_color2(0.0f, 0.1f, 0.8f, 1.0f); + Vector4 end_color2 (0.3f, 1.0f, 0.1f, 0.0f); + Vector2 rotate_center2(0.0f + noise_maker * 0.1f, -0.4f + noise_maker * 0.1f); + float rotate_amount2 = 7.0f + noise_maker * 0.1f; + float offset2 = 2.f + noise_maker * 0.1f; + + propertyMap.Insert("gradientType", "LINEAR"); + propertyMap.Insert("unitType", "USER_SPACE"); + propertyMap.Insert("spreadType", "CLAMP"); + + propertyMap.Insert("startPosition", buildAnimatedMap(start1 , start2 ,0)); + propertyMap.Insert("endPosition", buildAnimatedMap(end1 , end2 ,1)); + propertyMap.Insert("startColor", buildAnimatedMap(start_color1 , start_color2 ,2)); + propertyMap.Insert("endColor", buildAnimatedMap(end_color1 , end_color2 ,3)); + propertyMap.Insert("rotateCenter", buildAnimatedMap(rotate_center1, rotate_center2,4)); + propertyMap.Insert("rotateAmount", buildAnimatedMap(rotate_amount1, rotate_amount2,5)); + propertyMap.Insert("offset", buildAnimatedMap(offset1 , offset2 ,6)); + + Visual::Base visual = factory.CreateVisual( propertyMap ); + + DummyControl actor = DummyControl::New( true ); + Impl::DummyControl& dummyImpl = static_cast( actor.GetImplementation() ); + dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual ); + actor.SetSize( 2000, 2000 ); + actor.SetParentOrigin(ParentOrigin::CENTER); + actor.SetColor(Color::BLACK); + Stage::GetCurrent().Add(actor); + + application.SendNotification(); + application.Render( 0 ); + application.SendNotification(); + + DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION); + + application.SendNotification(); + + //Compare between CPU calculated value and Shader Visual calculated value + auto testProperty = [&application, &_direction, &_duration, &_delay, &_loop_count, &_repeat_delay, &_motion, &_easing, &test_case](const char* name, const Property::Value& start, const Property::Value& target, int tc_offset, int value_type, float progress)->void + { + int tc = (test_case + tc_offset); + int idx_easing = tc % 4; tc /= 4; + int idx_motion = tc % 2; tc /= 2; + int idx_loop_count = tc % 3; tc /= 3; + int idx_direction = tc % 2; tc /= 2; + int idx_delay = tc % 4; tc /= 4; + + float duration = _duration - _repeat_delay; + float repeat_delay = _repeat_delay; + float delay = _delay[idx_delay] * _duration; + int direction = _direction[idx_direction]; + int loop_count = _loop_count[idx_loop_count]; + int motion = _motion[idx_motion]; + int easing = _easing[idx_easing]; + + progress -= delay / _duration; + + Property::Value s = start; + Property::Value t = target; + if( direction == 1 ) + { + s = target; + t = start; + } + float x; ///< Animator progress value + if( loop_count == 0 ) + { + x = 1.0f; + } + else if( loop_count > 0 && progress + 0.01f > loop_count ) + { + x = ( motion == 0 ) ? 1.0f : 0.0f; + } + else + { + if( progress < 0.0f ) + { + progress = 0.0f; + } + progress = fmodf( progress, 1.0f ); + progress = Dali::Clamp( (progress * (duration + repeat_delay) - repeat_delay) / duration, 0.0f, 1.0f ); + + x = progress; + if( motion == 1 ) + { + x = progress * 2.0f; + if( x > 1.0f ) + { + x = 2.0f - x; + } + } + + if( easing == 1 ) // EASE_IN + { + x = x*x; + } + else if( easing == 2 ) // EASE_OUT + { + x = 2.0f*x - x*x; + } + else if( easing == 3 ) // EASE_IN_OUT + { + x = x * x * (3.0f - 2.0f * x); + } + } + if( value_type == 0 ) // result type is Float + { + float res; + float cur; + res = s.Get() * (1.0f - x) + t.Get() * (x); + DALI_TEST_EQUALS( application.GetGlAbstraction().GetUniformValue(name, cur), true, TEST_LOCATION ); + DALI_TEST_EQUALS( res, cur, Math::MACHINE_EPSILON_100, TEST_LOCATION ); + } + else if( value_type == 1 ) // result type is Vector2 + { + Vector2 res; + Vector2 cur; + res = s.Get() * (1.0f - x) + t.Get() * (x); + DALI_TEST_EQUALS( application.GetGlAbstraction().GetUniformValue(name, cur), true, TEST_LOCATION ); + DALI_TEST_EQUALS( res, cur, Math::MACHINE_EPSILON_100, TEST_LOCATION ); + } + else if( value_type == 2 ) // result type is Vector3 + { + Vector3 res; + Vector3 cur; + res = s.Get() * (1.0f - x) + t.Get() * (x); + DALI_TEST_EQUALS( application.GetGlAbstraction().GetUniformValue(name, cur), true, TEST_LOCATION ); + DALI_TEST_EQUALS( res, cur, Math::MACHINE_EPSILON_100, TEST_LOCATION ); + } + else // result type is Vector4 + { + Vector4 res; + Vector4 cur; + res = s.Get() * (1.0f - x) + t.Get() * (x); + DALI_TEST_EQUALS( application.GetGlAbstraction().GetUniformValue(name, cur), true, TEST_LOCATION ); + DALI_TEST_EQUALS( res, cur, Math::MACHINE_EPSILON_100, TEST_LOCATION ); + } + }; - application.Render(2000u); + float step = 0.0f; + for( int iter = 0; iter < 2; iter++ ) // test 2*duration seconds + { + for( int step_iter = 0; step_iter < 3; step_iter++ ) + { + application.SendNotification(); + application.Render( _duration * 250.f ); // step i/4 + application.SendNotification(); + step += 0.25f; + + testProperty( "start_point" , Property::Value( start1 ) , Property::Value( start2 ) , 0, 1, step ); + testProperty( "end_point" , Property::Value( end1 ) , Property::Value( end2 ) , 1, 1, step ); + testProperty( "start_color" , Property::Value( start_color1 ) , Property::Value( start_color2 ) , 2, 3, step ); + testProperty( "end_color" , Property::Value( end_color1 ) , Property::Value( end_color2 ) , 3, 3, step ); + testProperty( "rotate_center" , Property::Value( rotate_center1 ), Property::Value( rotate_center2 ), 4, 1, step ); + testProperty( "rotate_angle" , Property::Value( rotate_amount1 ), Property::Value( rotate_amount2 ), 5, 0, step ); + testProperty( "gradient_offset", Property::Value( offset1 ) , Property::Value( offset2 ) , 6, 0, step ); + } + application.SendNotification(); + application.Render(_duration * 250.f); // step 4/4 will not test + application.SendNotification(); + step += 0.25f; + } - DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue("pixelArea", Vector4( 0.0f, 0.0f, 1.0f, 1.0f )), true, TEST_LOCATION ); + application.SendNotification(); + actor.Unparent(); + application.SendNotification(); + application.Render(10.f); // tempral time + application.SendNotification(); + } + } END_TEST; } - int UtcDaliVisualWireframeVisual(void) { ToolkitTestApplication application; VisualFactory factory = VisualFactory::Get(); Property::Map propertyMap; - propertyMap.Insert( Visual::Property::TYPE, Visual::WIREFRAME ); + propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::WIREFRAME ); // Create the visual. Visual::Base visual = factory.CreateVisual( propertyMap ); @@ -1540,7 +2651,7 @@ int UtcDaliVisualWireframeVisual(void) visual.CreatePropertyMap( resultMap ); // Check the property values from the returned map from visual - Property::Value* value = resultMap.Find( Visual::Property::TYPE, Property::INTEGER ); + Property::Value* value = resultMap.Find( Toolkit::Visual::Property::TYPE, Property::INTEGER ); DALI_TEST_CHECK( value ); DALI_TEST_CHECK( value->Get() == Visual::WIREFRAME ); @@ -1560,35 +2671,40 @@ int UtcDaliVisualGetTransform(void) Dali::Property::Map visualMap; colorVisual.CreatePropertyMap( visualMap ); - Property::Value* value = visualMap.Find( Dali::Toolkit::DevelVisual::Property::TRANSFORM ); + Property::Value* value = visualMap.Find( Dali::Toolkit::Visual::Property::TRANSFORM ); Dali::Property::Map* map = value->GetMap(); DALI_TEST_CHECK( map ); //Test default values { - Property::Value* typeValue = map->Find( Toolkit::DevelVisual::Transform::Property::OFFSET ); + Property::Value* typeValue = map->Find( Toolkit::Visual::Transform::Property::OFFSET ); DALI_TEST_CHECK( typeValue ); DALI_TEST_CHECK( typeValue->Get() == Vector2(0.0f,0.0f) ); } { - Property::Value* typeValue = map->Find( Toolkit::DevelVisual::Transform::Property::SIZE ); + Property::Value* typeValue = map->Find( Toolkit::Visual::Transform::Property::SIZE ); DALI_TEST_CHECK( typeValue ); DALI_TEST_CHECK( typeValue->Get() == Vector2(1.0f,1.0f) ); } { - Property::Value* typeValue = map->Find( Toolkit::DevelVisual::Transform::Property::OFFSET_SIZE_MODE ); + Property::Value* typeValue = map->Find( Toolkit::Visual::Transform::Property::OFFSET_POLICY ); + DALI_TEST_CHECK( typeValue ); + DALI_TEST_CHECK( typeValue->Get< Vector2 >() == Vector2( Toolkit::Visual::Transform::Policy::RELATIVE, Toolkit::Visual::Transform::Policy::RELATIVE ) ); + } + { + Property::Value* typeValue = map->Find( Toolkit::Visual::Transform::Property::SIZE_POLICY ); DALI_TEST_CHECK( typeValue ); - DALI_TEST_CHECK( typeValue->Get() == Vector4(0.0f,0.0f,0.0f,0.0f) ); + DALI_TEST_CHECK( typeValue->Get< Vector2 >() == Vector2( Toolkit::Visual::Transform::Policy::RELATIVE, Toolkit::Visual::Transform::Policy::RELATIVE ) ); } { - Property::Value* typeValue = map->Find( Toolkit::DevelVisual::Transform::Property::ORIGIN ); + Property::Value* typeValue = map->Find( Toolkit::Visual::Transform::Property::ORIGIN ); DALI_TEST_CHECK( typeValue ); - DALI_TEST_CHECK( (Toolkit::Align::Type)typeValue->Get() == Toolkit::Align::CENTER ); + DALI_TEST_CHECK( (Toolkit::Align::Type)typeValue->Get() == Toolkit::Align::TOP_BEGIN ); } { - Property::Value* typeValue = map->Find( Toolkit::DevelVisual::Transform::Property::ANCHOR_POINT ); + Property::Value* typeValue = map->Find( Toolkit::Visual::Transform::Property::ANCHOR_POINT ); DALI_TEST_CHECK( typeValue ); - DALI_TEST_CHECK( (Toolkit::Align::Type)typeValue->Get() == Toolkit::Align::CENTER ); + DALI_TEST_CHECK( (Toolkit::Align::Type)typeValue->Get() == Toolkit::Align::TOP_BEGIN ); } END_TEST; @@ -1597,42 +2713,47 @@ int UtcDaliVisualGetTransform(void) static void TestTransform( ToolkitTestApplication& application, Visual::Base visual ) { Property::Map transform; - transform.Insert( DevelVisual::Transform::Property::OFFSET, Vector2(10.0f, 10.0f) ); - transform.Insert( DevelVisual::Transform::Property::SIZE, Vector2(0.2f, 0.2f) ); - transform.Insert( DevelVisual::Transform::Property::OFFSET_SIZE_MODE, Vector4(1.0f, 1.0f, 0.0f,0.0f) ); - transform.Insert( DevelVisual::Transform::Property::ORIGIN, "TOP_BEGIN" ); - transform.Insert( DevelVisual::Transform::Property::ANCHOR_POINT, Toolkit::Align::BOTTOM_END ); + transform.Insert( Visual::Transform::Property::OFFSET, Vector2(10.0f, 10.0f) ); + transform.Insert( Visual::Transform::Property::SIZE, Vector2(0.2f, 0.2f) ); + transform.Insert( Visual::Transform::Property::OFFSET_POLICY, Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ) ); + transform.Insert( Visual::Transform::Property::ORIGIN, "CENTER" ); + transform.Insert( Visual::Transform::Property::ANCHOR_POINT, Toolkit::Align::BOTTOM_END ); visual.SetTransformAndSize( transform, Vector2(100, 100) ); Dali::Property::Map visualMap; visual.CreatePropertyMap( visualMap ); - Property::Value* value = visualMap.Find( Dali::Toolkit::DevelVisual::Property::TRANSFORM ); + Property::Value* value = visualMap.Find( Dali::Toolkit::Visual::Property::TRANSFORM ); Dali::Property::Map* map = value->GetMap(); DALI_TEST_CHECK( map ); { - Property::Value* typeValue = map->Find( Toolkit::DevelVisual::Transform::Property::OFFSET ); + Property::Value* typeValue = map->Find( Toolkit::Visual::Transform::Property::OFFSET ); DALI_TEST_CHECK( typeValue ); DALI_TEST_EQUALS( typeValue->Get(),Vector2(10.0f,10.0f), TEST_LOCATION ); } { - Property::Value* typeValue = map->Find( Toolkit::DevelVisual::Transform::Property::SIZE ); + Property::Value* typeValue = map->Find( Toolkit::Visual::Transform::Property::SIZE ); DALI_TEST_CHECK( typeValue ); DALI_TEST_EQUALS( typeValue->Get(), Vector2(0.2f,0.2f), TEST_LOCATION ); } { - Property::Value* typeValue = map->Find( Toolkit::DevelVisual::Transform::Property::OFFSET_SIZE_MODE ); + Property::Value* typeValue = map->Find( Toolkit::Visual::Transform::Property::OFFSET_POLICY ); + DALI_TEST_CHECK( typeValue ); + DALI_TEST_EQUALS( typeValue->Get< Vector2 >(), Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ), TEST_LOCATION ); + } + { + Property::Value* typeValue = map->Find( Toolkit::Visual::Transform::Property::SIZE_POLICY ); DALI_TEST_CHECK( typeValue ); - DALI_TEST_EQUALS( typeValue->Get(), Vector4(1.0f,1.0f,0.0f,0.0f), TEST_LOCATION ); + DALI_TEST_EQUALS( typeValue->Get< Vector2 >(), Vector2( Toolkit::Visual::Transform::Policy::RELATIVE, Toolkit::Visual::Transform::Policy::RELATIVE ), TEST_LOCATION ); } { - Property::Value* typeValue = map->Find( Toolkit::DevelVisual::Transform::Property::ORIGIN ); + Property::Value* typeValue = map->Find( Toolkit::Visual::Transform::Property::ORIGIN ); DALI_TEST_CHECK( typeValue ); - DALI_TEST_EQUALS( (Toolkit::Align::Type)typeValue->Get(), Toolkit::Align::TOP_BEGIN, TEST_LOCATION ); + DALI_TEST_EQUALS( (Toolkit::Align::Type)typeValue->Get(), Toolkit::Align::CENTER, TEST_LOCATION ); } { - Property::Value* typeValue = map->Find( Toolkit::DevelVisual::Transform::Property::ANCHOR_POINT ); + Property::Value* typeValue = map->Find( Toolkit::Visual::Transform::Property::ANCHOR_POINT ); DALI_TEST_CHECK( typeValue ); DALI_TEST_EQUALS( (Toolkit::Align::Type)typeValue->Get(), Toolkit::Align::BOTTOM_END, TEST_LOCATION ); } @@ -1670,7 +2791,7 @@ static void TestTransform( ToolkitTestApplication& application, Visual::Base vis index = renderer.GetPropertyIndex( "origin" ); DALI_TEST_CHECK( index != Property::INVALID_INDEX ); Vector2 parentOrigin = renderer.GetProperty( index ); - DALI_TEST_EQUALS( parentOrigin, Vector2(-0.5f,-0.5f), TEST_LOCATION ); + DALI_TEST_EQUALS( parentOrigin, Vector2(0.0f,0.0f), TEST_LOCATION ); index = renderer.GetPropertyIndex( "anchorPoint" ); DALI_TEST_CHECK( index != Property::INVALID_INDEX ); @@ -1679,9 +2800,10 @@ static void TestTransform( ToolkitTestApplication& application, Visual::Base vis //Set a new transform transform.Clear(); - transform.Insert( DevelVisual::Transform::Property::OFFSET, Vector2(20.0f, 20.0f) ); - transform.Insert( DevelVisual::Transform::Property::SIZE, Vector2(100.0f, 100.0f) ); - transform.Insert( DevelVisual::Transform::Property::OFFSET_SIZE_MODE, Vector4(0.0f, 0.0f, 1.0f,1.0f) ); + transform = DefaultTransform(); + transform.Insert( Visual::Transform::Property::OFFSET, Vector2(20.0f, 20.0f) ); + transform.Insert( Visual::Transform::Property::SIZE, Vector2(100.0f, 100.0f) ); + transform.Insert( Visual::Transform::Property::SIZE_POLICY, Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ) ); visual.SetTransformAndSize( transform, Vector2(100, 100) ); application.SendNotification(); application.Render(0); @@ -1696,12 +2818,12 @@ static void TestTransform( ToolkitTestApplication& application, Visual::Base vis offsetSizeMode = renderer.GetProperty( renderer.GetPropertyIndex( "offsetSizeMode" ) ); DALI_TEST_EQUALS( offsetSizeMode, Vector4(0.0f,0.0f,1.0f,1.0f), TEST_LOCATION ); - //Parent origin and anchor point should have default values + //Parent origin and anchor point should have the default values parentOrigin = renderer.GetProperty( renderer.GetPropertyIndex( "origin" ) ); - DALI_TEST_EQUALS( parentOrigin, Vector2(0.0f,0.0f), TEST_LOCATION ); + DALI_TEST_EQUALS( parentOrigin, Vector2(-0.5f,-0.5f), TEST_LOCATION ); anchorPoint = renderer.GetProperty( renderer.GetPropertyIndex( "anchorPoint" ) ); - DALI_TEST_EQUALS( anchorPoint, Vector2(0.0f,0.0f), TEST_LOCATION ); + DALI_TEST_EQUALS( anchorPoint, Vector2(0.5f,0.5f), TEST_LOCATION ); } int UtcDaliVisualSetTransform0(void) @@ -1727,7 +2849,7 @@ int UtcDaliVisualSetTransform1(void) VisualFactory factory = VisualFactory::Get(); Property::Map propertyMap; - propertyMap[ Visual::Property::TYPE ] = Visual::PRIMITIVE; + propertyMap[ Toolkit::Visual::Property::TYPE ] = Visual::PRIMITIVE; propertyMap[ PrimitiveVisual::Property::MIX_COLOR ] = Color::WHITE; propertyMap[ PrimitiveVisual::Property::SHAPE ] = PrimitiveVisual::Shape::SPHERE; propertyMap[ PrimitiveVisual::Property::SLICES ] = 10; @@ -1746,8 +2868,8 @@ int UtcDaliVisualSetTransform2(void) VisualFactory factory = VisualFactory::Get(); Property::Map propertyMap; - propertyMap.Insert( Visual::Property::TYPE, Visual::GRADIENT ); - propertyMap.Insert( DevelVisual::Property::MIX_COLOR, Color::GREEN ); + propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::GRADIENT ); + propertyMap.Insert( Visual::Property::MIX_COLOR, Color::GREEN ); Property::Array stopOffsets; stopOffsets.PushBack( 0.0f ); @@ -1768,7 +2890,7 @@ int UtcDaliVisualSetTransform2(void) propertyMap.Insert( GradientVisual::Property::RADIUS, 1.414f ); Visual::Base visual = factory.CreateVisual( propertyMap ); TestTransform( application, visual ); - TestMixColor( visual, DevelVisual::Property::MIX_COLOR, Color::GREEN ); + TestMixColor( visual, Visual::Property::MIX_COLOR, Color::GREEN ); END_TEST; } @@ -1780,13 +2902,13 @@ int UtcDaliVisualSetTransform3(void) VisualFactory factory = VisualFactory::Get(); Property::Map propertyMap; - propertyMap.Insert( Visual::Property::TYPE, Visual::BORDER ); - propertyMap.Insert( DevelVisual::Property::MIX_COLOR, Color::MAGENTA ); + propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::BORDER ); + propertyMap.Insert( Visual::Property::MIX_COLOR, Color::MAGENTA ); propertyMap.Insert( BorderVisual::Property::COLOR, Vector4(0.f, 1.f, 0.f, 0.6f) ); propertyMap.Insert( BorderVisual::Property::SIZE, 3.0f ); Visual::Base visual = factory.CreateVisual( propertyMap ); TestTransform( application, visual ); - TestMixColor( visual, DevelVisual::Property::MIX_COLOR, Color::MAGENTA ); + TestMixColor( visual, Visual::Property::MIX_COLOR, Color::MAGENTA ); END_TEST; } @@ -1798,8 +2920,8 @@ int UtcDaliVisualSetTransform4(void) VisualFactory factory = VisualFactory::Get(); Property::Map propertyMap; - propertyMap.Insert( Visual::Property::TYPE, Visual::MESH ); - propertyMap.Insert( DevelVisual::Property::MIX_COLOR, Color::CYAN ); + propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::MESH ); + propertyMap.Insert( Visual::Property::MIX_COLOR, Color::CYAN ); propertyMap.Insert( "objectUrl", TEST_OBJ_FILE_NAME ); propertyMap.Insert( "materialUrl", TEST_MTL_FILE_NAME ); @@ -1808,7 +2930,7 @@ int UtcDaliVisualSetTransform4(void) propertyMap.Insert( "lightPosition", Vector3( 5.0f, 10.0f, 15.0f) ); Visual::Base visual = factory.CreateVisual( propertyMap ); TestTransform( application, visual ); - TestMixColor( visual, DevelVisual::Property::MIX_COLOR, Color::CYAN ); + TestMixColor( visual, Visual::Property::MIX_COLOR, Color::CYAN ); END_TEST; } @@ -1822,7 +2944,7 @@ int UtcDaliVisualSetTransform5(void) Image image = ResourceImage::New(TEST_IMAGE_FILE_NAME, ImageDimensions(100, 200)); Visual::Base visual = factory.CreateVisual(image); TestTransform( application, visual ); - TestMixColor( visual, DevelVisual::Property::MIX_COLOR, Color::WHITE ); + TestMixColor( visual, Visual::Property::MIX_COLOR, Color::WHITE ); END_TEST; } @@ -1835,7 +2957,7 @@ int UtcDaliVisualSetTransform6(void) VisualFactory factory = VisualFactory::Get(); Property::Map propertyMap; propertyMap[Toolkit::Visual::Property::TYPE] = Toolkit::Visual::IMAGE; - propertyMap[DevelVisual::Property::MIX_COLOR] = Color::YELLOW; + propertyMap[Visual::Property::MIX_COLOR] = Color::YELLOW; propertyMap[Toolkit::ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME; propertyMap[Toolkit::ImageVisual::Property::DESIRED_WIDTH] = 100.0f; propertyMap[Toolkit::ImageVisual::Property::DESIRED_HEIGHT] = 100.0f; @@ -1844,7 +2966,7 @@ int UtcDaliVisualSetTransform6(void) propertyMap[Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING] = true; Visual::Base visual = factory.CreateVisual(propertyMap); TestTransform( application, visual ); - TestMixColor( visual, DevelVisual::Property::MIX_COLOR, Color::YELLOW ); + TestMixColor( visual, Visual::Property::MIX_COLOR, Color::YELLOW ); END_TEST; } @@ -1858,7 +2980,45 @@ int UtcDaliVisualSetTransform7(void) Image image = ResourceImage::New(TEST_NPATCH_FILE_NAME, ImageDimensions(100, 200)); Visual::Base visual = factory.CreateVisual(image); TestTransform( application, visual ); - TestMixColor( visual, DevelVisual::Property::MIX_COLOR, Color::WHITE ); + TestMixColor( visual, Visual::Property::MIX_COLOR, Color::WHITE ); + + END_TEST; +} + +int UtcDaliVisualTestTransformPoliciesAsStrings(void) +{ + ToolkitTestApplication application; + tet_infoline( "UtcDaliVisualTestTransformPoliciesAsStrings: Use a ColorVisual and test the offset and size policies as strings" ); + + VisualFactory factory = VisualFactory::Get(); + Property::Map propertyMap; + propertyMap.Insert(Visual::Property::TYPE, Visual::COLOR); + propertyMap.Insert(ColorVisual::Property::MIX_COLOR, Color::BLUE); + Visual::Base visual = factory.CreateVisual( propertyMap ); + + Property::Map transform; + transform[ "offsetPolicy" ] = Property::Array().Add( "ABSOLUTE" ) + .Add( "RELATIVE" ); + transform[ "sizePolicy" ] = Property::Array().Add( "RELATIVE" ) + .Add( "ABSOLUTE" ); + visual.SetTransformAndSize( transform, Vector2(100, 100) ); + + Dali::Property::Map visualMap; + visual.CreatePropertyMap( visualMap ); + Property::Value* value = visualMap.Find( Dali::Toolkit::Visual::Property::TRANSFORM ); + Dali::Property::Map* map = value->GetMap(); + DALI_TEST_CHECK( map ); + + { + Property::Value* typeValue = map->Find( Toolkit::Visual::Transform::Property::OFFSET_POLICY ); + DALI_TEST_CHECK( typeValue ); + DALI_TEST_EQUALS( typeValue->Get< Vector2 >(), Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::RELATIVE ), TEST_LOCATION ); + } + { + Property::Value* typeValue = map->Find( Toolkit::Visual::Transform::Property::SIZE_POLICY ); + DALI_TEST_CHECK( typeValue ); + DALI_TEST_EQUALS( typeValue->Get< Vector2 >(), Vector2( Toolkit::Visual::Transform::Policy::RELATIVE, Toolkit::Visual::Transform::Policy::ABSOLUTE ), TEST_LOCATION ); + } END_TEST; } @@ -1871,24 +3031,26 @@ int UtcDaliNPatchVisualCustomShader(void) VisualFactory factory = VisualFactory::Get(); Property::Map properties; Property::Map shader; + const std::string vertexShader = "Foobar"; const std::string fragmentShader = "Foobar"; shader[Dali::Toolkit::Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader; + shader[Dali::Toolkit::Visual::Shader::Property::VERTEX_SHADER] = vertexShader; Property::Map transformMap; transformMap["size"] = Vector2( 0.5f, 0.5f ) ; transformMap["offset"] = Vector2( 20.0f, 0.0f ) ; - transformMap["offsetSizeMode"] = Vector4( 1.0f, 1.0f, 0.0f, 0.0f ); + transformMap["offsetPolicy"] = Vector2( Visual::Transform::Policy::ABSOLUTE, Visual::Transform::Policy::ABSOLUTE ); transformMap["anchorPoint"] = Align::CENTER; transformMap["origin"] = Align::CENTER; - properties[DevelVisual::Property::TRANSFORM] = transformMap; + properties[Visual::Property::TRANSFORM] = transformMap; properties[Visual::Property::TYPE] = Visual::IMAGE; - properties[DevelVisual::Property::MIX_COLOR] = Color::BLUE; + properties[Visual::Property::MIX_COLOR] = Color::BLUE; properties[Visual::Property::SHADER]=shader; properties[ImageVisual::Property::URL] = TEST_NPATCH_FILE_NAME; Visual::Base visual = factory.CreateVisual( properties ); - TestMixColor( visual, DevelVisual::Property::MIX_COLOR, Color::BLUE ); + TestMixColor( visual, Visual::Property::MIX_COLOR, Color::BLUE ); // trigger creation through setting on stage DummyControl dummy = DummyControl::New(true); @@ -1910,10 +3072,11 @@ int UtcDaliNPatchVisualCustomShader(void) DALI_TEST_EQUALS( renderer.GetProperty( index ), Property::Value(Vector2(0.5, 0.5)), 0.001, TEST_LOCATION ); Property::Value* fragment = map->Find( "fragment" ); // fragment key name from shader-impl.cpp - // *map["vertex"]; is default here so not verifying it - DALI_TEST_EQUALS( fragmentShader, fragment->Get(), TEST_LOCATION ); + Property::Value* vertex = map->Find( "vertex" ); // vertex key name from shader-impl.cpp + DALI_TEST_EQUALS( vertexShader, vertex->Get(), TEST_LOCATION ); + END_TEST; } @@ -1923,14 +3086,14 @@ int UtcDaliGradientVisualBlendMode(void) VisualFactory factory = VisualFactory::Get(); Visual::Base opaqueGradientVisual = factory.CreateVisual( - Property::Map().Add( Visual::Property::TYPE, Visual::GRADIENT ) + Property::Map().Add( Toolkit::Visual::Property::TYPE, Visual::GRADIENT ) .Add( GradientVisual::Property::START_POSITION, Vector2( -0.5f, -0.5f ) ) .Add( GradientVisual::Property::END_POSITION, Vector2( 0.5f, 0.5f ) ) .Add( GradientVisual::Property::STOP_COLOR, Property::Array().Add( Color::RED ) .Add( Color::GREEN ) ) ); Visual::Base alphaGradientVisual = factory.CreateVisual( - Property::Map().Add( Visual::Property::TYPE, Visual::GRADIENT ) + Property::Map().Add( Toolkit::Visual::Property::TYPE, Visual::GRADIENT ) .Add( GradientVisual::Property::START_POSITION, Vector2( -0.5f, -0.5f ) ) .Add( GradientVisual::Property::END_POSITION, Vector2( 0.5f, 0.5f ) ) .Add( GradientVisual::Property::STOP_COLOR, Property::Array().Add( Color::RED ) @@ -1966,7 +3129,7 @@ int UtcDaliVisualRendererRemovalAndReAddition(void) propertyMap.Insert(ColorVisual::Property::MIX_COLOR, Color::BLUE); Visual::Base visual = factory.CreateVisual( propertyMap ); - visual.SetDepthIndex( 1.f ); + visual.SetDepthIndex( 1 ); DummyControl dummyControl = DummyControl::New(true); Impl::DummyControl& dummyImpl = static_cast(dummyControl.GetImplementation()); @@ -2011,7 +3174,7 @@ int UtcDaliVisualTextVisualRender(void) VisualFactory factory = VisualFactory::Get(); Property::Map propertyMap; - propertyMap.Insert( Visual::Property::TYPE, DevelVisual::TEXT ); + propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::TEXT ); propertyMap.Insert( "mixColor", Color::WHITE ); propertyMap.Insert( "renderingBackend", static_cast( Toolkit::Text::DEFAULT_RENDERING_BACKEND ) ); propertyMap.Insert( "enableMarkup", false ); @@ -2028,7 +3191,7 @@ int UtcDaliVisualTextVisualRender(void) propertyMap.Insert( "verticalAlignment", "CENTER" ); propertyMap.Insert( "textColor", Color::RED ); Visual::Base textVisual = factory.CreateVisual( propertyMap ); - textVisual.SetDepthIndex( 1.f ); + textVisual.SetDepthIndex( 1 ); DummyControl dummyControl = DummyControl::New(true); Impl::DummyControl& dummyImpl = static_cast(dummyControl.GetImplementation()); @@ -2045,17 +3208,17 @@ int UtcDaliVisualTextVisualRender(void) // Create a texture bigger than the maximum allowed by the image atlas. Used to increase coverage. propertyMap.Clear(); - propertyMap.Insert( Visual::Property::TYPE, DevelVisual::TEXT ); + propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::TEXT ); propertyMap.Insert( TextVisual::Property::ENABLE_MARKUP, true ); propertyMap.Insert( TextVisual::Property::TEXT, "Hello world" ); propertyMap.Insert( TextVisual::Property::MULTI_LINE, true ); Property::Map transformMap; transformMap.Insert( "size", Vector2( 0.5f, 0.5f ) ); - propertyMap.Insert( DevelVisual::Property::TRANSFORM, transformMap ); + propertyMap.Insert( Visual::Property::TRANSFORM, transformMap ); textVisual = factory.CreateVisual( propertyMap ); - textVisual.SetDepthIndex( 1.f ); + textVisual.SetDepthIndex( 1 ); dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, textVisual ); dummyControl.SetSize( 720.f, 640.f ); @@ -2067,8 +3230,59 @@ int UtcDaliVisualTextVisualRender(void) Renderer renderer = dummyControl.GetRendererAt(0u); Property::Index index = renderer.GetPropertyIndex("size"); - tet_infoline( "Test that the TextVisual overrides anything set by developer" ); - DALI_TEST_EQUALS( renderer.GetProperty(index), Vector2( 1.0, 1.0 ), 0.001f, TEST_LOCATION ); + tet_infoline( "Test that the TextVisual has NOT overridden what was set by developer" ); + DALI_TEST_EQUALS( renderer.GetProperty(index), Vector2( 0.5f, 0.5f ), 0.001f, TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliVisualTextVisualDisableEnable(void) +{ + ToolkitTestApplication application; + tet_infoline( "UtcDaliVisualTextVisualDisableEnable Ensure Text visible can be re-enabled" ); + + VisualFactory factory = VisualFactory::Get(); + Property::Map propertyMap; + propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::TEXT ); + propertyMap.Insert( "mixColor", Color::WHITE ); + propertyMap.Insert( "renderingBackend", static_cast( Toolkit::Text::DEFAULT_RENDERING_BACKEND ) ); + propertyMap.Insert( "enableMarkup", false ); + propertyMap.Insert( "text", "Hello world" ); + propertyMap.Insert( "fontFamily", "TizenSans" ); + + Property::Map fontStyleMapSet; + fontStyleMapSet.Insert( "weight", "bold" ); + propertyMap.Insert( "fontStyle", fontStyleMapSet ); + + propertyMap.Insert( "pointSize", 12.f ); + propertyMap.Insert( "multiLine", true ); + propertyMap.Insert( "horizontalAlignment", "CENTER" ); + propertyMap.Insert( "verticalAlignment", "CENTER" ); + propertyMap.Insert( "textColor", Color::RED ); + Visual::Base textVisual = factory.CreateVisual( propertyMap ); + textVisual.SetDepthIndex( 1 ); + + DummyControl dummyControl = DummyControl::New(true); + Impl::DummyControl& dummyImpl = static_cast(dummyControl.GetImplementation()); + dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, textVisual ); + DALI_TEST_EQUALS( dummyControl.GetRendererCount(), 0, TEST_LOCATION ); + + dummyControl.SetSize(200.f, 200.f); + dummyControl.SetParentOrigin( ParentOrigin::CENTER ); + + Stage::GetCurrent().Add( dummyControl ); + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( dummyControl.GetRendererCount(), 1, TEST_LOCATION ); + + dummyImpl.EnableVisual( DummyControl::Property::TEST_VISUAL, false ); + + DALI_TEST_EQUALS( dummyControl.GetRendererCount(), 0, TEST_LOCATION ); + + dummyImpl.EnableVisual( DummyControl::Property::TEST_VISUAL, true ); + + DALI_TEST_EQUALS( dummyControl.GetRendererCount(), 1, TEST_LOCATION ); END_TEST; } @@ -2084,12 +3298,12 @@ int UtcDaliVisualPremultipliedAlpha(void) { Visual::Base imageVisual = factory.CreateVisual( Property::Map() - .Add( Visual::Property::TYPE, Visual::IMAGE ) + .Add( Toolkit::Visual::Property::TYPE, Visual::IMAGE ) .Add( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME ) ); Dali::Property::Map visualMap; imageVisual.CreatePropertyMap( visualMap ); - Property::Value* value = visualMap.Find( DevelVisual::Property::PREMULTIPLIED_ALPHA ); + Property::Value* value = visualMap.Find( Visual::Property::PREMULTIPLIED_ALPHA ); // test values DALI_TEST_CHECK( value ); @@ -2100,13 +3314,13 @@ int UtcDaliVisualPremultipliedAlpha(void) { Visual::Base imageVisual = factory.CreateVisual( Property::Map() - .Add( Visual::Property::TYPE, Visual::IMAGE ) + .Add( Toolkit::Visual::Property::TYPE, Visual::IMAGE ) .Add( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME ) - .Add( DevelVisual::Property::PREMULTIPLIED_ALPHA, true ) ); + .Add( Visual::Property::PREMULTIPLIED_ALPHA, true ) ); Dali::Property::Map visualMap; imageVisual.CreatePropertyMap( visualMap ); - Property::Value* value = visualMap.Find( DevelVisual::Property::PREMULTIPLIED_ALPHA ); + Property::Value* value = visualMap.Find( Visual::Property::PREMULTIPLIED_ALPHA ); // test values DALI_TEST_CHECK( value ); @@ -2117,12 +3331,12 @@ int UtcDaliVisualPremultipliedAlpha(void) { Visual::Base imageVisual = factory.CreateVisual( Property::Map() - .Add( Visual::Property::TYPE, Visual::IMAGE ) + .Add( Toolkit::Visual::Property::TYPE, Visual::IMAGE ) .Add( ImageVisual::Property::URL, TEST_SVG_FILE_NAME ) ); Dali::Property::Map visualMap; imageVisual.CreatePropertyMap( visualMap ); - Property::Value* value = visualMap.Find( DevelVisual::Property::PREMULTIPLIED_ALPHA ); + Property::Value* value = visualMap.Find( Visual::Property::PREMULTIPLIED_ALPHA ); // test values DALI_TEST_CHECK( value ); @@ -2131,3 +3345,231 @@ int UtcDaliVisualPremultipliedAlpha(void) END_TEST; } + +int UtcDaliRegisterVisualOrder(void) +{ + ToolkitTestApplication application; + tet_infoline( "Register Visual Order" ); + + DummyControl dummyControl = DummyControl::New(true); + Impl::DummyControl& dummyImpl = static_cast(dummyControl.GetImplementation()); + + VisualFactory factory = VisualFactory::Get(); + Property::Map propertyMap; + propertyMap.Insert(Visual::Property::TYPE, Visual::COLOR); + propertyMap.Insert(ColorVisual::Property::MIX_COLOR, Color::BLUE); + + tet_infoline( "Register visual, should have depth index of 0.0f" ); + Visual::Base testVisual = factory.CreateVisual( propertyMap ); + dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, testVisual ); + DALI_TEST_EQUALS( testVisual.GetDepthIndex(), 0, TEST_LOCATION ); + + tet_infoline( "Register more visuals, each added one should have a depth index greater than previous" ); + + Visual::Base testVisual2 = factory.CreateVisual( propertyMap ); + dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL2, testVisual2 ); + DALI_TEST_CHECK( testVisual2.GetDepthIndex() > testVisual.GetDepthIndex() ); + + Visual::Base foregroundVisual = factory.CreateVisual( propertyMap ); + dummyImpl.RegisterVisual( DummyControl::Property::FOREGROUND_VISUAL, foregroundVisual ); + DALI_TEST_CHECK( foregroundVisual.GetDepthIndex() > testVisual2.GetDepthIndex() ); + + Visual::Base focusVisual = factory.CreateVisual( propertyMap ); + dummyImpl.RegisterVisual( DummyControl::Property::FOCUS_VISUAL, focusVisual ); + DALI_TEST_CHECK( focusVisual.GetDepthIndex() > foregroundVisual.GetDepthIndex() ); + + tet_infoline( "Set depth index on a new visual before registering, the depth index should not have been changed" ); + Visual::Base labelVisual = factory.CreateVisual( propertyMap ); + labelVisual.SetDepthIndex( -2000 ); + dummyImpl.RegisterVisual( DummyControl::Property::LABEL_VISUAL, labelVisual ); + DALI_TEST_EQUALS( labelVisual.GetDepthIndex(), -2000, TEST_LOCATION ); + + tet_infoline( "Replace visual, the depth index should be the same as what was previously set" ); + const int testVisual2DepthIndex = testVisual2.GetDepthIndex(); + Visual::Base testVisual2Replacement = factory.CreateVisual( propertyMap ); + DALI_TEST_CHECK( testVisual2Replacement.GetDepthIndex() != testVisual2DepthIndex ); + dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL2, testVisual2Replacement ); + DALI_TEST_EQUALS( testVisual2Replacement.GetDepthIndex(), testVisual2DepthIndex, TEST_LOCATION ); + + tet_infoline( "Replace visual and set a depth index on the replacement, the depth index of the replacement should be honoured" ); + Visual::Base anotherTestVisual2Replacement = factory.CreateVisual( propertyMap ); + anotherTestVisual2Replacement.SetDepthIndex( 2000 ); + dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL2, anotherTestVisual2Replacement ); + DALI_TEST_EQUALS( anotherTestVisual2Replacement.GetDepthIndex(), 2000, TEST_LOCATION ); + + dummyControl.SetSize(200.f, 200.f); + Stage::GetCurrent().Add( dummyControl ); + + END_TEST; +} + +int UtcDaliRegisterVisualOrder02(void) +{ + ToolkitTestApplication application; + tet_infoline( "Register Visual Order with Background Set" ); + + DummyControl dummyControl = DummyControl::New(true); + Impl::DummyControl& dummyImpl = static_cast(dummyControl.GetImplementation()); + + const int backgroundDepthIndex = Toolkit::DepthIndex::BACKGROUND; + + VisualFactory factory = VisualFactory::Get(); + Property::Map propertyMap; + propertyMap.Insert(Visual::Property::TYPE, Visual::COLOR); + propertyMap.Insert(ColorVisual::Property::MIX_COLOR, Color::BLUE); + + tet_printf( "Register a control background visual, should have depth index of %d\n", backgroundDepthIndex ); + + dummyControl.SetProperty( Control::Property::BACKGROUND, propertyMap ); + + const int TEST_VISUAL_1_DEPTH_INDEX = 0; + tet_printf( "Register visual, should have depth index of %d\n", TEST_VISUAL_1_DEPTH_INDEX ); + Visual::Base testVisual1 = factory.CreateVisual( propertyMap ); + dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, testVisual1 ); + DALI_TEST_EQUALS( testVisual1.GetDepthIndex(), TEST_VISUAL_1_DEPTH_INDEX , TEST_LOCATION ); + + tet_printf( "Register another visual, should have a depth index greater than previous(%d)\n", TEST_VISUAL_1_DEPTH_INDEX ); + Visual::Base testVisual2 = factory.CreateVisual( propertyMap ); + dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL2, testVisual2 ); + DALI_TEST_CHECK( testVisual2.GetDepthIndex() > testVisual1.GetDepthIndex() ); + + dummyControl.SetSize(200.f, 200.f); + Stage::GetCurrent().Add( dummyControl ); + + END_TEST; +} + +int UtcDaliRegisterVisualWithDepthIndex(void) +{ + ToolkitTestApplication application; + tet_infoline( "Register a Visual With Depth Index" ); + + DummyControl dummyControl = DummyControl::New(true); + Impl::DummyControl& dummyImpl = static_cast(dummyControl.GetImplementation()); + + VisualFactory factory = VisualFactory::Get(); + Property::Map propertyMap; + propertyMap.Insert(Visual::Property::TYPE, Visual::COLOR); + propertyMap.Insert(ColorVisual::Property::MIX_COLOR, Color::BLUE); + + tet_infoline( "Register a visual with a depth index, it should be enabled by default too" ); + Visual::Base testVisual = factory.CreateVisual( propertyMap ); + DevelControl::RegisterVisual( dummyImpl, DummyControl::Property::TEST_VISUAL, testVisual, 203 ); + DALI_TEST_EQUALS( testVisual.GetDepthIndex(), 203, TEST_LOCATION ); + DALI_TEST_EQUALS( DevelControl::IsVisualEnabled( dummyImpl, DummyControl::Property::TEST_VISUAL ), true, TEST_LOCATION ); + + tet_infoline( "Register another visual with a depth index and it disabled" ); + Visual::Base testVisual2 = factory.CreateVisual( propertyMap ); + DevelControl::RegisterVisual( dummyImpl, DummyControl::Property::TEST_VISUAL2, testVisual2, false, 450 ); + DALI_TEST_EQUALS( testVisual2.GetDepthIndex(), 450, TEST_LOCATION ); + DALI_TEST_EQUALS( DevelControl::IsVisualEnabled( dummyImpl, DummyControl::Property::TEST_VISUAL2 ), false, TEST_LOCATION ); + + tet_infoline( "Register another visual with a depth index and it enabled using the enabled API" ); + Visual::Base testVisual3 = factory.CreateVisual( propertyMap ); + DevelControl::RegisterVisual( dummyImpl, DummyControl::Property::TEST_VISUAL2, testVisual3, true, 300 ); + DALI_TEST_EQUALS( testVisual3.GetDepthIndex(), 300, TEST_LOCATION ); + DALI_TEST_EQUALS( DevelControl::IsVisualEnabled( dummyImpl, DummyControl::Property::TEST_VISUAL2 ), true, TEST_LOCATION ); + + dummyControl.SetSize(200.f, 200.f); + Stage::GetCurrent().Add( dummyControl ); + + END_TEST; +} + +int UtcDaliColorVisualRenderIfTransparentProperty(void) +{ + ToolkitTestApplication application; + tet_infoline( "Test the renderIfTransparent property of ColorVisual" ); + + VisualFactory factory = VisualFactory::Get(); + Property::Map propertyMap; + propertyMap.Insert( Visual::Property::TYPE, Visual::COLOR ); + propertyMap.Insert( ColorVisual::Property::MIX_COLOR, Color::BLUE ); + + tet_infoline( "Check default value" ); + { + Visual::Base testVisual = factory.CreateVisual( propertyMap ); + Property::Map returnedMap; + testVisual.CreatePropertyMap( returnedMap ); + + Property::Value* renderIfTransparentProperty = returnedMap.Find( DevelColorVisual::Property::RENDER_IF_TRANSPARENT ); + DALI_TEST_CHECK( renderIfTransparentProperty ); + DALI_TEST_EQUALS( renderIfTransparentProperty->Get< bool >(), false, TEST_LOCATION ); + } + + propertyMap.Insert( DevelColorVisual::Property::RENDER_IF_TRANSPARENT, true ); + + tet_infoline( "Ensure set to value required" ); + { + Visual::Base testVisual = factory.CreateVisual( propertyMap ); + Property::Map returnedMap; + testVisual.CreatePropertyMap( returnedMap ); + + Property::Value* renderIfTransparentProperty = returnedMap.Find( DevelColorVisual::Property::RENDER_IF_TRANSPARENT ); + DALI_TEST_CHECK( renderIfTransparentProperty ); + DALI_TEST_EQUALS( renderIfTransparentProperty->Get< bool >(), true, TEST_LOCATION ); + } + + propertyMap[ DevelColorVisual::Property::RENDER_IF_TRANSPARENT ] = Color::BLUE; + + tet_infoline( "Ensure it returns default value if set to wrong type" ); + { + Visual::Base testVisual = factory.CreateVisual( propertyMap ); + Property::Map returnedMap; + testVisual.CreatePropertyMap( returnedMap ); + + Property::Value* renderIfTransparentProperty = returnedMap.Find( DevelColorVisual::Property::RENDER_IF_TRANSPARENT ); + DALI_TEST_CHECK( renderIfTransparentProperty ); + DALI_TEST_EQUALS( renderIfTransparentProperty->Get< bool >(), false, TEST_LOCATION ); + } + + END_TEST; +} + +int UtcDaliSvgVisualCustomShader(void) +{ + ToolkitTestApplication application; + tet_infoline( "SvgVisual with custom shader" ); + + VisualFactory factory = VisualFactory::Get(); + Property::Map properties; + Property::Map shader; + const std::string vertexShader = "Foobar"; + const std::string fragmentShader = "Foobar"; + shader[Dali::Toolkit::Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader; + shader[Dali::Toolkit::Visual::Shader::Property::VERTEX_SHADER] = vertexShader; + + properties[Visual::Property::TYPE] = Visual::IMAGE; + properties[Visual::Property::SHADER] = shader; + properties[ImageVisual::Property::URL] = TEST_SVG_FILE_NAME; + + Visual::Base visual = factory.CreateVisual( properties ); + + // trigger creation through setting on stage + DummyControl dummy = DummyControl::New( true ); + Impl::DummyControl& dummyImpl = static_cast< Impl::DummyControl& >( dummy.GetImplementation() ); + dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual ); + + dummy.SetSize( 200.f, 200.f ); + dummy.SetParentOrigin( ParentOrigin::CENTER ); + Stage::GetCurrent().Add( dummy ); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION ); + + Renderer renderer = dummy.GetRendererAt( 0 ); + Shader shader2 = renderer.GetShader(); + Property::Value value = shader2.GetProperty( Shader::Property::PROGRAM ); + Property::Map* map = value.GetMap(); + DALI_TEST_CHECK( map ); + + Property::Value* fragment = map->Find( "fragment" ); // fragment key name from shader-impl.cpp + DALI_TEST_EQUALS( fragmentShader, fragment->Get< std::string >(), TEST_LOCATION ); + + Property::Value* vertex = map->Find( "vertex" ); // vertex key name from shader-impl.cpp + DALI_TEST_EQUALS( vertexShader, vertex->Get< std::string >(), TEST_LOCATION ); + + END_TEST; +}