Fix SVACE error in render-manager.cpp
[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 UtcDaliActorSizer_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   DALI_TEST_EQUALS(testActorImpl.IsRelayoutEnabled(), false, TEST_LOCATION);
52   DALI_TEST_CHECK(true);
53
54   actor.SetResizePolicy(ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS);
55   actor[Dali::Actor::Property::SIZE] = Vector2(150.0f, 100.0f); // Should automatically set preferred size
56   scene.Add(actor);
57
58   DALI_TEST_EQUALS(actorImpl.IsRelayoutEnabled(), true, TEST_LOCATION);
59
60   testActorImpl.SetNaturalSize(Vector3(150.0f, 180.0f, 150.0f));
61   actor.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS);
62   application.SendNotification();
63   application.Render();
64
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);
68
69   testActorImpl.SetWidthForHeightFactor(3.5f);
70   testActorImpl.SetHeightForWidthFactor(1.7f);
71   actor.SetResizePolicy(ResizePolicy::DIMENSION_DEPENDENCY, Dimension::WIDTH);
72   application.SendNotification();
73   application.Render();
74
75   size = Vector3(actor[Dali::Actor::Property::SIZE]);
76   DALI_TEST_EQUALS(size.width, 3.5f * 180.0f, 0.00001f, TEST_LOCATION);
77
78   actor.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::WIDTH);
79   actor.SetResizePolicy(ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT);
80   application.SendNotification();
81   application.Render();
82   size = Vector3(actor[Dali::Actor::Property::SIZE]);
83   DALI_TEST_EQUALS(size.height, 1.7f * 150.0f, 0.00001f, TEST_LOCATION);
84
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);
89   actor.Add(child);
90   actor.TestRelayoutRequest();
91
92   tet_infoline("Test actor takes child size");
93   actor.SetResizePolicy(ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS);
94   application.SendNotification();
95   application.Render();
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);
99
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);
104
105   childImpl.RelayoutRequest();
106   application.SendNotification();
107   application.Render();
108
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);
112
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();
119
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);
123
124   END_TEST;
125 }