Rename C api

Summary: This renames the core C api to use the new Yoga branding.

Differential Revision: D4259190

fbshipit-source-id: 26c8b356ca464d4304f5f9dc4192bff10cea2dc9
This commit is contained in:
Emil Sjolander
2016-12-03 04:40:18 -08:00
committed by Facebook Github Bot
parent f7cc614d67
commit dda24b1e23
49 changed files with 6459 additions and 6441 deletions

View File

@@ -7,7 +7,7 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/
#include <CSSLayout/CSSLayout.h>
#include <CSSLayout/Yoga.h>
#include <gtest/gtest.h>
struct _MeasureConstraint {
@@ -22,12 +22,12 @@ struct _MeasureConstraintList {
struct _MeasureConstraint *constraints;
};
static CSSSize _measure(CSSNodeRef node,
static YGSize _measure(YGNodeRef node,
float width,
YGMeasureMode widthMode,
float height,
YGMeasureMode heightMode) {
struct _MeasureConstraintList *constraintList = (struct _MeasureConstraintList *)CSSNodeGetContext(node);
struct _MeasureConstraintList *constraintList = (struct _MeasureConstraintList *)YGNodeGetContext(node);
struct _MeasureConstraint *constraints = constraintList->constraints;
uint32_t currentIndex = constraintList->length;
(&constraints[currentIndex])->width = width;
@@ -36,28 +36,28 @@ static CSSSize _measure(CSSNodeRef node,
(&constraints[currentIndex])->heightMode = heightMode;
constraintList->length = currentIndex + 1;
return CSSSize {
return YGSize {
.width = widthMode == YGMeasureModeUndefined ? 10 : width,
.height = heightMode == YGMeasureModeUndefined ? 10 : width,
};
}
TEST(CSSLayoutTest, exactly_measure_stretched_child_column) {
TEST(YogaTest, exactly_measure_stretched_child_column) {
struct _MeasureConstraintList constraintList = _MeasureConstraintList {
.length = 0,
.constraints = (struct _MeasureConstraint *) malloc(10 * sizeof(struct _MeasureConstraint)),
};
const CSSNodeRef root = CSSNodeNew();
CSSNodeStyleSetWidth(root, 100);
CSSNodeStyleSetHeight(root, 100);
const YGNodeRef root = YGNodeNew();
YGNodeStyleSetWidth(root, 100);
YGNodeStyleSetHeight(root, 100);
const CSSNodeRef root_child0 = CSSNodeNew();
CSSNodeSetContext(root_child0, &constraintList);
CSSNodeSetMeasureFunc(root_child0, _measure);
CSSNodeInsertChild(root, root_child0, 0);
const YGNodeRef root_child0 = YGNodeNew();
YGNodeSetContext(root_child0, &constraintList);
YGNodeSetMeasureFunc(root_child0, _measure);
YGNodeInsertChild(root, root_child0, 0);
CSSNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
ASSERT_EQ(1, constraintList.length);
@@ -65,26 +65,26 @@ TEST(CSSLayoutTest, exactly_measure_stretched_child_column) {
ASSERT_EQ(YGMeasureModeExactly, constraintList.constraints[0].widthMode);
free(constraintList.constraints);
CSSNodeFreeRecursive(root);
YGNodeFreeRecursive(root);
}
TEST(CSSLayoutTest, exactly_measure_stretched_child_row) {
TEST(YogaTest, exactly_measure_stretched_child_row) {
struct _MeasureConstraintList constraintList = _MeasureConstraintList {
.length = 0,
.constraints = (struct _MeasureConstraint *) malloc(10 * sizeof(struct _MeasureConstraint)),
};
const CSSNodeRef root = CSSNodeNew();
CSSNodeStyleSetFlexDirection(root, YGFlexDirectionRow);
CSSNodeStyleSetWidth(root, 100);
CSSNodeStyleSetHeight(root, 100);
const YGNodeRef root = YGNodeNew();
YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow);
YGNodeStyleSetWidth(root, 100);
YGNodeStyleSetHeight(root, 100);
const CSSNodeRef root_child0 = CSSNodeNew();
CSSNodeSetContext(root_child0, &constraintList);
CSSNodeSetMeasureFunc(root_child0, _measure);
CSSNodeInsertChild(root, root_child0, 0);
const YGNodeRef root_child0 = YGNodeNew();
YGNodeSetContext(root_child0, &constraintList);
YGNodeSetMeasureFunc(root_child0, _measure);
YGNodeInsertChild(root, root_child0, 0);
CSSNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
ASSERT_EQ(1, constraintList.length);
@@ -92,25 +92,25 @@ TEST(CSSLayoutTest, exactly_measure_stretched_child_row) {
ASSERT_EQ(YGMeasureModeExactly, constraintList.constraints[0].heightMode);
free(constraintList.constraints);
CSSNodeFreeRecursive(root);
YGNodeFreeRecursive(root);
}
TEST(CSSLayoutTest, at_most_main_axis_column) {
TEST(YogaTest, at_most_main_axis_column) {
struct _MeasureConstraintList constraintList = _MeasureConstraintList {
.length = 0,
.constraints = (struct _MeasureConstraint *) malloc(10 * sizeof(struct _MeasureConstraint)),
};
const CSSNodeRef root = CSSNodeNew();
CSSNodeStyleSetWidth(root, 100);
CSSNodeStyleSetHeight(root, 100);
const YGNodeRef root = YGNodeNew();
YGNodeStyleSetWidth(root, 100);
YGNodeStyleSetHeight(root, 100);
const CSSNodeRef root_child0 = CSSNodeNew();
CSSNodeSetContext(root_child0, &constraintList);
CSSNodeSetMeasureFunc(root_child0, _measure);
CSSNodeInsertChild(root, root_child0, 0);
const YGNodeRef root_child0 = YGNodeNew();
YGNodeSetContext(root_child0, &constraintList);
YGNodeSetMeasureFunc(root_child0, _measure);
YGNodeInsertChild(root, root_child0, 0);
CSSNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
ASSERT_EQ(1, constraintList.length);
@@ -118,26 +118,26 @@ TEST(CSSLayoutTest, at_most_main_axis_column) {
ASSERT_EQ(YGMeasureModeAtMost, constraintList.constraints[0].heightMode);
free(constraintList.constraints);
CSSNodeFreeRecursive(root);
YGNodeFreeRecursive(root);
}
TEST(CSSLayoutTest, at_most_cross_axis_column) {
TEST(YogaTest, at_most_cross_axis_column) {
struct _MeasureConstraintList constraintList = _MeasureConstraintList {
.length = 0,
.constraints = (struct _MeasureConstraint *) malloc(10 * sizeof(struct _MeasureConstraint)),
};
const CSSNodeRef root = CSSNodeNew();
CSSNodeStyleSetAlignItems(root, YGAlignFlexStart);
CSSNodeStyleSetWidth(root, 100);
CSSNodeStyleSetHeight(root, 100);
const YGNodeRef root = YGNodeNew();
YGNodeStyleSetAlignItems(root, YGAlignFlexStart);
YGNodeStyleSetWidth(root, 100);
YGNodeStyleSetHeight(root, 100);
const CSSNodeRef root_child0 = CSSNodeNew();
CSSNodeSetContext(root_child0, &constraintList);
CSSNodeSetMeasureFunc(root_child0, _measure);
CSSNodeInsertChild(root, root_child0, 0);
const YGNodeRef root_child0 = YGNodeNew();
YGNodeSetContext(root_child0, &constraintList);
YGNodeSetMeasureFunc(root_child0, _measure);
YGNodeInsertChild(root, root_child0, 0);
CSSNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
ASSERT_EQ(1, constraintList.length);
@@ -145,26 +145,26 @@ TEST(CSSLayoutTest, at_most_cross_axis_column) {
ASSERT_EQ(YGMeasureModeAtMost, constraintList.constraints[0].widthMode);
free(constraintList.constraints);
CSSNodeFreeRecursive(root);
YGNodeFreeRecursive(root);
}
TEST(CSSLayoutTest, at_most_main_axis_row) {
TEST(YogaTest, at_most_main_axis_row) {
struct _MeasureConstraintList constraintList = _MeasureConstraintList {
.length = 0,
.constraints = (struct _MeasureConstraint *) malloc(10 * sizeof(struct _MeasureConstraint)),
};
const CSSNodeRef root = CSSNodeNew();
CSSNodeStyleSetFlexDirection(root, YGFlexDirectionRow);
CSSNodeStyleSetWidth(root, 100);
CSSNodeStyleSetHeight(root, 100);
const YGNodeRef root = YGNodeNew();
YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow);
YGNodeStyleSetWidth(root, 100);
YGNodeStyleSetHeight(root, 100);
const CSSNodeRef root_child0 = CSSNodeNew();
CSSNodeSetContext(root_child0, &constraintList);
CSSNodeSetMeasureFunc(root_child0, _measure);
CSSNodeInsertChild(root, root_child0, 0);
const YGNodeRef root_child0 = YGNodeNew();
YGNodeSetContext(root_child0, &constraintList);
YGNodeSetMeasureFunc(root_child0, _measure);
YGNodeInsertChild(root, root_child0, 0);
CSSNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
ASSERT_EQ(1, constraintList.length);
@@ -172,27 +172,27 @@ TEST(CSSLayoutTest, at_most_main_axis_row) {
ASSERT_EQ(YGMeasureModeAtMost, constraintList.constraints[0].widthMode);
free(constraintList.constraints);
CSSNodeFreeRecursive(root);
YGNodeFreeRecursive(root);
}
TEST(CSSLayoutTest, at_most_cross_axis_row) {
TEST(YogaTest, at_most_cross_axis_row) {
struct _MeasureConstraintList constraintList = _MeasureConstraintList {
.length = 0,
.constraints = (struct _MeasureConstraint *) malloc(10 * sizeof(struct _MeasureConstraint)),
};
const CSSNodeRef root = CSSNodeNew();
CSSNodeStyleSetFlexDirection(root, YGFlexDirectionRow);
CSSNodeStyleSetAlignItems(root, YGAlignFlexStart);
CSSNodeStyleSetWidth(root, 100);
CSSNodeStyleSetHeight(root, 100);
const YGNodeRef root = YGNodeNew();
YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow);
YGNodeStyleSetAlignItems(root, YGAlignFlexStart);
YGNodeStyleSetWidth(root, 100);
YGNodeStyleSetHeight(root, 100);
const CSSNodeRef root_child0 = CSSNodeNew();
CSSNodeSetContext(root_child0, &constraintList);
CSSNodeSetMeasureFunc(root_child0, _measure);
CSSNodeInsertChild(root, root_child0, 0);
const YGNodeRef root_child0 = YGNodeNew();
YGNodeSetContext(root_child0, &constraintList);
YGNodeSetMeasureFunc(root_child0, _measure);
YGNodeInsertChild(root, root_child0, 0);
CSSNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
ASSERT_EQ(1, constraintList.length);
@@ -200,25 +200,25 @@ TEST(CSSLayoutTest, at_most_cross_axis_row) {
ASSERT_EQ(YGMeasureModeAtMost, constraintList.constraints[0].heightMode);
free(constraintList.constraints);
CSSNodeFreeRecursive(root);
YGNodeFreeRecursive(root);
}
TEST(CSSLayoutTest, flex_child) {
TEST(YogaTest, flex_child) {
struct _MeasureConstraintList constraintList = _MeasureConstraintList {
.length = 0,
.constraints = (struct _MeasureConstraint *) malloc(10 * sizeof(struct _MeasureConstraint)),
};
const CSSNodeRef root = CSSNodeNew();
CSSNodeStyleSetHeight(root, 100);
const YGNodeRef root = YGNodeNew();
YGNodeStyleSetHeight(root, 100);
const CSSNodeRef root_child0 = CSSNodeNew();
CSSNodeStyleSetFlexGrow(root_child0, 1);
CSSNodeSetContext(root_child0, &constraintList);
CSSNodeSetMeasureFunc(root_child0, _measure);
CSSNodeInsertChild(root, root_child0, 0);
const YGNodeRef root_child0 = YGNodeNew();
YGNodeStyleSetFlexGrow(root_child0, 1);
YGNodeSetContext(root_child0, &constraintList);
YGNodeSetMeasureFunc(root_child0, _measure);
YGNodeInsertChild(root, root_child0, 0);
CSSNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
ASSERT_EQ(2, constraintList.length);
@@ -229,26 +229,26 @@ TEST(CSSLayoutTest, flex_child) {
ASSERT_EQ(YGMeasureModeExactly, constraintList.constraints[1].heightMode);
free(constraintList.constraints);
CSSNodeFreeRecursive(root);
YGNodeFreeRecursive(root);
}
TEST(CSSLayoutTest, flex_child_with_flex_basis) {
TEST(YogaTest, flex_child_with_flex_basis) {
struct _MeasureConstraintList constraintList = _MeasureConstraintList {
.length = 0,
.constraints = (struct _MeasureConstraint *) malloc(10 * sizeof(struct _MeasureConstraint)),
};
const CSSNodeRef root = CSSNodeNew();
CSSNodeStyleSetHeight(root, 100);
const YGNodeRef root = YGNodeNew();
YGNodeStyleSetHeight(root, 100);
const CSSNodeRef root_child0 = CSSNodeNew();
CSSNodeStyleSetFlexGrow(root_child0, 1);
CSSNodeStyleSetFlexBasis(root_child0, 0);
CSSNodeSetContext(root_child0, &constraintList);
CSSNodeSetMeasureFunc(root_child0, _measure);
CSSNodeInsertChild(root, root_child0, 0);
const YGNodeRef root_child0 = YGNodeNew();
YGNodeStyleSetFlexGrow(root_child0, 1);
YGNodeStyleSetFlexBasis(root_child0, 0);
YGNodeSetContext(root_child0, &constraintList);
YGNodeSetMeasureFunc(root_child0, _measure);
YGNodeInsertChild(root, root_child0, 0);
CSSNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
ASSERT_EQ(1, constraintList.length);
@@ -256,68 +256,68 @@ TEST(CSSLayoutTest, flex_child_with_flex_basis) {
ASSERT_EQ(YGMeasureModeExactly, constraintList.constraints[0].heightMode);
free(constraintList.constraints);
CSSNodeFreeRecursive(root);
YGNodeFreeRecursive(root);
}
TEST(CSSLayoutTest, overflow_scroll_column) {
TEST(YogaTest, overflow_scroll_column) {
struct _MeasureConstraintList constraintList = _MeasureConstraintList {
.length = 0,
.constraints = (struct _MeasureConstraint *) malloc(10 * sizeof(struct _MeasureConstraint)),
};
const CSSNodeRef root = CSSNodeNew();
CSSNodeStyleSetAlignItems(root, YGAlignFlexStart);
CSSNodeStyleSetOverflow(root, YGOverflowScroll);
CSSNodeStyleSetHeight(root, 100);
CSSNodeStyleSetWidth(root, 100);
const YGNodeRef root = YGNodeNew();
YGNodeStyleSetAlignItems(root, YGAlignFlexStart);
YGNodeStyleSetOverflow(root, YGOverflowScroll);
YGNodeStyleSetHeight(root, 100);
YGNodeStyleSetWidth(root, 100);
const CSSNodeRef root_child0 = CSSNodeNew();
CSSNodeSetContext(root_child0, &constraintList);
CSSNodeSetMeasureFunc(root_child0, _measure);
CSSNodeInsertChild(root, root_child0, 0);
const YGNodeRef root_child0 = YGNodeNew();
YGNodeSetContext(root_child0, &constraintList);
YGNodeSetMeasureFunc(root_child0, _measure);
YGNodeInsertChild(root, root_child0, 0);
CSSNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
ASSERT_EQ(1, constraintList.length);
ASSERT_FLOAT_EQ(100, constraintList.constraints[0].width);
ASSERT_EQ(YGMeasureModeAtMost, constraintList.constraints[0].widthMode);
ASSERT_TRUE(CSSValueIsUndefined(constraintList.constraints[0].height));
ASSERT_TRUE(YGValueIsUndefined(constraintList.constraints[0].height));
ASSERT_EQ(YGMeasureModeUndefined, constraintList.constraints[0].heightMode);
free(constraintList.constraints);
CSSNodeFreeRecursive(root);
YGNodeFreeRecursive(root);
}
TEST(CSSLayoutTest, overflow_scroll_row) {
TEST(YogaTest, overflow_scroll_row) {
struct _MeasureConstraintList constraintList = _MeasureConstraintList {
.length = 0,
.constraints = (struct _MeasureConstraint *) malloc(10 * sizeof(struct _MeasureConstraint)),
};
const CSSNodeRef root = CSSNodeNew();
CSSNodeStyleSetAlignItems(root, YGAlignFlexStart);
CSSNodeStyleSetFlexDirection(root, YGFlexDirectionRow);
CSSNodeStyleSetOverflow(root, YGOverflowScroll);
CSSNodeStyleSetHeight(root, 100);
CSSNodeStyleSetWidth(root, 100);
const YGNodeRef root = YGNodeNew();
YGNodeStyleSetAlignItems(root, YGAlignFlexStart);
YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow);
YGNodeStyleSetOverflow(root, YGOverflowScroll);
YGNodeStyleSetHeight(root, 100);
YGNodeStyleSetWidth(root, 100);
const CSSNodeRef root_child0 = CSSNodeNew();
CSSNodeSetContext(root_child0, &constraintList);
CSSNodeSetMeasureFunc(root_child0, _measure);
CSSNodeInsertChild(root, root_child0, 0);
const YGNodeRef root_child0 = YGNodeNew();
YGNodeSetContext(root_child0, &constraintList);
YGNodeSetMeasureFunc(root_child0, _measure);
YGNodeInsertChild(root, root_child0, 0);
CSSNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
ASSERT_EQ(1, constraintList.length);
ASSERT_TRUE(CSSValueIsUndefined(constraintList.constraints[0].width));
ASSERT_TRUE(YGValueIsUndefined(constraintList.constraints[0].width));
ASSERT_EQ(YGMeasureModeUndefined, constraintList.constraints[0].widthMode);
ASSERT_FLOAT_EQ(100, constraintList.constraints[0].height);
ASSERT_EQ(YGMeasureModeAtMost, constraintList.constraints[0].heightMode);
free(constraintList.constraints);
CSSNodeFreeRecursive(root);
YGNodeFreeRecursive(root);
}