Merge "Removed redundant resource loading & rendering code" into devel/master
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-Actor.cpp
index b5f360a..cb353df 100644 (file)
@@ -721,11 +721,44 @@ int UtcDaliActorSetSize01(void)
 
   actor.SetSize(vector.x, vector.y);
 
-  // flush the queue and render once
+  // Immediately retrieve the size after setting
+  Vector3 currentSize = actor.GetProperty( Actor::Property::SIZE ).Get< Vector3 >();
+  DALI_TEST_EQUALS( currentSize, vector, Math::MACHINE_EPSILON_0, TEST_LOCATION );
+
+  // Flush the queue and render once
   application.SendNotification();
   application.Render();
 
+  // Check the size in the new frame
   DALI_TEST_CHECK(vector == actor.GetCurrentSize());
+
+  currentSize = actor.GetProperty( Actor::Property::SIZE ).Get< Vector3 >();
+  DALI_TEST_EQUALS( currentSize, vector, Math::MACHINE_EPSILON_0, TEST_LOCATION );
+
+  // Change the resize policy and check whether the size stays the same
+  actor.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
+
+  currentSize = actor.GetProperty( Actor::Property::SIZE ).Get< Vector3 >();
+  DALI_TEST_EQUALS( currentSize, vector, Math::MACHINE_EPSILON_0, TEST_LOCATION );
+
+  // Set a new size after resize policy is changed and check the new size
+  actor.SetSize( Vector3( 0.1f, 0.2f, 0.0f ) );
+
+  currentSize = actor.GetProperty( Actor::Property::SIZE ).Get< Vector3 >();
+  DALI_TEST_EQUALS( currentSize, Vector3( 0.1f, 0.2f, 0.0f ), Math::MACHINE_EPSILON_0, TEST_LOCATION );
+
+  // Change the resize policy again and check whether the new size stays the same
+  actor.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
+
+  currentSize = actor.GetProperty( Actor::Property::SIZE ).Get< Vector3 >();
+  DALI_TEST_EQUALS( currentSize, Vector3( 0.1f, 0.2f, 0.0f ), Math::MACHINE_EPSILON_0, TEST_LOCATION );
+
+  // Set another new size after resize policy is changed and check the new size
+  actor.SetSize( Vector3( 50.0f, 60.0f, 0.0f ) );
+
+  currentSize = actor.GetProperty( Actor::Property::SIZE ).Get< Vector3 >();
+  DALI_TEST_EQUALS( currentSize, Vector3( 50.0f, 60.0f, 0.0f ), Math::MACHINE_EPSILON_0, TEST_LOCATION );
+
   END_TEST;
 }
 
@@ -741,11 +774,20 @@ int UtcDaliActorSetSize02(void)
 
   actor.SetSize(vector.x, vector.y, vector.z);
 
+  // Immediately check the size after setting
+  Vector3 currentSize = actor.GetProperty( Actor::Property::SIZE ).Get< Vector3 >();
+  DALI_TEST_EQUALS( currentSize, vector, Math::MACHINE_EPSILON_0, TEST_LOCATION );
+
   // flush the queue and render once
   application.SendNotification();
   application.Render();
 
+  // Check the size in the new frame
   DALI_TEST_CHECK(vector == actor.GetCurrentSize());
+
+  currentSize = actor.GetProperty( Actor::Property::SIZE ).Get< Vector3 >();
+  DALI_TEST_EQUALS( currentSize, vector, Math::MACHINE_EPSILON_0, TEST_LOCATION );
+
   END_TEST;
 }
 
@@ -761,11 +803,20 @@ int UtcDaliActorSetSize03(void)
 
   actor.SetSize(Vector2(vector.x, vector.y));
 
+  // Immediately check the size after setting
+  Vector3 currentSize = actor.GetProperty( Actor::Property::SIZE ).Get< Vector3 >();
+  DALI_TEST_EQUALS( currentSize, vector, Math::MACHINE_EPSILON_0, TEST_LOCATION );
+
   // flush the queue and render once
   application.SendNotification();
   application.Render();
 
+  // Check the size in the new frame
   DALI_TEST_CHECK(vector == actor.GetCurrentSize());
+
+  currentSize = actor.GetProperty( Actor::Property::SIZE ).Get< Vector3 >();
+  DALI_TEST_EQUALS( currentSize, vector, Math::MACHINE_EPSILON_0, TEST_LOCATION );
+
   END_TEST;
 }
 
@@ -781,20 +832,34 @@ int UtcDaliActorSetSize04(void)
 
   actor.SetSize(vector);
 
+  // Immediately check the size after setting
+  Vector3 currentSize = actor.GetProperty( Actor::Property::SIZE ).Get< Vector3 >();
+  DALI_TEST_EQUALS( currentSize, vector, Math::MACHINE_EPSILON_0, TEST_LOCATION );
+
   // flush the queue and render once
   application.SendNotification();
   application.Render();
 
+  // Check the size in the new frame
   DALI_TEST_CHECK(vector == actor.GetCurrentSize());
 
   Stage::GetCurrent().Add( actor );
   actor.SetSize( Vector3( 0.1f, 0.2f, 0.3f ) );
 
+  // Immediately check the size after setting
+  currentSize = actor.GetProperty( Actor::Property::SIZE ).Get< Vector3 >();
+  DALI_TEST_EQUALS( currentSize, Vector3( 0.1f, 0.2f, 0.3f ), Math::MACHINE_EPSILON_0, TEST_LOCATION );
+
   // flush the queue and render once
   application.SendNotification();
   application.Render();
 
+  // Check the size in the new frame
   DALI_TEST_EQUALS( Vector3( 0.1f, 0.2f, 0.3f ), actor.GetCurrentSize(), TEST_LOCATION );
+
+  currentSize = actor.GetProperty( Actor::Property::SIZE ).Get< Vector3 >();
+  DALI_TEST_EQUALS( currentSize, Vector3( 0.1f, 0.2f, 0.3f ), Math::MACHINE_EPSILON_0, TEST_LOCATION );
+
   Stage::GetCurrent().Remove( actor );
   END_TEST;
 }
@@ -810,28 +875,76 @@ int UtcDaliActorSetSizeIndividual(void)
 
   actor.SetProperty( Actor::Property::SIZE_WIDTH, vector.width );
 
+  // Immediately check the width after setting
+  float sizeWidth = actor.GetProperty( Actor::Property::SIZE_WIDTH ).Get< float >();
+  DALI_TEST_EQUALS( sizeWidth, vector.width, Math::MACHINE_EPSILON_0, TEST_LOCATION );
+
   // flush the queue and render once
   application.SendNotification();
   application.Render();
 
+  // Check the width in the new frame
   DALI_TEST_EQUALS( vector.width, actor.GetCurrentSize().width, TEST_LOCATION );
 
+  sizeWidth = actor.GetProperty( Actor::Property::SIZE_WIDTH ).Get< float >();
+  DALI_TEST_EQUALS( sizeWidth, vector.width, Math::MACHINE_EPSILON_0, TEST_LOCATION );
+
   actor.SetProperty( Actor::Property::SIZE_HEIGHT, vector.height );
 
+  // Immediately check the height after setting
+  float sizeHeight = actor.GetProperty( Actor::Property::SIZE_HEIGHT ).Get< float >();
+  DALI_TEST_EQUALS( sizeHeight, vector.height, Math::MACHINE_EPSILON_0, TEST_LOCATION );
+
   // flush the queue and render once
   application.SendNotification();
   application.Render();
 
+  // Check the height in the new frame
   DALI_TEST_EQUALS( vector.height, actor.GetCurrentSize().height, TEST_LOCATION );
 
+  sizeHeight = actor.GetProperty( Actor::Property::SIZE_HEIGHT ).Get< float >();
+  DALI_TEST_EQUALS( sizeHeight, vector.height, Math::MACHINE_EPSILON_0, TEST_LOCATION );
+
   actor.SetProperty( Actor::Property::SIZE_DEPTH, vector.depth );
 
+  // Immediately check the depth after setting
+  float sizeDepth = actor.GetProperty( Actor::Property::SIZE_DEPTH ).Get< float >();
+  DALI_TEST_EQUALS( sizeDepth, vector.depth, Math::MACHINE_EPSILON_0, TEST_LOCATION );
+
   // flush the queue and render once
   application.SendNotification();
   application.Render();
 
+  // Check the depth in the new frame
   DALI_TEST_EQUALS( vector.depth, actor.GetCurrentSize().depth, TEST_LOCATION );
 
+  sizeDepth = actor.GetProperty( Actor::Property::SIZE_DEPTH ).Get< float >();
+  DALI_TEST_EQUALS( sizeDepth, vector.depth, Math::MACHINE_EPSILON_0, TEST_LOCATION );
+
+  // Change the resize policy and check whether the size stays the same
+  actor.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
+
+  sizeWidth = actor.GetProperty( Actor::Property::SIZE_WIDTH ).Get< float >();
+  DALI_TEST_EQUALS( sizeWidth, vector.width, Math::MACHINE_EPSILON_0, TEST_LOCATION );
+
+  sizeHeight = actor.GetProperty( Actor::Property::SIZE_HEIGHT ).Get< float >();
+  DALI_TEST_EQUALS( sizeHeight, vector.height, Math::MACHINE_EPSILON_0, TEST_LOCATION );
+
+  sizeDepth = actor.GetProperty( Actor::Property::SIZE_DEPTH ).Get< float >();
+  DALI_TEST_EQUALS( sizeDepth, vector.depth, Math::MACHINE_EPSILON_0, TEST_LOCATION );
+
+  // Change the resize policy again and check whether the size stays the same
+  actor.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
+
+  sizeWidth = actor.GetProperty( Actor::Property::SIZE_WIDTH ).Get< float >();
+  DALI_TEST_EQUALS( sizeWidth, vector.width, Math::MACHINE_EPSILON_0, TEST_LOCATION );
+
+  sizeHeight = actor.GetProperty( Actor::Property::SIZE_HEIGHT ).Get< float >();
+  DALI_TEST_EQUALS( sizeHeight, vector.height, Math::MACHINE_EPSILON_0, TEST_LOCATION );
+
+  sizeDepth = actor.GetProperty( Actor::Property::SIZE_DEPTH ).Get< float >();
+  DALI_TEST_EQUALS( sizeDepth, vector.depth, Math::MACHINE_EPSILON_0, TEST_LOCATION );
+
   END_TEST;
 }
 
@@ -1878,6 +1991,14 @@ int UtcDaliActorSetColorIndividual(void)
 
   DALI_TEST_EQUALS( vector.a, actor.GetCurrentColor().a, TEST_LOCATION );
 
+  actor.SetProperty( DevelActor::Property::OPACITY, 0.2f );
+
+  // flush the queue and render once
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS( 0.2f, actor.GetCurrentColor().a, TEST_LOCATION );
+
   END_TEST;
 }
 
@@ -2494,6 +2615,12 @@ int UtcDaliActorSetDrawModeOverlayRender(void)
   Actor b = CreateRenderableActor( imageB );
   Actor c = CreateRenderableActor( imageC );
 
+  app.SendNotification();
+  app.Render(1);
+
+  //Textures are bound when first created. Clear bound textures vector
+  app.GetGlAbstraction().ClearBoundTextures();
+
   // Render a,b,c as regular non-overlays. so order will be:
   // a (8)
   // b (9)
@@ -2660,6 +2787,41 @@ int UtcDaliActorConstrainedToOrientation(void)
   END_TEST;
 }
 
+int UtcDaliActorConstrainedToOpacity(void)
+{
+  TestApplication app;
+  tet_infoline(" UtcDaliActorConstrainedToOpacity");
+
+  Actor parent = Actor::New();
+  parent.SetOpacity( 0.7f );
+  Stage::GetCurrent().Add( parent );
+
+  Actor child = Actor::New();
+  Constraint opacityConstraint = Constraint::New<float>( child, DevelActor::Property::OPACITY, EqualToConstraint() );
+  opacityConstraint.AddSource( Source( parent, DevelActor::Property::OPACITY ) );
+  opacityConstraint.Apply();
+
+  Stage::GetCurrent().Add( child );
+
+  app.SendNotification();
+  app.Render(0);
+  app.Render();
+  app.SendNotification();
+
+  DALI_TEST_EQUALS( child.GetCurrentOpacity(), parent.GetCurrentOpacity(), 0.001f, TEST_LOCATION );
+
+  parent.SetOpacity( 0.3f );
+
+  app.SendNotification();
+  app.Render(0);
+  app.Render();
+  app.SendNotification();
+
+  DALI_TEST_EQUALS( child.GetCurrentOpacity(), parent.GetCurrentOpacity(), 0.001f, TEST_LOCATION );
+
+  END_TEST;
+}
+
 int UtcDaliActorUnparent(void)
 {
   TestApplication app;
@@ -2815,8 +2977,8 @@ const PropertyStringIndex PROPERTY_TABLE[] =
   { "minimumSize",              Actor::Property::MINIMUM_SIZE,             Property::VECTOR2     },
   { "maximumSize",              Actor::Property::MAXIMUM_SIZE,             Property::VECTOR2     },
   { "inheritPosition",          Actor::Property::INHERIT_POSITION,         Property::BOOLEAN     },
-  { "batchParent",              DevelActor::Property::BATCH_PARENT,        Property::BOOLEAN     },
   { "clippingMode",             Actor::Property::CLIPPING_MODE,            Property::STRING      },
+  { "opacity",                  DevelActor::Property::OPACITY,             Property::FLOAT       },
 };
 const unsigned int PROPERTY_TABLE_COUNT = sizeof( PROPERTY_TABLE ) / sizeof( PROPERTY_TABLE[0] );
 } // unnamed namespace
@@ -3729,6 +3891,56 @@ int UtcDaliActorPropertyClippingActor(void)
   END_TEST;
 }
 
+int UtcDaliActorPropertyClippingActorEnableThenDisable(void)
+{
+  // This test checks that an actor is correctly setup for clipping and then correctly setup when clipping is disabled
+  tet_infoline( "Testing Actor::Property::CLIPPING_MODE actor enable and then disable" );
+  TestApplication application;
+
+  TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
+  TraceCallStack& stencilTrace = glAbstraction.GetStencilFunctionTrace();
+  TraceCallStack& enabledDisableTrace = glAbstraction.GetEnableDisableTrace();
+  size_t startIndex = 0u;
+
+  // Create a clipping actor.
+  Actor actorDepth1Clip = CreateActorWithContent();
+  actorDepth1Clip.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
+  Stage::GetCurrent().Add( actorDepth1Clip );
+
+  // Gather the call trace.
+  GenerateTrace( application, enabledDisableTrace, stencilTrace );
+
+  // Check we are writing to the color buffer.
+  CheckColorMask( glAbstraction, true );
+
+  // Check the stencil buffer was enabled.
+  DALI_TEST_CHECK( enabledDisableTrace.FindMethodAndParams( "Enable", "2960" ) );                                   // 2960 is GL_STENCIL_TEST
+
+  // Check the stencil buffer was cleared.
+  DALI_TEST_CHECK( stencilTrace.FindMethodAndParamsFromStartIndex( "ClearStencil", "0", startIndex ) );
+
+  // Check the correct setup was done to write to the first bit-plane (only) of the stencil buffer.
+  DALI_TEST_CHECK( stencilTrace.FindMethodAndParamsFromStartIndex( "StencilFunc",  "514, 1, 0", startIndex ) );     // 514 is GL_EQUAL, But testing no bit-planes for the first clipping node.
+  DALI_TEST_CHECK( stencilTrace.FindMethodAndParamsFromStartIndex( "StencilMask", "1", startIndex ) );
+  DALI_TEST_CHECK( stencilTrace.FindMethodAndParamsFromStartIndex( "StencilOp", "7680, 7681, 7681", startIndex ) ); // GL_KEEP, GL_REPLACE, GL_REPLACE
+
+  // Now disable the clipping
+  actorDepth1Clip.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::DISABLED );
+
+  // Gather the call trace.
+  GenerateTrace( application, enabledDisableTrace, stencilTrace );
+
+  // Check the stencil buffer was disabled.
+  DALI_TEST_CHECK( enabledDisableTrace.FindMethodAndParams( "Disable", "2960" ) );                                   // 2960 is GL_STENCIL_TEST
+
+  // Ensure all values in stencil-mask are set to 1.
+  startIndex = 0u;
+  DALI_TEST_CHECK( stencilTrace.FindMethodAndParamsFromStartIndex( "StencilMask", "255", startIndex ) );
+
+  END_TEST;
+}
+
+
 int UtcDaliActorPropertyClippingNestedChildren(void)
 {
   // This test checks that a hierarchy of actors are clipped correctly by