2019-06-06 19:36:56 -07:00
|
|
|
/*
|
2022-10-04 13:59:32 -07:00
|
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
2017-01-15 15:16:10 -08:00
|
|
|
*
|
2019-10-15 10:30:08 -07:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2017-01-15 15:16:10 -08:00
|
|
|
*/
|
2019-10-15 10:30:08 -07:00
|
|
|
|
2017-01-15 15:16:10 -08:00
|
|
|
#include <gtest/gtest.h>
|
2017-01-31 09:28:10 -08:00
|
|
|
#include <yoga/Yoga.h>
|
2018-10-12 15:04:54 -07:00
|
|
|
#include <array>
|
2017-01-15 15:16:10 -08:00
|
|
|
|
|
|
|
TEST(YogaTest, computed_layout_margin) {
|
2024-07-03 17:30:10 -07:00
|
|
|
YGNodeRef root = YGNodeNew();
|
2017-01-15 15:16:10 -08:00
|
|
|
YGNodeStyleSetWidth(root, 100);
|
|
|
|
YGNodeStyleSetHeight(root, 100);
|
|
|
|
YGNodeStyleSetMarginPercent(root, YGEdgeStart, 10);
|
|
|
|
|
|
|
|
YGNodeCalculateLayout(root, 100, 100, YGDirectionLTR);
|
|
|
|
|
|
|
|
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetMargin(root, YGEdgeLeft));
|
|
|
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetMargin(root, YGEdgeRight));
|
|
|
|
|
|
|
|
YGNodeCalculateLayout(root, 100, 100, YGDirectionRTL);
|
|
|
|
|
|
|
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetMargin(root, YGEdgeLeft));
|
|
|
|
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetMargin(root, YGEdgeRight));
|
|
|
|
|
|
|
|
YGNodeFreeRecursive(root);
|
|
|
|
}
|
2018-10-12 15:04:54 -07:00
|
|
|
|
|
|
|
TEST(YogaTest, margin_side_overrides_horizontal_and_vertical) {
|
2021-01-10 10:03:53 -08:00
|
|
|
const std::array<YGEdge, 6> edges = {
|
|
|
|
{YGEdgeTop,
|
|
|
|
YGEdgeBottom,
|
|
|
|
YGEdgeStart,
|
|
|
|
YGEdgeEnd,
|
|
|
|
YGEdgeLeft,
|
|
|
|
YGEdgeRight}};
|
2018-10-12 15:04:54 -07:00
|
|
|
|
|
|
|
for (float edgeValue = 0; edgeValue < 2; ++edgeValue) {
|
|
|
|
for (const auto& edge : edges) {
|
|
|
|
YGEdge horizontalOrVertical = edge == YGEdgeTop || edge == YGEdgeBottom
|
|
|
|
? YGEdgeVertical
|
|
|
|
: YGEdgeHorizontal;
|
|
|
|
|
2024-07-03 17:30:10 -07:00
|
|
|
YGNodeRef root = YGNodeNew();
|
2018-10-12 15:04:54 -07:00
|
|
|
YGNodeStyleSetWidth(root, 100);
|
|
|
|
YGNodeStyleSetHeight(root, 100);
|
|
|
|
YGNodeStyleSetMargin(root, horizontalOrVertical, 10);
|
|
|
|
YGNodeStyleSetMargin(root, edge, edgeValue);
|
|
|
|
|
|
|
|
YGNodeCalculateLayout(root, 100, 100, YGDirectionLTR);
|
|
|
|
|
|
|
|
ASSERT_FLOAT_EQ(edgeValue, YGNodeLayoutGetMargin(root, edge));
|
|
|
|
|
|
|
|
YGNodeFreeRecursive(root);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(YogaTest, margin_side_overrides_all) {
|
2021-01-10 10:03:53 -08:00
|
|
|
const std::array<YGEdge, 6> edges = {
|
|
|
|
{YGEdgeTop,
|
|
|
|
YGEdgeBottom,
|
|
|
|
YGEdgeStart,
|
|
|
|
YGEdgeEnd,
|
|
|
|
YGEdgeLeft,
|
|
|
|
YGEdgeRight}};
|
2018-10-12 15:04:54 -07:00
|
|
|
|
|
|
|
for (float edgeValue = 0; edgeValue < 2; ++edgeValue) {
|
|
|
|
for (const auto& edge : edges) {
|
2024-07-03 17:30:10 -07:00
|
|
|
YGNodeRef root = YGNodeNew();
|
2018-10-12 15:04:54 -07:00
|
|
|
YGNodeStyleSetWidth(root, 100);
|
|
|
|
YGNodeStyleSetHeight(root, 100);
|
|
|
|
YGNodeStyleSetMargin(root, YGEdgeAll, 10);
|
|
|
|
YGNodeStyleSetMargin(root, edge, edgeValue);
|
|
|
|
|
|
|
|
YGNodeCalculateLayout(root, 100, 100, YGDirectionLTR);
|
|
|
|
|
|
|
|
ASSERT_FLOAT_EQ(edgeValue, YGNodeLayoutGetMargin(root, edge));
|
|
|
|
|
|
|
|
YGNodeFreeRecursive(root);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(YogaTest, margin_horizontal_and_vertical_overrides_all) {
|
|
|
|
const std::array<YGEdge, 2> directions = {{YGEdgeHorizontal, YGEdgeVertical}};
|
|
|
|
|
|
|
|
for (float directionValue = 0; directionValue < 2; ++directionValue) {
|
|
|
|
for (const auto& direction : directions) {
|
2024-07-03 17:30:10 -07:00
|
|
|
YGNodeRef root = YGNodeNew();
|
2018-10-12 15:04:54 -07:00
|
|
|
YGNodeStyleSetWidth(root, 100);
|
|
|
|
YGNodeStyleSetHeight(root, 100);
|
|
|
|
YGNodeStyleSetMargin(root, YGEdgeAll, 10);
|
|
|
|
YGNodeStyleSetMargin(root, direction, directionValue);
|
|
|
|
|
|
|
|
YGNodeCalculateLayout(root, 100, 100, YGDirectionLTR);
|
|
|
|
|
|
|
|
if (direction == YGEdgeVertical) {
|
|
|
|
ASSERT_FLOAT_EQ(directionValue, YGNodeLayoutGetMargin(root, YGEdgeTop));
|
|
|
|
ASSERT_FLOAT_EQ(
|
|
|
|
directionValue, YGNodeLayoutGetMargin(root, YGEdgeBottom));
|
|
|
|
} else {
|
|
|
|
ASSERT_FLOAT_EQ(
|
|
|
|
directionValue, YGNodeLayoutGetMargin(root, YGEdgeStart));
|
|
|
|
ASSERT_FLOAT_EQ(directionValue, YGNodeLayoutGetMargin(root, YGEdgeEnd));
|
|
|
|
ASSERT_FLOAT_EQ(
|
|
|
|
directionValue, YGNodeLayoutGetMargin(root, YGEdgeLeft));
|
|
|
|
ASSERT_FLOAT_EQ(
|
|
|
|
directionValue, YGNodeLayoutGetMargin(root, YGEdgeRight));
|
|
|
|
}
|
|
|
|
|
|
|
|
YGNodeFreeRecursive(root);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|