Remove some public Setter/Getter APIs from Dali::Actor
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-Layer.cpp
index 5c6d1b8..65abc00 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2017 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.
@@ -250,7 +250,7 @@ int UtcDaliLayerGetClippingBox(void)
 
 static int gTestSortFunctionCalled;
 
-static float TestSortFunction(const Vector3& /*position*/, float /*sortModifier*/)
+static float TestSortFunction(const Vector3& /*position*/)
 {
   ++gTestSortFunctionCalled;
   return 0.0f;
@@ -262,12 +262,12 @@ int UtcDaliLayerSetSortFunction(void)
   TestApplication application;
   BufferImage img = BufferImage::New( 1,1 );
   // create two transparent actors so there is something to sort
-  ImageActor actor = ImageActor::New( img );
-  ImageActor actor2 = ImageActor::New( img );
+  Actor actor = CreateRenderableActor( img );
+  Actor actor2 = CreateRenderableActor( img );
   actor.SetSize(1,1);
-  actor.SetColor( Vector4(1, 1, 1, 0.5f ) ); // 50% transparent
+  actor.SetProperty( Actor::Property::COLOR, Vector4(1, 1, 1, 0.5f ) ); // 50% transparent
   actor2.SetSize(1,1);
-  actor2.SetColor( Vector4(1, 1, 1, 0.5f ) ); // 50% transparent
+  actor2.SetProperty( Actor::Property::COLOR, Vector4(1, 1, 1, 0.5f ) ); // 50% transparent
 
   // add to stage
   Stage::GetCurrent().Add( actor );
@@ -441,9 +441,10 @@ int UtcDaliLayerDefaultProperties(void)
 
   Layer actor = Layer::New();
 
-  std::vector<Property::Index> indices ;
+  std::vector<Property::Index> indices;
   indices.push_back(Layer::Property::CLIPPING_ENABLE);
   indices.push_back(Layer::Property::CLIPPING_BOX);
+  indices.push_back(Layer::Property::BEHAVIOR);
 
   DALI_TEST_CHECK(actor.GetPropertyCount() == ( Actor::New().GetPropertyCount() + indices.size() ) );
 
@@ -463,17 +464,27 @@ int UtcDaliLayerDefaultProperties(void)
 
   actor.SetProperty(Layer::Property::CLIPPING_BOX, Property::Value(Rect<int>(testBox)));
 
-  DALI_TEST_CHECK(Property::RECTANGLE == actor.GetPropertyType(Layer::Property::CLIPPING_BOX)) ;
+  DALI_TEST_CHECK(Property::RECTANGLE == actor.GetPropertyType(Layer::Property::CLIPPING_BOX));
 
   Property::Value v = actor.GetProperty(Layer::Property::CLIPPING_BOX);
+  DALI_TEST_CHECK(v.Get<Rect<int> >() == testBox);
 
+  v = actor.GetCurrentProperty( Layer::Property::CLIPPING_BOX );
   DALI_TEST_CHECK(v.Get<Rect<int> >() == testBox);
 
   // set the same boundaries, but through a clipping box object
   actor.SetClippingBox( testBox );
-
   DALI_TEST_CHECK( actor.GetClippingBox() == testBox );
 
+  actor.SetProperty(Layer::Property::BEHAVIOR, Property::Value(Layer::LAYER_UI));
+  DALI_TEST_CHECK(Property::STRING == actor.GetPropertyType(Layer::Property::BEHAVIOR));
+
+  Property::Value behavior = actor.GetProperty(Layer::Property::BEHAVIOR);
+  DALI_TEST_EQUALS(behavior.Get<std::string>().c_str(), "LAYER_UI", TEST_LOCATION );
+
+  behavior = actor.GetCurrentProperty( Layer::Property::BEHAVIOR );
+  DALI_TEST_EQUALS(behavior.Get<std::string>().c_str(), "LAYER_UI", TEST_LOCATION );
+
   END_TEST;
 }
 
@@ -483,11 +494,17 @@ int UtcDaliLayerSetDepthTestDisabled(void)
   tet_infoline("Testing Dali::Layer::SetDepthTestDisabled() ");
 
   Layer actor = Layer::New();
+  // Note that IsDepthTestDisabled does not depend on layer behavior,
+  // as 2D layers can still have depth tests performed on a per-renderer basis.
+  // Check default.
+  DALI_TEST_CHECK( actor.IsDepthTestDisabled() );
 
+  // Check Set / Unset.
+  actor.SetDepthTestDisabled( false );
   DALI_TEST_CHECK( !actor.IsDepthTestDisabled() );
-
   actor.SetDepthTestDisabled( true );
   DALI_TEST_CHECK( actor.IsDepthTestDisabled() );
+
   END_TEST;
 }
 
@@ -508,8 +525,8 @@ int UtcDaliLayerPropertyIndices(void)
 
   Property::IndexContainer indices;
   layer.GetPropertyIndices( indices );
-  DALI_TEST_CHECK( indices.size() > basicActor.GetPropertyCount() );
-  DALI_TEST_EQUALS( indices.size(), layer.GetPropertyCount(), TEST_LOCATION );
+  DALI_TEST_CHECK( indices.Size() > basicActor.GetPropertyCount() );
+  DALI_TEST_EQUALS( indices.Size(), layer.GetPropertyCount(), TEST_LOCATION );
   END_TEST;
 }
 
@@ -548,7 +565,7 @@ int UtcDaliLayerClippingGLCalls(void)
 
   // Add at least one renderable actor so the GL calls are actually made
   BufferImage img = BufferImage::New( 1,1 );
-  Actor actor = ImageActor::New( img );
+  Actor actor = CreateRenderableActor( img );
   stage.Add( actor );
 
   // flush the queue and render once
@@ -556,8 +573,74 @@ int UtcDaliLayerClippingGLCalls(void)
   application.Render();
 
   DALI_TEST_EQUALS( testBox.x, glScissorParams.x, TEST_LOCATION );
-  DALI_TEST_EQUALS( testBox.y, stage.GetSize().height - glScissorParams.y - testBox.height, TEST_LOCATION ); // GL Coordinates are from bottom left
+  DALI_TEST_EQUALS( testBox.y, (int)(stage.GetSize().height - glScissorParams.y - testBox.height), TEST_LOCATION ); // GL Coordinates are from bottom left
   DALI_TEST_EQUALS( testBox.width, glScissorParams.width, TEST_LOCATION );
   DALI_TEST_EQUALS( testBox.height, glScissorParams.height, TEST_LOCATION );
   END_TEST;
 }
+
+int UtcDaliLayerBehaviour(void)
+{
+  TestApplication application;
+  Layer layer = Layer::New();
+
+  DALI_TEST_EQUALS( layer.GetBehavior(), Dali::Layer::LAYER_UI, TEST_LOCATION );
+  layer.SetBehavior( Dali::Layer::LAYER_3D );
+  DALI_TEST_EQUALS( layer.GetBehavior(), Dali::Layer::LAYER_3D, TEST_LOCATION );
+  END_TEST;
+}
+
+Actor CreateActor( bool withAlpha )
+{
+  Dali::BufferImage bufferImage;
+
+  if( withAlpha )
+  {
+    bufferImage = Dali::BufferImage::WHITE();
+  }
+  else
+  {
+    bufferImage = BufferImage::New( 1u, 1u, Pixel::RGB888 );
+    PixelBuffer* pBuffer = bufferImage.GetBuffer();
+    if( pBuffer )
+    {
+      pBuffer[0] = pBuffer[1] = pBuffer[2] = 0xFF;
+    }
+  }
+
+  Actor actor = CreateRenderableActor( bufferImage );
+  actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
+  actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
+
+  return actor;
+}
+
+int UtcDaliLayer3DSort(void)
+{
+  tet_infoline( "Testing LAYER_3D sort coverage test" );
+  TestApplication application;
+  TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
+  TraceCallStack& enabledDisableTrace = glAbstraction.GetEnableDisableTrace();
+
+  Stage::GetCurrent().GetRootLayer().SetBehavior( Layer::LAYER_3D );
+
+  // Create an actor.
+  Actor actor = CreateActor( false );
+  Stage::GetCurrent().Add( actor );
+
+  // Create child actors.
+  Actor child1 = CreateActor( true );
+  actor.Add( child1 );
+  Actor child2 = CreateActor( false );
+  child1.Add( child2 );
+
+  enabledDisableTrace.Reset();
+  enabledDisableTrace.Enable( true );
+  application.SendNotification();
+  application.Render();
+  enabledDisableTrace.Enable( false );
+
+  DALI_TEST_CHECK( enabledDisableTrace.FindMethodAndParams( "Enable", "2929" ) );  // 2929 is GL_DEPTH_TEST
+
+  END_TEST;
+}