Fixup UTs for MSVC and Release Mode

Summary: This fixes incompatibility with MSVC in /W3 (designated initializers, precision loss) along with guarding tests which will only pass in DEBUG builds

Reviewed By: cortinico

Differential Revision: D42406531

fbshipit-source-id: 2c0d59678f76decf9b9b4d91a7c9ec12136ca1b9
This commit is contained in:
Nick Gerleman
2023-01-09 13:59:19 -08:00
committed by Facebook GitHub Bot
parent 9808358e08
commit 83cef5b12f
11 changed files with 55 additions and 70 deletions

View File

@@ -234,7 +234,7 @@ TEST_F(EventTest, layout_events_has_max_measure_cache) {
YGNodeInsertChild(root, b, 1);
YGNodeStyleSetFlexBasis(a, 10.0f);
for (auto s : {20, 30, 40}) {
for (auto s : {20.0f, 30.0f, 40.0f}) {
YGNodeCalculateLayout(root, s, s, YGDirectionLTR);
}

View File

@@ -22,10 +22,7 @@ static YGSize _measure1(
YGMeasureMode widthMode,
float height,
YGMeasureMode heightMode) {
return YGSize{
.width = 42,
.height = 50,
};
return YGSize{42, 50};
}
static YGSize _measure2(
@@ -34,10 +31,7 @@ static YGSize _measure2(
YGMeasureMode widthMode,
float height,
YGMeasureMode heightMode) {
return YGSize{
.width = 279,
.height = 126,
};
return YGSize{279, 126};
}
static YGNodeRef createYGNode(
@@ -51,8 +45,8 @@ static YGNodeRef createYGNode(
if (alignBaseline) {
YGNodeStyleSetAlignItems(node, YGAlignBaseline);
}
YGNodeStyleSetWidth(node, width);
YGNodeStyleSetHeight(node, height);
YGNodeStyleSetWidth(node, (float) width);
YGNodeStyleSetHeight(node, (float) height);
return node;
}

View File

@@ -16,8 +16,8 @@ static YGSize _measure(
float height,
YGMeasureMode heightMode) {
return YGSize{
.width = widthMode == YGMeasureModeExactly ? width : 50,
.height = heightMode == YGMeasureModeExactly ? height : 50,
widthMode == YGMeasureModeExactly ? width : 50,
heightMode == YGMeasureModeExactly ? height : 50,
};
}

View File

@@ -9,6 +9,8 @@
#include <stdarg.h>
#include <yoga/Yoga.h>
#if DEBUG
namespace {
char writeBuffer[4096];
int _unmanagedLogger(
@@ -131,3 +133,5 @@ TEST(YogaTest, logger_node_with_children_should_print_indented) {
"style=\"\" ></div>\n</div>";
ASSERT_STREQ(expected, writeBuffer);
}
#endif

View File

@@ -19,8 +19,8 @@ static YGSize _measureMax(
(*measureCount)++;
return YGSize{
.width = widthMode == YGMeasureModeUndefined ? 10 : width,
.height = heightMode == YGMeasureModeUndefined ? 10 : height,
widthMode == YGMeasureModeUndefined ? 10 : width,
heightMode == YGMeasureModeUndefined ? 10 : height,
};
}
@@ -33,11 +33,11 @@ static YGSize _measureMin(
int* measureCount = (int*) node->getContext();
*measureCount = *measureCount + 1;
return YGSize{
.width = widthMode == YGMeasureModeUndefined ||
widthMode == YGMeasureModeUndefined ||
(widthMode == YGMeasureModeAtMost && width > 10)
? 10
: width,
.height = heightMode == YGMeasureModeUndefined ||
heightMode == YGMeasureModeUndefined ||
(heightMode == YGMeasureModeAtMost && height > 10)
? 10
: height,
@@ -55,10 +55,7 @@ static YGSize _measure_84_49(
(*measureCount)++;
}
return YGSize{
.width = 84.f,
.height = 49.f,
};
return YGSize{84.f, 49.f};
}
TEST(YogaTest, measure_once_single_flexible_child) {

View File

@@ -38,15 +38,15 @@ static YGSize _measure(
constraintList->length = currentIndex + 1;
return YGSize{
.width = widthMode == YGMeasureModeUndefined ? 10 : width,
.height = heightMode == YGMeasureModeUndefined ? 10 : width,
widthMode == YGMeasureModeUndefined ? 10 : width,
heightMode == YGMeasureModeUndefined ? 10 : width,
};
}
TEST(YogaTest, exactly_measure_stretched_child_column) {
struct _MeasureConstraintList constraintList = _MeasureConstraintList{
.length = 0,
.constraints = (struct _MeasureConstraint*) malloc(
0,
(struct _MeasureConstraint*) malloc(
10 * sizeof(struct _MeasureConstraint)),
};
@@ -74,8 +74,8 @@ TEST(YogaTest, exactly_measure_stretched_child_column) {
TEST(YogaTest, exactly_measure_stretched_child_row) {
struct _MeasureConstraintList constraintList = _MeasureConstraintList{
.length = 0,
.constraints = (struct _MeasureConstraint*) malloc(
0,
(struct _MeasureConstraint*) malloc(
10 * sizeof(struct _MeasureConstraint)),
};
@@ -103,8 +103,8 @@ TEST(YogaTest, exactly_measure_stretched_child_row) {
TEST(YogaTest, at_most_main_axis_column) {
struct _MeasureConstraintList constraintList = _MeasureConstraintList{
.length = 0,
.constraints = (struct _MeasureConstraint*) malloc(
0,
(struct _MeasureConstraint*) malloc(
10 * sizeof(struct _MeasureConstraint)),
};
@@ -130,8 +130,8 @@ TEST(YogaTest, at_most_main_axis_column) {
TEST(YogaTest, at_most_cross_axis_column) {
struct _MeasureConstraintList constraintList = _MeasureConstraintList{
.length = 0,
.constraints = (struct _MeasureConstraint*) malloc(
0,
(struct _MeasureConstraint*) malloc(
10 * sizeof(struct _MeasureConstraint)),
};
@@ -158,8 +158,8 @@ TEST(YogaTest, at_most_cross_axis_column) {
TEST(YogaTest, at_most_main_axis_row) {
struct _MeasureConstraintList constraintList = _MeasureConstraintList{
.length = 0,
.constraints = (struct _MeasureConstraint*) malloc(
0,
(struct _MeasureConstraint*) malloc(
10 * sizeof(struct _MeasureConstraint)),
};
@@ -186,8 +186,8 @@ TEST(YogaTest, at_most_main_axis_row) {
TEST(YogaTest, at_most_cross_axis_row) {
struct _MeasureConstraintList constraintList = _MeasureConstraintList{
.length = 0,
.constraints = (struct _MeasureConstraint*) malloc(
0,
(struct _MeasureConstraint*) malloc(
10 * sizeof(struct _MeasureConstraint)),
};
@@ -215,8 +215,8 @@ TEST(YogaTest, at_most_cross_axis_row) {
TEST(YogaTest, flex_child) {
struct _MeasureConstraintList constraintList = _MeasureConstraintList{
.length = 0,
.constraints = (struct _MeasureConstraint*) malloc(
0,
(struct _MeasureConstraint*) malloc(
10 * sizeof(struct _MeasureConstraint)),
};
@@ -245,8 +245,8 @@ TEST(YogaTest, flex_child) {
TEST(YogaTest, flex_child_with_flex_basis) {
struct _MeasureConstraintList constraintList = _MeasureConstraintList{
.length = 0,
.constraints = (struct _MeasureConstraint*) malloc(
0,
(struct _MeasureConstraint*) malloc(
10 * sizeof(struct _MeasureConstraint)),
};
@@ -273,8 +273,8 @@ TEST(YogaTest, flex_child_with_flex_basis) {
TEST(YogaTest, overflow_scroll_column) {
struct _MeasureConstraintList constraintList = _MeasureConstraintList{
.length = 0,
.constraints = (struct _MeasureConstraint*) malloc(
0,
(struct _MeasureConstraint*) malloc(
10 * sizeof(struct _MeasureConstraint)),
};
@@ -305,8 +305,8 @@ TEST(YogaTest, overflow_scroll_column) {
TEST(YogaTest, overflow_scroll_row) {
struct _MeasureConstraintList constraintList = _MeasureConstraintList{
.length = 0,
.constraints = (struct _MeasureConstraint*) malloc(
0,
(struct _MeasureConstraint*) malloc(
10 * sizeof(struct _MeasureConstraint)),
};

View File

@@ -20,10 +20,7 @@ static YGSize _measure(
(*measureCount)++;
}
return YGSize{
.width = 10,
.height = 10,
};
return YGSize{10, 10};
}
static YGSize _simulate_wrapping_text(
@@ -33,13 +30,10 @@ static YGSize _simulate_wrapping_text(
float height,
YGMeasureMode heightMode) {
if (widthMode == YGMeasureModeUndefined || width >= 68) {
return YGSize{.width = 68, .height = 16};
return YGSize{68, 16};
}
return YGSize{
.width = 50,
.height = 32,
};
return YGSize{50, 32};
}
static YGSize _measure_assert_negative(
@@ -51,10 +45,7 @@ static YGSize _measure_assert_negative(
EXPECT_GE(width, 0);
EXPECT_GE(height, 0);
return YGSize{
.width = 0,
.height = 0,
};
return YGSize{0, 0};
}
TEST(YogaTest, dont_measure_single_grow_shrink_child) {
@@ -656,10 +647,7 @@ static YGSize _measure_90_10(
float height,
YGMeasureMode heightMode) {
return YGSize{
.width = 90,
.height = 10,
};
return YGSize{90, 10};
}
static YGSize _measure_100_100(
@@ -669,10 +657,7 @@ static YGSize _measure_100_100(
float height,
YGMeasureMode heightMode) {
return YGSize{
.width = 100,
.height = 100,
};
return YGSize{100, 100};
}
TEST(YogaTest, percent_with_text_node) {

View File

@@ -48,7 +48,7 @@ TEST(YGNode, measure_with_context_measure_fn) {
return *(YGSize*) ctx;
});
auto result = YGSize{123.4, -56.7};
auto result = YGSize{123.4f, -56.7f};
ASSERT_EQ(
n.measure(0, YGMeasureModeUndefined, 0, YGMeasureModeUndefined, &result),
result);

View File

@@ -48,7 +48,7 @@ static YGSize measureText(
YGMeasureMode widthMode,
float height,
YGMeasureMode heightMode) {
return (YGSize){.width = 10, .height = 10};
return YGSize{10, 10};
}
// Regression test for https://github.com/facebook/yoga/issues/824
@@ -57,7 +57,7 @@ TEST(YogaTest, consistent_rounding_during_repeated_layouts) {
YGConfigSetPointScaleFactor(config, 2);
const YGNodeRef root = YGNodeNewWithConfig(config);
YGNodeStyleSetMargin(root, YGEdgeTop, -1.49);
YGNodeStyleSetMargin(root, YGEdgeTop, -1.49f);
YGNodeStyleSetWidth(root, 500);
YGNodeStyleSetHeight(root, 500);
@@ -70,7 +70,7 @@ TEST(YogaTest, consistent_rounding_during_repeated_layouts) {
for (int i = 0; i < 5; i++) {
// Dirty the tree so YGRoundToPixelGrid runs again
YGNodeStyleSetMargin(root, YGEdgeLeft, i + 1);
YGNodeStyleSetMargin(root, YGEdgeLeft, (float) (i + 1));
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(node1));

View File

@@ -57,8 +57,8 @@ TEST(YogaTest, rounding_feature_with_custom_measure_func_floor) {
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
ASSERT_FLOAT_EQ(10.2, YGNodeLayoutGetWidth(root_child0));
ASSERT_FLOAT_EQ(10.2, YGNodeLayoutGetHeight(root_child0));
ASSERT_FLOAT_EQ(10.2f, YGNodeLayoutGetWidth(root_child0));
ASSERT_FLOAT_EQ(10.2f, YGNodeLayoutGetHeight(root_child0));
YGConfigSetPointScaleFactor(config, 1.0f);

View File

@@ -81,6 +81,9 @@ namespace yoga {
using CompactValue = detail::CompactValue;
// TODO: MSVC doesn't like the macros
#ifndef _MSC_VER
ACCESSOR_TEST(
direction,
YGDirectionInherit,
@@ -250,5 +253,7 @@ ACCESSOR_TEST(
YGFloatOptional{0.0f},
YGFloatOptional{});
#endif
} // namespace yoga
} // namespace facebook