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=396bab4a7da7175ad8ee85a3bf4deae1a539cb76;hp=bfb390cb6cc7441e9a168a06878a7156d920547b;hb=894bdab40ca92a1c6ff5f553322b6c9f11d48741;hpb=26080f936f851754221bb16e4e5e3834c24b96db diff --git a/automated-tests/src/dali-toolkit/utc-Dali-Control.cpp b/automated-tests/src/dali-toolkit/utc-Dali-Control.cpp index bfb390c..396bab4 100644 --- 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) 2020 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. @@ -26,7 +26,11 @@ #include #include #include +#include #include +#include + + #include #include "dummy-control.h" @@ -71,6 +75,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 @@ -111,7 +142,7 @@ int UtcDaliControlRegister(void) ToolkitTestApplication application; // Ensure the object is registered after creation - ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry(); + ObjectRegistry registry = application.GetCore().GetObjectRegistry(); DALI_TEST_CHECK( registry ); gObjectCreatedCallBackCalled = false; @@ -150,6 +181,43 @@ int UtcDaliControlCopyAndAssignment(void) END_TEST; } +int UtcDaliControlMoveConstructor(void) +{ + ToolkitTestApplication application; + + Control control = Control::New(); + DALI_TEST_EQUALS( 1, control.GetBaseObject().ReferenceCount(), TEST_LOCATION ); + control.SetProperty( Actor::Property::SENSITIVE, false ); + DALI_TEST_CHECK( false == control.GetProperty< bool >( Actor::Property::SENSITIVE ) ); + + Control moved = std::move( control ); + DALI_TEST_CHECK( moved ); + DALI_TEST_EQUALS( 1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION ); + DALI_TEST_CHECK( false == moved.GetProperty< bool >( Actor::Property::SENSITIVE ) ); + DALI_TEST_CHECK( !control ); + + END_TEST; +} + +int UtcDaliControlMoveAssignment(void) +{ + ToolkitTestApplication application; + + Control control = Control::New(); + DALI_TEST_EQUALS( 1, control.GetBaseObject().ReferenceCount(), TEST_LOCATION ); + control.SetProperty( Actor::Property::SENSITIVE, false ); + DALI_TEST_CHECK( false == control.GetProperty< bool >( Actor::Property::SENSITIVE ) ); + + Control moved; + moved = std::move( control ); + DALI_TEST_CHECK( moved ); + DALI_TEST_EQUALS( 1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION ); + DALI_TEST_CHECK( false == moved.GetProperty< bool >( Actor::Property::SENSITIVE ) ); + DALI_TEST_CHECK( !control ); + + END_TEST; +} + int UtcDaliControlDownCast(void) { ToolkitTestApplication application; @@ -199,7 +267,7 @@ int UtcDaliControlNavigationProperties(void) ToolkitTestApplication application; Control control = Control::New(); - Stage::GetCurrent().Add( control ); + application.GetScene().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 ); @@ -230,7 +298,7 @@ int UtcDaliControlNavigationProperties(void) int UtcDaliControlKeyInputFocus(void) { ToolkitTestApplication application; - Stage stage = Stage::GetCurrent(); + Integration::Scene stage = application.GetScene(); DummyControl control; @@ -338,7 +406,7 @@ int UtcDaliControlSignalConnectDisconnect(void) DummyControl dummy = DummyControlImpl::New(); Actor actor = Actor::New(); - DALI_TEST_EQUALS( actor.OnStageSignal().GetConnectionCount(), 0u, TEST_LOCATION ); + DALI_TEST_EQUALS( actor.OnSceneSignal().GetConnectionCount(), 0u, TEST_LOCATION ); Toolkit::Internal::Control& control = Toolkit::Internal::GetImplementation( dummy ); DummyControlImpl* dummyImpl = dynamic_cast(&control); @@ -348,18 +416,18 @@ int UtcDaliControlSignalConnectDisconnect(void) END_TEST; } - actor.OnStageSignal().Connect( dummyImpl, &DummyControlImpl::CustomSlot1 ); - DALI_TEST_EQUALS( actor.OnStageSignal().GetConnectionCount(), 1u, TEST_LOCATION ); + actor.OnSceneSignal().Connect( dummyImpl, &DummyControlImpl::CustomSlot1 ); + DALI_TEST_EQUALS( actor.OnSceneSignal().GetConnectionCount(), 1u, TEST_LOCATION ); DALI_TEST_EQUALS( dummyImpl->mCustomSlot1Called, false, TEST_LOCATION ); - Stage::GetCurrent().Add( actor ); + application.GetScene().Add( actor ); DALI_TEST_EQUALS( dummyImpl->mCustomSlot1Called, true, TEST_LOCATION ); dummyImpl->mCustomSlot1Called = false; - actor.OnStageSignal().Disconnect( dummyImpl, &DummyControlImpl::CustomSlot1 ); - DALI_TEST_EQUALS( actor.OnStageSignal().GetConnectionCount(), 0u, TEST_LOCATION ); - Stage::GetCurrent().Remove( actor ); - Stage::GetCurrent().Add( actor ); + actor.OnSceneSignal().Disconnect( dummyImpl, &DummyControlImpl::CustomSlot1 ); + DALI_TEST_EQUALS( actor.OnSceneSignal().GetConnectionCount(), 0u, TEST_LOCATION ); + application.GetScene().Remove( actor ); + application.GetScene().Add( actor ); DALI_TEST_EQUALS( dummyImpl->mCustomSlot1Called, false, TEST_LOCATION ); } END_TEST; @@ -382,20 +450,20 @@ int UtcDaliControlSignalAutomaticDisconnect(void) END_TEST; } - actor.OnStageSignal().Connect( dummyImpl, &DummyControlImpl::CustomSlot1 ); - DALI_TEST_EQUALS( actor.OnStageSignal().GetConnectionCount(), 1u, TEST_LOCATION ); + actor.OnSceneSignal().Connect( dummyImpl, &DummyControlImpl::CustomSlot1 ); + DALI_TEST_EQUALS( actor.OnSceneSignal().GetConnectionCount(), 1u, TEST_LOCATION ); DALI_TEST_EQUALS( dummyImpl->mCustomSlot1Called, false, TEST_LOCATION ); - Stage::GetCurrent().Add( actor ); + application.GetScene().Add( actor ); DALI_TEST_EQUALS( dummyImpl->mCustomSlot1Called, true, TEST_LOCATION ); - Stage::GetCurrent().Remove( actor ); + application.GetScene().Remove( actor ); } // dummyControl automatically disconnects - DALI_TEST_EQUALS( actor.OnStageSignal().GetConnectionCount(), 0u, TEST_LOCATION ); + DALI_TEST_EQUALS( actor.OnSceneSignal().GetConnectionCount(), 0u, TEST_LOCATION ); const Vector3 ignoredSize( 20, 20, 0 ); - actor.SetSize( ignoredSize ); + actor.SetProperty( Actor::Property::SIZE, ignoredSize ); END_TEST; } @@ -404,9 +472,9 @@ 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 ); + application.GetScene().Add( test ); application.SendNotification(); application.Render(); @@ -430,9 +498,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(); @@ -441,16 +509,98 @@ 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(); + application.GetScene().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 ); + + Renderer renderer = control.GetRendererAt( 0 ); + DALI_TEST_CHECK( renderer ); + + tet_infoline( "Set semi transparent alpha with positive RGB values, renderer should not be changed" ); + const Vector4 newColor( 1.0f, 1.0f, 0.5f, 0.5f ); + control.SetBackgroundColor( newColor ); + application.SendNotification(); + application.Render(); + DALI_TEST_EQUALS( control.GetRendererCount(), 1u, TEST_LOCATION ); + DALI_TEST_EQUALS( GetControlBackgroundColor( control ), newColor, TEST_LOCATION ); + DALI_TEST_EQUALS( renderer, control.GetRendererAt( 0 ), 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; } @@ -460,10 +610,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(); @@ -472,8 +620,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(); @@ -488,7 +636,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; @@ -531,22 +678,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; +} + +int UtcDaliControlShadowProperties(void) +{ + ToolkitTestApplication application; + Control control = Control::New(); - control.ClearBackground(); + DALI_TEST_CHECK( control.GetProperty( DevelControl::Property::SHADOW ).Get< Property::Map >().Empty() ); - Property::Map deprecatedImageMap; - deprecatedImageMap[ "filename" ] = "TestImage"; - control.SetProperty( Control::Property::BACKGROUND_IMAGE, deprecatedImageMap ); - propValue = control.GetProperty( Control::Property::BACKGROUND_IMAGE ); + 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; } @@ -556,7 +722,7 @@ int UtcDaliControlKeyProperties(void) ToolkitTestApplication application; Control control = Control::New(); - Stage::GetCurrent().Add( control ); + application.GetScene().Add( control ); DALI_TEST_EQUALS( control.HasKeyInputFocus(), control.GetProperty( Control::Property::KEY_INPUT_FOCUS ).Get< bool >(), TEST_LOCATION ); @@ -603,7 +769,7 @@ int UtcDaliControlImplKeyInputFocusGainedSignal(void) ToolkitTestApplication application; Control control = Control::New(); - Stage::GetCurrent().Add( control ); + application.GetScene().Add( control ); gKeyInputFocusCallBackCalled = false; control.KeyInputFocusGainedSignal().Connect(&TestKeyInputFocusCallback); @@ -625,7 +791,7 @@ int UtcDaliControlImplKeyInputFocusLostSignal(void) ToolkitTestApplication application; Control control = Control::New(); - Stage::GetCurrent().Add( control ); + application.GetScene().Add( control ); gKeyInputFocusCallBackCalled = false; control.KeyInputFocusLostSignal().Connect(&TestKeyInputFocusCallback); @@ -667,7 +833,7 @@ int UtcDaliControlAutoClipping(void) control.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN ); - Stage::GetCurrent().Add( control ); + application.GetScene().Add( control ); application.SendNotification(); application.Render(); @@ -690,7 +856,7 @@ int UtcDaliControlAutoClippingN(void) control.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN ); - Stage::GetCurrent().Add( control ); + application.GetScene().Add( control ); application.SendNotification(); application.Render(); @@ -717,7 +883,7 @@ int UtcDaliControlAutoClippingWhenAlreadyOnStage(void) DALI_TEST_EQUALS( 0, control.GetRendererCount(), TEST_LOCATION ); - Stage::GetCurrent().Add( control ); + application.GetScene().Add( control ); application.SendNotification(); application.Render(); @@ -745,7 +911,7 @@ int UtcDaliControlAutoClippingWhenAlreadyOnStageN(void) DALI_TEST_EQUALS( 0, control.GetRendererCount(), TEST_LOCATION ); - Stage::GetCurrent().Add( control ); + application.GetScene().Add( control ); application.SendNotification(); application.Render(); @@ -786,7 +952,7 @@ int UtcDaliControlSetTransformSize(void) tet_infoline( "Test to ensure that the control background transform does not get overwritten when adding to the stage" ); - Stage::GetCurrent().Add( control ); + application.GetScene().Add( control ); application.SendNotification(); application.Render(); @@ -831,13 +997,17 @@ 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 ); + 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 ); 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.GetScene().Add( actor ); application.SendNotification(); application.Render(); @@ -846,8 +1016,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 +1029,56 @@ 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; +} + +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 ); + + application.GetScene().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; } @@ -875,7 +1092,7 @@ int UtcDaliControlMarginProperty(void) control.SetProperty( Control::Property::MARGIN, Extents( 20, 10, 0, 0 ) ); - Stage::GetCurrent().Add( control ); + application.GetScene().Add( control ); application.SendNotification(); application.Render(); @@ -904,14 +1121,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 ) ); + + application.GetScene().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.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) ); + application.GetScene().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.SetProperty( Actor::Property::SIZE, Vector2( 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(); - Stage::GetCurrent().Add( control ); + tet_infoline( "Adding control to stage will in turn add the visual to the stage" ); + application.GetScene().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( control.GetProperty( Control::Property::PADDING ), Extents( 10, 10, 10, 10 ), TEST_LOCATION ); + DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION ); + DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION ); + textureTrace.Reset(); END_TEST; }