This is the mail archive of the
mauve-patches@sourceware.org
mailing list for the Mauve project.
FYI: complete ImageInputStreamImpl test
- From: Thomas Fitzsimmons <fitzsim at redhat dot com>
- To: mauve-patches at sources dot redhat dot com
- Date: Thu, 18 May 2006 22:11:59 -0400
- Subject: FYI: complete ImageInputStreamImpl test
Hi,
I committed this patch which completes the ImageInputStreamImpl test.
Tom
2006-05-18 Thomas Fitzsimmons <fitzsim@redhat.com>
*
gnu/testlet/javax/imageio/stream/MemoryCacheImageInputStream/TestImageInputStreamImpl.java:
Complete test.
Index: gnu/testlet/javax/imageio/stream/MemoryCacheImageInputStream/TestImageInputStreamImpl.java
===================================================================
RCS file: /cvs/mauve/mauve/gnu/testlet/javax/imageio/stream/MemoryCacheImageInputStream/TestImageInputStreamImpl.java,v
retrieving revision 1.1
diff -u -r1.1 TestImageInputStreamImpl.java
--- gnu/testlet/javax/imageio/stream/MemoryCacheImageInputStream/TestImageInputStreamImpl.java 18 May 2006 01:52:55 -0000 1.1
+++ gnu/testlet/javax/imageio/stream/MemoryCacheImageInputStream/TestImageInputStreamImpl.java 19 May 2006 02:08:56 -0000
@@ -24,6 +24,7 @@
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.nio.ByteOrder;
+import java.util.Arrays;
import javax.imageio.stream.ImageInputStream;
import javax.imageio.stream.ImageInputStreamImpl;
@@ -33,8 +34,7 @@
import gnu.testlet.Testlet;
/**
- * Test ImageInputStreamImpl's read methods reading from an in-memory
- * source.
+ * Test ImageInputStreamImpl.
*/
public class TestImageInputStreamImpl
implements Testlet
@@ -42,6 +42,8 @@
public void test(TestHarness h)
{
+ int k = 0;
+
try
{
// Test unsigned values.
@@ -61,6 +63,9 @@
ImageInputStream i = new MemoryCacheImageInputStream(bs);
// Test ByteOrder.BIG_ENDIAN, the default.
+
+ h.check(i.getByteOrder() == ByteOrder.BIG_ENDIAN);
+
h.check(i.read() == 114);
i.seek(0);
h.check(i.readBoolean() == true);
@@ -87,6 +92,8 @@
// Test ByteOrder.LITTLE_ENDIAN.
i.setByteOrder(ByteOrder.LITTLE_ENDIAN);
+
+ h.check(i.getByteOrder() == ByteOrder.LITTLE_ENDIAN);
i.seek(0);
h.check(i.read() == 114);
i.seek(0);
@@ -179,6 +186,513 @@
h.check(i.readUnsignedInt() == 1996849298);
i.seek(0);
h.check(i.readUnsignedShort() == 32914);
+
+ // Test flush().
+
+ i.seek(4);
+
+ h.check(i.getStreamPosition() == 4);
+
+ i.flush();
+
+ h.check(i.getFlushedPosition() == 4);
+
+ boolean exceptionThrown = false;
+ try
+ {
+ i.flushBefore(3);
+ }
+ catch (IndexOutOfBoundsException e)
+ {
+ exceptionThrown = true;
+ }
+ h.check(exceptionThrown);
+
+ exceptionThrown = false;
+ try
+ {
+ i.flushBefore(5);
+ }
+ catch (IndexOutOfBoundsException e)
+ {
+ exceptionThrown = true;
+ }
+ h.check(exceptionThrown);
+
+ exceptionThrown = false;
+ try
+ {
+ i.seek(2);
+ }
+ catch (IndexOutOfBoundsException e)
+ {
+ exceptionThrown = true;
+ }
+ h.check(exceptionThrown);
+
+ exceptionThrown = false;
+ try
+ {
+ i.seek(3);
+ }
+ catch (IndexOutOfBoundsException e)
+ {
+ exceptionThrown = true;
+ }
+ h.check(exceptionThrown);
+
+ exceptionThrown = false;
+ try
+ {
+ i.setBitOffset(-1);
+ }
+ catch (IllegalArgumentException e)
+ {
+ exceptionThrown = true;
+ }
+ h.check(exceptionThrown);
+
+ exceptionThrown = false;
+ try
+ {
+ i.setBitOffset(8);
+ }
+ catch (IllegalArgumentException e)
+ {
+ exceptionThrown = true;
+ }
+ h.check(exceptionThrown);
+
+ i.setBitOffset(4);
+ h.check(i.getBitOffset() == 4);
+
+ // A MemoryCacheImageInputStream is cached in memory.
+ h.check(i.isCached() == true);
+ h.check(i.isCachedFile() == false);
+ h.check(i.isCachedMemory() == true);
+
+ h.check(i.length() == -1);
+
+ // Test mark() and reset().
+ i.seek(4);
+ i.mark();
+
+ i.read();
+ i.read();
+
+ i.reset();
+ h.check(i.getStreamPosition() == 4);
+
+ // Test readBit().
+ // We're currently at b[4], byte 0xac.
+ h.check(i.readBit() == 1);
+ h.check(i.readBit() == 0);
+ h.check(i.readBit() == 1);
+ h.check(i.readBit() == 0);
+ h.check(i.readBit() == 1);
+ h.check(i.readBit() == 1);
+ h.check(i.readBit() == 0);
+
+ // Check that the bit offset is incremented.
+ h.check(i.getBitOffset() == 7);
+
+ // Roll back the bit offset within the same byte.
+ i.setBitOffset(2);
+
+ // R-read some bits within the same byte.
+ h.check(i.readBit() == 1);
+ h.check(i.readBit() == 0);
+ h.check(i.readBit() == 1);
+ h.check(i.readBit() == 1);
+ h.check(i.readBit() == 0);
+
+ // Check that the stream position is still 4.
+ h.check(i.getStreamPosition() == 4);
+
+ // Read the final bit in b[4].
+ h.check(i.readBit() == 0);
+
+ // Check that readBit on the 8th bit increments the stream
+ // position.
+ h.check(i.getStreamPosition() == 5);
+
+ // Read the bits from b[5], byte 0xf2.
+ h.check(i.readBit() == 1);
+ h.check(i.readBit() == 1);
+ h.check(i.readBit() == 1);
+ h.check(i.readBit() == 1);
+
+ h.check(i.getBitOffset() == 4);
+
+ h.check(i.readBit() == 0);
+ h.check(i.readBit() == 0);
+ h.check(i.readBit() == 1);
+ h.check(i.readBit() == 0);
+
+ // Check that the bit offset is reset and the position
+ // incremented.
+ h.check(i.getBitOffset() == 0);
+ h.check(i.getStreamPosition() == 6);
+
+ h.check(i.length() == -1);
+
+ // Test close().
+ i.close();
+
+ // Test checkClosed().
+ exceptionThrown = false;
+ try
+ {
+ i.close();
+ }
+ catch (IOException e)
+ {
+ exceptionThrown = true;
+ }
+ h.check(exceptionThrown);
+
+ // 64 bytes of data.
+ b = new byte[]
+ {
+ (byte) 0x92, (byte) 0x80, (byte) 0x05, (byte) 0x77,
+ (byte) 0xac, (byte) 0xf2, (byte) 0x8b, (byte) 0xa7,
+ (byte) 0x5c, (byte) 0xd0, (byte) 0xaa, (byte) 0x0f,
+ (byte) 0x89, (byte) 0x00, (byte) 0x12, (byte) 0xf1,
+ (byte) 0xa1, (byte) 0xef, (byte) 0x82, (byte) 0x00,
+ (byte) 0x92, (byte) 0x80, (byte) 0x05, (byte) 0x77,
+ (byte) 0xac, (byte) 0xf2, (byte) 0x8b, (byte) 0xa7,
+ (byte) 0x5c, (byte) 0xd0, (byte) 0xaa, (byte) 0x0f,
+ (byte) 0x89, (byte) 0x00, (byte) 0x12, (byte) 0xf1,
+ (byte) 0xa1, (byte) 0xef, (byte) 0x82, (byte) 0x00,
+ (byte) 0x92, (byte) 0x80, (byte) 0x05, (byte) 0x77,
+ (byte) 0xac, (byte) 0xf2, (byte) 0x8b, (byte) 0xa7,
+ (byte) 0x5c, (byte) 0xd0, (byte) 0xaa, (byte) 0x0f,
+ (byte) 0x89, (byte) 0x00, (byte) 0x12, (byte) 0xf1,
+ (byte) 0xa1, (byte) 0xef, (byte) 0x82, (byte) 0x00,
+ (byte) 0x92, (byte) 0x80, (byte) 0x05, (byte) 0x77,
+ };
+
+ bs = new ByteArrayInputStream(b);
+ i = new MemoryCacheImageInputStream(bs);
+
+ // Test readBits().
+ i.seek(5);
+ i.setBitOffset(6);
+
+ exceptionThrown = false;
+ try
+ {
+ i.readBits(-1);
+ }
+ catch (IllegalArgumentException e)
+ {
+ exceptionThrown = true;
+ }
+ h.check(exceptionThrown);
+
+ exceptionThrown = false;
+ try
+ {
+ i.readBits(65);
+ }
+ catch (IllegalArgumentException e)
+ {
+ exceptionThrown = true;
+ }
+ h.check(exceptionThrown);
+
+ h.check(i.readBits(59) == 366848453836545810L);
+
+ i.seek(5);
+ i.setBitOffset(6);
+ h.check(i.readBits(58) == 183424226918272905L);
+
+ b = new byte[]
+ {
+ (byte) 0xa2, (byte) 0xe9, (byte) 0xd7, (byte) 0x34,
+ (byte) 0x2a, (byte) 0x83, (byte) 0xe2, (byte) 0x40
+ };
+ bs = new ByteArrayInputStream(b);
+ i = new MemoryCacheImageInputStream(bs);
+ h.check(i.readBits(59) == 366848453836545810L);
+
+ b = new byte[]
+ {
+ (byte) 0xa2, (byte) 0x02
+ };
+ bs = new ByteArrayInputStream(b);
+ i = new MemoryCacheImageInputStream(bs);
+
+ long[] res = new long[8];
+
+ i.seek(0);
+
+ h.check(i.readBits(0) == 0);
+ i.seek(0);
+
+ for (k = 0; k < 8; k++)
+ {
+ i.setBitOffset(k);
+ res[k] = i.readBits(8);
+ i.seek(0);
+ }
+ i.seek(0);
+ h.check(Arrays.equals(res, new long[] { 162, 68, 136, 16,
+ 32, 64, 128, 1 }));
+
+ // 64 bytes of data.
+ b = new byte[]
+ {
+ (byte) 0x92, (byte) 0x80, (byte) 0x05, (byte) 0x77,
+ (byte) 0xac, (byte) 0xf2, (byte) 0x8b, (byte) 0xa7,
+ (byte) 0x5c, (byte) 0xd0, (byte) 0xaa, (byte) 0x0f,
+ // Here is a two-character-long UTF String to be read by
+ // DataInputStream.
+ (byte) 0x00, (byte) 0x02, (byte) 0x12, (byte) 0x21,
+ (byte) 0xa1, (byte) 0xef, (byte) 0x82, (byte) 0x00,
+ (byte) 0x92, (byte) 0x80, (byte) 0x05, (byte) 0x77,
+ (byte) 0xac, (byte) 0xf2, (byte) 0x8b, (byte) 0xa7,
+ (byte) 0x5c, (byte) 0xd0, (byte) 0xaa, (byte) 0x0f,
+ (byte) 0x89, (byte) 0x00, (byte) 0x12, (byte) 0xf1,
+ (byte) 0xa1, (byte) 0xef, (byte) 0x82, (byte) 0x00,
+ (byte) 0x92, (byte) 0x80, (byte) 0x05, (byte) 0x77,
+ (byte) 0xac, (byte) 0xf2, (byte) 0x8b, (byte) 0xa7,
+ (byte) 0x5c, (byte) 0xd0, (byte) 0xaa, (byte) 0x0f,
+ (byte) 0x89, (byte) 0x00, (byte) 0x12, (byte) 0xf1,
+ (byte) 0xa1, (byte) 0xef, (byte) 0x82, (byte) 0x00,
+ (byte) 0x92, (byte) 0x80, (byte) 0x05, (byte) 0x77,
+ };
+
+ bs = new ByteArrayInputStream(b);
+ i = new MemoryCacheImageInputStream(bs);
+
+ // Test mark() and reset().
+ i.seek(17);
+ h.check(i.getStreamPosition() == 17);
+ i.mark();
+ i.seek(49);
+ h.check(i.getStreamPosition() == 49);
+ i.reset();
+ h.check(i.getStreamPosition() == 17);
+
+ // Test skipBytes().
+ i.setBitOffset(3);
+ i.skipBytes(20);
+ h.check(i.getStreamPosition() == 37);
+ h.check(i.getBitOffset() == 0);
+
+ // Test readUTF().
+ i.seek(12);
+ String str = i.readUTF();
+ h.check(str.codePointAt(0) == 18);
+ h.check(str.codePointAt(1) == 33);
+
+ b = new byte[]
+ { (byte) 0x47, (byte) 0x4e, (byte) 0x55,
+ '\r',
+ (byte) 0x43, (byte) 0x6c, (byte) 0x61, (byte) 0x73, (byte) 0x73,
+ (byte) 0x70, (byte) 0x61, (byte) 0x74, (byte) 0x68,
+ '\r', '\n',
+ (byte) 0x52, (byte) 0x75, (byte) 0x6c,
+ (byte) 0x65, (byte) 0x7a,
+ '\n',
+ (byte) 0x44, (byte) 0x75, (byte) 0x64, (byte) 0x65, (byte) 0x7a,
+ (byte) 0x21,
+ '\r'
+ };
+
+ bs = new ByteArrayInputStream(b);
+ i = new MemoryCacheImageInputStream(bs);
+
+ h.check(i.readLine().equals("GNU"));
+ h.check(i.readLine().equals("Classpath"));
+ h.check(i.readLine().equals("Rulez"));
+ h.check(i.readLine().equals("Dudez!"));
+ h.check(i.readLine() == null);
+
+ // 64 bytes of data.
+ b = new byte[]
+ {
+ (byte) 0x92, (byte) 0x80, (byte) 0x05, (byte) 0x77,
+ (byte) 0xac, (byte) 0xf2, (byte) 0x8b, (byte) 0xa7,
+ (byte) 0x5c, (byte) 0xd0, (byte) 0xaa, (byte) 0x0f,
+ (byte) 0x89, (byte) 0x00, (byte) 0x12, (byte) 0xf1,
+ (byte) 0xa1, (byte) 0xef, (byte) 0x82, (byte) 0x00,
+ (byte) 0x92, (byte) 0x80, (byte) 0x05, (byte) 0x77,
+ (byte) 0xac, (byte) 0xf2, (byte) 0x8b, (byte) 0xa7,
+ (byte) 0x5c, (byte) 0xd0, (byte) 0xaa, (byte) 0x0f,
+ (byte) 0x89, (byte) 0x00, (byte) 0x12, (byte) 0xf1,
+ (byte) 0xa1, (byte) 0xef, (byte) 0x82, (byte) 0x00,
+ (byte) 0x92, (byte) 0x80, (byte) 0x05, (byte) 0x77,
+ (byte) 0xac, (byte) 0xf2, (byte) 0x8b, (byte) 0xa7,
+ (byte) 0x5c, (byte) 0xd0, (byte) 0xaa, (byte) 0x0f,
+ (byte) 0x89, (byte) 0x00, (byte) 0x12, (byte) 0xf1,
+ (byte) 0xa1, (byte) 0xef, (byte) 0x82, (byte) 0x00,
+ (byte) 0x92, (byte) 0x80, (byte) 0x05, (byte) 0x77,
+ };
+
+ bs = new ByteArrayInputStream(b);
+ i = new MemoryCacheImageInputStream(bs);
+
+ byte[] fullB = new byte[26];
+ i.seek(0);
+ i.readFully(fullB);
+ h.check(Arrays.equals(fullB,
+ new byte[]
+ {
+ (byte) 0x92, (byte) 0x80, (byte) 0x05, (byte) 0x77,
+ (byte) 0xac, (byte) 0xf2, (byte) 0x8b, (byte) 0xa7,
+ (byte) 0x5c, (byte) 0xd0, (byte) 0xaa, (byte) 0x0f,
+ (byte) 0x89, (byte) 0x00, (byte) 0x12, (byte) 0xf1,
+ (byte) 0xa1, (byte) 0xef, (byte) 0x82, (byte) 0x00,
+ (byte) 0x92, (byte) 0x80, (byte) 0x05, (byte) 0x77,
+ (byte) 0xac, (byte) 0xf2
+ }));
+
+ for (k = 0; k < fullB.length; k++)
+ fullB[k] = 0;
+
+ i.seek(0);
+ i.readFully(fullB, 5, 13);
+
+ h.check(Arrays.equals(fullB, new byte[]
+ {
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x92, (byte) 0x80, (byte) 0x05,
+ (byte) 0x77, (byte) 0xac, (byte) 0xf2, (byte) 0x8b,
+ (byte) 0xa7, (byte) 0x5c, (byte) 0xd0, (byte) 0xaa,
+ (byte) 0x0f, (byte) 0x89, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00
+ }));
+
+ char[] fullC = new char[15];
+ i.seek(0);
+ i.readFully(fullC, 0, 15);
+
+ h.check(Arrays.equals(fullC, new char[]
+ {
+ (char) 37504, (char) 1399, (char) 44274,
+ (char) 35751, (char) 23760, (char) 43535,
+ (char) 35072, (char) 4849, (char) 41455,
+ (char) 33280, (char) 37504, (char) 1399,
+ (char) 44274, (char) 35751, (char) 23760
+ }));
+
+ double[] fullD = new double[8];
+ i.seek(0);
+ i.readFully(fullD, 0, 8);
+
+ h.check(Arrays.equals(fullD, new double[] {
+ -1.4183142849706364E-219,
+ 1.2402952421911034E139,
+ -3.154063812740471E-145,
+ -3.556316535750171E-92,
+ -2.4925149951304603E-265,
+ -1.4183142849706364E-219,
+ 1.2402952421911034E139,
+ -3.154063812740471E-145
+ }));
+
+ float[] fullF = new float[16];
+ i.seek(0);
+ i.readFully(fullF, 0, 16);
+
+ h.check(Arrays.equals(fullF, new float[] {
+ -8.079283E-28f,
+ -6.893558E-12f,
+ 4.69870212E17f,
+ -1.5416346E-33f,
+ -1.6229681E-18f,
+ -8.079283E-28f,
+ -6.893558E-12f,
+ 4.69870212E17f,
+ -1.5416346E-33f,
+ -1.6229681E-18f,
+ -8.079283E-28f,
+ -6.893558E-12f,
+ 4.69870212E17f,
+ -1.5416346E-33f,
+ -1.6229681E-18f,
+ -8.079283E-28f
+ }));
+
+ int[] fullI = new int[16];
+ i.seek(0);
+ i.readFully(fullI, 0, 16);
+
+ h.check(Arrays.equals(fullI, new int[] {
+ -1837103753,
+ -1393390681,
+ 1557178895,
+ -1996483855,
+ -1578139136,
+ -1837103753,
+ -1393390681,
+ 1557178895,
+ -1996483855,
+ -1578139136,
+ -1837103753,
+ -1393390681,
+ 1557178895,
+ -1996483855,
+ -1578139136,
+ -1837103753,
+ }));
+
+ long[] fullL = new long[8];
+ i.seek(0);
+ i.readFully(fullL, 0, 8);
+
+ h.check(Arrays.equals(fullL, new long[] {
+ -7890300535592285273L,
+ 6688032430344901361L,
+ -6778055975199832713L,
+ -5984567403888989681L,
+ -8574832861500177920L,
+ -7890300535592285273L,
+ 6688032430344901361L,
+ -6778055975199832713L,
+ }));
+
+ short[] fullS = new short[32];
+ i.seek(0);
+ i.readFully(fullS, 0, 32);
+
+ h.check(Arrays.equals(fullS, new short[] {
+ -28032,
+ 1399,
+ -21262,
+ -29785,
+ 23760,
+ -22001,
+ -30464,
+ 4849,
+ -24081,
+ -32256,
+ -28032,
+ 1399,
+ -21262,
+ -29785,
+ 23760,
+ -22001,
+ -30464,
+ 4849,
+ -24081,
+ -32256,
+ -28032,
+ 1399,
+ -21262,
+ -29785,
+ 23760,
+ -22001,
+ -30464,
+ 4849,
+ -24081,
+ -32256,
+ -28032,
+ 1399,
+ }));
}
catch(IOException e)
{