sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1589732 - in /sis/branches/JDK8/storage/sis-storage/src: main/java/org/apache/sis/internal/storage/ test/java/org/apache/sis/internal/storage/
Date Thu, 24 Apr 2014 14:04:14 GMT
Author: desruisseaux
Date: Thu Apr 24 14:04:14 2014
New Revision: 1589732

URL: http://svn.apache.org/r1589732
Log:
Share common test code.

Added:
    sis/branches/JDK8/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/ChannelDataTestCase.java
      - copied, changed from r1589456, sis/branches/JDK8/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/ChannelDataOutputTest.java
Modified:
    sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/ChannelDataInput.java
    sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/ChannelDataOutput.java
    sis/branches/JDK8/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/ChannelDataInputTest.java
    sis/branches/JDK8/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/ChannelDataOutputTest.java
    sis/branches/JDK8/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/ChannelImageInputStreamTest.java

Modified: sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/ChannelDataInput.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/ChannelDataInput.java?rev=1589732&r1=1589731&r2=1589732&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/ChannelDataInput.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/ChannelDataInput.java
[UTF-8] Thu Apr 24 14:04:14 2014
@@ -708,9 +708,7 @@ public class ChannelDataInput extends Ch
              */
             ((SeekableByteChannel) channel).position(channelOffset + position);
             bufferOffset = position;
-            buffer.clear();
-            channel.read(buffer);
-            buffer.flip();
+            buffer.clear().limit(0);
         } else if (p >= 0) {
             /*
              * Requested position is after the current buffer limits and

Modified: sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/ChannelDataOutput.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/ChannelDataOutput.java?rev=1589732&r1=1589731&r2=1589732&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/ChannelDataOutput.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/ChannelDataOutput.java
[UTF-8] Thu Apr 24 14:04:14 2014
@@ -344,7 +344,7 @@ public class ChannelDataOutput extends C
      * @param  length The number of bytes to write.
      * @throws IOException If an error occurred while writing the stream.
      */
-    public void write(final byte[] src, int offset, int length) throws IOException {
+    public final void write(final byte[] src, int offset, int length) throws IOException
{
         while (length != 0) {
             final int n = Math.min(buffer.capacity(), length);
             ensureBufferAccepts(n);
@@ -413,7 +413,7 @@ public class ChannelDataOutput extends C
      * @param  length The number of chars to write.
      * @throws IOException If an error occurred while writing the stream.
      */
-    public void writeChars(final char[] src, int offset, int length) throws IOException {
+    public final void writeChars(final char[] src, int offset, int length) throws IOException
{
         new ArrayWriter() {
             private CharBuffer view;
             @Override Buffer createView() {return view = buffer.asCharBuffer();}
@@ -429,7 +429,7 @@ public class ChannelDataOutput extends C
      * @param  length The number of shorts to write.
      * @throws IOException If an error occurred while writing the stream.
      */
-    public void writeShorts(final short[] src, int offset, int length) throws IOException
{
+    public final void writeShorts(final short[] src, int offset, int length) throws IOException
{
         new ArrayWriter() {
             private ShortBuffer view;
             @Override Buffer createView() {return view = buffer.asShortBuffer();}
@@ -445,7 +445,7 @@ public class ChannelDataOutput extends C
      * @param  length The number of integers to write.
      * @throws IOException If an error occurred while writing the stream.
      */
-    public void writeInts(final int[] src, int offset, int length) throws IOException {
+    public final void writeInts(final int[] src, int offset, int length) throws IOException
{
         new ArrayWriter() {
             private IntBuffer view;
             @Override Buffer createView() {return view = buffer.asIntBuffer();}
@@ -461,7 +461,7 @@ public class ChannelDataOutput extends C
      * @param  length The number of longs to write.
      * @throws IOException If an error occurred while writing the stream.
      */
-    public void writeLongs(final long[] src, int offset, int length) throws IOException {
+    public final void writeLongs(final long[] src, int offset, int length) throws IOException
{
         new ArrayWriter() {
             private LongBuffer view;
             @Override Buffer createView() {return view = buffer.asLongBuffer();}
@@ -477,7 +477,7 @@ public class ChannelDataOutput extends C
      * @param  length The number of floats to write.
      * @throws IOException If an error occurred while writing the stream.
      */
-    public void writeFloats(final float[] src, int offset, int length) throws IOException
{
+    public final void writeFloats(final float[] src, int offset, int length) throws IOException
{
         new ArrayWriter() {
             private FloatBuffer view;
             @Override Buffer createView() {return view = buffer.asFloatBuffer();}
@@ -493,7 +493,7 @@ public class ChannelDataOutput extends C
      * @param  length The number of doubles to write.
      * @throws IOException If an error occurred while writing the stream.
      */
-    public void writeDoubles(final double[] src, int offset, int length) throws IOException
{
+    public final void writeDoubles(final double[] src, int offset, int length) throws IOException
{
         new ArrayWriter() {
             private DoubleBuffer view;
             @Override Buffer createView() {return view = buffer.asDoubleBuffer();}
@@ -508,7 +508,7 @@ public class ChannelDataOutput extends C
      * @throws IOException If the stream can not be moved to the given position.
      */
     @Override
-    public void seek(final long position) throws IOException {
+    public final void seek(final long position) throws IOException {
         long p = position - bufferOffset;
         if (p >= 0 && p <= buffer.limit()) {
             /*
@@ -535,7 +535,7 @@ public class ChannelDataOutput extends C
      * @throws IOException If an error occurred while writing the stream.
      */
     @Override
-    public void flush() throws IOException {
+    public final void flush() throws IOException {
         buffer.flip();
         int n = buffer.remaining();
         while (n != 0) {

Modified: sis/branches/JDK8/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/ChannelDataInputTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/ChannelDataInputTest.java?rev=1589732&r1=1589731&r2=1589732&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/ChannelDataInputTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/ChannelDataInputTest.java
[UTF-8] Thu Apr 24 14:04:14 2014
@@ -16,14 +16,11 @@
  */
 package org.apache.sis.internal.storage;
 
-import java.util.Random;
 import java.io.DataInput;
 import java.io.DataInputStream;
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.nio.ByteBuffer;
-import org.apache.sis.test.TestUtilities;
-import org.apache.sis.test.TestCase;
 import org.junit.Test;
 
 import static org.junit.Assert.*;
@@ -35,29 +32,10 @@ import static org.junit.Assert.*;
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3 (derived from geotk-3.07)
- * @version 0.4
+ * @version 0.5
  * @module
  */
-public final strictfp class ChannelDataInputTest extends TestCase {
-    /**
-     * The maximal size of the arrays to be used for the tests, in bytes.
-     */
-    private static final int ARRAY_MAX_SIZE = 256;
-
-    /**
-     * Creates an array filled with random values.
-     *
-     * @param length The length of the array to create.
-     * @param random The random number generator to use.
-     */
-    static byte[] createRandomArray(final int length, final Random random) {
-        final byte[] array = new byte[length];
-        for (int i=0; i<length; i++) {
-            array[i] = (byte) random.nextInt(256);
-        }
-        return array;
-    }
-
+public final strictfp class ChannelDataInputTest extends ChannelDataTestCase {
     /**
      * Fills a buffer with random data and compare the result with a standard image input
stream.
      * We allocate a small buffer for the {@code ChannelDataInput} in order to force frequent
@@ -67,28 +45,23 @@ public final strictfp class ChannelDataI
      */
     @Test
     public void testAllReadMethods() throws IOException {
-        final Random random = TestUtilities.createRandomNumberGenerator();
-        final byte[] array = createRandomArray(ARRAY_MAX_SIZE * 1024, random);
-        compareStreamToBuffer(random, array.length,
+        final byte[] array = createRandomArray(STREAM_SIZE);
+        compareStreamToBuffer(array.length - ARRAY_MAX_SIZE, // Margin against buffer underflow.
                 new DataInputStream(new ByteArrayInputStream(array)),
                 new ChannelDataInput("testAllReadMethods",
                     new DripByteChannel(array, random, 1, 1024),
-                    ByteBuffer.allocate(random.nextInt(ARRAY_MAX_SIZE / 4) + Double.BYTES),
false));
+                    ByteBuffer.allocate(random.nextInt(BUFFER_MAX_SIZE) + Double.BYTES),
false));
     }
 
     /**
      * Compares the data returned by the given input to the data returned by the given buffer.
      *
-     * @param  random A random number generator for executing the test.
-     * @param  length Number of bytes in the {@code r} stream.
+     * @param  length Number of bytes in the {@code data} stream.
      * @param  data   A stream over all expected data.
      * @param  input  The instance to test.
      * @throws IOException Should never happen.
      */
-    private static void compareStreamToBuffer(final Random random, int length,
-            final DataInput data, final ChannelDataInput input) throws IOException
-    {
-        length -= ARRAY_MAX_SIZE; // Margin against buffer underflow.
+    private void compareStreamToBuffer(final int length, final DataInput data, final ChannelDataInput
input) throws IOException {
         while (input.getStreamPosition() < length) {
             final int operation = random.nextInt(16);
             switch (operation) {
@@ -162,7 +135,6 @@ public final strictfp class ChannelDataI
      */
     @Test
     public void testReadString() throws IOException {
-        final Random random   = TestUtilities.createRandomNumberGenerator();
         final String expected = "お元気ですか";
         final byte[] array    = expected.getBytes("UTF-8");
         assertEquals(expected.length()*3, array.length); // Sanity check.
@@ -181,9 +153,8 @@ public final strictfp class ChannelDataI
      */
     @Test
     public void testSeekOnForwardOnlyChannel() throws IOException {
-        final Random random = TestUtilities.createRandomNumberGenerator();
         int length = random.nextInt(2048) + 1024;
-        final byte[] array = createRandomArray(length, random);
+        final byte[] array = createRandomArray(length);
         length -= Long.BYTES; // Safety against buffer underflow.
         final ByteBuffer buffer = ByteBuffer.wrap(array);
         final ChannelDataInput input = new ChannelDataInput("testSeekOnForwardOnlyChannel",
@@ -205,9 +176,8 @@ public final strictfp class ChannelDataI
      */
     @Test
     public void testPrefetch() throws IOException {
-        final Random     random = TestUtilities.createRandomNumberGenerator();
         final int        length = random.nextInt(256) + 128;
-        final byte[]     array  = createRandomArray(length, random);
+        final byte[]     array  = createRandomArray(length);
         final ByteBuffer buffer = ByteBuffer.allocate(random.nextInt(64) + 16);
         final ChannelDataInput input = new ChannelDataInput("testPrefetch",
                 new DripByteChannel(array, random, 1, 64), buffer, false);

Modified: sis/branches/JDK8/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/ChannelDataOutputTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/ChannelDataOutputTest.java?rev=1589732&r1=1589731&r2=1589732&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/ChannelDataOutputTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/ChannelDataOutputTest.java
[UTF-8] Thu Apr 24 14:04:14 2014
@@ -18,14 +18,11 @@ package org.apache.sis.internal.storage;
 
 
 import java.util.Arrays;
-import java.util.Random;
 import java.io.ByteArrayOutputStream;
 import java.io.DataOutput;
 import java.io.DataOutputStream;
 import java.io.IOException;
 import java.nio.ByteBuffer;
-import org.apache.sis.test.TestCase;
-import org.apache.sis.test.TestUtilities;
 import org.apache.sis.test.DependsOnMethod;
 import org.junit.Test;
 
@@ -42,33 +39,7 @@ import static org.junit.Assert.*;
  * @version 0.5
  * @module
  */
-public final strictfp class ChannelDataOutputTest extends TestCase {
-    /**
-     * The maximal size of the arrays to be read or written from/to the channel, in bytes.
-     * This size may be smaller or greater than the buffer capacity, but a greater size is
-     * recommended in order to test the {@link ChannelDataOutput} capability to split a
-     * write operation in more than one call to {@code channel.write(buffer)}.
-     *
-     * @see #writeInStreams(Random, int, DataOutput, ChannelDataOutput)
-     */
-    private static final int ARRAY_MAX_SIZE = 256;
-
-    /**
-     * The maximal capacity of the buffer to use for write operations.
-     */
-    private static final int BUFFER_MAX_SIZE = ARRAY_MAX_SIZE / 4;
-
-    /**
-     * The size of the {@link ByteArrayChannel} backing array.
-     * A greater size increases the amount of iteration performed by test methods.
-     */
-    private static final int STREAM_SIZE = ARRAY_MAX_SIZE * 1024;
-
-    /**
-     * Random number generator used for tests.
-     */
-    private final Random random = TestUtilities.createRandomNumberGenerator();
-
+public final strictfp class ChannelDataOutputTest extends ChannelDataTestCase {
     /**
      * The {@link DataOutput} implementation to test. This implementation will write data
to
      * {@link #testedStreamBackingArray}. The content of that array will be compared to

Copied: sis/branches/JDK8/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/ChannelDataTestCase.java
(from r1589456, sis/branches/JDK8/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/ChannelDataOutputTest.java)
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/ChannelDataTestCase.java?p2=sis/branches/JDK8/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/ChannelDataTestCase.java&p1=sis/branches/JDK8/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/ChannelDataOutputTest.java&r1=1589456&r2=1589732&rev=1589732&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/ChannelDataOutputTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/ChannelDataTestCase.java
[UTF-8] Thu Apr 24 14:04:14 2014
@@ -17,24 +17,13 @@
 package org.apache.sis.internal.storage;
 
 
-import java.util.Arrays;
 import java.util.Random;
-import java.io.ByteArrayOutputStream;
-import java.io.DataOutput;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.nio.ByteBuffer;
 import org.apache.sis.test.TestCase;
 import org.apache.sis.test.TestUtilities;
-import org.apache.sis.test.DependsOnMethod;
-import org.junit.Test;
-
-import static org.junit.Assert.*;
 
 
 /**
- * Tests {@link ChannelDataOutput}.
- * First we write into two different output streams, then we compare theirs written byte
array.
+ * Base class of {@link ChannelDataInputTest} and {@link ChannelDataOutputTest}.
  *
  * @author  Rémi Maréchal (Geomatys)
  * @author  Martin Desruisseaux (Geomatys)
@@ -42,263 +31,48 @@ import static org.junit.Assert.*;
  * @version 0.5
  * @module
  */
-public final strictfp class ChannelDataOutputTest extends TestCase {
+abstract strictfp class ChannelDataTestCase extends TestCase {
     /**
      * The maximal size of the arrays to be read or written from/to the channel, in bytes.
      * This size may be smaller or greater than the buffer capacity, but a greater size is
-     * recommended in order to test the {@link ChannelDataOutput} capability to split a
-     * write operation in more than one call to {@code channel.write(buffer)}.
-     *
-     * @see #writeInStreams(Random, int, DataOutput, ChannelDataOutput)
+     * recommended in order to test the {@link ChannelData} capability to split a read or
+     * write operation in more than one access to the channel.
      */
-    private static final int ARRAY_MAX_SIZE = 256;
+    static final int ARRAY_MAX_SIZE = 256;
 
     /**
      * The maximal capacity of the buffer to use for write operations.
      */
-    private static final int BUFFER_MAX_SIZE = ARRAY_MAX_SIZE / 4;
+    static final int BUFFER_MAX_SIZE = ARRAY_MAX_SIZE / 4;
 
     /**
      * The size of the {@link ByteArrayChannel} backing array.
      * A greater size increases the amount of iteration performed by test methods.
      */
-    private static final int STREAM_SIZE = ARRAY_MAX_SIZE * 1024;
+    static final int STREAM_SIZE = ARRAY_MAX_SIZE * 1024;
 
     /**
      * Random number generator used for tests.
      */
-    private final Random random = TestUtilities.createRandomNumberGenerator();
-
-    /**
-     * The {@link DataOutput} implementation to test. This implementation will write data
to
-     * {@link #testedStreamBackingArray}. The content of that array will be compared to
-     * {@link #expectedData} for verifying result correctness.
-     */
-    private ChannelDataOutput testedStream;
-
-    /**
-     * A stream to use as a reference implementation. Any data written in {@link #testedStream}
-     * will also be written in {@code referenceStream}, for later comparison.
-     */
-    private DataOutput referenceStream;
-
-    /**
-     * Byte array which is filled by the {@linkplain #testedStream} implementation during
write operations.
-     * The content of this array will be compared to {@linkplain #expectedData}.
-     */
-    private byte[] testedStreamBackingArray;
-
-    /**
-     * Object which is filled by {@link #referenceStream} implementation during write operations.
-     * <b>Do not write to this stream</b> - this field is kept only for invocation
of
-     * {@link ByteArrayOutputStream#toByteArray()}.
-     */
-    private ByteArrayOutputStream expectedData;
-
-    /**
-     * Initializes all non-final fields before to execute a test.
-     *
-     * @param  testName     The name of the test method to be executed.
-     * @param  streamLength Length of stream to create.
-     * @param  bufferLength Length of the {@code ByteBuffer} to use for the tests.
-     * @throws IOException Should never happen.
-     */
-    private void initialize(final String testName, final int streamLength, final int bufferLength)
throws IOException {
-        testedStreamBackingArray = new byte[streamLength];
-        testedStream             = new ChannelDataOutput(testName, new ByteArrayChannel(testedStreamBackingArray),
ByteBuffer.allocate(bufferLength));
-        expectedData             = new ByteArrayOutputStream(streamLength);
-        referenceStream          = new DataOutputStream(expectedData);
-    }
+    final Random random;
 
     /**
-     * Fills a stream with random data and compares the result with a reference output stream.
-     * We allocate a small buffer for the {@code ChannelDataOutput} in order to force frequent
-     * interactions between the buffer and the channel.
-     *
-     * @throws IOException Should never happen.
-     */
-    @Test
-    public void testAllWriteMethods() throws IOException {
-        initialize("testAllWriteMethods", STREAM_SIZE, random.nextInt(BUFFER_MAX_SIZE) +
Double.BYTES);
-        writeInStreams();
-        flush();
-        final byte[] expectedArray = expectedData.toByteArray();
-        assertArrayEquals(expectedArray, Arrays.copyOf(testedStreamBackingArray, expectedArray.length));
-    }
-
-    /**
-     * Tests write operations followed by seek operations.
-     *
-     * @throws IOException Should never happen.
-     */
-    @Test
-    @DependsOnMethod("testAllWriteMethods")
-    public void testWriteAndSeek() throws IOException {
-        initialize("testWriteAndSeek", STREAM_SIZE, random.nextInt(BUFFER_MAX_SIZE) + Double.BYTES);
-        writeInStreams();
-        final byte[] expectedArray = expectedData.toByteArray();
-        final int seekRange = expectedArray.length - Long.BYTES;
-        final ByteBuffer arrayView = ByteBuffer.wrap(expectedArray);
-        for (int i=0; i<100; i++) {
-            final int position = random.nextInt(seekRange);
-            testedStream.seek(position);
-            assertEquals("getStreamPosition()", position, testedStream.getStreamPosition());
-            final long v = random.nextLong();
-            testedStream.writeLong(v);
-            arrayView.putLong(position, v);
-        }
-        flush();
-        assertArrayEquals(expectedArray, Arrays.copyOf(testedStreamBackingArray, expectedArray.length));
-    }
-
-    /**
-     * Tests {@link ChannelDataOutput#seek(long)} with an invalid seek position.
-     *
-     * @throws IOException Should never happen.
-     */
-    @Test
-    public void testInvalidSeek() throws IOException {
-        initialize("dataOutput : fail test", 20, 20);
-        try {
-            testedStream.seek(1);
-            fail("Shall not seek further than stream length.");
-        } catch (IllegalArgumentException e) {
-            final String message = e.getMessage();
-            assertTrue(message, message.contains("position"));
-        }
-    }
-
-    /**
-     * Flushes the streams.
-     *
-     * @throws IOException Should never happen.
+     * Creates a new test case.
      */
-    private void flush() throws IOException {
-        testedStream.flush();
+    ChannelDataTestCase() {
+        random = TestUtilities.createRandomNumberGenerator();
     }
 
     /**
-     * Writes the same random data in both {@link #testedStream} and {@link #referenceStream}.
+     * Creates an array filled with random values.
      *
-     * @throws IOException Should never happen.
+     * @param length The length of the array to create.
      */
-    private void writeInStreams() throws IOException {
-        while (testedStream.getStreamPosition() < testedStreamBackingArray.length - ARRAY_MAX_SIZE)
{
-            final int operation = random.nextInt(16);
-            switch (operation) {
-                case 0: {
-                    final byte v = (byte) random.nextInt(1 << Byte.SIZE);
-                    referenceStream.writeByte(v);
-                    testedStream.writeByte(v);
-                    break;
-                }
-                case 1: {
-                    final short v = (short) random.nextInt(1 << Short.SIZE);
-                    referenceStream.writeShort(v);
-                    testedStream.writeShort(v);
-                    break;
-                }
-                case 2: {
-                    final char v = (char) random.nextInt(1 << Character.SIZE);
-                    referenceStream.writeChar(v);
-                    testedStream.writeChar(v);
-                    break;
-                }
-                case 3: {
-                    final int v = random.nextInt();
-                    referenceStream.writeInt(v);
-                    testedStream.writeInt(v);
-                    break;
-                }
-                case 4: {
-                    final long v = random.nextLong();
-                    referenceStream.writeLong(v);
-                    testedStream.writeLong(v);
-                    break;
-                }
-                case 5: {
-                    final float v = random.nextFloat();
-                    referenceStream.writeFloat(v);
-                    testedStream.writeFloat(v);
-                    break;
-                }
-                case 6: {
-                    final double v = random.nextDouble();
-                    referenceStream.writeDouble(v);
-                    testedStream.writeDouble(v);
-                    break;
-                }
-                case 7: {
-                    final byte[] tmp = new byte[random.nextInt(ARRAY_MAX_SIZE / Byte.BYTES)];
-                    random.nextBytes(tmp);
-                    referenceStream.write(tmp);
-                    testedStream.write(tmp);
-                    break;
-                }
-                case 8: {
-                    final char[] tmp = new char[random.nextInt(ARRAY_MAX_SIZE / Character.BYTES)];
-                    for (int i=0; i<tmp.length; i++) {
-                        referenceStream.writeChar(tmp[i] = (char) random.nextInt(1 <<
Character.SIZE));
-                    }
-                    testedStream.writeChars(tmp);
-                    break;
-                }
-                case 9: {
-                    final short[] tmp = new short[random.nextInt(ARRAY_MAX_SIZE / Short.BYTES)];
-                    for (int i=0; i<tmp.length; i++) {
-                        referenceStream.writeShort(tmp[i] = (short) random.nextInt(1 <<
Short.SIZE));
-                    }
-                    testedStream.writeShorts(tmp);
-                    break;
-                }
-                case 10: {
-                    final int[] tmp = new int[random.nextInt(ARRAY_MAX_SIZE / Integer.BYTES)];
-                    for (int i=0; i<tmp.length; i++) {
-                        referenceStream.writeInt(tmp[i] = random.nextInt());
-                    }
-                    testedStream.writeInts(tmp);
-                    break;
-                }
-                case 11: {
-                    final long[] tmp = new long[random.nextInt(ARRAY_MAX_SIZE / Long.BYTES)];
-                    for (int i=0; i<tmp.length; i++) {
-                        referenceStream.writeLong(tmp[i] = random.nextLong());
-                    }
-                    testedStream.writeLongs(tmp);
-                    break;
-                }
-                case 12: {
-                    final float[] tmp = new float[random.nextInt(ARRAY_MAX_SIZE / Float.BYTES)];
-                    for (int i=0; i<tmp.length; i++) {
-                        referenceStream.writeFloat(tmp[i] = random.nextFloat());
-                    }
-                    testedStream.writeFloats(tmp);
-                    break;
-                }
-                case 13: {
-                    final double[] tmp = new double[random.nextInt(ARRAY_MAX_SIZE / Double.BYTES)];
-                    for (int i=0; i<tmp.length; i++) {
-                        referenceStream.writeDouble(tmp[i] = random.nextDouble());
-                    }
-                    testedStream.writeDoubles(tmp);
-                    break;
-                }
-                case 14: {
-                    final String str = "test : ChannelDataOutput";
-//                  referenceStream.writeChars(str);
-//                  testedStream.writeChars(str);
-                    break;
-                }
-                case 15: {
-                    final String str = "お元気ですか";
-                    final byte[] array = str.getBytes("UTF-8");
-                    assertEquals(str.length() * 3, array.length); // Sanity check.
-//                  referenceStream.writeUTF(str);
-//                  testedStream.writeUTF(str);
-                    break;
-                }
-                default: throw new AssertionError(operation);
-            }
+    final byte[] createRandomArray(final int length) {
+        final byte[] array = new byte[length];
+        for (int i=0; i<length; i++) {
+            array[i] = (byte) random.nextInt(256);
         }
+        return array;
     }
 }

Modified: sis/branches/JDK8/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/ChannelImageInputStreamTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/ChannelImageInputStreamTest.java?rev=1589732&r1=1589731&r2=1589732&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/ChannelImageInputStreamTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/ChannelImageInputStreamTest.java
[UTF-8] Thu Apr 24 14:04:14 2014
@@ -17,7 +17,6 @@
 package org.apache.sis.internal.storage;
 
 import java.util.Arrays;
-import java.util.Random;
 import java.nio.ByteOrder;
 import java.nio.ByteBuffer;
 import java.nio.channels.Channels;
@@ -26,8 +25,6 @@ import java.io.IOException;
 import javax.imageio.ImageIO;
 import javax.imageio.stream.ImageInputStream;
 import org.apache.sis.test.DependsOn;
-import org.apache.sis.test.TestCase;
-import org.apache.sis.test.TestUtilities;
 import org.junit.Test;
 
 import static org.junit.Assert.*;
@@ -43,12 +40,7 @@ import static org.junit.Assert.*;
  * @module
  */
 @DependsOn(ChannelDataInputTest.class)
-public final strictfp class ChannelImageInputStreamTest extends TestCase {
-    /**
-     * The maximal size of the arrays to be used for the tests, in bytes.
-     */
-    private static final int ARRAY_MAX_SIZE = 512;
-
+public final strictfp class ChannelImageInputStreamTest extends ChannelDataTestCase {
     /**
      * Fills a buffer with random data and compares the result with a standard image input
stream.
      * We will allocate a small buffer for the {@code ChannelImageInputStream} in order to
force
@@ -62,9 +54,8 @@ public final strictfp class ChannelImage
         int bitOffset = 0;
         int operation = 0;
         final ByteBuffer buffer = ByteBuffer.allocate(128);
-        final Random random = TestUtilities.createRandomNumberGenerator();
         final ByteOrder byteOrder = random.nextBoolean() ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN;
-        final byte[] data = ChannelDataInputTest.createRandomArray(512 * 1024, random);
+        final byte[] data = createRandomArray(STREAM_SIZE);
         try (ImageInputStream r = ImageIO.createImageInputStream(new ByteArrayInputStream(data));
              ImageInputStream t = new ChannelImageInputStream("Test data",
                      Channels.newChannel(new ByteArrayInputStream(data)), buffer, false))



Mime
View raw message