From 3499e2e0efaa06cf8bd56c9623bb47defc07c06f Mon Sep 17 00:00:00 2001 From: David Aurelio Date: Mon, 30 Jul 2018 09:30:51 -0700 Subject: [PATCH] Add `YogaNodeProperties` implementation based on `ByteBuffer` Summary: @public Adds an implementation of `YogaNodeProperties` that accesses style and layout properties using a `ByteBuffer` rather than JNI calls. We hope for a speed improvement. This needs further cleanup after experimenting, e.g. to codegen the offsets. Reviewed By: pasqualeanatriello Differential Revision: D8911723 fbshipit-source-id: 3c24b57eb545155878896ebb5d64d4553eb6bedc --- java/BUCK | 1 + java/com/facebook/yoga/YogaNode.java | 41 +- .../facebook/yoga/YogaNodeMemoryLayout.java | 151 ++++++ .../com/facebook/yoga/YogaNodeProperties.java | 2 +- .../yoga/YogaNodePropertiesByteBuffer.java | 510 ++++++++++++++++++ .../facebook/yoga/YogaNodePropertiesJNI.java | 3 +- java/com/facebook/yoga/YogaValue.java | 4 +- java/jni/YGJNI.cpp | 57 +- .../facebook/yoga/TestParametrization.java | 54 ++ .../facebook/yoga/YGAbsolutePositionTest.java | 111 ++-- .../com/facebook/yoga/YGAlignContentTest.java | 237 ++++---- .../com/facebook/yoga/YGAlignItemsTest.java | 257 ++++----- .../com/facebook/yoga/YGAlignSelfTest.java | 41 +- .../com/facebook/yoga/YGAndroidNewsFeed.java | 48 +- .../tests/com/facebook/yoga/YGBorderTest.java | 35 +- .../com/facebook/yoga/YGDimensionTest.java | 27 +- .../com/facebook/yoga/YGDisplayTest.java | 51 +- .../facebook/yoga/YGFlexDirectionTest.java | 65 ++- java/tests/com/facebook/yoga/YGFlexTest.java | 71 ++- .../com/facebook/yoga/YGFlexWrapTest.java | 215 ++++---- .../facebook/yoga/YGJustifyContentTest.java | 129 +++-- .../tests/com/facebook/yoga/YGMarginTest.java | 191 ++++--- .../facebook/yoga/YGMinMaxDimensionTest.java | 153 +++--- .../com/facebook/yoga/YGPaddingTest.java | 39 +- .../com/facebook/yoga/YGPercentageTest.java | 141 ++--- .../com/facebook/yoga/YGRoundingTest.java | 141 ++--- .../com/facebook/yoga/YGSizeOverflowTest.java | 35 +- .../yoga/YogaNodeStylePropertiesTest.java | 114 ++-- .../tests/com/facebook/yoga/YogaNodeTest.java | 89 +-- 29 files changed, 2034 insertions(+), 979 deletions(-) create mode 100644 java/com/facebook/yoga/YogaNodeMemoryLayout.java create mode 100644 java/com/facebook/yoga/YogaNodePropertiesByteBuffer.java create mode 100644 java/tests/com/facebook/yoga/TestParametrization.java diff --git a/java/BUCK b/java/BUCK index 0975d521..4ddabcef 100644 --- a/java/BUCK +++ b/java/BUCK @@ -8,6 +8,7 @@ load("//:yoga_defs.bzl", "ANDROID", "CXX_LIBRARY_WHITELIST", "FBJNI_JAVA_TARGET" yoga_cxx_library( name = "jni", srcs = glob(["jni/*.cpp"]), + headers = glob(["jni/*.h"]), header_namespace = "", compiler_flags = [ "-fno-omit-frame-pointer", diff --git a/java/com/facebook/yoga/YogaNode.java b/java/com/facebook/yoga/YogaNode.java index 18c49cfd..17297019 100644 --- a/java/com/facebook/yoga/YogaNode.java +++ b/java/com/facebook/yoga/YogaNode.java @@ -18,12 +18,10 @@ import javax.annotation.Nullable; public class YogaNode implements Cloneable { static { - SoLoader.loadLibrary("yoga"); + SoLoader.loadLibrary("yoga"); } - /** - * Get native instance count. Useful for testing only. - */ + /** Get native instance count. Useful for testing only. */ static native int jni_YGNodeGetInstanceCount(); private YogaNodeProperties mDelegate; @@ -41,6 +39,14 @@ public class YogaNode implements Cloneable { mDelegate = new YogaNodePropertiesJNI(this, config); } + public YogaNode(boolean unsafeClownyUseByteBufferValueDoesNotMatter) { + mDelegate = new YogaNodePropertiesByteBuffer(this); + } + + public YogaNode(boolean unsafeClownyUseByteBufferValueDoesNotMatter, YogaConfig config) { + mDelegate = new YogaNodePropertiesByteBuffer(this, config); + } + public long getNativePointer() { return mDelegate.getNativePointer(); } @@ -69,6 +75,7 @@ public class YogaNode implements Cloneable { } private native void jni_YGNodeInsertChild(long nativePointer, long childPointer, int index); + public void addChildAt(YogaNode child, int i) { if (child.mOwner != null) { throw new IllegalStateException("Child already has a parent, it must be removed first."); @@ -144,6 +151,7 @@ public class YogaNode implements Cloneable { } private native void jni_YGNodeRemoveChild(long nativePointer, long childPointer); + public YogaNode removeChildAt(int i) { if (mChildren == null) { throw new IllegalStateException( @@ -156,12 +164,10 @@ public class YogaNode implements Cloneable { } /** - * @returns the {@link YogaNode} that owns this {@link YogaNode}. - * The owner is used to identify the YogaTree that a {@link YogaNode} belongs - * to. - * This method will return the parent of the {@link YogaNode} when the - * {@link YogaNode} only belongs to one YogaTree or null when the - * {@link YogaNode} is shared between two or more YogaTrees. + * @returns the {@link YogaNode} that owns this {@link YogaNode}. The owner is used to identify + * the YogaTree that a {@link YogaNode} belongs to. This method will return the parent of the + * {@link YogaNode} when the {@link YogaNode} only belongs to one YogaTree or null when the + * {@link YogaNode} is shared between two or more YogaTrees. */ @Nullable public YogaNode getOwner() { @@ -179,10 +185,11 @@ public class YogaNode implements Cloneable { return mChildren == null ? -1 : mChildren.indexOf(child); } - private native void jni_YGNodeCalculateLayout(long nativePointer, float width, float height); + private native boolean jni_YGNodeCalculateLayout(long nativePointer, float width, float height); + public void calculateLayout(float width, float height) { - jni_YGNodeCalculateLayout(getNativePointer(), width, height); - mDelegate.onAfterCalculateLayout(); + boolean hasNewLayout = jni_YGNodeCalculateLayout(getNativePointer(), width, height); + mDelegate.onAfterCalculateLayout(hasNewLayout); } public boolean hasNewLayout() { @@ -190,6 +197,7 @@ public class YogaNode implements Cloneable { } private native void jni_YGNodeMarkDirty(long nativePointer); + public void dirty() { jni_YGNodeMarkDirty(getNativePointer()); } @@ -205,6 +213,7 @@ public class YogaNode implements Cloneable { } private native void jni_YGNodeCopyStyle(long dstNativePointer, long srcNativePointer); + public void copyStyle(YogaNode srcNode) { jni_YGNodeCopyStyle(getNativePointer(), srcNode.getNativePointer()); } @@ -498,6 +507,7 @@ public class YogaNode implements Cloneable { } private native void jni_YGNodeSetHasMeasureFunc(long nativePointer, boolean hasMeasureFunc); + public void setMeasureFunction(YogaMeasureFunction measureFunction) { mMeasureFunction = measureFunction; jni_YGNodeSetHasMeasureFunc(getNativePointer(), measureFunction != null); @@ -523,6 +533,7 @@ public class YogaNode implements Cloneable { } private native void jni_YGNodeSetHasBaselineFunc(long nativePointer, boolean hasMeasureFunc); + public void setBaselineFunction(YogaBaselineFunction baselineFunction) { mBaselineFunction = baselineFunction; jni_YGNodeSetHasBaselineFunc(getNativePointer(), baselineFunction != null); @@ -548,8 +559,8 @@ public class YogaNode implements Cloneable { private native void jni_YGNodePrint(long nativePointer); /** - * Use the set logger (defaults to adb log) to print out the styles, children, and computed - * layout of the tree rooted at this node. + * Use the set logger (defaults to adb log) to print out the styles, children, and computed layout + * of the tree rooted at this node. */ public void print() { jni_YGNodePrint(getNativePointer()); diff --git a/java/com/facebook/yoga/YogaNodeMemoryLayout.java b/java/com/facebook/yoga/YogaNodeMemoryLayout.java new file mode 100644 index 00000000..212c27ec --- /dev/null +++ b/java/com/facebook/yoga/YogaNodeMemoryLayout.java @@ -0,0 +1,151 @@ +/* + * Copyright (c) 2014-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the LICENSE + * file in the root directory of this source tree. + * + */ + +package com.facebook.yoga; + +import com.facebook.proguard.annotations.DoNotStrip; +import java.nio.ByteBuffer; + +@DoNotStrip +/* package */ final class YogaNodeMemoryLayout { + + private static final int FLOAT_SIZE = 4; + private static final int INT_SIZE = 4; + private static final int VALUE_SIZE = FLOAT_SIZE + INT_SIZE; + private static final byte FALSE = 0; + private static final byte TRUE = 1; + private static final int AUTO = YogaUnit.AUTO.intValue(); + private static final int POINT = YogaUnit.POINT.intValue(); + private static final int PERCENT = YogaUnit.PERCENT.intValue(); + private static final int UNDEFINED = YogaUnit.UNDEFINED.intValue(); + + // TODO(davidaurelio) code-gen these values + static final int styleDirection = 0; + static final int styleFlexDirection = 4; + static final int styleJustifyContent = 8; + static final int styleAlignContent = 12; + static final int styleAlignItems = 16; + static final int styleAlignSelf = 20; + static final int stylePositionType = 24; + static final int styleFlexWrap = 28; + static final int styleOverflow = 32; + static final int styleDisplay = 36; + static final int styleFlex = 40; + static final int styleFlexGrow = 48; + static final int styleFlexShrink = 56; + static final int styleFlexBasis = 64; + static final int styleMargin = 72; + static final int stylePosition = 144; + static final int stylePadding = 216; + static final int styleBorder = 288; + static final int styleDimensions = 360; + static final int styleMinDimensions = 376; + static final int styleMaxDimensions = 392; + static final int styleAspectRatio = 408; + + static final int styleWidth = styleDimensions; + static final int styleHeight = styleDimensions + VALUE_SIZE; + static final int styleMinWidth = styleMinDimensions; + static final int styleMinHeight = styleMinDimensions + VALUE_SIZE; + static final int styleMaxWidth = styleMaxDimensions; + static final int styleMaxHeight = styleMaxDimensions + VALUE_SIZE; + + static final int layoutPosition = 0; + static final int layoutDimensions = 16; + static final int layoutMargin = 24; + static final int layoutBorder = 48; + static final int layoutPadding = 72; + static final int layoutDirection = 96; + static final int layoutComputedFlexBasisGeneration = 100; + static final int layoutComputedFlexBasis = 104; + static final int layoutHadOverflow = 112; + static final int layoutGenerationCount = 116; + static final int layoutLastOwnerDirection = 120; + static final int layoutNextCachedMeasurementsIndex = 124; + static final int layoutCachedMeasurements = 128; + static final int layoutMeasuredDimensions = 512; + static final int layoutCachedLayout = 520; + static final int layoutDidUseLegacyFlag = 544; + static final int layoutDoesLegacyStretchFlagAffectsLayout = 545; + + static final int layoutX = layoutPosition; + static final int layoutY = layoutPosition + FLOAT_SIZE; + static final int layoutWidth = layoutDimensions; + static final int layoutHeight = layoutDimensions + FLOAT_SIZE; + + static int stylePositionOffset(YogaEdge edge) { + return stylePosition + edge.intValue() * VALUE_SIZE; + } + + static int styleMarginOffset(YogaEdge edge) { + return styleMargin + edge.intValue() * VALUE_SIZE; + } + + static int layoutMarginOffset(YogaEdge edge) { + return layoutMargin + edge.intValue() * FLOAT_SIZE; + } + + static int stylePaddingOffset(YogaEdge edge) { + return stylePadding + edge.intValue() * VALUE_SIZE; + } + + static int layoutPaddingOffset(YogaEdge edge) { + return layoutPadding + edge.intValue() * FLOAT_SIZE; + } + + static int styleBorderOffset(YogaEdge edge) { + return styleBorder + edge.intValue() * VALUE_SIZE; + } + + static int layoutBorderOffset(YogaEdge edge) { + return layoutBorder + edge.intValue() * FLOAT_SIZE; + } + + static void putOptional(ByteBuffer buffer, int offset, float value) { + buffer.putFloat(offset, value); + buffer.put( + offset + FLOAT_SIZE, YogaConstants.isUndefined(value) ? TRUE : FALSE); // bool isUndefined_ + } + + static float getOptional(ByteBuffer buffer, int offset) { + return getBoolean(buffer, offset + FLOAT_SIZE) + ? YogaConstants.UNDEFINED + : buffer.getFloat(offset); + } + + private static void putValue(ByteBuffer buffer, int offset, float value, int unit) { + if (YogaConstants.isUndefined(value)) { + value = YogaConstants.UNDEFINED; + unit = UNDEFINED; + } + buffer.putFloat(offset, value); + buffer.putInt(offset + FLOAT_SIZE, unit); + } + + static void putAutoValue(ByteBuffer buffer, int offset) { + putValue(buffer, offset, 0, AUTO); + } + + static void putPointValue(ByteBuffer buffer, int offset, float value) { + putValue(buffer, offset, value, POINT); + } + + static void putPercentValue(ByteBuffer buffer, int offset, float value) { + putValue(buffer, offset, value, PERCENT); + } + + static YogaValue getValue(ByteBuffer buffer, int offset) { + float value = buffer.getFloat(offset); + int unit = buffer.getInt(offset + FLOAT_SIZE); + return new YogaValue(value, YogaUnit.fromInt(unit)); + } + + static boolean getBoolean(ByteBuffer buffer, int offset) { + return buffer.get(offset) != 0; + } +} diff --git a/java/com/facebook/yoga/YogaNodeProperties.java b/java/com/facebook/yoga/YogaNodeProperties.java index 834aa833..c93145e4 100644 --- a/java/com/facebook/yoga/YogaNodeProperties.java +++ b/java/com/facebook/yoga/YogaNodeProperties.java @@ -13,7 +13,7 @@ public interface YogaNodeProperties { long getNativePointer(); - void onAfterCalculateLayout(); + void onAfterCalculateLayout(boolean hasNewLayout); void reset(); diff --git a/java/com/facebook/yoga/YogaNodePropertiesByteBuffer.java b/java/com/facebook/yoga/YogaNodePropertiesByteBuffer.java new file mode 100644 index 00000000..b792062b --- /dev/null +++ b/java/com/facebook/yoga/YogaNodePropertiesByteBuffer.java @@ -0,0 +1,510 @@ +/* + * Copyright (c) 2018-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the LICENSE + * file in the root directory of this source tree. + * + */ +package com.facebook.yoga; + +import com.facebook.proguard.annotations.DoNotStrip; +import com.facebook.soloader.SoLoader; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; + +@DoNotStrip +public class YogaNodePropertiesByteBuffer implements YogaNodeProperties, Cloneable { + + static { + SoLoader.loadLibrary("yoga"); + } + + private static final int RTL = YogaDirection.RTL.intValue(); + private final ByteBuffer mStyleBuffer; + private final ByteBuffer mLayoutBuffer; + private final long mNativePointer; + private boolean mHasBorderSet = false; + private boolean mHasNewLayout = true; + + private static native ByteBuffer jni_getStyleBuffer(long nativePointer); + + private static native ByteBuffer jni_getLayoutBuffer(long nativePointer); + + private static native long jni_YGNodeNewByteBuffer(YogaNode node); + + public YogaNodePropertiesByteBuffer(YogaNode node) { + this(jni_YGNodeNewByteBuffer(node)); + } + + private static native long jni_YGNodeNewByteBufferWithConfig(YogaNode node, long configPointer); + + public YogaNodePropertiesByteBuffer(YogaNode node, YogaConfig config) { + this(jni_YGNodeNewByteBufferWithConfig(node, config.mNativePointer)); + } + + public YogaNodePropertiesByteBuffer(long nativePointer) { + mNativePointer = nativePointer; + mStyleBuffer = jni_getStyleBuffer(nativePointer).order(ByteOrder.LITTLE_ENDIAN); + mLayoutBuffer = jni_getLayoutBuffer(nativePointer).order(ByteOrder.LITTLE_ENDIAN); + } + + private static native void jni_YGNodeFree(long nativePointer); + + @Override + protected void finalize() throws Throwable { + try { + jni_YGNodeFree(getNativePointer()); + } finally { + super.finalize(); + } + } + + private static native long jni_YGNodeCloneNoProps(long nativePointer, YogaNode newNode); + + @Override + public YogaNodeProperties clone(YogaNode node) { + long clonedNativePointer = jni_YGNodeCloneNoProps(getNativePointer(), node); + YogaNodePropertiesByteBuffer clone = new YogaNodePropertiesByteBuffer(clonedNativePointer); + clone.mHasBorderSet = mHasBorderSet; + clone.mHasNewLayout = mHasNewLayout; + return clone; + } + + @Override + public long getNativePointer() { + return mNativePointer; + } + + @Override + public void onAfterCalculateLayout(boolean hasNewLayout) { + mHasNewLayout = hasNewLayout; + } + + private static native void jni_YGNodeReset(long nativePointer); + + @Override + public void reset() { + mHasBorderSet = false; + jni_YGNodeReset(getNativePointer()); + } + + @Override + public boolean hasNewLayout() { + return mHasNewLayout; + } + + private static native boolean jni_YGNodeIsDirty(long nativePointer); + + @Override + public boolean isDirty() { + return jni_YGNodeIsDirty(mNativePointer); + } + + @Override + public void markLayoutSeen() { + mHasNewLayout = false; + } + + @Override + public YogaDirection getStyleDirection() { + return YogaDirection.fromInt(mStyleBuffer.getInt(YogaNodeMemoryLayout.styleDirection)); + } + + @Override + public YogaValue getPosition(YogaEdge edge) { + return YogaNodeMemoryLayout.getValue( + mStyleBuffer, YogaNodeMemoryLayout.stylePositionOffset(edge)); + } + + @Override + public YogaValue getMargin(YogaEdge edge) { + return YogaNodeMemoryLayout.getValue( + mStyleBuffer, YogaNodeMemoryLayout.styleMarginOffset(edge)); + } + + @Override + public YogaValue getPadding(YogaEdge edge) { + return YogaNodeMemoryLayout.getValue( + mStyleBuffer, YogaNodeMemoryLayout.stylePaddingOffset(edge)); + } + + @Override + public float getBorder(YogaEdge edge) { + return mHasBorderSet + ? mStyleBuffer.getFloat(YogaNodeMemoryLayout.styleBorderOffset(edge)) + : YogaConstants.UNDEFINED; + } + + @Override + public void setDirection(YogaDirection direction) { + mStyleBuffer.putInt(YogaNodeMemoryLayout.styleDirection, direction.intValue()); + } + + @Override + public YogaFlexDirection getFlexDirection() { + return YogaFlexDirection.fromInt(mStyleBuffer.getInt(YogaNodeMemoryLayout.styleFlexDirection)); + } + + @Override + public void setFlexDirection(YogaFlexDirection flexDirection) { + mStyleBuffer.putInt(YogaNodeMemoryLayout.styleFlexDirection, flexDirection.intValue()); + } + + @Override + public YogaJustify getJustifyContent() { + return YogaJustify.fromInt(mStyleBuffer.getInt(YogaNodeMemoryLayout.styleJustifyContent)); + } + + @Override + public void setJustifyContent(YogaJustify justifyContent) { + mStyleBuffer.putInt(YogaNodeMemoryLayout.styleJustifyContent, justifyContent.intValue()); + } + + @Override + public YogaAlign getAlignItems() { + return YogaAlign.fromInt(mStyleBuffer.getInt(YogaNodeMemoryLayout.styleAlignItems)); + } + + @Override + public void setAlignItems(YogaAlign alignItems) { + mStyleBuffer.putInt(YogaNodeMemoryLayout.styleAlignItems, alignItems.intValue()); + } + + @Override + public YogaAlign getAlignSelf() { + return YogaAlign.fromInt(mStyleBuffer.getInt(YogaNodeMemoryLayout.styleAlignSelf)); + } + + @Override + public void setAlignSelf(YogaAlign alignSelf) { + mStyleBuffer.putInt(YogaNodeMemoryLayout.styleAlignSelf, alignSelf.intValue()); + } + + @Override + public YogaAlign getAlignContent() { + return YogaAlign.fromInt(mStyleBuffer.getInt(YogaNodeMemoryLayout.styleAlignContent)); + } + + @Override + public void setAlignContent(YogaAlign alignContent) { + mStyleBuffer.putInt(YogaNodeMemoryLayout.styleAlignContent, alignContent.intValue()); + } + + @Override + public YogaPositionType getPositionType() { + return YogaPositionType.fromInt(mStyleBuffer.getInt(YogaNodeMemoryLayout.stylePositionType)); + } + + @Override + public void setPositionType(YogaPositionType positionType) { + mStyleBuffer.putInt(YogaNodeMemoryLayout.stylePositionType, positionType.intValue()); + } + + @Override + public void setWrap(YogaWrap flexWrap) { + mStyleBuffer.putInt(YogaNodeMemoryLayout.styleFlexWrap, flexWrap.intValue()); + } + + @Override + public YogaOverflow getOverflow() { + return YogaOverflow.fromInt(mStyleBuffer.getInt(YogaNodeMemoryLayout.styleOverflow)); + } + + @Override + public void setOverflow(YogaOverflow overflow) { + mStyleBuffer.putInt(YogaNodeMemoryLayout.styleOverflow, overflow.intValue()); + } + + @Override + public YogaDisplay getDisplay() { + return YogaDisplay.fromInt(mStyleBuffer.getInt(YogaNodeMemoryLayout.styleDisplay)); + } + + @Override + public void setDisplay(YogaDisplay display) { + mStyleBuffer.putInt(YogaNodeMemoryLayout.styleDisplay, display.intValue()); + } + + @Override + public void setFlex(float flex) { + YogaNodeMemoryLayout.putOptional(mStyleBuffer, YogaNodeMemoryLayout.styleFlex, flex); + } + + @Override + public float getFlexGrow() { + return mStyleBuffer.getFloat(YogaNodeMemoryLayout.styleFlexGrow); + } + + @Override + public void setFlexGrow(float flexGrow) { + YogaNodeMemoryLayout.putOptional(mStyleBuffer, YogaNodeMemoryLayout.styleFlexGrow, flexGrow); + } + + @Override + public float getFlexShrink() { + return mStyleBuffer.getFloat(YogaNodeMemoryLayout.styleFlexShrink); + } + + @Override + public void setFlexShrink(float flexShrink) { + YogaNodeMemoryLayout.putOptional( + mStyleBuffer, YogaNodeMemoryLayout.styleFlexShrink, flexShrink); + } + + @Override + public YogaValue getFlexBasis() { + return YogaNodeMemoryLayout.getValue(mStyleBuffer, YogaNodeMemoryLayout.styleFlexBasis); + } + + @Override + public void setFlexBasis(float flexBasis) { + YogaNodeMemoryLayout.putPointValue( + mStyleBuffer, YogaNodeMemoryLayout.styleFlexBasis, flexBasis); + } + + @Override + public void setFlexBasisPercent(float percent) { + YogaNodeMemoryLayout.putPercentValue( + mStyleBuffer, YogaNodeMemoryLayout.styleFlexBasis, percent); + } + + @Override + public void setFlexBasisAuto() { + YogaNodeMemoryLayout.putAutoValue(mStyleBuffer, YogaNodeMemoryLayout.styleFlexBasis); + } + + @Override + public void setMargin(YogaEdge edge, float margin) { + YogaNodeMemoryLayout.putPointValue( + mStyleBuffer, YogaNodeMemoryLayout.styleMarginOffset(edge), margin); + } + + @Override + public void setMarginPercent(YogaEdge edge, float percent) { + YogaNodeMemoryLayout.putPercentValue( + mStyleBuffer, YogaNodeMemoryLayout.styleMarginOffset(edge), percent); + } + + @Override + public void setMarginAuto(YogaEdge edge) { + YogaNodeMemoryLayout.putAutoValue(mStyleBuffer, YogaNodeMemoryLayout.styleMarginOffset(edge)); + } + + @Override + public void setPadding(YogaEdge edge, float padding) { + YogaNodeMemoryLayout.putPointValue( + mStyleBuffer, YogaNodeMemoryLayout.stylePaddingOffset(edge), padding); + } + + @Override + public void setPaddingPercent(YogaEdge edge, float percent) { + YogaNodeMemoryLayout.putPercentValue( + mStyleBuffer, YogaNodeMemoryLayout.stylePaddingOffset(edge), percent); + } + + @Override + public void setBorder(YogaEdge edge, float border) { + mHasBorderSet = true; + YogaNodeMemoryLayout.putPointValue( + mStyleBuffer, YogaNodeMemoryLayout.styleBorderOffset(edge), border); + } + + @Override + public void setPosition(YogaEdge edge, float position) { + YogaNodeMemoryLayout.putPointValue( + mStyleBuffer, YogaNodeMemoryLayout.stylePositionOffset(edge), position); + } + + @Override + public void setPositionPercent(YogaEdge edge, float percent) { + YogaNodeMemoryLayout.putPercentValue( + mStyleBuffer, YogaNodeMemoryLayout.stylePositionOffset(edge), percent); + } + + @Override + public YogaValue getWidth() { + return YogaNodeMemoryLayout.getValue(mStyleBuffer, YogaNodeMemoryLayout.styleWidth); + } + + @Override + public void setWidth(float width) { + YogaNodeMemoryLayout.putPointValue(mStyleBuffer, YogaNodeMemoryLayout.styleWidth, width); + } + + @Override + public void setWidthPercent(float percent) { + YogaNodeMemoryLayout.putPercentValue(mStyleBuffer, YogaNodeMemoryLayout.styleWidth, percent); + } + + @Override + public void setWidthAuto() { + YogaNodeMemoryLayout.putAutoValue(mStyleBuffer, YogaNodeMemoryLayout.styleWidth); + } + + @Override + public YogaValue getHeight() { + return YogaNodeMemoryLayout.getValue(mStyleBuffer, YogaNodeMemoryLayout.styleHeight); + } + + @Override + public void setHeight(float height) { + YogaNodeMemoryLayout.putPointValue(mStyleBuffer, YogaNodeMemoryLayout.styleHeight, height); + } + + @Override + public void setHeightPercent(float percent) { + YogaNodeMemoryLayout.putPercentValue(mStyleBuffer, YogaNodeMemoryLayout.styleHeight, percent); + } + + @Override + public void setHeightAuto() { + YogaNodeMemoryLayout.putAutoValue(mStyleBuffer, YogaNodeMemoryLayout.styleHeight); + } + + @Override + public YogaValue getMinWidth() { + return YogaNodeMemoryLayout.getValue(mStyleBuffer, YogaNodeMemoryLayout.styleMinWidth); + } + + @Override + public void setMinWidth(float minWidth) { + YogaNodeMemoryLayout.putPointValue(mStyleBuffer, YogaNodeMemoryLayout.styleMinWidth, minWidth); + } + + @Override + public void setMinWidthPercent(float percent) { + YogaNodeMemoryLayout.putPercentValue(mStyleBuffer, YogaNodeMemoryLayout.styleMinWidth, percent); + } + + @Override + public YogaValue getMinHeight() { + return YogaNodeMemoryLayout.getValue(mStyleBuffer, YogaNodeMemoryLayout.styleMinHeight); + } + + @Override + public void setMinHeight(float minHeight) { + YogaNodeMemoryLayout.putPointValue( + mStyleBuffer, YogaNodeMemoryLayout.styleMinHeight, minHeight); + } + + @Override + public void setMinHeightPercent(float percent) { + YogaNodeMemoryLayout.putPercentValue( + mStyleBuffer, YogaNodeMemoryLayout.styleMinHeight, percent); + } + + @Override + public YogaValue getMaxWidth() { + return YogaNodeMemoryLayout.getValue(mStyleBuffer, YogaNodeMemoryLayout.styleMaxWidth); + } + + @Override + public void setMaxWidth(float maxWidth) { + YogaNodeMemoryLayout.putPointValue(mStyleBuffer, YogaNodeMemoryLayout.styleMaxWidth, maxWidth); + } + + @Override + public void setMaxWidthPercent(float percent) { + YogaNodeMemoryLayout.putPercentValue(mStyleBuffer, YogaNodeMemoryLayout.styleMaxWidth, percent); + } + + @Override + public YogaValue getMaxHeight() { + return YogaNodeMemoryLayout.getValue(mStyleBuffer, YogaNodeMemoryLayout.styleMaxHeight); + } + + @Override + public void setMaxHeight(float maxHeight) { + YogaNodeMemoryLayout.putPointValue( + mStyleBuffer, YogaNodeMemoryLayout.styleMaxHeight, maxHeight); + } + + @Override + public void setMaxHeightPercent(float percent) { + YogaNodeMemoryLayout.putPercentValue( + mStyleBuffer, YogaNodeMemoryLayout.styleMaxHeight, percent); + } + + @Override + public float getAspectRatio() { + return YogaNodeMemoryLayout.getOptional(mStyleBuffer, YogaNodeMemoryLayout.styleAspectRatio); + } + + @Override + public void setAspectRatio(float aspectRatio) { + YogaNodeMemoryLayout.putOptional( + mStyleBuffer, YogaNodeMemoryLayout.styleAspectRatio, aspectRatio); + } + + @Override + public float getLayoutX() { + return mLayoutBuffer.getFloat(YogaNodeMemoryLayout.layoutX); + } + + @Override + public float getLayoutY() { + return mLayoutBuffer.getFloat(YogaNodeMemoryLayout.layoutY); + } + + @Override + public float getLayoutWidth() { + return mLayoutBuffer.getFloat(YogaNodeMemoryLayout.layoutWidth); + } + + @Override + public float getLayoutHeight() { + return mLayoutBuffer.getFloat(YogaNodeMemoryLayout.layoutHeight); + } + + @Override + public boolean getDoesLegacyStretchFlagAffectsLayout() { + return YogaNodeMemoryLayout.getBoolean( + mLayoutBuffer, YogaNodeMemoryLayout.layoutDoesLegacyStretchFlagAffectsLayout); + } + + @Override + public float getLayoutMargin(YogaEdge edge) { + return mLayoutBuffer.getFloat(YogaNodeMemoryLayout.layoutMarginOffset(layoutEdge(edge))); + } + + @Override + public float getLayoutPadding(YogaEdge edge) { + return mLayoutBuffer.getFloat(YogaNodeMemoryLayout.layoutPaddingOffset(layoutEdge(edge))); + } + + @Override + public float getLayoutBorder(YogaEdge edge) { + return mLayoutBuffer.getFloat(YogaNodeMemoryLayout.layoutBorderOffset(layoutEdge(edge))); + } + + @Override + public YogaDirection getLayoutDirection() { + return YogaDirection.fromInt(getLayoutDirectionInt()); + } + + @Override + public void freeNatives() { + jni_YGNodeFree(mNativePointer); + } + + private int getLayoutDirectionInt() { + return mLayoutBuffer.getInt(YogaNodeMemoryLayout.layoutDirection); + } + + private YogaEdge layoutEdge(YogaEdge edge) { + int layoutDirection = getLayoutDirectionInt(); + switch (edge) { + case LEFT: + return layoutDirection == RTL ? YogaEdge.END : YogaEdge.START; + case RIGHT: + return layoutDirection == RTL ? YogaEdge.START : YogaEdge.END; + case TOP: + case BOTTOM: + case START: + case END: + return edge; + default: + throw new IllegalArgumentException("Cannot get layout properties of multi-edge shorthands"); + } + } +} diff --git a/java/com/facebook/yoga/YogaNodePropertiesJNI.java b/java/com/facebook/yoga/YogaNodePropertiesJNI.java index d44cd1d2..3ce7b493 100644 --- a/java/com/facebook/yoga/YogaNodePropertiesJNI.java +++ b/java/com/facebook/yoga/YogaNodePropertiesJNI.java @@ -10,6 +10,7 @@ package com.facebook.yoga; import com.facebook.proguard.annotations.DoNotStrip; import com.facebook.soloader.SoLoader; +@DoNotStrip public class YogaNodePropertiesJNI implements Cloneable, YogaNodeProperties { static { @@ -105,7 +106,7 @@ public class YogaNodePropertiesJNI implements Cloneable, YogaNodeProperties { private static native void jni_YGTransferLayoutOutputsRecursive(long nativePointer); @Override - public void onAfterCalculateLayout() { + public void onAfterCalculateLayout(boolean hasNewLayoutIgnoredSetByNative) { jni_YGTransferLayoutOutputsRecursive(mNativePointer); } diff --git a/java/com/facebook/yoga/YogaValue.java b/java/com/facebook/yoga/YogaValue.java index c0bb6e22..27781a15 100644 --- a/java/com/facebook/yoga/YogaValue.java +++ b/java/com/facebook/yoga/YogaValue.java @@ -33,7 +33,9 @@ public class YogaValue { if (other instanceof YogaValue) { final YogaValue otherValue = (YogaValue) other; if (unit == otherValue.unit) { - return unit == YogaUnit.UNDEFINED || Float.compare(value, otherValue.value) == 0; + return unit == YogaUnit.UNDEFINED + || unit == YogaUnit.AUTO + || Float.compare(value, otherValue.value) == 0; } } return false; diff --git a/java/jni/YGJNI.cpp b/java/jni/YGJNI.cpp index dc38500e..d83f7034 100644 --- a/java/jni/YGJNI.cpp +++ b/java/jni/YGJNI.cpp @@ -6,6 +6,7 @@ * */ #include +#include #include #include #include @@ -26,6 +27,12 @@ struct JYogaNodePropertiesJNI : public JavaClass { "Lcom/facebook/yoga/YogaNodePropertiesJNI;"; }; +struct JYogaNodePropertiesByteBuffer + : public JavaClass { + static constexpr auto kJavaDescriptor = + "Lcom/facebook/yoga/YogaNodePropertiesByteBuffer"; +}; + struct YGConfigContext { global_ref* logger; global_ref* config; @@ -331,6 +338,19 @@ jlong jni_YGNodeNewWithConfig( return reinterpret_cast(node); } +jlong jni_YGNodeNewByteBuffer( + alias_ref, + alias_ref javaNode) { + return jni_YGNodeNew(nullptr, javaNode); +} + +jlong jni_YGNodeNewByteBufferWithConfig( + alias_ref, + alias_ref javaNode, + jlong configPointer) { + return jni_YGNodeNewWithConfig(nullptr, javaNode, configPointer); +} + void jni_YGNodeSetOwner( alias_ref thiz, jlong nativePointer, @@ -351,6 +371,13 @@ jlong jni_YGNodeClone( return reinterpret_cast(clonedYogaNode); } +jlong jni_YGNodeCloneNoProps( + alias_ref cls, + jlong nativePointer, + alias_ref clonedJavaObject) { + return jni_YGNodeClone(cls, nativePointer, clonedJavaObject, nullptr); +} + void jni_YGNodeFree(alias_ref thiz, jlong nativePointer) { const YGNodeRef node = _jlong2YGNodeRef(nativePointer); delete reinterpret_cast(node->getContext()); @@ -404,7 +431,7 @@ void jni_YGNodeRemoveChild( _jlong2YGNodeRef(nativePointer), _jlong2YGNodeRef(childPointer)); } -void jni_YGNodeCalculateLayout( +jboolean jni_YGNodeCalculateLayout( alias_ref, jlong nativePointer, jfloat width, @@ -415,6 +442,7 @@ void jni_YGNodeCalculateLayout( static_cast(width), static_cast(height), YGNodeStyleGetDirection(_jlong2YGNodeRef(nativePointer))); + return root->getHasNewLayout(); } static void jni_YGTransferLayoutOutputsRecursive( @@ -694,6 +722,21 @@ void jni_YGConfigSetLogger( jint jni_YGNodeGetInstanceCount(alias_ref clazz) { return YGNodeGetInstanceCount(); } +local_ref jni_getStyleBuffer( + alias_ref, + jlong nativePointer) { + YGStyle* style = &_jlong2YGNodeRef(nativePointer)->getStyle(); + return JByteBuffer::wrapBytes( + reinterpret_cast(style), sizeof(YGStyle)); +} + +local_ref jni_getLayoutBuffer( + alias_ref, + jlong nativePointer) { + YGLayout* layout = &_jlong2YGNodeRef(nativePointer)->getLayout(); + return JByteBuffer::wrapBytes( + reinterpret_cast(layout), sizeof(YGLayout)); +} #define YGMakeNativeMethod(name) makeNativeMethod(#name, name) @@ -803,5 +846,17 @@ jint JNI_OnLoad(JavaVM* vm, void*) { YGMakeNativeMethod( jni_YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviour), }); + registerNatives( + "com/facebook/yoga/YogaNodePropertiesByteBuffer", + { + YGMakeNativeMethod(jni_YGNodeCloneNoProps), + YGMakeNativeMethod(jni_YGNodeFree), + YGMakeNativeMethod(jni_YGNodeNewByteBuffer), + YGMakeNativeMethod(jni_YGNodeNewByteBufferWithConfig), + YGMakeNativeMethod(jni_YGNodeReset), + YGMakeNativeMethod(jni_YGNodeIsDirty), + YGMakeNativeMethod(jni_getStyleBuffer), + YGMakeNativeMethod(jni_getLayoutBuffer), + }); }); } diff --git a/java/tests/com/facebook/yoga/TestParametrization.java b/java/tests/com/facebook/yoga/TestParametrization.java new file mode 100644 index 00000000..f53f32b7 --- /dev/null +++ b/java/tests/com/facebook/yoga/TestParametrization.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2018-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the LICENSE + * file in the root directory of this source tree. + * + */ +package com.facebook.yoga; + +import java.util.Arrays; + +public class TestParametrization { + public static Iterable nodeFactories() { + return Arrays.asList( + new NodeFactory() { + @Override + public YogaNode create() { + return new YogaNode(); + } + + @Override + public YogaNode create(YogaConfig config) { + return new YogaNode(config); + } + + @Override + public String toString() { + return "JNI"; + } + }, + new NodeFactory() { + @Override + public YogaNode create() { + return new YogaNode(true); + } + + @Override + public YogaNode create(YogaConfig config) { + return new YogaNode(true, config); + } + + @Override + public String toString() { + return "ByteBuffer"; + } + }); + } + + public interface NodeFactory { + YogaNode create(); + + YogaNode create(YogaConfig config); + } +} diff --git a/java/tests/com/facebook/yoga/YGAbsolutePositionTest.java b/java/tests/com/facebook/yoga/YGAbsolutePositionTest.java index c0590a52..ac42a041 100644 --- a/java/tests/com/facebook/yoga/YGAbsolutePositionTest.java +++ b/java/tests/com/facebook/yoga/YGAbsolutePositionTest.java @@ -9,20 +9,30 @@ package com.facebook.yoga; -import org.junit.Test; - import static org.junit.Assert.assertEquals; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +@RunWith(Parameterized.class) public class YGAbsolutePositionTest { + @Parameterized.Parameters(name = "{0}") + public static Iterable nodeFactories() { + return TestParametrization.nodeFactories(); + } + + @Parameterized.Parameter public TestParametrization.NodeFactory mNodeFactory; + @Test public void test_absolute_layout_width_height_start_top() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setWidth(100f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setPositionType(YogaPositionType.ABSOLUTE); root_child0.setPosition(YogaEdge.START, 10f); root_child0.setPosition(YogaEdge.TOP, 10f); @@ -60,11 +70,11 @@ public class YGAbsolutePositionTest { public void test_absolute_layout_width_height_end_bottom() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setWidth(100f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setPositionType(YogaPositionType.ABSOLUTE); root_child0.setPosition(YogaEdge.END, 10f); root_child0.setPosition(YogaEdge.BOTTOM, 10f); @@ -102,11 +112,11 @@ public class YGAbsolutePositionTest { public void test_absolute_layout_start_top_end_bottom() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setWidth(100f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setPositionType(YogaPositionType.ABSOLUTE); root_child0.setPosition(YogaEdge.START, 10f); root_child0.setPosition(YogaEdge.TOP, 10f); @@ -144,11 +154,11 @@ public class YGAbsolutePositionTest { public void test_absolute_layout_width_height_start_top_end_bottom() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setWidth(100f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setPositionType(YogaPositionType.ABSOLUTE); root_child0.setPosition(YogaEdge.START, 10f); root_child0.setPosition(YogaEdge.TOP, 10f); @@ -188,19 +198,19 @@ public class YGAbsolutePositionTest { public void test_do_not_clamp_height_of_absolute_node_to_height_of_its_overflow_hidden_parent() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.ROW); root.setOverflow(YogaOverflow.HIDDEN); root.setWidth(50f); root.setHeight(50f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setPositionType(YogaPositionType.ABSOLUTE); root_child0.setPosition(YogaEdge.START, 0f); root_child0.setPosition(YogaEdge.TOP, 0f); root.addChildAt(root_child0, 0); - final YogaNode root_child0_child0 = new YogaNode(config); + final YogaNode root_child0_child0 = createNode(config); root_child0_child0.setWidth(100f); root_child0_child0.setHeight(100f); root_child0.addChildAt(root_child0_child0, 0); @@ -245,7 +255,7 @@ public class YGAbsolutePositionTest { public void test_absolute_layout_within_border() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setMargin(YogaEdge.LEFT, 10f); root.setMargin(YogaEdge.TOP, 10f); root.setMargin(YogaEdge.RIGHT, 10f); @@ -261,7 +271,7 @@ public class YGAbsolutePositionTest { root.setWidth(100f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setPositionType(YogaPositionType.ABSOLUTE); root_child0.setPosition(YogaEdge.LEFT, 0f); root_child0.setPosition(YogaEdge.TOP, 0f); @@ -269,7 +279,7 @@ public class YGAbsolutePositionTest { root_child0.setHeight(50f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setPositionType(YogaPositionType.ABSOLUTE); root_child1.setPosition(YogaEdge.RIGHT, 0f); root_child1.setPosition(YogaEdge.BOTTOM, 0f); @@ -277,7 +287,7 @@ public class YGAbsolutePositionTest { root_child1.setHeight(50f); root.addChildAt(root_child1, 1); - final YogaNode root_child2 = new YogaNode(config); + final YogaNode root_child2 = createNode(config); root_child2.setPositionType(YogaPositionType.ABSOLUTE); root_child2.setPosition(YogaEdge.LEFT, 0f); root_child2.setPosition(YogaEdge.TOP, 0f); @@ -289,7 +299,7 @@ public class YGAbsolutePositionTest { root_child2.setHeight(50f); root.addChildAt(root_child2, 2); - final YogaNode root_child3 = new YogaNode(config); + final YogaNode root_child3 = createNode(config); root_child3.setPositionType(YogaPositionType.ABSOLUTE); root_child3.setPosition(YogaEdge.RIGHT, 0f); root_child3.setPosition(YogaEdge.BOTTOM, 0f); @@ -361,14 +371,14 @@ public class YGAbsolutePositionTest { public void test_absolute_layout_align_items_and_justify_content_center() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setJustifyContent(YogaJustify.CENTER); root.setAlignItems(YogaAlign.CENTER); root.setFlexGrow(1f); root.setWidth(110f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setPositionType(YogaPositionType.ABSOLUTE); root_child0.setWidth(60f); root_child0.setHeight(40f); @@ -404,14 +414,14 @@ public class YGAbsolutePositionTest { public void test_absolute_layout_align_items_and_justify_content_flex_end() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setJustifyContent(YogaJustify.FLEX_END); root.setAlignItems(YogaAlign.FLEX_END); root.setFlexGrow(1f); root.setWidth(110f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setPositionType(YogaPositionType.ABSOLUTE); root_child0.setWidth(60f); root_child0.setHeight(40f); @@ -447,13 +457,13 @@ public class YGAbsolutePositionTest { public void test_absolute_layout_justify_content_center() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setJustifyContent(YogaJustify.CENTER); root.setFlexGrow(1f); root.setWidth(110f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setPositionType(YogaPositionType.ABSOLUTE); root_child0.setWidth(60f); root_child0.setHeight(40f); @@ -489,13 +499,13 @@ public class YGAbsolutePositionTest { public void test_absolute_layout_align_items_center() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setAlignItems(YogaAlign.CENTER); root.setFlexGrow(1f); root.setWidth(110f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setPositionType(YogaPositionType.ABSOLUTE); root_child0.setWidth(60f); root_child0.setHeight(40f); @@ -531,12 +541,12 @@ public class YGAbsolutePositionTest { public void test_absolute_layout_align_items_center_on_child_only() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexGrow(1f); root.setWidth(110f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setAlignSelf(YogaAlign.CENTER); root_child0.setPositionType(YogaPositionType.ABSOLUTE); root_child0.setWidth(60f); @@ -573,14 +583,14 @@ public class YGAbsolutePositionTest { public void test_absolute_layout_align_items_and_justify_content_center_and_top_position() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setJustifyContent(YogaJustify.CENTER); root.setAlignItems(YogaAlign.CENTER); root.setFlexGrow(1f); root.setWidth(110f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setPositionType(YogaPositionType.ABSOLUTE); root_child0.setPosition(YogaEdge.TOP, 10f); root_child0.setWidth(60f); @@ -617,14 +627,14 @@ public class YGAbsolutePositionTest { public void test_absolute_layout_align_items_and_justify_content_center_and_bottom_position() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setJustifyContent(YogaJustify.CENTER); root.setAlignItems(YogaAlign.CENTER); root.setFlexGrow(1f); root.setWidth(110f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setPositionType(YogaPositionType.ABSOLUTE); root_child0.setPosition(YogaEdge.BOTTOM, 10f); root_child0.setWidth(60f); @@ -661,14 +671,14 @@ public class YGAbsolutePositionTest { public void test_absolute_layout_align_items_and_justify_content_center_and_left_position() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setJustifyContent(YogaJustify.CENTER); root.setAlignItems(YogaAlign.CENTER); root.setFlexGrow(1f); root.setWidth(110f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setPositionType(YogaPositionType.ABSOLUTE); root_child0.setPosition(YogaEdge.LEFT, 5f); root_child0.setWidth(60f); @@ -705,14 +715,14 @@ public class YGAbsolutePositionTest { public void test_absolute_layout_align_items_and_justify_content_center_and_right_position() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setJustifyContent(YogaJustify.CENTER); root.setAlignItems(YogaAlign.CENTER); root.setFlexGrow(1f); root.setWidth(110f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setPositionType(YogaPositionType.ABSOLUTE); root_child0.setPosition(YogaEdge.RIGHT, 5f); root_child0.setWidth(60f); @@ -749,7 +759,7 @@ public class YGAbsolutePositionTest { public void test_position_root_with_rtl_should_position_withoutdirection() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setPosition(YogaEdge.LEFT, 72f); root.setWidth(52f); root.setHeight(52f); @@ -774,25 +784,25 @@ public class YGAbsolutePositionTest { public void test_absolute_layout_percentage_bottom_based_on_parent_height() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setWidth(100f); root.setHeight(200f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setPositionType(YogaPositionType.ABSOLUTE); root_child0.setPositionPercent(YogaEdge.TOP, 50f); root_child0.setWidth(10f); root_child0.setHeight(10f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setPositionType(YogaPositionType.ABSOLUTE); root_child1.setPositionPercent(YogaEdge.BOTTOM, 50f); root_child1.setWidth(10f); root_child1.setHeight(10f); root.addChildAt(root_child1, 1); - final YogaNode root_child2 = new YogaNode(config); + final YogaNode root_child2 = createNode(config); root_child2.setPositionType(YogaPositionType.ABSOLUTE); root_child2.setPositionPercent(YogaEdge.TOP, 10f); root_child2.setPositionPercent(YogaEdge.BOTTOM, 10f); @@ -849,12 +859,12 @@ public class YGAbsolutePositionTest { public void test_absolute_layout_in_wrap_reverse_column_container() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setWrap(YogaWrap.WRAP_REVERSE); root.setWidth(100f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setPositionType(YogaPositionType.ABSOLUTE); root_child0.setWidth(20f); root_child0.setHeight(20f); @@ -890,13 +900,13 @@ public class YGAbsolutePositionTest { public void test_absolute_layout_in_wrap_reverse_row_container() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.ROW); root.setWrap(YogaWrap.WRAP_REVERSE); root.setWidth(100f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setPositionType(YogaPositionType.ABSOLUTE); root_child0.setWidth(20f); root_child0.setHeight(20f); @@ -932,12 +942,12 @@ public class YGAbsolutePositionTest { public void test_absolute_layout_in_wrap_reverse_column_container_flex_end() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setWrap(YogaWrap.WRAP_REVERSE); root.setWidth(100f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setAlignSelf(YogaAlign.FLEX_END); root_child0.setPositionType(YogaPositionType.ABSOLUTE); root_child0.setWidth(20f); @@ -974,13 +984,13 @@ public class YGAbsolutePositionTest { public void test_absolute_layout_in_wrap_reverse_row_container_flex_end() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.ROW); root.setWrap(YogaWrap.WRAP_REVERSE); root.setWidth(100f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setAlignSelf(YogaAlign.FLEX_END); root_child0.setPositionType(YogaPositionType.ABSOLUTE); root_child0.setWidth(20f); @@ -1013,4 +1023,7 @@ public class YGAbsolutePositionTest { assertEquals(20f, root_child0.getLayoutHeight(), 0.0f); } + private YogaNode createNode(YogaConfig config) { + return mNodeFactory.create(config); + } } diff --git a/java/tests/com/facebook/yoga/YGAlignContentTest.java b/java/tests/com/facebook/yoga/YGAlignContentTest.java index c20f9767..82ef4cb0 100644 --- a/java/tests/com/facebook/yoga/YGAlignContentTest.java +++ b/java/tests/com/facebook/yoga/YGAlignContentTest.java @@ -9,42 +9,52 @@ package com.facebook.yoga; -import org.junit.Test; - import static org.junit.Assert.assertEquals; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +@RunWith(Parameterized.class) public class YGAlignContentTest { + @Parameterized.Parameters(name = "{0}") + public static Iterable nodeFactories() { + return TestParametrization.nodeFactories(); + } + + @Parameterized.Parameter public TestParametrization.NodeFactory mNodeFactory; + @Test public void test_align_content_flex_start() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.ROW); root.setWrap(YogaWrap.WRAP); root.setWidth(130f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setWidth(50f); root_child0.setHeight(10f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setWidth(50f); root_child1.setHeight(10f); root.addChildAt(root_child1, 1); - final YogaNode root_child2 = new YogaNode(config); + final YogaNode root_child2 = createNode(config); root_child2.setWidth(50f); root_child2.setHeight(10f); root.addChildAt(root_child2, 2); - final YogaNode root_child3 = new YogaNode(config); + final YogaNode root_child3 = createNode(config); root_child3.setWidth(50f); root_child3.setHeight(10f); root.addChildAt(root_child3, 3); - final YogaNode root_child4 = new YogaNode(config); + final YogaNode root_child4 = createNode(config); root_child4.setWidth(50f); root_child4.setHeight(10f); root.addChildAt(root_child4, 4); @@ -119,30 +129,30 @@ public class YGAlignContentTest { public void test_align_content_flex_start_without_height_on_children() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setWrap(YogaWrap.WRAP); root.setWidth(100f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setWidth(50f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setWidth(50f); root_child1.setHeight(10f); root.addChildAt(root_child1, 1); - final YogaNode root_child2 = new YogaNode(config); + final YogaNode root_child2 = createNode(config); root_child2.setWidth(50f); root.addChildAt(root_child2, 2); - final YogaNode root_child3 = new YogaNode(config); + final YogaNode root_child3 = createNode(config); root_child3.setWidth(50f); root_child3.setHeight(10f); root.addChildAt(root_child3, 3); - final YogaNode root_child4 = new YogaNode(config); + final YogaNode root_child4 = createNode(config); root_child4.setWidth(50f); root.addChildAt(root_child4, 4); root.setDirection(YogaDirection.LTR); @@ -216,36 +226,36 @@ public class YGAlignContentTest { public void test_align_content_flex_start_with_flex() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setWrap(YogaWrap.WRAP); root.setWidth(100f); root.setHeight(120f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setFlexGrow(1f); root_child0.setFlexBasisPercent(0f); root_child0.setWidth(50f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setFlexGrow(1f); root_child1.setFlexBasisPercent(0f); root_child1.setWidth(50f); root_child1.setHeight(10f); root.addChildAt(root_child1, 1); - final YogaNode root_child2 = new YogaNode(config); + final YogaNode root_child2 = createNode(config); root_child2.setWidth(50f); root.addChildAt(root_child2, 2); - final YogaNode root_child3 = new YogaNode(config); + final YogaNode root_child3 = createNode(config); root_child3.setFlexGrow(1f); root_child3.setFlexShrink(1f); root_child3.setFlexBasisPercent(0f); root_child3.setWidth(50f); root.addChildAt(root_child3, 3); - final YogaNode root_child4 = new YogaNode(config); + final YogaNode root_child4 = createNode(config); root_child4.setWidth(50f); root.addChildAt(root_child4, 4); root.setDirection(YogaDirection.LTR); @@ -319,33 +329,33 @@ public class YGAlignContentTest { public void test_align_content_flex_end() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setAlignContent(YogaAlign.FLEX_END); root.setWrap(YogaWrap.WRAP); root.setWidth(100f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setWidth(50f); root_child0.setHeight(10f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setWidth(50f); root_child1.setHeight(10f); root.addChildAt(root_child1, 1); - final YogaNode root_child2 = new YogaNode(config); + final YogaNode root_child2 = createNode(config); root_child2.setWidth(50f); root_child2.setHeight(10f); root.addChildAt(root_child2, 2); - final YogaNode root_child3 = new YogaNode(config); + final YogaNode root_child3 = createNode(config); root_child3.setWidth(50f); root_child3.setHeight(10f); root.addChildAt(root_child3, 3); - final YogaNode root_child4 = new YogaNode(config); + final YogaNode root_child4 = createNode(config); root_child4.setWidth(50f); root_child4.setHeight(10f); root.addChildAt(root_child4, 4); @@ -420,29 +430,29 @@ public class YGAlignContentTest { public void test_align_content_stretch() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setAlignContent(YogaAlign.STRETCH); root.setWrap(YogaWrap.WRAP); root.setWidth(150f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setWidth(50f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setWidth(50f); root.addChildAt(root_child1, 1); - final YogaNode root_child2 = new YogaNode(config); + final YogaNode root_child2 = createNode(config); root_child2.setWidth(50f); root.addChildAt(root_child2, 2); - final YogaNode root_child3 = new YogaNode(config); + final YogaNode root_child3 = createNode(config); root_child3.setWidth(50f); root.addChildAt(root_child3, 3); - final YogaNode root_child4 = new YogaNode(config); + final YogaNode root_child4 = createNode(config); root_child4.setWidth(50f); root.addChildAt(root_child4, 4); root.setDirection(YogaDirection.LTR); @@ -516,34 +526,34 @@ public class YGAlignContentTest { public void test_align_content_spacebetween() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.ROW); root.setAlignContent(YogaAlign.SPACE_BETWEEN); root.setWrap(YogaWrap.WRAP); root.setWidth(130f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setWidth(50f); root_child0.setHeight(10f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setWidth(50f); root_child1.setHeight(10f); root.addChildAt(root_child1, 1); - final YogaNode root_child2 = new YogaNode(config); + final YogaNode root_child2 = createNode(config); root_child2.setWidth(50f); root_child2.setHeight(10f); root.addChildAt(root_child2, 2); - final YogaNode root_child3 = new YogaNode(config); + final YogaNode root_child3 = createNode(config); root_child3.setWidth(50f); root_child3.setHeight(10f); root.addChildAt(root_child3, 3); - final YogaNode root_child4 = new YogaNode(config); + final YogaNode root_child4 = createNode(config); root_child4.setWidth(50f); root_child4.setHeight(10f); root.addChildAt(root_child4, 4); @@ -618,34 +628,34 @@ public class YGAlignContentTest { public void test_align_content_spacearound() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.ROW); root.setAlignContent(YogaAlign.SPACE_AROUND); root.setWrap(YogaWrap.WRAP); root.setWidth(140f); root.setHeight(120f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setWidth(50f); root_child0.setHeight(10f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setWidth(50f); root_child1.setHeight(10f); root.addChildAt(root_child1, 1); - final YogaNode root_child2 = new YogaNode(config); + final YogaNode root_child2 = createNode(config); root_child2.setWidth(50f); root_child2.setHeight(10f); root.addChildAt(root_child2, 2); - final YogaNode root_child3 = new YogaNode(config); + final YogaNode root_child3 = createNode(config); root_child3.setWidth(50f); root_child3.setHeight(10f); root.addChildAt(root_child3, 3); - final YogaNode root_child4 = new YogaNode(config); + final YogaNode root_child4 = createNode(config); root_child4.setWidth(50f); root_child4.setHeight(10f); root.addChildAt(root_child4, 4); @@ -720,30 +730,30 @@ public class YGAlignContentTest { public void test_align_content_stretch_row() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.ROW); root.setAlignContent(YogaAlign.STRETCH); root.setWrap(YogaWrap.WRAP); root.setWidth(150f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setWidth(50f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setWidth(50f); root.addChildAt(root_child1, 1); - final YogaNode root_child2 = new YogaNode(config); + final YogaNode root_child2 = createNode(config); root_child2.setWidth(50f); root.addChildAt(root_child2, 2); - final YogaNode root_child3 = new YogaNode(config); + final YogaNode root_child3 = createNode(config); root_child3.setWidth(50f); root.addChildAt(root_child3, 3); - final YogaNode root_child4 = new YogaNode(config); + final YogaNode root_child4 = createNode(config); root_child4.setWidth(50f); root.addChildAt(root_child4, 4); root.setDirection(YogaDirection.LTR); @@ -817,36 +827,36 @@ public class YGAlignContentTest { public void test_align_content_stretch_row_with_children() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.ROW); root.setAlignContent(YogaAlign.STRETCH); root.setWrap(YogaWrap.WRAP); root.setWidth(150f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setWidth(50f); root.addChildAt(root_child0, 0); - final YogaNode root_child0_child0 = new YogaNode(config); + final YogaNode root_child0_child0 = createNode(config); root_child0_child0.setFlexGrow(1f); root_child0_child0.setFlexShrink(1f); root_child0_child0.setFlexBasisPercent(0f); root_child0.addChildAt(root_child0_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setWidth(50f); root.addChildAt(root_child1, 1); - final YogaNode root_child2 = new YogaNode(config); + final YogaNode root_child2 = createNode(config); root_child2.setWidth(50f); root.addChildAt(root_child2, 2); - final YogaNode root_child3 = new YogaNode(config); + final YogaNode root_child3 = createNode(config); root_child3.setWidth(50f); root.addChildAt(root_child3, 3); - final YogaNode root_child4 = new YogaNode(config); + final YogaNode root_child4 = createNode(config); root_child4.setWidth(50f); root.addChildAt(root_child4, 4); root.setDirection(YogaDirection.LTR); @@ -930,36 +940,36 @@ public class YGAlignContentTest { public void test_align_content_stretch_row_with_flex() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.ROW); root.setAlignContent(YogaAlign.STRETCH); root.setWrap(YogaWrap.WRAP); root.setWidth(150f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setWidth(50f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setFlexGrow(1f); root_child1.setFlexShrink(1f); root_child1.setFlexBasisPercent(0f); root_child1.setWidth(50f); root.addChildAt(root_child1, 1); - final YogaNode root_child2 = new YogaNode(config); + final YogaNode root_child2 = createNode(config); root_child2.setWidth(50f); root.addChildAt(root_child2, 2); - final YogaNode root_child3 = new YogaNode(config); + final YogaNode root_child3 = createNode(config); root_child3.setFlexGrow(1f); root_child3.setFlexShrink(1f); root_child3.setFlexBasisPercent(0f); root_child3.setWidth(50f); root.addChildAt(root_child3, 3); - final YogaNode root_child4 = new YogaNode(config); + final YogaNode root_child4 = createNode(config); root_child4.setWidth(50f); root.addChildAt(root_child4, 4); root.setDirection(YogaDirection.LTR); @@ -1033,35 +1043,35 @@ public class YGAlignContentTest { public void test_align_content_stretch_row_with_flex_no_shrink() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.ROW); root.setAlignContent(YogaAlign.STRETCH); root.setWrap(YogaWrap.WRAP); root.setWidth(150f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setWidth(50f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setFlexGrow(1f); root_child1.setFlexShrink(1f); root_child1.setFlexBasisPercent(0f); root_child1.setWidth(50f); root.addChildAt(root_child1, 1); - final YogaNode root_child2 = new YogaNode(config); + final YogaNode root_child2 = createNode(config); root_child2.setWidth(50f); root.addChildAt(root_child2, 2); - final YogaNode root_child3 = new YogaNode(config); + final YogaNode root_child3 = createNode(config); root_child3.setFlexGrow(1f); root_child3.setFlexBasisPercent(0f); root_child3.setWidth(50f); root.addChildAt(root_child3, 3); - final YogaNode root_child4 = new YogaNode(config); + final YogaNode root_child4 = createNode(config); root_child4.setWidth(50f); root.addChildAt(root_child4, 4); root.setDirection(YogaDirection.LTR); @@ -1135,18 +1145,18 @@ public class YGAlignContentTest { public void test_align_content_stretch_row_with_margin() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.ROW); root.setAlignContent(YogaAlign.STRETCH); root.setWrap(YogaWrap.WRAP); root.setWidth(150f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setWidth(50f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setMargin(YogaEdge.LEFT, 10f); root_child1.setMargin(YogaEdge.TOP, 10f); root_child1.setMargin(YogaEdge.RIGHT, 10f); @@ -1154,11 +1164,11 @@ public class YGAlignContentTest { root_child1.setWidth(50f); root.addChildAt(root_child1, 1); - final YogaNode root_child2 = new YogaNode(config); + final YogaNode root_child2 = createNode(config); root_child2.setWidth(50f); root.addChildAt(root_child2, 2); - final YogaNode root_child3 = new YogaNode(config); + final YogaNode root_child3 = createNode(config); root_child3.setMargin(YogaEdge.LEFT, 10f); root_child3.setMargin(YogaEdge.TOP, 10f); root_child3.setMargin(YogaEdge.RIGHT, 10f); @@ -1166,7 +1176,7 @@ public class YGAlignContentTest { root_child3.setWidth(50f); root.addChildAt(root_child3, 3); - final YogaNode root_child4 = new YogaNode(config); + final YogaNode root_child4 = createNode(config); root_child4.setWidth(50f); root.addChildAt(root_child4, 4); root.setDirection(YogaDirection.LTR); @@ -1240,18 +1250,18 @@ public class YGAlignContentTest { public void test_align_content_stretch_row_with_padding() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.ROW); root.setAlignContent(YogaAlign.STRETCH); root.setWrap(YogaWrap.WRAP); root.setWidth(150f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setWidth(50f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setPadding(YogaEdge.LEFT, 10); root_child1.setPadding(YogaEdge.TOP, 10); root_child1.setPadding(YogaEdge.RIGHT, 10); @@ -1259,11 +1269,11 @@ public class YGAlignContentTest { root_child1.setWidth(50f); root.addChildAt(root_child1, 1); - final YogaNode root_child2 = new YogaNode(config); + final YogaNode root_child2 = createNode(config); root_child2.setWidth(50f); root.addChildAt(root_child2, 2); - final YogaNode root_child3 = new YogaNode(config); + final YogaNode root_child3 = createNode(config); root_child3.setPadding(YogaEdge.LEFT, 10); root_child3.setPadding(YogaEdge.TOP, 10); root_child3.setPadding(YogaEdge.RIGHT, 10); @@ -1271,7 +1281,7 @@ public class YGAlignContentTest { root_child3.setWidth(50f); root.addChildAt(root_child3, 3); - final YogaNode root_child4 = new YogaNode(config); + final YogaNode root_child4 = createNode(config); root_child4.setWidth(50f); root.addChildAt(root_child4, 4); root.setDirection(YogaDirection.LTR); @@ -1345,18 +1355,18 @@ public class YGAlignContentTest { public void test_align_content_stretch_row_with_single_row() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.ROW); root.setAlignContent(YogaAlign.STRETCH); root.setWrap(YogaWrap.WRAP); root.setWidth(150f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setWidth(50f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setWidth(50f); root.addChildAt(root_child1, 1); root.setDirection(YogaDirection.LTR); @@ -1400,31 +1410,31 @@ public class YGAlignContentTest { public void test_align_content_stretch_row_with_fixed_height() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.ROW); root.setAlignContent(YogaAlign.STRETCH); root.setWrap(YogaWrap.WRAP); root.setWidth(150f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setWidth(50f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setWidth(50f); root_child1.setHeight(60f); root.addChildAt(root_child1, 1); - final YogaNode root_child2 = new YogaNode(config); + final YogaNode root_child2 = createNode(config); root_child2.setWidth(50f); root.addChildAt(root_child2, 2); - final YogaNode root_child3 = new YogaNode(config); + final YogaNode root_child3 = createNode(config); root_child3.setWidth(50f); root.addChildAt(root_child3, 3); - final YogaNode root_child4 = new YogaNode(config); + final YogaNode root_child4 = createNode(config); root_child4.setWidth(50f); root.addChildAt(root_child4, 4); root.setDirection(YogaDirection.LTR); @@ -1498,31 +1508,31 @@ public class YGAlignContentTest { public void test_align_content_stretch_row_with_max_height() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.ROW); root.setAlignContent(YogaAlign.STRETCH); root.setWrap(YogaWrap.WRAP); root.setWidth(150f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setWidth(50f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setWidth(50f); root_child1.setMaxHeight(20f); root.addChildAt(root_child1, 1); - final YogaNode root_child2 = new YogaNode(config); + final YogaNode root_child2 = createNode(config); root_child2.setWidth(50f); root.addChildAt(root_child2, 2); - final YogaNode root_child3 = new YogaNode(config); + final YogaNode root_child3 = createNode(config); root_child3.setWidth(50f); root.addChildAt(root_child3, 3); - final YogaNode root_child4 = new YogaNode(config); + final YogaNode root_child4 = createNode(config); root_child4.setWidth(50f); root.addChildAt(root_child4, 4); root.setDirection(YogaDirection.LTR); @@ -1596,31 +1606,31 @@ public class YGAlignContentTest { public void test_align_content_stretch_row_with_min_height() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.ROW); root.setAlignContent(YogaAlign.STRETCH); root.setWrap(YogaWrap.WRAP); root.setWidth(150f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setWidth(50f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setWidth(50f); root_child1.setMinHeight(80f); root.addChildAt(root_child1, 1); - final YogaNode root_child2 = new YogaNode(config); + final YogaNode root_child2 = createNode(config); root_child2.setWidth(50f); root.addChildAt(root_child2, 2); - final YogaNode root_child3 = new YogaNode(config); + final YogaNode root_child3 = createNode(config); root_child3.setWidth(50f); root.addChildAt(root_child3, 3); - final YogaNode root_child4 = new YogaNode(config); + final YogaNode root_child4 = createNode(config); root_child4.setWidth(50f); root.addChildAt(root_child4, 4); root.setDirection(YogaDirection.LTR); @@ -1694,38 +1704,38 @@ public class YGAlignContentTest { public void test_align_content_stretch_column() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setAlignContent(YogaAlign.STRETCH); root.setWrap(YogaWrap.WRAP); root.setWidth(100f); root.setHeight(150f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setHeight(50f); root.addChildAt(root_child0, 0); - final YogaNode root_child0_child0 = new YogaNode(config); + final YogaNode root_child0_child0 = createNode(config); root_child0_child0.setFlexGrow(1f); root_child0_child0.setFlexShrink(1f); root_child0_child0.setFlexBasisPercent(0f); root_child0.addChildAt(root_child0_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setFlexGrow(1f); root_child1.setFlexShrink(1f); root_child1.setFlexBasisPercent(0f); root_child1.setHeight(50f); root.addChildAt(root_child1, 1); - final YogaNode root_child2 = new YogaNode(config); + final YogaNode root_child2 = createNode(config); root_child2.setHeight(50f); root.addChildAt(root_child2, 2); - final YogaNode root_child3 = new YogaNode(config); + final YogaNode root_child3 = createNode(config); root_child3.setHeight(50f); root.addChildAt(root_child3, 3); - final YogaNode root_child4 = new YogaNode(config); + final YogaNode root_child4 = createNode(config); root_child4.setHeight(50f); root.addChildAt(root_child4, 4); root.setDirection(YogaDirection.LTR); @@ -1809,10 +1819,10 @@ public class YGAlignContentTest { public void test_align_content_stretch_is_not_overriding_align_items() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setAlignContent(YogaAlign.STRETCH); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setFlexDirection(YogaFlexDirection.ROW); root_child0.setAlignContent(YogaAlign.STRETCH); root_child0.setAlignItems(YogaAlign.CENTER); @@ -1820,7 +1830,7 @@ public class YGAlignContentTest { root_child0.setHeight(100f); root.addChildAt(root_child0, 0); - final YogaNode root_child0_child0 = new YogaNode(config); + final YogaNode root_child0_child0 = createNode(config); root_child0_child0.setAlignContent(YogaAlign.STRETCH); root_child0_child0.setWidth(10f); root_child0_child0.setHeight(10f); @@ -1862,4 +1872,7 @@ public class YGAlignContentTest { assertEquals(10f, root_child0_child0.getLayoutHeight(), 0.0f); } + private YogaNode createNode(YogaConfig config) { + return mNodeFactory.create(config); + } } diff --git a/java/tests/com/facebook/yoga/YGAlignItemsTest.java b/java/tests/com/facebook/yoga/YGAlignItemsTest.java index 0cc5ba45..2a65b735 100644 --- a/java/tests/com/facebook/yoga/YGAlignItemsTest.java +++ b/java/tests/com/facebook/yoga/YGAlignItemsTest.java @@ -9,20 +9,30 @@ package com.facebook.yoga; -import org.junit.Test; - import static org.junit.Assert.assertEquals; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +@RunWith(Parameterized.class) public class YGAlignItemsTest { + @Parameterized.Parameters(name = "{0}") + public static Iterable nodeFactories() { + return TestParametrization.nodeFactories(); + } + + @Parameterized.Parameter public TestParametrization.NodeFactory mNodeFactory; + @Test public void test_align_items_stretch() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setWidth(100f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setHeight(10f); root.addChildAt(root_child0, 0); root.setDirection(YogaDirection.LTR); @@ -56,12 +66,12 @@ public class YGAlignItemsTest { public void test_align_items_center() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setAlignItems(YogaAlign.CENTER); root.setWidth(100f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setWidth(10f); root_child0.setHeight(10f); root.addChildAt(root_child0, 0); @@ -96,12 +106,12 @@ public class YGAlignItemsTest { public void test_align_items_flex_start() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setAlignItems(YogaAlign.FLEX_START); root.setWidth(100f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setWidth(10f); root_child0.setHeight(10f); root.addChildAt(root_child0, 0); @@ -136,12 +146,12 @@ public class YGAlignItemsTest { public void test_align_items_flex_end() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setAlignItems(YogaAlign.FLEX_END); root.setWidth(100f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setWidth(10f); root_child0.setHeight(10f); root.addChildAt(root_child0, 0); @@ -176,18 +186,18 @@ public class YGAlignItemsTest { public void test_align_baseline() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.ROW); root.setAlignItems(YogaAlign.BASELINE); root.setWidth(100f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setWidth(50f); root_child0.setHeight(50f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setWidth(50f); root_child1.setHeight(20f); root.addChildAt(root_child1, 1); @@ -232,23 +242,23 @@ public class YGAlignItemsTest { public void test_align_baseline_child() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.ROW); root.setAlignItems(YogaAlign.BASELINE); root.setWidth(100f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setWidth(50f); root_child0.setHeight(50f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setWidth(50f); root_child1.setHeight(20f); root.addChildAt(root_child1, 1); - final YogaNode root_child1_child0 = new YogaNode(config); + final YogaNode root_child1_child0 = createNode(config); root_child1_child0.setWidth(50f); root_child1_child0.setHeight(10f); root_child1.addChildAt(root_child1_child0, 0); @@ -303,40 +313,40 @@ public class YGAlignItemsTest { public void test_align_baseline_child_multiline() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.ROW); root.setAlignItems(YogaAlign.BASELINE); root.setWidth(100f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setWidth(50f); root_child0.setHeight(60f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setFlexDirection(YogaFlexDirection.ROW); root_child1.setWrap(YogaWrap.WRAP); root_child1.setWidth(50f); root_child1.setHeight(25f); root.addChildAt(root_child1, 1); - final YogaNode root_child1_child0 = new YogaNode(config); + final YogaNode root_child1_child0 = createNode(config); root_child1_child0.setWidth(25f); root_child1_child0.setHeight(20f); root_child1.addChildAt(root_child1_child0, 0); - final YogaNode root_child1_child1 = new YogaNode(config); + final YogaNode root_child1_child1 = createNode(config); root_child1_child1.setWidth(25f); root_child1_child1.setHeight(10f); root_child1.addChildAt(root_child1_child1, 1); - final YogaNode root_child1_child2 = new YogaNode(config); + final YogaNode root_child1_child2 = createNode(config); root_child1_child2.setWidth(25f); root_child1_child2.setHeight(20f); root_child1.addChildAt(root_child1_child2, 2); - final YogaNode root_child1_child3 = new YogaNode(config); + final YogaNode root_child1_child3 = createNode(config); root_child1_child3.setWidth(25f); root_child1_child3.setHeight(10f); root_child1.addChildAt(root_child1_child3, 3); @@ -421,41 +431,41 @@ public class YGAlignItemsTest { public void test_align_baseline_child_multiline_override() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.ROW); root.setAlignItems(YogaAlign.BASELINE); root.setWidth(100f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setWidth(50f); root_child0.setHeight(60f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setFlexDirection(YogaFlexDirection.ROW); root_child1.setWrap(YogaWrap.WRAP); root_child1.setWidth(50f); root_child1.setHeight(25f); root.addChildAt(root_child1, 1); - final YogaNode root_child1_child0 = new YogaNode(config); + final YogaNode root_child1_child0 = createNode(config); root_child1_child0.setWidth(25f); root_child1_child0.setHeight(20f); root_child1.addChildAt(root_child1_child0, 0); - final YogaNode root_child1_child1 = new YogaNode(config); + final YogaNode root_child1_child1 = createNode(config); root_child1_child1.setAlignSelf(YogaAlign.BASELINE); root_child1_child1.setWidth(25f); root_child1_child1.setHeight(10f); root_child1.addChildAt(root_child1_child1, 1); - final YogaNode root_child1_child2 = new YogaNode(config); + final YogaNode root_child1_child2 = createNode(config); root_child1_child2.setWidth(25f); root_child1_child2.setHeight(20f); root_child1.addChildAt(root_child1_child2, 2); - final YogaNode root_child1_child3 = new YogaNode(config); + final YogaNode root_child1_child3 = createNode(config); root_child1_child3.setAlignSelf(YogaAlign.BASELINE); root_child1_child3.setWidth(25f); root_child1_child3.setHeight(10f); @@ -541,40 +551,40 @@ public class YGAlignItemsTest { public void test_align_baseline_child_multiline_no_override_on_secondline() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.ROW); root.setAlignItems(YogaAlign.BASELINE); root.setWidth(100f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setWidth(50f); root_child0.setHeight(60f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setFlexDirection(YogaFlexDirection.ROW); root_child1.setWrap(YogaWrap.WRAP); root_child1.setWidth(50f); root_child1.setHeight(25f); root.addChildAt(root_child1, 1); - final YogaNode root_child1_child0 = new YogaNode(config); + final YogaNode root_child1_child0 = createNode(config); root_child1_child0.setWidth(25f); root_child1_child0.setHeight(20f); root_child1.addChildAt(root_child1_child0, 0); - final YogaNode root_child1_child1 = new YogaNode(config); + final YogaNode root_child1_child1 = createNode(config); root_child1_child1.setWidth(25f); root_child1_child1.setHeight(10f); root_child1.addChildAt(root_child1_child1, 1); - final YogaNode root_child1_child2 = new YogaNode(config); + final YogaNode root_child1_child2 = createNode(config); root_child1_child2.setWidth(25f); root_child1_child2.setHeight(20f); root_child1.addChildAt(root_child1_child2, 2); - final YogaNode root_child1_child3 = new YogaNode(config); + final YogaNode root_child1_child3 = createNode(config); root_child1_child3.setAlignSelf(YogaAlign.BASELINE); root_child1_child3.setWidth(25f); root_child1_child3.setHeight(10f); @@ -660,24 +670,24 @@ public class YGAlignItemsTest { public void test_align_baseline_child_top() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.ROW); root.setAlignItems(YogaAlign.BASELINE); root.setWidth(100f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setPosition(YogaEdge.TOP, 10f); root_child0.setWidth(50f); root_child0.setHeight(50f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setWidth(50f); root_child1.setHeight(20f); root.addChildAt(root_child1, 1); - final YogaNode root_child1_child0 = new YogaNode(config); + final YogaNode root_child1_child0 = createNode(config); root_child1_child0.setWidth(50f); root_child1_child0.setHeight(10f); root_child1.addChildAt(root_child1_child0, 0); @@ -732,24 +742,24 @@ public class YGAlignItemsTest { public void test_align_baseline_child_top2() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.ROW); root.setAlignItems(YogaAlign.BASELINE); root.setWidth(100f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setWidth(50f); root_child0.setHeight(50f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setPosition(YogaEdge.TOP, 5f); root_child1.setWidth(50f); root_child1.setHeight(20f); root.addChildAt(root_child1, 1); - final YogaNode root_child1_child0 = new YogaNode(config); + final YogaNode root_child1_child0 = createNode(config); root_child1_child0.setWidth(50f); root_child1_child0.setHeight(10f); root_child1.addChildAt(root_child1_child0, 0); @@ -804,28 +814,28 @@ public class YGAlignItemsTest { public void test_align_baseline_double_nested_child() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.ROW); root.setAlignItems(YogaAlign.BASELINE); root.setWidth(100f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setWidth(50f); root_child0.setHeight(50f); root.addChildAt(root_child0, 0); - final YogaNode root_child0_child0 = new YogaNode(config); + final YogaNode root_child0_child0 = createNode(config); root_child0_child0.setWidth(50f); root_child0_child0.setHeight(20f); root_child0.addChildAt(root_child0_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setWidth(50f); root_child1.setHeight(20f); root.addChildAt(root_child1, 1); - final YogaNode root_child1_child0 = new YogaNode(config); + final YogaNode root_child1_child0 = createNode(config); root_child1_child0.setWidth(50f); root_child1_child0.setHeight(15f); root_child1.addChildAt(root_child1_child0, 0); @@ -890,17 +900,17 @@ public class YGAlignItemsTest { public void test_align_baseline_column() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setAlignItems(YogaAlign.BASELINE); root.setWidth(100f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setWidth(50f); root_child0.setHeight(50f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setWidth(50f); root_child1.setHeight(20f); root.addChildAt(root_child1, 1); @@ -945,13 +955,13 @@ public class YGAlignItemsTest { public void test_align_baseline_child_margin() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.ROW); root.setAlignItems(YogaAlign.BASELINE); root.setWidth(100f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setMargin(YogaEdge.LEFT, 5f); root_child0.setMargin(YogaEdge.TOP, 5f); root_child0.setMargin(YogaEdge.RIGHT, 5f); @@ -960,12 +970,12 @@ public class YGAlignItemsTest { root_child0.setHeight(50f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setWidth(50f); root_child1.setHeight(20f); root.addChildAt(root_child1, 1); - final YogaNode root_child1_child0 = new YogaNode(config); + final YogaNode root_child1_child0 = createNode(config); root_child1_child0.setMargin(YogaEdge.LEFT, 1f); root_child1_child0.setMargin(YogaEdge.TOP, 1f); root_child1_child0.setMargin(YogaEdge.RIGHT, 1f); @@ -1024,7 +1034,7 @@ public class YGAlignItemsTest { public void test_align_baseline_child_padding() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.ROW); root.setAlignItems(YogaAlign.BASELINE); root.setPadding(YogaEdge.LEFT, 5); @@ -1034,12 +1044,12 @@ public class YGAlignItemsTest { root.setWidth(100f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setWidth(50f); root_child0.setHeight(50f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setPadding(YogaEdge.LEFT, 5); root_child1.setPadding(YogaEdge.TOP, 5); root_child1.setPadding(YogaEdge.RIGHT, 5); @@ -1048,7 +1058,7 @@ public class YGAlignItemsTest { root_child1.setHeight(20f); root.addChildAt(root_child1, 1); - final YogaNode root_child1_child0 = new YogaNode(config); + final YogaNode root_child1_child0 = createNode(config); root_child1_child0.setWidth(50f); root_child1_child0.setHeight(10f); root_child1.addChildAt(root_child1_child0, 0); @@ -1103,39 +1113,39 @@ public class YGAlignItemsTest { public void test_align_baseline_multiline() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.ROW); root.setAlignItems(YogaAlign.BASELINE); root.setWrap(YogaWrap.WRAP); root.setWidth(100f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setWidth(50f); root_child0.setHeight(50f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setWidth(50f); root_child1.setHeight(20f); root.addChildAt(root_child1, 1); - final YogaNode root_child1_child0 = new YogaNode(config); + final YogaNode root_child1_child0 = createNode(config); root_child1_child0.setWidth(50f); root_child1_child0.setHeight(10f); root_child1.addChildAt(root_child1_child0, 0); - final YogaNode root_child2 = new YogaNode(config); + final YogaNode root_child2 = createNode(config); root_child2.setWidth(50f); root_child2.setHeight(20f); root.addChildAt(root_child2, 2); - final YogaNode root_child2_child0 = new YogaNode(config); + final YogaNode root_child2_child0 = createNode(config); root_child2_child0.setWidth(50f); root_child2_child0.setHeight(10f); root_child2.addChildAt(root_child2_child0, 0); - final YogaNode root_child3 = new YogaNode(config); + final YogaNode root_child3 = createNode(config); root_child3.setWidth(50f); root_child3.setHeight(50f); root.addChildAt(root_child3, 3); @@ -1220,38 +1230,38 @@ public class YGAlignItemsTest { public void test_align_baseline_multiline_column() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setAlignItems(YogaAlign.BASELINE); root.setWrap(YogaWrap.WRAP); root.setWidth(100f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setWidth(50f); root_child0.setHeight(50f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setWidth(30f); root_child1.setHeight(50f); root.addChildAt(root_child1, 1); - final YogaNode root_child1_child0 = new YogaNode(config); + final YogaNode root_child1_child0 = createNode(config); root_child1_child0.setWidth(20f); root_child1_child0.setHeight(20f); root_child1.addChildAt(root_child1_child0, 0); - final YogaNode root_child2 = new YogaNode(config); + final YogaNode root_child2 = createNode(config); root_child2.setWidth(40f); root_child2.setHeight(70f); root.addChildAt(root_child2, 2); - final YogaNode root_child2_child0 = new YogaNode(config); + final YogaNode root_child2_child0 = createNode(config); root_child2_child0.setWidth(10f); root_child2_child0.setHeight(10f); root_child2.addChildAt(root_child2_child0, 0); - final YogaNode root_child3 = new YogaNode(config); + final YogaNode root_child3 = createNode(config); root_child3.setWidth(50f); root_child3.setHeight(20f); root.addChildAt(root_child3, 3); @@ -1336,38 +1346,38 @@ public class YGAlignItemsTest { public void test_align_baseline_multiline_column2() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setAlignItems(YogaAlign.BASELINE); root.setWrap(YogaWrap.WRAP); root.setWidth(100f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setWidth(50f); root_child0.setHeight(50f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setWidth(30f); root_child1.setHeight(50f); root.addChildAt(root_child1, 1); - final YogaNode root_child1_child0 = new YogaNode(config); + final YogaNode root_child1_child0 = createNode(config); root_child1_child0.setWidth(20f); root_child1_child0.setHeight(20f); root_child1.addChildAt(root_child1_child0, 0); - final YogaNode root_child2 = new YogaNode(config); + final YogaNode root_child2 = createNode(config); root_child2.setWidth(40f); root_child2.setHeight(70f); root.addChildAt(root_child2, 2); - final YogaNode root_child2_child0 = new YogaNode(config); + final YogaNode root_child2_child0 = createNode(config); root_child2_child0.setWidth(10f); root_child2_child0.setHeight(10f); root_child2.addChildAt(root_child2_child0, 0); - final YogaNode root_child3 = new YogaNode(config); + final YogaNode root_child3 = createNode(config); root_child3.setWidth(50f); root_child3.setHeight(20f); root.addChildAt(root_child3, 3); @@ -1452,39 +1462,39 @@ public class YGAlignItemsTest { public void test_align_baseline_multiline_row_and_column() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.ROW); root.setAlignItems(YogaAlign.BASELINE); root.setWrap(YogaWrap.WRAP); root.setWidth(100f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setWidth(50f); root_child0.setHeight(50f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setWidth(50f); root_child1.setHeight(50f); root.addChildAt(root_child1, 1); - final YogaNode root_child1_child0 = new YogaNode(config); + final YogaNode root_child1_child0 = createNode(config); root_child1_child0.setWidth(50f); root_child1_child0.setHeight(10f); root_child1.addChildAt(root_child1_child0, 0); - final YogaNode root_child2 = new YogaNode(config); + final YogaNode root_child2 = createNode(config); root_child2.setWidth(50f); root_child2.setHeight(20f); root.addChildAt(root_child2, 2); - final YogaNode root_child2_child0 = new YogaNode(config); + final YogaNode root_child2_child0 = createNode(config); root_child2_child0.setWidth(50f); root_child2_child0.setHeight(10f); root_child2.addChildAt(root_child2_child0, 0); - final YogaNode root_child3 = new YogaNode(config); + final YogaNode root_child3 = createNode(config); root_child3.setWidth(50f); root_child3.setHeight(20f); root.addChildAt(root_child3, 3); @@ -1569,17 +1579,17 @@ public class YGAlignItemsTest { public void test_align_items_center_child_with_margin_bigger_than_parent() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setJustifyContent(YogaJustify.CENTER); root.setAlignItems(YogaAlign.CENTER); root.setWidth(52f); root.setHeight(52f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setAlignItems(YogaAlign.CENTER); root.addChildAt(root_child0, 0); - final YogaNode root_child0_child0 = new YogaNode(config); + final YogaNode root_child0_child0 = createNode(config); root_child0_child0.setMargin(YogaEdge.LEFT, 10f); root_child0_child0.setMargin(YogaEdge.RIGHT, 10f); root_child0_child0.setWidth(52f); @@ -1626,17 +1636,17 @@ public class YGAlignItemsTest { public void test_align_items_flex_end_child_with_margin_bigger_than_parent() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setJustifyContent(YogaJustify.CENTER); root.setAlignItems(YogaAlign.CENTER); root.setWidth(52f); root.setHeight(52f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setAlignItems(YogaAlign.FLEX_END); root.addChildAt(root_child0, 0); - final YogaNode root_child0_child0 = new YogaNode(config); + final YogaNode root_child0_child0 = createNode(config); root_child0_child0.setMargin(YogaEdge.LEFT, 10f); root_child0_child0.setMargin(YogaEdge.RIGHT, 10f); root_child0_child0.setWidth(52f); @@ -1683,17 +1693,17 @@ public class YGAlignItemsTest { public void test_align_items_center_child_without_margin_bigger_than_parent() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setJustifyContent(YogaJustify.CENTER); root.setAlignItems(YogaAlign.CENTER); root.setWidth(52f); root.setHeight(52f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setAlignItems(YogaAlign.CENTER); root.addChildAt(root_child0, 0); - final YogaNode root_child0_child0 = new YogaNode(config); + final YogaNode root_child0_child0 = createNode(config); root_child0_child0.setWidth(72f); root_child0_child0.setHeight(72f); root_child0.addChildAt(root_child0_child0, 0); @@ -1738,17 +1748,17 @@ public class YGAlignItemsTest { public void test_align_items_flex_end_child_without_margin_bigger_than_parent() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setJustifyContent(YogaJustify.CENTER); root.setAlignItems(YogaAlign.CENTER); root.setWidth(52f); root.setHeight(52f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setAlignItems(YogaAlign.FLEX_END); root.addChildAt(root_child0, 0); - final YogaNode root_child0_child0 = new YogaNode(config); + final YogaNode root_child0_child0 = createNode(config); root_child0_child0.setWidth(72f); root_child0_child0.setHeight(72f); root_child0.addChildAt(root_child0_child0, 0); @@ -1793,23 +1803,23 @@ public class YGAlignItemsTest { public void test_align_center_should_size_based_on_content() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setAlignItems(YogaAlign.CENTER); root.setMargin(YogaEdge.TOP, 20f); root.setWidth(100f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setJustifyContent(YogaJustify.CENTER); root_child0.setFlexShrink(1f); root.addChildAt(root_child0, 0); - final YogaNode root_child0_child0 = new YogaNode(config); + final YogaNode root_child0_child0 = createNode(config); root_child0_child0.setFlexGrow(1f); root_child0_child0.setFlexShrink(1f); root_child0.addChildAt(root_child0_child0, 0); - final YogaNode root_child0_child0_child0 = new YogaNode(config); + final YogaNode root_child0_child0_child0 = createNode(config); root_child0_child0_child0.setWidth(20f); root_child0_child0_child0.setHeight(20f); root_child0_child0.addChildAt(root_child0_child0_child0, 0); @@ -1864,22 +1874,22 @@ public class YGAlignItemsTest { public void test_align_strech_should_size_based_on_parent() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setMargin(YogaEdge.TOP, 20f); root.setWidth(100f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setJustifyContent(YogaJustify.CENTER); root_child0.setFlexShrink(1f); root.addChildAt(root_child0, 0); - final YogaNode root_child0_child0 = new YogaNode(config); + final YogaNode root_child0_child0 = createNode(config); root_child0_child0.setFlexGrow(1f); root_child0_child0.setFlexShrink(1f); root_child0.addChildAt(root_child0_child0, 0); - final YogaNode root_child0_child0_child0 = new YogaNode(config); + final YogaNode root_child0_child0_child0 = createNode(config); root_child0_child0_child0.setWidth(20f); root_child0_child0_child0.setHeight(20f); root_child0_child0.addChildAt(root_child0_child0_child0, 0); @@ -1934,20 +1944,20 @@ public class YGAlignItemsTest { public void test_align_flex_start_with_shrinking_children() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setWidth(500f); root.setHeight(500f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setAlignItems(YogaAlign.FLEX_START); root.addChildAt(root_child0, 0); - final YogaNode root_child0_child0 = new YogaNode(config); + final YogaNode root_child0_child0 = createNode(config); root_child0_child0.setFlexGrow(1f); root_child0_child0.setFlexShrink(1f); root_child0.addChildAt(root_child0_child0, 0); - final YogaNode root_child0_child0_child0 = new YogaNode(config); + final YogaNode root_child0_child0_child0 = createNode(config); root_child0_child0_child0.setFlexGrow(1f); root_child0_child0_child0.setFlexShrink(1f); root_child0_child0.addChildAt(root_child0_child0_child0, 0); @@ -2002,19 +2012,19 @@ public class YGAlignItemsTest { public void test_align_flex_start_with_stretching_children() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setWidth(500f); root.setHeight(500f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root.addChildAt(root_child0, 0); - final YogaNode root_child0_child0 = new YogaNode(config); + final YogaNode root_child0_child0 = createNode(config); root_child0_child0.setFlexGrow(1f); root_child0_child0.setFlexShrink(1f); root_child0.addChildAt(root_child0_child0, 0); - final YogaNode root_child0_child0_child0 = new YogaNode(config); + final YogaNode root_child0_child0_child0 = createNode(config); root_child0_child0_child0.setFlexGrow(1f); root_child0_child0_child0.setFlexShrink(1f); root_child0_child0.addChildAt(root_child0_child0_child0, 0); @@ -2069,20 +2079,20 @@ public class YGAlignItemsTest { public void test_align_flex_start_with_shrinking_children_with_stretch() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setWidth(500f); root.setHeight(500f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setAlignItems(YogaAlign.FLEX_START); root.addChildAt(root_child0, 0); - final YogaNode root_child0_child0 = new YogaNode(config); + final YogaNode root_child0_child0 = createNode(config); root_child0_child0.setFlexGrow(1f); root_child0_child0.setFlexShrink(1f); root_child0.addChildAt(root_child0_child0, 0); - final YogaNode root_child0_child0_child0 = new YogaNode(config); + final YogaNode root_child0_child0_child0 = createNode(config); root_child0_child0_child0.setFlexGrow(1f); root_child0_child0_child0.setFlexShrink(1f); root_child0_child0.addChildAt(root_child0_child0_child0, 0); @@ -2133,4 +2143,7 @@ public class YGAlignItemsTest { assertEquals(0f, root_child0_child0_child0.getLayoutHeight(), 0.0f); } + private YogaNode createNode(YogaConfig config) { + return mNodeFactory.create(config); + } } diff --git a/java/tests/com/facebook/yoga/YGAlignSelfTest.java b/java/tests/com/facebook/yoga/YGAlignSelfTest.java index d7ea10a6..ebf000a9 100644 --- a/java/tests/com/facebook/yoga/YGAlignSelfTest.java +++ b/java/tests/com/facebook/yoga/YGAlignSelfTest.java @@ -9,20 +9,30 @@ package com.facebook.yoga; -import org.junit.Test; - import static org.junit.Assert.assertEquals; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +@RunWith(Parameterized.class) public class YGAlignSelfTest { + @Parameterized.Parameters(name = "{0}") + public static Iterable nodeFactories() { + return TestParametrization.nodeFactories(); + } + + @Parameterized.Parameter public TestParametrization.NodeFactory mNodeFactory; + @Test public void test_align_self_center() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setWidth(100f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setAlignSelf(YogaAlign.CENTER); root_child0.setWidth(10f); root_child0.setHeight(10f); @@ -58,11 +68,11 @@ public class YGAlignSelfTest { public void test_align_self_flex_end() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setWidth(100f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setAlignSelf(YogaAlign.FLEX_END); root_child0.setWidth(10f); root_child0.setHeight(10f); @@ -98,11 +108,11 @@ public class YGAlignSelfTest { public void test_align_self_flex_start() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setWidth(100f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setAlignSelf(YogaAlign.FLEX_START); root_child0.setWidth(10f); root_child0.setHeight(10f); @@ -138,12 +148,12 @@ public class YGAlignSelfTest { public void test_align_self_flex_end_override_flex_start() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setAlignItems(YogaAlign.FLEX_START); root.setWidth(100f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setAlignSelf(YogaAlign.FLEX_END); root_child0.setWidth(10f); root_child0.setHeight(10f); @@ -179,24 +189,24 @@ public class YGAlignSelfTest { public void test_align_self_baseline() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.ROW); root.setWidth(100f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setAlignSelf(YogaAlign.BASELINE); root_child0.setWidth(50f); root_child0.setHeight(50f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setAlignSelf(YogaAlign.BASELINE); root_child1.setWidth(50f); root_child1.setHeight(20f); root.addChildAt(root_child1, 1); - final YogaNode root_child1_child0 = new YogaNode(config); + final YogaNode root_child1_child0 = createNode(config); root_child1_child0.setWidth(50f); root_child1_child0.setHeight(10f); root_child1.addChildAt(root_child1_child0, 0); @@ -247,4 +257,7 @@ public class YGAlignSelfTest { assertEquals(10f, root_child1_child0.getLayoutHeight(), 0.0f); } + private YogaNode createNode(YogaConfig config) { + return mNodeFactory.create(config); + } } diff --git a/java/tests/com/facebook/yoga/YGAndroidNewsFeed.java b/java/tests/com/facebook/yoga/YGAndroidNewsFeed.java index 54c5ac1d..fcf1214a 100644 --- a/java/tests/com/facebook/yoga/YGAndroidNewsFeed.java +++ b/java/tests/com/facebook/yoga/YGAndroidNewsFeed.java @@ -12,28 +12,38 @@ package com.facebook.yoga; import static org.junit.Assert.assertEquals; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +@RunWith(Parameterized.class) public class YGAndroidNewsFeed { + @Parameterized.Parameters(name = "{0}") + public static Iterable nodeFactories() { + return TestParametrization.nodeFactories(); + } + + @Parameterized.Parameter public TestParametrization.NodeFactory mNodeFactory; + @Test public void test_android_news_feed() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setAlignContent(YogaAlign.STRETCH); root.setWidth(1080f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root.addChildAt(root_child0, 0); - final YogaNode root_child0_child0 = new YogaNode(config); + final YogaNode root_child0_child0 = createNode(config); root_child0_child0.setAlignContent(YogaAlign.STRETCH); root_child0.addChildAt(root_child0_child0, 0); - final YogaNode root_child0_child0_child0 = new YogaNode(config); + final YogaNode root_child0_child0_child0 = createNode(config); root_child0_child0_child0.setAlignContent(YogaAlign.STRETCH); root_child0_child0.addChildAt(root_child0_child0_child0, 0); - final YogaNode root_child0_child0_child0_child0 = new YogaNode(config); + final YogaNode root_child0_child0_child0_child0 = createNode(config); root_child0_child0_child0_child0.setFlexDirection(YogaFlexDirection.ROW); root_child0_child0_child0_child0.setAlignContent(YogaAlign.STRETCH); root_child0_child0_child0_child0.setAlignItems(YogaAlign.FLEX_START); @@ -41,19 +51,19 @@ public class YGAndroidNewsFeed { root_child0_child0_child0_child0.setMargin(YogaEdge.TOP, 24f); root_child0_child0_child0.addChildAt(root_child0_child0_child0_child0, 0); - final YogaNode root_child0_child0_child0_child0_child0 = new YogaNode(config); + final YogaNode root_child0_child0_child0_child0_child0 = createNode(config); root_child0_child0_child0_child0_child0.setFlexDirection(YogaFlexDirection.ROW); root_child0_child0_child0_child0_child0.setAlignContent(YogaAlign.STRETCH); root_child0_child0_child0_child0.addChildAt(root_child0_child0_child0_child0_child0, 0); - final YogaNode root_child0_child0_child0_child0_child0_child0 = new YogaNode(config); + final YogaNode root_child0_child0_child0_child0_child0_child0 = createNode(config); root_child0_child0_child0_child0_child0_child0.setAlignContent(YogaAlign.STRETCH); root_child0_child0_child0_child0_child0_child0.setWidth(120f); root_child0_child0_child0_child0_child0_child0.setHeight(120f); root_child0_child0_child0_child0_child0.addChildAt( root_child0_child0_child0_child0_child0_child0, 0); - final YogaNode root_child0_child0_child0_child0_child1 = new YogaNode(config); + final YogaNode root_child0_child0_child0_child0_child1 = createNode(config); root_child0_child0_child0_child0_child1.setAlignContent(YogaAlign.STRETCH); root_child0_child0_child0_child0_child1.setFlexShrink(1f); root_child0_child0_child0_child0_child1.setMargin(YogaEdge.RIGHT, 36f); @@ -63,24 +73,24 @@ public class YGAndroidNewsFeed { root_child0_child0_child0_child0_child1.setPadding(YogaEdge.BOTTOM, 18); root_child0_child0_child0_child0.addChildAt(root_child0_child0_child0_child0_child1, 1); - final YogaNode root_child0_child0_child0_child0_child1_child0 = new YogaNode(config); + final YogaNode root_child0_child0_child0_child0_child1_child0 = createNode(config); root_child0_child0_child0_child0_child1_child0.setFlexDirection(YogaFlexDirection.ROW); root_child0_child0_child0_child0_child1_child0.setAlignContent(YogaAlign.STRETCH); root_child0_child0_child0_child0_child1_child0.setFlexShrink(1f); root_child0_child0_child0_child0_child1.addChildAt( root_child0_child0_child0_child0_child1_child0, 0); - final YogaNode root_child0_child0_child0_child0_child1_child1 = new YogaNode(config); + final YogaNode root_child0_child0_child0_child0_child1_child1 = createNode(config); root_child0_child0_child0_child0_child1_child1.setAlignContent(YogaAlign.STRETCH); root_child0_child0_child0_child0_child1_child1.setFlexShrink(1f); root_child0_child0_child0_child0_child1.addChildAt( root_child0_child0_child0_child0_child1_child1, 1); - final YogaNode root_child0_child0_child1 = new YogaNode(config); + final YogaNode root_child0_child0_child1 = createNode(config); root_child0_child0_child1.setAlignContent(YogaAlign.STRETCH); root_child0_child0.addChildAt(root_child0_child0_child1, 1); - final YogaNode root_child0_child0_child1_child0 = new YogaNode(config); + final YogaNode root_child0_child0_child1_child0 = createNode(config); root_child0_child0_child1_child0.setFlexDirection(YogaFlexDirection.ROW); root_child0_child0_child1_child0.setAlignContent(YogaAlign.STRETCH); root_child0_child0_child1_child0.setAlignItems(YogaAlign.FLEX_START); @@ -88,19 +98,19 @@ public class YGAndroidNewsFeed { root_child0_child0_child1_child0.setMargin(YogaEdge.TOP, 24f); root_child0_child0_child1.addChildAt(root_child0_child0_child1_child0, 0); - final YogaNode root_child0_child0_child1_child0_child0 = new YogaNode(config); + final YogaNode root_child0_child0_child1_child0_child0 = createNode(config); root_child0_child0_child1_child0_child0.setFlexDirection(YogaFlexDirection.ROW); root_child0_child0_child1_child0_child0.setAlignContent(YogaAlign.STRETCH); root_child0_child0_child1_child0.addChildAt(root_child0_child0_child1_child0_child0, 0); - final YogaNode root_child0_child0_child1_child0_child0_child0 = new YogaNode(config); + final YogaNode root_child0_child0_child1_child0_child0_child0 = createNode(config); root_child0_child0_child1_child0_child0_child0.setAlignContent(YogaAlign.STRETCH); root_child0_child0_child1_child0_child0_child0.setWidth(72f); root_child0_child0_child1_child0_child0_child0.setHeight(72f); root_child0_child0_child1_child0_child0.addChildAt( root_child0_child0_child1_child0_child0_child0, 0); - final YogaNode root_child0_child0_child1_child0_child1 = new YogaNode(config); + final YogaNode root_child0_child0_child1_child0_child1 = createNode(config); root_child0_child0_child1_child0_child1.setAlignContent(YogaAlign.STRETCH); root_child0_child0_child1_child0_child1.setFlexShrink(1f); root_child0_child0_child1_child0_child1.setMargin(YogaEdge.RIGHT, 36f); @@ -110,14 +120,14 @@ public class YGAndroidNewsFeed { root_child0_child0_child1_child0_child1.setPadding(YogaEdge.BOTTOM, 18); root_child0_child0_child1_child0.addChildAt(root_child0_child0_child1_child0_child1, 1); - final YogaNode root_child0_child0_child1_child0_child1_child0 = new YogaNode(config); + final YogaNode root_child0_child0_child1_child0_child1_child0 = createNode(config); root_child0_child0_child1_child0_child1_child0.setFlexDirection(YogaFlexDirection.ROW); root_child0_child0_child1_child0_child1_child0.setAlignContent(YogaAlign.STRETCH); root_child0_child0_child1_child0_child1_child0.setFlexShrink(1f); root_child0_child0_child1_child0_child1.addChildAt( root_child0_child0_child1_child0_child1_child0, 0); - final YogaNode root_child0_child0_child1_child0_child1_child1 = new YogaNode(config); + final YogaNode root_child0_child0_child1_child0_child1_child1 = createNode(config); root_child0_child0_child1_child0_child1_child1.setAlignContent(YogaAlign.STRETCH); root_child0_child0_child1_child0_child1_child1.setFlexShrink(1f); root_child0_child0_child1_child0_child1.addChildAt( @@ -298,4 +308,8 @@ public class YGAndroidNewsFeed { assertEquals(0f, root_child0_child0_child1_child0_child1_child1.getLayoutWidth(), 0.0f); assertEquals(0f, root_child0_child0_child1_child0_child1_child1.getLayoutHeight(), 0.0f); } + + private YogaNode createNode(YogaConfig config) { + return mNodeFactory.create(config); + } } diff --git a/java/tests/com/facebook/yoga/YGBorderTest.java b/java/tests/com/facebook/yoga/YGBorderTest.java index 18a7431e..b75ad9a1 100644 --- a/java/tests/com/facebook/yoga/YGBorderTest.java +++ b/java/tests/com/facebook/yoga/YGBorderTest.java @@ -9,16 +9,26 @@ package com.facebook.yoga; -import org.junit.Test; - import static org.junit.Assert.assertEquals; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +@RunWith(Parameterized.class) public class YGBorderTest { + @Parameterized.Parameters(name = "{0}") + public static Iterable nodeFactories() { + return TestParametrization.nodeFactories(); + } + + @Parameterized.Parameter public TestParametrization.NodeFactory mNodeFactory; + @Test public void test_border_no_size() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setBorder(YogaEdge.LEFT, 10f); root.setBorder(YogaEdge.TOP, 10f); root.setBorder(YogaEdge.RIGHT, 10f); @@ -44,13 +54,13 @@ public class YGBorderTest { public void test_border_container_match_child() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setBorder(YogaEdge.LEFT, 10f); root.setBorder(YogaEdge.TOP, 10f); root.setBorder(YogaEdge.RIGHT, 10f); root.setBorder(YogaEdge.BOTTOM, 10f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setWidth(10f); root_child0.setHeight(10f); root.addChildAt(root_child0, 0); @@ -85,7 +95,7 @@ public class YGBorderTest { public void test_border_flex_child() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setBorder(YogaEdge.LEFT, 10f); root.setBorder(YogaEdge.TOP, 10f); root.setBorder(YogaEdge.RIGHT, 10f); @@ -93,7 +103,7 @@ public class YGBorderTest { root.setWidth(100f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setFlexGrow(1f); root_child0.setWidth(10f); root.addChildAt(root_child0, 0); @@ -128,7 +138,7 @@ public class YGBorderTest { public void test_border_stretch_child() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setBorder(YogaEdge.LEFT, 10f); root.setBorder(YogaEdge.TOP, 10f); root.setBorder(YogaEdge.RIGHT, 10f); @@ -136,7 +146,7 @@ public class YGBorderTest { root.setWidth(100f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setHeight(10f); root.addChildAt(root_child0, 0); root.setDirection(YogaDirection.LTR); @@ -170,7 +180,7 @@ public class YGBorderTest { public void test_border_center_child() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setJustifyContent(YogaJustify.CENTER); root.setAlignItems(YogaAlign.CENTER); root.setBorder(YogaEdge.START, 10f); @@ -179,7 +189,7 @@ public class YGBorderTest { root.setWidth(100f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setWidth(10f); root_child0.setHeight(10f); root.addChildAt(root_child0, 0); @@ -210,4 +220,7 @@ public class YGBorderTest { assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); } + private YogaNode createNode(YogaConfig config) { + return mNodeFactory.create(config); + } } diff --git a/java/tests/com/facebook/yoga/YGDimensionTest.java b/java/tests/com/facebook/yoga/YGDimensionTest.java index d9cfbea2..21b20356 100644 --- a/java/tests/com/facebook/yoga/YGDimensionTest.java +++ b/java/tests/com/facebook/yoga/YGDimensionTest.java @@ -9,18 +9,28 @@ package com.facebook.yoga; -import org.junit.Test; - import static org.junit.Assert.assertEquals; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +@RunWith(Parameterized.class) public class YGDimensionTest { + @Parameterized.Parameters(name = "{0}") + public static Iterable nodeFactories() { + return TestParametrization.nodeFactories(); + } + + @Parameterized.Parameter public TestParametrization.NodeFactory mNodeFactory; + @Test public void test_wrap_child() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setWidth(100f); root_child0.setHeight(100f); root.addChildAt(root_child0, 0); @@ -55,12 +65,12 @@ public class YGDimensionTest { public void test_wrap_grandchild() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root.addChildAt(root_child0, 0); - final YogaNode root_child0_child0 = new YogaNode(config); + final YogaNode root_child0_child0 = createNode(config); root_child0_child0.setWidth(100f); root_child0_child0.setHeight(100f); root_child0.addChildAt(root_child0_child0, 0); @@ -101,4 +111,7 @@ public class YGDimensionTest { assertEquals(100f, root_child0_child0.getLayoutHeight(), 0.0f); } + private YogaNode createNode(YogaConfig config) { + return mNodeFactory.create(config); + } } diff --git a/java/tests/com/facebook/yoga/YGDisplayTest.java b/java/tests/com/facebook/yoga/YGDisplayTest.java index b8ffab07..a7d093c7 100644 --- a/java/tests/com/facebook/yoga/YGDisplayTest.java +++ b/java/tests/com/facebook/yoga/YGDisplayTest.java @@ -9,25 +9,35 @@ package com.facebook.yoga; -import org.junit.Test; - import static org.junit.Assert.assertEquals; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +@RunWith(Parameterized.class) public class YGDisplayTest { + @Parameterized.Parameters(name = "{0}") + public static Iterable nodeFactories() { + return TestParametrization.nodeFactories(); + } + + @Parameterized.Parameter public TestParametrization.NodeFactory mNodeFactory; + @Test public void test_display_none() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.ROW); root.setWidth(100f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setFlexGrow(1f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setFlexGrow(1f); root_child1.setDisplay(YogaDisplay.NONE); root.addChildAt(root_child1, 1); @@ -72,16 +82,16 @@ public class YGDisplayTest { public void test_display_none_fixed_size() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.ROW); root.setWidth(100f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setFlexGrow(1f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setWidth(20f); root_child1.setHeight(20f); root_child1.setDisplay(YogaDisplay.NONE); @@ -127,12 +137,12 @@ public class YGDisplayTest { public void test_display_none_with_margin() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.ROW); root.setWidth(100f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setMargin(YogaEdge.LEFT, 10f); root_child0.setMargin(YogaEdge.TOP, 10f); root_child0.setMargin(YogaEdge.RIGHT, 10f); @@ -142,7 +152,7 @@ public class YGDisplayTest { root_child0.setDisplay(YogaDisplay.NONE); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setFlexGrow(1f); root.addChildAt(root_child1, 1); root.setDirection(YogaDirection.LTR); @@ -186,25 +196,25 @@ public class YGDisplayTest { public void test_display_none_with_child() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.ROW); root.setWidth(100f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setFlexGrow(1f); root_child0.setFlexShrink(1f); root_child0.setFlexBasisPercent(0f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setFlexGrow(1f); root_child1.setFlexShrink(1f); root_child1.setFlexBasisPercent(0f); root_child1.setDisplay(YogaDisplay.NONE); root.addChildAt(root_child1, 1); - final YogaNode root_child1_child0 = new YogaNode(config); + final YogaNode root_child1_child0 = createNode(config); root_child1_child0.setFlexGrow(1f); root_child1_child0.setFlexShrink(1f); root_child1_child0.setFlexBasisPercent(0f); @@ -213,7 +223,7 @@ public class YGDisplayTest { root_child1_child0.setMinHeight(0f); root_child1.addChildAt(root_child1_child0, 0); - final YogaNode root_child2 = new YogaNode(config); + final YogaNode root_child2 = createNode(config); root_child2.setFlexGrow(1f); root_child2.setFlexShrink(1f); root_child2.setFlexBasisPercent(0f); @@ -279,16 +289,16 @@ public class YGDisplayTest { public void test_display_none_with_position() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.ROW); root.setWidth(100f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setFlexGrow(1f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setFlexGrow(1f); root_child1.setPosition(YogaEdge.TOP, 10f); root_child1.setDisplay(YogaDisplay.NONE); @@ -330,4 +340,7 @@ public class YGDisplayTest { assertEquals(0f, root_child1.getLayoutHeight(), 0.0f); } + private YogaNode createNode(YogaConfig config) { + return mNodeFactory.create(config); + } } diff --git a/java/tests/com/facebook/yoga/YGFlexDirectionTest.java b/java/tests/com/facebook/yoga/YGFlexDirectionTest.java index d5fb3f4a..07f96d17 100644 --- a/java/tests/com/facebook/yoga/YGFlexDirectionTest.java +++ b/java/tests/com/facebook/yoga/YGFlexDirectionTest.java @@ -9,27 +9,37 @@ package com.facebook.yoga; -import org.junit.Test; - import static org.junit.Assert.assertEquals; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +@RunWith(Parameterized.class) public class YGFlexDirectionTest { + @Parameterized.Parameters(name = "{0}") + public static Iterable nodeFactories() { + return TestParametrization.nodeFactories(); + } + + @Parameterized.Parameter public TestParametrization.NodeFactory mNodeFactory; + @Test public void test_flex_direction_column_no_height() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setWidth(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setHeight(10f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setHeight(10f); root.addChildAt(root_child1, 1); - final YogaNode root_child2 = new YogaNode(config); + final YogaNode root_child2 = createNode(config); root_child2.setHeight(10f); root.addChildAt(root_child2, 2); root.setDirection(YogaDirection.LTR); @@ -83,19 +93,19 @@ public class YGFlexDirectionTest { public void test_flex_direction_row_no_width() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.ROW); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setWidth(10f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setWidth(10f); root.addChildAt(root_child1, 1); - final YogaNode root_child2 = new YogaNode(config); + final YogaNode root_child2 = createNode(config); root_child2.setWidth(10f); root.addChildAt(root_child2, 2); root.setDirection(YogaDirection.LTR); @@ -149,19 +159,19 @@ public class YGFlexDirectionTest { public void test_flex_direction_column() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setWidth(100f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setHeight(10f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setHeight(10f); root.addChildAt(root_child1, 1); - final YogaNode root_child2 = new YogaNode(config); + final YogaNode root_child2 = createNode(config); root_child2.setHeight(10f); root.addChildAt(root_child2, 2); root.setDirection(YogaDirection.LTR); @@ -215,20 +225,20 @@ public class YGFlexDirectionTest { public void test_flex_direction_row() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.ROW); root.setWidth(100f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setWidth(10f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setWidth(10f); root.addChildAt(root_child1, 1); - final YogaNode root_child2 = new YogaNode(config); + final YogaNode root_child2 = createNode(config); root_child2.setWidth(10f); root.addChildAt(root_child2, 2); root.setDirection(YogaDirection.LTR); @@ -282,20 +292,20 @@ public class YGFlexDirectionTest { public void test_flex_direction_column_reverse() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.COLUMN_REVERSE); root.setWidth(100f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setHeight(10f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setHeight(10f); root.addChildAt(root_child1, 1); - final YogaNode root_child2 = new YogaNode(config); + final YogaNode root_child2 = createNode(config); root_child2.setHeight(10f); root.addChildAt(root_child2, 2); root.setDirection(YogaDirection.LTR); @@ -349,20 +359,20 @@ public class YGFlexDirectionTest { public void test_flex_direction_row_reverse() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.ROW_REVERSE); root.setWidth(100f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setWidth(10f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setWidth(10f); root.addChildAt(root_child1, 1); - final YogaNode root_child2 = new YogaNode(config); + final YogaNode root_child2 = createNode(config); root_child2.setWidth(10f); root.addChildAt(root_child2, 2); root.setDirection(YogaDirection.LTR); @@ -412,4 +422,7 @@ public class YGFlexDirectionTest { assertEquals(100f, root_child2.getLayoutHeight(), 0.0f); } + private YogaNode createNode(YogaConfig config) { + return mNodeFactory.create(config); + } } diff --git a/java/tests/com/facebook/yoga/YGFlexTest.java b/java/tests/com/facebook/yoga/YGFlexTest.java index 000c33c1..7140d7a1 100644 --- a/java/tests/com/facebook/yoga/YGFlexTest.java +++ b/java/tests/com/facebook/yoga/YGFlexTest.java @@ -9,25 +9,35 @@ package com.facebook.yoga; -import org.junit.Test; - import static org.junit.Assert.assertEquals; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +@RunWith(Parameterized.class) public class YGFlexTest { + @Parameterized.Parameters(name = "{0}") + public static Iterable nodeFactories() { + return TestParametrization.nodeFactories(); + } + + @Parameterized.Parameter public TestParametrization.NodeFactory mNodeFactory; + @Test public void test_flex_basis_flex_grow_column() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setWidth(100f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setFlexGrow(1f); root_child0.setFlexBasis(50f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setFlexGrow(1f); root.addChildAt(root_child1, 1); root.setDirection(YogaDirection.LTR); @@ -71,17 +81,17 @@ public class YGFlexTest { public void test_flex_basis_flex_grow_row() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.ROW); root.setWidth(100f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setFlexGrow(1f); root_child0.setFlexBasis(50f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setFlexGrow(1f); root.addChildAt(root_child1, 1); root.setDirection(YogaDirection.LTR); @@ -125,16 +135,16 @@ public class YGFlexTest { public void test_flex_basis_flex_shrink_column() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setWidth(100f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setFlexShrink(1f); root_child0.setFlexBasis(100f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setFlexBasis(50f); root.addChildAt(root_child1, 1); root.setDirection(YogaDirection.LTR); @@ -178,17 +188,17 @@ public class YGFlexTest { public void test_flex_basis_flex_shrink_row() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.ROW); root.setWidth(100f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setFlexShrink(1f); root_child0.setFlexBasis(100f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setFlexBasis(50f); root.addChildAt(root_child1, 1); root.setDirection(YogaDirection.LTR); @@ -232,21 +242,21 @@ public class YGFlexTest { public void test_flex_shrink_to_zero() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setHeight(75f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setWidth(50f); root_child0.setHeight(50f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setFlexShrink(1f); root_child1.setWidth(50f); root_child1.setHeight(50f); root.addChildAt(root_child1, 1); - final YogaNode root_child2 = new YogaNode(config); + final YogaNode root_child2 = createNode(config); root_child2.setWidth(50f); root_child2.setHeight(50f); root.addChildAt(root_child2, 2); @@ -301,22 +311,22 @@ public class YGFlexTest { public void test_flex_basis_overrides_main_size() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setWidth(100f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setFlexGrow(1f); root_child0.setFlexBasis(50f); root_child0.setHeight(20f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setFlexGrow(1f); root_child1.setHeight(10f); root.addChildAt(root_child1, 1); - final YogaNode root_child2 = new YogaNode(config); + final YogaNode root_child2 = createNode(config); root_child2.setFlexGrow(1f); root_child2.setHeight(10f); root.addChildAt(root_child2, 2); @@ -371,14 +381,14 @@ public class YGFlexTest { public void test_flex_grow_shrink_at_most() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setWidth(100f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root.addChildAt(root_child0, 0); - final YogaNode root_child0_child0 = new YogaNode(config); + final YogaNode root_child0_child0 = createNode(config); root_child0_child0.setFlexGrow(1f); root_child0_child0.setFlexShrink(1f); root_child0.addChildAt(root_child0_child0, 0); @@ -423,20 +433,20 @@ public class YGFlexTest { public void test_flex_grow_less_than_factor_one() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setWidth(200f); root.setHeight(500f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setFlexGrow(0.2f); root_child0.setFlexBasis(40f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setFlexGrow(0.2f); root.addChildAt(root_child1, 1); - final YogaNode root_child2 = new YogaNode(config); + final YogaNode root_child2 = createNode(config); root_child2.setFlexGrow(0.4f); root.addChildAt(root_child2, 2); root.setDirection(YogaDirection.LTR); @@ -486,4 +496,7 @@ public class YGFlexTest { assertEquals(184f, root_child2.getLayoutHeight(), 0.0f); } + private YogaNode createNode(YogaConfig config) { + return mNodeFactory.create(config); + } } diff --git a/java/tests/com/facebook/yoga/YGFlexWrapTest.java b/java/tests/com/facebook/yoga/YGFlexWrapTest.java index d7d0dc2b..0c36aa9c 100644 --- a/java/tests/com/facebook/yoga/YGFlexWrapTest.java +++ b/java/tests/com/facebook/yoga/YGFlexWrapTest.java @@ -9,35 +9,45 @@ package com.facebook.yoga; -import org.junit.Test; - import static org.junit.Assert.assertEquals; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +@RunWith(Parameterized.class) public class YGFlexWrapTest { + @Parameterized.Parameters(name = "{0}") + public static Iterable nodeFactories() { + return TestParametrization.nodeFactories(); + } + + @Parameterized.Parameter public TestParametrization.NodeFactory mNodeFactory; + @Test public void test_wrap_column() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setWrap(YogaWrap.WRAP); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setWidth(30f); root_child0.setHeight(30f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setWidth(30f); root_child1.setHeight(30f); root.addChildAt(root_child1, 1); - final YogaNode root_child2 = new YogaNode(config); + final YogaNode root_child2 = createNode(config); root_child2.setWidth(30f); root_child2.setHeight(30f); root.addChildAt(root_child2, 2); - final YogaNode root_child3 = new YogaNode(config); + final YogaNode root_child3 = createNode(config); root_child3.setWidth(30f); root_child3.setHeight(30f); root.addChildAt(root_child3, 3); @@ -102,27 +112,27 @@ public class YGFlexWrapTest { public void test_wrap_row() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.ROW); root.setWrap(YogaWrap.WRAP); root.setWidth(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setWidth(30f); root_child0.setHeight(30f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setWidth(30f); root_child1.setHeight(30f); root.addChildAt(root_child1, 1); - final YogaNode root_child2 = new YogaNode(config); + final YogaNode root_child2 = createNode(config); root_child2.setWidth(30f); root_child2.setHeight(30f); root.addChildAt(root_child2, 2); - final YogaNode root_child3 = new YogaNode(config); + final YogaNode root_child3 = createNode(config); root_child3.setWidth(30f); root_child3.setHeight(30f); root.addChildAt(root_child3, 3); @@ -187,28 +197,28 @@ public class YGFlexWrapTest { public void test_wrap_row_align_items_flex_end() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.ROW); root.setAlignItems(YogaAlign.FLEX_END); root.setWrap(YogaWrap.WRAP); root.setWidth(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setWidth(30f); root_child0.setHeight(10f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setWidth(30f); root_child1.setHeight(20f); root.addChildAt(root_child1, 1); - final YogaNode root_child2 = new YogaNode(config); + final YogaNode root_child2 = createNode(config); root_child2.setWidth(30f); root_child2.setHeight(30f); root.addChildAt(root_child2, 2); - final YogaNode root_child3 = new YogaNode(config); + final YogaNode root_child3 = createNode(config); root_child3.setWidth(30f); root_child3.setHeight(30f); root.addChildAt(root_child3, 3); @@ -273,28 +283,28 @@ public class YGFlexWrapTest { public void test_wrap_row_align_items_center() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.ROW); root.setAlignItems(YogaAlign.CENTER); root.setWrap(YogaWrap.WRAP); root.setWidth(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setWidth(30f); root_child0.setHeight(10f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setWidth(30f); root_child1.setHeight(20f); root.addChildAt(root_child1, 1); - final YogaNode root_child2 = new YogaNode(config); + final YogaNode root_child2 = createNode(config); root_child2.setWidth(30f); root_child2.setHeight(30f); root.addChildAt(root_child2, 2); - final YogaNode root_child3 = new YogaNode(config); + final YogaNode root_child3 = createNode(config); root_child3.setWidth(30f); root_child3.setHeight(30f); root.addChildAt(root_child3, 3); @@ -359,18 +369,18 @@ public class YGFlexWrapTest { public void test_flex_wrap_children_with_min_main_overriding_flex_basis() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.ROW); root.setWrap(YogaWrap.WRAP); root.setWidth(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setFlexBasis(50f); root_child0.setMinWidth(55f); root_child0.setHeight(50f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setFlexBasis(50f); root_child1.setMinWidth(55f); root_child1.setHeight(50f); @@ -416,24 +426,24 @@ public class YGFlexWrapTest { public void test_flex_wrap_wrap_to_child_height() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setFlexDirection(YogaFlexDirection.ROW); root_child0.setAlignItems(YogaAlign.FLEX_START); root_child0.setWrap(YogaWrap.WRAP); root.addChildAt(root_child0, 0); - final YogaNode root_child0_child0 = new YogaNode(config); + final YogaNode root_child0_child0 = createNode(config); root_child0_child0.setWidth(100f); root_child0.addChildAt(root_child0_child0, 0); - final YogaNode root_child0_child0_child0 = new YogaNode(config); + final YogaNode root_child0_child0_child0 = createNode(config); root_child0_child0_child0.setWidth(100f); root_child0_child0_child0.setHeight(100f); root_child0_child0.addChildAt(root_child0_child0_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setWidth(100f); root_child1.setHeight(100f); root.addChildAt(root_child1, 1); @@ -498,17 +508,17 @@ public class YGFlexWrapTest { public void test_flex_wrap_align_stretch_fits_one_row() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.ROW); root.setWrap(YogaWrap.WRAP); root.setWidth(150f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setWidth(50f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setWidth(50f); root.addChildAt(root_child1, 1); root.setDirection(YogaDirection.LTR); @@ -552,32 +562,32 @@ public class YGFlexWrapTest { public void test_wrap_reverse_row_align_content_flex_start() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.ROW); root.setWrap(YogaWrap.WRAP_REVERSE); root.setWidth(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setWidth(30f); root_child0.setHeight(10f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setWidth(30f); root_child1.setHeight(20f); root.addChildAt(root_child1, 1); - final YogaNode root_child2 = new YogaNode(config); + final YogaNode root_child2 = createNode(config); root_child2.setWidth(30f); root_child2.setHeight(30f); root.addChildAt(root_child2, 2); - final YogaNode root_child3 = new YogaNode(config); + final YogaNode root_child3 = createNode(config); root_child3.setWidth(30f); root_child3.setHeight(40f); root.addChildAt(root_child3, 3); - final YogaNode root_child4 = new YogaNode(config); + final YogaNode root_child4 = createNode(config); root_child4.setWidth(30f); root_child4.setHeight(50f); root.addChildAt(root_child4, 4); @@ -652,33 +662,33 @@ public class YGFlexWrapTest { public void test_wrap_reverse_row_align_content_center() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.ROW); root.setAlignContent(YogaAlign.CENTER); root.setWrap(YogaWrap.WRAP_REVERSE); root.setWidth(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setWidth(30f); root_child0.setHeight(10f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setWidth(30f); root_child1.setHeight(20f); root.addChildAt(root_child1, 1); - final YogaNode root_child2 = new YogaNode(config); + final YogaNode root_child2 = createNode(config); root_child2.setWidth(30f); root_child2.setHeight(30f); root.addChildAt(root_child2, 2); - final YogaNode root_child3 = new YogaNode(config); + final YogaNode root_child3 = createNode(config); root_child3.setWidth(30f); root_child3.setHeight(40f); root.addChildAt(root_child3, 3); - final YogaNode root_child4 = new YogaNode(config); + final YogaNode root_child4 = createNode(config); root_child4.setWidth(30f); root_child4.setHeight(50f); root.addChildAt(root_child4, 4); @@ -753,32 +763,32 @@ public class YGFlexWrapTest { public void test_wrap_reverse_row_single_line_different_size() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.ROW); root.setWrap(YogaWrap.WRAP_REVERSE); root.setWidth(300f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setWidth(30f); root_child0.setHeight(10f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setWidth(30f); root_child1.setHeight(20f); root.addChildAt(root_child1, 1); - final YogaNode root_child2 = new YogaNode(config); + final YogaNode root_child2 = createNode(config); root_child2.setWidth(30f); root_child2.setHeight(30f); root.addChildAt(root_child2, 2); - final YogaNode root_child3 = new YogaNode(config); + final YogaNode root_child3 = createNode(config); root_child3.setWidth(30f); root_child3.setHeight(40f); root.addChildAt(root_child3, 3); - final YogaNode root_child4 = new YogaNode(config); + final YogaNode root_child4 = createNode(config); root_child4.setWidth(30f); root_child4.setHeight(50f); root.addChildAt(root_child4, 4); @@ -853,33 +863,33 @@ public class YGFlexWrapTest { public void test_wrap_reverse_row_align_content_stretch() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.ROW); root.setAlignContent(YogaAlign.STRETCH); root.setWrap(YogaWrap.WRAP_REVERSE); root.setWidth(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setWidth(30f); root_child0.setHeight(10f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setWidth(30f); root_child1.setHeight(20f); root.addChildAt(root_child1, 1); - final YogaNode root_child2 = new YogaNode(config); + final YogaNode root_child2 = createNode(config); root_child2.setWidth(30f); root_child2.setHeight(30f); root.addChildAt(root_child2, 2); - final YogaNode root_child3 = new YogaNode(config); + final YogaNode root_child3 = createNode(config); root_child3.setWidth(30f); root_child3.setHeight(40f); root.addChildAt(root_child3, 3); - final YogaNode root_child4 = new YogaNode(config); + final YogaNode root_child4 = createNode(config); root_child4.setWidth(30f); root_child4.setHeight(50f); root.addChildAt(root_child4, 4); @@ -954,33 +964,33 @@ public class YGFlexWrapTest { public void test_wrap_reverse_row_align_content_space_around() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.ROW); root.setAlignContent(YogaAlign.SPACE_AROUND); root.setWrap(YogaWrap.WRAP_REVERSE); root.setWidth(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setWidth(30f); root_child0.setHeight(10f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setWidth(30f); root_child1.setHeight(20f); root.addChildAt(root_child1, 1); - final YogaNode root_child2 = new YogaNode(config); + final YogaNode root_child2 = createNode(config); root_child2.setWidth(30f); root_child2.setHeight(30f); root.addChildAt(root_child2, 2); - final YogaNode root_child3 = new YogaNode(config); + final YogaNode root_child3 = createNode(config); root_child3.setWidth(30f); root_child3.setHeight(40f); root.addChildAt(root_child3, 3); - final YogaNode root_child4 = new YogaNode(config); + final YogaNode root_child4 = createNode(config); root_child4.setWidth(30f); root_child4.setHeight(50f); root.addChildAt(root_child4, 4); @@ -1055,33 +1065,33 @@ public class YGFlexWrapTest { public void test_wrap_reverse_column_fixed_size() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setAlignItems(YogaAlign.CENTER); root.setWrap(YogaWrap.WRAP_REVERSE); root.setWidth(200f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setWidth(30f); root_child0.setHeight(10f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setWidth(30f); root_child1.setHeight(20f); root.addChildAt(root_child1, 1); - final YogaNode root_child2 = new YogaNode(config); + final YogaNode root_child2 = createNode(config); root_child2.setWidth(30f); root_child2.setHeight(30f); root.addChildAt(root_child2, 2); - final YogaNode root_child3 = new YogaNode(config); + final YogaNode root_child3 = createNode(config); root_child3.setWidth(30f); root_child3.setHeight(40f); root.addChildAt(root_child3, 3); - final YogaNode root_child4 = new YogaNode(config); + final YogaNode root_child4 = createNode(config); root_child4.setWidth(30f); root_child4.setHeight(50f); root.addChildAt(root_child4, 4); @@ -1156,22 +1166,22 @@ public class YGFlexWrapTest { public void test_wrapped_row_within_align_items_center() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setAlignItems(YogaAlign.CENTER); root.setWidth(200f); root.setHeight(200f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setFlexDirection(YogaFlexDirection.ROW); root_child0.setWrap(YogaWrap.WRAP); root.addChildAt(root_child0, 0); - final YogaNode root_child0_child0 = new YogaNode(config); + final YogaNode root_child0_child0 = createNode(config); root_child0_child0.setWidth(150f); root_child0_child0.setHeight(80f); root_child0.addChildAt(root_child0_child0, 0); - final YogaNode root_child0_child1 = new YogaNode(config); + final YogaNode root_child0_child1 = createNode(config); root_child0_child1.setWidth(80f); root_child0_child1.setHeight(80f); root_child0.addChildAt(root_child0_child1, 1); @@ -1226,22 +1236,22 @@ public class YGFlexWrapTest { public void test_wrapped_row_within_align_items_flex_start() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setAlignItems(YogaAlign.FLEX_START); root.setWidth(200f); root.setHeight(200f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setFlexDirection(YogaFlexDirection.ROW); root_child0.setWrap(YogaWrap.WRAP); root.addChildAt(root_child0, 0); - final YogaNode root_child0_child0 = new YogaNode(config); + final YogaNode root_child0_child0 = createNode(config); root_child0_child0.setWidth(150f); root_child0_child0.setHeight(80f); root_child0.addChildAt(root_child0_child0, 0); - final YogaNode root_child0_child1 = new YogaNode(config); + final YogaNode root_child0_child1 = createNode(config); root_child0_child1.setWidth(80f); root_child0_child1.setHeight(80f); root_child0.addChildAt(root_child0_child1, 1); @@ -1296,22 +1306,22 @@ public class YGFlexWrapTest { public void test_wrapped_row_within_align_items_flex_end() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setAlignItems(YogaAlign.FLEX_END); root.setWidth(200f); root.setHeight(200f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setFlexDirection(YogaFlexDirection.ROW); root_child0.setWrap(YogaWrap.WRAP); root.addChildAt(root_child0, 0); - final YogaNode root_child0_child0 = new YogaNode(config); + final YogaNode root_child0_child0 = createNode(config); root_child0_child0.setWidth(150f); root_child0_child0.setHeight(80f); root_child0.addChildAt(root_child0_child0, 0); - final YogaNode root_child0_child1 = new YogaNode(config); + final YogaNode root_child0_child1 = createNode(config); root_child0_child1.setWidth(80f); root_child0_child1.setHeight(80f); root_child0.addChildAt(root_child0_child1, 1); @@ -1366,7 +1376,7 @@ public class YGFlexWrapTest { public void test_wrapped_column_max_height() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setJustifyContent(YogaJustify.CENTER); root.setAlignContent(YogaAlign.CENTER); root.setAlignItems(YogaAlign.CENTER); @@ -1374,13 +1384,13 @@ public class YGFlexWrapTest { root.setWidth(700f); root.setHeight(500f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setWidth(100f); root_child0.setHeight(500f); root_child0.setMaxHeight(200f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setMargin(YogaEdge.LEFT, 20f); root_child1.setMargin(YogaEdge.TOP, 20f); root_child1.setMargin(YogaEdge.RIGHT, 20f); @@ -1389,7 +1399,7 @@ public class YGFlexWrapTest { root_child1.setHeight(200f); root.addChildAt(root_child1, 1); - final YogaNode root_child2 = new YogaNode(config); + final YogaNode root_child2 = createNode(config); root_child2.setWidth(100f); root_child2.setHeight(100f); root.addChildAt(root_child2, 2); @@ -1444,7 +1454,7 @@ public class YGFlexWrapTest { public void test_wrapped_column_max_height_flex() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setJustifyContent(YogaJustify.CENTER); root.setAlignContent(YogaAlign.CENTER); root.setAlignItems(YogaAlign.CENTER); @@ -1452,7 +1462,7 @@ public class YGFlexWrapTest { root.setWidth(700f); root.setHeight(500f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setFlexGrow(1f); root_child0.setFlexShrink(1f); root_child0.setFlexBasisPercent(0f); @@ -1461,7 +1471,7 @@ public class YGFlexWrapTest { root_child0.setMaxHeight(200f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setFlexGrow(1f); root_child1.setFlexShrink(1f); root_child1.setFlexBasisPercent(0f); @@ -1473,7 +1483,7 @@ public class YGFlexWrapTest { root_child1.setHeight(200f); root.addChildAt(root_child1, 1); - final YogaNode root_child2 = new YogaNode(config); + final YogaNode root_child2 = createNode(config); root_child2.setWidth(100f); root_child2.setHeight(100f); root.addChildAt(root_child2, 2); @@ -1528,29 +1538,29 @@ public class YGFlexWrapTest { public void test_wrap_nodes_with_content_sizing_overflowing_margin() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setWidth(500f); root.setHeight(500f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setFlexDirection(YogaFlexDirection.ROW); root_child0.setWrap(YogaWrap.WRAP); root_child0.setWidth(85f); root.addChildAt(root_child0, 0); - final YogaNode root_child0_child0 = new YogaNode(config); + final YogaNode root_child0_child0 = createNode(config); root_child0.addChildAt(root_child0_child0, 0); - final YogaNode root_child0_child0_child0 = new YogaNode(config); + final YogaNode root_child0_child0_child0 = createNode(config); root_child0_child0_child0.setWidth(40f); root_child0_child0_child0.setHeight(40f); root_child0_child0.addChildAt(root_child0_child0_child0, 0); - final YogaNode root_child0_child1 = new YogaNode(config); + final YogaNode root_child0_child1 = createNode(config); root_child0_child1.setMargin(YogaEdge.RIGHT, 10f); root_child0.addChildAt(root_child0_child1, 1); - final YogaNode root_child0_child1_child0 = new YogaNode(config); + final YogaNode root_child0_child1_child0 = createNode(config); root_child0_child1_child0.setWidth(40f); root_child0_child1_child0.setHeight(40f); root_child0_child1.addChildAt(root_child0_child1_child0, 0); @@ -1625,29 +1635,29 @@ public class YGFlexWrapTest { public void test_wrap_nodes_with_content_sizing_margin_cross() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setWidth(500f); root.setHeight(500f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setFlexDirection(YogaFlexDirection.ROW); root_child0.setWrap(YogaWrap.WRAP); root_child0.setWidth(70f); root.addChildAt(root_child0, 0); - final YogaNode root_child0_child0 = new YogaNode(config); + final YogaNode root_child0_child0 = createNode(config); root_child0.addChildAt(root_child0_child0, 0); - final YogaNode root_child0_child0_child0 = new YogaNode(config); + final YogaNode root_child0_child0_child0 = createNode(config); root_child0_child0_child0.setWidth(40f); root_child0_child0_child0.setHeight(40f); root_child0_child0.addChildAt(root_child0_child0_child0, 0); - final YogaNode root_child0_child1 = new YogaNode(config); + final YogaNode root_child0_child1 = createNode(config); root_child0_child1.setMargin(YogaEdge.TOP, 10f); root_child0.addChildAt(root_child0_child1, 1); - final YogaNode root_child0_child1_child0 = new YogaNode(config); + final YogaNode root_child0_child1_child0 = createNode(config); root_child0_child1_child0.setWidth(40f); root_child0_child1_child0.setHeight(40f); root_child0_child1.addChildAt(root_child0_child1_child0, 0); @@ -1718,4 +1728,7 @@ public class YGFlexWrapTest { assertEquals(40f, root_child0_child1_child0.getLayoutHeight(), 0.0f); } + private YogaNode createNode(YogaConfig config) { + return mNodeFactory.create(config); + } } diff --git a/java/tests/com/facebook/yoga/YGJustifyContentTest.java b/java/tests/com/facebook/yoga/YGJustifyContentTest.java index cde75c84..69b2077e 100644 --- a/java/tests/com/facebook/yoga/YGJustifyContentTest.java +++ b/java/tests/com/facebook/yoga/YGJustifyContentTest.java @@ -9,29 +9,39 @@ package com.facebook.yoga; -import org.junit.Test; - import static org.junit.Assert.assertEquals; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +@RunWith(Parameterized.class) public class YGJustifyContentTest { + @Parameterized.Parameters(name = "{0}") + public static Iterable nodeFactories() { + return TestParametrization.nodeFactories(); + } + + @Parameterized.Parameter public TestParametrization.NodeFactory mNodeFactory; + @Test public void test_justify_content_row_flex_start() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.ROW); root.setWidth(102f); root.setHeight(102f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setWidth(10f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setWidth(10f); root.addChildAt(root_child1, 1); - final YogaNode root_child2 = new YogaNode(config); + final YogaNode root_child2 = createNode(config); root_child2.setWidth(10f); root.addChildAt(root_child2, 2); root.setDirection(YogaDirection.LTR); @@ -85,21 +95,21 @@ public class YGJustifyContentTest { public void test_justify_content_row_flex_end() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.ROW); root.setJustifyContent(YogaJustify.FLEX_END); root.setWidth(102f); root.setHeight(102f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setWidth(10f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setWidth(10f); root.addChildAt(root_child1, 1); - final YogaNode root_child2 = new YogaNode(config); + final YogaNode root_child2 = createNode(config); root_child2.setWidth(10f); root.addChildAt(root_child2, 2); root.setDirection(YogaDirection.LTR); @@ -153,21 +163,21 @@ public class YGJustifyContentTest { public void test_justify_content_row_center() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.ROW); root.setJustifyContent(YogaJustify.CENTER); root.setWidth(102f); root.setHeight(102f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setWidth(10f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setWidth(10f); root.addChildAt(root_child1, 1); - final YogaNode root_child2 = new YogaNode(config); + final YogaNode root_child2 = createNode(config); root_child2.setWidth(10f); root.addChildAt(root_child2, 2); root.setDirection(YogaDirection.LTR); @@ -221,21 +231,21 @@ public class YGJustifyContentTest { public void test_justify_content_row_space_between() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.ROW); root.setJustifyContent(YogaJustify.SPACE_BETWEEN); root.setWidth(102f); root.setHeight(102f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setWidth(10f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setWidth(10f); root.addChildAt(root_child1, 1); - final YogaNode root_child2 = new YogaNode(config); + final YogaNode root_child2 = createNode(config); root_child2.setWidth(10f); root.addChildAt(root_child2, 2); root.setDirection(YogaDirection.LTR); @@ -289,21 +299,21 @@ public class YGJustifyContentTest { public void test_justify_content_row_space_around() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.ROW); root.setJustifyContent(YogaJustify.SPACE_AROUND); root.setWidth(102f); root.setHeight(102f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setWidth(10f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setWidth(10f); root.addChildAt(root_child1, 1); - final YogaNode root_child2 = new YogaNode(config); + final YogaNode root_child2 = createNode(config); root_child2.setWidth(10f); root.addChildAt(root_child2, 2); root.setDirection(YogaDirection.LTR); @@ -357,19 +367,19 @@ public class YGJustifyContentTest { public void test_justify_content_column_flex_start() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setWidth(102f); root.setHeight(102f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setHeight(10f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setHeight(10f); root.addChildAt(root_child1, 1); - final YogaNode root_child2 = new YogaNode(config); + final YogaNode root_child2 = createNode(config); root_child2.setHeight(10f); root.addChildAt(root_child2, 2); root.setDirection(YogaDirection.LTR); @@ -423,20 +433,20 @@ public class YGJustifyContentTest { public void test_justify_content_column_flex_end() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setJustifyContent(YogaJustify.FLEX_END); root.setWidth(102f); root.setHeight(102f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setHeight(10f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setHeight(10f); root.addChildAt(root_child1, 1); - final YogaNode root_child2 = new YogaNode(config); + final YogaNode root_child2 = createNode(config); root_child2.setHeight(10f); root.addChildAt(root_child2, 2); root.setDirection(YogaDirection.LTR); @@ -490,20 +500,20 @@ public class YGJustifyContentTest { public void test_justify_content_column_center() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setJustifyContent(YogaJustify.CENTER); root.setWidth(102f); root.setHeight(102f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setHeight(10f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setHeight(10f); root.addChildAt(root_child1, 1); - final YogaNode root_child2 = new YogaNode(config); + final YogaNode root_child2 = createNode(config); root_child2.setHeight(10f); root.addChildAt(root_child2, 2); root.setDirection(YogaDirection.LTR); @@ -557,20 +567,20 @@ public class YGJustifyContentTest { public void test_justify_content_column_space_between() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setJustifyContent(YogaJustify.SPACE_BETWEEN); root.setWidth(102f); root.setHeight(102f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setHeight(10f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setHeight(10f); root.addChildAt(root_child1, 1); - final YogaNode root_child2 = new YogaNode(config); + final YogaNode root_child2 = createNode(config); root_child2.setHeight(10f); root.addChildAt(root_child2, 2); root.setDirection(YogaDirection.LTR); @@ -624,20 +634,20 @@ public class YGJustifyContentTest { public void test_justify_content_column_space_around() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setJustifyContent(YogaJustify.SPACE_AROUND); root.setWidth(102f); root.setHeight(102f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setHeight(10f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setHeight(10f); root.addChildAt(root_child1, 1); - final YogaNode root_child2 = new YogaNode(config); + final YogaNode root_child2 = createNode(config); root_child2.setHeight(10f); root.addChildAt(root_child2, 2); root.setDirection(YogaDirection.LTR); @@ -691,13 +701,13 @@ public class YGJustifyContentTest { public void test_justify_content_row_min_width_and_margin() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.ROW); root.setJustifyContent(YogaJustify.CENTER); root.setMargin(YogaEdge.LEFT, 100f); root.setMinWidth(50f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setWidth(20f); root_child0.setHeight(20f); root.addChildAt(root_child0, 0); @@ -732,14 +742,14 @@ public class YGJustifyContentTest { public void test_justify_content_row_max_width_and_margin() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.ROW); root.setJustifyContent(YogaJustify.CENTER); root.setMargin(YogaEdge.LEFT, 100f); root.setWidth(100f); root.setMaxWidth(80f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setWidth(20f); root_child0.setHeight(20f); root.addChildAt(root_child0, 0); @@ -774,12 +784,12 @@ public class YGJustifyContentTest { public void test_justify_content_column_min_height_and_margin() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setJustifyContent(YogaJustify.CENTER); root.setMargin(YogaEdge.TOP, 100f); root.setMinHeight(50f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setWidth(20f); root_child0.setHeight(20f); root.addChildAt(root_child0, 0); @@ -814,13 +824,13 @@ public class YGJustifyContentTest { public void test_justify_content_colunn_max_height_and_margin() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setJustifyContent(YogaJustify.CENTER); root.setMargin(YogaEdge.TOP, 100f); root.setHeight(100f); root.setMaxHeight(80f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setWidth(20f); root_child0.setHeight(20f); root.addChildAt(root_child0, 0); @@ -855,20 +865,20 @@ public class YGJustifyContentTest { public void test_justify_content_column_space_evenly() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setJustifyContent(YogaJustify.SPACE_EVENLY); root.setWidth(102f); root.setHeight(102f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setHeight(10f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setHeight(10f); root.addChildAt(root_child1, 1); - final YogaNode root_child2 = new YogaNode(config); + final YogaNode root_child2 = createNode(config); root_child2.setHeight(10f); root.addChildAt(root_child2, 2); root.setDirection(YogaDirection.LTR); @@ -922,21 +932,21 @@ public class YGJustifyContentTest { public void test_justify_content_row_space_evenly() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.ROW); root.setJustifyContent(YogaJustify.SPACE_EVENLY); root.setWidth(102f); root.setHeight(102f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setHeight(10f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setHeight(10f); root.addChildAt(root_child1, 1); - final YogaNode root_child2 = new YogaNode(config); + final YogaNode root_child2 = createNode(config); root_child2.setHeight(10f); root.addChildAt(root_child2, 2); root.setDirection(YogaDirection.LTR); @@ -986,4 +996,7 @@ public class YGJustifyContentTest { assertEquals(10f, root_child2.getLayoutHeight(), 0.0f); } + private YogaNode createNode(YogaConfig config) { + return mNodeFactory.create(config); + } } diff --git a/java/tests/com/facebook/yoga/YGMarginTest.java b/java/tests/com/facebook/yoga/YGMarginTest.java index c4921e16..e6f774a1 100644 --- a/java/tests/com/facebook/yoga/YGMarginTest.java +++ b/java/tests/com/facebook/yoga/YGMarginTest.java @@ -9,21 +9,31 @@ package com.facebook.yoga; -import org.junit.Test; - import static org.junit.Assert.assertEquals; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +@RunWith(Parameterized.class) public class YGMarginTest { + @Parameterized.Parameters(name = "{0}") + public static Iterable nodeFactories() { + return TestParametrization.nodeFactories(); + } + + @Parameterized.Parameter public TestParametrization.NodeFactory mNodeFactory; + @Test public void test_margin_start() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.ROW); root.setWidth(100f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setMargin(YogaEdge.START, 10f); root_child0.setWidth(10f); root.addChildAt(root_child0, 0); @@ -58,11 +68,11 @@ public class YGMarginTest { public void test_margin_top() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setWidth(100f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setMargin(YogaEdge.TOP, 10f); root_child0.setHeight(10f); root.addChildAt(root_child0, 0); @@ -97,13 +107,13 @@ public class YGMarginTest { public void test_margin_end() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.ROW); root.setJustifyContent(YogaJustify.FLEX_END); root.setWidth(100f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setMargin(YogaEdge.END, 10f); root_child0.setWidth(10f); root.addChildAt(root_child0, 0); @@ -138,12 +148,12 @@ public class YGMarginTest { public void test_margin_bottom() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setJustifyContent(YogaJustify.FLEX_END); root.setWidth(100f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setMargin(YogaEdge.BOTTOM, 10f); root_child0.setHeight(10f); root.addChildAt(root_child0, 0); @@ -178,12 +188,12 @@ public class YGMarginTest { public void test_margin_and_flex_row() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.ROW); root.setWidth(100f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setFlexGrow(1f); root_child0.setMargin(YogaEdge.START, 10f); root_child0.setMargin(YogaEdge.END, 10f); @@ -219,11 +229,11 @@ public class YGMarginTest { public void test_margin_and_flex_column() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setWidth(100f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setFlexGrow(1f); root_child0.setMargin(YogaEdge.TOP, 10f); root_child0.setMargin(YogaEdge.BOTTOM, 10f); @@ -259,12 +269,12 @@ public class YGMarginTest { public void test_margin_and_stretch_row() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.ROW); root.setWidth(100f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setFlexGrow(1f); root_child0.setMargin(YogaEdge.TOP, 10f); root_child0.setMargin(YogaEdge.BOTTOM, 10f); @@ -300,11 +310,11 @@ public class YGMarginTest { public void test_margin_and_stretch_column() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setWidth(100f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setFlexGrow(1f); root_child0.setMargin(YogaEdge.START, 10f); root_child0.setMargin(YogaEdge.END, 10f); @@ -340,17 +350,17 @@ public class YGMarginTest { public void test_margin_with_sibling_row() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.ROW); root.setWidth(100f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setFlexGrow(1f); root_child0.setMargin(YogaEdge.END, 10f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setFlexGrow(1f); root.addChildAt(root_child1, 1); root.setDirection(YogaDirection.LTR); @@ -394,16 +404,16 @@ public class YGMarginTest { public void test_margin_with_sibling_column() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setWidth(100f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setFlexGrow(1f); root_child0.setMargin(YogaEdge.BOTTOM, 10f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setFlexGrow(1f); root.addChildAt(root_child1, 1); root.setDirection(YogaDirection.LTR); @@ -447,18 +457,18 @@ public class YGMarginTest { public void test_margin_auto_bottom() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setAlignItems(YogaAlign.CENTER); root.setWidth(200f); root.setHeight(200f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setMarginAuto(YogaEdge.BOTTOM); root_child0.setWidth(50f); root_child0.setHeight(50f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setWidth(50f); root_child1.setHeight(50f); root.addChildAt(root_child1, 1); @@ -503,18 +513,18 @@ public class YGMarginTest { public void test_margin_auto_top() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setAlignItems(YogaAlign.CENTER); root.setWidth(200f); root.setHeight(200f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setMarginAuto(YogaEdge.TOP); root_child0.setWidth(50f); root_child0.setHeight(50f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setWidth(50f); root_child1.setHeight(50f); root.addChildAt(root_child1, 1); @@ -559,19 +569,19 @@ public class YGMarginTest { public void test_margin_auto_bottom_and_top() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setAlignItems(YogaAlign.CENTER); root.setWidth(200f); root.setHeight(200f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setMarginAuto(YogaEdge.TOP); root_child0.setMarginAuto(YogaEdge.BOTTOM); root_child0.setWidth(50f); root_child0.setHeight(50f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setWidth(50f); root_child1.setHeight(50f); root.addChildAt(root_child1, 1); @@ -616,19 +626,19 @@ public class YGMarginTest { public void test_margin_auto_bottom_and_top_justify_center() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setJustifyContent(YogaJustify.CENTER); root.setWidth(200f); root.setHeight(200f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setMarginAuto(YogaEdge.TOP); root_child0.setMarginAuto(YogaEdge.BOTTOM); root_child0.setWidth(50f); root_child0.setHeight(50f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setWidth(50f); root_child1.setHeight(50f); root.addChildAt(root_child1, 1); @@ -673,24 +683,24 @@ public class YGMarginTest { public void test_margin_auto_mutiple_children_column() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setAlignItems(YogaAlign.CENTER); root.setWidth(200f); root.setHeight(200f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setMarginAuto(YogaEdge.TOP); root_child0.setWidth(50f); root_child0.setHeight(50f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setMarginAuto(YogaEdge.TOP); root_child1.setWidth(50f); root_child1.setHeight(50f); root.addChildAt(root_child1, 1); - final YogaNode root_child2 = new YogaNode(config); + final YogaNode root_child2 = createNode(config); root_child2.setWidth(50f); root_child2.setHeight(50f); root.addChildAt(root_child2, 2); @@ -745,25 +755,25 @@ public class YGMarginTest { public void test_margin_auto_mutiple_children_row() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.ROW); root.setAlignItems(YogaAlign.CENTER); root.setWidth(200f); root.setHeight(200f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setMarginAuto(YogaEdge.RIGHT); root_child0.setWidth(50f); root_child0.setHeight(50f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setMarginAuto(YogaEdge.RIGHT); root_child1.setWidth(50f); root_child1.setHeight(50f); root.addChildAt(root_child1, 1); - final YogaNode root_child2 = new YogaNode(config); + final YogaNode root_child2 = createNode(config); root_child2.setWidth(50f); root_child2.setHeight(50f); root.addChildAt(root_child2, 2); @@ -818,20 +828,20 @@ public class YGMarginTest { public void test_margin_auto_left_and_right_column() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.ROW); root.setAlignItems(YogaAlign.CENTER); root.setWidth(200f); root.setHeight(200f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setMarginAuto(YogaEdge.LEFT); root_child0.setMarginAuto(YogaEdge.RIGHT); root_child0.setWidth(50f); root_child0.setHeight(50f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setWidth(50f); root_child1.setHeight(50f); root.addChildAt(root_child1, 1); @@ -876,18 +886,18 @@ public class YGMarginTest { public void test_margin_auto_left_and_right() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setWidth(200f); root.setHeight(200f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setMarginAuto(YogaEdge.LEFT); root_child0.setMarginAuto(YogaEdge.RIGHT); root_child0.setWidth(50f); root_child0.setHeight(50f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setWidth(50f); root_child1.setHeight(50f); root.addChildAt(root_child1, 1); @@ -932,20 +942,20 @@ public class YGMarginTest { public void test_margin_auto_start_and_end_column() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.ROW); root.setAlignItems(YogaAlign.CENTER); root.setWidth(200f); root.setHeight(200f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setMarginAuto(YogaEdge.START); root_child0.setMarginAuto(YogaEdge.END); root_child0.setWidth(50f); root_child0.setHeight(50f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setWidth(50f); root_child1.setHeight(50f); root.addChildAt(root_child1, 1); @@ -990,18 +1000,18 @@ public class YGMarginTest { public void test_margin_auto_start_and_end() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setWidth(200f); root.setHeight(200f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setMarginAuto(YogaEdge.START); root_child0.setMarginAuto(YogaEdge.END); root_child0.setWidth(50f); root_child0.setHeight(50f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setWidth(50f); root_child1.setHeight(50f); root.addChildAt(root_child1, 1); @@ -1046,19 +1056,19 @@ public class YGMarginTest { public void test_margin_auto_left_and_right_column_and_center() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setAlignItems(YogaAlign.CENTER); root.setWidth(200f); root.setHeight(200f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setMarginAuto(YogaEdge.LEFT); root_child0.setMarginAuto(YogaEdge.RIGHT); root_child0.setWidth(50f); root_child0.setHeight(50f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setWidth(50f); root_child1.setHeight(50f); root.addChildAt(root_child1, 1); @@ -1103,18 +1113,18 @@ public class YGMarginTest { public void test_margin_auto_left() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setAlignItems(YogaAlign.CENTER); root.setWidth(200f); root.setHeight(200f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setMarginAuto(YogaEdge.LEFT); root_child0.setWidth(50f); root_child0.setHeight(50f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setWidth(50f); root_child1.setHeight(50f); root.addChildAt(root_child1, 1); @@ -1159,18 +1169,18 @@ public class YGMarginTest { public void test_margin_auto_right() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setAlignItems(YogaAlign.CENTER); root.setWidth(200f); root.setHeight(200f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setMarginAuto(YogaEdge.RIGHT); root_child0.setWidth(50f); root_child0.setHeight(50f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setWidth(50f); root_child1.setHeight(50f); root.addChildAt(root_child1, 1); @@ -1215,19 +1225,19 @@ public class YGMarginTest { public void test_margin_auto_left_and_right_strech() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.ROW); root.setWidth(200f); root.setHeight(200f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setMarginAuto(YogaEdge.LEFT); root_child0.setMarginAuto(YogaEdge.RIGHT); root_child0.setWidth(50f); root_child0.setHeight(50f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setWidth(50f); root_child1.setHeight(50f); root.addChildAt(root_child1, 1); @@ -1272,18 +1282,18 @@ public class YGMarginTest { public void test_margin_auto_top_and_bottom_strech() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setWidth(200f); root.setHeight(200f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setMarginAuto(YogaEdge.TOP); root_child0.setMarginAuto(YogaEdge.BOTTOM); root_child0.setWidth(50f); root_child0.setHeight(50f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setWidth(50f); root_child1.setHeight(50f); root.addChildAt(root_child1, 1); @@ -1328,11 +1338,11 @@ public class YGMarginTest { public void test_margin_should_not_be_part_of_max_height() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setWidth(250f); root.setHeight(250f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setMargin(YogaEdge.TOP, 20f); root_child0.setWidth(100f); root_child0.setHeight(100f); @@ -1369,11 +1379,11 @@ public class YGMarginTest { public void test_margin_should_not_be_part_of_max_width() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setWidth(250f); root.setHeight(250f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setMargin(YogaEdge.LEFT, 20f); root_child0.setWidth(100f); root_child0.setMaxWidth(100f); @@ -1410,12 +1420,12 @@ public class YGMarginTest { public void test_margin_auto_left_right_child_bigger_than_parent() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setJustifyContent(YogaJustify.CENTER); root.setWidth(52f); root.setHeight(52f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setMarginAuto(YogaEdge.LEFT); root_child0.setMarginAuto(YogaEdge.RIGHT); root_child0.setWidth(72f); @@ -1452,12 +1462,12 @@ public class YGMarginTest { public void test_margin_auto_left_child_bigger_than_parent() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setJustifyContent(YogaJustify.CENTER); root.setWidth(52f); root.setHeight(52f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setMarginAuto(YogaEdge.LEFT); root_child0.setWidth(72f); root_child0.setHeight(72f); @@ -1493,12 +1503,12 @@ public class YGMarginTest { public void test_margin_fix_left_auto_right_child_bigger_than_parent() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setJustifyContent(YogaJustify.CENTER); root.setWidth(52f); root.setHeight(52f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setMargin(YogaEdge.LEFT, 10f); root_child0.setMarginAuto(YogaEdge.RIGHT); root_child0.setWidth(72f); @@ -1535,12 +1545,12 @@ public class YGMarginTest { public void test_margin_auto_left_fix_right_child_bigger_than_parent() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setJustifyContent(YogaJustify.CENTER); root.setWidth(52f); root.setHeight(52f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setMarginAuto(YogaEdge.LEFT); root_child0.setMargin(YogaEdge.RIGHT, 10f); root_child0.setWidth(72f); @@ -1577,19 +1587,19 @@ public class YGMarginTest { public void test_margin_auto_top_stretching_child() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setAlignItems(YogaAlign.CENTER); root.setWidth(200f); root.setHeight(200f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setFlexGrow(1f); root_child0.setFlexShrink(1f); root_child0.setFlexBasisPercent(0f); root_child0.setMarginAuto(YogaEdge.TOP); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setWidth(50f); root_child1.setHeight(50f); root.addChildAt(root_child1, 1); @@ -1634,19 +1644,19 @@ public class YGMarginTest { public void test_margin_auto_left_stretching_child() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setAlignItems(YogaAlign.CENTER); root.setWidth(200f); root.setHeight(200f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setFlexGrow(1f); root_child0.setFlexShrink(1f); root_child0.setFlexBasisPercent(0f); root_child0.setMarginAuto(YogaEdge.LEFT); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setWidth(50f); root_child1.setHeight(50f); root.addChildAt(root_child1, 1); @@ -1687,4 +1697,7 @@ public class YGMarginTest { assertEquals(50f, root_child1.getLayoutHeight(), 0.0f); } + private YogaNode createNode(YogaConfig config) { + return mNodeFactory.create(config); + } } diff --git a/java/tests/com/facebook/yoga/YGMinMaxDimensionTest.java b/java/tests/com/facebook/yoga/YGMinMaxDimensionTest.java index eb01dd82..765fd2f5 100644 --- a/java/tests/com/facebook/yoga/YGMinMaxDimensionTest.java +++ b/java/tests/com/facebook/yoga/YGMinMaxDimensionTest.java @@ -9,20 +9,30 @@ package com.facebook.yoga; -import org.junit.Test; - import static org.junit.Assert.assertEquals; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +@RunWith(Parameterized.class) public class YGMinMaxDimensionTest { + @Parameterized.Parameters(name = "{0}") + public static Iterable nodeFactories() { + return TestParametrization.nodeFactories(); + } + + @Parameterized.Parameter public TestParametrization.NodeFactory mNodeFactory; + @Test public void test_max_width() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setWidth(100f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setMaxWidth(50f); root_child0.setHeight(10f); root.addChildAt(root_child0, 0); @@ -57,12 +67,12 @@ public class YGMinMaxDimensionTest { public void test_max_height() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.ROW); root.setWidth(100f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setWidth(10f); root_child0.setMaxHeight(50f); root.addChildAt(root_child0, 0); @@ -97,16 +107,16 @@ public class YGMinMaxDimensionTest { public void test_min_height() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setWidth(100f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setFlexGrow(1f); root_child0.setMinHeight(60f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setFlexGrow(1f); root.addChildAt(root_child1, 1); root.setDirection(YogaDirection.LTR); @@ -150,17 +160,17 @@ public class YGMinMaxDimensionTest { public void test_min_width() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.ROW); root.setWidth(100f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setFlexGrow(1f); root_child0.setMinWidth(60f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setFlexGrow(1f); root.addChildAt(root_child1, 1); root.setDirection(YogaDirection.LTR); @@ -204,13 +214,13 @@ public class YGMinMaxDimensionTest { public void test_justify_content_min_max() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setJustifyContent(YogaJustify.CENTER); root.setWidth(100f); root.setMinHeight(100f); root.setMaxHeight(200f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setWidth(60f); root_child0.setHeight(60f); root.addChildAt(root_child0, 0); @@ -245,13 +255,13 @@ public class YGMinMaxDimensionTest { public void test_align_items_min_max() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setAlignItems(YogaAlign.CENTER); root.setMinWidth(100f); root.setMaxWidth(200f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setWidth(60f); root_child0.setHeight(60f); root.addChildAt(root_child0, 0); @@ -286,22 +296,22 @@ public class YGMinMaxDimensionTest { public void test_justify_content_overflow_min_max() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setJustifyContent(YogaJustify.CENTER); root.setMinHeight(100f); root.setMaxHeight(110f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setWidth(50f); root_child0.setHeight(50f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setWidth(50f); root_child1.setHeight(50f); root.addChildAt(root_child1, 1); - final YogaNode root_child2 = new YogaNode(config); + final YogaNode root_child2 = createNode(config); root_child2.setWidth(50f); root_child2.setHeight(50f); root.addChildAt(root_child2, 2); @@ -356,17 +366,17 @@ public class YGMinMaxDimensionTest { public void test_flex_grow_to_min() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setWidth(100f); root.setMinHeight(100f); root.setMaxHeight(500f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setFlexGrow(1f); root_child0.setFlexShrink(1f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setHeight(50f); root.addChildAt(root_child1, 1); root.setDirection(YogaDirection.LTR); @@ -410,17 +420,17 @@ public class YGMinMaxDimensionTest { public void test_flex_grow_in_at_most_container() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.ROW); root.setAlignItems(YogaAlign.FLEX_START); root.setWidth(100f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setFlexDirection(YogaFlexDirection.ROW); root.addChildAt(root_child0, 0); - final YogaNode root_child0_child0 = new YogaNode(config); + final YogaNode root_child0_child0 = createNode(config); root_child0_child0.setFlexGrow(1f); root_child0_child0.setFlexBasis(0f); root_child0.addChildAt(root_child0_child0, 0); @@ -465,10 +475,10 @@ public class YGMinMaxDimensionTest { public void test_flex_grow_child() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.ROW); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setFlexGrow(1f); root_child0.setFlexBasis(0f); root_child0.setHeight(100f); @@ -504,15 +514,15 @@ public class YGMinMaxDimensionTest { public void test_flex_grow_within_constrained_min_max_column() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setMinHeight(100f); root.setMaxHeight(200f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setFlexGrow(1f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setHeight(50f); root.addChildAt(root_child1, 1); root.setDirection(YogaDirection.LTR); @@ -556,16 +566,16 @@ public class YGMinMaxDimensionTest { public void test_flex_grow_within_max_width() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setWidth(200f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setFlexDirection(YogaFlexDirection.ROW); root_child0.setMaxWidth(100f); root.addChildAt(root_child0, 0); - final YogaNode root_child0_child0 = new YogaNode(config); + final YogaNode root_child0_child0 = createNode(config); root_child0_child0.setFlexGrow(1f); root_child0_child0.setHeight(20f); root_child0.addChildAt(root_child0_child0, 0); @@ -610,16 +620,16 @@ public class YGMinMaxDimensionTest { public void test_flex_grow_within_constrained_max_width() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setWidth(200f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setFlexDirection(YogaFlexDirection.ROW); root_child0.setMaxWidth(300f); root.addChildAt(root_child0, 0); - final YogaNode root_child0_child0 = new YogaNode(config); + final YogaNode root_child0_child0 = createNode(config); root_child0_child0.setFlexGrow(1f); root_child0_child0.setHeight(20f); root_child0.addChildAt(root_child0_child0, 0); @@ -664,18 +674,18 @@ public class YGMinMaxDimensionTest { public void test_flex_root_ignored() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexGrow(1f); root.setWidth(100f); root.setMinHeight(100f); root.setMaxHeight(500f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setFlexGrow(1f); root_child0.setFlexBasis(200f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setHeight(100f); root.addChildAt(root_child1, 1); root.setDirection(YogaDirection.LTR); @@ -719,23 +729,23 @@ public class YGMinMaxDimensionTest { public void test_flex_grow_root_minimized() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setWidth(100f); root.setMinHeight(100f); root.setMaxHeight(500f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setFlexGrow(1f); root_child0.setMinHeight(100f); root_child0.setMaxHeight(500f); root.addChildAt(root_child0, 0); - final YogaNode root_child0_child0 = new YogaNode(config); + final YogaNode root_child0_child0 = createNode(config); root_child0_child0.setFlexGrow(1f); root_child0_child0.setFlexBasis(200f); root_child0.addChildAt(root_child0_child0, 0); - final YogaNode root_child0_child1 = new YogaNode(config); + final YogaNode root_child0_child1 = createNode(config); root_child0_child1.setHeight(100f); root_child0.addChildAt(root_child0_child1, 1); root.setDirection(YogaDirection.LTR); @@ -789,22 +799,22 @@ public class YGMinMaxDimensionTest { public void test_flex_grow_height_maximized() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setWidth(100f); root.setHeight(500f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setFlexGrow(1f); root_child0.setMinHeight(100f); root_child0.setMaxHeight(500f); root.addChildAt(root_child0, 0); - final YogaNode root_child0_child0 = new YogaNode(config); + final YogaNode root_child0_child0 = createNode(config); root_child0_child0.setFlexGrow(1f); root_child0_child0.setFlexBasis(200f); root_child0.addChildAt(root_child0_child0, 0); - final YogaNode root_child0_child1 = new YogaNode(config); + final YogaNode root_child0_child1 = createNode(config); root_child0_child1.setHeight(100f); root_child0.addChildAt(root_child0_child1, 1); root.setDirection(YogaDirection.LTR); @@ -858,16 +868,16 @@ public class YGMinMaxDimensionTest { public void test_flex_grow_within_constrained_min_row() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.ROW); root.setMinWidth(100f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setFlexGrow(1f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setWidth(50f); root.addChildAt(root_child1, 1); root.setDirection(YogaDirection.LTR); @@ -911,14 +921,14 @@ public class YGMinMaxDimensionTest { public void test_flex_grow_within_constrained_min_column() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setMinHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setFlexGrow(1f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setHeight(50f); root.addChildAt(root_child1, 1); root.setDirection(YogaDirection.LTR); @@ -962,21 +972,21 @@ public class YGMinMaxDimensionTest { public void test_flex_grow_within_constrained_max_row() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setWidth(200f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setFlexDirection(YogaFlexDirection.ROW); root_child0.setMaxWidth(100f); root_child0.setHeight(100f); root.addChildAt(root_child0, 0); - final YogaNode root_child0_child0 = new YogaNode(config); + final YogaNode root_child0_child0 = createNode(config); root_child0_child0.setFlexShrink(1f); root_child0_child0.setFlexBasis(100f); root_child0.addChildAt(root_child0_child0, 0); - final YogaNode root_child0_child1 = new YogaNode(config); + final YogaNode root_child0_child1 = createNode(config); root_child0_child1.setWidth(50f); root_child0.addChildAt(root_child0_child1, 1); root.setDirection(YogaDirection.LTR); @@ -1030,16 +1040,16 @@ public class YGMinMaxDimensionTest { public void test_flex_grow_within_constrained_max_column() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setWidth(100f); root.setMaxHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setFlexShrink(1f); root_child0.setFlexBasis(100f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setHeight(50f); root.addChildAt(root_child1, 1); root.setDirection(YogaDirection.LTR); @@ -1083,18 +1093,18 @@ public class YGMinMaxDimensionTest { public void test_child_min_max_width_flexing() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.ROW); root.setWidth(120f); root.setHeight(50f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setFlexGrow(1f); root_child0.setFlexBasis(0f); root_child0.setMinWidth(60f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setFlexGrow(1f); root_child1.setFlexBasisPercent(50f); root_child1.setMaxWidth(20f); @@ -1140,7 +1150,7 @@ public class YGMinMaxDimensionTest { public void test_min_width_overrides_width() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setWidth(50f); root.setMinWidth(100f); root.setDirection(YogaDirection.LTR); @@ -1164,7 +1174,7 @@ public class YGMinMaxDimensionTest { public void test_max_width_overrides_width() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setWidth(200f); root.setMaxWidth(100f); root.setDirection(YogaDirection.LTR); @@ -1188,7 +1198,7 @@ public class YGMinMaxDimensionTest { public void test_min_height_overrides_height() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setHeight(50f); root.setMinHeight(100f); root.setDirection(YogaDirection.LTR); @@ -1212,7 +1222,7 @@ public class YGMinMaxDimensionTest { public void test_max_height_overrides_height() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setHeight(200f); root.setMaxHeight(100f); root.setDirection(YogaDirection.LTR); @@ -1236,12 +1246,12 @@ public class YGMinMaxDimensionTest { public void test_min_max_percent_no_width_height() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setAlignItems(YogaAlign.FLEX_START); root.setWidth(100f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setMinWidthPercent(10f); root_child0.setMaxWidthPercent(10f); root_child0.setMinHeightPercent(10f); @@ -1274,4 +1284,7 @@ public class YGMinMaxDimensionTest { assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); } + private YogaNode createNode(YogaConfig config) { + return mNodeFactory.create(config); + } } diff --git a/java/tests/com/facebook/yoga/YGPaddingTest.java b/java/tests/com/facebook/yoga/YGPaddingTest.java index b8d477c9..9407c35b 100644 --- a/java/tests/com/facebook/yoga/YGPaddingTest.java +++ b/java/tests/com/facebook/yoga/YGPaddingTest.java @@ -9,16 +9,26 @@ package com.facebook.yoga; -import org.junit.Test; - import static org.junit.Assert.assertEquals; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +@RunWith(Parameterized.class) public class YGPaddingTest { + @Parameterized.Parameters(name = "{0}") + public static Iterable nodeFactories() { + return TestParametrization.nodeFactories(); + } + + @Parameterized.Parameter public TestParametrization.NodeFactory mNodeFactory; + @Test public void test_padding_no_size() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setPadding(YogaEdge.LEFT, 10); root.setPadding(YogaEdge.TOP, 10); root.setPadding(YogaEdge.RIGHT, 10); @@ -44,13 +54,13 @@ public class YGPaddingTest { public void test_padding_container_match_child() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setPadding(YogaEdge.LEFT, 10); root.setPadding(YogaEdge.TOP, 10); root.setPadding(YogaEdge.RIGHT, 10); root.setPadding(YogaEdge.BOTTOM, 10); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setWidth(10f); root_child0.setHeight(10f); root.addChildAt(root_child0, 0); @@ -85,7 +95,7 @@ public class YGPaddingTest { public void test_padding_flex_child() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setPadding(YogaEdge.LEFT, 10); root.setPadding(YogaEdge.TOP, 10); root.setPadding(YogaEdge.RIGHT, 10); @@ -93,7 +103,7 @@ public class YGPaddingTest { root.setWidth(100f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setFlexGrow(1f); root_child0.setWidth(10f); root.addChildAt(root_child0, 0); @@ -128,7 +138,7 @@ public class YGPaddingTest { public void test_padding_stretch_child() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setPadding(YogaEdge.LEFT, 10); root.setPadding(YogaEdge.TOP, 10); root.setPadding(YogaEdge.RIGHT, 10); @@ -136,7 +146,7 @@ public class YGPaddingTest { root.setWidth(100f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setHeight(10f); root.addChildAt(root_child0, 0); root.setDirection(YogaDirection.LTR); @@ -170,7 +180,7 @@ public class YGPaddingTest { public void test_padding_center_child() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setJustifyContent(YogaJustify.CENTER); root.setAlignItems(YogaAlign.CENTER); root.setPadding(YogaEdge.START, 10); @@ -179,7 +189,7 @@ public class YGPaddingTest { root.setWidth(100f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setWidth(10f); root_child0.setHeight(10f); root.addChildAt(root_child0, 0); @@ -214,13 +224,13 @@ public class YGPaddingTest { public void test_child_with_padding_align_end() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setJustifyContent(YogaJustify.FLEX_END); root.setAlignItems(YogaAlign.FLEX_END); root.setWidth(200f); root.setHeight(200f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setPadding(YogaEdge.LEFT, 20); root_child0.setPadding(YogaEdge.TOP, 20); root_child0.setPadding(YogaEdge.RIGHT, 20); @@ -255,4 +265,7 @@ public class YGPaddingTest { assertEquals(100f, root_child0.getLayoutHeight(), 0.0f); } + private YogaNode createNode(YogaConfig config) { + return mNodeFactory.create(config); + } } diff --git a/java/tests/com/facebook/yoga/YGPercentageTest.java b/java/tests/com/facebook/yoga/YGPercentageTest.java index 8b06a21e..eabffa60 100644 --- a/java/tests/com/facebook/yoga/YGPercentageTest.java +++ b/java/tests/com/facebook/yoga/YGPercentageTest.java @@ -9,21 +9,31 @@ package com.facebook.yoga; -import org.junit.Test; - import static org.junit.Assert.assertEquals; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +@RunWith(Parameterized.class) public class YGPercentageTest { + @Parameterized.Parameters(name = "{0}") + public static Iterable nodeFactories() { + return TestParametrization.nodeFactories(); + } + + @Parameterized.Parameter public TestParametrization.NodeFactory mNodeFactory; + @Test public void test_percentage_width_height() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.ROW); root.setWidth(200f); root.setHeight(200f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setWidthPercent(30f); root_child0.setHeightPercent(30f); root.addChildAt(root_child0, 0); @@ -58,12 +68,12 @@ public class YGPercentageTest { public void test_percentage_position_left_top() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.ROW); root.setWidth(400f); root.setHeight(400f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setPositionPercent(YogaEdge.LEFT, 10f); root_child0.setPositionPercent(YogaEdge.TOP, 20f); root_child0.setWidthPercent(45f); @@ -100,12 +110,12 @@ public class YGPercentageTest { public void test_percentage_position_bottom_right() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.ROW); root.setWidth(500f); root.setHeight(500f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setPositionPercent(YogaEdge.RIGHT, 20f); root_child0.setPositionPercent(YogaEdge.BOTTOM, 10f); root_child0.setWidthPercent(55f); @@ -142,17 +152,17 @@ public class YGPercentageTest { public void test_percentage_flex_basis() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.ROW); root.setWidth(200f); root.setHeight(200f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setFlexGrow(1f); root_child0.setFlexBasisPercent(50f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setFlexGrow(1f); root_child1.setFlexBasisPercent(25f); root.addChildAt(root_child1, 1); @@ -197,16 +207,16 @@ public class YGPercentageTest { public void test_percentage_flex_basis_cross() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setWidth(200f); root.setHeight(200f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setFlexGrow(1f); root_child0.setFlexBasisPercent(50f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setFlexGrow(1f); root_child1.setFlexBasisPercent(25f); root.addChildAt(root_child1, 1); @@ -251,16 +261,16 @@ public class YGPercentageTest { public void test_percentage_flex_basis_cross_min_height() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setWidth(200f); root.setHeight(200f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setFlexGrow(1f); root_child0.setMinHeightPercent(60f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setFlexGrow(2f); root_child1.setMinHeightPercent(10f); root.addChildAt(root_child1, 1); @@ -305,18 +315,18 @@ public class YGPercentageTest { public void test_percentage_flex_basis_main_max_height() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.ROW); root.setWidth(200f); root.setHeight(200f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setFlexGrow(1f); root_child0.setFlexBasisPercent(10f); root_child0.setMaxHeightPercent(60f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setFlexGrow(4f); root_child1.setFlexBasisPercent(10f); root_child1.setMaxHeightPercent(20f); @@ -362,17 +372,17 @@ public class YGPercentageTest { public void test_percentage_flex_basis_cross_max_height() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setWidth(200f); root.setHeight(200f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setFlexGrow(1f); root_child0.setFlexBasisPercent(10f); root_child0.setMaxHeightPercent(60f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setFlexGrow(4f); root_child1.setFlexBasisPercent(10f); root_child1.setMaxHeightPercent(20f); @@ -418,18 +428,18 @@ public class YGPercentageTest { public void test_percentage_flex_basis_main_max_width() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.ROW); root.setWidth(200f); root.setHeight(200f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setFlexGrow(1f); root_child0.setFlexBasisPercent(15f); root_child0.setMaxWidthPercent(60f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setFlexGrow(4f); root_child1.setFlexBasisPercent(10f); root_child1.setMaxWidthPercent(20f); @@ -475,17 +485,17 @@ public class YGPercentageTest { public void test_percentage_flex_basis_cross_max_width() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setWidth(200f); root.setHeight(200f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setFlexGrow(1f); root_child0.setFlexBasisPercent(10f); root_child0.setMaxWidthPercent(60f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setFlexGrow(4f); root_child1.setFlexBasisPercent(15f); root_child1.setMaxWidthPercent(20f); @@ -531,18 +541,18 @@ public class YGPercentageTest { public void test_percentage_flex_basis_main_min_width() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.ROW); root.setWidth(200f); root.setHeight(200f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setFlexGrow(1f); root_child0.setFlexBasisPercent(15f); root_child0.setMinWidthPercent(60f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setFlexGrow(4f); root_child1.setFlexBasisPercent(10f); root_child1.setMinWidthPercent(20f); @@ -588,17 +598,17 @@ public class YGPercentageTest { public void test_percentage_flex_basis_cross_min_width() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setWidth(200f); root.setHeight(200f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setFlexGrow(1f); root_child0.setFlexBasisPercent(10f); root_child0.setMinWidthPercent(60f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setFlexGrow(4f); root_child1.setFlexBasisPercent(15f); root_child1.setMinWidthPercent(20f); @@ -644,11 +654,11 @@ public class YGPercentageTest { public void test_percentage_multiple_nested_with_padding_margin_and_percentage_values() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setWidth(200f); root.setHeight(200f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setFlexGrow(1f); root_child0.setFlexBasisPercent(10f); root_child0.setMargin(YogaEdge.LEFT, 5f); @@ -662,7 +672,7 @@ public class YGPercentageTest { root_child0.setMinWidthPercent(60f); root.addChildAt(root_child0, 0); - final YogaNode root_child0_child0 = new YogaNode(config); + final YogaNode root_child0_child0 = createNode(config); root_child0_child0.setMargin(YogaEdge.LEFT, 5f); root_child0_child0.setMargin(YogaEdge.TOP, 5f); root_child0_child0.setMargin(YogaEdge.RIGHT, 5f); @@ -674,7 +684,7 @@ public class YGPercentageTest { root_child0_child0.setWidthPercent(50f); root_child0.addChildAt(root_child0_child0, 0); - final YogaNode root_child0_child0_child0 = new YogaNode(config); + final YogaNode root_child0_child0_child0 = createNode(config); root_child0_child0_child0.setMarginPercent(YogaEdge.LEFT, 5f); root_child0_child0_child0.setMarginPercent(YogaEdge.TOP, 5f); root_child0_child0_child0.setMarginPercent(YogaEdge.RIGHT, 5f); @@ -686,7 +696,7 @@ public class YGPercentageTest { root_child0_child0_child0.setWidthPercent(45f); root_child0_child0.addChildAt(root_child0_child0_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setFlexGrow(4f); root_child1.setFlexBasisPercent(15f); root_child1.setMinWidthPercent(20f); @@ -752,11 +762,11 @@ public class YGPercentageTest { public void test_percentage_margin_should_calculate_based_only_on_width() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setWidth(200f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setFlexGrow(1f); root_child0.setMarginPercent(YogaEdge.LEFT, 10f); root_child0.setMarginPercent(YogaEdge.TOP, 10f); @@ -764,7 +774,7 @@ public class YGPercentageTest { root_child0.setMarginPercent(YogaEdge.BOTTOM, 10f); root.addChildAt(root_child0, 0); - final YogaNode root_child0_child0 = new YogaNode(config); + final YogaNode root_child0_child0 = createNode(config); root_child0_child0.setWidth(10f); root_child0_child0.setHeight(10f); root_child0.addChildAt(root_child0_child0, 0); @@ -809,11 +819,11 @@ public class YGPercentageTest { public void test_percentage_padding_should_calculate_based_only_on_width() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setWidth(200f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setFlexGrow(1f); root_child0.setPaddingPercent(YogaEdge.LEFT, 10); root_child0.setPaddingPercent(YogaEdge.TOP, 10); @@ -821,7 +831,7 @@ public class YGPercentageTest { root_child0.setPaddingPercent(YogaEdge.BOTTOM, 10); root.addChildAt(root_child0, 0); - final YogaNode root_child0_child0 = new YogaNode(config); + final YogaNode root_child0_child0 = createNode(config); root_child0_child0.setWidth(10f); root_child0_child0.setHeight(10f); root_child0.addChildAt(root_child0_child0, 0); @@ -866,11 +876,11 @@ public class YGPercentageTest { public void test_percentage_absolute_position() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setWidth(200f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setPositionType(YogaPositionType.ABSOLUTE); root_child0.setPositionPercent(YogaEdge.LEFT, 30f); root_child0.setPositionPercent(YogaEdge.TOP, 10f); @@ -908,9 +918,9 @@ public class YGPercentageTest { public void test_percentage_width_height_undefined_parent_size() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setWidthPercent(50f); root_child0.setHeightPercent(50f); root.addChildAt(root_child0, 0); @@ -945,24 +955,24 @@ public class YGPercentageTest { public void test_percent_within_flex_grow() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.ROW); root.setWidth(350f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setWidth(100f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setFlexGrow(1f); root.addChildAt(root_child1, 1); - final YogaNode root_child1_child0 = new YogaNode(config); + final YogaNode root_child1_child0 = createNode(config); root_child1_child0.setWidthPercent(100f); root_child1.addChildAt(root_child1_child0, 0); - final YogaNode root_child2 = new YogaNode(config); + final YogaNode root_child2 = createNode(config); root_child2.setWidth(100f); root.addChildAt(root_child2, 2); root.setDirection(YogaDirection.LTR); @@ -1026,27 +1036,27 @@ public class YGPercentageTest { public void test_percentage_container_in_wrapping_container() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setJustifyContent(YogaJustify.CENTER); root.setAlignItems(YogaAlign.CENTER); root.setWidth(200f); root.setHeight(200f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root.addChildAt(root_child0, 0); - final YogaNode root_child0_child0 = new YogaNode(config); + final YogaNode root_child0_child0 = createNode(config); root_child0_child0.setFlexDirection(YogaFlexDirection.ROW); root_child0_child0.setJustifyContent(YogaJustify.CENTER); root_child0_child0.setWidthPercent(100f); root_child0.addChildAt(root_child0_child0, 0); - final YogaNode root_child0_child0_child0 = new YogaNode(config); + final YogaNode root_child0_child0_child0 = createNode(config); root_child0_child0_child0.setWidth(50f); root_child0_child0_child0.setHeight(50f); root_child0_child0.addChildAt(root_child0_child0_child0, 0); - final YogaNode root_child0_child0_child1 = new YogaNode(config); + final YogaNode root_child0_child0_child1 = createNode(config); root_child0_child0_child1.setWidth(50f); root_child0_child0_child1.setHeight(50f); root_child0_child0.addChildAt(root_child0_child0_child1, 1); @@ -1111,11 +1121,11 @@ public class YGPercentageTest { public void test_percent_absolute_position() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setWidth(60f); root.setHeight(50f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setFlexDirection(YogaFlexDirection.ROW); root_child0.setPositionType(YogaPositionType.ABSOLUTE); root_child0.setPositionPercent(YogaEdge.LEFT, 50f); @@ -1123,11 +1133,11 @@ public class YGPercentageTest { root_child0.setHeight(50f); root.addChildAt(root_child0, 0); - final YogaNode root_child0_child0 = new YogaNode(config); + final YogaNode root_child0_child0 = createNode(config); root_child0_child0.setWidthPercent(100f); root_child0.addChildAt(root_child0_child0, 0); - final YogaNode root_child0_child1 = new YogaNode(config); + final YogaNode root_child0_child1 = createNode(config); root_child0_child1.setWidthPercent(100f); root_child0.addChildAt(root_child0_child1, 1); root.setDirection(YogaDirection.LTR); @@ -1177,4 +1187,7 @@ public class YGPercentageTest { assertEquals(50f, root_child0_child1.getLayoutHeight(), 0.0f); } + private YogaNode createNode(YogaConfig config) { + return mNodeFactory.create(config); + } } diff --git a/java/tests/com/facebook/yoga/YGRoundingTest.java b/java/tests/com/facebook/yoga/YGRoundingTest.java index 31489988..a9384f20 100644 --- a/java/tests/com/facebook/yoga/YGRoundingTest.java +++ b/java/tests/com/facebook/yoga/YGRoundingTest.java @@ -9,29 +9,39 @@ package com.facebook.yoga; -import org.junit.Test; - import static org.junit.Assert.assertEquals; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +@RunWith(Parameterized.class) public class YGRoundingTest { + @Parameterized.Parameters(name = "{0}") + public static Iterable nodeFactories() { + return TestParametrization.nodeFactories(); + } + + @Parameterized.Parameter public TestParametrization.NodeFactory mNodeFactory; + @Test public void test_rounding_flex_basis_flex_grow_row_width_of_100() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.ROW); root.setWidth(100f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setFlexGrow(1f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setFlexGrow(1f); root.addChildAt(root_child1, 1); - final YogaNode root_child2 = new YogaNode(config); + final YogaNode root_child2 = createNode(config); root_child2.setFlexGrow(1f); root.addChildAt(root_child2, 2); root.setDirection(YogaDirection.LTR); @@ -85,28 +95,28 @@ public class YGRoundingTest { public void test_rounding_flex_basis_flex_grow_row_prime_number_width() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.ROW); root.setWidth(113f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setFlexGrow(1f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setFlexGrow(1f); root.addChildAt(root_child1, 1); - final YogaNode root_child2 = new YogaNode(config); + final YogaNode root_child2 = createNode(config); root_child2.setFlexGrow(1f); root.addChildAt(root_child2, 2); - final YogaNode root_child3 = new YogaNode(config); + final YogaNode root_child3 = createNode(config); root_child3.setFlexGrow(1f); root.addChildAt(root_child3, 3); - final YogaNode root_child4 = new YogaNode(config); + final YogaNode root_child4 = createNode(config); root_child4.setFlexGrow(1f); root.addChildAt(root_child4, 4); root.setDirection(YogaDirection.LTR); @@ -180,21 +190,21 @@ public class YGRoundingTest { public void test_rounding_flex_basis_flex_shrink_row() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.ROW); root.setWidth(101f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setFlexShrink(1f); root_child0.setFlexBasis(100f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setFlexBasis(25f); root.addChildAt(root_child1, 1); - final YogaNode root_child2 = new YogaNode(config); + final YogaNode root_child2 = createNode(config); root_child2.setFlexBasis(25f); root.addChildAt(root_child2, 2); root.setDirection(YogaDirection.LTR); @@ -248,22 +258,22 @@ public class YGRoundingTest { public void test_rounding_flex_basis_overrides_main_size() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setWidth(100f); root.setHeight(113f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setFlexGrow(1f); root_child0.setFlexBasis(50f); root_child0.setHeight(20f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setFlexGrow(1f); root_child1.setHeight(10f); root.addChildAt(root_child1, 1); - final YogaNode root_child2 = new YogaNode(config); + final YogaNode root_child2 = createNode(config); root_child2.setFlexGrow(1f); root_child2.setHeight(10f); root.addChildAt(root_child2, 2); @@ -318,22 +328,22 @@ public class YGRoundingTest { public void test_rounding_total_fractial() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setWidth(87.4f); root.setHeight(113.4f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setFlexGrow(0.7f); root_child0.setFlexBasis(50.3f); root_child0.setHeight(20.3f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setFlexGrow(1.6f); root_child1.setHeight(10f); root.addChildAt(root_child1, 1); - final YogaNode root_child2 = new YogaNode(config); + final YogaNode root_child2 = createNode(config); root_child2.setFlexGrow(1.1f); root_child2.setHeight(10.7f); root.addChildAt(root_child2, 2); @@ -388,36 +398,36 @@ public class YGRoundingTest { public void test_rounding_total_fractial_nested() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setWidth(87.4f); root.setHeight(113.4f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setFlexGrow(0.7f); root_child0.setFlexBasis(50.3f); root_child0.setHeight(20.3f); root.addChildAt(root_child0, 0); - final YogaNode root_child0_child0 = new YogaNode(config); + final YogaNode root_child0_child0 = createNode(config); root_child0_child0.setFlexGrow(1f); root_child0_child0.setFlexBasis(0.3f); root_child0_child0.setPosition(YogaEdge.BOTTOM, 13.3f); root_child0_child0.setHeight(9.9f); root_child0.addChildAt(root_child0_child0, 0); - final YogaNode root_child0_child1 = new YogaNode(config); + final YogaNode root_child0_child1 = createNode(config); root_child0_child1.setFlexGrow(4f); root_child0_child1.setFlexBasis(0.3f); root_child0_child1.setPosition(YogaEdge.TOP, 13.3f); root_child0_child1.setHeight(1.1f); root_child0.addChildAt(root_child0_child1, 1); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setFlexGrow(1.6f); root_child1.setHeight(10f); root.addChildAt(root_child1, 1); - final YogaNode root_child2 = new YogaNode(config); + final YogaNode root_child2 = createNode(config); root_child2.setFlexGrow(1.1f); root_child2.setHeight(10.7f); root.addChildAt(root_child2, 2); @@ -492,22 +502,22 @@ public class YGRoundingTest { public void test_rounding_fractial_input_1() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setWidth(100f); root.setHeight(113.4f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setFlexGrow(1f); root_child0.setFlexBasis(50f); root_child0.setHeight(20f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setFlexGrow(1f); root_child1.setHeight(10f); root.addChildAt(root_child1, 1); - final YogaNode root_child2 = new YogaNode(config); + final YogaNode root_child2 = createNode(config); root_child2.setFlexGrow(1f); root_child2.setHeight(10f); root.addChildAt(root_child2, 2); @@ -562,22 +572,22 @@ public class YGRoundingTest { public void test_rounding_fractial_input_2() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setWidth(100f); root.setHeight(113.6f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setFlexGrow(1f); root_child0.setFlexBasis(50f); root_child0.setHeight(20f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setFlexGrow(1f); root_child1.setHeight(10f); root.addChildAt(root_child1, 1); - final YogaNode root_child2 = new YogaNode(config); + final YogaNode root_child2 = createNode(config); root_child2.setFlexGrow(1f); root_child2.setHeight(10f); root.addChildAt(root_child2, 2); @@ -632,23 +642,23 @@ public class YGRoundingTest { public void test_rounding_fractial_input_3() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setPosition(YogaEdge.TOP, 0.3f); root.setWidth(100f); root.setHeight(113.4f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setFlexGrow(1f); root_child0.setFlexBasis(50f); root_child0.setHeight(20f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setFlexGrow(1f); root_child1.setHeight(10f); root.addChildAt(root_child1, 1); - final YogaNode root_child2 = new YogaNode(config); + final YogaNode root_child2 = createNode(config); root_child2.setFlexGrow(1f); root_child2.setHeight(10f); root.addChildAt(root_child2, 2); @@ -703,23 +713,23 @@ public class YGRoundingTest { public void test_rounding_fractial_input_4() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setPosition(YogaEdge.TOP, 0.7f); root.setWidth(100f); root.setHeight(113.4f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setFlexGrow(1f); root_child0.setFlexBasis(50f); root_child0.setHeight(20f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setFlexGrow(1f); root_child1.setHeight(10f); root.addChildAt(root_child1, 1); - final YogaNode root_child2 = new YogaNode(config); + final YogaNode root_child2 = createNode(config); root_child2.setFlexGrow(1f); root_child2.setHeight(10f); root.addChildAt(root_child2, 2); @@ -774,26 +784,26 @@ public class YGRoundingTest { public void test_rounding_inner_node_controversy_horizontal() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.ROW); root.setWidth(320f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setFlexGrow(1f); root_child0.setHeight(10f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setFlexGrow(1f); root_child1.setHeight(10f); root.addChildAt(root_child1, 1); - final YogaNode root_child1_child0 = new YogaNode(config); + final YogaNode root_child1_child0 = createNode(config); root_child1_child0.setFlexGrow(1f); root_child1_child0.setHeight(10f); root_child1.addChildAt(root_child1_child0, 0); - final YogaNode root_child2 = new YogaNode(config); + final YogaNode root_child2 = createNode(config); root_child2.setFlexGrow(1f); root_child2.setHeight(10f); root.addChildAt(root_child2, 2); @@ -858,25 +868,25 @@ public class YGRoundingTest { public void test_rounding_inner_node_controversy_vertical() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setHeight(320f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setFlexGrow(1f); root_child0.setWidth(10f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setFlexGrow(1f); root_child1.setWidth(10f); root.addChildAt(root_child1, 1); - final YogaNode root_child1_child0 = new YogaNode(config); + final YogaNode root_child1_child0 = createNode(config); root_child1_child0.setFlexGrow(1f); root_child1_child0.setWidth(10f); root_child1.addChildAt(root_child1_child0, 0); - final YogaNode root_child2 = new YogaNode(config); + final YogaNode root_child2 = createNode(config); root_child2.setFlexGrow(1f); root_child2.setWidth(10f); root.addChildAt(root_child2, 2); @@ -941,42 +951,42 @@ public class YGRoundingTest { public void test_rounding_inner_node_controversy_combined() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setFlexDirection(YogaFlexDirection.ROW); root.setWidth(640f); root.setHeight(320f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setFlexGrow(1f); root_child0.setHeightPercent(100f); root.addChildAt(root_child0, 0); - final YogaNode root_child1 = new YogaNode(config); + final YogaNode root_child1 = createNode(config); root_child1.setFlexGrow(1f); root_child1.setHeightPercent(100f); root.addChildAt(root_child1, 1); - final YogaNode root_child1_child0 = new YogaNode(config); + final YogaNode root_child1_child0 = createNode(config); root_child1_child0.setFlexGrow(1f); root_child1_child0.setWidthPercent(100f); root_child1.addChildAt(root_child1_child0, 0); - final YogaNode root_child1_child1 = new YogaNode(config); + final YogaNode root_child1_child1 = createNode(config); root_child1_child1.setFlexGrow(1f); root_child1_child1.setWidthPercent(100f); root_child1.addChildAt(root_child1_child1, 1); - final YogaNode root_child1_child1_child0 = new YogaNode(config); + final YogaNode root_child1_child1_child0 = createNode(config); root_child1_child1_child0.setFlexGrow(1f); root_child1_child1_child0.setWidthPercent(100f); root_child1_child1.addChildAt(root_child1_child1_child0, 0); - final YogaNode root_child1_child2 = new YogaNode(config); + final YogaNode root_child1_child2 = createNode(config); root_child1_child2.setFlexGrow(1f); root_child1_child2.setWidthPercent(100f); root_child1.addChildAt(root_child1_child2, 2); - final YogaNode root_child2 = new YogaNode(config); + final YogaNode root_child2 = createNode(config); root_child2.setFlexGrow(1f); root_child2.setHeightPercent(100f); root.addChildAt(root_child2, 2); @@ -1067,4 +1077,7 @@ public class YGRoundingTest { assertEquals(320f, root_child2.getLayoutHeight(), 0.0f); } + private YogaNode createNode(YogaConfig config) { + return mNodeFactory.create(config); + } } diff --git a/java/tests/com/facebook/yoga/YGSizeOverflowTest.java b/java/tests/com/facebook/yoga/YGSizeOverflowTest.java index e4aa71cd..e24e0677 100644 --- a/java/tests/com/facebook/yoga/YGSizeOverflowTest.java +++ b/java/tests/com/facebook/yoga/YGSizeOverflowTest.java @@ -9,23 +9,33 @@ package com.facebook.yoga; -import org.junit.Test; - import static org.junit.Assert.assertEquals; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +@RunWith(Parameterized.class) public class YGSizeOverflowTest { + @Parameterized.Parameters(name = "{0}") + public static Iterable nodeFactories() { + return TestParametrization.nodeFactories(); + } + + @Parameterized.Parameter public TestParametrization.NodeFactory mNodeFactory; + @Test public void test_nested_overflowing_child() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setWidth(100f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root.addChildAt(root_child0, 0); - final YogaNode root_child0_child0 = new YogaNode(config); + final YogaNode root_child0_child0 = createNode(config); root_child0_child0.setWidth(200f); root_child0_child0.setHeight(200f); root_child0.addChildAt(root_child0_child0, 0); @@ -70,16 +80,16 @@ public class YGSizeOverflowTest { public void test_nested_overflowing_child_in_constraint_parent() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setWidth(100f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setWidth(100f); root_child0.setHeight(100f); root.addChildAt(root_child0, 0); - final YogaNode root_child0_child0 = new YogaNode(config); + final YogaNode root_child0_child0 = createNode(config); root_child0_child0.setWidth(200f); root_child0_child0.setHeight(200f); root_child0.addChildAt(root_child0_child0, 0); @@ -124,15 +134,15 @@ public class YGSizeOverflowTest { public void test_parent_wrap_child_size_overflowing_parent() { YogaConfig config = new YogaConfig(); - final YogaNode root = new YogaNode(config); + final YogaNode root = createNode(config); root.setWidth(100f); root.setHeight(100f); - final YogaNode root_child0 = new YogaNode(config); + final YogaNode root_child0 = createNode(config); root_child0.setWidth(100f); root.addChildAt(root_child0, 0); - final YogaNode root_child0_child0 = new YogaNode(config); + final YogaNode root_child0_child0 = createNode(config); root_child0_child0.setWidth(100f); root_child0_child0.setHeight(200f); root_child0.addChildAt(root_child0_child0, 0); @@ -173,4 +183,7 @@ public class YGSizeOverflowTest { assertEquals(200f, root_child0_child0.getLayoutHeight(), 0.0f); } + private YogaNode createNode(YogaConfig config) { + return mNodeFactory.create(config); + } } diff --git a/java/tests/com/facebook/yoga/YogaNodeStylePropertiesTest.java b/java/tests/com/facebook/yoga/YogaNodeStylePropertiesTest.java index 8efcdd13..6ba58ed4 100644 --- a/java/tests/com/facebook/yoga/YogaNodeStylePropertiesTest.java +++ b/java/tests/com/facebook/yoga/YogaNodeStylePropertiesTest.java @@ -10,14 +10,24 @@ package com.facebook.yoga; import static org.junit.Assert.assertEquals; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +@RunWith(Parameterized.class) public class YogaNodeStylePropertiesTest { + @Parameterized.Parameters(name = "{0}") + public static Iterable nodeFactories() { + return TestParametrization.nodeFactories(); + } + + @Parameterized.Parameter public TestParametrization.NodeFactory mNodeFactory; + private static final float UNDEFINED = YogaValue.UNDEFINED.value; @Test public void testDirectionDefault() { - final YogaNode node = new YogaNode(); + final YogaNode node = createNode(); assertEquals(node.getStyleDirection(), YogaDirection.INHERIT); assertEquals(node.getLayoutDirection(), YogaDirection.INHERIT); @@ -25,7 +35,7 @@ public class YogaNodeStylePropertiesTest { @Test public void testDirectionAssignment() { - final YogaNode node = new YogaNode(); + final YogaNode node = createNode(); node.setDirection(YogaDirection.LTR); node.calculateLayout(UNDEFINED, UNDEFINED); @@ -44,7 +54,7 @@ public class YogaNodeStylePropertiesTest { @Test public void testFlexDirectionDefault() { - final YogaNode node = new YogaNode(); + final YogaNode node = createNode(); assertEquals(YogaFlexDirection.COLUMN, node.getFlexDirection()); } @@ -71,14 +81,14 @@ public class YogaNodeStylePropertiesTest { @Test public void testJustifyContentDefault() { - final YogaNode node = new YogaNode(); + final YogaNode node = createNode(); assertEquals(YogaJustify.FLEX_START, node.getJustifyContent()); } @Test public void testJustifyContentAssignment() { - final YogaNode node = new YogaNode(); + final YogaNode node = createNode(); node.setJustifyContent(YogaJustify.SPACE_EVENLY); assertEquals(YogaJustify.SPACE_EVENLY, node.getJustifyContent()); @@ -99,14 +109,14 @@ public class YogaNodeStylePropertiesTest { @Test public void testAlignItemsDefault() { - final YogaNode node = new YogaNode(); + final YogaNode node = createNode(); assertEquals(YogaAlign.STRETCH, node.getAlignItems()); } @Test public void testAlignItemsAssignment() { - final YogaNode node = new YogaNode(); + final YogaNode node = createNode(); node.setAlignItems(YogaAlign.SPACE_AROUND); assertEquals(YogaAlign.SPACE_AROUND, node.getAlignItems()); @@ -123,14 +133,14 @@ public class YogaNodeStylePropertiesTest { @Test public void testAlignSelfDefault() { - final YogaNode node = new YogaNode(); + final YogaNode node = createNode(); assertEquals(YogaAlign.AUTO, node.getAlignSelf()); } @Test public void testAlignSelfAssignment() { - final YogaNode node = new YogaNode(); + final YogaNode node = createNode(); node.setAlignSelf(YogaAlign.FLEX_END); assertEquals(YogaAlign.FLEX_END, node.getAlignSelf()); @@ -147,14 +157,14 @@ public class YogaNodeStylePropertiesTest { @Test public void testAlignContentDefault() { - final YogaNode node = new YogaNode(); + final YogaNode node = createNode(); assertEquals(YogaAlign.FLEX_START, node.getAlignContent()); } @Test public void testAlignContentAssignment() { - final YogaNode node = new YogaNode(); + final YogaNode node = createNode(); node.setAlignContent(YogaAlign.BASELINE); assertEquals(YogaAlign.BASELINE, node.getAlignContent()); @@ -179,14 +189,14 @@ public class YogaNodeStylePropertiesTest { @Test public void testPositionTypeDefault() { - final YogaNode node = new YogaNode(); + final YogaNode node = createNode(); assertEquals(YogaPositionType.RELATIVE, node.getPositionType()); } @Test public void testPositionTypeAssignment() { - final YogaNode node = new YogaNode(); + final YogaNode node = createNode(); node.setPositionType(YogaPositionType.ABSOLUTE); assertEquals(YogaPositionType.ABSOLUTE, node.getPositionType()); @@ -221,14 +231,14 @@ public class YogaNodeStylePropertiesTest { @Test public void testOverflowDefault() { - final YogaNode node = new YogaNode(); + final YogaNode node = createNode(); assertEquals(YogaOverflow.VISIBLE, node.getOverflow()); } @Test public void testOverflowAssignment() { - final YogaNode node = new YogaNode(); + final YogaNode node = createNode(); node.setOverflow(YogaOverflow.SCROLL); assertEquals(YogaOverflow.SCROLL, node.getOverflow()); @@ -238,14 +248,14 @@ public class YogaNodeStylePropertiesTest { @Test public void testDisplayDefault() { - final YogaNode node = new YogaNode(); + final YogaNode node = createNode(); assertEquals(YogaDisplay.FLEX, node.getDisplay()); } @Test public void testDisplayAssignment() { - final YogaNode node = new YogaNode(); + final YogaNode node = createNode(); node.setDisplay(YogaDisplay.NONE); assertEquals(YogaDisplay.NONE, node.getDisplay()); @@ -278,14 +288,14 @@ public class YogaNodeStylePropertiesTest { @Test public void testFlexGrowDefault() { - final YogaNode node = new YogaNode(); + final YogaNode node = createNode(); assertEquals(0, node.getFlexGrow(), 0); } @Test public void testFlexGrowAssignment() { - final YogaNode node = new YogaNode(); + final YogaNode node = createNode(); node.setFlexGrow(2.5f); assertEquals(2.5f, node.getFlexGrow(), 0); @@ -302,14 +312,14 @@ public class YogaNodeStylePropertiesTest { @Test public void testFlexShrinkDefault() { - final YogaNode node = new YogaNode(); + final YogaNode node = createNode(); assertEquals(0, node.getFlexShrink(), 0); } @Test public void testFlexShrinkAssignment() { - final YogaNode node = new YogaNode(); + final YogaNode node = createNode(); node.setFlexShrink(2.5f); assertEquals(2.5f, node.getFlexShrink(), 0); @@ -326,14 +336,14 @@ public class YogaNodeStylePropertiesTest { @Test public void testFlexBasisDefault() { - final YogaNode node = new YogaNode(); + final YogaNode node = createNode(); assertEquals(YogaValue.AUTO, node.getFlexBasis()); } @Test public void testFlexBasisAssignment() { - final YogaNode node = new YogaNode(); + final YogaNode node = createNode(); node.setFlexBasis(50); assertEquals(new YogaValue(50, YogaUnit.POINT), node.getFlexBasis()); @@ -370,7 +380,7 @@ public class YogaNodeStylePropertiesTest { @Test public void testMarginDefault() { - final YogaNode node = new YogaNode(); + final YogaNode node = createNode(); for (YogaEdge edge : YogaEdge.values()) { assertEquals(YogaValue.UNDEFINED, node.getMargin(edge)); } @@ -378,7 +388,7 @@ public class YogaNodeStylePropertiesTest { @Test public void testMarginAssignment() { - final YogaNode node = new YogaNode(); + final YogaNode node = createNode(); for (YogaEdge edge : YogaEdge.values()) { node.setMargin(edge, 25); assertEquals(new YogaValue(25, YogaUnit.POINT), node.getMargin(edge)); @@ -423,7 +433,7 @@ public class YogaNodeStylePropertiesTest { @Test public void testPaddingDefault() { - final YogaNode node = new YogaNode(); + final YogaNode node = createNode(); for (YogaEdge edge : YogaEdge.values()) { assertEquals(YogaValue.UNDEFINED, node.getPadding(edge)); } @@ -431,7 +441,7 @@ public class YogaNodeStylePropertiesTest { @Test public void testPaddingAssignment() { - final YogaNode node = new YogaNode(); + final YogaNode node = createNode(); for (YogaEdge edge : YogaEdge.values()) { node.setPadding(edge, 25); assertEquals(new YogaValue(25, YogaUnit.POINT), node.getPadding(edge)); @@ -460,7 +470,7 @@ public class YogaNodeStylePropertiesTest { @Test public void testBorderDefault() { - final YogaNode node = new YogaNode(); + final YogaNode node = createNode(); for (YogaEdge edge : YogaEdge.values()) { assertEquals(UNDEFINED, node.getBorder(edge), 0); } @@ -468,7 +478,7 @@ public class YogaNodeStylePropertiesTest { @Test public void testBorderAssignment() { - final YogaNode node = new YogaNode(); + final YogaNode node = createNode(); for (YogaEdge edge : YogaEdge.values()) { node.setBorder(edge, 2.5f); assertEquals(2.5f, node.getBorder(edge), 0); @@ -485,7 +495,7 @@ public class YogaNodeStylePropertiesTest { @Test public void testPositionDefault() { - final YogaNode node = new YogaNode(); + final YogaNode node = createNode(); for (YogaEdge edge : YogaEdge.values()) { assertEquals(YogaValue.UNDEFINED, node.getPosition(edge)); } @@ -493,7 +503,7 @@ public class YogaNodeStylePropertiesTest { @Test public void testPositionAssignment() { - final YogaNode node = new YogaNode(); + final YogaNode node = createNode(); for (YogaEdge edge : YogaEdge.values()) { node.setPosition(edge, 25); assertEquals(new YogaValue(25, YogaUnit.POINT), node.getPosition(edge)); @@ -537,14 +547,14 @@ public class YogaNodeStylePropertiesTest { @Test public void testWidthDefault() { - final YogaNode node = new YogaNode(); + final YogaNode node = createNode(); assertEquals(YogaValue.AUTO, node.getWidth()); } @Test public void testWidthAssignment() { - final YogaNode node = new YogaNode(); + final YogaNode node = createNode(); node.setWidth(123); assertEquals(new YogaValue(123, YogaUnit.POINT), node.getWidth()); @@ -572,14 +582,14 @@ public class YogaNodeStylePropertiesTest { @Test public void testHeightDefault() { - final YogaNode node = new YogaNode(); + final YogaNode node = createNode(); assertEquals(YogaValue.AUTO, node.getHeight()); } @Test public void testHeightAssignment() { - final YogaNode node = new YogaNode(); + final YogaNode node = createNode(); node.setHeight(123); assertEquals(new YogaValue(123, YogaUnit.POINT), node.getHeight()); @@ -607,14 +617,14 @@ public class YogaNodeStylePropertiesTest { @Test public void testMinWidthDefault() { - final YogaNode node = new YogaNode(); + final YogaNode node = createNode(); assertEquals(YogaValue.UNDEFINED, node.getMinWidth()); } @Test public void testMinWidthAssignment() { - final YogaNode node = new YogaNode(); + final YogaNode node = createNode(); node.setMinWidth(123); assertEquals(new YogaValue(123, YogaUnit.POINT), node.getMinWidth()); @@ -640,14 +650,14 @@ public class YogaNodeStylePropertiesTest { @Test public void testMinHeightDefault() { - final YogaNode node = new YogaNode(); + final YogaNode node = createNode(); assertEquals(YogaValue.UNDEFINED, node.getMinHeight()); } @Test public void testMinHeightAssignment() { - final YogaNode node = new YogaNode(); + final YogaNode node = createNode(); node.setMinHeight(123); assertEquals(new YogaValue(123, YogaUnit.POINT), node.getMinHeight()); @@ -673,14 +683,14 @@ public class YogaNodeStylePropertiesTest { @Test public void testMaxWidthDefault() { - final YogaNode node = new YogaNode(); + final YogaNode node = createNode(); assertEquals(YogaValue.UNDEFINED, node.getMaxWidth()); } @Test public void testMaxWidthAssignment() { - final YogaNode node = new YogaNode(); + final YogaNode node = createNode(); node.setMaxWidth(123); assertEquals(new YogaValue(123, YogaUnit.POINT), node.getMaxWidth()); @@ -706,14 +716,14 @@ public class YogaNodeStylePropertiesTest { @Test public void testMaxHeightDefault() { - final YogaNode node = new YogaNode(); + final YogaNode node = createNode(); assertEquals(YogaValue.UNDEFINED, node.getMaxHeight()); } @Test public void testMaxHeightAssignment() { - final YogaNode node = new YogaNode(); + final YogaNode node = createNode(); node.setMaxHeight(123); assertEquals(new YogaValue(123, YogaUnit.POINT), node.getMaxHeight()); @@ -749,14 +759,14 @@ public class YogaNodeStylePropertiesTest { @Test public void testAspectRatioDefault() { - final YogaNode node = new YogaNode(); + final YogaNode node = createNode(); assertEquals(UNDEFINED, node.getAspectRatio(), 0); } @Test public void testAspectRatioAssignment() { - final YogaNode node = new YogaNode(); + final YogaNode node = createNode(); node.setAspectRatio(2.75f); assertEquals(2.75f, node.getAspectRatio(), 0); @@ -778,13 +788,21 @@ public class YogaNodeStylePropertiesTest { assertEquals(450, node.getChildAt(0).getLayoutWidth(), 0); } - private static StyledNode style() { - return new StyledNode(); + private YogaNode createNode() { + return mNodeFactory.create(); + } + + private StyledNode style() { + return new StyledNode(mNodeFactory); } private static class StyledNode { - private YogaNode mNode = new YogaNode(); + private YogaNode mNode; + + public StyledNode(TestParametrization.NodeFactory nodeFactory) { + mNode = nodeFactory.create(); + } YogaNode node() { return mNode; diff --git a/java/tests/com/facebook/yoga/YogaNodeTest.java b/java/tests/com/facebook/yoga/YogaNodeTest.java index 9cc26eb9..e72930e4 100644 --- a/java/tests/com/facebook/yoga/YogaNodeTest.java +++ b/java/tests/com/facebook/yoga/YogaNodeTest.java @@ -1,10 +1,10 @@ -/** - * Copyright (c) 2014-present, Facebook, Inc. +/* + * Copyright (c) 2014-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the LICENSE + * file in the root directory of this source tree. * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. */ - package com.facebook.yoga; import static org.junit.Assert.assertEquals; @@ -17,30 +17,39 @@ import static org.junit.Assert.fail; import java.lang.ref.WeakReference; import java.util.concurrent.atomic.AtomicBoolean; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +@RunWith(Parameterized.class) public class YogaNodeTest { + @Parameterized.Parameters(name = "{0}") + public static Iterable nodeFactories() { + return TestParametrization.nodeFactories(); + } + + @Parameterized.Parameter public TestParametrization.NodeFactory mNodeFactory; @Test public void testInit() { final int refCount = YogaNode.jni_YGNodeGetInstanceCount(); - final YogaNode node = new YogaNode(); + final YogaNode node = createNode(); assertEquals(refCount + 1, YogaNode.jni_YGNodeGetInstanceCount()); } @Test public void testBaseline() { - final YogaNode root = new YogaNode(); + final YogaNode root = createNode(); root.setFlexDirection(YogaFlexDirection.ROW); root.setAlignItems(YogaAlign.BASELINE); root.setWidth(100); root.setHeight(100); - final YogaNode child1 = new YogaNode(); + final YogaNode child1 = createNode(); child1.setWidth(40); child1.setHeight(40); root.addChildAt(child1, 0); - final YogaNode child2 = new YogaNode(); + final YogaNode child2 = createNode(); child2.setWidth(40); child2.setHeight(40); child2.setBaselineFunction(new YogaBaselineFunction() { @@ -58,7 +67,7 @@ public class YogaNodeTest { @Test public void testMeasure() { - final YogaNode node = new YogaNode(); + final YogaNode node = createNode(); node.setMeasureFunction(new YogaMeasureFunction() { public long measure( YogaNode node, @@ -76,7 +85,7 @@ public class YogaNodeTest { @Test public void testMeasureFloat() { - final YogaNode node = new YogaNode(); + final YogaNode node = createNode(); node.setMeasureFunction(new YogaMeasureFunction() { public long measure( YogaNode node, @@ -94,7 +103,7 @@ public class YogaNodeTest { @Test public void testMeasureFloatMin() { - final YogaNode node = new YogaNode(); + final YogaNode node = createNode(); node.setMeasureFunction(new YogaMeasureFunction() { public long measure( YogaNode node, @@ -112,7 +121,7 @@ public class YogaNodeTest { @Test public void testMeasureFloatBigNumber() { - final YogaNode node = new YogaNode(); + final YogaNode node = createNode(); final float bigNumber = (float) 10E5; node.setMeasureFunction( new YogaMeasureFunction() { @@ -132,10 +141,10 @@ public class YogaNodeTest { @Test public void testCopyStyle() { - final YogaNode node0 = new YogaNode(); + final YogaNode node0 = createNode(); assertTrue(YogaConstants.isUndefined(node0.getMaxHeight())); - final YogaNode node1 = new YogaNode(); + final YogaNode node1 = createNode(); node1.setMaxHeight(100); node0.copyStyle(node1); @@ -144,7 +153,7 @@ public class YogaNodeTest { @Test public void testLayoutMargin() { - final YogaNode node = new YogaNode(); + final YogaNode node = createNode(); node.setWidth(100); node.setHeight(100); node.setMargin(YogaEdge.START, 1); @@ -161,7 +170,7 @@ public class YogaNodeTest { @Test public void testLayoutPadding() { - final YogaNode node = new YogaNode(); + final YogaNode node = createNode(); node.setWidth(100); node.setHeight(100); node.setPadding(YogaEdge.START, 1); @@ -178,7 +187,7 @@ public class YogaNodeTest { @Test public void testLayoutBorder() { - final YogaNode node = new YogaNode(); + final YogaNode node = createNode(); node.setWidth(100); node.setHeight(100); node.setBorder(YogaEdge.START, 1); @@ -197,13 +206,13 @@ public class YogaNodeTest { public void testUseWebDefaults() { final YogaConfig config = new YogaConfig(); config.setUseWebDefaults(true); - final YogaNode node = new YogaNode(config); + final YogaNode node = createNode(config); assertEquals(YogaFlexDirection.ROW, node.getFlexDirection()); } @Test public void testPercentPaddingOnRoot() { - final YogaNode node = new YogaNode(); + final YogaNode node = createNode(); node.setPaddingPercent(YogaEdge.ALL, 10); node.calculateLayout(50, 50); @@ -215,7 +224,7 @@ public class YogaNodeTest { @Test public void testDefaultEdgeValues() { - final YogaNode node = new YogaNode(); + final YogaNode node = createNode(); for (YogaEdge edge : YogaEdge.values()) { assertEquals(YogaUnit.UNDEFINED, node.getMargin(edge).unit); @@ -228,9 +237,9 @@ public class YogaNodeTest { @Test public void testCloneNode() throws Exception { YogaConfig config = new YogaConfig(); - YogaNode root = new YogaNode(config); - YogaNode child = new YogaNode(config); - YogaNode grandChild = new YogaNode(config); + YogaNode root = createNode(config); + YogaNode child = createNode(config); + YogaNode grandChild = createNode(config); root.addChildAt(child, 0); child.addChildAt(grandChild, 0); child.setFlexDirection(YogaFlexDirection.ROW); @@ -255,9 +264,9 @@ public class YogaNodeTest { @Test public void testCloneWithNewChildren() throws Exception { YogaConfig config = new YogaConfig(); - YogaNode root = new YogaNode(config); - YogaNode child = new YogaNode(config); - YogaNode grandChild = new YogaNode(config); + YogaNode root = createNode(config); + YogaNode child = createNode(config); + YogaNode grandChild = createNode(config); root.addChildAt(child, 0); child.addChildAt(grandChild, 0); child.setFlexDirection(YogaFlexDirection.ROW); @@ -274,9 +283,9 @@ public class YogaNodeTest { @Test public void testAddSharedChildCloneWithNewChildren() throws Exception { YogaConfig config = new YogaConfig(); - YogaNode root = new YogaNode(config); - YogaNode child = new YogaNode(config); - YogaNode grandChild = new YogaNode(config); + YogaNode root = createNode(config); + YogaNode child = createNode(config); + YogaNode grandChild = createNode(config); root.addChildAt(child, 0); child.addChildAt(grandChild, 0); child.setFlexDirection(YogaFlexDirection.ROW); @@ -306,10 +315,10 @@ public class YogaNodeTest { return oldNode.clone(); } }); - YogaNode root = new YogaNode(config); + YogaNode root = createNode(config); root.setWidth(100f); root.setHeight(100f); - YogaNode child0 = new YogaNode(config); + YogaNode child0 = createNode(config); root.addChildAt(child0, 0); child0.setWidth(50f); root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); @@ -359,21 +368,29 @@ public class YogaNodeTest { YogaConfig config = new YogaConfig(); config.setShouldDiffLayoutWithoutLegacyStretchBehaviour(true); config.setUseLegacyStretchBehaviour(true); - YogaNode root = new YogaNode(config); + YogaNode root = createNode(config); root.setWidth(500); root.setHeight(500); - YogaNode root_child0 = new YogaNode(config); + YogaNode root_child0 = createNode(config); root_child0.setAlignItems(YogaAlign.FLEX_START); root.addChildAt(root_child0, 0); - YogaNode root_child0_child0 = new YogaNode(config); + YogaNode root_child0_child0 = createNode(config); root_child0_child0.setFlexGrow(1); root_child0_child0.setFlexShrink(1); root_child0.addChildAt(root_child0_child0, 0); - YogaNode root_child0_child0_child0 = new YogaNode(config); + YogaNode root_child0_child0_child0 = createNode(config); root_child0_child0_child0.setFlexGrow(1); root_child0_child0_child0.setFlexShrink(1); root_child0_child0.addChildAt(root_child0_child0_child0, 0); root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); assertFalse(root.getDoesLegacyStretchFlagAffectsLayout()); } + + private YogaNode createNode() { + return mNodeFactory.create(); + } + + private YogaNode createNode(YogaConfig config) { + return mNodeFactory.create(config); + } }