Moved some Actor APIs to the Public API
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-Actor.cpp
index 34ef21c..439f2d1 100644 (file)
@@ -51,6 +51,8 @@ bool gHoverCallBackCalled=false;
 
 static bool gTestConstraintCalled;
 
+LayoutDirection::Type gLayoutDirectionType;
+
 struct TestConstraint
 {
   void operator()( Vector4& color, const PropertyInputContainer& /* inputs */ )
@@ -4218,6 +4220,98 @@ int UtcDaliActorPropertyClippingNestedChildren(void)
   END_TEST;
 }
 
+int UtcDaliActorPropertyClippingActorDrawOrder(void)
+{
+  // This test checks that a hierarchy of actors are drawn in the correct order when clipping is enabled.
+  tet_infoline( "Testing Actor::Property::CLIPPING_MODE draw order" );
+  TestApplication application;
+  TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
+  TraceCallStack& enabledDisableTrace = glAbstraction.GetEnableDisableTrace();
+
+  /* We create a small tree of actors as follows:
+
+                           A
+                          / \
+     Clipping enabled -> B   D
+                         |   |
+                         C   E
+
+     The correct draw order is "ABCDE" (the same as if clipping was not enabled).
+  */
+  Actor actors[5];
+  for( int i = 0; i < 5; ++i )
+  {
+    BufferImage image = BufferImage::New( 16u, 16u );
+    Actor actor = CreateRenderableActor( image );
+
+    // Setup dimensions and position so actor is not skipped by culling.
+    actor.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
+    actor.SetSize( 16.0f, 16.0f );
+
+    if( i == 0 )
+    {
+      actor.SetParentOrigin( ParentOrigin::CENTER );
+    }
+    else
+    {
+      float b = i > 2 ? 1.0f : -1.0f;
+      actor.SetParentOrigin( Vector3( 0.5 + ( 0.2f * b ), 0.8f, 0.8f ) );
+    }
+
+    actors[i] = actor;
+  }
+
+  // Enable clipping on the actor at the top of the left branch.
+  actors[1].SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
+
+  // Build the scene graph.
+  Stage::GetCurrent().Add( actors[0] );
+
+  // Left branch:
+  actors[0].Add( actors[1] );
+  actors[1].Add( actors[2] );
+
+  // Right branch:
+  actors[0].Add( actors[3] );
+  actors[3].Add( actors[4] );
+
+  // Gather the call trace.
+  enabledDisableTrace.Reset();
+  enabledDisableTrace.Enable( true );
+  application.SendNotification();
+  application.Render();
+  enabledDisableTrace.Enable( false );
+
+  /* Check stencil is enabled and disabled again (as right-hand branch of tree is drawn).
+
+     Note: Correct enable call trace:    StackTrace: Index:0, Function:Enable, ParamList:3042 StackTrace: Index:1, Function:Enable, ParamList:2960 StackTrace: Index:2, Function:Disable, ParamList:2960
+           Incorrect enable call trace:  StackTrace: Index:0, Function:Enable, ParamList:3042 StackTrace: Index:1, Function:Enable, ParamList:2960
+  */
+  size_t startIndex = 0u;
+  DALI_TEST_CHECK( enabledDisableTrace.FindMethodAndParamsFromStartIndex( "Enable",  "3042", startIndex ) );
+  DALI_TEST_CHECK( enabledDisableTrace.FindMethodAndParamsFromStartIndex( "Enable",  "2960", startIndex ) ); // 2960 is GL_STENCIL_TEST
+  DALI_TEST_CHECK( enabledDisableTrace.FindMethodAndParamsFromStartIndex( "Disable", "2960", startIndex ) );
+
+  // Swap the clipping actor from top of left branch to top of right branch.
+  actors[1].SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::DISABLED );
+  actors[3].SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
+
+  // Gather the call trace.
+  enabledDisableTrace.Reset();
+  enabledDisableTrace.Enable( true );
+  application.SendNotification();
+  application.Render();
+  enabledDisableTrace.Enable( false );
+
+  // Check stencil is enabled but NOT disabled again (as right-hand branch of tree is drawn).
+  // This proves the draw order has remained the same.
+  startIndex = 0u;
+  DALI_TEST_CHECK( enabledDisableTrace.FindMethodAndParamsFromStartIndex(  "Enable",  "2960", startIndex ) );
+  DALI_TEST_CHECK( !enabledDisableTrace.FindMethodAndParamsFromStartIndex( "Disable", "2960", startIndex ) );
+
+  END_TEST;
+}
+
 int UtcDaliActorPropertyClippingActorWithRendererOverride(void)
 {
   // This test checks that an actor with clipping will be ignored if overridden by the Renderer properties.
@@ -4337,7 +4431,7 @@ int UtcDaliActorRaiseLower(void)
   Property::Value value  = actorB.GetProperty(Dali::DevelActor::Property::SIBLING_ORDER );
   value.Get( preActorOrder );
 
-  DevelActor::Raise( actorB );
+  actorB.Raise();
   // Ensure sort order is calculated before next touch event
   application.SendNotification();
 
@@ -4359,7 +4453,7 @@ int UtcDaliActorRaiseLower(void)
   value  = actorB.GetProperty(Dali::DevelActor::Property::SIBLING_ORDER );
   value.Get( preActorOrder );
 
-  DevelActor::Lower( actorB );
+  actorB.Lower();
   application.SendNotification(); // ensure sort order calculated before next touch event
 
   value  = actorB.GetProperty(Dali::DevelActor::Property::SIBLING_ORDER );
@@ -4486,7 +4580,7 @@ int UtcDaliActorRaiseToTopLowerToBottom(void)
 
   tet_printf( "RaiseToTop ActorA\n" );
 
-  DevelActor::RaiseToTop( actorA );
+  actorA.RaiseToTop();
   application.SendNotification(); // ensure sorting order is calculated before next touch event
 
   application.ProcessEvent( touchEvent );
@@ -4517,7 +4611,7 @@ int UtcDaliActorRaiseToTopLowerToBottom(void)
 
   tet_printf( "RaiseToTop ActorB\n" );
 
-  DevelActor::RaiseToTop( actorB );
+  actorB.RaiseToTop();
   application.SendNotification(); // Ensure sort order is calculated before next touch event
 
   application.ProcessEvent( touchEvent );
@@ -4548,11 +4642,11 @@ int UtcDaliActorRaiseToTopLowerToBottom(void)
 
   tet_printf( "LowerToBottom ActorA then ActorB leaving Actor C at Top\n" );
 
-  DevelActor::LowerToBottom( actorA );
+  actorA.LowerToBottom();
   application.SendNotification();
   application.Render();
 
-  DevelActor::LowerToBottom( actorB );
+  actorB.LowerToBottom();
   application.SendNotification();
   application.Render();
 
@@ -4651,7 +4745,7 @@ int UtcDaliActorRaiseAbove(void)
 
   tet_printf( "Raise actor B Above Actor C\n" );
 
-  DevelActor::RaiseAbove( actorB, actorC );
+  actorB.RaiseAbove( actorC );
   // Ensure sorting happens at end of Core::ProcessEvents() before next touch
   application.SendNotification();
 
@@ -4665,7 +4759,7 @@ int UtcDaliActorRaiseAbove(void)
 
   tet_printf( "Raise actor A Above Actor B\n" );
 
-  DevelActor::RaiseAbove( actorA, actorB );
+  actorA.RaiseAbove( actorB );
 
   // Ensure sorting happens at end of Core::ProcessEvents() before next touch
   application.SendNotification();
@@ -4799,7 +4893,7 @@ int UtcDaliActorLowerBelow(void)
 
   tet_printf( "Lower actor C below Actor B ( actor B and A on same level due to insertion order) so C is below both \n" );
 
-  DevelActor::LowerBelow( actorC, actorB );
+  actorC.LowerBelow( actorB );
   // Ensure sorting happens at end of Core::ProcessEvents() before next touch
   application.SendNotification();
   application.Render();
@@ -4831,7 +4925,7 @@ int UtcDaliActorLowerBelow(void)
 
   tet_printf( "Lower actor C below Actor A leaving B on top\n" );
 
-  DevelActor::LowerBelow( actorC, actorA );
+  actorC.LowerBelow( actorA );
   // Ensure sorting happens at end of Core::ProcessEvents() before next touch
   application.SendNotification();
   application.Render();
@@ -4860,7 +4954,7 @@ int UtcDaliActorLowerBelow(void)
 
   tet_printf( "Lower actor B below Actor C leaving A on top\n" );
 
-  DevelActor::LowerBelow( actorB, actorC );
+  actorB.LowerBelow( actorC );
   // Ensure sorting happens at end of Core::ProcessEvents() before next touch
   application.SendNotification();
   application.Render();
@@ -4969,7 +5063,7 @@ int UtcDaliActorRaiseAboveDifferentParentsN(void)
 
   tet_printf( "Raise actor A Above Actor C which have different parents\n" );
 
-  DevelActor::RaiseAbove( actorA, actorC );
+  actorA.RaiseAbove( actorC );
   // Ensure sorting happens at end of Core::ProcessEvents() before next touch
   application.SendNotification();
 
@@ -5038,7 +5132,7 @@ int UtcDaliActorRaiseLowerWhenUnparentedTargetN(void)
 
   tet_printf( "Raise actor A Above Actor C which have no parents\n" );
 
-  DevelActor::RaiseAbove( actorA, actorC );
+  actorA.RaiseAbove( actorC );
   // Ensure sorting happens at end of Core::ProcessEvents() before next touch
   application.SendNotification();
 
@@ -5054,7 +5148,7 @@ int UtcDaliActorRaiseLowerWhenUnparentedTargetN(void)
 
   stage.Add ( actorB );
   tet_printf( "Lower actor A below Actor C when only A is not on stage \n" );
-  DevelActor::LowerBelow( actorA, actorC );
+  actorA.LowerBelow( actorC );
 
   // Ensure sorting happens at end of Core::ProcessEvents() before next touch
   application.SendNotification();
@@ -5076,7 +5170,7 @@ int UtcDaliActorRaiseLowerWhenUnparentedTargetN(void)
   application.Render();
 
   tet_printf( "Raise actor B Above Actor C when only B has a parent\n" );
-  DevelActor::RaiseAbove( actorB, actorC );
+  actorB.RaiseAbove( actorC );
   // Ensure sorting happens at end of Core::ProcessEvents() before next touch
   application.SendNotification();
 
@@ -5090,7 +5184,7 @@ int UtcDaliActorRaiseLowerWhenUnparentedTargetN(void)
   ResetTouchCallbacks();
 
   tet_printf( "Lower actor A below Actor C when only A has a parent\n" );
-  DevelActor::LowerBelow( actorA, actorC );
+  actorA.LowerBelow( actorC );
   // Ensure sorting happens at end of Core::ProcessEvents() before next touch
   application.SendNotification();
 
@@ -5104,7 +5198,7 @@ int UtcDaliActorRaiseLowerWhenUnparentedTargetN(void)
   ResetTouchCallbacks();
 
   stage.Add ( actorC );
-  DevelActor::RaiseAbove( actorA, actorC );
+  actorA.RaiseAbove( actorC );
   // Ensure sorting happens at end of Core::ProcessEvents() before next touch
   application.SendNotification();
   application.Render();
@@ -5166,7 +5260,7 @@ int UtcDaliActorTestAllAPIwhenActorNotParented(void)
 
   stage.Add ( actorA );
   tet_printf( "Raise actor B Above Actor C but B not parented\n" );
-  DevelActor::Raise( actorB );
+  actorB.Raise();
 
   application.SendNotification();
   application.Render();
@@ -5182,7 +5276,7 @@ int UtcDaliActorTestAllAPIwhenActorNotParented(void)
   tet_printf( "Raise actor B Above Actor C but B not parented\n" );
   ResetTouchCallbacks();
 
-  DevelActor::Lower( actorC );
+  actorC.Lower();
   // Sort actor tree before next touch event
   application.SendNotification();
   application.Render();
@@ -5198,7 +5292,7 @@ int UtcDaliActorTestAllAPIwhenActorNotParented(void)
 
   tet_printf( "Lower actor C below B but C not parented\n" );
 
-  DevelActor::Lower( actorB );
+  actorB.Lower();
   // Sort actor tree before next touch event
   application.SendNotification();
   application.Render();
@@ -5214,7 +5308,7 @@ int UtcDaliActorTestAllAPIwhenActorNotParented(void)
 
   tet_printf( "Raise actor B to top\n" );
 
-  DevelActor::RaiseToTop( actorB );
+  actorB.RaiseToTop();
   // Sort actor tree before next touch event
   application.SendNotification();
   application.Render();
@@ -5234,7 +5328,7 @@ int UtcDaliActorTestAllAPIwhenActorNotParented(void)
 
   tet_printf( "Lower actor C to Bottom, B stays at top\n" );
 
-  DevelActor::LowerToBottom( actorC );
+  actorC.LowerToBottom();
   application.SendNotification();
   application.Render();
 
@@ -5313,7 +5407,7 @@ int UtcDaliActorRaiseAboveActorAndTargetTheSameN(void)
 
   tet_infoline( "Raise actor A Above Actor A which is the same actor!!\n" );
 
-  DevelActor::RaiseAbove( actorA, actorA );
+  actorA.RaiseAbove( actorA );
   application.SendNotification();
   application.Render();
 
@@ -5327,7 +5421,7 @@ int UtcDaliActorRaiseAboveActorAndTargetTheSameN(void)
 
   ResetTouchCallbacks();
 
-  DevelActor::RaiseAbove( actorA, actorC );
+  actorA.RaiseAbove( actorC );
   application.SendNotification();
   application.Render();
 
@@ -6028,3 +6122,97 @@ int utcDaliActorVisibilityChangeSignalAfterAnimation(void)
 
   END_TEST;
 }
+
+
+static void LayoutDirectionChanged( Actor actor, LayoutDirection::Type type )
+{
+  gLayoutDirectionType = type;
+}
+
+int UtcDaliActorLayoutDirectionProperty(void)
+{
+  TestApplication application;
+  tet_infoline( "Check layout direction property" );
+
+  Actor actor0 = Actor::New();
+  DALI_TEST_EQUALS( actor0.GetProperty< int >( Actor::Property::LAYOUT_DIRECTION ), static_cast< int >( LayoutDirection::LEFT_TO_RIGHT ), TEST_LOCATION );
+  Stage::GetCurrent().Add( actor0 );
+
+  application.SendNotification();
+  application.Render();
+
+  Actor actor1 = Actor::New();
+  DALI_TEST_EQUALS( actor1.GetProperty< int >( Actor::Property::LAYOUT_DIRECTION ), static_cast< int >( LayoutDirection::LEFT_TO_RIGHT ), TEST_LOCATION );
+  Actor actor2 = Actor::New();
+  DALI_TEST_EQUALS( actor2.GetProperty< int >( Actor::Property::LAYOUT_DIRECTION ), static_cast< int >( LayoutDirection::LEFT_TO_RIGHT ), TEST_LOCATION );
+  Actor actor3 = Actor::New();
+  DALI_TEST_EQUALS( actor3.GetProperty< int >( Actor::Property::LAYOUT_DIRECTION ), static_cast< int >( LayoutDirection::LEFT_TO_RIGHT ), TEST_LOCATION );
+  Actor actor4 = Actor::New();
+  DALI_TEST_EQUALS( actor4.GetProperty< int >( Actor::Property::LAYOUT_DIRECTION ), static_cast< int >( LayoutDirection::LEFT_TO_RIGHT ), TEST_LOCATION );
+  Actor actor5 = Actor::New();
+  DALI_TEST_EQUALS( actor5.GetProperty< int >( Actor::Property::LAYOUT_DIRECTION ), static_cast< int >( LayoutDirection::LEFT_TO_RIGHT ), TEST_LOCATION );
+  Actor actor6 = Actor::New();
+  DALI_TEST_EQUALS( actor6.GetProperty< int >( Actor::Property::LAYOUT_DIRECTION ), static_cast< int >( LayoutDirection::LEFT_TO_RIGHT ), TEST_LOCATION );
+  Actor actor7 = Actor::New();
+  DALI_TEST_EQUALS( actor7.GetProperty< int >( Actor::Property::LAYOUT_DIRECTION ), static_cast< int >( LayoutDirection::LEFT_TO_RIGHT ), TEST_LOCATION );
+  Actor actor8 = Actor::New();
+  DALI_TEST_EQUALS( actor8.GetProperty< int >( Actor::Property::LAYOUT_DIRECTION ), static_cast< int >( LayoutDirection::LEFT_TO_RIGHT ), TEST_LOCATION );
+  Actor actor9 = Actor::New();
+  DALI_TEST_EQUALS( actor9.GetProperty< int >( Actor::Property::LAYOUT_DIRECTION ), static_cast< int >( LayoutDirection::LEFT_TO_RIGHT ), TEST_LOCATION );
+
+  actor1.Add( actor2 );
+  gLayoutDirectionType = LayoutDirection::LEFT_TO_RIGHT;
+  actor2.LayoutDirectionChangedSignal().Connect( LayoutDirectionChanged );
+
+  DALI_TEST_EQUALS( actor1.GetProperty< bool >( Actor::Property::INHERIT_LAYOUT_DIRECTION ), true, TEST_LOCATION );
+  actor1.SetProperty( Actor::Property::LAYOUT_DIRECTION, LayoutDirection::RIGHT_TO_LEFT );
+  DALI_TEST_EQUALS( actor1.GetProperty< bool >( Actor::Property::INHERIT_LAYOUT_DIRECTION ), false, TEST_LOCATION );
+
+  DALI_TEST_EQUALS( actor1.GetProperty< int >( Actor::Property::LAYOUT_DIRECTION ), static_cast< int >( LayoutDirection::RIGHT_TO_LEFT ), TEST_LOCATION );
+  DALI_TEST_EQUALS( actor2.GetProperty< int >( Actor::Property::LAYOUT_DIRECTION ), static_cast< int >( LayoutDirection::RIGHT_TO_LEFT ), TEST_LOCATION );
+  DALI_TEST_EQUALS( gLayoutDirectionType, LayoutDirection::RIGHT_TO_LEFT, TEST_LOCATION );
+
+  actor1.SetProperty( Actor::Property::INHERIT_LAYOUT_DIRECTION, true );
+  actor0.Add( actor1 );
+  DALI_TEST_EQUALS( actor1.GetProperty< int >( Actor::Property::LAYOUT_DIRECTION ), static_cast< int >( LayoutDirection::LEFT_TO_RIGHT ), TEST_LOCATION );
+  DALI_TEST_EQUALS( actor2.GetProperty< int >( Actor::Property::LAYOUT_DIRECTION ), static_cast< int >( LayoutDirection::LEFT_TO_RIGHT ), TEST_LOCATION );
+
+  Stage::GetCurrent().Add( actor3 );
+  actor3.Add( actor4 );
+  actor4.Add( actor5 );
+  actor5.Add( actor6 );
+  actor5.Add( actor7 );
+  actor7.Add( actor8 );
+  actor8.Add( actor9 );
+  actor3.SetProperty( Actor::Property::LAYOUT_DIRECTION, "RIGHT_TO_LEFT" );
+  actor5.SetProperty( Actor::Property::LAYOUT_DIRECTION, LayoutDirection::LEFT_TO_RIGHT );
+
+  DALI_TEST_EQUALS( actor8.GetProperty< bool >( Actor::Property::INHERIT_LAYOUT_DIRECTION ), true, TEST_LOCATION );
+  actor8.SetProperty( Actor::Property::INHERIT_LAYOUT_DIRECTION, false );
+  DALI_TEST_EQUALS( actor8.GetProperty< bool >( Actor::Property::INHERIT_LAYOUT_DIRECTION ), false, TEST_LOCATION );
+
+  actor7.SetProperty( Actor::Property::LAYOUT_DIRECTION, "RIGHT_TO_LEFT" );
+
+  DALI_TEST_EQUALS( actor3.GetProperty< int >( Actor::Property::LAYOUT_DIRECTION ), static_cast< int >( LayoutDirection::RIGHT_TO_LEFT ), TEST_LOCATION );
+  DALI_TEST_EQUALS( actor4.GetProperty< int >( Actor::Property::LAYOUT_DIRECTION ), static_cast< int >( LayoutDirection::RIGHT_TO_LEFT ), TEST_LOCATION );
+  DALI_TEST_EQUALS( actor5.GetProperty< int >( Actor::Property::LAYOUT_DIRECTION ), static_cast< int >( LayoutDirection::LEFT_TO_RIGHT ), TEST_LOCATION );
+  DALI_TEST_EQUALS( actor6.GetProperty< int >( Actor::Property::LAYOUT_DIRECTION ), static_cast< int >( LayoutDirection::LEFT_TO_RIGHT ), TEST_LOCATION );
+  DALI_TEST_EQUALS( actor7.GetProperty< int >( Actor::Property::LAYOUT_DIRECTION ), static_cast< int >( LayoutDirection::RIGHT_TO_LEFT ), TEST_LOCATION );
+  DALI_TEST_EQUALS( actor8.GetProperty< int >( Actor::Property::LAYOUT_DIRECTION ), static_cast< int >( LayoutDirection::LEFT_TO_RIGHT ), TEST_LOCATION );
+  DALI_TEST_EQUALS( actor9.GetProperty< int >( Actor::Property::LAYOUT_DIRECTION ), static_cast< int >( LayoutDirection::LEFT_TO_RIGHT ), TEST_LOCATION );
+
+  actor8.SetProperty( Actor::Property::LAYOUT_DIRECTION, "RIGHT_TO_LEFT" );
+  DALI_TEST_EQUALS( actor8.GetProperty< int >( Actor::Property::LAYOUT_DIRECTION ), static_cast< int >( LayoutDirection::RIGHT_TO_LEFT ), TEST_LOCATION );
+  DALI_TEST_EQUALS( actor9.GetProperty< int >( Actor::Property::LAYOUT_DIRECTION ), static_cast< int >( LayoutDirection::RIGHT_TO_LEFT ), TEST_LOCATION );
+
+  actor7.SetProperty( Actor::Property::LAYOUT_DIRECTION, LayoutDirection::LEFT_TO_RIGHT );
+  DALI_TEST_EQUALS( actor7.GetProperty< int >( Actor::Property::LAYOUT_DIRECTION ), static_cast< int >( LayoutDirection::LEFT_TO_RIGHT ), TEST_LOCATION );
+  DALI_TEST_EQUALS( actor8.GetProperty< int >( Actor::Property::LAYOUT_DIRECTION ), static_cast< int >( LayoutDirection::RIGHT_TO_LEFT ), TEST_LOCATION );
+  DALI_TEST_EQUALS( actor9.GetProperty< int >( Actor::Property::LAYOUT_DIRECTION ), static_cast< int >( LayoutDirection::RIGHT_TO_LEFT ), TEST_LOCATION );
+
+  actor8.SetProperty( Actor::Property::INHERIT_LAYOUT_DIRECTION, true );
+  DALI_TEST_EQUALS( actor8.GetProperty< int >( Actor::Property::LAYOUT_DIRECTION ), static_cast< int >( LayoutDirection::LEFT_TO_RIGHT ), TEST_LOCATION );
+  DALI_TEST_EQUALS( actor9.GetProperty< int >( Actor::Property::LAYOUT_DIRECTION ), static_cast< int >( LayoutDirection::LEFT_TO_RIGHT ), TEST_LOCATION );
+
+  END_TEST;
+}