From 7d74e1cb66fe823d990d1f1c508dbd6459d9c260 Mon Sep 17 00:00:00 2001 From: Emil Sjolander Date: Tue, 29 Nov 2016 16:11:41 -0800 Subject: [PATCH] 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 --- .../CSSLayoutPaddingTest.cs | 44 +++++++++++++++++++ gentest/fixtures/CSSLayoutPaddingTest.html | 4 ++ .../csslayout/CSSLayoutPaddingTest.java | 43 ++++++++++++++++++ tests/CSSLayoutPaddingTest.cpp | 42 ++++++++++++++++++ 4 files changed, 133 insertions(+) diff --git a/csharp/tests/Facebook.CSSLayout/CSSLayoutPaddingTest.cs b/csharp/tests/Facebook.CSSLayout/CSSLayoutPaddingTest.cs index 7712b8a..02a5fa1 100644 --- a/csharp/tests/Facebook.CSSLayout/CSSLayoutPaddingTest.cs +++ b/csharp/tests/Facebook.CSSLayout/CSSLayoutPaddingTest.cs @@ -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); + } + } } diff --git a/gentest/fixtures/CSSLayoutPaddingTest.html b/gentest/fixtures/CSSLayoutPaddingTest.html index 1f67978..f1616fe 100644 --- a/gentest/fixtures/CSSLayoutPaddingTest.html +++ b/gentest/fixtures/CSSLayoutPaddingTest.html @@ -16,3 +16,7 @@
+ +
+
+
diff --git a/java/tests/com/facebook/csslayout/CSSLayoutPaddingTest.java b/java/tests/com/facebook/csslayout/CSSLayoutPaddingTest.java index 4212679..f837953 100644 --- a/java/tests/com/facebook/csslayout/CSSLayoutPaddingTest.java +++ b/java/tests/com/facebook/csslayout/CSSLayoutPaddingTest.java @@ -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); + } + } diff --git a/tests/CSSLayoutPaddingTest.cpp b/tests/CSSLayoutPaddingTest.cpp index 808d818..355c7d3 100644 --- a/tests/CSSLayoutPaddingTest.cpp +++ b/tests/CSSLayoutPaddingTest.cpp @@ -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); +}