Delete YGNode only root of Flex::Node
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-FlexNode.cpp
1 /*
2  * Copyright (c) 2022 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 <stdlib.h>
19 #include <iostream>
20
21 #include <dali-toolkit-test-suite-utils.h>
22
23 #include <dali-toolkit/dali-toolkit.h>
24 #include <dali-toolkit/devel-api/layouting/flex-node.h>
25 #include <dali/devel-api/actors/actor-devel.h>
26
27 using namespace Dali;
28 using namespace Toolkit;
29
30 void dali_flexNodeContainer_startup(void)
31 {
32   test_return_value = TET_UNDEF;
33 }
34
35 void dali_flexNodeContainer_cleanup(void)
36 {
37   test_return_value = TET_PASS;
38 }
39
40 namespace
41 {
42 const Flex::SizeTuple ITEM_SIZE               = Flex::SizeTuple{10.0f, 10.0f};
43 const Flex::SizeTuple ITEM_SIZE_CALLBACK_TEST = Flex::SizeTuple{15.0f, 15.0f};
44
45 void MeasureChild(Actor child, float width, int measureModeWidth, float height, int measureModeHeight, Flex::SizeTuple* childSize)
46 {
47   *childSize = ITEM_SIZE;
48   if(child.GetProperty<std::string>(Dali::Actor::Property::NAME) == "callbackTest")
49   {
50     *childSize = ITEM_SIZE_CALLBACK_TEST;
51   }
52   tet_printf(" MeasureChild test callback executed (%f,%f)\n", childSize->width, childSize->height);
53 }
54
55 } // namespace
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   delete flexNode;
94
95   END_TEST;
96 }
97
98 int UtcDaliToolkitFlexNodeAddChildrenRowP(void)
99 {
100   ToolkitTestApplication application;
101   tet_infoline(" UtcDaliToolkitFlexNodeAddChildrenRowP");
102   Flex::Node* flexNode = new Flex::Node();
103   DALI_TEST_CHECK(flexNode);
104
105   // Position elements as a Row
106   flexNode->SetFlexDirection(Flex::FlexDirection::ROW);
107
108   // Create two actors and add them to the parent flex node
109   Actor actor1 = Actor::New();
110   Actor actor2 = Actor::New();
111   DALI_TEST_CHECK(actor1);
112   DALI_TEST_CHECK(actor2);
113
114   flexNode->AddChild(actor1, Extents(0, 0, 0, 0), &MeasureChild, 0);
115   flexNode->AddChild(actor2, Extents(0, 0, 0, 0), &MeasureChild, 1);
116
117   DALI_TEST_EQUALS((int)flexNode->GetFlexDirection(), (int)Flex::FlexDirection::ROW, TEST_LOCATION);
118
119   flexNode->CalculateLayout(480, 800, false);
120
121   Vector4 actor1Frame = flexNode->GetNodeFrame(0);
122   Vector4 actor2Frame = flexNode->GetNodeFrame(1);
123
124   tet_printf("Actor 1 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor1Frame.x, actor1Frame.y, actor1Frame.z, actor1Frame.w);
125   tet_printf("Actor 2 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor2Frame.x, actor2Frame.y, actor2Frame.z, actor2Frame.w);
126
127   DALI_TEST_EQUALS(actor1Frame, Vector4(0.0f, 0.0f, ITEM_SIZE.width, ITEM_SIZE.height), TEST_LOCATION);
128   DALI_TEST_EQUALS(actor2Frame, Vector4(ITEM_SIZE.width, 0.0f, ITEM_SIZE.width * 2, ITEM_SIZE.height), TEST_LOCATION);
129
130   delete flexNode;
131
132   END_TEST;
133 }
134
135 int UtcDaliToolkitFlexNodeAddChildrenColumnP(void)
136 {
137   ToolkitTestApplication application;
138   tet_infoline("UtcDaliToolkitFlexNodeAddChildrenColumnP");
139   Flex::Node* flexNode = new Flex::Node();
140   DALI_TEST_CHECK(flexNode);
141
142   // Position elements in a Column
143   flexNode->SetFlexDirection(Flex::FlexDirection::COLUMN);
144
145   // Create two actors and add them to the parent flex node
146   Actor actor1 = Actor::New();
147   Actor actor2 = Actor::New();
148   DALI_TEST_CHECK(actor1);
149   DALI_TEST_CHECK(actor2);
150
151   flexNode->AddChild(actor1, Extents(0, 0, 0, 0), &MeasureChild, 0);
152   flexNode->AddChild(actor2, Extents(0, 0, 0, 0), &MeasureChild, 1);
153
154   flexNode->CalculateLayout(480, 800, false);
155
156   Vector4 root        = flexNode->GetNodeFrame(-1); // -1 is the root
157   Vector4 actor1Frame = flexNode->GetNodeFrame(0);  // 0 is first child
158   Vector4 actor2Frame = flexNode->GetNodeFrame(1);  // 1 is second child
159
160   tet_printf("Root frame(left:%f,top:%f,right:%f,bottom:%f)\n", root.x, root.y, root.z, root.w);
161
162   tet_printf("Actor 1 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor1Frame.x, actor1Frame.y, actor1Frame.z, actor1Frame.w);
163   tet_printf("Actor 2 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor2Frame.x, actor2Frame.y, actor2Frame.z, actor2Frame.w);
164
165   DALI_TEST_EQUALS(actor1Frame, Vector4(0.0f, 0.0f, ITEM_SIZE.width, ITEM_SIZE.height), TEST_LOCATION);
166   DALI_TEST_EQUALS(actor2Frame, Vector4(0.0f, ITEM_SIZE.height, ITEM_SIZE.width, ITEM_SIZE.height * 2), TEST_LOCATION);
167
168   delete flexNode;
169
170   END_TEST;
171 }
172
173 int UtcDaliToolkitFlexNodeAddChildrenColumnJustify(void)
174 {
175   ToolkitTestApplication application;
176   tet_infoline("UtcDaliToolkitFlexNodeAddChildrenColumnJustify");
177   Flex::Node* flexNode = new Flex::Node();
178   DALI_TEST_CHECK(flexNode);
179
180   // Position elements in a Column
181   flexNode->SetFlexDirection(Flex::FlexDirection::COLUMN);
182
183   tet_infoline("Justify to the Start, align to start, third item should be displayed at the top and the end");
184   flexNode->SetFlexJustification(Flex::Justification::FLEX_START);
185   flexNode->SetFlexItemsAlignment(Flex::Alignment::FLEX_START);
186
187   // Create three actors and add them to the parent flex node
188   Actor actor1 = Actor::New();
189   Actor actor2 = Actor::New();
190   Actor actor3 = Actor::New();
191   DALI_TEST_CHECK(actor1);
192   DALI_TEST_CHECK(actor2);
193   DALI_TEST_CHECK(actor3);
194
195   DALI_TEST_EQUALS((int)flexNode->GetFlexJustification(), (int)Flex::Justification::FLEX_START, TEST_LOCATION);
196   DALI_TEST_EQUALS((int)flexNode->GetFlexItemsAlignment(), (int)Flex::Alignment::FLEX_START, TEST_LOCATION);
197
198   flexNode->AddChild(actor1, Extents(0, 0, 0, 0), &MeasureChild, 0);
199   flexNode->AddChild(actor2, Extents(0, 0, 0, 0), &MeasureChild, 1);
200   Flex::Node* actor3node = flexNode->AddChild(actor3, Extents(0, 0, 0, 0), &MeasureChild, 2);
201   actor3node->SetFlexAlignmentSelf(Flex::Alignment::FLEX_END);
202
203   flexNode->CalculateLayout(480, 800, false);
204
205   Vector4 root        = flexNode->GetNodeFrame(-1); // -1 is the root
206   Vector4 actor1Frame = flexNode->GetNodeFrame(0);  // 0 is first child
207   Vector4 actor2Frame = flexNode->GetNodeFrame(1);  // 1 is second child
208   Vector4 actor3Frame = flexNode->GetNodeFrame(2);  // 2 is third child
209
210   tet_printf("Root frame(left:%f,top:%f,right:%f,bottom:%f)\n", root.x, root.y, root.z, root.w);
211
212   tet_printf("Actor 1 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor1Frame.x, actor1Frame.y, actor1Frame.z, actor1Frame.w);
213   tet_printf("Actor 2 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor2Frame.x, actor2Frame.y, actor2Frame.z, actor2Frame.w);
214   tet_printf("Actor 3 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor3Frame.x, actor3Frame.y, actor3Frame.z, actor3Frame.w);
215
216   /*
217     ---------
218     |1      |
219     |2      |
220     |      3|
221     |       |
222     |       |
223     ---------
224   */
225
226   DALI_TEST_EQUALS(actor1Frame, Vector4(0.0f, 0.0f, ITEM_SIZE.width, ITEM_SIZE.height), TEST_LOCATION);
227   DALI_TEST_EQUALS(actor2Frame, Vector4(0.0f, ITEM_SIZE.height, ITEM_SIZE.width, ITEM_SIZE.height * 2), TEST_LOCATION);
228   DALI_TEST_EQUALS(actor3Frame, Vector4(root.z - ITEM_SIZE.width, ITEM_SIZE.height * 2, root.z, ITEM_SIZE.height * 3), TEST_LOCATION);
229
230   tet_infoline(" Justify to the End, items should now be displayed at the bottom, third item should now be displayed at the end");
231   flexNode->SetFlexJustification(Flex::Justification::FLEX_END);
232   flexNode->SetFlexItemsAlignment(Flex::Alignment::FLEX_START);
233
234   // Recalulate layout
235   flexNode->CalculateLayout(480, 800, false);
236
237   root        = flexNode->GetNodeFrame(-1); // -1 is the root
238   actor1Frame = flexNode->GetNodeFrame(0);  // 0 is first child
239   actor2Frame = flexNode->GetNodeFrame(1);  // 1 is second child
240   actor3Frame = flexNode->GetNodeFrame(2);  // 2 is third child
241
242   tet_printf("Root frame(left:%f,top:%f,right:%f,bottom:%f)\n", root.x, root.y, root.z, root.w);
243
244   tet_printf("Actor 1 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor1Frame.x, actor1Frame.y, actor1Frame.z, actor1Frame.w);
245   tet_printf("Actor 2 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor2Frame.x, actor2Frame.y, actor2Frame.z, actor2Frame.w);
246   tet_printf("Actor 3 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor3Frame.x, actor3Frame.y, actor3Frame.z, actor3Frame.w);
247
248   /*
249     ---------
250     |       |
251     |       |
252     |1      |
253     |2      |
254     |      3|
255     ---------
256   */
257
258   DALI_TEST_EQUALS(actor1Frame, Vector4(0.0f, root.w - (ITEM_SIZE.height * 3), ITEM_SIZE.width, root.w - (ITEM_SIZE.height * 2)), TEST_LOCATION);
259   DALI_TEST_EQUALS(actor2Frame, Vector4(0.0f, root.w - (ITEM_SIZE.height * 2), ITEM_SIZE.width, root.w - ITEM_SIZE.height), TEST_LOCATION);
260   DALI_TEST_EQUALS(actor3Frame, Vector4(root.z - ITEM_SIZE.width, root.w - ITEM_SIZE.height, root.z, root.w), TEST_LOCATION);
261
262   tet_infoline(" Align to End, items should now be displayed at the bottom and the end");
263   flexNode->SetFlexJustification(Flex::Justification::FLEX_END);
264   flexNode->SetFlexItemsAlignment(Flex::Alignment::FLEX_END);
265   // Recalulate layout
266   flexNode->CalculateLayout(480, 800, false);
267
268   root        = flexNode->GetNodeFrame(-1); // -1 is the root
269   actor1Frame = flexNode->GetNodeFrame(0);  // 0 is first child
270   actor2Frame = flexNode->GetNodeFrame(1);  // 1 is second child
271   actor3Frame = flexNode->GetNodeFrame(2);  // 2 is third child
272
273   tet_printf("Actor 1 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor1Frame.x, actor1Frame.y, actor1Frame.z, actor1Frame.w);
274   tet_printf("Actor 2 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor2Frame.x, actor2Frame.y, actor2Frame.z, actor2Frame.w);
275   tet_printf("Actor 3 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor3Frame.x, actor3Frame.y, actor3Frame.z, actor3Frame.w);
276
277   /*
278     ---------
279     |       |
280     |       |
281     |      1|
282     |      2|
283     |      3|
284     ---------
285   */
286
287   DALI_TEST_EQUALS(actor1Frame, Vector4(root.z - ITEM_SIZE.width, root.w - (ITEM_SIZE.height * 3), root.z, root.w - (ITEM_SIZE.height * 2)), TEST_LOCATION);
288   DALI_TEST_EQUALS(actor2Frame, Vector4(root.z - ITEM_SIZE.width, root.w - (ITEM_SIZE.height * 2), root.z, root.w - ITEM_SIZE.height), TEST_LOCATION);
289   DALI_TEST_EQUALS(actor3Frame, Vector4(root.z - ITEM_SIZE.width, root.w - ITEM_SIZE.height, root.z, root.w), TEST_LOCATION);
290
291   delete flexNode;
292
293   END_TEST;
294 }
295
296 int UtcDaliToolkitFlexNodeSizingP(void)
297 {
298   ToolkitTestApplication application;
299   tet_infoline(" UtcDaliToolkitFlexNodeSizingP");
300   Flex::Node* flexNode = new Flex::Node();
301   DALI_TEST_CHECK(flexNode);
302
303   // Create two actors and add them to the parent flex node
304   Actor actor1 = Actor::New();
305   Actor actor2 = Actor::New();
306   DALI_TEST_CHECK(actor1);
307   DALI_TEST_CHECK(actor2);
308
309   flexNode->AddChild(actor1, Extents(0, 0, 0, 0), &MeasureChild, 0);
310   flexNode->AddChild(actor2, Extents(0, 0, 0, 0), &MeasureChild, 1);
311
312   flexNode->CalculateLayout(480, 800, false);
313
314   DALI_TEST_EQUALS(flexNode->GetFlexWidth(), 480.0f, TEST_LOCATION);
315   DALI_TEST_EQUALS(flexNode->GetFlexHeight(), 800.0f, TEST_LOCATION);
316
317   delete flexNode;
318
319   END_TEST;
320 }
321
322 int UtcDaliToolkitFlexNodeWrapModeP(void)
323 {
324   ToolkitTestApplication application;
325   tet_infoline("UtcDaliToolkitFlexNodeWrapModeP");
326   Flex::Node* flexNode = new Flex::Node();
327   DALI_TEST_CHECK(flexNode);
328
329   // Position elements in a Column
330   flexNode->SetFlexDirection(Flex::FlexDirection::ROW);
331   flexNode->SetFlexAlignment(Flex::Alignment::FLEX_START);
332   flexNode->SetFlexWrap(Flex::WrapType::NO_WRAP);
333
334   // Create two actors and add them to the parent flex node
335   Actor actor1 = Actor::New();
336   Actor actor2 = Actor::New();
337   Actor actor3 = Actor::New();
338   Actor actor4 = Actor::New();
339
340   DALI_TEST_EQUALS((int)flexNode->GetFlexJustification(), (int)Flex::Justification::FLEX_START, TEST_LOCATION);
341   DALI_TEST_EQUALS((int)flexNode->GetFlexItemsAlignment(), (int)Flex::Alignment::FLEX_START, TEST_LOCATION);
342   DALI_TEST_EQUALS((int)flexNode->GetFlexAlignment(), (int)Flex::Alignment::FLEX_START, TEST_LOCATION);
343   DALI_TEST_EQUALS((int)flexNode->GetFlexWrap(), (int)Flex::WrapType::NO_WRAP, TEST_LOCATION);
344
345   flexNode->AddChild(actor1, Extents(0, 0, 0, 0), &MeasureChild, 0);
346   flexNode->AddChild(actor2, Extents(0, 0, 0, 0), &MeasureChild, 1);
347   flexNode->AddChild(actor2, Extents(0, 0, 0, 0), &MeasureChild, 2);
348   flexNode->AddChild(actor2, Extents(0, 0, 0, 0), &MeasureChild, 3);
349
350   flexNode->CalculateLayout(30, 800, false);
351
352   Vector4 root        = flexNode->GetNodeFrame(-1); // -1 is the root
353   Vector4 actor1Frame = flexNode->GetNodeFrame(0);  // 0 is first child
354   Vector4 actor2Frame = flexNode->GetNodeFrame(1);  // 1 is second child
355   Vector4 actor3Frame = flexNode->GetNodeFrame(2);  // 2 is first child
356   Vector4 actor4Frame = flexNode->GetNodeFrame(3);  // 3 is second child
357
358   tet_printf("Root frame(left:%f,top:%f,right:%f,bottom:%f)\n", root.x, root.y, root.z, root.w);
359   tet_printf("Actor 1 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor1Frame.x, actor1Frame.y, actor1Frame.z, actor1Frame.w);
360   tet_printf("Actor 2 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor2Frame.x, actor2Frame.y, actor2Frame.z, actor2Frame.w);
361   tet_printf("Actor 3 frame(left:%f,top:%f,right:cdt%f,bottom:%f)\n", actor3Frame.x, actor3Frame.y, actor3Frame.z, actor3Frame.w);
362   tet_printf("Actor 4 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor4Frame.x, actor4Frame.y, actor4Frame.z, actor4Frame.w);
363
364   /*
365     -------
366     |1 2 3 4     |
367     |     |
368     |     |
369     |     |
370     |     |
371     -------
372   */
373
374   DALI_TEST_EQUALS(actor1Frame, Vector4(0.0f, 0.0f, ITEM_SIZE.width, ITEM_SIZE.height), TEST_LOCATION);
375   DALI_TEST_EQUALS(actor2Frame, Vector4(ITEM_SIZE.width, 0.0f, ITEM_SIZE.width * 2, ITEM_SIZE.height), TEST_LOCATION);
376   DALI_TEST_EQUALS(actor3Frame, Vector4(ITEM_SIZE.width * 2, 0.0f, ITEM_SIZE.width * 3, ITEM_SIZE.height), TEST_LOCATION);
377   DALI_TEST_EQUALS(actor4Frame, Vector4(ITEM_SIZE.width * 3, 0.0f, ITEM_SIZE.width * 4, ITEM_SIZE.height), TEST_LOCATION);
378
379   flexNode->SetFlexWrap(Flex::WrapType::WRAP);
380
381   flexNode->CalculateLayout(30, 800, false);
382   root = flexNode->GetNodeFrame(-1); // -1 is the root
383
384   DALI_TEST_EQUALS((int)flexNode->GetFlexWrap(), (int)Flex::WrapType::WRAP, TEST_LOCATION);
385   tet_printf("Root frame(left:%f,top:%f,right:%f,bottom:%f)\n", root.x, root.y, root.z, root.w);
386
387   actor1Frame = flexNode->GetNodeFrame(0); // 0 is first child
388   actor2Frame = flexNode->GetNodeFrame(1); // 1 is second child
389   actor3Frame = flexNode->GetNodeFrame(2); // 2 is first child
390   actor4Frame = flexNode->GetNodeFrame(3); // 3 is second child
391
392   tet_printf("Actor 1 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor1Frame.x, actor1Frame.y, actor1Frame.z, actor1Frame.w);
393   tet_printf("Actor 2 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor2Frame.x, actor2Frame.y, actor2Frame.z, actor2Frame.w);
394   tet_printf("Actor 3 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor3Frame.x, actor3Frame.y, actor3Frame.z, actor3Frame.w);
395   tet_printf("Actor 4 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor4Frame.x, actor4Frame.y, actor4Frame.z, actor4Frame.w);
396
397   /*
398     -------
399     |1 2 3|     |
400     |4    |
401     |     |
402     |     |
403     |     |
404     -------
405   */
406
407   DALI_TEST_EQUALS(actor1Frame, Vector4(0.0f, 0.0f, ITEM_SIZE.width, ITEM_SIZE.height), TEST_LOCATION);
408   DALI_TEST_EQUALS(actor2Frame, Vector4(ITEM_SIZE.width, 0.0f, ITEM_SIZE.width * 2, ITEM_SIZE.height), TEST_LOCATION);
409   DALI_TEST_EQUALS(actor3Frame, Vector4(ITEM_SIZE.width * 2, 0.0f, ITEM_SIZE.width * 3, ITEM_SIZE.height), TEST_LOCATION);
410   DALI_TEST_EQUALS(actor4Frame, Vector4(0.0, ITEM_SIZE.height, ITEM_SIZE.width, ITEM_SIZE.height * 2), TEST_LOCATION);
411
412   delete flexNode;
413
414   END_TEST;
415 }
416
417 int UtcDaliToolkitFlexNodeRemoveChildP(void)
418 {
419   ToolkitTestApplication application;
420   tet_infoline(" UtcDaliToolkitFlexNodeRemoveChildP");
421   Flex::Node* flexNode = new Flex::Node();
422   DALI_TEST_CHECK(flexNode);
423
424   // Create two actors and add them to the parent flex node
425   Actor actor1 = Actor::New();
426   Actor actor2 = Actor::New();
427   actor1.SetProperty(Dali::Actor::Property::NAME, "Actor1");
428   actor2.SetProperty(Dali::Actor::Property::NAME, "Actor2");
429
430   DALI_TEST_CHECK(actor1);
431   DALI_TEST_CHECK(actor2);
432
433   flexNode->AddChild(actor1, Extents(0, 0, 0, 0), &MeasureChild, 0);
434   flexNode->AddChild(actor2, Extents(0, 0, 0, 0), &MeasureChild, 1);
435
436   flexNode->CalculateLayout(480, 800, false);
437
438   Vector4 actor1Frame = flexNode->GetNodeFrame(0);
439   Vector4 actor2Frame = flexNode->GetNodeFrame(1);
440
441   tet_printf("Actor 1 frame(%f,%f,%f,%f)\n", actor1Frame.x, actor1Frame.y, actor1Frame.z, actor1Frame.w);
442   tet_printf("Actor 2 frame(%f,%f,%f,%f)\n", actor2Frame.x, actor2Frame.y, actor2Frame.z, actor2Frame.w);
443
444   DALI_TEST_EQUALS(actor2Frame, Vector4(0.0f, ITEM_SIZE.width, ITEM_SIZE.width, ITEM_SIZE.height * 2), TEST_LOCATION);
445
446   flexNode->RemoveChild(actor1);
447
448   flexNode->CalculateLayout(480, 800, false);
449
450   actor2Frame = flexNode->GetNodeFrame(0);
451
452   tet_printf("Actor 1 frame(%f,%f,%f,%f)\n", actor1Frame.x, actor1Frame.y, actor1Frame.z, actor1Frame.w);
453   tet_printf("Actor 2 frame(%f,%f,%f,%f)\n", actor2Frame.x, actor2Frame.y, actor2Frame.z, actor2Frame.w);
454
455   DALI_TEST_EQUALS(actor2Frame, Vector4(0.0f, 0.0f, ITEM_SIZE.width, ITEM_SIZE.height), TEST_LOCATION);
456
457   delete flexNode;
458
459   END_TEST;
460 }
461
462 int UtcDaliToolkitFlexNodeRemoveAllChildrenP(void)
463 {
464   ToolkitTestApplication application;
465   tet_infoline(" UtcDaliToolkitFlexNodeRemoveAllChildrenP");
466   Flex::Node* flexNode = new Flex::Node();
467   DALI_TEST_CHECK(flexNode);
468
469   // Create two actors and add them to the parent flex node
470   Actor actor1 = Actor::New();
471   Actor actor2 = Actor::New();
472   actor1.SetProperty(Dali::Actor::Property::NAME, "Actor1");
473   actor2.SetProperty(Dali::Actor::Property::NAME, "Actor2");
474
475   DALI_TEST_CHECK(actor1);
476   DALI_TEST_CHECK(actor2);
477
478   flexNode->AddChild(actor1, Extents(0, 0, 0, 0), &MeasureChild, 0);
479   flexNode->AddChild(actor2, Extents(0, 0, 0, 0), &MeasureChild, 1);
480
481   flexNode->CalculateLayout(480, 800, false);
482
483   Vector4 actor1Frame = flexNode->GetNodeFrame(0);
484   Vector4 actor2Frame = flexNode->GetNodeFrame(1);
485
486   tet_printf("Actor 1 frame(%f,%f,%f,%f)\n", actor1Frame.x, actor1Frame.y, actor1Frame.z, actor1Frame.w);
487   tet_printf("Actor 2 frame(%f,%f,%f,%f)\n", actor2Frame.x, actor2Frame.y, actor2Frame.z, actor2Frame.w);
488
489   flexNode->RemoveChild(actor1);
490   flexNode->RemoveChild(actor2);
491
492   flexNode->CalculateLayout(480, 800, false);
493
494   Vector4 actor1FrameRemoved = flexNode->GetNodeFrame(0);
495   Vector4 actor2FrameRemoved = flexNode->GetNodeFrame(1);
496
497   tet_printf("Actor 1 frame(%f,%f,%f,%f)\n", actor1FrameRemoved.x, actor1FrameRemoved.y, actor1FrameRemoved.z, actor1FrameRemoved.w);
498   tet_printf("Actor 2 frame(%f,%f,%f,%f)\n", actor2FrameRemoved.x, actor2FrameRemoved.y, actor2FrameRemoved.z, actor2FrameRemoved.w);
499
500   DALI_TEST_NOT_EQUALS(actor1Frame, actor1FrameRemoved, 0.1, TEST_LOCATION);
501   DALI_TEST_NOT_EQUALS(actor2Frame, actor2FrameRemoved, 0.1, TEST_LOCATION);
502
503   delete flexNode;
504
505   END_TEST;
506 }
507
508 int UtcDaliToolkitFlexNodePaddingMarginP(void)
509 {
510   ToolkitTestApplication application;
511   tet_infoline(" UtcDaliToolkitFlexNodePaddingMarginP");
512   Flex::Node* flexNode = new Flex::Node();
513   DALI_TEST_CHECK(flexNode);
514   flexNode->SetFlexDirection(Flex::FlexDirection::ROW);
515
516   // Create two actors and add them to the parent flex node
517   Actor actor1 = Actor::New();
518   Actor actor2 = Actor::New();
519   DALI_TEST_CHECK(actor1);
520   DALI_TEST_CHECK(actor2);
521
522   flexNode->AddChild(actor1, Extents(0, 0, 0, 0), &MeasureChild, 0);
523   flexNode->AddChild(actor2, Extents(0, 0, 0, 0), &MeasureChild, 1);
524
525   Extents padding(5, 5, 5, 5);
526   Extents margin(5, 5, 5, 5);
527
528   flexNode->SetPadding(padding);
529   flexNode->SetMargin(margin);
530
531   flexNode->CalculateLayout(480, 800, false);
532
533   Vector4 actor1Frame = flexNode->GetNodeFrame(0);
534   Vector4 actor2Frame = flexNode->GetNodeFrame(1);
535
536   /*  p = padding
537   -----
538   |ppppp|
539   |p1 2p|
540   |p   p|
541   |ppppp|
542   -------
543   */
544   DALI_TEST_EQUALS(actor1Frame, Vector4(5.0f, 5.0f, ITEM_SIZE.width + 5, ITEM_SIZE.height + 5), TEST_LOCATION);
545   DALI_TEST_EQUALS(actor2Frame, Vector4(5 + ITEM_SIZE.width, 5.0f, (ITEM_SIZE.width * 2) + 5, ITEM_SIZE.height + 5), TEST_LOCATION);
546
547   delete flexNode;
548
549   END_TEST;
550 }
551
552 int UtcDaliToolkitFlexNodeCallbackTestP(void)
553 {
554   ToolkitTestApplication application;
555   tet_infoline("UtcDaliToolkitFlexNodeCallbackTestP");
556   Flex::Node* flexNode = new Flex::Node();
557   DALI_TEST_CHECK(flexNode);
558
559   // Position elements in a Column
560   flexNode->SetFlexDirection(Flex::FlexDirection::COLUMN);
561
562   // Create two actors and add them to the parent flex node
563   Actor actor1 = Actor::New();
564   Actor actor2 = Actor::New();
565
566   actor1.SetProperty(Dali::Actor::Property::NAME, "callbackTest");
567
568   DALI_TEST_CHECK(actor1);
569   DALI_TEST_CHECK(actor2);
570
571   flexNode->AddChild(actor1, Extents(0, 0, 0, 0), &MeasureChild, 0);
572   flexNode->AddChild(actor2, Extents(0, 0, 0, 0), &MeasureChild, 1);
573
574   flexNode->CalculateLayout(480, 800, false);
575
576   Vector4 root        = flexNode->GetNodeFrame(-1); // -1 is the root
577   Vector4 actor1Frame = flexNode->GetNodeFrame(0);  // 0 is first child
578   Vector4 actor2Frame = flexNode->GetNodeFrame(1);  // 1 is second child
579
580   tet_printf("Root frame(left:%f,top:%f,right:%f,bottom:%f)\n", root.x, root.y, root.z, root.w);
581
582   tet_printf("Actor 1 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor1Frame.x, actor1Frame.y, actor1Frame.z, actor1Frame.w);
583   tet_printf("Actor 2 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor2Frame.x, actor2Frame.y, actor2Frame.z, actor2Frame.w);
584
585   DALI_TEST_EQUALS(actor1Frame, Vector4(0.0f, 0.0f, ITEM_SIZE_CALLBACK_TEST.width, ITEM_SIZE_CALLBACK_TEST.height), TEST_LOCATION);
586   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);
587
588   delete flexNode;
589
590   END_TEST;
591 }
592
593 int UtcDaliToolkitFlexNodeFlexPositionType(void)
594 {
595   ToolkitTestApplication application;
596   tet_infoline("UtcDaliToolkitFlexNodeFlexPositionType");
597   Flex::Node* flexNode = new Flex::Node();
598   DALI_TEST_CHECK(flexNode);
599
600   tet_infoline(" FlexPositionType is RELATIVE by default");
601
602   // Create two actors and add them to the parent flex node
603   Actor actor1 = Actor::New();
604   Actor actor2 = Actor::New();
605   DALI_TEST_CHECK(actor1);
606   DALI_TEST_CHECK(actor2);
607
608   flexNode->AddChild(actor1, Extents(0, 0, 0, 0), &MeasureChild, 0);
609   Flex::Node* actor2node = flexNode->AddChild(actor2, Extents(0, 0, 0, 0), &MeasureChild, 1);
610
611   DALI_TEST_EQUALS((int)actor2node->GetFlexPositionType(), (int)Flex::PositionType::RELATIVE, TEST_LOCATION);
612
613   flexNode->CalculateLayout(480, 800, false);
614
615   Vector4 root        = flexNode->GetNodeFrame(-1); // -1 is the root
616   Vector4 actor1Frame = flexNode->GetNodeFrame(0);  // 0 is first child
617   Vector4 actor2Frame = flexNode->GetNodeFrame(1);  // 1 is second child
618
619   tet_printf("Root frame(left:%f,top:%f,right:%f,bottom:%f)\n", root.x, root.y, root.z, root.w);
620
621   tet_printf("Actor 1 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor1Frame.x, actor1Frame.y, actor1Frame.z, actor1Frame.w);
622   tet_printf("Actor 2 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor2Frame.x, actor2Frame.y, actor2Frame.z, actor2Frame.w);
623
624   /*
625     ---------
626     |1      |
627     |2      |
628     |       |
629     |       |
630     |       |
631     ---------
632   */
633
634   DALI_TEST_EQUALS(actor1Frame, Vector4(0.0f, 0.0f, ITEM_SIZE.width, ITEM_SIZE.height), TEST_LOCATION);
635   DALI_TEST_EQUALS(actor2Frame, Vector4(0.0f, ITEM_SIZE.height, ITEM_SIZE.width, ITEM_SIZE.height * 2), TEST_LOCATION);
636
637   tet_infoline(" ABSOLUTE FlexPositionType, second item should now be ignore any properties");
638   actor2node->SetFlexPositionType(Flex::PositionType::ABSOLUTE);
639
640   // Recalulate layout
641   flexNode->CalculateLayout(480, 800, false);
642
643   root        = flexNode->GetNodeFrame(-1); // -1 is the root
644   actor1Frame = flexNode->GetNodeFrame(0);  // 0 is first child
645   actor2Frame = flexNode->GetNodeFrame(1);  // 1 is second child
646
647   tet_printf("Root frame(left:%f,top:%f,right:%f,bottom:%f)\n", root.x, root.y, root.z, root.w);
648
649   tet_printf("Actor 1 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor1Frame.x, actor1Frame.y, actor1Frame.z, actor1Frame.w);
650   tet_printf("Actor 2 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor2Frame.x, actor2Frame.y, actor2Frame.z, actor2Frame.w);
651
652   /*
653     ---------
654     |1(2)   |
655     |       |
656     |       |
657     |       |
658     |       |
659     ---------
660   */
661
662   DALI_TEST_EQUALS(actor1Frame, Vector4(0.0f, 0.0f, ITEM_SIZE.width, ITEM_SIZE.height), TEST_LOCATION);
663   DALI_TEST_EQUALS(actor2Frame, Vector4(0.0f, 0.0f, ITEM_SIZE.width, ITEM_SIZE.height), TEST_LOCATION);
664
665   delete flexNode;
666
667   END_TEST;
668 }
669
670 int UtcDaliToolkitFlexNodeFlexAspectRatio(void)
671 {
672   ToolkitTestApplication application;
673   tet_infoline("UtcDaliToolkitFlexNodeFlexAspectRatio");
674   Flex::Node* flexNode = new Flex::Node();
675   DALI_TEST_CHECK(flexNode);
676
677   // Create a actor and add them to the parent flex node
678   Actor actor1 = Actor::New();
679   DALI_TEST_CHECK(actor1);
680
681   tet_infoline(" 1.0 FlexAspectRatio");
682   Flex::Node* actor1node = flexNode->AddChild(actor1, Extents(0, 0, 0, 0), &MeasureChild, 0);
683   actor1node->SetFlexAspectRatio(1.0);
684
685   DALI_TEST_EQUALS(actor1node->GetFlexAspectRatio(), 1.0f, TEST_LOCATION);
686
687   flexNode->CalculateLayout(480, 800, false);
688
689   Vector4 root        = flexNode->GetNodeFrame(-1); // -1 is the root
690   Vector4 actor1Frame = flexNode->GetNodeFrame(0);  // 0 is first child
691
692   tet_printf("Root frame(left:%f,top:%f,right:%f,bottom:%f)\n", root.x, root.y, root.z, root.w);
693
694   tet_printf("Actor 1 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor1Frame.x, actor1Frame.y, actor1Frame.z, actor1Frame.w);
695
696   /*
697     ---------
698     |---    |
699     ||1|    |
700     |---    |
701     |       |
702     |       |
703     ---------
704   */
705
706   DALI_TEST_EQUALS(actor1Frame, Vector4(0.0f, 0.0f, ITEM_SIZE.width, ITEM_SIZE.height), TEST_LOCATION);
707
708   tet_infoline(" 2.0 FlexAspectRatio");
709   actor1node->SetFlexAspectRatio(2.0);
710
711   DALI_TEST_EQUALS(actor1node->GetFlexAspectRatio(), 2.0f, TEST_LOCATION);
712
713   // Recalulate layout
714   flexNode->CalculateLayout(480, 800, false);
715
716   root        = flexNode->GetNodeFrame(-1); // -1 is the root
717   actor1Frame = flexNode->GetNodeFrame(0);  // 0 is first child
718
719   tet_printf("Root frame(left:%f,top:%f,right:%f,bottom:%f)\n", root.x, root.y, root.z, root.w);
720
721   tet_printf("Actor 1 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor1Frame.x, actor1Frame.y, actor1Frame.z, actor1Frame.w);
722
723   /*
724     ---------
725     |------ |
726     || 1  | |
727     |------ |
728     |       |
729     |       |
730     ---------
731   */
732
733   DALI_TEST_EQUALS(actor1Frame, Vector4(0.0f, 0.0f, ITEM_SIZE.width * 2, ITEM_SIZE.height), TEST_LOCATION);
734
735   delete flexNode;
736
737   END_TEST;
738 }
739
740 int UtcDaliToolkitFlexNodeFlexBasisShrinkGrow(void)
741 {
742   ToolkitTestApplication application;
743   tet_infoline("UtcDaliToolkitFlexNodeFlexBasisShrinkGrow");
744   Flex::Node* flexNode = new Flex::Node();
745   DALI_TEST_CHECK(flexNode);
746
747   // Position elements as a Row
748   flexNode->SetFlexDirection(Flex::FlexDirection::ROW);
749
750   // Create three actors and add them to the parent flex node
751   Actor actor1 = Actor::New();
752   Actor actor2 = Actor::New();
753   Actor actor3 = Actor::New();
754   DALI_TEST_CHECK(actor1);
755   DALI_TEST_CHECK(actor2);
756   DALI_TEST_CHECK(actor3);
757
758   Flex::Node* actor1node = flexNode->AddChild(actor1, Extents(0, 0, 0, 0), &MeasureChild, 0);
759   Flex::Node* actor2node = flexNode->AddChild(actor2, Extents(0, 0, 0, 0), &MeasureChild, 1);
760   Flex::Node* actor3node = flexNode->AddChild(actor3, Extents(0, 0, 0, 0), &MeasureChild, 2);
761
762   float basis = 5;
763
764   actor1node->SetFlexGrow(0.0);
765   actor2node->SetFlexGrow(0.0);
766   actor3node->SetFlexGrow(0.0);
767   actor1node->SetFlexShrink(1.0);
768   actor2node->SetFlexShrink(1.0);
769   actor3node->SetFlexShrink(1.0);
770   actor1node->SetFlexBasis(basis);
771   actor2node->SetFlexBasis(basis);
772   actor3node->SetFlexBasis(basis);
773
774   DALI_TEST_EQUALS(actor1node->GetFlexGrow(), 0.0f, TEST_LOCATION);
775   DALI_TEST_EQUALS(actor1node->GetFlexShrink(), 1.0f, TEST_LOCATION);
776   DALI_TEST_EQUALS(actor1node->GetFlexBasis(), basis, TEST_LOCATION);
777
778   flexNode->CalculateLayout(600, 200, false);
779
780   Vector4 root        = flexNode->GetNodeFrame(-1); // -1 is the root
781   Vector4 actor1Frame = flexNode->GetNodeFrame(0);  // 0 is first child
782   Vector4 actor2Frame = flexNode->GetNodeFrame(1);  // 1 is second child
783   Vector4 actor3Frame = flexNode->GetNodeFrame(2);  // 2 is third child
784
785   tet_printf("Root frame(left:%f,top:%f,right:%f,bottom:%f)\n", root.x, root.y, root.z, root.w);
786
787   tet_printf("Actor 1 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor1Frame.x, actor1Frame.y, actor1Frame.z, actor1Frame.w);
788   tet_printf("Actor 2 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor2Frame.x, actor2Frame.y, actor2Frame.z, actor2Frame.w);
789   tet_printf("Actor 3 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor3Frame.x, actor3Frame.y, actor3Frame.z, actor3Frame.w);
790
791   /*
792     -------------------
793     ||1||2||3|        |
794     |                 |
795     -------------------
796   */
797
798   DALI_TEST_EQUALS(actor1Frame, Vector4(0.0f, 0.0f, basis, ITEM_SIZE.height), TEST_LOCATION);
799   DALI_TEST_EQUALS(actor2Frame, Vector4(basis, 0.0f, basis * 2, ITEM_SIZE.height), TEST_LOCATION);
800   DALI_TEST_EQUALS(actor3Frame, Vector4(basis * 2, 0.0f, basis * 3, ITEM_SIZE.height), TEST_LOCATION);
801
802   actor2node->SetFlexGrow(1.0);
803   actor3node->SetFlexGrow(1.0);
804
805   // Recalulate layout
806   flexNode->CalculateLayout(605, 200, false);
807
808   root        = flexNode->GetNodeFrame(-1); // -1 is the root
809   actor1Frame = flexNode->GetNodeFrame(0);  // 0 is first child
810   actor2Frame = flexNode->GetNodeFrame(1);  // 1 is second child
811   actor3Frame = flexNode->GetNodeFrame(2);  // 2 is third child
812
813   tet_printf("Root frame(left:%f,top:%f,right:%f,bottom:%f)\n", root.x, root.y, root.z, root.w);
814
815   tet_printf("Actor 1 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor1Frame.x, actor1Frame.y, actor1Frame.z, actor1Frame.w);
816   tet_printf("Actor 2 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor2Frame.x, actor2Frame.y, actor2Frame.z, actor2Frame.w);
817   tet_printf("Actor 3 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor3Frame.x, actor3Frame.y, actor3Frame.z, actor3Frame.w);
818
819   /*
820     -------------------
821     ||1||  2  ||  3  ||
822     |                 |
823     -------------------
824   */
825
826   DALI_TEST_EQUALS(actor1Frame, Vector4(0.0f, 0.0f, basis, ITEM_SIZE.height), TEST_LOCATION);
827   DALI_TEST_EQUALS(actor2Frame, Vector4(basis, 0.0f, basis + (root.z - basis) / 2, ITEM_SIZE.height), TEST_LOCATION);
828   DALI_TEST_EQUALS(actor3Frame, Vector4(basis + (root.z - basis) / 2, 0.0f, root.z, ITEM_SIZE.height), TEST_LOCATION);
829
830   delete flexNode;
831
832   END_TEST;
833 }