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-Button.cpp;h=e99c8f7e3493d39208bebd9b4b54605a9b4f92d5;hp=79d5cef296d5941215af459f00291424c5f4d1f6;hb=268f651469300b3950b3f314fa33803b6c24273e;hpb=190a30974e11c5792335e3b0493bf1c212beec6a diff --git a/automated-tests/src/dali-toolkit/utc-Dali-Button.cpp b/automated-tests/src/dali-toolkit/utc-Dali-Button.cpp index 79d5cef..e99c8f7 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-Button.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-Button.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 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. @@ -28,8 +28,6 @@ #include #include -#include -#include using namespace Dali; using namespace Toolkit; @@ -48,8 +46,7 @@ void utc_dali_toolkit_button_cleanup(void) namespace { static bool gIsCalledButtonCallback = false; - -const int RENDER_FRAME_INTERVAL = 16; +static bool gIsCalledChildButtonCallback = false; static bool ButtonCallback( Button button ) { @@ -57,6 +54,12 @@ static bool ButtonCallback( Button button ) return false; } +static bool ChildButtonCallback( Button button ) +{ + gIsCalledChildButtonCallback = true; + return false; +} + static std::string GetButtonText( Button button ) { Property::Value value = button.GetProperty( Toolkit::Button::Property::LABEL ); @@ -136,8 +139,6 @@ Dali::Integration::Point GetPointUpOutside() return point; } -static float ANIMATION_TIME( 0.5f ); - } // namespace int UtcDaliButtonConstructorP(void) @@ -162,6 +163,25 @@ int UtcDaliButtonCopyConstructorP(void) END_TEST; } +int UtcDaliButtonMoveConstructor(void) +{ + ToolkitTestApplication application; + + Button button = PushButton::New(); + DALI_TEST_EQUALS( 1, button.GetBaseObject().ReferenceCount(), TEST_LOCATION ); + DALI_TEST_EQUALS( button.GetProperty( Button::Property::TOGGLABLE ), false , TEST_LOCATION ); + button.SetProperty( Button::Property::TOGGLABLE, true ); + DALI_TEST_EQUALS( button.GetProperty( Button::Property::TOGGLABLE ), true , TEST_LOCATION ); + + Button moved = std::move( button ); + DALI_TEST_CHECK( moved ); + DALI_TEST_EQUALS( 1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION ); + DALI_TEST_EQUALS( moved.GetProperty( Button::Property::TOGGLABLE ), true , TEST_LOCATION ); + DALI_TEST_CHECK( !button ); + + END_TEST; +} + int UtcDaliButtonAssignmentOperatorP(void) { TestApplication application; @@ -175,6 +195,26 @@ int UtcDaliButtonAssignmentOperatorP(void) END_TEST; } +int UtcDaliButtonMoveAssignment(void) +{ + ToolkitTestApplication application; + + Button button = PushButton::New(); + DALI_TEST_EQUALS( 1, button.GetBaseObject().ReferenceCount(), TEST_LOCATION ); + DALI_TEST_EQUALS( button.GetProperty( Button::Property::TOGGLABLE ), false , TEST_LOCATION ); + button.SetProperty( Button::Property::TOGGLABLE, true ); + DALI_TEST_EQUALS( button.GetProperty( Button::Property::TOGGLABLE ), true , TEST_LOCATION ); + + Button moved; + moved = std::move( button ); + DALI_TEST_CHECK( moved ); + DALI_TEST_EQUALS( 1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION ); + DALI_TEST_EQUALS( moved.GetProperty( Button::Property::TOGGLABLE ), true , TEST_LOCATION ); + DALI_TEST_CHECK( !button ); + + END_TEST; +} + int UtcDaliButtonDownCastP(void) { TestApplication application; @@ -274,7 +314,7 @@ int UtcDaliButtonSetDisabledWithDifferentStates02P(void) DALI_TEST_EQUALS( isSelected, SELECTED , TEST_LOCATION ); tet_infoline("Set button to DISABLED = false whilst disabled and then set to unselected\n"); - button.SetProperty( Button::Property::DISABLED, false ); + button.SetProperty( Button::Property::DISABLED, false); button.SetProperty( Button::Property::SELECTED, !SELECTED ); isSelected = button.GetProperty( Button::Property::SELECTED ); @@ -301,13 +341,13 @@ int UtcDaliButtonIsDisabledP(void) Button button = PushButton::New(); - button.SetDisabled( true ); + button.SetProperty( Button::Property::DISABLED, true); - DALI_TEST_CHECK( button.IsDisabled() ); + DALI_TEST_EQUALS( button.GetProperty( Button::Property::DISABLED ), true, TEST_LOCATION ); - button.SetDisabled( false ); + button.SetProperty( Button::Property::DISABLED, false); - DALI_TEST_CHECK( !button.IsDisabled() ); + DALI_TEST_EQUALS( button.GetProperty( Button::Property::DISABLED ), false, TEST_LOCATION ); END_TEST; } @@ -329,9 +369,6 @@ int UtcDaliButtonAutoRepeatingPropertyP(void) DALI_TEST_EQUALS( button.GetProperty( button.GetPropertyIndex("autoRepeating")), true, TEST_LOCATION ); - button.SetAutoRepeating( false ); - - DALI_TEST_CHECK( !button.IsAutoRepeating() ); END_TEST; } @@ -341,13 +378,14 @@ int UtcDaliButtonIsAutoRepeatingP(void) Button button = PushButton::New(); - button.SetAutoRepeating( true ); + button.SetProperty( Button::Property::AUTO_REPEATING, true); - DALI_TEST_CHECK( button.IsAutoRepeating() ); + DALI_TEST_EQUALS( button.GetProperty( Button::Property::AUTO_REPEATING ), true, TEST_LOCATION ); - button.SetAutoRepeating( false ); + button.SetProperty( Button::Property::AUTO_REPEATING, false); + + DALI_TEST_EQUALS( button.GetProperty( Button::Property::AUTO_REPEATING ), false, TEST_LOCATION ); - DALI_TEST_CHECK( !button.IsAutoRepeating() ); END_TEST; } @@ -359,11 +397,11 @@ int UtcDaliButtonAutoRepeatingP(void) const float AUTO_REPEATING_DELAY = 0.15f; Button button = PushButton::New(); - button.SetAnchorPoint( AnchorPoint::TOP_LEFT ); - button.SetParentOrigin( ParentOrigin::TOP_LEFT ); - button.SetPosition( 240, 400 ); - button.SetSize( 100, 100 ); - Stage::GetCurrent().Add( button ); + button.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); + button.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); + button.SetProperty( Actor::Property::POSITION, Vector2( 240, 400 )); + button.SetProperty( Actor::Property::SIZE, Vector2( 100, 100 ) ); + application.GetScene().Add( button ); application.SendNotification(); application.Render(); @@ -477,26 +515,13 @@ int UtcDaliButtonSelectedPropertyP(void) END_TEST; } -int UtcDaliButtonSetAnimationTimeP(void) -{ - ToolkitTestApplication application; - tet_infoline(" UtcDaliButtonSetAnimationTimeP"); - - Button button = PushButton::New(); - - button.SetAnimationTime( ANIMATION_TIME ); - - DALI_TEST_EQUALS( button.GetAnimationTime(), ANIMATION_TIME, TEST_LOCATION ); - END_TEST; -} - int UtcDaliButtonSetLabelStringWithPropertyMapP(void) { ToolkitTestApplication application; Button button = PushButton::New(); button.SetProperty( Toolkit::Button::Property::LABEL, - Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::DevelVisual::TEXT ) + Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::TEXT ) .Add( Toolkit::TextVisual::Property::POINT_SIZE, 15.0f ) .Add( Toolkit::TextVisual::Property::TEXT, "Button Label") ); @@ -525,7 +550,7 @@ int UtcDaliButtonSetLabelStringWithPropertyMapStringsP(void) tet_infoline(" UtcDaliButtonSetLabelStringWithPropertyMapStringsP Intermediate part of test"); Property::Map propertyMap; - propertyMap.Insert( Toolkit::Visual::Property::TYPE, Toolkit::DevelVisual::TEXT ); + propertyMap.Insert( Toolkit::Visual::Property::TYPE, Toolkit::Visual::TEXT ); propertyMap.Insert( Toolkit::TextVisual::Property::TEXT, "error if this is the final text" ); propertyMap.Insert( Toolkit::TextVisual::Property::POINT_SIZE, 15.0f ); @@ -554,7 +579,7 @@ int UtcDaliButtonSetLabelWithStringP(void) // Set default point size for text visual as style sheet not available. button.SetProperty( Toolkit::Button::Property::LABEL, - Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::DevelVisual::TEXT ) + Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::TEXT ) .Add( Toolkit::TextVisual::Property::POINT_SIZE, 15.0f ) ); @@ -577,7 +602,7 @@ int UtcDaliButtonSetLabelPropertyP(void) Button button = PushButton::New(); button.SetProperty( Toolkit::Button::Property::LABEL, - Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::DevelVisual::TEXT ) + Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::TEXT ) .Add( Toolkit::TextVisual::Property::POINT_SIZE, 15.0f ) .Add( Toolkit::TextVisual::Property::TEXT, TEST_LABEL1 ) ); @@ -585,7 +610,7 @@ int UtcDaliButtonSetLabelPropertyP(void) DALI_TEST_EQUALS( GetButtonText( button ), TEST_LABEL1, TEST_LOCATION ); Property::Map propertyMap; - propertyMap.Insert( Toolkit::Visual::Property::TYPE, Toolkit::DevelVisual::TEXT ); + propertyMap.Insert( Toolkit::Visual::Property::TYPE, Toolkit::Visual::TEXT ); propertyMap.Insert( Toolkit::TextVisual::Property::TEXT, TEST_LABEL2 ); propertyMap.Insert( Toolkit::TextVisual::Property::TEXT_COLOR, Color::BLUE ); propertyMap.Insert( Toolkit::TextVisual::Property::POINT_SIZE, 15.0f ); @@ -602,12 +627,12 @@ int UtcDaliButtonPressedSignalP(void) tet_infoline(" UtcDaliButtonPressedSignalP"); Button button = PushButton::New(); - button.SetAnchorPoint( AnchorPoint::TOP_LEFT ); - button.SetParentOrigin( ParentOrigin::TOP_LEFT ); - button.SetPosition( 240, 400 ); - button.SetSize( 100, 100 ); + button.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); + button.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); + button.SetProperty( Actor::Property::POSITION, Vector2( 240, 400 )); + button.SetProperty( Actor::Property::SIZE, Vector2( 100, 100 ) ); - Stage::GetCurrent().Add( button ); + application.GetScene().Add( button ); application.SendNotification(); application.Render(); @@ -709,12 +734,12 @@ int UtcDaliButtonClickedSignalP(void) tet_infoline(" UtcDaliButtonClickedSignalP"); Button button = PushButton::New(); - button.SetAnchorPoint( AnchorPoint::TOP_LEFT ); - button.SetParentOrigin( ParentOrigin::TOP_LEFT ); - button.SetPosition( 240, 400 ); - button.SetSize( 100, 100 ); + button.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); + button.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); + button.SetProperty( Actor::Property::POSITION, Vector2( 240, 400 )); + button.SetProperty( Actor::Property::SIZE, Vector2( 100, 100 ) ); - Stage::GetCurrent().Add( button ); + application.GetScene().Add( button ); application.SendNotification(); application.Render(); @@ -805,7 +830,7 @@ int UtcDaliButtonStateChangedSignalP(void) button.SetProperty( Button::Property::TOGGLABLE, true); - Stage::GetCurrent().Add( button ); + application.GetScene().Add( button ); application.SendNotification(); application.Render(); @@ -848,117 +873,177 @@ int UtcDaliButtonSetProperty(void) END_TEST; } -// Deprecated API Tests - -int UtcDaliButtonSetDisabledP(void) +int UtcDaliButtonEventConsumption(void) { - ToolkitTestApplication application; + /** + * [ Parent ] + * [ Child ] + * + * Child parented and positioned under parent. + * Touch up and down performed on child. + * Should only trigger signal on child. + */ - Button button = PushButton::New(); + ToolkitTestApplication application; - button.SetDisabled( true ); + Button parentButton = PushButton::New(); + parentButton.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); + parentButton.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); + parentButton.SetProperty( Actor::Property::SIZE, Vector2( 20, 20 ) ); + application.GetScene().Add( parentButton ); - DALI_TEST_CHECK( button.IsDisabled() ); + Button childButton = PushButton::New(); + childButton.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); + childButton.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_LEFT ); + childButton.SetProperty( Actor::Property::SIZE, Vector2( 20, 20 ) ); + parentButton.Add( childButton ); - button.SetDisabled( false ); + // Reset signal flags + gIsCalledChildButtonCallback = false; + gIsCalledButtonCallback = false; - DALI_TEST_CHECK( !button.IsDisabled() ); + parentButton.ClickedSignal().Connect( &ButtonCallback ); + childButton.ClickedSignal().Connect( &ChildButtonCallback ); - button.SetDisabled( true ); + // Peform a button click at coordinates (10,30) which is the child. + Dali::Integration::TouchEvent event; + event = Dali::Integration::TouchEvent(); + Dali::Integration::Point point; + point.SetState( PointState::DOWN ); + point.SetScreenPosition( Vector2( 10, 30 ) ); + event.AddPoint( point ); + // flush the queue and render once + application.SendNotification(); + application.Render(); + application.ProcessEvent( event ); - DALI_TEST_CHECK( button.IsDisabled() ); + event = Dali::Integration::TouchEvent(); + point.SetState( PointState::UP ); + point.SetScreenPosition( Vector2( 10, 30 ) ); + event.AddPoint( point ); + // flush the queue and render once + application.SendNotification(); + application.Render(); + application.ProcessEvent( event ); - button.SetDisabled( false ); + DALI_TEST_EQUALS( gIsCalledChildButtonCallback, true, TEST_LOCATION ); + DALI_TEST_EQUALS( ! gIsCalledButtonCallback, true, TEST_LOCATION ); - DALI_TEST_CHECK( !button.IsDisabled() ); END_TEST; } -int UtcDaliButtonSetAutoRepeatingP(void) +int UtcDaliButtonRelease(void) { - ToolkitTestApplication application; + /** + * Down event followed by interrupted event should signal Release. + */ - Button button = PushButton::New(); - - button.SetAutoRepeating( true ); - - DALI_TEST_CHECK( button.IsAutoRepeating() ); + ToolkitTestApplication application; - button.SetAutoRepeating( false ); + Button parentButton = PushButton::New(); + parentButton.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); + parentButton.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); + parentButton.SetProperty( Actor::Property::SIZE, Vector2( 20, 20 ) ); + application.GetScene().Add( parentButton ); + parentButton.ReleasedSignal().Connect( &ButtonCallback ); - DALI_TEST_CHECK( !button.IsAutoRepeating() ); + // Reset signal flags + gIsCalledButtonCallback = false; - button.SetAutoRepeating( true ); + // Peform a button down and then button interrupted at coordinates (10,10). + Dali::Integration::TouchEvent event; + event = Dali::Integration::TouchEvent(); + Dali::Integration::Point point; + point.SetState( PointState::DOWN ); + point.SetScreenPosition( Vector2( 10, 10 ) ); + event.AddPoint( point ); + // flush the queue and render once + application.SendNotification(); + application.Render(); + application.ProcessEvent( event ); - DALI_TEST_CHECK( button.IsAutoRepeating() ); + event = Dali::Integration::TouchEvent(); + point.SetState( PointState::INTERRUPTED ); + event.AddPoint( point ); + // flush the queue and render once + application.SendNotification(); + application.Render(); + application.ProcessEvent( event ); - button.SetAutoRepeating( false ); + DALI_TEST_EQUALS( gIsCalledButtonCallback, true, TEST_LOCATION ); - DALI_TEST_CHECK( !button.IsAutoRepeating() ); END_TEST; } -int UtcDaliButtonSetInitialAutoRepeatingDelayP(void) +int UtcDaliButtonMultiTouch(void) { - ToolkitTestApplication application; - - Button button = PushButton::New(); - - button.SetInitialAutoRepeatingDelay( 0.5f ); - - DALI_TEST_EQUALS( button.GetInitialAutoRepeatingDelay(), 0.5f, TEST_LOCATION ); + /** + * Down event followed by a multi touch point event should signal Release. + */ - button.SetInitialAutoRepeatingDelay( 0.2f ); - - DALI_TEST_EQUALS( button.GetInitialAutoRepeatingDelay(), 0.2f, TEST_LOCATION ); - END_TEST; -} - -int UtcDaliButtonSetNextAutoRepeatingDelayP(void) -{ ToolkitTestApplication application; Button button = PushButton::New(); + button.SetProperty( Button::Property::TOGGLABLE, true); - button.SetNextAutoRepeatingDelay( 0.5f ); - - DALI_TEST_EQUALS( button.GetNextAutoRepeatingDelay(), 0.5f, TEST_LOCATION ); - - button.SetProperty( Button::Property::NEXT_AUTO_REPEATING_DELAY, 0.2f ); - - DALI_TEST_EQUALS( button.GetNextAutoRepeatingDelay(), 0.2f, TEST_LOCATION ); - END_TEST; -} - -int UtcDaliButtonSetTogglableButtonP(void) -{ - ToolkitTestApplication application; + button.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); + button.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); + button.SetProperty( Actor::Property::SIZE, Vector2( 20, 20 ) ); + application.GetScene().Add( button ); + button.ReleasedSignal().Connect( &ButtonCallback ); - Button button = PushButton::New(); + // Reset signal flags + gIsCalledButtonCallback = false; - button.SetTogglableButton( true ); + // Peform a button down and then button interrupted at coordinates (10,10). + Dali::Integration::TouchEvent downEvent; + downEvent = Dali::Integration::TouchEvent(); + Dali::Integration::Point point; - DALI_TEST_CHECK( button.IsTogglableButton() ); + // Add Press button + point.SetState( PointState::DOWN ); + point.SetScreenPosition( Vector2( 15, 15 ) ); + downEvent.AddPoint( point ); + // flush the queue and render once + application.SendNotification(); + application.Render(); + application.ProcessEvent( downEvent ); - button.SetTogglableButton( false ); + // Release button + Dali::Integration::TouchEvent upEvent; + upEvent = Dali::Integration::TouchEvent(); + point.SetState( PointState::UP ); + point.SetScreenPosition( Vector2( 15, 15 ) ); + upEvent.AddPoint( point ); + // flush the queue and render once + application.SendNotification(); + application.Render(); + application.ProcessEvent( upEvent ); - DALI_TEST_CHECK( !button.IsTogglableButton() ); - END_TEST; -} + tet_infoline("Button should now be selected\n"); + bool isSelected = button.GetProperty( Button::Property::SELECTED ) ; + DALI_TEST_EQUALS( isSelected, true, TEST_LOCATION ); -int UtcDaliButtonSetSelectedP(void) -{ - ToolkitTestApplication application; + // Add first point + Dali::Integration::TouchEvent multiEvent; + multiEvent = Dali::Integration::TouchEvent(); + point.SetState( PointState::DOWN ); + point.SetScreenPosition( Vector2( 10, 10 ) ); + multiEvent.AddPoint( point ); - Button button = PushButton::New(); - button.SetTogglableButton( true ); + // Add second point + point.SetState( PointState::DOWN ); + point.SetScreenPosition( Vector2( 15, 15 ) ); + multiEvent.AddPoint( point ); - button.SetSelected( true ); + tet_infoline("Before a multi touch event\n"); - DALI_TEST_CHECK( button.IsSelected() ); + // flush the queue and render once + application.SendNotification(); + application.Render(); + application.ProcessEvent( multiEvent ); - button.SetSelected( false ); + DALI_TEST_EQUALS( gIsCalledButtonCallback, true, TEST_LOCATION ); - DALI_TEST_CHECK( !button.IsSelected() ); END_TEST; }