forked from facebook/yoga
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathYGLayoutDiffingTest.cpp
89 lines (66 loc) · 3.42 KB
/
YGLayoutDiffingTest.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
/**
* Copyright (c) 2014-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
#include <gtest/gtest.h>
#include <yoga/YGNode.h>
#include <yoga/Yoga.h>
TEST(YogaTest, assert_layout_trees_are_same) {
YGConfig* config = YGConfigNew();
YGConfigSetUseLegacyStretchBehaviour(config, true);
const YGNodeRef root1 = YGNodeNewWithConfig(config);
YGNodeStyleSetWidth(root1, 500);
YGNodeStyleSetHeight(root1, 500);
const YGNodeRef root1_child0 = YGNodeNewWithConfig(config);
YGNodeStyleSetAlignItems(root1_child0, YGAlignFlexStart);
YGNodeInsertChild(root1, root1_child0, 0);
const YGNodeRef root1_child0_child0 = YGNodeNewWithConfig(config);
YGNodeStyleSetFlexGrow(root1_child0_child0, 1);
YGNodeStyleSetFlexShrink(root1_child0_child0, 1);
YGNodeInsertChild(root1_child0, root1_child0_child0, 0);
const YGNodeRef root1_child0_child0_child0 = YGNodeNewWithConfig(config);
YGNodeStyleSetFlexGrow(root1_child0_child0_child0, 1);
YGNodeStyleSetFlexShrink(root1_child0_child0_child0, 1);
YGNodeInsertChild(root1_child0_child0, root1_child0_child0_child0, 0);
const int32_t cal1_configInstanceCount = YGConfigGetInstanceCount();
const int32_t cal1_nodeInstanceCount = YGNodeGetInstanceCount();
YGNodeCalculateLayout(root1, YGUndefined, YGUndefined, YGDirectionLTR);
ASSERT_EQ(YGConfigGetInstanceCount(), cal1_configInstanceCount);
ASSERT_EQ(YGNodeGetInstanceCount(), cal1_nodeInstanceCount);
const YGNodeRef root2 = YGNodeNewWithConfig(config);
YGNodeStyleSetWidth(root2, 500);
YGNodeStyleSetHeight(root2, 500);
const YGNodeRef root2_child0 = YGNodeNewWithConfig(config);
YGNodeStyleSetAlignItems(root2_child0, YGAlignFlexStart);
YGNodeInsertChild(root2, root2_child0, 0);
const YGNodeRef root2_child0_child0 = YGNodeNewWithConfig(config);
YGNodeStyleSetFlexGrow(root2_child0_child0, 1);
YGNodeStyleSetFlexShrink(root2_child0_child0, 1);
YGNodeInsertChild(root2_child0, root2_child0_child0, 0);
const YGNodeRef root2_child0_child0_child0 = YGNodeNewWithConfig(config);
YGNodeStyleSetFlexGrow(root2_child0_child0_child0, 1);
YGNodeStyleSetFlexShrink(root2_child0_child0_child0, 1);
YGNodeInsertChild(root2_child0_child0, root2_child0_child0_child0, 0);
const int32_t cal2_configInstanceCount = YGConfigGetInstanceCount();
const int32_t cal2_nodeInstanceCount = YGNodeGetInstanceCount();
YGNodeCalculateLayout(root2, YGUndefined, YGUndefined, YGDirectionLTR);
ASSERT_EQ(YGConfigGetInstanceCount(), cal2_configInstanceCount);
ASSERT_EQ(YGNodeGetInstanceCount(), cal2_nodeInstanceCount);
ASSERT_TRUE(YGNodeLayoutGetDidUseLegacyFlag(root1));
ASSERT_TRUE(YGNodeLayoutGetDidUseLegacyFlag(root2));
ASSERT_TRUE(root1->isLayoutTreeEqualToNode(*root2));
YGNodeStyleSetAlignItems(root2, YGAlignFlexEnd);
const int32_t cal3_configInstanceCount = YGConfigGetInstanceCount();
const int32_t cal3_nodeInstanceCount = YGNodeGetInstanceCount();
YGNodeCalculateLayout(root2, YGUndefined, YGUndefined, YGDirectionLTR);
ASSERT_EQ(YGConfigGetInstanceCount(), cal3_configInstanceCount);
ASSERT_EQ(YGNodeGetInstanceCount(), cal3_nodeInstanceCount);
ASSERT_FALSE(root1->isLayoutTreeEqualToNode(*root2));
YGNodeFreeRecursive(root1);
YGNodeFreeRecursive(root2);
YGConfigFree(config);
}