forked from cntrump/yoga
-
Notifications
You must be signed in to change notification settings - Fork 0
/
YGComputedMarginTest.cpp
115 lines (92 loc) · 3.86 KB
/
YGComputedMarginTest.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
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include <gtest/gtest.h>
#include <yoga/Yoga.h>
#include <array>
TEST(YogaTest, computed_layout_margin) {
const YGNodeRef root = YGNodeNew();
YGNodeStyleSetWidth(root, 100);
YGNodeStyleSetHeight(root, 100);
YGNodeStyleSetMarginPercent(root, YGEdgeStart, 10);
YGNodeCalculateLayout(root, 100, 100, YGDirectionLTR);
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetMargin(root, YGEdgeLeft));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetMargin(root, YGEdgeRight));
YGNodeCalculateLayout(root, 100, 100, YGDirectionRTL);
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetMargin(root, YGEdgeLeft));
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetMargin(root, YGEdgeRight));
YGNodeFreeRecursive(root);
}
TEST(YogaTest, margin_side_overrides_horizontal_and_vertical) {
const std::array<YGEdge, 6> edges = {{YGEdgeTop,
YGEdgeBottom,
YGEdgeStart,
YGEdgeEnd,
YGEdgeLeft,
YGEdgeRight}};
for (float edgeValue = 0; edgeValue < 2; ++edgeValue) {
for (const auto& edge : edges) {
YGEdge horizontalOrVertical = edge == YGEdgeTop || edge == YGEdgeBottom
? YGEdgeVertical
: YGEdgeHorizontal;
const YGNodeRef root = YGNodeNew();
YGNodeStyleSetWidth(root, 100);
YGNodeStyleSetHeight(root, 100);
YGNodeStyleSetMargin(root, horizontalOrVertical, 10);
YGNodeStyleSetMargin(root, edge, edgeValue);
YGNodeCalculateLayout(root, 100, 100, YGDirectionLTR);
ASSERT_FLOAT_EQ(edgeValue, YGNodeLayoutGetMargin(root, edge));
YGNodeFreeRecursive(root);
}
}
}
TEST(YogaTest, margin_side_overrides_all) {
const std::array<YGEdge, 6> edges = {{YGEdgeTop,
YGEdgeBottom,
YGEdgeStart,
YGEdgeEnd,
YGEdgeLeft,
YGEdgeRight}};
for (float edgeValue = 0; edgeValue < 2; ++edgeValue) {
for (const auto& edge : edges) {
const YGNodeRef root = YGNodeNew();
YGNodeStyleSetWidth(root, 100);
YGNodeStyleSetHeight(root, 100);
YGNodeStyleSetMargin(root, YGEdgeAll, 10);
YGNodeStyleSetMargin(root, edge, edgeValue);
YGNodeCalculateLayout(root, 100, 100, YGDirectionLTR);
ASSERT_FLOAT_EQ(edgeValue, YGNodeLayoutGetMargin(root, edge));
YGNodeFreeRecursive(root);
}
}
}
TEST(YogaTest, margin_horizontal_and_vertical_overrides_all) {
const std::array<YGEdge, 2> directions = {{YGEdgeHorizontal, YGEdgeVertical}};
for (float directionValue = 0; directionValue < 2; ++directionValue) {
for (const auto& direction : directions) {
const YGNodeRef root = YGNodeNew();
YGNodeStyleSetWidth(root, 100);
YGNodeStyleSetHeight(root, 100);
YGNodeStyleSetMargin(root, YGEdgeAll, 10);
YGNodeStyleSetMargin(root, direction, directionValue);
YGNodeCalculateLayout(root, 100, 100, YGDirectionLTR);
if (direction == YGEdgeVertical) {
ASSERT_FLOAT_EQ(directionValue, YGNodeLayoutGetMargin(root, YGEdgeTop));
ASSERT_FLOAT_EQ(
directionValue, YGNodeLayoutGetMargin(root, YGEdgeBottom));
} else {
ASSERT_FLOAT_EQ(
directionValue, YGNodeLayoutGetMargin(root, YGEdgeStart));
ASSERT_FLOAT_EQ(directionValue, YGNodeLayoutGetMargin(root, YGEdgeEnd));
ASSERT_FLOAT_EQ(
directionValue, YGNodeLayoutGetMargin(root, YGEdgeLeft));
ASSERT_FLOAT_EQ(
directionValue, YGNodeLayoutGetMargin(root, YGEdgeRight));
}
YGNodeFreeRecursive(root);
}
}
}