Switch tests to test utility for counting nodes

Summary:
@public
replaces the global node counter with the event-based one for all tests.

Reviewed By: SidharthGuglani

Differential Revision: D15174856

fbshipit-source-id: f4401d502bdbaf3b6e4632a4d985aac260cb35a8
This commit is contained in:
David Aurelio
2019-05-09 04:14:08 -07:00
committed by Facebook Github Bot
parent 6e04631862
commit 9e20dfeea1
3 changed files with 18 additions and 10 deletions

View File

@@ -31,9 +31,9 @@ public class YogaNodeTest {
@Test @Test
public void testInit() { public void testInit() {
final int refCount = YogaNative.jni_YGNodeGetInstanceCount(); TestUtil.startCountingNodes();
final YogaNode node = createNode(); final YogaNode node = createNode();
assertEquals(refCount + 1, YogaNative.jni_YGNodeGetInstanceCount()); assertEquals(1, TestUtil.stopCountingNodes());
} }
@Test @Test

View File

@@ -5,10 +5,15 @@
* file in the root directory of this source tree. * file in the root directory of this source tree.
*/ */
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <yoga/testutil/testutil.h>
#include <yoga/YGNode.h> #include <yoga/YGNode.h>
#include <yoga/Yoga.h> #include <yoga/Yoga.h>
using facebook::yoga::test::TestUtil;
TEST(YogaTest, assert_layout_trees_are_same) { TEST(YogaTest, assert_layout_trees_are_same) {
TestUtil::startCountingNodes();
YGConfig* config = YGConfigNew(); YGConfig* config = YGConfigNew();
YGConfigSetUseLegacyStretchBehaviour(config, true); YGConfigSetUseLegacyStretchBehaviour(config, true);
const YGNodeRef root1 = YGNodeNewWithConfig(config); const YGNodeRef root1 = YGNodeNewWithConfig(config);
@@ -30,12 +35,12 @@ TEST(YogaTest, assert_layout_trees_are_same) {
YGNodeInsertChild(root1_child0_child0, root1_child0_child0_child0, 0); YGNodeInsertChild(root1_child0_child0, root1_child0_child0_child0, 0);
const int32_t cal1_configInstanceCount = YGConfigGetInstanceCount(); const int32_t cal1_configInstanceCount = YGConfigGetInstanceCount();
const int32_t cal1_nodeInstanceCount = YGNodeGetInstanceCount(); const int32_t cal1_nodeInstanceCount = TestUtil::nodeCount();
YGNodeCalculateLayout(root1, YGUndefined, YGUndefined, YGDirectionLTR); YGNodeCalculateLayout(root1, YGUndefined, YGUndefined, YGDirectionLTR);
ASSERT_EQ(YGConfigGetInstanceCount(), cal1_configInstanceCount); ASSERT_EQ(YGConfigGetInstanceCount(), cal1_configInstanceCount);
ASSERT_EQ(YGNodeGetInstanceCount(), cal1_nodeInstanceCount); ASSERT_EQ(TestUtil::nodeCount(), cal1_nodeInstanceCount);
const YGNodeRef root2 = YGNodeNewWithConfig(config); const YGNodeRef root2 = YGNodeNewWithConfig(config);
YGNodeStyleSetWidth(root2, 500); YGNodeStyleSetWidth(root2, 500);
@@ -56,12 +61,12 @@ TEST(YogaTest, assert_layout_trees_are_same) {
YGNodeInsertChild(root2_child0_child0, root2_child0_child0_child0, 0); YGNodeInsertChild(root2_child0_child0, root2_child0_child0_child0, 0);
const int32_t cal2_configInstanceCount = YGConfigGetInstanceCount(); const int32_t cal2_configInstanceCount = YGConfigGetInstanceCount();
const int32_t cal2_nodeInstanceCount = YGNodeGetInstanceCount(); const int32_t cal2_nodeInstanceCount = TestUtil::nodeCount();
YGNodeCalculateLayout(root2, YGUndefined, YGUndefined, YGDirectionLTR); YGNodeCalculateLayout(root2, YGUndefined, YGUndefined, YGDirectionLTR);
ASSERT_EQ(YGConfigGetInstanceCount(), cal2_configInstanceCount); ASSERT_EQ(YGConfigGetInstanceCount(), cal2_configInstanceCount);
ASSERT_EQ(YGNodeGetInstanceCount(), cal2_nodeInstanceCount); ASSERT_EQ(TestUtil::nodeCount(), cal2_nodeInstanceCount);
ASSERT_TRUE(YGNodeLayoutGetDidUseLegacyFlag(root1)); ASSERT_TRUE(YGNodeLayoutGetDidUseLegacyFlag(root1));
ASSERT_TRUE(YGNodeLayoutGetDidUseLegacyFlag(root2)); ASSERT_TRUE(YGNodeLayoutGetDidUseLegacyFlag(root2));
@@ -70,12 +75,12 @@ TEST(YogaTest, assert_layout_trees_are_same) {
YGNodeStyleSetAlignItems(root2, YGAlignFlexEnd); YGNodeStyleSetAlignItems(root2, YGAlignFlexEnd);
const int32_t cal3_configInstanceCount = YGConfigGetInstanceCount(); const int32_t cal3_configInstanceCount = YGConfigGetInstanceCount();
const int32_t cal3_nodeInstanceCount = YGNodeGetInstanceCount(); const int32_t cal3_nodeInstanceCount = TestUtil::nodeCount();
YGNodeCalculateLayout(root2, YGUndefined, YGUndefined, YGDirectionLTR); YGNodeCalculateLayout(root2, YGUndefined, YGUndefined, YGDirectionLTR);
ASSERT_EQ(YGConfigGetInstanceCount(), cal3_configInstanceCount); ASSERT_EQ(YGConfigGetInstanceCount(), cal3_configInstanceCount);
ASSERT_EQ(YGNodeGetInstanceCount(), cal3_nodeInstanceCount); ASSERT_EQ(TestUtil::stopCountingNodes(), cal3_nodeInstanceCount);
ASSERT_FALSE(root1->isLayoutTreeEqualToNode(*root2)); ASSERT_FALSE(root1->isLayoutTreeEqualToNode(*root2));

View File

@@ -5,9 +5,12 @@
* file in the root directory of this source tree. * file in the root directory of this source tree.
*/ */
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <yoga/testutil/testutil.h>
#include <yoga/Yoga.h> #include <yoga/Yoga.h>
#include <yoga/YGNode.h> #include <yoga/YGNode.h>
using facebook::yoga::test::TestUtil;
TEST(YogaTest, cloning_shared_root) { TEST(YogaTest, cloning_shared_root) {
const YGConfigRef config = YGConfigNew(); const YGConfigRef config = YGConfigNew();
@@ -220,7 +223,7 @@ TEST(YogaTest, cloning_two_levels) {
} }
TEST(YogaTest, cloning_and_freeing) { TEST(YogaTest, cloning_and_freeing) {
const int32_t initialInstanceCount = YGNodeGetInstanceCount(); TestUtil::startCountingNodes();
const YGConfigRef config = YGConfigNew(); const YGConfigRef config = YGConfigNew();
@@ -249,7 +252,7 @@ TEST(YogaTest, cloning_and_freeing) {
YGConfigFree(config); YGConfigFree(config);
ASSERT_EQ(initialInstanceCount, YGNodeGetInstanceCount()); ASSERT_EQ(0, TestUtil::stopCountingNodes());
} }
TEST(YogaTest, mixed_shared_and_owned_children) { TEST(YogaTest, mixed_shared_and_owned_children) {