C++ Cleanup 3/N: Reorganize YGNode (#1350)
Summary: X-link: https://github.com/facebook/react-native/pull/39219 Pull Request resolved: https://github.com/facebook/yoga/pull/1350 X-link: https://github.com/facebook/react-native/pull/39170 ## This diff This diff adds a top level `node` directory for code related to Yoga nodes and data structures on them (inc moving `YGLayout` to `LayoutResults`). The public API for config handles is `YGNodeRef`, which is forward declared to be a pointer to a struct named `YGNode`. The existing `YGNode` is split into `yoga::Node`, as the private C++ implementation, inheriting from `YGNode`, a marker type represented as an empty struct. The public API continues to accept `YGNodeRef`, which continues to be `YGNode *`, but it must be cast to its concrete internal representation at the API boundary before doing work on it. This change ends up needing to touch quite a bit, due to the amount of code that mixed and matched private and public APIs. Don't be scared though, because these changes are very mechanical, and Phabricator's line-count is 3x the actual amount due to mirrors and dirsyncs. ## This stack The organization of the C++ internals of Yoga are in need of attention. 1. Some of the C++ internals are namespaced, but others not. 2. Some of the namespaces include `detail`, but are meant to be used outside of the translation unit (FB Clang Tidy rules warn on any usage of these) 2. Most of the files are in a flat hierarchy, except for event tracing in its own folder 3. Some files and functions begin with YG, others don’t 4. Some functions are uppercase, others are not 5. Almost all of the interesting logic is in Yoga.cpp, and the file is too large to reason about 6. There are multiple grab bag files where folks put random functions they need in (Utils, BitUtils, Yoga-Internal.h) 7. There is no clear indication from file structure or type naming what is private vs not 8. Handles like `YGNodeRef` and `YGConfigRef` can be used to access internals just by importing headers This stack does some much needed spring cleaning: 1. All non-public headers and C++ implementation details are in separate folders from the root level `yoga`. This will give us room to split up logic and add more files without too large a flat hierarchy 3. All private C++ internals are under the `facebook::yoga` namespace. Details namespaces are only ever used within the same header, as they are intended 4. Utils files are split 5. Most C++ internals drop the YG prefix 6. Most C++ internal function names are all lower camel case 7. We start to split up Yoga.cpp 8. Every header beginning with YG or at the top-level directory is public and C only, with the exception of Yoga-Internal.h which has non-public functions for bindings 9. It is not possible to use private APIs without static casting handles to internal classes This will give us more leeway to continue splitting monolithic files, and consistent guidelines for style in new files as well. These changes should not be breaking to any project using only public Yoga headers. This includes every usage of Yoga in fbsource except for RN Fabric which is currently tied to internals. This refactor should make that boundary clearer. Changelog: [Internal] bypass-github-export-checks Reviewed By: shwanton Differential Revision: D48847258 fbshipit-source-id: fc560893533b55a5c2d52c37d8e9a59f7369f174
This commit is contained in:
committed by
Facebook GitHub Bot
parent
f82babba8a
commit
992f073746
@@ -9,7 +9,6 @@
|
||||
#include <yoga/event/event.h>
|
||||
#include <yoga/Yoga.h>
|
||||
#include <yoga/YGEnums.h>
|
||||
#include <yoga/YGNode.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
@@ -30,7 +29,7 @@ struct TypedEventTestData<Event::LayoutPassEnd> {
|
||||
};
|
||||
|
||||
struct EventArgs {
|
||||
const YGNode* node;
|
||||
const YGNodeConstRef node;
|
||||
Event::Type type;
|
||||
std::unique_ptr<void, std::function<void(void*)>> dataPtr;
|
||||
std::unique_ptr<void, std::function<void(void*)>> eventTestDataPtr;
|
||||
@@ -48,7 +47,7 @@ struct EventArgs {
|
||||
|
||||
class EventTest : public ::testing::Test {
|
||||
ScopedEventSubscription subscription = {&EventTest::listen};
|
||||
static void listen(const YGNode&, Event::Type, Event::Data);
|
||||
static void listen(YGNodeConstRef, Event::Type, Event::Data);
|
||||
|
||||
public:
|
||||
static std::vector<EventArgs> events;
|
||||
@@ -284,16 +283,16 @@ TEST_F(EventTest, baseline_functions_get_wrapped) {
|
||||
namespace {
|
||||
|
||||
template <Event::Type E>
|
||||
EventArgs createArgs(const YGNode& node, const Event::Data data) {
|
||||
EventArgs createArgs(YGNodeConstRef node, const Event::Data data) {
|
||||
using Data = Event::TypedData<E>;
|
||||
auto deleteData = [](void* x) { delete static_cast<Data*>(x); };
|
||||
|
||||
return {&node, E, {new Data{(data.get<E>())}, deleteData}, nullptr};
|
||||
return {node, E, {new Data{(data.get<E>())}, deleteData}, nullptr};
|
||||
}
|
||||
|
||||
template <Event::Type E>
|
||||
EventArgs createArgs(
|
||||
const YGNode& node,
|
||||
YGNodeConstRef node,
|
||||
const Event::Data data,
|
||||
TypedEventTestData<E> eventTestData) {
|
||||
using EventTestData = TypedEventTestData<E>;
|
||||
@@ -309,7 +308,10 @@ EventArgs createArgs(
|
||||
|
||||
} // namespace
|
||||
|
||||
void EventTest::listen(const YGNode& node, Event::Type type, Event::Data data) {
|
||||
void EventTest::listen(
|
||||
YGNodeConstRef node,
|
||||
Event::Type type,
|
||||
Event::Data data) {
|
||||
switch (type) {
|
||||
case Event::NodeAllocation:
|
||||
events.push_back(createArgs<Event::NodeAllocation>(node, data));
|
||||
|
@@ -6,7 +6,6 @@
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <yoga/YGNode.h>
|
||||
#include <yoga/Yoga.h>
|
||||
|
||||
static float _baselineFunc(
|
||||
@@ -197,7 +196,7 @@ TEST(YogaTest, align_baseline_parent_using_child_in_column_as_reference) {
|
||||
|
||||
const YGNodeRef root_child1_child1 =
|
||||
createYGNode(config, YGFlexDirectionColumn, 500, 400, false);
|
||||
root_child1_child1->setBaselineFunc(_baselineFunc);
|
||||
YGNodeSetBaselineFunc(root_child1_child1, _baselineFunc);
|
||||
YGNodeSetIsReferenceBaseline(root_child1_child1, true);
|
||||
YGNodeInsertChild(root_child1, root_child1_child1, 1);
|
||||
|
||||
@@ -242,7 +241,7 @@ TEST(
|
||||
|
||||
const YGNodeRef root_child1_child1 =
|
||||
createYGNode(config, YGFlexDirectionColumn, 500, 400, false);
|
||||
root_child1_child1->setBaselineFunc(_baselineFunc);
|
||||
YGNodeSetBaselineFunc(root_child1_child1, _baselineFunc);
|
||||
YGNodeSetIsReferenceBaseline(root_child1_child1, true);
|
||||
YGNodeStyleSetPadding(root_child1_child1, YGEdgeLeft, 100);
|
||||
YGNodeStyleSetPadding(root_child1_child1, YGEdgeRight, 100);
|
||||
@@ -295,7 +294,7 @@ TEST(
|
||||
|
||||
const YGNodeRef root_child1_child1 =
|
||||
createYGNode(config, YGFlexDirectionColumn, 500, 400, false);
|
||||
root_child1_child1->setBaselineFunc(_baselineFunc);
|
||||
YGNodeSetBaselineFunc(root_child1_child1, _baselineFunc);
|
||||
YGNodeSetIsReferenceBaseline(root_child1_child1, true);
|
||||
YGNodeInsertChild(root_child1, root_child1_child1, 1);
|
||||
|
||||
@@ -344,7 +343,7 @@ TEST(
|
||||
|
||||
const YGNodeRef root_child1_child1 =
|
||||
createYGNode(config, YGFlexDirectionColumn, 500, 400, false);
|
||||
root_child1_child1->setBaselineFunc(_baselineFunc);
|
||||
YGNodeSetBaselineFunc(root_child1_child1, _baselineFunc);
|
||||
YGNodeSetIsReferenceBaseline(root_child1_child1, true);
|
||||
YGNodeInsertChild(root_child1, root_child1_child1, 1);
|
||||
|
||||
@@ -389,7 +388,7 @@ TEST(
|
||||
|
||||
const YGNodeRef root_child1_child1 =
|
||||
createYGNode(config, YGFlexDirectionColumn, 500, 400, false);
|
||||
root_child1_child1->setBaselineFunc(_baselineFunc);
|
||||
YGNodeSetBaselineFunc(root_child1_child1, _baselineFunc);
|
||||
YGNodeSetIsReferenceBaseline(root_child1_child1, true);
|
||||
YGNodeStyleSetMargin(root_child1_child1, YGEdgeLeft, 100);
|
||||
YGNodeStyleSetMargin(root_child1_child1, YGEdgeRight, 100);
|
||||
@@ -436,7 +435,7 @@ TEST(YogaTest, align_baseline_parent_using_child_in_row_as_reference) {
|
||||
|
||||
const YGNodeRef root_child1_child1 =
|
||||
createYGNode(config, YGFlexDirectionColumn, 500, 400, false);
|
||||
root_child1_child1->setBaselineFunc(_baselineFunc);
|
||||
YGNodeSetBaselineFunc(root_child1_child1, _baselineFunc);
|
||||
YGNodeSetIsReferenceBaseline(root_child1_child1, true);
|
||||
YGNodeInsertChild(root_child1, root_child1_child1, 1);
|
||||
|
||||
@@ -481,7 +480,7 @@ TEST(
|
||||
|
||||
const YGNodeRef root_child1_child1 =
|
||||
createYGNode(config, YGFlexDirectionColumn, 500, 400, false);
|
||||
root_child1_child1->setBaselineFunc(_baselineFunc);
|
||||
YGNodeSetBaselineFunc(root_child1_child1, _baselineFunc);
|
||||
YGNodeSetIsReferenceBaseline(root_child1_child1, true);
|
||||
YGNodeStyleSetPadding(root_child1_child1, YGEdgeLeft, 100);
|
||||
YGNodeStyleSetPadding(root_child1_child1, YGEdgeRight, 100);
|
||||
@@ -530,7 +529,7 @@ TEST(
|
||||
|
||||
const YGNodeRef root_child1_child1 =
|
||||
createYGNode(config, YGFlexDirectionColumn, 500, 400, false);
|
||||
root_child1_child1->setBaselineFunc(_baselineFunc);
|
||||
YGNodeSetBaselineFunc(root_child1_child1, _baselineFunc);
|
||||
YGNodeSetIsReferenceBaseline(root_child1_child1, true);
|
||||
YGNodeStyleSetMargin(root_child1_child1, YGEdgeLeft, 100);
|
||||
YGNodeStyleSetMargin(root_child1_child1, YGEdgeRight, 100);
|
||||
@@ -670,7 +669,7 @@ TEST(
|
||||
|
||||
const YGNodeRef root_child1_child1 =
|
||||
createYGNode(config, YGFlexDirectionColumn, 500, 400, false);
|
||||
root_child1_child1->setBaselineFunc(_baselineFunc);
|
||||
YGNodeSetBaselineFunc(root_child1_child1, _baselineFunc);
|
||||
YGNodeSetIsReferenceBaseline(root_child1_child1, true);
|
||||
YGNodeInsertChild(root_child1, root_child1_child1, 1);
|
||||
|
||||
@@ -721,7 +720,7 @@ TEST(
|
||||
|
||||
const YGNodeRef root_child1_child1 =
|
||||
createYGNode(config, YGFlexDirectionColumn, 500, 400, false);
|
||||
root_child1_child1->setBaselineFunc(_baselineFunc);
|
||||
YGNodeSetBaselineFunc(root_child1_child1, _baselineFunc);
|
||||
YGNodeSetIsReferenceBaseline(root_child1_child1, true);
|
||||
YGNodeInsertChild(root_child1, root_child1_child1, 1);
|
||||
|
||||
|
@@ -6,7 +6,6 @@
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <yoga/YGNode.h>
|
||||
#include <yoga/Yoga.h>
|
||||
|
||||
static YGSize _measure(
|
||||
@@ -449,7 +448,7 @@ TEST(YogaTest, aspect_ratio_with_measure_func) {
|
||||
YGNodeStyleSetHeight(root, 100);
|
||||
|
||||
const YGNodeRef root_child0 = YGNodeNew();
|
||||
root_child0->setMeasureFunc(_measure);
|
||||
YGNodeSetMeasureFunc(root_child0, _measure);
|
||||
YGNodeStyleSetAspectRatio(root_child0, 1);
|
||||
YGNodeInsertChild(root, root_child0, 0);
|
||||
|
||||
|
@@ -6,14 +6,13 @@
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <yoga/YGNode.h>
|
||||
#include <yoga/Yoga.h>
|
||||
|
||||
static float _baseline(
|
||||
YGNodeRef node,
|
||||
const float /*width*/,
|
||||
const float /*height*/) {
|
||||
float* baseline = (float*) node->getContext();
|
||||
float* baseline = (float*) YGNodeGetContext(node);
|
||||
return *baseline;
|
||||
}
|
||||
|
||||
@@ -36,9 +35,9 @@ TEST(YogaTest, align_baseline_customer_func) {
|
||||
|
||||
float baselineValue = 10;
|
||||
const YGNodeRef root_child1_child0 = YGNodeNew();
|
||||
root_child1_child0->setContext(&baselineValue);
|
||||
YGNodeSetContext(root_child1_child0, &baselineValue);
|
||||
YGNodeStyleSetWidth(root_child1_child0, 50);
|
||||
root_child1_child0->setBaselineFunc(_baseline);
|
||||
YGNodeSetBaselineFunc(root_child1_child0, _baseline);
|
||||
YGNodeStyleSetHeight(root_child1_child0, 20);
|
||||
YGNodeInsertChild(root_child1, root_child1_child0, 0);
|
||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||
|
@@ -6,10 +6,13 @@
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <yoga/YGNode.h>
|
||||
#include <yoga/Yoga.h>
|
||||
#include <yoga/node/Node.h>
|
||||
|
||||
using namespace facebook;
|
||||
|
||||
static void _dirtied(YGNodeRef node) {
|
||||
int* dirtiedCount = (int*) node->getContext();
|
||||
int* dirtiedCount = (int*) YGNodeGetContext(node);
|
||||
(*dirtiedCount)++;
|
||||
}
|
||||
|
||||
@@ -22,17 +25,17 @@ TEST(YogaTest, dirtied) {
|
||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||
|
||||
int dirtiedCount = 0;
|
||||
root->setContext(&dirtiedCount);
|
||||
root->setDirtiedFunc(_dirtied);
|
||||
YGNodeSetContext(root, &dirtiedCount);
|
||||
YGNodeSetDirtiedFunc(root, _dirtied);
|
||||
|
||||
ASSERT_EQ(0, dirtiedCount);
|
||||
|
||||
// `_dirtied` MUST be called in case of explicit dirtying.
|
||||
root->setDirty(true);
|
||||
static_cast<yoga::Node*>(root)->setDirty(true);
|
||||
ASSERT_EQ(1, dirtiedCount);
|
||||
|
||||
// `_dirtied` MUST be called ONCE.
|
||||
root->setDirty(true);
|
||||
static_cast<yoga::Node*>(root)->setDirty(true);
|
||||
ASSERT_EQ(1, dirtiedCount);
|
||||
}
|
||||
|
||||
@@ -55,17 +58,17 @@ TEST(YogaTest, dirtied_propagation) {
|
||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||
|
||||
int dirtiedCount = 0;
|
||||
root->setContext(&dirtiedCount);
|
||||
root->setDirtiedFunc(_dirtied);
|
||||
YGNodeSetContext(root, &dirtiedCount);
|
||||
YGNodeSetDirtiedFunc(root, _dirtied);
|
||||
|
||||
ASSERT_EQ(0, dirtiedCount);
|
||||
|
||||
// `_dirtied` MUST be called for the first time.
|
||||
root_child0->markDirtyAndPropagate();
|
||||
static_cast<yoga::Node*>(root_child0)->markDirtyAndPropagate();
|
||||
ASSERT_EQ(1, dirtiedCount);
|
||||
|
||||
// `_dirtied` must NOT be called for the second time.
|
||||
root_child0->markDirtyAndPropagate();
|
||||
static_cast<yoga::Node*>(root_child0)->markDirtyAndPropagate();
|
||||
ASSERT_EQ(1, dirtiedCount);
|
||||
}
|
||||
|
||||
@@ -88,20 +91,20 @@ TEST(YogaTest, dirtied_hierarchy) {
|
||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||
|
||||
int dirtiedCount = 0;
|
||||
root_child0->setContext(&dirtiedCount);
|
||||
root_child0->setDirtiedFunc(_dirtied);
|
||||
YGNodeSetContext(root_child0, &dirtiedCount);
|
||||
YGNodeSetDirtiedFunc(root_child0, _dirtied);
|
||||
|
||||
ASSERT_EQ(0, dirtiedCount);
|
||||
|
||||
// `_dirtied` must NOT be called for descendants.
|
||||
root->markDirtyAndPropagate();
|
||||
static_cast<yoga::Node*>(root)->markDirtyAndPropagate();
|
||||
ASSERT_EQ(0, dirtiedCount);
|
||||
|
||||
// `_dirtied` must NOT be called for the sibling node.
|
||||
root_child1->markDirtyAndPropagate();
|
||||
static_cast<yoga::Node*>(root_child1)->markDirtyAndPropagate();
|
||||
ASSERT_EQ(0, dirtiedCount);
|
||||
|
||||
// `_dirtied` MUST be called in case of explicit dirtying.
|
||||
root_child0->markDirtyAndPropagate();
|
||||
static_cast<yoga::Node*>(root_child0)->markDirtyAndPropagate();
|
||||
ASSERT_EQ(1, dirtiedCount);
|
||||
}
|
||||
|
@@ -6,7 +6,7 @@
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <yoga/YGNode.h>
|
||||
#include <yoga/Yoga.h>
|
||||
|
||||
TEST(YogaTest, dirty_propagation) {
|
||||
const YGNodeRef root = YGNodeNew();
|
||||
@@ -28,15 +28,15 @@ TEST(YogaTest, dirty_propagation) {
|
||||
|
||||
YGNodeStyleSetWidth(root_child0, 20);
|
||||
|
||||
EXPECT_TRUE(root_child0->isDirty());
|
||||
EXPECT_FALSE(root_child1->isDirty());
|
||||
EXPECT_TRUE(root->isDirty());
|
||||
EXPECT_TRUE(YGNodeIsDirty(root_child0));
|
||||
EXPECT_FALSE(YGNodeIsDirty(root_child1));
|
||||
EXPECT_TRUE(YGNodeIsDirty(root));
|
||||
|
||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||
|
||||
EXPECT_FALSE(root_child0->isDirty());
|
||||
EXPECT_FALSE(root_child1->isDirty());
|
||||
EXPECT_FALSE(root->isDirty());
|
||||
EXPECT_FALSE(YGNodeIsDirty(root_child0));
|
||||
EXPECT_FALSE(YGNodeIsDirty(root_child1));
|
||||
EXPECT_FALSE(YGNodeIsDirty(root));
|
||||
|
||||
YGNodeFreeRecursive(root);
|
||||
}
|
||||
@@ -61,9 +61,9 @@ TEST(YogaTest, dirty_propagation_only_if_prop_changed) {
|
||||
|
||||
YGNodeStyleSetWidth(root_child0, 50);
|
||||
|
||||
EXPECT_FALSE(root_child0->isDirty());
|
||||
EXPECT_FALSE(root_child1->isDirty());
|
||||
EXPECT_FALSE(root->isDirty());
|
||||
EXPECT_FALSE(YGNodeIsDirty(root_child0));
|
||||
EXPECT_FALSE(YGNodeIsDirty(root_child1));
|
||||
EXPECT_FALSE(YGNodeIsDirty(root));
|
||||
|
||||
YGNodeFreeRecursive(root);
|
||||
}
|
||||
@@ -91,26 +91,26 @@ TEST(YogaTest, dirty_propagation_changing_layout_config) {
|
||||
|
||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||
|
||||
EXPECT_FALSE(root->isDirty());
|
||||
EXPECT_FALSE(root_child0->isDirty());
|
||||
EXPECT_FALSE(root_child1->isDirty());
|
||||
EXPECT_FALSE(root_child0_child0->isDirty());
|
||||
EXPECT_FALSE(YGNodeIsDirty(root));
|
||||
EXPECT_FALSE(YGNodeIsDirty(root_child0));
|
||||
EXPECT_FALSE(YGNodeIsDirty(root_child1));
|
||||
EXPECT_FALSE(YGNodeIsDirty(root_child0_child0));
|
||||
|
||||
YGConfigRef newConfig = YGConfigNew();
|
||||
YGConfigSetErrata(newConfig, YGErrataStretchFlexBasis);
|
||||
YGNodeSetConfig(root_child0, newConfig);
|
||||
|
||||
EXPECT_TRUE(root->isDirty());
|
||||
EXPECT_TRUE(root_child0->isDirty());
|
||||
EXPECT_FALSE(root_child1->isDirty());
|
||||
EXPECT_FALSE(root_child0_child0->isDirty());
|
||||
EXPECT_TRUE(YGNodeIsDirty(root));
|
||||
EXPECT_TRUE(YGNodeIsDirty(root_child0));
|
||||
EXPECT_FALSE(YGNodeIsDirty(root_child1));
|
||||
EXPECT_FALSE(YGNodeIsDirty(root_child0_child0));
|
||||
|
||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||
|
||||
EXPECT_FALSE(root->isDirty());
|
||||
EXPECT_FALSE(root_child0->isDirty());
|
||||
EXPECT_FALSE(root_child1->isDirty());
|
||||
EXPECT_FALSE(root_child0_child0->isDirty());
|
||||
EXPECT_FALSE(YGNodeIsDirty(root));
|
||||
EXPECT_FALSE(YGNodeIsDirty(root_child0));
|
||||
EXPECT_FALSE(YGNodeIsDirty(root_child1));
|
||||
EXPECT_FALSE(YGNodeIsDirty(root_child0_child0));
|
||||
|
||||
YGConfigFree(newConfig);
|
||||
YGNodeFreeRecursive(root);
|
||||
@@ -139,10 +139,10 @@ TEST(YogaTest, dirty_propagation_changing_benign_config) {
|
||||
|
||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||
|
||||
EXPECT_FALSE(root->isDirty());
|
||||
EXPECT_FALSE(root_child0->isDirty());
|
||||
EXPECT_FALSE(root_child1->isDirty());
|
||||
EXPECT_FALSE(root_child0_child0->isDirty());
|
||||
EXPECT_FALSE(YGNodeIsDirty(root));
|
||||
EXPECT_FALSE(YGNodeIsDirty(root_child0));
|
||||
EXPECT_FALSE(YGNodeIsDirty(root_child1));
|
||||
EXPECT_FALSE(YGNodeIsDirty(root_child0_child0));
|
||||
|
||||
YGConfigRef newConfig = YGConfigNew();
|
||||
YGConfigSetLogger(
|
||||
@@ -152,10 +152,10 @@ TEST(YogaTest, dirty_propagation_changing_benign_config) {
|
||||
});
|
||||
YGNodeSetConfig(root_child0, newConfig);
|
||||
|
||||
EXPECT_FALSE(root->isDirty());
|
||||
EXPECT_FALSE(root_child0->isDirty());
|
||||
EXPECT_FALSE(root_child1->isDirty());
|
||||
EXPECT_FALSE(root_child0_child0->isDirty());
|
||||
EXPECT_FALSE(YGNodeIsDirty(root));
|
||||
EXPECT_FALSE(YGNodeIsDirty(root_child0));
|
||||
EXPECT_FALSE(YGNodeIsDirty(root_child1));
|
||||
EXPECT_FALSE(YGNodeIsDirty(root_child0_child0));
|
||||
|
||||
YGConfigFree(newConfig);
|
||||
YGNodeFreeRecursive(root);
|
||||
@@ -224,11 +224,11 @@ TEST(YogaTest, dirty_node_only_if_children_are_actually_removed) {
|
||||
|
||||
const YGNodeRef child1 = YGNodeNew();
|
||||
YGNodeRemoveChild(root, child1);
|
||||
EXPECT_FALSE(root->isDirty());
|
||||
EXPECT_FALSE(YGNodeIsDirty(root));
|
||||
YGNodeFree(child1);
|
||||
|
||||
YGNodeRemoveChild(root, child0);
|
||||
EXPECT_TRUE(root->isDirty());
|
||||
EXPECT_TRUE(YGNodeIsDirty(root));
|
||||
YGNodeFree(child0);
|
||||
|
||||
YGNodeFreeRecursive(root);
|
||||
@@ -241,12 +241,11 @@ TEST(YogaTest, dirty_node_only_if_undefined_values_gets_set_to_undefined) {
|
||||
YGNodeStyleSetMinWidth(root, YGUndefined);
|
||||
|
||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||
|
||||
EXPECT_FALSE(root->isDirty());
|
||||
EXPECT_FALSE(YGNodeIsDirty(root));
|
||||
|
||||
YGNodeStyleSetMinWidth(root, YGUndefined);
|
||||
|
||||
EXPECT_FALSE(root->isDirty());
|
||||
EXPECT_FALSE(YGNodeIsDirty(root));
|
||||
|
||||
YGNodeFreeRecursive(root);
|
||||
}
|
||||
|
@@ -6,7 +6,6 @@
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <yoga/YGNode.h>
|
||||
#include <yoga/Yoga.h>
|
||||
|
||||
static YGSize _measureMax(
|
||||
@@ -15,7 +14,7 @@ static YGSize _measureMax(
|
||||
YGMeasureMode widthMode,
|
||||
float height,
|
||||
YGMeasureMode heightMode) {
|
||||
int* measureCount = (int*) node->getContext();
|
||||
int* measureCount = (int*) YGNodeGetContext(node);
|
||||
(*measureCount)++;
|
||||
|
||||
return YGSize{
|
||||
@@ -30,7 +29,7 @@ static YGSize _measureMin(
|
||||
YGMeasureMode widthMode,
|
||||
float height,
|
||||
YGMeasureMode heightMode) {
|
||||
int* measureCount = (int*) node->getContext();
|
||||
int* measureCount = (int*) YGNodeGetContext(node);
|
||||
*measureCount = *measureCount + 1;
|
||||
return YGSize{
|
||||
widthMode == YGMeasureModeUndefined ||
|
||||
@@ -50,7 +49,7 @@ static YGSize _measure_84_49(
|
||||
YGMeasureMode /*widthMode*/,
|
||||
float /*height*/,
|
||||
YGMeasureMode /*heightMode*/) {
|
||||
int* measureCount = (int*) node->getContext();
|
||||
int* measureCount = (int*) YGNodeGetContext(node);
|
||||
if (measureCount) {
|
||||
(*measureCount)++;
|
||||
}
|
||||
@@ -67,8 +66,8 @@ TEST(YogaTest, measure_once_single_flexible_child) {
|
||||
|
||||
const YGNodeRef root_child0 = YGNodeNew();
|
||||
int measureCount = 0;
|
||||
root_child0->setContext(&measureCount);
|
||||
root_child0->setMeasureFunc(_measureMax);
|
||||
YGNodeSetContext(root_child0, &measureCount);
|
||||
YGNodeSetMeasureFunc(root_child0, _measureMax);
|
||||
YGNodeStyleSetFlexGrow(root_child0, 1);
|
||||
YGNodeInsertChild(root, root_child0, 0);
|
||||
|
||||
@@ -84,8 +83,8 @@ TEST(YogaTest, remeasure_with_same_exact_width_larger_than_needed_height) {
|
||||
|
||||
const YGNodeRef root_child0 = YGNodeNew();
|
||||
int measureCount = 0;
|
||||
root_child0->setContext(&measureCount);
|
||||
root_child0->setMeasureFunc(_measureMin);
|
||||
YGNodeSetContext(root_child0, &measureCount);
|
||||
YGNodeSetMeasureFunc(root_child0, _measureMin);
|
||||
YGNodeInsertChild(root, root_child0, 0);
|
||||
|
||||
YGNodeCalculateLayout(root, 100, 100, YGDirectionLTR);
|
||||
@@ -102,8 +101,8 @@ TEST(YogaTest, remeasure_with_same_atmost_width_larger_than_needed_height) {
|
||||
|
||||
const YGNodeRef root_child0 = YGNodeNew();
|
||||
int measureCount = 0;
|
||||
root_child0->setContext(&measureCount);
|
||||
root_child0->setMeasureFunc(_measureMin);
|
||||
YGNodeSetContext(root_child0, &measureCount);
|
||||
YGNodeSetMeasureFunc(root_child0, _measureMin);
|
||||
YGNodeInsertChild(root, root_child0, 0);
|
||||
|
||||
YGNodeCalculateLayout(root, 100, 100, YGDirectionLTR);
|
||||
@@ -120,8 +119,8 @@ TEST(YogaTest, remeasure_with_computed_width_larger_than_needed_height) {
|
||||
|
||||
const YGNodeRef root_child0 = YGNodeNew();
|
||||
int measureCount = 0;
|
||||
root_child0->setContext(&measureCount);
|
||||
root_child0->setMeasureFunc(_measureMin);
|
||||
YGNodeSetContext(root_child0, &measureCount);
|
||||
YGNodeSetMeasureFunc(root_child0, _measureMin);
|
||||
YGNodeInsertChild(root, root_child0, 0);
|
||||
|
||||
YGNodeCalculateLayout(root, 100, 100, YGDirectionLTR);
|
||||
@@ -139,8 +138,8 @@ TEST(YogaTest, remeasure_with_atmost_computed_width_undefined_height) {
|
||||
|
||||
const YGNodeRef root_child0 = YGNodeNew();
|
||||
int measureCount = 0;
|
||||
root_child0->setContext(&measureCount);
|
||||
root_child0->setMeasureFunc(_measureMin);
|
||||
YGNodeSetContext(root_child0, &measureCount);
|
||||
YGNodeSetMeasureFunc(root_child0, _measureMin);
|
||||
YGNodeInsertChild(root, root_child0, 0);
|
||||
|
||||
YGNodeCalculateLayout(root, 100, YGUndefined, YGDirectionLTR);
|
||||
@@ -167,8 +166,8 @@ TEST(
|
||||
YGNodeInsertChild(root, root_child0, 0);
|
||||
|
||||
const YGNodeRef root_child0_child0 = YGNodeNew();
|
||||
root_child0_child0->setContext(&measureCount);
|
||||
root_child0_child0->setMeasureFunc(_measure_84_49);
|
||||
YGNodeSetContext(root_child0_child0, &measureCount);
|
||||
YGNodeSetMeasureFunc(root_child0_child0, _measure_84_49);
|
||||
YGNodeInsertChild(root_child0, root_child0_child0, 0);
|
||||
|
||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||
|
@@ -6,7 +6,6 @@
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <yoga/YGNode.h>
|
||||
#include <yoga/Yoga.h>
|
||||
|
||||
struct _MeasureConstraint {
|
||||
@@ -28,7 +27,7 @@ static YGSize _measure(
|
||||
float height,
|
||||
YGMeasureMode heightMode) {
|
||||
struct _MeasureConstraintList* constraintList =
|
||||
(struct _MeasureConstraintList*) node->getContext();
|
||||
(struct _MeasureConstraintList*) YGNodeGetContext(node);
|
||||
struct _MeasureConstraint* constraints = constraintList->constraints;
|
||||
uint32_t currentIndex = constraintList->length;
|
||||
(&constraints[currentIndex])->width = width;
|
||||
@@ -55,10 +54,8 @@ TEST(YogaTest, exactly_measure_stretched_child_column) {
|
||||
YGNodeStyleSetHeight(root, 100);
|
||||
|
||||
const YGNodeRef root_child0 = YGNodeNew();
|
||||
// root_child0->setContext(&constraintList);
|
||||
root_child0->setContext(&constraintList);
|
||||
root_child0->setMeasureFunc(_measure);
|
||||
// root_child0->setMeasureFunc(_measure);
|
||||
YGNodeSetContext(root_child0, &constraintList);
|
||||
YGNodeSetMeasureFunc(root_child0, _measure);
|
||||
YGNodeInsertChild(root, root_child0, 0);
|
||||
|
||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||
@@ -85,9 +82,8 @@ TEST(YogaTest, exactly_measure_stretched_child_row) {
|
||||
YGNodeStyleSetHeight(root, 100);
|
||||
|
||||
const YGNodeRef root_child0 = YGNodeNew();
|
||||
// root_child0->setContext(&constraintList);
|
||||
root_child0->setContext(&constraintList);
|
||||
root_child0->setMeasureFunc(_measure);
|
||||
YGNodeSetContext(root_child0, &constraintList);
|
||||
YGNodeSetMeasureFunc(root_child0, _measure);
|
||||
YGNodeInsertChild(root, root_child0, 0);
|
||||
|
||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||
@@ -113,8 +109,8 @@ TEST(YogaTest, at_most_main_axis_column) {
|
||||
YGNodeStyleSetHeight(root, 100);
|
||||
|
||||
const YGNodeRef root_child0 = YGNodeNew();
|
||||
root_child0->setContext(&constraintList);
|
||||
root_child0->setMeasureFunc(_measure);
|
||||
YGNodeSetContext(root_child0, &constraintList);
|
||||
YGNodeSetMeasureFunc(root_child0, _measure);
|
||||
YGNodeInsertChild(root, root_child0, 0);
|
||||
|
||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||
@@ -141,8 +137,8 @@ TEST(YogaTest, at_most_cross_axis_column) {
|
||||
YGNodeStyleSetHeight(root, 100);
|
||||
|
||||
const YGNodeRef root_child0 = YGNodeNew();
|
||||
root_child0->setContext(&constraintList);
|
||||
root_child0->setMeasureFunc(_measure);
|
||||
YGNodeSetContext(root_child0, &constraintList);
|
||||
YGNodeSetMeasureFunc(root_child0, _measure);
|
||||
YGNodeInsertChild(root, root_child0, 0);
|
||||
|
||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||
@@ -169,8 +165,8 @@ TEST(YogaTest, at_most_main_axis_row) {
|
||||
YGNodeStyleSetHeight(root, 100);
|
||||
|
||||
const YGNodeRef root_child0 = YGNodeNew();
|
||||
root_child0->setContext(&constraintList);
|
||||
root_child0->setMeasureFunc(_measure);
|
||||
YGNodeSetContext(root_child0, &constraintList);
|
||||
YGNodeSetMeasureFunc(root_child0, _measure);
|
||||
YGNodeInsertChild(root, root_child0, 0);
|
||||
|
||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||
@@ -198,8 +194,8 @@ TEST(YogaTest, at_most_cross_axis_row) {
|
||||
YGNodeStyleSetHeight(root, 100);
|
||||
|
||||
const YGNodeRef root_child0 = YGNodeNew();
|
||||
root_child0->setContext(&constraintList);
|
||||
root_child0->setMeasureFunc(_measure);
|
||||
YGNodeSetContext(root_child0, &constraintList);
|
||||
YGNodeSetMeasureFunc(root_child0, _measure);
|
||||
YGNodeInsertChild(root, root_child0, 0);
|
||||
|
||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||
@@ -225,8 +221,8 @@ TEST(YogaTest, flex_child) {
|
||||
|
||||
const YGNodeRef root_child0 = YGNodeNew();
|
||||
YGNodeStyleSetFlexGrow(root_child0, 1);
|
||||
root_child0->setContext(&constraintList);
|
||||
root_child0->setMeasureFunc(_measure);
|
||||
YGNodeSetContext(root_child0, &constraintList);
|
||||
YGNodeSetMeasureFunc(root_child0, _measure);
|
||||
YGNodeInsertChild(root, root_child0, 0);
|
||||
|
||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||
@@ -256,8 +252,8 @@ TEST(YogaTest, flex_child_with_flex_basis) {
|
||||
const YGNodeRef root_child0 = YGNodeNew();
|
||||
YGNodeStyleSetFlexGrow(root_child0, 1);
|
||||
YGNodeStyleSetFlexBasis(root_child0, 0);
|
||||
root_child0->setContext(&constraintList);
|
||||
root_child0->setMeasureFunc(_measure);
|
||||
YGNodeSetContext(root_child0, &constraintList);
|
||||
YGNodeSetMeasureFunc(root_child0, _measure);
|
||||
YGNodeInsertChild(root, root_child0, 0);
|
||||
|
||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||
@@ -285,8 +281,8 @@ TEST(YogaTest, overflow_scroll_column) {
|
||||
YGNodeStyleSetWidth(root, 100);
|
||||
|
||||
const YGNodeRef root_child0 = YGNodeNew();
|
||||
root_child0->setContext(&constraintList);
|
||||
root_child0->setMeasureFunc(_measure);
|
||||
YGNodeSetContext(root_child0, &constraintList);
|
||||
YGNodeSetMeasureFunc(root_child0, _measure);
|
||||
YGNodeInsertChild(root, root_child0, 0);
|
||||
|
||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||
@@ -318,8 +314,8 @@ TEST(YogaTest, overflow_scroll_row) {
|
||||
YGNodeStyleSetWidth(root, 100);
|
||||
|
||||
const YGNodeRef root_child0 = YGNodeNew();
|
||||
root_child0->setContext(&constraintList);
|
||||
root_child0->setMeasureFunc(_measure);
|
||||
YGNodeSetContext(root_child0, &constraintList);
|
||||
YGNodeSetMeasureFunc(root_child0, _measure);
|
||||
YGNodeInsertChild(root, root_child0, 0);
|
||||
|
||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||
|
@@ -6,7 +6,6 @@
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <yoga/YGNode.h>
|
||||
#include <yoga/Yoga.h>
|
||||
|
||||
static YGSize _measure(
|
||||
@@ -15,7 +14,7 @@ static YGSize _measure(
|
||||
YGMeasureMode /*widthMode*/,
|
||||
float /*height*/,
|
||||
YGMeasureMode /*heightMode*/) {
|
||||
int* measureCount = (int*) node->getContext();
|
||||
int* measureCount = (int*) YGNodeGetContext(node);
|
||||
if (measureCount) {
|
||||
(*measureCount)++;
|
||||
}
|
||||
@@ -56,8 +55,8 @@ TEST(YogaTest, dont_measure_single_grow_shrink_child) {
|
||||
int measureCount = 0;
|
||||
|
||||
const YGNodeRef root_child0 = YGNodeNew();
|
||||
root_child0->setContext(&measureCount);
|
||||
root_child0->setMeasureFunc(_measure);
|
||||
YGNodeSetContext(root_child0, &measureCount);
|
||||
YGNodeSetMeasureFunc(root_child0, _measure);
|
||||
YGNodeStyleSetFlexGrow(root_child0, 1);
|
||||
YGNodeStyleSetFlexShrink(root_child0, 1);
|
||||
YGNodeInsertChild(root, root_child0, 0);
|
||||
@@ -79,8 +78,8 @@ TEST(YogaTest, measure_absolute_child_with_no_constraints) {
|
||||
|
||||
const YGNodeRef root_child0_child0 = YGNodeNew();
|
||||
YGNodeStyleSetPositionType(root_child0_child0, YGPositionTypeAbsolute);
|
||||
root_child0_child0->setContext(&measureCount);
|
||||
root_child0_child0->setMeasureFunc(_measure);
|
||||
YGNodeSetContext(root_child0_child0, &measureCount);
|
||||
YGNodeSetMeasureFunc(root_child0_child0, _measure);
|
||||
YGNodeInsertChild(root_child0, root_child0_child0, 0);
|
||||
|
||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||
@@ -99,8 +98,8 @@ TEST(YogaTest, dont_measure_when_min_equals_max) {
|
||||
int measureCount = 0;
|
||||
|
||||
const YGNodeRef root_child0 = YGNodeNew();
|
||||
root_child0->setContext(&measureCount);
|
||||
root_child0->setMeasureFunc(_measure);
|
||||
YGNodeSetContext(root_child0, &measureCount);
|
||||
YGNodeSetMeasureFunc(root_child0, _measure);
|
||||
YGNodeStyleSetMinWidth(root_child0, 10);
|
||||
YGNodeStyleSetMaxWidth(root_child0, 10);
|
||||
YGNodeStyleSetMinHeight(root_child0, 10);
|
||||
@@ -127,8 +126,8 @@ TEST(YogaTest, dont_measure_when_min_equals_max_percentages) {
|
||||
int measureCount = 0;
|
||||
|
||||
const YGNodeRef root_child0 = YGNodeNew();
|
||||
root_child0->setContext(&measureCount);
|
||||
root_child0->setMeasureFunc(_measure);
|
||||
YGNodeSetContext(root_child0, &measureCount);
|
||||
YGNodeSetMeasureFunc(root_child0, _measure);
|
||||
YGNodeStyleSetMinWidthPercent(root_child0, 10);
|
||||
YGNodeStyleSetMaxWidthPercent(root_child0, 10);
|
||||
YGNodeStyleSetMinHeightPercent(root_child0, 10);
|
||||
@@ -152,7 +151,7 @@ TEST(YogaTest, measure_nodes_with_margin_auto_and_stretch) {
|
||||
YGNodeStyleSetHeight(root, 500);
|
||||
|
||||
const YGNodeRef root_child0 = YGNodeNew();
|
||||
root_child0->setMeasureFunc(_measure);
|
||||
YGNodeSetMeasureFunc(root_child0, _measure);
|
||||
YGNodeStyleSetMarginAuto(root_child0, YGEdgeLeft);
|
||||
YGNodeInsertChild(root, root_child0, 0);
|
||||
|
||||
@@ -175,8 +174,8 @@ TEST(YogaTest, dont_measure_when_min_equals_max_mixed_width_percent) {
|
||||
int measureCount = 0;
|
||||
|
||||
const YGNodeRef root_child0 = YGNodeNew();
|
||||
root_child0->setContext(&measureCount);
|
||||
root_child0->setMeasureFunc(_measure);
|
||||
YGNodeSetContext(root_child0, &measureCount);
|
||||
YGNodeSetMeasureFunc(root_child0, _measure);
|
||||
YGNodeStyleSetMinWidthPercent(root_child0, 10);
|
||||
YGNodeStyleSetMaxWidthPercent(root_child0, 10);
|
||||
YGNodeStyleSetMinHeight(root_child0, 10);
|
||||
@@ -203,8 +202,8 @@ TEST(YogaTest, dont_measure_when_min_equals_max_mixed_height_percent) {
|
||||
int measureCount = 0;
|
||||
|
||||
const YGNodeRef root_child0 = YGNodeNew();
|
||||
root_child0->setContext(&measureCount);
|
||||
root_child0->setMeasureFunc(_measure);
|
||||
YGNodeSetContext(root_child0, &measureCount);
|
||||
YGNodeSetMeasureFunc(root_child0, _measure);
|
||||
YGNodeStyleSetMinWidth(root_child0, 10);
|
||||
YGNodeStyleSetMaxWidth(root_child0, 10);
|
||||
YGNodeStyleSetMinHeightPercent(root_child0, 10);
|
||||
@@ -228,7 +227,7 @@ TEST(YogaTest, measure_enough_size_should_be_in_single_line) {
|
||||
|
||||
const YGNodeRef root_child0 = YGNodeNew();
|
||||
YGNodeStyleSetAlignSelf(root_child0, YGAlignFlexStart);
|
||||
root_child0->setMeasureFunc(_simulate_wrapping_text);
|
||||
YGNodeSetMeasureFunc(root_child0, _simulate_wrapping_text);
|
||||
|
||||
YGNodeInsertChild(root, root_child0, 0);
|
||||
|
||||
@@ -247,7 +246,7 @@ TEST(YogaTest, measure_not_enough_size_should_wrap) {
|
||||
const YGNodeRef root_child0 = YGNodeNew();
|
||||
YGNodeStyleSetAlignSelf(root_child0, YGAlignFlexStart);
|
||||
// YGNodeSetMeasureFunc(root_child0, _simulate_wrapping_text);
|
||||
root_child0->setMeasureFunc(_simulate_wrapping_text);
|
||||
YGNodeSetMeasureFunc(root_child0, _simulate_wrapping_text);
|
||||
YGNodeInsertChild(root, root_child0, 0);
|
||||
|
||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||
@@ -269,8 +268,8 @@ TEST(YogaTest, measure_zero_space_should_grow) {
|
||||
const YGNodeRef root_child0 = YGNodeNew();
|
||||
YGNodeStyleSetFlexDirection(root_child0, YGFlexDirectionColumn);
|
||||
YGNodeStyleSetPadding(root_child0, YGEdgeAll, 100);
|
||||
root_child0->setContext(&measureCount);
|
||||
root_child0->setMeasureFunc(_measure);
|
||||
YGNodeSetContext(root_child0, &measureCount);
|
||||
YGNodeSetMeasureFunc(root_child0, _measure);
|
||||
|
||||
YGNodeInsertChild(root, root_child0, 0);
|
||||
|
||||
@@ -295,8 +294,7 @@ TEST(YogaTest, measure_flex_direction_row_and_padding) {
|
||||
YGNodeStyleSetHeight(root, 50);
|
||||
|
||||
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
|
||||
root_child0->setMeasureFunc(_simulate_wrapping_text);
|
||||
// YGNodeSetMeasureFunc(root_child0, _simulate_wrapping_text);
|
||||
YGNodeSetMeasureFunc(root_child0, _simulate_wrapping_text);
|
||||
YGNodeInsertChild(root, root_child0, 0);
|
||||
|
||||
const YGNodeRef root_child1 = YGNodeNewWithConfig(config);
|
||||
@@ -335,7 +333,7 @@ TEST(YogaTest, measure_flex_direction_column_and_padding) {
|
||||
YGNodeStyleSetHeight(root, 50);
|
||||
|
||||
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
|
||||
root_child0->setMeasureFunc(_simulate_wrapping_text);
|
||||
YGNodeSetMeasureFunc(root_child0, _simulate_wrapping_text);
|
||||
// YGNodeSetMeasureFunc(root_child0, _simulate_wrapping_text);
|
||||
YGNodeInsertChild(root, root_child0, 0);
|
||||
|
||||
@@ -376,7 +374,7 @@ TEST(YogaTest, measure_flex_direction_row_no_padding) {
|
||||
|
||||
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
|
||||
// YGNodeSetMeasureFunc(root_child0, _simulate_wrapping_text);
|
||||
root_child0->setMeasureFunc(_simulate_wrapping_text);
|
||||
YGNodeSetMeasureFunc(root_child0, _simulate_wrapping_text);
|
||||
YGNodeInsertChild(root, root_child0, 0);
|
||||
|
||||
const YGNodeRef root_child1 = YGNodeNewWithConfig(config);
|
||||
@@ -416,7 +414,7 @@ TEST(YogaTest, measure_flex_direction_row_no_padding_align_items_flexstart) {
|
||||
YGNodeStyleSetAlignItems(root, YGAlignFlexStart);
|
||||
|
||||
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
|
||||
root_child0->setMeasureFunc(_simulate_wrapping_text);
|
||||
YGNodeSetMeasureFunc(root_child0, _simulate_wrapping_text);
|
||||
YGNodeInsertChild(root, root_child0, 0);
|
||||
|
||||
const YGNodeRef root_child1 = YGNodeNewWithConfig(config);
|
||||
@@ -455,7 +453,7 @@ TEST(YogaTest, measure_with_fixed_size) {
|
||||
YGNodeStyleSetHeight(root, 50);
|
||||
|
||||
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
|
||||
root_child0->setMeasureFunc(_simulate_wrapping_text);
|
||||
YGNodeSetMeasureFunc(root_child0, _simulate_wrapping_text);
|
||||
YGNodeStyleSetWidth(root_child0, 10);
|
||||
YGNodeStyleSetHeight(root_child0, 10);
|
||||
YGNodeInsertChild(root, root_child0, 0);
|
||||
@@ -496,7 +494,7 @@ TEST(YogaTest, measure_with_flex_shrink) {
|
||||
YGNodeStyleSetHeight(root, 50);
|
||||
|
||||
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
|
||||
root_child0->setMeasureFunc(_simulate_wrapping_text);
|
||||
YGNodeSetMeasureFunc(root_child0, _simulate_wrapping_text);
|
||||
YGNodeStyleSetFlexShrink(root_child0, 1);
|
||||
YGNodeInsertChild(root, root_child0, 0);
|
||||
|
||||
@@ -535,7 +533,7 @@ TEST(YogaTest, measure_no_padding) {
|
||||
YGNodeStyleSetHeight(root, 50);
|
||||
|
||||
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
|
||||
root_child0->setMeasureFunc(_simulate_wrapping_text);
|
||||
YGNodeSetMeasureFunc(root_child0, _simulate_wrapping_text);
|
||||
YGNodeStyleSetFlexShrink(root_child0, 1);
|
||||
YGNodeInsertChild(root, root_child0, 0);
|
||||
|
||||
@@ -568,7 +566,7 @@ TEST(YogaTest, measure_no_padding) {
|
||||
#if GTEST_HAS_DEATH_TEST
|
||||
TEST(YogaDeathTest, cannot_add_child_to_node_with_measure_func) {
|
||||
const YGNodeRef root = YGNodeNew();
|
||||
root->setMeasureFunc(_measure);
|
||||
YGNodeSetMeasureFunc(root, _measure);
|
||||
|
||||
const YGNodeRef root_child0 = YGNodeNew();
|
||||
#if defined(__cpp_exceptions)
|
||||
@@ -585,9 +583,10 @@ TEST(YogaDeathTest, cannot_add_nonnull_measure_func_to_non_leaf_node) {
|
||||
const YGNodeRef root_child0 = YGNodeNew();
|
||||
YGNodeInsertChild(root, root_child0, 0);
|
||||
#if defined(__cpp_exceptions)
|
||||
ASSERT_THROW(root->setMeasureFunc(_measure), std::logic_error);
|
||||
ASSERT_THROW(YGNodeSetMeasureFunc(root, _measure), std::logic_error);
|
||||
#else // !defined(__cpp_exceptions)
|
||||
ASSERT_DEATH(root->setMeasureFunc(_measure), "Cannot set measure function.*");
|
||||
ASSERT_DEATH(
|
||||
YGNodeSetMeasureFunc(root, _measure), "Cannot set measure function.*");
|
||||
#endif // defined(__cpp_exceptions)
|
||||
YGNodeFreeRecursive(root);
|
||||
}
|
||||
@@ -597,8 +596,8 @@ TEST(YogaDeathTest, cannot_add_nonnull_measure_func_to_non_leaf_node) {
|
||||
TEST(YogaTest, can_nullify_measure_func_on_any_node) {
|
||||
const YGNodeRef root = YGNodeNew();
|
||||
YGNodeInsertChild(root, YGNodeNew(), 0);
|
||||
root->setMeasureFunc(nullptr);
|
||||
ASSERT_TRUE(!root->hasMeasureFunc());
|
||||
YGNodeSetMeasureFunc(root, nullptr);
|
||||
ASSERT_TRUE(!YGNodeHasMeasureFunc(root));
|
||||
YGNodeFreeRecursive(root);
|
||||
}
|
||||
|
||||
@@ -611,7 +610,7 @@ TEST(YogaTest, cant_call_negative_measure) {
|
||||
YGNodeStyleSetHeight(root, 10);
|
||||
|
||||
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
|
||||
root_child0->setMeasureFunc(_measure_assert_negative);
|
||||
YGNodeSetMeasureFunc(root_child0, _measure_assert_negative);
|
||||
YGNodeStyleSetMargin(root_child0, YGEdgeTop, 20);
|
||||
YGNodeInsertChild(root, root_child0, 0);
|
||||
|
||||
@@ -630,7 +629,7 @@ TEST(YogaTest, cant_call_negative_measure_horizontal) {
|
||||
YGNodeStyleSetHeight(root, 20);
|
||||
|
||||
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
|
||||
root_child0->setMeasureFunc(_measure_assert_negative);
|
||||
YGNodeSetMeasureFunc(root_child0, _measure_assert_negative);
|
||||
YGNodeStyleSetMargin(root_child0, YGEdgeStart, 20);
|
||||
YGNodeInsertChild(root, root_child0, 0);
|
||||
|
||||
@@ -674,7 +673,7 @@ TEST(YogaTest, percent_with_text_node) {
|
||||
YGNodeInsertChild(root, root_child0, 0);
|
||||
|
||||
const YGNodeRef root_child1 = YGNodeNewWithConfig(config);
|
||||
root_child1->setMeasureFunc(_measure_90_10);
|
||||
YGNodeSetMeasureFunc(root_child1, _measure_90_10);
|
||||
YGNodeStyleSetMaxWidthPercent(root_child1, 50);
|
||||
YGNodeStyleSetPaddingPercent(root_child1, YGEdgeTop, 50);
|
||||
YGNodeInsertChild(root, root_child1, 1);
|
||||
@@ -713,28 +712,28 @@ TEST(YogaTest, percent_margin_with_measure_func) {
|
||||
YGNodeStyleSetWidth(root_child0, 100);
|
||||
YGNodeStyleSetHeight(root_child0, 100);
|
||||
YGNodeStyleSetMargin(root_child0, YGEdgeTop, 0);
|
||||
root_child0->setMeasureFunc(_measure_100_100);
|
||||
YGNodeSetMeasureFunc(root_child0, _measure_100_100);
|
||||
YGNodeInsertChild(root, root_child0, 0);
|
||||
|
||||
const YGNodeRef root_child1 = YGNodeNewWithConfig(config);
|
||||
YGNodeStyleSetWidth(root_child1, 100);
|
||||
YGNodeStyleSetHeight(root_child1, 100);
|
||||
YGNodeStyleSetMargin(root_child1, YGEdgeTop, 100);
|
||||
root_child1->setMeasureFunc(_measure_100_100);
|
||||
YGNodeSetMeasureFunc(root_child1, _measure_100_100);
|
||||
YGNodeInsertChild(root, root_child1, 1);
|
||||
|
||||
const YGNodeRef root_child2 = YGNodeNewWithConfig(config);
|
||||
YGNodeStyleSetWidth(root_child2, 100);
|
||||
YGNodeStyleSetHeight(root_child2, 100);
|
||||
YGNodeStyleSetMarginPercent(root_child2, YGEdgeTop, 10);
|
||||
root_child2->setMeasureFunc(_measure_100_100);
|
||||
YGNodeSetMeasureFunc(root_child2, _measure_100_100);
|
||||
YGNodeInsertChild(root, root_child2, 2);
|
||||
|
||||
const YGNodeRef root_child3 = YGNodeNewWithConfig(config);
|
||||
YGNodeStyleSetWidth(root_child3, 100);
|
||||
YGNodeStyleSetHeight(root_child3, 100);
|
||||
YGNodeStyleSetMarginPercent(root_child3, YGEdgeTop, 20);
|
||||
root_child3->setMeasureFunc(_measure_100_100);
|
||||
YGNodeSetMeasureFunc(root_child3, _measure_100_100);
|
||||
YGNodeInsertChild(root, root_child3, 3);
|
||||
|
||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||
@@ -783,24 +782,24 @@ TEST(YogaTest, percent_padding_with_measure_func) {
|
||||
YGNodeStyleSetWidth(root_child0, 100);
|
||||
YGNodeStyleSetHeight(root_child0, 100);
|
||||
YGNodeStyleSetPadding(root_child0, YGEdgeTop, 0);
|
||||
root_child0->setMeasureFunc(_measure_100_100);
|
||||
YGNodeSetMeasureFunc(root_child0, _measure_100_100);
|
||||
YGNodeInsertChild(root, root_child0, 0);
|
||||
|
||||
const YGNodeRef root_child1 = YGNodeNewWithConfig(config);
|
||||
YGNodeStyleSetWidth(root_child1, 100);
|
||||
YGNodeStyleSetHeight(root_child1, 100);
|
||||
YGNodeStyleSetPadding(root_child1, YGEdgeTop, 100);
|
||||
root_child1->setMeasureFunc(_measure_100_100);
|
||||
YGNodeSetMeasureFunc(root_child1, _measure_100_100);
|
||||
YGNodeInsertChild(root, root_child1, 1);
|
||||
|
||||
const YGNodeRef root_child2 = YGNodeNewWithConfig(config);
|
||||
YGNodeStyleSetPaddingPercent(root_child2, YGEdgeTop, 10);
|
||||
root_child2->setMeasureFunc(_measure_100_100);
|
||||
YGNodeSetMeasureFunc(root_child2, _measure_100_100);
|
||||
YGNodeInsertChild(root, root_child2, 2);
|
||||
|
||||
const YGNodeRef root_child3 = YGNodeNewWithConfig(config);
|
||||
YGNodeStyleSetPaddingPercent(root_child3, YGEdgeTop, 20);
|
||||
root_child3->setMeasureFunc(_measure_100_100);
|
||||
YGNodeSetMeasureFunc(root_child3, _measure_100_100);
|
||||
YGNodeInsertChild(root, root_child3, 3);
|
||||
|
||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||
@@ -849,26 +848,26 @@ TEST(YogaTest, percent_padding_and_percent_margin_with_measure_func) {
|
||||
YGNodeStyleSetWidth(root_child0, 100);
|
||||
YGNodeStyleSetHeight(root_child0, 100);
|
||||
YGNodeStyleSetPadding(root_child0, YGEdgeTop, 0);
|
||||
root_child0->setMeasureFunc(_measure_100_100);
|
||||
YGNodeSetMeasureFunc(root_child0, _measure_100_100);
|
||||
YGNodeInsertChild(root, root_child0, 0);
|
||||
|
||||
const YGNodeRef root_child1 = YGNodeNewWithConfig(config);
|
||||
YGNodeStyleSetWidth(root_child1, 100);
|
||||
YGNodeStyleSetHeight(root_child1, 100);
|
||||
YGNodeStyleSetPadding(root_child1, YGEdgeTop, 100);
|
||||
root_child1->setMeasureFunc(_measure_100_100);
|
||||
YGNodeSetMeasureFunc(root_child1, _measure_100_100);
|
||||
YGNodeInsertChild(root, root_child1, 1);
|
||||
|
||||
const YGNodeRef root_child2 = YGNodeNewWithConfig(config);
|
||||
YGNodeStyleSetPaddingPercent(root_child2, YGEdgeTop, 10);
|
||||
YGNodeStyleSetMarginPercent(root_child2, YGEdgeTop, 10);
|
||||
root_child2->setMeasureFunc(_measure_100_100);
|
||||
YGNodeSetMeasureFunc(root_child2, _measure_100_100);
|
||||
YGNodeInsertChild(root, root_child2, 2);
|
||||
|
||||
const YGNodeRef root_child3 = YGNodeNewWithConfig(config);
|
||||
YGNodeStyleSetPaddingPercent(root_child3, YGEdgeTop, 20);
|
||||
YGNodeStyleSetMarginPercent(root_child3, YGEdgeTop, 20);
|
||||
root_child3->setMeasureFunc(_measure_100_100);
|
||||
YGNodeSetMeasureFunc(root_child3, _measure_100_100);
|
||||
YGNodeInsertChild(root, root_child3, 3);
|
||||
|
||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||
|
@@ -6,33 +6,33 @@
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <yoga/YGNode.h>
|
||||
#include <yoga/node/Node.h>
|
||||
#include <ostream>
|
||||
|
||||
using namespace facebook::yoga;
|
||||
|
||||
inline bool operator==(const YGSize& lhs, const YGSize& rhs) {
|
||||
return lhs.width == rhs.width && lhs.height == rhs.height;
|
||||
}
|
||||
|
||||
void PrintTo(const YGSize&, std::ostream*);
|
||||
|
||||
TEST(YGNode, hasMeasureFunc_initial) {
|
||||
auto n = YGNode{};
|
||||
TEST(Node, hasMeasureFunc_initial) {
|
||||
auto n = Node{};
|
||||
ASSERT_FALSE(n.hasMeasureFunc());
|
||||
}
|
||||
|
||||
TEST(YGNode, hasMeasureFunc_with_measure_fn) {
|
||||
auto n = YGNode{};
|
||||
n.setMeasureFunc([](YGNode*, float, YGMeasureMode, float, YGMeasureMode) {
|
||||
TEST(Node, hasMeasureFunc_with_measure_fn) {
|
||||
auto n = Node{};
|
||||
n.setMeasureFunc([](YGNodeRef, float, YGMeasureMode, float, YGMeasureMode) {
|
||||
return YGSize{};
|
||||
});
|
||||
ASSERT_TRUE(n.hasMeasureFunc());
|
||||
}
|
||||
|
||||
TEST(YGNode, measure_with_measure_fn) {
|
||||
auto n = YGNode{};
|
||||
TEST(Node, measure_with_measure_fn) {
|
||||
auto n = Node{};
|
||||
|
||||
n.setMeasureFunc(
|
||||
[](YGNode*, float w, YGMeasureMode wm, float h, YGMeasureMode hm) {
|
||||
[](YGNodeRef, float w, YGMeasureMode wm, float h, YGMeasureMode hm) {
|
||||
return YGSize{w * static_cast<int>(wm), h / static_cast<int>(hm)};
|
||||
});
|
||||
|
||||
@@ -41,10 +41,10 @@ TEST(YGNode, measure_with_measure_fn) {
|
||||
(YGSize{23, 12}));
|
||||
}
|
||||
|
||||
TEST(YGNode, measure_with_context_measure_fn) {
|
||||
auto n = YGNode{};
|
||||
TEST(Node, measure_with_context_measure_fn) {
|
||||
auto n = Node{};
|
||||
n.setMeasureFunc(
|
||||
[](YGNode*, float, YGMeasureMode, float, YGMeasureMode, void* ctx) {
|
||||
[](YGNodeRef, float, YGMeasureMode, float, YGMeasureMode, void* ctx) {
|
||||
return *(YGSize*) ctx;
|
||||
});
|
||||
|
||||
@@ -54,14 +54,14 @@ TEST(YGNode, measure_with_context_measure_fn) {
|
||||
result);
|
||||
}
|
||||
|
||||
TEST(YGNode, switching_measure_fn_types) {
|
||||
auto n = YGNode{};
|
||||
TEST(Node, switching_measure_fn_types) {
|
||||
auto n = Node{};
|
||||
n.setMeasureFunc(
|
||||
[](YGNode*, float, YGMeasureMode, float, YGMeasureMode, void*) {
|
||||
[](YGNodeRef, float, YGMeasureMode, float, YGMeasureMode, void*) {
|
||||
return YGSize{};
|
||||
});
|
||||
n.setMeasureFunc(
|
||||
[](YGNode*, float w, YGMeasureMode wm, float h, YGMeasureMode hm) {
|
||||
[](YGNodeRef, float w, YGMeasureMode wm, float h, YGMeasureMode hm) {
|
||||
return YGSize{w * static_cast<int>(wm), h / static_cast<int>(hm)};
|
||||
});
|
||||
|
||||
@@ -70,9 +70,9 @@ TEST(YGNode, switching_measure_fn_types) {
|
||||
(YGSize{23, 12}));
|
||||
}
|
||||
|
||||
TEST(YGNode, hasMeasureFunc_after_unset) {
|
||||
auto n = YGNode{};
|
||||
n.setMeasureFunc([](YGNode*, float, YGMeasureMode, float, YGMeasureMode) {
|
||||
TEST(Node, hasMeasureFunc_after_unset) {
|
||||
auto n = Node{};
|
||||
n.setMeasureFunc([](YGNodeRef, float, YGMeasureMode, float, YGMeasureMode) {
|
||||
return YGSize{};
|
||||
});
|
||||
|
||||
@@ -80,10 +80,10 @@ TEST(YGNode, hasMeasureFunc_after_unset) {
|
||||
ASSERT_FALSE(n.hasMeasureFunc());
|
||||
}
|
||||
|
||||
TEST(YGNode, hasMeasureFunc_after_unset_context) {
|
||||
auto n = YGNode{};
|
||||
TEST(Node, hasMeasureFunc_after_unset_context) {
|
||||
auto n = Node{};
|
||||
n.setMeasureFunc(
|
||||
[](YGNode*, float, YGMeasureMode, float, YGMeasureMode, void*) {
|
||||
[](YGNodeRef, float, YGMeasureMode, float, YGMeasureMode, void*) {
|
||||
return YGSize{};
|
||||
});
|
||||
|
||||
@@ -91,27 +91,27 @@ TEST(YGNode, hasMeasureFunc_after_unset_context) {
|
||||
ASSERT_FALSE(n.hasMeasureFunc());
|
||||
}
|
||||
|
||||
TEST(YGNode, hasBaselineFunc_initial) {
|
||||
auto n = YGNode{};
|
||||
TEST(Node, hasBaselineFunc_initial) {
|
||||
auto n = Node{};
|
||||
ASSERT_FALSE(n.hasBaselineFunc());
|
||||
}
|
||||
|
||||
TEST(YGNode, hasBaselineFunc_with_baseline_fn) {
|
||||
auto n = YGNode{};
|
||||
n.setBaselineFunc([](YGNode*, float, float) { return 0.0f; });
|
||||
TEST(Node, hasBaselineFunc_with_baseline_fn) {
|
||||
auto n = Node{};
|
||||
n.setBaselineFunc([](YGNodeRef, float, float) { return 0.0f; });
|
||||
ASSERT_TRUE(n.hasBaselineFunc());
|
||||
}
|
||||
|
||||
TEST(YGNode, baseline_with_baseline_fn) {
|
||||
auto n = YGNode{};
|
||||
n.setBaselineFunc([](YGNode*, float w, float h) { return w + h; });
|
||||
TEST(Node, baseline_with_baseline_fn) {
|
||||
auto n = Node{};
|
||||
n.setBaselineFunc([](YGNodeRef, float w, float h) { return w + h; });
|
||||
|
||||
ASSERT_EQ(n.baseline(1.25f, 2.5f, nullptr), 3.75f);
|
||||
}
|
||||
|
||||
TEST(YGNode, baseline_with_context_baseline_fn) {
|
||||
auto n = YGNode{};
|
||||
n.setBaselineFunc([](YGNode*, float w, float h, void* ctx) {
|
||||
TEST(Node, baseline_with_context_baseline_fn) {
|
||||
auto n = Node{};
|
||||
n.setBaselineFunc([](YGNodeRef, float w, float h, void* ctx) {
|
||||
return w + h + *(float*) ctx;
|
||||
});
|
||||
|
||||
@@ -119,29 +119,25 @@ TEST(YGNode, baseline_with_context_baseline_fn) {
|
||||
ASSERT_EQ(n.baseline(1.25f, 2.5f, &ctx), -6.25f);
|
||||
}
|
||||
|
||||
TEST(YGNode, hasBaselineFunc_after_unset) {
|
||||
auto n = YGNode{};
|
||||
n.setBaselineFunc([](YGNode*, float, float) { return 0.0f; });
|
||||
TEST(Node, hasBaselineFunc_after_unset) {
|
||||
auto n = Node{};
|
||||
n.setBaselineFunc([](YGNodeRef, float, float) { return 0.0f; });
|
||||
|
||||
n.setBaselineFunc(nullptr);
|
||||
ASSERT_FALSE(n.hasBaselineFunc());
|
||||
}
|
||||
|
||||
TEST(YGNode, hasBaselineFunc_after_unset_context) {
|
||||
auto n = YGNode{};
|
||||
n.setBaselineFunc([](YGNode*, float, float, void*) { return 0.0f; });
|
||||
TEST(Node, hasBaselineFunc_after_unset_context) {
|
||||
auto n = Node{};
|
||||
n.setBaselineFunc([](YGNodeRef, float, float, void*) { return 0.0f; });
|
||||
|
||||
n.setMeasureFunc(nullptr);
|
||||
ASSERT_FALSE(n.hasMeasureFunc());
|
||||
}
|
||||
|
||||
TEST(YGNode, switching_baseline_fn_types) {
|
||||
auto n = YGNode{};
|
||||
n.setBaselineFunc([](YGNode*, float, float, void*) { return 0.0f; });
|
||||
n.setBaselineFunc([](YGNode*, float, float) { return 1.0f; });
|
||||
TEST(Node, switching_baseline_fn_types) {
|
||||
auto n = Node{};
|
||||
n.setBaselineFunc([](YGNodeRef, float, float, void*) { return 0.0f; });
|
||||
n.setBaselineFunc([](YGNodeRef, float, float) { return 1.0f; });
|
||||
ASSERT_EQ(n.baseline(1, 2, nullptr), 1.0f);
|
||||
}
|
||||
|
||||
void PrintTo(const YGSize& size, std::ostream* os) {
|
||||
*os << "YGSize{" << size.width << ", " << size.height << "}";
|
||||
}
|
||||
|
@@ -7,10 +7,11 @@
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <yoga/Yoga.h>
|
||||
#include <yoga/YGNode.h>
|
||||
#include <yoga/node/Node.h>
|
||||
|
||||
#include "util/TestUtil.h"
|
||||
|
||||
using namespace facebook;
|
||||
using facebook::yoga::test::TestUtil;
|
||||
|
||||
TEST(YogaTest, cloning_shared_root) {
|
||||
@@ -273,9 +274,10 @@ TEST(YogaTest, mixed_shared_and_owned_children) {
|
||||
YGNodeInsertChild(root1, root1_child0, 0);
|
||||
YGNodeInsertChild(root1, root1_child2, 1);
|
||||
|
||||
auto children = root1->getChildren();
|
||||
children.insert(children.begin() + 1, root0_child0);
|
||||
root1->setChildren(children);
|
||||
auto children = static_cast<yoga::Node*>(root1)->getChildren();
|
||||
children.insert(children.begin() + 1, static_cast<yoga::Node*>(root0_child0));
|
||||
static_cast<yoga::Node*>(root1)->setChildren(children);
|
||||
|
||||
auto secondChild = YGNodeGetChild(root1, 1);
|
||||
ASSERT_EQ(secondChild, YGNodeGetChild(root0, 0));
|
||||
ASSERT_EQ(YGNodeGetChild(secondChild, 0), YGNodeGetChild(root0_child0, 0));
|
||||
|
@@ -6,7 +6,6 @@
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <yoga/YGNode.h>
|
||||
#include <yoga/Yoga.h>
|
||||
|
||||
static YGSize _measureFloor(
|
||||
@@ -50,7 +49,7 @@ TEST(YogaTest, rounding_feature_with_custom_measure_func_floor) {
|
||||
const YGNodeRef root = YGNodeNewWithConfig(config);
|
||||
|
||||
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
|
||||
root_child0->setMeasureFunc(_measureFloor);
|
||||
YGNodeSetMeasureFunc(root_child0, _measureFloor);
|
||||
YGNodeInsertChild(root, root_child0, 0);
|
||||
|
||||
YGConfigSetPointScaleFactor(config, 0.0f);
|
||||
@@ -98,7 +97,7 @@ TEST(YogaTest, rounding_feature_with_custom_measure_func_ceil) {
|
||||
const YGNodeRef root = YGNodeNewWithConfig(config);
|
||||
|
||||
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
|
||||
root_child0->setMeasureFunc(_measureCeil);
|
||||
YGNodeSetMeasureFunc(root_child0, _measureCeil);
|
||||
YGNodeInsertChild(root, root_child0, 0);
|
||||
|
||||
YGConfigSetPointScaleFactor(config, 1.0f);
|
||||
@@ -121,7 +120,7 @@ TEST(
|
||||
|
||||
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
|
||||
YGNodeStyleSetPosition(root_child0, YGEdgeLeft, 73.625);
|
||||
root_child0->setMeasureFunc(_measureFractial);
|
||||
YGNodeSetMeasureFunc(root_child0, _measureFractial);
|
||||
YGNodeInsertChild(root, root_child0, 0);
|
||||
|
||||
YGConfigSetPointScaleFactor(config, 2.0f);
|
||||
|
@@ -6,16 +6,15 @@
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <yoga/YGNode.h>
|
||||
#include <iostream>
|
||||
#include <yoga/Yoga.h>
|
||||
|
||||
TEST(YogaTest, copy_style_same) {
|
||||
const YGNodeRef node0 = YGNodeNew();
|
||||
const YGNodeRef node1 = YGNodeNew();
|
||||
ASSERT_FALSE(node0->isDirty());
|
||||
ASSERT_FALSE(YGNodeIsDirty(node0));
|
||||
|
||||
YGNodeCopyStyle(node0, node1);
|
||||
ASSERT_FALSE(node0->isDirty());
|
||||
ASSERT_FALSE(YGNodeIsDirty(node0));
|
||||
|
||||
YGNodeFree(node0);
|
||||
YGNodeFree(node1);
|
||||
@@ -23,7 +22,7 @@ TEST(YogaTest, copy_style_same) {
|
||||
|
||||
TEST(YogaTest, copy_style_modified) {
|
||||
const YGNodeRef node0 = YGNodeNew();
|
||||
ASSERT_FALSE(node0->isDirty());
|
||||
ASSERT_FALSE(YGNodeIsDirty(node0));
|
||||
ASSERT_EQ(YGFlexDirectionColumn, YGNodeStyleGetFlexDirection(node0));
|
||||
ASSERT_FALSE(YGNodeStyleGetMaxHeight(node0).unit != YGUnitUndefined);
|
||||
|
||||
@@ -32,7 +31,7 @@ TEST(YogaTest, copy_style_modified) {
|
||||
YGNodeStyleSetMaxHeight(node1, 10);
|
||||
|
||||
YGNodeCopyStyle(node0, node1);
|
||||
ASSERT_TRUE(node0->isDirty());
|
||||
ASSERT_TRUE(YGNodeIsDirty(node0));
|
||||
ASSERT_EQ(YGFlexDirectionRow, YGNodeStyleGetFlexDirection(node0));
|
||||
ASSERT_FLOAT_EQ(10, YGNodeStyleGetMaxHeight(node0).value);
|
||||
|
||||
@@ -45,14 +44,14 @@ TEST(YogaTest, copy_style_modified_same) {
|
||||
YGNodeStyleSetFlexDirection(node0, YGFlexDirectionRow);
|
||||
YGNodeStyleSetMaxHeight(node0, 10);
|
||||
YGNodeCalculateLayout(node0, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||
ASSERT_FALSE(node0->isDirty());
|
||||
ASSERT_FALSE(YGNodeIsDirty(node0));
|
||||
|
||||
const YGNodeRef node1 = YGNodeNew();
|
||||
YGNodeStyleSetFlexDirection(node1, YGFlexDirectionRow);
|
||||
YGNodeStyleSetMaxHeight(node1, 10);
|
||||
|
||||
YGNodeCopyStyle(node0, node1);
|
||||
ASSERT_FALSE(node0->isDirty());
|
||||
ASSERT_FALSE(YGNodeIsDirty(node0));
|
||||
|
||||
YGNodeFree(node0);
|
||||
YGNodeFree(node1);
|
||||
|
@@ -10,7 +10,7 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <yoga/Yoga.h>
|
||||
#include <yoga/config/Config.h>
|
||||
#include <yoga/YGNode.h>
|
||||
#include <yoga/node/Node.h>
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
@@ -22,7 +22,7 @@ struct ConfigCloningTest : public ::testing::Test {
|
||||
void SetUp() override;
|
||||
void TearDown() override;
|
||||
|
||||
static YGNode clonedNode;
|
||||
static yoga::Node clonedNode;
|
||||
static YGNodeRef cloneNode(YGNodeRef, YGNodeRef, int) { return &clonedNode; }
|
||||
static YGNodeRef doNotClone(YGNodeRef, YGNodeRef, int) { return nullptr; }
|
||||
};
|
||||
@@ -30,7 +30,7 @@ struct ConfigCloningTest : public ::testing::Test {
|
||||
TEST_F(ConfigCloningTest, uses_values_provided_by_cloning_callback) {
|
||||
config->setCloneNodeCallback(cloneNode);
|
||||
|
||||
YGNode node{}, owner{};
|
||||
yoga::Node node{}, owner{};
|
||||
auto clone = config->cloneNode(&node, &owner, 0, nullptr);
|
||||
|
||||
ASSERT_EQ(clone, &clonedNode);
|
||||
@@ -41,7 +41,7 @@ TEST_F(
|
||||
falls_back_to_regular_cloning_if_callback_returns_null) {
|
||||
config->setCloneNodeCallback(doNotClone);
|
||||
|
||||
YGNode node{}, owner{};
|
||||
yoga::Node node{}, owner{};
|
||||
auto clone = config->cloneNode(&node, &owner, 0, nullptr);
|
||||
|
||||
ASSERT_NE(clone, nullptr);
|
||||
@@ -53,7 +53,7 @@ TEST_F(ConfigCloningTest, can_clone_with_context) {
|
||||
return (YGNodeRef) context;
|
||||
});
|
||||
|
||||
YGNode node{}, owner{}, clone{};
|
||||
yoga::Node node{}, owner{}, clone{};
|
||||
ASSERT_EQ(config->cloneNode(&node, &owner, 0, &clone), &clone);
|
||||
}
|
||||
|
||||
@@ -65,4 +65,4 @@ void ConfigCloningTest::TearDown() {
|
||||
config.reset();
|
||||
}
|
||||
|
||||
YGNode ConfigCloningTest::clonedNode = {};
|
||||
yoga::Node ConfigCloningTest::clonedNode = {};
|
||||
|
@@ -7,7 +7,7 @@
|
||||
|
||||
#include "TestUtil.h"
|
||||
|
||||
#include <yoga/YGNode.h>
|
||||
#include <yoga/node/Node.h>
|
||||
#include <yoga/event/event.h>
|
||||
|
||||
namespace facebook::yoga::test {
|
||||
@@ -17,7 +17,7 @@ int nodeInstanceCount = 0;
|
||||
namespace {
|
||||
|
||||
void yogaEventSubscriber(
|
||||
const YGNode& /*node*/,
|
||||
YGNodeConstRef /*node*/,
|
||||
Event::Type eventType,
|
||||
const Event::Data& /*eventData*/) {
|
||||
|
||||
|
Reference in New Issue
Block a user