[yoga] Replace float with double

This commit is contained in:
Lvv.me
2021-07-05 10:57:32 +08:00
parent 578d197dd6
commit 860bb8b660
36 changed files with 694 additions and 686 deletions

View File

@@ -13,14 +13,14 @@
using facebook::yoga::detail::CompactValue;
const auto tooSmall = nextafterf(CompactValue::LOWER_BOUND, -INFINITY);
const auto tooSmall = nextafter(CompactValue::LOWER_BOUND, -INFINITY);
const auto tooLargePoints =
nextafterf(CompactValue::UPPER_BOUND_POINT, INFINITY);
nextafter(CompactValue::UPPER_BOUND_POINT, INFINITY);
const auto tooLargePercent =
nextafterf(CompactValue::UPPER_BOUND_PERCENT, INFINITY);
nextafter(CompactValue::UPPER_BOUND_PERCENT, INFINITY);
TEST(YogaTest, compact_value_can_represent_undefined) {
auto c = CompactValue{YGValue{12.5f, YGUnitUndefined}};
auto c = CompactValue{YGValue{12.5, YGUnitUndefined}};
YGValue v = c;
ASSERT_EQ(v, YGValueUndefined);
ASSERT_NE(v, YGValueAuto);
@@ -32,7 +32,7 @@ TEST(YogaTest, compact_value_can_represent_undefined) {
TEST(YogaTest, compact_value_manages_infinity_as_undefined) {
auto c = CompactValue{
YGValue{std::numeric_limits<float>::infinity(), YGUnitUndefined}};
YGValue{std::numeric_limits<double>::infinity(), YGUnitUndefined}};
YGValue v = c;
ASSERT_EQ(v, YGValueUndefined);
ASSERT_NE(v, YGValueAuto);
@@ -299,23 +299,23 @@ TEST(YogaTest, dedicated_unit_factories) {
ASSERT_EQ(CompactValue::ofUndefined(), CompactValue(YGValueUndefined));
ASSERT_EQ(CompactValue::ofAuto(), CompactValue(YGValueAuto));
ASSERT_EQ(
CompactValue::of<YGUnitPoint>(-9876.5f),
CompactValue(YGValue{-9876.5f, YGUnitPoint}));
CompactValue::of<YGUnitPoint>(-9876.5),
CompactValue(YGValue{-9876.5, YGUnitPoint}));
ASSERT_EQ(
CompactValue::of<YGUnitPercent>(123.456f),
CompactValue(YGValue{123.456f, YGUnitPercent}));
CompactValue::of<YGUnitPercent>(123.456),
CompactValue(YGValue{123.456, YGUnitPercent}));
}
TEST(YogaTest, dedicated_unit_maybe_factories) {
ASSERT_EQ(
CompactValue::ofMaybe<YGUnitPoint>(-9876.5f),
CompactValue(YGValue{-9876.5f, YGUnitPoint}));
CompactValue::ofMaybe<YGUnitPoint>(-9876.5),
CompactValue(YGValue{-9876.5, YGUnitPoint}));
ASSERT_EQ(
CompactValue::ofMaybe<YGUnitPoint>(YGUndefined),
CompactValue(YGValueUndefined));
ASSERT_EQ(
CompactValue::ofMaybe<YGUnitPercent>(123.456f),
CompactValue(YGValue{123.456f, YGUnitPercent}));
CompactValue::ofMaybe<YGUnitPercent>(123.456),
CompactValue(YGValue{123.456, YGUnitPercent}));
ASSERT_EQ(
CompactValue::ofMaybe<YGUnitPercent>(YGUndefined),
CompactValue(YGValueUndefined));
@@ -324,7 +324,7 @@ TEST(YogaTest, dedicated_unit_maybe_factories) {
TEST(YogaTest, can_be_assigned_from_YGValue) {
CompactValue c{};
YGValue v{2.0f, YGUnitPercent};
YGValue v{2.0, YGUnitPercent};
c = v;
ASSERT_EQ((YGValue) c, v);
@@ -335,28 +335,28 @@ TEST(YogaTest, can_be_assigned_from_YGValue) {
TEST(YogaTest, compact_value_bound_representations) {
ASSERT_EQ(
CompactValue::of<YGUnitPoint>(CompactValue::LOWER_BOUND).repr(),
uint32_t{0});
uint64_t{0});
ASSERT_EQ(
CompactValue::of<YGUnitPoint>(CompactValue::UPPER_BOUND_POINT).repr(),
uint32_t{0x3fffffff});
uint64_t{0x3fffffffffffffff});
ASSERT_EQ(
CompactValue::of<YGUnitPercent>(CompactValue::LOWER_BOUND).repr(),
uint32_t{0x40000000});
uint64_t{0x4000000000000000});
ASSERT_EQ(
CompactValue::of<YGUnitPercent>(CompactValue::UPPER_BOUND_PERCENT).repr(),
uint32_t{0x7f7fffff});
uint64_t{0x7f7fffffffffffff});
ASSERT_EQ(
CompactValue::of<YGUnitPoint>(-CompactValue::LOWER_BOUND).repr(),
uint32_t{0x80000000});
uint64_t{0x8000000000000000});
ASSERT_EQ(
CompactValue::of<YGUnitPoint>(-CompactValue::UPPER_BOUND_POINT).repr(),
uint32_t{0xbfffffff});
uint64_t{0xbfffffffffffffff});
ASSERT_EQ(
CompactValue::of<YGUnitPercent>(-CompactValue::LOWER_BOUND).repr(),
uint32_t{0xc0000000});
uint64_t{0xc000000000000000});
ASSERT_EQ(
CompactValue::of<YGUnitPercent>(-CompactValue::UPPER_BOUND_PERCENT)
.repr(),
uint32_t{0xff7fffff});
uint64_t{0xff7fffffffffffff});
}

View File

@@ -231,7 +231,7 @@ TEST_F(EventTest, layout_events_has_max_measure_cache) {
YGNodeInsertChild(root, a, 0);
auto b = YGNodeNew();
YGNodeInsertChild(root, b, 1);
YGNodeStyleSetFlexBasis(a, 10.0f);
YGNodeStyleSetFlexBasis(a, 10.0);
for (auto s : {20, 30, 40}) {
YGNodeCalculateLayout(root, s, s, YGDirectionLTR);
@@ -251,7 +251,7 @@ TEST_F(EventTest, layout_events_has_max_measure_cache) {
TEST_F(EventTest, measure_functions_get_wrapped) {
auto root = YGNodeNew();
YGNodeSetMeasureFunc(
root, [](YGNodeRef, float, YGMeasureMode, float, YGMeasureMode) {
root, [](YGNodeRef, double, YGMeasureMode, double, YGMeasureMode) {
return YGSize{};
});
@@ -269,7 +269,7 @@ TEST_F(EventTest, baseline_functions_get_wrapped) {
auto child = YGNodeNew();
YGNodeInsertChild(root, child, 0);
YGNodeSetBaselineFunc(child, [](YGNodeRef, float, float) { return 0.0f; });
YGNodeSetBaselineFunc(child, [](YGNodeRef, double, double) { return 0.0; });
YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow);
YGNodeStyleSetAlignItems(root, YGAlignBaseline);

View File

@@ -9,18 +9,18 @@
#include <yoga/YGNode.h>
#include <yoga/Yoga.h>
static float _baselineFunc(
static double _baselineFunc(
YGNodeRef node,
const float width,
const float height) {
const double width,
const double height) {
return height / 2;
}
static YGSize _measure1(
YGNodeRef node,
float width,
double width,
YGMeasureMode widthMode,
float height,
double height,
YGMeasureMode heightMode) {
return YGSize{
.width = 42,
@@ -30,9 +30,9 @@ static YGSize _measure1(
static YGSize _measure2(
YGNodeRef node,
float width,
double width,
YGMeasureMode widthMode,
float height,
double height,
YGMeasureMode heightMode) {
return YGSize{
.width = 279,

View File

@@ -11,9 +11,9 @@
static YGSize _measure(
YGNodeRef node,
float width,
double width,
YGMeasureMode widthMode,
float height,
double height,
YGMeasureMode heightMode) {
return YGSize{
.width = widthMode == YGMeasureModeExactly ? width : 50,

View File

@@ -9,8 +9,8 @@
#include <yoga/YGNode.h>
#include <yoga/Yoga.h>
static float _baseline(YGNodeRef node, const float width, const float height) {
float* baseline = (float*) node->getContext();
static double _baseline(YGNodeRef node, const double width, const double height) {
double* baseline = (double*) node->getContext();
return *baseline;
}
@@ -31,7 +31,7 @@ TEST(YogaTest, align_baseline_customer_func) {
YGNodeStyleSetHeight(root_child1, 20);
YGNodeInsertChild(root, root_child1, 1);
float baselineValue = 10;
double baselineValue = 10;
const YGNodeRef root_child1_child0 = YGNodeNew();
root_child1_child0->setContext(&baselineValue);
YGNodeStyleSetWidth(root_child1_child0, 50);

View File

@@ -37,7 +37,7 @@ TEST(YogaTest, margin_side_overrides_horizontal_and_vertical) {
YGEdgeLeft,
YGEdgeRight}};
for (float edgeValue = 0; edgeValue < 2; ++edgeValue) {
for (double edgeValue = 0; edgeValue < 2; ++edgeValue) {
for (const auto& edge : edges) {
YGEdge horizontalOrVertical = edge == YGEdgeTop || edge == YGEdgeBottom
? YGEdgeVertical
@@ -67,7 +67,7 @@ TEST(YogaTest, margin_side_overrides_all) {
YGEdgeLeft,
YGEdgeRight}};
for (float edgeValue = 0; edgeValue < 2; ++edgeValue) {
for (double edgeValue = 0; edgeValue < 2; ++edgeValue) {
for (const auto& edge : edges) {
const YGNodeRef root = YGNodeNew();
YGNodeStyleSetWidth(root, 100);
@@ -87,7 +87,7 @@ TEST(YogaTest, margin_side_overrides_all) {
TEST(YogaTest, margin_horizontal_and_vertical_overrides_all) {
const std::array<YGEdge, 2> directions = {{YGEdgeHorizontal, YGEdgeVertical}};
for (float directionValue = 0; directionValue < 2; ++directionValue) {
for (double directionValue = 0; directionValue < 2; ++directionValue) {
for (const auto& direction : directions) {
const YGNodeRef root = YGNodeNew();
YGNodeStyleSetWidth(root, 100);

View File

@@ -37,7 +37,7 @@ TEST(YogaTest, padding_side_overrides_horizontal_and_vertical) {
YGEdgeLeft,
YGEdgeRight}};
for (float edgeValue = 0; edgeValue < 2; ++edgeValue) {
for (double edgeValue = 0; edgeValue < 2; ++edgeValue) {
for (const auto& edge : edges) {
YGEdge horizontalOrVertical = edge == YGEdgeTop || edge == YGEdgeBottom
? YGEdgeVertical
@@ -67,7 +67,7 @@ TEST(YogaTest, padding_side_overrides_all) {
YGEdgeLeft,
YGEdgeRight}};
for (float edgeValue = 0; edgeValue < 2; ++edgeValue) {
for (double edgeValue = 0; edgeValue < 2; ++edgeValue) {
for (const auto& edge : edges) {
const YGNodeRef root = YGNodeNew();
YGNodeStyleSetWidth(root, 100);
@@ -87,7 +87,7 @@ TEST(YogaTest, padding_side_overrides_all) {
TEST(YogaTest, padding_horizontal_and_vertical_overrides_all) {
const std::array<YGEdge, 2> directions = {{YGEdgeHorizontal, YGEdgeVertical}};
for (float directionValue = 0; directionValue < 2; ++directionValue) {
for (double directionValue = 0; directionValue < 2; ++directionValue) {
for (const auto& direction : directions) {
const YGNodeRef root = YGNodeNew();
YGNodeStyleSetWidth(root, 100);

View File

@@ -96,7 +96,7 @@ TEST(YogaTest, assert_webdefault_values) {
ASSERT_EQ(YGFlexDirectionRow, YGNodeStyleGetFlexDirection(root));
ASSERT_EQ(YGAlignStretch, YGNodeStyleGetAlignContent(root));
ASSERT_FLOAT_EQ(1.0f, YGNodeStyleGetFlexShrink(root));
ASSERT_FLOAT_EQ(1.0, YGNodeStyleGetFlexShrink(root));
YGNodeFreeRecursive(root);
YGConfigFree(config);
@@ -110,7 +110,7 @@ TEST(YogaTest, assert_webdefault_values_reset) {
ASSERT_EQ(YGFlexDirectionRow, YGNodeStyleGetFlexDirection(root));
ASSERT_EQ(YGAlignStretch, YGNodeStyleGetAlignContent(root));
ASSERT_FLOAT_EQ(1.0f, YGNodeStyleGetFlexShrink(root));
ASSERT_FLOAT_EQ(1.0, YGNodeStyleGetFlexShrink(root));
YGNodeFreeRecursive(root);
YGConfigFree(config);

View File

@@ -546,16 +546,16 @@ TEST(YogaTest, flex_grow_less_than_factor_one) {
YGNodeStyleSetHeight(root, 500);
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
YGNodeStyleSetFlexGrow(root_child0, 0.2f);
YGNodeStyleSetFlexGrow(root_child0, 0.2);
YGNodeStyleSetFlexBasis(root_child0, 40);
YGNodeInsertChild(root, root_child0, 0);
const YGNodeRef root_child1 = YGNodeNewWithConfig(config);
YGNodeStyleSetFlexGrow(root_child1, 0.2f);
YGNodeStyleSetFlexGrow(root_child1, 0.2);
YGNodeInsertChild(root, root_child1, 1);
const YGNodeRef root_child2 = YGNodeNewWithConfig(config);
YGNodeStyleSetFlexGrow(root_child2, 0.4f);
YGNodeStyleSetFlexGrow(root_child2, 0.4);
YGNodeInsertChild(root, root_child2, 2);
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);

View File

@@ -12,17 +12,17 @@
#include <yoga/YGValue.h>
constexpr auto empty = YGFloatOptional{};
constexpr auto zero = YGFloatOptional{0.0f};
constexpr auto one = YGFloatOptional{1.0f};
constexpr auto positive = YGFloatOptional{1234.5f};
constexpr auto negative = YGFloatOptional{-9876.5f};
constexpr auto zero = YGFloatOptional{0.0};
constexpr auto one = YGFloatOptional{1.0};
constexpr auto positive = YGFloatOptional{1234.5};
constexpr auto negative = YGFloatOptional{-9876.5};
TEST(YGFloatOptional, value) {
ASSERT_TRUE(YGFloatIsUndefined(empty.unwrap()));
ASSERT_EQ(zero.unwrap(), 0.0f);
ASSERT_EQ(one.unwrap(), 1.0f);
ASSERT_EQ(positive.unwrap(), 1234.5f);
ASSERT_EQ(negative.unwrap(), -9876.5f);
ASSERT_EQ(zero.unwrap(), 0.0);
ASSERT_EQ(one.unwrap(), 1.0);
ASSERT_EQ(positive.unwrap(), 1234.5);
ASSERT_EQ(negative.unwrap(), -9876.5);
ASSERT_TRUE(empty.isUndefined());
ASSERT_FALSE(zero.isUndefined());
@@ -36,15 +36,15 @@ TEST(YGFloatOptional, equality) {
ASSERT_TRUE(empty == YGUndefined);
ASSERT_FALSE(empty == zero);
ASSERT_FALSE(empty == negative);
ASSERT_FALSE(empty == 12.3f);
ASSERT_FALSE(empty == 12.3);
ASSERT_TRUE(zero == zero);
ASSERT_TRUE(zero == 0.0f);
ASSERT_TRUE(zero == 0.0);
ASSERT_FALSE(zero == positive);
ASSERT_FALSE(zero == -5555.5f);
ASSERT_FALSE(zero == -5555.5);
ASSERT_TRUE(one == one);
ASSERT_TRUE(one == 1.0f);
ASSERT_TRUE(one == 1.0);
ASSERT_FALSE(one == positive);
ASSERT_TRUE(positive == positive);
@@ -61,15 +61,15 @@ TEST(YGFloatOptional, inequality) {
ASSERT_FALSE(empty != YGUndefined);
ASSERT_TRUE(empty != zero);
ASSERT_TRUE(empty != negative);
ASSERT_TRUE(empty != 12.3f);
ASSERT_TRUE(empty != 12.3);
ASSERT_FALSE(zero != zero);
ASSERT_FALSE(zero != 0.0f);
ASSERT_FALSE(zero != 0.0);
ASSERT_TRUE(zero != positive);
ASSERT_TRUE(zero != -5555.5f);
ASSERT_TRUE(zero != -5555.5);
ASSERT_FALSE(one != one);
ASSERT_FALSE(one != 1.0f);
ASSERT_FALSE(one != 1.0);
ASSERT_TRUE(one != positive);
ASSERT_FALSE(positive != positive);
@@ -198,12 +198,12 @@ TEST(YGFloatOptionalTest, YGFloatOptionalMax) {
ASSERT_EQ(YGFloatOptionalMax(negative, empty), negative);
ASSERT_EQ(YGFloatOptionalMax(negative, YGFloatOptional{-INFINITY}), negative);
ASSERT_EQ(
YGFloatOptionalMax(YGFloatOptional{1.0f}, YGFloatOptional{1.125f}),
YGFloatOptional{1.125f});
YGFloatOptionalMax(YGFloatOptional{1.0}, YGFloatOptional{1.125}),
YGFloatOptional{1.125});
}
TEST(YGFloatOptionalTest, unwrap) {
ASSERT_TRUE(YGFloatIsUndefined(empty.unwrap()));
ASSERT_EQ(zero.unwrap(), 0.0f);
ASSERT_EQ(YGFloatOptional{123456.78f}.unwrap(), 123456.78f);
ASSERT_EQ(zero.unwrap(), 0.0);
ASSERT_EQ(YGFloatOptional{123456.78}.unwrap(), 123456.78);
}

View File

@@ -11,9 +11,9 @@
static YGSize _measureMax(
YGNodeRef node,
float width,
double width,
YGMeasureMode widthMode,
float height,
double height,
YGMeasureMode heightMode) {
int* measureCount = (int*) node->getContext();
(*measureCount)++;
@@ -26,9 +26,9 @@ static YGSize _measureMax(
static YGSize _measureMin(
YGNodeRef node,
float width,
double width,
YGMeasureMode widthMode,
float height,
double height,
YGMeasureMode heightMode) {
int* measureCount = (int*) node->getContext();
*measureCount = *measureCount + 1;
@@ -46,9 +46,9 @@ static YGSize _measureMin(
static YGSize _measure_84_49(
YGNodeRef node,
float width,
double width,
YGMeasureMode widthMode,
float height,
double height,
YGMeasureMode heightMode) {
int* measureCount = (int*) node->getContext();
if (measureCount) {
@@ -56,8 +56,8 @@ static YGSize _measure_84_49(
}
return YGSize{
.width = 84.f,
.height = 49.f,
.width = 84,
.height = 49,
};
}
@@ -160,12 +160,12 @@ TEST(
int measureCount = 0;
const YGNodeRef root = YGNodeNew();
YGNodeStyleSetWidth(root, 288.f);
YGNodeStyleSetHeight(root, 288.f);
YGNodeStyleSetWidth(root, 288);
YGNodeStyleSetHeight(root, 288);
YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow);
const YGNodeRef root_child0 = YGNodeNew();
YGNodeStyleSetPadding(root_child0, YGEdgeAll, 2.88f);
YGNodeStyleSetPadding(root_child0, YGEdgeAll, 2.88);
YGNodeStyleSetFlexDirection(root_child0, YGFlexDirectionRow);
YGNodeInsertChild(root, root_child0, 0);

View File

@@ -10,9 +10,9 @@
#include <yoga/Yoga.h>
struct _MeasureConstraint {
float width;
double width;
YGMeasureMode widthMode;
float height;
double height;
YGMeasureMode heightMode;
};
@@ -23,9 +23,9 @@ struct _MeasureConstraintList {
static YGSize _measure(
YGNodeRef node,
float width,
double width,
YGMeasureMode widthMode,
float height,
double height,
YGMeasureMode heightMode) {
struct _MeasureConstraintList* constraintList =
(struct _MeasureConstraintList*) node->getContext();

View File

@@ -11,9 +11,9 @@
static YGSize _measure(
YGNodeRef node,
float width,
double width,
YGMeasureMode widthMode,
float height,
double height,
YGMeasureMode heightMode) {
int* measureCount = (int*) node->getContext();
if (measureCount) {
@@ -28,9 +28,9 @@ static YGSize _measure(
static YGSize _simulate_wrapping_text(
YGNodeRef node,
float width,
double width,
YGMeasureMode widthMode,
float height,
double height,
YGMeasureMode heightMode) {
if (widthMode == YGMeasureModeUndefined || width >= 68) {
return YGSize{.width = 68, .height = 16};
@@ -44,9 +44,9 @@ static YGSize _simulate_wrapping_text(
static YGSize _measure_assert_negative(
YGNodeRef node,
float width,
double width,
YGMeasureMode widthMode,
float height,
double height,
YGMeasureMode heightMode) {
EXPECT_GE(width, 0);
EXPECT_GE(height, 0);
@@ -643,9 +643,9 @@ TEST(YogaTest, cant_call_negative_measure_horizontal) {
static YGSize _measure_90_10(
YGNodeRef node,
float width,
double width,
YGMeasureMode widthMode,
float height,
double height,
YGMeasureMode heightMode) {
return YGSize{
@@ -656,9 +656,9 @@ static YGSize _measure_90_10(
static YGSize _measure_100_100(
YGNodeRef node,
float width,
double width,
YGMeasureMode widthMode,
float height,
double height,
YGMeasureMode heightMode) {
return YGSize{

View File

@@ -1298,9 +1298,9 @@ TEST(YogaTest, min_max_percent_no_width_height) {
static YGSize _measureCk_test_label_shrink_based_on_height(
YGNodeRef node,
float width,
double width,
YGMeasureMode widthMode,
float height,
double height,
YGMeasureMode heightMode) {
if (heightMode == YGMeasureModeAtMost) {

View File

@@ -22,7 +22,7 @@ TEST(YGNode, hasMeasureFunc_initial) {
TEST(YGNode, hasMeasureFunc_with_measure_fn) {
auto n = YGNode{};
n.setMeasureFunc([](YGNode*, float, YGMeasureMode, float, YGMeasureMode) {
n.setMeasureFunc([](YGNode*, double, YGMeasureMode, double, YGMeasureMode) {
return YGSize{};
});
ASSERT_TRUE(n.hasMeasureFunc());
@@ -32,7 +32,7 @@ TEST(YGNode, measure_with_measure_fn) {
auto n = YGNode{};
n.setMeasureFunc(
[](YGNode*, float w, YGMeasureMode wm, float h, YGMeasureMode hm) {
[](YGNode*, double w, YGMeasureMode wm, double h, YGMeasureMode hm) {
return YGSize{w * wm, h / hm};
});
@@ -44,7 +44,7 @@ TEST(YGNode, measure_with_measure_fn) {
TEST(YGNode, measure_with_context_measure_fn) {
auto n = YGNode{};
n.setMeasureFunc(
[](YGNode*, float, YGMeasureMode, float, YGMeasureMode, void* ctx) {
[](YGNode*, double, YGMeasureMode, double, YGMeasureMode, void* ctx) {
return *(YGSize*) ctx;
});
@@ -57,11 +57,11 @@ TEST(YGNode, measure_with_context_measure_fn) {
TEST(YGNode, switching_measure_fn_types) {
auto n = YGNode{};
n.setMeasureFunc(
[](YGNode*, float, YGMeasureMode, float, YGMeasureMode, void*) {
[](YGNode*, double, YGMeasureMode, double, YGMeasureMode, void*) {
return YGSize{};
});
n.setMeasureFunc(
[](YGNode*, float w, YGMeasureMode wm, float h, YGMeasureMode hm) {
[](YGNode*, double w, YGMeasureMode wm, double h, YGMeasureMode hm) {
return YGSize{w * wm, h / hm};
});
@@ -72,7 +72,7 @@ TEST(YGNode, switching_measure_fn_types) {
TEST(YGNode, hasMeasureFunc_after_unset) {
auto n = YGNode{};
n.setMeasureFunc([](YGNode*, float, YGMeasureMode, float, YGMeasureMode) {
n.setMeasureFunc([](YGNode*, double, YGMeasureMode, double, YGMeasureMode) {
return YGSize{};
});
@@ -83,7 +83,7 @@ TEST(YGNode, hasMeasureFunc_after_unset) {
TEST(YGNode, hasMeasureFunc_after_unset_context) {
auto n = YGNode{};
n.setMeasureFunc(
[](YGNode*, float, YGMeasureMode, float, YGMeasureMode, void*) {
[](YGNode*, double, YGMeasureMode, double, YGMeasureMode, void*) {
return YGSize{};
});
@@ -98,30 +98,30 @@ TEST(YGNode, hasBaselineFunc_initial) {
TEST(YGNode, hasBaselineFunc_with_baseline_fn) {
auto n = YGNode{};
n.setBaselineFunc([](YGNode*, float, float) { return 0.0f; });
n.setBaselineFunc([](YGNode*, double, double) { return 0.0; });
ASSERT_TRUE(n.hasBaselineFunc());
}
TEST(YGNode, baseline_with_baseline_fn) {
auto n = YGNode{};
n.setBaselineFunc([](YGNode*, float w, float h) { return w + h; });
n.setBaselineFunc([](YGNode*, double w, double h) { return w + h; });
ASSERT_EQ(n.baseline(1.25f, 2.5f, nullptr), 3.75f);
ASSERT_EQ(n.baseline(1.25, 2.5, nullptr), 3.75);
}
TEST(YGNode, baseline_with_context_baseline_fn) {
auto n = YGNode{};
n.setBaselineFunc([](YGNode*, float w, float h, void* ctx) {
return w + h + *(float*) ctx;
n.setBaselineFunc([](YGNode*, double w, double h, void* ctx) {
return w + h + *(double*) ctx;
});
auto ctx = -10.0f;
ASSERT_EQ(n.baseline(1.25f, 2.5f, &ctx), -6.25f);
auto ctx = -10.0;
ASSERT_EQ(n.baseline(1.25, 2.5, &ctx), -6.25);
}
TEST(YGNode, hasBaselineFunc_after_unset) {
auto n = YGNode{};
n.setBaselineFunc([](YGNode*, float, float) { return 0.0f; });
n.setBaselineFunc([](YGNode*, double, double) { return 0.0; });
n.setBaselineFunc(nullptr);
ASSERT_FALSE(n.hasBaselineFunc());
@@ -129,7 +129,7 @@ TEST(YGNode, hasBaselineFunc_after_unset) {
TEST(YGNode, hasBaselineFunc_after_unset_context) {
auto n = YGNode{};
n.setBaselineFunc([](YGNode*, float, float, void*) { return 0.0f; });
n.setBaselineFunc([](YGNode*, double, double, void*) { return 0.0; });
n.setMeasureFunc(nullptr);
ASSERT_FALSE(n.hasMeasureFunc());
@@ -137,9 +137,9 @@ TEST(YGNode, hasBaselineFunc_after_unset_context) {
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; });
ASSERT_EQ(n.baseline(1, 2, nullptr), 1.0f);
n.setBaselineFunc([](YGNode*, double, double, void*) { return 0.0; });
n.setBaselineFunc([](YGNode*, double, double) { return 1.0; });
ASSERT_EQ(n.baseline(1, 2, nullptr), 1.0);
}
void PrintTo(const YGSize& size, std::ostream* os) {

View File

@@ -1196,9 +1196,9 @@ TEST(YogaTest, percent_absolute_position) {
static YGSize _measureCk_test_label_shrink_based_on_height(
YGNodeRef node,
float width,
double width,
YGMeasureMode widthMode,
float height,
double height,
YGMeasureMode heightMode) {
if (heightMode == YGMeasureModeAtMost) {

View File

@@ -44,9 +44,9 @@ TEST(YogaTest, rounding_value) {
static YGSize measureText(
YGNodeRef node,
float width,
double width,
YGMeasureMode widthMode,
float height,
double height,
YGMeasureMode heightMode) {
return (YGSize){.width = 10, .height = 10};
}

View File

@@ -11,37 +11,37 @@
static YGSize _measureFloor(
YGNodeRef node,
float width,
double width,
YGMeasureMode widthMode,
float height,
double height,
YGMeasureMode heightMode) {
return YGSize{
width = 10.2f,
height = 10.2f,
width = 10.2,
height = 10.2,
};
}
static YGSize _measureCeil(
YGNodeRef node,
float width,
double width,
YGMeasureMode widthMode,
float height,
double height,
YGMeasureMode heightMode) {
return YGSize{
width = 10.5f,
height = 10.5f,
width = 10.5,
height = 10.5,
};
}
static YGSize _measureFractial(
YGNodeRef node,
float width,
double width,
YGMeasureMode widthMode,
float height,
double height,
YGMeasureMode heightMode) {
return YGSize{
width = 0.5f,
height = 0.5f,
width = 0.5,
height = 0.5,
};
}
@@ -53,35 +53,35 @@ TEST(YogaTest, rounding_feature_with_custom_measure_func_floor) {
root_child0->setMeasureFunc(_measureFloor);
YGNodeInsertChild(root, root_child0, 0);
YGConfigSetPointScaleFactor(config, 0.0f);
YGConfigSetPointScaleFactor(config, 0.0);
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
ASSERT_FLOAT_EQ(10.2, YGNodeLayoutGetWidth(root_child0));
ASSERT_FLOAT_EQ(10.2, YGNodeLayoutGetHeight(root_child0));
YGConfigSetPointScaleFactor(config, 1.0f);
YGConfigSetPointScaleFactor(config, 1.0);
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
ASSERT_FLOAT_EQ(11, YGNodeLayoutGetWidth(root_child0));
ASSERT_FLOAT_EQ(11, YGNodeLayoutGetHeight(root_child0));
YGConfigSetPointScaleFactor(config, 2.0f);
YGConfigSetPointScaleFactor(config, 2.0);
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
ASSERT_FLOAT_EQ(10.5, YGNodeLayoutGetWidth(root_child0));
ASSERT_FLOAT_EQ(10.5, YGNodeLayoutGetHeight(root_child0));
YGConfigSetPointScaleFactor(config, 4.0f);
YGConfigSetPointScaleFactor(config, 4.0);
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
ASSERT_FLOAT_EQ(10.25, YGNodeLayoutGetWidth(root_child0));
ASSERT_FLOAT_EQ(10.25, YGNodeLayoutGetHeight(root_child0));
YGConfigSetPointScaleFactor(config, 1.0f / 3.0f);
YGConfigSetPointScaleFactor(config, 1.0 / 3.0);
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
@@ -101,7 +101,7 @@ TEST(YogaTest, rounding_feature_with_custom_measure_func_ceil) {
root_child0->setMeasureFunc(_measureCeil);
YGNodeInsertChild(root, root_child0, 0);
YGConfigSetPointScaleFactor(config, 1.0f);
YGConfigSetPointScaleFactor(config, 1.0);
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
@@ -124,7 +124,7 @@ TEST(
root_child0->setMeasureFunc(_measureFractial);
YGNodeInsertChild(root, root_child0, 0);
YGConfigSetPointScaleFactor(config, 2.0f);
YGConfigSetPointScaleFactor(config, 2.0);
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);

View File

@@ -317,23 +317,23 @@ TEST(YogaTest, rounding_total_fractial) {
const YGConfigRef config = YGConfigNew();
const YGNodeRef root = YGNodeNewWithConfig(config);
YGNodeStyleSetWidth(root, 87.4f);
YGNodeStyleSetHeight(root, 113.4f);
YGNodeStyleSetWidth(root, 87.4);
YGNodeStyleSetHeight(root, 113.4);
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
YGNodeStyleSetFlexGrow(root_child0, 0.7f);
YGNodeStyleSetFlexBasis(root_child0, 50.3f);
YGNodeStyleSetHeight(root_child0, 20.3f);
YGNodeStyleSetFlexGrow(root_child0, 0.7);
YGNodeStyleSetFlexBasis(root_child0, 50.3);
YGNodeStyleSetHeight(root_child0, 20.3);
YGNodeInsertChild(root, root_child0, 0);
const YGNodeRef root_child1 = YGNodeNewWithConfig(config);
YGNodeStyleSetFlexGrow(root_child1, 1.6f);
YGNodeStyleSetFlexGrow(root_child1, 1.6);
YGNodeStyleSetHeight(root_child1, 10);
YGNodeInsertChild(root, root_child1, 1);
const YGNodeRef root_child2 = YGNodeNewWithConfig(config);
YGNodeStyleSetFlexGrow(root_child2, 1.1f);
YGNodeStyleSetHeight(root_child2, 10.7f);
YGNodeStyleSetFlexGrow(root_child2, 1.1);
YGNodeStyleSetHeight(root_child2, 10.7);
YGNodeInsertChild(root, root_child2, 2);
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
@@ -388,37 +388,37 @@ TEST(YogaTest, rounding_total_fractial_nested) {
const YGConfigRef config = YGConfigNew();
const YGNodeRef root = YGNodeNewWithConfig(config);
YGNodeStyleSetWidth(root, 87.4f);
YGNodeStyleSetHeight(root, 113.4f);
YGNodeStyleSetWidth(root, 87.4);
YGNodeStyleSetHeight(root, 113.4);
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
YGNodeStyleSetFlexGrow(root_child0, 0.7f);
YGNodeStyleSetFlexBasis(root_child0, 50.3f);
YGNodeStyleSetHeight(root_child0, 20.3f);
YGNodeStyleSetFlexGrow(root_child0, 0.7);
YGNodeStyleSetFlexBasis(root_child0, 50.3);
YGNodeStyleSetHeight(root_child0, 20.3);
YGNodeInsertChild(root, root_child0, 0);
const YGNodeRef root_child0_child0 = YGNodeNewWithConfig(config);
YGNodeStyleSetFlexGrow(root_child0_child0, 1);
YGNodeStyleSetFlexBasis(root_child0_child0, 0.3f);
YGNodeStyleSetPosition(root_child0_child0, YGEdgeBottom, 13.3f);
YGNodeStyleSetHeight(root_child0_child0, 9.9f);
YGNodeStyleSetFlexBasis(root_child0_child0, 0.3);
YGNodeStyleSetPosition(root_child0_child0, YGEdgeBottom, 13.3);
YGNodeStyleSetHeight(root_child0_child0, 9.9);
YGNodeInsertChild(root_child0, root_child0_child0, 0);
const YGNodeRef root_child0_child1 = YGNodeNewWithConfig(config);
YGNodeStyleSetFlexGrow(root_child0_child1, 4);
YGNodeStyleSetFlexBasis(root_child0_child1, 0.3f);
YGNodeStyleSetPosition(root_child0_child1, YGEdgeTop, 13.3f);
YGNodeStyleSetHeight(root_child0_child1, 1.1f);
YGNodeStyleSetFlexBasis(root_child0_child1, 0.3);
YGNodeStyleSetPosition(root_child0_child1, YGEdgeTop, 13.3);
YGNodeStyleSetHeight(root_child0_child1, 1.1);
YGNodeInsertChild(root_child0, root_child0_child1, 1);
const YGNodeRef root_child1 = YGNodeNewWithConfig(config);
YGNodeStyleSetFlexGrow(root_child1, 1.6f);
YGNodeStyleSetFlexGrow(root_child1, 1.6);
YGNodeStyleSetHeight(root_child1, 10);
YGNodeInsertChild(root, root_child1, 1);
const YGNodeRef root_child2 = YGNodeNewWithConfig(config);
YGNodeStyleSetFlexGrow(root_child2, 1.1f);
YGNodeStyleSetHeight(root_child2, 10.7f);
YGNodeStyleSetFlexGrow(root_child2, 1.1);
YGNodeStyleSetHeight(root_child2, 10.7);
YGNodeInsertChild(root, root_child2, 2);
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
@@ -494,7 +494,7 @@ TEST(YogaTest, rounding_fractial_input_1) {
const YGNodeRef root = YGNodeNewWithConfig(config);
YGNodeStyleSetWidth(root, 100);
YGNodeStyleSetHeight(root, 113.4f);
YGNodeStyleSetHeight(root, 113.4);
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
YGNodeStyleSetFlexGrow(root_child0, 1);
@@ -565,7 +565,7 @@ TEST(YogaTest, rounding_fractial_input_2) {
const YGNodeRef root = YGNodeNewWithConfig(config);
YGNodeStyleSetWidth(root, 100);
YGNodeStyleSetHeight(root, 113.6f);
YGNodeStyleSetHeight(root, 113.6);
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
YGNodeStyleSetFlexGrow(root_child0, 1);
@@ -635,9 +635,9 @@ TEST(YogaTest, rounding_fractial_input_3) {
const YGConfigRef config = YGConfigNew();
const YGNodeRef root = YGNodeNewWithConfig(config);
YGNodeStyleSetPosition(root, YGEdgeTop, 0.3f);
YGNodeStyleSetPosition(root, YGEdgeTop, 0.3);
YGNodeStyleSetWidth(root, 100);
YGNodeStyleSetHeight(root, 113.4f);
YGNodeStyleSetHeight(root, 113.4);
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
YGNodeStyleSetFlexGrow(root_child0, 1);
@@ -707,9 +707,9 @@ TEST(YogaTest, rounding_fractial_input_4) {
const YGConfigRef config = YGConfigNew();
const YGNodeRef root = YGNodeNewWithConfig(config);
YGNodeStyleSetPosition(root, YGEdgeTop, 0.7f);
YGNodeStyleSetPosition(root, YGEdgeTop, 0.7);
YGNodeStyleSetWidth(root, 100);
YGNodeStyleSetHeight(root, 113.4f);
YGNodeStyleSetHeight(root, 113.4);
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
YGNodeStyleSetFlexGrow(root_child0, 1);

View File

@@ -156,22 +156,22 @@ ACCESSOR_TEST(display, YGDisplayFlex, YGDisplayNone, YGDisplayFlex)
ACCESSOR_TEST(
flex,
YGFloatOptional{},
YGFloatOptional{123.45f},
YGFloatOptional{-9.87f},
YGFloatOptional{123.45},
YGFloatOptional{-9.87},
YGFloatOptional{})
ACCESSOR_TEST(
flexGrow,
YGFloatOptional{},
YGFloatOptional{123.45f},
YGFloatOptional{-9.87f},
YGFloatOptional{123.45},
YGFloatOptional{-9.87},
YGFloatOptional{})
ACCESSOR_TEST(
flexShrink,
YGFloatOptional{},
YGFloatOptional{123.45f},
YGFloatOptional{-9.87f},
YGFloatOptional{123.45},
YGFloatOptional{-9.87},
YGFloatOptional{})
ACCESSOR_TEST(
@@ -179,8 +179,8 @@ ACCESSOR_TEST(
CompactValue::ofAuto(),
CompactValue::ofUndefined(),
CompactValue::ofAuto(),
CompactValue::of<YGUnitPoint>(7777.77f),
CompactValue::of<YGUnitPercent>(-100.0f))
CompactValue::of<YGUnitPoint>(7777.77),
CompactValue::of<YGUnitPercent>(-100.0))
INDEX_ACCESSOR_TEST(
position,
@@ -188,8 +188,8 @@ INDEX_ACCESSOR_TEST(
YGEdgeBottom,
CompactValue::ofAuto(),
CompactValue::ofUndefined(),
CompactValue::of<YGUnitPoint>(7777.77f),
CompactValue::of<YGUnitPercent>(-100.0f))
CompactValue::of<YGUnitPoint>(7777.77),
CompactValue::of<YGUnitPercent>(-100.0))
INDEX_ACCESSOR_TEST(
margin,
@@ -197,22 +197,22 @@ INDEX_ACCESSOR_TEST(
YGEdgeTop,
CompactValue::ofAuto(),
CompactValue::ofUndefined(),
CompactValue::of<YGUnitPoint>(7777.77f),
CompactValue::of<YGUnitPercent>(-100.0f))
CompactValue::of<YGUnitPoint>(7777.77),
CompactValue::of<YGUnitPercent>(-100.0))
INDEX_ACCESSOR_TEST(
padding,
CompactValue::ofUndefined(),
YGEdgeAll,
CompactValue::of<YGUnitPoint>(7777.77f),
CompactValue::of<YGUnitPoint>(7777.77),
CompactValue::ofUndefined(),
CompactValue::of<YGUnitPercent>(-100.0f))
CompactValue::of<YGUnitPercent>(-100.0))
INDEX_ACCESSOR_TEST(
border,
CompactValue::ofUndefined(),
YGEdgeHorizontal,
CompactValue::of<YGUnitPoint>(-7777.77f),
CompactValue::of<YGUnitPoint>(-7777.77),
CompactValue::ofUndefined())
INDEX_ACCESSOR_TEST(
@@ -221,8 +221,8 @@ INDEX_ACCESSOR_TEST(
YGDimensionWidth,
CompactValue::ofUndefined(),
CompactValue::ofAuto(),
CompactValue::of<YGUnitPoint>(7777.77f),
CompactValue::of<YGUnitPercent>(-100.0f))
CompactValue::of<YGUnitPoint>(7777.77),
CompactValue::of<YGUnitPercent>(-100.0))
INDEX_ACCESSOR_TEST(
minDimensions,
@@ -230,8 +230,8 @@ INDEX_ACCESSOR_TEST(
YGDimensionHeight,
CompactValue::ofAuto(),
CompactValue::ofUndefined(),
CompactValue::of<YGUnitPoint>(7777.77f),
CompactValue::of<YGUnitPercent>(-100.0f))
CompactValue::of<YGUnitPoint>(7777.77),
CompactValue::of<YGUnitPercent>(-100.0))
INDEX_ACCESSOR_TEST(
maxDimensions,
@@ -239,15 +239,15 @@ INDEX_ACCESSOR_TEST(
YGDimensionHeight,
CompactValue::ofAuto(),
CompactValue::ofUndefined(),
CompactValue::of<YGUnitPoint>(7777.77f),
CompactValue::of<YGUnitPercent>(-100.0f))
CompactValue::of<YGUnitPoint>(7777.77),
CompactValue::of<YGUnitPercent>(-100.0))
ACCESSOR_TEST(
aspectRatio,
YGFloatOptional{},
YGFloatOptional{-123.45f},
YGFloatOptional{9876.5f},
YGFloatOptional{0.0f},
YGFloatOptional{-123.45},
YGFloatOptional{9876.5},
YGFloatOptional{0.0},
YGFloatOptional{});
} // namespace yoga

View File

@@ -10,14 +10,14 @@
#include <yoga/YGValue.h>
TEST(YGValue, supports_equality) {
ASSERT_EQ((YGValue{12.5f, YGUnitPercent}), (YGValue{12.5f, YGUnitPercent}));
ASSERT_NE((YGValue{12.5f, YGUnitPercent}), (YGValue{56.7f, YGUnitPercent}));
ASSERT_NE((YGValue{12.5f, YGUnitPercent}), (YGValue{12.5f, YGUnitPoint}));
ASSERT_NE((YGValue{12.5f, YGUnitPercent}), (YGValue{12.5f, YGUnitAuto}));
ASSERT_NE((YGValue{12.5f, YGUnitPercent}), (YGValue{12.5f, YGUnitUndefined}));
ASSERT_EQ((YGValue{12.5, YGUnitPercent}), (YGValue{12.5, YGUnitPercent}));
ASSERT_NE((YGValue{12.5, YGUnitPercent}), (YGValue{56.7, YGUnitPercent}));
ASSERT_NE((YGValue{12.5, YGUnitPercent}), (YGValue{12.5, YGUnitPoint}));
ASSERT_NE((YGValue{12.5, YGUnitPercent}), (YGValue{12.5, YGUnitAuto}));
ASSERT_NE((YGValue{12.5, YGUnitPercent}), (YGValue{12.5, YGUnitUndefined}));
ASSERT_EQ(
(YGValue{12.5f, YGUnitUndefined}),
(YGValue{12.5, YGUnitUndefined}),
(YGValue{YGUndefined, YGUnitUndefined}));
ASSERT_EQ((YGValue{0, YGUnitAuto}), (YGValue{-1, YGUnitAuto}));
}