Added extra test to check for potential division by zero.

This commit is contained in:
Russell Keith-Magee
2015-04-01 14:46:28 +08:00
parent 8ae56041b5
commit 9cf2e71e01
3 changed files with 259 additions and 13 deletions

View File

@@ -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();
{

View File

@@ -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}}
@@ -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}}
@@ -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: [