[3.0] Change CustomActorImpl destructor to protected
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-CustomActor.cpp
index 44b15c7..c32c8e7 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2016 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.
@@ -21,7 +21,7 @@
 
 #include <dali/integration-api/events/touch-event-integ.h>
 #include <dali/integration-api/events/hover-event-integ.h>
-#include <dali/integration-api/events/mouse-wheel-event-integ.h>
+#include <dali/integration-api/events/wheel-event-integ.h>
 #include <dali/integration-api/events/key-event-integ.h>
 
 #include "dali-test-suite-utils/dali-test-suite-utils.h"
@@ -57,16 +57,17 @@ struct TestCustomActor : public CustomActorImpl
    * Constructor
    */
   TestCustomActor()
-  : CustomActorImpl( ActorFlags( REQUIRES_TOUCH_EVENTS | REQUIRES_MOUSE_WHEEL_EVENTS | REQUIRES_HOVER_EVENTS | DISABLE_SIZE_NEGOTIATION ) ),
+  : CustomActorImpl( ActorFlags( REQUIRES_TOUCH_EVENTS | REQUIRES_WHEEL_EVENTS | REQUIRES_HOVER_EVENTS | DISABLE_SIZE_NEGOTIATION ) ),
     mDaliProperty( Property::INVALID_INDEX ),
     mSizeSet( Vector3::ZERO ),
     mTargetSize( Vector3::ZERO ),
-    mNego( false )
+    mNego( false ),
+    mDepth(0u)
   {
   }
 
   TestCustomActor(bool nego)
-  : CustomActorImpl( ActorFlags( REQUIRES_TOUCH_EVENTS | REQUIRES_MOUSE_WHEEL_EVENTS | REQUIRES_HOVER_EVENTS ) ),
+  : CustomActorImpl( ActorFlags( REQUIRES_TOUCH_EVENTS | REQUIRES_WHEEL_EVENTS | REQUIRES_HOVER_EVENTS ) ),
     mDaliProperty( Property::INVALID_INDEX ),
     mSizeSet( Vector3::ZERO ),
     mTargetSize( Vector3::ZERO ),
@@ -119,9 +120,10 @@ struct TestCustomActor : public CustomActorImpl
   }
 
   // From CustomActorImpl
-  virtual void OnStageConnection()
+  virtual void OnStageConnection( int depth )
   {
     AddToCallStacks("OnStageConnection");
+    mDepth = depth;
   }
   virtual void OnStageDisconnection()
   {
@@ -159,9 +161,9 @@ struct TestCustomActor : public CustomActorImpl
     AddToCallStacks("OnHoverEvent");
     return true;
   }
-  virtual bool OnMouseWheelEvent(const MouseWheelEvent& event)
+  virtual bool OnWheelEvent(const WheelEvent& event)
   {
-    AddToCallStacks("OnMouseWheelEvent");
+    AddToCallStacks("OnWheelEvent");
     return true;
   }
   virtual bool OnKeyEvent(const KeyEvent& event)
@@ -221,7 +223,7 @@ struct TestCustomActor : public CustomActorImpl
 
   void SetDaliProperty(std::string s)
   {
-    Self().SetProperty(mDaliProperty, s) ;
+    Self().SetProperty(mDaliProperty, s);
   }
   void TestRelayoutRequest()
   {
@@ -253,6 +255,7 @@ struct TestCustomActor : public CustomActorImpl
   Vector3 mSizeSet;
   Vector3 mTargetSize;
   bool mNego;
+  unsigned int mDepth;
 };
 
 /**
@@ -269,10 +272,10 @@ struct TestCustomActorVariant1 : public TestCustomActor
   }
 
   // From CustomActorImpl
-  virtual void OnStageConnection()
+  virtual void OnStageConnection( int depth )
   {
     // Chain up first
-    TestCustomActor::OnStageConnection();
+    TestCustomActor::OnStageConnection( depth );
 
     // Add the child
     Self().Add( mChildToAdd );
@@ -294,10 +297,10 @@ struct TestCustomActorVariant2 : public TestCustomActor
   }
 
   // From CustomActorImpl
-  virtual void OnStageConnection()
+  virtual void OnStageConnection( int depth )
   {
     // Chain up first
-    TestCustomActor::OnStageConnection();
+    TestCustomActor::OnStageConnection( depth );
 
     // Remove all the children
     for( unsigned int i=0, num=Self().GetChildCount(); i<num; ++i )
@@ -372,10 +375,10 @@ struct TestCustomActorVariant5 : public TestCustomActor
   }
 
   // From CustomActorImpl
-  virtual void OnStageConnection()
+  virtual void OnStageConnection( int depth )
   {
     // Chain up first
-    TestCustomActor::OnStageConnection();
+    TestCustomActor::OnStageConnection( depth );
 
     // Take parent off-stage
     Actor parent = Self().GetParent();
@@ -497,7 +500,7 @@ public:
   }
 
   // From CustomActorImpl
-  virtual void OnStageConnection()
+  virtual void OnStageConnection( int depth )
   {
   }
   virtual void OnStageDisconnection()
@@ -523,7 +526,7 @@ public:
   {
     return true;
   }
-  virtual bool OnMouseWheelEvent(const MouseWheelEvent& event)
+  virtual bool OnWheelEvent(const WheelEvent& event)
   {
     return true;
   }
@@ -607,6 +610,7 @@ public:
   {
     Impl::TestCustomActor* impl = new Impl::TestCustomActor( true );
     TestCustomActor custom( *impl ); // takes ownership
+    custom.SetName( "SizeNegotiationActor" );
 
     impl->Initialize();
 
@@ -779,6 +783,10 @@ public:
     return GetImpl().TestRelayoutDependentOnChildrenBase( dimension );
   }
 
+  unsigned int GetDepth()
+  {
+    return GetImpl().mDepth;
+  }
 private:
 
   TestCustomActor( Impl::TestCustomActor& impl ) : CustomActor( impl )
@@ -815,7 +823,7 @@ int UtcDaliCustomActorImplDestructor(void)
 {
   TestApplication application;
   CustomActorImpl* actor = new Impl::TestCustomActor();
-  delete actor;
+  CustomActor customActor( *actor ); // Will automatically unref at the end of this function
 
   DALI_TEST_CHECK( true );
   END_TEST;
@@ -1559,17 +1567,21 @@ int UtcDaliCustomActorRemoveDuringOnChildRemove(void)
   DALI_TEST_EQUALS( "OnChildRemove",        actorA.GetMethodsCalled()[ 2 ], TEST_LOCATION ); // The actorB added to actorA
   // mContainer will then receive OnChildAdd
 
-  DALI_TEST_EQUALS( 2, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION );
+  DALI_TEST_EQUALS( 3, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION );
   DALI_TEST_EQUALS( "OnStageConnection",    actorB.GetMethodsCalled()[ 0 ], TEST_LOCATION );
-  DALI_TEST_EQUALS( "OnChildAdd",           actorB.GetMethodsCalled()[ 1 ], TEST_LOCATION );
+  // The derived class are always notified, no matter the child is successfully removed or not
+  DALI_TEST_EQUALS( "OnChildRemove",        actorB.GetMethodsCalled()[ 1 ], TEST_LOCATION );
+  DALI_TEST_EQUALS( "OnChildAdd",           actorB.GetMethodsCalled()[ 2 ], TEST_LOCATION );
 
-  DALI_TEST_EQUALS( 5, (int)(MasterCallStack.size()), TEST_LOCATION );
+  DALI_TEST_EQUALS( 6, (int)(MasterCallStack.size()), TEST_LOCATION );
 
   DALI_TEST_EQUALS( "ActorB: OnStageConnection",    MasterCallStack[ 0 ], TEST_LOCATION );
   DALI_TEST_EQUALS( "ActorA: OnStageConnection",    MasterCallStack[ 1 ], TEST_LOCATION );
   DALI_TEST_EQUALS( "ActorA: OnChildAdd",           MasterCallStack[ 2 ], TEST_LOCATION );
   DALI_TEST_EQUALS( "ActorA: OnChildRemove",        MasterCallStack[ 3 ], TEST_LOCATION );
-  DALI_TEST_EQUALS( "ActorB: OnChildAdd",           MasterCallStack[ 4 ], TEST_LOCATION );
+  // The derived class are always notified, no matter the child is successfully removed or not
+  DALI_TEST_EQUALS( "ActorB: OnChildRemove",        MasterCallStack[ 4 ], TEST_LOCATION );
+  DALI_TEST_EQUALS( "ActorB: OnChildAdd",           MasterCallStack[ 5 ], TEST_LOCATION );
 
   // Excercise the message passing to Update thread
 
@@ -1587,7 +1599,7 @@ int UtcDaliCustomActorOnPropertySet(void)
   TestCustomActor custom = TestCustomActor::New();
   DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
 
-  custom.SetDaliProperty("yes") ;
+  custom.SetDaliProperty("yes");
 
   DALI_TEST_EQUALS( 1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
   DALI_TEST_EQUALS( "OnPropertySet", custom.GetMethodsCalled()[ 0 ], TEST_LOCATION );
@@ -1656,7 +1668,9 @@ int UtcDaliCustomActorOnTouchEvent(void)
   application.Render();
 
   // simulate a touch event
-  Dali::TouchPoint point( 0, TouchPoint::Down, 1, 1 );
+  Dali::Integration::Point point;
+  point.SetState( PointState::DOWN );
+  point.SetScreenPosition( Vector2( 1, 1 ) );
   Dali::Integration::TouchEvent event;
   event.AddPoint( point );
   application.ProcessEvent( event );
@@ -1687,7 +1701,9 @@ int UtcDaliCustomActorOnHoverEvent(void)
   application.Render();
 
   // simulate a hover event
-  Dali::TouchPoint point( 0, TouchPoint::Motion, 1, 1 );
+  Dali::Integration::Point point;
+  point.SetState( PointState::MOTION );
+  point.SetScreenPosition( Vector2( 1, 1 ) );
   Dali::Integration::HoverEvent event;
   event.AddPoint( point );
   application.ProcessEvent( event );
@@ -1697,10 +1713,10 @@ int UtcDaliCustomActorOnHoverEvent(void)
   END_TEST;
 }
 
-int UtcDaliCustomActorOnMouseWheelEvent(void)
+int UtcDaliCustomActorOnWheelEvent(void)
 {
   TestApplication application;
-  tet_infoline("Testing Dali::CustomActor::OnMouseWheelEvent()");
+  tet_infoline("Testing Dali::CustomActor::OnWheelEvent()");
 
   TestCustomActor custom = TestCustomActor::New();
   DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
@@ -1717,13 +1733,13 @@ int UtcDaliCustomActorOnMouseWheelEvent(void)
   application.SendNotification();
   application.Render();
 
-  // simulate a mouse wheel event
+  // simulate a wheel event
   Vector2 screenCoordinates( 10.0f, 10.0f );
-  Integration::MouseWheelEvent event(0, 0u, screenCoordinates, 1, 1000u);
+  Integration::WheelEvent event( Integration::WheelEvent::MOUSE_WHEEL, 0, 0u, screenCoordinates, 1, 1000u );
   application.ProcessEvent( event );
 
   DALI_TEST_EQUALS( 1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
-  DALI_TEST_EQUALS( "OnMouseWheelEvent", custom.GetMethodsCalled()[ 0 ], TEST_LOCATION );
+  DALI_TEST_EQUALS( "OnWheelEvent", custom.GetMethodsCalled()[ 0 ], TEST_LOCATION );
   END_TEST;
 }
 
@@ -1731,12 +1747,12 @@ int UtcDaliCustomActorImplOnPropertySet(void)
 {
   TestApplication application;
   CustomActorImpl* impl = new Impl::SimpleTestCustomActor();
+  CustomActor customActor( *impl ); // Will automatically unref at the end of this function
 
   impl->OnPropertySet( 0, 0 );
 
   DALI_TEST_CHECK( true );
 
-  delete impl;
   END_TEST;
 }
 
@@ -1767,7 +1783,7 @@ int UtcDaliCustomActorDoAction(void)
 
   DALI_TEST_CHECK(customActorObject);
 
-  std::vector<Property::Value> attributes;
+  Property::Map attributes;
 
   // Check that an invalid command is not performed
   DALI_TEST_CHECK(customActorObject.DoAction("invalidCommand", attributes) == false);
@@ -1948,3 +1964,56 @@ int UtcDaliCustomActorGetExtensionP(void)
 
   END_TEST;
 }
+
+int UtcDaliCustomActorOnConnectionDepth(void)
+{
+  TestApplication application;
+  tet_infoline("Testing Dali::CustomActor::OnStageConnection() hierarchy depth");
+
+  Stage stage = Stage::GetCurrent();
+
+  /* Build tree of actors:
+   *
+   *                      Depth
+   *
+   *       A (parent)       1
+   *      / \
+   *     B   C              2
+   *    / \   \
+   *   D   E   F            3
+   *
+   * OnStageConnection should return 1 for A, 2 for B and C, and 3 for D, E and F.
+   */
+
+  TestCustomActor actorA = TestCustomActor::New();
+  stage.Add( actorA );
+
+  TestCustomActor actorB = TestCustomActor::New();
+  actorA.Add( actorB );
+
+  TestCustomActor actorC = TestCustomActor::New();
+  actorA.Add( actorC );
+
+  TestCustomActor actorD = TestCustomActor::New();
+  actorB.Add( actorD );
+
+  TestCustomActor actorE = TestCustomActor::New();
+  actorB.Add( actorE );
+
+  TestCustomActor actorF = TestCustomActor::New();
+  actorC.Add( actorF );
+
+  // Excercise the message passing to Update thread
+  application.SendNotification();
+  application.Render();
+  application.Render();
+
+  DALI_TEST_EQUALS( 1u, actorA.GetDepth(), TEST_LOCATION );
+  DALI_TEST_EQUALS( 2u, actorB.GetDepth(), TEST_LOCATION );
+  DALI_TEST_EQUALS( 2u, actorC.GetDepth(), TEST_LOCATION );
+  DALI_TEST_EQUALS( 3u, actorD.GetDepth(), TEST_LOCATION );
+  DALI_TEST_EQUALS( 3u, actorE.GetDepth(), TEST_LOCATION );
+  DALI_TEST_EQUALS( 3u, actorF.GetDepth(), TEST_LOCATION );
+
+  END_TEST;
+}