[dali_1.4.16] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-GridLayout.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/grid.h>
27 #include <dali-toolkit/devel-api/layouting/layout-item-impl.h>
28 #include <dali-toolkit/devel-api/layouting/layout-group-impl.h>
29
30 #include <../custom-layout.h>
31
32 #include <layout-utils.h>
33
34 using namespace Dali;
35 using namespace Toolkit;
36
37 void utc_dali_toolkit_grid_layouting_startup(void)
38 {
39   test_return_value = TET_UNDEF;
40 }
41
42 void utc_dali_toolkit_grid_layouting_cleanup(void)
43 {
44   test_return_value = TET_PASS;
45 }
46
47 int UtcDaliLayouting_GridLayout00(void)
48 {
49   ToolkitTestApplication application;
50   tet_infoline(" UtcDaliLayouting_GridLayout00 1 Column, 0 Items");
51
52   const auto NUMBER_OF_COLUMNS = 1;
53   const auto NUMBER_OF_ITEMS = 0;
54
55   tet_printf( "Testing %d columns with %d items\n", NUMBER_OF_COLUMNS, NUMBER_OF_ITEMS );
56
57   Stage stage = Stage::GetCurrent();
58
59   auto rootControl = Control::New();
60   auto absoluteLayout = AbsoluteLayout::New();
61   DevelControl::SetLayout( rootControl, absoluteLayout );
62   rootControl.SetName( "AbsoluteLayout" );
63   stage.Add( rootControl );
64
65   auto gridContainer = Control::New();
66   auto gridLayout = Grid::New();
67   gridLayout.SetNumberOfColumns( NUMBER_OF_COLUMNS );
68   gridContainer.SetName( "GridLayout");
69   DevelControl::SetLayout( gridContainer, gridLayout );
70   gridContainer.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::WRAP_CONTENT );
71   gridContainer.SetProperty( LayoutItem::ChildProperty::HEIGHT_SPECIFICATION,  ChildLayoutData::WRAP_CONTENT );
72
73   rootControl.Add( gridContainer );
74
75   // Ensure layouting happens
76   application.SendNotification();
77   application.Render();
78
79   tet_printf( "Confirm number of columns is as set\n");
80   DALI_TEST_EQUALS( gridLayout.GetNumberOfColumns(), NUMBER_OF_COLUMNS, TEST_LOCATION );
81
82   END_TEST;
83 }
84
85 int UtcDaliLayouting_GridLayout01(void)
86 {
87   ToolkitTestApplication application;
88   tet_infoline(" UtcDaliLayouting_GridLayout01 2 Column, 4 Items");
89
90   const auto NUMBER_OF_COLUMNS = 2;
91   const auto NUMBER_OF_ITEMS = 4;
92
93   tet_printf( "Testing %d columns with %d items\n", NUMBER_OF_COLUMNS, NUMBER_OF_ITEMS );
94
95   Stage stage = Stage::GetCurrent();
96
97   auto rootControl = Control::New();
98   auto absoluteLayout = AbsoluteLayout::New();
99   DevelControl::SetLayout( rootControl, absoluteLayout );
100   rootControl.SetName( "AbsoluteLayout" );
101   stage.Add( rootControl );
102
103   auto gridContainer = Control::New();
104   auto gridLayout = Grid::New();
105   gridLayout.SetNumberOfColumns( NUMBER_OF_COLUMNS );
106   gridContainer.SetName( "GridLayout");
107   DevelControl::SetLayout( gridContainer, gridLayout );
108   gridContainer.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::WRAP_CONTENT );
109   gridContainer.SetProperty( LayoutItem::ChildProperty::HEIGHT_SPECIFICATION,  ChildLayoutData::WRAP_CONTENT );
110
111   std::vector< Control > controls;
112   for( auto i=0; i < NUMBER_OF_ITEMS; i++ )
113   {
114     controls.push_back( CreateLeafControl( 100, 100 ) );
115   }
116
117   for( auto&& iter : controls )
118   {
119     gridContainer.Add( iter );
120   }
121
122   rootControl.Add( gridContainer );
123
124   // Ensure layouting happens
125   application.SendNotification();
126   application.Render();
127
128  // Grid will layout first 2 items on first row then last 2 on second row.
129   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
130   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 100.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
131   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
132   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
133
134   // Item sizes will not be changed
135   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
136   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
137   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
138   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
139
140   tet_printf( "Confirm number of columns is as set\n");
141   DALI_TEST_EQUALS( gridLayout.GetNumberOfColumns(), NUMBER_OF_COLUMNS, TEST_LOCATION );
142
143   END_TEST;
144 }
145
146 int UtcDaliLayouting_GridLayout02(void)
147 {
148   ToolkitTestApplication application;
149   tet_infoline("UtcDaliLayouting_GridLayout02");
150
151   const auto NUMBER_OF_COLUMNS = 3;
152   const auto NUMBER_OF_ITEMS = 7;
153
154   tet_printf( "Testing %d columns with %d items\n", NUMBER_OF_COLUMNS, NUMBER_OF_ITEMS );
155
156   Stage stage = Stage::GetCurrent();
157
158   auto rootControl = Control::New();
159   auto absoluteLayout = AbsoluteLayout::New();
160   DevelControl::SetLayout( rootControl, absoluteLayout );
161   rootControl.SetName( "AbsoluteLayout" );
162   stage.Add( rootControl );
163
164   auto gridContainer = Control::New();
165   auto gridLayout = Grid::New();
166   gridLayout.SetNumberOfColumns( NUMBER_OF_COLUMNS );
167   gridContainer.SetName( "GridLayout");
168   DevelControl::SetLayout( gridContainer, gridLayout );
169   gridContainer.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::WRAP_CONTENT );
170   gridContainer.SetProperty( LayoutItem::ChildProperty::HEIGHT_SPECIFICATION,  ChildLayoutData::WRAP_CONTENT );
171
172   std::vector< Control > controls;
173   for( auto i=0; i < NUMBER_OF_ITEMS; i++ )
174   {
175     controls.push_back( CreateLeafControl( 100, 100 ) );
176   }
177
178   for( auto&& iter : controls )
179   {
180     gridContainer.Add( iter );
181   }
182
183   rootControl.Add( gridContainer );
184
185   // Ensure layouting happens
186   application.SendNotification();
187   application.Render();
188
189   // grid  layouts out 3 items per row, which is 480x800.
190   // Row 1
191   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
192   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 100.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
193   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 200.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
194   // Row 2
195   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
196   DALI_TEST_EQUALS( controls[4].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
197   DALI_TEST_EQUALS( controls[5].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 200.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
198   // Row 3
199   DALI_TEST_EQUALS( controls[6].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 200.0f, 0.0f ), 0.0001f, TEST_LOCATION );
200
201   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
202   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
203   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
204   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
205   DALI_TEST_EQUALS( controls[4].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
206   DALI_TEST_EQUALS( controls[5].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
207   DALI_TEST_EQUALS( controls[6].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
208
209   END_TEST;
210 }
211
212 int UtcDaliLayouting_GridLayout03(void)
213 {
214   ToolkitTestApplication application;
215   tet_infoline(" UtcDaliLayouting_GridLayout03 Grid Padding");
216
217   const auto NUMBER_OF_COLUMNS = 2;
218   const auto NUMBER_OF_ITEMS = 4;
219
220   tet_printf( "Testing %d columns with %d items\n", NUMBER_OF_COLUMNS, NUMBER_OF_ITEMS );
221
222   Extents GRID_PADDING( Extents( 10, 10, 20, 20 ) ); // start,end,top,bottom
223
224   tet_printf( "Testing with Padding 10,10,20,20\n");
225
226   Stage stage = Stage::GetCurrent();
227
228   auto rootControl = Control::New();
229   auto absoluteLayout = AbsoluteLayout::New();
230   DevelControl::SetLayout( rootControl, absoluteLayout );
231   rootControl.SetName( "AbsoluteLayout" );
232   stage.Add( rootControl );
233
234   auto gridContainer = Control::New();
235   auto gridLayout = Grid::New();
236   gridLayout.SetNumberOfColumns( NUMBER_OF_COLUMNS );
237   gridContainer.SetName( "GridLayout");
238   DevelControl::SetLayout( gridContainer, gridLayout );
239   gridContainer.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::WRAP_CONTENT );
240   gridContainer.SetProperty( LayoutItem::ChildProperty::HEIGHT_SPECIFICATION,  ChildLayoutData::WRAP_CONTENT );
241   gridContainer.SetProperty( Control::Property::PADDING, GRID_PADDING );
242
243   std::vector< Control > controls;
244   for( auto i=0; i < NUMBER_OF_ITEMS; i++ )
245   {
246     controls.push_back( CreateLeafControl( 100, 100 ) );
247   }
248
249   for( auto&& iter : controls )
250   {
251     gridContainer.Add( iter );
252   }
253
254   rootControl.Add( gridContainer );
255
256   // Ensure layouting happens
257   application.SendNotification();
258   application.Render();
259
260   tet_infoline(" UtcDaliLayouting_GridLayout03 Grid Padding 2 Column, 4 Items");
261   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f + GRID_PADDING.start , 0.0f + GRID_PADDING.top, 0.0f ), 0.0001f, TEST_LOCATION );
262   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 100.0f + GRID_PADDING.start, 0.0f + GRID_PADDING.top, 0.0f ), 0.0001f, TEST_LOCATION );
263   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f + GRID_PADDING.start, 100.0f + GRID_PADDING.top , 0.0f ), 0.0001f, TEST_LOCATION );
264   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 100.0f + GRID_PADDING.start, 100.0f + GRID_PADDING.top, 0.0f ), 0.0001f, TEST_LOCATION );
265
266   tet_infoline(" UtcDaliLayouting_GridLayout03 Size of Grid should include padding");
267   DALI_TEST_EQUALS( gridContainer.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f * NUMBER_OF_COLUMNS + GRID_PADDING.start + + GRID_PADDING.end,
268                                                                                  100.0f * ( NUMBER_OF_ITEMS / NUMBER_OF_COLUMNS ) +
269                                                                                  GRID_PADDING.top + GRID_PADDING.bottom,
270                                                                                  0.0f ), 0.0001f, TEST_LOCATION );
271
272   tet_infoline(" UtcDaliLayouting_GridLayout03 Item sizes unchanged");
273   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
274   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
275   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
276   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
277
278   END_TEST;
279 }
280
281 int UtcDaliLayouting_GridLayout04(void)
282 {
283   ToolkitTestApplication application;
284   tet_infoline(" UtcDaliLayouting_GridLayout04 Child Margin");
285
286   const auto NUMBER_OF_COLUMNS = 2;
287   const auto NUMBER_OF_ITEMS = 4;
288
289   tet_printf( "Testing %d columns with %d items\n", NUMBER_OF_COLUMNS, NUMBER_OF_ITEMS );
290
291   Extents GRID_PADDING( Extents( 10, 10, 20, 20 ) ); // start,end,top,bottom
292   Extents ITEM_MARGIN( Extents( 10, 10, 5, 5 ) ); // start,end,top,bottom
293
294   tet_printf( "Testing with Margin 10,10,5,5\n");
295
296   Stage stage = Stage::GetCurrent();
297
298   auto rootControl = Control::New();
299   auto absoluteLayout = AbsoluteLayout::New();
300   DevelControl::SetLayout( rootControl, absoluteLayout );
301   rootControl.SetName( "AbsoluteLayout" );
302   stage.Add( rootControl );
303
304   auto gridContainer = Control::New();
305   auto gridLayout = Grid::New();
306   gridLayout.SetNumberOfColumns( NUMBER_OF_COLUMNS );
307   gridContainer.SetName( "GridLayout");
308   DevelControl::SetLayout( gridContainer, gridLayout );
309   gridContainer.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::WRAP_CONTENT );
310   gridContainer.SetProperty( LayoutItem::ChildProperty::HEIGHT_SPECIFICATION,  ChildLayoutData::WRAP_CONTENT );
311   gridContainer.SetProperty( Control::Property::PADDING, GRID_PADDING );
312
313   std::vector< Control > controls;
314   for( auto i=0; i < NUMBER_OF_ITEMS; i++ )
315   {
316     auto control = CreateLeafControl( 100, 100 );
317     control.SetProperty(Toolkit::Control::Property::MARGIN, ITEM_MARGIN );
318     controls.push_back( control );
319   }
320
321   for( auto&& iter : controls )
322   {
323     gridContainer.Add( iter );
324   }
325
326   rootControl.Add( gridContainer );
327
328   // Ensure layouting happens
329   application.SendNotification();
330   application.Render();
331
332   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ),
333                     Vector3( 0.0f + GRID_PADDING.start + ITEM_MARGIN.start,
334                     0.0f + GRID_PADDING.top + ITEM_MARGIN.top,
335                     0.0f ),
336                     0.0001f, TEST_LOCATION );
337
338   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ),
339                     Vector3( 100.0f + GRID_PADDING.start + ITEM_MARGIN.start *2 + ITEM_MARGIN.end,
340                     0.0f + GRID_PADDING.top + ITEM_MARGIN.top,
341                     0.0f ), 0.0001f, TEST_LOCATION );
342
343   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::POSITION ),
344                     Vector3( 0.0f + GRID_PADDING.start + ITEM_MARGIN.start,
345                     100.0f + GRID_PADDING.top + ITEM_MARGIN.top*2 + ITEM_MARGIN.bottom,
346                     0.0f ), 0.0001f, TEST_LOCATION );
347
348   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::POSITION ),
349                     Vector3( 100.0f + GRID_PADDING.start + ITEM_MARGIN.start*2 + ITEM_MARGIN.end,
350                     100.0f + GRID_PADDING.top + ITEM_MARGIN.top*2 + ITEM_MARGIN.bottom,
351                     0.0f ), 0.0001f, TEST_LOCATION );
352
353   tet_infoline(" UtcDaliLayouting_GridLayout03 Size of Grid should include padding and margins");
354
355   const auto NUMBER_OF_ROWS = ( NUMBER_OF_ITEMS / NUMBER_OF_COLUMNS );
356
357   DALI_TEST_EQUALS( gridContainer.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f * NUMBER_OF_COLUMNS + GRID_PADDING.start + GRID_PADDING.end +
358                                                                                           ITEM_MARGIN.start *NUMBER_OF_COLUMNS + ITEM_MARGIN.end *NUMBER_OF_COLUMNS,
359                                                                                           100.0f * NUMBER_OF_ROWS +
360                                                                                           GRID_PADDING.top + GRID_PADDING.bottom +
361                                                                                           ITEM_MARGIN.bottom *NUMBER_OF_ROWS + ITEM_MARGIN.bottom *NUMBER_OF_ROWS,
362                                                                                           0.0f ), 0.0001f, TEST_LOCATION );
363
364   tet_infoline(" UtcDaliLayouting_GridLayout03 Item sizes unchanged");
365   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
366   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
367   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
368   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
369
370   END_TEST;
371 }
372
373 int UtcDaliLayouting_GridLayout05(void)
374 {
375   ToolkitTestApplication application;
376   tet_infoline(" UtcDaliLayouting_GridLayout05 2 Column, 4 Items UNSPECIFIED width and height SPECIFICATIONS");
377
378   const auto NUMBER_OF_COLUMNS = 2;
379   const auto NUMBER_OF_ITEMS = 4;
380
381   tet_printf( "Testing %d columns with %d items\n", NUMBER_OF_COLUMNS, NUMBER_OF_ITEMS );
382
383   Stage stage = Stage::GetCurrent();
384
385   auto rootControl = Control::New();
386   auto absoluteLayout = AbsoluteLayout::New();
387   DevelControl::SetLayout( rootControl, absoluteLayout );
388   rootControl.SetName( "AbsoluteLayout" );
389   stage.Add( rootControl );
390
391   auto customLayout = Test::CustomLayout::New();
392   tet_printf( "Set Flag so child is measured with an unconstrained measure spec\n");
393   customLayout.SetCustomBehaviourFlag( Test::CustomLayout::BEHAVIOUR_FLAG_UNCONSTRAINED_CHILD_WIDTH );
394   customLayout.SetCustomBehaviourFlag( Test::CustomLayout::BEHAVIOUR_FLAG_UNCONSTRAINED_CHILD_HEIGHT );
395   auto customHBox = Control::New();
396   customHBox.SetName("CustomHBox");
397   DevelControl::SetLayout( customHBox, customLayout );
398   tet_printf( "Set width of custom layout to be smaller than child Grid wants to be\n");
399   customHBox.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION, 150 );
400   customHBox.SetProperty( LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, 150 );
401   rootControl.Add( customHBox );
402
403   auto gridContainer = Control::New();
404   auto gridLayout = Grid::New();
405   gridLayout.SetNumberOfColumns( NUMBER_OF_COLUMNS );
406   gridContainer.SetName( "GridLayout");
407   DevelControl::SetLayout( gridContainer, gridLayout );
408   tet_printf( "Grid SPEC set to MATCH_PARENT, this will be ignored if BEHAVIOUR_FLAG_UNCONSTRAINED_CHILD_WIDTH or BEHAVIOUR_FLAG_UNCONSTRAINED_CHILD_HEIGHT flags are set\n");
409   gridContainer.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
410   gridContainer.SetProperty( LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
411
412   std::vector< Control > controls;
413   for( auto i=0; i < NUMBER_OF_ITEMS; i++ )
414   {
415     controls.push_back( CreateLeafControl( 100, 100 ) );
416   }
417
418   for( auto&& iter : controls )
419   {
420     gridContainer.Add( iter );
421   }
422
423   customHBox.Add( gridContainer );
424
425   // Ensure layouting happens
426   application.SendNotification();
427   application.Render();
428
429  // Grid will layout first 2 items on first row then last 2 on second row.
430   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
431   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 100.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
432   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
433   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
434
435   // Item sizes will not be changed
436   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
437   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
438   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
439   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
440
441   END_TEST;
442 }
443
444 int UtcDaliLayouting_GridLayout06(void)
445 {
446   ToolkitTestApplication application;
447   tet_infoline(" UtcDaliLayouting_GridLayout06 2 Column, 4 Items UNSPECIFIED width SPECIFICATION");
448
449   const auto NUMBER_OF_COLUMNS = 2;
450   const auto NUMBER_OF_ITEMS = 4;
451
452   tet_printf( "Testing %d columns with %d items\n", NUMBER_OF_COLUMNS, NUMBER_OF_ITEMS );
453
454   Stage stage = Stage::GetCurrent();
455
456   auto rootControl = Control::New();
457   auto absoluteLayout = AbsoluteLayout::New();
458   DevelControl::SetLayout( rootControl, absoluteLayout );
459   rootControl.SetName( "AbsoluteLayout" );
460   stage.Add( rootControl );
461
462   auto customLayout = Test::CustomLayout::New();
463   tet_printf( "Set Flag so child is measured with an unconstrained measure spec\n");
464   customLayout.SetCustomBehaviourFlag( Test::CustomLayout::BEHAVIOUR_FLAG_UNCONSTRAINED_CHILD_WIDTH );
465   auto customHBox = Control::New();
466   customHBox.SetName("CustomHBox");
467   DevelControl::SetLayout( customHBox, customLayout );
468   tet_printf( "Set width of custom layout to be smaller than child Grid wants to be\n");
469   customHBox.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION, 150 );
470   customHBox.SetProperty( LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, 150 );
471   rootControl.Add( customHBox );
472
473   auto gridContainer = Control::New();
474   auto gridLayout = Grid::New();
475   gridLayout.SetNumberOfColumns( NUMBER_OF_COLUMNS );
476   gridContainer.SetName( "GridLayout");
477   DevelControl::SetLayout( gridContainer, gridLayout );
478   tet_printf( "Grid SPEC set to MATCH_PARENT, this will be ignored if BEHAVIOUR_FLAG_UNCONSTRAINED_CHILD_WIDTH or BEHAVIOUR_FLAG_UNCONSTRAINED_CHILD_HEIGHT flags are set\n");
479   gridContainer.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
480   gridContainer.SetProperty( LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
481
482   std::vector< Control > controls;
483   for( auto i=0; i < NUMBER_OF_ITEMS; i++ )
484   {
485     controls.push_back( CreateLeafControl( 100, 100 ) );
486   }
487
488   for( auto&& iter : controls )
489   {
490     gridContainer.Add( iter );
491   }
492
493   customHBox.Add( gridContainer );
494
495   // Ensure layouting happens
496   application.SendNotification();
497   application.Render();
498
499  // Grid will layout first 2 items on first row then last 2 on second row.
500   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
501   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 100.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
502   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 75.0f, 0.0f ), 0.0001f, TEST_LOCATION );
503   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 100.0f, 75.0f, 0.0f ), 0.0001f, TEST_LOCATION );
504
505   // Item sizes will not be changed
506   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 75.0f, 0.0f ), 0.0001f, TEST_LOCATION );
507   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 75.0f, 0.0f ), 0.0001f, TEST_LOCATION );
508   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 75.0f, 0.0f ), 0.0001f, TEST_LOCATION );
509   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 75.0f, 0.0f ), 0.0001f, TEST_LOCATION );
510
511   END_TEST;
512 }
513
514
515 int UtcDaliLayouting_GridLayout07(void)
516 {
517   ToolkitTestApplication application;
518   tet_infoline(" UtcDaliLayouting_GridLayout07 2 Column, 4 Items UNSPECIFIED height SPECIFICATION");
519
520   const auto NUMBER_OF_COLUMNS = 2;
521   const auto NUMBER_OF_ITEMS = 4;
522
523   tet_printf( "Testing %d columns with %d items\n", NUMBER_OF_COLUMNS, NUMBER_OF_ITEMS );
524
525   Stage stage = Stage::GetCurrent();
526
527   auto rootControl = Control::New();
528   auto absoluteLayout = AbsoluteLayout::New();
529   DevelControl::SetLayout( rootControl, absoluteLayout );
530   rootControl.SetName( "AbsoluteLayout" );
531   stage.Add( rootControl );
532
533   auto customLayout = Test::CustomLayout::New();
534   tet_printf( "Set Flag so child is measured with an unconstrained measure spec\n");
535   customLayout.SetCustomBehaviourFlag( Test::CustomLayout::BEHAVIOUR_FLAG_UNCONSTRAINED_CHILD_HEIGHT );
536   auto customHBox = Control::New();
537   customHBox.SetName("CustomHBox");
538   DevelControl::SetLayout( customHBox, customLayout );
539   tet_printf( "Set width of custom layout to be smaller than child Grid wants to be\n");
540   customHBox.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION, 150 );
541   customHBox.SetProperty( LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, 150 );
542   rootControl.Add( customHBox );
543
544   auto gridContainer = Control::New();
545   auto gridLayout = Grid::New();
546   gridLayout.SetNumberOfColumns( NUMBER_OF_COLUMNS );
547   gridContainer.SetName( "GridLayout");
548   DevelControl::SetLayout( gridContainer, gridLayout );
549   tet_printf( "Grid SPEC set to MATCH_PARENT, this will be ignored if BEHAVIOUR_FLAG_UNCONSTRAINED_CHILD_WIDTH or BEHAVIOUR_FLAG_UNCONSTRAINED_CHILD_HEIGHT flags are set\n");
550   gridContainer.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
551   gridContainer.SetProperty( LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
552
553   std::vector< Control > controls;
554   for( auto i=0; i < NUMBER_OF_ITEMS; i++ )
555   {
556     controls.push_back( CreateLeafControl( 100, 100 ) );
557   }
558
559   for( auto&& iter : controls )
560   {
561     gridContainer.Add( iter );
562   }
563
564   customHBox.Add( gridContainer );
565
566   // Ensure layouting happens
567   application.SendNotification();
568   application.Render();
569
570  // Grid will layout first 2 items on first row then last 2 on second row.
571   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
572   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 75.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
573   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
574   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 75.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
575
576   // Item sizes will not be changed
577   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 75.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
578   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 75.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
579   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 75.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
580   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 75.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
581
582   END_TEST;
583 }
584
585
586 int UtcDaliLayouting_GridLayout08(void)
587 {
588   ToolkitTestApplication application;
589   tet_infoline(" UtcDaliLayouting_GridLayout08 2 Column, 4 Items Grid with children too wide for parent spec");
590
591   const auto NUMBER_OF_COLUMNS = 2;
592   const auto NUMBER_OF_ITEMS = 4;
593
594   tet_printf( "Testing %d columns with %d items\n", NUMBER_OF_COLUMNS, NUMBER_OF_ITEMS );
595
596   Stage stage = Stage::GetCurrent();
597
598   auto rootControl = Control::New();
599   auto absoluteLayout = AbsoluteLayout::New();
600   DevelControl::SetLayout( rootControl, absoluteLayout );
601   rootControl.SetName( "AbsoluteLayout" );
602   stage.Add( rootControl );
603
604   auto customLayout = Test::CustomLayout::New();
605   auto customHBox = Control::New();
606   customHBox.SetName("CustomHBox");
607   DevelControl::SetLayout( customHBox, customLayout );
608   tet_printf( "Set width of custom layout to be smaller than child Grid wants to be\n");
609   customHBox.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION, 150 );
610   customHBox.SetProperty( LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, 200 );
611   rootControl.Add( customHBox );
612
613   auto gridContainer = Control::New();
614   auto gridLayout = Grid::New();
615   gridLayout.SetNumberOfColumns( NUMBER_OF_COLUMNS );
616   gridContainer.SetName( "GridLayout");
617   DevelControl::SetLayout( gridContainer, gridLayout );
618   gridContainer.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
619   gridContainer.SetProperty( LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
620
621   std::vector< Control > controls;
622   for( auto i=0; i < NUMBER_OF_ITEMS; i++ )
623   {
624     controls.push_back( CreateLeafControl( 100, 100 ) );
625   }
626
627   for( auto&& iter : controls )
628   {
629     gridContainer.Add( iter );
630   }
631
632   customHBox.Add( gridContainer );
633
634   // Ensure layouting happens
635   application.SendNotification();
636   application.Render();
637
638   tet_printf( "Children width reduced from 100 to 75\n", NUMBER_OF_COLUMNS, NUMBER_OF_ITEMS );
639   // Grid will layout first 2 items on first row then last 2 on second row.
640   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
641   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 75.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
642   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
643   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 75.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
644
645   // Item sizes will be changed
646   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 75.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
647   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 75.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
648   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 75.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
649   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 75.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
650
651   END_TEST;
652 }
653
654
655 int UtcDaliLayouting_GridLayoutDownCast(void)
656 {
657   TestApplication application;
658   tet_infoline(" UtcDaliLayouting_GridLayoutDownCast - Testing Downcast");
659
660   Grid gridLayout = Grid::New();
661
662   LayoutGroup layoutGroup( gridLayout );
663
664   Grid gridLayoutCandidate = Grid::DownCast( layoutGroup );
665   DALI_TEST_CHECK( gridLayoutCandidate );
666
667   END_TEST;
668 }