2 * Copyright (c) 2014-present, Facebook, Inc.
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
8 #include <gtest/gtest.h>
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();
17 const YGNodeRef root = YGNodeNewWithConfig(config);
18 YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow);
19 YGNodeStyleSetWidth(root, 300);
21 const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
22 YGNodeStyleSetWidth(root_child0, 300);
23 YGNodeStyleSetHeight(root_child0, 300);
24 YGNodeInsertChild(root, root_child0, 0);
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);
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));
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));
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));
50 YGNodeFreeRecursive(root);