Fix svace issue (uint32_t to long)
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-WeakHandle.cpp
index 6848f1f..4b8fe8b 100644 (file)
  *
  */
 
-#include <dali/public-api/dali-core.h>
 #include <dali-test-suite-utils.h>
+#include <dali/public-api/dali-core.h>
 
 using namespace Dali;
 
 namespace
 {
-
 /*******************************************************************************
  *
  * Custom Actor
@@ -32,24 +31,27 @@ namespace Impl
 {
 struct MyTestCustomActor : public CustomActorImpl
 {
-  typedef Signal< void ()> SignalType;
-  typedef Signal< void (float)> SignalTypeFloat;
+  typedef Signal<void()>      SignalType;
+  typedef Signal<void(float)> SignalTypeFloat;
 
-  MyTestCustomActor() : CustomActorImpl( ActorFlags( REQUIRES_TOUCH_EVENTS ) )
-  { }
+  MyTestCustomActor()
+  : CustomActorImpl(ActorFlags())
+  {
+  }
 
   virtual ~MyTestCustomActor()
-  { }
+  {
+  }
 
   void ResetCallStack()
   {
   }
 
   // From CustomActorImpl
-  virtual void OnStageConnection( int depth )
+  virtual void OnSceneConnection(int depth)
   {
   }
-  virtual void OnStageDisconnection()
+  virtual void OnSceneDisconnection()
   {
   }
   virtual void OnChildAdd(Actor& child)
@@ -64,22 +66,6 @@ struct MyTestCustomActor : public CustomActorImpl
   virtual void OnSizeAnimation(Animation& animation, const Vector3& targetSize)
   {
   }
-  virtual bool OnTouchEvent(const TouchEvent& event)
-  {
-    return true;
-  }
-  virtual bool OnHoverEvent(const HoverEvent& event)
-  {
-    return true;
-  }
-  virtual bool OnWheelEvent(const WheelEvent& event)
-  {
-    return true;
-  }
-  virtual bool OnKeyEvent(const KeyEvent& event)
-  {
-    return true;
-  }
   virtual void OnKeyInputFocusGained()
   {
   }
@@ -88,47 +74,46 @@ struct MyTestCustomActor : public CustomActorImpl
   }
   virtual Vector3 GetNaturalSize()
   {
-    return Vector3( 0.0f, 0.0f, 0.0f );
+    return Vector3(0.0f, 0.0f, 0.0f);
   }
 
-  virtual float GetHeightForWidth( float width )
+  virtual float GetHeightForWidth(float width)
   {
     return 0.0f;
   }
 
-  virtual float GetWidthForHeight( float height )
+  virtual float GetWidthForHeight(float height)
   {
     return 0.0f;
   }
 
-  virtual void OnRelayout( const Vector2& size, RelayoutContainer& container )
+  virtual void OnRelayout(const Vector2& size, RelayoutContainer& container)
   {
   }
 
-  virtual void OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
+  virtual void OnSetResizePolicy(ResizePolicy::Type policy, Dimension::Type dimension)
   {
   }
 
-  virtual void OnCalculateRelayoutSize( Dimension::Type dimension )
+  virtual void OnCalculateRelayoutSize(Dimension::Type dimension)
   {
   }
 
-  virtual float CalculateChildSize( const Dali::Actor& child, Dimension::Type dimension )
+  virtual float CalculateChildSize(const Dali::Actor& child, Dimension::Type dimension)
   {
     return 0.0f;
   }
 
-  virtual void OnLayoutNegotiated( float size, Dimension::Type dimension )
+  virtual void OnLayoutNegotiated(float size, Dimension::Type dimension)
   {
   }
 
-  virtual bool RelayoutDependentOnChildren( Dimension::Type dimension = Dimension::ALL_DIMENSIONS )
+  virtual bool RelayoutDependentOnChildren(Dimension::Type dimension = Dimension::ALL_DIMENSIONS)
   {
     return false;
   }
 
 public:
-
   SignalType mSignal;
 };
 
@@ -137,9 +122,8 @@ public:
 class MyTestCustomActor : public CustomActor
 {
 public:
-
-  typedef Signal< void ()> SignalType;
-  typedef Signal< void (float)> SignalTypeFloat;
+  typedef Signal<void()>      SignalType;
+  typedef Signal<void(float)> SignalTypeFloat;
 
   MyTestCustomActor()
   {
@@ -148,25 +132,25 @@ public:
   static MyTestCustomActor New()
   {
     Impl::MyTestCustomActor* p = new Impl::MyTestCustomActor;
-    return MyTestCustomActor( *p ); // takes ownership
+    return MyTestCustomActor(*p); // takes ownership
   }
 
   virtual ~MyTestCustomActor()
   {
   }
 
-  static MyTestCustomActor DownCast( BaseHandle handle )
+  static MyTestCustomActor DownCast(BaseHandle handle)
   {
     MyTestCustomActor result;
 
-    CustomActor custom = Dali::CustomActor::DownCast( handle );
-    if ( custom )
+    CustomActor custom = Dali::CustomActor::DownCast(handle);
+    if(custom)
     {
       CustomActorImpl& customImpl = custom.GetImplementation();
 
       Impl::MyTestCustomActor* impl = dynamic_cast<Impl::MyTestCustomActor*>(&customImpl);
 
-      if (impl)
+      if(impl)
       {
         result = MyTestCustomActor(customImpl.GetOwner());
       }
@@ -178,7 +162,7 @@ public:
   SignalType& GetCustomSignal()
   {
     Dali::RefObject& obj = GetImplementation();
-    return static_cast<Impl::MyTestCustomActor&>( obj ).mSignal;
+    return static_cast<Impl::MyTestCustomActor&>(obj).mSignal;
   }
 
   MyTestCustomActor(Internal::CustomActor* internal)
@@ -186,13 +170,13 @@ public:
   {
   }
 
-  MyTestCustomActor( Impl::MyTestCustomActor& impl )
-  : CustomActor( impl )
+  MyTestCustomActor(Impl::MyTestCustomActor& impl)
+  : CustomActor(impl)
   {
   }
 };
 
-}
+} // namespace
 
 int UtcDaliWeakHandleBaseConstructorVoid(void)
 {
@@ -211,17 +195,17 @@ int UtcDaliWeakHandleBaseConstructorWithBaseHandle(void)
   TestApplication application;
   tet_infoline("Testing Dali::WeakHandleBase::WeakHandleBase(BaseHandle)");
 
-  BaseHandle emptyHandle;
+  BaseHandle     emptyHandle;
   WeakHandleBase emptyObject(emptyHandle);
   DALI_TEST_CHECK(!emptyObject.GetBaseHandle());
 
-  Actor actor = Actor::New();
+  Actor          actor = Actor::New();
   WeakHandleBase object(actor);
   DALI_TEST_CHECK(object.GetBaseHandle() == actor);
 
-  Animation animation = Animation::New( 1.0f );
-  WeakHandleBase animationObject( animation );
-  DALI_TEST_CHECK( animationObject.GetBaseHandle() == animation );
+  Animation      animation = Animation::New(1.0f);
+  WeakHandleBase animationObject(animation);
+  DALI_TEST_CHECK(animationObject.GetBaseHandle() == animation);
 
   END_TEST;
 }
@@ -264,6 +248,45 @@ int UtcDaliWeakHandleBaseAssignmentOperator(void)
   END_TEST;
 }
 
+int UtcDaliWeakHandleBaseMoveConstructor(void)
+{
+  TestApplication application;
+
+  Actor actor = Actor::New();
+  DALI_TEST_EQUALS(1, actor.GetBaseObject().ReferenceCount(), TEST_LOCATION); // reference count of the actor is not increased
+
+  WeakHandleBase object(actor);
+  DALI_TEST_CHECK(object.GetBaseHandle() == actor);
+  DALI_TEST_EQUALS(1, actor.GetBaseObject().ReferenceCount(), TEST_LOCATION); // reference count of the actor is not increased
+
+  WeakHandleBase move = std::move(object);
+  DALI_TEST_CHECK(move.GetBaseHandle() == actor);
+  DALI_TEST_EQUALS(1, actor.GetBaseObject().ReferenceCount(), TEST_LOCATION); // reference count of the actor is not increased
+  DALI_TEST_CHECK(!object.GetBaseHandle());                                   // object moved
+
+  END_TEST;
+}
+
+int UtcDaliWeakHandleBaseMoveAssignment(void)
+{
+  TestApplication application;
+
+  Actor actor = Actor::New();
+  DALI_TEST_EQUALS(1, actor.GetBaseObject().ReferenceCount(), TEST_LOCATION); // reference count of the actor is not increased
+
+  WeakHandleBase object(actor);
+  DALI_TEST_CHECK(object.GetBaseHandle() == actor);
+  DALI_TEST_EQUALS(1, actor.GetBaseObject().ReferenceCount(), TEST_LOCATION); // reference count of the actor is not increased
+
+  WeakHandleBase move;
+  move = std::move(object);
+  DALI_TEST_CHECK(move.GetBaseHandle() == actor);
+  DALI_TEST_EQUALS(1, actor.GetBaseObject().ReferenceCount(), TEST_LOCATION); // reference count of the actor is not increased
+  DALI_TEST_CHECK(!object.GetBaseHandle());                                   // object moved
+
+  END_TEST;
+}
+
 int UtcDaliWeakHandleBaseEqualityOperatorP(void)
 {
   TestApplication application;
@@ -295,7 +318,7 @@ int UtcDaliWeakHandleBaseEqualityOperatorN(void)
   WeakHandleBase object(actor);
   DALI_TEST_CHECK(object.GetBaseHandle() == actor);
 
-  Actor differentActor = Actor::New();
+  Actor          differentActor = Actor::New();
   WeakHandleBase aDifferentWeakHandleBase(differentActor);
 
   DALI_TEST_CHECK(!(object == aDifferentWeakHandleBase));
@@ -313,7 +336,7 @@ int UtcDaliWeakHandleBaseInequalityOperatorP(void)
   WeakHandleBase object(actor);
   DALI_TEST_CHECK(object.GetBaseHandle() == actor);
 
-  Actor differentActor = Actor::New();
+  Actor          differentActor = Actor::New();
   WeakHandleBase aDifferentWeakHandleBase(differentActor);
 
   DALI_TEST_CHECK(object != aDifferentWeakHandleBase);
@@ -341,31 +364,31 @@ int UtcDaliWeakHandleBaseGetBaseHandle(void)
   TestApplication application;
   tet_infoline("Testing Dali::WeakHandleBase::GetBaseHandle()");
 
-  Handle emptyHandle;
+  Handle         emptyHandle;
   WeakHandleBase emptyObject(emptyHandle);
   DALI_TEST_CHECK(!emptyObject.GetBaseHandle());
 
-  Actor actor = Actor::New();
+  Actor          actor = Actor::New();
   WeakHandleBase object(actor);
   DALI_TEST_CHECK(object.GetBaseHandle() == actor);
 
   WeakHandleBase theSameObject = WeakHandleBase(actor);
   DALI_TEST_CHECK(object.GetBaseHandle() == theSameObject.GetBaseHandle());
 
-  Actor differentActor = Actor::New();
+  Actor          differentActor = Actor::New();
   WeakHandleBase aDifferentWeakHandleBase(differentActor);
   DALI_TEST_CHECK(object.GetBaseHandle() != aDifferentWeakHandleBase.GetBaseHandle());
 
-  Animation animation = Animation::New( 1.0f );
-  WeakHandleBase animationObject( animation );
-  DALI_TEST_CHECK( animationObject.GetBaseHandle() == animation );
+  Animation      animation = Animation::New(1.0f);
+  WeakHandleBase animationObject(animation);
+  DALI_TEST_CHECK(animationObject.GetBaseHandle() == animation);
 
-  WeakHandleBase theSameAnimationObject = WeakHandleBase( animation );
-  DALI_TEST_CHECK( animationObject.GetBaseHandle() == theSameAnimationObject.GetBaseHandle() );
+  WeakHandleBase theSameAnimationObject = WeakHandleBase(animation);
+  DALI_TEST_CHECK(animationObject.GetBaseHandle() == theSameAnimationObject.GetBaseHandle());
 
-  Animation differentAnimation = Animation::New( 1.0f );
-  WeakHandleBase aDifferentAnimationObject( differentAnimation );
-  DALI_TEST_CHECK( animationObject.GetBaseHandle() != aDifferentAnimationObject.GetBaseHandle() );
+  Animation      differentAnimation = Animation::New(1.0f);
+  WeakHandleBase aDifferentAnimationObject(differentAnimation);
+  DALI_TEST_CHECK(animationObject.GetBaseHandle() != aDifferentAnimationObject.GetBaseHandle());
 
   END_TEST;
 }
@@ -373,9 +396,9 @@ int UtcDaliWeakHandleBaseGetBaseHandle(void)
 int UtcDaliWeakHandleBaseReset(void)
 {
   TestApplication application;
-  tet_infoline( "Testing Daku::WeakHandleBase::Reset()" );
+  tet_infoline("Testing Daku::WeakHandleBase::Reset()");
 
-  Actor actor = Actor::New();
+  Actor          actor = Actor::New();
   WeakHandleBase object(actor);
   DALI_TEST_CHECK(object.GetBaseHandle() == actor);
 
@@ -392,24 +415,61 @@ int UtcDaliWeakHandleGetHandle(void)
   TestApplication application;
   tet_infoline("Testing Dali::WeakHandle::GetHandle()");
 
-  Actor actor = Actor::New();
+  Actor             actor = Actor::New();
   WeakHandle<Actor> object(actor);
   DALI_TEST_CHECK(object.GetHandle() == actor);
 
-  MyTestCustomActor customActor = MyTestCustomActor::New();
+  MyTestCustomActor             customActor = MyTestCustomActor::New();
   WeakHandle<MyTestCustomActor> customObject(customActor);
   DALI_TEST_CHECK(customObject.GetHandle() == customActor);
 
   DALI_TEST_CHECK(object.GetHandle() != customObject.GetHandle());
 
-  Animation animation = Animation::New( 1.0f );
-  WeakHandle<Animation>  animationObject( animation );
-  DALI_TEST_CHECK( animationObject.GetHandle() == animation );
+  Animation             animation = Animation::New(1.0f);
+  WeakHandle<Animation> animationObject(animation);
+  DALI_TEST_CHECK(animationObject.GetHandle() == animation);
 
   animation.Reset();
-  DALI_TEST_CHECK( animationObject.GetHandle() == Animation() );
+  DALI_TEST_CHECK(animationObject.GetHandle() == Animation());
+
+  END_TEST;
+}
+
+int UtcDaliWeakHandleMoveConstructor(void)
+{
+  TestApplication application;
+
+  Actor actor = Actor::New();
+  DALI_TEST_EQUALS(1, actor.GetBaseObject().ReferenceCount(), TEST_LOCATION); // reference count of the actor is not increased
+
+  WeakHandle<Actor> object(actor);
+  DALI_TEST_CHECK(object.GetHandle() == actor);
+  DALI_TEST_EQUALS(1, actor.GetBaseObject().ReferenceCount(), TEST_LOCATION); // reference count of the actor is not increased
+
+  WeakHandle<Actor> move = std::move(object);
+  DALI_TEST_CHECK(move.GetHandle() == actor);
+  DALI_TEST_EQUALS(1, actor.GetBaseObject().ReferenceCount(), TEST_LOCATION); // reference count of the actor is not increased
+  DALI_TEST_CHECK(!object.GetHandle());                                       // object moved
 
   END_TEST;
 }
 
+int UtcDaliWeakHandleMoveAssignment(void)
+{
+  TestApplication application;
+
+  Actor actor = Actor::New();
+  DALI_TEST_EQUALS(1, actor.GetBaseObject().ReferenceCount(), TEST_LOCATION); // reference count of the actor is not increased
+
+  WeakHandle<Actor> object(actor);
+  DALI_TEST_CHECK(object.GetHandle() == actor);
+  DALI_TEST_EQUALS(1, actor.GetBaseObject().ReferenceCount(), TEST_LOCATION); // reference count of the actor is not increased
+
+  WeakHandle<Actor> move;
+  move = std::move(object);
+  DALI_TEST_CHECK(move.GetHandle() == actor);
+  DALI_TEST_EQUALS(1, actor.GetBaseObject().ReferenceCount(), TEST_LOCATION); // reference count of the actor is not increased
+  DALI_TEST_CHECK(!object.GetHandle());                                       // object moved
 
+  END_TEST;
+}