Revert D48712710: C++ Cleanup 3/N: Reorganize YGNode

Differential Revision:
D48712710

Original commit changeset: d28eae38469a

Original Phabricator Diff: D48712710

fbshipit-source-id: 7a10b071edcf045ce98bbf8f9deca0d0e2e80a14
This commit is contained in:
Zhiyao Zhou
2023-08-29 23:27:25 -07:00
committed by Facebook GitHub Bot
parent 6ca56e87ce
commit ea7f61a3db
31 changed files with 578 additions and 625 deletions

View File

@@ -6,13 +6,10 @@
*/
#include <gtest/gtest.h>
#include <yoga/Yoga.h>
#include <yoga/node/Node.h>
using namespace facebook;
#include <yoga/YGNode.h>
static void _dirtied(YGNodeRef node) {
int* dirtiedCount = (int*) YGNodeGetContext(node);
int* dirtiedCount = (int*) node->getContext();
(*dirtiedCount)++;
}
@@ -25,17 +22,17 @@ TEST(YogaTest, dirtied) {
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
int dirtiedCount = 0;
YGNodeSetContext(root, &dirtiedCount);
YGNodeSetDirtiedFunc(root, _dirtied);
root->setContext(&dirtiedCount);
root->setDirtiedFunc(_dirtied);
ASSERT_EQ(0, dirtiedCount);
// `_dirtied` MUST be called in case of explicit dirtying.
static_cast<yoga::Node*>(root)->setDirty(true);
root->setDirty(true);
ASSERT_EQ(1, dirtiedCount);
// `_dirtied` MUST be called ONCE.
static_cast<yoga::Node*>(root)->setDirty(true);
root->setDirty(true);
ASSERT_EQ(1, dirtiedCount);
}
@@ -58,17 +55,17 @@ TEST(YogaTest, dirtied_propagation) {
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
int dirtiedCount = 0;
YGNodeSetContext(root, &dirtiedCount);
YGNodeSetDirtiedFunc(root, _dirtied);
root->setContext(&dirtiedCount);
root->setDirtiedFunc(_dirtied);
ASSERT_EQ(0, dirtiedCount);
// `_dirtied` MUST be called for the first time.
static_cast<yoga::Node*>(root_child0)->markDirtyAndPropagate();
root_child0->markDirtyAndPropagate();
ASSERT_EQ(1, dirtiedCount);
// `_dirtied` must NOT be called for the second time.
static_cast<yoga::Node*>(root_child0)->markDirtyAndPropagate();
root_child0->markDirtyAndPropagate();
ASSERT_EQ(1, dirtiedCount);
}
@@ -91,20 +88,20 @@ TEST(YogaTest, dirtied_hierarchy) {
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
int dirtiedCount = 0;
YGNodeSetContext(root_child0, &dirtiedCount);
YGNodeSetDirtiedFunc(root_child0, _dirtied);
root_child0->setContext(&dirtiedCount);
root_child0->setDirtiedFunc(_dirtied);
ASSERT_EQ(0, dirtiedCount);
// `_dirtied` must NOT be called for descendants.
static_cast<yoga::Node*>(root)->markDirtyAndPropagate();
root->markDirtyAndPropagate();
ASSERT_EQ(0, dirtiedCount);
// `_dirtied` must NOT be called for the sibling node.
static_cast<yoga::Node*>(root_child1)->markDirtyAndPropagate();
root_child1->markDirtyAndPropagate();
ASSERT_EQ(0, dirtiedCount);
// `_dirtied` MUST be called in case of explicit dirtying.
static_cast<yoga::Node*>(root_child0)->markDirtyAndPropagate();
root_child0->markDirtyAndPropagate();
ASSERT_EQ(1, dirtiedCount);
}