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=f8e61b8067c85135d593e9516c063932940d4973;hp=563c593064605dcc20fbbf3fdf9fcc84925badf9;hb=b977f2ca75522fc2eb536eef07f1180ec4377589;hpb=45ecb0b3535fc8588ae5d95d2a846c90422c3a4d diff --git a/automated-tests/src/dali-toolkit/utc-Dali-Visual.cpp b/automated-tests/src/dali-toolkit/utc-Dali-Visual.cpp index 563c593..f8e61b8 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) 2017 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. @@ -23,9 +23,13 @@ #include #include #include +#include +#include #include +#include #include #include +#include #include #include #include "dummy-control.h" @@ -38,6 +42,7 @@ namespace 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_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 "/"; @@ -50,9 +55,10 @@ Property::Map DefaultTransform() 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::DevelVisual::Transform::Property::ORIGIN, Toolkit::Align::TOP_BEGIN ) + .Add( Toolkit::DevelVisual::Transform::Property::ANCHOR_POINT, Toolkit::Align::TOP_BEGIN ) + .Add( Toolkit::DevelVisual::Transform::Property::OFFSET_POLICY, Vector2( Toolkit::DevelVisual::Transform::Policy::RELATIVE, Toolkit::DevelVisual::Transform::Policy::RELATIVE ) ) + .Add( Toolkit::DevelVisual::Transform::Property::SIZE_POLICY, Vector2( Toolkit::DevelVisual::Transform::Policy::RELATIVE, Toolkit::DevelVisual::Transform::Policy::RELATIVE ) ); return transformMap; } @@ -84,6 +90,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) @@ -96,6 +116,31 @@ void dali_visual_cleanup(void) test_return_value = TET_PASS; } + +static void TestMixColor( Visual::Base visual, Property::Index mixColorIndex, const Vector4& testColor ) +{ + Property::Map map; + visual.CreatePropertyMap(map); + Property::Value* value = map.Find( mixColorIndex ); + DALI_TEST_CHECK( value ); + Vector3 mixColor1; + DALI_TEST_CHECK( value->Get( mixColor1 ) ); + DALI_TEST_EQUALS( mixColor1, Vector3(testColor), 0.001, TEST_LOCATION ); + + value = map.Find( DevelVisual::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( DevelVisual::Property::OPACITY ); + DALI_TEST_CHECK( value ); + float opacity; + DALI_TEST_CHECK( value->Get( opacity ) ); + DALI_TEST_EQUALS( opacity, testColor.a, 0.001, TEST_LOCATION ); +} + + int UtcDaliVisualCopyAndAssignment(void) { ToolkitTestApplication application; @@ -159,11 +204,11 @@ 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(); - DummyControlImpl& dummyImpl = static_cast(dummyControl.GetImplementation()); - dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual ); + DummyControl dummyControl = DummyControl::New(true); + Impl::DummyControl& dummyImpl = static_cast(dummyControl.GetImplementation()); + dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual ); dummyControl.SetSize(200.f, 200.f); Stage::GetCurrent().Add( dummyControl ); @@ -171,12 +216,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; } @@ -202,6 +247,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 ); @@ -227,9 +273,11 @@ int UtcDaliVisualSize(void) propertyMap.Insert(Visual::Property::TYPE, Visual::GRADIENT); Vector2 start(-1.f, -1.f); Vector2 end(1.f, 1.f); - propertyMap.Insert(GradientVisual::Property::START_POSITION, start); - propertyMap.Insert(GradientVisual::Property::END_POSITION, end); - propertyMap.Insert(GradientVisual::Property::STOP_OFFSET, Vector2(0.f, 1.f)); + propertyMap.Insert( "mixColor", Color::MAGENTA ); + propertyMap.Insert( GradientVisual::Property::START_POSITION, start) ; + propertyMap.Insert( GradientVisual::Property::END_POSITION, end ); + propertyMap.Insert( GradientVisual::Property::STOP_OFFSET, Vector2(0.f, 1.f) ); + propertyMap.Insert( GradientVisual::Property::SPREAD_METHOD, GradientVisual::SpreadMethod::REPEAT) ; Property::Array stopColors; stopColors.PushBack( Color::RED ); stopColors.PushBack( Color::GREEN ); @@ -254,19 +302,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( ImageVisual::Property::BATCHING_ENABLED, 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. @@ -292,6 +327,14 @@ int UtcDaliVisualSize(void) const float height = textVisual.GetHeightForWidth( 40.f ); DALI_TEST_EQUALS( height, 40.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION ); + //AnimatedImageVisual + Visual::Base animatedImageVisual = factory.CreateVisual( TEST_GIF_FILE_NAME, ImageDimensions() ); + animatedImageVisual.SetTransformAndSize(DefaultTransform(), controlSize ); + animatedImageVisual.GetNaturalSize(naturalSize); + // TEST_GIF_FILE: anim.gif + // resolution: 50*50, frame count: 4, frame delay: 0.2 second for each frame + DALI_TEST_EQUALS( naturalSize, Vector2(50.f, 50.f), TEST_LOCATION ); + END_TEST; } @@ -306,9 +349,9 @@ int UtcDaliVisualSetOnOffStage(void) propertyMap.Insert(ColorVisual::Property::MIX_COLOR, Color::BLUE); Visual::Base visual = factory.CreateVisual( propertyMap ); - DummyControl actor = DummyControl::New(); - DummyControlImpl& dummyImpl = static_cast(actor.GetImplementation()); - dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual ); + 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); @@ -331,16 +374,15 @@ int UtcDaliVisualSetOnOffStage(void) END_TEST; } - int UtcDaliVisualGetPropertyMap1(void) { ToolkitTestApplication application; - tet_infoline( "UtcDaliVisualGetPropertyMap1: ColorVisual" ); + tet_infoline( "UtcDaliVisualGetPropertyMap1: ColorVisual (With base MixColor" ); VisualFactory factory = VisualFactory::Get(); Property::Map propertyMap; propertyMap.Insert(Visual::Property::TYPE, Visual::COLOR); - propertyMap.Insert(ColorVisual::Property::MIX_COLOR, Color::BLUE); + propertyMap.Insert(DevelVisual::Property::MIX_COLOR, Color::BLUE); Visual::Base colorVisual = factory.CreateVisual( propertyMap ); Property::Map resultMap; @@ -374,8 +416,10 @@ int UtcDaliVisualGetPropertyMap2(void) VisualFactory factory = VisualFactory::Get(); Property::Map propertyMap; propertyMap.Insert(Visual::Property::TYPE, Visual::BORDER); - propertyMap.Insert(BorderVisual::Property::COLOR, Color::BLUE); - propertyMap.Insert(BorderVisual::Property::SIZE, 5.f); + propertyMap.Insert("mixColor", Vector4(1.0f, 0.0f, 1.0f, 0.5f) ); + propertyMap.Insert("borderColor", Color::BLUE); + propertyMap.Insert("borderSize", 5.f); + propertyMap.Insert("antiAliasing", true); Visual::Base borderVisual = factory.CreateVisual( propertyMap ); Property::Map resultMap; @@ -394,6 +438,10 @@ int UtcDaliVisualGetPropertyMap2(void) DALI_TEST_CHECK( sizeValue ); DALI_TEST_CHECK( sizeValue->Get() == 5.f ); + Property::Value* AAValue = resultMap.Find( BorderVisual::Property::ANTI_ALIASING, Property::BOOLEAN ); + DALI_TEST_CHECK( AAValue ); + DALI_TEST_CHECK( AAValue->Get() == true ); + Property::Map propertyMap1; propertyMap1[ Visual::Property::TYPE ] = Visual::BORDER; propertyMap1[ BorderVisual::Property::COLOR ] = Color::CYAN; @@ -417,6 +465,30 @@ int UtcDaliVisualGetPropertyMap2(void) END_TEST; } +int UtcDaliVisualGetPropertyMap2N(void) +{ + ToolkitTestApplication application; + tet_infoline( "UtcDaliVisualGetPropertyMap2N: BorderVisual with no setup properties" ); + + VisualFactory factory = VisualFactory::Get(); + Property::Map propertyMap; + propertyMap.Insert(Visual::Property::TYPE, Visual::BORDER); + Visual::Base borderVisual = factory.CreateVisual( propertyMap ); + + tet_infoline( "Test that the visual is created, with a default renderer" ); + DALI_TEST_CHECK( borderVisual ); + + DummyControl dummyControl = DummyControl::New(true); + Impl::DummyControl& dummyImpl = static_cast(dummyControl.GetImplementation()); + dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, borderVisual ); + Stage::GetCurrent().Add( dummyControl ); + + DALI_TEST_EQUALS( dummyControl.GetRendererCount(), 1, TEST_LOCATION ); + + END_TEST; +} + + int UtcDaliVisualGetPropertyMap3(void) { ToolkitTestApplication application; @@ -430,9 +502,9 @@ int UtcDaliVisualGetPropertyMap3(void) Vector2 start(-1.f, -1.f); Vector2 end(1.f, 1.f); - propertyMap.Insert(GradientVisual::Property::START_POSITION, start); - propertyMap.Insert(GradientVisual::Property::END_POSITION, end); - propertyMap.Insert(GradientVisual::Property::SPREAD_METHOD, GradientVisual::SpreadMethod::REPEAT); + propertyMap.Insert( "startPosition", start); + propertyMap.Insert( "endPosition", end); + propertyMap.Insert( "spreadMethod", GradientVisual::SpreadMethod::REPEAT); propertyMap.Insert(GradientVisual::Property::STOP_OFFSET, Vector2(0.2f, 0.8f)); @@ -563,14 +635,15 @@ 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( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME ); propertyMap.Insert( ImageVisual::Property::DESIRED_WIDTH, 20 ); propertyMap.Insert( ImageVisual::Property::DESIRED_HEIGHT, 30 ); - propertyMap.Insert( ImageVisual::Property::FITTING_MODE, FittingMode::FIT_HEIGHT ); - propertyMap.Insert( ImageVisual::Property::SAMPLING_MODE, SamplingMode::BOX_THEN_NEAREST ); - propertyMap.Insert( ImageVisual::Property::PIXEL_AREA, Vector4( 0.25f, 0.25f, 0.5f, 0.5f ) ); - propertyMap.Insert( ImageVisual::Property::WRAP_MODE_U, WrapMode::REPEAT ); - propertyMap.Insert( ImageVisual::Property::WRAP_MODE_V, WrapMode::MIRRORED_REPEAT ); + propertyMap.Insert( "fittingMode", FittingMode::FIT_HEIGHT ); + propertyMap.Insert( "samplingMode", SamplingMode::BOX_THEN_NEAREST ); + propertyMap.Insert( "pixelArea", Vector4( 0.25f, 0.25f, 0.5f, 0.5f ) ); + propertyMap.Insert( "wrapModeU", WrapMode::REPEAT ); + propertyMap.Insert( "wrapModeV", WrapMode::MIRRORED_REPEAT ); propertyMap.Insert( "synchronousLoading", true ); Visual::Base imageVisual = factory.CreateVisual(propertyMap); @@ -588,6 +661,10 @@ 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 ); + DALI_TEST_CHECK( value ); + DALI_TEST_CHECK( value->Get() == Color::MAGENTA ); + value = resultMap.Find( ImageVisual::Property::FITTING_MODE, Property::INTEGER ); DALI_TEST_CHECK( value ); DALI_TEST_CHECK( value->Get() == FittingMode::FIT_HEIGHT ); @@ -621,6 +698,7 @@ 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 ); @@ -673,11 +751,15 @@ 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( Visual::Property::TYPE, DevelVisual::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( DevelImageVisual::Property::BORDER, border ); Visual::Base nPatchVisual = factory.CreateVisual( propertyMap ); Property::Map resultMap; @@ -686,7 +768,44 @@ int UtcDaliVisualGetPropertyMap6(void) // 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 ); + DALI_TEST_CHECK( value->Get() == DevelVisual::N_PATCH ); + + value = resultMap.Find( DevelVisual::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( DevelImageVisual::Property::BORDER, Property::RECTANGLE ); + DALI_TEST_CHECK( value ); + DALI_TEST_CHECK( value->Get< Rect< int > >() == border ); + + Vector4 border1( 1.0f, 1.0f, 1.0f, 1.0f ); + + Property::Map propertyMap1; + propertyMap1.Insert( Visual::Property::TYPE, DevelVisual::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( DevelImageVisual::Property::BORDER, border1 ); + nPatchVisual = factory.CreateVisual( propertyMap1 ); + + nPatchVisual.CreatePropertyMap( resultMap ); + + // check the property values from the returned map from visual + value = resultMap.Find( Visual::Property::TYPE, Property::INTEGER ); + DALI_TEST_CHECK( value ); + DALI_TEST_CHECK( value->Get() == DevelVisual::N_PATCH ); + + value = resultMap.Find( DevelVisual::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 ); @@ -696,6 +815,9 @@ int UtcDaliVisualGetPropertyMap6(void) DALI_TEST_CHECK( value ); DALI_TEST_CHECK( value->Get() ); + value = resultMap.Find( DevelImageVisual::Property::BORDER, Property::RECTANGLE ); + DALI_TEST_CHECK( value ); + DALI_TEST_CHECK( value->Get< Rect< int > >() == border ); END_TEST; } @@ -708,7 +830,8 @@ 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( Visual::Property::TYPE, DevelVisual::SVG ); + propertyMap.Insert( DevelVisual::Property::MIX_COLOR, Color::WHITE ); propertyMap.Insert( ImageVisual::Property::URL, TEST_SVG_FILE_NAME ); Visual::Base svgVisual = factory.CreateVisual( propertyMap ); @@ -717,7 +840,7 @@ int UtcDaliVisualGetPropertyMap7(void) // check the property values from the returned map from a visual Property::Value* value = resultMap.Find( Visual::Property::TYPE, Property::INTEGER ); DALI_TEST_CHECK( value ); - DALI_TEST_CHECK( value->Get() == Visual::IMAGE ); + DALI_TEST_CHECK( value->Get() == DevelVisual::SVG ); value = resultMap.Find( ImageVisual::Property::URL, Property::STRING ); DALI_TEST_CHECK( value ); @@ -730,7 +853,7 @@ int UtcDaliVisualGetPropertyMap7(void) // check the property values from the returned map from a visual value = resultMap.Find( Visual::Property::TYPE, Property::INTEGER ); DALI_TEST_CHECK( value ); - DALI_TEST_CHECK( value->Get() == Visual::IMAGE ); + DALI_TEST_CHECK( value->Get() == DevelVisual::SVG ); value = resultMap.Find( ImageVisual::Property::URL, Property::STRING ); DALI_TEST_CHECK( value ); @@ -749,6 +872,7 @@ int UtcDaliVisualGetPropertyMap8(void) VisualFactory factory = VisualFactory::Get(); Property::Map propertyMap; propertyMap.Insert( Visual::Property::TYPE, Visual::MESH ); + propertyMap.Insert( DevelVisual::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 ); @@ -758,6 +882,7 @@ int UtcDaliVisualGetPropertyMap8(void) Property::Map resultMap; meshVisual.CreatePropertyMap( resultMap ); + TestMixColor( meshVisual, DevelVisual::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 ); @@ -874,45 +999,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) { @@ -924,6 +1010,7 @@ int UtcDaliVisualGetPropertyMap10(void) Property::Map propertyMap; propertyMap.Insert( Visual::Property::TYPE, DevelVisual::TEXT ); + propertyMap.Insert( DevelVisual::Property::MIX_COLOR, Color::BLACK ); propertyMap.Insert( "renderingBackend", static_cast( Toolkit::Text::DEFAULT_RENDERING_BACKEND ) ); propertyMap.Insert( "enableMarkup", false ); propertyMap.Insert( "text", "Hello world" ); @@ -948,6 +1035,10 @@ int UtcDaliVisualGetPropertyMap10(void) DALI_TEST_CHECK( value ); DALI_TEST_EQUALS( value->Get(), (int)DevelVisual::TEXT, TEST_LOCATION ); + value = resultMap.Find( DevelVisual::Property::MIX_COLOR, Property::VECTOR4 ); + DALI_TEST_CHECK( value ); + DALI_TEST_EQUALS( value->Get(), Color::BLACK, 0.001f, TEST_LOCATION ); + value = resultMap.Find( TextVisual::Property::TEXT, Property::STRING ); DALI_TEST_CHECK( value ); DALI_TEST_EQUALS( value->Get(), "Hello world", TEST_LOCATION ); @@ -990,32 +1081,40 @@ int UtcDaliVisualGetPropertyMap10(void) END_TEST; } -int UtcDaliVisualGetPropertyMapBatchImageVisualNoAtlas(void) +int UtcDaliVisualGetPropertyMap11(void) { ToolkitTestApplication application; - tet_infoline( "UtcDaliVisualGetPropertyMapBatchImageVisualNoAtlas:" ); + tet_infoline( "UtcDaliVisualGetPropertyMap11: AnimatedImageVisual" ); + // request AnimatedImageVisual with a property map 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 ); - - // 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 ); + Visual::Base animatedImageVisual = factory.CreateVisual( Property::Map() + .Add( Visual::Property::TYPE, DevelVisual::ANIMATED_IMAGE ) + .Add( ImageVisual::Property::URL, TEST_GIF_FILE_NAME ) ); - // Create the visual. - Visual::Base batchImageVisual = factory.CreateVisual( propertyMap ); + Property::Map resultMap; + animatedImageVisual.CreatePropertyMap( resultMap ); + // check the property values from the returned map from a visual + Property::Value* value = resultMap.Find( Visual::Property::TYPE, Property::INTEGER ); + DALI_TEST_CHECK( value ); + DALI_TEST_CHECK( value->Get() == DevelVisual::ANIMATED_IMAGE ); - DALI_TEST_CHECK( batchImageVisual ); + value = resultMap.Find( ImageVisual::Property::URL, Property::STRING ); + DALI_TEST_CHECK( value ); + DALI_TEST_CHECK( value->Get() == TEST_GIF_FILE_NAME ); - DummyControl dummyControl = DummyControl::New(); - DummyControlImpl& dummyImpl = static_cast(dummyControl.GetImplementation()); - dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, batchImageVisual ); - Stage::GetCurrent().Add( dummyControl ); + // request AnimatedImageVisual with an URL + Visual::Base animatedImageVisual2 = factory.CreateVisual( TEST_GIF_FILE_NAME, ImageDimensions() ); + resultMap.Clear(); + animatedImageVisual2.CreatePropertyMap( resultMap ); + // check the property values from the returned map from a visual + value = resultMap.Find( Visual::Property::TYPE, Property::INTEGER ); + DALI_TEST_CHECK( value ); + DALI_TEST_CHECK( value->Get() == DevelVisual::ANIMATED_IMAGE ); - DALI_TEST_CHECK( dummyControl.GetRendererCount() == 1u ); + value = resultMap.Find( ImageVisual::Property::URL, Property::STRING ); + DALI_TEST_CHECK( value ); + DALI_TEST_CHECK( value->Get() == TEST_GIF_FILE_NAME ); END_TEST; } @@ -1028,13 +1127,26 @@ 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(BorderVisual::Property::COLOR, Color::BLUE); propertyMap.Insert(BorderVisual::Property::SIZE, 5.f); Visual::Base borderVisual = factory.CreateVisual( propertyMap ); - DummyControl actor = DummyControl::New(); - DummyControlImpl& dummyImpl = static_cast(actor.GetImplementation()); - dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, borderVisual ); + Property::Map map; + map["target"] = "testVisual"; + map["property"] = "mixColor"; + map["targetValue"] = Vector4(1,1,1,0); + 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 ); + + DummyControl actor = DummyControl::New(true); + Impl::DummyControl& dummyImpl = static_cast(actor.GetImplementation()); + dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, borderVisual ); actor.SetSize(2000, 2000); actor.SetParentOrigin(ParentOrigin::CENTER); Stage::GetCurrent().Add(actor); @@ -1042,27 +1154,43 @@ int UtcDaliVisualAnimateBorderVisual01(void) DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION); Renderer renderer = actor.GetRendererAt(0); - Property::Index index = DevelHandle::GetPropertyIndex( renderer, BorderVisual::Property::COLOR ); + Property::Index borderColorIndex = DevelHandle::GetPropertyIndex( renderer, BorderVisual::Property::COLOR ); + Property::Index mixColorIndex = DevelHandle::GetPropertyIndex( renderer, DevelVisual::Property::MIX_COLOR ); - Animation animation = Animation::New(4.0f); - animation.AnimateTo( Property(renderer, index), Color::WHITE ); + Animation animation = dummyImpl.CreateTransition( transition ); + + // Animate the mix color through the transition, and the border color through + // programmatic method. + animation.AnimateTo( Property(renderer, borderColorIndex), Color::WHITE ); animation.Play(); application.SendNotification(); application.Render(0); application.Render(2000u); // halfway point between blue and white - Vector4 color = renderer.GetProperty( index ); + 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 ); - application.Render(2000u); // halfway point between blue and white + color = renderer.GetCurrentProperty< Vector3 >( mixColorIndex ); + testColor = Vector4( 1,1,1,0.4f ); + DALI_TEST_EQUALS( Vector3(color), Vector3(testColor), 0.0001f, TEST_LOCATION ); + DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue("mixColor", Vector3(testColor) ), true, TEST_LOCATION ); + DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue("opacity", testColor.a ) , true, TEST_LOCATION ); + + application.Render(2000u); - color = renderer.GetProperty( index ); + 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.GetCurrentProperty< Vector4 >( mixColorIndex ); + testColor = Vector4(1,1,1,0); + DALI_TEST_EQUALS( color, testColor, TEST_LOCATION ); + DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue("mixColor", Vector3(testColor) ), true, TEST_LOCATION ); + DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue("opacity", testColor.a ), true, TEST_LOCATION ); + END_TEST; } @@ -1079,9 +1207,9 @@ int UtcDaliVisualAnimateBorderVisual02(void) propertyMap.Insert(BorderVisual::Property::SIZE, 5.f); Visual::Base borderVisual = factory.CreateVisual( propertyMap ); - DummyControl actor = DummyControl::New(); - DummyControlImpl& dummyImpl = static_cast(actor.GetImplementation()); - dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, borderVisual ); + DummyControl actor = DummyControl::New(true); + Impl::DummyControl& dummyImpl = static_cast(actor.GetImplementation()); + dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, borderVisual ); actor.SetSize(2000, 2000); actor.SetParentOrigin(ParentOrigin::CENTER); Stage::GetCurrent().Add(actor); @@ -1099,13 +1227,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 ); @@ -1123,9 +1251,9 @@ int UtcDaliVisualAnimateColorVisual(void) propertyMap.Insert(ColorVisual::Property::MIX_COLOR, Color::BLUE); Visual::Base borderVisual = factory.CreateVisual( propertyMap ); - DummyControl actor = DummyControl::New(); - DummyControlImpl& dummyImpl = static_cast(actor.GetImplementation()); - dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, borderVisual ); + DummyControl actor = DummyControl::New(true); + Impl::DummyControl& dummyImpl = static_cast(actor.GetImplementation()); + dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, borderVisual ); actor.SetSize(2000, 2000); actor.SetParentOrigin(ParentOrigin::CENTER); Stage::GetCurrent().Add(actor); @@ -1133,81 +1261,119 @@ 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.GetCurrentProperty( Renderer::Property::BLEND_MODE ); + DALI_TEST_EQUALS( blendModeValue.Get(), (int)BlendMode::AUTO, TEST_LOCATION ); END_TEST; } - int UtcDaliVisualAnimatePrimitiveVisual(void) { ToolkitTestApplication application; tet_infoline( "UtcDaliAnimatePrimitiveVisual color" ); - VisualFactory factory = VisualFactory::Get(); - Property::Map propertyMap; - propertyMap.Insert(Visual::Property::TYPE, Visual::COLOR); - propertyMap.Insert(ColorVisual::Property::MIX_COLOR, Color::BLUE); - Visual::Base borderVisual = factory.CreateVisual( propertyMap ); - - DummyControl actor = DummyControl::New(); - DummyControlImpl& dummyImpl = static_cast(actor.GetImplementation()); - dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, borderVisual ); - 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, PrimitiveVisual::Property::MIX_COLOR ); - - // The property isn't registered on the renderer, it's instead registered on the shader. - DALI_TEST_EQUALS( index, Property::INVALID_INDEX, TEST_LOCATION ); - - Animation animation = Animation::New(4.0f); - animation.AnimateTo( Property(actor, Actor::Property::COLOR), Color::WHITE ); - animation.Play(); - - application.SendNotification(); - application.Render(0); - application.Render(2000u); // halfway point - - // Actor color overrides renderer color. - DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue("uColor", Vector4(0.5f, 0.5f, 0.5f, 1.0f )), true, TEST_LOCATION ); - - application.Render(2000u); // halfway point between blue and white - - DALI_TEST_EQUALS( actor.GetCurrentColor(), Color::WHITE, TEST_LOCATION ); - DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue("uColor", Color::WHITE ), true, TEST_LOCATION ); - + { + VisualFactory factory = VisualFactory::Get(); + Property::Map propertyMap; + propertyMap.Insert(Visual::Property::TYPE, Visual::PRIMITIVE); + propertyMap.Insert(PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::CUBE); + propertyMap.Insert(PrimitiveVisual::Property::MIX_COLOR, Color::BLUE); + 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, PrimitiveVisual::Property::MIX_COLOR ); + + tet_infoline("Test that the renderer has the Primitive mix color"); + DALI_TEST_CHECK( index != Property::INVALID_INDEX ); + + const Vector4 INITIAL_MIX_COLOR( 1.0f,0.0f,1.0f,0.5f ); // Magenta with half alpha + const Vector4 TARGET_MIX_COLOR( Color::RED ); + + Property::Map map; + map["target"] = "testVisual"; + map["property"] = "mixColor"; + map["initialValue"] = INITIAL_MIX_COLOR; + map["targetValue"] = TARGET_MIX_COLOR; + 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 ); + + Animation animation = dummyImpl.CreateTransition( transition ); + Property::Value blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE ); + DALI_TEST_EQUALS( blendModeValue.Get(), (int)BlendMode::ON, TEST_LOCATION ); + + animation.AnimateTo( Property(actor, Actor::Property::COLOR), Color::WHITE ); + animation.Play(); + + application.SendNotification(); + application.Render(0); + 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", Vector3(halfwayColor) ), true, TEST_LOCATION ); + DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue("opacity", halfwayColor.a ), 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", Vector3(TARGET_MIX_COLOR) ), true, TEST_LOCATION ); + DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue("opacity", TARGET_MIX_COLOR.a ), true, TEST_LOCATION ); + + blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE ); + DALI_TEST_EQUALS( blendModeValue.Get(), (int)BlendMode::AUTO, TEST_LOCATION ); + + actor.Unparent(); + } END_TEST; } + int UtcDaliVisualWireframeVisual(void) { ToolkitTestApplication application; @@ -1261,19 +1427,24 @@ int UtcDaliVisualGetTransform(void) 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::DevelVisual::Transform::Property::OFFSET_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::DevelVisual::Transform::Policy::RELATIVE, Toolkit::DevelVisual::Transform::Policy::RELATIVE ) ); + } + { + Property::Value* typeValue = map->Find( Toolkit::DevelVisual::Transform::Property::SIZE_POLICY ); + DALI_TEST_CHECK( typeValue ); + DALI_TEST_CHECK( typeValue->Get< Vector2 >() == Vector2( Toolkit::DevelVisual::Transform::Policy::RELATIVE, Toolkit::DevelVisual::Transform::Policy::RELATIVE ) ); } { Property::Value* typeValue = map->Find( Toolkit::DevelVisual::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 ); 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; @@ -1284,8 +1455,8 @@ static void TestTransform( ToolkitTestApplication& application, Visual::Base vis 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::OFFSET_POLICY, Vector2( Toolkit::DevelVisual::Transform::Policy::ABSOLUTE, Toolkit::DevelVisual::Transform::Policy::ABSOLUTE ) ); + transform.Insert( DevelVisual::Transform::Property::ORIGIN, "CENTER" ); transform.Insert( DevelVisual::Transform::Property::ANCHOR_POINT, Toolkit::Align::BOTTOM_END ); visual.SetTransformAndSize( transform, Vector2(100, 100) ); @@ -1307,14 +1478,19 @@ static void TestTransform( ToolkitTestApplication& application, Visual::Base vis 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::DevelVisual::Transform::Property::OFFSET_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::DevelVisual::Transform::Policy::ABSOLUTE, Toolkit::DevelVisual::Transform::Policy::ABSOLUTE ), TEST_LOCATION ); + } + { + Property::Value* typeValue = map->Find( Toolkit::DevelVisual::Transform::Property::SIZE_POLICY ); + DALI_TEST_CHECK( typeValue ); + DALI_TEST_EQUALS( typeValue->Get< Vector2 >(), Vector2( Toolkit::DevelVisual::Transform::Policy::RELATIVE, Toolkit::DevelVisual::Transform::Policy::RELATIVE ), TEST_LOCATION ); } { Property::Value* typeValue = map->Find( Toolkit::DevelVisual::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 ); @@ -1323,38 +1499,51 @@ static void TestTransform( ToolkitTestApplication& application, Visual::Base vis } //Put the visual on the stage - DummyControl actor = DummyControl::New(); - DummyControlImpl& dummyImpl = static_cast(actor.GetImplementation()); - dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual ); + DummyControl actor = DummyControl::New(true); + Impl::DummyControl& dummyImpl = static_cast(actor.GetImplementation()); actor.SetSize(2000, 2000); actor.SetParentOrigin(ParentOrigin::CENTER); Stage::GetCurrent().Add(actor); + dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual ); + dummyImpl.SetLayout( DummyControl::Property::TEST_VISUAL, transform ); + application.SendNotification(); application.Render(0); Renderer renderer( actor.GetRendererAt(0) ); //Check that the properties have been registered on the Renderer - Vector2 offset = renderer.GetProperty( renderer.GetPropertyIndex( "offset" ) ); + Property::Index index = renderer.GetPropertyIndex( "offset" ); + DALI_TEST_CHECK( index != Property::INVALID_INDEX ); + Vector2 offset = renderer.GetProperty( index ); DALI_TEST_EQUALS( offset, Vector2(10.0f,10.0f), TEST_LOCATION ); - Vector2 size = renderer.GetProperty( renderer.GetPropertyIndex( "size" ) ); + index = renderer.GetPropertyIndex( "size" ); + DALI_TEST_CHECK( index != Property::INVALID_INDEX ); + Vector2 size = renderer.GetProperty( index ); DALI_TEST_EQUALS( size, Vector2(0.2f,0.2f), TEST_LOCATION ); - Vector4 offsetSizeMode = renderer.GetProperty( renderer.GetPropertyIndex( "offsetSizeMode" ) ); + index = renderer.GetPropertyIndex( "offsetSizeMode" ); + DALI_TEST_CHECK( index != Property::INVALID_INDEX ); + Vector4 offsetSizeMode = renderer.GetProperty( index ); DALI_TEST_EQUALS( offsetSizeMode, Vector4(1.0f,1.0f,0.0f,0.0f), TEST_LOCATION ); - Vector2 parentOrigin = renderer.GetProperty( renderer.GetPropertyIndex( "origin" ) ); - DALI_TEST_EQUALS( parentOrigin, Vector2(-0.5f,-0.5f), TEST_LOCATION ); + index = renderer.GetPropertyIndex( "origin" ); + DALI_TEST_CHECK( index != Property::INVALID_INDEX ); + Vector2 parentOrigin = renderer.GetProperty( index ); + DALI_TEST_EQUALS( parentOrigin, Vector2(0.0f,0.0f), TEST_LOCATION ); - Vector2 anchorPoint = renderer.GetProperty( renderer.GetPropertyIndex( "anchorPoint" ) ); + index = renderer.GetPropertyIndex( "anchorPoint" ); + DALI_TEST_CHECK( index != Property::INVALID_INDEX ); + Vector2 anchorPoint = renderer.GetProperty( index ); DALI_TEST_EQUALS( anchorPoint, Vector2(-0.5f,-0.5f), TEST_LOCATION ); //Set a new transform transform.Clear(); + transform = DefaultTransform(); 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.Insert( DevelVisual::Transform::Property::SIZE_POLICY, Vector2( Toolkit::DevelVisual::Transform::Policy::ABSOLUTE, Toolkit::DevelVisual::Transform::Policy::ABSOLUTE ) ); visual.SetTransformAndSize( transform, Vector2(100, 100) ); application.SendNotification(); application.Render(0); @@ -1369,12 +1558,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) @@ -1388,6 +1577,7 @@ int UtcDaliVisualSetTransform0(void) propertyMap.Insert(ColorVisual::Property::MIX_COLOR, Color::BLUE); Visual::Base visual = factory.CreateVisual( propertyMap ); TestTransform( application, visual ); + TestMixColor( visual, ColorVisual::Property::MIX_COLOR, Color::BLUE ); END_TEST; } @@ -1400,12 +1590,13 @@ int UtcDaliVisualSetTransform1(void) VisualFactory factory = VisualFactory::Get(); Property::Map propertyMap; propertyMap[ Visual::Property::TYPE ] = Visual::PRIMITIVE; - propertyMap[ PrimitiveVisual::Property::MIX_COLOR ] = Vector4(1.0f,1.0f,1.0f,1.0f); + propertyMap[ PrimitiveVisual::Property::MIX_COLOR ] = Color::WHITE; propertyMap[ PrimitiveVisual::Property::SHAPE ] = PrimitiveVisual::Shape::SPHERE; propertyMap[ PrimitiveVisual::Property::SLICES ] = 10; propertyMap[ PrimitiveVisual::Property::STACKS ] = 10; Visual::Base visual = factory.CreateVisual( propertyMap ); TestTransform( application, visual ); + TestMixColor( visual, PrimitiveVisual::Property::MIX_COLOR, Color::WHITE ); END_TEST; } @@ -1418,6 +1609,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 ); + Property::Array stopOffsets; stopOffsets.PushBack( 0.0f ); stopOffsets.PushBack( 0.3f ); @@ -1437,6 +1630,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 ); END_TEST; } @@ -1449,10 +1643,12 @@ 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( 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 ); END_TEST; } @@ -1465,13 +1661,16 @@ int UtcDaliVisualSetTransform4(void) VisualFactory factory = VisualFactory::Get(); Property::Map propertyMap; propertyMap.Insert( Visual::Property::TYPE, Visual::MESH ); - 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 ); - propertyMap.Insert( MeshVisual::Property::SHADING_MODE, MeshVisual::ShadingMode::TEXTURELESS_WITH_DIFFUSE_LIGHTING ); - propertyMap.Insert( MeshVisual::Property::LIGHT_POSITION, Vector3( 5.0f, 10.0f, 15.0f) ); + propertyMap.Insert( DevelVisual::Property::MIX_COLOR, Color::CYAN ); + + propertyMap.Insert( "objectUrl", TEST_OBJ_FILE_NAME ); + propertyMap.Insert( "materialUrl", TEST_MTL_FILE_NAME ); + propertyMap.Insert( "texturesPath", TEST_RESOURCE_LOCATION ); + propertyMap.Insert( "shadingMode", MeshVisual::ShadingMode::TEXTURELESS_WITH_DIFFUSE_LIGHTING ); + 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 ); END_TEST; } @@ -1485,6 +1684,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 ); END_TEST; } @@ -1497,6 +1697,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[Toolkit::ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME; propertyMap[Toolkit::ImageVisual::Property::DESIRED_WIDTH] = 100.0f; propertyMap[Toolkit::ImageVisual::Property::DESIRED_HEIGHT] = 100.0f; @@ -1505,6 +1706,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 ); END_TEST; } @@ -1518,6 +1720,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 ); + + 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::DevelVisual::Property::TRANSFORM ); + Dali::Property::Map* map = value->GetMap(); + DALI_TEST_CHECK( map ); + + { + Property::Value* typeValue = map->Find( Toolkit::DevelVisual::Transform::Property::OFFSET_POLICY ); + DALI_TEST_CHECK( typeValue ); + DALI_TEST_EQUALS( typeValue->Get< Vector2 >(), Vector2( Toolkit::DevelVisual::Transform::Policy::ABSOLUTE, Toolkit::DevelVisual::Transform::Policy::RELATIVE ), TEST_LOCATION ); + } + { + Property::Value* typeValue = map->Find( Toolkit::DevelVisual::Transform::Property::SIZE_POLICY ); + DALI_TEST_CHECK( typeValue ); + DALI_TEST_EQUALS( typeValue->Get< Vector2 >(), Vector2( Toolkit::DevelVisual::Transform::Policy::RELATIVE, Toolkit::DevelVisual::Transform::Policy::ABSOLUTE ), TEST_LOCATION ); + } END_TEST; } @@ -1530,21 +1771,36 @@ 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; - properties[Dali::Toolkit::Visual::Property::TYPE] = Dali::Toolkit::Visual::IMAGE; - properties[Dali::Toolkit::Visual::Property::SHADER]=shader; - properties[Dali::Toolkit::ImageVisual::Property::URL] = TEST_NPATCH_FILE_NAME; + 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["offsetPolicy"] = Vector2( DevelVisual::Transform::Policy::ABSOLUTE, DevelVisual::Transform::Policy::ABSOLUTE ); + transformMap["anchorPoint"] = Align::CENTER; + transformMap["origin"] = Align::CENTER; + properties[DevelVisual::Property::TRANSFORM] = transformMap; + + properties[Visual::Property::TYPE] = Visual::IMAGE; + properties[DevelVisual::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 ); // trigger creation through setting on stage - DummyControl dummy = DummyControl::New(); - DummyControlImpl& dummyImpl = static_cast(dummy.GetImplementation()); - dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual ); + DummyControl dummy = DummyControl::New(true); + Impl::DummyControl& dummyImpl = static_cast(dummy.GetImplementation()); + dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual ); + dummyImpl.SetLayout( DummyControl::Property::TEST_VISUAL, transformMap ); dummy.SetSize(2000, 2000); dummy.SetParentOrigin(ParentOrigin::CENTER); Stage::GetCurrent().Add(dummy); + application.SendNotification(); Renderer renderer = dummy.GetRendererAt( 0 ); Shader shader2 = renderer.GetShader(); @@ -1552,13 +1808,18 @@ int UtcDaliNPatchVisualCustomShader(void) Property::Map* map = value.GetMap(); DALI_TEST_CHECK( map ); - Property::Value* fragment = map->Find( "fragment" ); // fragment key name from shader-impl.cpp - // *map["vertex"]; is default here so not verifying it + Property::Index index = renderer.GetPropertyIndex("size"); + 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 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; } + int UtcDaliGradientVisualBlendMode(void) { ToolkitTestApplication application; @@ -1578,13 +1839,13 @@ int UtcDaliGradientVisualBlendMode(void) .Add( GradientVisual::Property::STOP_COLOR, Property::Array().Add( Color::RED ) .Add( Vector4( 1.0f, 1.0f, 1.0f, 0.5f ) ) ) ); - DummyControl control = DummyControl::New(); + DummyControl control = DummyControl::New(true); control.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); Stage::GetCurrent().Add( control ); - DummyControlImpl& dummyImpl = static_cast( control.GetImplementation() ); - dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, opaqueGradientVisual ); - dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 2, alphaGradientVisual ); + Impl::DummyControl& dummyImpl = static_cast( control.GetImplementation() ); + dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, opaqueGradientVisual ); + dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL2, alphaGradientVisual ); application.SendNotification(); application.Render(); @@ -1608,11 +1869,11 @@ 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(); - DummyControlImpl& dummyImpl = static_cast(dummyControl.GetImplementation()); - dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual ); + DummyControl dummyControl = DummyControl::New(true); + Impl::DummyControl& dummyImpl = static_cast(dummyControl.GetImplementation()); + dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual ); DALI_TEST_EQUALS( dummyControl.GetRendererCount(), 0, TEST_LOCATION ); dummyControl.SetSize(200.f, 200.f); @@ -1654,6 +1915,7 @@ int UtcDaliVisualTextVisualRender(void) VisualFactory factory = VisualFactory::Get(); Property::Map propertyMap; propertyMap.Insert( Visual::Property::TYPE, DevelVisual::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" ); @@ -1669,14 +1931,15 @@ 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); - DummyControlImpl& dummyImpl = static_cast(dummyControl.GetImplementation()); - dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, textVisual ); + 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(); @@ -1691,18 +1954,76 @@ int UtcDaliVisualTextVisualRender(void) propertyMap.Insert( TextVisual::Property::MULTI_LINE, true ); Property::Map transformMap; - transformMap.Insert( DevelVisual::Transform::Property::SIZE, Vector2( 720.f, 640.f ) ); + transformMap.Insert( "size", Vector2( 0.5f, 0.5f ) ); propertyMap.Insert( DevelVisual::Property::TRANSFORM, transformMap ); textVisual = factory.CreateVisual( propertyMap ); - textVisual.SetDepthIndex( 1.f ); + textVisual.SetDepthIndex( 1 ); - dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, textVisual ); + dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, textVisual ); dummyControl.SetSize( 720.f, 640.f ); + application.SendNotification(); // force process events to ensure text visual + // adds renderer to the dummy control in OnRelayout + application.Render(); + + Renderer renderer = dummyControl.GetRendererAt(0u); + Property::Index index = renderer.GetPropertyIndex("size"); + + 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( Visual::Property::TYPE, DevelVisual::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; } @@ -1764,3 +2085,133 @@ 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; +}