Files
yoga/tests/YGLayoutDiffingTest.cpp
Sophie Alpert a2b6ddb7b1 Update license headers for MIT license
Summary:
Includes React Native and its dependencies Fresco, Metro, and Yoga. Excludes samples/examples/docs.

find: ^(?:( *)|( *(?:[\*~#]|::))( )? *)?Copyright (?:\(c\) )?(\d{4})\b.+Facebook[\s\S]+?BSD[\s\S]+?(?:this source tree|the same directory)\.$
replace: $1$2$3Copyright (c) $4-present, Facebook, Inc.\n$2\n$1$2$3This source code is licensed under the MIT license found in the\n$1$2$3LICENSE file in the root directory of this source tree.

Reviewed By: TheSavior, yungsters

Differential Revision: D7007050

fbshipit-source-id: 37dd6bf0ffec0923bfc99c260bb330683f35553e
2018-02-16 18:27:33 -08:00

88 lines
3.3 KiB
C++

/**
* Copyright (c) 2014-present, Facebook, Inc.
*
* 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/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);
}