Increase animation test line coverage to 100% 55/192255/2
authorKimmo Hoikka <kimmo.hoikka@samsung.com>
Thu, 1 Nov 2018 13:38:55 +0000 (13:38 +0000)
committerKimmo Hoikka <kimmo.hoikka@samsung.com>
Thu, 1 Nov 2018 13:40:23 +0000 (13:40 +0000)
- add more test logic
- refactor to get rid of unreachable code

Change-Id: Ic15b0184137dd8ad1853219aaa69d8f1a859d2e7

automated-tests/src/dali/utc-Dali-BaseHandle.cpp
dali/internal/event/animation/animation-impl.cpp

index 865fa5b..722cc85 100644 (file)
@@ -48,7 +48,7 @@ struct AnimationFinishCheck
   {
   }
 
-  void operator()(Animation& animation)
+  void operator()()
   {
     mSignalReceived = true;
   }
@@ -366,16 +366,43 @@ int UtcDaliBaseHandleDoAction(void)
 
   bool signalReceived(false);
   AnimationFinishCheck finishCheck(signalReceived);
-  animation.FinishedSignal().Connect(&application, finishCheck);
+  // use the handle API to connect the signal
+  animation.ConnectSignal( &application, "finished", finishCheck );
+  // just for coverage connect to non-existant signal as well
+  animation.ConnectSignal( &application, "foo", finishCheck );
+  DALI_TEST_EQUALS( signalReceived, false, TEST_LOCATION );
+
+  application.SendNotification();
+  application.Render(static_cast<uint32_t>(newDurationSeconds * 500.0f) /* half of time */);
+  DALI_TEST_EQUALS( signalReceived, false, TEST_LOCATION );
+
+  // pause
+  animationObject.DoAction("pause", attributes);
+  application.SendNotification();
+  application.Render(static_cast<uint32_t>(newDurationSeconds * 500.0f) + 1u/*just beyond the animation duration*/);
+  DALI_TEST_EQUALS( signalReceived, false, TEST_LOCATION );
 
+  // continue
+  animationObject.DoAction("play", attributes);
   application.SendNotification();
-  application.Render(static_cast<unsigned int>(newDurationSeconds * 1000.0f) + 1u/*just beyond the animation duration*/);
+  application.Render(static_cast<uint32_t>(newDurationSeconds * 500.0f) + 1u/*just beyond the animation duration*/);
 
   // We expect the animation to finish
   application.SendNotification();
   finishCheck.CheckSignalReceived();
   DALI_TEST_EQUALS( actor.GetCurrentPosition(), targetPosition, TEST_LOCATION );
 
+  // play again
+  signalReceived = false;
+  animationObject.DoAction("play", attributes);
+  DALI_TEST_EQUALS(animation.GetCurrentProgress(), 0.f, TEST_LOCATION);
+  application.SendNotification();
+  application.Render(static_cast<uint32_t>(newDurationSeconds * 500.0f) /* half of time */);
+  animationObject.DoAction("stop", attributes);
+  application.SendNotification();
+  application.Render(static_cast<uint32_t>(newDurationSeconds * 1000.0f) /* full time */);
+  DALI_TEST_EQUALS( signalReceived, false, TEST_LOCATION );
+
   // Check the new animation duration is 2 seconds
   DALI_TEST_EQUALS(animation.GetDuration(), newDurationSeconds, TEST_LOCATION);
   END_TEST;
index 6a914c3..5dbb390 100644 (file)
@@ -832,17 +832,13 @@ void Animation::EmitSignalProgressReached()
 
 bool Animation::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
 {
-  bool connected( true );
+  bool connected( false );
   Animation* animation = static_cast< Animation* >(object); // TypeRegistry guarantees that this is the correct type.
 
   if( 0 == signalName.compare( SIGNAL_FINISHED ) )
   {
     animation->FinishedSignal().Connect( tracker, functor );
-  }
-  else
-  {
-    // signalName does not match any signal
-    connected = false;
+    connected = true;
   }
 
   return connected;
@@ -966,12 +962,13 @@ void Animation::SetCurrentProgress(float progress)
 
 float Animation::GetCurrentProgress()
 {
-  if( mAnimation )
+  float progress = 0.f;
+  if( mAnimation ) // always exists in practice
   {
-    return mAnimation->GetCurrentProgress();
+    progress = mAnimation->GetCurrentProgress();
   }
 
-  return 0.0f;
+  return progress;
 }
 
 void Animation::ExtendDuration( const TimePeriod& timePeriod )