2 * Copyright (c) 2014-present, Facebook, Inc.
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
8 #include <gtest/gtest.h>
9 #include <yoga/YGNode.h>
12 TEST(YogaTest, copy_style_same) {
13 const YGNodeRef node0 = YGNodeNew();
14 const YGNodeRef node1 = YGNodeNew();
15 ASSERT_FALSE(node0->isDirty());
17 YGNodeCopyStyle(node0, node1);
18 ASSERT_FALSE(node0->isDirty());
24 TEST(YogaTest, copy_style_modified) {
25 const YGNodeRef node0 = YGNodeNew();
26 ASSERT_FALSE(node0->isDirty());
27 ASSERT_EQ(YGFlexDirectionColumn, YGNodeStyleGetFlexDirection(node0));
28 ASSERT_FALSE(YGNodeStyleGetMaxHeight(node0).unit != YGUnitUndefined);
30 const YGNodeRef node1 = YGNodeNew();
31 YGNodeStyleSetFlexDirection(node1, YGFlexDirectionRow);
32 YGNodeStyleSetMaxHeight(node1, 10);
34 YGNodeCopyStyle(node0, node1);
35 ASSERT_TRUE(node0->isDirty());
36 ASSERT_EQ(YGFlexDirectionRow, YGNodeStyleGetFlexDirection(node0));
37 ASSERT_FLOAT_EQ(10, YGNodeStyleGetMaxHeight(node0).value);
43 TEST(YogaTest, copy_style_modified_same) {
44 const YGNodeRef node0 = YGNodeNew();
45 YGNodeStyleSetFlexDirection(node0, YGFlexDirectionRow);
46 YGNodeStyleSetMaxHeight(node0, 10);
47 YGNodeCalculateLayout(node0, YGUndefined, YGUndefined, YGDirectionLTR);
48 ASSERT_FALSE(node0->isDirty());
50 const YGNodeRef node1 = YGNodeNew();
51 YGNodeStyleSetFlexDirection(node1, YGFlexDirectionRow);
52 YGNodeStyleSetMaxHeight(node1, 10);
54 YGNodeCopyStyle(node0, node1);
55 ASSERT_FALSE(node0->isDirty());
61 TEST(YogaTest, initialise_flexShrink_flexGrow) {
62 const YGNodeRef node0 = YGNodeNew();
63 YGNodeStyleSetFlexShrink(node0, 1);
64 ASSERT_EQ(1, YGNodeStyleGetFlexShrink(node0));
66 YGNodeStyleSetFlexShrink(node0, YGUndefined);
67 YGNodeStyleSetFlexGrow(node0, 3);
70 YGNodeStyleGetFlexShrink(
71 node0)); // Default value is Zero, if flex shrink is not defined
72 ASSERT_EQ(3, YGNodeStyleGetFlexGrow(node0));
74 YGNodeStyleSetFlexGrow(node0, YGUndefined);
75 YGNodeStyleSetFlexShrink(node0, 3);
78 YGNodeStyleGetFlexGrow(
79 node0)); // Default value is Zero, if flex grow is not defined
80 ASSERT_EQ(3, YGNodeStyleGetFlexShrink(node0));