This is the mail archive of the
mauve-patches@sourceware.org
mailing list for the Mauve project.
FYI: Raster.createChild checks
- From: Francis Kung <fkung at redhat dot com>
- To: mauve-patches <mauve-patches at sources dot redhat dot com>
- Date: Tue, 17 Oct 2006 10:47:14 -0400
- Subject: FYI: Raster.createChild checks
Hi,
This patch adds some tests for Raster.createChild,
WritableRaster.createWritableChild, and BufferedImage.getSubimage.
Cheers,
Francis
2006-10-17 Francis Kung <fkung@redhat.com>
* gnu/testlet/java/awt/image/BufferedImage/getSubimage.java,
* gnu/testlet/java/awt/image/Raster/createChild.java,
* gnu/testlet/java/awt/image/WritableRaster/createWritableChild.java:
New tests.
Index: gnu/testlet/java/awt/image/BufferedImage/getSubimage.java
===================================================================
RCS file: gnu/testlet/java/awt/image/BufferedImage/getSubimage.java
diff -N gnu/testlet/java/awt/image/BufferedImage/getSubimage.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/java/awt/image/BufferedImage/getSubimage.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,90 @@
+/* getSubimage.java -- some checks for the getSubimage() method in the
+ BufferedImage 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.BufferedImage;
+
+import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
+
+import java.awt.image.BufferedImage;
+import java.awt.image.RasterFormatException;
+
+public class getSubimage implements Testlet
+{
+ public void test(TestHarness harness)
+ {
+ // Create initial image, fill with data
+ BufferedImage img = new BufferedImage(50, 50, BufferedImage.TYPE_INT_RGB);
+
+ for (int x = 0; x < 50; x++)
+ for (int y = 0; y < 50; y++)
+ for (int b = 0; b < 3; b++)
+ img.getRaster().setSample(x, y, b, x+y+b);
+
+ // Subimage with identical bounds
+ BufferedImage img2 = img.getSubimage(0, 0, 50, 50);
+
+ harness.check(img.getRaster() != img2.getRaster());
+ harness.check(img.getRaster().getDataBuffer(),
+ img2.getRaster().getDataBuffer());
+ harness.check(img.getSampleModel(), img2.getSampleModel());
+ harness.check(img.getColorModel(), img2.getColorModel());
+ harness.check(img2.getMinX(), 0);
+ harness.check(img2.getMinY(), 0);
+ harness.check(img2.getWidth(), 50);
+ harness.check(img2.getHeight(), 50);
+
+ for (int x = 0; x < 50; x++)
+ for (int y = 0; y < 50; y++)
+ for (int b = 0; b < 3; b++)
+ harness.check(img2.getRaster().getSample(x, y, b), x+y+b);
+
+ // Offset subimage with smaller bounds
+ img2 = img.getSubimage(20, 30, 15, 10);
+
+ harness.check(img.getRaster().getDataBuffer(),
+ img2.getRaster().getDataBuffer());
+ harness.check(img.getSampleModel(), img2.getSampleModel());
+ harness.check(img2.getMinX(), 0);
+ harness.check(img2.getMinY(), 0);
+ harness.check(img2.getWidth(), 15);
+ harness.check(img2.getHeight(), 10);
+
+ for (int x = 0; x < 15; x++)
+ for (int y = 0; y < 10; y++)
+ for (int b = 0; b < 3; b++)
+ harness.check(img2.getRaster().getSample(x, y, b), x+20 + y+30 +b);
+
+ // Subimage overflows original image bounds
+ try
+ {
+ img2 = img.getSubimage(40, 40, 20, 20);
+ harness.check(false);
+ }
+ catch (RasterFormatException ex)
+ {
+ harness.check(true);
+ }
+ }
+}
Index: gnu/testlet/java/awt/image/WritableRaster/createWritableChild.java
===================================================================
RCS file: gnu/testlet/java/awt/image/WritableRaster/createWritableChild.java
diff -N gnu/testlet/java/awt/image/WritableRaster/createWritableChild.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/java/awt/image/WritableRaster/createWritableChild.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,172 @@
+/* createWritableChild.java -- some checks for the createWritableChild() method
+ in the WritableRaster 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.WritableRaster;
+
+import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
+
+import java.awt.Point;
+import java.awt.image.DataBuffer;
+import java.awt.image.Raster;
+import java.awt.image.RasterFormatException;
+import java.awt.image.SinglePixelPackedSampleModel;
+import java.awt.image.WritableRaster;
+
+public class createWritableChild implements Testlet
+{
+ public void test(TestHarness harness)
+ {
+ testData(harness);
+ testBounds(harness);
+ testBands(harness);
+ }
+
+ private void testData(TestHarness harness)
+ {
+ WritableRaster rst = createRaster();
+
+ // Child raster
+ WritableRaster rst2 = rst.createWritableChild(10, 20, 25, 15, 0, 0, null);
+ harness.check(rst2.getMinX(), 0);
+ harness.check(rst2.getMinY(), 0);
+ harness.check(rst2.getWidth(), 25);
+ harness.check(rst2.getHeight(), 15);
+
+ for (int x = 0; x < 25; x++)
+ for (int y = 0; y < 15; y++)
+ for (int b = 0; b < 3; b++)
+ harness.check(rst2.getSample(x, y, b), x+10 + y+20 + b);
+
+ // Offset child
+ rst2 = rst.createWritableChild(10, 20, 25, 15, 30, 40, null);
+ harness.check(rst2.getMinX(), 30);
+ harness.check(rst2.getMinY(), 40);
+ harness.check(rst2.getWidth(), 25);
+ harness.check(rst2.getHeight(), 15);
+
+ for (int x = 30; x < 55; x++)
+ for (int y = 40; y < 55; y++)
+ for (int b = 0; b < 3; b++)
+ harness.check(rst2.getSample(x, y, b), x-20 + y-20 + b);
+ }
+
+ private void testBounds(TestHarness harness)
+ {
+ WritableRaster rst = createRaster();
+
+ // Width and height out of bounds
+ try
+ {
+ rst.createChild(10, 20, 100, 100, 0, 0, null);
+ harness.check(false);
+ }
+ catch (RasterFormatException ex)
+ {
+ harness.check(true);
+ }
+ catch (Exception ex)
+ {
+ harness.check(false);
+ }
+
+ // MinX and MinY out of bounds
+ try
+ {
+ // Create child with non-zero minX and minY
+ WritableRaster rst2 = rst.createWritableChild(0, 0, 25, 25, 30, 30, null);
+
+ // Create child's child with minX and minY out of bounds
+ rst2.createChild(10, 20, 10, 10, 0, 0, null);
+ harness.check(false);
+ }
+ catch (RasterFormatException ex)
+ {
+ harness.check(true);
+ }
+ catch (Exception ex)
+ {
+ harness.check(false);
+ }
+ }
+
+ private void testBands(TestHarness harness)
+ {
+ WritableRaster rst = createRaster();
+
+ // Copy all bands
+ WritableRaster rst2 = rst.createWritableChild(0, 0, 50, 40, 0, 0, null);
+ harness.check(rst2.getNumBands(), rst.getNumBands());
+
+ // Only first two bands
+ rst2 = rst.createWritableChild(0, 0, 50, 40, 0, 0, new int[]{0, 1});
+ harness.check(rst2.getNumBands(), 2);
+ for (int x = 0; x < 50; x++)
+ for (int y = 0; y < 40; y++)
+ for (int b = 0; b < 2; b++)
+ harness.check(rst2.getSample(x, y, b), x+y+b);
+
+ // Only last two bands
+ rst2 = rst.createWritableChild(0, 0, 50, 40, 0, 0, new int[]{1, 2});
+ harness.check(rst2.getNumBands(), 2);
+ for (int x = 0; x < 50; x++)
+ for (int y = 0; y < 40; y++)
+ for (int b = 0; b < 2; b++)
+ harness.check(rst2.getSample(x, y, b), x+y+b+1);
+
+ // Only middle band
+ rst2 = rst.createWritableChild(0, 0, 50, 40, 0, 0, new int[]{1});
+ harness.check(rst2.getNumBands(), 1);
+ for (int x = 0; x < 50; x++)
+ for (int y = 0; y < 40; y++)
+ harness.check(rst2.getSample(x, y, 0), x+y+1);
+
+ // Reverse order of bands
+ rst2 = rst.createWritableChild(0, 0, 50, 40, 0, 0, new int[]{2, 0});
+ harness.check(rst2.getNumBands(), 2);
+ for (int x = 0; x < 50; x++)
+ for (int y = 0; y < 40; y++)
+ {
+ harness.check(rst2.getSample(x, y, 0), x+y+2);
+ harness.check(rst2.getSample(x, y, 1), x+y);
+ }
+ }
+
+ private WritableRaster createRaster()
+ {
+ // Create initial raster
+ WritableRaster rst = Raster.createWritableRaster(new SinglePixelPackedSampleModel(DataBuffer.TYPE_INT,
+ 50, 40,
+ new int[]{0xff0000, 0xff00, 0xff}),
+ new Point(0, 0));
+
+ // Fill with test data
+ for (int x = 0; x < 50; x++)
+ for (int y = 0; y < 40; y++)
+ for (int b = 0; b < 3; b++)
+ rst.setSample(x, y, b, x+y+b);
+
+ return rst;
+ }
+}
Index: gnu/testlet/java/awt/image/Raster/createChild.java
===================================================================
RCS file: gnu/testlet/java/awt/image/Raster/createChild.java
diff -N gnu/testlet/java/awt/image/Raster/createChild.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/java/awt/image/Raster/createChild.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,174 @@
+/* createChild.java -- some checks for the createChild() method
+ in the Raster 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.Raster;
+
+import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
+
+import java.awt.Point;
+import java.awt.image.DataBuffer;
+import java.awt.image.Raster;
+import java.awt.image.RasterFormatException;
+import java.awt.image.SinglePixelPackedSampleModel;
+import java.awt.image.WritableRaster;
+
+public class createChild implements Testlet
+{
+ public void test(TestHarness harness)
+ {
+ testData(harness);
+ testBounds(harness);
+ testBands(harness);
+ }
+
+ private void testData(TestHarness harness)
+ {
+ Raster rst = createRaster();
+
+ // Child raster
+ Raster rst2 = rst.createChild(10, 20, 25, 15, 0, 0, null);
+ harness.check(rst2.getMinX(), 0);
+ harness.check(rst2.getMinY(), 0);
+ harness.check(rst2.getWidth(), 25);
+ harness.check(rst2.getHeight(), 15);
+
+ for (int x = 0; x < 25; x++)
+ for (int y = 0; y < 15; y++)
+ for (int b = 0; b < 3; b++)
+ harness.check(rst2.getSample(x, y, b), x+10 + y+20 + b);
+
+ // Offset child
+ rst2 = rst.createChild(10, 20, 25, 15, 30, 40, null);
+ harness.check(rst2.getMinX(), 30);
+ harness.check(rst2.getMinY(), 40);
+ harness.check(rst2.getWidth(), 25);
+ harness.check(rst2.getHeight(), 15);
+
+ for (int x = 30; x < 55; x++)
+ for (int y = 40; y < 55; y++)
+ for (int b = 0; b < 3; b++)
+ harness.check(rst2.getSample(x, y, b), x-20 + y-20 + b);
+ }
+
+ private void testBounds(TestHarness harness)
+ {
+ Raster rst = createRaster();
+
+ // Width and height out of bounds
+ try
+ {
+ rst.createChild(10, 20, 100, 100, 0, 0, null);
+ harness.check(false);
+ }
+ catch (RasterFormatException ex)
+ {
+ harness.check(true);
+ }
+ catch (Exception ex)
+ {
+ harness.check(false);
+ }
+
+ // MinX and MinY out of bounds
+ try
+ {
+ // Create child with non-zero minX and minY
+ Raster rst2 = rst.createChild(0, 0, 25, 25, 30, 30, null);
+
+ // Create child's child with minX and minY out of bounds
+ rst2.createChild(10, 20, 10, 10, 0, 0, null);
+ harness.check(false);
+ }
+ catch (RasterFormatException ex)
+ {
+ harness.check(true);
+ }
+ catch (Exception ex)
+ {
+ harness.check(false);
+ }
+ }
+
+ private void testBands(TestHarness harness)
+ {
+ Raster rst = createRaster();
+
+ // Copy all bands
+ Raster rst2 = rst.createChild(0, 0, 50, 40, 0, 0, null);
+ harness.check(rst2.getNumBands(), rst.getNumBands());
+
+ // Only first two bands
+ rst2 = rst.createChild(0, 0, 50, 40, 0, 0, new int[]{0, 1});
+ harness.check(rst2.getNumBands(), 2);
+ for (int x = 0; x < 50; x++)
+ for (int y = 0; y < 40; y++)
+ for (int b = 0; b < 2; b++)
+ harness.check(rst2.getSample(x, y, b), x+y+b);
+
+ // Only last two bands
+ rst2 = rst.createChild(0, 0, 50, 40, 0, 0, new int[]{1, 2});
+ harness.check(rst2.getNumBands(), 2);
+ for (int x = 0; x < 50; x++)
+ for (int y = 0; y < 40; y++)
+ for (int b = 0; b < 2; b++)
+ harness.check(rst2.getSample(x, y, b), x+y+b+1);
+
+ // Only middle band
+ rst2 = rst.createChild(0, 0, 50, 40, 0, 0, new int[]{1});
+ harness.check(rst2.getNumBands(), 1);
+ for (int x = 0; x < 50; x++)
+ for (int y = 0; y < 40; y++)
+ harness.check(rst2.getSample(x, y, 0), x+y+1);
+
+ // Reverse order of bands
+ rst2 = rst.createChild(0, 0, 50, 40, 0, 0, new int[]{2, 0});
+ harness.check(rst2.getNumBands(), 2);
+ for (int x = 0; x < 50; x++)
+ for (int y = 0; y < 40; y++)
+ {
+ harness.check(rst2.getSample(x, y, 0), x+y+2);
+ harness.check(rst2.getSample(x, y, 1), x+y);
+ }
+ }
+
+ private Raster createRaster()
+ {
+ // Create initial raster
+ WritableRaster rst = Raster.createWritableRaster(new SinglePixelPackedSampleModel(DataBuffer.TYPE_INT,
+ 50, 40,
+ new int[]{0xff0000, 0xff00, 0xff}),
+ new Point(0, 0));
+
+ // Fill with test data
+ for (int x = 0; x < 50; x++)
+ for (int y = 0; y < 40; y++)
+ for (int b = 0; b < 3; b++)
+ rst.setSample(x, y, b, x+y+b);
+
+ // Get non-writable child
+ Raster rst2 = rst.createChild(0, 0, 50, 40, 0, 0, null);
+ return rst2;
+ }
+}