Skip to content

Commit

Permalink
Add test case covering padding on child
Browse files Browse the repository at this point in the history
Summary: Add coverage exposed by facebook#262

Reviewed By: splhack

Differential Revision: D4247282

fbshipit-source-id: 25500bcfced58a8095665b73eeebca8d1c266a17
  • Loading branch information
Emil Sjolander authored and Facebook Github Bot committed Nov 30, 2016
1 parent b32b602 commit 7d74e1c
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 0 deletions.
44 changes: 44 additions & 0 deletions csharp/tests/Facebook.CSSLayout/CSSLayoutPaddingTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,5 +208,49 @@ public void Test_padding_center_child()
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);
}

}
}
4 changes: 4 additions & 0 deletions gentest/fixtures/CSSLayoutPaddingTest.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>
43 changes: 43 additions & 0 deletions java/tests/com/facebook/csslayout/CSSLayoutPaddingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,47 @@ public void test_padding_center_child() {
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);
}

}
42 changes: 42 additions & 0 deletions tests/CSSLayoutPaddingTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

0 comments on commit 7d74e1c

Please sign in to comment.