Fix the screen rotation issue
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-BaseHandle.cpp
index b0fb0c0..5b2061b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014 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.
  *
  */
 
-#include <iostream>
-
-#include <stdlib.h>
-#include <dali/public-api/dali-core.h>
 #include <dali/integration-api/events/touch-event-integ.h>
+#include <dali/public-api/dali-core.h>
+#include <stdlib.h>
+
+#include <iostream>
 
 #include "dali-test-suite-utils/dali-test-suite-utils.h"
 
 using namespace Dali;
 
-
 void utc_base_handle_startup(void)
 {
   test_return_value = TET_UNDEF;
@@ -39,7 +38,6 @@ void utc_base_handle_cleanup(void)
 
 namespace
 {
-
 // Functor to test whether an animation finish signal is emitted
 struct AnimationFinishCheck
 {
@@ -48,7 +46,7 @@ struct AnimationFinishCheck
   {
   }
 
-  void operator()(Animation& animation)
+  void operator()()
   {
     mSignalReceived = true;
   }
@@ -60,7 +58,7 @@ struct AnimationFinishCheck
 
   void CheckSignalReceived()
   {
-    if (!mSignalReceived)
+    if(!mSignalReceived)
     {
       tet_printf("Expected Finish signal was not received\n");
       tet_result(TET_FAIL);
@@ -78,7 +76,7 @@ BaseHandle ImplicitCopyConstructor(BaseHandle passedByValue)
 {
   // object + copy + passedByValue, ref count == 3
   DALI_TEST_CHECK(passedByValue);
-  if (passedByValue)
+  if(passedByValue)
   {
     DALI_TEST_EQUALS(3, passedByValue.GetBaseObject().ReferenceCount(), TEST_LOCATION);
   }
@@ -100,17 +98,7 @@ struct TestCallback
 class FakeObject : public BaseObject
 {
 };
-// used for testing ThisIsSaferThanReturningVoidStar
-class FakeHandle :  public BaseHandle
-{
-public:
-
-  void RunTest()
-  {
-    return ThisIsSaferThanReturningVoidStar();
-  }
-};
-} // anon namespace
+} // namespace
 
 int UtcDaliBaseHandleConstructorVoid(void)
 {
@@ -123,7 +111,6 @@ int UtcDaliBaseHandleConstructorVoid(void)
   END_TEST;
 }
 
-
 int UtcDaliBaseHandleCopyConstructor(void)
 {
   TestApplication application;
@@ -137,7 +124,7 @@ int UtcDaliBaseHandleCopyConstructor(void)
   // Copy the object, ref count == 2
   BaseHandle copy(object);
   DALI_TEST_CHECK(copy);
-  if (copy)
+  if(copy)
   {
     DALI_TEST_EQUALS(2, copy.GetBaseObject().ReferenceCount(), TEST_LOCATION);
   }
@@ -147,7 +134,7 @@ int UtcDaliBaseHandleCopyConstructor(void)
     BaseHandle anotherCopy = ImplicitCopyConstructor(copy);
 
     DALI_TEST_CHECK(anotherCopy);
-    if (anotherCopy)
+    if(anotherCopy)
     {
       DALI_TEST_EQUALS(3, anotherCopy.GetBaseObject().ReferenceCount(), TEST_LOCATION);
     }
@@ -155,7 +142,7 @@ int UtcDaliBaseHandleCopyConstructor(void)
 
   // anotherCopy out of scope, ref count == 2
   DALI_TEST_CHECK(copy);
-  if (copy)
+  if(copy)
   {
     DALI_TEST_EQUALS(2, copy.GetBaseObject().ReferenceCount(), TEST_LOCATION);
   }
@@ -170,7 +157,7 @@ int UtcDaliBaseHandleAssignmentOperator(void)
   BaseHandle object = Actor::New();
 
   DALI_TEST_CHECK(object);
-  if (object)
+  if(object)
   {
     DALI_TEST_EQUALS(1, object.GetBaseObject().ReferenceCount(), TEST_LOCATION);
   }
@@ -178,13 +165,60 @@ int UtcDaliBaseHandleAssignmentOperator(void)
   BaseHandle copy = object;
 
   DALI_TEST_CHECK(copy);
-  if (copy)
+  if(copy)
   {
     DALI_TEST_EQUALS(2, copy.GetBaseObject().ReferenceCount(), TEST_LOCATION);
   }
   END_TEST;
 }
 
+int UtcDaliBaseHandleMoveConstructor(void)
+{
+  TestApplication application;
+
+  // Initialize an object, ref count == 1
+  BaseHandle object = Actor::New();
+
+  DALI_TEST_EQUALS(1, object.GetBaseObject().ReferenceCount(), TEST_LOCATION);
+
+  // Move the object, ref count == 1
+  BaseHandle move = std::move(object);
+  DALI_TEST_CHECK(move);
+
+  // Check that object is moved (not copied, so ref count keeps the same)
+  if(move)
+  {
+    DALI_TEST_EQUALS(1, move.GetBaseObject().ReferenceCount(), TEST_LOCATION);
+  }
+  DALI_TEST_CHECK(!object);
+
+  END_TEST;
+}
+
+int UtcDaliBaseHandleMoveAssignment(void)
+{
+  TestApplication application;
+
+  // Initialize an object, ref count == 1
+  BaseHandle object = Actor::New();
+
+  DALI_TEST_EQUALS(1, object.GetBaseObject().ReferenceCount(), TEST_LOCATION);
+
+  // Move the object, ref count == 1
+  BaseHandle move;
+  move = std::move(object);
+  DALI_TEST_CHECK(move);
+
+  // Check that object is moved (not copied, so ref count keeps the same)
+  if(move)
+  {
+    DALI_TEST_EQUALS(1, move.GetBaseObject().ReferenceCount(), TEST_LOCATION);
+  }
+  DALI_TEST_CHECK(!object);
+
+  END_TEST;
+}
+
 int UtcDaliBaseHandleGetBaseObject(void)
 {
   TestApplication application;
@@ -274,6 +308,30 @@ int UtcDaliBaseHandleInequalityOperator02(void)
   END_TEST;
 }
 
+int UtcDaliBaseHandleInequalityWithNullptr(void)
+{
+  TestApplication application;
+  tet_infoline("Test for Dali::BaseHandle::operator == nullptr");
+
+  BaseHandle object;
+
+  // object is nullptr.
+  DALI_TEST_CHECK(object == nullptr);
+  DALI_TEST_CHECK(nullptr == object);
+  DALI_TEST_CHECK(!(object != nullptr));
+  DALI_TEST_CHECK(!(nullptr != object));
+
+  object = Actor::New();
+
+  // object is not nullptr.
+  DALI_TEST_CHECK(!(object == nullptr));
+  DALI_TEST_CHECK(!(nullptr == object));
+  DALI_TEST_CHECK(object != nullptr);
+  DALI_TEST_CHECK(nullptr != object);
+
+  END_TEST;
+}
+
 int UtcDaliBaseHandleStlVector(void)
 {
   TestApplication application;
@@ -283,24 +341,24 @@ int UtcDaliBaseHandleStlVector(void)
 
   std::vector<Actor> myVector;
 
-  for (int i=0; i<TargetVectorSize; ++i)
+  for(int i = 0; i < TargetVectorSize; ++i)
   {
     Actor actor = Actor::New();
 
     std::stringstream stream;
-    stream << "Actor " << i+1;
-    actor.SetName(stream.str());
+    stream << "Actor " << i + 1;
+    actor.SetProperty(Actor::Property::NAME, stream.str());
 
     myVector.push_back(actor);
   }
 
   DALI_TEST_EQUALS(TargetVectorSize, static_cast<int>(myVector.size()), TEST_LOCATION);
 
-  DALI_TEST_CHECK(myVector[0].GetName() == "Actor 1");
-  DALI_TEST_CHECK(myVector[1].GetName() == "Actor 2");
-  DALI_TEST_CHECK(myVector[2].GetName() == "Actor 3");
-  DALI_TEST_CHECK(myVector[3].GetName() == "Actor 4");
-  DALI_TEST_CHECK(myVector[4].GetName() == "Actor 5");
+  DALI_TEST_CHECK(myVector[0].GetProperty<std::string>(Actor::Property::NAME) == "Actor 1");
+  DALI_TEST_CHECK(myVector[1].GetProperty<std::string>(Actor::Property::NAME) == "Actor 2");
+  DALI_TEST_CHECK(myVector[2].GetProperty<std::string>(Actor::Property::NAME) == "Actor 3");
+  DALI_TEST_CHECK(myVector[3].GetProperty<std::string>(Actor::Property::NAME) == "Actor 4");
+  DALI_TEST_CHECK(myVector[4].GetProperty<std::string>(Actor::Property::NAME) == "Actor 5");
   END_TEST;
 }
 
@@ -309,18 +367,18 @@ int UtcDaliBaseHandleDoAction(void)
   TestApplication application;
   tet_infoline("Positive Test Dali::BaseHandle::UtcDaliBaseHandleDoAction");
 
-  Actor actor = Actor::New();
+  Actor      actor       = Actor::New();
   BaseHandle actorObject = actor;
 
   DALI_TEST_CHECK(actorObject);
 
   // Check that an invalid command is not performed
-  std::vector<Property::Value> attributes;
+  Property::Map attributes;
   DALI_TEST_CHECK(actorObject.DoAction("invalidCommand", attributes) == false);
 
   // Check that the actor is visible
-  actor.SetVisible(true);
-  DALI_TEST_CHECK(actor.IsVisible() == true);
+  actor.SetProperty(Actor::Property::VISIBLE, true);
+  DALI_TEST_CHECK(actor.GetCurrentProperty<bool>(Actor::Property::VISIBLE) == true);
 
   // Check the actor performed an action to hide itself
   DALI_TEST_CHECK(actorObject.DoAction("hide", attributes) == true);
@@ -330,7 +388,7 @@ int UtcDaliBaseHandleDoAction(void)
   application.Render();
 
   // Check that the actor is now invisible
-  DALI_TEST_CHECK(actor.IsVisible() == false);
+  DALI_TEST_CHECK(actor.GetCurrentProperty<bool>(Actor::Property::VISIBLE) == false);
 
   // Check the actor performed an action to show itself
   DALI_TEST_CHECK(actorObject.DoAction("show", attributes) == true);
@@ -340,13 +398,13 @@ int UtcDaliBaseHandleDoAction(void)
   application.Render();
 
   // Check that the actor is now visible
-  DALI_TEST_CHECK(actor.IsVisible() == true);
+  DALI_TEST_CHECK(actor.GetCurrentProperty<bool>(Actor::Property::VISIBLE) == true);
 
-  Stage::GetCurrent().Add(actor);
+  application.GetScene().Add(actor);
 
   // Build an animation with initial duration of 1 second
-  float durationSeconds(1.0f);
-  Animation animation = Animation::New(durationSeconds);
+  float      durationSeconds(1.0f);
+  Animation  animation       = Animation::New(durationSeconds);
   BaseHandle animationObject = animation;
 
   DALI_TEST_CHECK(animationObject);
@@ -358,31 +416,57 @@ int UtcDaliBaseHandleDoAction(void)
   animation.AnimateTo(Property(actor, Actor::Property::POSITION), targetPosition, AlphaFunction::LINEAR);
 
   // Set the new duration to be 2 seconds
-  float newDurationSeconds(2.0f);
-  Property::Value newDurationSecondsValue = Property::Value( newDurationSeconds );
-  attributes.push_back(newDurationSecondsValue);
+  float           newDurationSeconds(2.0f);
+  Property::Value newDurationSecondsValue = Property::Value(newDurationSeconds);
+  attributes["duration"]                  = newDurationSecondsValue;
 
   // Check the animation performed an action to play itself with the specified duration of 2 seconds
   animationObject.DoAction("play", attributes);
 
-  bool signalReceived(false);
+  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<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*/);
+  DALI_TEST_EQUALS(signalReceived, false, TEST_LOCATION);
+
+  // continue
+  animationObject.DoAction("play", attributes);
+  application.SendNotification();
+  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 );
+  DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Actor::Property::POSITION), 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;
 }
 
-
 int UtcDaliBaseHandleConnectSignal(void)
 {
   TestApplication application;
@@ -392,17 +476,17 @@ int UtcDaliBaseHandleConnectSignal(void)
 
   // get the root layer
   Actor actor = Actor::New();
-  actor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
-  actor.SetParentOrigin( ParentOrigin::TOP_LEFT );
-  actor.SetPosition( 240, 400 );
-  actor.SetSize( 100, 100 );
+  actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
+  actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
+  actor.SetProperty(Actor::Property::POSITION, Vector2(240, 400));
+  actor.SetProperty(Actor::Property::SIZE, Vector2(100, 100));
 
-  Stage::GetCurrent().Add( actor );
+  application.GetScene().Add(actor);
 
-  DALI_TEST_CHECK( gTouchCallBackCalled == false );
+  DALI_TEST_CHECK(gTouchCallBackCalled == false);
 
   // connect to its touch signal
-  actor.ConnectSignal( &application, "touched", TestCallback() );
+  actor.ConnectSignal(&application, "touched", TestCallback());
 
   application.SendNotification();
   application.Render(1000);
@@ -410,26 +494,28 @@ int UtcDaliBaseHandleConnectSignal(void)
   application.Render(1000);
 
   // simulate a touch event
-  Dali::TouchPoint point( 0, TouchPoint::Down, 240, 400  );
+  Dali::Integration::Point point;
+  point.SetState(PointState::DOWN);
+  point.SetScreenPosition(Vector2(240, 400));
   Dali::Integration::TouchEvent event;
-  event.AddPoint( point );
-  application.ProcessEvent( event );
+  event.AddPoint(point);
+  application.ProcessEvent(event);
 
   application.SendNotification();
   application.Render(1000);
   application.SendNotification();
   application.Render(1000);
 
-  DALI_TEST_CHECK( application.GetConnectionCount() > 0 );
-  DALI_TEST_CHECK( gTouchCallBackCalled == true );
+  DALI_TEST_CHECK(application.GetConnectionCount() > 0);
+  DALI_TEST_CHECK(gTouchCallBackCalled == true);
 
   gTouchCallBackCalled = false;
   application.DisconnectAll();
 
   // simulate another touch event
-  application.ProcessEvent( event );
+  application.ProcessEvent(event);
 
-  DALI_TEST_CHECK( gTouchCallBackCalled == false );
+  DALI_TEST_CHECK(gTouchCallBackCalled == false);
   END_TEST;
 }
 
@@ -443,20 +529,19 @@ int UtcDaliBaseHandleGetTypeNameP(void)
 
   std::string typeName = actor.GetTypeName();
 
-  DALI_TEST_CHECK( typeName.size() );
-  DALI_TEST_CHECK( typeName == std::string("Actor") );
+  DALI_TEST_CHECK(typeName.size());
+  DALI_TEST_CHECK(typeName == std::string("Actor"));
   END_TEST;
 }
 
 int UtcDaliBaseHandleGetTypeNameN(void)
 {
-
   TestApplication application;
   tet_infoline("Testing Dali::BaseObject::GetTypeName");
-  FakeObject object;
+  FakeObject  object;
   std::string typeName = object.GetTypeName();
 
-  DALI_TEST_CHECK( typeName == Dali::String::EMPTY );
+  DALI_TEST_CHECK(typeName.empty());
   END_TEST;
 }
 
@@ -466,22 +551,11 @@ int UtcDaliBaseHandleGetTypeInfoP(void)
   tet_infoline("Testing Dali::BaseHandle::GetTypeInfo");
 
   Dali::TypeInfo info;
-  Actor actor = Actor::New();
+  Actor          actor = Actor::New();
 
-  bool ok = actor.GetTypeInfo( info );
-  DALI_TEST_CHECK( ok );
-  END_TEST;
-}
-
-int UtcDaliBaseHandleThisIsSaferThanReturningVoidStar(void)
-{
-  TestApplication application;
-  tet_infoline("Testing Dali::BaseHandle::GetTypeInfo");
-  FakeHandle handle;
-  handle.RunTest();
-  tet_result(TET_PASS);
+  bool ok = actor.GetTypeInfo(info);
+  DALI_TEST_CHECK(ok);
   END_TEST;
-
 }
 
 int UtcDaliBaseHandleGetTypeInfoN(void)
@@ -490,10 +564,10 @@ int UtcDaliBaseHandleGetTypeInfoN(void)
   tet_infoline("Testing Dali::BaseHandle::GetTypeInfo");
 
   Dali::TypeInfo info;
-  FakeObject object;
+  FakeObject     object;
 
-  bool ok = object.GetTypeInfo( info );
-  DALI_TEST_CHECK( !ok );
+  bool ok = object.GetTypeInfo(info);
+  DALI_TEST_CHECK(!ok);
   END_TEST;
 }
 
@@ -507,18 +581,80 @@ int UtcDaliBaseHandleGetObjectPtr(void)
 
   Dali::RefObject* p = actor.GetObjectPtr();
 
-  DALI_TEST_CHECK( p != NULL );
+  DALI_TEST_CHECK(p != NULL);
   END_TEST;
 }
 
 int UtcDaliBaseHandleBooleanCast(void)
 {
   TestApplication application;
-  tet_infoline("Testing Dali::BaseHandle::BooleanType");
+  tet_infoline("Testing Dali::BaseHandle::operator bool");
 
   // get the root layer
   BaseHandle handle = Actor::New();
 
-  DALI_TEST_CHECK( static_cast<BaseHandle::BooleanType>( handle ) );
+  DALI_TEST_CHECK(static_cast<bool>(handle));
+  END_TEST;
+}
+
+int UtcDaliBaseHandleCompareOperatorN(void)
+{
+  TestApplication application;
+  BaseHandle      handle1 = Actor::New();
+  BaseHandle      handle2 = handle1;
+
+  DALI_TEST_CHECK((handle1 < handle2) == false);
+
+  END_TEST;
+}
+
+int UtcDaliBaseHandleDoActionNegative(void)
+{
+  TestApplication  application;
+  Dali::BaseHandle instance;
+  try
+  {
+    std::string         arg1;
+    Dali::Property::Map arg2;
+    instance.DoAction(arg1, arg2);
+    DALI_TEST_CHECK(false); // Should not get here
+  }
+  catch(...)
+  {
+    DALI_TEST_CHECK(true); // We expect an assert
+  }
+  END_TEST;
+}
+
+int UtcDaliBaseHandleGetTypeInfoNegative(void)
+{
+  TestApplication  application;
+  Dali::BaseHandle instance;
+  try
+  {
+    Dali::TypeInfo arg1;
+    instance.GetTypeInfo(arg1);
+    DALI_TEST_CHECK(false); // Should not get here
+  }
+  catch(...)
+  {
+    DALI_TEST_CHECK(true); // We expect an assert
+  }
+  END_TEST;
+}
+
+int UtcDaliBaseHandleGetTypeNameNegative(void)
+{
+  TestApplication  application;
+  Dali::BaseHandle instance;
+  try
+  {
+    instance.GetTypeName();
+    DALI_TEST_CHECK(false); // Should not get here
+  }
+  catch(...)
+  {
+    DALI_TEST_CHECK(true); // We expect an assert
+  }
   END_TEST;
 }