2 * Copyright (c) 2022 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 #include <dali-toolkit-test-suite-utils.h>
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>
28 using namespace Toolkit;
30 void dali_flexNodeContainer_startup(void)
32 test_return_value = TET_UNDEF;
35 void dali_flexNodeContainer_cleanup(void)
37 test_return_value = TET_PASS;
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};
45 void MeasureChild(Actor child, float width, int measureModeWidth, float height, int measureModeHeight, Flex::SizeTuple* childSize)
47 *childSize = ITEM_SIZE;
48 if(child.GetProperty<std::string>(Dali::Actor::Property::NAME) == "callbackTest")
50 *childSize = ITEM_SIZE_CALLBACK_TEST;
52 tet_printf(" MeasureChild test callback executed (%f,%f)\n", childSize->width, childSize->height);
57 int UtcDaliToolkitFlexNodeConstructorP(void)
59 ToolkitTestApplication application;
60 tet_infoline(" UtcDaliToolkitFlexNodeNewP");
61 Flex::Node* flexNode = new Flex::Node();
62 DALI_TEST_CHECK(flexNode);
66 int UtcDaliToolkitFlexNodeAddChildWithMarginP(void)
68 ToolkitTestApplication application;
69 tet_infoline(" UtcDaliToolkitFlexNodeAddChildWithMarginP");
70 Flex::Node* flexNode = new Flex::Node();
71 DALI_TEST_CHECK(flexNode);
73 // Position elements as a Row
74 flexNode->SetFlexDirection(Flex::FlexDirection::ROW);
76 // Create two actors and add them to the parent flex node
77 Actor actor = Actor::New();
78 DALI_TEST_CHECK(actor);
80 Extents margin(5, 5, 5, 5);
81 flexNode->AddChild(actor, margin, &MeasureChild, 0);
83 DALI_TEST_EQUALS((int)flexNode->GetFlexDirection(), (int)Flex::FlexDirection::ROW, TEST_LOCATION);
85 flexNode->CalculateLayout(480, 800, false);
87 Vector4 actorFrame = flexNode->GetNodeFrame(0);
89 tet_printf("Actor frame(left:%f,top:%f,right:%f,bottom:%f)\n", actorFrame.x, actorFrame.y, actorFrame.z, actorFrame.w);
91 DALI_TEST_EQUALS(actorFrame, Vector4(5.0f, 5.0f, ITEM_SIZE.width + 5, ITEM_SIZE.height + 5), TEST_LOCATION);
96 int UtcDaliToolkitFlexNodeAddChildrenRowP(void)
98 ToolkitTestApplication application;
99 tet_infoline(" UtcDaliToolkitFlexNodeAddChildrenRowP");
100 Flex::Node* flexNode = new Flex::Node();
101 DALI_TEST_CHECK(flexNode);
103 // Position elements as a Row
104 flexNode->SetFlexDirection(Flex::FlexDirection::ROW);
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);
112 flexNode->AddChild(actor1, Extents(0, 0, 0, 0), &MeasureChild, 0);
113 flexNode->AddChild(actor2, Extents(0, 0, 0, 0), &MeasureChild, 1);
115 DALI_TEST_EQUALS((int)flexNode->GetFlexDirection(), (int)Flex::FlexDirection::ROW, TEST_LOCATION);
117 flexNode->CalculateLayout(480, 800, false);
119 Vector4 actor1Frame = flexNode->GetNodeFrame(0);
120 Vector4 actor2Frame = flexNode->GetNodeFrame(1);
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);
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);
131 int UtcDaliToolkitFlexNodeAddChildrenColumnP(void)
133 ToolkitTestApplication application;
134 tet_infoline("UtcDaliToolkitFlexNodeAddChildrenColumnP");
135 Flex::Node* flexNode = new Flex::Node();
136 DALI_TEST_CHECK(flexNode);
138 // Position elements in a Column
139 flexNode->SetFlexDirection(Flex::FlexDirection::COLUMN);
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);
147 flexNode->AddChild(actor1, Extents(0, 0, 0, 0), &MeasureChild, 0);
148 flexNode->AddChild(actor2, Extents(0, 0, 0, 0), &MeasureChild, 1);
150 flexNode->CalculateLayout(480, 800, false);
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
156 tet_printf("Root frame(left:%f,top:%f,right:%f,bottom:%f)\n", root.x, root.y, root.z, root.w);
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);
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);
167 int UtcDaliToolkitFlexNodeAddChildrenColumnJustify(void)
169 ToolkitTestApplication application;
170 tet_infoline("UtcDaliToolkitFlexNodeAddChildrenColumnJustify");
171 Flex::Node* flexNode = new Flex::Node();
172 DALI_TEST_CHECK(flexNode);
174 // Position elements in a Column
175 flexNode->SetFlexDirection(Flex::FlexDirection::COLUMN);
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);
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);
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);
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);
197 flexNode->CalculateLayout(480, 800, false);
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
204 tet_printf("Root frame(left:%f,top:%f,right:%f,bottom:%f)\n", root.x, root.y, root.z, root.w);
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);
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);
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);
229 flexNode->CalculateLayout(480, 800, false);
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
236 tet_printf("Root frame(left:%f,top:%f,right:%f,bottom:%f)\n", root.x, root.y, root.z, root.w);
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);
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);
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);
260 flexNode->CalculateLayout(480, 800, false);
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
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);
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);
288 int UtcDaliToolkitFlexNodeSizingP(void)
290 ToolkitTestApplication application;
291 tet_infoline(" UtcDaliToolkitFlexNodeSizingP");
292 Flex::Node* flexNode = new Flex::Node();
293 DALI_TEST_CHECK(flexNode);
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);
301 flexNode->AddChild(actor1, Extents(0, 0, 0, 0), &MeasureChild, 0);
302 flexNode->AddChild(actor2, Extents(0, 0, 0, 0), &MeasureChild, 1);
304 flexNode->CalculateLayout(480, 800, false);
306 DALI_TEST_EQUALS(flexNode->GetFlexWidth(), 480.0f, TEST_LOCATION);
307 DALI_TEST_EQUALS(flexNode->GetFlexHeight(), 800.0f, TEST_LOCATION);
312 int UtcDaliToolkitFlexNodeWrapModeP(void)
314 ToolkitTestApplication application;
315 tet_infoline("UtcDaliToolkitFlexNodeWrapModeP");
316 Flex::Node* flexNode = new Flex::Node();
317 DALI_TEST_CHECK(flexNode);
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);
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();
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);
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);
340 flexNode->CalculateLayout(30, 800, false);
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
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);
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);
369 flexNode->SetFlexWrap(Flex::WrapType::WRAP);
371 flexNode->CalculateLayout(30, 800, false);
372 root = flexNode->GetNodeFrame(-1); // -1 is the root
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);
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
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);
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);
405 int UtcDaliToolkitFlexNodeRemoveChildP(void)
407 ToolkitTestApplication application;
408 tet_infoline(" UtcDaliToolkitFlexNodeRemoveChildP");
409 Flex::Node* flexNode = new Flex::Node();
410 DALI_TEST_CHECK(flexNode);
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");
418 DALI_TEST_CHECK(actor1);
419 DALI_TEST_CHECK(actor2);
421 flexNode->AddChild(actor1, Extents(0, 0, 0, 0), &MeasureChild, 0);
422 flexNode->AddChild(actor2, Extents(0, 0, 0, 0), &MeasureChild, 1);
424 flexNode->CalculateLayout(480, 800, false);
426 Vector4 actor1Frame = flexNode->GetNodeFrame(0);
427 Vector4 actor2Frame = flexNode->GetNodeFrame(1);
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);
432 DALI_TEST_EQUALS(actor2Frame, Vector4(0.0f, ITEM_SIZE.width, ITEM_SIZE.width, ITEM_SIZE.height * 2), TEST_LOCATION);
434 flexNode->RemoveChild(actor1);
436 flexNode->CalculateLayout(480, 800, false);
438 actor2Frame = flexNode->GetNodeFrame(0);
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);
443 DALI_TEST_EQUALS(actor2Frame, Vector4(0.0f, 0.0f, ITEM_SIZE.width, ITEM_SIZE.height), TEST_LOCATION);
448 int UtcDaliToolkitFlexNodeRemoveAllChildrenP(void)
450 ToolkitTestApplication application;
451 tet_infoline(" UtcDaliToolkitFlexNodeRemoveAllChildrenP");
452 Flex::Node* flexNode = new Flex::Node();
453 DALI_TEST_CHECK(flexNode);
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");
461 DALI_TEST_CHECK(actor1);
462 DALI_TEST_CHECK(actor2);
464 flexNode->AddChild(actor1, Extents(0, 0, 0, 0), &MeasureChild, 0);
465 flexNode->AddChild(actor2, Extents(0, 0, 0, 0), &MeasureChild, 1);
467 flexNode->CalculateLayout(480, 800, false);
469 Vector4 actor1Frame = flexNode->GetNodeFrame(0);
470 Vector4 actor2Frame = flexNode->GetNodeFrame(1);
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);
475 flexNode->RemoveChild(actor1);
476 flexNode->RemoveChild(actor2);
478 flexNode->CalculateLayout(480, 800, false);
480 Vector4 actor1FrameRemoved = flexNode->GetNodeFrame(0);
481 Vector4 actor2FrameRemoved = flexNode->GetNodeFrame(1);
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);
486 DALI_TEST_NOT_EQUALS(actor1Frame, actor1FrameRemoved, 0.1, TEST_LOCATION);
487 DALI_TEST_NOT_EQUALS(actor2Frame, actor2FrameRemoved, 0.1, TEST_LOCATION);
492 int UtcDaliToolkitFlexNodePaddingMarginP(void)
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);
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);
506 flexNode->AddChild(actor1, Extents(0, 0, 0, 0), &MeasureChild, 0);
507 flexNode->AddChild(actor2, Extents(0, 0, 0, 0), &MeasureChild, 1);
509 Extents padding(5, 5, 5, 5);
510 Extents margin(5, 5, 5, 5);
512 flexNode->SetPadding(padding);
513 flexNode->SetMargin(margin);
515 flexNode->CalculateLayout(480, 800, false);
517 Vector4 actor1Frame = flexNode->GetNodeFrame(0);
518 Vector4 actor2Frame = flexNode->GetNodeFrame(1);
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);
534 int UtcDaliToolkitFlexNodeCallbackTestP(void)
536 ToolkitTestApplication application;
537 tet_infoline("UtcDaliToolkitFlexNodeCallbackTestP");
538 Flex::Node* flexNode = new Flex::Node();
539 DALI_TEST_CHECK(flexNode);
541 // Position elements in a Column
542 flexNode->SetFlexDirection(Flex::FlexDirection::COLUMN);
544 // Create two actors and add them to the parent flex node
545 Actor actor1 = Actor::New();
546 Actor actor2 = Actor::New();
548 actor1.SetProperty(Dali::Actor::Property::NAME, "callbackTest");
550 DALI_TEST_CHECK(actor1);
551 DALI_TEST_CHECK(actor2);
553 flexNode->AddChild(actor1, Extents(0, 0, 0, 0), &MeasureChild, 0);
554 flexNode->AddChild(actor2, Extents(0, 0, 0, 0), &MeasureChild, 1);
556 flexNode->CalculateLayout(480, 800, false);
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
562 tet_printf("Root frame(left:%f,top:%f,right:%f,bottom:%f)\n", root.x, root.y, root.z, root.w);
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);
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);
573 int UtcDaliToolkitFlexNodeFlexPositionType(void)
575 ToolkitTestApplication application;
576 tet_infoline("UtcDaliToolkitFlexNodeFlexPositionType");
577 Flex::Node* flexNode = new Flex::Node();
578 DALI_TEST_CHECK(flexNode);
580 tet_infoline(" FlexPositionType is RELATIVE by default");
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);
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);
591 DALI_TEST_EQUALS((int)actor2node->GetFlexPositionType(), (int)Flex::PositionType::RELATIVE, TEST_LOCATION);
593 flexNode->CalculateLayout(480, 800, false);
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
599 tet_printf("Root frame(left:%f,top:%f,right:%f,bottom:%f)\n", root.x, root.y, root.z, root.w);
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);
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);
617 tet_infoline(" ABSOLUTE FlexPositionType, second item should now be ignore any properties");
618 actor2node->SetFlexPositionType(Flex::PositionType::ABSOLUTE);
621 flexNode->CalculateLayout(480, 800, false);
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
627 tet_printf("Root frame(left:%f,top:%f,right:%f,bottom:%f)\n", root.x, root.y, root.z, root.w);
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);
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);
648 int UtcDaliToolkitFlexNodeFlexAspectRatio(void)
650 ToolkitTestApplication application;
651 tet_infoline("UtcDaliToolkitFlexNodeFlexAspectRatio");
652 Flex::Node* flexNode = new Flex::Node();
653 DALI_TEST_CHECK(flexNode);
655 // Create a actor and add them to the parent flex node
656 Actor actor1 = Actor::New();
657 DALI_TEST_CHECK(actor1);
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);
663 DALI_TEST_EQUALS(actor1node->GetFlexAspectRatio(), 1.0f, TEST_LOCATION);
665 flexNode->CalculateLayout(480, 800, false);
667 Vector4 root = flexNode->GetNodeFrame(-1); // -1 is the root
668 Vector4 actor1Frame = flexNode->GetNodeFrame(0); // 0 is first child
670 tet_printf("Root frame(left:%f,top:%f,right:%f,bottom:%f)\n", root.x, root.y, root.z, root.w);
672 tet_printf("Actor 1 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor1Frame.x, actor1Frame.y, actor1Frame.z, actor1Frame.w);
684 DALI_TEST_EQUALS(actor1Frame, Vector4(0.0f, 0.0f, ITEM_SIZE.width, ITEM_SIZE.height), TEST_LOCATION);
686 tet_infoline(" 2.0 FlexAspectRatio");
687 actor1node->SetFlexAspectRatio(2.0);
689 DALI_TEST_EQUALS(actor1node->GetFlexAspectRatio(), 2.0f, TEST_LOCATION);
692 flexNode->CalculateLayout(480, 800, false);
694 root = flexNode->GetNodeFrame(-1); // -1 is the root
695 actor1Frame = flexNode->GetNodeFrame(0); // 0 is first child
697 tet_printf("Root frame(left:%f,top:%f,right:%f,bottom:%f)\n", root.x, root.y, root.z, root.w);
699 tet_printf("Actor 1 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor1Frame.x, actor1Frame.y, actor1Frame.z, actor1Frame.w);
711 DALI_TEST_EQUALS(actor1Frame, Vector4(0.0f, 0.0f, ITEM_SIZE.width * 2, ITEM_SIZE.height), TEST_LOCATION);
716 int UtcDaliToolkitFlexNodeFlexBasisShrinkGrow(void)
718 ToolkitTestApplication application;
719 tet_infoline("UtcDaliToolkitFlexNodeFlexBasisShrinkGrow");
720 Flex::Node* flexNode = new Flex::Node();
721 DALI_TEST_CHECK(flexNode);
723 // Position elements as a Row
724 flexNode->SetFlexDirection(Flex::FlexDirection::ROW);
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);
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);
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);
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);
754 flexNode->CalculateLayout(600, 200, false);
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
761 tet_printf("Root frame(left:%f,top:%f,right:%f,bottom:%f)\n", root.x, root.y, root.z, root.w);
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);
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);
778 actor2node->SetFlexGrow(1.0);
779 actor3node->SetFlexGrow(1.0);
782 flexNode->CalculateLayout(605, 200, false);
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
789 tet_printf("Root frame(left:%f,top:%f,right:%f,bottom:%f)\n", root.x, root.y, root.z, root.w);
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);
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);