Rebase of facebook flexbox to yoga
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit-third-party / yoga / YGEdgeTest.cpp
1 /**
2  * Copyright (c) 2014-present, Facebook, Inc.
3  *
4  * This source code is licensed under the MIT license found in the
5  * LICENSE file in the root directory of this source tree.
6  */
7
8 #include <gtest/gtest.h>
9 #include <yoga/Yoga.h>
10
11 TEST(YogaTest, start_overrides) {
12   const YGNodeRef root = YGNodeNew();
13   YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow);
14   YGNodeStyleSetWidth(root, 100);
15   YGNodeStyleSetHeight(root, 100);
16
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);
23
24   YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
25   ASSERT_FLOAT_EQ(10, YGNodeLayoutGetLeft(root_child0));
26   ASSERT_FLOAT_EQ(20, YGNodeLayoutGetRight(root_child0));
27
28   YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
29   ASSERT_FLOAT_EQ(20, YGNodeLayoutGetLeft(root_child0));
30   ASSERT_FLOAT_EQ(10, YGNodeLayoutGetRight(root_child0));
31
32   YGNodeFreeRecursive(root);
33 }
34
35 TEST(YogaTest, end_overrides) {
36   const YGNodeRef root = YGNodeNew();
37   YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow);
38   YGNodeStyleSetWidth(root, 100);
39   YGNodeStyleSetHeight(root, 100);
40
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);
47
48   YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
49   ASSERT_FLOAT_EQ(20, YGNodeLayoutGetLeft(root_child0));
50   ASSERT_FLOAT_EQ(10, YGNodeLayoutGetRight(root_child0));
51
52   YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
53   ASSERT_FLOAT_EQ(10, YGNodeLayoutGetLeft(root_child0));
54   ASSERT_FLOAT_EQ(20, YGNodeLayoutGetRight(root_child0));
55
56   YGNodeFreeRecursive(root);
57 }
58
59 TEST(YogaTest, horizontal_overridden) {
60   const YGNodeRef root = YGNodeNew();
61   YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow);
62   YGNodeStyleSetWidth(root, 100);
63   YGNodeStyleSetHeight(root, 100);
64
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);
70
71   YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
72   ASSERT_FLOAT_EQ(20, YGNodeLayoutGetLeft(root_child0));
73   ASSERT_FLOAT_EQ(10, YGNodeLayoutGetRight(root_child0));
74
75   YGNodeFreeRecursive(root);
76 }
77
78 TEST(YogaTest, vertical_overridden) {
79   const YGNodeRef root = YGNodeNew();
80   YGNodeStyleSetFlexDirection(root, YGFlexDirectionColumn);
81   YGNodeStyleSetWidth(root, 100);
82   YGNodeStyleSetHeight(root, 100);
83
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);
89
90   YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
91   ASSERT_FLOAT_EQ(20, YGNodeLayoutGetTop(root_child0));
92   ASSERT_FLOAT_EQ(10, YGNodeLayoutGetBottom(root_child0));
93
94   YGNodeFreeRecursive(root);
95 }
96
97 TEST(YogaTest, horizontal_overrides_all) {
98   const YGNodeRef root = YGNodeNew();
99   YGNodeStyleSetFlexDirection(root, YGFlexDirectionColumn);
100   YGNodeStyleSetWidth(root, 100);
101   YGNodeStyleSetHeight(root, 100);
102
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);
108
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));
114
115   YGNodeFreeRecursive(root);
116 }
117
118 TEST(YogaTest, vertical_overrides_all) {
119   const YGNodeRef root = YGNodeNew();
120   YGNodeStyleSetFlexDirection(root, YGFlexDirectionColumn);
121   YGNodeStyleSetWidth(root, 100);
122   YGNodeStyleSetHeight(root, 100);
123
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);
129
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));
135
136   YGNodeFreeRecursive(root);
137 }
138
139 TEST(YogaTest, all_overridden) {
140   const YGNodeRef root = YGNodeNew();
141   YGNodeStyleSetFlexDirection(root, YGFlexDirectionColumn);
142   YGNodeStyleSetWidth(root, 100);
143   YGNodeStyleSetHeight(root, 100);
144
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);
153
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));
159
160   YGNodeFreeRecursive(root);
161 }