2016-10-23 10:40:30 -07:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2014-present, Facebook, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <gtest/gtest.h>
|
2017-01-31 09:28:10 -08:00
|
|
|
#include <yoga/Yoga.h>
|
2016-10-23 10:40:30 -07:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
TEST(YogaTest, assert_default_values) {
|
|
|
|
const YGNodeRef root = YGNodeNew();
|
2016-10-23 10:40:30 -07:00
|
|
|
|
2016-12-16 04:39:13 -08:00
|
|
|
ASSERT_EQ(0, YGNodeGetChildCount(root));
|
2016-12-03 04:40:18 -08:00
|
|
|
ASSERT_EQ(NULL, YGNodeGetChild(root, 1));
|
2016-10-31 12:41:09 -07:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
ASSERT_EQ(YGDirectionInherit, YGNodeStyleGetDirection(root));
|
|
|
|
ASSERT_EQ(YGFlexDirectionColumn, YGNodeStyleGetFlexDirection(root));
|
|
|
|
ASSERT_EQ(YGJustifyFlexStart, YGNodeStyleGetJustifyContent(root));
|
|
|
|
ASSERT_EQ(YGAlignFlexStart, YGNodeStyleGetAlignContent(root));
|
|
|
|
ASSERT_EQ(YGAlignStretch, YGNodeStyleGetAlignItems(root));
|
|
|
|
ASSERT_EQ(YGAlignAuto, YGNodeStyleGetAlignSelf(root));
|
|
|
|
ASSERT_EQ(YGPositionTypeRelative, YGNodeStyleGetPositionType(root));
|
|
|
|
ASSERT_EQ(YGWrapNoWrap, YGNodeStyleGetFlexWrap(root));
|
|
|
|
ASSERT_EQ(YGOverflowVisible, YGNodeStyleGetOverflow(root));
|
|
|
|
ASSERT_FLOAT_EQ(0, YGNodeStyleGetFlexGrow(root));
|
|
|
|
ASSERT_FLOAT_EQ(0, YGNodeStyleGetFlexShrink(root));
|
2017-02-28 09:17:17 -08:00
|
|
|
ASSERT_EQ(YGNodeStyleGetFlexBasis(root).unit, YGUnitAuto);
|
2016-10-23 10:40:30 -07:00
|
|
|
|
2017-02-03 11:19:40 -08:00
|
|
|
ASSERT_EQ(YGNodeStyleGetPosition(root, YGEdgeLeft).unit, YGUnitUndefined);
|
|
|
|
ASSERT_EQ(YGNodeStyleGetPosition(root, YGEdgeTop).unit, YGUnitUndefined);
|
|
|
|
ASSERT_EQ(YGNodeStyleGetPosition(root, YGEdgeRight).unit, YGUnitUndefined);
|
|
|
|
ASSERT_EQ(YGNodeStyleGetPosition(root, YGEdgeBottom).unit, YGUnitUndefined);
|
|
|
|
ASSERT_EQ(YGNodeStyleGetPosition(root, YGEdgeStart).unit, YGUnitUndefined);
|
|
|
|
ASSERT_EQ(YGNodeStyleGetPosition(root, YGEdgeEnd).unit, YGUnitUndefined);
|
2016-10-23 10:40:30 -07:00
|
|
|
|
2017-02-03 11:19:40 -08:00
|
|
|
ASSERT_EQ(YGNodeStyleGetMargin(root, YGEdgeLeft).unit, YGUnitUndefined);
|
|
|
|
ASSERT_EQ(YGNodeStyleGetMargin(root, YGEdgeTop).unit, YGUnitUndefined);
|
|
|
|
ASSERT_EQ(YGNodeStyleGetMargin(root, YGEdgeRight).unit, YGUnitUndefined);
|
|
|
|
ASSERT_EQ(YGNodeStyleGetMargin(root, YGEdgeBottom).unit, YGUnitUndefined);
|
|
|
|
ASSERT_EQ(YGNodeStyleGetMargin(root, YGEdgeStart).unit, YGUnitUndefined);
|
|
|
|
ASSERT_EQ(YGNodeStyleGetMargin(root, YGEdgeEnd).unit, YGUnitUndefined);
|
2016-10-23 10:40:30 -07:00
|
|
|
|
2017-02-03 11:19:40 -08:00
|
|
|
ASSERT_EQ(YGNodeStyleGetPadding(root, YGEdgeLeft).unit, YGUnitUndefined);
|
|
|
|
ASSERT_EQ(YGNodeStyleGetPadding(root, YGEdgeTop).unit, YGUnitUndefined);
|
|
|
|
ASSERT_EQ(YGNodeStyleGetPadding(root, YGEdgeRight).unit, YGUnitUndefined);
|
|
|
|
ASSERT_EQ(YGNodeStyleGetPadding(root, YGEdgeBottom).unit, YGUnitUndefined);
|
|
|
|
ASSERT_EQ(YGNodeStyleGetPadding(root, YGEdgeStart).unit, YGUnitUndefined);
|
|
|
|
ASSERT_EQ(YGNodeStyleGetPadding(root, YGEdgeEnd).unit, YGUnitUndefined);
|
2016-10-23 10:40:30 -07:00
|
|
|
|
2017-02-03 11:19:40 -08:00
|
|
|
ASSERT_TRUE(YGFloatIsUndefined(YGNodeStyleGetBorder(root, YGEdgeLeft)));
|
|
|
|
ASSERT_TRUE(YGFloatIsUndefined(YGNodeStyleGetBorder(root, YGEdgeTop)));
|
|
|
|
ASSERT_TRUE(YGFloatIsUndefined(YGNodeStyleGetBorder(root, YGEdgeRight)));
|
|
|
|
ASSERT_TRUE(YGFloatIsUndefined(YGNodeStyleGetBorder(root, YGEdgeBottom)));
|
Add feature to use percentage as value unit
Summary:
Adds the feature to use percentage as a value unit.
You can use the function ```YGPx(float)``` and ```YGPercent(float)``` for convenience.
I did some benchmarks:
```
Without Percentage Feature - Release x86:
Stack with flex: median: 0.000000 ms, stddev: 0.146683 ms
Align stretch in undefined axis: median: 0.000000 ms, stddev: 0.136525 ms
Nested flex: median: 0.000000 ms, stddev: 0.490101 ms
Huge nested layout: median: 23.000000 ms, stddev: 0.928291 ms
Stack with flex: median: 0.000000 ms, stddev: 0.170587 ms
Align stretch in undefined axis: median: 0.000000 ms, stddev: 0.143384 ms
Nested flex: median: 0.000000 ms, stddev: 0.477791 ms
Huge nested layout: median: 22.000000 ms, stddev: 2.129779 ms
With Percentage Feature - Release x86:
Stack with flex: median: 0.000000 ms, stddev: 0.132951 ms
Align stretch in undefined axis: median: 0.000000 ms, stddev: 0.136525 ms
Nested flex: median: 0.000000 ms, stddev: 0.489570 ms
Huge nested layout: median: 21.000000 ms, stddev: 1.390476 ms
Closes https://github.com/facebook/yoga/pull/258
Reviewed By: dshahidehpour
Differential Revision: D4361945
Pulled By: emilsjolander
fbshipit-source-id: a8f5bc63ad352eb9410d792729e56664468cd76a
2017-01-02 05:20:37 -08:00
|
|
|
ASSERT_TRUE(YGFloatIsUndefined(YGNodeStyleGetBorder(root, YGEdgeStart)));
|
|
|
|
ASSERT_TRUE(YGFloatIsUndefined(YGNodeStyleGetBorder(root, YGEdgeEnd)));
|
2016-10-23 10:40:30 -07:00
|
|
|
|
2017-02-14 14:26:09 -08:00
|
|
|
ASSERT_EQ(YGNodeStyleGetWidth(root).unit, YGUnitAuto);
|
|
|
|
ASSERT_EQ(YGNodeStyleGetHeight(root).unit, YGUnitAuto);
|
2017-02-03 11:19:40 -08:00
|
|
|
ASSERT_EQ(YGNodeStyleGetMinWidth(root).unit, YGUnitUndefined);
|
|
|
|
ASSERT_EQ(YGNodeStyleGetMinHeight(root).unit, YGUnitUndefined);
|
|
|
|
ASSERT_EQ(YGNodeStyleGetMaxWidth(root).unit, YGUnitUndefined);
|
|
|
|
ASSERT_EQ(YGNodeStyleGetMaxHeight(root).unit, YGUnitUndefined);
|
2016-10-23 10:40:30 -07:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
|
|
|
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
|
|
|
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetRight(root));
|
|
|
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetBottom(root));
|
2017-02-03 11:19:40 -08:00
|
|
|
|
|
|
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetMargin(root, YGEdgeLeft));
|
|
|
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetMargin(root, YGEdgeTop));
|
|
|
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetMargin(root, YGEdgeRight));
|
|
|
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetMargin(root, YGEdgeBottom));
|
|
|
|
|
|
|
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetPadding(root, YGEdgeLeft));
|
|
|
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetPadding(root, YGEdgeTop));
|
|
|
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetPadding(root, YGEdgeRight));
|
|
|
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetPadding(root, YGEdgeBottom));
|
|
|
|
|
|
|
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetBorder(root, YGEdgeLeft));
|
|
|
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetBorder(root, YGEdgeTop));
|
|
|
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetBorder(root, YGEdgeRight));
|
|
|
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetBorder(root, YGEdgeBottom));
|
|
|
|
|
Add feature to use percentage as value unit
Summary:
Adds the feature to use percentage as a value unit.
You can use the function ```YGPx(float)``` and ```YGPercent(float)``` for convenience.
I did some benchmarks:
```
Without Percentage Feature - Release x86:
Stack with flex: median: 0.000000 ms, stddev: 0.146683 ms
Align stretch in undefined axis: median: 0.000000 ms, stddev: 0.136525 ms
Nested flex: median: 0.000000 ms, stddev: 0.490101 ms
Huge nested layout: median: 23.000000 ms, stddev: 0.928291 ms
Stack with flex: median: 0.000000 ms, stddev: 0.170587 ms
Align stretch in undefined axis: median: 0.000000 ms, stddev: 0.143384 ms
Nested flex: median: 0.000000 ms, stddev: 0.477791 ms
Huge nested layout: median: 22.000000 ms, stddev: 2.129779 ms
With Percentage Feature - Release x86:
Stack with flex: median: 0.000000 ms, stddev: 0.132951 ms
Align stretch in undefined axis: median: 0.000000 ms, stddev: 0.136525 ms
Nested flex: median: 0.000000 ms, stddev: 0.489570 ms
Huge nested layout: median: 21.000000 ms, stddev: 1.390476 ms
Closes https://github.com/facebook/yoga/pull/258
Reviewed By: dshahidehpour
Differential Revision: D4361945
Pulled By: emilsjolander
fbshipit-source-id: a8f5bc63ad352eb9410d792729e56664468cd76a
2017-01-02 05:20:37 -08:00
|
|
|
ASSERT_TRUE(YGFloatIsUndefined(YGNodeLayoutGetWidth(root)));
|
|
|
|
ASSERT_TRUE(YGFloatIsUndefined(YGNodeLayoutGetHeight(root)));
|
2016-12-03 04:40:18 -08:00
|
|
|
ASSERT_EQ(YGDirectionInherit, YGNodeLayoutGetDirection(root));
|
2016-10-23 10:40:30 -07:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeFreeRecursive(root);
|
2016-10-23 10:40:30 -07:00
|
|
|
}
|
2017-03-03 10:47:42 -08:00
|
|
|
|
|
|
|
TEST(YogaTest, assert_webdefault_values) {
|
2017-05-03 09:22:35 -07:00
|
|
|
YGConfig *config = YGConfigNew();
|
2017-03-03 10:47:42 -08:00
|
|
|
YGConfigSetUseWebDefaults(config, true);
|
|
|
|
const YGNodeRef root = YGNodeNewWithConfig(config);
|
|
|
|
|
|
|
|
ASSERT_EQ(YGFlexDirectionRow, YGNodeStyleGetFlexDirection(root));
|
|
|
|
ASSERT_EQ(YGAlignStretch, YGNodeStyleGetAlignContent(root));
|
|
|
|
ASSERT_FLOAT_EQ(1.0f, YGNodeStyleGetFlexShrink(root));
|
|
|
|
|
|
|
|
YGNodeFreeRecursive(root);
|
|
|
|
YGConfigFree(config);
|
|
|
|
}
|
2017-03-29 03:06:19 -07:00
|
|
|
|
|
|
|
TEST(YogaTest, assert_webdefault_values_reset) {
|
2017-05-03 09:22:35 -07:00
|
|
|
YGConfig *config = YGConfigNew();
|
2017-03-29 03:06:19 -07:00
|
|
|
YGConfigSetUseWebDefaults(config, true);
|
|
|
|
const YGNodeRef root = YGNodeNewWithConfig(config);
|
|
|
|
YGNodeReset(root);
|
|
|
|
|
|
|
|
ASSERT_EQ(YGFlexDirectionRow, YGNodeStyleGetFlexDirection(root));
|
|
|
|
ASSERT_EQ(YGAlignStretch, YGNodeStyleGetAlignContent(root));
|
|
|
|
ASSERT_FLOAT_EQ(1.0f, YGNodeStyleGetFlexShrink(root));
|
|
|
|
|
|
|
|
YGNodeFreeRecursive(root);
|
|
|
|
YGConfigFree(config);
|
|
|
|
}
|