Merge "DALi Version 1.3.26" into devel/master
[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 <dali-toolkit/dali-toolkit.h>
22 #include <dali/devel-api/adaptor-framework/pixel-buffer.h>
23 #include <dali-toolkit/devel-api/image-loader/texture-manager.h>
24 #include <dali-toolkit/devel-api/controls/control-devel.h>
25 #include <dali-toolkit/devel-api/layouting/hbox-layout.h>
26 #include <dali-toolkit/devel-api/layouting/vbox-layout.h>
27 //#include <dali-toolkit/internal/controls/control/control-data-impl-debug.h>
28
29 using namespace Dali;
30 using namespace Toolkit;
31
32 void utc_dali_toolkit_layouting_startup(void)
33 {
34   test_return_value = TET_UNDEF;
35 }
36
37 void utc_dali_toolkit_layouting_cleanup(void)
38 {
39   test_return_value = TET_PASS;
40 }
41
42
43 Control CreateLeafControl( int width, int height )
44 {
45   auto control = Control::New();
46   control.SetName( "Leaf" );
47
48   auto pixelBuffer = Devel::PixelBuffer::New( 1, 1, Pixel::RGB888 );
49   unsigned char* pixels = pixelBuffer.GetBuffer();
50   pixels[0] = 0xff;
51   pixels[1] = 0x00;
52   pixels[2] = 0x00;
53   auto texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGB888, 1, 1 );
54   auto pixelData = Devel::PixelBuffer::Convert( pixelBuffer );
55   texture.Upload( pixelData );
56   std::string url = TextureManager::AddTexture( texture );
57
58   Property::Map map;
59   map[ Visual::Property::TYPE ] = Visual::IMAGE;
60   map[ ImageVisual::Property::URL ] = url;
61   map[ ImageVisual::Property::DESIRED_WIDTH ] = (float) width;
62   map[ ImageVisual::Property::DESIRED_HEIGHT ] = (float) height;
63   control.SetProperty( Control::Property::BACKGROUND, map );
64   return control;
65 }
66
67 int UtcDaliLayouting_HboxLayout01(void)
68 {
69   ToolkitTestApplication application;
70   tet_infoline(" UtcDaliLayouting_HboxLayout01");
71
72   Stage stage = Stage::GetCurrent();
73   auto hbox = Control::New();
74   auto hboxLayout = HboxLayout::New();
75   hboxLayout.SetCellPadding( LayoutSize( 10, 0 ) );
76   DevelControl::SetLayout( hbox, hboxLayout );
77   hbox.SetName( "HBox");
78
79   std::vector< Control > controls;
80   controls.push_back( CreateLeafControl( 40, 40 ) );
81   controls.push_back( CreateLeafControl( 60, 40 ) );
82   controls.push_back( CreateLeafControl( 80, 40 ) );
83   controls.push_back( CreateLeafControl( 100, 40 ) );
84
85   for( auto&& iter : controls )
86   {
87     hbox.Add( iter );
88   }
89   hbox.SetParentOrigin( ParentOrigin::CENTER );
90   hbox.SetAnchorPoint( AnchorPoint::CENTER );
91   stage.Add( hbox );
92
93   // Ensure layouting happens
94   application.SendNotification();
95   application.Render();
96
97   // hbox centers elements vertically, it fills test harness stage, which is 480x800.
98   // hbox left justifies elements
99   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 380.0f, 0.0f ), 0.0001f, TEST_LOCATION );
100   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 50.0f, 380.0f, 0.0f ), 0.0001f, TEST_LOCATION );
101   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 120.0f, 380.0f, 0.0f ), 0.0001f, TEST_LOCATION );
102   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 210.0f, 380.0f, 0.0f ), 0.0001f, TEST_LOCATION );
103
104   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
105   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 60.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
106   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 80.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
107   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
108
109   END_TEST;
110 }
111
112
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 = HboxLayout::New();
124   DevelControl::SetLayout( hbox1, hboxLayout1 );
125
126   auto hbox2 = Control::New();
127   auto hboxLayout2 = HboxLayout::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 = HboxLayout::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 = HboxLayout::New();
224   DevelControl::SetLayout( hbox1, hboxLayout1 );
225
226   auto hbox2 = Control::New();
227   auto hboxLayout2 = HboxLayout::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 = HboxLayout::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
321
322
323 int UtcDaliLayouting_HboxLayout04(void)
324 {
325   ToolkitTestApplication application;
326   tet_infoline(" UtcDaliLayouting_HboxLayout04 Test nested hboxes with explicit WRAP_CONTENT");
327
328   Stage stage = Stage::GetCurrent();
329
330   auto hbox1 = Control::New();
331   auto hboxLayout1 = HboxLayout::New();
332   DevelControl::SetLayout( hbox1, hboxLayout1 );
333
334   auto hbox2 = Control::New();
335   auto hboxLayout2 = HboxLayout::New();
336   DevelControl::SetLayout( hbox2, hboxLayout2 );
337
338   hbox1.SetName( "HBox1"); // Default spec is to wrap content
339   hbox2.SetName( "HBox2");
340   hbox1.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::WRAP_CONTENT );
341   hbox1.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::WRAP_CONTENT );
342   hbox2.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::WRAP_CONTENT );
343   hbox2.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::WRAP_CONTENT );
344
345   std::vector< Control > controls;
346   controls.push_back( CreateLeafControl( 80, 40 ) );
347   controls.push_back( CreateLeafControl( 80, 50 ) );
348   controls.push_back( CreateLeafControl( 80, 60 ) );
349   controls.push_back( CreateLeafControl( 80, 70 ) );
350
351   controls.push_back( CreateLeafControl( 80, 40 ) );
352   controls.push_back( CreateLeafControl( 80, 50 ) );
353   controls.push_back( CreateLeafControl( 80, 60 ) );
354   controls.push_back( CreateLeafControl( 80, 70 ) );
355
356   int counter=0;
357   for( auto&& iter : controls )
358   {
359     if( counter < 4 )
360     {
361       hbox1.Add( iter );
362     }
363     else
364     {
365       hbox2.Add( iter );
366     }
367     ++counter;
368   }
369
370   controls[6].SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
371   auto hbox3 = Control::New();
372   auto hboxLayout3 = HboxLayout::New();
373   DevelControl::SetLayout( hbox3, hboxLayout3 );
374
375   hbox3.SetParentOrigin( ParentOrigin::CENTER );
376   hbox3.SetName( "HBox3");
377   hbox3.Add( hbox1 );
378   hbox3.Add( hbox2 );
379   stage.Add( hbox3 );
380
381   //std::ostringstream oss;
382   //DumpControlHierarchy( oss, Stage::GetCurrent().GetRootLayer() );
383   //printf("Control hierarchy: \n%s\n", oss.str().c_str() );
384
385   // Ensure layouting happens
386   application.SendNotification();
387   application.Render();
388
389
390   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 15.0f, 0.0f ), 0.0001f, TEST_LOCATION );
391   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 80.0f,10.0f, 0.0f ), 0.0001f, TEST_LOCATION );
392   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 160.0f, 5.0f, 0.0f ), 0.0001f, TEST_LOCATION );
393   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 240.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
394
395   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 80.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
396   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 80.0f, 50.0f, 0.0f ), 0.0001f, TEST_LOCATION );
397   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 80.0f, 60.0f, 0.0f ), 0.0001f, TEST_LOCATION );
398   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 80.0f, 70.0f, 0.0f ), 0.0001f, TEST_LOCATION );
399
400   DALI_TEST_EQUALS( controls[4].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3(  0.0f, 15.0f, 0.0f ), 0.0001f, TEST_LOCATION );
401   DALI_TEST_EQUALS( controls[5].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 80.0f, 10.0f, 0.0f ), 0.0001f, TEST_LOCATION );
402   DALI_TEST_EQUALS( controls[6].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 160.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
403   DALI_TEST_EQUALS( controls[7].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 240.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
404
405   DALI_TEST_EQUALS( controls[4].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 80.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
406   DALI_TEST_EQUALS( controls[5].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 80.0f, 50.0f, 0.0f ), 0.0001f, TEST_LOCATION );
407   DALI_TEST_EQUALS( controls[6].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 80.0f, 70.0f, 0.0f ), 0.0001f, TEST_LOCATION );
408   DALI_TEST_EQUALS( controls[7].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 80.0f, 70.0f, 0.0f ), 0.0001f, TEST_LOCATION );
409
410   DALI_TEST_EQUALS( hbox1.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 320.0f, 70.0f, 0.0f ), 0.0001f, TEST_LOCATION );
411   DALI_TEST_EQUALS( hbox2.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 320.0f, 70.0f, 0.0f ), 0.0001f, TEST_LOCATION );
412   DALI_TEST_EQUALS( hbox1.GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 365.0f, 0.0f ), 0.0001f, TEST_LOCATION );
413   DALI_TEST_EQUALS( hbox2.GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 320.0f, 365.0f, 0.0f ), 0.0001f, TEST_LOCATION );
414
415
416   // Test hbox3 matches parent (root layer)
417   DALI_TEST_EQUALS( hbox3.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 480.0f, 800.0f, 0.0f ), 0.0001f, TEST_LOCATION );
418   DALI_TEST_EQUALS( hbox3.GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
419
420   END_TEST;
421 }
422
423
424 int UtcDaliLayouting_VboxLayout01(void)
425 {
426   ToolkitTestApplication application;
427   tet_infoline(" UtcDaliLayouting_VboxLayout01");
428
429   Stage stage = Stage::GetCurrent();
430   auto vbox = Control::New();
431   auto vboxLayout = VboxLayout::New();
432   DevelControl::SetLayout( vbox, vboxLayout );
433   vbox.SetName( "Vbox");
434
435   std::vector< Control > controls;
436   controls.push_back( CreateLeafControl( 40, 40 ) );
437   controls.push_back( CreateLeafControl( 60, 60 ) );
438   controls.push_back( CreateLeafControl( 80, 80 ) );
439   controls.push_back( CreateLeafControl( 100, 100 ) );
440
441   for( auto&& iter : controls )
442   {
443     vbox.Add( iter );
444   }
445   vbox.SetParentOrigin( ParentOrigin::CENTER );
446   vbox.SetAnchorPoint( AnchorPoint::CENTER );
447   stage.Add( vbox );
448
449   controls[2].SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
450
451   // Check it.
452   DALI_TEST_EQUALS( controls[2].GetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION ), Property::Value( ChildLayoutData::MATCH_PARENT ), TEST_LOCATION );
453
454   // Ensure layouting happens
455   application.SendNotification();
456   application.Render();
457
458   // vbox centers elements horizontally, it fills test harness stage, which is 480x800.
459   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 220.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
460   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 210.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
461   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
462   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 190.0f, 180.0f, 0.0f ), 0.0001f, TEST_LOCATION );
463
464   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
465   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 60.0f, 60.0f, 0.0f ), 0.0001f, TEST_LOCATION );
466   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 480.0f, 80.0f, 0.0f ), 0.0001f, TEST_LOCATION );
467   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
468
469   END_TEST;
470 }
471
472 int UtcDaliLayouting_VboxLayout02(void)
473 {
474   ToolkitTestApplication application;
475   tet_infoline(" UtcDaliLayouting_VboxLayout01");
476
477   Stage stage = Stage::GetCurrent();
478
479   // @todo Can't set specification properties on root control. Really need to make LayoutController a root
480   // LayoutGroup for this to happen automatically.
481   //
482   // For this test, add an hbox instead
483   auto hbox = Control::New();
484   auto hboxLayout = HboxLayout::New();
485   DevelControl::SetLayout( hbox, hboxLayout );
486   hbox.SetName( "Hbox");
487   stage.Add( hbox );
488
489   auto vbox = Control::New();
490   auto vboxLayout = VboxLayout::New();
491   DevelControl::SetLayout( vbox, vboxLayout );
492   vbox.SetName( "Vbox");
493   hbox.Add( vbox );
494
495   vbox.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::WRAP_CONTENT );
496   vbox.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
497
498   std::vector< Control > controls;
499   controls.push_back( CreateLeafControl( 40, 40 ) );
500   controls.push_back( CreateLeafControl( 60, 60 ) );
501   controls.push_back( CreateLeafControl( 80, 80 ) );
502   controls.push_back( CreateLeafControl( 100, 100 ) );
503
504   for( auto&& iter : controls )
505   {
506     vbox.Add( iter );
507   }
508   vbox.SetParentOrigin( ParentOrigin::CENTER );
509   vbox.SetAnchorPoint( AnchorPoint::CENTER );
510
511   controls[2].SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
512
513   // Check it.
514   DALI_TEST_EQUALS( controls[2].GetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION ), Property::Value( ChildLayoutData::MATCH_PARENT ), TEST_LOCATION );
515
516   // Ensure layouting happens
517   application.SendNotification();
518   application.Render();
519
520   DALI_TEST_EQUALS( hbox.GetProperty<Vector3>(Actor::Property::POSITION), Vector3(0,0,0),TEST_LOCATION);
521   DALI_TEST_EQUALS( hbox.GetProperty<Vector3>(Actor::Property::SIZE), Vector3(480,800,0),TEST_LOCATION);
522
523   // vbox centers elements horizontally, it should wrap it's content horizontally, i.e. it should take the width of the largest element (100)
524   DALI_TEST_EQUALS( vbox.GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
525   DALI_TEST_EQUALS( vbox.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 800.0f, 0.0f ), 0.0001f, TEST_LOCATION );
526
527   // 3rd control is set to match parent - this should also be 100 wide
528   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 30.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
529   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 20.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
530   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
531   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 180.0f, 0.0f ), 0.0001f, TEST_LOCATION );
532
533   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
534   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 60.0f, 60.0f, 0.0f ), 0.0001f, TEST_LOCATION );
535   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 80.0f, 0.0f ), 0.0001f, TEST_LOCATION );
536   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
537
538   END_TEST;
539 }
540
541
542 int UtcDaliLayouting_VboxLayout03(void)
543 {
544   ToolkitTestApplication application;
545   tet_infoline(" UtcDaliLayouting_VboxLayout03 test with cell padding set");
546
547   Stage stage = Stage::GetCurrent();
548
549   // @todo Can't set specification properties on root control. Really need to make LayoutController a root
550   // LayoutGroup for this to happen automatically.
551   //
552   // For this test, add an hbox instead
553   auto hbox = Control::New();
554   auto hboxLayout = HboxLayout::New();
555   DevelControl::SetLayout( hbox, hboxLayout );
556   hbox.SetName( "Hbox");
557   stage.Add( hbox );
558
559   auto vbox = Control::New();
560   auto vboxLayout = VboxLayout::New();
561   vboxLayout.SetCellPadding( LayoutSize( 0, 10 ) );
562
563   DALI_TEST_EQUALS( vboxLayout.GetCellPadding(), LayoutSize( 0, 10 ), TEST_LOCATION );
564
565   DevelControl::SetLayout( vbox, vboxLayout );
566   vbox.SetName( "Vbox");
567   hbox.Add( vbox );
568
569   vbox.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::WRAP_CONTENT );
570   vbox.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
571
572   std::vector< Control > controls;
573   controls.push_back( CreateLeafControl( 40, 40 ) );
574   controls.push_back( CreateLeafControl( 60, 60 ) );
575   controls.push_back( CreateLeafControl( 80, 80 ) );
576   controls.push_back( CreateLeafControl( 100, 100 ) );
577
578   for( auto&& iter : controls )
579   {
580     vbox.Add( iter );
581   }
582   vbox.SetParentOrigin( ParentOrigin::CENTER );
583   vbox.SetAnchorPoint( AnchorPoint::CENTER );
584
585   controls[2].SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
586
587   // Check it.
588   DALI_TEST_EQUALS( controls[2].GetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION ), Property::Value( ChildLayoutData::MATCH_PARENT ), TEST_LOCATION );
589
590   // Ensure layouting happens
591   application.SendNotification();
592   application.Render();
593
594   DALI_TEST_EQUALS( hbox.GetProperty<Vector3>(Actor::Property::POSITION), Vector3(0,0,0),TEST_LOCATION);
595   DALI_TEST_EQUALS( hbox.GetProperty<Vector3>(Actor::Property::SIZE), Vector3(480,800,0),TEST_LOCATION);
596
597   // vbox centers elements horizontally, it should wrap it's content horizontally, i.e. it should take the width of the largest element (100)
598   DALI_TEST_EQUALS( vbox.GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
599   DALI_TEST_EQUALS( vbox.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 800.0f, 0.0f ), 0.0001f, TEST_LOCATION );
600
601   // 3rd control is set to match parent - this should also be 100 wide
602   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 30.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
603   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 20.0f, 50.0f, 0.0f ), 0.0001f, TEST_LOCATION );
604   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 120.0f, 0.0f ), 0.0001f, TEST_LOCATION );
605   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 210.0f, 0.0f ), 0.0001f, TEST_LOCATION );
606
607   DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
608   DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 60.0f, 60.0f, 0.0f ), 0.0001f, TEST_LOCATION );
609   DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 80.0f, 0.0f ), 0.0001f, TEST_LOCATION );
610   DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
611
612   END_TEST;
613 }