Skip to content

Commit

Permalink
Added extra test to check for potential division by zero.
Browse files Browse the repository at this point in the history
  • Loading branch information
freakboy3742 committed Apr 1, 2015
1 parent 8ae5604 commit 9cf2e71
Show file tree
Hide file tree
Showing 3 changed files with 259 additions and 13 deletions.
106 changes: 106 additions & 0 deletions src/__tests__/Layout-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -4107,6 +4107,112 @@ int main()
test("should override flex direction size with max bounds", root_node, root_layout);
}

{
css_node_t *root_node = new_test_css_node();
{
css_node_t *node_0 = root_node;
node_0->style.flex_direction = CSS_FLEX_DIRECTION_ROW;
node_0->style.dimensions[CSS_WIDTH] = 300;
node_0->style.dimensions[CSS_HEIGHT] = 200;
init_css_node_children(node_0, 3);
{
css_node_t *node_1;
node_1 = node_0->get_child(node_0->context, 0);
node_1->style.flex = 1;
node_1->style.maxDimensions[CSS_WIDTH] = 60;
node_1 = node_0->get_child(node_0->context, 1);
node_1->style.flex = 1;
node_1->style.maxDimensions[CSS_WIDTH] = 60;
node_1 = node_0->get_child(node_0->context, 2);
node_1->style.flex = 1;
node_1->style.maxDimensions[CSS_WIDTH] = 60;
}
}

css_node_t *root_layout = new_test_css_node();
{
css_node_t *node_0 = root_layout;
node_0->layout.position[CSS_TOP] = 0;
node_0->layout.position[CSS_LEFT] = 0;
node_0->layout.dimensions[CSS_WIDTH] = 300;
node_0->layout.dimensions[CSS_HEIGHT] = 200;
init_css_node_children(node_0, 3);
{
css_node_t *node_1;
node_1 = node_0->get_child(node_0->context, 0);
node_1->layout.position[CSS_TOP] = 0;
node_1->layout.position[CSS_LEFT] = 0;
node_1->layout.dimensions[CSS_WIDTH] = 60;
node_1->layout.dimensions[CSS_HEIGHT] = 200;
node_1 = node_0->get_child(node_0->context, 1);
node_1->layout.position[CSS_TOP] = 0;
node_1->layout.position[CSS_LEFT] = 60;
node_1->layout.dimensions[CSS_WIDTH] = 60;
node_1->layout.dimensions[CSS_HEIGHT] = 200;
node_1 = node_0->get_child(node_0->context, 2);
node_1->layout.position[CSS_TOP] = 0;
node_1->layout.position[CSS_LEFT] = 120;
node_1->layout.dimensions[CSS_WIDTH] = 60;
node_1->layout.dimensions[CSS_HEIGHT] = 200;
}
}

test("should ignore flex size if fully max bound", root_node, root_layout);
}

{
css_node_t *root_node = new_test_css_node();
{
css_node_t *node_0 = root_node;
node_0->style.flex_direction = CSS_FLEX_DIRECTION_ROW;
node_0->style.dimensions[CSS_WIDTH] = 300;
node_0->style.dimensions[CSS_HEIGHT] = 200;
init_css_node_children(node_0, 3);
{
css_node_t *node_1;
node_1 = node_0->get_child(node_0->context, 0);
node_1->style.flex = 1;
node_1->style.minDimensions[CSS_WIDTH] = 120;
node_1 = node_0->get_child(node_0->context, 1);
node_1->style.flex = 1;
node_1->style.minDimensions[CSS_WIDTH] = 120;
node_1 = node_0->get_child(node_0->context, 2);
node_1->style.flex = 1;
node_1->style.minDimensions[CSS_WIDTH] = 120;
}
}

css_node_t *root_layout = new_test_css_node();
{
css_node_t *node_0 = root_layout;
node_0->layout.position[CSS_TOP] = 0;
node_0->layout.position[CSS_LEFT] = 0;
node_0->layout.dimensions[CSS_WIDTH] = 300;
node_0->layout.dimensions[CSS_HEIGHT] = 200;
init_css_node_children(node_0, 3);
{
css_node_t *node_1;
node_1 = node_0->get_child(node_0->context, 0);
node_1->layout.position[CSS_TOP] = 0;
node_1->layout.position[CSS_LEFT] = 0;
node_1->layout.dimensions[CSS_WIDTH] = 120;
node_1->layout.dimensions[CSS_HEIGHT] = 200;
node_1 = node_0->get_child(node_0->context, 1);
node_1->layout.position[CSS_TOP] = 0;
node_1->layout.position[CSS_LEFT] = 120;
node_1->layout.dimensions[CSS_WIDTH] = 120;
node_1->layout.dimensions[CSS_HEIGHT] = 200;
node_1 = node_0->get_child(node_0->context, 2);
node_1->layout.position[CSS_TOP] = 0;
node_1->layout.position[CSS_LEFT] = 240;
node_1->layout.dimensions[CSS_WIDTH] = 120;
node_1->layout.dimensions[CSS_HEIGHT] = 200;
}
}

test("should ignore flex size if fully min bound", root_node, root_layout);
}

{
css_node_t *root_node = new_test_css_node();
{
Expand Down
34 changes: 32 additions & 2 deletions src/__tests__/Layout-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1302,7 +1302,7 @@ describe('Layout', function() {

it('should override flex direction size with min bounds', function() {
testLayout(
{style: {width: 300, height: 200, flexDirection:'row'}, children: [
{style: {width: 300, height: 200, flexDirection: 'row'}, children: [
{style: {flex: 1}},
{style: {flex: 1, minWidth: 200}},
{style: {flex: 1}}
Expand Down Expand Up @@ -1332,7 +1332,7 @@ describe('Layout', function() {

it('should override flex direction size with max bounds', function() {
testLayout(
{style: {width: 300, height: 200, flexDirection:'row'}, children: [
{style: {width: 300, height: 200, flexDirection: 'row'}, children: [
{style: {flex: 1}},
{style: {flex: 1, maxWidth: 60}},
{style: {flex: 1}}
Expand All @@ -1345,6 +1345,36 @@ describe('Layout', function() {
);
});

it ('should ignore flex size if fully max bound', function() {
testLayout(
{style: {width: 300, height: 200, flexDirection: 'row'}, children: [
{style: {flex: 1, maxWidth: 60}},
{style: {flex: 1, maxWidth: 60}},
{style: {flex: 1, maxWidth: 60}}
]},
{width: 300, height: 200, top: 0, left: 0, children: [
{width: 60, height: 200, top: 0, left: 0},
{width: 60, height: 200, top: 0, left: 60},
{width: 60, height: 200, top: 0, left: 120}
]}
);
});

it ('should ignore flex size if fully min bound', function() {
testLayout(
{style: {width: 300, height: 200, flexDirection: 'row'}, children: [
{style: {flex: 1, minWidth: 120}},
{style: {flex: 1, minWidth: 120}},
{style: {flex: 1, minWidth: 120}}
]},
{width: 300, height: 200, top: 0, left: 0, children: [
{width: 120, height: 200, top: 0, left: 0},
{width: 120, height: 200, top: 0, left: 120},
{width: 120, height: 200, top: 0, left: 240}
]}
);
});

it('should pre-fill child size within bounds', function() {
testLayout(
{style: {width: 300, height: 200}, children: [
Expand Down
132 changes: 121 additions & 11 deletions src/java/tests/com/facebook/csslayout/LayoutEngineTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4396,6 +4396,116 @@ public void testCase105()

@Test
public void testCase106()
{
TestCSSNode root_node = new TestCSSNode();
{
TestCSSNode node_0 = root_node;
node_0.style.flexDirection = CSSFlexDirection.ROW;
node_0.style.width = 300;
node_0.style.height = 200;
addChildren(node_0, 3);
{
TestCSSNode node_1;
node_1 = node_0.getChildAt(0);
node_1.style.flex = 1;
node_1.style.maxWidth = 60;
node_1 = node_0.getChildAt(1);
node_1.style.flex = 1;
node_1.style.maxWidth = 60;
node_1 = node_0.getChildAt(2);
node_1.style.flex = 1;
node_1.style.maxWidth = 60;
}
}

TestCSSNode root_layout = new TestCSSNode();
{
TestCSSNode node_0 = root_layout;
node_0.layout.y = 0;
node_0.layout.x = 0;
node_0.layout.width = 300;
node_0.layout.height = 200;
addChildren(node_0, 3);
{
TestCSSNode node_1;
node_1 = node_0.getChildAt(0);
node_1.layout.y = 0;
node_1.layout.x = 0;
node_1.layout.width = 60;
node_1.layout.height = 200;
node_1 = node_0.getChildAt(1);
node_1.layout.y = 0;
node_1.layout.x = 60;
node_1.layout.width = 60;
node_1.layout.height = 200;
node_1 = node_0.getChildAt(2);
node_1.layout.y = 0;
node_1.layout.x = 120;
node_1.layout.width = 60;
node_1.layout.height = 200;
}
}

test("should ignore flex size if fully max bound", root_node, root_layout);
}

@Test
public void testCase107()
{
TestCSSNode root_node = new TestCSSNode();
{
TestCSSNode node_0 = root_node;
node_0.style.flexDirection = CSSFlexDirection.ROW;
node_0.style.width = 300;
node_0.style.height = 200;
addChildren(node_0, 3);
{
TestCSSNode node_1;
node_1 = node_0.getChildAt(0);
node_1.style.flex = 1;
node_1.style.minWidth = 120;
node_1 = node_0.getChildAt(1);
node_1.style.flex = 1;
node_1.style.minWidth = 120;
node_1 = node_0.getChildAt(2);
node_1.style.flex = 1;
node_1.style.minWidth = 120;
}
}

TestCSSNode root_layout = new TestCSSNode();
{
TestCSSNode node_0 = root_layout;
node_0.layout.y = 0;
node_0.layout.x = 0;
node_0.layout.width = 300;
node_0.layout.height = 200;
addChildren(node_0, 3);
{
TestCSSNode node_1;
node_1 = node_0.getChildAt(0);
node_1.layout.y = 0;
node_1.layout.x = 0;
node_1.layout.width = 120;
node_1.layout.height = 200;
node_1 = node_0.getChildAt(1);
node_1.layout.y = 0;
node_1.layout.x = 120;
node_1.layout.width = 120;
node_1.layout.height = 200;
node_1 = node_0.getChildAt(2);
node_1.layout.y = 0;
node_1.layout.x = 240;
node_1.layout.width = 120;
node_1.layout.height = 200;
}
}

test("should ignore flex size if fully min bound", root_node, root_layout);
}

@Test
public void testCase108()
{
TestCSSNode root_node = new TestCSSNode();
{
Expand Down Expand Up @@ -4434,7 +4544,7 @@ public void testCase106()
}

@Test
public void testCase107()
public void testCase109()
{
TestCSSNode root_node = new TestCSSNode();
{
Expand Down Expand Up @@ -4472,7 +4582,7 @@ public void testCase107()
}

@Test
public void testCase108()
public void testCase110()
{
TestCSSNode root_node = new TestCSSNode();
{
Expand Down Expand Up @@ -4510,7 +4620,7 @@ public void testCase108()
}

@Test
public void testCase109()
public void testCase111()
{
TestCSSNode root_node = new TestCSSNode();
{
Expand Down Expand Up @@ -4558,7 +4668,7 @@ public void testCase109()
}

@Test
public void testCase110()
public void testCase112()
{
TestCSSNode root_node = new TestCSSNode();
{
Expand Down Expand Up @@ -4604,7 +4714,7 @@ public void testCase110()
}

@Test
public void testCase111()
public void testCase113()
{
TestCSSNode root_node = new TestCSSNode();
{
Expand Down Expand Up @@ -4650,7 +4760,7 @@ public void testCase111()
}

@Test
public void testCase112()
public void testCase114()
{
TestCSSNode root_node = new TestCSSNode();
{
Expand Down Expand Up @@ -4691,7 +4801,7 @@ public void testCase112()
}

@Test
public void testCase113()
public void testCase115()
{
TestCSSNode root_node = new TestCSSNode();
{
Expand Down Expand Up @@ -4730,7 +4840,7 @@ public void testCase113()
}

@Test
public void testCase114()
public void testCase116()
{
TestCSSNode root_node = new TestCSSNode();
{
Expand Down Expand Up @@ -4769,7 +4879,7 @@ public void testCase114()
}

@Test
public void testCase115()
public void testCase117()
{
TestCSSNode root_node = new TestCSSNode();
{
Expand Down Expand Up @@ -4808,7 +4918,7 @@ public void testCase115()
}

@Test
public void testCase116()
public void testCase118()
{
TestCSSNode root_node = new TestCSSNode();
{
Expand Down Expand Up @@ -4851,7 +4961,7 @@ public void testCase116()
}

@Test
public void testCase117()
public void testCase119()
{
TestCSSNode root_node = new TestCSSNode();
{
Expand Down

0 comments on commit 9cf2e71

Please sign in to comment.