Change Adaptor implementation API in toolkit for multiple windows.
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-LayoutingNesting.cpp
1 /*
2  * Copyright (c) 2018 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 <iostream>
19 #include <stdlib.h>
20 #include <dali-toolkit-test-suite-utils.h>
21 #include <toolkit-event-thread-callback.h>
22
23 #include <dali-toolkit/dali-toolkit.h>
24 #include <dali-toolkit/devel-api/controls/control-devel.h>
25 #include <dali-toolkit/devel-api/layouting/absolute-layout.h>
26 #include <dali-toolkit/devel-api/layouting/linear-layout.h>
27 #include <dali-toolkit/devel-api/layouting/layout-item-impl.h>
28 #include <dali-toolkit/devel-api/layouting/layout-group-impl.h>
29 #include <dali/devel-api/actors/actor-devel.h>
30
31 #include <../custom-layout.h>
32
33 #include <layout-utils.h>
34
35 using namespace Dali;
36 using namespace Toolkit;
37
38 namespace
39 {
40
41 // Turns the given control into a Root layout control and adds it to the stage.
42 void SetupRootLayoutControl( Control& rootControl )
43 {
44   rootControl = Control::New();
45   auto absoluteLayout = AbsoluteLayout::New();
46   DevelControl::SetLayout( rootControl, absoluteLayout );
47   rootControl.SetName( "RootAbsoluteLayout" );
48   Stage stage = Stage::GetCurrent();
49   stage.Add( rootControl );
50 }
51
52 } // unnamed namespace
53
54 void utc_dali_toolkit_layouting_nesting_startup(void)
55 {
56   test_return_value = TET_UNDEF;
57 }
58
59 void utc_dali_toolkit_layouting_nesting_cleanup(void)
60 {
61   test_return_value = TET_PASS;
62 }
63
64 // Test nesting of Layouts and Controls
65
66 int UtcDaliLayoutingNesting_01(void)
67 {
68   /*
69
70   Root
71     |
72   Control (LinearLayout Horizontal)
73     |
74   Control (LinearLayout Vertical)
75     |
76   LeafControl
77
78   */
79
80   ToolkitTestApplication application;
81   tet_infoline("UtcDaliLayoutingNesting_01 - Nesting a LinearLayout (MATCH_PARENT) containing a leaf control within a LinearLayout");
82
83   auto rootControl = Control::New();
84   SetupRootLayoutControl( rootControl );
85
86   auto hbox = Control::New();
87   auto hboxLayout = LinearLayout::New();
88   hboxLayout.SetOrientation( LinearLayout::Orientation::HORIZONTAL );
89   DevelControl::SetLayout( hbox, hboxLayout );
90   hbox.SetName( "hBox" );
91   hbox.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, 480 );
92   hbox.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, 800 );
93
94
95   auto vbox = Control::New();
96   auto vboxLayout = LinearLayout::New();
97   vboxLayout.SetOrientation( LinearLayout::Orientation::VERTICAL );
98   DevelControl::SetLayout( vbox, vboxLayout );
99   vbox.SetName( "vBox" );
100   vbox.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
101   vbox.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
102   hbox.Add( vbox );
103
104   std::vector< Control > controls;
105   controls.push_back( CreateLeafControl( 40, 40 ) );
106
107   for( auto&& iter : controls )
108   {
109     vbox.Add( iter );
110   }
111
112   rootControl.Add( hbox );
113
114   // Ensure layouting happens
115   application.SendNotification();
116   application.Render();
117
118   DALI_TEST_EQUALS( hbox.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 480.0f, 800.0f, 0.0f ), 0.0001f, TEST_LOCATION );
119   DALI_TEST_EQUALS( vbox.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 480.0f, 800.0f, 0.0f ), 0.0001f, TEST_LOCATION );
120
121   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
122
123   END_TEST;
124 }
125
126 int UtcDaliLayoutingNesting_02(void)
127 {
128   /*
129
130   Root
131     |
132   Control (LinearLayout Horizontal)
133     |    |
134   Control (LinearLayout Vertical)
135     |    |
136   LeafControl
137
138   */
139
140   ToolkitTestApplication application;
141   tet_infoline("UtcDaliLayoutingNesting_02 - Nesting a LinearLayout (MATCH_PARENT) containing a leaf control within a LinearLayout");
142   tet_infoline("Then change the parent's size and test child responded correctly");
143
144   auto rootControl = Control::New();
145   SetupRootLayoutControl( rootControl );
146
147   auto hbox = Control::New();
148   auto hboxLayout = LinearLayout::New();
149   hboxLayout.SetOrientation( LinearLayout::Orientation::HORIZONTAL );
150   DevelControl::SetLayout( hbox, hboxLayout );
151   hbox.SetName( "hBox" );
152   hbox.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, 480 );
153   hbox.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, 800 );
154
155
156   auto vbox = Control::New();
157   auto vboxLayout = LinearLayout::New();
158   vboxLayout.SetOrientation( LinearLayout::Orientation::VERTICAL );
159   DevelControl::SetLayout( vbox, vboxLayout );
160   vbox.SetName( "vBox" );
161   vbox.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
162   vbox.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
163   hbox.Add( vbox );
164
165   std::vector< Control > controls;
166   controls.push_back( CreateLeafControl( 40, 40 ) );
167
168   for( auto&& iter : controls )
169   {
170     vbox.Add( iter );
171   }
172
173   rootControl.Add( hbox );
174
175   // Ensure layouting happens
176   application.SendNotification();
177   application.Render();
178
179   DALI_TEST_EQUALS( hbox.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 480.0f, 800.0f, 0.0f ), 0.0001f, TEST_LOCATION );
180   DALI_TEST_EQUALS( vbox.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 480.0f, 800.0f, 0.0f ), 0.0001f, TEST_LOCATION );
181   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
182
183   hbox.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, 400 );
184
185   // Ensure layouting happens
186   application.SendNotification();
187   application.Render();
188
189
190   DALI_TEST_EQUALS( hbox.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 400.0f, 800.0f, 0.0f ), 0.0001f, TEST_LOCATION );
191   DALI_TEST_EQUALS( vbox.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 400.0f, 800.0f, 0.0f ), 0.0001f, TEST_LOCATION );
192   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
193
194   END_TEST;
195 }
196
197 int UtcDaliLayoutingNesting_LeafSizeChange(void)
198 {
199  /*
200   Root
201     |
202   Control (LayoutingRequired)
203     |
204   Control (LinearLayout Horizontal)  (WRAP_CONTENT)
205     |    |
206   TextLabel
207   */
208
209   ToolkitTestApplication application;
210   tet_infoline("UtcDaliLayoutingNesting_LeafSizeChange - Nesting a TextLabel within a layout that is parented to a control");
211   tet_infoline("Then change the TextLabels size and test the parent resized to wrap the new size");
212
213   auto rootControl = Control::New();
214   SetupRootLayoutControl( rootControl );
215
216   auto control = Control::New();
217   DevelControl::SetLayoutingRequired( control, true );
218   control.SetName( "control" );
219
220   auto hbox = Control::New();
221   auto hboxLayout = LinearLayout::New();
222   hboxLayout.SetOrientation( LinearLayout::Orientation::HORIZONTAL );
223   DevelControl::SetLayout( hbox, hboxLayout );
224   hbox.SetName( "hBox" );
225   hbox.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::WRAP_CONTENT );
226   hbox.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::WRAP_CONTENT );
227
228   control.Add( hbox );
229
230   TextLabel textLabel = CreateTextLabel("SmallText" );
231
232   hbox.Add( textLabel );
233
234   rootControl.Add( control );
235
236   // Ensure layouting happens
237   application.SendNotification();
238   application.Render();
239
240   DALI_TEST_EQUALS( hbox.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 260.0f, 64.0f, 0.0f ), 0.0001f, TEST_LOCATION );
241   DALI_TEST_EQUALS( textLabel.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 260.0f, 64.0f, 0.0f ), 0.0001f, TEST_LOCATION );
242
243   tet_infoline("Changing to longer text");
244   textLabel.SetProperty( TextLabel::Property::TEXT, "muchlongerText" );
245
246   // Ensure layouting happens
247   application.SendNotification();
248   application.Render();
249
250   DALI_TEST_EQUALS( hbox.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 432.0f, 64.0f, 0.0f ), 0.0001f, TEST_LOCATION );
251   DALI_TEST_EQUALS( textLabel.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 432.0f, 64.0f, 0.0f ), 0.0001f, TEST_LOCATION );
252
253   END_TEST;
254 }