1 // Copyright 2004-present Facebook. All Rights Reserved.
3 #include <gtest/gtest.h>
6 using namespace ::testing;
8 class YogaTest_HadOverflowTests : public testing::Test {
10 YogaTest_HadOverflowTests() {
11 config = YGConfigNew();
12 root = YGNodeNewWithConfig(config);
13 YGNodeStyleSetWidth(root, 200);
14 YGNodeStyleSetHeight(root, 100);
15 YGNodeStyleSetFlexDirection(root, YGFlexDirectionColumn);
16 YGNodeStyleSetFlexWrap(root, YGWrapNoWrap);
19 ~YogaTest_HadOverflowTests() {
20 YGNodeFreeRecursive(root);
28 TEST_F(YogaTest_HadOverflowTests, children_overflow_no_wrap_and_no_flex_children) {
29 const YGNodeRef child0 = YGNodeNewWithConfig(config);
30 YGNodeStyleSetWidth(child0, 80);
31 YGNodeStyleSetHeight(child0, 40);
32 YGNodeStyleSetMargin(child0, YGEdgeTop, 10);
33 YGNodeStyleSetMargin(child0, YGEdgeBottom, 15);
34 YGNodeInsertChild(root, child0, 0);
35 const YGNodeRef child1 = YGNodeNewWithConfig(config);
36 YGNodeStyleSetWidth(child1, 80);
37 YGNodeStyleSetHeight(child1, 40);
38 YGNodeStyleSetMargin(child1, YGEdgeBottom, 5);
39 YGNodeInsertChild(root, child1, 1);
41 YGNodeCalculateLayout(root, 200, 100, YGDirectionLTR);
43 ASSERT_TRUE(YGNodeLayoutGetHadOverflow(root));
46 TEST_F(YogaTest_HadOverflowTests, spacing_overflow_no_wrap_and_no_flex_children) {
47 const YGNodeRef child0 = YGNodeNewWithConfig(config);
48 YGNodeStyleSetWidth(child0, 80);
49 YGNodeStyleSetHeight(child0, 40);
50 YGNodeStyleSetMargin(child0, YGEdgeTop, 10);
51 YGNodeStyleSetMargin(child0, YGEdgeBottom, 10);
52 YGNodeInsertChild(root, child0, 0);
53 const YGNodeRef child1 = YGNodeNewWithConfig(config);
54 YGNodeStyleSetWidth(child1, 80);
55 YGNodeStyleSetHeight(child1, 40);
56 YGNodeStyleSetMargin(child1, YGEdgeBottom, 5);
57 YGNodeInsertChild(root, child1, 1);
59 YGNodeCalculateLayout(root, 200, 100, YGDirectionLTR);
61 ASSERT_TRUE(YGNodeLayoutGetHadOverflow(root));
64 TEST_F(YogaTest_HadOverflowTests, no_overflow_no_wrap_and_flex_children) {
65 const YGNodeRef child0 = YGNodeNewWithConfig(config);
66 YGNodeStyleSetWidth(child0, 80);
67 YGNodeStyleSetHeight(child0, 40);
68 YGNodeStyleSetMargin(child0, YGEdgeTop, 10);
69 YGNodeStyleSetMargin(child0, YGEdgeBottom, 10);
70 YGNodeInsertChild(root, child0, 0);
71 const YGNodeRef child1 = YGNodeNewWithConfig(config);
72 YGNodeStyleSetWidth(child1, 80);
73 YGNodeStyleSetHeight(child1, 40);
74 YGNodeStyleSetMargin(child1, YGEdgeBottom, 5);
75 YGNodeStyleSetFlexShrink(child1, 1);
76 YGNodeInsertChild(root, child1, 1);
78 YGNodeCalculateLayout(root, 200, 100, YGDirectionLTR);
80 ASSERT_FALSE(YGNodeLayoutGetHadOverflow(root));
83 TEST_F(YogaTest_HadOverflowTests, hadOverflow_gets_reset_if_not_logger_valid) {
84 const YGNodeRef child0 = YGNodeNewWithConfig(config);
85 YGNodeStyleSetWidth(child0, 80);
86 YGNodeStyleSetHeight(child0, 40);
87 YGNodeStyleSetMargin(child0, YGEdgeTop, 10);
88 YGNodeStyleSetMargin(child0, YGEdgeBottom, 10);
89 YGNodeInsertChild(root, child0, 0);
90 const YGNodeRef child1 = YGNodeNewWithConfig(config);
91 YGNodeStyleSetWidth(child1, 80);
92 YGNodeStyleSetHeight(child1, 40);
93 YGNodeStyleSetMargin(child1, YGEdgeBottom, 5);
94 YGNodeInsertChild(root, child1, 1);
96 YGNodeCalculateLayout(root, 200, 100, YGDirectionLTR);
98 ASSERT_TRUE(YGNodeLayoutGetHadOverflow(root));
100 YGNodeStyleSetFlexShrink(child1, 1);
102 YGNodeCalculateLayout(root, 200, 100, YGDirectionLTR);
104 ASSERT_FALSE(YGNodeLayoutGetHadOverflow(root));
107 TEST_F(YogaTest_HadOverflowTests, spacing_overflow_in_nested_nodes) {
108 const YGNodeRef child0 = YGNodeNewWithConfig(config);
109 YGNodeStyleSetWidth(child0, 80);
110 YGNodeStyleSetHeight(child0, 40);
111 YGNodeStyleSetMargin(child0, YGEdgeTop, 10);
112 YGNodeStyleSetMargin(child0, YGEdgeBottom, 10);
113 YGNodeInsertChild(root, child0, 0);
114 const YGNodeRef child1 = YGNodeNewWithConfig(config);
115 YGNodeStyleSetWidth(child1, 80);
116 YGNodeStyleSetHeight(child1, 40);
117 YGNodeInsertChild(root, child1, 1);
118 const YGNodeRef child1_1 = YGNodeNewWithConfig(config);
119 YGNodeStyleSetWidth(child1_1, 80);
120 YGNodeStyleSetHeight(child1_1, 40);
121 YGNodeStyleSetMargin(child1_1, YGEdgeBottom, 5);
122 YGNodeInsertChild(child1, child1_1, 0);
124 YGNodeCalculateLayout(root, 200, 100, YGDirectionLTR);
126 ASSERT_TRUE(YGNodeLayoutGetHadOverflow(root));