Add child flex node with its margin
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-FlexNode.cpp
1 /*
2  * Copyright (c) 2019 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/actors/actor-devel.h>
23 #include <dali-toolkit/devel-api/layouting/flex-node.h>
24
25 using namespace Dali;
26 using namespace Toolkit;
27
28 void dali_flexNodeContainer_startup(void)
29 {
30   test_return_value = TET_UNDEF;
31 }
32
33 void dali_flexNodeContainer_cleanup(void)
34 {
35   test_return_value = TET_PASS;
36 }
37
38 namespace
39 {
40
41 const Flex::SizeTuple ITEM_SIZE = Flex::SizeTuple{ 10.0f, 10.0f };
42 const Flex::SizeTuple ITEM_SIZE_CALLBACK_TEST = Flex::SizeTuple{ 15.0f, 15.0f };
43
44 Flex::SizeTuple MeasureChild( Actor child, float width, int measureModeWidth, float height, int measureModeHeight)
45 {
46   Flex::SizeTuple childSize = ITEM_SIZE;
47   if (child.GetName() == "callbackTest")
48   {
49     childSize = ITEM_SIZE_CALLBACK_TEST;
50   }
51   tet_printf(" MeasureChild test callback executed (%f,%f)\n", childSize.width, childSize.height );
52   return childSize;
53 }
54
55 }
56
57 int UtcDaliToolkitFlexNodeConstructorP(void)
58 {
59   ToolkitTestApplication application;
60   tet_infoline(" UtcDaliToolkitFlexNodeNewP");
61   Flex::Node* flexNode = new Flex::Node();
62   DALI_TEST_CHECK( flexNode );
63   END_TEST;
64 }
65
66 int UtcDaliToolkitFlexNodeAddChildWithMarginP(void)
67 {
68   ToolkitTestApplication application;
69   tet_infoline(" UtcDaliToolkitFlexNodeAddChildWithMarginP");
70   Flex::Node* flexNode = new Flex::Node();
71   DALI_TEST_CHECK( flexNode );
72
73   // Position elements as a Row
74   flexNode->SetFlexDirection(Flex::FlexDirection::ROW);
75
76   // Create two actors and add them to the parent flex node
77   Actor actor = Actor::New();
78   DALI_TEST_CHECK( actor );
79
80   Extents margin( 5,5,5,5);
81   flexNode->AddChild(actor, margin, &MeasureChild, 0);
82
83   DALI_TEST_EQUALS( (int)flexNode->GetFlexDirection(), (int)Flex::FlexDirection::ROW, TEST_LOCATION );
84
85   flexNode->CalculateLayout(480, 800, false);
86
87   Vector4 actorFrame = flexNode->GetNodeFrame(0);
88
89   tet_printf("Actor frame(left:%f,top:%f,right:%f,bottom:%f)\n", actorFrame.x, actorFrame.y, actorFrame.z, actorFrame.w);
90
91   DALI_TEST_EQUALS( actorFrame, Vector4( 5.0f, 5.0f, ITEM_SIZE.width+5, ITEM_SIZE.height+5 ), TEST_LOCATION );
92
93   END_TEST;
94 }
95
96 int UtcDaliToolkitFlexNodeAddChildrenRowP(void)
97 {
98   ToolkitTestApplication application;
99   tet_infoline(" UtcDaliToolkitFlexNodeAddChildrenRowP");
100   Flex::Node* flexNode = new Flex::Node();
101   DALI_TEST_CHECK( flexNode );
102
103   // Position elements as a Row
104   flexNode->SetFlexDirection(Flex::FlexDirection::ROW);
105
106   // Create two actors and add them to the parent flex node
107   Actor actor1 = Actor::New();
108   Actor actor2 = Actor::New();
109   DALI_TEST_CHECK( actor1 );
110   DALI_TEST_CHECK( actor2 );
111
112   flexNode->AddChild(actor1, Extents(0,0,0,0), &MeasureChild, 0);
113   flexNode->AddChild(actor2, Extents(0,0,0,0), &MeasureChild, 1);
114
115   DALI_TEST_EQUALS( (int)flexNode->GetFlexDirection(), (int)Flex::FlexDirection::ROW, TEST_LOCATION );
116
117   flexNode->CalculateLayout(480, 800, false);
118
119   Vector4 actor1Frame = flexNode->GetNodeFrame(0);
120   Vector4 actor2Frame = flexNode->GetNodeFrame(1);
121
122   tet_printf("Actor 1 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor1Frame.x, actor1Frame.y, actor1Frame.z, actor1Frame.w);
123   tet_printf("Actor 2 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor2Frame.x, actor2Frame.y, actor2Frame.z, actor2Frame.w);
124
125   DALI_TEST_EQUALS( actor1Frame, Vector4( 0.0f, 0.0f, ITEM_SIZE.width, ITEM_SIZE.height ), TEST_LOCATION );
126   DALI_TEST_EQUALS( actor2Frame, Vector4( ITEM_SIZE.width, 0.0f, ITEM_SIZE.width * 2, ITEM_SIZE.height ), TEST_LOCATION );
127
128   END_TEST;
129 }
130
131 int UtcDaliToolkitFlexNodeAddChildrenColumnP(void)
132 {
133   ToolkitTestApplication application;
134   tet_infoline("UtcDaliToolkitFlexNodeAddChildrenColumnP");
135   Flex::Node* flexNode = new Flex::Node();
136   DALI_TEST_CHECK( flexNode );
137
138   // Position elements in a Column
139   flexNode->SetFlexDirection(Flex::FlexDirection::COLUMN);
140
141   // Create two actors and add them to the parent flex node
142   Actor actor1 = Actor::New();
143   Actor actor2 = Actor::New();
144   DALI_TEST_CHECK( actor1 );
145   DALI_TEST_CHECK( actor2 );
146
147   flexNode->AddChild(actor1, Extents(0,0,0,0), &MeasureChild, 0);
148   flexNode->AddChild(actor2, Extents(0,0,0,0), &MeasureChild, 1);
149
150   flexNode->CalculateLayout(480, 800, false);
151
152   Vector4 root = flexNode->GetNodeFrame(-1); // -1 is the root
153   Vector4 actor1Frame = flexNode->GetNodeFrame(0); // 0 is first child
154   Vector4 actor2Frame = flexNode->GetNodeFrame(1); // 1 is second child
155
156   tet_printf("Root frame(left:%f,top:%f,right:%f,bottom:%f)\n", root.x, root.y, root.z, root.w);
157
158   tet_printf("Actor 1 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor1Frame.x, actor1Frame.y, actor1Frame.z, actor1Frame.w);
159   tet_printf("Actor 2 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor2Frame.x, actor2Frame.y, actor2Frame.z, actor2Frame.w);
160
161   DALI_TEST_EQUALS( actor1Frame, Vector4( 0.0f, 0.0f, ITEM_SIZE.width, ITEM_SIZE.height ), TEST_LOCATION );
162   DALI_TEST_EQUALS( actor2Frame, Vector4( 0.0f, ITEM_SIZE.height, ITEM_SIZE.width, ITEM_SIZE.height *2 ), TEST_LOCATION );
163
164   END_TEST;
165 }
166
167
168 int UtcDaliToolkitFlexNodeAddChildrenColumnJustify(void)
169 {
170   ToolkitTestApplication application;
171   tet_infoline("UtcDaliToolkitFlexNodeAddChildrenColumnJustify");
172   Flex::Node* flexNode = new Flex::Node();
173   DALI_TEST_CHECK( flexNode );
174
175   // Position elements in a Column
176   flexNode->SetFlexDirection(Flex::FlexDirection::COLUMN);
177
178   tet_infoline("Justify to the Start, align to start");
179   flexNode->SetFlexJustification(Flex::Justification::FLEX_START);
180   flexNode->SetFlexItemsAlignment( Flex::Alignment::FLEX_START );
181
182   // Create two actors and add them to the parent flex node
183   Actor actor1 = Actor::New();
184   Actor actor2 = Actor::New();
185   DALI_TEST_CHECK( actor1 );
186   DALI_TEST_CHECK( actor2 );
187
188   DALI_TEST_EQUALS( (int)flexNode->GetFlexJustification(), (int)Flex::Justification::FLEX_START, TEST_LOCATION );
189   DALI_TEST_EQUALS( (int)flexNode->GetFlexItemsAlignment(), (int)Flex::Alignment::FLEX_START, TEST_LOCATION );
190
191   flexNode->AddChild(actor1, Extents(0,0,0,0), &MeasureChild, 0);
192   flexNode->AddChild(actor2, Extents(0,0,0,0), &MeasureChild, 1);
193
194   flexNode->CalculateLayout(480, 800, false);
195
196   Vector4 root = flexNode->GetNodeFrame(-1); // -1 is the root
197   Vector4 actor1Frame = flexNode->GetNodeFrame(0); // 0 is first child
198   Vector4 actor2Frame = flexNode->GetNodeFrame(1); // 1 is second child
199
200   tet_printf("Root frame(left:%f,top:%f,right:%f,bottom:%f)\n", root.x, root.y, root.z, root.w);
201
202   tet_printf("Actor 1 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor1Frame.x, actor1Frame.y, actor1Frame.z, actor1Frame.w);
203   tet_printf("Actor 2 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor2Frame.x, actor2Frame.y, actor2Frame.z, actor2Frame.w);
204
205   /*
206     ---------
207     |1      |
208     |2      |
209     |       |
210     |       |
211     |       |
212     ---------
213   */
214
215   DALI_TEST_EQUALS( actor1Frame, Vector4( 0.0f, 0.0f, ITEM_SIZE.width, ITEM_SIZE.height ), TEST_LOCATION );
216   DALI_TEST_EQUALS( actor2Frame, Vector4( 0.0f, ITEM_SIZE.height, ITEM_SIZE.width, ITEM_SIZE.height *2 ), TEST_LOCATION );
217
218   tet_infoline(" Justify to the End, items should now be displayed at the bottom");
219   flexNode->SetFlexJustification( Flex::Justification::FLEX_END );
220   flexNode->SetFlexItemsAlignment( Flex::Alignment::FLEX_START );
221
222   // Recalulate layout
223   flexNode->CalculateLayout(480, 800, false);
224
225   root = flexNode->GetNodeFrame(-1); // -1 is the root
226   actor1Frame = flexNode->GetNodeFrame(0); // 0 is first child
227   actor2Frame = flexNode->GetNodeFrame(1); // 1 is second child
228
229   tet_printf("Root frame(left:%f,top:%f,right:%f,bottom:%f)\n", root.x, root.y, root.z, root.w);
230
231   tet_printf("Actor 1 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor1Frame.x, actor1Frame.y, actor1Frame.z, actor1Frame.w);
232   tet_printf("Actor 2 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor2Frame.x, actor2Frame.y, actor2Frame.z, actor2Frame.w);
233
234   /*
235     ---------
236     |       |
237     |       |
238     |       |
239     |1      |
240     |2      |
241     ---------
242   */
243
244   DALI_TEST_EQUALS( actor1Frame, Vector4( 0.0f, root.w - (ITEM_SIZE.height*2), ITEM_SIZE.width,  root.w - ITEM_SIZE.height ), TEST_LOCATION );
245   DALI_TEST_EQUALS( actor2Frame, Vector4( 0.0f, root.w - ITEM_SIZE.height, ITEM_SIZE.width, root.w ), TEST_LOCATION );
246
247   tet_infoline(" Align to End, items should now be displayed at the bottom and the end");
248   flexNode->SetFlexJustification( Flex::Justification::FLEX_END );
249   flexNode->SetFlexItemsAlignment( Flex::Alignment::FLEX_END );
250   // Recalulate layout
251   flexNode->CalculateLayout(480, 800, false);
252
253   root = flexNode->GetNodeFrame(-1); // -1 is the root
254   actor1Frame = flexNode->GetNodeFrame(0); // 0 is first child
255   actor2Frame = flexNode->GetNodeFrame(1); // 1 is second child
256
257   tet_printf("Actor 1 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor1Frame.x, actor1Frame.y, actor1Frame.z, actor1Frame.w);
258   tet_printf("Actor 2 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor2Frame.x, actor2Frame.y, actor2Frame.z, actor2Frame.w);
259
260   /*
261     ---------
262     |       |
263     |       |
264     |       |
265     |      1|
266     |      2|
267     ---------
268   */
269
270   DALI_TEST_EQUALS( actor1Frame, Vector4( root.z - ITEM_SIZE.width, root.w - (ITEM_SIZE.height*2), root.z,  root.w - ITEM_SIZE.height ), TEST_LOCATION );
271   DALI_TEST_EQUALS( actor2Frame, Vector4( root.z - ITEM_SIZE.width, root.w - ITEM_SIZE.height, root.z, root.w ), TEST_LOCATION );
272
273   END_TEST;
274 }
275
276 int UtcDaliToolkitFlexNodeSizingP(void)
277 {
278   ToolkitTestApplication application;
279   tet_infoline(" UtcDaliToolkitFlexNodeSizingP");
280   Flex::Node* flexNode = new Flex::Node();
281   DALI_TEST_CHECK( flexNode );
282
283   // Create two actors and add them to the parent flex node
284   Actor actor1 = Actor::New();
285   Actor actor2 = Actor::New();
286   DALI_TEST_CHECK( actor1 );
287   DALI_TEST_CHECK( actor2 );
288
289   flexNode->AddChild(actor1, Extents(0,0,0,0), &MeasureChild, 0);
290   flexNode->AddChild(actor2, Extents(0,0,0,0), &MeasureChild, 1);
291
292   flexNode->CalculateLayout(480, 800, false);
293
294   DALI_TEST_EQUALS( flexNode->GetFlexWidth(), 480.0f, TEST_LOCATION );
295   DALI_TEST_EQUALS( flexNode->GetFlexHeight(), 800.0f, TEST_LOCATION );
296
297   END_TEST;
298 }
299
300 int UtcDaliToolkitFlexNodeWrapModeP(void)
301 {
302   ToolkitTestApplication application;
303   tet_infoline("UtcDaliToolkitFlexNodeWrapModeP");
304   Flex::Node* flexNode = new Flex::Node();
305   DALI_TEST_CHECK( flexNode );
306
307   // Position elements in a Column
308   flexNode->SetFlexDirection( Flex::FlexDirection::ROW );
309   flexNode->SetFlexAlignment( Flex::Alignment::FLEX_START );
310   flexNode->SetFlexWrap( Flex::WrapType::NO_WRAP );
311
312   // Create two actors and add them to the parent flex node
313   Actor actor1 = Actor::New();
314   Actor actor2 = Actor::New();
315   Actor actor3 = Actor::New();
316   Actor actor4 = Actor::New();
317
318   DALI_TEST_EQUALS( (int)flexNode->GetFlexJustification(), (int)Flex::Justification::FLEX_START, TEST_LOCATION );
319   DALI_TEST_EQUALS( (int)flexNode->GetFlexItemsAlignment(), (int)Flex::Alignment::FLEX_START, TEST_LOCATION );
320   DALI_TEST_EQUALS( (int)flexNode->GetFlexAlignment(), (int)Flex::Alignment::FLEX_START, TEST_LOCATION );
321   DALI_TEST_EQUALS( (int)flexNode->GetFlexWrap(), (int)Flex::WrapType::NO_WRAP, TEST_LOCATION );
322
323   flexNode->AddChild( actor1, Extents(0,0,0,0), &MeasureChild, 0 );
324   flexNode->AddChild( actor2, Extents(0,0,0,0), &MeasureChild, 1 );
325   flexNode->AddChild( actor2, Extents(0,0,0,0), &MeasureChild, 2 );
326   flexNode->AddChild( actor2, Extents(0,0,0,0), &MeasureChild, 3 );
327
328   flexNode->CalculateLayout(30, 800, false);
329
330   Vector4 root = flexNode->GetNodeFrame(-1); // -1 is the root
331   Vector4 actor1Frame = flexNode->GetNodeFrame(0); // 0 is first child
332   Vector4 actor2Frame = flexNode->GetNodeFrame(1); // 1 is second child
333   Vector4 actor3Frame = flexNode->GetNodeFrame(2); // 2 is first child
334   Vector4 actor4Frame = flexNode->GetNodeFrame(3); // 3 is second child
335
336   tet_printf("Root frame(left:%f,top:%f,right:%f,bottom:%f)\n", root.x, root.y, root.z, root.w);
337   tet_printf("Actor 1 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor1Frame.x, actor1Frame.y, actor1Frame.z, actor1Frame.w);
338   tet_printf("Actor 2 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor2Frame.x, actor2Frame.y, actor2Frame.z, actor2Frame.w);
339   tet_printf("Actor 3 frame(left:%f,top:%f,right:cdt%f,bottom:%f)\n", actor3Frame.x, actor3Frame.y, actor3Frame.z, actor3Frame.w);
340   tet_printf("Actor 4 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor4Frame.x, actor4Frame.y, actor4Frame.z, actor4Frame.w);
341
342   /*
343     -------
344     |1 2 3 4     |
345     |     |
346     |     |
347     |     |
348     |     |
349     -------
350   */
351
352   DALI_TEST_EQUALS( actor1Frame, Vector4( 0.0f,            0.0f, ITEM_SIZE.width, ITEM_SIZE.height ), TEST_LOCATION );
353   DALI_TEST_EQUALS( actor2Frame, Vector4( ITEM_SIZE.width, 0.0f, ITEM_SIZE.width*2, ITEM_SIZE.height ), TEST_LOCATION );
354   DALI_TEST_EQUALS( actor3Frame, Vector4( ITEM_SIZE.width*2, 0.0f, ITEM_SIZE.width*3, ITEM_SIZE.height ), TEST_LOCATION );
355   DALI_TEST_EQUALS( actor4Frame, Vector4( ITEM_SIZE.width*3, 0.0f, ITEM_SIZE.width*4, ITEM_SIZE.height ), TEST_LOCATION );
356
357   flexNode->SetFlexWrap( Flex::WrapType::WRAP );
358
359   flexNode->CalculateLayout( 30, 800, false );
360   root = flexNode->GetNodeFrame(-1); // -1 is the root
361
362   DALI_TEST_EQUALS( (int)flexNode->GetFlexWrap(), (int)Flex::WrapType::WRAP, TEST_LOCATION );
363   tet_printf("Root frame(left:%f,top:%f,right:%f,bottom:%f)\n", root.x, root.y, root.z, root.w);
364
365   actor1Frame = flexNode->GetNodeFrame(0); // 0 is first child
366   actor2Frame = flexNode->GetNodeFrame(1); // 1 is second child
367   actor3Frame = flexNode->GetNodeFrame(2); // 2 is first child
368   actor4Frame = flexNode->GetNodeFrame(3); // 3 is second child
369
370   tet_printf("Actor 1 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor1Frame.x, actor1Frame.y, actor1Frame.z, actor1Frame.w);
371   tet_printf("Actor 2 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor2Frame.x, actor2Frame.y, actor2Frame.z, actor2Frame.w);
372   tet_printf("Actor 3 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor3Frame.x, actor3Frame.y, actor3Frame.z, actor3Frame.w);
373   tet_printf("Actor 4 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor4Frame.x, actor4Frame.y, actor4Frame.z, actor4Frame.w);
374
375   /*
376     -------
377     |1 2 3|     |
378     |4    |
379     |     |
380     |     |
381     |     |
382     -------
383   */
384
385   DALI_TEST_EQUALS( actor1Frame, Vector4( 0.0f,            0.0f, ITEM_SIZE.width, ITEM_SIZE.height ), TEST_LOCATION );
386   DALI_TEST_EQUALS( actor2Frame, Vector4( ITEM_SIZE.width, 0.0f, ITEM_SIZE.width*2, ITEM_SIZE.height ), TEST_LOCATION );
387   DALI_TEST_EQUALS( actor3Frame, Vector4( ITEM_SIZE.width*2, 0.0f, ITEM_SIZE.width*3, ITEM_SIZE.height ), TEST_LOCATION );
388   DALI_TEST_EQUALS( actor4Frame, Vector4( 0.0,ITEM_SIZE.height, ITEM_SIZE.width, ITEM_SIZE.height*2 ), TEST_LOCATION );
389
390
391   END_TEST;
392 }
393
394 int UtcDaliToolkitFlexNodeRemoveChildP(void)
395 {
396   ToolkitTestApplication application;
397   tet_infoline(" UtcDaliToolkitFlexNodeRemoveChildP");
398   Flex::Node* flexNode = new Flex::Node();
399   DALI_TEST_CHECK( flexNode );
400
401   // Create two actors and add them to the parent flex node
402   Actor actor1 = Actor::New();
403   Actor actor2 = Actor::New();
404   actor1.SetName("Actor1");
405   actor2.SetName("Actor2");
406
407   DALI_TEST_CHECK( actor1 );
408   DALI_TEST_CHECK( actor2 );
409
410   flexNode->AddChild(actor1, Extents(0,0,0,0), &MeasureChild, 0);
411   flexNode->AddChild(actor2, Extents(0,0,0,0), &MeasureChild, 1);
412
413   flexNode->CalculateLayout(480, 800, false);
414
415   Vector4 actor1Frame = flexNode->GetNodeFrame(0);
416   Vector4 actor2Frame = flexNode->GetNodeFrame(1);
417
418   tet_printf("Actor 1 frame(%f,%f,%f,%f)\n", actor1Frame.x, actor1Frame.y, actor1Frame.z, actor1Frame.w);
419   tet_printf("Actor 2 frame(%f,%f,%f,%f)\n", actor2Frame.x, actor2Frame.y, actor2Frame.z, actor2Frame.w);
420
421   DALI_TEST_EQUALS( actor2Frame, Vector4( 0.0f, ITEM_SIZE.width, ITEM_SIZE.width, ITEM_SIZE.height*2 ), TEST_LOCATION );
422
423   flexNode->RemoveChild(actor1);
424
425   flexNode->CalculateLayout(480, 800, false);
426
427   actor2Frame = flexNode->GetNodeFrame(0);
428
429   tet_printf("Actor 1 frame(%f,%f,%f,%f)\n", actor1Frame.x, actor1Frame.y, actor1Frame.z, actor1Frame.w);
430   tet_printf("Actor 2 frame(%f,%f,%f,%f)\n", actor2Frame.x, actor2Frame.y, actor2Frame.z, actor2Frame.w);
431
432   DALI_TEST_EQUALS( actor2Frame, Vector4( 0.0f, 0.0f, ITEM_SIZE.width, ITEM_SIZE.height ), TEST_LOCATION );
433
434   END_TEST;
435 }
436
437 int UtcDaliToolkitFlexNodeRemoveAllChildrenP(void)
438 {
439   ToolkitTestApplication application;
440   tet_infoline(" UtcDaliToolkitFlexNodeRemoveAllChildrenP");
441   Flex::Node* flexNode = new Flex::Node();
442   DALI_TEST_CHECK( flexNode );
443
444   // Create two actors and add them to the parent flex node
445   Actor actor1 = Actor::New();
446   Actor actor2 = Actor::New();
447   actor1.SetName("Actor1");
448   actor2.SetName("Actor2");
449
450   DALI_TEST_CHECK( actor1 );
451   DALI_TEST_CHECK( actor2 );
452
453   flexNode->AddChild(actor1, Extents(0,0,0,0), &MeasureChild, 0);
454   flexNode->AddChild(actor2, Extents(0,0,0,0), &MeasureChild, 1);
455
456   flexNode->CalculateLayout(480, 800, false);
457
458   Vector4 actor1Frame = flexNode->GetNodeFrame(0);
459   Vector4 actor2Frame = flexNode->GetNodeFrame(1);
460
461   tet_printf("Actor 1 frame(%f,%f,%f,%f)\n", actor1Frame.x, actor1Frame.y, actor1Frame.z, actor1Frame.w);
462   tet_printf("Actor 2 frame(%f,%f,%f,%f)\n", actor2Frame.x, actor2Frame.y, actor2Frame.z, actor2Frame.w);
463
464   flexNode->RemoveChild(actor1);
465   flexNode->RemoveChild(actor2);
466
467   flexNode->CalculateLayout(480, 800, false);
468
469   Vector4 actor1FrameRemoved = flexNode->GetNodeFrame(0);
470   Vector4 actor2FrameRemoved = flexNode->GetNodeFrame(1);
471
472   tet_printf("Actor 1 frame(%f,%f,%f,%f)\n", actor1FrameRemoved.x, actor1FrameRemoved.y, actor1FrameRemoved.z, actor1FrameRemoved.w);
473   tet_printf("Actor 2 frame(%f,%f,%f,%f)\n", actor2FrameRemoved.x, actor2FrameRemoved.y, actor2FrameRemoved.z, actor2FrameRemoved.w);
474
475   DALI_TEST_NOT_EQUALS( actor1Frame, actor1FrameRemoved, 0.1, TEST_LOCATION );
476   DALI_TEST_NOT_EQUALS( actor2Frame, actor2FrameRemoved, 0.1, TEST_LOCATION );
477
478   END_TEST;
479 }
480
481 int UtcDaliToolkitFlexNodePaddingMarginP(void)
482 {
483   ToolkitTestApplication application;
484   tet_infoline(" UtcDaliToolkitFlexNodePaddingMarginP");
485   Flex::Node* flexNode = new Flex::Node();
486   DALI_TEST_CHECK( flexNode );
487   flexNode->SetFlexDirection( Flex::FlexDirection::ROW );
488
489   // Create two actors and add them to the parent flex node
490   Actor actor1 = Actor::New();
491   Actor actor2 = Actor::New();
492   DALI_TEST_CHECK( actor1 );
493   DALI_TEST_CHECK( actor2 );
494
495   flexNode->AddChild(actor1, Extents(0,0,0,0), &MeasureChild, 0);
496   flexNode->AddChild(actor2, Extents(0,0,0,0), &MeasureChild, 1);
497
498   Extents padding( 5,5,5,5);
499   Extents margin( 5,5,5,5);
500
501   flexNode->SetPadding( padding );
502   flexNode->SetMargin( margin );
503
504   flexNode->CalculateLayout(480, 800, false);
505
506   Vector4 actor1Frame = flexNode->GetNodeFrame(0);
507   Vector4 actor2Frame = flexNode->GetNodeFrame(1);
508
509   /*  p = padding
510   -----
511   |ppppp|
512   |p1 2p|
513   |p   p|
514   |ppppp|
515   -------
516   */
517   DALI_TEST_EQUALS( actor1Frame, Vector4( 5.0f, 5.0f, ITEM_SIZE.width +5 , ITEM_SIZE.height + 5 ), TEST_LOCATION );
518   DALI_TEST_EQUALS( actor2Frame, Vector4( 5+ ITEM_SIZE.width, 5.0f, (ITEM_SIZE.width*2) +5, ITEM_SIZE.height +5 ), TEST_LOCATION );
519
520   END_TEST;
521 }
522
523 int UtcDaliToolkitFlexNodeCallbackTestP(void)
524 {
525   ToolkitTestApplication application;
526   tet_infoline("UtcDaliToolkitFlexNodeCallbackTestP");
527   Flex::Node* flexNode = new Flex::Node();
528   DALI_TEST_CHECK( flexNode );
529
530   // Position elements in a Column
531   flexNode->SetFlexDirection(Flex::FlexDirection::COLUMN);
532
533   // Create two actors and add them to the parent flex node
534   Actor actor1 = Actor::New();
535   Actor actor2 = Actor::New();
536
537   actor1.SetName("callbackTest");
538
539   DALI_TEST_CHECK( actor1 );
540   DALI_TEST_CHECK( actor2 );
541
542   flexNode->AddChild(actor1, Extents(0,0,0,0), &MeasureChild, 0);
543   flexNode->AddChild(actor2, Extents(0,0,0,0), &MeasureChild, 1);
544
545   flexNode->CalculateLayout(480, 800, false);
546
547   Vector4 root = flexNode->GetNodeFrame(-1); // -1 is the root
548   Vector4 actor1Frame = flexNode->GetNodeFrame(0); // 0 is first child
549   Vector4 actor2Frame = flexNode->GetNodeFrame(1); // 1 is second child
550
551   tet_printf("Root frame(left:%f,top:%f,right:%f,bottom:%f)\n", root.x, root.y, root.z, root.w);
552
553   tet_printf("Actor 1 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor1Frame.x, actor1Frame.y, actor1Frame.z, actor1Frame.w);
554   tet_printf("Actor 2 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor2Frame.x, actor2Frame.y, actor2Frame.z, actor2Frame.w);
555
556   DALI_TEST_EQUALS( actor1Frame, Vector4( 0.0f, 0.0f, ITEM_SIZE_CALLBACK_TEST.width, ITEM_SIZE_CALLBACK_TEST.height ), TEST_LOCATION );
557   DALI_TEST_EQUALS( actor2Frame, Vector4( 0.0f, ITEM_SIZE_CALLBACK_TEST.height, ITEM_SIZE.width, ITEM_SIZE_CALLBACK_TEST.height + ITEM_SIZE.height ), TEST_LOCATION );
558
559   END_TEST;
560 }