Summary: This does some preprataion for the Yoga CMake Build. The main change is removing the dedicated testutil top-level-directory and static library. This contains a method to count nodes using the event functions exposed to C++, along with a Java binding for the test utility (since the events don't have a Java binding). It is only used in a single place in a way that isn't very useful, so it simplifies things to treat is as source in the existing C++ test library. This also separates the hand-written and generated UTs, like we are doing in the JS directory in D42207782. Reviewed By: christophpurrer Differential Revision: D42247762 fbshipit-source-id: f8a270e99d0315ba7fc608f2471333e7a7be9d79
94 lines
3.4 KiB
C++
94 lines
3.4 KiB
C++
/*
|
|
* 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/YGNode.h>
|
|
#include <yoga/Yoga.h>
|
|
|
|
#include "util/TestUtil.h"
|
|
|
|
using facebook::yoga::test::TestUtil;
|
|
|
|
TEST(YogaTest, assert_layout_trees_are_same) {
|
|
TestUtil::startCountingNodes();
|
|
|
|
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 = TestUtil::nodeCount();
|
|
|
|
YGNodeCalculateLayout(root1, YGUndefined, YGUndefined, YGDirectionLTR);
|
|
|
|
ASSERT_EQ(YGConfigGetInstanceCount(), cal1_configInstanceCount);
|
|
ASSERT_EQ(TestUtil::nodeCount(), 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 = TestUtil::nodeCount();
|
|
|
|
YGNodeCalculateLayout(root2, YGUndefined, YGUndefined, YGDirectionLTR);
|
|
|
|
ASSERT_EQ(YGConfigGetInstanceCount(), cal2_configInstanceCount);
|
|
ASSERT_EQ(TestUtil::nodeCount(), 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 = TestUtil::nodeCount();
|
|
|
|
YGNodeCalculateLayout(root2, YGUndefined, YGUndefined, YGDirectionLTR);
|
|
|
|
ASSERT_EQ(YGConfigGetInstanceCount(), cal3_configInstanceCount);
|
|
ASSERT_EQ(TestUtil::stopCountingNodes(), cal3_nodeInstanceCount);
|
|
|
|
ASSERT_FALSE(root1->isLayoutTreeEqualToNode(*root2));
|
|
|
|
YGNodeFreeRecursive(root1);
|
|
YGNodeFreeRecursive(root2);
|
|
|
|
YGConfigFree(config);
|
|
}
|