2 * Copyright (c) 2018 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 #include <dali-toolkit-test-suite-utils.h>
21 #include <toolkit-event-thread-callback.h>
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>
30 #include <../custom-layout.h>
32 #include <layout-utils.h>
35 using namespace Toolkit;
37 void utc_dali_toolkit_grid_layouting_startup(void)
39 test_return_value = TET_UNDEF;
42 void utc_dali_toolkit_grid_layouting_cleanup(void)
44 test_return_value = TET_PASS;
47 int UtcDaliLayouting_GridLayout01(void)
49 ToolkitTestApplication application;
50 tet_infoline(" UtcDaliLayouting_GridLayout01 2 Column, 4 Items");
52 const auto NUMBER_OF_COLUMNS = 2;
53 const auto NUMBER_OF_ITEMS = 4;
55 tet_printf( "Testing %d columns with %d items\n", NUMBER_OF_COLUMNS, NUMBER_OF_ITEMS );
57 Stage stage = Stage::GetCurrent();
59 auto rootControl = Control::New();
60 auto absoluteLayout = AbsoluteLayout::New();
61 DevelControl::SetLayout( rootControl, absoluteLayout );
62 rootControl.SetName( "AbsoluteLayout" );
63 stage.Add( rootControl );
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 );
73 std::vector< Control > controls;
74 for( auto i=0; i < NUMBER_OF_ITEMS; i++ )
76 controls.push_back( CreateLeafControl( 100, 100 ) );
79 for( auto&& iter : controls )
81 gridContainer.Add( iter );
84 rootControl.Add( gridContainer );
86 // Ensure layouting happens
87 application.SendNotification();
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 );
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 );
102 tet_printf( "Confirm number of columns is as set\n");
103 DALI_TEST_EQUALS( gridLayout.GetNumberOfColumns(), NUMBER_OF_COLUMNS, TEST_LOCATION );
108 int UtcDaliLayouting_GridLayout02(void)
110 ToolkitTestApplication application;
111 tet_infoline("UtcDaliLayouting_GridLayout02");
113 const auto NUMBER_OF_COLUMNS = 3;
114 const auto NUMBER_OF_ITEMS = 7;
116 tet_printf( "Testing %d columns with %d items\n", NUMBER_OF_COLUMNS, NUMBER_OF_ITEMS );
118 Stage stage = Stage::GetCurrent();
120 auto rootControl = Control::New();
121 auto absoluteLayout = AbsoluteLayout::New();
122 DevelControl::SetLayout( rootControl, absoluteLayout );
123 rootControl.SetName( "AbsoluteLayout" );
124 stage.Add( rootControl );
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 );
134 std::vector< Control > controls;
135 for( auto i=0; i < NUMBER_OF_ITEMS; i++ )
137 controls.push_back( CreateLeafControl( 100, 100 ) );
140 for( auto&& iter : controls )
142 gridContainer.Add( iter );
145 rootControl.Add( gridContainer );
147 // Ensure layouting happens
148 application.SendNotification();
149 application.Render();
151 // grid layouts out 3 items per row, which is 480x800.
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 );
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 );
161 DALI_TEST_EQUALS( controls[6].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 200.0f, 0.0f ), 0.0001f, TEST_LOCATION );
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 );
174 int UtcDaliLayouting_GridLayout03(void)
176 ToolkitTestApplication application;
177 tet_infoline(" UtcDaliLayouting_GridLayout03 Grid Padding");
179 const auto NUMBER_OF_COLUMNS = 2;
180 const auto NUMBER_OF_ITEMS = 4;
182 tet_printf( "Testing %d columns with %d items\n", NUMBER_OF_COLUMNS, NUMBER_OF_ITEMS );
184 Extents GRID_PADDING( Extents( 10, 10, 20, 20 ) ); // start,end,top,bottom
186 tet_printf( "Testing with Padding 10,10,20,20\n");
188 Stage stage = Stage::GetCurrent();
190 auto rootControl = Control::New();
191 auto absoluteLayout = AbsoluteLayout::New();
192 DevelControl::SetLayout( rootControl, absoluteLayout );
193 rootControl.SetName( "AbsoluteLayout" );
194 stage.Add( rootControl );
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 );
205 std::vector< Control > controls;
206 for( auto i=0; i < NUMBER_OF_ITEMS; i++ )
208 controls.push_back( CreateLeafControl( 100, 100 ) );
211 for( auto&& iter : controls )
213 gridContainer.Add( iter );
216 rootControl.Add( gridContainer );
218 // Ensure layouting happens
219 application.SendNotification();
220 application.Render();
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 );
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 );
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 );
243 int UtcDaliLayouting_GridLayout04(void)
245 ToolkitTestApplication application;
246 tet_infoline(" UtcDaliLayouting_GridLayout04 Child Margin");
248 const auto NUMBER_OF_COLUMNS = 2;
249 const auto NUMBER_OF_ITEMS = 4;
251 tet_printf( "Testing %d columns with %d items\n", NUMBER_OF_COLUMNS, NUMBER_OF_ITEMS );
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
256 tet_printf( "Testing with Margin 10,10,5,5\n");
258 Stage stage = Stage::GetCurrent();
260 auto rootControl = Control::New();
261 auto absoluteLayout = AbsoluteLayout::New();
262 DevelControl::SetLayout( rootControl, absoluteLayout );
263 rootControl.SetName( "AbsoluteLayout" );
264 stage.Add( rootControl );
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 );
275 std::vector< Control > controls;
276 for( auto i=0; i < NUMBER_OF_ITEMS; i++ )
278 auto control = CreateLeafControl( 100, 100 );
279 control.SetProperty(Toolkit::Control::Property::MARGIN, ITEM_MARGIN );
280 controls.push_back( control );
283 for( auto&& iter : controls )
285 gridContainer.Add( iter );
288 rootControl.Add( gridContainer );
290 // Ensure layouting happens
291 application.SendNotification();
292 application.Render();
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,
298 0.0001f, TEST_LOCATION );
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 );
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 );
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 );
315 tet_infoline(" UtcDaliLayouting_GridLayout03 Size of Grid should include padding and margins");
317 const auto NUMBER_OF_ROWS = ( NUMBER_OF_ITEMS / NUMBER_OF_COLUMNS );
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 );
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 );
336 int UtcDaliLayouting_GridLayoutDownCast(void)
338 TestApplication application;
339 tet_infoline(" UtcDaliLayouting_GridLayoutDownCast - Testing Downcast");
341 Grid gridLayout = Grid::New();
343 LayoutGroup layoutGroup( gridLayout );
345 Grid gridLayoutCandidate = Grid::DownCast( layoutGroup );
346 DALI_TEST_CHECK( gridLayoutCandidate );