Add test case covering padding on child
Summary: Add coverage exposed by https://github.com/facebook/css-layout/pull/262 Reviewed By: splhack Differential Revision: D4247282 fbshipit-source-id: 25500bcfced58a8095665b73eeebca8d1c266a17
This commit is contained in:
Родитель
b32b6029de
Коммит
7d74e1cb66
|
@ -208,5 +208,49 @@ namespace Facebook.CSSLayout
|
|||
Assert.AreEqual(10f, root_child0.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_child_with_padding_align_end()
|
||||
{
|
||||
CSSNode root = new CSSNode();
|
||||
root.JustifyContent = CSSJustify.FlexEnd;
|
||||
root.AlignItems = CSSAlign.FlexEnd;
|
||||
root.Width = 200f;
|
||||
root.Height = 200f;
|
||||
|
||||
CSSNode root_child0 = new CSSNode();
|
||||
root_child0.SetPadding(CSSEdge.Left, 20f);
|
||||
root_child0.SetPadding(CSSEdge.Top, 20f);
|
||||
root_child0.SetPadding(CSSEdge.Right, 20f);
|
||||
root_child0.SetPadding(CSSEdge.Bottom, 20f);
|
||||
root_child0.Width = 100f;
|
||||
root_child0.Height = 100f;
|
||||
root.Insert(0, root_child0);
|
||||
root.StyleDirection = CSSDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0f, root.LayoutX);
|
||||
Assert.AreEqual(0f, root.LayoutY);
|
||||
Assert.AreEqual(200f, root.LayoutWidth);
|
||||
Assert.AreEqual(200f, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(100f, root_child0.LayoutX);
|
||||
Assert.AreEqual(100f, root_child0.LayoutY);
|
||||
Assert.AreEqual(100f, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(100f, root_child0.LayoutHeight);
|
||||
|
||||
root.StyleDirection = CSSDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0f, root.LayoutX);
|
||||
Assert.AreEqual(0f, root.LayoutY);
|
||||
Assert.AreEqual(200f, root.LayoutWidth);
|
||||
Assert.AreEqual(200f, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0f, root_child0.LayoutX);
|
||||
Assert.AreEqual(100f, root_child0.LayoutY);
|
||||
Assert.AreEqual(100f, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(100f, root_child0.LayoutHeight);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,3 +16,7 @@
|
|||
<div id="padding_center_child" style="width: 100px; height: 100px; padding-start: 10px; padding-top: 10; padding-end: 20px; padding-bottom: 20px; align-items: center; justify-content: center;">
|
||||
<div style="height: 10px; width: 10px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="child_with_padding_align_end" style="width: 200px; height: 200px; justify-content: flex-end; align-items: flex-end;">
|
||||
<div style="width: 100px; height: 100px; padding: 20px;"></div>
|
||||
</div>
|
||||
|
|
|
@ -202,4 +202,47 @@ public class CSSLayoutPaddingTest {
|
|||
assertEquals(10f, root_child0.getLayoutHeight(), 0.0f);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_child_with_padding_align_end() {
|
||||
final CSSNode root = new CSSNode();
|
||||
root.setJustifyContent(CSSJustify.FLEX_END);
|
||||
root.setAlignItems(CSSAlign.FLEX_END);
|
||||
root.setWidth(200f);
|
||||
root.setHeight(200f);
|
||||
|
||||
final CSSNode root_child0 = new CSSNode();
|
||||
root_child0.setPadding(CSSEdge.LEFT, 20);
|
||||
root_child0.setPadding(CSSEdge.TOP, 20);
|
||||
root_child0.setPadding(CSSEdge.RIGHT, 20);
|
||||
root_child0.setPadding(CSSEdge.BOTTOM, 20);
|
||||
root_child0.setWidth(100f);
|
||||
root_child0.setHeight(100f);
|
||||
root.addChildAt(root_child0, 0);
|
||||
root.setDirection(CSSDirection.LTR);
|
||||
root.calculateLayout();
|
||||
|
||||
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);
|
||||
|
||||
root.setDirection(CSSDirection.RTL);
|
||||
root.calculateLayout();
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -192,3 +192,45 @@ TEST(CSSLayoutTest, padding_center_child) {
|
|||
|
||||
CSSNodeFreeRecursive(root);
|
||||
}
|
||||
|
||||
TEST(CSSLayoutTest, child_with_padding_align_end) {
|
||||
const CSSNodeRef root = CSSNodeNew();
|
||||
CSSNodeStyleSetJustifyContent(root, CSSJustifyFlexEnd);
|
||||
CSSNodeStyleSetAlignItems(root, CSSAlignFlexEnd);
|
||||
CSSNodeStyleSetWidth(root, 200);
|
||||
CSSNodeStyleSetHeight(root, 200);
|
||||
|
||||
const CSSNodeRef root_child0 = CSSNodeNew();
|
||||
CSSNodeStyleSetPadding(root_child0, CSSEdgeLeft, 20);
|
||||
CSSNodeStyleSetPadding(root_child0, CSSEdgeTop, 20);
|
||||
CSSNodeStyleSetPadding(root_child0, CSSEdgeRight, 20);
|
||||
CSSNodeStyleSetPadding(root_child0, CSSEdgeBottom, 20);
|
||||
CSSNodeStyleSetWidth(root_child0, 100);
|
||||
CSSNodeStyleSetHeight(root_child0, 100);
|
||||
CSSNodeInsertChild(root, root_child0, 0);
|
||||
CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR);
|
||||
|
||||
ASSERT_FLOAT_EQ(0, CSSNodeLayoutGetLeft(root));
|
||||
ASSERT_FLOAT_EQ(0, CSSNodeLayoutGetTop(root));
|
||||
ASSERT_FLOAT_EQ(200, CSSNodeLayoutGetWidth(root));
|
||||
ASSERT_FLOAT_EQ(200, CSSNodeLayoutGetHeight(root));
|
||||
|
||||
ASSERT_FLOAT_EQ(100, CSSNodeLayoutGetLeft(root_child0));
|
||||
ASSERT_FLOAT_EQ(100, CSSNodeLayoutGetTop(root_child0));
|
||||
ASSERT_FLOAT_EQ(100, CSSNodeLayoutGetWidth(root_child0));
|
||||
ASSERT_FLOAT_EQ(100, CSSNodeLayoutGetHeight(root_child0));
|
||||
|
||||
CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionRTL);
|
||||
|
||||
ASSERT_FLOAT_EQ(0, CSSNodeLayoutGetLeft(root));
|
||||
ASSERT_FLOAT_EQ(0, CSSNodeLayoutGetTop(root));
|
||||
ASSERT_FLOAT_EQ(200, CSSNodeLayoutGetWidth(root));
|
||||
ASSERT_FLOAT_EQ(200, CSSNodeLayoutGetHeight(root));
|
||||
|
||||
ASSERT_FLOAT_EQ(0, CSSNodeLayoutGetLeft(root_child0));
|
||||
ASSERT_FLOAT_EQ(100, CSSNodeLayoutGetTop(root_child0));
|
||||
ASSERT_FLOAT_EQ(100, CSSNodeLayoutGetWidth(root_child0));
|
||||
ASSERT_FLOAT_EQ(100, CSSNodeLayoutGetHeight(root_child0));
|
||||
|
||||
CSSNodeFreeRecursive(root);
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче