X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=automated-tests%2Fsrc%2Fdali%2Futc-Dali-CustomActor.cpp;h=1df10a6df91c3e7ae546273476fccc2409b9b722;hb=fe58df83b2d72c4beceb101eb9cffcc5442f3d6e;hp=208f5634c7a8ee58ee629ce627d15a5afd6f12d9;hpb=91f3a7014e5633ea185eaf9a624bba52e71feff6;p=platform%2Fcore%2Fuifw%2Fdali-core.git diff --git a/automated-tests/src/dali/utc-Dali-CustomActor.cpp b/automated-tests/src/dali/utc-Dali-CustomActor.cpp index 208f563..1df10a6 100644 --- a/automated-tests/src/dali/utc-Dali-CustomActor.cpp +++ b/automated-tests/src/dali/utc-Dali-CustomActor.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 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. @@ -31,6 +31,14 @@ using namespace Dali; +namespace Test +{ +void Doubler(float& current, const PropertyInputContainer& inputs) +{ + current = 2.0f * inputs[0]->GetFloat(); +} +} // namespace Test + void custom_actor_test_startup(void) { test_return_value = TET_UNDEF; @@ -1081,6 +1089,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; @@ -1160,23 +1191,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; } @@ -1552,3 +1617,95 @@ int UtcDaliCustomActorPropertyRegistrationDefaultValue(void) END_TEST; } + +int UtcDaliCustomActorComponentPropertyConstraintsP(void) +{ + TestApplication application; // Need the type registry + + // register our base and add a property with default value for it + Dali::TypeRegistration typeRegistration(typeid(UnregisteredCustomActor), typeid(Dali::CustomActor), nullptr); + + auto derived = DerivedCustomActor::New(); + application.GetScene().Add(derived); + + // should have all actor properties + auto actorHandle = Actor::New(); + DALI_TEST_EQUALS(derived.GetPropertyCount(), actorHandle.GetPropertyCount(), TEST_LOCATION); + + // add a property in base class + const Property::Index foobarIndex = ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX; + const Property::Index fooIndex = foobarIndex + 1; + const Property::Index barIndex = foobarIndex + 2; + + AnimatablePropertyRegistration(typeRegistration, "Foobar", foobarIndex, Vector2(10.0f, 20.0f)); + AnimatablePropertyComponentRegistration(typeRegistration, "Foobar.x", fooIndex, foobarIndex, 0); + AnimatablePropertyComponentRegistration(typeRegistration, "Foobar.y", barIndex, foobarIndex, 1); + + tet_infoline("Test the default values of the registered property"); + // should be more properties now + DALI_TEST_EQUALS(derived.GetPropertyCount(), actorHandle.GetPropertyCount() + 3, TEST_LOCATION); + // check that the default value is set for base class + DALI_TEST_EQUALS(UnregisteredCustomActor::New().GetProperty(foobarIndex).Get(), Vector2(10.f, 20.0f), 0.0001f, TEST_LOCATION); + // check that the default value is set for the derived instance as well + DALI_TEST_EQUALS(derived.GetProperty(foobarIndex).Get(), Vector2(10.f, 20.0f), 0.0001f, TEST_LOCATION); + + tet_infoline("Test that the components of the registered property can be constrained"); + + // Try constraining the properties + Constraint fooCons = Constraint::New(derived, fooIndex, &Test::Doubler); + fooCons.AddSource(LocalSource(Actor::Property::POSITION_X)); + fooCons.Apply(); + Constraint barCons = Constraint::New(derived, barIndex, &Test::Doubler); + barCons.AddSource(LocalSource(fooIndex)); + barCons.Apply(); + + for(int i = 1; i < 10; ++i) + { + derived[Actor::Property::POSITION_X] = i * 1.0f; + application.SendNotification(); + application.Render(); + DALI_TEST_EQUALS(derived.GetCurrentProperty(foobarIndex).Get(), Vector2(i * 2.0f, i * 4.0f), 0.0001f, TEST_LOCATION); + } + + // Add a Vector3 property and its components for completeness + const Property::Index vec3PropIndex = barIndex + 1; + const Property::Index vec3xPropIndex = vec3PropIndex + 1; + const Property::Index vec3yPropIndex = vec3PropIndex + 2; + const Property::Index vec3zPropIndex = vec3PropIndex + 3; + + AnimatablePropertyRegistration(typeRegistration, "vec3Prop", vec3PropIndex, Vector3(10.0f, 20.0f, 30.0f)); + AnimatablePropertyComponentRegistration(typeRegistration, "vec3Prop.x", vec3xPropIndex, vec3PropIndex, 0); + AnimatablePropertyComponentRegistration(typeRegistration, "vec3Prop.y", vec3yPropIndex, vec3PropIndex, 1); + AnimatablePropertyComponentRegistration(typeRegistration, "vec3Prop.z", vec3zPropIndex, vec3PropIndex, 2); + + tet_infoline("Test the default values of the registered vec3 property"); + // should be more properties now + DALI_TEST_EQUALS(derived.GetPropertyCount(), actorHandle.GetPropertyCount() + 7, TEST_LOCATION); + // check that the default value is set for base class + DALI_TEST_EQUALS(UnregisteredCustomActor::New().GetProperty(vec3PropIndex).Get(), Vector3(10.f, 20.0f, 30.0f), 0.0001f, TEST_LOCATION); + // check that the default value is set for the derived instance as well + DALI_TEST_EQUALS(derived.GetProperty(vec3PropIndex).Get(), Vector3(10.f, 20.0f, 30.0f), 0.0001f, TEST_LOCATION); + + tet_infoline("Test that the components of the registered property can be constrained"); + + // Try constraining the properties + Constraint vec3xConstraint = Constraint::New(derived, vec3xPropIndex, &Test::Doubler); + vec3xConstraint.AddSource(LocalSource(Actor::Property::POSITION_X)); + vec3xConstraint.Apply(); + Constraint vec3yConstraint = Constraint::New(derived, vec3yPropIndex, &Test::Doubler); + vec3yConstraint.AddSource(LocalSource(vec3xPropIndex)); + vec3yConstraint.Apply(); + Constraint vec3zConstraint = Constraint::New(derived, vec3zPropIndex, &Test::Doubler); + vec3zConstraint.AddSource(LocalSource(vec3yPropIndex)); + vec3zConstraint.Apply(); + + for(int i = 1; i < 10; ++i) + { + derived[Actor::Property::POSITION_X] = i * 1.0f; + application.SendNotification(); + application.Render(); + DALI_TEST_EQUALS(derived.GetCurrentProperty(vec3PropIndex).Get(), Vector3(i * 2.0f, i * 4.0f, i * 8.0f), 0.0001f, TEST_LOCATION); + } + + END_TEST; +}