2016-10-23 10:27:32 -07:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2014-present, Facebook, Inc.
|
|
|
|
*
|
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-10-23 10:27:32 -07:00
|
|
|
*/
|
|
|
|
|
2017-01-31 09:28:09 -08:00
|
|
|
// @Generated by gentest/gentest.rb from gentest/fixtures/YGPaddingTest.html
|
2016-10-23 10:27:32 -07:00
|
|
|
|
2016-12-05 02:56:20 -08:00
|
|
|
package com.facebook.yoga;
|
2016-10-23 10:27:32 -07:00
|
|
|
|
|
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
|
|
2016-12-03 04:40:21 -08:00
|
|
|
public class YGPaddingTest {
|
2016-10-23 10:27:32 -07:00
|
|
|
@Test
|
|
|
|
public void test_padding_no_size() {
|
2017-03-01 09:19:55 -08:00
|
|
|
YogaConfig config = new YogaConfig();
|
|
|
|
|
|
|
|
final YogaNode root = new YogaNode(config);
|
2016-12-02 05:47:43 -08:00
|
|
|
root.setPadding(YogaEdge.LEFT, 10);
|
|
|
|
root.setPadding(YogaEdge.TOP, 10);
|
|
|
|
root.setPadding(YogaEdge.RIGHT, 10);
|
|
|
|
root.setPadding(YogaEdge.BOTTOM, 10);
|
|
|
|
root.setDirection(YogaDirection.LTR);
|
2017-02-03 11:19:45 -08:00
|
|
|
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
|
2016-10-23 10:27:32 -07:00
|
|
|
|
2016-11-23 11:12:51 -08:00
|
|
|
assertEquals(0f, root.getLayoutX(), 0.0f);
|
|
|
|
assertEquals(0f, root.getLayoutY(), 0.0f);
|
|
|
|
assertEquals(20f, root.getLayoutWidth(), 0.0f);
|
|
|
|
assertEquals(20f, root.getLayoutHeight(), 0.0f);
|
2016-10-23 10:27:32 -07:00
|
|
|
|
2016-12-02 05:47:43 -08:00
|
|
|
root.setDirection(YogaDirection.RTL);
|
2017-02-03 11:19:45 -08:00
|
|
|
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
|
2016-10-23 10:27:32 -07:00
|
|
|
|
2016-11-23 11:12:51 -08:00
|
|
|
assertEquals(0f, root.getLayoutX(), 0.0f);
|
|
|
|
assertEquals(0f, root.getLayoutY(), 0.0f);
|
|
|
|
assertEquals(20f, root.getLayoutWidth(), 0.0f);
|
|
|
|
assertEquals(20f, root.getLayoutHeight(), 0.0f);
|
2016-10-23 10:27:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void test_padding_container_match_child() {
|
2017-03-01 09:19:55 -08:00
|
|
|
YogaConfig config = new YogaConfig();
|
|
|
|
|
|
|
|
final YogaNode root = new YogaNode(config);
|
2016-12-02 05:47:43 -08:00
|
|
|
root.setPadding(YogaEdge.LEFT, 10);
|
|
|
|
root.setPadding(YogaEdge.TOP, 10);
|
|
|
|
root.setPadding(YogaEdge.RIGHT, 10);
|
|
|
|
root.setPadding(YogaEdge.BOTTOM, 10);
|
2016-10-23 10:27:32 -07:00
|
|
|
|
2017-03-01 09:19:55 -08:00
|
|
|
final YogaNode root_child0 = new YogaNode(config);
|
2016-11-29 09:04:43 -08:00
|
|
|
root_child0.setWidth(10f);
|
|
|
|
root_child0.setHeight(10f);
|
2016-10-23 10:27:32 -07:00
|
|
|
root.addChildAt(root_child0, 0);
|
2016-12-02 05:47:43 -08:00
|
|
|
root.setDirection(YogaDirection.LTR);
|
2017-02-03 11:19:45 -08:00
|
|
|
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
|
2016-10-23 10:27:32 -07:00
|
|
|
|
2016-11-23 11:12:51 -08:00
|
|
|
assertEquals(0f, root.getLayoutX(), 0.0f);
|
|
|
|
assertEquals(0f, root.getLayoutY(), 0.0f);
|
|
|
|
assertEquals(30f, root.getLayoutWidth(), 0.0f);
|
|
|
|
assertEquals(30f, root.getLayoutHeight(), 0.0f);
|
2016-10-23 10:27:32 -07:00
|
|
|
|
2016-11-23 11:12:51 -08:00
|
|
|
assertEquals(10f, root_child0.getLayoutX(), 0.0f);
|
|
|
|
assertEquals(10f, root_child0.getLayoutY(), 0.0f);
|
|
|
|
assertEquals(10f, root_child0.getLayoutWidth(), 0.0f);
|
|
|
|
assertEquals(10f, root_child0.getLayoutHeight(), 0.0f);
|
2016-10-23 10:27:32 -07:00
|
|
|
|
2016-12-02 05:47:43 -08:00
|
|
|
root.setDirection(YogaDirection.RTL);
|
2017-02-03 11:19:45 -08:00
|
|
|
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
|
2016-10-23 10:27:32 -07:00
|
|
|
|
2016-11-23 11:12:51 -08:00
|
|
|
assertEquals(0f, root.getLayoutX(), 0.0f);
|
|
|
|
assertEquals(0f, root.getLayoutY(), 0.0f);
|
|
|
|
assertEquals(30f, root.getLayoutWidth(), 0.0f);
|
|
|
|
assertEquals(30f, root.getLayoutHeight(), 0.0f);
|
2016-10-23 10:27:32 -07:00
|
|
|
|
2016-11-23 11:12:51 -08:00
|
|
|
assertEquals(10f, root_child0.getLayoutX(), 0.0f);
|
|
|
|
assertEquals(10f, root_child0.getLayoutY(), 0.0f);
|
|
|
|
assertEquals(10f, root_child0.getLayoutWidth(), 0.0f);
|
|
|
|
assertEquals(10f, root_child0.getLayoutHeight(), 0.0f);
|
2016-10-23 10:27:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void test_padding_flex_child() {
|
2017-03-01 09:19:55 -08:00
|
|
|
YogaConfig config = new YogaConfig();
|
|
|
|
|
|
|
|
final YogaNode root = new YogaNode(config);
|
2016-12-02 05:47:43 -08:00
|
|
|
root.setPadding(YogaEdge.LEFT, 10);
|
|
|
|
root.setPadding(YogaEdge.TOP, 10);
|
|
|
|
root.setPadding(YogaEdge.RIGHT, 10);
|
|
|
|
root.setPadding(YogaEdge.BOTTOM, 10);
|
2016-11-29 09:04:43 -08:00
|
|
|
root.setWidth(100f);
|
|
|
|
root.setHeight(100f);
|
2016-10-23 10:27:32 -07:00
|
|
|
|
2017-03-01 09:19:55 -08:00
|
|
|
final YogaNode root_child0 = new YogaNode(config);
|
2016-11-23 11:12:51 -08:00
|
|
|
root_child0.setFlexGrow(1f);
|
2016-11-29 09:04:43 -08:00
|
|
|
root_child0.setWidth(10f);
|
2016-10-23 10:27:32 -07:00
|
|
|
root.addChildAt(root_child0, 0);
|
2016-12-02 05:47:43 -08:00
|
|
|
root.setDirection(YogaDirection.LTR);
|
2017-02-03 11:19:45 -08:00
|
|
|
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
|
2016-10-23 10:27:32 -07:00
|
|
|
|
2016-11-23 11:12:51 -08:00
|
|
|
assertEquals(0f, root.getLayoutX(), 0.0f);
|
|
|
|
assertEquals(0f, root.getLayoutY(), 0.0f);
|
|
|
|
assertEquals(100f, root.getLayoutWidth(), 0.0f);
|
|
|
|
assertEquals(100f, root.getLayoutHeight(), 0.0f);
|
2016-10-23 10:27:32 -07:00
|
|
|
|
2016-11-23 11:12:51 -08:00
|
|
|
assertEquals(10f, root_child0.getLayoutX(), 0.0f);
|
|
|
|
assertEquals(10f, root_child0.getLayoutY(), 0.0f);
|
|
|
|
assertEquals(10f, root_child0.getLayoutWidth(), 0.0f);
|
|
|
|
assertEquals(80f, root_child0.getLayoutHeight(), 0.0f);
|
2016-10-23 10:27:32 -07:00
|
|
|
|
2016-12-02 05:47:43 -08:00
|
|
|
root.setDirection(YogaDirection.RTL);
|
2017-02-03 11:19:45 -08:00
|
|
|
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
|
2016-10-23 10:27:32 -07:00
|
|
|
|
2016-11-23 11:12:51 -08:00
|
|
|
assertEquals(0f, root.getLayoutX(), 0.0f);
|
|
|
|
assertEquals(0f, root.getLayoutY(), 0.0f);
|
|
|
|
assertEquals(100f, root.getLayoutWidth(), 0.0f);
|
|
|
|
assertEquals(100f, root.getLayoutHeight(), 0.0f);
|
2016-10-23 10:27:32 -07:00
|
|
|
|
2016-11-23 11:12:51 -08:00
|
|
|
assertEquals(80f, root_child0.getLayoutX(), 0.0f);
|
|
|
|
assertEquals(10f, root_child0.getLayoutY(), 0.0f);
|
|
|
|
assertEquals(10f, root_child0.getLayoutWidth(), 0.0f);
|
|
|
|
assertEquals(80f, root_child0.getLayoutHeight(), 0.0f);
|
2016-10-23 10:27:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void test_padding_stretch_child() {
|
2017-03-01 09:19:55 -08:00
|
|
|
YogaConfig config = new YogaConfig();
|
|
|
|
|
|
|
|
final YogaNode root = new YogaNode(config);
|
2016-12-02 05:47:43 -08:00
|
|
|
root.setPadding(YogaEdge.LEFT, 10);
|
|
|
|
root.setPadding(YogaEdge.TOP, 10);
|
|
|
|
root.setPadding(YogaEdge.RIGHT, 10);
|
|
|
|
root.setPadding(YogaEdge.BOTTOM, 10);
|
2016-11-29 09:04:43 -08:00
|
|
|
root.setWidth(100f);
|
|
|
|
root.setHeight(100f);
|
2016-10-23 10:27:32 -07:00
|
|
|
|
2017-03-01 09:19:55 -08:00
|
|
|
final YogaNode root_child0 = new YogaNode(config);
|
2016-11-29 09:04:43 -08:00
|
|
|
root_child0.setHeight(10f);
|
2016-10-23 10:27:32 -07:00
|
|
|
root.addChildAt(root_child0, 0);
|
2016-12-02 05:47:43 -08:00
|
|
|
root.setDirection(YogaDirection.LTR);
|
2017-02-03 11:19:45 -08:00
|
|
|
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
|
2016-10-23 10:27:32 -07:00
|
|
|
|
2016-11-23 11:12:51 -08:00
|
|
|
assertEquals(0f, root.getLayoutX(), 0.0f);
|
|
|
|
assertEquals(0f, root.getLayoutY(), 0.0f);
|
|
|
|
assertEquals(100f, root.getLayoutWidth(), 0.0f);
|
|
|
|
assertEquals(100f, root.getLayoutHeight(), 0.0f);
|
2016-10-23 10:27:32 -07:00
|
|
|
|
2016-11-23 11:12:51 -08:00
|
|
|
assertEquals(10f, root_child0.getLayoutX(), 0.0f);
|
|
|
|
assertEquals(10f, root_child0.getLayoutY(), 0.0f);
|
|
|
|
assertEquals(80f, root_child0.getLayoutWidth(), 0.0f);
|
|
|
|
assertEquals(10f, root_child0.getLayoutHeight(), 0.0f);
|
2016-10-23 10:27:32 -07:00
|
|
|
|
2016-12-02 05:47:43 -08:00
|
|
|
root.setDirection(YogaDirection.RTL);
|
2017-02-03 11:19:45 -08:00
|
|
|
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
|
2016-10-23 10:27:32 -07:00
|
|
|
|
2016-11-23 11:12:51 -08:00
|
|
|
assertEquals(0f, root.getLayoutX(), 0.0f);
|
|
|
|
assertEquals(0f, root.getLayoutY(), 0.0f);
|
|
|
|
assertEquals(100f, root.getLayoutWidth(), 0.0f);
|
|
|
|
assertEquals(100f, root.getLayoutHeight(), 0.0f);
|
2016-10-23 10:27:32 -07:00
|
|
|
|
2016-11-23 11:12:51 -08:00
|
|
|
assertEquals(10f, root_child0.getLayoutX(), 0.0f);
|
|
|
|
assertEquals(10f, root_child0.getLayoutY(), 0.0f);
|
|
|
|
assertEquals(80f, root_child0.getLayoutWidth(), 0.0f);
|
|
|
|
assertEquals(10f, root_child0.getLayoutHeight(), 0.0f);
|
2016-10-23 10:27:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void test_padding_center_child() {
|
2017-03-01 09:19:55 -08:00
|
|
|
YogaConfig config = new YogaConfig();
|
|
|
|
|
|
|
|
final YogaNode root = new YogaNode(config);
|
2016-12-02 05:47:43 -08:00
|
|
|
root.setJustifyContent(YogaJustify.CENTER);
|
|
|
|
root.setAlignItems(YogaAlign.CENTER);
|
|
|
|
root.setPadding(YogaEdge.START, 10);
|
|
|
|
root.setPadding(YogaEdge.END, 20);
|
|
|
|
root.setPadding(YogaEdge.BOTTOM, 20);
|
2016-11-29 09:04:43 -08:00
|
|
|
root.setWidth(100f);
|
|
|
|
root.setHeight(100f);
|
2016-10-23 10:27:32 -07:00
|
|
|
|
2017-03-01 09:19:55 -08:00
|
|
|
final YogaNode root_child0 = new YogaNode(config);
|
2016-11-29 09:04:43 -08:00
|
|
|
root_child0.setWidth(10f);
|
|
|
|
root_child0.setHeight(10f);
|
2016-10-23 10:27:32 -07:00
|
|
|
root.addChildAt(root_child0, 0);
|
2016-12-02 05:47:43 -08:00
|
|
|
root.setDirection(YogaDirection.LTR);
|
2017-02-03 11:19:45 -08:00
|
|
|
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
|
2016-10-23 10:27:32 -07:00
|
|
|
|
2016-11-23 11:12:51 -08:00
|
|
|
assertEquals(0f, root.getLayoutX(), 0.0f);
|
|
|
|
assertEquals(0f, root.getLayoutY(), 0.0f);
|
|
|
|
assertEquals(100f, root.getLayoutWidth(), 0.0f);
|
|
|
|
assertEquals(100f, root.getLayoutHeight(), 0.0f);
|
2016-10-23 10:27:32 -07:00
|
|
|
|
2016-11-23 11:12:51 -08:00
|
|
|
assertEquals(40f, root_child0.getLayoutX(), 0.0f);
|
|
|
|
assertEquals(35f, root_child0.getLayoutY(), 0.0f);
|
|
|
|
assertEquals(10f, root_child0.getLayoutWidth(), 0.0f);
|
|
|
|
assertEquals(10f, root_child0.getLayoutHeight(), 0.0f);
|
2016-10-23 10:27:32 -07:00
|
|
|
|
2016-12-02 05:47:43 -08:00
|
|
|
root.setDirection(YogaDirection.RTL);
|
2017-02-03 11:19:45 -08:00
|
|
|
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
|
2016-10-23 10:27:32 -07:00
|
|
|
|
2016-11-23 11:12:51 -08:00
|
|
|
assertEquals(0f, root.getLayoutX(), 0.0f);
|
|
|
|
assertEquals(0f, root.getLayoutY(), 0.0f);
|
|
|
|
assertEquals(100f, root.getLayoutWidth(), 0.0f);
|
|
|
|
assertEquals(100f, root.getLayoutHeight(), 0.0f);
|
2016-10-23 10:27:32 -07:00
|
|
|
|
2016-11-23 11:12:51 -08:00
|
|
|
assertEquals(50f, root_child0.getLayoutX(), 0.0f);
|
|
|
|
assertEquals(35f, root_child0.getLayoutY(), 0.0f);
|
|
|
|
assertEquals(10f, root_child0.getLayoutWidth(), 0.0f);
|
|
|
|
assertEquals(10f, root_child0.getLayoutHeight(), 0.0f);
|
2016-10-23 10:27:32 -07:00
|
|
|
}
|
|
|
|
|
2016-11-29 16:11:41 -08:00
|
|
|
@Test
|
|
|
|
public void test_child_with_padding_align_end() {
|
2017-03-01 09:19:55 -08:00
|
|
|
YogaConfig config = new YogaConfig();
|
|
|
|
|
|
|
|
final YogaNode root = new YogaNode(config);
|
2016-12-02 05:47:43 -08:00
|
|
|
root.setJustifyContent(YogaJustify.FLEX_END);
|
|
|
|
root.setAlignItems(YogaAlign.FLEX_END);
|
2016-11-29 16:11:41 -08:00
|
|
|
root.setWidth(200f);
|
|
|
|
root.setHeight(200f);
|
|
|
|
|
2017-03-01 09:19:55 -08:00
|
|
|
final YogaNode root_child0 = new YogaNode(config);
|
2016-12-02 05:47:43 -08:00
|
|
|
root_child0.setPadding(YogaEdge.LEFT, 20);
|
|
|
|
root_child0.setPadding(YogaEdge.TOP, 20);
|
|
|
|
root_child0.setPadding(YogaEdge.RIGHT, 20);
|
|
|
|
root_child0.setPadding(YogaEdge.BOTTOM, 20);
|
2016-11-29 16:11:41 -08:00
|
|
|
root_child0.setWidth(100f);
|
|
|
|
root_child0.setHeight(100f);
|
|
|
|
root.addChildAt(root_child0, 0);
|
2016-12-02 05:47:43 -08:00
|
|
|
root.setDirection(YogaDirection.LTR);
|
2017-02-03 11:19:45 -08:00
|
|
|
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
|
2016-11-29 16:11:41 -08:00
|
|
|
|
|
|
|
assertEquals(0f, root.getLayoutX(), 0.0f);
|
|
|
|
assertEquals(0f, root.getLayoutY(), 0.0f);
|
|
|
|
assertEquals(200f, root.getLayoutWidth(), 0.0f);
|
|
|
|
assertEquals(200f, root.getLayoutHeight(), 0.0f);
|
|
|
|
|
|
|
|
assertEquals(100f, root_child0.getLayoutX(), 0.0f);
|
|
|
|
assertEquals(100f, root_child0.getLayoutY(), 0.0f);
|
|
|
|
assertEquals(100f, root_child0.getLayoutWidth(), 0.0f);
|
|
|
|
assertEquals(100f, root_child0.getLayoutHeight(), 0.0f);
|
|
|
|
|
2016-12-02 05:47:43 -08:00
|
|
|
root.setDirection(YogaDirection.RTL);
|
2017-02-03 11:19:45 -08:00
|
|
|
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
|
2016-11-29 16:11:41 -08:00
|
|
|
|
|
|
|
assertEquals(0f, root.getLayoutX(), 0.0f);
|
|
|
|
assertEquals(0f, root.getLayoutY(), 0.0f);
|
|
|
|
assertEquals(200f, root.getLayoutWidth(), 0.0f);
|
|
|
|
assertEquals(200f, root.getLayoutHeight(), 0.0f);
|
|
|
|
|
|
|
|
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
|
|
|
|
assertEquals(100f, root_child0.getLayoutY(), 0.0f);
|
|
|
|
assertEquals(100f, root_child0.getLayoutWidth(), 0.0f);
|
|
|
|
assertEquals(100f, root_child0.getLayoutHeight(), 0.0f);
|
|
|
|
}
|
|
|
|
|
2016-10-23 10:27:32 -07:00
|
|
|
}
|