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 TEST(YogaTest, start_overrides) {
12 const YGNodeRef root = YGNodeNew();
13 YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow);
14 YGNodeStyleSetWidth(root, 100);
15 YGNodeStyleSetHeight(root, 100);
17 const YGNodeRef root_child0 = YGNodeNew();
18 YGNodeStyleSetFlexGrow(root_child0, 1);
19 YGNodeStyleSetMargin(root_child0, YGEdgeStart, 10);
20 YGNodeStyleSetMargin(root_child0, YGEdgeLeft, 20);
21 YGNodeStyleSetMargin(root_child0, YGEdgeRight, 20);
22 YGNodeInsertChild(root, root_child0, 0);
24 YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
25 ASSERT_FLOAT_EQ(10, YGNodeLayoutGetLeft(root_child0));
26 ASSERT_FLOAT_EQ(20, YGNodeLayoutGetRight(root_child0));
28 YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
29 ASSERT_FLOAT_EQ(20, YGNodeLayoutGetLeft(root_child0));
30 ASSERT_FLOAT_EQ(10, YGNodeLayoutGetRight(root_child0));
32 YGNodeFreeRecursive(root);
35 TEST(YogaTest, end_overrides) {
36 const YGNodeRef root = YGNodeNew();
37 YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow);
38 YGNodeStyleSetWidth(root, 100);
39 YGNodeStyleSetHeight(root, 100);
41 const YGNodeRef root_child0 = YGNodeNew();
42 YGNodeStyleSetFlexGrow(root_child0, 1);
43 YGNodeStyleSetMargin(root_child0, YGEdgeEnd, 10);
44 YGNodeStyleSetMargin(root_child0, YGEdgeLeft, 20);
45 YGNodeStyleSetMargin(root_child0, YGEdgeRight, 20);
46 YGNodeInsertChild(root, root_child0, 0);
48 YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
49 ASSERT_FLOAT_EQ(20, YGNodeLayoutGetLeft(root_child0));
50 ASSERT_FLOAT_EQ(10, YGNodeLayoutGetRight(root_child0));
52 YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
53 ASSERT_FLOAT_EQ(10, YGNodeLayoutGetLeft(root_child0));
54 ASSERT_FLOAT_EQ(20, YGNodeLayoutGetRight(root_child0));
56 YGNodeFreeRecursive(root);
59 TEST(YogaTest, horizontal_overridden) {
60 const YGNodeRef root = YGNodeNew();
61 YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow);
62 YGNodeStyleSetWidth(root, 100);
63 YGNodeStyleSetHeight(root, 100);
65 const YGNodeRef root_child0 = YGNodeNew();
66 YGNodeStyleSetFlexGrow(root_child0, 1);
67 YGNodeStyleSetMargin(root_child0, YGEdgeHorizontal, 10);
68 YGNodeStyleSetMargin(root_child0, YGEdgeLeft, 20);
69 YGNodeInsertChild(root, root_child0, 0);
71 YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
72 ASSERT_FLOAT_EQ(20, YGNodeLayoutGetLeft(root_child0));
73 ASSERT_FLOAT_EQ(10, YGNodeLayoutGetRight(root_child0));
75 YGNodeFreeRecursive(root);
78 TEST(YogaTest, vertical_overridden) {
79 const YGNodeRef root = YGNodeNew();
80 YGNodeStyleSetFlexDirection(root, YGFlexDirectionColumn);
81 YGNodeStyleSetWidth(root, 100);
82 YGNodeStyleSetHeight(root, 100);
84 const YGNodeRef root_child0 = YGNodeNew();
85 YGNodeStyleSetFlexGrow(root_child0, 1);
86 YGNodeStyleSetMargin(root_child0, YGEdgeVertical, 10);
87 YGNodeStyleSetMargin(root_child0, YGEdgeTop, 20);
88 YGNodeInsertChild(root, root_child0, 0);
90 YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
91 ASSERT_FLOAT_EQ(20, YGNodeLayoutGetTop(root_child0));
92 ASSERT_FLOAT_EQ(10, YGNodeLayoutGetBottom(root_child0));
94 YGNodeFreeRecursive(root);
97 TEST(YogaTest, horizontal_overrides_all) {
98 const YGNodeRef root = YGNodeNew();
99 YGNodeStyleSetFlexDirection(root, YGFlexDirectionColumn);
100 YGNodeStyleSetWidth(root, 100);
101 YGNodeStyleSetHeight(root, 100);
103 const YGNodeRef root_child0 = YGNodeNew();
104 YGNodeStyleSetFlexGrow(root_child0, 1);
105 YGNodeStyleSetMargin(root_child0, YGEdgeHorizontal, 10);
106 YGNodeStyleSetMargin(root_child0, YGEdgeAll, 20);
107 YGNodeInsertChild(root, root_child0, 0);
109 YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
110 ASSERT_FLOAT_EQ(10, YGNodeLayoutGetLeft(root_child0));
111 ASSERT_FLOAT_EQ(20, YGNodeLayoutGetTop(root_child0));
112 ASSERT_FLOAT_EQ(10, YGNodeLayoutGetRight(root_child0));
113 ASSERT_FLOAT_EQ(20, YGNodeLayoutGetBottom(root_child0));
115 YGNodeFreeRecursive(root);
118 TEST(YogaTest, vertical_overrides_all) {
119 const YGNodeRef root = YGNodeNew();
120 YGNodeStyleSetFlexDirection(root, YGFlexDirectionColumn);
121 YGNodeStyleSetWidth(root, 100);
122 YGNodeStyleSetHeight(root, 100);
124 const YGNodeRef root_child0 = YGNodeNew();
125 YGNodeStyleSetFlexGrow(root_child0, 1);
126 YGNodeStyleSetMargin(root_child0, YGEdgeVertical, 10);
127 YGNodeStyleSetMargin(root_child0, YGEdgeAll, 20);
128 YGNodeInsertChild(root, root_child0, 0);
130 YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
131 ASSERT_FLOAT_EQ(20, YGNodeLayoutGetLeft(root_child0));
132 ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child0));
133 ASSERT_FLOAT_EQ(20, YGNodeLayoutGetRight(root_child0));
134 ASSERT_FLOAT_EQ(10, YGNodeLayoutGetBottom(root_child0));
136 YGNodeFreeRecursive(root);
139 TEST(YogaTest, all_overridden) {
140 const YGNodeRef root = YGNodeNew();
141 YGNodeStyleSetFlexDirection(root, YGFlexDirectionColumn);
142 YGNodeStyleSetWidth(root, 100);
143 YGNodeStyleSetHeight(root, 100);
145 const YGNodeRef root_child0 = YGNodeNew();
146 YGNodeStyleSetFlexGrow(root_child0, 1);
147 YGNodeStyleSetMargin(root_child0, YGEdgeLeft, 10);
148 YGNodeStyleSetMargin(root_child0, YGEdgeTop, 10);
149 YGNodeStyleSetMargin(root_child0, YGEdgeRight, 10);
150 YGNodeStyleSetMargin(root_child0, YGEdgeBottom, 10);
151 YGNodeStyleSetMargin(root_child0, YGEdgeAll, 20);
152 YGNodeInsertChild(root, root_child0, 0);
154 YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
155 ASSERT_FLOAT_EQ(10, YGNodeLayoutGetLeft(root_child0));
156 ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child0));
157 ASSERT_FLOAT_EQ(10, YGNodeLayoutGetRight(root_child0));
158 ASSERT_FLOAT_EQ(10, YGNodeLayoutGetBottom(root_child0));
160 YGNodeFreeRecursive(root);