Rebase of facebook flexbox to yoga
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit-third-party / yoga / YGLayoutDiffingTest.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/YGNode.h>
10 #include <yoga/Yoga.h>
11
12 TEST(YogaTest, assert_layout_trees_are_same) {
13   YGConfig* config = YGConfigNew();
14   YGConfigSetUseLegacyStretchBehaviour(config, true);
15   const YGNodeRef root1 = YGNodeNewWithConfig(config);
16   YGNodeStyleSetWidth(root1, 500);
17   YGNodeStyleSetHeight(root1, 500);
18
19   const YGNodeRef root1_child0 = YGNodeNewWithConfig(config);
20   YGNodeStyleSetAlignItems(root1_child0, YGAlignFlexStart);
21   YGNodeInsertChild(root1, root1_child0, 0);
22
23   const YGNodeRef root1_child0_child0 = YGNodeNewWithConfig(config);
24   YGNodeStyleSetFlexGrow(root1_child0_child0, 1);
25   YGNodeStyleSetFlexShrink(root1_child0_child0, 1);
26   YGNodeInsertChild(root1_child0, root1_child0_child0, 0);
27
28   const YGNodeRef root1_child0_child0_child0 = YGNodeNewWithConfig(config);
29   YGNodeStyleSetFlexGrow(root1_child0_child0_child0, 1);
30   YGNodeStyleSetFlexShrink(root1_child0_child0_child0, 1);
31   YGNodeInsertChild(root1_child0_child0, root1_child0_child0_child0, 0);
32
33   const int32_t cal1_configInstanceCount = YGConfigGetInstanceCount();
34   const int32_t cal1_nodeInstanceCount = YGNodeGetInstanceCount();
35
36   YGNodeCalculateLayout(root1, YGUndefined, YGUndefined, YGDirectionLTR);
37
38   ASSERT_EQ(YGConfigGetInstanceCount(), cal1_configInstanceCount);
39   ASSERT_EQ(YGNodeGetInstanceCount(), cal1_nodeInstanceCount);
40
41   const YGNodeRef root2 = YGNodeNewWithConfig(config);
42   YGNodeStyleSetWidth(root2, 500);
43   YGNodeStyleSetHeight(root2, 500);
44
45   const YGNodeRef root2_child0 = YGNodeNewWithConfig(config);
46   YGNodeStyleSetAlignItems(root2_child0, YGAlignFlexStart);
47   YGNodeInsertChild(root2, root2_child0, 0);
48
49   const YGNodeRef root2_child0_child0 = YGNodeNewWithConfig(config);
50   YGNodeStyleSetFlexGrow(root2_child0_child0, 1);
51   YGNodeStyleSetFlexShrink(root2_child0_child0, 1);
52   YGNodeInsertChild(root2_child0, root2_child0_child0, 0);
53
54   const YGNodeRef root2_child0_child0_child0 = YGNodeNewWithConfig(config);
55   YGNodeStyleSetFlexGrow(root2_child0_child0_child0, 1);
56   YGNodeStyleSetFlexShrink(root2_child0_child0_child0, 1);
57   YGNodeInsertChild(root2_child0_child0, root2_child0_child0_child0, 0);
58
59   const int32_t cal2_configInstanceCount = YGConfigGetInstanceCount();
60   const int32_t cal2_nodeInstanceCount = YGNodeGetInstanceCount();
61
62   YGNodeCalculateLayout(root2, YGUndefined, YGUndefined, YGDirectionLTR);
63
64   ASSERT_EQ(YGConfigGetInstanceCount(), cal2_configInstanceCount);
65   ASSERT_EQ(YGNodeGetInstanceCount(), cal2_nodeInstanceCount);
66
67   ASSERT_TRUE(YGNodeLayoutGetDidUseLegacyFlag(root1));
68   ASSERT_TRUE(YGNodeLayoutGetDidUseLegacyFlag(root2));
69   ASSERT_TRUE(root1->isLayoutTreeEqualToNode(*root2));
70
71   YGNodeStyleSetAlignItems(root2, YGAlignFlexEnd);
72
73   const int32_t cal3_configInstanceCount = YGConfigGetInstanceCount();
74   const int32_t cal3_nodeInstanceCount = YGNodeGetInstanceCount();
75
76   YGNodeCalculateLayout(root2, YGUndefined, YGUndefined, YGDirectionLTR);
77
78   ASSERT_EQ(YGConfigGetInstanceCount(), cal3_configInstanceCount);
79   ASSERT_EQ(YGNodeGetInstanceCount(), cal3_nodeInstanceCount);
80
81   ASSERT_FALSE(root1->isLayoutTreeEqualToNode(*root2));
82
83   YGNodeFreeRecursive(root1);
84   YGNodeFreeRecursive(root2);
85
86   YGConfigFree(config);
87 }