File: YGLayoutableChildrenTest.cpp

package info (click to toggle)
yoga 3.2.1%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 984 kB
  • sloc: cpp: 12,985; python: 260; sh: 32; makefile: 6
file content (191 lines) | stat: -rw-r--r-- 6,006 bytes parent folder | download | duplicates (2)
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/*
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */

#include <gtest/gtest.h>
#include <yoga/Yoga.h>
#include <yoga/node/Node.h>
#include <cstdio>

TEST(YogaTest, layoutable_children_single_contents_node) {
  YGNodeRef root = YGNodeNew();

  YGNodeRef root_child0 = YGNodeNew();
  YGNodeRef root_child1 = YGNodeNew();
  YGNodeRef root_child2 = YGNodeNew();

  YGNodeRef root_grandchild0 = YGNodeNew();
  YGNodeRef root_grandchild1 = YGNodeNew();

  YGNodeInsertChild(root, root_child0, 0);
  YGNodeInsertChild(root, root_child1, 1);
  YGNodeInsertChild(root, root_child2, 2);

  YGNodeInsertChild(root_child1, root_grandchild0, 0);
  YGNodeInsertChild(root_child1, root_grandchild1, 1);

  YGNodeStyleSetDisplay(root_child1, YGDisplayContents);

  std::vector<facebook::yoga::Node*> order = {
      facebook::yoga::resolveRef(root_child0),
      facebook::yoga::resolveRef(root_grandchild0),
      facebook::yoga::resolveRef(root_grandchild1),
      facebook::yoga::resolveRef(root_child2),
  };
  auto correctOrderIt = order.begin();

  for (auto node : facebook::yoga::resolveRef(root)->getLayoutChildren()) {
    ASSERT_EQ(node, *correctOrderIt);
    correctOrderIt++;
  }

  YGNodeFreeRecursive(root);
}

TEST(YogaTest, layoutable_children_multiple_contents_nodes) {
  YGNodeRef root = YGNodeNew();

  YGNodeRef root_child0 = YGNodeNew();
  YGNodeRef root_child1 = YGNodeNew();
  YGNodeRef root_child2 = YGNodeNew();

  YGNodeRef root_grandchild0 = YGNodeNew();
  YGNodeRef root_grandchild1 = YGNodeNew();
  YGNodeRef root_grandchild2 = YGNodeNew();
  YGNodeRef root_grandchild3 = YGNodeNew();
  YGNodeRef root_grandchild4 = YGNodeNew();
  YGNodeRef root_grandchild5 = YGNodeNew();

  YGNodeInsertChild(root, root_child0, 0);
  YGNodeInsertChild(root, root_child1, 1);
  YGNodeInsertChild(root, root_child2, 2);

  YGNodeInsertChild(root_child0, root_grandchild0, 0);
  YGNodeInsertChild(root_child0, root_grandchild1, 1);
  YGNodeInsertChild(root_child1, root_grandchild2, 0);
  YGNodeInsertChild(root_child1, root_grandchild3, 1);
  YGNodeInsertChild(root_child2, root_grandchild4, 0);
  YGNodeInsertChild(root_child2, root_grandchild5, 1);

  YGNodeStyleSetDisplay(root_child0, YGDisplayContents);
  YGNodeStyleSetDisplay(root_child1, YGDisplayContents);
  YGNodeStyleSetDisplay(root_child2, YGDisplayContents);

  std::vector<facebook::yoga::Node*> order = {
      facebook::yoga::resolveRef(root_grandchild0),
      facebook::yoga::resolveRef(root_grandchild1),
      facebook::yoga::resolveRef(root_grandchild2),
      facebook::yoga::resolveRef(root_grandchild3),
      facebook::yoga::resolveRef(root_grandchild4),
      facebook::yoga::resolveRef(root_grandchild5),
  };
  auto correctOrderIt = order.begin();

  for (auto node : facebook::yoga::resolveRef(root)->getLayoutChildren()) {
    ASSERT_EQ(node, *correctOrderIt);
    correctOrderIt++;
  }

  YGNodeFreeRecursive(root);
}

TEST(YogaTest, layoutable_children_nested_contents_nodes) {
  YGNodeRef root = YGNodeNew();

  YGNodeRef root_child0 = YGNodeNew();
  YGNodeRef root_child1 = YGNodeNew();
  YGNodeRef root_child2 = YGNodeNew();

  YGNodeRef root_grandchild0 = YGNodeNew();
  YGNodeRef root_grandchild1 = YGNodeNew();

  YGNodeRef root_great_grandchild0 = YGNodeNew();
  YGNodeRef root_great_grandchild1 = YGNodeNew();

  YGNodeInsertChild(root, root_child0, 0);
  YGNodeInsertChild(root, root_child1, 1);
  YGNodeInsertChild(root, root_child2, 2);

  YGNodeInsertChild(root_child1, root_grandchild0, 0);
  YGNodeInsertChild(root_child1, root_grandchild1, 1);

  YGNodeInsertChild(root_grandchild1, root_great_grandchild0, 0);
  YGNodeInsertChild(root_grandchild1, root_great_grandchild1, 1);

  YGNodeStyleSetDisplay(root_child1, YGDisplayContents);
  YGNodeStyleSetDisplay(root_grandchild1, YGDisplayContents);

  std::vector<facebook::yoga::Node*> order = {
      facebook::yoga::resolveRef(root_child0),
      facebook::yoga::resolveRef(root_grandchild0),
      facebook::yoga::resolveRef(root_great_grandchild0),
      facebook::yoga::resolveRef(root_great_grandchild1),
      facebook::yoga::resolveRef(root_child2),
  };
  auto correctOrderIt = order.begin();

  for (auto node : facebook::yoga::resolveRef(root)->getLayoutChildren()) {
    ASSERT_EQ(node, *correctOrderIt);
    correctOrderIt++;
  }

  YGNodeFreeRecursive(root);
}

TEST(YogaTest, layoutable_children_contents_leaf_node) {
  YGNodeRef root = YGNodeNew();

  YGNodeRef root_child0 = YGNodeNew();
  YGNodeRef root_child1 = YGNodeNew();
  YGNodeRef root_child2 = YGNodeNew();

  YGNodeInsertChild(root, root_child0, 0);
  YGNodeInsertChild(root, root_child1, 1);
  YGNodeInsertChild(root, root_child2, 2);

  YGNodeStyleSetDisplay(root_child1, YGDisplayContents);

  std::vector<facebook::yoga::Node*> order = {
      facebook::yoga::resolveRef(root_child0),
      facebook::yoga::resolveRef(root_child2),
  };
  auto correctOrderIt = order.begin();

  for (auto node : facebook::yoga::resolveRef(root)->getLayoutChildren()) {
    ASSERT_EQ(node, *correctOrderIt);
    correctOrderIt++;
  }

  YGNodeFreeRecursive(root);
}

TEST(YogaTest, layoutable_children_contents_root_node) {
  YGNodeRef root = YGNodeNew();

  YGNodeRef root_child0 = YGNodeNew();
  YGNodeRef root_child1 = YGNodeNew();
  YGNodeRef root_child2 = YGNodeNew();

  YGNodeInsertChild(root, root_child0, 0);
  YGNodeInsertChild(root, root_child1, 1);
  YGNodeInsertChild(root, root_child2, 2);

  YGNodeStyleSetDisplay(root, YGDisplayContents);

  std::vector<facebook::yoga::Node*> order = {
      facebook::yoga::resolveRef(root_child0),
      facebook::yoga::resolveRef(root_child1),
      facebook::yoga::resolveRef(root_child2),
  };
  auto correctOrderIt = order.begin();

  for (auto node : facebook::yoga::resolveRef(root)->getLayoutChildren()) {
    ASSERT_EQ(node, *correctOrderIt);
    correctOrderIt++;
  }

  YGNodeFreeRecursive(root);
}