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-RadioButton.cpp;h=606241548c740640f8b034d34ec038213c440a79;hp=85c791a498ff0542d5cd57e6ac375f4849043177;hb=HEAD;hpb=c01f2590ed7bb00d9b3600511d08dc420261ed46 diff --git a/automated-tests/src/dali-toolkit/utc-Dali-RadioButton.cpp b/automated-tests/src/dali-toolkit/utc-Dali-RadioButton.cpp index 85c791a..20d20e3 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-RadioButton.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-RadioButton.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 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. @@ -15,12 +15,11 @@ * */ -#include -#include #include #include #include - +#include +#include using namespace Dali; using namespace Dali::Toolkit; @@ -37,7 +36,6 @@ void dali_radio_button_cleanup(void) namespace { - static bool gObjectCreatedCallBackCalled; static void TestCallback(BaseHandle handle) @@ -45,57 +43,96 @@ static void TestCallback(BaseHandle handle) gObjectCreatedCallBackCalled = true; } -static std::string GetButtonText( Button button ) +static std::string GetButtonText(Button button) { - Property::Value value = button.GetProperty( Toolkit::Button::Property::LABEL ); + Property::Value value = button.GetProperty(Toolkit::Button::Property::LABEL); - Property::Map *labelProperty = value.GetMap(); + Property::Map* labelProperty = value.GetMap(); std::string textLabel; - if ( labelProperty ) + if(labelProperty) { - Property::Value* value = labelProperty->Find( Toolkit::TextVisual::Property::TEXT ); - value->Get( textLabel ); + Property::Value* value = labelProperty->Find(Toolkit::TextVisual::Property::TEXT); + value->Get(textLabel); } return textLabel; } -} +} // namespace int UtcDaliRadioButtonConstructorP(void) { - TestApplication application; + ToolkitTestApplication application; RadioButton button; - DALI_TEST_CHECK( !button ); + DALI_TEST_CHECK(!button); END_TEST; } int UtcDaliRadioButtonCopyConstructorP(void) { - TestApplication application; + ToolkitTestApplication application; // Initialize an object, ref count == 1 RadioButton button = RadioButton::New(); - RadioButton copy( button ); - DALI_TEST_CHECK( copy ); + RadioButton copy(button); + DALI_TEST_CHECK(copy); + END_TEST; +} + +int UtcDaliRadioButtonMoveConstructor(void) +{ + ToolkitTestApplication application; + + RadioButton button = RadioButton::New(); + DALI_TEST_EQUALS(1, button.GetBaseObject().ReferenceCount(), TEST_LOCATION); + DALI_TEST_EQUALS(button.GetProperty(Button::Property::TOGGLABLE), true, TEST_LOCATION); + button.SetProperty(Button::Property::TOGGLABLE, false); + DALI_TEST_EQUALS(button.GetProperty(Button::Property::TOGGLABLE), false, TEST_LOCATION); + + RadioButton 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), false, TEST_LOCATION); + DALI_TEST_CHECK(!button); + END_TEST; } int UtcDaliRadioButtonAssignmentOperatorP(void) { - TestApplication application; + ToolkitTestApplication application; RadioButton button = RadioButton::New(); - RadioButton copy( button ); - DALI_TEST_CHECK( copy ); + RadioButton copy(button); + DALI_TEST_CHECK(copy); + + DALI_TEST_CHECK(button == copy); + END_TEST; +} + +int UtcDaliRadioButtonMoveAssignment(void) +{ + ToolkitTestApplication application; + + RadioButton button = RadioButton::New(); + DALI_TEST_EQUALS(1, button.GetBaseObject().ReferenceCount(), TEST_LOCATION); + DALI_TEST_EQUALS(button.GetProperty(Button::Property::TOGGLABLE), true, TEST_LOCATION); + button.SetProperty(Button::Property::TOGGLABLE, false); + DALI_TEST_EQUALS(button.GetProperty(Button::Property::TOGGLABLE), false, TEST_LOCATION); + + RadioButton 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), false, TEST_LOCATION); + DALI_TEST_CHECK(!button); - DALI_TEST_CHECK( button == copy ); END_TEST; } @@ -107,26 +144,26 @@ int UtcDaliRadioButtonNewP(void) // Create the Slider actor RadioButton radioButton; - DALI_TEST_CHECK( !radioButton ); + DALI_TEST_CHECK(!radioButton); radioButton = RadioButton::New(); - DALI_TEST_CHECK( radioButton ); + DALI_TEST_CHECK(radioButton); RadioButton radioButton2(radioButton); - DALI_TEST_CHECK( radioButton2 == radioButton ); + DALI_TEST_CHECK(radioButton2 == radioButton); //Additional check to ensure object is created by checking if it's registered - ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry(); - DALI_TEST_CHECK( registry ); + ObjectRegistry registry = application.GetCore().GetObjectRegistry(); + DALI_TEST_CHECK(registry); gObjectCreatedCallBackCalled = false; - registry.ObjectCreatedSignal().Connect( &TestCallback ); + registry.ObjectCreatedSignal().Connect(&TestCallback); { RadioButton radioButton = RadioButton::New(); } - DALI_TEST_CHECK( gObjectCreatedCallBackCalled ); + DALI_TEST_CHECK(gObjectCreatedCallBackCalled); END_TEST; } @@ -137,7 +174,7 @@ int UtcDaliRadioButtonDestructorP(void) RadioButton* radioButton = new RadioButton(); delete radioButton; - DALI_TEST_CHECK( true ); + DALI_TEST_CHECK(true); END_TEST; } @@ -147,9 +184,9 @@ int UtcDaliRadioButtonDownCast(void) Handle handle = RadioButton::New(); - RadioButton radioButton = RadioButton::DownCast( handle ); + RadioButton radioButton = RadioButton::DownCast(handle); - DALI_TEST_CHECK( radioButton == handle ); + DALI_TEST_CHECK(radioButton == handle); END_TEST; } @@ -161,77 +198,74 @@ int UtcDaliRadioButtonLabelProperty(void) RadioButton radioButton = RadioButton::New(); - radioButton.SetProperty( Toolkit::Button::Property::LABEL, - Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::TEXT ) - .Add( Toolkit::TextVisual::Property::POINT_SIZE, 15.0f ) - ); - - radioButton.SetProperty( Toolkit::Button::Property::LABEL, labelText ); - DALI_TEST_EQUALS( GetButtonText( radioButton ), labelText, TEST_LOCATION ); + radioButton.SetProperty(Toolkit::Button::Property::LABEL, + Property::Map().Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::TEXT).Add(Toolkit::TextVisual::Property::POINT_SIZE, 15.0f)); + radioButton.SetProperty(Toolkit::Button::Property::LABEL, labelText); + DALI_TEST_EQUALS(GetButtonText(radioButton), labelText, TEST_LOCATION); std::string labelText2 = "test actor 2"; - radioButton.SetProperty( Toolkit::Button::Property::LABEL, labelText2 ); + radioButton.SetProperty(Toolkit::Button::Property::LABEL, labelText2); - DALI_TEST_EQUALS( GetButtonText( radioButton ), labelText2, TEST_LOCATION ); + DALI_TEST_EQUALS(GetButtonText(radioButton), labelText2, TEST_LOCATION); END_TEST; } int UtcDaliRadioButtonSelectedProperty(void) { - ToolkitTestApplication application; // Exceptions require ToolkitTestApplication + ToolkitTestApplication application; // Exceptions require ToolkitTestApplication tet_infoline(" UtcDaliRadioButtonSelectedProperty"); // Create the RadioButton actor RadioButton radioButton = RadioButton::New(); - Stage::GetCurrent().Add( radioButton ); - radioButton.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::TOP_LEFT); - radioButton.SetProperty( Actor::Property::ANCHOR_POINT,ParentOrigin::TOP_LEFT); - radioButton.SetPosition( 0.0f, 0.0f ); + application.GetScene().Add(radioButton); + radioButton.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT); + radioButton.SetProperty(Actor::Property::ANCHOR_POINT, ParentOrigin::TOP_LEFT); + radioButton.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 0.0f)); // Default selected - DALI_TEST_CHECK( radioButton.GetProperty( Button::Property::SELECTED ) == false ); + DALI_TEST_CHECK(radioButton.GetProperty(Button::Property::SELECTED) == false); // Setting false selected - radioButton.SetProperty( Button::Property::SELECTED, false ); - DALI_TEST_CHECK( radioButton.GetProperty( Button::Property::SELECTED ) == false ); + radioButton.SetProperty(Button::Property::SELECTED, false); + DALI_TEST_CHECK(radioButton.GetProperty(Button::Property::SELECTED) == false); // Setting true selected - radioButton.SetProperty( Button::Property::SELECTED, true ); - DALI_TEST_CHECK( radioButton.GetProperty( Button::Property::SELECTED ) == true ); + radioButton.SetProperty(Button::Property::SELECTED, true); + DALI_TEST_CHECK(radioButton.GetProperty(Button::Property::SELECTED) == true); // Setting false again - radioButton.SetProperty( Button::Property::SELECTED, false ); - DALI_TEST_CHECK( radioButton.GetProperty( Button::Property::SELECTED ) == false ); + radioButton.SetProperty(Button::Property::SELECTED, false); + DALI_TEST_CHECK(radioButton.GetProperty(Button::Property::SELECTED) == false); // Test selecting radio buttons - RadioButton radioButton2 = RadioButton::New( "label" ); - radioButton2.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::TOP_LEFT); - radioButton2.SetProperty( Actor::Property::ANCHOR_POINT,ParentOrigin::TOP_LEFT); - radioButton2.SetPosition( 0.0f, 0.0f ); + RadioButton radioButton2 = RadioButton::New("label"); + radioButton2.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT); + radioButton2.SetProperty(Actor::Property::ANCHOR_POINT, ParentOrigin::TOP_LEFT); + radioButton2.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 0.0f)); - RadioButton radioButton3 = RadioButton::New( "label" ); - radioButton3.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::TOP_LEFT); - radioButton3.SetProperty( Actor::Property::ANCHOR_POINT,ParentOrigin::TOP_LEFT); - radioButton3.SetPosition( 0.0f, 40.0f ); + RadioButton radioButton3 = RadioButton::New("label"); + radioButton3.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT); + radioButton3.SetProperty(Actor::Property::ANCHOR_POINT, ParentOrigin::TOP_LEFT); + radioButton3.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 40.0f)); Actor radioGroup = Actor::New(); - Stage::GetCurrent().Add( radioGroup ); - radioGroup.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::TOP_LEFT); - radioGroup.SetProperty( Actor::Property::ANCHOR_POINT,ParentOrigin::TOP_LEFT); - radioGroup.SetPosition( 0.0f, 0.0f ); - radioGroup.SetSize( 400.0f, 400.0 ); + application.GetScene().Add(radioGroup); + radioGroup.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT); + radioGroup.SetProperty(Actor::Property::ANCHOR_POINT, ParentOrigin::TOP_LEFT); + radioGroup.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 0.0f)); + radioGroup.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0)); - radioGroup.Add( radioButton2 ); - radioGroup.Add( radioButton3 ); + radioGroup.Add(radioButton2); + radioGroup.Add(radioButton3); application.SendNotification(); application.Render(); // Simulate touch events - DALI_TEST_CHECK( radioButton2.GetProperty( Button::Property::SELECTED ) == false ); - DALI_TEST_CHECK( radioButton3.GetProperty( Button::Property::SELECTED ) == false ); + DALI_TEST_CHECK(radioButton2.GetProperty(Button::Property::SELECTED) == false); + DALI_TEST_CHECK(radioButton3.GetProperty(Button::Property::SELECTED) == false); // Select first radio { @@ -239,23 +273,23 @@ int UtcDaliRadioButtonSelectedProperty(void) Dali::Integration::TouchEvent event2 = Dali::Integration::TouchEvent(); Dali::Integration::Point pointDown; - pointDown.SetState( PointState::DOWN ); - pointDown.SetScreenPosition( Vector2( 1.0f, 1.0f ) ); + pointDown.SetState(PointState::DOWN); + pointDown.SetScreenPosition(Vector2(1.0f, 1.0f)); - Dali::Integration::Point pointUp( pointDown ); - pointUp.SetState( PointState::UP ); + Dali::Integration::Point pointUp(pointDown); + pointUp.SetState(PointState::UP); - event1.AddPoint( pointDown ); - application.ProcessEvent( event1 ); + event1.AddPoint(pointDown); + application.ProcessEvent(event1); - event2.AddPoint( pointUp ); - application.ProcessEvent( event2 ); + event2.AddPoint(pointUp); + application.ProcessEvent(event2); application.SendNotification(); application.Render(); - DALI_TEST_CHECK( radioButton2.GetProperty( Button::Property::SELECTED ) == true ); - DALI_TEST_CHECK( radioButton3.GetProperty( Button::Property::SELECTED ) == false ); + DALI_TEST_CHECK(radioButton2.GetProperty(Button::Property::SELECTED) == true); + DALI_TEST_CHECK(radioButton3.GetProperty(Button::Property::SELECTED) == false); } // Select an already selected radio @@ -264,23 +298,23 @@ int UtcDaliRadioButtonSelectedProperty(void) Dali::Integration::TouchEvent event2 = Dali::Integration::TouchEvent(); Dali::Integration::Point pointDown; - pointDown.SetState( PointState::DOWN ); - pointDown.SetScreenPosition( Vector2( 1.0f, 1.0f ) ); + pointDown.SetState(PointState::DOWN); + pointDown.SetScreenPosition(Vector2(1.0f, 1.0f)); - Dali::Integration::Point pointUp( pointDown ); - pointUp.SetState( PointState::UP ); + Dali::Integration::Point pointUp(pointDown); + pointUp.SetState(PointState::UP); - event1.AddPoint( pointDown ); - application.ProcessEvent( event1 ); + event1.AddPoint(pointDown); + application.ProcessEvent(event1); - event2.AddPoint( pointUp ); - application.ProcessEvent( event2 ); + event2.AddPoint(pointUp); + application.ProcessEvent(event2); application.SendNotification(); application.Render(); - DALI_TEST_CHECK( radioButton2.GetProperty( Button::Property::SELECTED ) == true ); - DALI_TEST_CHECK( radioButton3.GetProperty( Button::Property::SELECTED ) == false ); + DALI_TEST_CHECK(radioButton2.GetProperty(Button::Property::SELECTED) == true); + DALI_TEST_CHECK(radioButton3.GetProperty(Button::Property::SELECTED) == false); } // Select second radio @@ -289,23 +323,23 @@ int UtcDaliRadioButtonSelectedProperty(void) Dali::Integration::TouchEvent event2 = Dali::Integration::TouchEvent(); Dali::Integration::Point pointDown; - pointDown.SetState( PointState::DOWN ); - pointDown.SetScreenPosition( Vector2( 1.0f, 41.0f ) ); + pointDown.SetState(PointState::DOWN); + pointDown.SetScreenPosition(Vector2(1.0f, 41.0f)); - Dali::Integration::Point pointUp( pointDown ); - pointUp.SetState( PointState::UP ); + Dali::Integration::Point pointUp(pointDown); + pointUp.SetState(PointState::UP); - event1.AddPoint( pointDown ); - application.ProcessEvent( event1 ); + event1.AddPoint(pointDown); + application.ProcessEvent(event1); - event2.AddPoint( pointUp ); - application.ProcessEvent( event2 ); + event2.AddPoint(pointUp); + application.ProcessEvent(event2); application.SendNotification(); application.Render(); - DALI_TEST_CHECK( radioButton2.GetProperty( Button::Property::SELECTED ) == false ); - DALI_TEST_CHECK( radioButton3.GetProperty( Button::Property::SELECTED ) == true ); + DALI_TEST_CHECK(radioButton2.GetProperty(Button::Property::SELECTED) == false); + DALI_TEST_CHECK(radioButton3.GetProperty(Button::Property::SELECTED) == true); } // Select outside radio group @@ -314,24 +348,24 @@ int UtcDaliRadioButtonSelectedProperty(void) Dali::Integration::TouchEvent event2 = Dali::Integration::TouchEvent(); Dali::Integration::Point pointDown; - pointDown.SetState( PointState::DOWN ); - pointDown.SetScreenPosition( Vector2( 1.0f, 500.0f ) ); + pointDown.SetState(PointState::DOWN); + pointDown.SetScreenPosition(Vector2(1.0f, 500.0f)); - Dali::Integration::Point pointUp( pointDown ); - pointUp.SetState( PointState::UP ); + Dali::Integration::Point pointUp(pointDown); + pointUp.SetState(PointState::UP); - event1.AddPoint( pointDown ); - application.ProcessEvent( event1 ); + event1.AddPoint(pointDown); + application.ProcessEvent(event1); - event2.AddPoint( pointUp ); - application.ProcessEvent( event2 ); + event2.AddPoint(pointUp); + application.ProcessEvent(event2); application.SendNotification(); application.Render(); - DALI_TEST_CHECK( radioButton2.GetProperty( Button::Property::SELECTED ) == false ); - DALI_TEST_CHECK( radioButton3.GetProperty( Button::Property::SELECTED ) == true ); + DALI_TEST_CHECK(radioButton2.GetProperty(Button::Property::SELECTED) == false); + DALI_TEST_CHECK(radioButton3.GetProperty(Button::Property::SELECTED) == true); } END_TEST; -} \ No newline at end of file +}