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-Control.cpp;h=bd15bb0da2707d64adc1f94a429dc06d62a4c642;hp=93ee34e14df294b2f0e1634401f3470c0c51e8fa;hb=4d3140d11ea9df2cf933d32419f49fc5e63fa4a9;hpb=84d36f3df81b55d0c7ae20db8005a28742fa4060 diff --git a/automated-tests/src/dali-toolkit/utc-Dali-Control.cpp b/automated-tests/src/dali-toolkit/utc-Dali-Control.cpp old mode 100644 new mode 100755 index 93ee34e..bd15bb0 --- a/automated-tests/src/dali-toolkit/utc-Dali-Control.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-Control.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 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. @@ -24,6 +24,14 @@ #include #include +#include +#include +#include +#include + + +#include + #include "dummy-control.h" using namespace Dali; @@ -64,6 +72,21 @@ static void TestKeyInputFocusCallback( Control control ) gKeyInputFocusCallBackCalled = true; } +const char* TEST_LARGE_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/tbcol.png"; +const char* TEST_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/gallery-small-1.jpg"; + +Vector4 GetControlBackgroundColor( Control& control ) +{ + Property::Value propValue = control.GetProperty( Control::Property::BACKGROUND ); + Property::Map* resultMap = propValue.GetMap(); + DALI_TEST_CHECK( resultMap->Find( ColorVisual::Property::MIX_COLOR ) ); + + Vector4 color; + resultMap->Find( ColorVisual::Property::MIX_COLOR )->Get( color ); + + return color; +} + } // namespace /////////////////////////////////////////////////////////////////////////////////////////////////// @@ -186,6 +209,39 @@ int UtcDaliControlDownCastTemplate(void) END_TEST; } +int UtcDaliControlNavigationProperties(void) +{ + ToolkitTestApplication application; + + Control control = Control::New(); + Stage::GetCurrent().Add( control ); + + DALI_TEST_EQUALS( -1, control.GetProperty( DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION ); + DALI_TEST_EQUALS( -1, control.GetProperty( DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION ); + DALI_TEST_EQUALS( -1, control.GetProperty( DevelControl::Property::UP_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION ); + DALI_TEST_EQUALS( -1, control.GetProperty( DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION ); + + control.SetProperty( DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID, 1 ); + DALI_TEST_EQUALS( 1, control.GetProperty( DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION ); + control.SetProperty( DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID, 2 ); + DALI_TEST_EQUALS( 2, control.GetProperty( DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION ); + control.SetProperty( DevelControl::Property::UP_FOCUSABLE_ACTOR_ID, 3 ); + DALI_TEST_EQUALS( 3, control.GetProperty( DevelControl::Property::UP_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION ); + control.SetProperty( DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID, 4 ); + DALI_TEST_EQUALS( 4, control.GetProperty( DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION ); + + control.SetProperty( DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID, 15 ); + DALI_TEST_EQUALS( 15, control.GetProperty( DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION ); + control.SetProperty( DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID, 16 ); + DALI_TEST_EQUALS( 16, control.GetProperty( DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION ); + control.SetProperty( DevelControl::Property::UP_FOCUSABLE_ACTOR_ID, 17 ); + DALI_TEST_EQUALS( 17, control.GetProperty( DevelControl::Property::UP_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION ); + control.SetProperty( DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID, 18 ); + DALI_TEST_EQUALS( 18, control.GetProperty( DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION ); + + END_TEST; +} + int UtcDaliControlKeyInputFocus(void) { ToolkitTestApplication application; @@ -389,27 +445,97 @@ int UtcDaliControlBackgroundColor(void) ToolkitTestApplication application; Control control = Control::New(); - DALI_TEST_EQUALS( control.GetBackgroundColor(), Color::TRANSPARENT, TEST_LOCATION ); + DALI_TEST_CHECK( control.GetProperty( Control::Property::BACKGROUND ).Get< Property::Map >().Empty() ); - control.SetBackgroundColor( Color::RED ); + control.SetProperty( Control::Property::BACKGROUND, Color::RED ); Property::Value propValue = control.GetProperty( Control::Property::BACKGROUND ); Property::Map* resultMap = propValue.GetMap(); - DALI_TEST_CHECK( resultMap->Find( Visual::Property::TYPE ) ); - DALI_TEST_CHECK( resultMap->Find( Visual::Property::TYPE )->Get() == Visual::COLOR ); + DALI_TEST_CHECK( resultMap->Find( Toolkit::Visual::Property::TYPE ) ); + DALI_TEST_CHECK( resultMap->Find( Toolkit::Visual::Property::TYPE )->Get() == Visual::COLOR ); DALI_TEST_CHECK( resultMap->Find( ColorVisual::Property::MIX_COLOR ) ); DALI_TEST_CHECK( resultMap->Find( ColorVisual::Property::MIX_COLOR )->Get() == Color::RED ); - DALI_TEST_EQUALS( control.GetBackgroundColor(), Color::RED, TEST_LOCATION ); - - control.SetBackgroundColor( Color::YELLOW ); + control.SetProperty( Control::Property::BACKGROUND, Color::YELLOW ); propValue = control.GetProperty( Control::Property::BACKGROUND ); resultMap = propValue.GetMap(); DALI_TEST_CHECK( resultMap->Find( ColorVisual::Property::MIX_COLOR ) ); DALI_TEST_CHECK( resultMap->Find( ColorVisual::Property::MIX_COLOR )->Get() == Color::YELLOW ); - DALI_TEST_EQUALS( control.GetBackgroundColor(), Color::YELLOW, TEST_LOCATION ); + END_TEST; +} + +int UtcDaliControlBackgroundColorRendererCount(void) +{ + tet_infoline( "Test ensures we only create renderers when non-transparent color is requested or if we our clipping-mode is set to CLIP_CHILDREN" ); + + ToolkitTestApplication application; + Control control = Control::New(); + Stage::GetCurrent().Add( control ); + + tet_infoline( "Set transparent, no renderers should be created" ); + control.SetBackgroundColor( Color::TRANSPARENT ); + application.SendNotification(); + application.Render(); + DALI_TEST_EQUALS( control.GetRendererCount(), 0u, TEST_LOCATION ); + + tet_infoline( "Set transparent alpha with positive RGB values, no renderers should be created, but returned color should reflect what we set" ); + const Vector4 alphaZero( 1.0f, 0.5f, 0.25f, 0.0f ); + control.SetBackgroundColor( alphaZero ); + application.SendNotification(); + application.Render(); + DALI_TEST_EQUALS( control.GetRendererCount(), 0u, TEST_LOCATION ); + DALI_TEST_EQUALS( GetControlBackgroundColor( control ), alphaZero, TEST_LOCATION ); + + tet_infoline( "Set semi transparent alpha with positive RGB values, 1 renderer should be created, but returned color should reflect what we set" ); + const Vector4 semiTransparent( 1.0f, 0.75f, 0.5f, 0.5f ); + control.SetBackgroundColor( semiTransparent ); + application.SendNotification(); + application.Render(); + DALI_TEST_EQUALS( control.GetRendererCount(), 1u, TEST_LOCATION ); + DALI_TEST_EQUALS( GetControlBackgroundColor( control ), semiTransparent, TEST_LOCATION ); + + tet_infoline( "Set transparent, ensure no renderers are created" ); + control.SetBackgroundColor( Color::TRANSPARENT ); + application.SendNotification(); + application.Render(); + DALI_TEST_EQUALS( control.GetRendererCount(), 0u, TEST_LOCATION ); + DALI_TEST_EQUALS( GetControlBackgroundColor( control ), Color::TRANSPARENT, TEST_LOCATION ); + + tet_infoline( "Set control to clip its children, a renderer should be created which will be transparent" ); + control.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN ); + application.SendNotification(); + application.Render(); + DALI_TEST_EQUALS( control.GetRendererCount(), 1u, TEST_LOCATION ); + DALI_TEST_EQUALS( GetControlBackgroundColor( control ), Color::TRANSPARENT, TEST_LOCATION ); + + tet_infoline( "Set a color, only 1 renderer should exist" ); + control.SetBackgroundColor( Color::RED ); + application.SendNotification(); + application.Render(); + DALI_TEST_EQUALS( control.GetRendererCount(), 1u, TEST_LOCATION ); + DALI_TEST_EQUALS( GetControlBackgroundColor( control ), Color::RED, TEST_LOCATION ); + + tet_infoline( "Clear the background, no renderers" ); + control.ClearBackground(); + application.SendNotification(); + application.Render(); + DALI_TEST_EQUALS( control.GetRendererCount(), 0u, TEST_LOCATION ); + + tet_infoline( "Set control to clip its children again, a renderer should be created which will be transparent" ); + control.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN ); + application.SendNotification(); + application.Render(); + DALI_TEST_EQUALS( control.GetRendererCount(), 1u, TEST_LOCATION ); + DALI_TEST_EQUALS( GetControlBackgroundColor( control ), Color::TRANSPARENT, TEST_LOCATION ); + + tet_infoline( "Disable clipping, no renderers" ); + control.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::DISABLED ); + application.SendNotification(); + application.Render(); + DALI_TEST_EQUALS( control.GetRendererCount(), 0u, TEST_LOCATION ); + DALI_TEST_EQUALS( GetControlBackgroundColor( control ), Color::TRANSPARENT, TEST_LOCATION ); END_TEST; } @@ -419,20 +545,18 @@ int UtcDaliControlBackgroundImage(void) ToolkitTestApplication application; Control control = Control::New(); - DALI_TEST_EQUALS( control.GetBackgroundColor(), Color::TRANSPARENT, TEST_LOCATION ); - - Image image = ResourceImage::New("TestImage"); - control.SetBackgroundImage( image ); + tet_infoline( "Set first background image" ); + control.SetProperty( Control::Property::BACKGROUND, "TestImage" ); Property::Value propValue = control.GetProperty( Control::Property::BACKGROUND ); Property::Map* resultMap = propValue.GetMap(); - DALI_TEST_CHECK( resultMap->Find( Visual::Property::TYPE ) ); - DALI_TEST_CHECK( resultMap->Find( Visual::Property::TYPE )->Get() == Visual::IMAGE ); + DALI_TEST_CHECK( resultMap->Find( Toolkit::Visual::Property::TYPE ) ); + DALI_TEST_CHECK( resultMap->Find( Toolkit::Visual::Property::TYPE )->Get() == Visual::IMAGE ); DALI_TEST_CHECK( resultMap->Find( ImageVisual::Property::URL ) ); DALI_TEST_CHECK( resultMap->Find( ImageVisual::Property::URL )->Get() == "TestImage" ); - image = ResourceImage::New("TestImage2"); - control.SetBackgroundImage( image ); + tet_infoline( "Set replacement background image" ); + control.SetProperty( Control::Property::BACKGROUND, "TestImage2" ); propValue = control.GetProperty( Control::Property::BACKGROUND ); resultMap = propValue.GetMap(); @@ -447,17 +571,16 @@ int UtcDaliControlBackgroundProperties(void) ToolkitTestApplication application; Control control = Control::New(); - DALI_TEST_EQUALS( control.GetBackgroundColor(), Color::TRANSPARENT, TEST_LOCATION ); DALI_TEST_CHECK( control.GetProperty( Control::Property::BACKGROUND ).Get< Property::Map >().Empty() ); Property::Map imageMap; - imageMap[ Visual::Property::TYPE ] = Visual::IMAGE; + imageMap[ Toolkit::Visual::Property::TYPE ] = Visual::IMAGE; imageMap[ ImageVisual::Property::URL ] = "TestImage"; control.SetProperty( Control::Property::BACKGROUND, imageMap ); Property::Value propValue = control.GetProperty( Control::Property::BACKGROUND ); Property::Map* resultMap = propValue.GetMap(); - DALI_TEST_CHECK( resultMap->Find( Visual::Property::TYPE ) ); - DALI_TEST_EQUALS( resultMap->Find( Visual::Property::TYPE )->Get(),(int)Visual::IMAGE, TEST_LOCATION ); + DALI_TEST_CHECK( resultMap->Find( Toolkit::Visual::Property::TYPE ) ); + DALI_TEST_EQUALS( resultMap->Find( Toolkit::Visual::Property::TYPE )->Get(),(int)Visual::IMAGE, TEST_LOCATION ); DALI_TEST_CHECK( resultMap->Find( ImageVisual::Property::URL ) ); DALI_TEST_EQUALS( resultMap->Find( ImageVisual::Property::URL )->Get(), "TestImage", TEST_LOCATION ); @@ -467,8 +590,8 @@ int UtcDaliControlBackgroundProperties(void) control.SetProperty( Control::Property::BACKGROUND, rendererMap ); propValue = control.GetProperty( Control::Property::BACKGROUND ); resultMap = propValue.GetMap(); - DALI_TEST_CHECK( resultMap->Find( Visual::Property::TYPE ) ); - DALI_TEST_EQUALS( resultMap->Find( Visual::Property::TYPE )->Get(), (int)Visual::COLOR, TEST_LOCATION ); + DALI_TEST_CHECK( resultMap->Find( Toolkit::Visual::Property::TYPE ) ); + DALI_TEST_EQUALS( resultMap->Find( Toolkit::Visual::Property::TYPE )->Get(), (int)Visual::COLOR, TEST_LOCATION ); DALI_TEST_CHECK( resultMap->Find( ColorVisual::Property::MIX_COLOR ) ); DALI_TEST_EQUALS( resultMap->Find( ColorVisual::Property::MIX_COLOR )->Get(), Color::CYAN, TEST_LOCATION ); @@ -480,25 +603,51 @@ int UtcDaliControlBackgroundProperties(void) control.SetProperty( Control::Property::BACKGROUND, "Foobar.png" ); propValue = control.GetProperty( Control::Property::BACKGROUND ); resultMap = propValue.GetMap(); - DALI_TEST_EQUALS( resultMap->Find( Visual::Property::TYPE )->Get(), (int)Visual::IMAGE, TEST_LOCATION ); + DALI_TEST_EQUALS( resultMap->Find( Toolkit::Visual::Property::TYPE )->Get(), (int)Visual::IMAGE, TEST_LOCATION ); DALI_TEST_EQUALS( resultMap->Find( ImageVisual::Property::URL )->Get(), "Foobar.png", TEST_LOCATION ); - // Deprecated Properties - control.SetProperty( Control::Property::BACKGROUND_COLOR, Color::YELLOW ); - DALI_TEST_EQUALS( control.GetProperty( Control::Property::BACKGROUND_COLOR ).Get< Vector4 >(), Color::YELLOW, TEST_LOCATION ); - DALI_TEST_EQUALS( control.GetProperty( Control::Property::BACKGROUND_COLOR ).Get< Vector4 >(), control.GetBackgroundColor(), TEST_LOCATION ); + // set as Color + control.SetProperty( Control::Property::BACKGROUND, Color::RED ); + propValue = control.GetProperty( Control::Property::BACKGROUND ); + resultMap = propValue.GetMap(); + DALI_TEST_EQUALS( resultMap->Find( Toolkit::Visual::Property::TYPE )->Get(), (int)Visual::COLOR, TEST_LOCATION ); + DALI_TEST_EQUALS( resultMap->Find( ColorVisual::Property::MIX_COLOR )->Get(), Color::RED, TEST_LOCATION ); - control.ClearBackground(); + END_TEST; +} - Property::Map deprecatedImageMap; - deprecatedImageMap[ "filename" ] = "TestImage"; - control.SetProperty( Control::Property::BACKGROUND_IMAGE, deprecatedImageMap ); - propValue = control.GetProperty( Control::Property::BACKGROUND_IMAGE ); +int UtcDaliControlShadowProperties(void) +{ + ToolkitTestApplication application; + Control control = Control::New(); + + DALI_TEST_CHECK( control.GetProperty( DevelControl::Property::SHADOW ).Get< Property::Map >().Empty() ); + + Property::Map imageMap; + imageMap[ Toolkit::Visual::Property::TYPE ] = Visual::IMAGE; + imageMap[ ImageVisual::Property::URL ] = "TestImage"; + control.SetProperty( DevelControl::Property::SHADOW, imageMap ); + Property::Value propValue = control.GetProperty( DevelControl::Property::SHADOW ); + Property::Map* resultMap = propValue.GetMap(); + DALI_TEST_CHECK( resultMap->Find( Toolkit::Visual::Property::TYPE ) ); + DALI_TEST_EQUALS( resultMap->Find( Toolkit::Visual::Property::TYPE )->Get(),(int)Visual::IMAGE, TEST_LOCATION ); + DALI_TEST_CHECK( resultMap->Find( ImageVisual::Property::URL ) ); + DALI_TEST_EQUALS( resultMap->Find( ImageVisual::Property::URL )->Get(), "TestImage", TEST_LOCATION ); + + Property::Map colorMap; + colorMap[Visual::Property::TYPE] = Visual::COLOR; + colorMap[ColorVisual::Property::MIX_COLOR] = Color::CYAN; + control.SetProperty( DevelControl::Property::SHADOW, colorMap ); + propValue = control.GetProperty( DevelControl::Property::SHADOW ); resultMap = propValue.GetMap(); - DALI_TEST_EQUALS( resultMap->Find( ImageVisual::Property::URL )->Get< std::string >(), "TestImage" , TEST_LOCATION ); + DALI_TEST_CHECK( resultMap->Find( Toolkit::Visual::Property::TYPE ) ); + DALI_TEST_EQUALS( resultMap->Find( Toolkit::Visual::Property::TYPE )->Get(), (int)Visual::COLOR, TEST_LOCATION ); + DALI_TEST_CHECK( resultMap->Find( ColorVisual::Property::MIX_COLOR ) ); + DALI_TEST_EQUALS( resultMap->Find( ColorVisual::Property::MIX_COLOR )->Get(), Color::CYAN, TEST_LOCATION ); - control.SetProperty( Control::Property::BACKGROUND_IMAGE, emptyMap ); - DALI_TEST_CHECK( control.GetProperty( Control::Property::BACKGROUND_IMAGE ).Get< Property::Map >().Empty() ); + Property::Map emptyMap; + control.SetProperty( DevelControl::Property::SHADOW, emptyMap ); + DALI_TEST_CHECK( control.GetProperty( DevelControl::Property::SHADOW ).Get< Property::Map >().Empty() ); END_TEST; } @@ -633,7 +782,7 @@ int UtcDaliControlAutoClippingN(void) { ToolkitTestApplication application; Control control = Control::New(); - control.SetProperty( Control::Property::BACKGROUND, Property::Map().Add( Visual::Property::TYPE, Visual::COLOR ) + control.SetProperty( Control::Property::BACKGROUND, Property::Map().Add( Toolkit::Visual::Property::TYPE, Visual::COLOR ) .Add( ColorVisual::Property::MIX_COLOR, Color::RED ) ); tet_infoline( "Test to ensure that a renderer does NOT get added when we are clipping children and already have renderers/visuals" ); @@ -690,7 +839,7 @@ int UtcDaliControlAutoClippingWhenAlreadyOnStageN(void) { ToolkitTestApplication application; Control control = Control::New(); - control.SetProperty( Control::Property::BACKGROUND, Property::Map().Add( Visual::Property::TYPE, Visual::COLOR ) + control.SetProperty( Control::Property::BACKGROUND, Property::Map().Add( Toolkit::Visual::Property::TYPE, Visual::COLOR ) .Add( ColorVisual::Property::MIX_COLOR, Color::RED ) ); tet_infoline( "Test to ensure that a renderer does NOT get added when we are clipping children and already have renderers/visuals and when already on stage" ); @@ -721,3 +870,280 @@ int UtcDaliControlAutoClippingWhenAlreadyOnStageN(void) END_TEST; } + +int UtcDaliControlSetTransformSize(void) +{ + ToolkitTestApplication application; + Control control = Control::New(); + + Property::Map transformMap; + transformMap.Add( Visual::Transform::Property::OFFSET, Vector2( 10, 10 ) ) + .Add( Visual::Transform::Property::ANCHOR_POINT, Align::BOTTOM_END ) + .Add( Visual::Transform::Property::ORIGIN, Align::BOTTOM_END ) + .Add( Visual::Transform::Property::SIZE, Vector2( 10, 20 ) ); + + control.SetProperty( Control::Property::BACKGROUND, Property::Map().Add( Toolkit::Visual::Property::TYPE, Visual::COLOR ) + .Add( Visual::Property::TRANSFORM, transformMap ) ); + + tet_infoline( "Test to ensure that the control background transform does not get overwritten when adding to the stage" ); + + Stage::GetCurrent().Add( control ); + + application.SendNotification(); + application.Render(); + + // Ensure the transform property still matches what we set + Property::Value value = control.GetProperty( Control::Property::BACKGROUND ); + Property::Map* map = value.GetMap(); + DALI_TEST_CHECK( map ); + Property::Value* transformValue = map->Find( Visual::Property::TRANSFORM ); + DALI_TEST_CHECK( transformValue ); + + Property::Map* retMap = transformValue->GetMap(); + DALI_TEST_CHECK( retMap ); + DALI_TEST_EQUALS( retMap->Find( Visual::Transform::Property::OFFSET )->Get< Vector2 >(), Vector2( 10, 10 ), TEST_LOCATION ); + DALI_TEST_EQUALS( retMap->Find( Visual::Transform::Property::ANCHOR_POINT )->Get< int >(), (int)Align::BOTTOM_END, TEST_LOCATION ); + DALI_TEST_EQUALS( retMap->Find( Visual::Transform::Property::ORIGIN )->Get< int >(), (int)Align::BOTTOM_END, TEST_LOCATION ); + DALI_TEST_EQUALS( retMap->Find( Visual::Transform::Property::SIZE )->Get< Vector2 >(), Vector2( 10, 20 ), TEST_LOCATION ); + + END_TEST; +} + + +int UtcDaliControlResourcesReady(void) +{ + ToolkitTestApplication application; + tet_infoline( "Register 2 visuals and check ResourceReady when a visual is disabled" ); + + VisualFactory factory = VisualFactory::Get(); + DALI_TEST_CHECK( factory ); + + Property::Map propertyMapLarge; + propertyMapLarge.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE ); + propertyMapLarge.Insert( ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME ); + + Property::Map propertyMapSmall; + propertyMapSmall.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE ); + propertyMapSmall.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME ); + + Visual::Base smallVisual = factory.CreateVisual( propertyMapSmall ); + smallVisual.SetName("smallVisual"); + DALI_TEST_CHECK( smallVisual ); + + DummyControl actor = DummyControl::New(); + DummyControlImpl& dummyImpl = static_cast(actor.GetImplementation()); + + dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, smallVisual ); + + actor.SetSize( 200.f, 200.f ); + + Toolkit::Visual::ResourceStatus resourceStatus = actor.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL); + DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION ); + DALI_TEST_EQUALS( actor.IsResourceReady(), false, TEST_LOCATION ); + DALI_TEST_EQUALS( static_cast(resourceStatus), static_cast(Toolkit::Visual::ResourceStatus::PREPARING), TEST_LOCATION ); + + Stage::GetCurrent().Add( actor ); + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION ); + + application.SendNotification(); + application.Render(); + + resourceStatus = actor.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL); + DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION ); + DALI_TEST_EQUALS( actor.IsResourceReady(), true, TEST_LOCATION ); + DALI_TEST_EQUALS( static_cast(resourceStatus), static_cast(Toolkit::Visual::ResourceStatus::READY), TEST_LOCATION ); + + Visual::Base largeVisual = factory.CreateVisual( propertyMapLarge ); + largeVisual.SetName("largeVisual"); + DALI_TEST_CHECK( largeVisual ); + + tet_infoline( "Register Visual but set disabled, IsResourceReady should be true" ); + + dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL2, largeVisual, false ); + + resourceStatus = actor.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL2); + DALI_TEST_EQUALS( static_cast(resourceStatus), static_cast(Toolkit::Visual::ResourceStatus::PREPARING), TEST_LOCATION ); + + application.SendNotification(); + + resourceStatus = actor.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL2); + DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION ); + DALI_TEST_EQUALS( actor.IsResourceReady(), true, TEST_LOCATION ); + DALI_TEST_EQUALS( static_cast(resourceStatus), static_cast(Toolkit::Visual::ResourceStatus::PREPARING), TEST_LOCATION ); + + dummyImpl.EnableVisual( DummyControl::Property::TEST_VISUAL2, true ); + + DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION ); + + application.SendNotification(); + + resourceStatus = actor.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL2); + DALI_TEST_EQUALS( static_cast(resourceStatus), static_cast(Toolkit::Visual::ResourceStatus::READY), TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliControlMarginProperty(void) +{ + ToolkitTestApplication application; + + Control control = Control::New(); + control.SetBackgroundColor( Color::BLUE ); + + control.SetProperty( Control::Property::MARGIN, Extents( 20, 10, 0, 0 ) ); + + Stage::GetCurrent().Add( control ); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( control.GetProperty( Control::Property::MARGIN ), Extents( 20, 10, 0, 0 ), TEST_LOCATION ); + + // Parent control has one ImageView as a Child. + ImageView image = ImageView::New(); + image.SetBackgroundColor( Color::RED ); + image.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); + image.SetProperty( Control::Property::PADDING, Extents( 10, 10, 10, 10 ) ); + control.Add( image ); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( image.GetProperty( Control::Property::PADDING ), Extents( 10, 10, 10, 10 ), TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliControlPaddingProperty(void) +{ + ToolkitTestApplication application; + + Control control = Control::New(); + control.SetBackgroundColor( Color::BLUE ); + + control.SetProperty( Control::Property::PADDING, Extents( 15, 10, 5, 10 ) ); + + Stage::GetCurrent().Add( control ); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( control.GetProperty( Control::Property::PADDING ), Extents( 15, 10, 5, 10 ), TEST_LOCATION ); + + Control child = Control::New(); + control.Add(child); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( child.GetProperty( Dali::Actor::Property::POSITION ), Vector3( 15, 5, 0 ), TEST_LOCATION ); + + control.SetProperty( Dali::Actor::Property::LAYOUT_DIRECTION, Dali::LayoutDirection::RIGHT_TO_LEFT); + application.SendNotification(); + application.Render(); + DALI_TEST_EQUALS( child.GetProperty( Dali::Actor::Property::POSITION ), Vector3( 10, 5, 0 ), TEST_LOCATION ); + + control.SetProperty( Dali::Actor::Property::LAYOUT_DIRECTION, Dali::LayoutDirection::LEFT_TO_RIGHT); + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( child.GetProperty( Dali::Actor::Property::POSITION ), Vector3( 15, 5, 0 ), TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliControlDoAction(void) +{ + ToolkitTestApplication application; + tet_infoline( "DoAction on a visual registered with a control" ); + + // Set up trace debug + TestGlAbstraction& gl = application.GetGlAbstraction(); + TraceCallStack& textureTrace = gl.GetTextureTrace(); + textureTrace.Enable( true ); + + //Created AnimatedImageVisual + VisualFactory factory = VisualFactory::Get(); + Visual::Base imageVisual = factory.CreateVisual( TEST_IMAGE_FILE_NAME, ImageDimensions() ); + + DummyControl dummyControl = DummyControl::New(true); + Impl::DummyControl& dummyImpl = static_cast(dummyControl.GetImplementation()); + + dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual ); + dummyControl.SetSize(200.f, 200.f); + Stage::GetCurrent().Add( dummyControl ); + + DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION ); + + application.SendNotification(); + application.Render(); + DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION ); + DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION ); + textureTrace.Reset(); + + Property::Map attributes; + DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, DevelImageVisual::Action::RELOAD, attributes ); + + tet_infoline( "Perform RELOAD action. should reload Image and generate a texture" ); + DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION ); + + application.SendNotification(); + application.Render(); + DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION ); + DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION ); + END_TEST; +} + +int UtcDaliControlDoActionWhenNotStage(void) +{ + ToolkitTestApplication application; + tet_infoline( "DoAction on a visual registered with a control but not staged" ); + + // Set up trace debug + TestGlAbstraction& gl = application.GetGlAbstraction(); + TraceCallStack& textureTrace = gl.GetTextureTrace(); + textureTrace.Enable( true ); + + //Created AnimatedImageVisual + VisualFactory factory = VisualFactory::Get(); + Visual::Base imageVisual = factory.CreateVisual( TEST_IMAGE_FILE_NAME, ImageDimensions() ); + + DummyControl dummyControl = DummyControl::New(true); + Impl::DummyControl& dummyImpl = static_cast(dummyControl.GetImplementation()); + + dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual ); + dummyControl.SetSize(200.f, 200.f); + + application.SendNotification(); + application.Render(); + DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION ); + DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION ); + textureTrace.Reset(); + + Property::Map attributes; + DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, DevelImageVisual::Action::RELOAD, attributes ); + + tet_infoline( "Perform RELOAD action. should reload Image and generate a texture" ); + DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION ); + + application.SendNotification(); + application.Render(); + DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION ); + textureTrace.Reset(); + + tet_infoline( "Adding control to stage will in turn add the visual to the stage" ); + + Stage::GetCurrent().Add( dummyControl ); + application.SendNotification(); + application.Render(); + tet_infoline( "No change in textures could occurs as already loaded and cached texture will be used" ); + + DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION ); + DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION ); + textureTrace.Reset(); + + END_TEST; +}