6abc0c7ded5bb0c364e31497fa28cf38cd95cefb
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-Layouting.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
22 #include <dali-toolkit/dali-toolkit.h>
23 #include <dali-toolkit/devel-api/controls/control-devel.h>
24 #include <dali-toolkit/devel-api/layouting/hbox-layout.h>
25 #include <dali-toolkit/devel-api/layouting/vbox-layout.h>
26
27 #include <layout-utils.h>
28
29 using namespace Dali;
30 using namespace Toolkit;
31
32 void utc_dali_toolkit_layouting_startup(void)
33 {
34   test_return_value = TET_UNDEF;
35 }
36
37 void utc_dali_toolkit_layouting_cleanup(void)
38 {
39   test_return_value = TET_PASS;
40 }
41
42 int UtcDaliLayouting_HboxLayout01(void)
43 {
44   ToolkitTestApplication application;
45   tet_infoline(" UtcDaliLayouting_HboxLayout01");
46
47   Stage stage = Stage::GetCurrent();
48   auto hbox = Control::New();
49   auto hboxLayout = HboxLayout::New();
50   hboxLayout.SetCellPadding( LayoutSize( 10, 0 ) );
51   DevelControl::SetLayout( hbox, hboxLayout );
52   hbox.SetName( "HBox");
53
54   std::vector< Control > controls;
55   controls.push_back( CreateLeafControl( 40, 40 ) );
56   controls.push_back( CreateLeafControl( 60, 40 ) );
57   controls.push_back( CreateLeafControl( 80, 40 ) );
58   controls.push_back( CreateLeafControl( 100, 40 ) );
59
60   for( auto&& iter : controls )
61   {
62     hbox.Add( iter );
63   }
64   hbox.SetParentOrigin( ParentOrigin::CENTER );
65   hbox.SetAnchorPoint( AnchorPoint::CENTER );
66   stage.Add( hbox );
67
68   // Ensure layouting happens
69   application.SendNotification();
70   application.Render();
71
72   // hbox centers elements vertically, it fills test harness stage, which is 480x800.
73   // hbox left justifies elements
74   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 380.0f, 0.0f ), 0.0001f, TEST_LOCATION );
75   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 50.0f, 380.0f, 0.0f ), 0.0001f, TEST_LOCATION );
76   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 120.0f, 380.0f, 0.0f ), 0.0001f, TEST_LOCATION );
77   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 210.0f, 380.0f, 0.0f ), 0.0001f, TEST_LOCATION );
78
79   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
80   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 60.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
81   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 80.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
82   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
83
84   END_TEST;
85 }
86
87 int UtcDaliLayouting_HboxLayout02(void)
88 {
89   ToolkitTestApplication application;
90   tet_infoline(" UtcDaliLayouting_HboxLayout02 Test nested hboxes with default spec of WRAP_CONTENT");
91
92   Stage stage = Stage::GetCurrent();
93
94   auto hbox1 = Control::New();
95   auto hboxLayout1 = HboxLayout::New();
96   DevelControl::SetLayout( hbox1, hboxLayout1 );
97
98   auto hbox2 = Control::New();
99   auto hboxLayout2 = HboxLayout::New();
100   DevelControl::SetLayout( hbox2, hboxLayout2 );
101
102   hbox1.SetName( "HBox1");
103   hbox2.SetName( "HBox2");
104
105   std::vector< Control > controls;
106   controls.push_back( CreateLeafControl( 20, 40 ) );
107   controls.push_back( CreateLeafControl( 30, 50 ) );
108   controls.push_back( CreateLeafControl( 40, 60 ) );
109   controls.push_back( CreateLeafControl( 50, 70 ) );
110
111   controls.push_back( CreateLeafControl( 25, 40 ) );
112   controls.push_back( CreateLeafControl( 35, 50 ) );
113   controls.push_back( CreateLeafControl( 45, 60 ) );
114   controls.push_back( CreateLeafControl( 55, 70 ) );
115
116   int counter=0;
117   for( auto&& iter : controls )
118   {
119     if( counter < 4 )
120     {
121       hbox1.Add( iter );
122     }
123     else
124     {
125       hbox2.Add( iter );
126     }
127     ++counter;
128   }
129   hbox1.SetParentOrigin( ParentOrigin::CENTER );
130   hbox1.SetAnchorPoint( AnchorPoint::CENTER );
131   hbox2.SetParentOrigin( ParentOrigin::CENTER );
132   hbox2.SetAnchorPoint( AnchorPoint::CENTER );
133
134   auto hbox3 = Control::New();
135   auto hboxLayout3 = HboxLayout::New();
136   DevelControl::SetLayout( hbox3, hboxLayout3 );
137
138   hbox3.SetParentOrigin( ParentOrigin::CENTER );
139   hbox3.SetName( "HBox3");
140   hbox3.Add( hbox1 );
141   hbox3.Add( hbox2 );
142
143   stage.Add( hbox3 );
144
145   // Ensure layouting happens
146   application.SendNotification();
147   application.Render();
148
149
150   // hbox centers elements vertically, it fills test harness stage, which is 480x800.
151   // hbox left justifies elements
152   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3(  0.0f, 15.0f, 0.0f ), 0.0001f, TEST_LOCATION );
153   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 20.0f, 10.0f, 0.0f ), 0.0001f, TEST_LOCATION );
154   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 50.0f,  5.0f, 0.0f ), 0.0001f, TEST_LOCATION );
155   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 90.0f,  0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
156
157   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 20.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
158   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 30.0f, 50.0f, 0.0f ), 0.0001f, TEST_LOCATION );
159   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 40.0f, 60.0f, 0.0f ), 0.0001f, TEST_LOCATION );
160   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 50.0f, 70.0f, 0.0f ), 0.0001f, TEST_LOCATION );
161
162
163   DALI_TEST_EQUALS( controls[4].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3(  0.0f, 15.0f, 0.0f ), 0.0001f, TEST_LOCATION );
164   DALI_TEST_EQUALS( controls[5].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 25.0f, 10.0f, 0.0f ), 0.0001f, TEST_LOCATION );
165   DALI_TEST_EQUALS( controls[6].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 60.0f,  5.0f, 0.0f ), 0.0001f, TEST_LOCATION );
166   DALI_TEST_EQUALS( controls[7].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 105.0f,  0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
167
168   DALI_TEST_EQUALS( controls[4].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 25.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
169   DALI_TEST_EQUALS( controls[5].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 35.0f, 50.0f, 0.0f ), 0.0001f, TEST_LOCATION );
170   DALI_TEST_EQUALS( controls[6].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 45.0f, 60.0f, 0.0f ), 0.0001f, TEST_LOCATION );
171   DALI_TEST_EQUALS( controls[7].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 55.0f, 70.0f, 0.0f ), 0.0001f, TEST_LOCATION );
172
173   // Test hbox1 and 2 are sized to wrap their content
174   DALI_TEST_EQUALS( hbox1.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 140.0f, 70.0f, 0.0f ), 0.0001f, TEST_LOCATION );
175   DALI_TEST_EQUALS( hbox2.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 160.0f, 70.0f, 0.0f ), 0.0001f, TEST_LOCATION );
176   DALI_TEST_EQUALS( hbox1.GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 365.0f, 0.0f ), 0.0001f, TEST_LOCATION );
177   DALI_TEST_EQUALS( hbox2.GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 140.0f, 365.0f, 0.0f ), 0.0001f, TEST_LOCATION );
178
179   // Test hbox3 matches parent (root layer)
180   DALI_TEST_EQUALS( hbox3.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 480.0f, 800.0f, 0.0f ), 0.0001f, TEST_LOCATION );
181   DALI_TEST_EQUALS( hbox3.GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
182
183   END_TEST;
184 }
185
186
187 int UtcDaliLayouting_HboxLayout03(void)
188 {
189   ToolkitTestApplication application;
190   tet_infoline(" UtcDaliLayouting_HboxLayout03 Test nested hboxes with MATCH_PARENT");
191
192   Stage stage = Stage::GetCurrent();
193
194   auto hbox1 = Control::New();
195   auto hboxLayout1 = HboxLayout::New();
196   DevelControl::SetLayout( hbox1, hboxLayout1 );
197
198   auto hbox2 = Control::New();
199   auto hboxLayout2 = HboxLayout::New();
200   DevelControl::SetLayout( hbox2, hboxLayout2 );
201
202   hbox1.SetName( "HBox1");
203   hbox2.SetName( "HBox2");
204   hbox1.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
205   hbox1.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
206   hbox2.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
207   hbox2.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
208
209   std::vector< Control > controls;
210   controls.push_back( CreateLeafControl( 20, 40 ) );
211   controls.push_back( CreateLeafControl( 30, 50 ) );
212   controls.push_back( CreateLeafControl( 40, 60 ) );
213   controls.push_back( CreateLeafControl( 50, 70 ) );
214
215   controls.push_back( CreateLeafControl( 25, 40 ) );
216   controls.push_back( CreateLeafControl( 35, 50 ) );
217   controls.push_back( CreateLeafControl( 45, 60 ) );
218   controls.push_back( CreateLeafControl( 55, 70 ) );
219
220   int counter=0;
221   for( auto&& iter : controls )
222   {
223     if( counter < 4 )
224     {
225       hbox1.Add( iter );
226     }
227     else
228     {
229       hbox2.Add( iter );
230     }
231     ++counter;
232   }
233   hbox1.SetParentOrigin( ParentOrigin::CENTER );
234   hbox1.SetAnchorPoint( AnchorPoint::CENTER );
235   hbox2.SetParentOrigin( ParentOrigin::CENTER );
236   hbox2.SetAnchorPoint( AnchorPoint::CENTER );
237
238   auto hbox3 = Control::New();
239   auto hboxLayout3 = HboxLayout::New();
240   DevelControl::SetLayout( hbox3, hboxLayout3);
241
242   hbox3.SetParentOrigin( ParentOrigin::CENTER );
243   hbox3.SetName( "HBox3");
244   hbox3.Add( hbox1 );
245   hbox3.Add( hbox2 );
246
247   stage.Add( hbox3 );
248
249   //std::ostringstream oss;
250   //DumpControlHierarchy( oss, Stage::GetCurrent().GetRootLayer() );
251   //printf("Control hierarchy: \n%s\n", oss.str().c_str() );
252
253   // Ensure layouting happens
254   application.SendNotification();
255   application.Render();
256
257
258   // hbox centers elements vertically, it fills test harness stage, which is 480x800.
259   // hbox left justifies elements
260   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 380.0f, 0.0f ), 0.0001f, TEST_LOCATION );
261   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 20.0f,375.0f, 0.0f ), 0.0001f, TEST_LOCATION );
262   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 50.0f,370.0f, 0.0f ), 0.0001f, TEST_LOCATION );
263   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 90.0f,365.0f, 0.0f ), 0.0001f, TEST_LOCATION );
264
265   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 20.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
266   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 30.0f, 50.0f, 0.0f ), 0.0001f, TEST_LOCATION );
267   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 40.0f, 60.0f, 0.0f ), 0.0001f, TEST_LOCATION );
268   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 50.0f, 70.0f, 0.0f ), 0.0001f, TEST_LOCATION );
269
270   DALI_TEST_EQUALS( controls[4].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3(  0.0f, 380.0f, 0.0f ), 0.0001f, TEST_LOCATION );
271   DALI_TEST_EQUALS( controls[5].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 25.0f, 375.0f, 0.0f ), 0.0001f, TEST_LOCATION );
272   DALI_TEST_EQUALS( controls[6].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 60.0f, 370.0f, 0.0f ), 0.0001f, TEST_LOCATION );
273   DALI_TEST_EQUALS( controls[7].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 105.0f,365.0f, 0.0f ), 0.0001f, TEST_LOCATION );
274
275   DALI_TEST_EQUALS( controls[4].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 25.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
276   DALI_TEST_EQUALS( controls[5].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 35.0f, 50.0f, 0.0f ), 0.0001f, TEST_LOCATION );
277   DALI_TEST_EQUALS( controls[6].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 45.0f, 60.0f, 0.0f ), 0.0001f, TEST_LOCATION );
278   DALI_TEST_EQUALS( controls[7].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 55.0f, 70.0f, 0.0f ), 0.0001f, TEST_LOCATION );
279
280   DALI_TEST_EQUALS( hbox1.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 480.0f, 800.0f, 0.0f ), 0.0001f, TEST_LOCATION );
281   DALI_TEST_EQUALS( hbox2.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 480.0f, 800.0f, 0.0f ), 0.0001f, TEST_LOCATION );
282   DALI_TEST_EQUALS( hbox1.GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
283   DALI_TEST_EQUALS( hbox2.GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 480.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
284
285   // Test hbox3 matches parent (root layer)
286   DALI_TEST_EQUALS( hbox3.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 480.0f, 800.0f, 0.0f ), 0.0001f, TEST_LOCATION );
287   DALI_TEST_EQUALS( hbox3.GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
288
289   END_TEST;
290 }
291
292 int UtcDaliLayouting_HboxLayout04(void)
293 {
294   ToolkitTestApplication application;
295   tet_infoline(" UtcDaliLayouting_HboxLayout04 Test nested hboxes with explicit WRAP_CONTENT");
296
297   Stage stage = Stage::GetCurrent();
298
299   auto hbox1 = Control::New();
300   auto hboxLayout1 = HboxLayout::New();
301   DevelControl::SetLayout( hbox1, hboxLayout1 );
302
303   auto hbox2 = Control::New();
304   auto hboxLayout2 = HboxLayout::New();
305   DevelControl::SetLayout( hbox2, hboxLayout2 );
306
307   hbox1.SetName( "HBox1"); // Default spec is to wrap content
308   hbox2.SetName( "HBox2");
309   hbox1.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::WRAP_CONTENT );
310   hbox1.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::WRAP_CONTENT );
311   hbox2.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::WRAP_CONTENT );
312   hbox2.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::WRAP_CONTENT );
313
314   std::vector< Control > controls;
315   controls.push_back( CreateLeafControl( 80, 40 ) );
316   controls.push_back( CreateLeafControl( 80, 50 ) );
317   controls.push_back( CreateLeafControl( 80, 60 ) );
318   controls.push_back( CreateLeafControl( 80, 70 ) );
319
320   controls.push_back( CreateLeafControl( 80, 40 ) );
321   controls.push_back( CreateLeafControl( 80, 50 ) );
322   controls.push_back( CreateLeafControl( 80, 60 ) );
323   controls.push_back( CreateLeafControl( 80, 70 ) );
324
325   int counter=0;
326   for( auto&& iter : controls )
327   {
328     if( counter < 4 )
329     {
330       hbox1.Add( iter );
331     }
332     else
333     {
334       hbox2.Add( iter );
335     }
336     ++counter;
337   }
338
339   controls[6].SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
340   auto hbox3 = Control::New();
341   auto hboxLayout3 = HboxLayout::New();
342   DevelControl::SetLayout( hbox3, hboxLayout3 );
343
344   hbox3.SetParentOrigin( ParentOrigin::CENTER );
345   hbox3.SetName( "HBox3");
346   hbox3.Add( hbox1 );
347   hbox3.Add( hbox2 );
348   stage.Add( hbox3 );
349
350   //std::ostringstream oss;
351   //DumpControlHierarchy( oss, Stage::GetCurrent().GetRootLayer() );
352   //printf("Control hierarchy: \n%s\n", oss.str().c_str() );
353
354   // Ensure layouting happens
355   application.SendNotification();
356   application.Render();
357
358
359   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 15.0f, 0.0f ), 0.0001f, TEST_LOCATION );
360   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 80.0f,10.0f, 0.0f ), 0.0001f, TEST_LOCATION );
361   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 160.0f, 5.0f, 0.0f ), 0.0001f, TEST_LOCATION );
362   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 240.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
363
364   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 80.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
365   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 80.0f, 50.0f, 0.0f ), 0.0001f, TEST_LOCATION );
366   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 80.0f, 60.0f, 0.0f ), 0.0001f, TEST_LOCATION );
367   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 80.0f, 70.0f, 0.0f ), 0.0001f, TEST_LOCATION );
368
369   DALI_TEST_EQUALS( controls[4].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3(  0.0f, 15.0f, 0.0f ), 0.0001f, TEST_LOCATION );
370   DALI_TEST_EQUALS( controls[5].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 80.0f, 10.0f, 0.0f ), 0.0001f, TEST_LOCATION );
371   DALI_TEST_EQUALS( controls[6].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 160.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
372   DALI_TEST_EQUALS( controls[7].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 240.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
373
374   DALI_TEST_EQUALS( controls[4].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 80.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
375   DALI_TEST_EQUALS( controls[5].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 80.0f, 50.0f, 0.0f ), 0.0001f, TEST_LOCATION );
376   DALI_TEST_EQUALS( controls[6].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 80.0f, 70.0f, 0.0f ), 0.0001f, TEST_LOCATION );
377   DALI_TEST_EQUALS( controls[7].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 80.0f, 70.0f, 0.0f ), 0.0001f, TEST_LOCATION );
378
379   DALI_TEST_EQUALS( hbox1.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 320.0f, 70.0f, 0.0f ), 0.0001f, TEST_LOCATION );
380   DALI_TEST_EQUALS( hbox2.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 320.0f, 70.0f, 0.0f ), 0.0001f, TEST_LOCATION );
381   DALI_TEST_EQUALS( hbox1.GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 365.0f, 0.0f ), 0.0001f, TEST_LOCATION );
382   DALI_TEST_EQUALS( hbox2.GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 320.0f, 365.0f, 0.0f ), 0.0001f, TEST_LOCATION );
383
384
385   // Test hbox3 matches parent (root layer)
386   DALI_TEST_EQUALS( hbox3.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 480.0f, 800.0f, 0.0f ), 0.0001f, TEST_LOCATION );
387   DALI_TEST_EQUALS( hbox3.GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
388
389   END_TEST;
390 }
391
392 int UtcDaliLayouting_HboxLayout05(void)
393 {
394   ToolkitTestApplication application;
395   tet_infoline(" UtcDaliLayouting_HboxLayout05 - Set children size explicitly via width & height specification");
396
397   Stage stage = Stage::GetCurrent();
398   auto hbox = Control::New();
399   auto hboxLayout = HboxLayout::New();
400   hboxLayout.SetCellPadding( LayoutSize( 10, 0 ) );
401   DevelControl::SetLayout( hbox, hboxLayout );
402   hbox.SetName( "HBox");
403
404   std::vector< Control > controls;
405   controls.push_back( CreateLeafControl( 40, 40 ) );
406   controls.push_back( CreateLeafControl( 60, 40 ) );
407   controls.push_back( CreateLeafControl( 80, 40 ) );
408   controls.push_back( CreateLeafControl( 100, 40 ) );
409
410   for( auto&& iter : controls )
411   {
412     hbox.Add( iter );
413     iter.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, 100 );
414     iter.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, 50 );
415   }
416
417   hbox.SetParentOrigin( ParentOrigin::CENTER );
418   hbox.SetAnchorPoint( AnchorPoint::CENTER );
419   stage.Add( hbox );
420
421   // Ensure layouting happens
422   application.SendNotification();
423   application.Render();
424
425   // hbox centers elements vertically, it fills test harness stage, which is 480x800.
426   // hbox left justifies elements
427   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 375.0f, 0.0f ), 0.0001f, TEST_LOCATION );
428   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 110.0f, 375.0f, 0.0f ), 0.0001f, TEST_LOCATION );
429   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 220.0f, 375.0f, 0.0f ), 0.0001f, TEST_LOCATION );
430   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 330.0f, 375.0f, 0.0f ), 0.0001f, TEST_LOCATION );
431
432   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 50.0f, 0.0f ), 0.0001f, TEST_LOCATION );
433   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 50.0f, 0.0f ), 0.0001f, TEST_LOCATION );
434   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 50.0f, 0.0f ), 0.0001f, TEST_LOCATION );
435   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 50.0f, 0.0f ), 0.0001f, TEST_LOCATION );
436
437   END_TEST;
438 }
439
440 // Padding tests
441
442 int UtcDaliLayouting_HboxLayout_Padding01(void)
443 {
444   ToolkitTestApplication application;
445   tet_infoline("UtcDaliLayouting_HboxLayout_Padding01 - Adding Padding to a single child");
446
447   Stage stage = Stage::GetCurrent();
448   auto hbox = Control::New();
449   auto hboxLayout = HboxLayout::New();
450   DevelControl::SetLayout( hbox, hboxLayout );
451   hbox.SetName( "HBox");
452
453   std::vector< Control > controls;
454   controls.push_back( CreateLeafControl( 40, 40 ) );
455   controls.push_back( CreateLeafControl( 60, 40 ) );
456   controls.push_back( CreateLeafControl( 80, 40 ) );
457   controls.push_back( CreateLeafControl( 100, 40 ) );
458
459   const Extents CONTROL_PADDING = Extents(5, 10, 20, 2 );
460   tet_printf( "\nAdding Padding to control at index %u \n", 1 );
461   controls[1].SetProperty(Toolkit::Control::Property::PADDING, CONTROL_PADDING );
462
463   for( auto&& iter : controls )
464   {
465     hbox.Add( iter );
466   }
467   hbox.SetParentOrigin( ParentOrigin::CENTER );
468   hbox.SetAnchorPoint( AnchorPoint::CENTER );
469   stage.Add( hbox );
470
471   // Ensure layouting happens
472   application.SendNotification();
473   application.Render();
474
475   // hbox centers elements vertically, it fills test harness stage, which is 480x800.
476   // hbox left justifies elements
477   tet_infoline("Test Child Actor Position");
478   float xPositionOfControlBeingTested = 0.0f;
479   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( xPositionOfControlBeingTested,
480                                                                                             380.0f,
481                                                                                             0.0f ), 0.0001f, TEST_LOCATION );
482   xPositionOfControlBeingTested += 40.0f;
483
484   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( xPositionOfControlBeingTested,
485                                                                                             380.0f - ( ( CONTROL_PADDING.top + CONTROL_PADDING.bottom) * 0.5f ),                                                                                            0.0f ),
486                                                                                             0.0001f, TEST_LOCATION );
487
488   xPositionOfControlBeingTested += 60.0f + CONTROL_PADDING.start + CONTROL_PADDING.end;
489   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( xPositionOfControlBeingTested, 380.0f, 0.0f ), 0.0001f, TEST_LOCATION );
490
491   xPositionOfControlBeingTested += 80.0f;
492   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( xPositionOfControlBeingTested,380.0f, 0.0f ), 0.0001f, TEST_LOCATION );
493
494   tet_infoline("Test Child Actor Size");
495   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
496
497   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 60.0f + CONTROL_PADDING.start + CONTROL_PADDING.end,
498                                                                                         40.0f + CONTROL_PADDING.top + CONTROL_PADDING.bottom , 0.0f ),
499                                                                                         0.0001f, TEST_LOCATION );
500
501   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 80.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
502   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
503
504   END_TEST;
505 }
506
507 int UtcDaliLayouting_HboxLayout_Padding02(void)
508 {
509   ToolkitTestApplication application;
510   tet_infoline("UtcDaliLayouting_HboxLayout_Padding02 - Adding Padding to a all children");
511
512   Stage stage = Stage::GetCurrent();
513   auto hbox = Control::New();
514   auto hboxLayout = HboxLayout::New();
515   DevelControl::SetLayout( hbox, hboxLayout );
516   hbox.SetName( "HBox");
517
518   std::vector< Control > controls;
519   controls.push_back( CreateLeafControl( 40, 40 ) );
520   controls.push_back( CreateLeafControl( 60, 40 ) );
521   controls.push_back( CreateLeafControl( 80, 40 ) );
522   controls.push_back( CreateLeafControl( 100, 40 ) );
523
524   const Extents CONTROL_PADDING = Extents(5, 10, 20, 2 );
525
526   for( auto&& iter : controls )
527   {
528     iter.SetProperty(Toolkit::Control::Property::PADDING, CONTROL_PADDING );
529     hbox.Add( iter );
530   }
531   hbox.SetParentOrigin( ParentOrigin::CENTER );
532   hbox.SetAnchorPoint( AnchorPoint::CENTER );
533   stage.Add( hbox );
534
535   // Ensure layouting happens
536   application.SendNotification();
537   application.Render();
538
539   // hbox centers elements vertically, it fills test harness stage, which is 480x800.
540   // hbox left justifies elements
541   tet_infoline("Test Child Actor Position");
542   float xPositionOfControlBeingTested = 0.0f;
543   float yPositionOfControlBeingTested = ( 800.0f * 0.5) - ( 0.5 * ( 40.0f + CONTROL_PADDING.top + CONTROL_PADDING.bottom ) );
544
545   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( xPositionOfControlBeingTested,
546                                                                                             yPositionOfControlBeingTested,
547                                                                                             0.0f ), 0.0001f, TEST_LOCATION );
548   xPositionOfControlBeingTested += 40.0f + CONTROL_PADDING.start + CONTROL_PADDING.end;
549
550   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( xPositionOfControlBeingTested,
551                                                                                             yPositionOfControlBeingTested,
552                                                                                             0.0f ),
553                                                                                             0.0001f, TEST_LOCATION );
554
555   xPositionOfControlBeingTested += 60.0f + CONTROL_PADDING.start + CONTROL_PADDING.end;
556   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( xPositionOfControlBeingTested,
557                                                                                             yPositionOfControlBeingTested,
558                                                                                             0.0f ), 0.0001f, TEST_LOCATION );
559
560   xPositionOfControlBeingTested += 80.0f + CONTROL_PADDING.start + CONTROL_PADDING.end;
561   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( xPositionOfControlBeingTested,
562                                                                                             yPositionOfControlBeingTested,
563                                                                                             0.0f ), 0.0001f, TEST_LOCATION );
564
565   tet_infoline("Test Child Actor Size");
566   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 40.0f + CONTROL_PADDING.start + CONTROL_PADDING.end,
567                                                                                         40.0f + CONTROL_PADDING.top + CONTROL_PADDING.bottom,
568                                                                                         0.0f ), 0.0001f, TEST_LOCATION );
569
570   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 60.0f + CONTROL_PADDING.start + CONTROL_PADDING.end,
571                                                                                         40.0f + CONTROL_PADDING.top + CONTROL_PADDING.bottom,
572                                                                                         0.0f ), 0.0001f, TEST_LOCATION );
573
574   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 80.0f + CONTROL_PADDING.start + CONTROL_PADDING.end ,
575                                                                                         40.0f + CONTROL_PADDING.top + CONTROL_PADDING.bottom,
576                                                                                         0.0f ), 0.0001f, TEST_LOCATION );
577
578   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f + CONTROL_PADDING.start + CONTROL_PADDING.end,
579                                                                                         40.0f + CONTROL_PADDING.top + CONTROL_PADDING.bottom,
580                                                                                         0.0f ), 0.0001f, TEST_LOCATION );
581
582   END_TEST;
583 }
584
585
586 int UtcDaliLayouting_HboxLayout_Padding03(void)
587 {
588   ToolkitTestApplication application;
589   tet_infoline("UtcDaliLayouting_HboxLayout_Padding03 - Adding Changing padding on a single child");
590
591   Stage stage = Stage::GetCurrent();
592   auto hbox = Control::New();
593   auto hboxLayout = HboxLayout::New();
594   DevelControl::SetLayout( hbox, hboxLayout );
595   hbox.SetName( "HBox");
596
597   std::vector< Control > controls;
598   controls.push_back( CreateLeafControl( 40, 40 ) );
599   controls.push_back( CreateLeafControl( 40, 40 ) );
600   controls.push_back( CreateLeafControl( 40, 40 ) );
601
602   const Extents CONTROL_PADDING = Extents(5, 10, 20, 2 );
603   tet_printf( "\nAdding Padding to control at index 1 \n" );
604   controls[1].SetProperty(Toolkit::Control::Property::PADDING, CONTROL_PADDING );
605
606   for( auto&& iter : controls )
607   {
608     hbox.Add( iter );
609   }
610   hbox.SetParentOrigin( ParentOrigin::CENTER );
611   hbox.SetAnchorPoint( AnchorPoint::CENTER );
612   stage.Add( hbox );
613
614   // Ensure layouting happens
615   application.SendNotification();
616   application.Render();
617
618   // hbox centers elements vertically, it fills test harness stage, which is 480x800.
619   // hbox left justifies elements
620   tet_infoline("Test Child Actor Position");
621   float xPositionOfControlBeingTested = 0.0f;
622   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( xPositionOfControlBeingTested,
623                                                                                             380.0f,
624                                                                                             0.0f ), 0.0001f, TEST_LOCATION );
625   xPositionOfControlBeingTested += 40.0f;
626
627   DALI_TEST_EQUALS( controls[ 1 ].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( xPositionOfControlBeingTested,
628                                                                                             380.0f - ( ( CONTROL_PADDING.top + CONTROL_PADDING.bottom) * 0.5f ),                                                                                            0.0f ),
629                                                                                             0.0001f, TEST_LOCATION );
630
631   xPositionOfControlBeingTested += 40.0f + CONTROL_PADDING.start + CONTROL_PADDING.end;
632   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( xPositionOfControlBeingTested, 380.0f, 0.0f ), 0.0001f, TEST_LOCATION );
633
634   const Extents NEW_CONTROL_PADDING = Extents(10, 10, 20, 2 );
635   tet_printf( "\nChanging Padding to control at index 1 \n" );
636   controls[1].SetProperty(Toolkit::Control::Property::PADDING, NEW_CONTROL_PADDING );
637
638   // Ensure layouting happens
639   application.SendNotification();
640   application.Render();
641
642   xPositionOfControlBeingTested = 0.0f; // reset
643
644   tet_infoline("Test Child Actor Position");
645   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( xPositionOfControlBeingTested,
646                                                                                             380.0f,
647                                                                                             0.0f ), 0.0001f, TEST_LOCATION );
648   xPositionOfControlBeingTested += 40.0f;
649
650   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( xPositionOfControlBeingTested,
651                                                                                             380.0f - ( ( NEW_CONTROL_PADDING.top + NEW_CONTROL_PADDING.bottom) * 0.5f ),                                                                                            0.0f ),
652                                                                                             0.0001f, TEST_LOCATION );
653
654   xPositionOfControlBeingTested += 40.0f + NEW_CONTROL_PADDING.start + NEW_CONTROL_PADDING.end;
655   tet_printf( "\nIf x position %u then change has not been processed \n", 40 + 40 + CONTROL_PADDING.start + CONTROL_PADDING.end );
656   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( xPositionOfControlBeingTested, 380.0f, 0.0f ), 0.0001f, TEST_LOCATION );
657
658   tet_infoline("Test Child Actor Size");
659   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ) , Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
660
661   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ) , Vector3( 40.0f + NEW_CONTROL_PADDING.start + NEW_CONTROL_PADDING.end,
662                                                                                         40.0f + NEW_CONTROL_PADDING.top + NEW_CONTROL_PADDING.bottom , 0.0f ),
663                                                                                         0.0001f, TEST_LOCATION );
664
665   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::SIZE ) , Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
666
667   END_TEST;
668 }
669
670 // Margin Tests
671
672 int UtcDaliLayouting_HboxLayout_Margin01(void)
673 {
674   ToolkitTestApplication application;
675   tet_infoline("UtcDaliLayouting_HboxLayout_Margin01 - Adding a margin to a single child");
676
677   Stage stage = Stage::GetCurrent();
678   auto hbox = Control::New();
679   auto hboxLayout = HboxLayout::New();
680   DevelControl::SetLayout( hbox, hboxLayout );
681   hbox.SetName( "HBox");
682
683   std::vector< Control > controls;
684   controls.push_back( CreateLeafControl( 40, 40 ) );
685   controls.push_back( CreateLeafControl( 60, 40 ) );
686   controls.push_back( CreateLeafControl( 80, 40 ) );
687   controls.push_back( CreateLeafControl( 100, 40 ) );
688
689   const Extents CONTROL_MARGIN = Extents(5, 10, 20, 0 );
690   tet_printf( "\nAdding Margin to control at index 1 \n" );
691   controls[1].SetProperty(Toolkit::Control::Property::MARGIN, CONTROL_MARGIN );
692
693   for( auto&& iter : controls )
694   {
695     hbox.Add( iter );
696   }
697   hbox.SetParentOrigin( ParentOrigin::CENTER );
698   hbox.SetAnchorPoint( AnchorPoint::CENTER );
699   stage.Add( hbox );
700
701   // Ensure layouting happens
702   application.SendNotification();
703   application.Render();
704
705   // hbox centers elements vertically, it fills test harness stage, which is 480x800.
706   // hbox left justifies elements
707   tet_infoline("Test Child Actor Position");
708   auto xPositionOfControlBeingTested = 0.0f;
709   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( xPositionOfControlBeingTested,
710                                                                                             380.0f,
711                                                                                             0.0f ), 0.0001f, TEST_LOCATION );
712   xPositionOfControlBeingTested += 40.0f + CONTROL_MARGIN.start;
713
714   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( xPositionOfControlBeingTested,
715                                                                                             380.0f + CONTROL_MARGIN.top, 0.0f ),
716                                                                                             0.0001f, TEST_LOCATION );
717
718   xPositionOfControlBeingTested += 60.0f + CONTROL_MARGIN.end;
719   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( xPositionOfControlBeingTested, 380.0f, 0.0f ), 0.0001f, TEST_LOCATION );
720
721   xPositionOfControlBeingTested += 80.0f;
722   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( xPositionOfControlBeingTested,380.0f, 0.0f ), 0.0001f, TEST_LOCATION );
723
724   tet_infoline("Test Child Actor Size is the same after Margin added");
725   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
726   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 60.0f, 40.0f , 0.0f ), 0.0001f, TEST_LOCATION );
727   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 80.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
728   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
729
730   END_TEST;
731 }
732
733
734 int UtcDaliLayouting_VboxLayout01(void)
735 {
736   ToolkitTestApplication application;
737   tet_infoline(" UtcDaliLayouting_VboxLayout01");
738
739   Stage stage = Stage::GetCurrent();
740   auto vbox = Control::New();
741   auto vboxLayout = VboxLayout::New();
742   DevelControl::SetLayout( vbox, vboxLayout );
743   vbox.SetName( "Vbox");
744
745   std::vector< Control > controls;
746   controls.push_back( CreateLeafControl( 40, 40 ) );
747   controls.push_back( CreateLeafControl( 60, 60 ) );
748   controls.push_back( CreateLeafControl( 80, 80 ) );
749   controls.push_back( CreateLeafControl( 100, 100 ) );
750
751   for( auto&& iter : controls )
752   {
753     vbox.Add( iter );
754   }
755   vbox.SetParentOrigin( ParentOrigin::CENTER );
756   vbox.SetAnchorPoint( AnchorPoint::CENTER );
757   stage.Add( vbox );
758
759   controls[2].SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
760
761   // Check it.
762   DALI_TEST_EQUALS( controls[2].GetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION ), Property::Value( ChildLayoutData::MATCH_PARENT ), TEST_LOCATION );
763
764   // Ensure layouting happens
765   application.SendNotification();
766   application.Render();
767
768   // vbox centers elements horizontally, it fills test harness stage, which is 480x800.
769   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 220.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
770   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 210.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
771   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
772   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 190.0f, 180.0f, 0.0f ), 0.0001f, TEST_LOCATION );
773
774   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
775   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 60.0f, 60.0f, 0.0f ), 0.0001f, TEST_LOCATION );
776   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 480.0f, 80.0f, 0.0f ), 0.0001f, TEST_LOCATION );
777   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
778
779   END_TEST;
780 }
781
782 int UtcDaliLayouting_VboxLayout02(void)
783 {
784   ToolkitTestApplication application;
785   tet_infoline(" UtcDaliLayouting_VboxLayout01");
786
787   Stage stage = Stage::GetCurrent();
788
789   // @todo Can't set specification properties on root control. Really need to make LayoutController a root
790   // LayoutGroup for this to happen automatically.
791   //
792   // For this test, add an hbox instead
793   auto hbox = Control::New();
794   auto hboxLayout = HboxLayout::New();
795   DevelControl::SetLayout( hbox, hboxLayout );
796   hbox.SetName( "Hbox");
797   stage.Add( hbox );
798
799   auto vbox = Control::New();
800   auto vboxLayout = VboxLayout::New();
801   DevelControl::SetLayout( vbox, vboxLayout );
802   vbox.SetName( "Vbox");
803   hbox.Add( vbox );
804
805   vbox.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::WRAP_CONTENT );
806   vbox.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
807
808   std::vector< Control > controls;
809   controls.push_back( CreateLeafControl( 40, 40 ) );
810   controls.push_back( CreateLeafControl( 60, 60 ) );
811   controls.push_back( CreateLeafControl( 80, 80 ) );
812   controls.push_back( CreateLeafControl( 100, 100 ) );
813
814   for( auto&& iter : controls )
815   {
816     vbox.Add( iter );
817   }
818   vbox.SetParentOrigin( ParentOrigin::CENTER );
819   vbox.SetAnchorPoint( AnchorPoint::CENTER );
820
821   controls[2].SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
822
823   // Check it.
824   DALI_TEST_EQUALS( controls[2].GetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION ), Property::Value( ChildLayoutData::MATCH_PARENT ), TEST_LOCATION );
825
826   // Ensure layouting happens
827   application.SendNotification();
828   application.Render();
829
830   DALI_TEST_EQUALS( hbox.GetProperty<Vector3>(Actor::Property::POSITION), Vector3(0,0,0),TEST_LOCATION);
831   DALI_TEST_EQUALS( hbox.GetProperty<Vector3>(Actor::Property::SIZE), Vector3(480,800,0),TEST_LOCATION);
832
833   // vbox centers elements horizontally, it should wrap it's content horizontally, i.e. it should take the width of the largest element (100)
834   DALI_TEST_EQUALS( vbox.GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
835   DALI_TEST_EQUALS( vbox.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 800.0f, 0.0f ), 0.0001f, TEST_LOCATION );
836
837   // 3rd control is set to match parent - this should also be 100 wide
838   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 30.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
839   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 20.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
840   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
841   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 180.0f, 0.0f ), 0.0001f, TEST_LOCATION );
842
843   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
844   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 60.0f, 60.0f, 0.0f ), 0.0001f, TEST_LOCATION );
845   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 80.0f, 0.0f ), 0.0001f, TEST_LOCATION );
846   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
847
848   END_TEST;
849 }
850
851
852 int UtcDaliLayouting_VboxLayout03(void)
853 {
854   ToolkitTestApplication application;
855   tet_infoline(" UtcDaliLayouting_VboxLayout03 test with cell padding set");
856
857   Stage stage = Stage::GetCurrent();
858
859   // @todo Can't set specification properties on root control. Really need to make LayoutController a root
860   // LayoutGroup for this to happen automatically.
861   //
862   // For this test, add an hbox instead
863   auto hbox = Control::New();
864   auto hboxLayout = HboxLayout::New();
865   DevelControl::SetLayout( hbox, hboxLayout );
866   hbox.SetName( "Hbox");
867   stage.Add( hbox );
868
869   auto vbox = Control::New();
870   auto vboxLayout = VboxLayout::New();
871   vboxLayout.SetCellPadding( LayoutSize( 0, 10 ) );
872
873   DALI_TEST_EQUALS( vboxLayout.GetCellPadding(), LayoutSize( 0, 10 ), TEST_LOCATION );
874
875   DevelControl::SetLayout( vbox, vboxLayout );
876   vbox.SetName( "Vbox");
877   hbox.Add( vbox );
878
879   vbox.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::WRAP_CONTENT );
880   vbox.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
881
882   std::vector< Control > controls;
883   controls.push_back( CreateLeafControl( 40, 40 ) );
884   controls.push_back( CreateLeafControl( 60, 60 ) );
885   controls.push_back( CreateLeafControl( 80, 80 ) );
886   controls.push_back( CreateLeafControl( 100, 100 ) );
887
888   for( auto&& iter : controls )
889   {
890     vbox.Add( iter );
891   }
892   vbox.SetParentOrigin( ParentOrigin::CENTER );
893   vbox.SetAnchorPoint( AnchorPoint::CENTER );
894
895   controls[2].SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
896
897   // Check it.
898   DALI_TEST_EQUALS( controls[2].GetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION ), Property::Value( ChildLayoutData::MATCH_PARENT ), TEST_LOCATION );
899
900   // Ensure layouting happens
901   application.SendNotification();
902   application.Render();
903
904   DALI_TEST_EQUALS( hbox.GetProperty<Vector3>(Actor::Property::POSITION), Vector3(0,0,0),TEST_LOCATION);
905   DALI_TEST_EQUALS( hbox.GetProperty<Vector3>(Actor::Property::SIZE), Vector3(480,800,0),TEST_LOCATION);
906
907   // vbox centers elements horizontally, it should wrap it's content horizontally, i.e. it should take the width of the largest element (100)
908   DALI_TEST_EQUALS( vbox.GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
909   DALI_TEST_EQUALS( vbox.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 800.0f, 0.0f ), 0.0001f, TEST_LOCATION );
910
911   // 3rd control is set to match parent - this should also be 100 wide
912   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 30.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
913   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 20.0f, 50.0f, 0.0f ), 0.0001f, TEST_LOCATION );
914   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 120.0f, 0.0f ), 0.0001f, TEST_LOCATION );
915   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 210.0f, 0.0f ), 0.0001f, TEST_LOCATION );
916
917   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
918   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 60.0f, 60.0f, 0.0f ), 0.0001f, TEST_LOCATION );
919   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 80.0f, 0.0f ), 0.0001f, TEST_LOCATION );
920   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
921
922   END_TEST;
923 }