Rebase of facebook flexbox to yoga
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit-third-party / yoga / YGHadOverflowTest.cpp
1 // Copyright 2004-present Facebook. All Rights Reserved.
2
3 #include <gtest/gtest.h>
4 #include <yoga/Yoga.h>
5
6 using namespace ::testing;
7
8 class YogaTest_HadOverflowTests : public testing::Test {
9 protected:
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);
17   }
18
19   ~YogaTest_HadOverflowTests() {
20     YGNodeFreeRecursive(root);
21     YGConfigFree(config);
22   }
23
24   YGNodeRef root;
25   YGConfigRef config;
26 };
27
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);
40
41   YGNodeCalculateLayout(root, 200, 100, YGDirectionLTR);
42
43   ASSERT_TRUE(YGNodeLayoutGetHadOverflow(root));
44 }
45
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);
58
59   YGNodeCalculateLayout(root, 200, 100, YGDirectionLTR);
60
61   ASSERT_TRUE(YGNodeLayoutGetHadOverflow(root));
62 }
63
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);
77
78   YGNodeCalculateLayout(root, 200, 100, YGDirectionLTR);
79
80   ASSERT_FALSE(YGNodeLayoutGetHadOverflow(root));
81 }
82
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);
95
96   YGNodeCalculateLayout(root, 200, 100, YGDirectionLTR);
97
98   ASSERT_TRUE(YGNodeLayoutGetHadOverflow(root));
99
100   YGNodeStyleSetFlexShrink(child1, 1);
101
102   YGNodeCalculateLayout(root, 200, 100, YGDirectionLTR);
103
104   ASSERT_FALSE(YGNodeLayoutGetHadOverflow(root));
105 }
106
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);
123
124   YGNodeCalculateLayout(root, 200, 100, YGDirectionLTR);
125
126   ASSERT_TRUE(YGNodeLayoutGetHadOverflow(root));
127 }