From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22659 invoked by alias); 27 Nov 2006 21:47:49 -0000 Received: (qmail 22650 invoked by uid 22791); 27 Nov 2006 21:47:47 -0000 X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (66.187.233.31) by sourceware.org (qpsmtpd/0.31) with ESMTP; Mon, 27 Nov 2006 21:47:38 +0000 Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254]) by mx1.redhat.com (8.12.11.20060308/8.12.11) with ESMTP id kARLlaSm019093 for ; Mon, 27 Nov 2006 16:47:36 -0500 Received: from pobox.toronto.redhat.com (pobox.toronto.redhat.com [172.16.14.4]) by int-mx1.corp.redhat.com (8.13.1/8.13.1) with ESMTP id kARLlZjT015883 for ; Mon, 27 Nov 2006 16:47:35 -0500 Received: from [172.16.14.87] (toddy.toronto.redhat.com [172.16.14.87]) by pobox.toronto.redhat.com (8.12.11.20060308/8.12.11) with ESMTP id kARLlZJk031679 for ; Mon, 27 Nov 2006 16:47:35 -0500 Subject: FYI: Raster child checks From: Francis Kung To: mauve-patches@sources.redhat.com Content-Type: multipart/mixed; boundary="=-1QpjWl6o3eN7hfjZ4dWK" Date: Mon, 27 Nov 2006 21:47:00 -0000 Message-Id: <1164664055.25606.45.camel@toddy.toronto.redhat.com> Mime-Version: 1.0 X-Mailer: Evolution 2.8.1.1 (2.8.1.1-3.fc6) X-IsSubscribed: yes Mailing-List: contact mauve-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: mauve-patches-owner@sourceware.org X-SW-Source: 2006/txt/msg00753.txt.bz2 --=-1QpjWl6o3eN7hfjZ4dWK Content-Type: text/plain Content-Transfer-Encoding: 7bit Content-length: 502 Hi, This patch adds a check to Raster.createChild, clarifying whether it returns a Raster or WritableRaster. Cheers, Francis 2006-11-27 Francis Kung * gnu/testlet/java/awt/image/Raster/createChild.java (createRaster): Add harness parameter, ensure that returned raster is not writable. (testData): Add check for class of child raster. * gnu/testlet/java/awt/image/Raster/MyRaster.java: New file. * gnu/testlet/java/awt/image/WritableRaster/createChild.java: New file. --=-1QpjWl6o3eN7hfjZ4dWK Content-Disposition: attachment; filename=rasterchild.diff Content-Type: text/x-patch; name=rasterchild.diff; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-length: 9469 Index: gnu/testlet/java/awt/image/Raster/createChild.java =================================================================== RCS file: /cvs/mauve/mauve/gnu/testlet/java/awt/image/Raster/createChild.java,v retrieving revision 1.1 diff -u -r1.1 createChild.java --- gnu/testlet/java/awt/image/Raster/createChild.java 17 Oct 2006 14:48:09 -0000 1.1 +++ gnu/testlet/java/awt/image/Raster/createChild.java 27 Nov 2006 21:43:28 -0000 @@ -45,10 +45,11 @@ private void testData(TestHarness harness) { - Raster rst = createRaster(); + Raster rst = createRaster(harness); // Child raster Raster rst2 = rst.createChild(10, 20, 25, 15, 0, 0, null); + harness.check(!(rst2 instanceof WritableRaster)); harness.check(rst2.getMinX(), 0); harness.check(rst2.getMinY(), 0); harness.check(rst2.getWidth(), 25); @@ -74,7 +75,7 @@ private void testBounds(TestHarness harness) { - Raster rst = createRaster(); + Raster rst = createRaster(harness); // Width and height out of bounds try @@ -113,7 +114,7 @@ private void testBands(TestHarness harness) { - Raster rst = createRaster(); + Raster rst = createRaster(harness); // Copy all bands Raster rst2 = rst.createChild(0, 0, 50, 40, 0, 0, null); @@ -153,7 +154,7 @@ } } - private Raster createRaster() + private Raster createRaster(TestHarness harness) { // Create initial raster WritableRaster rst = Raster.createWritableRaster(new SinglePixelPackedSampleModel(DataBuffer.TYPE_INT, @@ -167,8 +168,11 @@ 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); + // Get non-writable version with the same data + Raster rst2 = new MyRaster(rst.getSampleModel(), + rst.getDataBuffer(), + new Point(0, 0)); + harness.check(!(rst2 instanceof WritableRaster)); return rst2; } } Index: gnu/testlet/java/awt/image/Raster/MyRaster.java =================================================================== RCS file: gnu/testlet/java/awt/image/Raster/MyRaster.java diff -N gnu/testlet/java/awt/image/Raster/MyRaster.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ gnu/testlet/java/awt/image/Raster/MyRaster.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,34 @@ +// Tags: not-a-test + +// Copyright (C) 2006 Francis Kung + +// 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. + +package gnu.testlet.java.awt.image.Raster; + +import java.awt.Point; +import java.awt.image.DataBuffer; +import java.awt.image.Raster; +import java.awt.image.SampleModel; + +public class MyRaster + extends Raster +{ + public MyRaster(SampleModel sm, DataBuffer db, Point origin) + { + super(sm, db, origin); + } +} Index: gnu/testlet/java/awt/image/WritableRaster/createChild.java =================================================================== RCS file: gnu/testlet/java/awt/image/WritableRaster/createChild.java diff -N gnu/testlet/java/awt/image/WritableRaster/createChild.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ gnu/testlet/java/awt/image/WritableRaster/createChild.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,173 @@ +/* createChild.java -- some checks for the createChild() method + in the WritableRaster class. + Copyright (C) 2006 Francis Kung +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 createChild implements Testlet +{ + public void test(TestHarness harness) + { + testData(harness); + testBounds(harness); + testBands(harness); + } + + private void testData(TestHarness harness) + { + Raster rst = createRaster(harness); + + // Child raster + Raster rst2 = rst.createChild(10, 20, 25, 15, 0, 0, null); + harness.check(rst2 instanceof WritableRaster); + 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(harness); + + // 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(harness); + + // 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(TestHarness harness) + { + // 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; + } +} --=-1QpjWl6o3eN7hfjZ4dWK--