Add the logical key to Integration::KeyEvent
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-LayoutingResizePolicy.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_resize_policy_startup(void)
55 {
56   test_return_value = TET_UNDEF;
57 }
58
59 void utc_dali_toolkit_layouting_resize_policy_cleanup(void)
60 {
61   test_return_value = TET_PASS;
62 }
63
64 // Test setting of the MeasureSpecs with the legacy ResizePolicies
65
66 int UtcDaliLayoutingResizePolicy_01(void)
67 {
68   /*
69   Root
70     |
71   Control (LinearLayout Horizontal)
72     |
73   Control (LayoutingRequired)
74     |
75   Control (ResizePolicy::FILL_TO_PARENT)
76     |
77   LeafControl
78   */
79
80   ToolkitTestApplication application;
81   tet_infoline("UtcDaliLayoutingResizePolicy_01 - Set ResizePolicy FILL_TO_PARENT on Control");
82
83   Stage stage = Stage::GetCurrent();
84
85   auto rootControl = Control::New();
86   SetupRootLayoutControl( rootControl );
87
88   auto hbox = Control::New();
89   auto hboxLayout = LinearLayout::New();
90   hboxLayout.SetOrientation( LinearLayout::Orientation::HORIZONTAL );
91   DevelControl::SetLayout( hbox, hboxLayout );
92   hbox.SetName( "hBox" );
93   hbox.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
94   hbox.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
95
96   auto layoutingControl = Control::New();
97   layoutingControl.SetName( "layoutingRequiredControl" );
98   DevelControl::SetLayoutingRequired( layoutingControl, true );
99   layoutingControl.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
100   layoutingControl.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
101   hbox.Add( layoutingControl );
102
103   auto control = Control::New();
104   control.SetName( "fillToParentControl" );
105   DevelControl::SetLayoutingRequired( control, true );
106   control.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
107   layoutingControl.Add( control );
108
109   std::vector< Control > controls;
110   controls.push_back( CreateLeafControl( 40, 40 ) );
111
112   for( auto&& iter : controls )
113   {
114     control.Add( iter );
115   }
116
117   rootControl.Add( hbox );
118
119   // Ensure layouting happens
120   application.SendNotification();
121   application.Render();
122
123   DALI_TEST_EQUALS( DevelControl::IsLayoutingRequired( control ), true , 0.0001f, TEST_LOCATION );
124
125   DALI_TEST_EQUALS( control.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 480.0f, 800.0f, 0.0f ), 0.0001f, TEST_LOCATION );
126   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
127
128   END_TEST;
129 }
130
131
132 int UtcDaliLayoutingResizePolicy_02(void)
133 {
134   /*
135   Root
136     |
137   Control (LinearLayout Horizontal)
138     |
139   Control (LayoutingRequired)
140     |
141   Control (ResizePolicy::FIT_TO_CHILDREN)
142     |
143   LeafControl
144   */
145
146   ToolkitTestApplication application;
147   tet_infoline("UtcDaliLayoutingResizePolicy_02 - Set ResizePolicy FIT_TO_CHILDREN on Control");
148
149   Stage stage = Stage::GetCurrent();
150
151   auto rootControl = Control::New();
152   SetupRootLayoutControl( rootControl );
153
154   auto hbox = Control::New();
155   auto hboxLayout = LinearLayout::New();
156   hboxLayout.SetOrientation( LinearLayout::Orientation::HORIZONTAL );
157   DevelControl::SetLayout( hbox, hboxLayout );
158   hbox.SetName( "hBox" );
159   hbox.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
160   hbox.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
161
162   auto layoutingControl = Control::New();
163   layoutingControl.SetName( "layoutingRequiredControl" );
164   DevelControl::SetLayoutingRequired( layoutingControl, true );
165   layoutingControl.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
166   layoutingControl.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
167   hbox.Add( layoutingControl );
168
169   auto control = Control::New();
170   control.SetName( "fitToChildrenControl" );
171   DevelControl::SetLayoutingRequired( control, true );
172   control.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
173   layoutingControl.Add( control );
174
175   std::vector< Control > controls;
176   controls.push_back( CreateLeafControl( 40, 40 ) );
177
178   for( auto&& iter : controls )
179   {
180     control.Add( iter );
181   }
182
183   rootControl.Add( hbox );
184
185   // Ensure layouting happens
186   application.SendNotification();
187   application.Render();
188
189   DALI_TEST_EQUALS( DevelControl::IsLayoutingRequired( control ), true , 0.0001f, TEST_LOCATION );
190
191   DALI_TEST_EQUALS( control.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 40.0f, 40.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 UtcDaliLayoutingResizePolicy_03(void)
198 {
199   /*
200   Root
201     |
202   Control (LinearLayout Horizontal)
203     |
204   Control (LayoutingRequired)
205     |
206   Control (ResizePolicy::SIZE_RELATIVE_TO_PARENT)
207     |
208   LeafControl
209   */
210
211   ToolkitTestApplication application;
212   tet_infoline("UtcDaliLayoutingResizePolicy_03 - Set ResizePolicy SIZE_RELATIVE_TO_PARENT on Control");
213
214   Stage stage = Stage::GetCurrent();
215
216   auto rootControl = Control::New();
217   SetupRootLayoutControl( rootControl );
218
219   auto hbox = Control::New();
220   auto hboxLayout = LinearLayout::New();
221   hboxLayout.SetOrientation( LinearLayout::Orientation::HORIZONTAL );
222   DevelControl::SetLayout( hbox, hboxLayout );
223   hbox.SetName( "hBox" );
224   hbox.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
225   hbox.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
226
227   auto layoutingControl = Control::New();
228   layoutingControl.SetName( "layoutingRequiredControl" );
229   DevelControl::SetLayoutingRequired( layoutingControl, true );
230   layoutingControl.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
231   layoutingControl.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
232   hbox.Add( layoutingControl );
233
234   auto control = Control::New();
235   control.SetName( "fitToChildrenControl" );
236   DevelControl::SetLayoutingRequired( control, true );
237   control.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
238   control.SetSizeModeFactor( Vector3( 0.50f, 1.0f, 1.0f ) );
239   layoutingControl.Add( control );
240
241   std::vector< Control > controls;
242   controls.push_back( CreateLeafControl( 40, 40 ) );
243
244   for( auto&& iter : controls )
245   {
246     control.Add( iter );
247   }
248
249   rootControl.Add( hbox );
250
251   // Ensure layouting happens
252   application.SendNotification();
253   application.Render();
254
255   DALI_TEST_EQUALS( DevelControl::IsLayoutingRequired( control ), true , 0.0001f, TEST_LOCATION );
256
257   DALI_TEST_EQUALS( control.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 240.0f, 800.0f, 0.0f ), 0.0001f, TEST_LOCATION );
258   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
259
260   END_TEST;
261 }
262
263 int UtcDaliLayoutingResizePolicy_04(void)
264 {
265   /*
266   Root
267     |
268   Control (LinearLayout Horizontal)
269     |
270   Control (LayoutingRequired)
271     |
272   Control (ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT)
273     |
274   LeafControl
275   */
276
277   ToolkitTestApplication application;
278   tet_infoline("UtcDaliLayoutingResizePolicy_04 - Set ResizePolicy SIZE_FIXED_OFFSET_FROM_PARENT on Control");
279
280   Stage stage = Stage::GetCurrent();
281
282   auto rootControl = Control::New();
283   SetupRootLayoutControl( rootControl );
284
285   auto hbox = Control::New();
286   auto hboxLayout = LinearLayout::New();
287   hboxLayout.SetOrientation( LinearLayout::Orientation::HORIZONTAL );
288   DevelControl::SetLayout( hbox, hboxLayout );
289   hbox.SetName( "hBox" );
290   hbox.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
291   hbox.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
292
293   auto layoutingControl = Control::New();
294   layoutingControl.SetName( "layoutingRequiredControl" );
295   DevelControl::SetLayoutingRequired( layoutingControl, true );
296   layoutingControl.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
297   layoutingControl.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
298   hbox.Add( layoutingControl );
299
300   auto control = Control::New();
301   control.SetName( "fitToChildrenControl" );
302   DevelControl::SetLayoutingRequired( control, true );
303   control.SetResizePolicy( ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT, Dimension::ALL_DIMENSIONS );
304   control.SetSizeModeFactor( Vector3( -100.0f, 10.0f, 0.0f ) );
305   layoutingControl.Add( control );
306
307   std::vector< Control > controls;
308   controls.push_back( CreateLeafControl( 40, 40 ) );
309
310   for( auto&& iter : controls )
311   {
312     control.Add( iter );
313   }
314
315   rootControl.Add( hbox );
316
317   // Ensure layouting happens
318   application.SendNotification();
319   application.Render();
320
321   DALI_TEST_EQUALS( DevelControl::IsLayoutingRequired( control ), true , 0.0001f, TEST_LOCATION );
322
323   DALI_TEST_EQUALS( control.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 380.0f, 810.0f, 0.0f ), 0.0001f, TEST_LOCATION );
324   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
325
326   END_TEST;
327 }
328
329 int UtcDaliLayoutingResizePolicy_05(void)
330 {
331   /*
332   Root
333     |
334   Control (LinearLayout Horizontal)
335     |
336   Control (LayoutingRequired)
337     |
338   Control (ResizePolicy::FIXED)
339     |
340   LeafControl
341   */
342
343   ToolkitTestApplication application;
344   tet_infoline("UtcDaliLayoutingResizePolicy_05 - Set ResizePolicy FIXED on Control");
345
346   Stage stage = Stage::GetCurrent();
347
348   auto rootControl = Control::New();
349   SetupRootLayoutControl( rootControl );
350
351   auto hbox = Control::New();
352   auto hboxLayout = LinearLayout::New();
353   hboxLayout.SetOrientation( LinearLayout::Orientation::HORIZONTAL );
354   DevelControl::SetLayout( hbox, hboxLayout );
355   hbox.SetName( "hBox" );
356   hbox.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
357   hbox.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
358
359   auto layoutingControl = Control::New();
360   layoutingControl.SetName( "layoutingRequiredControl" );
361   DevelControl::SetLayoutingRequired( layoutingControl, true );
362   layoutingControl.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
363   layoutingControl.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
364   hbox.Add( layoutingControl );
365
366   auto control = Control::New();
367   control.SetName( "fitToChildrenControl" );
368   DevelControl::SetLayoutingRequired( control, true );
369   control.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
370   control.SetSize( Vector3( 300.0f, 300.0f, 0.0f ) );
371   layoutingControl.Add( control );
372
373   std::vector< Control > controls;
374   controls.push_back( CreateLeafControl( 40, 40 ) );
375
376   for( auto&& iter : controls )
377   {
378     control.Add( iter );
379   }
380
381   rootControl.Add( hbox );
382
383   // Ensure layouting happens
384   application.SendNotification();
385   application.Render();
386
387   DALI_TEST_EQUALS( DevelControl::IsLayoutingRequired( control ), true , 0.0001f, TEST_LOCATION );
388
389   DALI_TEST_EQUALS( control.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 300.0f, 300.0f, 0.0f ), 0.0001f, TEST_LOCATION );
390   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
391
392   END_TEST;
393 }