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