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