This is the mail archive of the
mauve-patches@sources.redhat.com
mailing list for the Mauve project.
java.awt.image.SinglePixelPackedSampleModel
- From: David Gilbert <david dot gilbert at object-refinery dot com>
- To: mauve-patches at sources dot redhat dot com
- Date: Tue, 28 Sep 2004 00:07:41 +0100
- Subject: java.awt.image.SinglePixelPackedSampleModel
I've attached some tests for the
java.awt.image.SinglePixelPackedSampleModel class. With JDK 1.4 the
tests all pass, with a fairly recent CVS version of Classpath running on
JamVM 1.2.0 there are 14 failures. The failures are not too serious,
just missing implementations of equals() and hashCode(), and not
throwing the specified exceptions on bad inputs:
dgilbert@linux42:~/workspace/mauve> jamvm -classpath .
gnu.testlet.SimpleTestHarness -file CurrentTests.txt -debug
FAIL:
gnu.testlet.java.awt.image.SinglePixelPackedSampleModel.constructors:
(int, int, int, int[]) (number 5)
FAIL:
gnu.testlet.java.awt.image.SinglePixelPackedSampleModel.constructors:
(int, int, int, int[]) (number 8)
FAIL:
gnu.testlet.java.awt.image.SinglePixelPackedSampleModel.constructors:
(int, int, int, int, int[]) (number 5)
FAIL:
gnu.testlet.java.awt.image.SinglePixelPackedSampleModel.constructors:
(int, int, int, int, int[]) (number 8)
FAIL:
gnu.testlet.java.awt.image.SinglePixelPackedSampleModel.createSubsetSampleModel (number 7)
FAIL: gnu.testlet.java.awt.image.SinglePixelPackedSampleModel.equals
(number 1)
FAIL: gnu.testlet.java.awt.image.SinglePixelPackedSampleModel.equals
(number 2)
FAIL: gnu.testlet.java.awt.image.SinglePixelPackedSampleModel.equals
(number 5)
FAIL: gnu.testlet.java.awt.image.SinglePixelPackedSampleModel.equals
(number 7)
FAIL: gnu.testlet.java.awt.image.SinglePixelPackedSampleModel.equals
(number 9)
FAIL: gnu.testlet.java.awt.image.SinglePixelPackedSampleModel.equals
(number 11)
FAIL:
gnu.testlet.java.awt.image.SinglePixelPackedSampleModel.getDataElements:
uncaught exception at "(int, int, Object, DataBuffer(Byte))" number 5
java.lang.ArrayStoreException
at java.lang.VMSystem.arraycopy (Native Method)
at java.lang.System.arraycopy (System.java:418)
at gnu.java.awt.Buffers.getData (Buffers.java:206)
at java.awt.image.SinglePixelPackedSampleModel.getDataElements
(SinglePixelPackedSampleModel.java:160)
at
gnu.testlet.java.awt.image.SinglePixelPackedSampleModel.getDataElements.testByte (getDataElements.java:89)
at
gnu.testlet.java.awt.image.SinglePixelPackedSampleModel.getDataElements.test (getDataElements.java:46)
at gnu.testlet.SimpleTestHarness.runtest (SimpleTestHarness.java:266)
at gnu.testlet.SimpleTestHarness.main (SimpleTestHarness.java:394)
FAIL: gnu.testlet.java.awt.image.SinglePixelPackedSampleModel.hashCode
(number 1)
FAIL: gnu.testlet.java.awt.image.SinglePixelPackedSampleModel.hashCode
(number 2)
got 1075486680 but expected 1075486848
14 of 228 tests failed
dgilbert@linux42:~/workspace/mauve> java -classpath .
gnu.testlet.SimpleTestHarness -file CurrentTests.txt -debug
0 of 241 tests failed
Regards,
Dave Gilbert
http://www.jfree.org
// Tags: JDK1.2
// Copyright (C) 2004 David Gilbert <david.gilbert@object-refinery.com>
// 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, 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA. */
package gnu.testlet.java.awt.image.SinglePixelPackedSampleModel;
import gnu.testlet.TestHarness;
import gnu.testlet.Testlet;
import java.awt.image.DataBuffer;
import java.awt.image.SinglePixelPackedSampleModel;
/**
* Some checks for the constructors in the {@link SinglePixelPackedSampleModel} 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);
}
private void testConstructor1(TestHarness harness)
{
harness.checkPoint("(int, int, int, int[])");
SinglePixelPackedSampleModel m1 = new SinglePixelPackedSampleModel(
DataBuffer.TYPE_BYTE, 1, 2, new int[] { 224, 28, 3 }
);
harness.check(m1.getDataType(), DataBuffer.TYPE_BYTE); // check 1
harness.check(m1.getWidth(), 1); // check 2
harness.check(m1.getHeight(), 2); // check 3
harness.check(m1.getNumBands(), 3); // check 4
// unsupported data type should throw an IllegalArgumentException
try // check 5
{
/* SampleModel m2 = */ new SinglePixelPackedSampleModel(
DataBuffer.TYPE_DOUBLE, 1, 2, new int[] { 224, 28, 3 }
);
harness.check(false);
}
catch (IllegalArgumentException e)
{
harness.check(true);
}
// if 'w' is <= 0 there should be an IllegalArgumentException
try // check 6
{
/* SampleModel m2 = */ new SinglePixelPackedSampleModel(
DataBuffer.TYPE_BYTE, 0, 2, new int[] { 224, 28, 3 }
);
harness.check(false);
}
catch (IllegalArgumentException e)
{
harness.check(true);
}
// if 'h' is <= 0 there should be an IllegalArgumentException
try // check 7
{
/* SampleModel m2 = */ new SinglePixelPackedSampleModel(
DataBuffer.TYPE_BYTE, 1, 0, new int[] { 224, 28, 3 }
);
harness.check(false);
}
catch (IllegalArgumentException e)
{
harness.check(true);
}
// if mask array is empty there should be an IllegalArgumentException
try // check 8
{
/* SampleModel m2 = */ new SinglePixelPackedSampleModel(
DataBuffer.TYPE_BYTE, 1, 2, new int[] { }
);
harness.check(false);
}
catch (IllegalArgumentException e)
{
harness.check(true);
}
// if mask array contains a non-contiguous mask there should be an IllegalArgumentException
try
{
/* SampleModel m2 = */ new SinglePixelPackedSampleModel(
DataBuffer.TYPE_BYTE, 1, 2, new int[] { 224, 27, 3 }
);
harness.check(false);
}
catch (IllegalArgumentException e)
{
harness.check(true);
}
}
private void testConstructor2(TestHarness harness)
{
harness.checkPoint("(int, int, int, int, int[])");
SinglePixelPackedSampleModel m1 = new SinglePixelPackedSampleModel(
DataBuffer.TYPE_BYTE, 1, 2, 3, new int[] { 224, 28, 3 }
);
harness.check(m1.getDataType(), DataBuffer.TYPE_BYTE); // check 1
harness.check(m1.getWidth(), 1); // check 2
harness.check(m1.getHeight(), 2); // check 3
harness.check(m1.getNumBands(), 3); // check 4
// unsupported data type should throw an IllegalArgumentException
try
{
/* SampleModel m2 = */ new SinglePixelPackedSampleModel(
DataBuffer.TYPE_DOUBLE, 1, 2, 3, new int[] { 224, 28, 3 }
);
harness.check(false);
}
catch (IllegalArgumentException e)
{
harness.check(true);
}
// if 'w' is <= 0 there should be an IllegalArgumentException
try
{
/* SampleModel m2 = */ new SinglePixelPackedSampleModel(
DataBuffer.TYPE_BYTE, 0, 2, 3, new int[] { 224, 28, 3 }
);
harness.check(false);
}
catch (IllegalArgumentException e)
{
harness.check(true);
}
// if 'h' is <= 0 there should be an IllegalArgumentException
try
{
/* SampleModel m2 = */ new SinglePixelPackedSampleModel(
DataBuffer.TYPE_BYTE, 1, 0, 3, new int[] { 224, 28, 3 }
);
harness.check(false);
}
catch (IllegalArgumentException e)
{
harness.check(true);
}
// if mask array is empty there should be an IllegalArgumentException
try
{
/* SampleModel m2 = */ new SinglePixelPackedSampleModel(
DataBuffer.TYPE_BYTE, 1, 2, 3, new int[] { }
);
harness.check(false);
}
catch (IllegalArgumentException e)
{
harness.check(true);
}
// if mask array contains a non-contiguous mask there should be an IllegalArgumentException
try
{
/* SampleModel m2 = */ new SinglePixelPackedSampleModel(
DataBuffer.TYPE_BYTE, 1, 2, new int[] { 224, 27, 3 }
);
harness.check(false);
}
catch (IllegalArgumentException e)
{
harness.check(true);
}
}
}
// Tags: JDK1.2
// Copyright (C) 2004 David Gilbert <david.gilbert@object-refinery.com>
// 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, 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA. */
package gnu.testlet.java.awt.image.SinglePixelPackedSampleModel;
import gnu.testlet.TestHarness;
import gnu.testlet.Testlet;
import java.awt.image.DataBuffer;
import java.awt.image.SinglePixelPackedSampleModel;
import java.util.Arrays;
/**
* Some checks for the <code>createCompatibleSampleModel()</code> method in the
* {@link SinglePixelPackedSampleModel} class.
*/
public class createCompatibleSampleModel implements Testlet
{
/**
* Runs the test using the specified harness.
*
* @param harness the test harness (<code>null</code> not permitted).
*/
public void test(TestHarness harness)
{
SinglePixelPackedSampleModel m1 = new SinglePixelPackedSampleModel(
DataBuffer.TYPE_BYTE, 1, 2, new int[] { 224, 28, 3 }
);
SinglePixelPackedSampleModel m2 = (SinglePixelPackedSampleModel) m1.createCompatibleSampleModel(5, 10);
harness.check(m2.getDataType(), DataBuffer.TYPE_BYTE); // check 1
harness.check(m2.getWidth(), 5); // check 2
harness.check(m2.getHeight(), 10); // check 3
harness.check(m2.getNumBands(), 3); // check 4
harness.check(Arrays.equals(m1.getBitMasks(), m2.getBitMasks())); // check 5
// if 'w' is <= 0 there should be an IllegalArgumentException
try
{
/* SampleModel m3 = */ m1.createCompatibleSampleModel(0, 10);
harness.check(false);
}
catch (IllegalArgumentException e)
{
harness.check(true);
}
// if 'h' is <= 0 there should be an IllegalArgumentException
try
{
/* SampleModel m4 = */ m1.createCompatibleSampleModel(5, 0);
harness.check(false);
}
catch (IllegalArgumentException e)
{
harness.check(true);
}
}
}
// Tags: JDK1.2
// Copyright (C) 2004 David Gilbert <david.gilbert@object-refinery.com>
// 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, 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA. */
package gnu.testlet.java.awt.image.SinglePixelPackedSampleModel;
import gnu.testlet.TestHarness;
import gnu.testlet.Testlet;
import java.awt.image.DataBuffer;
import java.awt.image.RasterFormatException;
import java.awt.image.SinglePixelPackedSampleModel;
import java.util.Arrays;
/**
* Some checks for the <code>createSubsetampleModel()</code> method in the
* {@link SinglePixelPackedSampleModel} class.
*/
public class createSubsetSampleModel implements Testlet
{
/**
* Runs the test using the specified harness.
*
* @param harness the test harness (<code>null</code> not permitted).
*/
public void test(TestHarness harness)
{
SinglePixelPackedSampleModel m1 = new SinglePixelPackedSampleModel(
DataBuffer.TYPE_BYTE, 1, 2, new int[] { 224, 28, 3 }
);
SinglePixelPackedSampleModel m2 = (SinglePixelPackedSampleModel) m1.createSubsetSampleModel(new int[] {0, 2});
harness.check(m2.getDataType(), DataBuffer.TYPE_BYTE); // check 1
harness.check(m2.getWidth(), 1); // check 2
harness.check(m2.getHeight(), 2); // check 3
harness.check(m2.getNumBands(), 2); // check 4
harness.check(Arrays.equals(new int[] { 224, 3 }, m2.getBitMasks())); // check 5
// if 'bands' contains an index outside the range there should be an ArrayIndexOutOfBoundsException
try
{
/* SampleModel m3 = */ m1.createSubsetSampleModel(new int [] {0, 5});
harness.check(false);
}
catch (ArrayIndexOutOfBoundsException e)
{
harness.check(true);
}
// if 'bands' has more bands than original there should be a RasterFormatException
try
{
/* SampleModel m3 = */ m1.createSubsetSampleModel(new int [] {0, 1, 2, 0});
harness.check(false);
}
catch (RasterFormatException e)
{
harness.check(true);
}
}
}
// Tags: JDK1.2
// Copyright (C) 2004 David Gilbert <david.gilbert@object-refinery.com>
// 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, 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA. */
package gnu.testlet.java.awt.image.SinglePixelPackedSampleModel;
import gnu.testlet.TestHarness;
import gnu.testlet.Testlet;
import java.awt.image.DataBuffer;
import java.awt.image.SinglePixelPackedSampleModel;
/**
* Some checks for the <code>equals()</code> method in the
* {@link SinglePixelPackedSampleModel} class.
*/
public class equals implements Testlet
{
/**
* Runs the test using the specified harness.
*
* @param harness the test harness (<code>null</code> not permitted).
*/
public void test(TestHarness harness)
{
SinglePixelPackedSampleModel m1 = new SinglePixelPackedSampleModel(
DataBuffer.TYPE_BYTE, 1, 2, new int[] { 224, 28, 3 }
);
SinglePixelPackedSampleModel m2 = new SinglePixelPackedSampleModel(
DataBuffer.TYPE_BYTE, 1, 2, new int[] { 224, 28, 3 }
);
harness.check(m1.equals(m2)); // check 1
harness.check(m2.equals(m1)); // check 2
harness.check(!m1.equals(null)); // check 3
// check that all fields are distinguished...
// dataType
m1 = new SinglePixelPackedSampleModel(
DataBuffer.TYPE_INT, 1, 2, new int[] { 224, 28, 3 }
);
harness.check(!m1.equals(m2));
m2 = new SinglePixelPackedSampleModel(
DataBuffer.TYPE_INT, 1, 2, new int[] { 224, 28, 3 }
);
harness.check(m1.equals(m2));
// w
m1 = new SinglePixelPackedSampleModel(
DataBuffer.TYPE_INT, 5, 2, new int[] { 224, 28, 3 }
);
harness.check(!m1.equals(m2));
m2 = new SinglePixelPackedSampleModel(
DataBuffer.TYPE_INT, 5, 2, new int[] { 224, 28, 3 }
);
harness.check(m1.equals(m2));
// h
m1 = new SinglePixelPackedSampleModel(
DataBuffer.TYPE_INT, 5, 10, new int[] { 224, 28, 3 }
);
harness.check(!m1.equals(m2));
m2 = new SinglePixelPackedSampleModel(
DataBuffer.TYPE_INT, 5, 10, new int[] { 224, 28, 3 }
);
harness.check(m1.equals(m2));
// bitmasks
m1 = new SinglePixelPackedSampleModel(
DataBuffer.TYPE_INT, 5, 10, new int[] { 224, 24, 7 }
);
harness.check(!m1.equals(m2));
m2 = new SinglePixelPackedSampleModel(
DataBuffer.TYPE_INT, 5, 10, new int[] { 224, 24, 7 }
);
harness.check(m1.equals(m2));
}
}
// Tags: JDK1.2
// Copyright (C) 2004 David Gilbert <david.gilbert@object-refinery.com>
// 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, 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA. */
package gnu.testlet.java.awt.image.SinglePixelPackedSampleModel;
import gnu.testlet.TestHarness;
import gnu.testlet.Testlet;
import java.awt.image.DataBuffer;
import java.awt.image.SinglePixelPackedSampleModel;
import java.util.Arrays;
/**
* Some checks for the <code>getBitMasks()</code> method in the
* {@link SinglePixelPackedSampleModel} class.
*/
public class getBitMasks implements Testlet
{
/**
* Runs the test using the specified harness.
*
* @param harness the test harness (<code>null</code> not permitted).
*/
public void test(TestHarness harness)
{
SinglePixelPackedSampleModel m1 = new SinglePixelPackedSampleModel(
DataBuffer.TYPE_BYTE, 1, 2, new int[] { 224, 28, 3 }
);
harness.check(Arrays.equals(m1.getBitMasks(), new int[] { 224, 28, 3 })); // check 4
}
}
// Tags: JDK1.2
// Copyright (C) 2004 David Gilbert <david.gilbert@object-refinery.com>
// 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, 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA. */
package gnu.testlet.java.awt.image.SinglePixelPackedSampleModel;
import gnu.testlet.TestHarness;
import gnu.testlet.Testlet;
import java.awt.image.DataBuffer;
import java.awt.image.SinglePixelPackedSampleModel;
import java.util.Arrays;
/**
* Some checks for the <code>getBitOffsets()</code> method in the
* {@link SinglePixelPackedSampleModel} class.
*/
public class getBitOffsets implements Testlet
{
/**
* Runs the test using the specified harness.
*
* @param harness the test harness (<code>null</code> not permitted).
*/
public void test(TestHarness harness)
{
SinglePixelPackedSampleModel m1 = new SinglePixelPackedSampleModel(
DataBuffer.TYPE_BYTE, 1, 2, new int[] { 224, 28, 3 }
);
harness.check(Arrays.equals(m1.getBitOffsets(), new int[] { 5, 2, 0 }));
}
}
// Tags: JDK1.2
// Copyright (C) 2004 David Gilbert <david.gilbert@object-refinery.com>
// 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, 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA. */
package gnu.testlet.java.awt.image.SinglePixelPackedSampleModel;
import gnu.testlet.TestHarness;
import gnu.testlet.Testlet;
import java.awt.image.DataBuffer;
import java.awt.image.DataBufferByte;
import java.awt.image.DataBufferInt;
import java.awt.image.DataBufferUShort;
import java.awt.image.SinglePixelPackedSampleModel;
/**
* Some checks for the <code>getDataElements()</code> method in the
* {@link SinglePixelPackedSampleModel} class.
*/
public class getDataElements implements Testlet
{
/**
* Runs the test using the specified harness.
*
* @param harness the test harness (<code>null</code> not permitted).
*/
public void test(TestHarness harness)
{
testByte(harness);
testUShort(harness);
testInt(harness);
}
private void testByte(TestHarness harness)
{
harness.checkPoint("(int, int, Object, DataBuffer(Byte))");
SinglePixelPackedSampleModel m1 = new SinglePixelPackedSampleModel(
DataBuffer.TYPE_BYTE, 2, 2, new int[] { 224, 28, 3 }
);
byte[] b = new byte[] { (byte) 11, (byte) 22, (byte) 33, (byte) 44 };
DataBuffer db = new DataBufferByte(b, 4);
byte[] de = (byte[]) m1.getDataElements(1, 1, null, db);
harness.check(de.length, 1); // check 1
harness.check(de[0], (byte) 44); // check 2
// check for coordinates out of bounds
try // check 3
{
m1.getDataElements(2, 2, null, db);
harness.check(false);
}
catch (ArrayIndexOutOfBoundsException e)
{
harness.check(true);
}
// check for return object of wrong dimension
try // check 4
{
m1.getDataElements(1, 1, new byte[0], db);
harness.check(false);
}
catch (ArrayIndexOutOfBoundsException e)
{
harness.check(true);
}
// check for return object of wrong type
try // check 5
{
m1.getDataElements(1, 1, new int[1], db);
harness.check(false);
}
catch (ClassCastException e)
{
harness.check(true);
}
// check for null data buffer
try // check 6
{
m1.getDataElements(0, 0, null, null);
harness.check(false);
}
catch (NullPointerException e)
{
harness.check(true);
}
}
private void testUShort(TestHarness harness)
{
harness.checkPoint("(int, int, Object, DataBuffer(UShort))");
SinglePixelPackedSampleModel m1 = new SinglePixelPackedSampleModel(
DataBuffer.TYPE_USHORT, 2, 2, new int[] { 224, 28, 3 }
);
short[] s = new short[] { (short) 11, (short) 22, (short) 33, (short) 44 };
DataBuffer db = new DataBufferUShort(s, 4);
short[] de = (short[]) m1.getDataElements(1, 1, null, db);
harness.check(de.length, 1);
harness.check(de[0], (byte) 44);
// check for coordinates out of bounds
try
{
m1.getDataElements(2, 2, null, db);
harness.check(false);
}
catch (ArrayIndexOutOfBoundsException e)
{
harness.check(true);
}
// check for return object of wrong dimension
try
{
m1.getDataElements(1, 1, new short[0], db);
harness.check(false);
}
catch (ArrayIndexOutOfBoundsException e)
{
harness.check(true);
}
// check for return object of wrong type
try
{
m1.getDataElements(1, 1, new int[1], db);
harness.check(false);
}
catch (ClassCastException e)
{
harness.check(true);
}
// check for null data buffer
try
{
m1.getDataElements(0, 0, null, null);
harness.check(false);
}
catch (NullPointerException e)
{
harness.check(true);
}
}
private void testInt(TestHarness harness)
{
harness.checkPoint("(int, int, Object, DataBuffer(Int))");
SinglePixelPackedSampleModel m1 = new SinglePixelPackedSampleModel(
DataBuffer.TYPE_INT, 2, 2, new int[] { 224, 28, 3 }
);
int[] i = new int[] { 11, 22, 33, 44 };
DataBuffer db = new DataBufferInt(i, 4);
int[] de = (int[]) m1.getDataElements(1, 1, null, db);
harness.check(de.length, 1);
harness.check(de[0], 44);
// check for coordinates out of bounds
try
{
m1.getDataElements(2, 2, null, db);
harness.check(false);
}
catch (ArrayIndexOutOfBoundsException e)
{
harness.check(true);
}
// check for return object of wrong dimension
try
{
m1.getDataElements(1, 1, new int[0], db);
harness.check(false);
}
catch (ArrayIndexOutOfBoundsException e)
{
harness.check(true);
}
// check for return object of wrong type
try
{
m1.getDataElements(1, 1, new byte[1], db);
harness.check(false);
}
catch (ClassCastException e)
{
harness.check(true);
}
// check for null data buffer
try
{
m1.getDataElements(0, 0, null, null);
harness.check(false);
}
catch (NullPointerException e)
{
harness.check(true);
}
}
}
// Tags: JDK1.2
// Copyright (C) 2004 David Gilbert <david.gilbert@object-refinery.com>
// 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, 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA. */
package gnu.testlet.java.awt.image.SinglePixelPackedSampleModel;
import gnu.testlet.TestHarness;
import gnu.testlet.Testlet;
import java.awt.image.DataBuffer;
import java.awt.image.SinglePixelPackedSampleModel;
/**
* Some checks for the <code>getNumDataElements()</code> method in the
* {@link SinglePixelPackedSampleModel} class.
*/
public class getNumDataElements implements Testlet
{
/**
* Runs the test using the specified harness.
*
* @param harness the test harness (<code>null</code> not permitted).
*/
public void test(TestHarness harness)
{
SinglePixelPackedSampleModel m1 = new SinglePixelPackedSampleModel(
DataBuffer.TYPE_BYTE, 1, 2, new int[] { 224, 28, 3 }
);
harness.check(m1.getNumDataElements(), 1);
}
}
// Tags: JDK1.2
// Copyright (C) 2004 David Gilbert <david.gilbert@object-refinery.com>
// 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, 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA. */
package gnu.testlet.java.awt.image.SinglePixelPackedSampleModel;
import gnu.testlet.TestHarness;
import gnu.testlet.Testlet;
import java.awt.image.DataBuffer;
import java.awt.image.SinglePixelPackedSampleModel;
/**
* Some checks for the <code>getOffset()</code> method in the
* {@link SinglePixelPackedSampleModel} class.
*/
public class getOffset implements Testlet
{
/**
* Runs the test using the specified harness.
*
* @param harness the test harness (<code>null</code> not permitted).
*/
public void test(TestHarness harness)
{
SinglePixelPackedSampleModel m1 = new SinglePixelPackedSampleModel(
DataBuffer.TYPE_BYTE, 2, 2, new int[] { 224, 28, 3 }
);
harness.check(m1.getOffset(0, 0), 0);
harness.check(m1.getOffset(1, 0), 1);
harness.check(m1.getOffset(0, 1), 2);
harness.check(m1.getOffset(1, 1), 3);
}
}
// Tags: JDK1.2
// Copyright (C) 2004 David Gilbert <david.gilbert@object-refinery.com>
// 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, 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA. */
package gnu.testlet.java.awt.image.SinglePixelPackedSampleModel;
import gnu.testlet.TestHarness;
import gnu.testlet.Testlet;
import java.awt.image.DataBuffer;
import java.awt.image.DataBufferByte;
import java.awt.image.SinglePixelPackedSampleModel;
/**
* Some checks for the <code>getPixel()</code> method in the
* {@link SinglePixelPackedSampleModel} class.
*/
public class getPixel implements Testlet
{
/**
* Runs the test using the specified harness.
*
* @param harness the test harness (<code>null</code> not permitted).
*/
public void test(TestHarness harness)
{
SinglePixelPackedSampleModel m1 = new SinglePixelPackedSampleModel(
DataBuffer.TYPE_BYTE, 2, 2, new int[] { 0xF0, 0x0F }
);
DataBufferByte db = new DataBufferByte(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0xAB, (byte) 0xCD }, 4);
// check regular fetch
int[] samples = m1.getPixel(1, 1, (int[]) null, db);
harness.check(samples[0], 0x0C);
harness.check(samples[1], 0x0D);
// check regular fetch with negative x
try
{
samples = m1.getPixel(-2, 0, (int[]) null, db);
harness.check(false);
}
catch (ArrayIndexOutOfBoundsException e)
{
harness.check(true);
}
// check regular fetch with negative y
try
{
samples = m1.getPixel(0, -1, (int[]) null, db);
harness.check(false);
}
catch (ArrayIndexOutOfBoundsException e)
{
harness.check(true);
}
// check regular fetch with presupplied array
int[] samplesIn = new int[2];
int[] samplesOut = m1.getPixel(1, 1, samplesIn, db);
harness.check(samplesIn == samplesOut);
harness.check(samplesOut[0], 0x0C);
harness.check(samplesOut[1], 0x0D);
// check regular fetch with presupplied array too short
int[] samplesIn2 = new int[1];
try
{
/* int[] samplesOut2 = */ m1.getPixel(1, 1, samplesIn2, db);
harness.check(false);
}
catch (ArrayIndexOutOfBoundsException e)
{
harness.check(true);
}
// check null data buffer
try
{
samples = m1.getPixel(0, 0, (int[]) null, null);
harness.check(false);
}
catch (NullPointerException e)
{
harness.check(true);
}
}
}
// Tags: JDK1.2
// Copyright (C) 2004 David Gilbert <david.gilbert@object-refinery.com>
// 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, 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA. */
package gnu.testlet.java.awt.image.SinglePixelPackedSampleModel;
import gnu.testlet.TestHarness;
import gnu.testlet.Testlet;
import java.awt.image.DataBuffer;
import java.awt.image.DataBufferByte;
import java.awt.image.SinglePixelPackedSampleModel;
/**
* Some checks for the <code>getPixels()</code> method in the
* {@link SinglePixelPackedSampleModel} class.
*/
public class getPixels implements Testlet
{
/**
* Runs the test using the specified harness.
*
* @param harness the test harness (<code>null</code> not permitted).
*/
public void test(TestHarness harness)
{
SinglePixelPackedSampleModel m1 = new SinglePixelPackedSampleModel(
DataBuffer.TYPE_BYTE, 2, 2, new int[] { 0xF0, 0x0F }
);
DataBufferByte db = new DataBufferByte(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0xAB, (byte) 0xCD }, 4);
// check regular fetch
int[] samples = m1.getPixels(0, 0, 1, 2, (int[]) null, db);
harness.check(samples[0], 0x01); // 1
harness.check(samples[1], 0x02); // 2
harness.check(samples[2], 0x0A); // 3
harness.check(samples[3], 0x0B); // 4
// check regular fetch with negative x
try
{
samples = m1.getPixels(-1, 0, 1, 1, (int[]) null, db);
harness.check(false);
}
catch (ArrayIndexOutOfBoundsException e)
{
harness.check(true);
}
// check regular fetch with negative y
try
{
samples = m1.getPixels(0, -1, 1, 1, (int[]) null, db);
harness.check(false);
}
catch (ArrayIndexOutOfBoundsException e)
{
harness.check(true);
}
// check regular fetch with w < 0
try
{
samples = m1.getPixels(0, 0, -1, 1, (int[]) null, db);
harness.check(false);
}
catch (NegativeArraySizeException e)
{
harness.check(true);
}
catch (ArrayIndexOutOfBoundsException e)
{
harness.check(true);
}
// check regular fetch with h < 0
try
{
samples = m1.getPixels(0, 0, 1, -1, (int[]) null, db);
harness.check(false);
}
catch (NegativeArraySizeException e)
{
harness.check(true);
}
catch (ArrayIndexOutOfBoundsException e)
{
harness.check(true);
}
// check regular fetch with presupplied array
int[] samplesIn = new int[4];
int[] samplesOut = m1.getPixels(1, 0, 1, 2, samplesIn, db);
harness.check(samplesIn == samplesOut);
harness.check(samplesOut[0], 0x03);
harness.check(samplesOut[1], 0x04);
harness.check(samplesOut[2], 0x0C);
harness.check(samplesOut[3], 0x0D);
// check regular fetch with presupplied array too short
int[] samplesIn2 = new int[1];
try
{
/* int[] samplesOut2 = */ m1.getPixels(1, 1, 1, 2, samplesIn2, db);
harness.check(false);
}
catch (ArrayIndexOutOfBoundsException e)
{
harness.check(true);
}
// check null data buffer
try
{
samples = m1.getPixels(0, 0, 1, 1, (int[]) null, null);
harness.check(false);
}
catch (NullPointerException e)
{
harness.check(true);
}
}
}
// Tags: JDK1.2
// Copyright (C) 2004 David Gilbert <david.gilbert@object-refinery.com>
// 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, 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA. */
package gnu.testlet.java.awt.image.SinglePixelPackedSampleModel;
import gnu.testlet.TestHarness;
import gnu.testlet.Testlet;
import java.awt.image.DataBuffer;
import java.awt.image.DataBufferByte;
import java.awt.image.SinglePixelPackedSampleModel;
/**
* Some checks for the <code>getSample()</code> method in the
* {@link SinglePixelPackedSampleModel} class.
*/
public class getSample implements Testlet
{
/**
* Runs the test using the specified harness.
*
* @param harness the test harness (<code>null</code> not permitted).
*/
public void test(TestHarness harness)
{
SinglePixelPackedSampleModel m1 = new SinglePixelPackedSampleModel(
DataBuffer.TYPE_BYTE, 2, 2, new int[] { 0xF0, 0x0F }
);
DataBufferByte db = new DataBufferByte(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0xAB, (byte) 0xCD }, 4);
// check regular fetch
int sample = m1.getSample(1, 1, 1, db);
harness.check(sample, 0x0D);
// check regular fetch with negative x
try
{
sample = m1.getSample(-2, 0, 0, db);
harness.check(false);
}
catch (ArrayIndexOutOfBoundsException e)
{
harness.check(true);
}
// check regular fetch with negative y
try
{
sample = m1.getSample(0, -1, 0, db);
harness.check(false);
}
catch (ArrayIndexOutOfBoundsException e)
{
harness.check(true);
}
// check null data buffer
try
{
sample = m1.getSample(0, 0, 0, null);
harness.check(false);
}
catch (NullPointerException e)
{
harness.check(true);
}
}
}
// Tags: JDK1.2
// Copyright (C) 2004 David Gilbert <david.gilbert@object-refinery.com>
// 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, 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA. */
package gnu.testlet.java.awt.image.SinglePixelPackedSampleModel;
import gnu.testlet.TestHarness;
import gnu.testlet.Testlet;
import java.awt.image.DataBuffer;
import java.awt.image.DataBufferByte;
import java.awt.image.SinglePixelPackedSampleModel;
/**
* Some checks for the <code>getSamples()</code> method in the
* {@link SinglePixelPackedSampleModel} class.
*/
public class getSamples implements Testlet
{
/**
* Runs the test using the specified harness.
*
* @param harness the test harness (<code>null</code> not permitted).
*/
public void test(TestHarness harness)
{
SinglePixelPackedSampleModel m1 = new SinglePixelPackedSampleModel(
DataBuffer.TYPE_BYTE, 2, 2, new int[] { 0xF0, 0x0F }
);
DataBufferByte db = new DataBufferByte(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0xAB, (byte) 0xCD }, 4);
// check regular fetch
int[] samples = m1.getSamples(0, 0, 1, 2, 1, (int[]) null, db);
harness.check(samples[0], 0x02); // 1
harness.check(samples[1], 0x0B); // 2
// check regular fetch with negative x
try
{
samples = m1.getSamples(-1, 0, 1, 1, 1, (int[]) null, db);
harness.check(false);
}
catch (ArrayIndexOutOfBoundsException e)
{
harness.check(true);
}
// check regular fetch with negative y
try
{
samples = m1.getSamples(0, -1, 1, 1, 1, (int[]) null, db);
harness.check(false);
}
catch (ArrayIndexOutOfBoundsException e)
{
harness.check(true);
}
// check regular fetch with w < 0
try
{
samples = m1.getSamples(0, 0, -1, 1, 1, (int[]) null, db);
harness.check(false);
}
catch (NegativeArraySizeException e)
{
harness.check(true);
}
catch (ArrayIndexOutOfBoundsException e)
{
harness.check(true);
}
// check regular fetch with h < 0
try
{
samples = m1.getSamples(0, 0, 1, -1, 1, (int[]) null, db);
harness.check(false);
}
catch (NegativeArraySizeException e)
{
harness.check(true);
}
catch (ArrayIndexOutOfBoundsException e)
{
harness.check(true);
}
// check regular fetch with band < 0
try
{
samples = m1.getSamples(0, 0, 1, 1, -1, (int[]) null, db);
harness.check(false);
}
catch (ArrayIndexOutOfBoundsException e)
{
harness.check(true);
}
// check regular fetch with presupplied array
int[] samplesIn = new int[2];
int[] samplesOut = m1.getSamples(1, 0, 1, 2, 0, samplesIn, db);
harness.check(samplesIn == samplesOut);
harness.check(samplesOut[0], 0x03);
harness.check(samplesOut[1], 0x0C);
// check regular fetch with presupplied array too short
int[] samplesIn2 = new int[1];
try
{
/* int[] samplesOut2 = */ m1.getSamples(1, 1, 1, 2, 1, samplesIn2, db);
harness.check(false);
}
catch (ArrayIndexOutOfBoundsException e)
{
harness.check(true);
}
// check null data buffer
try
{
samples = m1.getSamples(0, 0, 1, 1, 1, (int[]) null, null);
harness.check(false);
}
catch (NullPointerException e)
{
harness.check(true);
}
}
}
// Tags: JDK1.2
// Copyright (C) 2004 David Gilbert <david.gilbert@object-refinery.com>
// 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, 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA. */
package gnu.testlet.java.awt.image.SinglePixelPackedSampleModel;
import gnu.testlet.TestHarness;
import gnu.testlet.Testlet;
import java.awt.image.DataBuffer;
import java.awt.image.SinglePixelPackedSampleModel;
/**
* Some checks for the <code>getScanlineStride()</code> method in the
* {@link SinglePixelPackedSampleModel} class.
*/
public class getScanlineStride implements Testlet
{
/**
* Runs the test using the specified harness.
*
* @param harness the test harness (<code>null</code> not permitted).
*/
public void test(TestHarness harness)
{
SinglePixelPackedSampleModel m1 = new SinglePixelPackedSampleModel(
DataBuffer.TYPE_BYTE, 2, 2, new int[] { 224, 28, 3 }
);
harness.check(m1.getScanlineStride(), 2);
SinglePixelPackedSampleModel m2 = new SinglePixelPackedSampleModel(
DataBuffer.TYPE_INT, 20, 30, 22, new int[] { 0xF0, 0x0F }
);
harness.check(m2.getScanlineStride(), 22);
}
}
// Tags: JDK1.2
// Copyright (C) 2004 David Gilbert <david.gilbert@object-refinery.com>
// 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, 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA. */
package gnu.testlet.java.awt.image.SinglePixelPackedSampleModel;
import gnu.testlet.TestHarness;
import gnu.testlet.Testlet;
import java.awt.image.DataBuffer;
import java.awt.image.SinglePixelPackedSampleModel;
/**
* Some checks for the <code>hashCode()</code> method in the
* {@link SinglePixelPackedSampleModel} class.
*/
public class hashCode implements Testlet
{
/**
* Runs the test using the specified harness.
*
* @param harness the test harness (<code>null</code> not permitted).
*/
public void test(TestHarness harness)
{
// two instances that are equal must have the same hashCode...
SinglePixelPackedSampleModel m1 = new SinglePixelPackedSampleModel(
DataBuffer.TYPE_BYTE, 2, 2, new int[] { 224, 28, 3 }
);
SinglePixelPackedSampleModel m2 = new SinglePixelPackedSampleModel(
DataBuffer.TYPE_BYTE, 2, 2, new int[] { 224, 28, 3 }
);
harness.check(m1.equals(m2));
harness.check(m1.hashCode(), m2.hashCode());
}
}
// Tags: JDK1.2
// Copyright (C) 2004 David Gilbert <david.gilbert@object-refinery.com>
// 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, 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA. */
package gnu.testlet.java.awt.image.SinglePixelPackedSampleModel;
import gnu.testlet.TestHarness;
import gnu.testlet.Testlet;
import java.awt.image.DataBuffer;
import java.awt.image.DataBufferByte;
import java.awt.image.DataBufferInt;
import java.awt.image.DataBufferUShort;
import java.awt.image.SinglePixelPackedSampleModel;
/**
* Some checks for the <code>setDataElements()</code> method in the
* {@link SinglePixelPackedSampleModel} class.
*/
public class setDataElements implements Testlet
{
/**
* Runs the test using the specified harness.
*
* @param harness the test harness (<code>null</code> not permitted).
*/
public void test(TestHarness harness)
{
testByte(harness);
testUShort(harness);
testInt(harness);
}
private void testByte(TestHarness harness)
{
harness.checkPoint("(int, int, Object, DataBuffer(Byte))");
SinglePixelPackedSampleModel m1 = new SinglePixelPackedSampleModel(
DataBuffer.TYPE_BYTE, 2, 3, new int[] { 0xF0, 0x0F }
);
byte[] b = new byte[] { (byte) 0x11, (byte) 0x22, (byte) 0x33, (byte) 0x44, (byte) 0x55, (byte) 0x66 };
DataBuffer db = new DataBufferByte(b, 6);
// set a value
m1.setDataElements(0, 0, new byte[] { (byte) 0x77 }, db);
m1.setDataElements(1, 0, new byte[] { (byte) 0x88 }, db);
m1.setDataElements(0, 1, new byte[] { (byte) 0x99 }, db);
m1.setDataElements(1, 1, new byte[] { (byte) 0xAA }, db);
m1.setDataElements(0, 2, new byte[] { (byte) 0xBB }, db);
m1.setDataElements(1, 2, new byte[] { (byte) 0xCC }, db);
harness.check(db.getElem(0), 0x77);
harness.check(db.getElem(1), 0x88);
harness.check(db.getElem(2), 0x99);
harness.check(db.getElem(3), 0xAA);
harness.check(db.getElem(4), 0xBB);
harness.check(db.getElem(5), 0xCC);
// set a value with non-standard scanline stride
SinglePixelPackedSampleModel m2 = new SinglePixelPackedSampleModel(
DataBuffer.TYPE_BYTE, 2, 2, 3, new int[] { 0xF0, 0x0F }
);
m2.setDataElements(0, 0, new byte[] { (byte) 0x11 }, db);
m2.setDataElements(1, 0, new byte[] { (byte) 0x22 }, db);
m2.setDataElements(0, 1, new byte[] { (byte) 0x33 }, db);
m2.setDataElements(1, 1, new byte[] { (byte) 0x44 }, db);
harness.check(db.getElem(0), 0x11);
harness.check(db.getElem(1), 0x22);
harness.check(db.getElem(3), 0x33);
harness.check(db.getElem(4), 0x44);
// set a value with x < 0
try
{
m1.setDataElements(-1, 0, new byte[] { (byte) 0x99}, db);
harness.check(false); // should not get here
}
catch (ArrayIndexOutOfBoundsException e)
{
harness.check(true);
}
// set a value with y < 0
try
{
m1.setDataElements(0, -1, new byte[] { (byte) 0x99}, db);
harness.check(false); // should not get here
}
catch (ArrayIndexOutOfBoundsException e)
{
harness.check(true);
}
// set a value with wrong transfer type
try
{
m1.setDataElements(0, 0, new int[] { (int) 0x99}, db);
harness.check(false); // should not get here
}
catch (ClassCastException e)
{
harness.check(true);
}
// set a value with transfer array too small
try
{
m1.setDataElements(0, 0, new byte[] {}, db);
harness.check(false); // should not get here
}
catch (ArrayIndexOutOfBoundsException e)
{
harness.check(true);
}
// set a value with null data buffer
try
{
m1.setDataElements(0, 0, new byte[] { (byte) 0x99 }, null);
harness.check(false); // should not get here
}
catch (NullPointerException e)
{
harness.check(true);
}
}
private void testUShort(TestHarness harness)
{
harness.checkPoint("(int, int, Object, DataBuffer(UShort))");
SinglePixelPackedSampleModel m1 = new SinglePixelPackedSampleModel(
DataBuffer.TYPE_USHORT, 2, 3, new int[] { 0xFF00, 0x00FF }
);
short[] s = new short[] { (short) 0x1111, (short) 0x2222, (short) 0x3333, (short) 0x4444, (short) 0x5555, (short) 0x6666 };
DataBuffer db = new DataBufferUShort(s, 6);
// set a value
m1.setDataElements(0, 0, new short[] { (short) 0x7777 }, db);
m1.setDataElements(1, 0, new short[] { (short) 0x8888 }, db);
m1.setDataElements(0, 1, new short[] { (short) 0x9999 }, db);
m1.setDataElements(1, 1, new short[] { (short) 0xAAAA }, db);
m1.setDataElements(0, 2, new short[] { (short) 0xBBBB }, db);
m1.setDataElements(1, 2, new short[] { (short) 0xCCCC }, db);
harness.check(db.getElem(0), 0x7777);
harness.check(db.getElem(1), 0x8888);
harness.check(db.getElem(2), 0x9999);
harness.check(db.getElem(3), 0xAAAA);
harness.check(db.getElem(4), 0xBBBB);
harness.check(db.getElem(5), 0xCCCC);
// set a value with non-standard scanline stride
SinglePixelPackedSampleModel m2 = new SinglePixelPackedSampleModel(
DataBuffer.TYPE_USHORT, 2, 2, 3, new int[] { 0xFF00, 0x00FF }
);
m2.setDataElements(0, 0, new short[] { (short) 0x1111 }, db);
m2.setDataElements(1, 0, new short[] { (short) 0x2222 }, db);
m2.setDataElements(0, 1, new short[] { (short) 0x3333 }, db);
m2.setDataElements(1, 1, new short[] { (short) 0x4444 }, db);
harness.check(db.getElem(0), 0x1111);
harness.check(db.getElem(1), 0x2222);
harness.check(db.getElem(3), 0x3333);
harness.check(db.getElem(4), 0x4444);
// set a value with x < 0
try
{
m1.setDataElements(-1, 0, new short[] { (short) 0x9999 }, db);
harness.check(false); // should not get here
}
catch (ArrayIndexOutOfBoundsException e)
{
harness.check(true);
}
// set a value with y < 0
try
{
m1.setDataElements(0, -1, new short[] { (short) 0x9999 }, db);
harness.check(false); // should not get here
}
catch (ArrayIndexOutOfBoundsException e)
{
harness.check(true);
}
// set a value with wrong transfer type
try
{
m1.setDataElements(0, 0, new int[] { (int) 0x9999 }, db);
harness.check(false); // should not get here
}
catch (ClassCastException e)
{
harness.check(true);
}
// set a value with transfer array too small
try
{
m1.setDataElements(0, 0, new short[] {}, db);
harness.check(false); // should not get here
}
catch (ArrayIndexOutOfBoundsException e)
{
harness.check(true);
}
// set a value with null data buffer
try
{
m1.setDataElements(0, 0, new short[] { (short) 0x9999 }, null);
harness.check(false); // should not get here
}
catch (NullPointerException e)
{
harness.check(true);
}
}
private void testInt(TestHarness harness)
{
harness.checkPoint("(int, int, Object, DataBuffer(Int))");
SinglePixelPackedSampleModel m1 = new SinglePixelPackedSampleModel(
DataBuffer.TYPE_INT, 2, 3, new int[] { 0xFFFF00, 0x00FFFF }
);
int[] i = new int[] { (int) 0x11111111, (int) 0x22222222, (int) 0x33333333, (int) 0x44444444, (int) 0x55555555, (int) 0x66666666 };
DataBuffer db = new DataBufferInt(i, 6);
// set a value
m1.setDataElements(0, 0, new int[] { (int) 0x77777777 }, db);
m1.setDataElements(1, 0, new int[] { (int) 0x88888888 }, db);
m1.setDataElements(0, 1, new int[] { (int) 0x99999999 }, db);
m1.setDataElements(1, 1, new int[] { (int) 0xAAAAAAAA }, db);
m1.setDataElements(0, 2, new int[] { (int) 0xBBBBBBBB }, db);
m1.setDataElements(1, 2, new int[] { (int) 0xCCCCCCCC }, db);
harness.check(db.getElem(0), 0x77777777);
harness.check(db.getElem(1), 0x88888888);
harness.check(db.getElem(2), 0x99999999);
harness.check(db.getElem(3), 0xAAAAAAAA);
harness.check(db.getElem(4), 0xBBBBBBBB);
harness.check(db.getElem(5), 0xCCCCCCCC);
// set a value with non-standard scanline stride
SinglePixelPackedSampleModel m2 = new SinglePixelPackedSampleModel(
DataBuffer.TYPE_INT, 2, 2, 3, new int[] { 0xFFFF00, 0x00FFFF }
);
m2.setDataElements(0, 0, new int[] { (int) 0x11111111 }, db);
m2.setDataElements(1, 0, new int[] { (int) 0x22222222 }, db);
m2.setDataElements(0, 1, new int[] { (int) 0x33333333 }, db);
m2.setDataElements(1, 1, new int[] { (int) 0x44444444 }, db);
harness.check(db.getElem(0), 0x11111111);
harness.check(db.getElem(1), 0x22222222);
harness.check(db.getElem(3), 0x33333333);
harness.check(db.getElem(4), 0x44444444);
// set a value with x < 0
try
{
m1.setDataElements(-1, 0, new int[] { (int) 0x9999 }, db);
harness.check(false); // should not get here
}
catch (ArrayIndexOutOfBoundsException e)
{
harness.check(true);
}
// set a value with y < 0
try
{
m1.setDataElements(0, -1, new int[] { (int) 0x9999 }, db);
harness.check(false); // should not get here
}
catch (ArrayIndexOutOfBoundsException e)
{
harness.check(true);
}
// set a value with wrong transfer type
try
{
m1.setDataElements(0, 0, new short[] { (short) 0x9999 }, db);
harness.check(false); // should not get here
}
catch (ClassCastException e)
{
harness.check(true);
}
// set a value with transfer array too small
try
{
m1.setDataElements(0, 0, new int[] {}, db);
harness.check(false); // should not get here
}
catch (ArrayIndexOutOfBoundsException e)
{
harness.check(true);
}
// set a value with null data buffer
try
{
m1.setDataElements(0, 0, new int[] { (int) 0x9999 }, null);
harness.check(false); // should not get here
}
catch (NullPointerException e)
{
harness.check(true);
}
}
}
// Tags: JDK1.2
// Copyright (C) 2004 David Gilbert <david.gilbert@object-refinery.com>
// 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, 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA. */
package gnu.testlet.java.awt.image.SinglePixelPackedSampleModel;
import gnu.testlet.TestHarness;
import gnu.testlet.Testlet;
import java.awt.image.DataBuffer;
import java.awt.image.DataBufferByte;
import java.awt.image.DataBufferInt;
import java.awt.image.DataBufferUShort;
import java.awt.image.SinglePixelPackedSampleModel;
/**
* Some checks for the <code>setPixel()</code> method in the
* {@link SinglePixelPackedSampleModel} class.
*/
public class setPixel implements Testlet
{
/**
* Runs the test using the specified harness.
*
* @param harness the test harness (<code>null</code> not permitted).
*/
public void test(TestHarness harness)
{
testByte(harness);
testUShort(harness);
testInt(harness);
}
private void testByte(TestHarness harness)
{
harness.checkPoint("(int, int, Object, DataBuffer(Byte))");
SinglePixelPackedSampleModel m1 = new SinglePixelPackedSampleModel(
DataBuffer.TYPE_BYTE, 2, 3, new int[] { 0xF0, 0x0F }
);
byte[] b = new byte[] { (byte) 0x11, (byte) 0x22, (byte) 0x33, (byte) 0x44, (byte) 0x55, (byte) 0x66 };
DataBuffer db = new DataBufferByte(b, 6);
// set a value
m1.setPixel(0, 0, new int[] { 0x0C, 0x07 }, db);
m1.setPixel(1, 0, new int[] { 0x0B, 0x08 }, db);
m1.setPixel(0, 1, new int[] { 0x0A, 0x09 }, db);
m1.setPixel(1, 1, new int[] { 0x09, 0x0A }, db);
m1.setPixel(0, 2, new int[] { 0x08, 0x0B }, db);
m1.setPixel(1, 2, new int[] { 0x07, 0x0C }, db);
harness.check(db.getElem(0), 0xC7);
harness.check(db.getElem(1), 0xB8);
harness.check(db.getElem(2), 0xA9);
harness.check(db.getElem(3), 0x9A);
harness.check(db.getElem(4), 0x8B);
harness.check(db.getElem(5), 0x7C);
// set a value with non-standard scanline stride
SinglePixelPackedSampleModel m2 = new SinglePixelPackedSampleModel(
DataBuffer.TYPE_BYTE, 2, 2, 3, new int[] { 0xF0, 0x0F }
);
m2.setPixel(0, 0, new int[] { 0x04, 0x01 }, db);
m2.setPixel(1, 0, new int[] { 0x03, 0x02 }, db);
m2.setPixel(0, 1, new int[] { 0x02, 0x03 }, db);
m2.setPixel(1, 1, new int[] { 0x01, 0x04 }, db);
harness.check(db.getElem(0), 0x41);
harness.check(db.getElem(1), 0x32);
harness.check(db.getElem(3), 0x23);
harness.check(db.getElem(4), 0x14);
// set a value with x < 0
try
{
m1.setPixel(-1, 0, new int[] { 0x10, 0x01 }, db);
harness.check(false); // should not get here
}
catch (ArrayIndexOutOfBoundsException e)
{
harness.check(true);
}
// set a value with y < 0
try
{
m1.setPixel(0, -1, new int[] { 0x10, 0x01 }, db);
harness.check(false); // should not get here
}
catch (ArrayIndexOutOfBoundsException e)
{
harness.check(true);
}
// set a value with transfer array too small
try
{
m1.setPixel(0, 0, new int[] {}, db);
harness.check(false); // should not get here
}
catch (ArrayIndexOutOfBoundsException e)
{
harness.check(true);
}
// set a value with null data buffer
try
{
m1.setPixel(0, 0, new int[] { 0x10, 0x01 }, null);
harness.check(false); // should not get here
}
catch (NullPointerException e)
{
harness.check(true);
}
}
private void testUShort(TestHarness harness)
{
harness.checkPoint("(int, int, Object, DataBuffer(UShort))");
SinglePixelPackedSampleModel m1 = new SinglePixelPackedSampleModel(
DataBuffer.TYPE_USHORT, 2, 3, new int[] { 0xFF00, 0x00FF }
);
short[] s = new short[] { (short) 0x1111, (short) 0x2222, (short) 0x3333, (short) 0x4444, (short) 0x5555, (short) 0x6666 };
DataBuffer db = new DataBufferUShort(s, 6);
// set a value
m1.setPixel(0, 0, new int[] { 0x00CC, 0x0077 }, db);
m1.setPixel(1, 0, new int[] { 0x00BB, 0x0088 }, db);
m1.setPixel(0, 1, new int[] { 0x00AA, 0x0099 }, db);
m1.setPixel(1, 1, new int[] { 0x0099, 0x00AA }, db);
m1.setPixel(0, 2, new int[] { 0x0088, 0x00BB }, db);
m1.setPixel(1, 2, new int[] { 0x0077, 0x00CC }, db);
harness.check(db.getElem(0), 0xCC77);
harness.check(db.getElem(1), 0xBB88);
harness.check(db.getElem(2), 0xAA99);
harness.check(db.getElem(3), 0x99AA);
harness.check(db.getElem(4), 0x88BB);
harness.check(db.getElem(5), 0x77CC);
// set a value with non-standard scanline stride
SinglePixelPackedSampleModel m2 = new SinglePixelPackedSampleModel(
DataBuffer.TYPE_USHORT, 2, 2, 3, new int[] { 0xFF00, 0x00FF }
);
m2.setPixel(0, 0, new int[] { 0x0044, 0x0011 }, db);
m2.setPixel(1, 0, new int[] { 0x0033, 0x0022 }, db);
m2.setPixel(0, 1, new int[] { 0x0022, 0x0033 }, db);
m2.setPixel(1, 1, new int[] { 0x0011, 0x0044 }, db);
harness.check(db.getElem(0), 0x4411);
harness.check(db.getElem(1), 0x3322);
harness.check(db.getElem(3), 0x2233);
harness.check(db.getElem(4), 0x1144);
// set a value with x < 0
try
{
m1.setPixel(-1, 0, new int[] { 0x10, 0x01 }, db);
harness.check(false); // should not get here
}
catch (ArrayIndexOutOfBoundsException e)
{
harness.check(true);
}
// set a value with y < 0
try
{
m1.setPixel(0, -1, new int[] { 0x10, 0x01 }, db);
harness.check(false); // should not get here
}
catch (ArrayIndexOutOfBoundsException e)
{
harness.check(true);
}
// set a value with transfer array too small
try
{
m1.setPixel(0, 0, new int[] {}, db);
harness.check(false); // should not get here
}
catch (ArrayIndexOutOfBoundsException e)
{
harness.check(true);
}
// set a value with null data buffer
try
{
m1.setPixel(0, 0, new int[] { 0x10, 0x01 }, null);
harness.check(false); // should not get here
}
catch (NullPointerException e)
{
harness.check(true);
}
}
private void testInt(TestHarness harness)
{
harness.checkPoint("(int, int, Object, DataBuffer(Int))");
SinglePixelPackedSampleModel m1 = new SinglePixelPackedSampleModel(
DataBuffer.TYPE_INT, 2, 3, new int[] { 0xFFFF0000, 0x0000FFFF }
);
int[] i = new int[] { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666 };
DataBuffer db = new DataBufferInt(i, 6);
// set a value
m1.setPixel(0, 0, new int[] { 0x00CC, 0x0077 }, db);
m1.setPixel(1, 0, new int[] { 0x00BB, 0x0088 }, db);
m1.setPixel(0, 1, new int[] { 0x00AA, 0x0099 }, db);
m1.setPixel(1, 1, new int[] { 0x0099, 0x00AA }, db);
m1.setPixel(0, 2, new int[] { 0x0088, 0x00BB }, db);
m1.setPixel(1, 2, new int[] { 0x0077, 0x00CC }, db);
harness.check(db.getElem(0), 0x00CC0077);
harness.check(db.getElem(1), 0x00BB0088);
harness.check(db.getElem(2), 0x00AA0099);
harness.check(db.getElem(3), 0x009900AA);
harness.check(db.getElem(4), 0x008800BB);
harness.check(db.getElem(5), 0x007700CC);
// set a value with non-standard scanline stride
SinglePixelPackedSampleModel m2 = new SinglePixelPackedSampleModel(
DataBuffer.TYPE_INT, 2, 2, 3, new int[] { 0xFFFF0000, 0x0000FFFF }
);
m2.setPixel(0, 0, new int[] { 0x0044, 0x0011 }, db);
m2.setPixel(1, 0, new int[] { 0x0033, 0x0022 }, db);
m2.setPixel(0, 1, new int[] { 0x0022, 0x0033 }, db);
m2.setPixel(1, 1, new int[] { 0x0011, 0x0044 }, db);
harness.check(db.getElem(0), 0x00440011);
harness.check(db.getElem(1), 0x00330022);
harness.check(db.getElem(3), 0x00220033);
harness.check(db.getElem(4), 0x00110044);
// set a value with x < 0
try
{
m1.setPixel(-1, 0, new int[] { 0x10, 0x01 }, db);
harness.check(false); // should not get here
}
catch (ArrayIndexOutOfBoundsException e)
{
harness.check(true);
}
// set a value with y < 0
try
{
m1.setPixel(0, -1, new int[] { 0x10, 0x01 }, db);
harness.check(false); // should not get here
}
catch (ArrayIndexOutOfBoundsException e)
{
harness.check(true);
}
// set a value with transfer array too small
try
{
m1.setPixel(0, 0, new int[] {}, db);
harness.check(false); // should not get here
}
catch (ArrayIndexOutOfBoundsException e)
{
harness.check(true);
}
// set a value with null data buffer
try
{
m1.setPixel(0, 0, new int[] { 0x10, 0x01 }, null);
harness.check(false); // should not get here
}
catch (NullPointerException e)
{
harness.check(true);
}
}
}
// Tags: JDK1.2
// Copyright (C) 2004 David Gilbert <david.gilbert@object-refinery.com>
// 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, 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA. */
package gnu.testlet.java.awt.image.SinglePixelPackedSampleModel;
import gnu.testlet.TestHarness;
import gnu.testlet.Testlet;
import java.awt.image.DataBuffer;
import java.awt.image.DataBufferByte;
import java.awt.image.DataBufferInt;
import java.awt.image.DataBufferUShort;
import java.awt.image.SinglePixelPackedSampleModel;
/**
* Some checks for the <code>setSample()</code> method in the
* {@link SinglePixelPackedSampleModel} class.
*/
public class setSample implements Testlet
{
/**
* Runs the test using the specified harness.
*
* @param harness the test harness (<code>null</code> not permitted).
*/
public void test(TestHarness harness)
{
testByte(harness);
testUShort(harness);
testInt(harness);
}
private void testByte(TestHarness harness)
{
harness.checkPoint("(int, int, int, int, DataBuffer(Byte))");
SinglePixelPackedSampleModel m1 = new SinglePixelPackedSampleModel(
DataBuffer.TYPE_BYTE, 2, 3, new int[] { 0xF0, 0x0F }
);
byte[] b = new byte[] { (byte) 0x11, (byte) 0x22, (byte) 0x33, (byte) 0x44, (byte) 0x55, (byte) 0x66 };
DataBuffer db = new DataBufferByte(b, 6);
// set a value
m1.setSample(0, 0, 1, 0x07, db);
m1.setSample(1, 0, 1, 0x08, db);
m1.setSample(0, 1, 1, 0x09, db);
m1.setSample(1, 1, 1, 0x0A, db);
m1.setSample(0, 2, 1, 0x0B, db);
m1.setSample(1, 2, 1, 0x0C, db);
harness.check(db.getElem(0), 0x17);
harness.check(db.getElem(1), 0x28);
harness.check(db.getElem(2), 0x39);
harness.check(db.getElem(3), 0x4A);
harness.check(db.getElem(4), 0x5B);
harness.check(db.getElem(5), 0x6C);
// set a value with non-standard scanline stride
SinglePixelPackedSampleModel m2 = new SinglePixelPackedSampleModel(
DataBuffer.TYPE_BYTE, 2, 2, 3, new int[] { 0xF0, 0x0F }
);
m2.setSample(0, 0, 0, 0x04, db);
m2.setSample(1, 0, 0, 0x03, db);
m2.setSample(0, 1, 0, 0x02, db);
m2.setSample(1, 1, 0, 0x01, db);
m2.setSample(0, 0, 1, 0x01, db);
m2.setSample(1, 0, 1, 0x02, db);
m2.setSample(0, 1, 1, 0x03, db);
m2.setSample(1, 1, 1, 0x04, db);
harness.check(db.getElem(0), 0x41);
harness.check(db.getElem(1), 0x32);
harness.check(db.getElem(3), 0x23);
harness.check(db.getElem(4), 0x14);
// set a value with x < 0
try
{
m1.setSample(-1, 0, 0, 0x10, db);
harness.check(false); // should not get here
}
catch (ArrayIndexOutOfBoundsException e)
{
harness.check(true);
}
// set a value with y < 0
try
{
m1.setSample(0, -1, 0, 0x10, db);
harness.check(false); // should not get here
}
catch (ArrayIndexOutOfBoundsException e)
{
harness.check(true);
}
// set a value with sample index < 0
try
{
m1.setSample(0, 0, -1, 0x10, db);
harness.check(false); // should not get here
}
catch (ArrayIndexOutOfBoundsException e)
{
harness.check(true);
}
// set a value with null data buffer
try
{
m1.setSample(0, 0, 0, 0x01, null);
harness.check(false); // should not get here
}
catch (NullPointerException e)
{
harness.check(true);
}
}
private void testUShort(TestHarness harness)
{
harness.checkPoint("(int, int, int, int, DataBuffer(UShort))");
SinglePixelPackedSampleModel m1 = new SinglePixelPackedSampleModel(
DataBuffer.TYPE_USHORT, 2, 3, new int[] { 0xFF00, 0x00FF }
);
short[] s = new short[] { (short) 0x1111, (short) 0x2222, (short) 0x3333, (short) 0x4444, (short) 0x5555, (short) 0x6666 };
DataBuffer db = new DataBufferUShort(s, 6);
// set a value
m1.setSample(0, 0, 0, 0x00CC, db);
m1.setSample(1, 0, 0, 0x00BB, db);
m1.setSample(0, 1, 0, 0x00AA, db);
m1.setSample(1, 1, 0, 0x0099, db);
m1.setSample(0, 2, 0, 0x0088, db);
m1.setSample(1, 2, 0, 0x0077, db);
m1.setSample(0, 0, 1, 0x0077, db);
m1.setSample(1, 0, 1, 0x0088, db);
m1.setSample(0, 1, 1, 0x0099, db);
m1.setSample(1, 1, 1, 0x00AA, db);
m1.setSample(0, 2, 1, 0x00BB, db);
m1.setSample(1, 2, 1, 0x00CC, db);
harness.check(db.getElem(0), 0xCC77);
harness.check(db.getElem(1), 0xBB88);
harness.check(db.getElem(2), 0xAA99);
harness.check(db.getElem(3), 0x99AA);
harness.check(db.getElem(4), 0x88BB);
harness.check(db.getElem(5), 0x77CC);
// set a value with non-standard scanline stride
SinglePixelPackedSampleModel m2 = new SinglePixelPackedSampleModel(
DataBuffer.TYPE_USHORT, 2, 2, 3, new int[] { 0xFF00, 0x00FF }
);
m2.setSample(0, 0, 0, 0x0044, db);
m2.setSample(1, 0, 0, 0x0033, db);
m2.setSample(0, 1, 0, 0x0022, db);
m2.setSample(1, 1, 0, 0x0011, db);
m2.setSample(0, 0, 1, 0x0011, db);
m2.setSample(1, 0, 1, 0x0022, db);
m2.setSample(0, 1, 1, 0x0033, db);
m2.setSample(1, 1, 1, 0x0044, db);
harness.check(db.getElem(0), 0x4411);
harness.check(db.getElem(1), 0x3322);
harness.check(db.getElem(3), 0x2233);
harness.check(db.getElem(4), 0x1144);
// set a value with x < 0
try
{
m1.setSample(-1, 0, 0, 0x0044, db);
harness.check(false); // should not get here
}
catch (ArrayIndexOutOfBoundsException e)
{
harness.check(true);
}
// set a value with y < 0
try
{
m1.setSample(0, -1, 0, 0x0044, db);
harness.check(false); // should not get here
}
catch (ArrayIndexOutOfBoundsException e)
{
harness.check(true);
}
// set a value with sample index < 0
try
{
m1.setSample(0, 0, -1, 0x0044, db);
harness.check(false); // should not get here
}
catch (ArrayIndexOutOfBoundsException e)
{
harness.check(true);
}
// set a value with null data buffer
try
{
m1.setSample(0, 0, 0, 0x0044, null);
harness.check(false); // should not get here
}
catch (NullPointerException e)
{
harness.check(true);
}
}
private void testInt(TestHarness harness)
{
harness.checkPoint("(int, int, int, int, DataBuffer(Int))");
SinglePixelPackedSampleModel m1 = new SinglePixelPackedSampleModel(
DataBuffer.TYPE_INT, 2, 3, new int[] { 0xFFFF0000, 0x0000FFFF }
);
int[] i = new int[] { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666 };
DataBuffer db = new DataBufferInt(i, 6);
// set a value
m1.setSample(0, 0, 0, 0x00CC, db);
m1.setSample(1, 0, 0, 0x00BB, db);
m1.setSample(0, 1, 0, 0x00AA, db);
m1.setSample(1, 1, 0, 0x0099, db);
m1.setSample(0, 2, 0, 0x0088, db);
m1.setSample(1, 2, 0, 0x0077, db);
m1.setSample(0, 0, 1, 0x0077, db);
m1.setSample(1, 0, 1, 0x0088, db);
m1.setSample(0, 1, 1, 0x0099, db);
m1.setSample(1, 1, 1, 0x00AA, db);
m1.setSample(0, 2, 1, 0x00BB, db);
m1.setSample(1, 2, 1, 0x00CC, db);
harness.check(db.getElem(0), 0x00CC0077);
harness.check(db.getElem(1), 0x00BB0088);
harness.check(db.getElem(2), 0x00AA0099);
harness.check(db.getElem(3), 0x009900AA);
harness.check(db.getElem(4), 0x008800BB);
harness.check(db.getElem(5), 0x007700CC);
// set a value with non-standard scanline stride
SinglePixelPackedSampleModel m2 = new SinglePixelPackedSampleModel(
DataBuffer.TYPE_INT, 2, 2, 3, new int[] { 0xFFFF0000, 0x0000FFFF }
);
m2.setSample(0, 0, 0, 0x0044, db);
m2.setSample(1, 0, 0, 0x0033, db);
m2.setSample(0, 1, 0, 0x0022, db);
m2.setSample(1, 1, 0, 0x0011, db);
m2.setSample(0, 0, 1, 0x0011, db);
m2.setSample(1, 0, 1, 0x0022, db);
m2.setSample(0, 1, 1, 0x0033, db);
m2.setSample(1, 1, 1, 0x0044, db);
harness.check(db.getElem(0), 0x00440011);
harness.check(db.getElem(1), 0x00330022);
harness.check(db.getElem(3), 0x00220033);
harness.check(db.getElem(4), 0x00110044);
// set a value with x < 0
try
{
m1.setSample(-1, 0, 0, 0x10, db);
harness.check(false); // should not get here
}
catch (ArrayIndexOutOfBoundsException e)
{
harness.check(true);
}
// set a value with y < 0
try
{
m1.setSample(0, -1, 0, 0x10, db);
harness.check(false); // should not get here
}
catch (ArrayIndexOutOfBoundsException e)
{
harness.check(true);
}
// set a value with sample index < 0
try
{
m1.setSample(0, 0, -1, 0x10, db);
harness.check(false); // should not get here
}
catch (ArrayIndexOutOfBoundsException e)
{
harness.check(true);
}
// set a value with null data buffer
try
{
m1.setSample(0, 0, 0, 0x10, null);
harness.check(false); // should not get here
}
catch (NullPointerException e)
{
harness.check(true);
}
}
}