11babca956c0dace46fcc8470c7ab81ce82594b5
[platform/core/uifw/dali-core.git] / automated-tests / src / dali-internal / utc-Dali-Internal-ActorRelayout.cpp
1 /*
2  * Copyright (c) 2021 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 #include <dali-test-suite-utils.h>
19 #include <dali/public-api/signals/callback.h>
20 #include <stdlib.h>
21 #include "test-custom-actor.h"
22
23 #include <iostream>
24
25 // Internal headers are allowed here
26 #include <dali/internal/event/actors/actor-impl.h>
27 #include <dali/internal/event/actors/actor-relayouter.h>
28
29 using namespace Dali;
30 using Dali::Internal::Actor;
31
32 void utc_dali_internal_actor_relayouter_startup()
33 {
34   test_return_value = TET_UNDEF;
35 }
36
37 void utc_dali_internal_actor_relayouter_cleanup()
38 {
39   test_return_value = TET_PASS;
40 }
41
42 int UtcDaliActorRelayouter_CalculateSize(void)
43 {
44   TestApplication application;
45
46   auto  scene         = application.GetScene();
47   auto  actor         = Test::TestCustomActor::New();
48   auto& testActorImpl = Test::Impl::GetImpl(actor);
49   auto& actorImpl     = GetImplementation(actor);
50
51   scene.Add(actor);
52   actorImpl.SetSize(Vector2(100.0f, 100.0f));
53   actorImpl.SetPreferredSize(Vector2(200.0f, 350.0f));
54
55   Vector2 maxSize(400.0f, 500.0f);
56
57   DALI_TEST_EQUALS(actorImpl.CalculateSize(Dimension::WIDTH, maxSize), 200.0f, 0.00001f, TEST_LOCATION);
58   DALI_TEST_EQUALS(actorImpl.CalculateSize(Dimension::HEIGHT, maxSize), 350.0f, 0.00001f, TEST_LOCATION);
59
60   actor.SetResizePolicy(ResizePolicy::USE_ASSIGNED_SIZE, Dimension::HEIGHT);
61   DALI_TEST_EQUALS(actorImpl.CalculateSize(Dimension::WIDTH, maxSize), 200.0f, 0.00001f, TEST_LOCATION);
62   DALI_TEST_EQUALS(actorImpl.CalculateSize(Dimension::HEIGHT, maxSize), maxSize.y, 0.00001f, TEST_LOCATION);
63
64   testActorImpl.SetNaturalSize(Vector3(150.0f, 180.0f, 150.0f));
65   actor.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS);
66
67   DALI_TEST_EQUALS(actorImpl.CalculateSize(Dimension::WIDTH, maxSize), 150.0f, 0.00001f, TEST_LOCATION);
68   DALI_TEST_EQUALS(actorImpl.CalculateSize(Dimension::HEIGHT, maxSize), 180.0f, 0.00001f, TEST_LOCATION);
69
70   actor.SetResizePolicy(ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS);
71   auto child = Test::TestCustomActor::New();
72   child.SetResizePolicy(ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS);
73   child.SetProperty(Dali::Actor::Property::SIZE, Vector2(20.0f, 40.0f));
74   auto& childImpl = GetImplementation(child);
75   actor.Add(child);
76
77   application.SendNotification();
78   application.Render();
79
80   DALI_TEST_EQUALS(actorImpl.CalculateSize(Dimension::WIDTH, maxSize), 20.0f, 0.00001f, TEST_LOCATION);
81   DALI_TEST_EQUALS(actorImpl.CalculateSize(Dimension::HEIGHT, maxSize), 40.0f, 0.00001f, TEST_LOCATION);
82
83   testActorImpl.SetWidthForHeightFactor(3.5f);
84   testActorImpl.SetHeightForWidthFactor(1.7f);
85   actor.SetResizePolicy(ResizePolicy::DIMENSION_DEPENDENCY, Dimension::WIDTH);
86   DALI_TEST_EQUALS(actorImpl.CalculateSize(Dimension::WIDTH, maxSize), 140.0f, 0.00001f, TEST_LOCATION);
87
88   actor.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::WIDTH);
89   actor.SetResizePolicy(ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT);
90   application.SendNotification();
91   application.Render();
92   DALI_TEST_EQUALS(actorImpl.CalculateSize(Dimension::HEIGHT, maxSize), 255.0f, 0.00001f, TEST_LOCATION);
93
94   child.SetResizePolicy(ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS);
95   child[Dali::Actor::Property::SIZE_MODE_FACTOR] = Vector3(0.5f, 1.0f, 1.0f);
96   application.SendNotification();
97   application.Render();
98   DALI_TEST_EQUALS(childImpl.CalculateSize(Dimension::WIDTH, maxSize), 75.0f, 0.00001f, TEST_LOCATION);
99   DALI_TEST_EQUALS(childImpl.CalculateSize(Dimension::HEIGHT, maxSize), 255.0f, 0.00001f, TEST_LOCATION);
100
101   child.SetResizePolicy(ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT, Dimension::ALL_DIMENSIONS);
102   child[Dali::Actor::Property::SIZE_MODE_FACTOR] = Vector3(-40.0f, -20.0f, 1.0f);
103   application.SendNotification();
104   application.Render();
105   DALI_TEST_EQUALS(childImpl.CalculateSize(Dimension::WIDTH, maxSize), 110.0f, 0.00001f, TEST_LOCATION);
106   DALI_TEST_EQUALS(childImpl.CalculateSize(Dimension::HEIGHT, maxSize), 235.0f, 0.00001f, TEST_LOCATION);
107
108   END_TEST;
109 }