Merge "DALi Version 2.1.29" into devel/master
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-CustomActor.cpp
index 6dd051c..e33a738 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 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.
@@ -950,6 +950,8 @@ int UtcDaliCustomActorOnSizeAnimation(void)
   Test::TestCustomActor custom = Test::TestCustomActor::New();
   DALI_TEST_EQUALS(0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION);
 
+  application.GetScene().Add(custom);
+
   Animation anim = Animation::New(1.0f);
   anim.AnimateTo(Property(custom, Actor::Property::SIZE), Vector3(8.0f, 9.0f, 10.0f));
   anim.Play();
@@ -957,8 +959,8 @@ int UtcDaliCustomActorOnSizeAnimation(void)
   application.SendNotification();
   application.Render(static_cast<unsigned int>(1000.0f));
 
-  DALI_TEST_EQUALS(1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION);
-  DALI_TEST_EQUALS("OnSizeAnimation", custom.GetMethodsCalled()[0], TEST_LOCATION);
+  DALI_TEST_EQUALS(2, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION);
+  DALI_TEST_EQUALS("OnSizeAnimation", custom.GetMethodsCalled()[1], TEST_LOCATION);
   DALI_TEST_EQUALS(8.0f, custom.GetTargetSize().width, TEST_LOCATION);
   DALI_TEST_EQUALS(9.0f, custom.GetTargetSize().height, TEST_LOCATION);
   DALI_TEST_EQUALS(10.0f, custom.GetTargetSize().depth, TEST_LOCATION);
@@ -974,24 +976,26 @@ int UtcDaliCustomActorSizeComponentAnimation(void)
   float                 intialWidth(10.0f);
 
   DALI_TEST_EQUALS(0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION);
+
   custom.SetProperty(Actor::Property::SIZE, Vector2(intialWidth, 10.0f)); // First method
+  application.GetScene().Add(custom);
 
   Animation anim = Animation::New(1.0f);
 
-  DALI_TEST_EQUALS(2, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION);
+  DALI_TEST_EQUALS(3, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION);
 
   anim.AnimateTo(Property(custom, Actor::Property::SIZE_WIDTH), 20.0f);
 
-  DALI_TEST_EQUALS(2, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION);
+  DALI_TEST_EQUALS(3, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION);
 
   anim.Play(); // Triggers second method ( OnSizeAnimation )
 
   application.SendNotification();
   application.Render(static_cast<unsigned int>(1000.0f));
 
-  DALI_TEST_EQUALS(3, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION);
+  DALI_TEST_EQUALS(4, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION);
 
-  DALI_TEST_EQUALS("OnSizeAnimation", custom.GetMethodsCalled()[2], TEST_LOCATION);
+  DALI_TEST_EQUALS("OnSizeAnimation", custom.GetMethodsCalled()[3], TEST_LOCATION);
 
   END_TEST;
 }
@@ -1077,6 +1081,29 @@ int UtcDaliCustomActorCustomActor(void)
   END_TEST;
 }
 
+int UtcDaliCustomActorImplSetTransparent(void)
+{
+  TestApplication application; // Need the type registry
+
+  Test::TestCustomActor actor = Test::TestCustomActor::New();
+  application.GetScene().Add(actor);
+  actor.SetProperty(Actor::Property::OPACITY, 0.1f);
+  actor.SetProperty(Actor::Property::SIZE, Vector2(400, 400));
+
+  DALI_TEST_EQUALS(false, actor.IsTransparent(), TEST_LOCATION);
+
+  actor.SetTransparent(true);
+
+  // flush the queue and render once
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS(true, actor.IsTransparent(), TEST_LOCATION);
+
+  application.GetScene().Remove(actor);
+  END_TEST;
+}
+
 int UtcDaliCustomActorImplRelayoutRequest(void)
 {
   TestApplication application;
@@ -1156,23 +1183,57 @@ int UtcDaliCustomActorImplCalculateChildSizeBase(void)
 int UtcDaliCustomActorImplRelayoutDependentOnChildrenBase(void)
 {
   TestApplication       application;
-  Test::TestCustomActor custom = Test::TestCustomActor::NewNegoSize();
-  custom.SetResizePolicy(Dali::ResizePolicy::FIT_TO_CHILDREN, Dali::Dimension::ALL_DIMENSIONS);
+  Test::TestCustomActor customNego    = Test::TestCustomActor::NewNegoSize();
+  Test::TestCustomActor customNotNego = Test::TestCustomActor::New();
+
+  // A custom actor with default flags has relayouting enabled on initialization,
+  // and the default resize policy is USE_NATURAL_SIZE.
+  bool v = customNego.TestRelayoutDependentOnChildrenBase(Dali::Dimension::ALL_DIMENSIONS);
+  DALI_TEST_CHECK(v == true);
 
-  bool v = custom.TestRelayoutDependentOnChildrenBase(Dali::Dimension::ALL_DIMENSIONS);
+  // A custom actor with size negotiation explicitly switched off has no relayouting,
+  // and will not have any relayout dependencies. However, default resize policy when
+  // there is no relayouting is to return USE_NATURAL_SIZE, so this will actually return true,
+  // and is consistent.
+  v = customNotNego.TestRelayoutDependentOnChildrenBase(Dali::Dimension::ALL_DIMENSIONS);
+  DALI_TEST_CHECK(v == true);
+
+  customNego.SetResizePolicy(Dali::ResizePolicy::FIT_TO_CHILDREN, Dali::Dimension::ALL_DIMENSIONS);
+  customNotNego.SetResizePolicy(Dali::ResizePolicy::FIT_TO_CHILDREN, Dali::Dimension::ALL_DIMENSIONS);
+
+  v = customNego.TestRelayoutDependentOnChildrenBase(Dali::Dimension::ALL_DIMENSIONS);
+  DALI_TEST_CHECK(v == true);
+  v = customNotNego.TestRelayoutDependentOnChildrenBase(Dali::Dimension::ALL_DIMENSIONS);
   DALI_TEST_CHECK(v == true);
 
   application.SendNotification();
   application.Render();
 
-  custom.SetResizePolicy(Dali::ResizePolicy::FIXED, Dali::Dimension::ALL_DIMENSIONS);
-  v = custom.TestRelayoutDependentOnChildrenBase(Dali::Dimension::WIDTH);
+  customNego.SetResizePolicy(Dali::ResizePolicy::FIXED, Dali::Dimension::ALL_DIMENSIONS);
+  customNotNego.SetResizePolicy(Dali::ResizePolicy::FIXED, Dali::Dimension::ALL_DIMENSIONS);
+  v = customNego.TestRelayoutDependentOnChildrenBase(Dali::Dimension::WIDTH);
+  DALI_TEST_CHECK(v == false);
+  v = customNego.TestRelayoutDependentOnChildrenBase(Dali::Dimension::HEIGHT);
+  DALI_TEST_CHECK(v == false);
+  v = customNotNego.TestRelayoutDependentOnChildrenBase(Dali::Dimension::WIDTH);
+  DALI_TEST_CHECK(v == false);
+  v = customNotNego.TestRelayoutDependentOnChildrenBase(Dali::Dimension::HEIGHT);
   DALI_TEST_CHECK(v == false);
 
-  // why is this here?
   application.SendNotification();
   application.Render();
 
+  customNego.SetResizePolicy(Dali::ResizePolicy::USE_NATURAL_SIZE, Dali::Dimension::WIDTH);
+  customNotNego.SetResizePolicy(Dali::ResizePolicy::USE_NATURAL_SIZE, Dali::Dimension::HEIGHT);
+  v = customNego.TestRelayoutDependentOnChildrenBase(Dali::Dimension::WIDTH);
+  DALI_TEST_CHECK(v == true);
+  v = customNego.TestRelayoutDependentOnChildrenBase(Dali::Dimension::HEIGHT);
+  DALI_TEST_CHECK(v == false);
+  v = customNotNego.TestRelayoutDependentOnChildrenBase(Dali::Dimension::WIDTH);
+  DALI_TEST_CHECK(v == false);
+  v = customNotNego.TestRelayoutDependentOnChildrenBase(Dali::Dimension::HEIGHT);
+  DALI_TEST_CHECK(v == true);
+
   END_TEST;
 }