forked from facebook/yoga
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathYGHadOverflowTest.cpp
127 lines (104 loc) · 4.21 KB
/
YGHadOverflowTest.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
// Copyright 2004-present Facebook. All Rights Reserved.
#include <gtest/gtest.h>
#include <yoga/Yoga.h>
using namespace ::testing;
class YogaTest_HadOverflowTests : public Test {
protected:
YogaTest_HadOverflowTests() {
config = YGConfigNew();
root = YGNodeNewWithConfig(config);
YGNodeStyleSetWidth(root, 200);
YGNodeStyleSetHeight(root, 100);
YGNodeStyleSetFlexDirection(root, YGFlexDirectionColumn);
YGNodeStyleSetFlexWrap(root, YGWrapNoWrap);
}
~YogaTest_HadOverflowTests() {
YGNodeFreeRecursive(root);
YGConfigFree(config);
}
YGNodeRef root;
YGConfigRef config;
};
TEST_F(YogaTest_HadOverflowTests, children_overflow_no_wrap_and_no_flex_children) {
const YGNodeRef child0 = YGNodeNewWithConfig(config);
YGNodeStyleSetWidth(child0, 80);
YGNodeStyleSetHeight(child0, 40);
YGNodeStyleSetMargin(child0, YGEdgeTop, 10);
YGNodeStyleSetMargin(child0, YGEdgeBottom, 15);
YGNodeInsertChild(root, child0, 0);
const YGNodeRef child1 = YGNodeNewWithConfig(config);
YGNodeStyleSetWidth(child1, 80);
YGNodeStyleSetHeight(child1, 40);
YGNodeStyleSetMargin(child1, YGEdgeBottom, 5);
YGNodeInsertChild(root, child1, 1);
YGNodeCalculateLayout(root, 200, 100, YGDirectionLTR);
ASSERT_TRUE(YGNodeLayoutGetHadOverflow(root));
}
TEST_F(YogaTest_HadOverflowTests, spacing_overflow_no_wrap_and_no_flex_children) {
const YGNodeRef child0 = YGNodeNewWithConfig(config);
YGNodeStyleSetWidth(child0, 80);
YGNodeStyleSetHeight(child0, 40);
YGNodeStyleSetMargin(child0, YGEdgeTop, 10);
YGNodeStyleSetMargin(child0, YGEdgeBottom, 10);
YGNodeInsertChild(root, child0, 0);
const YGNodeRef child1 = YGNodeNewWithConfig(config);
YGNodeStyleSetWidth(child1, 80);
YGNodeStyleSetHeight(child1, 40);
YGNodeStyleSetMargin(child1, YGEdgeBottom, 5);
YGNodeInsertChild(root, child1, 1);
YGNodeCalculateLayout(root, 200, 100, YGDirectionLTR);
ASSERT_TRUE(YGNodeLayoutGetHadOverflow(root));
}
TEST_F(YogaTest_HadOverflowTests, no_overflow_no_wrap_and_flex_children) {
const YGNodeRef child0 = YGNodeNewWithConfig(config);
YGNodeStyleSetWidth(child0, 80);
YGNodeStyleSetHeight(child0, 40);
YGNodeStyleSetMargin(child0, YGEdgeTop, 10);
YGNodeStyleSetMargin(child0, YGEdgeBottom, 10);
YGNodeInsertChild(root, child0, 0);
const YGNodeRef child1 = YGNodeNewWithConfig(config);
YGNodeStyleSetWidth(child1, 80);
YGNodeStyleSetHeight(child1, 40);
YGNodeStyleSetMargin(child1, YGEdgeBottom, 5);
YGNodeStyleSetFlexShrink(child1, 1);
YGNodeInsertChild(root, child1, 1);
YGNodeCalculateLayout(root, 200, 100, YGDirectionLTR);
ASSERT_FALSE(YGNodeLayoutGetHadOverflow(root));
}
TEST_F(YogaTest_HadOverflowTests, hadOverflow_gets_reset_if_not_logger_valid) {
const YGNodeRef child0 = YGNodeNewWithConfig(config);
YGNodeStyleSetWidth(child0, 80);
YGNodeStyleSetHeight(child0, 40);
YGNodeStyleSetMargin(child0, YGEdgeTop, 10);
YGNodeStyleSetMargin(child0, YGEdgeBottom, 10);
YGNodeInsertChild(root, child0, 0);
const YGNodeRef child1 = YGNodeNewWithConfig(config);
YGNodeStyleSetWidth(child1, 80);
YGNodeStyleSetHeight(child1, 40);
YGNodeStyleSetMargin(child1, YGEdgeBottom, 5);
YGNodeInsertChild(root, child1, 1);
YGNodeCalculateLayout(root, 200, 100, YGDirectionLTR);
ASSERT_TRUE(YGNodeLayoutGetHadOverflow(root));
YGNodeStyleSetFlexShrink(child1, 1);
YGNodeCalculateLayout(root, 200, 100, YGDirectionLTR);
ASSERT_FALSE(YGNodeLayoutGetHadOverflow(root));
}
TEST_F(YogaTest_HadOverflowTests, spacing_overflow_in_nested_nodes) {
const YGNodeRef child0 = YGNodeNewWithConfig(config);
YGNodeStyleSetWidth(child0, 80);
YGNodeStyleSetHeight(child0, 40);
YGNodeStyleSetMargin(child0, YGEdgeTop, 10);
YGNodeStyleSetMargin(child0, YGEdgeBottom, 10);
YGNodeInsertChild(root, child0, 0);
const YGNodeRef child1 = YGNodeNewWithConfig(config);
YGNodeStyleSetWidth(child1, 80);
YGNodeStyleSetHeight(child1, 40);
YGNodeInsertChild(root, child1, 1);
const YGNodeRef child1_1 = YGNodeNewWithConfig(config);
YGNodeStyleSetWidth(child1_1, 80);
YGNodeStyleSetHeight(child1_1, 40);
YGNodeStyleSetMargin(child1_1, YGEdgeBottom, 5);
YGNodeInsertChild(child1, child1_1, 0);
YGNodeCalculateLayout(root, 200, 100, YGDirectionLTR);
ASSERT_TRUE(YGNodeLayoutGetHadOverflow(root));
}