You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sis.apache.org by de...@apache.org on 2014/04/27 21:37:00 UTC

svn commit: r1590469 - in /sis/branches/JDK8/storage/sis-storage/src: main/java/org/apache/sis/internal/storage/ test/java/org/apache/sis/internal/storage/

Author: desruisseaux
Date: Sun Apr 27 19:37:00 2014
New Revision: 1590469

URL: http://svn.apache.org/r1590469
Log:
More tests.

Modified:
    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/ChannelDataOutputTest.java
    sis/branches/JDK8/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/ChannelImageOutputStreamTest.java
    sis/branches/JDK8/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/MemoryCacheImageOutputStream.java

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=1590469&r1=1590468&r2=1590469&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] Sun Apr 27 19:37:00 2014
@@ -470,6 +470,7 @@ public class ChannelDataOutput extends C
          * @throws IOException If an error occurred while writing the stream.
          */
         final void writeFully(final int dataSize, int offset, int length) throws IOException {
+            clearBitOffset(); // Actually needed only if length == 0.
             ensureBufferAccepts(Math.min(length * dataSize, buffer.capacity()));
             final Buffer view = createView(); // Must be after ensureBufferAccept
             int n = Math.min(view.remaining(), length);

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=1590469&r1=1590468&r2=1590469&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] Sun Apr 27 19:37:00 2014
@@ -143,7 +143,7 @@ public strictfp class ChannelDataOutputT
      */
     @Test
     public void testArgumentChecks() throws IOException {
-        initialize("testArgumentChecks", 20, 20);
+        initialize("testArgumentChecks", 20, 10);
         try {
             testedStream.setBitOffset(9);
             fail("Shall not accept invalid bitOffset.");
@@ -260,7 +260,13 @@ public strictfp class ChannelDataOutputT
             case 8: {
                 final char[] tmp = new char[random.nextInt(ARRAY_MAX_LENGTH / Character.BYTES)];
                 for (int i=0; i<tmp.length; i++) {
-                    r.writeChar(tmp[i] = (char) random.nextInt(1 << Character.SIZE));
+                    tmp[i] = (char) random.nextInt(1 << Character.SIZE);
+                    if (!(r instanceof ImageOutputStream)) {
+                        r.writeChar(tmp[i]);
+                    }
+                }
+                if (r instanceof ImageOutputStream) {
+                    ((ImageOutputStream) r).writeChars(tmp, 0, tmp.length);
                 }
                 t.writeChars(tmp);
                 break;
@@ -268,7 +274,13 @@ public strictfp class ChannelDataOutputT
             case 9: {
                 final short[] tmp = new short[random.nextInt(ARRAY_MAX_LENGTH / Short.BYTES)];
                 for (int i=0; i<tmp.length; i++) {
-                    r.writeShort(tmp[i] = (short) random.nextInt(1 << Short.SIZE));
+                    tmp[i] = (short) random.nextInt(1 << Short.SIZE);
+                    if (!(r instanceof ImageOutputStream)) {
+                        r.writeShort(tmp[i]);
+                    }
+                }
+                if (r instanceof ImageOutputStream) {
+                    ((ImageOutputStream) r).writeShorts(tmp, 0, tmp.length);
                 }
                 t.writeShorts(tmp);
                 break;
@@ -276,7 +288,13 @@ public strictfp class ChannelDataOutputT
             case 10: {
                 final int[] tmp = new int[random.nextInt(ARRAY_MAX_LENGTH / Integer.BYTES)];
                 for (int i=0; i<tmp.length; i++) {
-                    r.writeInt(tmp[i] = random.nextInt());
+                    tmp[i] = random.nextInt();
+                    if (!(r instanceof ImageOutputStream)) {
+                        r.writeInt(tmp[i]);
+                    }
+                }
+                if (r instanceof ImageOutputStream) {
+                    ((ImageOutputStream) r).writeInts(tmp, 0, tmp.length);
                 }
                 t.writeInts(tmp);
                 break;
@@ -284,7 +302,13 @@ public strictfp class ChannelDataOutputT
             case 11: {
                 final long[] tmp = new long[random.nextInt(ARRAY_MAX_LENGTH / Long.BYTES)];
                 for (int i=0; i<tmp.length; i++) {
-                    r.writeLong(tmp[i] = random.nextLong());
+                    tmp[i] = random.nextLong();
+                    if (!(r instanceof ImageOutputStream)) {
+                        r.writeLong(tmp[i]);
+                    }
+                }
+                if (r instanceof ImageOutputStream) {
+                    ((ImageOutputStream) r).writeLongs(tmp, 0, tmp.length);
                 }
                 t.writeLongs(tmp);
                 break;
@@ -292,7 +316,13 @@ public strictfp class ChannelDataOutputT
             case 12: {
                 final float[] tmp = new float[random.nextInt(ARRAY_MAX_LENGTH / Float.BYTES)];
                 for (int i=0; i<tmp.length; i++) {
-                    r.writeFloat(tmp[i] = random.nextFloat());
+                    tmp[i] = random.nextFloat();
+                    if (!(r instanceof ImageOutputStream)) {
+                        r.writeFloat(tmp[i]);
+                    }
+                }
+                if (r instanceof ImageOutputStream) {
+                    ((ImageOutputStream) r).writeFloats(tmp, 0, tmp.length);
                 }
                 t.writeFloats(tmp);
                 break;
@@ -300,7 +330,13 @@ public strictfp class ChannelDataOutputT
             case 13: {
                 final double[] tmp = new double[random.nextInt(ARRAY_MAX_LENGTH / Double.BYTES)];
                 for (int i=0; i<tmp.length; i++) {
-                    r.writeDouble(tmp[i] = random.nextDouble());
+                    tmp[i] = random.nextDouble();
+                    if (!(r instanceof ImageOutputStream)) {
+                        r.writeDouble(tmp[i]);
+                    }
+                }
+                if (r instanceof ImageOutputStream) {
+                    ((ImageOutputStream) r).writeDoubles(tmp, 0, tmp.length);
                 }
                 t.writeDoubles(tmp);
                 break;

Modified: sis/branches/JDK8/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/ChannelImageOutputStreamTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/ChannelImageOutputStreamTest.java?rev=1590469&r1=1590468&r2=1590469&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/ChannelImageOutputStreamTest.java [UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/ChannelImageOutputStreamTest.java [UTF-8] Sun Apr 27 19:37:00 2014
@@ -21,6 +21,8 @@ import java.io.ByteArrayOutputStream;
 import java.nio.ByteBuffer;
 import java.nio.InvalidMarkException;
 import javax.imageio.stream.ImageOutputStream;
+import org.apache.sis.test.DependsOnMethod;
+import org.apache.sis.test.DependsOn;
 import org.junit.Test;
 
 import static org.junit.Assert.*;
@@ -35,6 +37,7 @@ import static org.junit.Assert.*;
  * @version 0.5
  * @module
  */
+@DependsOn(ChannelDataOutputTest.class)
 public final strictfp class ChannelImageOutputStreamTest extends ChannelDataOutputTest {
     /**
      * Initializes all non-final fields before to execute a test.
@@ -92,18 +95,25 @@ public final strictfp class ChannelImage
          */
         int nbMarks = 0;
         for (int i=0; i<STREAM_LENGTH; i++) {
-            final int v = random.nextInt(256);
             if (randomEvent() && i < STREAM_LENGTH - Long.BYTES) {
                 referenceStream.mark();
                 testedStream.mark();
                 nbMarks++;
             }
+            final int v = random.nextInt(256);
             referenceStream.writeByte(v);
             testedStream.writeByte(v);
         }
-        /*
-         * Now verify the marks position and write random values at those positions.
-         */
+        compareMarks(nbMarks);
+    }
+
+    /**
+     * Invokes {@link ChannelImageOutputStream#reset()} {@code nbMarks} times and verify that the stream position
+     * is the expected one. This method will then write random values at those positions, and finally compare the
+     * stream content.
+     */
+    private void compareMarks(int nbMarks) throws IOException {
+        final ImageOutputStream referenceStream = (ImageOutputStream) this.referenceStream;
         while (--nbMarks >= 0) {
             referenceStream.reset();
             testedStream.reset();
@@ -124,4 +134,43 @@ public final strictfp class ChannelImage
         }
         assertStreamContentEquals();
     }
+
+    /**
+     * Tests {@link ChannelImageOutputStream#flushBefore(long)}.
+     *
+     * @throws IOException Should never happen.
+     */
+    @Test
+    @DependsOnMethod("testMarkAndReset")
+    public void testFlushBefore() throws IOException {
+        final int N = 50; // Number of long values to write.
+        initialize("testFlushBefore", N*Long.BYTES, 200);
+        final ImageOutputStream referenceStream = (ImageOutputStream) this.referenceStream;
+        for (int i=0; i<N; i++) {
+            switch (i) {
+                case 20:
+                case 30:
+                case 40:
+                case 45: {
+                    referenceStream.mark();
+                    testedStream.mark();
+                    break;
+                }
+                case 10: {
+                    referenceStream.flushBefore(5 * Long.BYTES);
+                    testedStream.flushBefore(5 * Long.BYTES);
+                    break;
+                }
+                case 35: {
+                    referenceStream.flushBefore(32 * Long.BYTES);
+                    testedStream.flushBefore(32 * Long.BYTES);
+                    break;
+                }
+            }
+            final long v = random.nextLong();
+            referenceStream.writeLong(v);
+            testedStream.writeLong(v);
+        }
+        compareMarks(2);
+    }
 }

Modified: sis/branches/JDK8/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/MemoryCacheImageOutputStream.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/MemoryCacheImageOutputStream.java?rev=1590469&r1=1590468&r2=1590469&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/MemoryCacheImageOutputStream.java [UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/MemoryCacheImageOutputStream.java [UTF-8] Sun Apr 27 19:37:00 2014
@@ -18,6 +18,7 @@ package org.apache.sis.internal.storage;
 
 import java.io.IOException;
 import java.io.OutputStream;
+import org.apache.sis.util.Workaround;
 
 
 /**
@@ -30,11 +31,12 @@ import java.io.OutputStream;
  * @version 0.5
  * @module
  */
+@Workaround(library = "JDK", version = "1.8")
 final strictfp class MemoryCacheImageOutputStream extends javax.imageio.stream.MemoryCacheImageOutputStream {
     /**
      * Creates a new instance which will write the data in the given stream.
      */
-    public MemoryCacheImageOutputStream(OutputStream stream) {
+    MemoryCacheImageOutputStream(final OutputStream stream) {
         super(stream);
     }