Make YGNode as c++ struct with properties exposed through accessors

Summary: Moved c implementation of `YGNode` to C++ struct. Not moving to C++ class as the React Classes dependent on `Yoga.h` assume it to be C. Thats why keeping `Yoga.h` C compatible. Sorry for the long diff, didn't thought that it will turn out to be this much big.Will keep an eye on number of lines next time 😉

Reviewed By: emilsjolander

Differential Revision: D6592257

fbshipit-source-id: 641e8b9462ad00731a094511f9f5608b23a6bb21
This commit is contained in:
Pritesh Nandgaonkar
2017-12-19 11:18:00 -08:00
committed by Facebook Github Bot
parent dbf6a12134
commit fbd332dee8
16 changed files with 1957 additions and 1091 deletions

View File

@@ -8,6 +8,7 @@
*/
#include <gtest/gtest.h>
#include <yoga/YGNode.h>
#include <yoga/Yoga.h>
static YGSize _measure(YGNodeRef node,
@@ -449,7 +450,7 @@ TEST(YogaTest, aspect_ratio_with_measure_func) {
YGNodeStyleSetHeight(root, 100);
const YGNodeRef root_child0 = YGNodeNew();
YGNodeSetMeasureFunc(root_child0, _measure);
root_child0->setMeasureFunc(_measure);
YGNodeStyleSetAspectRatio(root_child0, 1);
YGNodeInsertChild(root, root_child0, 0);

View File

@@ -8,10 +8,11 @@
*/
#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 *) YGNodeGetContext(node);
float* baseline = (float*)node->getContext();
return *baseline;
}
@@ -34,9 +35,9 @@ TEST(YogaTest, align_baseline_customer_func) {
float baselineValue = 10;
const YGNodeRef root_child1_child0 = YGNodeNew();
YGNodeSetContext(root_child1_child0, &baselineValue);
root_child1_child0->setContext(&baselineValue);
YGNodeStyleSetWidth(root_child1_child0, 50);
YGNodeSetBaselineFunc(root_child1_child0, _baseline);
root_child1_child0->setBaseLineFunc(_baseline);
YGNodeStyleSetHeight(root_child1_child0, 20);
YGNodeInsertChild(root_child1, root_child1_child0, 0);
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);

View File

@@ -8,7 +8,7 @@
*/
#include <gtest/gtest.h>
#include <yoga/Yoga.h>
#include <yoga/YGNode.h>
TEST(YogaTest, dirty_propagation) {
const YGNodeRef root = YGNodeNew();
@@ -30,15 +30,15 @@ TEST(YogaTest, dirty_propagation) {
YGNodeStyleSetWidth(root_child0, 20);
EXPECT_TRUE(YGNodeIsDirty(root_child0));
EXPECT_FALSE(YGNodeIsDirty(root_child1));
EXPECT_TRUE(YGNodeIsDirty(root));
EXPECT_TRUE(root_child0->isDirty());
EXPECT_FALSE(root_child1->isDirty());
EXPECT_TRUE(root->isDirty());
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
EXPECT_FALSE(YGNodeIsDirty(root_child0));
EXPECT_FALSE(YGNodeIsDirty(root_child1));
EXPECT_FALSE(YGNodeIsDirty(root));
EXPECT_FALSE(root_child0->isDirty());
EXPECT_FALSE(root_child1->isDirty());
EXPECT_FALSE(root->isDirty());
YGNodeFreeRecursive(root);
}
@@ -63,9 +63,9 @@ TEST(YogaTest, dirty_propagation_only_if_prop_changed) {
YGNodeStyleSetWidth(root_child0, 50);
EXPECT_FALSE(YGNodeIsDirty(root_child0));
EXPECT_FALSE(YGNodeIsDirty(root_child1));
EXPECT_FALSE(YGNodeIsDirty(root));
EXPECT_FALSE(root_child0->isDirty());
EXPECT_FALSE(root_child1->isDirty());
EXPECT_FALSE(root->isDirty());
YGNodeFreeRecursive(root);
}
@@ -133,11 +133,11 @@ TEST(YogaTest, dirty_node_only_if_children_are_actually_removed) {
const YGNodeRef child1 = YGNodeNew();
YGNodeRemoveChild(root, child1);
EXPECT_FALSE(YGNodeIsDirty(root));
EXPECT_FALSE(root->isDirty());
YGNodeFree(child1);
YGNodeRemoveChild(root, child0);
EXPECT_TRUE(YGNodeIsDirty(root));
EXPECT_TRUE(root->isDirty());
YGNodeFree(child0);
YGNodeFreeRecursive(root);
@@ -151,11 +151,11 @@ TEST(YogaTest, dirty_node_only_if_undefined_values_gets_set_to_undefined) {
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
EXPECT_FALSE(YGNodeIsDirty(root));
EXPECT_FALSE(root->isDirty());
YGNodeStyleSetMinWidth(root, YGUndefined);
EXPECT_FALSE(YGNodeIsDirty(root));
EXPECT_FALSE(root->isDirty());
YGNodeFreeRecursive(root);
}

View File

@@ -8,6 +8,7 @@
*/
#include <gtest/gtest.h>
#include <yoga/YGNode.h>
#include <yoga/Yoga.h>
static YGSize _measureMax(YGNodeRef node,
@@ -15,7 +16,7 @@ static YGSize _measureMax(YGNodeRef node,
YGMeasureMode widthMode,
float height,
YGMeasureMode heightMode) {
int *measureCount = (int *) YGNodeGetContext(node);
int* measureCount = (int*)node->getContext();
(*measureCount)++;
return YGSize{
@@ -29,7 +30,7 @@ static YGSize _measureMin(YGNodeRef node,
YGMeasureMode widthMode,
float height,
YGMeasureMode heightMode) {
int *measureCount = (int *) YGNodeGetContext(node);
int* measureCount = (int*)node->getContext();
*measureCount = *measureCount + 1;
return YGSize{
.width =
@@ -48,7 +49,7 @@ static YGSize _measure_84_49(YGNodeRef node,
YGMeasureMode widthMode,
float height,
YGMeasureMode heightMode) {
int *measureCount = (int *) YGNodeGetContext(node);
int* measureCount = (int*)node->getContext();
if (measureCount) {
(*measureCount)++;
}
@@ -67,8 +68,8 @@ TEST(YogaTest, measure_once_single_flexible_child) {
const YGNodeRef root_child0 = YGNodeNew();
int measureCount = 0;
YGNodeSetContext(root_child0, &measureCount);
YGNodeSetMeasureFunc(root_child0, _measureMax);
root_child0->setContext(&measureCount);
root_child0->setMeasureFunc(_measureMax);
YGNodeStyleSetFlexGrow(root_child0, 1);
YGNodeInsertChild(root, root_child0, 0);
@@ -84,8 +85,8 @@ TEST(YogaTest, remeasure_with_same_exact_width_larger_than_needed_height) {
const YGNodeRef root_child0 = YGNodeNew();
int measureCount = 0;
YGNodeSetContext(root_child0, &measureCount);
YGNodeSetMeasureFunc(root_child0, _measureMin);
root_child0->setContext(&measureCount);
root_child0->setMeasureFunc(_measureMin);
YGNodeInsertChild(root, root_child0, 0);
YGNodeCalculateLayout(root, 100, 100, YGDirectionLTR);
@@ -102,8 +103,8 @@ TEST(YogaTest, remeasure_with_same_atmost_width_larger_than_needed_height) {
const YGNodeRef root_child0 = YGNodeNew();
int measureCount = 0;
YGNodeSetContext(root_child0, &measureCount);
YGNodeSetMeasureFunc(root_child0, _measureMin);
root_child0->setContext(&measureCount);
root_child0->setMeasureFunc(_measureMin);
YGNodeInsertChild(root, root_child0, 0);
YGNodeCalculateLayout(root, 100, 100, YGDirectionLTR);
@@ -120,8 +121,8 @@ TEST(YogaTest, remeasure_with_computed_width_larger_than_needed_height) {
const YGNodeRef root_child0 = YGNodeNew();
int measureCount = 0;
YGNodeSetContext(root_child0, &measureCount);
YGNodeSetMeasureFunc(root_child0, _measureMin);
root_child0->setContext(&measureCount);
root_child0->setMeasureFunc(_measureMin);
YGNodeInsertChild(root, root_child0, 0);
YGNodeCalculateLayout(root, 100, 100, YGDirectionLTR);
@@ -139,8 +140,8 @@ TEST(YogaTest, remeasure_with_atmost_computed_width_undefined_height) {
const YGNodeRef root_child0 = YGNodeNew();
int measureCount = 0;
YGNodeSetContext(root_child0, &measureCount);
YGNodeSetMeasureFunc(root_child0, _measureMin);
root_child0->setContext(&measureCount);
root_child0->setMeasureFunc(_measureMin);
YGNodeInsertChild(root, root_child0, 0);
YGNodeCalculateLayout(root, 100, YGUndefined, YGDirectionLTR);
@@ -165,8 +166,8 @@ TEST(YogaTest, remeasure_with_already_measured_value_smaller_but_still_float_equ
YGNodeInsertChild(root, root_child0, 0);
const YGNodeRef root_child0_child0 = YGNodeNew();
YGNodeSetContext(root_child0_child0, &measureCount);
YGNodeSetMeasureFunc(root_child0_child0, _measure_84_49);
root_child0_child0->setContext(&measureCount);
root_child0_child0->setMeasureFunc(_measure_84_49);
YGNodeInsertChild(root_child0, root_child0_child0, 0);
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);

View File

@@ -8,6 +8,7 @@
*/
#include <gtest/gtest.h>
#include <yoga/YGNode.h>
#include <yoga/Yoga.h>
struct _MeasureConstraint {
@@ -27,8 +28,8 @@ static YGSize _measure(YGNodeRef node,
YGMeasureMode widthMode,
float height,
YGMeasureMode heightMode) {
struct _MeasureConstraintList *constraintList =
(struct _MeasureConstraintList *) YGNodeGetContext(node);
struct _MeasureConstraintList* constraintList =
(struct _MeasureConstraintList*)node->getContext();
struct _MeasureConstraint *constraints = constraintList->constraints;
uint32_t currentIndex = constraintList->length;
(&constraints[currentIndex])->width = width;
@@ -54,8 +55,10 @@ TEST(YogaTest, exactly_measure_stretched_child_column) {
YGNodeStyleSetHeight(root, 100);
const YGNodeRef root_child0 = YGNodeNew();
YGNodeSetContext(root_child0, &constraintList);
YGNodeSetMeasureFunc(root_child0, _measure);
// root_child0->setContext(&constraintList);
root_child0->setContext(&constraintList);
root_child0->setMeasureFunc(_measure);
// root_child0->setMeasureFunc(_measure);
YGNodeInsertChild(root, root_child0, 0);
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
@@ -81,8 +84,9 @@ TEST(YogaTest, exactly_measure_stretched_child_row) {
YGNodeStyleSetHeight(root, 100);
const YGNodeRef root_child0 = YGNodeNew();
YGNodeSetContext(root_child0, &constraintList);
YGNodeSetMeasureFunc(root_child0, _measure);
// root_child0->setContext(&constraintList);
root_child0->setContext(&constraintList);
root_child0->setMeasureFunc(_measure);
YGNodeInsertChild(root, root_child0, 0);
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
@@ -107,8 +111,8 @@ TEST(YogaTest, at_most_main_axis_column) {
YGNodeStyleSetHeight(root, 100);
const YGNodeRef root_child0 = YGNodeNew();
YGNodeSetContext(root_child0, &constraintList);
YGNodeSetMeasureFunc(root_child0, _measure);
root_child0->setContext(&constraintList);
root_child0->setMeasureFunc(_measure);
YGNodeInsertChild(root, root_child0, 0);
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
@@ -134,8 +138,8 @@ TEST(YogaTest, at_most_cross_axis_column) {
YGNodeStyleSetHeight(root, 100);
const YGNodeRef root_child0 = YGNodeNew();
YGNodeSetContext(root_child0, &constraintList);
YGNodeSetMeasureFunc(root_child0, _measure);
root_child0->setContext(&constraintList);
root_child0->setMeasureFunc(_measure);
YGNodeInsertChild(root, root_child0, 0);
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
@@ -161,8 +165,8 @@ TEST(YogaTest, at_most_main_axis_row) {
YGNodeStyleSetHeight(root, 100);
const YGNodeRef root_child0 = YGNodeNew();
YGNodeSetContext(root_child0, &constraintList);
YGNodeSetMeasureFunc(root_child0, _measure);
root_child0->setContext(&constraintList);
root_child0->setMeasureFunc(_measure);
YGNodeInsertChild(root, root_child0, 0);
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
@@ -189,8 +193,8 @@ TEST(YogaTest, at_most_cross_axis_row) {
YGNodeStyleSetHeight(root, 100);
const YGNodeRef root_child0 = YGNodeNew();
YGNodeSetContext(root_child0, &constraintList);
YGNodeSetMeasureFunc(root_child0, _measure);
root_child0->setContext(&constraintList);
root_child0->setMeasureFunc(_measure);
YGNodeInsertChild(root, root_child0, 0);
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
@@ -215,8 +219,8 @@ TEST(YogaTest, flex_child) {
const YGNodeRef root_child0 = YGNodeNew();
YGNodeStyleSetFlexGrow(root_child0, 1);
YGNodeSetContext(root_child0, &constraintList);
YGNodeSetMeasureFunc(root_child0, _measure);
root_child0->setContext(&constraintList);
root_child0->setMeasureFunc(_measure);
YGNodeInsertChild(root, root_child0, 0);
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
@@ -245,8 +249,8 @@ TEST(YogaTest, flex_child_with_flex_basis) {
const YGNodeRef root_child0 = YGNodeNew();
YGNodeStyleSetFlexGrow(root_child0, 1);
YGNodeStyleSetFlexBasis(root_child0, 0);
YGNodeSetContext(root_child0, &constraintList);
YGNodeSetMeasureFunc(root_child0, _measure);
root_child0->setContext(&constraintList);
root_child0->setMeasureFunc(_measure);
YGNodeInsertChild(root, root_child0, 0);
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
@@ -273,8 +277,8 @@ TEST(YogaTest, overflow_scroll_column) {
YGNodeStyleSetWidth(root, 100);
const YGNodeRef root_child0 = YGNodeNew();
YGNodeSetContext(root_child0, &constraintList);
YGNodeSetMeasureFunc(root_child0, _measure);
root_child0->setContext(&constraintList);
root_child0->setMeasureFunc(_measure);
YGNodeInsertChild(root, root_child0, 0);
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
@@ -305,8 +309,8 @@ TEST(YogaTest, overflow_scroll_row) {
YGNodeStyleSetWidth(root, 100);
const YGNodeRef root_child0 = YGNodeNew();
YGNodeSetContext(root_child0, &constraintList);
YGNodeSetMeasureFunc(root_child0, _measure);
root_child0->setContext(&constraintList);
root_child0->setMeasureFunc(_measure);
YGNodeInsertChild(root, root_child0, 0);
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);

View File

@@ -8,6 +8,7 @@
*/
#include <gtest/gtest.h>
#include <yoga/YGNode.h>
#include <yoga/Yoga.h>
static YGSize _measure(YGNodeRef node,
@@ -15,7 +16,7 @@ static YGSize _measure(YGNodeRef node,
YGMeasureMode widthMode,
float height,
YGMeasureMode heightMode) {
int *measureCount = (int *) YGNodeGetContext(node);
int* measureCount = (int*)node->getContext();
if (measureCount) {
(*measureCount)++;
}
@@ -46,7 +47,7 @@ static YGSize _measure_assert_negative(YGNodeRef node,
YGMeasureMode heightMode) {
EXPECT_GE(width, 0);
EXPECT_GE(height, 0);
return YGSize{
.width = 0, .height = 0,
};
@@ -60,8 +61,8 @@ TEST(YogaTest, dont_measure_single_grow_shrink_child) {
int measureCount = 0;
const YGNodeRef root_child0 = YGNodeNew();
YGNodeSetContext(root_child0, &measureCount);
YGNodeSetMeasureFunc(root_child0, _measure);
root_child0->setContext(&measureCount);
root_child0->setMeasureFunc(_measure);
YGNodeStyleSetFlexGrow(root_child0, 1);
YGNodeStyleSetFlexShrink(root_child0, 1);
YGNodeInsertChild(root, root_child0, 0);
@@ -83,8 +84,8 @@ TEST(YogaTest, measure_absolute_child_with_no_constraints) {
const YGNodeRef root_child0_child0 = YGNodeNew();
YGNodeStyleSetPositionType(root_child0_child0, YGPositionTypeAbsolute);
YGNodeSetContext(root_child0_child0, &measureCount);
YGNodeSetMeasureFunc(root_child0_child0, _measure);
root_child0_child0->setContext(&measureCount);
root_child0_child0->setMeasureFunc(_measure);
YGNodeInsertChild(root_child0, root_child0_child0, 0);
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
@@ -103,8 +104,8 @@ TEST(YogaTest, dont_measure_when_min_equals_max) {
int measureCount = 0;
const YGNodeRef root_child0 = YGNodeNew();
YGNodeSetContext(root_child0, &measureCount);
YGNodeSetMeasureFunc(root_child0, _measure);
root_child0->setContext(&measureCount);
root_child0->setMeasureFunc(_measure);
YGNodeStyleSetMinWidth(root_child0, 10);
YGNodeStyleSetMaxWidth(root_child0, 10);
YGNodeStyleSetMinHeight(root_child0, 10);
@@ -131,8 +132,8 @@ TEST(YogaTest, dont_measure_when_min_equals_max_percentages) {
int measureCount = 0;
const YGNodeRef root_child0 = YGNodeNew();
YGNodeSetContext(root_child0, &measureCount);
YGNodeSetMeasureFunc(root_child0, _measure);
root_child0->setContext(&measureCount);
root_child0->setMeasureFunc(_measure);
YGNodeStyleSetMinWidthPercent(root_child0, 10);
YGNodeStyleSetMaxWidthPercent(root_child0, 10);
YGNodeStyleSetMinHeightPercent(root_child0, 10);
@@ -157,7 +158,7 @@ TEST(YogaTest, measure_nodes_with_margin_auto_and_stretch) {
YGNodeStyleSetHeight(root, 500);
const YGNodeRef root_child0 = YGNodeNew();
YGNodeSetMeasureFunc(root_child0, _measure);
root_child0->setMeasureFunc(_measure);
YGNodeStyleSetMarginAuto(root_child0, YGEdgeLeft);
YGNodeInsertChild(root, root_child0, 0);
@@ -180,8 +181,8 @@ TEST(YogaTest, dont_measure_when_min_equals_max_mixed_width_percent) {
int measureCount = 0;
const YGNodeRef root_child0 = YGNodeNew();
YGNodeSetContext(root_child0, &measureCount);
YGNodeSetMeasureFunc(root_child0, _measure);
root_child0->setContext(&measureCount);
root_child0->setMeasureFunc(_measure);
YGNodeStyleSetMinWidthPercent(root_child0, 10);
YGNodeStyleSetMaxWidthPercent(root_child0, 10);
YGNodeStyleSetMinHeight(root_child0, 10);
@@ -208,8 +209,8 @@ TEST(YogaTest, dont_measure_when_min_equals_max_mixed_height_percent) {
int measureCount = 0;
const YGNodeRef root_child0 = YGNodeNew();
YGNodeSetContext(root_child0, &measureCount);
YGNodeSetMeasureFunc(root_child0, _measure);
root_child0->setContext(&measureCount);
root_child0->setMeasureFunc(_measure);
YGNodeStyleSetMinWidth(root_child0, 10);
YGNodeStyleSetMaxWidth(root_child0, 10);
YGNodeStyleSetMinHeightPercent(root_child0, 10);
@@ -233,7 +234,7 @@ TEST(YogaTest, measure_enough_size_should_be_in_single_line) {
const YGNodeRef root_child0 = YGNodeNew();
YGNodeStyleSetAlignSelf(root_child0, YGAlignFlexStart);
YGNodeSetMeasureFunc(root_child0, _simulate_wrapping_text);
root_child0->setMeasureFunc(_simulate_wrapping_text);
YGNodeInsertChild(root, root_child0, 0);
@@ -251,8 +252,8 @@ TEST(YogaTest, measure_not_enough_size_should_wrap) {
const YGNodeRef root_child0 = YGNodeNew();
YGNodeStyleSetAlignSelf(root_child0, YGAlignFlexStart);
YGNodeSetMeasureFunc(root_child0, _simulate_wrapping_text);
// YGNodeSetMeasureFunc(root_child0, _simulate_wrapping_text);
root_child0->setMeasureFunc(_simulate_wrapping_text);
YGNodeInsertChild(root, root_child0, 0);
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
@@ -274,8 +275,8 @@ TEST(YogaTest, measure_zero_space_should_grow) {
const YGNodeRef root_child0 = YGNodeNew();
YGNodeStyleSetFlexDirection(root_child0, YGFlexDirectionColumn);
YGNodeStyleSetPadding(root_child0, YGEdgeAll, 100);
YGNodeSetContext(root_child0, &measureCount);
YGNodeSetMeasureFunc(root_child0, _measure);
root_child0->setContext(&measureCount);
root_child0->setMeasureFunc(_measure);
YGNodeInsertChild(root, root_child0, 0);
@@ -300,7 +301,8 @@ TEST(YogaTest, measure_flex_direction_row_and_padding) {
YGNodeStyleSetHeight(root, 50);
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);
@@ -339,7 +341,8 @@ TEST(YogaTest, measure_flex_direction_column_and_padding) {
YGNodeStyleSetHeight(root, 50);
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);
@@ -378,7 +381,8 @@ TEST(YogaTest, measure_flex_direction_row_no_padding) {
YGNodeStyleSetHeight(root, 50);
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
YGNodeSetMeasureFunc(root_child0, _simulate_wrapping_text);
// YGNodeSetMeasureFunc(root_child0, _simulate_wrapping_text);
root_child0->setMeasureFunc(_simulate_wrapping_text);
YGNodeInsertChild(root, root_child0, 0);
const YGNodeRef root_child1 = YGNodeNewWithConfig(config);
@@ -418,7 +422,7 @@ TEST(YogaTest, measure_flex_direction_row_no_padding_align_items_flexstart) {
YGNodeStyleSetAlignItems(root, YGAlignFlexStart);
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
YGNodeSetMeasureFunc(root_child0, _simulate_wrapping_text);
root_child0->setMeasureFunc(_simulate_wrapping_text);
YGNodeInsertChild(root, root_child0, 0);
const YGNodeRef root_child1 = YGNodeNewWithConfig(config);
@@ -457,7 +461,7 @@ TEST(YogaTest, measure_with_fixed_size) {
YGNodeStyleSetHeight(root, 50);
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
YGNodeSetMeasureFunc(root_child0, _simulate_wrapping_text);
root_child0->setMeasureFunc(_simulate_wrapping_text);
YGNodeStyleSetWidth(root_child0, 10);
YGNodeStyleSetHeight(root_child0, 10);
YGNodeInsertChild(root, root_child0, 0);
@@ -498,7 +502,7 @@ TEST(YogaTest, measure_with_flex_shrink) {
YGNodeStyleSetHeight(root, 50);
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
YGNodeSetMeasureFunc(root_child0, _simulate_wrapping_text);
root_child0->setMeasureFunc(_simulate_wrapping_text);
YGNodeStyleSetFlexShrink(root_child0, 1);
YGNodeInsertChild(root, root_child0, 0);
@@ -537,7 +541,7 @@ TEST(YogaTest, measure_no_padding) {
YGNodeStyleSetHeight(root, 50);
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
YGNodeSetMeasureFunc(root_child0, _simulate_wrapping_text);
root_child0->setMeasureFunc(_simulate_wrapping_text);
YGNodeStyleSetFlexShrink(root_child0, 1);
YGNodeInsertChild(root, root_child0, 0);
@@ -570,7 +574,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();
YGNodeSetMeasureFunc(root, _measure);
root->setMeasureFunc(_measure);
const YGNodeRef root_child0 = YGNodeNew();
ASSERT_DEATH(YGNodeInsertChild(root, root_child0, 0), "Cannot add child.*");
@@ -582,8 +586,7 @@ TEST(YogaDeathTest, cannot_add_nonnull_measure_func_to_non_leaf_node) {
const YGNodeRef root = YGNodeNew();
const YGNodeRef root_child0 = YGNodeNew();
YGNodeInsertChild(root, root_child0, 0);
ASSERT_DEATH(YGNodeSetMeasureFunc(root, _measure), "Cannot set measure function.*");
ASSERT_DEATH(root->setMeasureFunc(_measure), "Cannot set measure function.*");
YGNodeFreeRecursive(root);
}
@@ -592,46 +595,45 @@ 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);
YGNodeSetMeasureFunc(root, NULL);
ASSERT_TRUE(YGNodeGetMeasureFunc(root) == NULL);
root->setMeasureFunc(nullptr);
ASSERT_TRUE(root->getMeasure() == NULL);
YGNodeFreeRecursive(root);
}
TEST(YogaTest, cant_call_negative_measure) {
const YGConfigRef config = YGConfigNew();
const YGNodeRef root = YGNodeNewWithConfig(config);
YGNodeStyleSetFlexDirection(root, YGFlexDirectionColumn);
YGNodeStyleSetWidth(root, 50);
YGNodeStyleSetHeight(root, 10);
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
YGNodeSetMeasureFunc(root_child0, _measure_assert_negative);
root_child0->setMeasureFunc(_measure_assert_negative);
YGNodeStyleSetMargin(root_child0, YGEdgeTop, 20);
YGNodeInsertChild(root, root_child0, 0);
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
YGNodeFreeRecursive(root);
YGConfigFree(config);
}
TEST(YogaTest, cant_call_negative_measure_horizontal) {
const YGConfigRef config = YGConfigNew();
const YGNodeRef root = YGNodeNewWithConfig(config);
YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow);
YGNodeStyleSetWidth(root, 10);
YGNodeStyleSetHeight(root, 20);
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
YGNodeSetMeasureFunc(root_child0, _measure_assert_negative);
root_child0->setMeasureFunc(_measure_assert_negative);
YGNodeStyleSetMargin(root_child0, YGEdgeStart, 20);
YGNodeInsertChild(root, root_child0, 0);
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
YGNodeFreeRecursive(root);
YGConfigFree(config);
}
@@ -661,8 +663,7 @@ TEST(YogaTest, percent_with_text_node) {
YGNodeInsertChild(root, root_child0, 0);
const YGNodeRef root_child1 = YGNodeNewWithConfig(config);
YGNodeSetMeasureFunc(root_child1, _measure_90_10);
root_child1->setMeasureFunc(_measure_90_10);
YGNodeStyleSetMaxWidthPercent(root_child1, 50);
YGNodeStyleSetPaddingPercent(root_child1, YGEdgeTop, 50);
YGNodeInsertChild(root, root_child1, 1);

View File

@@ -8,6 +8,7 @@
*/
#include <gtest/gtest.h>
#include <yoga/YGNode.h>
#include <yoga/Yoga.h>
static YGSize _measureFloor(YGNodeRef node,
@@ -45,7 +46,7 @@ TEST(YogaTest, rounding_feature_with_custom_measure_func_floor) {
const YGNodeRef root = YGNodeNewWithConfig(config);
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
YGNodeSetMeasureFunc(root_child0, _measureFloor);
root_child0->setMeasureFunc(_measureFloor);
YGNodeInsertChild(root, root_child0, 0);
YGConfigSetPointScaleFactor(config, 0.0f);
@@ -93,7 +94,7 @@ TEST(YogaTest, rounding_feature_with_custom_measure_func_ceil) {
const YGNodeRef root = YGNodeNewWithConfig(config);
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
YGNodeSetMeasureFunc(root_child0, _measureCeil);
root_child0->setMeasureFunc(_measureCeil);
YGNodeInsertChild(root, root_child0, 0);
YGConfigSetPointScaleFactor(config, 1.0f);
@@ -114,7 +115,7 @@ TEST(YogaTest, rounding_feature_with_custom_measure_and_fractial_matching_scale)
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
YGNodeStyleSetPosition(root_child0, YGEdgeLeft, 73.625);
YGNodeSetMeasureFunc(root_child0, _measureFractial);
root_child0->setMeasureFunc(_measureFractial);
YGNodeInsertChild(root, root_child0, 0);
YGConfigSetPointScaleFactor(config, 2.0f);

View File

@@ -8,15 +8,15 @@
*/
#include <gtest/gtest.h>
#include <yoga/Yoga.h>
#include <yoga/YGNode.h>
TEST(YogaTest, copy_style_same) {
const YGNodeRef node0 = YGNodeNew();
const YGNodeRef node1 = YGNodeNew();
ASSERT_FALSE(YGNodeIsDirty(node0));
ASSERT_FALSE(node0->isDirty());
YGNodeCopyStyle(node0, node1);
ASSERT_FALSE(YGNodeIsDirty(node0));
ASSERT_FALSE(node0->isDirty());
YGNodeFree(node0);
YGNodeFree(node1);
@@ -24,7 +24,7 @@ TEST(YogaTest, copy_style_same) {
TEST(YogaTest, copy_style_modified) {
const YGNodeRef node0 = YGNodeNew();
ASSERT_FALSE(YGNodeIsDirty(node0));
ASSERT_FALSE(node0->isDirty());
ASSERT_EQ(YGFlexDirectionColumn, YGNodeStyleGetFlexDirection(node0));
ASSERT_FALSE(YGNodeStyleGetMaxHeight(node0).unit != YGUnitUndefined);
@@ -33,7 +33,7 @@ TEST(YogaTest, copy_style_modified) {
YGNodeStyleSetMaxHeight(node1, 10);
YGNodeCopyStyle(node0, node1);
ASSERT_TRUE(YGNodeIsDirty(node0));
ASSERT_TRUE(node0->isDirty());
ASSERT_EQ(YGFlexDirectionRow, YGNodeStyleGetFlexDirection(node0));
ASSERT_FLOAT_EQ(10, YGNodeStyleGetMaxHeight(node0).value);
@@ -46,14 +46,14 @@ TEST(YogaTest, copy_style_modified_same) {
YGNodeStyleSetFlexDirection(node0, YGFlexDirectionRow);
YGNodeStyleSetMaxHeight(node0, 10);
YGNodeCalculateLayout(node0, YGUndefined, YGUndefined, YGDirectionLTR);
ASSERT_FALSE(YGNodeIsDirty(node0));
ASSERT_FALSE(node0->isDirty());
const YGNodeRef node1 = YGNodeNew();
YGNodeStyleSetFlexDirection(node1, YGFlexDirectionRow);
YGNodeStyleSetMaxHeight(node1, 10);
YGNodeCopyStyle(node0, node1);
ASSERT_FALSE(YGNodeIsDirty(node0));
ASSERT_FALSE(node0->isDirty());
YGNodeFree(node0);
YGNodeFree(node1);