X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=automated-tests%2Fsrc%2Fdali-toolkit%2Futc-Dali-Control.cpp;h=6b09326688d89b72288b40975acc7639edd7b940;hb=65fe4d97a7a58199b2f5ad2d84e26acbb2b6ae39;hp=0a4dad2e1fff9f43b206091b011f03f3108470d7;hpb=6c3063e269a7f2d370c0ad45efde3eeb38dac3a1;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/automated-tests/src/dali-toolkit/utc-Dali-Control.cpp b/automated-tests/src/dali-toolkit/utc-Dali-Control.cpp index 0a4dad2..6b09326 100755 --- 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. @@ -74,6 +74,33 @@ 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"; +const char* TEST_SVG_FILE_NAME = TEST_RESOURCE_DIR "/Kid1.svg"; + +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; +} + +bool gResourceReadySignalFired = false; + +void ResourceReadySignal( Control control ) +{ + if( control.GetVisualResourceStatus( Control::Property::BACKGROUND ) == Visual::ResourceStatus::FAILED ) + { + Property::Map propertyMap; + propertyMap.Insert( ImageVisual::Property::URL, TEST_SVG_FILE_NAME ); + control.SetProperty( Control::Property::BACKGROUND, propertyMap ); + } + + gResourceReadySignalFired = true; +} } // namespace @@ -398,7 +425,7 @@ int UtcDaliControlSignalAutomaticDisconnect(void) DALI_TEST_EQUALS( actor.OnStageSignal().GetConnectionCount(), 0u, TEST_LOCATION ); const Vector3 ignoredSize( 20, 20, 0 ); - actor.SetSize( ignoredSize ); + actor.SetProperty( Actor::Property::SIZE, ignoredSize ); END_TEST; } @@ -407,7 +434,7 @@ int UtcDaliControlTestParameters(void) ToolkitTestApplication application; DummyControl test = DummyControl::New(); - test.SetSize( 0.7f, 0.7f, 0.7f ); + test.SetProperty( Actor::Property::SIZE, Vector3( 0.7f, 0.7f, 0.7f ) ); Stage::GetCurrent().Add( test ); @@ -433,9 +460,9 @@ 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(); @@ -444,16 +471,86 @@ int UtcDaliControlBackgroundColor(void) 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; } @@ -463,10 +560,8 @@ 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(); @@ -475,8 +570,8 @@ int UtcDaliControlBackgroundImage(void) 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(); @@ -491,7 +586,6 @@ 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; @@ -534,22 +628,41 @@ int UtcDaliControlBackgroundProperties(void) 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 ); - // 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 ); + END_TEST; +} - control.ClearBackground(); +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 deprecatedImageMap; - deprecatedImageMap[ "filename" ] = "TestImage"; - control.SetProperty( Control::Property::BACKGROUND_IMAGE, deprecatedImageMap ); - propValue = control.GetProperty( Control::Property::BACKGROUND_IMAGE ); + 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; } @@ -837,7 +950,7 @@ int UtcDaliControlResourcesReady(void) dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, smallVisual ); - actor.SetSize( 200.f, 200.f ); + actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) ); Toolkit::Visual::ResourceStatus resourceStatus = actor.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL); DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION ); @@ -888,6 +1001,38 @@ int UtcDaliControlResourcesReady(void) END_TEST; } +int UtcDaliControlResourcesReady02(void) +{ + ToolkitTestApplication application; + tet_infoline( "Change a resource during ResourceReady callback" ); + + gResourceReadySignalFired = false; + + Control control = Control::New(); + control.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) ); + control.ResourceReadySignal().Connect( &ResourceReadySignal ); + + Property::Map propertyMap; + propertyMap.Insert( ImageVisual::Property::URL, "invalid.jpg" ); + control.SetProperty( Control::Property::BACKGROUND, propertyMap ); + + Stage::GetCurrent().Add( control ); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION ); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( control.IsResourceReady(), true, TEST_LOCATION ); + DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION ); + gResourceReadySignalFired = false; + + END_TEST; +} + int UtcDaliControlMarginProperty(void) { ToolkitTestApplication application; @@ -975,7 +1120,7 @@ int UtcDaliControlDoAction(void) Impl::DummyControl& dummyImpl = static_cast(dummyControl.GetImplementation()); dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual ); - dummyControl.SetSize(200.f, 200.f); + dummyControl.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) ); Stage::GetCurrent().Add( dummyControl ); DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION ); @@ -1017,7 +1162,7 @@ int UtcDaliControlDoActionWhenNotStage(void) Impl::DummyControl& dummyImpl = static_cast(dummyControl.GetImplementation()); dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual ); - dummyControl.SetSize(200.f, 200.f); + dummyControl.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) ); application.SendNotification(); application.Render();