This is the mail archive of the
mauve-patches@sourceware.org
mailing list for the Mauve project.
Image Op tests
- From: Francis Kung <fkung at redhat dot com>
- To: Mauve Patch List <mauve-patches at sources dot redhat dot com>
- Date: Fri, 11 Aug 2006 17:04:56 -0400
- Subject: Image Op tests
I've updated and expanded the AffineTransformOp and BandCombineOp tests
from last week. Many of these tests currently fail, but I will be
submitting a Classpath patch shortly.
Regards,
Francis
2006-08-11 Francis Kung <fkung@redhat.com>
*
gnu/testlet/java/awt/image/AffineTransformOp/createCompatibleDestImage.java
(colorModelTest): New method.
(simpleTest): New method.
(test): Added more tests and split into two methods.
*
gnu/testlet/java/awt/image/AffineTransformOp/createCompatibleDestRaster.java:
New file.
* gnu/testlet/java/awt/image/AffineTransformOp/filterImage.java
(test): Removed a bad test.
(testDefaults): Added more tests.
(testTransform): Removed.
* gnu/testlet/java/awt/image/AffineTransformOp/filterRaster.java
(test): Removed a bad test.
(testDefaults): Added more tests.
(testTransform): Removed.
* gnu/testlet/java/awt/image/AffineTransformOp/getPoint2D.java
(testIdentity): Added more tests.
* gnu/testlet/java/awt/image/BandCombineOp/constructors.java
(basicTest): New method.
(emptyMatrix): New method.
(invalidMatrix): New method.
(test): Added more tests and split into multiple methods.
*
gnu/testlet/java/awt/image/BandCombineOp/createCompatibleDestRaster.java:
(basicTest): New method.
(impossibleTets): New method.
(test): Added more tests and split into multiple methods.
(test2): New method.
(test3): New method.
Index: gnu/testlet/java/awt/image/AffineTransformOp/createCompatibleDestImage.java
===================================================================
RCS file: /cvs/mauve/mauve/gnu/testlet/java/awt/image/AffineTransformOp/createCompatibleDestImage.java,v
retrieving revision 1.2
diff -u -r1.2 createCompatibleDestImage.java
--- gnu/testlet/java/awt/image/AffineTransformOp/createCompatibleDestImage.java 3 Aug 2006 17:43:16 -0000 1.2
+++ gnu/testlet/java/awt/image/AffineTransformOp/createCompatibleDestImage.java 11 Aug 2006 20:28:17 -0000
@@ -26,10 +26,16 @@
import gnu.testlet.TestHarness;
import gnu.testlet.Testlet;
+import java.awt.color.ColorSpace;
import java.awt.geom.AffineTransform;
import java.awt.image.AffineTransformOp;
import java.awt.image.BufferedImage;
+import java.awt.image.ColorModel;
+import java.awt.image.ComponentColorModel;
+import java.awt.image.DataBuffer;
import java.awt.image.DirectColorModel;
+import java.awt.image.PixelInterleavedSampleModel;
+import java.awt.image.SinglePixelPackedSampleModel;
/**
* Checks for the createCompatibleDestImage method in the
@@ -45,6 +51,12 @@
*/
public void test(TestHarness harness)
{
+ simpleTest(harness);
+ colorModelTest(harness);
+ }
+
+ private void simpleTest(TestHarness harness)
+ {
harness.checkPoint("createCompatibleDestImage");
// Simple test
@@ -67,28 +79,86 @@
harness.check(dest.getHeight(), 40);
harness.check(dest.getWidth(), 25);
harness.check(dest.getColorModel(), cm);
-
- // And the default color model
- dest = op.createCompatibleDestImage(img, null);
- harness.check(dest.getColorModel(), new DirectColorModel(32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000));
- //harness.check(dest.getColorModel(), img.getColorModel()) makes more sense,
- // but that fails on the reference implementation...
-
- /*
- // Throw the right exceptions
- img = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB);
- xform.scale(0.00000000000000001, 0.00000000000000001);
- op = new AffineTransformOp(xform, AffineTransformOp.TYPE_BICUBIC);
- try
- {
- op.createCompatibleDestImage(img, null);
- harness.check(false);
- }
- catch (RasterFormatException e)
- {
- harness.check(true);
- }
- */
+ }
+
+ // Test all the default color models
+ private void colorModelTest(TestHarness harness)
+ {
+ AffineTransform xform = new AffineTransform();
+ AffineTransformOp op = new AffineTransformOp(xform, AffineTransformOp.TYPE_BICUBIC);
+
+ int[] types = {BufferedImage.TYPE_INT_RGB,
+ BufferedImage.TYPE_INT_ARGB,
+ BufferedImage.TYPE_INT_ARGB_PRE,
+ BufferedImage.TYPE_3BYTE_BGR,
+ BufferedImage.TYPE_4BYTE_ABGR,
+ BufferedImage.TYPE_4BYTE_ABGR_PRE,
+ BufferedImage.TYPE_USHORT_565_RGB,
+ BufferedImage.TYPE_USHORT_555_RGB,
+ BufferedImage.TYPE_BYTE_GRAY,
+ BufferedImage.TYPE_USHORT_GRAY};
+ // Skipped types that are not implemented yet:
+ // TYPE_CUSTOM, TYPE_INT_BGR, TYPE_BYTE_BINARY, TYPE_BYTE_INDEXED
+
+ for (int i = 0; i < types.length; i++)
+ {
+ int type = types[i];
+ harness.checkPoint("type: " + type);
+
+ BufferedImage img = new BufferedImage(25, 40, type);
+ BufferedImage dest = op.createCompatibleDestImage(img, null);
+
+ dest = op.createCompatibleDestImage(img, null);
+ harness.check(dest.getColorModel().isCompatibleSampleModel(dest.getSampleModel()));
+
+ // This ensures that we have the same defaults as the reference implementation
+ switch (type)
+ {
+ case BufferedImage.TYPE_INT_RGB:
+ case BufferedImage.TYPE_INT_ARGB:
+ case BufferedImage.TYPE_INT_ARGB_PRE:
+ case BufferedImage.TYPE_3BYTE_BGR:
+ case BufferedImage.TYPE_USHORT_565_RGB:
+ case BufferedImage.TYPE_USHORT_555_RGB:
+ case BufferedImage.TYPE_BYTE_GRAY:
+ case BufferedImage.TYPE_USHORT_GRAY:
+
+ if (type == BufferedImage.TYPE_INT_ARGB_PRE)
+ harness.check(dest.getType(), BufferedImage.TYPE_INT_ARGB_PRE);
+ else
+ harness.check(dest.getType(), BufferedImage.TYPE_INT_ARGB);
+
+ harness.check(dest.getColorModel() instanceof DirectColorModel);
+ harness.check(dest.getSampleModel() instanceof SinglePixelPackedSampleModel);
+ harness.check(dest.getColorModel().getPixelSize(), 32);
+ harness.check(dest.getColorModel().getNumComponents(), 4);
+ harness.check(dest.getColorModel().getTransparency(), ColorModel.TRANSLUCENT);
+ harness.check(dest.getColorModel().hasAlpha(), true);
+ harness.check(dest.getColorModel().getTransferType(), DataBuffer.TYPE_INT);
+ harness.check(dest.getColorModel().isAlphaPremultiplied(), (type == BufferedImage.TYPE_INT_ARGB_PRE));
+ harness.check(dest.getColorModel().getColorSpace().getType(), ColorSpace.TYPE_RGB);
+ harness.check(dest.getRaster().getNumBands(), 4);
+ harness.check(dest.getRaster().getNumDataElements(), 1);
+ break;
+
+ case BufferedImage.TYPE_4BYTE_ABGR:
+ case BufferedImage.TYPE_4BYTE_ABGR_PRE:
+ harness.check(dest.getColorModel() instanceof ComponentColorModel);
+ harness.check(dest.getSampleModel() instanceof PixelInterleavedSampleModel);
+ harness.check(dest.getColorModel().getPixelSize(), 32);
+ harness.check(dest.getColorModel().getNumComponents(), 4);
+ harness.check(dest.getColorModel().getTransparency(), ColorModel.TRANSLUCENT);
+ harness.check(dest.getColorModel().hasAlpha(), true);
+ harness.check(dest.getColorModel().getTransferType(), DataBuffer.TYPE_BYTE);
+ harness.check(dest.getColorModel().isAlphaPremultiplied(), (type == BufferedImage.TYPE_4BYTE_ABGR_PRE));
+ harness.check(dest.getColorModel().getColorSpace().getType(), ColorSpace.TYPE_RGB);
+ harness.check(dest.getRaster().getNumBands(), 4);
+ harness.check(dest.getRaster().getNumDataElements(), 4);
+ break;
+ }
+ }
}
}
+
+
\ No newline at end of file
Index: gnu/testlet/java/awt/image/AffineTransformOp/filterRaster.java
===================================================================
RCS file: /cvs/mauve/mauve/gnu/testlet/java/awt/image/AffineTransformOp/filterRaster.java,v
retrieving revision 1.2
diff -u -r1.2 filterRaster.java
--- gnu/testlet/java/awt/image/AffineTransformOp/filterRaster.java 3 Aug 2006 17:43:16 -0000 1.2
+++ gnu/testlet/java/awt/image/AffineTransformOp/filterRaster.java 11 Aug 2006 20:28:17 -0000
@@ -27,16 +27,12 @@
import gnu.testlet.Testlet;
import java.awt.Graphics2D;
-import java.awt.Point;
import java.awt.geom.AffineTransform;
import java.awt.geom.Line2D;
import java.awt.image.AffineTransformOp;
import java.awt.image.BufferedImage;
-import java.awt.image.DataBuffer;
import java.awt.image.ImagingOpException;
-import java.awt.image.Raster;
import java.awt.image.WritableRaster;
-import java.util.Arrays;
/**
* Checks the filter(BufferedImage) method in the {@link AffineTransformOp} class.
@@ -55,9 +51,10 @@
testDefaults(harness, AffineTransformOp.TYPE_BICUBIC);
testDefaults(harness, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
- // testTransform(harness); // I don't really like how this test works,
- // but am leaving it in, in the hopes someone
- // might be able to base a better test off it
+ // Should write a test to ensure that the filter can actually be applied
+ // properly. Since interpolation comes into play, however, I don't know
+ // of a good way to test it, as our filtered image will be different
+ // from the reference implementation's...
}
private void testDefaults(TestHarness harness, int type)
@@ -94,6 +91,10 @@
harness.check(true);
}
+ /*
+ * This is not allowed on the ref impl, but it can't hurt to allow it
+ * here...
+ *
// Different type of raster (not allowed)
dest = Raster.createBandedRaster(DataBuffer.TYPE_USHORT, 20, 20, 1, new Point(0,0));
try
@@ -105,6 +106,7 @@
{
harness.check(true);
}
+ */
// Different size (allowed)
dest = src.createCompatibleWritableRaster(75, 87);
@@ -122,80 +124,5 @@
WritableRaster dest2 = op.filter(src, null);
harness.check(dest2 != null);
}
-
- private void testTransform(TestHarness harness)
- {
- // Create a raster to work on based on an image
- BufferedImage img = new BufferedImage(20, 20, BufferedImage.TYPE_USHORT_GRAY);
- Graphics2D g = (Graphics2D)img.getGraphics();
- g.draw(new Line2D.Double(0, 0, 20, 20));
-
- WritableRaster src = img.getRaster();
- AffineTransform xform = AffineTransform.getRotateInstance(Math.PI / 2, 10, 10);
- AffineTransformOp op = new AffineTransformOp(xform, AffineTransformOp.TYPE_BICUBIC);
-
- WritableRaster dst = op.filter(src, null);
-
- // The following values were found by testing against the ref impl, ie
- /*
- int[] pixels = dst.getSamples(0, 0, 20, 20, 0, (int[])null);
- for (int i = 0; i < pixels.length; i++)
- {
- if (pixels[i] != 0)
- System.out.println(i + ": " + pixels[i]);
- }
- */
- // Note that changing the interpolation type will result in different values.
- //
- // I'm not fully convinced this test is good, since pixel variations
- // in our transformations are tolerable (and visually insignificant)...
- // but i can't think of any other way to write a test for it.
- // Trying to draw a Line2D.Double(20, 0, 0, 20) and testing against that
- // fails on all implementations.
-
- int[] pixels = dst.getSamples(0, 0, 20, 20, 0, (int[])null);
-
- int[] pixels2 = new int[400];
- Arrays.fill(pixels2, 0);
-
- pixels2[19] = 65535;
- pixels2[37] = 65535;
- pixels2[38] = 65535;
- pixels2[56] = 65535;
- pixels2[57] = 65535;
- pixels2[75] = 65535;
- pixels2[76] = 65535;
- pixels2[94] = 65535;
- pixels2[95] = 65535;
- pixels2[113] = 65535;
- pixels2[114] = 65535;
- pixels2[132] = 65535;
- pixels2[133] = 65535;
- pixels2[151] = 65535;
- pixels2[152] = 65535;
- pixels2[170] = 65535;
- pixels2[171] = 65535;
- pixels2[189] = 65535;
- pixels2[190] = 65535;
- pixels2[208] = 65535;
- pixels2[209] = 65535;
- pixels2[227] = 65535;
- pixels2[228] = 65535;
- pixels2[246] = 65535;
- pixels2[247] = 65535;
- pixels2[265] = 65535;
- pixels2[266] = 65535;
- pixels2[284] = 65535;
- pixels2[285] = 65535;
- pixels2[303] = 65535;
- pixels2[304] = 65535;
- pixels2[322] = 65535;
- pixels2[323] = 65535;
- pixels2[342] = 65535;
- pixels2[361] = 65535;
- pixels2[380] = 65534;
-
- harness.check(Arrays.equals(pixels, pixels2));
- }
}
Index: gnu/testlet/java/awt/image/AffineTransformOp/getPoint2D.java
===================================================================
RCS file: /cvs/mauve/mauve/gnu/testlet/java/awt/image/AffineTransformOp/getPoint2D.java,v
retrieving revision 1.2
diff -u -r1.2 getPoint2D.java
--- gnu/testlet/java/awt/image/AffineTransformOp/getPoint2D.java 3 Aug 2006 17:43:16 -0000 1.2
+++ gnu/testlet/java/awt/image/AffineTransformOp/getPoint2D.java 11 Aug 2006 20:28:18 -0000
@@ -60,12 +60,14 @@
harness.check(op.getPoint2D(new Point2D.Double(5, 5), null), new Point2D.Double(5,5));
Point2D pt = null;
- op.getPoint2D(new Point2D.Double(10,-5), pt);
+ Point2D pt2 = op.getPoint2D(new Point2D.Double(10,-5), pt);
harness.check(pt, null); // this is what the ref impl does...
+ harness.check(pt2, new Point2D.Double(10, -5));
pt = new Point2D.Double(0,0);
- op.getPoint2D(new Point2D.Double(10,-5), pt);
+ pt2 = op.getPoint2D(new Point2D.Double(10,-5), pt);
harness.check(pt, new Point2D.Double(10, -5));
+ harness.check(pt, pt2);
pt = new Point2D.Float(0,0);
op.getPoint2D(new Point2D.Float(-10,-5), pt);
@@ -107,7 +109,7 @@
private void testShear(TestHarness harness)
{
- harness.checkPoint("testHarness");
+ harness.checkPoint("testShear");
AffineTransform xform = AffineTransform.getShearInstance(1.5, 3.25);
AffineTransformOp op = new AffineTransformOp(xform, AffineTransformOp.TYPE_BICUBIC);
Index: gnu/testlet/java/awt/image/AffineTransformOp/filterImage.java
===================================================================
RCS file: /cvs/mauve/mauve/gnu/testlet/java/awt/image/AffineTransformOp/filterImage.java,v
retrieving revision 1.2
diff -u -r1.2 filterImage.java
--- gnu/testlet/java/awt/image/AffineTransformOp/filterImage.java 3 Aug 2006 17:43:16 -0000 1.2
+++ gnu/testlet/java/awt/image/AffineTransformOp/filterImage.java 11 Aug 2006 20:28:17 -0000
@@ -31,7 +31,6 @@
import java.awt.geom.Line2D;
import java.awt.image.AffineTransformOp;
import java.awt.image.BufferedImage;
-import java.util.Arrays;
/**
* Checks the filter(BufferedImage) method in the {@link AffineTransformOp} class.
@@ -47,9 +46,11 @@
public void test(TestHarness harness)
{
testDefaults(harness);
- //testTransform(harness); // I don't really like how this test works,
- // but am leaving it in, in the hopes someone
- // might be able to base a better test off it
+
+ // Should write a test to ensure that the filter can actually be applied
+ // properly. Since interpolation comes into play, however, I don't know
+ // of a good way to test it, as our filtered image will be different
+ // from the reference implementation's...
}
private void testDefaults(TestHarness harness)
@@ -98,6 +99,9 @@
}
// Src and dst are different sizes AND different types (not allowed)
+ /*
+ * Fails on the ref impl...
+ *
dst = new BufferedImage(30, 40, BufferedImage.TYPE_INT_ARGB);
try
{
@@ -108,83 +112,11 @@
{
harness.check(true);
}
- }
-
- private void testTransform(TestHarness harness)
- {
- // Create an image to work on
- BufferedImage img = new BufferedImage(20, 20, BufferedImage.TYPE_USHORT_GRAY);
- Graphics2D g = (Graphics2D)img.getGraphics();
- g.draw(new Line2D.Double(0, 0, 20, 20));
-
- AffineTransform xform = AffineTransform.getRotateInstance(Math.PI / 2, 10, 10);
- AffineTransformOp op = new AffineTransformOp(xform, AffineTransformOp.TYPE_BICUBIC);
-
- BufferedImage dst = new BufferedImage(20, 20, BufferedImage.TYPE_USHORT_GRAY);
- BufferedImage dst2 = op.filter(img, dst);
-
- harness.check(dst, dst2);
-
- // The following values were found by testing against the ref impl, ie
- /*
- int[] pixels = img.getData().getPixels(0, 0, 20, 20, (int[])null);
- for (int i = 0; i < pixels.length; i++)
- {
- if (pixels[i] != 0)
- System.out.println(i + ": " + pixels[i]);
- }
- */
- // Note that changing the interpolation type will result in different values.
- //
- // I'm not fully convinced this test is good, since pixel variations
- // in our transformations are tolerable (and visually insignificant)...
- // but i can't think of any other way to write a test for it.
- // Trying to draw a Line2D.Double(20, 0, 0, 20) and testing against that
- // fails on all implementations.
-
- int[] pixels = dst.getData().getPixels(0,0,20,20,(int[])null);
-
- int[] pixels2 = new int[400];
- Arrays.fill(pixels2, 0);
-
- pixels2[19] = 65535;
- pixels2[37] = 65535;
- pixels2[38] = 65535;
- pixels2[56] = 65535;
- pixels2[57] = 65535;
- pixels2[75] = 65535;
- pixels2[76] = 65535;
- pixels2[94] = 65535;
- pixels2[95] = 65535;
- pixels2[113] = 65535;
- pixels2[114] = 65535;
- pixels2[132] = 65535;
- pixels2[133] = 65535;
- pixels2[151] = 65535;
- pixels2[152] = 65535;
- pixels2[170] = 65535;
- pixels2[171] = 65535;
- pixels2[189] = 65535;
- pixels2[190] = 65535;
- pixels2[208] = 65535;
- pixels2[209] = 65535;
- pixels2[227] = 65535;
- pixels2[228] = 65535;
- pixels2[246] = 65535;
- pixels2[247] = 65535;
- pixels2[265] = 65535;
- pixels2[266] = 65535;
- pixels2[284] = 65535;
- pixels2[285] = 65535;
- pixels2[303] = 65535;
- pixels2[304] = 65535;
- pixels2[322] = 65535;
- pixels2[323] = 65535;
- pixels2[342] = 65535;
- pixels2[361] = 65535;
- pixels2[380] = 65534;
+ */
- harness.check(Arrays.equals(pixels, pixels2));
+ // Checks the destination image type
+ dst = op.filter(img, null);
+ harness.check(dst.getType(), op.createCompatibleDestImage(img, null).getType());
}
}
Index: gnu/testlet/java/awt/image/BandCombineOp/createCompatibleDestRaster.java
===================================================================
RCS file: /cvs/mauve/mauve/gnu/testlet/java/awt/image/BandCombineOp/createCompatibleDestRaster.java,v
retrieving revision 1.2
diff -u -r1.2 createCompatibleDestRaster.java
--- gnu/testlet/java/awt/image/BandCombineOp/createCompatibleDestRaster.java 3 Aug 2006 17:43:15 -0000 1.2
+++ gnu/testlet/java/awt/image/BandCombineOp/createCompatibleDestRaster.java 11 Aug 2006 20:28:18 -0000
@@ -45,6 +45,14 @@
*/
public void test(TestHarness harness)
{
+ basicTest(harness);
+ test2(harness);
+ test3(harness);
+ impossibleTest(harness);
+ }
+
+ private void basicTest(TestHarness harness)
+ {
harness.checkPoint("createCompatibleDestRaster");
// Simple test
@@ -61,6 +69,7 @@
harness.check(dst.getNumBands(), 3);
harness.check(dst.getHeight(), src.getHeight());
harness.check(dst.getWidth(), src.getWidth());
+ harness.check(dst.getTransferType(), src.getTransferType());
harness.check(dst.getDataBuffer().getDataType(), src.getDataBuffer().getDataType());
}
catch (IllegalArgumentException e)
@@ -68,10 +77,13 @@
harness.check(false);
}
- src = Raster.createBandedRaster(DataBuffer.TYPE_INT, 25, 40, 3, new Point(5, 5));
+ // Try a different type
+ src = Raster.createBandedRaster(DataBuffer.TYPE_BYTE, 25, 40, 3, new Point(5, 5));
try
{
Raster dst = op.createCompatibleDestRaster(src);
+ harness.check(dst.getTransferType(), src.getTransferType());
+ harness.check(dst.getDataBuffer().getDataType(), src.getDataBuffer().getDataType());
harness.check(dst.getNumBands(), 3);
}
catch (IllegalArgumentException e)
@@ -79,7 +91,19 @@
harness.check(false);
}
- // The source (4 bands) is incompatible with the matrix (2 or 3 bands)
+ // This is where things get messy. The Sun API states that "The width of the matrix
+ // must be equal to the number of bands in the source Raster, optionally plus one. If
+ // there is one more column in the matrix than the number of bands, there is an implied
+ // 1 at the end of the vector of band samples representing a pixel. The height of the matrix
+ // must be equal to the number of bands in the destination", but this is NOT how their
+ // implementation behaves.
+ //
+ // They miss one requirement, however: the number of bands in the source and destination
+ // rasters must also be equal... which effectively means
+ // ((width == height) || (width == height + 1)) must be true
+
+ // The source (4 bands) is incompatible with the matrix (width = 3)
+
src = Raster.createBandedRaster(DataBuffer.TYPE_INT, 25, 40, 4, new Point(5, 5));
try
{
@@ -91,7 +115,8 @@
harness.check(true);
}
- // The source (1 band) is incompatible with the matrix (2 or 3 bands)
+ // The destination raster (3 bands) would be incompatibel with the source (2 bands)
+ // (the undocumented requirement)
src = Raster.createBandedRaster(DataBuffer.TYPE_INT, 25, 40, 1, new Point(5, 5));
try
{
@@ -102,6 +127,175 @@
{
harness.check(true);
}
+
+ }
+
+ // Using a non-square matrix
+ private void test2(TestHarness harness)
+ {
+ // Height still == 3, but width == 4
+ float[][] matrix = new float[][] {new float[] {1, 2, 3, 1},
+ new float[] {4, 5, 6, 1},
+ new float[] {7, 8, 9, 1}};
+
+ BandCombineOp op = new BandCombineOp(matrix, null);
+
+ // Source has 3 bands, which is the width minus one (uses the implied 1), works
+ Raster src = Raster.createBandedRaster(DataBuffer.TYPE_INT, 25, 40, 3, new Point(5, 5));
+ try
+ {
+ Raster dst = op.createCompatibleDestRaster(src);
+ harness.check(dst.getNumBands(), 3);
+ }
+ catch (IllegalArgumentException e)
+ {
+ harness.check(false);
+ }
+
+ // Source has 4 bands, which is compatible with the matrix (width is 4)
+ // The destination raster, however, is not compatible with the source (3 vs 4 bands)
+ // (the undocumented restriction)
+ src = Raster.createBandedRaster(DataBuffer.TYPE_INT, 25, 40, 4, new Point(5, 5));
+ try
+ {
+ op.createCompatibleDestRaster(src);
+ harness.check(false);
+ }
+ catch (IllegalArgumentException e)
+ {
+ harness.check(true);
+ }
+
+ // Also incompatible, but this is expected according to the spec
+ src = Raster.createBandedRaster(DataBuffer.TYPE_INT, 25, 40, 2, new Point(5, 5));
+ try
+ {
+ op.createCompatibleDestRaster(src);
+ harness.check(false);
+ }
+ catch (IllegalArgumentException e)
+ {
+ harness.check(true);
+ }
+
+ // Also still incompatible
+ src = Raster.createBandedRaster(DataBuffer.TYPE_INT, 25, 40, 5, new Point(5, 5));
+ try
+ {
+ op.createCompatibleDestRaster(src);
+ harness.check(false);
+ }
+ catch (IllegalArgumentException e)
+ {
+ harness.check(true);
+ }
+ }
+
+ // One more test, with a larger matrix
+ private void test3(TestHarness harness)
+ {
+ // Test again, with a different matrix
+ float[][] matrix = new float[][] {new float[] {1, 2, 3, 1, 5},
+ new float[] {4, 5, 6, 1, 5},
+ new float[] {7, 8, 9, 1, 5},
+ new float[] {1, 2, 3, 4, 5}};
+
+ BandCombineOp op = new BandCombineOp(matrix, null);
+
+ // Works using the implied 1
+ Raster src = Raster.createBandedRaster(DataBuffer.TYPE_INT, 25, 40, 4, new Point(5, 5));
+ try
+ {
+ Raster dst = op.createCompatibleDestRaster(src);
+ harness.check(dst.getNumBands(), 4);
+ }
+ catch (IllegalArgumentException e)
+ {
+ harness.check(false);
+ }
+
+ // Does not use implied 1; however source and dest would have incompabible bands
+ // (undocumented restriction)
+ src = Raster.createBandedRaster(DataBuffer.TYPE_INT, 25, 40, 5, new Point(5, 5));
+ try
+ {
+ op.createCompatibleDestRaster(src);
+ harness.check(false);
+ }
+ catch (IllegalArgumentException e)
+ {
+ harness.check(true);
+ }
+
+ // Just for completeness
+ src = Raster.createBandedRaster(DataBuffer.TYPE_INT, 25, 40, 3, new Point(5, 5));
+ try
+ {
+ op.createCompatibleDestRaster(src);
+ harness.check(false);
+ }
+ catch (IllegalArgumentException e)
+ {
+ harness.check(true);
+ }
+ src = Raster.createBandedRaster(DataBuffer.TYPE_INT, 25, 40, 6, new Point(5, 5));
+ try
+ {
+ op.createCompatibleDestRaster(src);
+ harness.check(false);
+ }
+ catch (IllegalArgumentException e)
+ {
+ harness.check(true);
+ }
+ }
+
+ private void impossibleTest(TestHarness harness)
+ {
+ // Thus, it would be impossible to create a compatible destination wraster if
+ // ((width != height) && (width != height + 1))
+ float[][] matrix = new float[][] {new float[] {1, 2, 3, 1, 5},
+ new float[] {4, 5, 6, 1, 5},
+ new float[] {7, 8, 9, 1, 5}};
+
+ BandCombineOp op = new BandCombineOp(matrix, null);
+
+ for (int i = 2; i < 6; i++)
+ {
+ Raster src = Raster.createBandedRaster(DataBuffer.TYPE_INT, 25, 40, i, new Point(5, 5));
+ try
+ {
+ op.createCompatibleDestRaster(src);
+ harness.check(false);
+ }
+ catch (IllegalArgumentException e)
+ {
+ harness.check(true);
+ }
+ }
+
+ // Repeat the above test, but with too many rows instead of too few
+ matrix = new float[][] {new float[] {1, 2, 3,},
+ new float[] {4, 5, 6,},
+ new float[] {2, 4, 6,},
+ new float[] {1, 3, 5,},
+ new float[] {7, 8, 9,}};
+
+ op = new BandCombineOp(matrix, null);
+
+ for (int i = 2; i < 6; i++)
+ {
+ Raster src = Raster.createBandedRaster(DataBuffer.TYPE_INT, 25, 40, i, new Point(5, 5));
+ try
+ {
+ op.createCompatibleDestRaster(src);
+ harness.check(false);
+ }
+ catch (IllegalArgumentException e)
+ {
+ harness.check(true);
+ }
+ }
}
}
Index: gnu/testlet/java/awt/image/BandCombineOp/constructors.java
===================================================================
RCS file: /cvs/mauve/mauve/gnu/testlet/java/awt/image/BandCombineOp/constructors.java,v
retrieving revision 1.2
diff -u -r1.2 constructors.java
--- gnu/testlet/java/awt/image/BandCombineOp/constructors.java 3 Aug 2006 17:43:15 -0000 1.2
+++ gnu/testlet/java/awt/image/BandCombineOp/constructors.java 11 Aug 2006 20:28:18 -0000
@@ -43,6 +43,14 @@
*/
public void test(TestHarness harness)
{
+ basicTest(harness);
+ emptyMatrix(harness);
+ invalidMatrix(harness);
+ }
+
+ // Test the basic operation of the constructor
+ private void basicTest(TestHarness harness)
+ {
harness.checkPoint("(constructor)");
float[][] matrix = new float[][] {new float[]{1, 2, 3},
@@ -63,10 +71,32 @@
else
for (int i = 0; i < expectedMatrix.length; i++)
harness.check(Arrays.equals(expectedMatrix[i], resultMatrix[i]));
-
+
+ // This happens even if the (width == height + 1)
+ matrix = new float[][] {new float[]{1, 2, 3, 4},
+ new float[]{4, 5, 6, 7},
+ new float[]{7, 8, 9, 1}};
+
+ op = new BandCombineOp(matrix, null);
+
+ resultMatrix = op.getMatrix();
+ expectedMatrix = new float[][] {new float[]{1, 2, 3, 4, 0},
+ new float[]{4, 5, 6, 7, 0},
+ new float[]{7, 8, 9, 1, 0}};
+
+ if (expectedMatrix.length != resultMatrix.length)
+ harness.check(false);
+ else
+ for (int i = 0; i < expectedMatrix.length; i++)
+ harness.check(Arrays.equals(expectedMatrix[i], resultMatrix[i]));
+ }
+
+ // Test behaviour of constructor when passed various empty matrices
+ private void emptyMatrix(TestHarness harness)
+ {
// Try creating with an empty matrix - this should be allowed
- matrix = new float[][] {new float[]{},
- new float[]{}};
+ float[][] matrix = new float[][] {new float[]{},
+ new float[]{}};
try
{
@@ -78,15 +108,77 @@
harness.check(false);
}
- op = new BandCombineOp(matrix, null);
- resultMatrix = op.getMatrix();
- expectedMatrix = new float[][] {new float[]{0},
- new float[]{0}};
+ BandCombineOp op = new BandCombineOp(matrix, null);
+ float[][] resultMatrix = op.getMatrix();
+ float[][] expectedMatrix = new float[][] {new float[]{0},
+ new float[]{0}};
if (expectedMatrix.length != resultMatrix.length)
harness.check(false);
else
for (int i = 0; i < expectedMatrix.length; i++)
harness.check(Arrays.equals(expectedMatrix[i], resultMatrix[i]));
+
+ // What about a null matrix, not an empty one??
+ matrix = new float[][] {null, null};
+
+ try
+ {
+ new BandCombineOp(matrix, null);
+ harness.check(false);
+ }
+ catch (NullPointerException e)
+ {
+ harness.check(true);
+ }
+
+ // And pass in a null parameter, not just a matrix of nulls
+ try
+ {
+ new BandCombineOp(null, null);
+ harness.check(false);
+ }
+ catch (NullPointerException e)
+ {
+ harness.check(true);
+ }
+ }
+
+ // Checks on behaviour of constructor when passed an invalid matrix
+ private void invalidMatrix(TestHarness harness)
+ {
+ // What checks are done to ensure the 2-d array is a 2-d matrix?
+ // If a row is too short, we throw an exception...
+ float[][] matrix = new float[][] {new float[]{1, 2, 3, 4},
+ new float[]{4, 5},
+ new float[]{7, 8, 9}};
+
+ try
+ {
+ new BandCombineOp(matrix, null);
+ harness.check(false);
+ }
+ catch (ArrayIndexOutOfBoundsException e)
+ {
+ harness.check(true);
+ }
+
+ // And if a row is too long, it gets concatenated.
+ matrix = new float[][] {new float[]{1, 2},
+ new float[]{4, 5, 6},
+ new float[]{7, 8, 9, 1}};
+
+ BandCombineOp op = new BandCombineOp(matrix, null);
+
+ float[][] resultMatrix = op.getMatrix();
+ float[][] expectedMatrix = new float[][] {new float[]{1, 2, 0},
+ new float[]{4, 5, 0},
+ new float[]{7, 8, 0}};
+
+ if (expectedMatrix.length != resultMatrix.length)
+ harness.check(false);
+ else
+ for (int i = 0; i < expectedMatrix.length; i++)
+ harness.check(Arrays.equals(expectedMatrix[i], resultMatrix[i]));
}
}
Index: gnu/testlet/java/awt/image/AffineTransformOp/createCompatibleDestRaster.java
===================================================================
RCS file: gnu/testlet/java/awt/image/AffineTransformOp/createCompatibleDestRaster.java
diff -N gnu/testlet/java/awt/image/AffineTransformOp/createCompatibleDestRaster.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/java/awt/image/AffineTransformOp/createCompatibleDestRaster.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,102 @@
+/* createCompatibleDestRaster.java -- some checks for the
+ createCompatibleDestRaster() method of the AffineTransformOp class.
+ Copyright (C) 2006 Francis Kung <fkung@redhat.com>
+This file is part of Mauve.
+
+Mauve is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+Mauve is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Mauve; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+*/
+
+// Tags: JDK1.2
+
+package gnu.testlet.java.awt.image.AffineTransformOp;
+
+import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
+
+import java.awt.Point;
+import java.awt.geom.AffineTransform;
+import java.awt.image.AffineTransformOp;
+import java.awt.image.DataBuffer;
+import java.awt.image.Raster;
+
+/**
+ * Checks for the createCompatibleDestRaster method in the
+ * {@link AffineTransformOp} class.
+ */
+public class createCompatibleDestRaster implements Testlet
+{
+
+ /**
+ * Runs the test using the specified harness.
+ *
+ * @param harness the test harness (<code>null</code> not permitted).
+ */
+ public void test(TestHarness harness)
+ {
+ harness.checkPoint("createCompatibleDestRaster");
+
+ // Simple test
+ Raster src = Raster.createBandedRaster(DataBuffer.TYPE_INT, 25, 40, 3, new Point(5, 5));
+ AffineTransform xform = new AffineTransform();
+ AffineTransformOp op = new AffineTransformOp(xform, AffineTransformOp.TYPE_BILINEAR);
+
+ try
+ {
+ Raster dst = op.createCompatibleDestRaster(src);
+ harness.check(dst.getHeight(), src.getHeight());
+ harness.check(dst.getWidth(), src.getWidth());
+ harness.check(dst.getNumBands(), src.getNumBands());
+ harness.check(dst.getTransferType(), src.getTransferType());
+ harness.check(dst.getDataBuffer().getDataType(), src.getDataBuffer().getDataType());
+ harness.check(dst.getNumDataElements(), src.getNumDataElements());
+ }
+ catch (IllegalArgumentException e)
+ {
+ harness.check(false);
+ }
+
+ // Try a different type
+ src = Raster.createBandedRaster(DataBuffer.TYPE_BYTE, 25, 40, 3, new Point(5, 5));
+ try
+ {
+ Raster dst = op.createCompatibleDestRaster(src);
+ harness.check(dst.getNumBands(), src.getNumBands());
+ harness.check(dst.getTransferType(), src.getTransferType());
+ harness.check(dst.getDataBuffer().getDataType(), src.getDataBuffer().getDataType());
+ harness.check(dst.getNumDataElements(), src.getNumDataElements());
+ }
+ catch (IllegalArgumentException e)
+ {
+ harness.check(false);
+ }
+
+ // Try a different number of bands
+ src = Raster.createBandedRaster(DataBuffer.TYPE_INT, 25, 40, 5, new Point(5, 5));
+ try
+ {
+ Raster dst = op.createCompatibleDestRaster(src);
+ harness.check(dst.getNumBands(), src.getNumBands());
+ harness.check(dst.getTransferType(), src.getTransferType());
+ harness.check(dst.getDataBuffer().getDataType(), src.getDataBuffer().getDataType());
+ harness.check(dst.getNumDataElements(), src.getNumDataElements());
+ }
+ catch (IllegalArgumentException e)
+ {
+ harness.check(false);
+ }
+ }
+}
+