This is the mail archive of the mauve-patches@sourceware.org mailing list for the Mauve project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

FYI: RescaleOp tests


Hi,

The following tests have been committed for the java.awt.image.RescaleOp
package.

Cheers,
Francis


2006-09-06  Francis Kung  <fkung@redhat.com>

	* gnu/testlet/java/awt/image/RescaleOp/constructors.java,
	* gnu/testlet/java/awt/image/RescaleOp/createCompatibleDestImage.java,
	* gnu/testlet/java/awt/image/RescaleOp/createCompatibleDestRaster.java,
	* gnu/testlet/java/awt/image/RescaleOp/filterImage.java,
	* gnu/testlet/java/awt/image/RescaleOp/filterRaster.java,
	* gnu/testlet/java/awt/image/RescaleOp/getBounds2D.java,
	* gnu/testlet/java/awt/image/RescaleOp/getNumFactors.java,
	* gnu/testlet/java/awt/image/RescaleOp/getOffsets.java,
	* gnu/testlet/java/awt/image/RescaleOp/getPoint2D.java,
	* gnu/testlet/java/awt/image/RescaleOp/getRenderingHints.java,
	* gnu/testlet/java/awt/image/RescaleOp/getScaleFactors.java: New files.

Index: gnu/testlet/java/awt/image/RescaleOp/getOffsets.java
===================================================================
RCS file: gnu/testlet/java/awt/image/RescaleOp/getOffsets.java
diff -N gnu/testlet/java/awt/image/RescaleOp/getOffsets.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/java/awt/image/RescaleOp/getOffsets.java	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,83 @@
+/* getffsets.java -- some checks for the getOffsets() method in the
+       RescaleOp 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.4
+
+package gnu.testlet.java.awt.image.RescaleOp;
+
+import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
+
+import java.awt.image.RescaleOp;
+import java.util.Arrays;
+
+public class getOffsets implements Testlet
+{
+  public void test(TestHarness harness)
+  {
+    RescaleOp op = new RescaleOp(1, 1, null);
+    harness.check(Arrays.equals(op.getOffsets(null), new float[]{1}));
+    
+    op = new RescaleOp(new float[]{1}, new float[]{1}, null);
+    harness.check(Arrays.equals(op.getOffsets(null), new float[]{1}));
+    
+    float[] flt = new float[]{1, 2, 3, 4, 5};
+    op = new RescaleOp(flt, flt, null);
+    harness.check(op.getOffsets(null) != flt);
+    harness.check(Arrays.equals(op.getOffsets(null),
+                                new float[]{1, 2, 3, 4, 5}));
+    
+    // Mismatched array sizes...
+    op = new RescaleOp(new float[]{1, 2}, flt, null);
+    harness.check(op.getOffsets(null).length == 2);
+    harness.check(op.getOffsets(null)[0] == 1);
+    harness.check(op.getOffsets(null)[1] == 2);
+    
+    // Try passing in an array to be populated
+    op = new RescaleOp(flt, flt, null);
+    float[] arr = new float[5];
+    harness.check(Arrays.equals(op.getOffsets(arr), arr));
+    harness.check(Arrays.equals(arr, flt));
+    
+    // What if the array is too big?
+    arr = new float[10];
+    Arrays.fill(arr, 25);
+    op.getOffsets(arr);
+    for (int i = 0; i < 5; i++)
+      harness.check(arr[i] == flt[i]);
+    for (int i = 5; i < arr.length; i++)
+      harness.check(arr[i] == 25);
+    
+    // What if array is too small?
+    arr = new float[2];
+    try
+    {
+      harness.check(op.getOffsets(arr).length == 2);
+      harness.check(op.getOffsets(arr)[0] == 1);
+      harness.check(op.getOffsets(arr)[1] == 2);
+    }
+    catch (ArrayIndexOutOfBoundsException ex)
+    {
+      harness.check(false);
+    }
+  }
+}
Index: gnu/testlet/java/awt/image/RescaleOp/getScaleFactors.java
===================================================================
RCS file: gnu/testlet/java/awt/image/RescaleOp/getScaleFactors.java
diff -N gnu/testlet/java/awt/image/RescaleOp/getScaleFactors.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/java/awt/image/RescaleOp/getScaleFactors.java	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,83 @@
+/* getScaleFactors.java -- some checks for the getScaleFactors() method in the
+       RescaleOp 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.4
+
+package gnu.testlet.java.awt.image.RescaleOp;
+
+import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
+
+import java.awt.image.RescaleOp;
+import java.util.Arrays;
+
+public class getScaleFactors implements Testlet
+{
+  public void test(TestHarness harness)
+  {
+    RescaleOp op = new RescaleOp(1, 1, null);
+    harness.check(Arrays.equals(op.getScaleFactors(null), new float[]{1}));
+    
+    op = new RescaleOp(new float[]{1}, new float[]{1}, null);
+    harness.check(Arrays.equals(op.getScaleFactors(null), new float[]{1}));
+    
+    float[] flt = new float[]{1, 2, 3, 4, 5};
+    op = new RescaleOp(flt, flt, null);
+    harness.check(op.getScaleFactors(null) != flt);
+    harness.check(Arrays.equals(op.getScaleFactors(null),
+                                new float[]{1, 2, 3, 4, 5}));
+    
+    // Mismatched array sizes...
+    op = new RescaleOp(flt, new float[]{1, 2}, null);
+    harness.check(op.getScaleFactors(null).length == 2);
+    harness.check(op.getScaleFactors(null)[0] == 1);
+    harness.check(op.getScaleFactors(null)[1] == 2);
+    
+    // Try passing in an array to be populated
+    op = new RescaleOp(flt, flt, null);
+    float[] arr = new float[5];
+    harness.check(Arrays.equals(op.getScaleFactors(arr), arr));
+    harness.check(Arrays.equals(arr, flt));
+    
+    // What if the array is too big?
+    arr = new float[10];
+    Arrays.fill(arr, 25);
+    op.getScaleFactors(arr);
+    for (int i = 0; i < 5; i++)
+      harness.check(arr[i] == flt[i]);
+    for (int i = 5; i < arr.length; i++)
+      harness.check(arr[i] == 25);
+    
+    // What if array is too small?
+    arr = new float[2];
+    try
+    {
+      harness.check(op.getScaleFactors(arr).length == 2);
+      harness.check(op.getScaleFactors(arr)[0] == 1);
+      harness.check(op.getScaleFactors(arr)[1] == 2);
+    }
+    catch (ArrayIndexOutOfBoundsException ex)
+    {
+      harness.check(false);
+    }
+  }
+}
Index: gnu/testlet/java/awt/image/RescaleOp/getBounds2D.java
===================================================================
RCS file: gnu/testlet/java/awt/image/RescaleOp/getBounds2D.java
diff -N gnu/testlet/java/awt/image/RescaleOp/getBounds2D.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/java/awt/image/RescaleOp/getBounds2D.java	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,91 @@
+/* getBounds2D.java -- some checks for the getBounds2D() methods in the
+       RescaleOp class.
+   Copyright (C) 2006 David Gilbert <david.gilbert@object-refinery.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.4
+
+package gnu.testlet.java.awt.image.RescaleOp;
+
+import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
+
+import java.awt.geom.Rectangle2D;
+import java.awt.image.BufferedImage;
+import java.awt.image.DataBuffer;
+import java.awt.image.MultiPixelPackedSampleModel;
+import java.awt.image.Raster;
+import java.awt.image.RescaleOp;
+
+public class getBounds2D implements Testlet
+{
+  public void test(TestHarness harness)
+  {
+    testMethod1(harness);
+    testMethod2(harness);
+  }
+  
+  public void testMethod1(TestHarness harness)
+  {
+    harness.checkPoint("(BufferedImage)");
+    BufferedImage image = new BufferedImage(10, 20, 
+            BufferedImage.TYPE_INT_ARGB);
+    RescaleOp op = new RescaleOp(1, 1, null);
+    Rectangle2D bounds = op.getBounds2D(image);
+    harness.check(bounds.getWidth(), 10);
+    harness.check(bounds.getHeight(), 20);
+    
+    // try null argument
+    boolean pass = false;
+    try
+    {
+      op.getBounds2D((BufferedImage) null);
+    }
+    catch (NullPointerException e)
+    {
+      pass = true;
+    }
+    harness.check(pass);
+  }
+  
+  public void testMethod2(TestHarness harness)
+  {
+    harness.checkPoint("(Raster)");    
+    RescaleOp op = new RescaleOp(1, 1, null);
+    Raster raster = Raster.createWritableRaster(
+            new MultiPixelPackedSampleModel(DataBuffer.TYPE_BYTE, 10, 20, 8), 
+            null);
+    Rectangle2D bounds = op.getBounds2D(raster);
+    harness.check(bounds.getWidth(), 10);
+    harness.check(bounds.getHeight(), 20);
+    
+    // try null argument
+    boolean pass = false;
+    try
+    {
+      op.getBounds2D((Raster) null);
+    }
+    catch (NullPointerException e)
+    {
+      pass = true;
+    }
+    harness.check(pass);
+  }
+}
Index: gnu/testlet/java/awt/image/RescaleOp/createCompatibleDestImage.java
===================================================================
RCS file: gnu/testlet/java/awt/image/RescaleOp/createCompatibleDestImage.java
diff -N gnu/testlet/java/awt/image/RescaleOp/createCompatibleDestImage.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/java/awt/image/RescaleOp/createCompatibleDestImage.java	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,120 @@
+/* createCompatibleDestImage.java -- some checks for the
+       createCompatibleDestImage() method of the RescaleOp 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.RescaleOp;
+
+import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
+
+import java.awt.image.BufferedImage;
+import java.awt.image.DirectColorModel;
+import java.awt.image.RescaleOp;
+
+/**
+ * Checks for the createCompatibleDestImage method in the
+ * {@link RescaleOp} class.
+ */
+public class createCompatibleDestImage implements Testlet 
+{
+
+  /**
+   * Runs the test using the specified harness.
+   * 
+   * @param harness  the test harness (<code>null</code> not permitted). 
+   */
+  public void test(TestHarness harness)      
+  {
+    simpleTest(harness);
+    colorModelTest(harness);
+  }
+  
+  private void simpleTest(TestHarness harness)
+  {
+    harness.checkPoint("createCompatibleDestImage");
+
+    // Simple test
+    RescaleOp op = new RescaleOp(1, 1, null);
+    
+    BufferedImage img = new BufferedImage(25, 40, BufferedImage.TYPE_INT_RGB);
+    
+    BufferedImage dest = op.createCompatibleDestImage(img, img.getColorModel());
+    
+    harness.check(dest.getHeight(), 40);
+    harness.check(dest.getWidth(), 25);
+    harness.check(dest.getColorModel(), img.getColorModel());
+    
+    // Try a different colour model
+    img = new BufferedImage(25, 40, BufferedImage.TYPE_INT_RGB);
+    DirectColorModel cm = new DirectColorModel(16, 0x0f00, 0x00f0, 0x000f);
+    dest = op.createCompatibleDestImage(img, cm);
+    
+    harness.check(dest.getHeight(), 40);
+    harness.check(dest.getWidth(), 25);
+    harness.check(dest.getColorModel(), cm);
+  }
+  
+  // Test all the default color models
+  private void colorModelTest(TestHarness harness)
+  {
+    RescaleOp op = new RescaleOp(1, 1, null);
+
+    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);
+        
+        // Unlike most Ops, this one creates a clone of the original image
+        harness.check(dest.getColorModel().getPixelSize(),
+                      img.getColorModel().getPixelSize());
+        harness.check(dest.getColorModel().getTransferType(), img.getColorModel().getTransferType());
+
+        harness.check(dest.getColorModel().getClass() == img.getColorModel().getClass());
+        harness.check(dest.getSampleModel().getClass() == img.getSampleModel().getClass());
+        harness.check(dest.getColorModel().getNumComponents(), img.getColorModel().getNumComponents());
+        harness.check(dest.getColorModel().getTransparency(), img.getColorModel().getTransparency());
+        harness.check(dest.getColorModel().hasAlpha(), img.getColorModel().hasAlpha());
+        harness.check(dest.getColorModel().isAlphaPremultiplied(), img.getColorModel().isAlphaPremultiplied());
+        harness.check(dest.getColorModel().getColorSpace().getType(), img.getColorModel().getColorSpace().getType());
+        harness.check(dest.getRaster().getNumBands(), img.getRaster().getNumBands());
+        harness.check(dest.getRaster().getNumDataElements(), img.getRaster().getNumDataElements());
+        harness.check(dest.getType(), img.getType());
+      }
+  }
+}
+ 
Index: gnu/testlet/java/awt/image/RescaleOp/constructors.java
===================================================================
RCS file: gnu/testlet/java/awt/image/RescaleOp/constructors.java
diff -N gnu/testlet/java/awt/image/RescaleOp/constructors.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/java/awt/image/RescaleOp/constructors.java	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,163 @@
+/* constructors.java -- some checks for the constructors in the 
+       RescaleOp 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.RescaleOp;
+
+import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
+
+import java.awt.image.RescaleOp;
+import java.util.Arrays;
+
+/**
+ * Some checks for the constructors in the {@link RescaleOp} class.
+ */
+public class constructors implements Testlet 
+{
+
+  /**
+   * Runs the test using the specified harness.
+   * 
+   * @param harness  the test harness (<code>null</code> not permitted). 
+   */
+  public void test(TestHarness harness)      
+  {
+    testConstructor1(harness);
+    testConstructor2(harness);
+  }
+  
+  public void testConstructor1(TestHarness harness)
+  {
+    harness.checkPoint("(float[], float[], RenderingHints)");
+
+    // Simple test
+    float[] scale = new float[] {0.6f};
+    float[] offset = new float[] {1.1f};
+    RescaleOp op = new RescaleOp(scale, offset, null);
+    
+    harness.check(Arrays.equals(op.getScaleFactors(null), scale));
+    harness.check(Arrays.equals(op.getOffsets(null), offset));
+    
+    harness.check(op.getRenderingHints(), null);
+
+    scale = new float[] {0.6f, 1.2f, 5.6f, 2.2f};
+    offset = new float[] {1.1f, 3f, 2.7f, 8.0f};
+    op = new RescaleOp(scale, offset, null);
+    
+    harness.check(Arrays.equals(op.getScaleFactors(null), scale));
+    harness.check(Arrays.equals(op.getOffsets(null), offset));
+    harness.check(op.getRenderingHints(), null);
+
+    // Null arguments
+    try
+    {
+      op = new RescaleOp(null, offset, null);
+      harness.check(false);
+    }
+    catch (NullPointerException e)
+    {
+      harness.check(true);
+    }
+    
+    try
+    {
+      op = new RescaleOp(scale, null, null);
+      harness.check(false);
+    }
+    catch (NullPointerException e)
+    {
+      harness.check(true);
+    }
+    
+    try
+    {
+      op = new RescaleOp(null, null, null);
+      harness.check(false);
+    }
+    catch (NullPointerException e)
+    {
+      harness.check(true);
+    }
+    
+    // Empty arrays
+    try
+    {
+      op = new RescaleOp(new float[]{}, new float[]{}, null);
+      harness.check(true);
+    }
+    catch (NullPointerException e)
+    {
+      harness.check(false);
+    }
+    
+    // Mis-matched array lengths are allowed for now
+    scale = new float[] {1f, 2f, 3f, 4f, 5f, 6f};
+    offset = new float[] {1f, 2f, 3f};
+    try
+    {
+      op = new RescaleOp(scale, offset, null);
+      harness.check(true);
+    }
+    catch (IllegalArgumentException ex)
+    {
+      harness.check(false);
+    }
+    
+    // Negative values
+    scale = new float[] {1f, -2f};
+    offset = new float[] {2f, -1f,};
+    try
+    {
+      op = new RescaleOp(scale, offset, null);
+      harness.check(true);
+    }
+    catch (IllegalArgumentException ex)
+    {
+      harness.check(false);
+    }
+  }
+
+  public void testConstructor2(TestHarness harness)
+  {
+    harness.checkPoint("(float, float, RenderingHints)");
+
+    // Simple test
+    RescaleOp op = new RescaleOp(2f, 6.5f, null);
+    
+    harness.check(Arrays.equals(op.getScaleFactors(null), new float[]{2f}));
+    harness.check(Arrays.equals(op.getOffsets(null), new float[]{6.5f}));
+    harness.check(op.getRenderingHints(), null);
+    
+    // Negative values
+    try
+    {
+      op = new RescaleOp(-5f, -2f, null);
+      harness.check(true);
+    }
+    catch (IllegalArgumentException ex)
+    {
+      harness.check(false);
+    }
+  }
+}
+
Index: gnu/testlet/java/awt/image/RescaleOp/filterImage.java
===================================================================
RCS file: gnu/testlet/java/awt/image/RescaleOp/filterImage.java
diff -N gnu/testlet/java/awt/image/RescaleOp/filterImage.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/java/awt/image/RescaleOp/filterImage.java	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,320 @@
+/* filterImage.java -- some checks for the filter(Image) method of the
+              RescaleOp 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.RescaleOp;
+
+import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
+
+import java.awt.image.BufferedImage;
+import java.awt.image.RescaleOp;
+import java.awt.image.WritableRaster;
+
+/**
+ * Checks the filter(BufferedImage) method in the {@link RescaleOp} class.
+ */
+public class filterImage implements Testlet
+{
+
+  /**
+   * Runs the test using the specified harness.
+   * 
+   * @param harness  the test harness (<code>null</code> not permitted). 
+   */
+  public void test(TestHarness harness)      
+  {
+    simpleTests(harness);
+    test1(harness);
+    test2(harness);
+    test3(harness);
+    testMismatch(harness);
+  }
+
+  private void simpleTests(TestHarness harness)
+  {
+    harness.checkPoint("filter(BufferedImage)");
+    
+    // Create an image to work on
+    BufferedImage img = new BufferedImage(20, 20, BufferedImage.TYPE_USHORT_GRAY);
+    WritableRaster r = img.getRaster();
+    r.setSample(1, 1, 0, 150);
+    
+    RescaleOp op = new RescaleOp(1, 1, null);
+    
+    // Src and dst images can be the same
+    try
+    {
+      op.filter(img, img);
+      harness.check(true);
+    }
+    catch (IllegalArgumentException e)
+    {
+      harness.check(false);
+    }
+    
+    // Src and dst use different colorspaces (allowed, will cause implied
+    // conversion)
+    BufferedImage dst = new BufferedImage(20, 20, BufferedImage.TYPE_INT_RGB);
+    try
+    {
+      op.filter(img, dst);
+      harness.check(true);
+    }
+    catch (IllegalArgumentException e)
+    {
+      harness.check(false);
+    }
+    
+    // Src and dst are different sizes (not allowed, unlike some other Ops)
+    dst = new BufferedImage(30, 40, BufferedImage.TYPE_USHORT_GRAY);
+    try
+    {
+      op.filter(img, dst);
+      harness.check(false);
+    }
+    catch (IllegalArgumentException e)
+    {
+      harness.check(true);
+    }
+    
+    // Null destination check
+    dst = op.filter(img, null);
+    harness.check(dst.getType(),
+                  op.createCompatibleDestImage(img, null).getType());
+    
+    // Test positive & negative clipping behaviour
+    img.getRaster().setSample(1, 1, 0, 1500);
+    op = new RescaleOp(100, 0, null);
+    dst = op.filter(img, null);
+    double maxValue = Math.pow(2, img.getColorModel().getComponentSize(0)) - 1;
+    harness.check(dst.getRaster().getSample(1, 1, 0), maxValue);
+    
+    op = new RescaleOp(1, -2000, null);
+    dst = op.filter(img, null);
+    harness.check(dst.getRaster().getSample(1, 1, 0), 0);
+  }
+  
+  private void test1(TestHarness harness)
+  {
+    harness.checkPoint("filter(BufferedImage) with one scaling factor");
+  
+    // Create an image to work on
+    BufferedImage img = new BufferedImage(20, 20, BufferedImage.TYPE_INT_ARGB);
+    WritableRaster r = img.getRaster();
+    r.setSample(1, 1, 0, 150);
+    r.setSample(1, 1, 1, 160);
+    r.setSample(1, 1, 2, 175);
+    r.setSample(1, 1, 3, 195);
+    
+    r.setSample(1, 3, 0, 45);
+    r.setSample(1, 3, 1, 60);
+    r.setSample(1, 3, 2, 70);
+    r.setSample(1, 3, 3, 90);
+    
+    RescaleOp op = new RescaleOp(0.75f, 25f, null);
+    BufferedImage dst = op.filter(img, null);
+    WritableRaster dest = dst.getRaster();
+    
+    harness.check(dest.getSample(1, 1, 0), 137);    //rounded down from 137.5
+    harness.check(dest.getSample(1, 1, 1), 145);
+    
+    harness.check(dest.getSample(1, 3, 0), 58);     //rounded down from 58.75
+    harness.check(dest.getSample(1, 3, 1), 70);
+    /*
+    // Again, Sun does RGAB whereas we do RGBA =(
+    // So, for Sun:
+    harness.check(dest.getSample(1, 1, 2), 175);
+    harness.check(dest.getSample(1, 1, 3), 171);    //rounded down from 171.25
+    harness.check(dest.getSample(1, 3, 2), 70);
+    harness.check(dest.getSample(1, 3, 3), 92);     //rounded down from 92.5 
+    
+    // For classpath:
+    harness.check(dest.getSample(1, 1, 2), 156);    //rounded down from 156.25 
+    harness.check(dest.getSample(1, 1, 3), 195);
+    harness.check(dest.getSample(1, 3, 2), 77);     //rounded down from 77.5
+    harness.check(dest.getSample(1, 3, 3), 90);
+    */
+  }
+  
+  private void test2(TestHarness harness)
+  {
+    harness.checkPoint("filter(BufferedImage) with num factors == num " +
+            "color components");
+    
+    // Create an image to work on
+    BufferedImage img = new BufferedImage(20, 20, BufferedImage.TYPE_INT_ARGB);
+    WritableRaster r = img.getRaster();
+    r.setSample(1, 1, 0, 10);
+    r.setSample(1, 1, 1, 20);
+    r.setSample(1, 1, 2, 35);
+    r.setSample(1, 1, 3, 40);
+    
+    r.setSample(1, 3, 0, 45);
+    r.setSample(1, 3, 1, 60);
+    r.setSample(1, 3, 2, 70);
+    r.setSample(1, 3, 3, 90);
+    
+    RescaleOp op = new RescaleOp(new float[]{0.75f, 2.5f, 1f},
+                                 new float[]{25f, 2f, 1.5f},
+                                 null);
+    
+    /* This causes Sun to throw an exception...
+     * 
+     * java.lang.IllegalArgumentException: Number of channels in the src (4)
+     * does not match number of channels in the destination (2)
+     * 
+     * I'm pretty sure it's a bug, but it's not one that's worth mimicing.
+     * This test will not run on Sun.
+     */ 
+    try
+    {
+      BufferedImage dst = op.filter(img, null);
+      WritableRaster dest = dst.getRaster();
+      
+      harness.check(dest.getSample(1, 1, 0), 32);   //rounded down from 32.5
+      harness.check(dest.getSample(1, 1, 1), 52);
+      
+      harness.check(dest.getSample(1, 3, 0), 58);   //rounded down from 58.75
+      harness.check(dest.getSample(1, 3, 1), 152);
+      /*
+      // Again, Sun does RGAB whereas we do RGBA =(
+      // So, for Sun:
+      harness.check(dest.getSample(1, 1, 2), 35);
+      harness.check(dest.getSample(1, 1, 3), 41.5);
+      harness.check(dest.getSample(1, 3, 2), 70);
+      harness.check(dest.getSample(1, 3, 3), 91.5);
+      */
+      // For classpath:
+      harness.check(dest.getSample(1, 1, 2), 36);   //rounded down from 36.5
+      harness.check(dest.getSample(1, 1, 3), 40);
+      harness.check(dest.getSample(1, 3, 2), 71);   //rounded down from 71.5
+      harness.check(dest.getSample(1, 3, 3), 90);
+      
+    }
+    catch (IllegalArgumentException ex)
+    {
+      harness.debug("Test did not run - this is expected on Sun due to a " +
+            "bug in their implementation, but this message should not show " +
+            "when testing Classpath.");
+    }
+  }
+  
+  private void test3(TestHarness harness)
+  {
+    harness.checkPoint("filter(BufferedImage) with num factors == num " +
+            "components");
+
+    // Create an image to work on
+    BufferedImage img = new BufferedImage(20, 20, BufferedImage.TYPE_INT_ARGB);
+    WritableRaster r = img.getRaster();
+    r.setSample(1, 1, 0, 10);
+    r.setSample(1, 1, 1, 20);
+    r.setSample(1, 1, 2, 35);
+    r.setSample(1, 1, 3, 40);
+    
+    r.setSample(1, 3, 0, 45);
+    r.setSample(1, 3, 1, 60);
+    r.setSample(1, 3, 2, 70);
+    r.setSample(1, 3, 3, 90);
+    
+    RescaleOp op = new RescaleOp(new float[]{0.75f, 2.5f, -1f, 0f},
+                                 new float[]{25f, 2f, 1f, 0f},
+                                 null);
+    BufferedImage dst = op.filter(img, null);
+    WritableRaster dest = dst.getRaster();
+    
+    harness.check(dest.getSample(1, 1, 0), 32);     //rounded down from 32.5 
+    harness.check(dest.getSample(1, 1, 1), 52);
+    harness.check(dest.getSample(1, 1, 2), 0);
+    harness.check(dest.getSample(1, 1, 3), 0);
+    
+    harness.check(dest.getSample(1, 3, 0), 58);     //rounded down from 58.75
+    harness.check(dest.getSample(1, 3, 1), 152);
+    harness.check(dest.getSample(1, 3, 2), 0);
+    harness.check(dest.getSample(1, 3, 3), 0);
+  }
+  
+  private void testMismatch(TestHarness harness)
+  {
+    harness.checkPoint("filter(BufferedImage) with mismatched arrays");
+
+    // Create an image to work on
+    BufferedImage img = new BufferedImage(20, 20, BufferedImage.TYPE_INT_ARGB);
+    WritableRaster r = img.getRaster();
+    r.setSample(1, 1, 0, 10);
+    r.setSample(1, 1, 1, 20);
+    r.setSample(1, 1, 2, 35);
+    r.setSample(1, 1, 3, 40);
+    
+    r.setSample(1, 3, 0, 45);
+    r.setSample(1, 3, 1, 60);
+    r.setSample(1, 3, 2, 70);
+    r.setSample(1, 3, 3, 90);
+
+    // Test mismatched arrays
+    RescaleOp op = new RescaleOp(new float[]{1, 2, 3, 4}, new float[]{1, 2}, null);
+    try
+    {
+      op.filter(img, null);
+      harness.check(false);
+    }
+    catch (IllegalArgumentException ex)
+    {
+      harness.check(true);
+    }
+    
+    // Only the first value from both arrays is read if the offsets array
+    // has only one value
+    op = new RescaleOp(new float[]{1, 2, 3, 4}, new float[]{1}, null);
+    try
+    {
+      BufferedImage dst = op.filter(img, null);
+      WritableRaster dest = dst.getRaster();
+      harness.check(dest.getSample(1, 1, 0), 11);
+      harness.check(dest.getSample(1, 1, 1), 21);
+      harness.check(dest.getSample(1, 3, 0), 46);
+      harness.check(dest.getSample(1, 3, 1), 61);
+    }
+    catch (IllegalArgumentException ex)
+    {
+      harness.check(false);
+    }
+    
+    // Same with a single-length factors array
+    op = new RescaleOp(new float[]{0.5f}, new float[]{2, 3, 4, 5}, null);
+    try
+    {
+      BufferedImage dst = op.filter(img, null);
+      WritableRaster dest = dst.getRaster();
+      harness.check(dest.getSample(1, 1, 0), 7);
+      harness.check(dest.getSample(1, 1, 1), 12);
+      harness.check(dest.getSample(1, 3, 0), 24);
+      harness.check(dest.getSample(1, 3, 1), 32);
+    }
+    catch (IllegalArgumentException ex)
+    {
+      harness.check(false);
+    }
+  }
+}
+
Index: gnu/testlet/java/awt/image/RescaleOp/getRenderingHints.java
===================================================================
RCS file: gnu/testlet/java/awt/image/RescaleOp/getRenderingHints.java
diff -N gnu/testlet/java/awt/image/RescaleOp/getRenderingHints.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/java/awt/image/RescaleOp/getRenderingHints.java	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,44 @@
+/* getRenderingHints.java -- some checks for the getRenderingHints() method
+       in the RescaleOp class.
+   Copyright (C) 2006 David Gilbert <david.gilbert@object-refinery.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.4
+
+package gnu.testlet.java.awt.image.RescaleOp;
+
+import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
+
+import java.awt.RenderingHints;
+import java.awt.image.RescaleOp;
+
+public class getRenderingHints implements Testlet 
+{
+  public void test(TestHarness harness)
+  {
+    RenderingHints r = new RenderingHints(RenderingHints.KEY_COLOR_RENDERING,
+            RenderingHints.VALUE_COLOR_RENDER_QUALITY);
+    RescaleOp op = new RescaleOp(1, 1, r);
+    harness.check(op.getRenderingHints() == r);
+    op = new RescaleOp(1, 1, null);
+    harness.check(op.getRenderingHints() == null);
+  }
+}
Index: gnu/testlet/java/awt/image/RescaleOp/createCompatibleDestRaster.java
===================================================================
RCS file: gnu/testlet/java/awt/image/RescaleOp/createCompatibleDestRaster.java
diff -N gnu/testlet/java/awt/image/RescaleOp/createCompatibleDestRaster.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/java/awt/image/RescaleOp/createCompatibleDestRaster.java	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,90 @@
+/* createCompatibleDestRaster.java -- some checks for the
+              createCompatibleDestRaster() method of the RescaleOp 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.RescaleOp;
+
+import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
+
+import java.awt.Point;
+import java.awt.image.DataBuffer;
+import java.awt.image.MultiPixelPackedSampleModel;
+import java.awt.image.Raster;
+import java.awt.image.RescaleOp;
+
+/**
+ * Checks for the createCompatibleDestRaster method in the
+ * {@link RescaleOp} 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)      
+  {
+    RescaleOp op = new RescaleOp(1, 1, null);
+    Raster raster = Raster.createWritableRaster(
+        new MultiPixelPackedSampleModel(DataBuffer.TYPE_BYTE, 10, 20, 8), null);
+    Raster dest = op.createCompatibleDestRaster(raster);
+    harness.check(dest.getWidth(), 10);
+    harness.check(dest.getHeight(), 20);
+    harness.check(dest.getNumBands(), 1);
+    harness.check(dest.getSampleModel() instanceof MultiPixelPackedSampleModel);
+    harness.check(dest.getTransferType(), raster.getTransferType());
+    harness.check(dest.getDataBuffer().getDataType(), raster.getDataBuffer().getDataType());
+    harness.check(dest.getNumDataElements(), raster.getNumDataElements());
+  
+    // try null argument
+    boolean pass = false;
+    try
+    {
+      op.createCompatibleDestRaster(null);
+    }
+    catch (NullPointerException e)
+    {
+      pass = true;
+    }
+    harness.check(pass);
+    
+    // Try a different type
+    raster = Raster.createBandedRaster(DataBuffer.TYPE_BYTE, 25, 40, 3, new Point(5, 5));
+    Raster dst = op.createCompatibleDestRaster(raster);
+    harness.check(dst.getNumBands(), raster.getNumBands());
+    harness.check(dst.getTransferType(), raster.getTransferType());
+    harness.check(dst.getDataBuffer().getDataType(), raster.getDataBuffer().getDataType());
+    harness.check(dst.getNumDataElements(), raster.getNumDataElements());
+    
+    // Try a different number of bands
+    raster = Raster.createBandedRaster(DataBuffer.TYPE_INT, 25, 40, 5, new Point(5, 5));
+    dst = op.createCompatibleDestRaster(raster);
+    harness.check(dst.getNumBands(), raster.getNumBands());
+    harness.check(dst.getTransferType(), raster.getTransferType());
+    harness.check(dst.getDataBuffer().getDataType(), raster.getDataBuffer().getDataType());
+    harness.check(dst.getNumDataElements(), raster.getNumDataElements());
+  }
+}
+
Index: gnu/testlet/java/awt/image/RescaleOp/getPoint2D.java
===================================================================
RCS file: gnu/testlet/java/awt/image/RescaleOp/getPoint2D.java
diff -N gnu/testlet/java/awt/image/RescaleOp/getPoint2D.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/java/awt/image/RescaleOp/getPoint2D.java	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,55 @@
+/* getPoint2D.java -- some checks for the getPoint2D() method in the RescaleOp
+       class.
+   Copyright (C) 2006 David Gilbert <david.gilbert@object-refinery.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.4
+
+package gnu.testlet.java.awt.image.RescaleOp;
+
+import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
+
+import java.awt.geom.Point2D;
+import java.awt.image.RescaleOp;
+
+public class getPoint2D implements Testlet
+{
+  public void test(TestHarness harness)
+  {
+    RescaleOp op = new RescaleOp(1, 1, null);
+    Point2D p = new Point2D.Double(1.0, 2.0);
+    Point2D pp = new Point2D.Double();
+    Point2D p1 = op.getPoint2D(p, pp);
+    harness.check(p1, p);
+    harness.check(p1 == pp);
+    harness.check(p1 != p);
+    
+    // try null dest
+    p1 = op.getPoint2D(p, null);
+    harness.check(p1, p);
+    harness.check(p1 != p); 
+    
+    // try src == dst
+    p1 = op.getPoint2D(p, p);
+    harness.check(p1, p);
+    harness.check(p1 == p);
+  }
+}
Index: gnu/testlet/java/awt/image/RescaleOp/getNumFactors.java
===================================================================
RCS file: gnu/testlet/java/awt/image/RescaleOp/getNumFactors.java
diff -N gnu/testlet/java/awt/image/RescaleOp/getNumFactors.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/java/awt/image/RescaleOp/getNumFactors.java	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,75 @@
+/* getNumFactors.java -- some checks for the getNumFactors() method of the
+              RescaleOp 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.RescaleOp;
+
+import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
+
+import java.awt.image.RescaleOp;
+
+/**
+ * Checks the getNumFactors method in the
+ * {@link RescaleOp} class.
+ */
+public class getNumFactors 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("getNumFactors");
+
+    RescaleOp op = new RescaleOp(1.5f, 2.3f, null);
+    harness.check(op.getNumFactors(), 1);
+    
+    op = new RescaleOp(new float[]{1.5f}, new float[]{2.3f}, null);
+    harness.check(op.getNumFactors(), 1);
+   
+    op = new RescaleOp(new float[]{1.5f, 2.5f}, new float[]{2.3f, 6.6f}, null);
+    harness.check(op.getNumFactors(), 2);
+    
+    op = new RescaleOp(new float[]{1.5f, 2.2f, 3.7f},
+                       new float[]{2.3f, 2.3f, 2.3f},
+                       null);
+    harness.check(op.getNumFactors(), 3);
+    
+    op = new RescaleOp(new float[]{}, new float[]{}, null);
+    harness.check(op.getNumFactors(), 0);
+    
+    // If the arrays are mismatched, return the lower value
+    op = new RescaleOp(new float[]{1, 2, 3}, new float[]{1}, null);
+    harness.check(op.getNumFactors(), 1);
+    op = new RescaleOp(new float[]{1}, new float[]{1, 2, 3}, null);
+    harness.check(op.getNumFactors(), 1);
+    op = new RescaleOp(new float[]{1, 2}, new float[]{1, 2, 3}, null);
+    harness.check(op.getNumFactors(), 2);
+    op = new RescaleOp(new float[]{1, 2, 3}, new float[]{1, 2}, null);
+    harness.check(op.getNumFactors(), 2);
+  }
+}
+
Index: gnu/testlet/java/awt/image/RescaleOp/filterRaster.java
===================================================================
RCS file: gnu/testlet/java/awt/image/RescaleOp/filterRaster.java
diff -N gnu/testlet/java/awt/image/RescaleOp/filterRaster.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/java/awt/image/RescaleOp/filterRaster.java	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,227 @@
+/* filterRaster.java -- some checks for the filter() methods in the
+                        RescaleOp 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.4
+
+package gnu.testlet.java.awt.image.RescaleOp;
+
+import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
+
+import java.awt.image.BufferedImage;
+import java.awt.image.DataBuffer;
+import java.awt.image.RescaleOp;
+import java.awt.image.WritableRaster;
+
+public class filterRaster implements Testlet
+{
+  public void test(TestHarness harness)
+  {
+    simpleTests(harness);
+    testRaster1(harness);
+    testRaster2(harness);
+    testMismatch(harness);
+  }
+  
+  private void simpleTests(TestHarness harness)
+  {
+    harness.checkPoint("filter(Raster)");
+    
+    // Create an image to work on
+    BufferedImage img = new BufferedImage(20, 20, BufferedImage.TYPE_USHORT_GRAY);
+    WritableRaster r = img.getRaster();
+    r.setSample(1, 1, 0, 150);
+    
+    RescaleOp op = new RescaleOp(1, 1, null);
+    
+    // Src and dst rasters can be the same
+    try
+    {
+      op.filter(r, r);
+      harness.check(true);
+    }
+    catch (IllegalArgumentException e)
+    {
+      harness.check(false);
+    }
+    
+    // Src and dst are different sizes (not allowed, unlike some other Ops)
+    BufferedImage dst = new BufferedImage(30, 40, BufferedImage.TYPE_INT_RGB);
+    try
+    {
+      op.filter(r, dst.getRaster());
+      harness.check(false);
+    }
+    catch (IllegalArgumentException e)
+    {
+      harness.check(true);
+    }
+    
+    // Null destination check
+    WritableRaster dstRast = op.filter(r, null);
+    harness.check(dstRast.getHeight(), r.getHeight());
+    harness.check(dstRast.getWidth(), r.getWidth());
+    harness.check(dstRast.getMinX(), r.getMinX());
+    harness.check(dstRast.getMinY(), r.getMinY());
+    harness.check(dstRast.getNumBands(), r.getNumBands());
+    harness.check(dstRast.getNumDataElements(), r.getNumDataElements());
+    harness.check(dstRast.getTransferType(), r.getTransferType());
+    harness.check(dstRast.getBounds(), r.getBounds());
+    harness.check(dstRast.getDataBuffer().getClass(), r.getDataBuffer().getClass());
+    
+    // Test positive & negative clipping behaviour
+    img.getRaster().setSample(1, 1, 0, 1500);
+    op = new RescaleOp(100, 0, null);
+    dstRast = op.filter(r, null);
+    double maxValue = Math.pow(2, DataBuffer.getDataTypeSize(r.getDataBuffer().getDataType())) - 1;
+    harness.check(dstRast.getSample(1, 1, 0), maxValue);
+    
+    op = new RescaleOp(1, -2000, null);
+    dstRast = op.filter(r, null);
+    harness.check(dstRast.getSample(1, 1, 0), 0);
+  }
+  
+  public void testRaster1(TestHarness harness)
+  {
+    harness.checkPoint("filter(Raster) with one scaling factor");
+
+    // Create a raster to work on
+    BufferedImage img = new BufferedImage(20, 20, BufferedImage.TYPE_INT_ARGB);
+    WritableRaster r = img.getRaster();
+    r.setSample(1, 1, 0, 150);
+    r.setSample(1, 1, 1, 160);
+    r.setSample(1, 1, 2, 175);
+    r.setSample(1, 1, 3, 195);
+    
+    r.setSample(1, 3, 0, 45);
+    r.setSample(1, 3, 1, 60);
+    r.setSample(1, 3, 2, 70);
+    r.setSample(1, 3, 3, 90);
+    
+    RescaleOp op = new RescaleOp(0.75f, 25f, null);
+    WritableRaster dest = op.filter(r, null);
+    
+    harness.check(dest.getSample(1, 1, 0), 137);    //rounded down from 137.5
+    harness.check(dest.getSample(1, 1, 1), 145);
+    harness.check(dest.getSample(1, 1, 3), 171);    //rounded down from 171.25
+    harness.check(dest.getSample(1, 1, 2), 156);    //rounded down from 156.25 
+    
+    harness.check(dest.getSample(1, 3, 0), 58);     //rounded down from 58.75
+    harness.check(dest.getSample(1, 3, 1), 70);
+    harness.check(dest.getSample(1, 3, 2), 77);     //rounded down from 77.5
+    harness.check(dest.getSample(1, 3, 3), 92);     //rounded down from 92.5 
+  }
+    
+  public void testRaster2(TestHarness harness)
+  {
+    harness.checkPoint("filter(Raster) with multiple factors");
+
+    // Create an image to work on
+    BufferedImage img = new BufferedImage(20, 20, BufferedImage.TYPE_INT_ARGB);
+    WritableRaster r = img.getRaster();
+    r.setSample(1, 1, 0, 10);
+    r.setSample(1, 1, 1, 20);
+    r.setSample(1, 1, 2, 35);
+    r.setSample(1, 1, 3, 40);
+    
+    r.setSample(1, 3, 0, 45);
+    r.setSample(1, 3, 1, 60);
+    r.setSample(1, 3, 2, 70);
+    r.setSample(1, 3, 3, 90);
+    
+    RescaleOp op = new RescaleOp(new float[]{0.75f, 2.5f, -1f, 0f},
+                             new float[]{25f, 2f, 1f, 0f},
+                             null);
+    WritableRaster dest = op.filter(r, null);
+    
+    harness.check(dest.getSample(1, 1, 0), 32);     //rounded down from 32.5 
+    harness.check(dest.getSample(1, 1, 1), 52);
+    harness.check(dest.getSample(1, 1, 2), 0);
+    harness.check(dest.getSample(1, 1, 3), 0);
+    
+    harness.check(dest.getSample(1, 3, 0), 58);     //rounded down from 58.75
+    harness.check(dest.getSample(1, 3, 1), 152);
+    harness.check(dest.getSample(1, 3, 2), 0);
+    harness.check(dest.getSample(1, 3, 3), 0);
+  }
+  
+  private void testMismatch(TestHarness harness)
+  {
+    harness.checkPoint("filter(Raster) with mismatched arrays");
+
+    // Create an image to work on
+    BufferedImage img = new BufferedImage(20, 20, BufferedImage.TYPE_INT_ARGB);
+    WritableRaster r = img.getRaster();
+    r.setSample(1, 1, 0, 10);
+    r.setSample(1, 1, 1, 20);
+    r.setSample(1, 1, 2, 35);
+    r.setSample(1, 1, 3, 40);
+    
+    r.setSample(1, 3, 0, 45);
+    r.setSample(1, 3, 1, 60);
+    r.setSample(1, 3, 2, 70);
+    r.setSample(1, 3, 3, 90);
+
+    // Test mismatched arrays
+    RescaleOp op = new RescaleOp(new float[]{1, 2, 3, 4}, new float[]{1, 2, 3}, null);
+    try
+    {
+      op.filter(r, null);
+      harness.check(false);
+    }
+    catch (IllegalArgumentException ex)
+    {
+      harness.check(true);
+    }
+    
+    // Only the first value from both arrays is read if the offsets array
+    // has only one value
+    op = new RescaleOp(new float[]{1, 2, 3, 4}, new float[]{1}, null);
+    try
+    {
+      WritableRaster dest = op.filter(r, null);
+      harness.check(dest.getSample(1, 1, 0), 11);
+      harness.check(dest.getSample(1, 1, 1), 21);
+      harness.check(dest.getSample(1, 3, 0), 46);
+      harness.check(dest.getSample(1, 3, 1), 61);
+    }
+    catch (IllegalArgumentException ex)
+    {
+      harness.check(false);
+    }
+    
+    // Same with a single-length factors array
+    op = new RescaleOp(new float[]{0.5f}, new float[]{2, 3, 4, 5}, null);
+    try
+    {
+      WritableRaster dest = op.filter(r, null);
+      harness.check(dest.getSample(1, 1, 0), 7);
+      harness.check(dest.getSample(1, 1, 1), 12);
+      harness.check(dest.getSample(1, 3, 0), 24);
+      harness.check(dest.getSample(1, 3, 1), 32);
+    }
+    catch (IllegalArgumentException ex)
+    {
+      harness.check(false);
+    }
+  }
+}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]