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=221bac02b006f75e1cbe6abe1d7aa3fbc07fb364;hp=bd15bb0da2707d64adc1f94a429dc06d62a4c642;hb=383021a5eeff5ade0a8e7d50d3fdbe5a7549f0da;hpb=4d3140d11ea9df2cf933d32419f49fc5e63fa4a9 diff --git a/automated-tests/src/dali-toolkit/utc-Dali-Control.cpp b/automated-tests/src/dali-toolkit/utc-Dali-Control.cpp old mode 100755 new mode 100644 index bd15bb0..221bac0 --- 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) 2019 Samsung Electronics Co., Ltd. + * Copyright (c) 2021 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,6 +26,7 @@ #include #include #include +#include #include #include @@ -74,6 +75,7 @@ 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 ) { @@ -87,6 +89,20 @@ Vector4 GetControlBackgroundColor( Control& control ) 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 /////////////////////////////////////////////////////////////////////////////////////////////////// @@ -126,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; @@ -165,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; @@ -214,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 ); @@ -245,7 +298,7 @@ int UtcDaliControlNavigationProperties(void) int UtcDaliControlKeyInputFocus(void) { ToolkitTestApplication application; - Stage stage = Stage::GetCurrent(); + Integration::Scene stage = application.GetScene(); DummyControl control; @@ -353,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); @@ -363,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; @@ -397,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; } @@ -419,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(); @@ -472,21 +525,8 @@ int UtcDaliControlBackgroundColorRendererCount(void) 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 ); + control[Actor::Property::SIZE] = Vector2(100.0f, 100.0f); + application.GetScene().Add( control ); 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 ); @@ -496,19 +536,41 @@ int UtcDaliControlBackgroundColorRendererCount(void) 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" ); + 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 ); + + TestGlAbstraction& gl = application.GetGlAbstraction(); + TraceCallStack& drawTrace = gl.GetDrawTrace(); + drawTrace.Enable(true); + + tet_infoline( "Set transparent, 1 renderer should be created, but ensure nothing is drawn" ); control.SetBackgroundColor( Color::TRANSPARENT ); application.SendNotification(); application.Render(); - DALI_TEST_EQUALS( control.GetRendererCount(), 0u, TEST_LOCATION ); + + DALI_TEST_EQUALS( control.GetRendererCount(), 1u, TEST_LOCATION ); DALI_TEST_EQUALS( GetControlBackgroundColor( control ), Color::TRANSPARENT, TEST_LOCATION ); + DALI_TEST_EQUALS(drawTrace.FindMethod("DrawArrays"), false, TEST_LOCATION); + + drawTrace.Reset(); 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 ); + DALI_TEST_EQUALS(drawTrace.FindMethod("DrawArrays"), true, TEST_LOCATION); tet_infoline( "Set a color, only 1 renderer should exist" ); control.SetBackgroundColor( Color::RED ); @@ -530,12 +592,15 @@ int UtcDaliControlBackgroundColorRendererCount(void) DALI_TEST_EQUALS( control.GetRendererCount(), 1u, TEST_LOCATION ); DALI_TEST_EQUALS( GetControlBackgroundColor( control ), Color::TRANSPARENT, TEST_LOCATION ); - tet_infoline( "Disable clipping, no renderers" ); + drawTrace.Reset(); + + tet_infoline( "Disable clipping, render nothing" ); 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 ); + DALI_TEST_EQUALS(drawTrace.FindMethod("DrawArrays"), false, TEST_LOCATION); END_TEST; } @@ -657,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 ); @@ -704,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); @@ -726,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); @@ -768,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(); @@ -791,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(); @@ -818,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(); @@ -846,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(); @@ -887,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(); @@ -935,14 +1000,14 @@ 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 ); 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(); @@ -986,6 +1051,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 ); + + 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; +} + int UtcDaliControlMarginProperty(void) { ToolkitTestApplication application; @@ -995,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(); @@ -1026,7 +1123,7 @@ int UtcDaliControlPaddingProperty(void) control.SetProperty( Control::Property::PADDING, Extents( 15, 10, 5, 10 ) ); - Stage::GetCurrent().Add( control ); + application.GetScene().Add( control ); application.SendNotification(); application.Render(); @@ -1073,8 +1170,8 @@ int UtcDaliControlDoAction(void) Impl::DummyControl& dummyImpl = static_cast(dummyControl.GetImplementation()); dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual ); - dummyControl.SetSize(200.f, 200.f); - Stage::GetCurrent().Add( dummyControl ); + dummyControl.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) ); + application.GetScene().Add( dummyControl ); DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION ); @@ -1115,7 +1212,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(); @@ -1136,7 +1233,7 @@ int UtcDaliControlDoActionWhenNotStage(void) tet_infoline( "Adding control to stage will in turn add the visual to the stage" ); - Stage::GetCurrent().Add( dummyControl ); + 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" );