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