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=9ba1bcf5c36e77a46974141e3c8c00802a3b4b9f;hp=588c7c52460c04eb25850ddd017954512b8efde7;hb=8cd51ee7d23a0981aaacfae27cf39d4c80c898cf;hpb=7862c06931f3feb015f06a011c875014e4cd2b37 diff --git a/automated-tests/src/dali-toolkit/utc-Dali-Control.cpp b/automated-tests/src/dali-toolkit/utc-Dali-Control.cpp index 588c7c5..9ba1bcf 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) 2015 Samsung Electronics Co., Ltd. + * Copyright (c) 2017 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,12 @@ #include #include +#include +#include +#include +#include +#include + #include "dummy-control.h" using namespace Dali; @@ -64,6 +70,9 @@ 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"; + } // namespace /////////////////////////////////////////////////////////////////////////////////////////////////// @@ -186,6 +195,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; @@ -395,10 +437,10 @@ int UtcDaliControlBackgroundColor(void) Property::Value propValue = control.GetProperty( Control::Property::BACKGROUND ); Property::Map* resultMap = propValue.GetMap(); - DALI_TEST_CHECK( resultMap->Find( "rendererType" ) ); - DALI_TEST_CHECK( resultMap->Find( "rendererType" )->Get() == "color" ); - DALI_TEST_CHECK( resultMap->Find( "blendColor" ) ); - DALI_TEST_CHECK( resultMap->Find( "blendColor" )->Get() == Color::RED ); + DALI_TEST_CHECK( resultMap->Find( Visual::Property::TYPE ) ); + DALI_TEST_CHECK( resultMap->Find( 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 ); @@ -406,8 +448,8 @@ int UtcDaliControlBackgroundColor(void) propValue = control.GetProperty( Control::Property::BACKGROUND ); resultMap = propValue.GetMap(); - DALI_TEST_CHECK( resultMap->Find( "blendColor" ) ); - DALI_TEST_CHECK( resultMap->Find( "blendColor" )->Get() == Color::YELLOW ); + 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 ); @@ -426,18 +468,18 @@ int UtcDaliControlBackgroundImage(void) Property::Value propValue = control.GetProperty( Control::Property::BACKGROUND ); Property::Map* resultMap = propValue.GetMap(); - DALI_TEST_CHECK( resultMap->Find( "rendererType" ) ); - DALI_TEST_CHECK( resultMap->Find( "rendererType" )->Get() == "image" ); - DALI_TEST_CHECK( resultMap->Find( "imageUrl" ) ); - DALI_TEST_CHECK( resultMap->Find( "imageUrl" )->Get() == "TestImage" ); + DALI_TEST_CHECK( resultMap->Find( Visual::Property::TYPE ) ); + DALI_TEST_CHECK( resultMap->Find( 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 ); propValue = control.GetProperty( Control::Property::BACKGROUND ); resultMap = propValue.GetMap(); - DALI_TEST_CHECK( resultMap->Find( "imageUrl" ) ); - DALI_TEST_CHECK( resultMap->Find( "imageUrl" )->Get() == "TestImage2" ); + DALI_TEST_CHECK( resultMap->Find( ImageVisual::Property::URL ) ); + DALI_TEST_CHECK( resultMap->Find( ImageVisual::Property::URL )->Get() == "TestImage2" ); END_TEST; } @@ -451,35 +493,50 @@ int UtcDaliControlBackgroundProperties(void) DALI_TEST_CHECK( control.GetProperty( Control::Property::BACKGROUND ).Get< Property::Map >().Empty() ); Property::Map imageMap; - imageMap[ "rendererType" ] = "image"; - imageMap[ "imageUrl" ] = "TestImage"; + imageMap[ 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( "rendererType" ) ); - DALI_TEST_CHECK( resultMap->Find( "rendererType" )->Get() == "image" ); - DALI_TEST_CHECK( resultMap->Find( "imageUrl" ) ); - DALI_TEST_CHECK( resultMap->Find( "imageUrl" )->Get() == "TestImage" ); + 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( ImageVisual::Property::URL ) ); + DALI_TEST_EQUALS( resultMap->Find( ImageVisual::Property::URL )->Get(), "TestImage", TEST_LOCATION ); Property::Map rendererMap; - rendererMap["rendererType"] = "color"; - rendererMap["blendColor"] = Color::CYAN; + rendererMap[Visual::Property::TYPE] = Visual::COLOR; + rendererMap[ColorVisual::Property::MIX_COLOR] = Color::CYAN; control.SetProperty( Control::Property::BACKGROUND, rendererMap ); propValue = control.GetProperty( Control::Property::BACKGROUND ); resultMap = propValue.GetMap(); - DALI_TEST_CHECK( resultMap->Find( "rendererType" ) ); - DALI_TEST_CHECK( resultMap->Find( "rendererType" )->Get() == "color" ); - DALI_TEST_CHECK( resultMap->Find( "blendColor" ) ); - DALI_TEST_CHECK( resultMap->Find( "blendColor" )->Get() == Color::CYAN ); + 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( ColorVisual::Property::MIX_COLOR ) ); + DALI_TEST_EQUALS( resultMap->Find( ColorVisual::Property::MIX_COLOR )->Get(), Color::CYAN, TEST_LOCATION ); Property::Map emptyMap; control.SetProperty( Control::Property::BACKGROUND, emptyMap ); DALI_TEST_CHECK( control.GetProperty( Control::Property::BACKGROUND ).Get< Property::Map >().Empty() ); + // set as URL + 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( ImageVisual::Property::URL )->Get(), "Foobar.png", 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( 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_CHECK( control.GetProperty( Control::Property::BACKGROUND_COLOR ).Get< Vector4 >() == Color::YELLOW ); - DALI_TEST_CHECK( control.GetProperty( Control::Property::BACKGROUND_COLOR ).Get< Vector4 >() == control.GetBackgroundColor() ); + 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 ); + control.ClearBackground(); Property::Map deprecatedImageMap; @@ -487,7 +544,8 @@ int UtcDaliControlBackgroundProperties(void) control.SetProperty( Control::Property::BACKGROUND_IMAGE, deprecatedImageMap ); propValue = control.GetProperty( Control::Property::BACKGROUND_IMAGE ); resultMap = propValue.GetMap(); - DALI_TEST_CHECK( resultMap->Find( "imageUrl" )->Get< std::string >() == "TestImage" ); + DALI_TEST_EQUALS( resultMap->Find( ImageVisual::Property::URL )->Get< std::string >(), "TestImage" , TEST_LOCATION ); + control.SetProperty( Control::Property::BACKGROUND_IMAGE, emptyMap ); DALI_TEST_CHECK( control.GetProperty( Control::Property::BACKGROUND_IMAGE ).Get< Property::Map >().Empty() ); @@ -598,3 +656,213 @@ int UtcDaliControlImplGetControlExtensionP(void) END_TEST; } + +int UtcDaliControlAutoClipping(void) +{ + ToolkitTestApplication application; + Control control = Control::New(); + + tet_infoline( "Test to see if a renderer gets added when we are clipping children" ); + + DALI_TEST_EQUALS( 0, control.GetRendererCount(), TEST_LOCATION ); + + control.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN ); + + Stage::GetCurrent().Add( control ); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( 1, control.GetRendererCount(), TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliControlAutoClippingN(void) +{ + ToolkitTestApplication application; + Control control = Control::New(); + control.SetProperty( Control::Property::BACKGROUND, Property::Map().Add( 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" ); + + DALI_TEST_EQUALS( 0, control.GetRendererCount(), TEST_LOCATION ); + + control.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN ); + + Stage::GetCurrent().Add( control ); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( 1, control.GetRendererCount(), TEST_LOCATION ); // Only 1, not 2 + + // Ensure the background color is still RED rather than what's set by the automatic clipping + Property::Value value = control.GetProperty( Control::Property::BACKGROUND ); + Property::Map* map = value.GetMap(); + DALI_TEST_CHECK( map ); + Property::Value* colorValue = map->Find(ColorVisual::Property::MIX_COLOR ); + DALI_TEST_CHECK( colorValue ); + DALI_TEST_EQUALS( colorValue->Get< Vector4 >(), Color::RED, TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliControlAutoClippingWhenAlreadyOnStage(void) +{ + ToolkitTestApplication application; + Control control = Control::New(); + + tet_infoline( "Test to see if a renderer gets added when we are clipping children and when already on stage" ); + + DALI_TEST_EQUALS( 0, control.GetRendererCount(), TEST_LOCATION ); + + Stage::GetCurrent().Add( control ); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( 0, control.GetRendererCount(), TEST_LOCATION ); + + control.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN ); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( 1, control.GetRendererCount(), TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliControlAutoClippingWhenAlreadyOnStageN(void) +{ + ToolkitTestApplication application; + Control control = Control::New(); + control.SetProperty( Control::Property::BACKGROUND, Property::Map().Add( 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" ); + + DALI_TEST_EQUALS( 0, control.GetRendererCount(), TEST_LOCATION ); + + Stage::GetCurrent().Add( control ); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( 1, control.GetRendererCount(), TEST_LOCATION ); + + control.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN ); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( 1, control.GetRendererCount(), TEST_LOCATION ); // Still should be 1 + + // Ensure the background color is still RED rather than what's set by the automatic clipping + Property::Value value = control.GetProperty( Control::Property::BACKGROUND ); + Property::Map* map = value.GetMap(); + DALI_TEST_CHECK( map ); + Property::Value* colorValue = map->Find(ColorVisual::Property::MIX_COLOR ); + DALI_TEST_CHECK( colorValue ); + DALI_TEST_EQUALS( colorValue->Get< Vector4 >(), Color::RED, TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliControlSetTransformSize(void) +{ + ToolkitTestApplication application; + Control control = Control::New(); + + Property::Map transformMap; + transformMap.Add( DevelVisual::Transform::Property::OFFSET, Vector2( 10, 10 ) ) + .Add( DevelVisual::Transform::Property::ANCHOR_POINT, Align::BOTTOM_END ) + .Add( DevelVisual::Transform::Property::ORIGIN, Align::BOTTOM_END ) + .Add( DevelVisual::Transform::Property::SIZE, Vector2( 10, 20 ) ); + + control.SetProperty( Control::Property::BACKGROUND, Property::Map().Add( Visual::Property::TYPE, Visual::COLOR ) + .Add( DevelVisual::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( DevelVisual::Property::TRANSFORM ); + DALI_TEST_CHECK( transformValue ); + + Property::Map* retMap = transformValue->GetMap(); + DALI_TEST_CHECK( retMap ); + DALI_TEST_EQUALS( retMap->Find( DevelVisual::Transform::Property::OFFSET )->Get< Vector2 >(), Vector2( 10, 10 ), TEST_LOCATION ); + DALI_TEST_EQUALS( retMap->Find( DevelVisual::Transform::Property::ANCHOR_POINT )->Get< int >(), (int)Align::BOTTOM_END, TEST_LOCATION ); + DALI_TEST_EQUALS( retMap->Find( DevelVisual::Transform::Property::ORIGIN )->Get< int >(), (int)Align::BOTTOM_END, TEST_LOCATION ); + DALI_TEST_EQUALS( retMap->Find( DevelVisual::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( Visual::Property::TYPE, Visual::IMAGE ); + propertyMapLarge.Insert( ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME ); + + Property::Map propertyMapSmall; + propertyMapSmall.Insert( 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 ); + DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION ); + DALI_TEST_EQUALS( actor.IsResourceReady(), false, TEST_LOCATION ); + + Stage::GetCurrent().Add( actor ); + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION ); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION ); + DALI_TEST_EQUALS( actor.IsResourceReady(), true, 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 ); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION ); + DALI_TEST_EQUALS( actor.IsResourceReady(), true, TEST_LOCATION ); + + END_TEST; +}