make C and Java tests pass and update their code

This commit is contained in:
Christopher Chedeau
2014-12-11 20:23:53 +00:00
parent e838124625
commit 28243156e4
8 changed files with 538 additions and 155 deletions

1
.gitignore vendored
View File

@@ -2,3 +2,4 @@ a.out
*.class
/**/java/out/*
/**/.idea/workspace.xml
/lib/

View File

@@ -95,6 +95,7 @@ var JavaTranspiler = {
.replace(/\/\*\([^\/]+\*\/\n/g, '') // remove comments for other languages
.replace(/var\/\*([^\/]+)\*\//g, '$1')
.replace(/ === /g, ' == ')
.replace(/ !== /g, ' != ')
.replace(/\n /g, '\n')
.replace(/\/[*]!([^*]+)[*]\//g, '$1')
.replace(/css_node_t\*/g, 'CSSNode'));

View File

@@ -10,6 +10,7 @@
var layoutTestUtils = (function() {
if (typeof jasmine !== 'undefined') {
jasmine.matchersUtil.buildFailureMessage = function () {
var args = Array.prototype.slice.call(arguments, 0),
matcherName = args[0],
@@ -41,6 +42,7 @@ var layoutTestUtils = (function() {
return message + '.';
};
}
var cachedIframe;
function getIframe() {

View File

@@ -394,8 +394,7 @@ static void layoutNodeImpl(css_node_t *node, float parentMaxWidth) {
if (getAlignItem(node, child) == CSS_ALIGN_STRETCH &&
getPositionType(child) == CSS_POSITION_RELATIVE &&
!isUndefined(node->layout.dimensions[dim[crossAxis]]) &&
!isDimDefined(child, crossAxis) &&
!isPosDefined(child, leading[crossAxis])) {
!isDimDefined(child, crossAxis)) {
child->layout.dimensions[dim[crossAxis]] = fmaxf(
node->layout.dimensions[dim[crossAxis]] -
getPaddingAndBorderAxis(node, crossAxis) -
@@ -480,7 +479,6 @@ static void layoutNodeImpl(css_node_t *node, float parentMaxWidth) {
}
}
// <Loop B> Layout flexible children and allocate empty space
// In order to position the elements in the main axis, we have two
@@ -489,14 +487,13 @@ static void layoutNodeImpl(css_node_t *node, float parentMaxWidth) {
float leadingMainDim = 0;
float betweenMainDim = 0;
// If the dimensions of the current node is defined by its children, they
// are all going to be packed together and we don't need to compute
// anything.
float definedMainDim = fmaxf(mainContentDim, 0);
if (!isUndefined(node->layout.dimensions[dim[mainAxis]])) {
definedMainDim = node->layout.dimensions[dim[mainAxis]] -
getPaddingAndBorderAxis(node, mainAxis);
}
// The remaining available space that needs to be allocated
float remainingMainDim = node->layout.dimensions[dim[mainAxis]] -
getPaddingAndBorderAxis(node, mainAxis) -
mainContentDim;
float remainingMainDim = definedMainDim - mainContentDim;
// If there are flexible children in the mix, they are going to fill the
// remaining space
@@ -548,8 +545,12 @@ static void layoutNodeImpl(css_node_t *node, float parentMaxWidth) {
leadingMainDim = remainingMainDim;
} else if (justifyContent == CSS_JUSTIFY_SPACE_BETWEEN) {
remainingMainDim = fmaxf(remainingMainDim, 0);
if (flexibleChildrenCount + nonFlexibleChildrenCount - 1 != 0) {
betweenMainDim = remainingMainDim /
(flexibleChildrenCount + nonFlexibleChildrenCount - 1);
} else {
betweenMainDim = 0;
}
} else if (justifyContent == CSS_JUSTIFY_SPACE_AROUND) {
// Space on the edges is half of the space between elements
betweenMainDim = remainingMainDim /
@@ -557,7 +558,6 @@ static void layoutNodeImpl(css_node_t *node, float parentMaxWidth) {
leadingMainDim = betweenMainDim / 2;
}
}
}
// <Loop C> Position elements in the main axis and compute dimensions

View File

@@ -3343,7 +3343,7 @@ int main()
}
}
test("should calcluate left properly with position: absolute right", root_node, root_layout);
test("should calculate left properly with position: absolute right", root_node, root_layout);
}
{
@@ -3415,7 +3415,7 @@ int main()
}
}
test("should calcluate left properly with position: absolute right and width", root_node, root_layout);
test("should calculate left properly with position: absolute right and width", root_node, root_layout);
}
{
@@ -3450,7 +3450,7 @@ int main()
}
}
test("should calcluate top properly with position: absolute right, width, and no parent dimensions", root_node, root_layout);
test("should calculate top properly with position: absolute right, width, and no parent dimensions", root_node, root_layout);
}
{
@@ -3485,7 +3485,191 @@ int main()
}
}
test("should calcluate left properly with position: absolute right, width, and no parent dimensions", root_node, root_layout);
test("should calculate left properly with position: absolute right, width, and no parent dimensions", root_node, root_layout);
}
{
css_node_t *root_node = new_test_css_node();
{
css_node_t *node_0 = root_node;
node_0->style.justify_content = CSS_JUSTIFY_SPACE_BETWEEN;
init_css_node_children(node_0, 1);
{
css_node_t *node_1;
node_1 = node_0->get_child(node_0->context, 0);
node_1->style.border[CSS_BOTTOM] = 1;
}
}
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] = 0;
node_0->layout.dimensions[CSS_HEIGHT] = 1;
init_css_node_children(node_0, 1);
{
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] = 0;
node_1->layout.dimensions[CSS_HEIGHT] = 1;
}
}
test("should layout border bottom inside of justify content space between container", root_node, root_layout);
}
{
css_node_t *root_node = new_test_css_node();
{
css_node_t *node_0 = root_node;
node_0->style.justify_content = CSS_JUSTIFY_CENTER;
init_css_node_children(node_0, 1);
{
css_node_t *node_1;
node_1 = node_0->get_child(node_0->context, 0);
node_1->style.margin[CSS_TOP] = -6;
}
}
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] = 0;
node_0->layout.dimensions[CSS_HEIGHT] = 0;
init_css_node_children(node_0, 1);
{
css_node_t *node_1;
node_1 = node_0->get_child(node_0->context, 0);
node_1->layout.position[CSS_TOP] = -3;
node_1->layout.position[CSS_LEFT] = 0;
node_1->layout.dimensions[CSS_WIDTH] = 0;
node_1->layout.dimensions[CSS_HEIGHT] = 0;
}
}
test("should layout negative margin top inside of justify content center container", root_node, root_layout);
}
{
css_node_t *root_node = new_test_css_node();
{
css_node_t *node_0 = root_node;
node_0->style.justify_content = CSS_JUSTIFY_CENTER;
init_css_node_children(node_0, 1);
{
css_node_t *node_1;
node_1 = node_0->get_child(node_0->context, 0);
node_1->style.margin[CSS_TOP] = 20;
}
}
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] = 0;
node_0->layout.dimensions[CSS_HEIGHT] = 20;
init_css_node_children(node_0, 1);
{
css_node_t *node_1;
node_1 = node_0->get_child(node_0->context, 0);
node_1->layout.position[CSS_TOP] = 20;
node_1->layout.position[CSS_LEFT] = 0;
node_1->layout.dimensions[CSS_WIDTH] = 0;
node_1->layout.dimensions[CSS_HEIGHT] = 0;
}
}
test("should layout positive margin top inside of justify content center container", root_node, root_layout);
}
{
css_node_t *root_node = new_test_css_node();
{
css_node_t *node_0 = root_node;
node_0->style.justify_content = CSS_JUSTIFY_FLEX_END;
node_0->style.border[CSS_BOTTOM] = 5;
init_css_node_children(node_0, 1);
{
css_node_t *node_1;
node_1 = node_0->get_child(node_0->context, 0);
}
}
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] = 0;
node_0->layout.dimensions[CSS_HEIGHT] = 5;
init_css_node_children(node_0, 1);
{
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] = 0;
node_1->layout.dimensions[CSS_HEIGHT] = 0;
}
}
test("should layout border bottom and flex end with an empty child", root_node, root_layout);
}
{
css_node_t *root_node = new_test_css_node();
{
css_node_t *node_0 = root_node;
node_0->style.dimensions[CSS_WIDTH] = 800;
init_css_node_children(node_0, 1);
{
css_node_t *node_1;
node_1 = node_0->get_child(node_0->context, 0);
node_1->style.position[CSS_LEFT] = 5;
init_css_node_children(node_1, 1);
{
css_node_t *node_2;
node_2 = node_1->get_child(node_1->context, 0);
}
}
}
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] = 800;
node_0->layout.dimensions[CSS_HEIGHT] = 0;
init_css_node_children(node_0, 1);
{
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] = 5;
node_1->layout.dimensions[CSS_WIDTH] = 800;
node_1->layout.dimensions[CSS_HEIGHT] = 0;
init_css_node_children(node_1, 1);
{
css_node_t *node_2;
node_2 = node_1->get_child(node_1->context, 0);
node_2->layout.position[CSS_TOP] = 0;
node_2->layout.position[CSS_LEFT] = 0;
node_2->layout.dimensions[CSS_WIDTH] = 800;
node_2->layout.dimensions[CSS_HEIGHT] = 0;
}
}
}
test("should layout with children of a contain with left", root_node, root_layout);
}
/** END_GENERATED **/
return tests_finished();

View File

@@ -340,8 +340,7 @@ public class LayoutEngine {
if (getAlignItem(node, child) == CSSAlign.STRETCH &&
getPositionType(child) == CSSPositionType.RELATIVE &&
!CSSConstants.isUndefined(getLayoutDimension(node, getDim(crossAxis))) &&
!isDimDefined(child, crossAxis) &&
!isPosDefined(child, getLeading(crossAxis))) {
!isDimDefined(child, crossAxis)) {
setLayoutDimension(child, getDim(crossAxis), Math.max(
getLayoutDimension(node, getDim(crossAxis)) -
getPaddingAndBorderAxis(node, crossAxis) -
@@ -426,7 +425,6 @@ public class LayoutEngine {
}
}
// <Loop B> Layout flexible children and allocate empty space
// In order to position the elements in the main axis, we have two
@@ -435,14 +433,13 @@ public class LayoutEngine {
float leadingMainDim = 0;
float betweenMainDim = 0;
// If the dimensions of the current node is defined by its children, they
// are all going to be packed together and we don't need to compute
// anything.
float definedMainDim = Math.max(mainContentDim, 0);
if (!CSSConstants.isUndefined(getLayoutDimension(node, getDim(mainAxis)))) {
definedMainDim = getLayoutDimension(node, getDim(mainAxis)) -
getPaddingAndBorderAxis(node, mainAxis);
}
// The remaining available space that needs to be allocated
float remainingMainDim = getLayoutDimension(node, getDim(mainAxis)) -
getPaddingAndBorderAxis(node, mainAxis) -
mainContentDim;
float remainingMainDim = definedMainDim - mainContentDim;
// If there are flexible children in the mix, they are going to fill the
// remaining space
@@ -494,8 +491,12 @@ public class LayoutEngine {
leadingMainDim = remainingMainDim;
} else if (justifyContent == CSSJustify.SPACE_BETWEEN) {
remainingMainDim = Math.max(remainingMainDim, 0);
if (flexibleChildrenCount + nonFlexibleChildrenCount - 1 != 0) {
betweenMainDim = remainingMainDim /
(flexibleChildrenCount + nonFlexibleChildrenCount - 1);
} else {
betweenMainDim = 0;
}
} else if (justifyContent == CSSJustify.SPACE_AROUND) {
// Space on the edges is half of the space between elements
betweenMainDim = remainingMainDim /
@@ -503,7 +504,6 @@ public class LayoutEngine {
leadingMainDim = betweenMainDim / 2;
}
}
}
// <Loop C> Position elements in the main axis and compute dimensions

View File

@@ -3585,7 +3585,7 @@ public class LayoutEngineTest {
}
}
test("should calcluate left properly with position: absolute right", root_node, root_layout);
test("should calculate left properly with position: absolute right", root_node, root_layout);
}
@Test
@@ -3661,7 +3661,7 @@ public class LayoutEngineTest {
}
}
test("should calcluate left properly with position: absolute right and width", root_node, root_layout);
test("should calculate left properly with position: absolute right and width", root_node, root_layout);
}
@Test
@@ -3698,7 +3698,7 @@ public class LayoutEngineTest {
}
}
test("should calcluate top properly with position: absolute right, width, and no parent dimensions", root_node, root_layout);
test("should calculate top properly with position: absolute right, width, and no parent dimensions", root_node, root_layout);
}
@Test
@@ -3735,7 +3735,201 @@ public class LayoutEngineTest {
}
}
test("should calcluate left properly with position: absolute right, width, and no parent dimensions", root_node, root_layout);
test("should calculate left properly with position: absolute right, width, and no parent dimensions", root_node, root_layout);
}
@Test
public void testCase88()
{
TestCSSNode root_node = new TestCSSNode();
{
TestCSSNode node_0 = root_node;
node_0.style.justifyContent = CSSJustify.SPACE_BETWEEN;
addChildren(node_0, 1);
{
TestCSSNode node_1;
node_1 = node_0.getChildAt(0);
node_1.style.border[CSSStyle.SPACING_BOTTOM] = 1;
}
}
TestCSSNode root_layout = new TestCSSNode();
{
TestCSSNode node_0 = root_layout;
node_0.layout.y = 0;
node_0.layout.x = 0;
node_0.layout.width = 0;
node_0.layout.height = 1;
addChildren(node_0, 1);
{
TestCSSNode node_1;
node_1 = node_0.getChildAt(0);
node_1.layout.y = 0;
node_1.layout.x = 0;
node_1.layout.width = 0;
node_1.layout.height = 1;
}
}
test("should layout border bottom inside of justify content space between container", root_node, root_layout);
}
@Test
public void testCase89()
{
TestCSSNode root_node = new TestCSSNode();
{
TestCSSNode node_0 = root_node;
node_0.style.justifyContent = CSSJustify.CENTER;
addChildren(node_0, 1);
{
TestCSSNode node_1;
node_1 = node_0.getChildAt(0);
node_1.style.margin[CSSStyle.SPACING_TOP] = -6;
}
}
TestCSSNode root_layout = new TestCSSNode();
{
TestCSSNode node_0 = root_layout;
node_0.layout.y = 0;
node_0.layout.x = 0;
node_0.layout.width = 0;
node_0.layout.height = 0;
addChildren(node_0, 1);
{
TestCSSNode node_1;
node_1 = node_0.getChildAt(0);
node_1.layout.y = -3;
node_1.layout.x = 0;
node_1.layout.width = 0;
node_1.layout.height = 0;
}
}
test("should layout negative margin top inside of justify content center container", root_node, root_layout);
}
@Test
public void testCase90()
{
TestCSSNode root_node = new TestCSSNode();
{
TestCSSNode node_0 = root_node;
node_0.style.justifyContent = CSSJustify.CENTER;
addChildren(node_0, 1);
{
TestCSSNode node_1;
node_1 = node_0.getChildAt(0);
node_1.style.margin[CSSStyle.SPACING_TOP] = 20;
}
}
TestCSSNode root_layout = new TestCSSNode();
{
TestCSSNode node_0 = root_layout;
node_0.layout.y = 0;
node_0.layout.x = 0;
node_0.layout.width = 0;
node_0.layout.height = 20;
addChildren(node_0, 1);
{
TestCSSNode node_1;
node_1 = node_0.getChildAt(0);
node_1.layout.y = 20;
node_1.layout.x = 0;
node_1.layout.width = 0;
node_1.layout.height = 0;
}
}
test("should layout positive margin top inside of justify content center container", root_node, root_layout);
}
@Test
public void testCase91()
{
TestCSSNode root_node = new TestCSSNode();
{
TestCSSNode node_0 = root_node;
node_0.style.justifyContent = CSSJustify.FLEX_END;
node_0.style.border[CSSStyle.SPACING_BOTTOM] = 5;
addChildren(node_0, 1);
{
TestCSSNode node_1;
node_1 = node_0.getChildAt(0);
}
}
TestCSSNode root_layout = new TestCSSNode();
{
TestCSSNode node_0 = root_layout;
node_0.layout.y = 0;
node_0.layout.x = 0;
node_0.layout.width = 0;
node_0.layout.height = 5;
addChildren(node_0, 1);
{
TestCSSNode node_1;
node_1 = node_0.getChildAt(0);
node_1.layout.y = 0;
node_1.layout.x = 0;
node_1.layout.width = 0;
node_1.layout.height = 0;
}
}
test("should layout border bottom and flex end with an empty child", root_node, root_layout);
}
@Test
public void testCase92()
{
TestCSSNode root_node = new TestCSSNode();
{
TestCSSNode node_0 = root_node;
node_0.style.width = 800;
addChildren(node_0, 1);
{
TestCSSNode node_1;
node_1 = node_0.getChildAt(0);
node_1.style.positionLeft = 5;
addChildren(node_1, 1);
{
TestCSSNode node_2;
node_2 = node_1.getChildAt(0);
}
}
}
TestCSSNode root_layout = new TestCSSNode();
{
TestCSSNode node_0 = root_layout;
node_0.layout.y = 0;
node_0.layout.x = 0;
node_0.layout.width = 800;
node_0.layout.height = 0;
addChildren(node_0, 1);
{
TestCSSNode node_1;
node_1 = node_0.getChildAt(0);
node_1.layout.y = 0;
node_1.layout.x = 5;
node_1.layout.width = 800;
node_1.layout.height = 0;
addChildren(node_1, 1);
{
TestCSSNode node_2;
node_2 = node_1.getChildAt(0);
node_2.layout.y = 0;
node_2.layout.x = 0;
node_2.layout.width = 800;
node_2.layout.height = 0;
}
}
}
test("should layout with children of a contain with left", root_node, root_layout);
}
/** END_GENERATED **/
}

View File

@@ -232,6 +232,7 @@ function transpileAnnotatedJStoC(jsCode) {
.replace(/parent\./g, 'parent->')
.replace(/var\/\*([^\/]+)\*\//g, '$1')
.replace(/ === /g, ' == ')
.replace(/ !== /g, ' != ')
.replace(/\n /g, '\n')
.replace(/\/\*\(c\)!([^*]+)\*\//g, '$1')
.replace(/\/[*]!([^*]+)[*]\//g, '$1')