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=df48a7de4c4d895c4102c927cbb7aca3a6b43864;hp=bfb390cb6cc7441e9a168a06878a7156d920547b;hb=5027b0fded1281b450ec58b6a1309ef8e01bcd47;hpb=3e3ba0c9a854a2a392b74baab03ae171833d3ac0 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 bfb390c..df48a7d --- a/automated-tests/src/dali-toolkit/utc-Dali-Control.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-Control.cpp @@ -27,6 +27,9 @@ #include #include #include +#include + + #include #include "dummy-control.h" @@ -72,6 +75,18 @@ static void TestKeyInputFocusCallback( Control control ) 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 /////////////////////////////////////////////////////////////////////////////////////////////////// @@ -455,6 +470,80 @@ int UtcDaliControlBackgroundColor(void) 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; +} + int UtcDaliControlBackgroundImage(void) { ToolkitTestApplication application; @@ -831,11 +920,15 @@ int UtcDaliControlResourcesReady(void) 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(); @@ -846,8 +939,10 @@ int UtcDaliControlResourcesReady(void) 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"); @@ -857,11 +952,24 @@ int UtcDaliControlResourcesReady(void) 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(); - application.Render(); + 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; } @@ -904,14 +1012,126 @@ int UtcDaliControlPaddingProperty(void) Control control = Control::New(); control.SetBackgroundColor( Color::BLUE ); - control.SetProperty( Control::Property::PADDING, Extents( 10, 10, 10, 10 ) ); + 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( 10, 10, 10, 10 ), TEST_LOCATION ); + 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; }