More niche box sizing tests (#1712)

Summary:
Pull Request resolved: https://github.com/facebook/yoga/pull/1712

tsia, add some more advanced tests checking

* percent widths/heights/padding/border
* absolute positioned nodes with content box
* containing block with content box + static
* flex basis (fails now, needs follow up)
* relative padding/border values

All pass but flex basis

Changelog: [Internal]

Reviewed By: NickGerleman

Differential Revision: D63423302

fbshipit-source-id: d117d305072e254af57eaab03a6349176e759327
This commit is contained in:
Joe Vilches
2024-10-01 15:19:22 -07:00
committed by Facebook GitHub Bot
parent 671ae61a39
commit bc236947d0
5 changed files with 3019 additions and 13 deletions

View File

@@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<c57cfea6c33a34e2a67a855138e9833b>>
* @generated SignedSource<<80fa9cf05afc330a721a756dfaf0d1a3>>
* generated by gentest/gentest-driver.ts from gentest/fixtures/YGBoxSizingTest.html
*/
@@ -62,7 +62,7 @@ public class YGBoxSizingTest {
}
@Test
public void test_box_sizing_border_box() {
public void test_box_sizing_border_box_simple() {
YogaConfig config = YogaConfigFactory.create();
final YogaNode root = createNode(config);
@@ -94,6 +94,327 @@ public class YGBoxSizingTest {
assertEquals(100f, root.getLayoutHeight(), 0.0f);
}
@Test
public void test_box_sizing_content_box_percent() {
YogaConfig config = YogaConfigFactory.create();
final YogaNode root = createNode(config);
root.setPositionType(YogaPositionType.ABSOLUTE);
root.setWidth(100f);
root.setHeight(100f);
final YogaNode root_child0 = createNode(config);
root_child0.setPadding(YogaEdge.LEFT, 4);
root_child0.setPadding(YogaEdge.TOP, 4);
root_child0.setPadding(YogaEdge.RIGHT, 4);
root_child0.setPadding(YogaEdge.BOTTOM, 4);
root_child0.setBorder(YogaEdge.LEFT, 16f);
root_child0.setBorder(YogaEdge.TOP, 16f);
root_child0.setBorder(YogaEdge.RIGHT, 16f);
root_child0.setBorder(YogaEdge.BOTTOM, 16f);
root_child0.setWidthPercent(50f);
root_child0.setHeightPercent(25f);
root_child0.setBoxSizing(YogaBoxSizing.CONTENT_BOX);
root.addChildAt(root_child0, 0);
root.setDirection(YogaDirection.LTR);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(100f, root.getLayoutWidth(), 0.0f);
assertEquals(100f, root.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(90f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(65f, root_child0.getLayoutHeight(), 0.0f);
root.setDirection(YogaDirection.RTL);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(100f, root.getLayoutWidth(), 0.0f);
assertEquals(100f, root.getLayoutHeight(), 0.0f);
assertEquals(10f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(90f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(65f, root_child0.getLayoutHeight(), 0.0f);
}
@Test
public void test_box_sizing_border_box_percent() {
YogaConfig config = YogaConfigFactory.create();
final YogaNode root = createNode(config);
root.setPositionType(YogaPositionType.ABSOLUTE);
root.setWidth(100f);
root.setHeight(100f);
final YogaNode root_child0 = createNode(config);
root_child0.setPadding(YogaEdge.LEFT, 4);
root_child0.setPadding(YogaEdge.TOP, 4);
root_child0.setPadding(YogaEdge.RIGHT, 4);
root_child0.setPadding(YogaEdge.BOTTOM, 4);
root_child0.setBorder(YogaEdge.LEFT, 16f);
root_child0.setBorder(YogaEdge.TOP, 16f);
root_child0.setBorder(YogaEdge.RIGHT, 16f);
root_child0.setBorder(YogaEdge.BOTTOM, 16f);
root_child0.setWidthPercent(50f);
root_child0.setHeightPercent(25f);
root.addChildAt(root_child0, 0);
root.setDirection(YogaDirection.LTR);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(100f, root.getLayoutWidth(), 0.0f);
assertEquals(100f, root.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(50f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(40f, root_child0.getLayoutHeight(), 0.0f);
root.setDirection(YogaDirection.RTL);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(100f, root.getLayoutWidth(), 0.0f);
assertEquals(100f, root.getLayoutHeight(), 0.0f);
assertEquals(50f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(50f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(40f, root_child0.getLayoutHeight(), 0.0f);
}
@Test
public void test_box_sizing_content_box_absolute() {
YogaConfig config = YogaConfigFactory.create();
final YogaNode root = createNode(config);
root.setPositionType(YogaPositionType.ABSOLUTE);
root.setWidth(100f);
root.setHeight(100f);
final YogaNode root_child0 = createNode(config);
root_child0.setPositionType(YogaPositionType.ABSOLUTE);
root_child0.setPadding(YogaEdge.LEFT, 12);
root_child0.setPadding(YogaEdge.TOP, 12);
root_child0.setPadding(YogaEdge.RIGHT, 12);
root_child0.setPadding(YogaEdge.BOTTOM, 12);
root_child0.setBorder(YogaEdge.LEFT, 8f);
root_child0.setBorder(YogaEdge.TOP, 8f);
root_child0.setBorder(YogaEdge.RIGHT, 8f);
root_child0.setBorder(YogaEdge.BOTTOM, 8f);
root_child0.setHeightPercent(25f);
root_child0.setBoxSizing(YogaBoxSizing.CONTENT_BOX);
root.addChildAt(root_child0, 0);
root.setDirection(YogaDirection.LTR);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(100f, root.getLayoutWidth(), 0.0f);
assertEquals(100f, root.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(40f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(65f, root_child0.getLayoutHeight(), 0.0f);
root.setDirection(YogaDirection.RTL);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(100f, root.getLayoutWidth(), 0.0f);
assertEquals(100f, root.getLayoutHeight(), 0.0f);
assertEquals(60f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(40f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(65f, root_child0.getLayoutHeight(), 0.0f);
}
@Test
public void test_box_sizing_border_box_absolute() {
YogaConfig config = YogaConfigFactory.create();
final YogaNode root = createNode(config);
root.setPositionType(YogaPositionType.ABSOLUTE);
root.setWidth(100f);
root.setHeight(100f);
final YogaNode root_child0 = createNode(config);
root_child0.setPositionType(YogaPositionType.ABSOLUTE);
root_child0.setPadding(YogaEdge.LEFT, 12);
root_child0.setPadding(YogaEdge.TOP, 12);
root_child0.setPadding(YogaEdge.RIGHT, 12);
root_child0.setPadding(YogaEdge.BOTTOM, 12);
root_child0.setBorder(YogaEdge.LEFT, 8f);
root_child0.setBorder(YogaEdge.TOP, 8f);
root_child0.setBorder(YogaEdge.RIGHT, 8f);
root_child0.setBorder(YogaEdge.BOTTOM, 8f);
root_child0.setHeightPercent(25f);
root.addChildAt(root_child0, 0);
root.setDirection(YogaDirection.LTR);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(100f, root.getLayoutWidth(), 0.0f);
assertEquals(100f, root.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(40f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(40f, root_child0.getLayoutHeight(), 0.0f);
root.setDirection(YogaDirection.RTL);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(100f, root.getLayoutWidth(), 0.0f);
assertEquals(100f, root.getLayoutHeight(), 0.0f);
assertEquals(60f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(40f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(40f, root_child0.getLayoutHeight(), 0.0f);
}
@Test
public void test_box_sizing_content_box_comtaining_block() {
YogaConfig config = YogaConfigFactory.create();
final YogaNode root = createNode(config);
root.setPositionType(YogaPositionType.ABSOLUTE);
root.setPadding(YogaEdge.LEFT, 12);
root.setPadding(YogaEdge.TOP, 12);
root.setPadding(YogaEdge.RIGHT, 12);
root.setPadding(YogaEdge.BOTTOM, 12);
root.setBorder(YogaEdge.LEFT, 8f);
root.setBorder(YogaEdge.TOP, 8f);
root.setBorder(YogaEdge.RIGHT, 8f);
root.setBorder(YogaEdge.BOTTOM, 8f);
root.setWidth(100f);
root.setHeight(100f);
root.setBoxSizing(YogaBoxSizing.CONTENT_BOX);
final YogaNode root_child0 = createNode(config);
root_child0.setPositionType(YogaPositionType.STATIC);
root.addChildAt(root_child0, 0);
final YogaNode root_child0_child0 = createNode(config);
root_child0_child0.setPositionType(YogaPositionType.ABSOLUTE);
root_child0_child0.setWidth(50f);
root_child0_child0.setHeightPercent(25f);
root_child0.addChildAt(root_child0_child0, 0);
root.setDirection(YogaDirection.LTR);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(140f, root.getLayoutWidth(), 0.0f);
assertEquals(140f, root.getLayoutHeight(), 0.0f);
assertEquals(20f, root_child0.getLayoutX(), 0.0f);
assertEquals(20f, root_child0.getLayoutY(), 0.0f);
assertEquals(100f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(0f, root_child0.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child0_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f);
assertEquals(50f, root_child0_child0.getLayoutWidth(), 0.0f);
assertEquals(31f, root_child0_child0.getLayoutHeight(), 0.0f);
root.setDirection(YogaDirection.RTL);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(140f, root.getLayoutWidth(), 0.0f);
assertEquals(140f, root.getLayoutHeight(), 0.0f);
assertEquals(20f, root_child0.getLayoutX(), 0.0f);
assertEquals(20f, root_child0.getLayoutY(), 0.0f);
assertEquals(100f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(0f, root_child0.getLayoutHeight(), 0.0f);
assertEquals(50f, root_child0_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f);
assertEquals(50f, root_child0_child0.getLayoutWidth(), 0.0f);
assertEquals(31f, root_child0_child0.getLayoutHeight(), 0.0f);
}
@Test
public void test_box_sizing_border_box_comtaining_block() {
YogaConfig config = YogaConfigFactory.create();
final YogaNode root = createNode(config);
root.setPositionType(YogaPositionType.ABSOLUTE);
root.setPadding(YogaEdge.LEFT, 12);
root.setPadding(YogaEdge.TOP, 12);
root.setPadding(YogaEdge.RIGHT, 12);
root.setPadding(YogaEdge.BOTTOM, 12);
root.setBorder(YogaEdge.LEFT, 8f);
root.setBorder(YogaEdge.TOP, 8f);
root.setBorder(YogaEdge.RIGHT, 8f);
root.setBorder(YogaEdge.BOTTOM, 8f);
root.setWidth(100f);
root.setHeight(100f);
final YogaNode root_child0 = createNode(config);
root_child0.setPositionType(YogaPositionType.STATIC);
root.addChildAt(root_child0, 0);
final YogaNode root_child0_child0 = createNode(config);
root_child0_child0.setPositionType(YogaPositionType.ABSOLUTE);
root_child0_child0.setWidth(50f);
root_child0_child0.setHeightPercent(25f);
root_child0.addChildAt(root_child0_child0, 0);
root.setDirection(YogaDirection.LTR);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(100f, root.getLayoutWidth(), 0.0f);
assertEquals(100f, root.getLayoutHeight(), 0.0f);
assertEquals(20f, root_child0.getLayoutX(), 0.0f);
assertEquals(20f, root_child0.getLayoutY(), 0.0f);
assertEquals(60f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(0f, root_child0.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child0_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f);
assertEquals(50f, root_child0_child0.getLayoutWidth(), 0.0f);
assertEquals(21f, root_child0_child0.getLayoutHeight(), 0.0f);
root.setDirection(YogaDirection.RTL);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(100f, root.getLayoutWidth(), 0.0f);
assertEquals(100f, root.getLayoutHeight(), 0.0f);
assertEquals(20f, root_child0.getLayoutX(), 0.0f);
assertEquals(20f, root_child0.getLayoutY(), 0.0f);
assertEquals(60f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(0f, root_child0.getLayoutHeight(), 0.0f);
assertEquals(10f, root_child0_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f);
assertEquals(50f, root_child0_child0.getLayoutWidth(), 0.0f);
assertEquals(21f, root_child0_child0.getLayoutHeight(), 0.0f);
}
@Test
public void test_box_sizing_content_box_padding_only() {
YogaConfig config = YogaConfigFactory.create();
@@ -124,6 +445,50 @@ public class YGBoxSizingTest {
assertEquals(110f, root.getLayoutHeight(), 0.0f);
}
@Test
public void test_box_sizing_content_box_padding_only_percent() {
YogaConfig config = YogaConfigFactory.create();
final YogaNode root = createNode(config);
root.setPositionType(YogaPositionType.ABSOLUTE);
root.setWidth(100f);
root.setHeight(100f);
final YogaNode root_child0 = createNode(config);
root_child0.setPaddingPercent(YogaEdge.LEFT, 10);
root_child0.setPaddingPercent(YogaEdge.TOP, 10);
root_child0.setPaddingPercent(YogaEdge.RIGHT, 10);
root_child0.setPaddingPercent(YogaEdge.BOTTOM, 10);
root_child0.setWidthPercent(50f);
root_child0.setBoxSizing(YogaBoxSizing.CONTENT_BOX);
root.addChildAt(root_child0, 0);
root.setDirection(YogaDirection.LTR);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(100f, root.getLayoutWidth(), 0.0f);
assertEquals(100f, root.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(70f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(20f, root_child0.getLayoutHeight(), 0.0f);
root.setDirection(YogaDirection.RTL);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(100f, root.getLayoutWidth(), 0.0f);
assertEquals(100f, root.getLayoutHeight(), 0.0f);
assertEquals(30f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(70f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(20f, root_child0.getLayoutHeight(), 0.0f);
}
@Test
public void test_box_sizing_border_box_padding_only() {
YogaConfig config = YogaConfigFactory.create();
@@ -153,6 +518,49 @@ public class YGBoxSizingTest {
assertEquals(100f, root.getLayoutHeight(), 0.0f);
}
@Test
public void test_box_sizing_border_box_padding_only_percent() {
YogaConfig config = YogaConfigFactory.create();
final YogaNode root = createNode(config);
root.setPositionType(YogaPositionType.ABSOLUTE);
root.setWidth(100f);
root.setHeight(100f);
final YogaNode root_child0 = createNode(config);
root_child0.setPaddingPercent(YogaEdge.LEFT, 10);
root_child0.setPaddingPercent(YogaEdge.TOP, 10);
root_child0.setPaddingPercent(YogaEdge.RIGHT, 10);
root_child0.setPaddingPercent(YogaEdge.BOTTOM, 10);
root_child0.setWidthPercent(50f);
root.addChildAt(root_child0, 0);
root.setDirection(YogaDirection.LTR);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(100f, root.getLayoutWidth(), 0.0f);
assertEquals(100f, root.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(50f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(20f, root_child0.getLayoutHeight(), 0.0f);
root.setDirection(YogaDirection.RTL);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(100f, root.getLayoutWidth(), 0.0f);
assertEquals(100f, root.getLayoutHeight(), 0.0f);
assertEquals(50f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(50f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(20f, root_child0.getLayoutHeight(), 0.0f);
}
@Test
public void test_box_sizing_content_box_border_only() {
YogaConfig config = YogaConfigFactory.create();
@@ -183,6 +591,46 @@ public class YGBoxSizingTest {
assertEquals(120f, root.getLayoutHeight(), 0.0f);
}
@Test
public void test_box_sizing_content_box_border_only_percent() {
YogaConfig config = YogaConfigFactory.create();
final YogaNode root = createNode(config);
root.setPositionType(YogaPositionType.ABSOLUTE);
root.setWidth(100f);
root.setHeight(100f);
final YogaNode root_child0 = createNode(config);
root_child0.setWidthPercent(50f);
root_child0.setBoxSizing(YogaBoxSizing.CONTENT_BOX);
root.addChildAt(root_child0, 0);
root.setDirection(YogaDirection.LTR);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(100f, root.getLayoutWidth(), 0.0f);
assertEquals(100f, root.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(50f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(0f, root_child0.getLayoutHeight(), 0.0f);
root.setDirection(YogaDirection.RTL);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(100f, root.getLayoutWidth(), 0.0f);
assertEquals(100f, root.getLayoutHeight(), 0.0f);
assertEquals(50f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(50f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(0f, root_child0.getLayoutHeight(), 0.0f);
}
@Test
public void test_box_sizing_border_box_border_only() {
YogaConfig config = YogaConfigFactory.create();
@@ -212,6 +660,45 @@ public class YGBoxSizingTest {
assertEquals(100f, root.getLayoutHeight(), 0.0f);
}
@Test
public void test_box_sizing_border_box_border_only_percent() {
YogaConfig config = YogaConfigFactory.create();
final YogaNode root = createNode(config);
root.setPositionType(YogaPositionType.ABSOLUTE);
root.setWidth(100f);
root.setHeight(100f);
final YogaNode root_child0 = createNode(config);
root_child0.setWidthPercent(50f);
root.addChildAt(root_child0, 0);
root.setDirection(YogaDirection.LTR);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(100f, root.getLayoutWidth(), 0.0f);
assertEquals(100f, root.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(50f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(0f, root_child0.getLayoutHeight(), 0.0f);
root.setDirection(YogaDirection.RTL);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(100f, root.getLayoutWidth(), 0.0f);
assertEquals(100f, root.getLayoutHeight(), 0.0f);
assertEquals(50f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(50f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(0f, root_child0.getLayoutHeight(), 0.0f);
}
@Test
public void test_box_sizing_content_box_no_padding_no_border() {
YogaConfig config = YogaConfigFactory.create();
@@ -1607,6 +2094,416 @@ public class YGBoxSizingTest {
assertEquals(9f, root_child0_child0_child0.getLayoutHeight(), 0.0f);
}
@Test
@Ignore
public void test_box_sizing_content_box_flex_basis_row() {
YogaConfig config = YogaConfigFactory.create();
final YogaNode root = createNode(config);
root.setFlexDirection(YogaFlexDirection.ROW);
root.setPositionType(YogaPositionType.ABSOLUTE);
root.setWidth(100f);
root.setHeight(100f);
final YogaNode root_child0 = createNode(config);
root_child0.setFlexBasis(50f);
root_child0.setPadding(YogaEdge.LEFT, 5);
root_child0.setPadding(YogaEdge.TOP, 5);
root_child0.setPadding(YogaEdge.RIGHT, 5);
root_child0.setPadding(YogaEdge.BOTTOM, 5);
root_child0.setBorder(YogaEdge.LEFT, 10f);
root_child0.setBorder(YogaEdge.TOP, 10f);
root_child0.setBorder(YogaEdge.RIGHT, 10f);
root_child0.setBorder(YogaEdge.BOTTOM, 10f);
root_child0.setHeight(25f);
root_child0.setBoxSizing(YogaBoxSizing.CONTENT_BOX);
root.addChildAt(root_child0, 0);
root.setDirection(YogaDirection.LTR);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(100f, root.getLayoutWidth(), 0.0f);
assertEquals(100f, root.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(80f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(55f, root_child0.getLayoutHeight(), 0.0f);
root.setDirection(YogaDirection.RTL);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(100f, root.getLayoutWidth(), 0.0f);
assertEquals(100f, root.getLayoutHeight(), 0.0f);
assertEquals(20f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(80f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(55f, root_child0.getLayoutHeight(), 0.0f);
}
@Test
public void test_box_sizing_border_box_flex_basis_row() {
YogaConfig config = YogaConfigFactory.create();
final YogaNode root = createNode(config);
root.setFlexDirection(YogaFlexDirection.ROW);
root.setPositionType(YogaPositionType.ABSOLUTE);
root.setWidth(100f);
root.setHeight(100f);
final YogaNode root_child0 = createNode(config);
root_child0.setFlexBasis(50f);
root_child0.setPadding(YogaEdge.LEFT, 5);
root_child0.setPadding(YogaEdge.TOP, 5);
root_child0.setPadding(YogaEdge.RIGHT, 5);
root_child0.setPadding(YogaEdge.BOTTOM, 5);
root_child0.setBorder(YogaEdge.LEFT, 10f);
root_child0.setBorder(YogaEdge.TOP, 10f);
root_child0.setBorder(YogaEdge.RIGHT, 10f);
root_child0.setBorder(YogaEdge.BOTTOM, 10f);
root_child0.setHeight(25f);
root.addChildAt(root_child0, 0);
root.setDirection(YogaDirection.LTR);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(100f, root.getLayoutWidth(), 0.0f);
assertEquals(100f, root.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(50f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(30f, root_child0.getLayoutHeight(), 0.0f);
root.setDirection(YogaDirection.RTL);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(100f, root.getLayoutWidth(), 0.0f);
assertEquals(100f, root.getLayoutHeight(), 0.0f);
assertEquals(50f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(50f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(30f, root_child0.getLayoutHeight(), 0.0f);
}
@Test
@Ignore
public void test_box_sizing_content_box_flex_basis_column() {
YogaConfig config = YogaConfigFactory.create();
final YogaNode root = createNode(config);
root.setPositionType(YogaPositionType.ABSOLUTE);
root.setWidth(100f);
root.setHeight(100f);
final YogaNode root_child0 = createNode(config);
root_child0.setFlexBasis(50f);
root_child0.setPadding(YogaEdge.LEFT, 5);
root_child0.setPadding(YogaEdge.TOP, 5);
root_child0.setPadding(YogaEdge.RIGHT, 5);
root_child0.setPadding(YogaEdge.BOTTOM, 5);
root_child0.setBorder(YogaEdge.LEFT, 10f);
root_child0.setBorder(YogaEdge.TOP, 10f);
root_child0.setBorder(YogaEdge.RIGHT, 10f);
root_child0.setBorder(YogaEdge.BOTTOM, 10f);
root_child0.setHeight(25f);
root_child0.setBoxSizing(YogaBoxSizing.CONTENT_BOX);
root.addChildAt(root_child0, 0);
root.setDirection(YogaDirection.LTR);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(100f, root.getLayoutWidth(), 0.0f);
assertEquals(100f, root.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(100f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(80f, root_child0.getLayoutHeight(), 0.0f);
root.setDirection(YogaDirection.RTL);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(100f, root.getLayoutWidth(), 0.0f);
assertEquals(100f, root.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(100f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(80f, root_child0.getLayoutHeight(), 0.0f);
}
@Test
public void test_box_sizing_border_box_flex_basis_column() {
YogaConfig config = YogaConfigFactory.create();
final YogaNode root = createNode(config);
root.setPositionType(YogaPositionType.ABSOLUTE);
root.setWidth(100f);
root.setHeight(100f);
final YogaNode root_child0 = createNode(config);
root_child0.setFlexBasis(50f);
root_child0.setPadding(YogaEdge.LEFT, 5);
root_child0.setPadding(YogaEdge.TOP, 5);
root_child0.setPadding(YogaEdge.RIGHT, 5);
root_child0.setPadding(YogaEdge.BOTTOM, 5);
root_child0.setBorder(YogaEdge.LEFT, 10f);
root_child0.setBorder(YogaEdge.TOP, 10f);
root_child0.setBorder(YogaEdge.RIGHT, 10f);
root_child0.setBorder(YogaEdge.BOTTOM, 10f);
root_child0.setHeight(25f);
root.addChildAt(root_child0, 0);
root.setDirection(YogaDirection.LTR);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(100f, root.getLayoutWidth(), 0.0f);
assertEquals(100f, root.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(100f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(50f, root_child0.getLayoutHeight(), 0.0f);
root.setDirection(YogaDirection.RTL);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(100f, root.getLayoutWidth(), 0.0f);
assertEquals(100f, root.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(100f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(50f, root_child0.getLayoutHeight(), 0.0f);
}
@Test
public void test_box_sizing_content_box_padding_start() {
YogaConfig config = YogaConfigFactory.create();
final YogaNode root = createNode(config);
root.setPositionType(YogaPositionType.ABSOLUTE);
root.setPadding(YogaEdge.START, 5);
root.setWidth(100f);
root.setHeight(100f);
root.setBoxSizing(YogaBoxSizing.CONTENT_BOX);
root.setDirection(YogaDirection.LTR);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(105f, root.getLayoutWidth(), 0.0f);
assertEquals(100f, root.getLayoutHeight(), 0.0f);
root.setDirection(YogaDirection.RTL);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(105f, root.getLayoutWidth(), 0.0f);
assertEquals(100f, root.getLayoutHeight(), 0.0f);
}
@Test
public void test_box_sizing_border_box_padding_start() {
YogaConfig config = YogaConfigFactory.create();
final YogaNode root = createNode(config);
root.setPositionType(YogaPositionType.ABSOLUTE);
root.setPadding(YogaEdge.START, 5);
root.setWidth(100f);
root.setHeight(100f);
root.setDirection(YogaDirection.LTR);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(100f, root.getLayoutWidth(), 0.0f);
assertEquals(100f, root.getLayoutHeight(), 0.0f);
root.setDirection(YogaDirection.RTL);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(100f, root.getLayoutWidth(), 0.0f);
assertEquals(100f, root.getLayoutHeight(), 0.0f);
}
@Test
public void test_box_sizing_content_box_padding_end() {
YogaConfig config = YogaConfigFactory.create();
final YogaNode root = createNode(config);
root.setPositionType(YogaPositionType.ABSOLUTE);
root.setPadding(YogaEdge.END, 5);
root.setWidth(100f);
root.setHeight(100f);
root.setBoxSizing(YogaBoxSizing.CONTENT_BOX);
root.setDirection(YogaDirection.LTR);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(105f, root.getLayoutWidth(), 0.0f);
assertEquals(100f, root.getLayoutHeight(), 0.0f);
root.setDirection(YogaDirection.RTL);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(105f, root.getLayoutWidth(), 0.0f);
assertEquals(100f, root.getLayoutHeight(), 0.0f);
}
@Test
public void test_box_sizing_border_box_padding_end() {
YogaConfig config = YogaConfigFactory.create();
final YogaNode root = createNode(config);
root.setPositionType(YogaPositionType.ABSOLUTE);
root.setPadding(YogaEdge.END, 5);
root.setWidth(100f);
root.setHeight(100f);
root.setDirection(YogaDirection.LTR);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(100f, root.getLayoutWidth(), 0.0f);
assertEquals(100f, root.getLayoutHeight(), 0.0f);
root.setDirection(YogaDirection.RTL);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(100f, root.getLayoutWidth(), 0.0f);
assertEquals(100f, root.getLayoutHeight(), 0.0f);
}
@Test
public void test_box_sizing_content_box_border_start() {
YogaConfig config = YogaConfigFactory.create();
final YogaNode root = createNode(config);
root.setPositionType(YogaPositionType.ABSOLUTE);
root.setBorder(YogaEdge.START, 5f);
root.setWidth(100f);
root.setHeight(100f);
root.setBoxSizing(YogaBoxSizing.CONTENT_BOX);
root.setDirection(YogaDirection.LTR);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(105f, root.getLayoutWidth(), 0.0f);
assertEquals(100f, root.getLayoutHeight(), 0.0f);
root.setDirection(YogaDirection.RTL);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(105f, root.getLayoutWidth(), 0.0f);
assertEquals(100f, root.getLayoutHeight(), 0.0f);
}
@Test
public void test_box_sizing_border_box_border_start() {
YogaConfig config = YogaConfigFactory.create();
final YogaNode root = createNode(config);
root.setPositionType(YogaPositionType.ABSOLUTE);
root.setBorder(YogaEdge.START, 5f);
root.setWidth(100f);
root.setHeight(100f);
root.setDirection(YogaDirection.LTR);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(100f, root.getLayoutWidth(), 0.0f);
assertEquals(100f, root.getLayoutHeight(), 0.0f);
root.setDirection(YogaDirection.RTL);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(100f, root.getLayoutWidth(), 0.0f);
assertEquals(100f, root.getLayoutHeight(), 0.0f);
}
@Test
public void test_box_sizing_content_box_border_end() {
YogaConfig config = YogaConfigFactory.create();
final YogaNode root = createNode(config);
root.setPositionType(YogaPositionType.ABSOLUTE);
root.setBorder(YogaEdge.END, 5f);
root.setWidth(100f);
root.setHeight(100f);
root.setBoxSizing(YogaBoxSizing.CONTENT_BOX);
root.setDirection(YogaDirection.LTR);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(105f, root.getLayoutWidth(), 0.0f);
assertEquals(100f, root.getLayoutHeight(), 0.0f);
root.setDirection(YogaDirection.RTL);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(105f, root.getLayoutWidth(), 0.0f);
assertEquals(100f, root.getLayoutHeight(), 0.0f);
}
@Test
public void test_box_sizing_border_box_border_end() {
YogaConfig config = YogaConfigFactory.create();
final YogaNode root = createNode(config);
root.setPositionType(YogaPositionType.ABSOLUTE);
root.setBorder(YogaEdge.END, 5f);
root.setWidth(100f);
root.setHeight(100f);
root.setDirection(YogaDirection.LTR);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(100f, root.getLayoutWidth(), 0.0f);
assertEquals(100f, root.getLayoutHeight(), 0.0f);
root.setDirection(YogaDirection.RTL);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(100f, root.getLayoutWidth(), 0.0f);
assertEquals(100f, root.getLayoutHeight(), 0.0f);
}
private YogaNode createNode(YogaConfig config) {
return mNodeFactory.create(config);
}