Controls are LayoutGroups instead of LayoutItems
[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 #include <toolkit-event-thread-callback.h>
22
23 #include <dali-toolkit/dali-toolkit.h>
24 #include <dali-toolkit/devel-api/controls/control-devel.h>
25 #include <dali-toolkit/devel-api/layouting/absolute-layout.h>
26 #include <dali-toolkit/devel-api/layouting/linear-layout.h>
27 #include <dali-toolkit/devel-api/layouting/layout-item-impl.h>
28 #include <dali-toolkit/devel-api/layouting/layout-group-impl.h>
29 #include <dali/devel-api/actors/actor-devel.h>
30
31 #include <../custom-layout.h>
32
33 #include <layout-utils.h>
34
35 using namespace Dali;
36 using namespace Toolkit;
37
38 namespace
39 {
40
41 void TestLayoutItemOrder( std::vector< Control >& controls, LayoutGroup& layoutGroup )
42 {
43   for( auto&& iter : controls )
44   {
45     unsigned int siblingOrder = static_cast< unsigned int>( iter.GetProperty< int >( DevelActor::Property::SIBLING_ORDER ) );
46     DALI_TEST_EQUALS( layoutGroup.GetChildAt( siblingOrder ), DevelControl::GetLayout( iter ), TEST_LOCATION );
47   }
48 }
49
50 // Turns the given control into a Root layout control and adds it to the stage.
51 void SetupRootLayoutControl( Control& rootControl )
52 {
53   rootControl = Control::New();
54   auto absoluteLayout = AbsoluteLayout::New();
55   DevelControl::SetLayout( rootControl, absoluteLayout );
56   rootControl.SetName( "RootAbsoluteLayout" );
57   Stage stage = Stage::GetCurrent();
58   stage.Add( rootControl );
59 }
60
61 } // unnamed namespace
62
63 void utc_dali_toolkit_layouting_startup(void)
64 {
65   test_return_value = TET_UNDEF;
66 }
67
68 void utc_dali_toolkit_layouting_cleanup(void)
69 {
70   test_return_value = TET_PASS;
71 }
72
73 int UtcDaliLayouting_HboxLayout01(void)
74 {
75   ToolkitTestApplication application;
76   tet_infoline(" UtcDaliLayouting_HboxLayout01");
77
78   Stage stage = Stage::GetCurrent();
79   auto hbox = Control::New();
80   auto hboxLayout = LinearLayout::New();
81   hboxLayout.SetCellPadding( LayoutSize( 10, 0 ) );
82   DevelControl::SetLayout( hbox, hboxLayout );
83   hbox.SetName( "HBox");
84
85   std::vector< Control > controls;
86   controls.push_back( CreateLeafControl( 40, 40 ) );
87   controls.push_back( CreateLeafControl( 60, 40 ) );
88   controls.push_back( CreateLeafControl( 80, 40 ) );
89   controls.push_back( CreateLeafControl( 100, 40 ) );
90
91   for( auto&& iter : controls )
92   {
93     hbox.Add( iter );
94   }
95   hbox.SetParentOrigin( ParentOrigin::CENTER );
96   hbox.SetAnchorPoint( AnchorPoint::CENTER );
97   stage.Add( hbox );
98
99   // Ensure layouting happens
100   application.SendNotification();
101   application.Render();
102
103   // hbox centers elements vertically, it fills test harness stage, which is 480x800.
104   // hbox left justifies elements
105   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 380.0f, 0.0f ), 0.0001f, TEST_LOCATION );
106   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 50.0f, 380.0f, 0.0f ), 0.0001f, TEST_LOCATION );
107   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 120.0f, 380.0f, 0.0f ), 0.0001f, TEST_LOCATION );
108   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 210.0f, 380.0f, 0.0f ), 0.0001f, TEST_LOCATION );
109
110   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
111   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 60.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
112   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 80.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
113   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
114
115   // Change a layout
116   auto newHBoxLayout = LinearLayout::New();
117   newHBoxLayout.SetCellPadding( LayoutSize( 10, 0 ) );
118   DevelControl::SetLayout( hbox, newHBoxLayout );
119
120   application.SendNotification();
121   application.Render();
122
123   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 380.0f, 0.0f ), 0.0001f, TEST_LOCATION );
124   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 50.0f, 380.0f, 0.0f ), 0.0001f, TEST_LOCATION );
125   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 120.0f, 380.0f, 0.0f ), 0.0001f, TEST_LOCATION );
126   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 210.0f, 380.0f, 0.0f ), 0.0001f, TEST_LOCATION );
127
128   END_TEST;
129 }
130
131 int UtcDaliLayouting_HboxLayout02(void)
132 {
133   ToolkitTestApplication application;
134   tet_infoline(" UtcDaliLayouting_HboxLayout02 Test nested hboxes with default spec of WRAP_CONTENT");
135
136   Stage stage = Stage::GetCurrent();
137
138   auto hbox1 = Control::New();
139   auto hboxLayout1 = LinearLayout::New();
140   DevelControl::SetLayout( hbox1, hboxLayout1 );
141
142   auto hbox2 = Control::New();
143   auto hboxLayout2 = LinearLayout::New();
144   DevelControl::SetLayout( hbox2, hboxLayout2 );
145
146   hbox1.SetName( "HBox1");
147   hbox2.SetName( "HBox2");
148
149   std::vector< Control > controls;
150   controls.push_back( CreateLeafControl( 20, 40 ) );
151   controls.push_back( CreateLeafControl( 30, 50 ) );
152   controls.push_back( CreateLeafControl( 40, 60 ) );
153   controls.push_back( CreateLeafControl( 50, 70 ) );
154
155   controls.push_back( CreateLeafControl( 25, 40 ) );
156   controls.push_back( CreateLeafControl( 35, 50 ) );
157   controls.push_back( CreateLeafControl( 45, 60 ) );
158   controls.push_back( CreateLeafControl( 55, 70 ) );
159
160   int counter=0;
161   for( auto&& iter : controls )
162   {
163     if( counter < 4 )
164     {
165       hbox1.Add( iter );
166     }
167     else
168     {
169       hbox2.Add( iter );
170     }
171     ++counter;
172   }
173   hbox1.SetParentOrigin( ParentOrigin::CENTER );
174   hbox1.SetAnchorPoint( AnchorPoint::CENTER );
175   hbox2.SetParentOrigin( ParentOrigin::CENTER );
176   hbox2.SetAnchorPoint( AnchorPoint::CENTER );
177
178   auto hbox3 = Control::New();
179   auto hboxLayout3 = LinearLayout::New();
180   DevelControl::SetLayout( hbox3, hboxLayout3 );
181
182   hbox3.SetParentOrigin( ParentOrigin::CENTER );
183   hbox3.SetName( "HBox3");
184   hbox3.Add( hbox1 );
185   hbox3.Add( hbox2 );
186
187   stage.Add( hbox3 );
188
189   // Ensure layouting happens
190   application.SendNotification();
191   application.Render();
192
193
194   // hbox centers elements vertically, it fills test harness stage, which is 480x800.
195   // hbox left justifies elements
196   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3(  0.0f, 15.0f, 0.0f ), 0.0001f, TEST_LOCATION );
197   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 20.0f, 10.0f, 0.0f ), 0.0001f, TEST_LOCATION );
198   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 50.0f,  5.0f, 0.0f ), 0.0001f, TEST_LOCATION );
199   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 90.0f,  0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
200
201   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 20.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
202   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 30.0f, 50.0f, 0.0f ), 0.0001f, TEST_LOCATION );
203   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 40.0f, 60.0f, 0.0f ), 0.0001f, TEST_LOCATION );
204   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 50.0f, 70.0f, 0.0f ), 0.0001f, TEST_LOCATION );
205
206
207   DALI_TEST_EQUALS( controls[4].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3(  0.0f, 15.0f, 0.0f ), 0.0001f, TEST_LOCATION );
208   DALI_TEST_EQUALS( controls[5].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 25.0f, 10.0f, 0.0f ), 0.0001f, TEST_LOCATION );
209   DALI_TEST_EQUALS( controls[6].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 60.0f,  5.0f, 0.0f ), 0.0001f, TEST_LOCATION );
210   DALI_TEST_EQUALS( controls[7].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 105.0f,  0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
211
212   DALI_TEST_EQUALS( controls[4].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 25.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
213   DALI_TEST_EQUALS( controls[5].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 35.0f, 50.0f, 0.0f ), 0.0001f, TEST_LOCATION );
214   DALI_TEST_EQUALS( controls[6].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 45.0f, 60.0f, 0.0f ), 0.0001f, TEST_LOCATION );
215   DALI_TEST_EQUALS( controls[7].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 55.0f, 70.0f, 0.0f ), 0.0001f, TEST_LOCATION );
216
217   // Test hbox1 and 2 are sized to wrap their content
218   DALI_TEST_EQUALS( hbox1.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 140.0f, 70.0f, 0.0f ), 0.0001f, TEST_LOCATION );
219   DALI_TEST_EQUALS( hbox2.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 160.0f, 70.0f, 0.0f ), 0.0001f, TEST_LOCATION );
220   DALI_TEST_EQUALS( hbox1.GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 365.0f, 0.0f ), 0.0001f, TEST_LOCATION );
221   DALI_TEST_EQUALS( hbox2.GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 140.0f, 365.0f, 0.0f ), 0.0001f, TEST_LOCATION );
222
223   // Test hbox3 matches parent (root layer)
224   DALI_TEST_EQUALS( hbox3.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 480.0f, 800.0f, 0.0f ), 0.0001f, TEST_LOCATION );
225   DALI_TEST_EQUALS( hbox3.GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
226
227   END_TEST;
228 }
229
230
231 int UtcDaliLayouting_HboxLayout03(void)
232 {
233   ToolkitTestApplication application;
234   tet_infoline(" UtcDaliLayouting_HboxLayout03 Test nested hboxes with MATCH_PARENT");
235
236   Stage stage = Stage::GetCurrent();
237
238   auto hbox1 = Control::New();
239   auto hboxLayout1 = LinearLayout::New();
240   DevelControl::SetLayout( hbox1, hboxLayout1 );
241
242   auto hbox2 = Control::New();
243   auto hboxLayout2 = LinearLayout::New();
244   DevelControl::SetLayout( hbox2, hboxLayout2 );
245
246   hbox1.SetName( "HBox1");
247   hbox2.SetName( "HBox2");
248   hbox1.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
249   hbox1.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
250   hbox2.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
251   hbox2.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
252
253   std::vector< Control > controls;
254   controls.push_back( CreateLeafControl( 20, 40 ) );
255   controls.push_back( CreateLeafControl( 30, 50 ) );
256   controls.push_back( CreateLeafControl( 40, 60 ) );
257   controls.push_back( CreateLeafControl( 50, 70 ) );
258
259   controls.push_back( CreateLeafControl( 25, 40 ) );
260   controls.push_back( CreateLeafControl( 35, 50 ) );
261   controls.push_back( CreateLeafControl( 45, 60 ) );
262   controls.push_back( CreateLeafControl( 55, 70 ) );
263
264   int counter=0;
265   for( auto&& iter : controls )
266   {
267     if( counter < 4 )
268     {
269       hbox1.Add( iter );
270     }
271     else
272     {
273       hbox2.Add( iter );
274     }
275     ++counter;
276   }
277   hbox1.SetParentOrigin( ParentOrigin::CENTER );
278   hbox1.SetAnchorPoint( AnchorPoint::CENTER );
279   hbox2.SetParentOrigin( ParentOrigin::CENTER );
280   hbox2.SetAnchorPoint( AnchorPoint::CENTER );
281
282   auto hbox3 = Control::New();
283   auto hboxLayout3 = LinearLayout::New();
284   DevelControl::SetLayout( hbox3, hboxLayout3);
285
286   hbox3.SetParentOrigin( ParentOrigin::CENTER );
287   hbox3.SetName( "HBox3");
288   hbox3.Add( hbox1 );
289   hbox3.Add( hbox2 );
290
291   stage.Add( hbox3 );
292
293   //std::ostringstream oss;
294   //DumpControlHierarchy( oss, Stage::GetCurrent().GetRootLayer() );
295   //printf("Control hierarchy: \n%s\n", oss.str().c_str() );
296
297   // Ensure layouting happens
298   application.SendNotification();
299   application.Render();
300
301
302   // hbox centers elements vertically, it fills test harness stage, which is 480x800.
303   // hbox left justifies elements
304   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 380.0f, 0.0f ), 0.0001f, TEST_LOCATION );
305   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 20.0f,375.0f, 0.0f ), 0.0001f, TEST_LOCATION );
306   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 50.0f,370.0f, 0.0f ), 0.0001f, TEST_LOCATION );
307   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 90.0f,365.0f, 0.0f ), 0.0001f, TEST_LOCATION );
308
309   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 20.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
310   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 30.0f, 50.0f, 0.0f ), 0.0001f, TEST_LOCATION );
311   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 40.0f, 60.0f, 0.0f ), 0.0001f, TEST_LOCATION );
312   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 50.0f, 70.0f, 0.0f ), 0.0001f, TEST_LOCATION );
313
314   DALI_TEST_EQUALS( controls[4].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3(  0.0f, 380.0f, 0.0f ), 0.0001f, TEST_LOCATION );
315   DALI_TEST_EQUALS( controls[5].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 25.0f, 375.0f, 0.0f ), 0.0001f, TEST_LOCATION );
316   DALI_TEST_EQUALS( controls[6].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 60.0f, 370.0f, 0.0f ), 0.0001f, TEST_LOCATION );
317   DALI_TEST_EQUALS( controls[7].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 105.0f,365.0f, 0.0f ), 0.0001f, TEST_LOCATION );
318
319   DALI_TEST_EQUALS( controls[4].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 25.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
320   DALI_TEST_EQUALS( controls[5].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 35.0f, 50.0f, 0.0f ), 0.0001f, TEST_LOCATION );
321   DALI_TEST_EQUALS( controls[6].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 45.0f, 60.0f, 0.0f ), 0.0001f, TEST_LOCATION );
322   DALI_TEST_EQUALS( controls[7].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 55.0f, 70.0f, 0.0f ), 0.0001f, TEST_LOCATION );
323
324   DALI_TEST_EQUALS( hbox1.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 480.0f, 800.0f, 0.0f ), 0.0001f, TEST_LOCATION );
325   DALI_TEST_EQUALS( hbox2.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 480.0f, 800.0f, 0.0f ), 0.0001f, TEST_LOCATION );
326   DALI_TEST_EQUALS( hbox1.GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
327   DALI_TEST_EQUALS( hbox2.GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 480.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
328
329   // Test hbox3 matches parent (root layer)
330   DALI_TEST_EQUALS( hbox3.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 480.0f, 800.0f, 0.0f ), 0.0001f, TEST_LOCATION );
331   DALI_TEST_EQUALS( hbox3.GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
332
333   END_TEST;
334 }
335
336 int UtcDaliLayouting_HboxLayout04(void)
337 {
338   ToolkitTestApplication application;
339   tet_infoline(" UtcDaliLayouting_HboxLayout04 Test nested hboxes with explicit WRAP_CONTENT");
340
341   Stage stage = Stage::GetCurrent();
342
343   auto hbox1 = Control::New();
344   auto hboxLayout1 = LinearLayout::New();
345   DevelControl::SetLayout( hbox1, hboxLayout1 );
346
347   auto hbox2 = Control::New();
348   auto hboxLayout2 = LinearLayout::New();
349   DevelControl::SetLayout( hbox2, hboxLayout2 );
350
351   hbox1.SetName( "HBox1"); // Default spec is to wrap content
352   hbox2.SetName( "HBox2");
353   hbox1.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::WRAP_CONTENT );
354   hbox1.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::WRAP_CONTENT );
355   hbox2.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::WRAP_CONTENT );
356   hbox2.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::WRAP_CONTENT );
357
358   std::vector< Control > controls;
359   controls.push_back( CreateLeafControl( 80, 40 ) );
360   controls.push_back( CreateLeafControl( 80, 50 ) );
361   controls.push_back( CreateLeafControl( 80, 60 ) );
362   controls.push_back( CreateLeafControl( 80, 70 ) );
363
364   controls.push_back( CreateLeafControl( 80, 40 ) );
365   controls.push_back( CreateLeafControl( 80, 50 ) );
366   controls.push_back( CreateLeafControl( 80, 60 ) );
367   controls.push_back( CreateLeafControl( 80, 70 ) );
368
369   int counter=0;
370   for( auto&& iter : controls )
371   {
372     if( counter < 4 )
373     {
374       hbox1.Add( iter );
375     }
376     else
377     {
378       hbox2.Add( iter );
379     }
380     ++counter;
381   }
382
383   controls[6].SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
384   auto hbox3 = Control::New();
385   auto hboxLayout3 = LinearLayout::New();
386   DevelControl::SetLayout( hbox3, hboxLayout3 );
387
388   hbox3.SetParentOrigin( ParentOrigin::CENTER );
389   hbox3.SetName( "HBox3");
390   hbox3.Add( hbox1 );
391   hbox3.Add( hbox2 );
392   stage.Add( hbox3 );
393
394   //std::ostringstream oss;
395   //DumpControlHierarchy( oss, Stage::GetCurrent().GetRootLayer() );
396   //printf("Control hierarchy: \n%s\n", oss.str().c_str() );
397
398   // Ensure layouting happens
399   application.SendNotification();
400   application.Render();
401
402
403   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 15.0f, 0.0f ), 0.0001f, TEST_LOCATION );
404   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 80.0f,10.0f, 0.0f ), 0.0001f, TEST_LOCATION );
405   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 160.0f, 5.0f, 0.0f ), 0.0001f, TEST_LOCATION );
406   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 240.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
407
408   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 80.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
409   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 80.0f, 50.0f, 0.0f ), 0.0001f, TEST_LOCATION );
410   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 80.0f, 60.0f, 0.0f ), 0.0001f, TEST_LOCATION );
411   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 80.0f, 70.0f, 0.0f ), 0.0001f, TEST_LOCATION );
412
413   DALI_TEST_EQUALS( controls[4].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3(  0.0f, 15.0f, 0.0f ), 0.0001f, TEST_LOCATION );
414   DALI_TEST_EQUALS( controls[5].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 80.0f, 10.0f, 0.0f ), 0.0001f, TEST_LOCATION );
415   DALI_TEST_EQUALS( controls[6].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 160.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
416   DALI_TEST_EQUALS( controls[7].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 240.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
417
418   DALI_TEST_EQUALS( controls[4].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 80.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
419   DALI_TEST_EQUALS( controls[5].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 80.0f, 50.0f, 0.0f ), 0.0001f, TEST_LOCATION );
420   DALI_TEST_EQUALS( controls[6].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 80.0f, 70.0f, 0.0f ), 0.0001f, TEST_LOCATION );
421   DALI_TEST_EQUALS( controls[7].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 80.0f, 70.0f, 0.0f ), 0.0001f, TEST_LOCATION );
422
423   DALI_TEST_EQUALS( hbox1.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 320.0f, 70.0f, 0.0f ), 0.0001f, TEST_LOCATION );
424   DALI_TEST_EQUALS( hbox2.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 320.0f, 70.0f, 0.0f ), 0.0001f, TEST_LOCATION );
425   DALI_TEST_EQUALS( hbox1.GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 365.0f, 0.0f ), 0.0001f, TEST_LOCATION );
426   DALI_TEST_EQUALS( hbox2.GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 320.0f, 365.0f, 0.0f ), 0.0001f, TEST_LOCATION );
427
428
429   // Test hbox3 matches parent (root layer)
430   DALI_TEST_EQUALS( hbox3.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 480.0f, 800.0f, 0.0f ), 0.0001f, TEST_LOCATION );
431   DALI_TEST_EQUALS( hbox3.GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
432
433   END_TEST;
434 }
435
436 int UtcDaliLayouting_HboxLayout05(void)
437 {
438   ToolkitTestApplication application;
439   tet_infoline(" UtcDaliLayouting_HboxLayout05 - Set children size explicitly via width & height specification");
440
441   Stage stage = Stage::GetCurrent();
442   auto hbox = Control::New();
443   auto hboxLayout = LinearLayout::New();
444   hboxLayout.SetCellPadding( LayoutSize( 10, 0 ) );
445   DevelControl::SetLayout( hbox, hboxLayout );
446   hbox.SetName( "HBox");
447
448   std::vector< Control > controls;
449   controls.push_back( CreateLeafControl( 40, 40 ) );
450   controls.push_back( CreateLeafControl( 60, 40 ) );
451   controls.push_back( CreateLeafControl( 80, 40 ) );
452   controls.push_back( CreateLeafControl( 100, 40 ) );
453
454   for( auto&& iter : controls )
455   {
456     hbox.Add( iter );
457     iter.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, 100 );
458     iter.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, 50 );
459   }
460
461   hbox.SetParentOrigin( ParentOrigin::CENTER );
462   hbox.SetAnchorPoint( AnchorPoint::CENTER );
463   stage.Add( hbox );
464
465   // Ensure layouting happens
466   application.SendNotification();
467   application.Render();
468
469   // hbox centers elements vertically, it fills test harness stage, which is 480x800.
470   // hbox left justifies elements
471   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 375.0f, 0.0f ), 0.0001f, TEST_LOCATION );
472   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 110.0f, 375.0f, 0.0f ), 0.0001f, TEST_LOCATION );
473   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 220.0f, 375.0f, 0.0f ), 0.0001f, TEST_LOCATION );
474   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 330.0f, 375.0f, 0.0f ), 0.0001f, TEST_LOCATION );
475
476   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 50.0f, 0.0f ), 0.0001f, TEST_LOCATION );
477   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 50.0f, 0.0f ), 0.0001f, TEST_LOCATION );
478   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 50.0f, 0.0f ), 0.0001f, TEST_LOCATION );
479   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 50.0f, 0.0f ), 0.0001f, TEST_LOCATION );
480
481   END_TEST;
482 }
483
484 int UtcDaliLayouting_HboxLayout06(void)
485 {
486   ToolkitTestApplication application;
487   tet_infoline(" UtcDaliLayouting_HboxLayout06 - Test nested layouts");
488
489   Stage stage = Stage::GetCurrent();
490
491   auto rootControl = Control::New();
492   auto absoluteLayout = AbsoluteLayout::New();
493   DevelControl::SetLayout( rootControl, absoluteLayout );
494   rootControl.SetName( "AbsoluteLayout" );
495   stage.Add( rootControl );
496
497   auto hbox = Control::New();
498   auto hboxLayout = LinearLayout::New();
499   hboxLayout.SetOrientation( LinearLayout::Orientation::HORIZONTAL );
500   DevelControl::SetLayout( hbox, hboxLayout );
501   hbox.SetName( "HBox" );
502
503   std::vector< Control > controls;
504   controls.push_back( CreateLeafControl( 40, 40 ) );
505   controls.push_back( CreateLeafControl( 60, 40 ) );
506
507   for( auto&& iter : controls )
508   {
509     hbox.Add( iter );
510   }
511   hbox.SetParentOrigin( ParentOrigin::CENTER );
512   hbox.SetAnchorPoint( AnchorPoint::CENTER );
513   rootControl.Add( hbox );
514
515   // Ensure layouting happens
516   application.SendNotification();
517   application.Render();
518
519   // hbox centers elements vertically, it fills test harness stage, which is 480x800.
520   // hbox left justifies elements
521   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
522   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 40.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
523
524   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
525   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 60.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
526
527   DALI_TEST_EQUALS( hbox.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
528
529   // Change a layout
530   auto newHBoxLayout = LinearLayout::New();
531   newHBoxLayout.SetOrientation( LinearLayout::Orientation::HORIZONTAL );
532   DevelControl::SetLayout( hbox, newHBoxLayout );
533
534   hbox.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::WRAP_CONTENT );
535   hbox.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::WRAP_CONTENT );
536
537   application.SendNotification();
538   application.Render();
539
540   DALI_TEST_EQUALS( hbox.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
541
542   // Change size specification
543   hbox.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
544   hbox.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
545
546   application.SendNotification();
547   application.Render();
548
549   DALI_TEST_EQUALS( hbox.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 480.0f, 800.0f, 0.0f ), 0.0001f, TEST_LOCATION );
550
551   // Use WRAP_CONTENT again
552   hbox.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::WRAP_CONTENT );
553   hbox.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::WRAP_CONTENT );
554
555   application.SendNotification();
556   application.Render();
557
558   DALI_TEST_EQUALS( hbox.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
559
560   END_TEST;
561 }
562
563 int UtcDaliLayouting_HboxLayout07(void)
564 {
565   ToolkitTestApplication application;
566   tet_infoline(" UtcDaliLayouting_HboxLayout07 - Set LTR/RTL direction");
567
568   Stage stage = Stage::GetCurrent();
569   auto hbox = Control::New();
570   auto hboxLayout = LinearLayout::New();
571   hboxLayout.SetCellPadding( LayoutSize( 10, 0 ) );
572   DevelControl::SetLayout( hbox, hboxLayout );
573   hbox.SetName( "HBox");
574
575   std::vector< Control > controls;
576   controls.push_back( CreateLeafControl( 40, 40 ) );
577   controls.push_back( CreateLeafControl( 60, 40 ) );
578   controls.push_back( CreateLeafControl( 80, 40 ) );
579   controls.push_back( CreateLeafControl( 100, 40 ) );
580
581   for( auto&& iter : controls )
582   {
583     hbox.Add( iter );
584   }
585   hbox.SetParentOrigin( ParentOrigin::CENTER );
586   hbox.SetAnchorPoint( AnchorPoint::CENTER );
587   stage.Add( hbox );
588
589   hbox.SetProperty( Actor::Property::LAYOUT_DIRECTION, LayoutDirection::LEFT_TO_RIGHT );
590
591   // Ensure layouting happens
592   application.SendNotification();
593   application.Render();
594
595   // hbox centers elements vertically, it fills test harness stage, which is 480x800 from left to right.
596   // hbox left justifies elements
597   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 380.0f, 0.0f ), 0.0001f, TEST_LOCATION );
598   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 50.0f, 380.0f, 0.0f ), 0.0001f, TEST_LOCATION );
599   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 120.0f, 380.0f, 0.0f ), 0.0001f, TEST_LOCATION );
600   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 210.0f, 380.0f, 0.0f ), 0.0001f, TEST_LOCATION );
601
602   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
603   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 60.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
604   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 80.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
605   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
606
607   hbox.SetProperty( Actor::Property::LAYOUT_DIRECTION, LayoutDirection::RIGHT_TO_LEFT );
608
609   // Ensure layouting happens
610   application.SendNotification();
611   application.Render();
612
613   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 470.0f, 380.0f, 0.0f ), 0.0001f, TEST_LOCATION );
614   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 400.0f, 380.0f, 0.0f ), 0.0001f, TEST_LOCATION );
615   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 310.0f, 380.0f, 0.0f ), 0.0001f, TEST_LOCATION );
616   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 200.0f, 380.0f, 0.0f ), 0.0001f, TEST_LOCATION );
617
618   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
619   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 60.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
620   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 80.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
621   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
622
623   END_TEST;
624 }
625
626 int UtcDaliLayouting_HboxLayout08(void)
627 {
628   ToolkitTestApplication application;
629   tet_infoline(" UtcDaliLayouting_HboxLayout08 - Test layout animation");
630
631   Stage stage = Stage::GetCurrent();
632
633   auto rootControl = Control::New();
634   auto absoluteLayout = AbsoluteLayout::New();
635   absoluteLayout.SetAnimateLayout( true );
636   DevelControl::SetLayout( rootControl, absoluteLayout );
637   rootControl.SetName( "AbsoluteLayout" );
638   stage.Add( rootControl );
639
640   Control control1 = CreateLeafControl( 40, 40 );
641   rootControl.Add( control1 );
642
643   auto hbox = Control::New();
644   auto hboxLayout = LinearLayout::New();
645   hboxLayout.SetOrientation( LinearLayout::Orientation::HORIZONTAL );
646   DevelControl::SetLayout( hbox, hboxLayout );
647   hbox.SetName( "HBox" );
648
649   Control control2 = CreateLeafControl( 40, 40 );
650   hbox.Add( control2 );
651
652   hbox.SetParentOrigin( ParentOrigin::CENTER );
653   hbox.SetAnchorPoint( AnchorPoint::CENTER );
654   rootControl.Add( hbox );
655
656   DALI_TEST_EQUALS( absoluteLayout.IsLayoutAnimated(), true, TEST_LOCATION );
657   DALI_TEST_EQUALS( DevelControl::GetLayout( control1 ).IsLayoutAnimated(), true, TEST_LOCATION );
658   DALI_TEST_EQUALS( hboxLayout.IsLayoutAnimated(), false, TEST_LOCATION );
659   DALI_TEST_EQUALS( DevelControl::GetLayout( control2 ).IsLayoutAnimated(), false, TEST_LOCATION );
660
661   tet_infoline(" Set hBoxLayout to animate");
662   hboxLayout.SetAnimateLayout( true );
663   tet_infoline(" Set absoluteLayout not to animate");
664   absoluteLayout.SetAnimateLayout( false );
665
666   DALI_TEST_EQUALS( absoluteLayout.IsLayoutAnimated(), false, TEST_LOCATION );
667   DALI_TEST_EQUALS( DevelControl::GetLayout( control1 ).IsLayoutAnimated(), false, TEST_LOCATION );
668   DALI_TEST_EQUALS( hboxLayout.IsLayoutAnimated(), true, TEST_LOCATION );
669   DALI_TEST_EQUALS( DevelControl::GetLayout( control2 ).IsLayoutAnimated(), true, TEST_LOCATION );
670
671   END_TEST;
672 }
673
674 namespace
675 {
676 const char* TEST_IMAGE_FILE_NAME =  TEST_RESOURCE_DIR  "/broken.png";
677 }
678
679 int UtcDaliLayouting_HboxLayout_ImageView(void)
680 {
681   ToolkitTestApplication application;
682   tet_infoline(" UtcDaliLayouting_HboxLayout - Use image view for leaf");
683
684   Stage stage = Stage::GetCurrent();
685   auto hbox = Control::New();
686   auto hboxLayout = LinearLayout::New();
687   DevelControl::SetLayout( hbox, hboxLayout );
688   hbox.SetName( "HBox" );
689
690   std::string url = CreateImageURL( Vector4( 0, 255, 0, 255), ImageDimensions( 100, 100 ) );
691   ImageView imageView = CreateImageView( url, ImageDimensions() );
692
693   hbox.SetParentOrigin( ParentOrigin::CENTER );
694   hbox.SetAnchorPoint( AnchorPoint::CENTER );
695   hbox.Add( imageView );
696   stage.Add( hbox );
697
698   // Ensure layouting happens
699   application.SendNotification();
700   application.Render();
701
702   DALI_TEST_EQUALS( imageView.GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 350.0f, 0.0f ), 0.0001f, TEST_LOCATION );
703   DALI_TEST_EQUALS( imageView.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
704
705   url = CreateImageURL( Vector4( 0, 255, 0, 255), ImageDimensions( 200, 200 ) );
706   imageView.SetImage( url );
707
708   // Ensure layouting happenss
709   application.SendNotification();
710   application.Render();
711
712   DALI_TEST_EQUALS( imageView.GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 300.0f, 0.0f ), 0.0001f, TEST_LOCATION );
713   DALI_TEST_EQUALS( imageView.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 200.0f, 200.0f, 0.0f ), 0.0001f, TEST_LOCATION );
714
715   imageView.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::WRAP_CONTENT );
716   imageView.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
717
718   // Ensure layouting happenss
719   application.SendNotification();
720   application.Render();
721
722   DALI_TEST_EQUALS( imageView.GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
723   DALI_TEST_EQUALS( imageView.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 200.0f, 800.0f, 0.0f ), 0.0001f, TEST_LOCATION );
724
725   imageView.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
726   imageView.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::WRAP_CONTENT );
727
728   // Ensure layouting happenss
729   application.SendNotification();
730   application.Render();
731
732   DALI_TEST_EQUALS( imageView.GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 300.0f, 0.0f ), 0.0001f, TEST_LOCATION );
733   DALI_TEST_EQUALS( imageView.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 480.0f, 200.0f, 0.0f ), 0.0001f, TEST_LOCATION );
734
735   imageView.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::WRAP_CONTENT );
736   imageView.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::WRAP_CONTENT );
737
738   Image image = FrameBufferImage::New( 50, 50, Pixel::RGBA8888 );
739   imageView.SetImage( image );
740
741   // Ensure layouting happenss
742   application.SendNotification();
743   application.Render();
744
745   DALI_TEST_EQUALS( imageView.GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 375.0f, 0.0f ), 0.0001f, TEST_LOCATION );
746   DALI_TEST_EQUALS( imageView.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 50.0f, 50.0f, 0.0f ), 0.0001f, TEST_LOCATION );
747
748   Property::Map imagePropertyMap;
749   imagePropertyMap[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::IMAGE;
750   imagePropertyMap[ ImageVisual::Property::URL ] = TEST_IMAGE_FILE_NAME;
751   imagePropertyMap[ ImageVisual::Property::DESIRED_WIDTH ] = 150;
752   imagePropertyMap[ ImageVisual::Property::DESIRED_HEIGHT ] = 150;
753   imageView.SetProperty( Toolkit::ImageView::Property::IMAGE, imagePropertyMap );
754
755   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
756   // Ensure layouting happenss
757   application.SendNotification();
758   application.Render();
759
760   DALI_TEST_EQUALS( imageView.GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 325.0f, 0.0f ), 0.0001f, TEST_LOCATION );
761   DALI_TEST_EQUALS( imageView.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 150.0f, 150.0f, 0.0f ), 0.0001f, TEST_LOCATION );
762
763   END_TEST;
764 }
765
766 int UtcDaliLayouting_HboxLayout_TextLabel(void)
767 {
768   ToolkitTestApplication application;
769   tet_infoline(" UtcDaliLayouting_HboxLayout - Use text label for leaf");
770
771   Stage stage = Stage::GetCurrent();
772
773   auto hbox = Control::New();
774   auto hboxLayout = LinearLayout::New();
775   DevelControl::SetLayout( hbox, hboxLayout );
776   hbox.SetName( "HBox" );
777   hbox.SetParentOrigin( ParentOrigin::CENTER );
778   hbox.SetAnchorPoint( AnchorPoint::CENTER );
779
780   std::vector< Control > controls;
781   TextLabel textLabel = CreateTextLabel( "W" );
782   controls.push_back( textLabel );
783   hbox.Add( textLabel );
784   stage.Add( hbox );
785
786   // Ensure layouting happens
787   application.SendNotification();
788   application.Render();
789
790   DALI_TEST_EQUALS( textLabel.GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 368.0f, 0.0f ), 0.0001f, TEST_LOCATION );
791   DALI_TEST_EQUALS( textLabel.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 54.0f, 64.0f, 0.0f ), 0.0001f, TEST_LOCATION );
792
793   textLabel.SetProperty( TextLabel::Property::TEXT, "WWWW" );
794
795   // Ensure layouting happens
796   application.SendNotification();
797   application.Render();
798
799   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 368.0f, 0.0f ), 0.0001f, TEST_LOCATION );
800   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 216.0f, 64.0f, 0.0f ), 0.0001f, TEST_LOCATION );
801
802   textLabel.SetProperty( TextLabel::Property::POINT_SIZE, 10.0f );
803
804   // Ensure layouting happens
805   application.SendNotification();
806   application.Render();
807
808   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 382.0f, 0.0f ), 0.0001f, TEST_LOCATION );
809   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 120.0f, 36.0f, 0.0f ), 0.0001f, TEST_LOCATION );
810
811   controls[0].SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::WRAP_CONTENT );
812   controls[0].SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
813
814   // Ensure layouting happens
815   application.SendNotification();
816   application.Render();
817
818   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
819   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 120.0f, 800.0f, 0.0f ), 0.0001f, TEST_LOCATION );
820
821   controls[0].SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
822   controls[0].SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::WRAP_CONTENT );
823
824   // Ensure layouting happens
825   application.SendNotification();
826   application.Render();
827
828   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 382.0f, 0.0f ), 0.0001f, TEST_LOCATION );
829   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 480.0f, 36.0f, 0.0f ), 0.0001f, TEST_LOCATION );
830
831   END_TEST;
832 }
833
834 // Padding tests
835
836 int UtcDaliLayouting_HboxLayout_Padding01(void)
837 {
838   ToolkitTestApplication application;
839   tet_infoline("UtcDaliLayouting_HboxLayout_Padding01 - Adding Padding to a single child");
840
841   Stage stage = Stage::GetCurrent();
842   auto hbox = Control::New();
843   auto hboxLayout = LinearLayout::New();
844   DevelControl::SetLayout( hbox, hboxLayout );
845   hbox.SetName( "HBox");
846
847   std::vector< Control > controls;
848   controls.push_back( CreateLeafControl( 40, 40 ) );
849   controls.push_back( CreateLeafControl( 60, 40 ) );
850   controls.push_back( CreateLeafControl( 80, 40 ) );
851   controls.push_back( CreateLeafControl( 100, 40 ) );
852
853   const Extents CONTROL_PADDING = Extents(5, 10, 20, 2 );
854   tet_printf( "\nAdding Padding to control at index %u \n", 1 );
855   controls[1].SetProperty(Toolkit::Control::Property::PADDING, CONTROL_PADDING );
856
857   for( auto&& iter : controls )
858   {
859     hbox.Add( iter );
860   }
861   hbox.SetParentOrigin( ParentOrigin::CENTER );
862   hbox.SetAnchorPoint( AnchorPoint::CENTER );
863   stage.Add( hbox );
864
865   // Ensure layouting happens
866   application.SendNotification();
867   application.Render();
868
869   // hbox centers elements vertically, it fills test harness stage, which is 480x800.
870   // hbox left justifies elements
871   tet_infoline("Test Child Actor Position");
872   float xPositionOfControlBeingTested = 0.0f;
873   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( xPositionOfControlBeingTested,
874                                                                                             380.0f,
875                                                                                             0.0f ), 0.0001f, TEST_LOCATION );
876   xPositionOfControlBeingTested += 40.0f;
877
878   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( xPositionOfControlBeingTested,
879                                                                                             380.0f - ( ( CONTROL_PADDING.top + CONTROL_PADDING.bottom) * 0.5f ),                                                                                            0.0f ),
880                                                                                             0.0001f, TEST_LOCATION );
881
882   xPositionOfControlBeingTested += 60.0f + CONTROL_PADDING.start + CONTROL_PADDING.end;
883   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( xPositionOfControlBeingTested, 380.0f, 0.0f ), 0.0001f, TEST_LOCATION );
884
885   xPositionOfControlBeingTested += 80.0f;
886   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( xPositionOfControlBeingTested,380.0f, 0.0f ), 0.0001f, TEST_LOCATION );
887
888   tet_infoline("Test Child Actor Size");
889   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
890
891   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 60.0f + CONTROL_PADDING.start + CONTROL_PADDING.end,
892                                                                                         40.0f + CONTROL_PADDING.top + CONTROL_PADDING.bottom , 0.0f ),
893                                                                                         0.0001f, TEST_LOCATION );
894
895   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 80.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
896   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
897
898   END_TEST;
899 }
900
901 int UtcDaliLayouting_HboxLayout_Padding02(void)
902 {
903   ToolkitTestApplication application;
904   tet_infoline("UtcDaliLayouting_HboxLayout_Padding02 - Adding Padding to a all children");
905
906   Stage stage = Stage::GetCurrent();
907   auto hbox = Control::New();
908   auto hboxLayout = LinearLayout::New();
909   DevelControl::SetLayout( hbox, hboxLayout );
910   hbox.SetName( "HBox");
911
912   std::vector< Control > controls;
913   controls.push_back( CreateLeafControl( 40, 40 ) );
914   controls.push_back( CreateLeafControl( 60, 40 ) );
915   controls.push_back( CreateLeafControl( 80, 40 ) );
916   controls.push_back( CreateLeafControl( 100, 40 ) );
917
918   const Extents CONTROL_PADDING = Extents(5, 10, 20, 2 );
919
920   for( auto&& iter : controls )
921   {
922     iter.SetProperty(Toolkit::Control::Property::PADDING, CONTROL_PADDING );
923     hbox.Add( iter );
924   }
925   hbox.SetParentOrigin( ParentOrigin::CENTER );
926   hbox.SetAnchorPoint( AnchorPoint::CENTER );
927   stage.Add( hbox );
928
929   // Ensure layouting happens
930   application.SendNotification();
931   application.Render();
932
933   // hbox centers elements vertically, it fills test harness stage, which is 480x800.
934   // hbox left justifies elements
935   tet_infoline("Test Child Actor Position");
936   float xPositionOfControlBeingTested = 0.0f;
937   float yPositionOfControlBeingTested = ( 800.0f * 0.5) - ( 0.5 * ( 40.0f + CONTROL_PADDING.top + CONTROL_PADDING.bottom ) );
938
939   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( xPositionOfControlBeingTested,
940                                                                                             yPositionOfControlBeingTested,
941                                                                                             0.0f ), 0.0001f, TEST_LOCATION );
942   xPositionOfControlBeingTested += 40.0f + CONTROL_PADDING.start + CONTROL_PADDING.end;
943
944   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( xPositionOfControlBeingTested,
945                                                                                             yPositionOfControlBeingTested,
946                                                                                             0.0f ),
947                                                                                             0.0001f, TEST_LOCATION );
948
949   xPositionOfControlBeingTested += 60.0f + CONTROL_PADDING.start + CONTROL_PADDING.end;
950   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( xPositionOfControlBeingTested,
951                                                                                             yPositionOfControlBeingTested,
952                                                                                             0.0f ), 0.0001f, TEST_LOCATION );
953
954   xPositionOfControlBeingTested += 80.0f + CONTROL_PADDING.start + CONTROL_PADDING.end;
955   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( xPositionOfControlBeingTested,
956                                                                                             yPositionOfControlBeingTested,
957                                                                                             0.0f ), 0.0001f, TEST_LOCATION );
958
959   tet_infoline("Test Child Actor Size");
960   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 40.0f + CONTROL_PADDING.start + CONTROL_PADDING.end,
961                                                                                         40.0f + CONTROL_PADDING.top + CONTROL_PADDING.bottom,
962                                                                                         0.0f ), 0.0001f, TEST_LOCATION );
963
964   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 60.0f + CONTROL_PADDING.start + CONTROL_PADDING.end,
965                                                                                         40.0f + CONTROL_PADDING.top + CONTROL_PADDING.bottom,
966                                                                                         0.0f ), 0.0001f, TEST_LOCATION );
967
968   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 80.0f + CONTROL_PADDING.start + CONTROL_PADDING.end ,
969                                                                                         40.0f + CONTROL_PADDING.top + CONTROL_PADDING.bottom,
970                                                                                         0.0f ), 0.0001f, TEST_LOCATION );
971
972   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f + CONTROL_PADDING.start + CONTROL_PADDING.end,
973                                                                                         40.0f + CONTROL_PADDING.top + CONTROL_PADDING.bottom,
974                                                                                         0.0f ), 0.0001f, TEST_LOCATION );
975
976   END_TEST;
977 }
978
979
980 int UtcDaliLayouting_HboxLayout_Padding03(void)
981 {
982   ToolkitTestApplication application;
983   tet_infoline("UtcDaliLayouting_HboxLayout_Padding03 - Changing padding on a single child");
984
985   Stage stage = Stage::GetCurrent();
986   auto hbox = Control::New();
987   auto hboxLayout = LinearLayout::New();
988   DevelControl::SetLayout( hbox, hboxLayout );
989   hbox.SetName( "HBox");
990
991   std::vector< Control > controls;
992   controls.push_back( CreateLeafControl( 40, 40 ) );
993   controls.push_back( CreateLeafControl( 40, 40 ) );
994   controls.push_back( CreateLeafControl( 40, 40 ) );
995
996   const Extents CONTROL_PADDING = Extents(5, 10, 20, 2 );
997   tet_printf( "\nAdding Padding to control at index 1 \n" );
998   controls[1].SetProperty(Toolkit::Control::Property::PADDING, CONTROL_PADDING );
999
1000   for( auto&& iter : controls )
1001   {
1002     hbox.Add( iter );
1003   }
1004   hbox.SetParentOrigin( ParentOrigin::CENTER );
1005   hbox.SetAnchorPoint( AnchorPoint::CENTER );
1006   stage.Add( hbox );
1007
1008   // Ensure layouting happens
1009   application.SendNotification();
1010   application.Render();
1011
1012   // hbox centers elements vertically, it fills test harness stage, which is 480x800.
1013   // hbox left justifies elements
1014   tet_infoline("Test Child Actor Position");
1015   float xPositionOfControlBeingTested = 0.0f;
1016   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( xPositionOfControlBeingTested,
1017                                                                                             380.0f,
1018                                                                                             0.0f ), 0.0001f, TEST_LOCATION );
1019   xPositionOfControlBeingTested += 40.0f;
1020
1021   DALI_TEST_EQUALS( controls[ 1 ].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( xPositionOfControlBeingTested,
1022                                                                                             380.0f - ( ( CONTROL_PADDING.top + CONTROL_PADDING.bottom) * 0.5f ),                                                                                            0.0f ),
1023                                                                                             0.0001f, TEST_LOCATION );
1024
1025   xPositionOfControlBeingTested += 40.0f + CONTROL_PADDING.start + CONTROL_PADDING.end;
1026   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( xPositionOfControlBeingTested, 380.0f, 0.0f ), 0.0001f, TEST_LOCATION );
1027
1028   const Extents NEW_CONTROL_PADDING = Extents(10, 10, 20, 2 );
1029   tet_printf( "\nChanging Padding to control at index 1 \n" );
1030   controls[1].SetProperty(Toolkit::Control::Property::PADDING, NEW_CONTROL_PADDING );
1031
1032   // Ensure layouting happens
1033   application.SendNotification();
1034   application.Render();
1035
1036   xPositionOfControlBeingTested = 0.0f; // reset
1037
1038   tet_infoline("Test Child Actor Position");
1039   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( xPositionOfControlBeingTested,
1040                                                                                             380.0f,
1041                                                                                             0.0f ), 0.0001f, TEST_LOCATION );
1042   xPositionOfControlBeingTested += 40.0f;
1043
1044   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( xPositionOfControlBeingTested,
1045                                                                                             380.0f - ( ( NEW_CONTROL_PADDING.top + NEW_CONTROL_PADDING.bottom) * 0.5f ),                                                                                            0.0f ),
1046                                                                                             0.0001f, TEST_LOCATION );
1047
1048   xPositionOfControlBeingTested += 40.0f + NEW_CONTROL_PADDING.start + NEW_CONTROL_PADDING.end;
1049   tet_printf( "\nIf x position %u then change has not been processed \n", 40 + 40 + CONTROL_PADDING.start + CONTROL_PADDING.end );
1050   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( xPositionOfControlBeingTested, 380.0f, 0.0f ), 0.0001f, TEST_LOCATION );
1051
1052   tet_infoline("Test Child Actor Size");
1053   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ) , Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
1054
1055   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ) , Vector3( 40.0f + NEW_CONTROL_PADDING.start + NEW_CONTROL_PADDING.end,
1056                                                                                         40.0f + NEW_CONTROL_PADDING.top + NEW_CONTROL_PADDING.bottom , 0.0f ),
1057                                                                                         0.0001f, TEST_LOCATION );
1058
1059   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::SIZE ) , Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
1060
1061   END_TEST;
1062 }
1063
1064 int UtcDaliLayouting_HboxLayout_Padding04(void)
1065 {
1066   ToolkitTestApplication application;
1067   tet_infoline("UtcDaliLayouting_HboxLayout_Padding04 - Adding Padding to the hbox");
1068
1069   // Adding padding to the layout should offset the positioning of the children.
1070
1071   const Extents LAYOUT_PADDING = Extents(5, 10, 20, 2 );
1072   const Size CONTROL_SIZE = Size( 40, 40 );
1073
1074   Stage stage = Stage::GetCurrent();
1075   // Create a root layout, ideally Dali would have a default layout in the root layer.
1076   // Without this root layer the LinearLayout (or any other layout) will not
1077   // honour WIDTH_SPECIFICATION or HEIGHT_SPECIFICATION settings.
1078   // It uses the default stage size and ideally should have a layout added to it.
1079   auto rootLayoutControl = Control::New();
1080   rootLayoutControl.SetName( "AbsoluteLayout");
1081   auto rootLayout = AbsoluteLayout::New();
1082   DevelControl::SetLayout( rootLayoutControl, rootLayout );
1083   rootLayoutControl.SetAnchorPoint( AnchorPoint::CENTER );
1084   rootLayoutControl.SetParentOrigin( ParentOrigin::CENTER );
1085   stage.Add( rootLayoutControl );
1086
1087   auto hbox = Control::New();
1088   auto hboxLayout = LinearLayout::New();
1089   hboxLayout.SetOrientation( LinearLayout::Orientation::HORIZONTAL );
1090   DevelControl::SetLayout( hbox, hboxLayout );
1091   hbox.SetName( "HBox");
1092   hbox.SetProperty(Toolkit::Control::Property::PADDING, LAYOUT_PADDING );
1093   hbox.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::WRAP_CONTENT );
1094   hbox.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::WRAP_CONTENT );
1095
1096   std::vector< Control > controls;
1097   controls.push_back( CreateLeafControl( CONTROL_SIZE.width, CONTROL_SIZE.height ) );
1098   controls.push_back( CreateLeafControl( CONTROL_SIZE.width, CONTROL_SIZE.height ) );
1099   controls.push_back( CreateLeafControl( CONTROL_SIZE.width, CONTROL_SIZE.height ) );
1100   controls.push_back( CreateLeafControl( CONTROL_SIZE.width, CONTROL_SIZE.height ) );
1101
1102   for( auto&& iter : controls )
1103   {
1104     hbox.Add( iter );
1105   }
1106
1107   hbox.SetParentOrigin( ParentOrigin::CENTER );
1108   hbox.SetAnchorPoint( AnchorPoint::CENTER );
1109   rootLayoutControl.Add( hbox );
1110
1111   // Ensure layouting happens
1112   application.SendNotification();
1113   application.Render();
1114
1115   // Extra update needed to Relayout one more time. Catches any position updates, false positive without this seen.
1116   application.SendNotification();
1117
1118   // hbox centers elements vertically, it fills test harness stage, which is 480x800.
1119   // hbox left justifies elements
1120   tet_infoline("Test Child Actor Position");
1121
1122   auto controlXPosition=0.0f;
1123
1124   controlXPosition = LAYOUT_PADDING.start;  // First child positioned at offset defined by the padding
1125   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( LAYOUT_PADDING.start,
1126                                                                                             LAYOUT_PADDING.top,
1127                                                                                             0.0f ), 0.0001f, TEST_LOCATION );
1128
1129   controlXPosition+=CONTROL_SIZE.width; // Second child positioned is the position of the first child + the first child's width.
1130   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( controlXPosition,
1131                                                                                             LAYOUT_PADDING.top,
1132                                                                                             0.0f ),
1133                                                                                             0.0001f, TEST_LOCATION );
1134
1135   controlXPosition+=CONTROL_SIZE.width; // Third child positioned adjacent to second
1136   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( controlXPosition,
1137                                                                                             LAYOUT_PADDING.top,
1138                                                                                             0.0f ), 0.0001f, TEST_LOCATION );
1139
1140   controlXPosition+=CONTROL_SIZE.width; // Forth passed adjacent to the third
1141   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( controlXPosition,
1142                                                                                             LAYOUT_PADDING.top,
1143                                                                                             0.0f ), 0.0001f, TEST_LOCATION );
1144
1145   auto totalControlsWidth = CONTROL_SIZE.width * controls.size();
1146   auto totalControlsHeight = CONTROL_SIZE.height;
1147
1148   DALI_TEST_EQUALS( hbox.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( totalControlsWidth + LAYOUT_PADDING.start + LAYOUT_PADDING.end,
1149                                                                                  totalControlsHeight + LAYOUT_PADDING.top + LAYOUT_PADDING.bottom,
1150                                                                                  0.0f ), 0.0001f, TEST_LOCATION );
1151
1152
1153   END_TEST;
1154 }
1155
1156 int UtcDaliLayouting_HboxLayout_Padding05(void)
1157 {
1158   ToolkitTestApplication application;
1159   tet_infoline("UtcDaliLayouting_HboxLayout_Padding05 - Changing the hbox Padding");
1160
1161   // Adding padding to the layout should offset the positioning of the children.
1162
1163   const Extents LAYOUT_PADDING = Extents(5, 10, 20, 2 );
1164   const Size CONTROL_SIZE = Size( 40, 40 );
1165
1166   Stage stage = Stage::GetCurrent();
1167   // Create a root layout, ideally Dali would have a default layout in the root layer.
1168   // Without this root layer the LinearLayout (or any other layout) will not
1169   // honour WIDTH_SPECIFICATION or HEIGHT_SPECIFICATION settings.
1170   // It uses the default stage size and ideally should have a layout added to it.
1171   auto rootLayoutControl = Control::New();
1172   rootLayoutControl.SetName( "AbsoluteLayout");
1173   auto rootLayout = AbsoluteLayout::New();
1174   DevelControl::SetLayout( rootLayoutControl, rootLayout );
1175   rootLayoutControl.SetAnchorPoint( AnchorPoint::CENTER );
1176   rootLayoutControl.SetParentOrigin( ParentOrigin::CENTER );
1177   stage.Add( rootLayoutControl );
1178
1179   auto hbox = Control::New();
1180   auto hboxLayout = LinearLayout::New();
1181   hboxLayout.SetOrientation( LinearLayout::Orientation::HORIZONTAL );
1182   DevelControl::SetLayout( hbox, hboxLayout );
1183   hbox.SetName( "HBox");
1184   hbox.SetProperty(Toolkit::Control::Property::PADDING, LAYOUT_PADDING );
1185   hbox.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::WRAP_CONTENT );
1186   hbox.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::WRAP_CONTENT );
1187
1188   std::vector< Control > controls;
1189   controls.push_back( CreateLeafControl( CONTROL_SIZE.width, CONTROL_SIZE.height ) );
1190   controls.push_back( CreateLeafControl( CONTROL_SIZE.width, CONTROL_SIZE.height ) );
1191   controls.push_back( CreateLeafControl( CONTROL_SIZE.width, CONTROL_SIZE.height ) );
1192   controls.push_back( CreateLeafControl( CONTROL_SIZE.width, CONTROL_SIZE.height ) );
1193
1194   for( auto&& iter : controls )
1195   {
1196     hbox.Add( iter );
1197   }
1198
1199   hbox.SetParentOrigin( ParentOrigin::CENTER );
1200   hbox.SetAnchorPoint( AnchorPoint::CENTER );
1201   rootLayoutControl.Add( hbox );
1202
1203   // Ensure layouting happens
1204   application.SendNotification();
1205   application.Render();
1206
1207   // Extra update needed to Relayout one more time. Catches any position updates, false positive without this seen.
1208   application.SendNotification();
1209
1210   // hbox centers elements vertically, it fills test harness stage, which is 480x800.
1211   // hbox left justifies elements
1212   tet_infoline("Test Child Actor Position");
1213
1214   auto controlXPosition=0.0f;
1215
1216   controlXPosition = LAYOUT_PADDING.start;  // First child positioned at offset defined by the padding
1217   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( LAYOUT_PADDING.start,
1218                                                                                             LAYOUT_PADDING.top,
1219                                                                                             0.0f ), 0.0001f, TEST_LOCATION );
1220
1221   controlXPosition+=CONTROL_SIZE.width; // Second child positioned is the position of the first child + the first child's width.
1222   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( controlXPosition,
1223                                                                                             LAYOUT_PADDING.top,
1224                                                                                             0.0f ),
1225                                                                                             0.0001f, TEST_LOCATION );
1226
1227   controlXPosition+=CONTROL_SIZE.width; // Third child positioned adjacent to second
1228   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( controlXPosition,
1229                                                                                             LAYOUT_PADDING.top,
1230                                                                                             0.0f ), 0.0001f, TEST_LOCATION );
1231
1232   controlXPosition+=CONTROL_SIZE.width; // Forth passed adjacent to the third
1233   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( controlXPosition,
1234                                                                                             LAYOUT_PADDING.top,
1235                                                                                             0.0f ), 0.0001f, TEST_LOCATION );
1236
1237   auto totalControlsWidth = CONTROL_SIZE.width * controls.size();
1238   auto totalControlsHeight = CONTROL_SIZE.height;
1239
1240   DALI_TEST_EQUALS( hbox.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( totalControlsWidth + LAYOUT_PADDING.start + LAYOUT_PADDING.end,
1241                                                                                  totalControlsHeight + LAYOUT_PADDING.top + LAYOUT_PADDING.bottom,
1242                                                                                  0.0f ), 0.0001f, TEST_LOCATION );
1243
1244   // Change layout padding
1245   const Extents NEW_LAYOUT_PADDING = Extents(5, 20, 10, 2 );
1246   tet_printf( "\nChanging Padding to control at index 1 \n" );
1247   hbox.SetProperty(Toolkit::Control::Property::PADDING, NEW_LAYOUT_PADDING );
1248
1249   // Ensure layouting happens
1250   application.SendNotification();
1251   application.Render();
1252
1253   // Extra update needed to Relayout one more time. Catches any position updates, false positive without this seen.
1254   application.SendNotification();
1255
1256   controlXPosition = NEW_LAYOUT_PADDING.start;  // First child positioned at offset defined by the padding
1257   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( NEW_LAYOUT_PADDING.start,
1258                                                                                             NEW_LAYOUT_PADDING.top,
1259                                                                                             0.0f ), 0.0001f, TEST_LOCATION );
1260
1261   controlXPosition+=CONTROL_SIZE.width; // Second child positioned is the position of the first child + the first child's width.
1262   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( controlXPosition,
1263                                                                                             NEW_LAYOUT_PADDING.top,
1264                                                                                             0.0f ),
1265                                                                                             0.0001f, TEST_LOCATION );
1266
1267   controlXPosition+=CONTROL_SIZE.width; // Third child positioned adjacent to second
1268   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( controlXPosition,
1269                                                                                             NEW_LAYOUT_PADDING.top,
1270                                                                                             0.0f ), 0.0001f, TEST_LOCATION );
1271
1272   controlXPosition+=CONTROL_SIZE.width; // Forth passed adjacent to the third
1273   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( controlXPosition,
1274                                                                                             NEW_LAYOUT_PADDING.top,
1275                                                                                             0.0f ), 0.0001f, TEST_LOCATION );
1276   totalControlsWidth = CONTROL_SIZE.width * controls.size();
1277   totalControlsHeight = CONTROL_SIZE.height;
1278
1279   DALI_TEST_EQUALS( hbox.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( totalControlsWidth + NEW_LAYOUT_PADDING.start + NEW_LAYOUT_PADDING.end,
1280                                                                                  totalControlsHeight + NEW_LAYOUT_PADDING.top + NEW_LAYOUT_PADDING.bottom,
1281                                                                                  0.0f ), 0.0001f, TEST_LOCATION );
1282   END_TEST;
1283 }
1284
1285 // Margin Tests
1286
1287 int UtcDaliLayouting_HboxLayout_Margin01(void)
1288 {
1289   ToolkitTestApplication application;
1290   tet_infoline("UtcDaliLayouting_HboxLayout_Margin01 - Adding a margin to a single child");
1291
1292   Stage stage = Stage::GetCurrent();
1293   auto hbox = Control::New();
1294   auto hboxLayout = LinearLayout::New();
1295   DevelControl::SetLayout( hbox, hboxLayout );
1296   hbox.SetName( "HBox");
1297
1298   std::vector< Control > controls;
1299   controls.push_back( CreateLeafControl( 40, 40 ) );
1300   controls.push_back( CreateLeafControl( 60, 40 ) );
1301   controls.push_back( CreateLeafControl( 80, 40 ) );
1302   controls.push_back( CreateLeafControl( 100, 40 ) );
1303
1304   const Extents CONTROL_MARGIN = Extents(5, 10, 20, 0 );
1305   tet_printf( "\nAdding Margin to control at index 1 \n" );
1306   controls[1].SetProperty(Toolkit::Control::Property::MARGIN, CONTROL_MARGIN );
1307
1308   for( auto&& iter : controls )
1309   {
1310     hbox.Add( iter );
1311   }
1312   hbox.SetParentOrigin( ParentOrigin::CENTER );
1313   hbox.SetAnchorPoint( AnchorPoint::CENTER );
1314   stage.Add( hbox );
1315
1316   // Ensure layouting happens
1317   application.SendNotification();
1318   application.Render();
1319
1320   // hbox centers elements vertically, it fills test harness stage, which is 480x800.
1321   // hbox left justifies elements
1322   tet_infoline("Test Child Actor Position");
1323   auto xPositionOfControlBeingTested = 0.0f;
1324   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( xPositionOfControlBeingTested,
1325                                                                                             380.0f,
1326                                                                                             0.0f ), 0.0001f, TEST_LOCATION );
1327   xPositionOfControlBeingTested += 40.0f + CONTROL_MARGIN.start;
1328
1329   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( xPositionOfControlBeingTested,
1330                                                                                             380.0f + CONTROL_MARGIN.top, 0.0f ),
1331                                                                                             0.0001f, TEST_LOCATION );
1332
1333   xPositionOfControlBeingTested += 60.0f + CONTROL_MARGIN.end;
1334   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( xPositionOfControlBeingTested, 380.0f, 0.0f ), 0.0001f, TEST_LOCATION );
1335
1336   xPositionOfControlBeingTested += 80.0f;
1337   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( xPositionOfControlBeingTested,380.0f, 0.0f ), 0.0001f, TEST_LOCATION );
1338
1339   tet_infoline("Test Child Actor Size is the same after Margin added");
1340   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
1341   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 60.0f, 40.0f , 0.0f ), 0.0001f, TEST_LOCATION );
1342   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 80.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
1343   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
1344
1345   END_TEST;
1346 }
1347
1348
1349 int UtcDaliLayouting_VboxLayout01(void)
1350 {
1351   ToolkitTestApplication application;
1352   tet_infoline(" UtcDaliLayouting_VboxLayout01");
1353
1354   Stage stage = Stage::GetCurrent();
1355   auto vbox = Control::New();
1356   auto vboxLayout = LinearLayout::New();
1357   vboxLayout.SetOrientation( LinearLayout::Orientation::VERTICAL );
1358   DevelControl::SetLayout( vbox, vboxLayout );
1359   vbox.SetName( "Vbox");
1360
1361   std::vector< Control > controls;
1362   controls.push_back( CreateLeafControl( 40, 40 ) );
1363   controls.push_back( CreateLeafControl( 60, 60 ) );
1364   controls.push_back( CreateLeafControl( 80, 80 ) );
1365   controls.push_back( CreateLeafControl( 100, 100 ) );
1366
1367   for( auto&& iter : controls )
1368   {
1369     vbox.Add( iter );
1370   }
1371   vbox.SetParentOrigin( ParentOrigin::CENTER );
1372   vbox.SetAnchorPoint( AnchorPoint::CENTER );
1373   stage.Add( vbox );
1374
1375   controls[2].SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
1376
1377   // Check it.
1378   DALI_TEST_EQUALS( controls[2].GetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION ), Property::Value( ChildLayoutData::MATCH_PARENT ), TEST_LOCATION );
1379
1380   // Ensure layouting happens
1381   application.SendNotification();
1382   application.Render();
1383
1384   // vbox centers elements horizontally, it fills test harness stage, which is 480x800.
1385   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 220.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
1386   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 210.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
1387   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
1388   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 190.0f, 180.0f, 0.0f ), 0.0001f, TEST_LOCATION );
1389
1390   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
1391   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 60.0f, 60.0f, 0.0f ), 0.0001f, TEST_LOCATION );
1392   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 480.0f, 80.0f, 0.0f ), 0.0001f, TEST_LOCATION );
1393   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
1394
1395   END_TEST;
1396 }
1397
1398 int UtcDaliLayouting_VboxLayout02(void)
1399 {
1400   ToolkitTestApplication application;
1401   tet_infoline(" UtcDaliLayouting_VboxLayout01");
1402
1403   Stage stage = Stage::GetCurrent();
1404
1405   // @todo Can't set specification properties on root control. Really need to make LayoutController a root
1406   // LayoutGroup for this to happen automatically.
1407   //
1408   // For this test, add an hbox instead
1409   auto rootControl = Control::New();
1410   auto absoluteLayout = AbsoluteLayout::New();
1411   DevelControl::SetLayout( rootControl, absoluteLayout );
1412   rootControl.SetName( "AbsoluteLayout");
1413   stage.Add( rootControl );
1414
1415   auto vbox = Control::New();
1416   auto vboxLayout = LinearLayout::New();
1417   vboxLayout.SetOrientation( LinearLayout::Orientation::VERTICAL );
1418   DevelControl::SetLayout( vbox, vboxLayout );
1419   vbox.SetName( "Vbox");
1420   rootControl.Add( vbox );
1421
1422   vbox.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::WRAP_CONTENT );
1423   vbox.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
1424
1425   std::vector< Control > controls;
1426   controls.push_back( CreateLeafControl( 40, 40 ) );
1427   controls.push_back( CreateLeafControl( 60, 60 ) );
1428   controls.push_back( CreateLeafControl( 80, 80 ) );
1429   controls.push_back( CreateLeafControl( 100, 100 ) );
1430
1431   for( auto&& iter : controls )
1432   {
1433     vbox.Add( iter );
1434   }
1435   vbox.SetParentOrigin( ParentOrigin::CENTER );
1436   vbox.SetAnchorPoint( AnchorPoint::CENTER );
1437
1438   controls[2].SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
1439
1440   // Check it.
1441   DALI_TEST_EQUALS( controls[2].GetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION ), Property::Value( ChildLayoutData::MATCH_PARENT ), TEST_LOCATION );
1442
1443   // Ensure layouting happens
1444   application.SendNotification();
1445   application.Render();
1446
1447   DALI_TEST_EQUALS( rootControl.GetProperty<Vector3>(Actor::Property::POSITION), Vector3(0,0,0),TEST_LOCATION);
1448   DALI_TEST_EQUALS( rootControl.GetProperty<Vector3>(Actor::Property::SIZE), Vector3(480,800,0),TEST_LOCATION);
1449
1450   // vbox centers elements horizontally, it should wrap it's content horizontally, i.e. it should take the width of the largest element (100)
1451   DALI_TEST_EQUALS( vbox.GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
1452   DALI_TEST_EQUALS( vbox.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 800.0f, 0.0f ), 0.0001f, TEST_LOCATION );
1453
1454   // 3rd control is set to match parent - this should also be 100 wide
1455   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 30.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
1456   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 20.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
1457   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
1458   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 180.0f, 0.0f ), 0.0001f, TEST_LOCATION );
1459
1460   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
1461   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 60.0f, 60.0f, 0.0f ), 0.0001f, TEST_LOCATION );
1462   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 80.0f, 0.0f ), 0.0001f, TEST_LOCATION );
1463   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
1464
1465   END_TEST;
1466 }
1467
1468
1469 int UtcDaliLayouting_VboxLayout03(void)
1470 {
1471   ToolkitTestApplication application;
1472   tet_infoline(" UtcDaliLayouting_VboxLayout03 test with cell padding set");
1473
1474   Stage stage = Stage::GetCurrent();
1475
1476   // @todo Can't set specification properties on root control. Really need to make LayoutController a root
1477   // LayoutGroup for this to happen automatically.
1478   //
1479   // For this test, add an hbox instead
1480   auto hbox = Control::New();
1481   auto hboxLayout = LinearLayout::New();
1482   DevelControl::SetLayout( hbox, hboxLayout );
1483   hbox.SetName( "Hbox");
1484   stage.Add( hbox );
1485
1486   auto vbox = Control::New();
1487   auto vboxLayout = LinearLayout::New();
1488   vboxLayout.SetCellPadding( LayoutSize( 0, 10 ) );
1489   vboxLayout.SetOrientation( LinearLayout::Orientation::VERTICAL );
1490
1491   DALI_TEST_EQUALS( vboxLayout.GetCellPadding(), LayoutSize( 0, 10 ), TEST_LOCATION );
1492
1493   DevelControl::SetLayout( vbox, vboxLayout );
1494   vbox.SetName( "Vbox");
1495   hbox.Add( vbox );
1496
1497   vbox.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::WRAP_CONTENT );
1498   vbox.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
1499
1500   std::vector< Control > controls;
1501   controls.push_back( CreateLeafControl( 40, 40 ) );
1502   controls.push_back( CreateLeafControl( 60, 60 ) );
1503   controls.push_back( CreateLeafControl( 80, 80 ) );
1504   controls.push_back( CreateLeafControl( 100, 100 ) );
1505
1506   for( auto&& iter : controls )
1507   {
1508     vbox.Add( iter );
1509   }
1510   vbox.SetParentOrigin( ParentOrigin::CENTER );
1511   vbox.SetAnchorPoint( AnchorPoint::CENTER );
1512
1513   controls[2].SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
1514
1515   // Check it.
1516   DALI_TEST_EQUALS( controls[2].GetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION ), Property::Value( ChildLayoutData::MATCH_PARENT ), TEST_LOCATION );
1517
1518   // Ensure layouting happens
1519   application.SendNotification();
1520   application.Render();
1521
1522   DALI_TEST_EQUALS( hbox.GetProperty<Vector3>(Actor::Property::POSITION), Vector3(0,0,0),TEST_LOCATION);
1523   DALI_TEST_EQUALS( hbox.GetProperty<Vector3>(Actor::Property::SIZE), Vector3(480,800,0),TEST_LOCATION);
1524
1525   // vbox centers elements horizontally, it should wrap it's content horizontally, i.e. it should take the width of the largest element (100)
1526   DALI_TEST_EQUALS( vbox.GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
1527   DALI_TEST_EQUALS( vbox.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 800.0f, 0.0f ), 0.0001f, TEST_LOCATION );
1528
1529   // 3rd control is set to match parent - this should also be 100 wide
1530   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 30.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
1531   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 20.0f, 50.0f, 0.0f ), 0.0001f, TEST_LOCATION );
1532   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 120.0f, 0.0f ), 0.0001f, TEST_LOCATION );
1533   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 210.0f, 0.0f ), 0.0001f, TEST_LOCATION );
1534
1535   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
1536   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 60.0f, 60.0f, 0.0f ), 0.0001f, TEST_LOCATION );
1537   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 80.0f, 0.0f ), 0.0001f, TEST_LOCATION );
1538   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
1539
1540   END_TEST;
1541 }
1542
1543 int UtcDaliLayouting_VboxLayout_Padding(void)
1544 {
1545   ToolkitTestApplication application;
1546   tet_infoline("UtcDaliLayouting_VboxLayout_Padding - Adding Padding to the vbox");
1547
1548   // Adding padding to the layout should offset the positioning of the children.
1549
1550   const Extents LAYOUT_PADDING = Extents(5, 10, 20, 2 );
1551   const Size CONTROL_SIZE = Size( 40, 40 );
1552
1553   Stage stage = Stage::GetCurrent();
1554   // Create a root layout, ideally Dali would have a default layout in the root layer.
1555   // Without this root layer the LinearLayout (or any other layout) will not
1556   // honour WIDTH_SPECIFICATION or HEIGHT_SPECIFICATION settings.
1557   // It uses the default stage size and ideally should have a layout added to it.
1558   auto rootLayoutControl = Control::New();
1559   rootLayoutControl.SetName( "AbsoluteLayout");
1560   auto rootLayout = AbsoluteLayout::New();
1561   DevelControl::SetLayout( rootLayoutControl, rootLayout );
1562   rootLayoutControl.SetAnchorPoint( AnchorPoint::CENTER );
1563   rootLayoutControl.SetParentOrigin( ParentOrigin::CENTER );
1564   stage.Add( rootLayoutControl );
1565
1566   auto vbox = Control::New();
1567   auto vboxLayout = LinearLayout::New();
1568   vboxLayout.SetOrientation( LinearLayout::Orientation::VERTICAL );
1569   DevelControl::SetLayout( vbox, vboxLayout );
1570   vbox.SetName( "VBox");
1571   vbox.SetProperty( Toolkit::Control::Property::PADDING, LAYOUT_PADDING );
1572   vbox.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::WRAP_CONTENT );
1573   vbox.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::WRAP_CONTENT );
1574
1575   std::vector< Control > controls;
1576   controls.push_back( CreateLeafControl( CONTROL_SIZE.width, CONTROL_SIZE.height ) );
1577   controls.push_back( CreateLeafControl( CONTROL_SIZE.width, CONTROL_SIZE.height ) );
1578   controls.push_back( CreateLeafControl( CONTROL_SIZE.width, CONTROL_SIZE.height ) );
1579   controls.push_back( CreateLeafControl( CONTROL_SIZE.width, CONTROL_SIZE.height ) );
1580
1581   for( auto&& iter : controls )
1582   {
1583     vbox.Add( iter );
1584   }
1585
1586   vbox.SetParentOrigin( ParentOrigin::CENTER );
1587   vbox.SetAnchorPoint( AnchorPoint::CENTER );
1588   rootLayoutControl.Add( vbox );
1589
1590   // Ensure layouting happens
1591   application.SendNotification();
1592   application.Render();
1593
1594   // Extra update needed to Relayout one more time. Catches any position updates, false positive without this seen.
1595   application.SendNotification();
1596
1597   // vbox centers elements horizontally, it fills test harness stage, which is 480x800.
1598   tet_infoline("Test Child Actor Position");
1599
1600   auto controlYPosition = 0.0f;
1601
1602   controlYPosition = LAYOUT_PADDING.top;  // First child positioned at offset defined by the padding
1603   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( LAYOUT_PADDING.start,
1604                                                                                             LAYOUT_PADDING.top,
1605                                                                                             0.0f ), 0.0001f, TEST_LOCATION );
1606
1607   controlYPosition += CONTROL_SIZE.height; // Second child positioned is the position of the first child + the first child's height.
1608   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( LAYOUT_PADDING.start,
1609                                                                                             controlYPosition,
1610                                                                                             0.0f ),
1611                                                                                             0.0001f, TEST_LOCATION );
1612
1613   controlYPosition += CONTROL_SIZE.height; // Third child positioned adjacent to second
1614   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( LAYOUT_PADDING.start,
1615                                                                                             controlYPosition,
1616                                                                                             0.0f ), 0.0001f, TEST_LOCATION );
1617
1618   controlYPosition += CONTROL_SIZE.height; // Forth passed adjacent to the third
1619   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( LAYOUT_PADDING.start,
1620                                                                                             controlYPosition,
1621                                                                                             0.0f ), 0.0001f, TEST_LOCATION );
1622
1623   auto totalControlsWidth = CONTROL_SIZE.width;
1624   auto totalControlsHeight = CONTROL_SIZE.height * controls.size();
1625
1626   DALI_TEST_EQUALS( vbox.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( totalControlsWidth + LAYOUT_PADDING.start + LAYOUT_PADDING.end,
1627                                                                                  totalControlsHeight + LAYOUT_PADDING.top + LAYOUT_PADDING.bottom,
1628                                                                                  0.0f ), 0.0001f, TEST_LOCATION );
1629
1630   END_TEST;
1631 }
1632
1633
1634 int UtcDaliLayouting_RelayoutOnChildOrderChanged(void)
1635 {
1636   ToolkitTestApplication application;
1637   tet_infoline(" UtcDaliLayouting_RelayoutOnChildOrderChanged");
1638   tet_infoline(" Test that if the sibling order changes, the container is re-laid out automatically");
1639
1640   Stage stage = Stage::GetCurrent();
1641
1642   auto hbox = Control::New();
1643   auto hboxLayout = Test::CustomLayout::New();
1644   DevelControl::SetLayout( hbox, hboxLayout );
1645   hbox.SetName( "HBox");
1646
1647   std::vector< Control > controls;
1648   controls.push_back( CreateLeafControl( 40, 40 ) );
1649   controls.push_back( CreateLeafControl( 60, 40 ) );
1650   controls.push_back( CreateLeafControl( 80, 40 ) );
1651   controls.push_back( CreateLeafControl( 100, 40 ) );
1652
1653   for( auto&& iter : controls )
1654   {
1655     hbox.Add( iter );
1656   }
1657   hbox.SetParentOrigin( ParentOrigin::CENTER );
1658   hbox.SetAnchorPoint( AnchorPoint::CENTER );
1659   stage.Add( hbox );
1660
1661   // Ensure layouting happens
1662   application.SendNotification();
1663   application.Render();
1664
1665   // hbox centers elements vertically, it fills test harness stage, which is 480x800.
1666   // hbox left justifies elements
1667   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 380.0f, 0.0f ), 0.0001f, TEST_LOCATION );
1668   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 40.0f, 380.0f, 0.0f ), 0.0001f, TEST_LOCATION );
1669   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 100.0f, 380.0f, 0.0f ), 0.0001f, TEST_LOCATION );
1670   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 180.0f, 380.0f, 0.0f ), 0.0001f, TEST_LOCATION );
1671
1672   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
1673   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 60.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
1674   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 80.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
1675   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
1676
1677   controls[0].RaiseToTop(); // 0->3; 1, 2, 3, 0
1678   controls[2].Lower();      // 2->1; 2, 1, 3, 0
1679
1680   application.SendNotification();
1681   application.Render();
1682
1683   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 380.0f, 0.0f ), 0.0001f, TEST_LOCATION );
1684   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 80.0f, 380.0f, 0.0f ), 0.0001f, TEST_LOCATION );
1685   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 140.0f, 380.0f, 0.0f ), 0.0001f, TEST_LOCATION );
1686   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 240.0f, 380.0f, 0.0f ), 0.0001f, TEST_LOCATION );
1687
1688   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
1689   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 60.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
1690   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 80.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
1691   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
1692
1693   END_TEST;
1694 }
1695
1696 int UtcDaliLayouting_HboxLayout_TargetSize(void)
1697 {
1698   ToolkitTestApplication application;
1699   tet_infoline(" UtcDaliLayouting_HboxLayout07 - Set target size on leaf");
1700
1701   Stage stage = Stage::GetCurrent();
1702   auto hbox = Control::New();
1703   auto hboxLayout = LinearLayout::New();
1704   DevelControl::SetLayout( hbox, hboxLayout );
1705   hbox.SetName( "HBox");
1706
1707   std::vector< Control > controls;
1708   controls.push_back( CreateLeafControl( 40, 40 ) );
1709   for( auto&& iter : controls )
1710   {
1711     iter.SetSize( 100, 100 );
1712     hbox.Add( iter );
1713   }
1714   hbox.SetParentOrigin( ParentOrigin::CENTER );
1715   hbox.SetAnchorPoint( AnchorPoint::CENTER );
1716   stage.Add( hbox );
1717
1718   // Ensure layouting happens
1719   application.SendNotification();
1720   application.Render();
1721
1722   // hbox centers elements vertically, it fills test harness stage, which is 480x800 from left to right.
1723   // hbox left justifies elements
1724   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 350.0f, 0.0f ), 0.0001f, TEST_LOCATION );
1725   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
1726
1727   END_TEST;
1728 }
1729
1730 int UtcDaliLayouting_RemoveLayout01(void)
1731 {
1732   ToolkitTestApplication application;
1733   tet_infoline(" UtcDaliLayouting_RemoveLayout");
1734
1735   Stage stage = Stage::GetCurrent();
1736
1737   auto rootControl = Control::New();
1738   auto absoluteLayout = AbsoluteLayout::New();
1739   DevelControl::SetLayout( rootControl, absoluteLayout );
1740   rootControl.SetName( "AbsoluteLayout" );
1741   stage.Add( rootControl );
1742
1743   auto hbox = Control::New();
1744   auto hboxLayout = LinearLayout::New();
1745   hboxLayout.SetOrientation( LinearLayout::Orientation::HORIZONTAL );
1746   DevelControl::SetLayout( hbox, hboxLayout );
1747   hbox.SetName( "HBox" );
1748
1749   std::vector< Control > controls;
1750   controls.push_back( CreateLeafControl( 40, 40 ) );
1751   controls.push_back( CreateLeafControl( 60, 40 ) );
1752
1753   for( auto&& iter : controls )
1754   {
1755     hbox.Add( iter );
1756   }
1757   hbox.SetParentOrigin( ParentOrigin::CENTER );
1758   hbox.SetAnchorPoint( AnchorPoint::CENTER );
1759   rootControl.Add( hbox );
1760
1761   tet_infoline("Layout as normal");
1762   application.SendNotification();
1763   application.Render();
1764
1765   tet_infoline("Set an empty layout on hbox container");
1766   LinearLayout emptyLayout;
1767   DevelControl::SetLayout( hbox, emptyLayout );
1768
1769   tet_infoline("Run another layout");
1770   application.SendNotification();
1771   application.Render();
1772
1773   tet_infoline("Check leaf controls haven't moved");
1774
1775   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
1776   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 40.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
1777
1778   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
1779   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 60.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
1780
1781   END_TEST;
1782 }
1783
1784 int UtcDaliLayouting_LayoutChildren01(void)
1785 {
1786   ToolkitTestApplication application;
1787   tet_infoline(" UtcDaliLayouting_LayoutChildren01");
1788
1789   Stage stage = Stage::GetCurrent();
1790
1791   auto rootControl = Control::New();
1792   auto absoluteLayout = AbsoluteLayout::New();
1793   DevelControl::SetLayout( rootControl, absoluteLayout );
1794   stage.Add( rootControl );
1795
1796   auto hbox = Control::New();
1797   auto hboxLayout = LinearLayout::New();
1798   DevelControl::SetLayout( hbox, hboxLayout );
1799   rootControl.Add( hbox );
1800
1801   DALI_TEST_EQUALS( absoluteLayout.GetChildCount(), 1, TEST_LOCATION );
1802
1803   tet_infoline("Test removal by setting empty layout to child container" );
1804   DevelControl::SetLayout( hbox, LayoutItem{} );
1805
1806   DALI_TEST_EQUALS( absoluteLayout.GetChildCount(), 0, TEST_LOCATION );
1807
1808   auto& hboxImpl = GetImplementation( hboxLayout );
1809   Handle empty;
1810   DALI_TEST_EQUALS( hboxLayout.GetOwner(), empty, TEST_LOCATION );
1811   DALI_TEST_EQUALS( (void*)hboxImpl.GetParent(), (void*)nullptr, TEST_LOCATION );
1812
1813   // For coverage
1814   hboxImpl.SetLayoutRequested();
1815
1816   END_TEST;
1817 }
1818
1819 int UtcDaliLayouting_LayoutChildren02(void)
1820 {
1821   ToolkitTestApplication application;
1822   tet_infoline(" UtcDaliLayouting_LayoutChildren02");
1823
1824   Stage stage = Stage::GetCurrent();
1825
1826   auto rootControl = Control::New();
1827   auto absoluteLayout = AbsoluteLayout::New();
1828   DevelControl::SetLayout( rootControl, absoluteLayout );
1829   stage.Add( rootControl );
1830
1831   auto hbox = Control::New();
1832   auto hboxLayout = LinearLayout::New();
1833   DevelControl::SetLayout( hbox, hboxLayout );
1834   rootControl.Add( hbox );
1835
1836   DALI_TEST_EQUALS( absoluteLayout.GetChildCount(), 1, TEST_LOCATION );
1837
1838   tet_infoline("Test removal by removing child actor from parent container" );
1839   hbox.Unparent();
1840
1841   DALI_TEST_EQUALS( absoluteLayout.GetChildCount(), 0, TEST_LOCATION );
1842
1843   auto& hboxImpl = GetImplementation( hboxLayout );
1844   tet_infoline("Test child actor still has hbox layout " );
1845   DALI_TEST_EQUALS( (bool)hboxLayout.GetOwner(), true, TEST_LOCATION );
1846
1847   tet_infoline("Test hbox layout has no parent " );
1848   DALI_TEST_EQUALS( (void*)hboxImpl.GetParent(), (void*)nullptr, TEST_LOCATION );
1849
1850   END_TEST;
1851 }
1852
1853 int UtcDaliLayouting_LayoutChildren03(void)
1854 {
1855   ToolkitTestApplication application;
1856   tet_infoline(" UtcDaliLayouting_LayoutChildren02");
1857
1858   Stage stage = Stage::GetCurrent();
1859
1860   auto rootControl = Control::New();
1861   auto absoluteLayout = AbsoluteLayout::New();
1862   DevelControl::SetLayout( rootControl, absoluteLayout );
1863   stage.Add( rootControl );
1864
1865   auto hbox = Control::New();
1866   auto hboxLayout = LinearLayout::New();
1867   DevelControl::SetLayout( hbox, hboxLayout );
1868   rootControl.Add( hbox );
1869
1870   DALI_TEST_EQUALS( absoluteLayout.GetChildCount(), 1, TEST_LOCATION );
1871
1872   tet_infoline("Test removal by removing child layout from parent layout" );
1873   absoluteLayout.Remove( hboxLayout );
1874
1875   DALI_TEST_EQUALS( absoluteLayout.GetChildCount(), 0, TEST_LOCATION );
1876
1877   auto& hboxImpl = GetImplementation( hboxLayout );
1878
1879   tet_infoline("Check child actor has orphaned layout (Moving child keeps old layout)");
1880   DALI_TEST_EQUALS( hboxLayout.GetOwner(), hbox, TEST_LOCATION );
1881   DALI_TEST_EQUALS( DevelControl::GetLayout(hbox), hboxLayout, TEST_LOCATION );
1882
1883   tet_infoline("Check orphaned layout has no parent");
1884   DALI_TEST_EQUALS( (void*)hboxImpl.GetParent(), (void*)nullptr, TEST_LOCATION );
1885
1886   END_TEST;
1887 }
1888
1889
1890 int UtcDaliLayouting_LayoutChildren04(void)
1891 {
1892   ToolkitTestApplication application;
1893   tet_infoline(" UtcDaliLayouting_LayoutChildren03");
1894
1895   Stage stage = Stage::GetCurrent();
1896
1897   auto rootControl = Control::New();
1898   auto absoluteLayout = AbsoluteLayout::New();
1899   DevelControl::SetLayout( rootControl, absoluteLayout );
1900   stage.Add( rootControl );
1901
1902   auto hbox = Control::New();
1903   tet_infoline("Test unparenting by adding child with no layout to parent (should auto-generate LayoutItem) ");
1904   auto hboxLayout = LinearLayout::New();
1905   rootControl.Add( hbox );
1906
1907   DALI_TEST_EQUALS( absoluteLayout.GetChildCount(), 1, TEST_LOCATION );
1908
1909   tet_infoline("Then setting a layout on the child container");
1910   DevelControl::SetLayout( hbox, hboxLayout );
1911
1912   DALI_TEST_EQUALS( absoluteLayout.GetChildCount(), 1, TEST_LOCATION );
1913
1914   auto& hboxImpl = GetImplementation( hboxLayout );
1915   auto& absImpl = GetImplementation( absoluteLayout );
1916   DALI_TEST_EQUALS( hboxLayout.GetOwner(), Handle(hbox), TEST_LOCATION );
1917   DALI_TEST_EQUALS( hboxImpl.GetParent(), (Dali::Toolkit::Internal::LayoutParent*)&absImpl, TEST_LOCATION );
1918
1919   END_TEST;
1920 }
1921
1922 int UtcDaliLayouting_SetLayoutOrder01(void)
1923 {
1924   ToolkitTestApplication application;
1925   tet_infoline(" UtcDaliLayouting_SetLayoutOrder01 - Call SetLayout after adding the control to the root layout");
1926
1927   Stage stage = Stage::GetCurrent();
1928
1929   auto rootControl = Control::New();
1930   auto absoluteLayout = AbsoluteLayout::New();
1931   DevelControl::SetLayout( rootControl, absoluteLayout );
1932   rootControl.SetName( "AbsoluteLayout" );
1933   stage.Add( rootControl );
1934
1935   tet_infoline(" UtcDaliLayouting_SetLayoutOrder - Creating control");
1936   auto hbox = Control::New();
1937   auto hboxLayout = LinearLayout::New();
1938   hbox.SetName( "HBox");
1939
1940   tet_infoline(" UtcDaliLayouting_SetLayoutOrder - Add control to root layout");
1941   rootControl.Add( hbox );
1942
1943   tet_infoline(" UtcDaliLayouting_SetLayoutOrder - Set layout to control AFTER control added to root");
1944   DevelControl::SetLayout( hbox, hboxLayout );
1945
1946   // Add a Child control
1947   std::vector< Control > controls;
1948   controls.push_back( CreateLeafControl( 100, 100 ) ); // Single control
1949   for( auto&& iter : controls )
1950   {
1951     hbox.Add( iter );
1952   }
1953
1954   // Ensure layouting happens
1955   application.SendNotification();
1956   application.Render();
1957
1958   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
1959
1960   END_TEST;
1961 }
1962
1963 int UtcDaliLayouting_SetLayoutOrder02(void)
1964 {
1965   ToolkitTestApplication application;
1966   tet_infoline(" UtcDaliLayouting_SetLayoutOrder02 - Test the layout item order and the control order");
1967
1968   Stage stage = Stage::GetCurrent();
1969
1970   auto rootControl = Control::New();
1971   auto absoluteLayout = AbsoluteLayout::New();
1972   DevelControl::SetLayout( rootControl, absoluteLayout );
1973   rootControl.SetName( "AbsoluteLayout" );
1974   stage.Add( rootControl );
1975
1976   auto hbox = Control::New();
1977   auto hboxLayout = LinearLayout::New();
1978   hbox.SetName( "HBox");
1979
1980   rootControl.Add( hbox );
1981
1982   DevelControl::SetLayout( hbox, hboxLayout );
1983
1984   // Add child controls
1985   std::vector< Control > controls;
1986   controls.push_back( CreateLeafControl( 100, 100 ) );  // 0
1987   controls.push_back( CreateLeafControl( 100, 100 ) );  // 1
1988   controls.push_back( CreateLeafControl( 100, 100 ) );  // 2
1989
1990   for( auto&& iter : controls )
1991   {
1992     hbox.Add( iter );
1993   }
1994
1995   // Ensure layouting happens
1996   application.SendNotification();
1997   application.Render();
1998
1999   TestLayoutItemOrder( controls, hboxLayout );
2000
2001   tet_infoline("RaiseToTop");
2002
2003   controls[0].RaiseToTop(); // 1 2 0
2004
2005   TestLayoutItemOrder( controls, hboxLayout );
2006
2007   tet_infoline("LowerToBottom");
2008
2009   controls[2].LowerToBottom();  // 2 1 0
2010
2011   TestLayoutItemOrder( controls, hboxLayout );
2012
2013   tet_infoline("Remove / Add");
2014
2015   hbox.Remove( controls[2] );  // 1 0
2016   hbox.Add( controls[2] );     // 1 0 2
2017
2018   TestLayoutItemOrder( controls, hboxLayout );
2019
2020   tet_infoline("SetLayout");
2021
2022   auto vboxLayout = LinearLayout::New();
2023   DevelControl::SetLayout( controls[0], vboxLayout );
2024
2025   TestLayoutItemOrder( controls, hboxLayout );
2026
2027   tet_infoline("Raise");
2028
2029   controls[0].Raise();  // 1 2 0
2030
2031   TestLayoutItemOrder( controls, hboxLayout );
2032
2033   tet_infoline("Lower");
2034
2035   controls[2].Lower();   // 2 1 0
2036
2037   TestLayoutItemOrder( controls, hboxLayout );
2038
2039   tet_infoline("SetLayout again");
2040
2041   auto vboxLayout1 = LinearLayout::New();
2042   DevelControl::SetLayout( controls[2], vboxLayout1 );
2043
2044   TestLayoutItemOrder( controls, hboxLayout );
2045
2046   DevelControl::SetLayout( controls[2], vboxLayout );
2047
2048   END_TEST;
2049 }
2050
2051 int UtcDaliLayouting_LayoutGroup01(void)
2052 {
2053   ToolkitTestApplication application;
2054   tet_infoline("UtcDaliLayouting_LayoutGroup01 - Test adding a control to a layout then adding a TextLabel to that control");
2055
2056   Control rootControl;
2057   SetupRootLayoutControl( rootControl );
2058
2059   // Create a parent layout
2060   auto hbox = Control::New();
2061   auto hboxLayout = LinearLayout::New();
2062   hbox.SetName( "HBox");
2063   rootControl.Add( hbox );
2064   DevelControl::SetLayout( hbox, hboxLayout );
2065   hbox.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION, 600 );
2066   hbox.SetProperty( LayoutItem::ChildProperty::HEIGHT_SPECIFICATION,  ChildLayoutData::WRAP_CONTENT );
2067   hbox.SetAnchorPoint( AnchorPoint::TOP_LEFT );  // LinearLayout will eventually do this internally.
2068
2069   tet_infoline("Add a control without SetLayout being called");
2070
2071   auto control = Control::New();
2072   control.SetName("Control1");
2073   hbox.Add( control );
2074   control.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
2075   control.SetProperty( LayoutItem::ChildProperty::HEIGHT_SPECIFICATION,  ChildLayoutData::WRAP_CONTENT );
2076
2077   tet_infoline("Add a Textlabel to the control");
2078   auto textLabel = TextLabel::New("Test text");
2079   textLabel.SetName("TextLabel");
2080   control.Add( textLabel );
2081
2082   // Ensure layouting happens
2083   application.SendNotification();
2084   application.Render();
2085
2086   tet_infoline("Test text is it's natural size");
2087   DALI_TEST_EQUALS( textLabel.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 230.0f, 64.0f, 0.0f ), 0.0001f, TEST_LOCATION );
2088   tet_infoline("Test control is width of it's parent and height of it's child");
2089   DALI_TEST_EQUALS( control.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 600.0f, 64.0f, 0.0f ), 0.0001f, TEST_LOCATION );
2090
2091   END_TEST;
2092 }
2093
2094 int UtcDaliLayouting_LayoutGroup02(void)
2095 {
2096   ToolkitTestApplication application;
2097   tet_infoline("UtcDaliLayouting_LayoutGroup02 - Test control is the size of it's largest child");
2098
2099   Control rootControl;
2100   SetupRootLayoutControl( rootControl );
2101
2102   // Create a parent layout
2103   auto hbox = Control::New();
2104   auto hboxLayout = LinearLayout::New();
2105   hbox.SetName( "HBox");
2106   rootControl.Add( hbox );
2107   DevelControl::SetLayout( hbox, hboxLayout );
2108   hbox.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION, 600 );
2109   hbox.SetProperty( LayoutItem::ChildProperty::HEIGHT_SPECIFICATION,  ChildLayoutData::WRAP_CONTENT );
2110   hbox.SetAnchorPoint( AnchorPoint::TOP_LEFT );  // LinearLayout will eventually do this internally.
2111
2112   tet_infoline("Add a control without SetLayout being called");
2113
2114   auto control = Control::New();
2115   control.SetName("Control1");
2116   hbox.Add( control );
2117   control.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::WRAP_CONTENT );
2118   control.SetProperty( LayoutItem::ChildProperty::HEIGHT_SPECIFICATION,  ChildLayoutData::WRAP_CONTENT );
2119
2120   tet_infoline("Add a Textlabel to the control");
2121   auto textLabel = TextLabel::New("Test text");
2122   textLabel.SetName("TextLabel");
2123   control.Add( textLabel );
2124
2125   tet_infoline("Add another  Textlabel to the control");
2126   auto largeTextLabel = TextLabel::New("Test large text");
2127   largeTextLabel.SetName("TextLabel-Large");
2128   control.Add( largeTextLabel );
2129
2130   // Ensure layouting happens
2131   application.SendNotification();
2132   application.Render();
2133
2134   tet_infoline("Test text is it's natural size");
2135   DALI_TEST_EQUALS( textLabel.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 230.0f, 64.0f, 0.0f ), 0.0001f, TEST_LOCATION );
2136   tet_infoline("Test text is centered in the control, the control is the size of the largest child");
2137   DALI_TEST_EQUALS( textLabel.GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
2138
2139   tet_infoline("Test large text is it's natural size");
2140   DALI_TEST_EQUALS( largeTextLabel.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 382.0f, 64.0f, 0.0f ), 0.0001f, TEST_LOCATION );
2141   tet_infoline("Test text is aligned to start as is the size of the control");
2142   DALI_TEST_EQUALS( largeTextLabel.GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
2143
2144   tet_infoline("Test control is width of it's parent and height of it's largest child");
2145   DALI_TEST_EQUALS( control.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 382.0f, 64.0f, 0.0f ), 0.0001f, TEST_LOCATION );
2146
2147   END_TEST;
2148 }
2149
2150 int UtcDaliLayouting_LayoutGroup03(void)
2151 {
2152   ToolkitTestApplication application;
2153   tet_infoline("UtcDaliLayouting_LayoutGroup03 - Test control witha LayoutGroup as a leaf");
2154
2155   Control rootControl;
2156   SetupRootLayoutControl( rootControl );
2157
2158   // Create a parent layout
2159   auto hbox = Control::New();
2160   auto hboxLayout = LinearLayout::New();
2161   hbox.SetName( "HBox");
2162   rootControl.Add( hbox );
2163   DevelControl::SetLayout( hbox, hboxLayout );
2164   hbox.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION, 600 );
2165   hbox.SetProperty( LayoutItem::ChildProperty::HEIGHT_SPECIFICATION,  ChildLayoutData::WRAP_CONTENT );
2166   hbox.SetAnchorPoint( AnchorPoint::TOP_LEFT );  // LinearLayout will eventually do this internally.
2167
2168   tet_infoline("Add a control without SetLayout being called");
2169
2170   auto control = Control::New();
2171   control.SetName("Control1");
2172   hbox.Add( control );
2173   control.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
2174   control.SetProperty( LayoutItem::ChildProperty::HEIGHT_SPECIFICATION,  100 );
2175
2176   // Ensure layouting happens
2177   application.SendNotification();
2178   application.Render();
2179
2180   tet_infoline("Test control is width of it's parent and exact given height");
2181   DALI_TEST_EQUALS( control.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 600.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
2182   DALI_TEST_EQUALS( control.GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
2183
2184   END_TEST;
2185 }
2186
2187 int UtcDaliLayouting_LayoutGroupWithPadding01(void)
2188 {
2189   ToolkitTestApplication application;
2190   tet_infoline("UtcDaliLayouting_LayoutGroupWithPadding01 - Test adding a control to a layout that has padding");
2191
2192   Control rootControl;
2193   SetupRootLayoutControl( rootControl );
2194
2195   // Create a parent layout
2196   auto hbox = Control::New();
2197   auto hboxLayout = LinearLayout::New();
2198   hbox.SetName( "HBox");
2199   rootControl.Add( hbox );
2200   DevelControl::SetLayout( hbox, hboxLayout );
2201   hbox.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION, 600 );
2202   hbox.SetProperty( LayoutItem::ChildProperty::HEIGHT_SPECIFICATION,  ChildLayoutData::WRAP_CONTENT );
2203   hbox.SetAnchorPoint( AnchorPoint::TOP_LEFT );  // LinearLayout will eventually do this internally.
2204
2205   tet_infoline("Add a control without SetLayout being called");
2206
2207   auto control = Control::New();
2208   control.SetName("Control1");
2209   hbox.Add( control );
2210   control.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::WRAP_CONTENT );
2211   control.SetProperty( LayoutItem::ChildProperty::HEIGHT_SPECIFICATION,  ChildLayoutData::WRAP_CONTENT );
2212
2213   const Extents CONTROL_PADDING = Extents(5, 10, 20, 2 );
2214   tet_printf( "Adding Padding to control");
2215   control.SetProperty( Toolkit::Control::Property::PADDING, CONTROL_PADDING );
2216
2217   tet_infoline("Add a Textlabel to the control");
2218   auto textLabel = TextLabel::New("Test text");
2219   textLabel.SetName("TextLabel");
2220   control.Add( textLabel );
2221
2222   // Ensure layouting happens
2223   application.SendNotification();
2224   application.Render();
2225
2226   tet_infoline("Test text is it's natural size");
2227   DALI_TEST_EQUALS( textLabel.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 230.0f, 64.0f, 0.0f ), 0.0001f, TEST_LOCATION );
2228   tet_infoline("Test control is size of it's child and control it's own padding");
2229   DALI_TEST_EQUALS( control.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 245.0f, 86.0f, 0.0f ), 0.0001f, TEST_LOCATION );
2230
2231   END_TEST;
2232 }
2233
2234 int UtcDaliLayouting_LayoutGroupWithChildMargin01(void)
2235 {
2236   ToolkitTestApplication application;
2237   tet_infoline("UtcDaliLayouting_LayoutGroupWithChildMargin01 - Test adding a control with padding to a layout that has padding");
2238
2239   Control rootControl;
2240   SetupRootLayoutControl( rootControl );
2241
2242   // Create a parent layout
2243   auto hbox = Control::New();
2244   auto hboxLayout = LinearLayout::New();
2245   hbox.SetName( "HBox");
2246   rootControl.Add( hbox );
2247   DevelControl::SetLayout( hbox, hboxLayout );
2248   hbox.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION, 600 );
2249   hbox.SetProperty( LayoutItem::ChildProperty::HEIGHT_SPECIFICATION,  ChildLayoutData::WRAP_CONTENT );
2250   hbox.SetAnchorPoint( AnchorPoint::TOP_LEFT );  // LinearLayout will eventually do this internally.
2251
2252   tet_infoline("Add a control without SetLayout being called");
2253
2254   auto control = Control::New();
2255   control.SetName("Control1");
2256   hbox.Add( control );
2257   control.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::WRAP_CONTENT );
2258   control.SetProperty( LayoutItem::ChildProperty::HEIGHT_SPECIFICATION,  ChildLayoutData::WRAP_CONTENT );
2259
2260   const Extents CONTROL_PADDING = Extents(5, 10, 20, 2 );
2261   tet_printf( "Adding Padding to control");
2262   control.SetProperty( Toolkit::Control::Property::PADDING, CONTROL_PADDING );
2263
2264   tet_infoline("Add a Textlabel to the control");
2265   auto textLabel = TextLabel::New("Test text");
2266   const Extents CHILD_MARGIN = Extents( 10, 0, 5, 0 );
2267   textLabel.SetProperty( Toolkit::Control::Property::MARGIN, CHILD_MARGIN );
2268   textLabel.SetName("TextLabel");
2269   control.Add( textLabel );
2270
2271   // Ensure layouting happens
2272   application.SendNotification();
2273   application.Render();
2274
2275   tet_infoline("Test text is it's natural size");
2276   DALI_TEST_EQUALS( textLabel.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 230.0f, 64.0f, 0.0f ), 0.0001f, TEST_LOCATION );
2277   tet_infoline("Test control is width of it's parent and height of it's child");
2278   DALI_TEST_EQUALS( control.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 255.0f, 91.0f, 0.0f ), 0.0001f, TEST_LOCATION );
2279
2280   END_TEST;
2281 }