2016-11-23 11:12:51 -08:00
|
|
|
/**
|
2018-09-11 15:27:47 -07:00
|
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
2016-11-23 11:12:51 -08:00
|
|
|
*
|
2018-02-16 18:24:55 -08:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2016-11-23 11:12:51 -08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <gtest/gtest.h>
|
2017-12-19 11:18:00 -08:00
|
|
|
#include <yoga/YGNode.h>
|
2017-01-31 09:28:10 -08:00
|
|
|
#include <yoga/Yoga.h>
|
2016-11-23 11:12:51 -08:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
static YGSize _measureFloor(YGNodeRef node,
|
2017-01-31 09:28:10 -08:00
|
|
|
float width,
|
|
|
|
YGMeasureMode widthMode,
|
|
|
|
float height,
|
|
|
|
YGMeasureMode heightMode) {
|
2016-12-03 04:40:18 -08:00
|
|
|
return YGSize{
|
2017-01-31 09:28:10 -08:00
|
|
|
width = 10.2f, height = 10.2f,
|
2016-11-23 11:12:51 -08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
static YGSize _measureCeil(YGNodeRef node,
|
2017-01-31 09:28:10 -08:00
|
|
|
float width,
|
|
|
|
YGMeasureMode widthMode,
|
|
|
|
float height,
|
|
|
|
YGMeasureMode heightMode) {
|
2016-12-03 04:40:18 -08:00
|
|
|
return YGSize{
|
2017-07-04 06:18:49 -07:00
|
|
|
width = 10.5f, height = 10.5f,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
static YGSize _measureFractial(YGNodeRef node,
|
|
|
|
float width,
|
|
|
|
YGMeasureMode widthMode,
|
|
|
|
float height,
|
|
|
|
YGMeasureMode heightMode) {
|
|
|
|
return YGSize{
|
|
|
|
width = 0.5f, height = 0.5f,
|
2016-11-23 11:12:51 -08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
TEST(YogaTest, rounding_feature_with_custom_measure_func_floor) {
|
2017-03-01 09:19:55 -08:00
|
|
|
const YGConfigRef config = YGConfigNew();
|
|
|
|
const YGNodeRef root = YGNodeNewWithConfig(config);
|
2016-11-23 11:12:51 -08:00
|
|
|
|
2017-03-01 09:19:55 -08:00
|
|
|
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
|
2017-12-19 11:18:00 -08:00
|
|
|
root_child0->setMeasureFunc(_measureFloor);
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeInsertChild(root, root_child0, 0);
|
2016-11-23 11:12:51 -08:00
|
|
|
|
2017-03-09 07:21:23 -08:00
|
|
|
YGConfigSetPointScaleFactor(config, 0.0f);
|
2017-03-01 09:19:55 -08:00
|
|
|
|
2017-02-24 09:45:31 -08:00
|
|
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
|
2017-03-01 09:19:55 -08:00
|
|
|
|
2017-02-24 09:45:31 -08:00
|
|
|
ASSERT_FLOAT_EQ(10.2, YGNodeLayoutGetWidth(root_child0));
|
|
|
|
ASSERT_FLOAT_EQ(10.2, YGNodeLayoutGetHeight(root_child0));
|
|
|
|
|
2017-03-09 07:21:23 -08:00
|
|
|
YGConfigSetPointScaleFactor(config, 1.0f);
|
2017-02-24 09:45:31 -08:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
2016-11-23 11:12:51 -08:00
|
|
|
|
2017-04-30 03:03:43 -07:00
|
|
|
ASSERT_FLOAT_EQ(11, YGNodeLayoutGetWidth(root_child0));
|
|
|
|
ASSERT_FLOAT_EQ(11, YGNodeLayoutGetHeight(root_child0));
|
2017-03-01 09:19:55 -08:00
|
|
|
|
2017-03-09 07:21:23 -08:00
|
|
|
YGConfigSetPointScaleFactor(config, 2.0f);
|
2017-02-24 09:45:31 -08:00
|
|
|
|
|
|
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
|
|
|
|
|
2017-04-30 03:03:43 -07:00
|
|
|
ASSERT_FLOAT_EQ(10.5, YGNodeLayoutGetWidth(root_child0));
|
|
|
|
ASSERT_FLOAT_EQ(10.5, YGNodeLayoutGetHeight(root_child0));
|
2017-03-01 09:19:55 -08:00
|
|
|
|
2017-03-09 07:21:23 -08:00
|
|
|
YGConfigSetPointScaleFactor(config, 4.0f);
|
2017-03-01 09:19:55 -08:00
|
|
|
|
2017-02-24 09:45:31 -08:00
|
|
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
2017-03-01 09:19:55 -08:00
|
|
|
|
2017-04-30 03:03:43 -07:00
|
|
|
ASSERT_FLOAT_EQ(10.25, YGNodeLayoutGetWidth(root_child0));
|
2017-02-24 09:45:31 -08:00
|
|
|
ASSERT_FLOAT_EQ(10.25, YGNodeLayoutGetHeight(root_child0));
|
|
|
|
|
2017-03-09 07:21:23 -08:00
|
|
|
YGConfigSetPointScaleFactor(config, 1.0f / 3.0f);
|
2017-03-01 09:19:55 -08:00
|
|
|
|
2017-02-24 09:45:31 -08:00
|
|
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
|
2017-03-01 09:19:55 -08:00
|
|
|
|
2017-04-30 03:03:43 -07:00
|
|
|
ASSERT_FLOAT_EQ(12.0, YGNodeLayoutGetWidth(root_child0));
|
|
|
|
ASSERT_FLOAT_EQ(12.0, YGNodeLayoutGetHeight(root_child0));
|
2016-11-23 11:12:51 -08:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeFreeRecursive(root);
|
2016-11-23 11:12:51 -08:00
|
|
|
|
2017-03-01 09:19:55 -08:00
|
|
|
YGConfigFree(config);
|
2016-11-23 11:12:51 -08:00
|
|
|
}
|
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
TEST(YogaTest, rounding_feature_with_custom_measure_func_ceil) {
|
2017-03-01 09:19:55 -08:00
|
|
|
const YGConfigRef config = YGConfigNew();
|
|
|
|
const YGNodeRef root = YGNodeNewWithConfig(config);
|
2016-11-23 11:12:51 -08:00
|
|
|
|
2017-03-01 09:19:55 -08:00
|
|
|
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
|
2017-12-19 11:18:00 -08:00
|
|
|
root_child0->setMeasureFunc(_measureCeil);
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeInsertChild(root, root_child0, 0);
|
2016-11-23 11:12:51 -08:00
|
|
|
|
2017-03-09 07:21:23 -08:00
|
|
|
YGConfigSetPointScaleFactor(config, 1.0f);
|
2017-02-24 09:45:31 -08:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
2016-11-23 11:12:51 -08:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
ASSERT_FLOAT_EQ(11, YGNodeLayoutGetWidth(root_child0));
|
|
|
|
ASSERT_FLOAT_EQ(11, YGNodeLayoutGetHeight(root_child0));
|
2016-11-23 11:12:51 -08:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeFreeRecursive(root);
|
2016-11-23 11:12:51 -08:00
|
|
|
|
2017-03-01 09:19:55 -08:00
|
|
|
YGConfigFree(config);
|
2016-11-23 11:12:51 -08:00
|
|
|
}
|
2017-07-04 06:18:49 -07:00
|
|
|
|
|
|
|
TEST(YogaTest, rounding_feature_with_custom_measure_and_fractial_matching_scale) {
|
|
|
|
const YGConfigRef config = YGConfigNew();
|
|
|
|
const YGNodeRef root = YGNodeNewWithConfig(config);
|
|
|
|
|
|
|
|
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
|
|
|
|
YGNodeStyleSetPosition(root_child0, YGEdgeLeft, 73.625);
|
2017-12-19 11:18:00 -08:00
|
|
|
root_child0->setMeasureFunc(_measureFractial);
|
2017-07-04 06:18:49 -07:00
|
|
|
YGNodeInsertChild(root, root_child0, 0);
|
|
|
|
|
|
|
|
YGConfigSetPointScaleFactor(config, 2.0f);
|
|
|
|
|
|
|
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
|
|
|
|
|
|
|
ASSERT_FLOAT_EQ(0.5, YGNodeLayoutGetWidth(root_child0));
|
|
|
|
ASSERT_FLOAT_EQ(0.5, YGNodeLayoutGetHeight(root_child0));
|
|
|
|
ASSERT_FLOAT_EQ(73.5, YGNodeLayoutGetLeft(root_child0));
|
|
|
|
|
|
|
|
YGNodeFreeRecursive(root);
|
|
|
|
|
|
|
|
YGConfigFree(config);
|
|
|
|
}
|