Merge "Add new layouting support for TextLabel and ImageView." into devel/master
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit-third-party / yoga / YGInfiniteHeightTest.cpp
1 /**
2  * Copyright (c) 2014-present, Facebook, Inc.
3  *
4  * This source code is licensed under the MIT license found in the
5  * LICENSE file in the root directory of this source tree.
6  */
7
8 #include <gtest/gtest.h>
9 #include <yoga/Yoga.h>
10
11 // This test isn't correct from the Flexbox standard standpoint,
12 // because percentages are calculated with parent constraints.
13 // However, we need to make sure we fail gracefully in this case, not returning NaN
14 TEST(YogaTest, percent_absolute_position_infinite_height) {
15   const YGConfigRef config = YGConfigNew();
16
17   const YGNodeRef root = YGNodeNewWithConfig(config);
18   YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow);
19   YGNodeStyleSetWidth(root, 300);
20
21   const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
22   YGNodeStyleSetWidth(root_child0, 300);
23   YGNodeStyleSetHeight(root_child0, 300);
24   YGNodeInsertChild(root, root_child0, 0);
25
26   const YGNodeRef root_child1 = YGNodeNewWithConfig(config);
27   YGNodeStyleSetPositionType(root_child1, YGPositionTypeAbsolute);
28   YGNodeStyleSetPositionPercent(root_child1, YGEdgeLeft, 20);
29   YGNodeStyleSetPositionPercent(root_child1, YGEdgeTop, 20);
30   YGNodeStyleSetWidthPercent(root_child1, 20);
31   YGNodeStyleSetHeightPercent(root_child1, 20);
32   YGNodeInsertChild(root, root_child1, 1);
33   YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
34
35   ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
36   ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
37   ASSERT_FLOAT_EQ(300, YGNodeLayoutGetWidth(root));
38   ASSERT_FLOAT_EQ(300, YGNodeLayoutGetHeight(root));
39
40   ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
41   ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
42   ASSERT_FLOAT_EQ(300, YGNodeLayoutGetWidth(root_child0));
43   ASSERT_FLOAT_EQ(300, YGNodeLayoutGetHeight(root_child0));
44
45   ASSERT_FLOAT_EQ(60, YGNodeLayoutGetLeft(root_child1));
46   ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1));
47   ASSERT_FLOAT_EQ(60, YGNodeLayoutGetWidth(root_child1));
48   ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child1));
49
50   YGNodeFreeRecursive(root);
51
52   YGConfigFree(config);
53 }