2 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include <dali-test-suite-utils.h>
19 #include <dali/public-api/signals/callback.h>
21 #include "test-custom-actor.h"
25 // Internal headers are allowed here
26 #include <dali/internal/event/actors/actor-impl.h>
27 #include <dali/internal/event/actors/actor-relayouter.h>
30 using Dali::Internal::Actor;
32 void utc_dali_internal_actor_relayouter_startup()
34 test_return_value = TET_UNDEF;
37 void utc_dali_internal_actor_relayouter_cleanup()
39 test_return_value = TET_PASS;
42 int UtcDaliActorSizer_CalculateSize(void)
44 TestApplication application;
46 auto scene = application.GetScene();
47 auto actor = Test::TestCustomActor::New();
48 auto& testActorImpl = Test::Impl::GetImpl(actor);
49 auto& actorImpl = GetImplementation(actor);
51 DALI_TEST_EQUALS(testActorImpl.IsRelayoutEnabled(), false, TEST_LOCATION);
52 DALI_TEST_CHECK(true);
54 actor.SetResizePolicy(ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS);
55 actor[Dali::Actor::Property::SIZE] = Vector2(150.0f, 100.0f); // Should automatically set preferred size
58 DALI_TEST_EQUALS(actorImpl.IsRelayoutEnabled(), true, TEST_LOCATION);
60 testActorImpl.SetNaturalSize(Vector3(150.0f, 180.0f, 150.0f));
61 actor.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS);
62 application.SendNotification();
65 Vector3 size = actor[Dali::Actor::Property::SIZE];
66 DALI_TEST_EQUALS(size.width, 150.0f, 0.00001f, TEST_LOCATION);
67 DALI_TEST_EQUALS(size.height, 180.0f, 0.00001f, TEST_LOCATION);
69 testActorImpl.SetWidthForHeightFactor(3.5f);
70 testActorImpl.SetHeightForWidthFactor(1.7f);
71 actor.SetResizePolicy(ResizePolicy::DIMENSION_DEPENDENCY, Dimension::WIDTH);
72 application.SendNotification();
75 size = Vector3(actor[Dali::Actor::Property::SIZE]);
76 DALI_TEST_EQUALS(size.width, 3.5f * 180.0f, 0.00001f, TEST_LOCATION);
78 actor.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::WIDTH);
79 actor.SetResizePolicy(ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT);
80 application.SendNotification();
82 size = Vector3(actor[Dali::Actor::Property::SIZE]);
83 DALI_TEST_EQUALS(size.height, 1.7f * 150.0f, 0.00001f, TEST_LOCATION);
85 auto child = Test::TestCustomActor::New();
86 child.SetResizePolicy(ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS);
87 child.SetProperty(Dali::Actor::Property::SIZE, Vector2(20.0f, 40.0f));
88 auto& childImpl = GetImplementation(child);
90 actor.TestRelayoutRequest();
92 tet_infoline("Test actor takes child size");
93 actor.SetResizePolicy(ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS);
94 application.SendNotification();
96 Vector3 parentSize = actor[Dali::Actor::Property::SIZE];
97 DALI_TEST_EQUALS(parentSize.width, 20.0f, 0.00001f, TEST_LOCATION);
98 DALI_TEST_EQUALS(parentSize.height, 40.0f, 0.00001f, TEST_LOCATION);
100 tet_infoline("Test child actor is the right factor of the parent");
101 actor[Dali::Actor::Property::SIZE] = Vector2(150.0f, 100.0f); // Should automatically set preferred size
102 child.SetResizePolicy(ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS);
103 child[Dali::Actor::Property::SIZE_MODE_FACTOR] = Vector3(0.5f, 1.0f, 1.0f);
105 childImpl.RelayoutRequest();
106 application.SendNotification();
107 application.Render();
109 Vector3 childSize = child[Dali::Actor::Property::SIZE];
110 DALI_TEST_EQUALS(childSize.width, 75.0f, 0.00001f, TEST_LOCATION);
111 DALI_TEST_EQUALS(childSize.height, 100.0f, 0.00001f, TEST_LOCATION);
113 tet_infoline("Test child actor is the right delta of the parent");
114 child.SetResizePolicy(ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT, Dimension::ALL_DIMENSIONS);
115 child[Dali::Actor::Property::SIZE_MODE_FACTOR] = Vector3(-40.0f, -20.0f, 1.0f);
116 child.TestRelayoutRequest();
117 application.SendNotification();
118 application.Render();
120 Vector3 size2 = child[Dali::Actor::Property::SIZE];
121 DALI_TEST_EQUALS(size2.width, 110.0f, 0.00001f, TEST_LOCATION);
122 DALI_TEST_EQUALS(size2.height, 80.0f, 0.00001f, TEST_LOCATION);