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:
committed by
Facebook GitHub Bot
parent
9808358e08
commit
83cef5b12f
@@ -234,7 +234,7 @@ TEST_F(EventTest, layout_events_has_max_measure_cache) {
|
|||||||
YGNodeInsertChild(root, b, 1);
|
YGNodeInsertChild(root, b, 1);
|
||||||
YGNodeStyleSetFlexBasis(a, 10.0f);
|
YGNodeStyleSetFlexBasis(a, 10.0f);
|
||||||
|
|
||||||
for (auto s : {20, 30, 40}) {
|
for (auto s : {20.0f, 30.0f, 40.0f}) {
|
||||||
YGNodeCalculateLayout(root, s, s, YGDirectionLTR);
|
YGNodeCalculateLayout(root, s, s, YGDirectionLTR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -22,10 +22,7 @@ static YGSize _measure1(
|
|||||||
YGMeasureMode widthMode,
|
YGMeasureMode widthMode,
|
||||||
float height,
|
float height,
|
||||||
YGMeasureMode heightMode) {
|
YGMeasureMode heightMode) {
|
||||||
return YGSize{
|
return YGSize{42, 50};
|
||||||
.width = 42,
|
|
||||||
.height = 50,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static YGSize _measure2(
|
static YGSize _measure2(
|
||||||
@@ -34,10 +31,7 @@ static YGSize _measure2(
|
|||||||
YGMeasureMode widthMode,
|
YGMeasureMode widthMode,
|
||||||
float height,
|
float height,
|
||||||
YGMeasureMode heightMode) {
|
YGMeasureMode heightMode) {
|
||||||
return YGSize{
|
return YGSize{279, 126};
|
||||||
.width = 279,
|
|
||||||
.height = 126,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static YGNodeRef createYGNode(
|
static YGNodeRef createYGNode(
|
||||||
@@ -51,8 +45,8 @@ static YGNodeRef createYGNode(
|
|||||||
if (alignBaseline) {
|
if (alignBaseline) {
|
||||||
YGNodeStyleSetAlignItems(node, YGAlignBaseline);
|
YGNodeStyleSetAlignItems(node, YGAlignBaseline);
|
||||||
}
|
}
|
||||||
YGNodeStyleSetWidth(node, width);
|
YGNodeStyleSetWidth(node, (float) width);
|
||||||
YGNodeStyleSetHeight(node, height);
|
YGNodeStyleSetHeight(node, (float) height);
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -16,8 +16,8 @@ static YGSize _measure(
|
|||||||
float height,
|
float height,
|
||||||
YGMeasureMode heightMode) {
|
YGMeasureMode heightMode) {
|
||||||
return YGSize{
|
return YGSize{
|
||||||
.width = widthMode == YGMeasureModeExactly ? width : 50,
|
widthMode == YGMeasureModeExactly ? width : 50,
|
||||||
.height = heightMode == YGMeasureModeExactly ? height : 50,
|
heightMode == YGMeasureModeExactly ? height : 50,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -9,6 +9,8 @@
|
|||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <yoga/Yoga.h>
|
#include <yoga/Yoga.h>
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
char writeBuffer[4096];
|
char writeBuffer[4096];
|
||||||
int _unmanagedLogger(
|
int _unmanagedLogger(
|
||||||
@@ -131,3 +133,5 @@ TEST(YogaTest, logger_node_with_children_should_print_indented) {
|
|||||||
"style=\"\" ></div>\n</div>";
|
"style=\"\" ></div>\n</div>";
|
||||||
ASSERT_STREQ(expected, writeBuffer);
|
ASSERT_STREQ(expected, writeBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
@@ -19,8 +19,8 @@ static YGSize _measureMax(
|
|||||||
(*measureCount)++;
|
(*measureCount)++;
|
||||||
|
|
||||||
return YGSize{
|
return YGSize{
|
||||||
.width = widthMode == YGMeasureModeUndefined ? 10 : width,
|
widthMode == YGMeasureModeUndefined ? 10 : width,
|
||||||
.height = heightMode == YGMeasureModeUndefined ? 10 : height,
|
heightMode == YGMeasureModeUndefined ? 10 : height,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,11 +33,11 @@ static YGSize _measureMin(
|
|||||||
int* measureCount = (int*) node->getContext();
|
int* measureCount = (int*) node->getContext();
|
||||||
*measureCount = *measureCount + 1;
|
*measureCount = *measureCount + 1;
|
||||||
return YGSize{
|
return YGSize{
|
||||||
.width = widthMode == YGMeasureModeUndefined ||
|
widthMode == YGMeasureModeUndefined ||
|
||||||
(widthMode == YGMeasureModeAtMost && width > 10)
|
(widthMode == YGMeasureModeAtMost && width > 10)
|
||||||
? 10
|
? 10
|
||||||
: width,
|
: width,
|
||||||
.height = heightMode == YGMeasureModeUndefined ||
|
heightMode == YGMeasureModeUndefined ||
|
||||||
(heightMode == YGMeasureModeAtMost && height > 10)
|
(heightMode == YGMeasureModeAtMost && height > 10)
|
||||||
? 10
|
? 10
|
||||||
: height,
|
: height,
|
||||||
@@ -55,10 +55,7 @@ static YGSize _measure_84_49(
|
|||||||
(*measureCount)++;
|
(*measureCount)++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return YGSize{
|
return YGSize{84.f, 49.f};
|
||||||
.width = 84.f,
|
|
||||||
.height = 49.f,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(YogaTest, measure_once_single_flexible_child) {
|
TEST(YogaTest, measure_once_single_flexible_child) {
|
||||||
|
@@ -38,15 +38,15 @@ static YGSize _measure(
|
|||||||
constraintList->length = currentIndex + 1;
|
constraintList->length = currentIndex + 1;
|
||||||
|
|
||||||
return YGSize{
|
return YGSize{
|
||||||
.width = widthMode == YGMeasureModeUndefined ? 10 : width,
|
widthMode == YGMeasureModeUndefined ? 10 : width,
|
||||||
.height = heightMode == YGMeasureModeUndefined ? 10 : width,
|
heightMode == YGMeasureModeUndefined ? 10 : width,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(YogaTest, exactly_measure_stretched_child_column) {
|
TEST(YogaTest, exactly_measure_stretched_child_column) {
|
||||||
struct _MeasureConstraintList constraintList = _MeasureConstraintList{
|
struct _MeasureConstraintList constraintList = _MeasureConstraintList{
|
||||||
.length = 0,
|
0,
|
||||||
.constraints = (struct _MeasureConstraint*) malloc(
|
(struct _MeasureConstraint*) malloc(
|
||||||
10 * sizeof(struct _MeasureConstraint)),
|
10 * sizeof(struct _MeasureConstraint)),
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -74,8 +74,8 @@ TEST(YogaTest, exactly_measure_stretched_child_column) {
|
|||||||
|
|
||||||
TEST(YogaTest, exactly_measure_stretched_child_row) {
|
TEST(YogaTest, exactly_measure_stretched_child_row) {
|
||||||
struct _MeasureConstraintList constraintList = _MeasureConstraintList{
|
struct _MeasureConstraintList constraintList = _MeasureConstraintList{
|
||||||
.length = 0,
|
0,
|
||||||
.constraints = (struct _MeasureConstraint*) malloc(
|
(struct _MeasureConstraint*) malloc(
|
||||||
10 * sizeof(struct _MeasureConstraint)),
|
10 * sizeof(struct _MeasureConstraint)),
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -103,8 +103,8 @@ TEST(YogaTest, exactly_measure_stretched_child_row) {
|
|||||||
|
|
||||||
TEST(YogaTest, at_most_main_axis_column) {
|
TEST(YogaTest, at_most_main_axis_column) {
|
||||||
struct _MeasureConstraintList constraintList = _MeasureConstraintList{
|
struct _MeasureConstraintList constraintList = _MeasureConstraintList{
|
||||||
.length = 0,
|
0,
|
||||||
.constraints = (struct _MeasureConstraint*) malloc(
|
(struct _MeasureConstraint*) malloc(
|
||||||
10 * sizeof(struct _MeasureConstraint)),
|
10 * sizeof(struct _MeasureConstraint)),
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -130,8 +130,8 @@ TEST(YogaTest, at_most_main_axis_column) {
|
|||||||
|
|
||||||
TEST(YogaTest, at_most_cross_axis_column) {
|
TEST(YogaTest, at_most_cross_axis_column) {
|
||||||
struct _MeasureConstraintList constraintList = _MeasureConstraintList{
|
struct _MeasureConstraintList constraintList = _MeasureConstraintList{
|
||||||
.length = 0,
|
0,
|
||||||
.constraints = (struct _MeasureConstraint*) malloc(
|
(struct _MeasureConstraint*) malloc(
|
||||||
10 * sizeof(struct _MeasureConstraint)),
|
10 * sizeof(struct _MeasureConstraint)),
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -158,8 +158,8 @@ TEST(YogaTest, at_most_cross_axis_column) {
|
|||||||
|
|
||||||
TEST(YogaTest, at_most_main_axis_row) {
|
TEST(YogaTest, at_most_main_axis_row) {
|
||||||
struct _MeasureConstraintList constraintList = _MeasureConstraintList{
|
struct _MeasureConstraintList constraintList = _MeasureConstraintList{
|
||||||
.length = 0,
|
0,
|
||||||
.constraints = (struct _MeasureConstraint*) malloc(
|
(struct _MeasureConstraint*) malloc(
|
||||||
10 * sizeof(struct _MeasureConstraint)),
|
10 * sizeof(struct _MeasureConstraint)),
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -186,8 +186,8 @@ TEST(YogaTest, at_most_main_axis_row) {
|
|||||||
|
|
||||||
TEST(YogaTest, at_most_cross_axis_row) {
|
TEST(YogaTest, at_most_cross_axis_row) {
|
||||||
struct _MeasureConstraintList constraintList = _MeasureConstraintList{
|
struct _MeasureConstraintList constraintList = _MeasureConstraintList{
|
||||||
.length = 0,
|
0,
|
||||||
.constraints = (struct _MeasureConstraint*) malloc(
|
(struct _MeasureConstraint*) malloc(
|
||||||
10 * sizeof(struct _MeasureConstraint)),
|
10 * sizeof(struct _MeasureConstraint)),
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -215,8 +215,8 @@ TEST(YogaTest, at_most_cross_axis_row) {
|
|||||||
|
|
||||||
TEST(YogaTest, flex_child) {
|
TEST(YogaTest, flex_child) {
|
||||||
struct _MeasureConstraintList constraintList = _MeasureConstraintList{
|
struct _MeasureConstraintList constraintList = _MeasureConstraintList{
|
||||||
.length = 0,
|
0,
|
||||||
.constraints = (struct _MeasureConstraint*) malloc(
|
(struct _MeasureConstraint*) malloc(
|
||||||
10 * sizeof(struct _MeasureConstraint)),
|
10 * sizeof(struct _MeasureConstraint)),
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -245,8 +245,8 @@ TEST(YogaTest, flex_child) {
|
|||||||
|
|
||||||
TEST(YogaTest, flex_child_with_flex_basis) {
|
TEST(YogaTest, flex_child_with_flex_basis) {
|
||||||
struct _MeasureConstraintList constraintList = _MeasureConstraintList{
|
struct _MeasureConstraintList constraintList = _MeasureConstraintList{
|
||||||
.length = 0,
|
0,
|
||||||
.constraints = (struct _MeasureConstraint*) malloc(
|
(struct _MeasureConstraint*) malloc(
|
||||||
10 * sizeof(struct _MeasureConstraint)),
|
10 * sizeof(struct _MeasureConstraint)),
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -273,8 +273,8 @@ TEST(YogaTest, flex_child_with_flex_basis) {
|
|||||||
|
|
||||||
TEST(YogaTest, overflow_scroll_column) {
|
TEST(YogaTest, overflow_scroll_column) {
|
||||||
struct _MeasureConstraintList constraintList = _MeasureConstraintList{
|
struct _MeasureConstraintList constraintList = _MeasureConstraintList{
|
||||||
.length = 0,
|
0,
|
||||||
.constraints = (struct _MeasureConstraint*) malloc(
|
(struct _MeasureConstraint*) malloc(
|
||||||
10 * sizeof(struct _MeasureConstraint)),
|
10 * sizeof(struct _MeasureConstraint)),
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -305,8 +305,8 @@ TEST(YogaTest, overflow_scroll_column) {
|
|||||||
|
|
||||||
TEST(YogaTest, overflow_scroll_row) {
|
TEST(YogaTest, overflow_scroll_row) {
|
||||||
struct _MeasureConstraintList constraintList = _MeasureConstraintList{
|
struct _MeasureConstraintList constraintList = _MeasureConstraintList{
|
||||||
.length = 0,
|
0,
|
||||||
.constraints = (struct _MeasureConstraint*) malloc(
|
(struct _MeasureConstraint*) malloc(
|
||||||
10 * sizeof(struct _MeasureConstraint)),
|
10 * sizeof(struct _MeasureConstraint)),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -20,10 +20,7 @@ static YGSize _measure(
|
|||||||
(*measureCount)++;
|
(*measureCount)++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return YGSize{
|
return YGSize{10, 10};
|
||||||
.width = 10,
|
|
||||||
.height = 10,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static YGSize _simulate_wrapping_text(
|
static YGSize _simulate_wrapping_text(
|
||||||
@@ -33,13 +30,10 @@ static YGSize _simulate_wrapping_text(
|
|||||||
float height,
|
float height,
|
||||||
YGMeasureMode heightMode) {
|
YGMeasureMode heightMode) {
|
||||||
if (widthMode == YGMeasureModeUndefined || width >= 68) {
|
if (widthMode == YGMeasureModeUndefined || width >= 68) {
|
||||||
return YGSize{.width = 68, .height = 16};
|
return YGSize{68, 16};
|
||||||
}
|
}
|
||||||
|
|
||||||
return YGSize{
|
return YGSize{50, 32};
|
||||||
.width = 50,
|
|
||||||
.height = 32,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static YGSize _measure_assert_negative(
|
static YGSize _measure_assert_negative(
|
||||||
@@ -51,10 +45,7 @@ static YGSize _measure_assert_negative(
|
|||||||
EXPECT_GE(width, 0);
|
EXPECT_GE(width, 0);
|
||||||
EXPECT_GE(height, 0);
|
EXPECT_GE(height, 0);
|
||||||
|
|
||||||
return YGSize{
|
return YGSize{0, 0};
|
||||||
.width = 0,
|
|
||||||
.height = 0,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(YogaTest, dont_measure_single_grow_shrink_child) {
|
TEST(YogaTest, dont_measure_single_grow_shrink_child) {
|
||||||
@@ -656,10 +647,7 @@ static YGSize _measure_90_10(
|
|||||||
float height,
|
float height,
|
||||||
YGMeasureMode heightMode) {
|
YGMeasureMode heightMode) {
|
||||||
|
|
||||||
return YGSize{
|
return YGSize{90, 10};
|
||||||
.width = 90,
|
|
||||||
.height = 10,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static YGSize _measure_100_100(
|
static YGSize _measure_100_100(
|
||||||
@@ -669,10 +657,7 @@ static YGSize _measure_100_100(
|
|||||||
float height,
|
float height,
|
||||||
YGMeasureMode heightMode) {
|
YGMeasureMode heightMode) {
|
||||||
|
|
||||||
return YGSize{
|
return YGSize{100, 100};
|
||||||
.width = 100,
|
|
||||||
.height = 100,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(YogaTest, percent_with_text_node) {
|
TEST(YogaTest, percent_with_text_node) {
|
||||||
|
@@ -48,7 +48,7 @@ TEST(YGNode, measure_with_context_measure_fn) {
|
|||||||
return *(YGSize*) ctx;
|
return *(YGSize*) ctx;
|
||||||
});
|
});
|
||||||
|
|
||||||
auto result = YGSize{123.4, -56.7};
|
auto result = YGSize{123.4f, -56.7f};
|
||||||
ASSERT_EQ(
|
ASSERT_EQ(
|
||||||
n.measure(0, YGMeasureModeUndefined, 0, YGMeasureModeUndefined, &result),
|
n.measure(0, YGMeasureModeUndefined, 0, YGMeasureModeUndefined, &result),
|
||||||
result);
|
result);
|
||||||
|
@@ -48,7 +48,7 @@ static YGSize measureText(
|
|||||||
YGMeasureMode widthMode,
|
YGMeasureMode widthMode,
|
||||||
float height,
|
float height,
|
||||||
YGMeasureMode heightMode) {
|
YGMeasureMode heightMode) {
|
||||||
return (YGSize){.width = 10, .height = 10};
|
return YGSize{10, 10};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Regression test for https://github.com/facebook/yoga/issues/824
|
// Regression test for https://github.com/facebook/yoga/issues/824
|
||||||
@@ -57,7 +57,7 @@ TEST(YogaTest, consistent_rounding_during_repeated_layouts) {
|
|||||||
YGConfigSetPointScaleFactor(config, 2);
|
YGConfigSetPointScaleFactor(config, 2);
|
||||||
|
|
||||||
const YGNodeRef root = YGNodeNewWithConfig(config);
|
const YGNodeRef root = YGNodeNewWithConfig(config);
|
||||||
YGNodeStyleSetMargin(root, YGEdgeTop, -1.49);
|
YGNodeStyleSetMargin(root, YGEdgeTop, -1.49f);
|
||||||
YGNodeStyleSetWidth(root, 500);
|
YGNodeStyleSetWidth(root, 500);
|
||||||
YGNodeStyleSetHeight(root, 500);
|
YGNodeStyleSetHeight(root, 500);
|
||||||
|
|
||||||
@@ -70,7 +70,7 @@ TEST(YogaTest, consistent_rounding_during_repeated_layouts) {
|
|||||||
|
|
||||||
for (int i = 0; i < 5; i++) {
|
for (int i = 0; i < 5; i++) {
|
||||||
// Dirty the tree so YGRoundToPixelGrid runs again
|
// Dirty the tree so YGRoundToPixelGrid runs again
|
||||||
YGNodeStyleSetMargin(root, YGEdgeLeft, i + 1);
|
YGNodeStyleSetMargin(root, YGEdgeLeft, (float) (i + 1));
|
||||||
|
|
||||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||||
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(node1));
|
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(node1));
|
||||||
|
@@ -57,8 +57,8 @@ TEST(YogaTest, rounding_feature_with_custom_measure_func_floor) {
|
|||||||
|
|
||||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
|
||||||
|
|
||||||
ASSERT_FLOAT_EQ(10.2, YGNodeLayoutGetWidth(root_child0));
|
ASSERT_FLOAT_EQ(10.2f, YGNodeLayoutGetWidth(root_child0));
|
||||||
ASSERT_FLOAT_EQ(10.2, YGNodeLayoutGetHeight(root_child0));
|
ASSERT_FLOAT_EQ(10.2f, YGNodeLayoutGetHeight(root_child0));
|
||||||
|
|
||||||
YGConfigSetPointScaleFactor(config, 1.0f);
|
YGConfigSetPointScaleFactor(config, 1.0f);
|
||||||
|
|
||||||
|
@@ -81,6 +81,9 @@ namespace yoga {
|
|||||||
|
|
||||||
using CompactValue = detail::CompactValue;
|
using CompactValue = detail::CompactValue;
|
||||||
|
|
||||||
|
// TODO: MSVC doesn't like the macros
|
||||||
|
#ifndef _MSC_VER
|
||||||
|
|
||||||
ACCESSOR_TEST(
|
ACCESSOR_TEST(
|
||||||
direction,
|
direction,
|
||||||
YGDirectionInherit,
|
YGDirectionInherit,
|
||||||
@@ -250,5 +253,7 @@ ACCESSOR_TEST(
|
|||||||
YGFloatOptional{0.0f},
|
YGFloatOptional{0.0f},
|
||||||
YGFloatOptional{});
|
YGFloatOptional{});
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
} // namespace yoga
|
} // namespace yoga
|
||||||
} // namespace facebook
|
} // namespace facebook
|
||||||
|
Reference in New Issue
Block a user