diff options
author | Vincent Hennebert <vhennebert@apache.org> | 2014-07-18 13:49:05 +0000 |
---|---|---|
committer | Vincent Hennebert <vhennebert@apache.org> | 2014-07-18 13:49:05 +0000 |
commit | f8dd309bf637ecd62762fdfd889be1e7b210b755 (patch) | |
tree | ff643bc8e7dd521f21c5b7b6eb4b533ab9f9c29b /test | |
parent | a1e5851e19b3b2f0b3224a4e9dd084515b280f72 (diff) | |
download | xmlgraphics-fop-f8dd309bf637ecd62762fdfd889be1e7b210b755.tar.gz xmlgraphics-fop-f8dd309bf637ecd62762fdfd889be1e7b210b755.zip |
Added more complete tests
Keep floats for bounds instead of converting them to doubles
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/FOP-2393_gradient-rendering@1611653 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'test')
-rw-r--r-- | test/java/org/apache/fop/render/gradient/GradientTestCase.java | 130 |
1 files changed, 126 insertions, 4 deletions
diff --git a/test/java/org/apache/fop/render/gradient/GradientTestCase.java b/test/java/org/apache/fop/render/gradient/GradientTestCase.java index 13a1c173d..51a9c6c37 100644 --- a/test/java/org/apache/fop/render/gradient/GradientTestCase.java +++ b/test/java/org/apache/fop/render/gradient/GradientTestCase.java @@ -28,6 +28,7 @@ import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import org.apache.batik.ext.awt.LinearGradientPaint; +import org.apache.batik.ext.awt.RadialGradientPaint; public class GradientTestCase { @@ -67,8 +68,13 @@ public class GradientTestCase { return this; } - ShadingChecker coords(Double... expectedCoords) { - assertArrayEquals(expectedCoords, shading.getCoords().toArray()); + ShadingChecker coords(double... expectedCoords) { + double[] coords = new double[shading.getCoords().size()]; + int index = 0; + for (Double d : shading.getCoords()) { + coords[index++] = d; + } + assertArrayEquals(expectedCoords, coords, 0.0001); return this; } @@ -100,7 +106,7 @@ public class GradientTestCase { return this; } - FunctionChecker bounds(Double... expectedBounds) { + FunctionChecker bounds(Float... expectedBounds) { assertArrayEquals(expectedBounds, function.getBounds().toArray()); return this; } @@ -131,7 +137,7 @@ public class GradientTestCase { } @Test - public void testGradient() { + public void simpleLinearGradient() { LinearGradientPaint gradient = new LinearGradientPaint(0f, 0f, 100f, 100f, fractions(0f, 1f), colors(Color.BLUE, Color.RED)); Pattern pattern = GradientMaker.makeLinearGradient(gradient, @@ -158,6 +164,122 @@ public class GradientTestCase { .functions(0); } + @Test + public void simpleRadialGradient() { + RadialGradientPaint gradient = new RadialGradientPaint(100, 200, 50, + fractions(0f, 1f), colors(Color.BLUE, Color.RED)); + Pattern pattern = GradientMaker.makeRadialGradient(gradient, new AffineTransform(), new AffineTransform()); + PatternChecker patternChecker = new PatternChecker(pattern).type(2); + ShadingChecker shadingChecker = patternChecker.shading() + .shadingType(3) + .coords(100.0, 200.0, 0.0, 100.0, 200.0, 50.0) + .extend(true, true); + FunctionChecker functionChecker = shadingChecker.function() + .functionType(3) + .domain(0.0, 1.0) + .bounds() + .encode(0.0, 1.0) + .functions(1); + functionChecker.function(0) + .functionType(2) + .domain(0.0, 1.0) + .cZero(0f, 0f, 1f) + .cOne(1f, 0f, 0f) + .functions(0); + } + + @Test + public void threeColorLinearGradient() { + LinearGradientPaint gradient = new LinearGradientPaint(0f, 10f, 20f, 30f, + fractions(0f, 0.5f, 1f), colors(Color.BLUE, Color.RED, Color.GREEN)); + Pattern pattern = GradientMaker.makeLinearGradient(gradient, new AffineTransform(), new AffineTransform()); + PatternChecker patternChecker = new PatternChecker(pattern) + .type(2) + .matrix(1.0, 0.0, 0.0, 1.0, 0.0, 0.0); + ShadingChecker shadingChecker = patternChecker.shading() + .shadingType(2) + .coords(0.0, 10.0, 20.0, 30.0) + .extend(true, true); + FunctionChecker functionChecker = shadingChecker.function() + .functionType(3) + .domain(0.0, 1.0) + .bounds(0.5f) + .encode(0.0, 1.0, 0.0, 1.0) + .functions(2); + functionChecker.function(0) + .functionType(2) + .domain(0.0, 1.0) + .cZero(0f, 0f, 1f) + .cOne(1f, 0f, 0f) + .functions(0); + functionChecker.function(1) + .functionType(2) + .domain(0.0, 1.0) + .cZero(1f, 0f, 0f) + .cOne(0f, 1f, 0f) + .functions(0); + } + + @Test + public void fourColorRadialGradientNonZeroFirstStop() { + RadialGradientPaint gradient = new RadialGradientPaint(100, 200, 50, 110, 220, + fractions(0.2f, 0.5f, 0.7f, 1f), colors(Color.BLUE, Color.RED, Color.GREEN, Color.WHITE)); + Pattern pattern = GradientMaker.makeRadialGradient(gradient, new AffineTransform(), new AffineTransform()); + ShadingChecker shadingChecker = new PatternChecker(pattern).shading() + .coords(110.0, 220.0, 0.0, 100.0, 200.0, 50.0); + FunctionChecker functionChecker = shadingChecker.function() + .functionType(3) + .bounds(0.2f, 0.5f, 0.7f) + .encode(0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0) + .functions(4); + functionChecker.function(0) + .functionType(2) + .cZero(0f, 0f, 1f) + .cOne(0f, 0f, 1f); + functionChecker.function(1) + .functionType(2) + .cZero(0f, 0f, 1f) + .cOne(1f, 0f, 0f); + functionChecker.function(2) + .functionType(2) + .cZero(1f, 0f, 0f) + .cOne(0f, 1f, 0f); + functionChecker.function(3) + .functionType(2) + .cZero(0f, 1f, 0f) + .cOne(1f, 1f, 1f); + } + + @Test + public void fourColorRadialGradientNonZeroLastStopFocalOut() { + RadialGradientPaint gradient = new RadialGradientPaint(0, 0, 100, 100, 100, + fractions(0f, 0.3f, 0.6f, 0.9f), colors(Color.WHITE, Color.RED, Color.GREEN, Color.BLUE)); + Pattern pattern = GradientMaker.makeRadialGradient(gradient, new AffineTransform(), new AffineTransform()); + ShadingChecker shadingChecker = new PatternChecker(pattern).shading() + .coords(70.7036, 70.7036, 0.0, 0.0, 0.0, 100.0); + FunctionChecker functionChecker = shadingChecker.function() + .functionType(3) + .bounds(0.3f, 0.6f, 0.9f) + .encode(0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0) + .functions(4); + functionChecker.function(0) + .functionType(2) + .cZero(1f, 1f, 1f) + .cOne(1f, 0f, 0f); + functionChecker.function(1) + .functionType(2) + .cZero(1f, 0f, 0f) + .cOne(0f, 1f, 0f); + functionChecker.function(2) + .functionType(2) + .cZero(0f, 1f, 0f) + .cOne(0f, 0f, 1f); + functionChecker.function(3) + .functionType(2) + .cZero(0f, 0f, 1f) + .cOne(0f, 0f, 1f); + } + private float[] fractions(float... fractions) { return fractions; } |