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=376ad0d4466af26d2a26e2decf63df1174781709;hp=1de1d579b09e22bf692588b2105218af52ca601b;hb=9ce1fa453940de2fb38552cc374cd54af660debf;hpb=d57dd5d306bcfaee778dcb6c00e24465f0f4f5de diff --git a/automated-tests/src/dali-toolkit/utc-Dali-Control.cpp b/automated-tests/src/dali-toolkit/utc-Dali-Control.cpp index 1de1d57..376ad0d 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-Control.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-Control.cpp @@ -1,18 +1,19 @@ -// -// Copyright (c) 2014 Samsung Electronics Co., Ltd. -// -// Licensed under the Flora License, Version 1.0 (the License); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://floralicense.org/license/ -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an AS IS BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// +/* + * 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ #include #include @@ -23,6 +24,9 @@ #include #include +#include +#include + #include "dummy-control.h" using namespace Dali; @@ -43,13 +47,26 @@ void utc_dali_toolkit_control_cleanup(void) namespace { -static bool gObjectCreatedCallBackCalled; +bool gObjectCreatedCallBackCalled; -static void TestCallback(BaseHandle handle) +void TestCallback(BaseHandle handle) { gObjectCreatedCallBackCalled = true; } +void TestVoidCallback() +{ +} + +static bool gKeyInputFocusCallBackCalled; + +static void TestKeyInputFocusCallback( Control control ) +{ + tet_infoline(" TestKeyInputFocusCallback"); + + gKeyInputFocusCallBackCalled = true; +} + } // namespace /////////////////////////////////////////////////////////////////////////////////////////////////// @@ -190,17 +207,16 @@ int UtcDaliControlKeyInputFocus(void) END_TEST; } -int UtcDaliControlGetImplementation(void) +int UtcDaliControlGetImplementationN(void) { ToolkitTestApplication application; - DummyControl control; // Get Empty { try { - ControlImpl& controlImpl = control.GetImplementation(); + Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( control ); (void)controlImpl; // Avoid unused warning tet_result(TET_FAIL); } @@ -209,13 +225,20 @@ int UtcDaliControlGetImplementation(void) tet_result(TET_PASS); } } + END_TEST; +} + +int UtcDaliControlGetImplementationConstN(void) +{ + ToolkitTestApplication application; + DummyControl control; // Get Const Empty { try { const DummyControl constControl(control); - const ControlImpl& controlImpl = constControl.GetImplementation(); + const Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( constControl ); (void)controlImpl; // Avoid unused warning tet_result(TET_FAIL); } @@ -224,14 +247,19 @@ int UtcDaliControlGetImplementation(void) tet_result(TET_PASS); } } + END_TEST; +} - control = DummyControl::New(); +int UtcDaliControlGetImplementationP(void) +{ + ToolkitTestApplication application; + DummyControl control = DummyControl::New(); // Get { try { - ControlImpl& controlImpl = control.GetImplementation(); + Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( control ); (void)controlImpl; // Avoid unused warning tet_result(TET_PASS); } @@ -240,13 +268,19 @@ int UtcDaliControlGetImplementation(void) tet_result(TET_FAIL); } } + END_TEST; +} +int UtcDaliControlGetImplementationConstP(void) +{ + ToolkitTestApplication application; + DummyControl control = DummyControl::New(); // Get Const { try { const DummyControl constControl(control); - const ControlImpl& controlImpl = constControl.GetImplementation(); + const Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( constControl ); (void)controlImpl; // Avoid unused warning tet_result(TET_PASS); } @@ -266,24 +300,29 @@ int UtcDaliControlSignalConnectDisconnect(void) DummyControl dummy = DummyControlImpl::New(); Actor actor = Actor::New(); - DALI_TEST_EQUALS( actor.SetSizeSignal().GetConnectionCount(), 0u, TEST_LOCATION ); - actor.SetSizeSignal().Connect( &dummy, &DummyControl::CustomSlot1 ); - DALI_TEST_EQUALS( actor.SetSizeSignal().GetConnectionCount(), 1u, TEST_LOCATION ); - DALI_TEST_EQUALS( dummy.mCustomSlot1Called, false, TEST_LOCATION ); - DALI_TEST_EQUALS( dummy.mCustomSlot1Value, Vector3::ZERO, TEST_LOCATION ); - - const Vector3 newSize( 10, 10, 0 ); - actor.SetSize( newSize ); - DALI_TEST_EQUALS( dummy.mCustomSlot1Called, true, TEST_LOCATION ); - DALI_TEST_EQUALS( dummy.mCustomSlot1Value, newSize, TEST_LOCATION ); - - dummy.mCustomSlot1Called = false; - actor.SetSizeSignal().Disconnect( &dummy, &DummyControl::CustomSlot1 ); - DALI_TEST_EQUALS( actor.SetSizeSignal().GetConnectionCount(), 0u, TEST_LOCATION ); - const Vector3 ignoredSize( 20, 20, 0 ); - actor.SetSize( ignoredSize ); - DALI_TEST_EQUALS( dummy.mCustomSlot1Called, false, TEST_LOCATION ); - DALI_TEST_EQUALS( dummy.mCustomSlot1Value, newSize/*not ignoredSize*/, TEST_LOCATION ); + DALI_TEST_EQUALS( actor.OnStageSignal().GetConnectionCount(), 0u, TEST_LOCATION ); + Toolkit::Internal::Control& control = Toolkit::Internal::GetImplementation( dummy ); + DummyControlImpl* dummyImpl = dynamic_cast(&control); + + if( dummyImpl == NULL ) + { + tet_result( TET_FAIL ); + END_TEST; + } + + actor.OnStageSignal().Connect( dummyImpl, &DummyControlImpl::CustomSlot1 ); + DALI_TEST_EQUALS( actor.OnStageSignal().GetConnectionCount(), 1u, TEST_LOCATION ); + DALI_TEST_EQUALS( dummyImpl->mCustomSlot1Called, false, TEST_LOCATION ); + + Stage::GetCurrent().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 ); + DALI_TEST_EQUALS( dummyImpl->mCustomSlot1Called, false, TEST_LOCATION ); } END_TEST; } @@ -296,20 +335,26 @@ int UtcDaliControlSignalAutomaticDisconnect(void) { DummyControl dummy = DummyControlImpl::New(); + Toolkit::Internal::Control& control = Toolkit::Internal::GetImplementation( dummy ); + DummyControlImpl* dummyImpl = dynamic_cast(&control); + + if( dummyImpl == NULL ) + { + tet_result( TET_FAIL ); + END_TEST; + } - actor.SetSizeSignal().Connect( &dummy, &DummyControl::CustomSlot1 ); - DALI_TEST_EQUALS( actor.SetSizeSignal().GetConnectionCount(), 1u, TEST_LOCATION ); - DALI_TEST_EQUALS( dummy.mCustomSlot1Called, false, TEST_LOCATION ); - DALI_TEST_EQUALS( dummy.mCustomSlot1Value, Vector3::ZERO, TEST_LOCATION ); + actor.OnStageSignal().Connect( dummyImpl, &DummyControlImpl::CustomSlot1 ); + DALI_TEST_EQUALS( actor.OnStageSignal().GetConnectionCount(), 1u, TEST_LOCATION ); + DALI_TEST_EQUALS( dummyImpl->mCustomSlot1Called, false, TEST_LOCATION ); - const Vector3 newSize( 10, 10, 0 ); - actor.SetSize( newSize ); - DALI_TEST_EQUALS( dummy.mCustomSlot1Called, true, TEST_LOCATION ); - DALI_TEST_EQUALS( dummy.mCustomSlot1Value, newSize, TEST_LOCATION ); + Stage::GetCurrent().Add( actor ); + DALI_TEST_EQUALS( dummyImpl->mCustomSlot1Called, true, TEST_LOCATION ); + Stage::GetCurrent().Remove( actor ); } // dummyControl automatically disconnects - DALI_TEST_EQUALS( actor.SetSizeSignal().GetConnectionCount(), 0u, TEST_LOCATION ); + DALI_TEST_EQUALS( actor.OnStageSignal().GetConnectionCount(), 0u, TEST_LOCATION ); const Vector3 ignoredSize( 20, 20, 0 ); actor.SetSize( ignoredSize ); @@ -321,30 +366,19 @@ int UtcDaliControlTestParameters(void) ToolkitTestApplication application; DummyControl test = DummyControl::New(); - Vector3 maxSize = test.GetNaturalSize(); - Vector3 minSize = maxSize / 2.0f; + test.SetSize( 0.7f, 0.7f, 0.7f ); - Toolkit::Control::SizePolicy widthPolicy( Control::Fixed ); - Toolkit::Control::SizePolicy heightPolicy( Control::Fixed ); - test.SetSizePolicy( widthPolicy, heightPolicy ); - test.GetSizePolicy( widthPolicy, heightPolicy ); + Stage::GetCurrent().Add( test ); - DALI_TEST_CHECK( widthPolicy == Control::Fixed && heightPolicy == Control::Fixed ); + application.SendNotification(); + application.Render(); - test.SetSize( 0.7f, 0.7f, 0.7f ); float width = 640.0f; float height = test.GetHeightForWidth( width ); - DALI_TEST_CHECK( test.GetWidthForHeight( height ) == width ); - - test.SetMinimumSize( minSize ); - DALI_TEST_CHECK( test.GetMinimumSize() == minSize ); - - test.SetMaximumSize( maxSize ); - DALI_TEST_CHECK( test.GetMaximumSize() == maxSize ); + DALI_TEST_EQUALS( 640.0f, height, TEST_LOCATION ); + DALI_TEST_EQUALS( 640.0f, test.GetWidthForHeight( height ), TEST_LOCATION ); test.KeyEventSignal(); - DummyControl test2 = DummyControl::New(); - dynamic_cast< ConnectionTrackerInterface& >( test2 ).GetConnectionCount(); // Provide coverage for pointer destructor Control* testControlPtr = new Control; @@ -358,13 +392,28 @@ int UtcDaliControlBackgroundColor(void) ToolkitTestApplication application; Control control = Control::New(); - DALI_TEST_CHECK( !control.GetBackgroundActor() ); DALI_TEST_EQUALS( control.GetBackgroundColor(), Color::TRANSPARENT, TEST_LOCATION ); control.SetBackgroundColor( Color::RED ); - DALI_TEST_CHECK( control.GetBackgroundActor() ); + + Property::Value propValue = control.GetProperty( Control::Property::BACKGROUND ); + Property::Map* resultMap = propValue.GetMap(); + 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 ); + control.SetBackgroundColor( 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; } @@ -373,25 +422,25 @@ int UtcDaliControlBackgroundImage(void) ToolkitTestApplication application; Control control = Control::New(); - DALI_TEST_CHECK( !control.GetBackgroundActor() ); DALI_TEST_EQUALS( control.GetBackgroundColor(), Color::TRANSPARENT, TEST_LOCATION ); - Image image = Image::New("TestImage"); - control.SetBackground( image ); - DALI_TEST_CHECK( control.GetBackgroundActor() ); - DALI_TEST_EQUALS( control.GetBackgroundColor(), Color::WHITE, TEST_LOCATION ); + Image image = ResourceImage::New("TestImage"); + control.SetBackgroundImage( image ); - control.SetBackgroundColor( Color::GREEN ); - DALI_TEST_EQUALS( control.GetBackgroundColor(), Color::GREEN, TEST_LOCATION ); + Property::Value propValue = control.GetProperty( Control::Property::BACKGROUND ); + Property::Map* resultMap = propValue.GetMap(); + 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" ); - control.ClearBackground(); - DALI_TEST_CHECK( !control.GetBackgroundActor() ); - DALI_TEST_EQUALS( control.GetBackgroundColor(), Color::TRANSPARENT, TEST_LOCATION ); + image = ResourceImage::New("TestImage2"); + control.SetBackgroundImage( image ); - control.SetBackgroundColor( Color::YELLOW ); - control.SetBackground( image ); - DALI_TEST_CHECK( control.GetBackgroundActor() ); - DALI_TEST_EQUALS( control.GetBackgroundColor(), Color::YELLOW, TEST_LOCATION ); + propValue = control.GetProperty( Control::Property::BACKGROUND ); + resultMap = propValue.GetMap(); + DALI_TEST_CHECK( resultMap->Find( ImageVisual::Property::URL ) ); + DALI_TEST_CHECK( resultMap->Find( ImageVisual::Property::URL )->Get() == "TestImage2" ); END_TEST; } @@ -401,36 +450,315 @@ int UtcDaliControlBackgroundProperties(void) ToolkitTestApplication application; Control control = Control::New(); - DALI_TEST_CHECK( !control.GetBackgroundActor() ); DALI_TEST_EQUALS( control.GetBackgroundColor(), Color::TRANSPARENT, TEST_LOCATION ); - DALI_TEST_EQUALS( control.GetProperty( Control::PROPERTY_BACKGROUND_COLOR ).Get< Vector4 >(), Color::TRANSPARENT, TEST_LOCATION ); - DALI_TEST_CHECK( control.GetProperty( Control::PROPERTY_BACKGROUND ).Get< Property::Map >().empty() ); - - control.SetProperty( Control::PROPERTY_BACKGROUND_COLOR, Color::RED ); - DALI_TEST_CHECK( control.GetBackgroundActor() ); - DALI_TEST_EQUALS( control.GetBackgroundColor(), Color::RED, TEST_LOCATION ); - DALI_TEST_EQUALS( control.GetProperty( Control::PROPERTY_BACKGROUND_COLOR ).Get< Vector4 >(), Color::RED, TEST_LOCATION ); + DALI_TEST_CHECK( control.GetProperty( Control::Property::BACKGROUND ).Get< Property::Map >().Empty() ); Property::Map imageMap; - imageMap.push_back( Property::StringValuePair( "filename", "TestImage" ) ); - Property::Map map; - map.push_back( Property::StringValuePair( "image", imageMap ) ); - control.SetProperty( Control::PROPERTY_BACKGROUND, map ); - DALI_TEST_CHECK( control.GetBackgroundActor() ); - DALI_TEST_EQUALS( control.GetBackgroundColor(), Color::RED, TEST_LOCATION ); - DALI_TEST_EQUALS( control.GetProperty( Control::PROPERTY_BACKGROUND_COLOR ).Get< Vector4 >(), Color::RED, TEST_LOCATION ); - - Property::Value propValue = control.GetProperty( Control::PROPERTY_BACKGROUND ); - DALI_TEST_CHECK( propValue.HasKey( "image" ) ); - DALI_TEST_CHECK( propValue.GetValue( "image" ).HasKey( "filename" ) ); - DALI_TEST_CHECK( propValue.GetValue( "image" ).GetValue( "filename" ).Get< std::string>() == "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( 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[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( 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.GetBackgroundActor() ); - DALI_TEST_EQUALS( control.GetBackgroundColor(), Color::TRANSPARENT, TEST_LOCATION ); - DALI_TEST_EQUALS( control.GetProperty( Control::PROPERTY_BACKGROUND_COLOR ).Get< Vector4 >(), Color::TRANSPARENT, TEST_LOCATION ); - DALI_TEST_CHECK( control.GetProperty( Control::PROPERTY_BACKGROUND ).Get< Property::Map >().empty() ); + 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 ); + + // 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 ); + + control.ClearBackground(); + + Property::Map deprecatedImageMap; + deprecatedImageMap[ "filename" ] = "TestImage"; + control.SetProperty( Control::Property::BACKGROUND_IMAGE, deprecatedImageMap ); + propValue = control.GetProperty( Control::Property::BACKGROUND_IMAGE ); + resultMap = propValue.GetMap(); + 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() ); + + END_TEST; +} + +int UtcDaliControlKeyProperties(void) +{ + ToolkitTestApplication application; + + Control control = Control::New(); + Stage::GetCurrent().Add( control ); + + DALI_TEST_EQUALS( control.HasKeyInputFocus(), control.GetProperty( Control::Property::KEY_INPUT_FOCUS ).Get< bool >(), TEST_LOCATION ); + + control.SetKeyInputFocus(); + DALI_TEST_EQUALS( true, control.GetProperty( Control::Property::KEY_INPUT_FOCUS ).Get< bool >(), TEST_LOCATION ); + + control.ClearKeyInputFocus(); + DALI_TEST_EQUALS( false, control.GetProperty( Control::Property::KEY_INPUT_FOCUS ).Get< bool >(), TEST_LOCATION ); + + control.SetProperty( Control::Property::KEY_INPUT_FOCUS, true ); + DALI_TEST_EQUALS( true, control.HasKeyInputFocus(), TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliControlGestureSignals(void) +{ + ToolkitTestApplication application; + ConnectionTracker connectionTracker; + Control control = Control::New(); + + // Each gesture detector gets created when connecting to the gesture signals + DALI_TEST_CHECK( !control.GetTapGestureDetector() ); + control.ConnectSignal( &connectionTracker, "tapped", &TestVoidCallback ); + DALI_TEST_CHECK( control.GetTapGestureDetector() ); + + DALI_TEST_CHECK( !control.GetPanGestureDetector() ); + control.ConnectSignal( &connectionTracker, "panned", &TestVoidCallback ); + DALI_TEST_CHECK( control.GetPanGestureDetector() ); + + DALI_TEST_CHECK( !control.GetPinchGestureDetector() ); + control.ConnectSignal( &connectionTracker, "pinched", &TestVoidCallback ); + DALI_TEST_CHECK( control.GetPinchGestureDetector() ); + + DALI_TEST_CHECK( !control.GetLongPressGestureDetector() ); + control.ConnectSignal( &connectionTracker, "longPressed", &TestVoidCallback ); + DALI_TEST_CHECK( control.GetLongPressGestureDetector() ); + + END_TEST; +} + +int UtcDaliControlImplKeyInputFocusGainedSignal(void) +{ + ToolkitTestApplication application; + + Control control = Control::New(); + Stage::GetCurrent().Add( control ); + + gKeyInputFocusCallBackCalled = false; + control.KeyInputFocusGainedSignal().Connect(&TestKeyInputFocusCallback); + + application.SendNotification(); + application.Render(); + + control.SetKeyInputFocus(); + + DALI_TEST_CHECK( control.HasKeyInputFocus() ); + + DALI_TEST_CHECK( gKeyInputFocusCallBackCalled ); + + END_TEST; +} + +int UtcDaliControlImplKeyInputFocusLostSignal(void) +{ + ToolkitTestApplication application; + + Control control = Control::New(); + Stage::GetCurrent().Add( control ); + + gKeyInputFocusCallBackCalled = false; + control.KeyInputFocusLostSignal().Connect(&TestKeyInputFocusCallback); + + application.SendNotification(); + application.Render(); + + control.SetKeyInputFocus(); + + DALI_TEST_CHECK( control.HasKeyInputFocus() ); + + control.ClearKeyInputFocus(); + + DALI_TEST_CHECK( gKeyInputFocusCallBackCalled ); + + END_TEST; +} + +int UtcDaliControlImplGetControlExtensionP(void) +{ + ToolkitTestApplication application; + Control control = Control::New(); + + Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( control ); + + DALI_TEST_CHECK( NULL == controlImpl.GetControlExtension() ); + + 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; }