ImageVisual Action::Reload added
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-RadioButton.cpp
index 66bb90d..16b38f6 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014 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.
@@ -45,12 +45,64 @@ static void TestCallback(BaseHandle handle)
   gObjectCreatedCallBackCalled = true;
 }
 
+static std::string GetButtonText( Button button )
+{
+  Property::Value value = button.GetProperty( Toolkit::Button::Property::LABEL );
+
+  Property::Map *labelProperty = value.GetMap();
+
+  std::string textLabel;
+
+  if ( labelProperty )
+  {
+    Property::Value* value = labelProperty->Find( Toolkit::TextVisual::Property::TEXT );
+    value->Get( textLabel );
+  }
+
+  return textLabel;
 }
 
-int UtcDaliRadioButtonNew(void)
+}
+
+int UtcDaliRadioButtonConstructorP(void)
+{
+  TestApplication application;
+
+  RadioButton button;
+
+  DALI_TEST_CHECK( !button );
+  END_TEST;
+}
+
+int UtcDaliRadioButtonCopyConstructorP(void)
+{
+  TestApplication application;
+
+  // Initialize an object, ref count == 1
+  RadioButton button = RadioButton::New();
+
+  RadioButton copy( button );
+  DALI_TEST_CHECK( copy );
+  END_TEST;
+}
+
+int UtcDaliRadioButtonAssignmentOperatorP(void)
+{
+  TestApplication application;
+
+  RadioButton button = RadioButton::New();
+
+  RadioButton copy( button );
+  DALI_TEST_CHECK( copy );
+
+  DALI_TEST_CHECK( button == copy );
+  END_TEST;
+}
+
+int UtcDaliRadioButtonNewP(void)
 {
   ToolkitTestApplication application;
-  tet_infoline(" UtcDaliRadioButtonNew");
+  tet_infoline(" UtcDaliRadioButtonNewP");
 
   // Create the Slider actor
   RadioButton radioButton;
@@ -78,7 +130,7 @@ int UtcDaliRadioButtonNew(void)
   END_TEST;
 }
 
-int UtcDaliRadioButtonDestructor(void)
+int UtcDaliRadioButtonDestructorP(void)
 {
   ToolkitTestApplication application;
 
@@ -101,58 +153,35 @@ int UtcDaliRadioButtonDownCast(void)
   END_TEST;
 }
 
-int UtcDaliRadioButtonLabelActor(void)
+int UtcDaliRadioButtonLabelProperty(void)
 {
   ToolkitTestApplication application;
 
-  TextView actor1 = TextView::New( "test actor 1" );
-
-  RadioButton radioButton = RadioButton::New( actor1 );
-  DALI_TEST_CHECK( actor1 == radioButton.GetLabel() );
-
-  TextView actor2 = TextView::New( "test actor 2" );
-  radioButton.SetLabel( actor2 );
-  DALI_TEST_CHECK( actor2 == radioButton.GetLabel() );
-
-  END_TEST;
-}
-
-int UtcDaliRadioButtonActive(void)
-{
-  ToolkitTestApplication application;
+  const std::string labelText = "test actor 1";
 
   RadioButton radioButton = RadioButton::New();
 
-  // Default active
-  DALI_TEST_CHECK( radioButton.IsSelected() == false );
+  radioButton.SetProperty( Toolkit::Button::Property::LABEL,
+                          Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::TEXT )
+                                         .Add( Toolkit::TextVisual::Property::POINT_SIZE, 15.0f )
+                        );
 
-  // False to true
-  radioButton.ToggleState();
-  DALI_TEST_CHECK( radioButton.IsSelected() == true );
+  radioButton.SetProperty( Toolkit::Button::Property::LABEL, labelText );
+  DALI_TEST_EQUALS( GetButtonText( radioButton ), labelText, TEST_LOCATION );
 
-  // True to false
-  radioButton.ToggleState();
-  DALI_TEST_CHECK( radioButton.IsSelected() == false );
 
-  // False
-  radioButton.SetSelected( false );
-  DALI_TEST_CHECK( radioButton.IsSelected() == false );
+  std::string labelText2 = "test actor 2";
+  radioButton.SetProperty( Toolkit::Button::Property::LABEL, labelText2 );
 
-  // True
-  radioButton.SetSelected( true );
-  DALI_TEST_CHECK( radioButton.IsSelected() == true );
-
-  // False
-  radioButton.SetSelected( false );
-  DALI_TEST_CHECK( radioButton.IsSelected() == false );
+  DALI_TEST_EQUALS( GetButtonText( radioButton ), labelText2, TEST_LOCATION );
 
   END_TEST;
 }
 
-int UtcDaliRadioButtonActiveProperty(void)
+int UtcDaliRadioButtonSelectedProperty(void)
 {
   ToolkitTestApplication application;  // Exceptions require ToolkitTestApplication
-  tet_infoline(" UtcDaliRadioButtonActiveProperty");
+  tet_infoline(" UtcDaliRadioButtonSelectedProperty");
 
   // Create the RadioButton actor
   RadioButton radioButton = RadioButton::New();
@@ -161,20 +190,20 @@ int UtcDaliRadioButtonActiveProperty(void)
   radioButton.SetAnchorPoint(ParentOrigin::TOP_LEFT);
   radioButton.SetPosition( 0.0f, 0.0f );
 
-  // Default active
-  DALI_TEST_CHECK( radioButton.GetProperty<bool>( Button::PROPERTY_TOGGLED ) == false );
+  // Default selected
+  DALI_TEST_CHECK( radioButton.GetProperty<bool>( Button::Property::SELECTED ) == false );
 
-  // Setting false active
-  radioButton.SetProperty( Button::PROPERTY_TOGGLED, false );
-  DALI_TEST_CHECK( radioButton.GetProperty<bool>( Button::PROPERTY_TOGGLED ) == false );
+  // Setting false selected
+  radioButton.SetProperty( Button::Property::SELECTED, false );
+  DALI_TEST_CHECK( radioButton.GetProperty<bool>( Button::Property::SELECTED ) == false );
 
-  // Setting true active
-  radioButton.SetProperty( Button::PROPERTY_TOGGLED, true );
-  DALI_TEST_CHECK( radioButton.GetProperty<bool>( Button::PROPERTY_TOGGLED ) == true );
+  // Setting true selected
+  radioButton.SetProperty( Button::Property::SELECTED, true );
+  DALI_TEST_CHECK( radioButton.GetProperty<bool>( Button::Property::SELECTED ) == true );
 
   // Setting false again
-  radioButton.SetProperty( Button::PROPERTY_TOGGLED, false );
-  DALI_TEST_CHECK( radioButton.GetProperty<bool>( Button::PROPERTY_TOGGLED ) == false );
+  radioButton.SetProperty( Button::Property::SELECTED, false );
+  DALI_TEST_CHECK( radioButton.GetProperty<bool>( Button::Property::SELECTED ) == false );
 
   // Test selecting radio buttons
   RadioButton radioButton2 = RadioButton::New( "label" );
@@ -201,72 +230,160 @@ int UtcDaliRadioButtonActiveProperty(void)
   application.Render();
 
   // Simulate touch events
-  DALI_TEST_CHECK( radioButton2.GetProperty<bool>( Button::PROPERTY_TOGGLED ) == false );
-  DALI_TEST_CHECK( radioButton3.GetProperty<bool>( Button::PROPERTY_TOGGLED ) == false );
+  DALI_TEST_CHECK( radioButton2.GetProperty<bool>( Button::Property::SELECTED ) == false );
+  DALI_TEST_CHECK( radioButton3.GetProperty<bool>( Button::Property::SELECTED ) == false );
 
   // Select first radio
   {
-    Dali::Integration::TouchEvent event = Dali::Integration::TouchEvent();
+    Dali::Integration::TouchEvent event1 = Dali::Integration::TouchEvent();
+    Dali::Integration::TouchEvent event2 = Dali::Integration::TouchEvent();
+
+    Dali::Integration::Point pointDown;
+    pointDown.SetState( PointState::DOWN );
+    pointDown.SetScreenPosition( Vector2( 1.0f, 1.0f ) );
+
+    Dali::Integration::Point pointUp( pointDown );
+    pointUp.SetState( PointState::UP );
 
-    const Dali::TouchPoint pointUp( 0, TouchPoint::Up, 10.0f, 10.0f );
-    event.AddPoint( pointUp );
+    event1.AddPoint( pointDown );
+    application.ProcessEvent( event1 );
 
-    application.ProcessEvent( event );
+    event2.AddPoint( pointUp );
+    application.ProcessEvent( event2 );
 
     application.SendNotification();
     application.Render();
 
-    DALI_TEST_CHECK( radioButton2.GetProperty<bool>( Button::PROPERTY_TOGGLED ) == true );
-    DALI_TEST_CHECK( radioButton3.GetProperty<bool>( Button::PROPERTY_TOGGLED ) == false );
+    DALI_TEST_CHECK( radioButton2.GetProperty<bool>( Button::Property::SELECTED ) == true );
+    DALI_TEST_CHECK( radioButton3.GetProperty<bool>( Button::Property::SELECTED ) == false );
   }
 
   // Select an already selected radio
   {
-    Dali::Integration::TouchEvent event = Dali::Integration::TouchEvent();
+    Dali::Integration::TouchEvent event1 = Dali::Integration::TouchEvent();
+    Dali::Integration::TouchEvent event2 = Dali::Integration::TouchEvent();
 
-    const Dali::TouchPoint pointDown( 0, TouchPoint::Up, 10.0f, 10.0f );
-    event.AddPoint( pointDown );
+    Dali::Integration::Point pointDown;
+    pointDown.SetState( PointState::DOWN );
+    pointDown.SetScreenPosition( Vector2( 1.0f, 1.0f ) );
 
-    application.ProcessEvent( event );
+    Dali::Integration::Point pointUp( pointDown );
+    pointUp.SetState( PointState::UP );
+
+    event1.AddPoint( pointDown );
+    application.ProcessEvent( event1 );
+
+    event2.AddPoint( pointUp );
+    application.ProcessEvent( event2 );
 
     application.SendNotification();
     application.Render();
 
-    DALI_TEST_CHECK( radioButton2.GetProperty<bool>( Button::PROPERTY_TOGGLED ) == true );
-    DALI_TEST_CHECK( radioButton3.GetProperty<bool>( Button::PROPERTY_TOGGLED ) == false );
+    DALI_TEST_CHECK( radioButton2.GetProperty<bool>( Button::Property::SELECTED ) == true );
+    DALI_TEST_CHECK( radioButton3.GetProperty<bool>( Button::Property::SELECTED ) == false );
   }
 
   // Select second radio
   {
-    Dali::Integration::TouchEvent event = Dali::Integration::TouchEvent();
+    Dali::Integration::TouchEvent event1 = Dali::Integration::TouchEvent();
+    Dali::Integration::TouchEvent event2 = Dali::Integration::TouchEvent();
+
+    Dali::Integration::Point pointDown;
+    pointDown.SetState( PointState::DOWN );
+    pointDown.SetScreenPosition( Vector2( 1.0f, 41.0f ) );
 
-    const Dali::TouchPoint pointDown( 0, TouchPoint::Up, 10.0f, 50.0f );
-    event.AddPoint( pointDown );
+    Dali::Integration::Point pointUp( pointDown );
+    pointUp.SetState( PointState::UP );
 
-    application.ProcessEvent( event );
+    event1.AddPoint( pointDown );
+    application.ProcessEvent( event1 );
+
+    event2.AddPoint( pointUp );
+    application.ProcessEvent( event2 );
 
     application.SendNotification();
     application.Render();
 
-    DALI_TEST_CHECK( radioButton2.GetProperty<bool>( Button::PROPERTY_TOGGLED ) == false );
-    DALI_TEST_CHECK( radioButton3.GetProperty<bool>( Button::PROPERTY_TOGGLED ) == true );
+    DALI_TEST_CHECK( radioButton2.GetProperty<bool>( Button::Property::SELECTED ) == false );
+    DALI_TEST_CHECK( radioButton3.GetProperty<bool>( Button::Property::SELECTED ) == true );
   }
 
   // Select outside radio group
   {
-    Dali::Integration::TouchEvent event = Dali::Integration::TouchEvent();
+    Dali::Integration::TouchEvent event1 = Dali::Integration::TouchEvent();
+    Dali::Integration::TouchEvent event2 = Dali::Integration::TouchEvent();
+
+    Dali::Integration::Point pointDown;
+    pointDown.SetState( PointState::DOWN );
+    pointDown.SetScreenPosition( Vector2( 1.0f, 500.0f ) );
+
+    Dali::Integration::Point pointUp( pointDown );
+    pointUp.SetState( PointState::UP );
 
-    const Dali::TouchPoint pointDown( 0, TouchPoint::Up, 10.0f, 500.0f );
-    event.AddPoint( pointDown );
+    event1.AddPoint( pointDown );
+    application.ProcessEvent( event1 );
 
-    application.ProcessEvent( event );
+    event2.AddPoint( pointUp );
+    application.ProcessEvent( event2 );
 
     application.SendNotification();
     application.Render();
 
-    DALI_TEST_CHECK( radioButton2.GetProperty<bool>( Button::PROPERTY_TOGGLED ) == false );
-    DALI_TEST_CHECK( radioButton3.GetProperty<bool>( Button::PROPERTY_TOGGLED ) == true );
+    DALI_TEST_CHECK( radioButton2.GetProperty<bool>( Button::Property::SELECTED ) == false );
+    DALI_TEST_CHECK( radioButton3.GetProperty<bool>( Button::Property::SELECTED ) == true );
   }
 
   END_TEST;
 }
+
+
+// Deprecated API Tests
+
+int UtcDaliRadioButtonLabelActor(void)
+{
+  ToolkitTestApplication application;
+
+  std::string labelText = "test actor 1";
+
+  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.SetLabelText( labelText );
+
+  DALI_TEST_EQUALS( radioButton.GetLabelText(), labelText, TEST_LOCATION );
+
+  std::string labelText2 = "test actor 2";
+  radioButton.SetLabelText( labelText2 );
+  DALI_TEST_EQUALS( radioButton.GetLabelText(), labelText2, TEST_LOCATION );
+
+  END_TEST;
+}
+
+int UtcDaliRadioButtonSelected(void)
+{
+  ToolkitTestApplication application;
+
+  RadioButton radioButton = RadioButton::New();
+
+  // Default selected
+  DALI_TEST_CHECK( radioButton.IsSelected() == false );
+
+  // False
+  radioButton.SetSelected( false );
+  DALI_TEST_CHECK( radioButton.IsSelected() == false );
+
+  // True
+  radioButton.SetSelected( true );
+  DALI_TEST_CHECK( radioButton.IsSelected() == true );
+
+  // False
+  radioButton.SetSelected( false );
+  DALI_TEST_CHECK( radioButton.IsSelected() == false );
+
+  END_TEST;
+}
+