Updated test cases for increased coverage
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-Button.cpp
index 3e7f4cf..80a8f70 100644 (file)
@@ -50,6 +50,21 @@ static bool ButtonCallback( Button button )
   return false;
 }
 
+struct CallbackFunctor
+{
+  CallbackFunctor(bool* callbackFlag)
+  : mCallbackFlag( callbackFlag )
+  {
+  }
+
+  void operator()()
+  {
+    *mCallbackFlag = true;
+  }
+  bool* mCallbackFlag;
+};
+
+
 Image CreateSolidColorImage( const Vector4& color, unsigned int width, unsigned int height )
 {
   BufferImage imageData = BufferImage::New( width, height, Pixel::RGBA8888 );
@@ -71,12 +86,54 @@ Image CreateSolidColorImage( const Vector4& color, unsigned int width, unsigned
   return imageData;
 }
 
-const Dali::TouchPoint pointDownInside( 0, TouchPoint::Down, 240, 400 );
-const Dali::TouchPoint pointUpInside( 0, TouchPoint::Up, 240, 400 );
-const Dali::TouchPoint pointLeave( 0, TouchPoint::Leave, 240, 400 );
-const Dali::TouchPoint pointEnter( 0, TouchPoint::Motion, 240, 400 );
-const Dali::TouchPoint pointDownOutside( 0, TouchPoint::Down, 10, 10 );
-const Dali::TouchPoint pointUpOutside( 0, TouchPoint::Up, 10, 10 );
+Dali::Integration::Point GetPointDownInside()
+{
+  Dali::Integration::Point point;
+  point.SetState( PointState::DOWN );
+  point.SetScreenPosition( Vector2( 240, 400 ) );
+  return point;
+}
+
+Dali::Integration::Point GetPointUpInside()
+{
+  Dali::Integration::Point point;
+  point.SetState( PointState::UP );
+  point.SetScreenPosition( Vector2( 240, 400 ) );
+  return point;
+}
+
+Dali::Integration::Point GetPointLeave()
+{
+  Dali::Integration::Point point;
+  point.SetState( PointState::LEAVE );
+  point.SetScreenPosition( Vector2( 240, 400 ) );
+  return point;
+}
+
+Dali::Integration::Point GetPointEnter()
+{
+  Dali::Integration::Point point;
+  point.SetState( PointState::MOTION );
+  point.SetScreenPosition( Vector2( 240, 400 ) );
+  return point;
+}
+
+Dali::Integration::Point GetPointDownOutside()
+{
+  Dali::Integration::Point point;
+  point.SetState( PointState::DOWN );
+  point.SetScreenPosition( Vector2( 10, 10 ) );
+  return point;
+}
+
+Dali::Integration::Point GetPointUpOutside()
+{
+  Dali::Integration::Point point;
+  point.SetState( PointState::UP );
+  point.SetScreenPosition( Vector2( 10, 10 ) );
+  return point;
+}
+
 
 static float ANIMATION_TIME( 0.5f );
 } // namespace
@@ -310,9 +367,9 @@ int UtcDaliButtonSetLabelStringP(void)
 
   Button button = PushButton::New();
 
-  button.SetLabel( "Button Label" );
+  button.SetLabelText( "Button Label" );
 
-  DALI_TEST_CHECK( button.GetLabel() );
+  DALI_TEST_EQUALS( button.GetLabelText(), "Button Label", TEST_LOCATION );
   END_TEST;
 }
 
@@ -322,19 +379,16 @@ int UtcDaliButtonSetLabelActorP(void)
 
   Button button = PushButton::New();
 
-  TextLabel textLabel = TextLabel::New( "Button Label" );
-  button.SetLabel( textLabel );
+  button.SetLabelText( "Button Label" );
 
-  DALI_TEST_CHECK( button.GetLabel() );
+  DALI_TEST_EQUALS( button.GetLabelText(), "Button Label", TEST_LOCATION );
   END_TEST;
 }
 
-int UtcDaliButtonSetButtonImage(void)
+int UtcDaliButtonSetUnselectedImageP(void)
 {
   ToolkitTestApplication application;
-  tet_infoline(" UtcDaliButtonSetButtonImage");
-
-  Image image = CreateSolidColorImage( Color::RED, 10, 10 );
+  tet_infoline(" UtcDaliButtonSetUnselectedImageP");
 
   PushButton pushButton = PushButton::New();
   Stage::GetCurrent().Add( pushButton );
@@ -343,7 +397,7 @@ int UtcDaliButtonSetButtonImage(void)
   application.Render();
 
   pushButton.SetSize( Vector2( 20.0f, 20.0f ) );
-  pushButton.SetButtonImage( image );
+  pushButton.SetUnselectedImage( "Image.jpg" );
 
   application.SendNotification();
   application.Render();
@@ -361,8 +415,6 @@ int UtcDaliButtonSetSelectedImageP(void)
   ToolkitTestApplication application;
   tet_infoline(" UtcDaliButtonSetButtonImage");
 
-  Image image = CreateSolidColorImage( Color::RED, 10, 10 );
-
   PushButton pushButton = PushButton::New();
   Stage::GetCurrent().Add( pushButton );
 
@@ -370,7 +422,7 @@ int UtcDaliButtonSetSelectedImageP(void)
   application.Render();
 
   pushButton.SetSize( Vector2( 20.0f, 20.0f ) );
-  pushButton.SetSelectedImage( image );
+  pushButton.SetSelectedImage( "Image.jpg" );
 
   application.SendNotification();
   application.Render();
@@ -400,8 +452,13 @@ int UtcDaliButtonPressedSignalP(void)
   application.Render();
 
   // connect to its touch signal
+  ConnectionTracker* testTracker = new ConnectionTracker();
   button.PressedSignal().Connect( &ButtonCallback );
   button.ReleasedSignal().Connect( &ButtonCallback );
+  bool pressedSignal = false;
+  bool releasedSignal = false;
+  button.ConnectSignal( testTracker, "pressed",   CallbackFunctor(&pressedSignal) );
+  button.ConnectSignal( testTracker, "released",  CallbackFunctor(&releasedSignal) );
 
   Dali::Integration::TouchEvent event;
 
@@ -409,50 +466,56 @@ int UtcDaliButtonPressedSignalP(void)
 
   gIsCalledButtonCallback = false;
   event = Dali::Integration::TouchEvent();
-  event.AddPoint( pointDownInside );
+  event.AddPoint( GetPointDownInside() );
   application.ProcessEvent( event );
 
   DALI_TEST_CHECK( gIsCalledButtonCallback );
+  DALI_TEST_CHECK( pressedSignal );
 
   gIsCalledButtonCallback = false;
   event = Dali::Integration::TouchEvent();
-  event.AddPoint( pointUpInside );
+  event.AddPoint( GetPointUpInside() );
   application.ProcessEvent( event );
 
   DALI_TEST_CHECK( gIsCalledButtonCallback );
+  DALI_TEST_CHECK( releasedSignal );
 
   // Test2. Touch point down and up outside the button.
 
+  pressedSignal = false;
+  releasedSignal = false;
   gIsCalledButtonCallback = false;
   event = Dali::Integration::TouchEvent();
-  event.AddPoint( pointDownOutside );
+  event.AddPoint( GetPointDownOutside() );
   application.ProcessEvent( event );
 
   DALI_TEST_CHECK( !gIsCalledButtonCallback );
+  DALI_TEST_CHECK( !pressedSignal );
 
   gIsCalledButtonCallback = false;
   event = Dali::Integration::TouchEvent();
-  event.AddPoint( pointUpOutside );
+  event.AddPoint( GetPointUpOutside() );
   application.ProcessEvent( event );
 
   DALI_TEST_CHECK( !gIsCalledButtonCallback );
+  DALI_TEST_CHECK( !releasedSignal );
 
   // Test3. Touch point down inside and up outside the button.
 
   gIsCalledButtonCallback = false;
   event = Dali::Integration::TouchEvent();
-  event.AddPoint( pointDownInside );
+  event.AddPoint( GetPointDownInside() );
   application.ProcessEvent( event );
 
   DALI_TEST_CHECK( gIsCalledButtonCallback );
 
   gIsCalledButtonCallback = false;
   event = Dali::Integration::TouchEvent();
-  event.AddPoint( pointLeave );
+  event.AddPoint( GetPointLeave() );
   application.ProcessEvent( event );
 
   event = Dali::Integration::TouchEvent();
-  event.AddPoint( pointUpOutside );
+  event.AddPoint( GetPointUpOutside() );
   application.ProcessEvent( event );
 
   DALI_TEST_CHECK( gIsCalledButtonCallback );
@@ -461,18 +524,18 @@ int UtcDaliButtonPressedSignalP(void)
 
   gIsCalledButtonCallback = false;
   event = Dali::Integration::TouchEvent();
-  event.AddPoint( pointDownOutside );
+  event.AddPoint( GetPointDownOutside() );
   application.ProcessEvent( event );
 
   DALI_TEST_CHECK( !gIsCalledButtonCallback );
 
   gIsCalledButtonCallback = false;
   event = Dali::Integration::TouchEvent();
-  event.AddPoint( pointEnter );
+  event.AddPoint( GetPointEnter() );
   application.ProcessEvent( event );
 
   event = Dali::Integration::TouchEvent();
-  event.AddPoint( pointUpInside );
+  event.AddPoint( GetPointUpInside() );
   application.ProcessEvent( event );
 
   DALI_TEST_CHECK( !gIsCalledButtonCallback );
@@ -497,6 +560,9 @@ int UtcDaliButtonClickedSignalP(void)
 
   // connect to its touch signal
   button.ClickedSignal().Connect( &ButtonCallback );
+  bool clickedSignal = false;
+  ConnectionTracker* testTracker = new ConnectionTracker();
+  button.ConnectSignal( testTracker, "clicked",   CallbackFunctor(&clickedSignal) );
 
   Dali::Integration::TouchEvent event;
 
@@ -504,61 +570,68 @@ int UtcDaliButtonClickedSignalP(void)
 
   gIsCalledButtonCallback = false;
   event = Dali::Integration::TouchEvent();
-  event.AddPoint( pointDownInside );
+  event.AddPoint( GetPointDownInside() );
   application.ProcessEvent( event );
 
   event = Dali::Integration::TouchEvent();
-  event.AddPoint( pointUpInside );
+  event.AddPoint( GetPointUpInside() );
   application.ProcessEvent( event );
 
   DALI_TEST_CHECK( gIsCalledButtonCallback );
+  DALI_TEST_CHECK( clickedSignal );
 
   // Test2. Touch point down and up outside the button.
 
   gIsCalledButtonCallback = false;
+  clickedSignal = false;
   event = Dali::Integration::TouchEvent();
-  event.AddPoint( pointDownOutside );
+  event.AddPoint( GetPointDownOutside() );
   application.ProcessEvent( event );
 
   event = Dali::Integration::TouchEvent();
-  event.AddPoint( pointUpOutside );
+  event.AddPoint( GetPointUpOutside() );
   application.ProcessEvent( event );
 
   DALI_TEST_CHECK( !gIsCalledButtonCallback );
+  DALI_TEST_CHECK( !clickedSignal );
 
   // Test3. Touch point down inside and up outside the button.
 
   gIsCalledButtonCallback = false;
+  clickedSignal = false;
   event = Dali::Integration::TouchEvent();
-  event.AddPoint( pointDownInside );
+  event.AddPoint( GetPointDownInside() );
   application.ProcessEvent( event );
 
   event = Dali::Integration::TouchEvent();
-  event.AddPoint( pointLeave );
+  event.AddPoint( GetPointLeave() );
   application.ProcessEvent( event );
 
   event = Dali::Integration::TouchEvent();
-  event.AddPoint( pointUpOutside );
+  event.AddPoint( GetPointUpOutside() );
   application.ProcessEvent( event );
 
   DALI_TEST_CHECK( !gIsCalledButtonCallback );
+  DALI_TEST_CHECK( !clickedSignal );
 
   // Test4. Touch point down outside and up inside the button.
 
   gIsCalledButtonCallback = false;
+  clickedSignal = false;
   event = Dali::Integration::TouchEvent();
-  event.AddPoint( pointDownOutside );
+  event.AddPoint( GetPointDownOutside() );
   application.ProcessEvent( event );
 
   event = Dali::Integration::TouchEvent();
-  event.AddPoint( pointEnter );
+  event.AddPoint( GetPointEnter() );
   application.ProcessEvent( event );
 
   event = Dali::Integration::TouchEvent();
-  event.AddPoint( pointUpInside );
+  event.AddPoint( GetPointUpInside() );
   application.ProcessEvent( event );
 
   DALI_TEST_CHECK( !gIsCalledButtonCallback );
+  DALI_TEST_CHECK( !clickedSignal );
   END_TEST;
 }
 
@@ -577,16 +650,23 @@ int UtcDaliButtonStateChangedSignalP(void)
 
   // connect to its signal
   button.StateChangedSignal().Connect( &ButtonCallback );
+  bool stateChangedSignal = false;
+  ConnectionTracker* testTracker = new ConnectionTracker();
+  button.ConnectSignal( testTracker, "stateChanged",   CallbackFunctor(&stateChangedSignal) );
 
   gIsCalledButtonCallback = false;
   button.SetSelected( true );
 
   DALI_TEST_CHECK( gIsCalledButtonCallback );
+  DALI_TEST_CHECK( stateChangedSignal );
 
   gIsCalledButtonCallback = false;
+  stateChangedSignal = false;
+
   button.SetSelected( false );
 
   DALI_TEST_CHECK( gIsCalledButtonCallback );
+  DALI_TEST_CHECK( stateChangedSignal );
   END_TEST;
 }
 
@@ -599,8 +679,10 @@ int UtcDaliButtonSetProperty(void)
 
   pushButton.SetProperty(pushButton.GetPropertyIndex("disabled"), false);
   DALI_TEST_CHECK( false == pushButton.IsDisabled() );
+
   pushButton.SetProperty(pushButton.GetPropertyIndex("disabled"), true);
   DALI_TEST_CHECK( true == pushButton.IsDisabled() );
+
   END_TEST;
 }
 
@@ -609,26 +691,17 @@ int UtcDaliButtonSize(void)
   ToolkitTestApplication application;
   tet_infoline(" UtcDaliButtonSize");
 
-  ImageActor image01 = ImageActor::New(CreateBufferImage());
-  image01.SetSize( 100, 50 );
-
-  PushButton pushButton;
-
-  Vector3 size;
-
-  // Test1 Size is set through Actor API
-
   // First an image is set, then SetSize is called.
-  pushButton = PushButton::New();
+  PushButton pushButton = PushButton::New();
   Stage::GetCurrent().Add( pushButton );
 
-  pushButton.SetBackgroundImage( image01 );
+  pushButton.SetBackgroundImage( "Image.jpg" );
   pushButton.SetSize( 10.f, 10.f );
 
   application.SendNotification();
   application.Render();
 
-  size = pushButton.GetCurrentSize();
+  Vector3 size = pushButton.GetCurrentSize();
 
   DALI_TEST_EQUALS( size.width, 10.f, TEST_LOCATION );
   DALI_TEST_EQUALS( size.height, 10.f, TEST_LOCATION );