aboutsummaryrefslogtreecommitdiffstats
path: root/src/junit
diff options
context:
space:
mode:
Diffstat (limited to 'src/junit')
-rw-r--r--src/junit/com/jogamp/common/nio/TestByteBufferCopyStream.java105
-rw-r--r--src/junit/com/jogamp/common/nio/TestByteBufferOutputStream.java298
-rw-r--r--src/junit/com/jogamp/common/util/TestIOUtil01.java37
3 files changed, 251 insertions, 189 deletions
diff --git a/src/junit/com/jogamp/common/nio/TestByteBufferCopyStream.java b/src/junit/com/jogamp/common/nio/TestByteBufferCopyStream.java
index 3442159..fef26b6 100644
--- a/src/junit/com/jogamp/common/nio/TestByteBufferCopyStream.java
+++ b/src/junit/com/jogamp/common/nio/TestByteBufferCopyStream.java
@@ -100,74 +100,107 @@ public class TestByteBufferCopyStream extends JunitTracer {
Assert.assertEquals(0, mos.position());
Assert.assertEquals(0, mos.remaining());
- mos.write(mis, mis.remaining());
+ OutOfMemoryError oome = null;
+ IOException ioe = null;
- Assert.assertEquals(size, input.length());
- Assert.assertEquals(size, output.length());
- Assert.assertEquals(size, mis.length());
- Assert.assertEquals(size, mos.length());
- Assert.assertEquals(size, mis.position());
- Assert.assertEquals(size, mos.position());
- Assert.assertEquals(0, mis.remaining());
- Assert.assertEquals(0, mos.remaining());
-
- mos.close();
- mis.close();
- input.close();
- output.close();
- srcFile.delete();
- dstFile.delete();
- TestByteBufferInputStream.dumpMem(prefix+" after ", runtime, usedMem0[0], freeMem0[0], usedMem1, freeMem1 );
- System.gc();
try {
- Thread.sleep(500);
- } catch (final InterruptedException e) { }
- TestByteBufferInputStream.dumpMem(prefix+" gc'ed ", runtime, usedMem0[0], freeMem0[0], usedMem1, freeMem1 );
+ mos.write(mis, mis.remaining());
+
+ Assert.assertEquals(size, input.length());
+ Assert.assertEquals(size, output.length());
+ Assert.assertEquals(size, mis.length());
+ Assert.assertEquals(size, mos.length());
+ Assert.assertEquals(size, mis.position());
+ Assert.assertEquals(size, mos.position());
+ Assert.assertEquals(0, mis.remaining());
+ Assert.assertEquals(0, mos.remaining());
+
+ } catch (final IOException e) {
+ if( e.getCause() instanceof OutOfMemoryError ) {
+ oome = (OutOfMemoryError) e.getCause(); // oops
+ } else {
+ ioe = e;
+ }
+ } catch (final OutOfMemoryError m) {
+ oome = m; // oops
+ } finally {
+ mos.close();
+ mis.close();
+ input.close();
+ output.close();
+ srcFile.delete();
+ dstFile.delete();
+ TestByteBufferInputStream.dumpMem(prefix+" after ", runtime, usedMem0[0], freeMem0[0], usedMem1, freeMem1 );
+ System.gc();
+ try {
+ Thread.sleep(500);
+ } catch (final InterruptedException e) { }
+ TestByteBufferInputStream.dumpMem(prefix+" gc'ed ", runtime, usedMem0[0], freeMem0[0], usedMem1, freeMem1 );
+ }
+ if( null != ioe || null != oome ) {
+ if( null != oome ) {
+ System.err.printf("%s: OutOfMemoryError.2 %s%n", prefix, oome.getMessage());
+ oome.printStackTrace();
+ } else {
+ Assert.assertNull(ioe);
+ }
+ }
}
+ /** {@value} */
+ static final long halfMiB = 1L << 19;
+ /** {@value} */
+ static final long oneGiB = 1L << 30;
+ /** {@value} */
+ static final long onePlusGiB = oneGiB + halfMiB;
+ /** {@value} */
+ static final long twoGiB = ( 2L << 30 );
+ /** {@value} */
+ static final long twoPlusGiB = twoGiB + halfMiB;
+
@Test
public void test00() throws IOException {
final int srcSliceShift = MappedByteBufferInputStream.DEFAULT_SLICE_SHIFT;
final int dstSliceShift = MappedByteBufferInputStream.DEFAULT_SLICE_SHIFT;
- final long size = 3L * ( 1L << 30 ); // 3 GiB
- testImpl("./testIn.bin", size, MappedByteBufferInputStream.CacheMode.FLUSH_PRE_HARD, srcSliceShift,
- "./testOut.bin", MappedByteBufferInputStream.CacheMode.FLUSH_PRE_HARD, dstSliceShift );
+ final long size = twoPlusGiB;
+ testImpl(getSimpleTestName(".")+"_In.bin", size, MappedByteBufferInputStream.CacheMode.FLUSH_PRE_HARD, srcSliceShift,
+ getSimpleTestName(".")+"_Out.bin", MappedByteBufferInputStream.CacheMode.FLUSH_PRE_HARD, dstSliceShift );
}
@Test
public void test01() throws IOException {
final int srcSliceShift = MappedByteBufferInputStream.DEFAULT_SLICE_SHIFT;
final int dstSliceShift = MappedByteBufferInputStream.DEFAULT_SLICE_SHIFT;
- final long size = 3L * ( 1L << 30 ); // 3 GiB
- testImpl("./testIn.bin", size, MappedByteBufferInputStream.CacheMode.FLUSH_PRE_SOFT, srcSliceShift,
- "./testOut.bin", MappedByteBufferInputStream.CacheMode.FLUSH_PRE_SOFT, dstSliceShift );
+ final long size = twoPlusGiB;
+ testImpl(getSimpleTestName(".")+"_In.bin", size, MappedByteBufferInputStream.CacheMode.FLUSH_PRE_SOFT, srcSliceShift,
+ getSimpleTestName(".")+"_Out.bin", MappedByteBufferInputStream.CacheMode.FLUSH_PRE_SOFT, dstSliceShift );
}
@Test
public void test02() throws IOException {
final int srcSliceShift = 28; // 256M bytes per slice
final int dstSliceShift = 28; // 256M bytes per slice
- final long size = 3L * ( 1L << 30 ); // 3 GiB
- testImpl("./testIn.bin", size, MappedByteBufferInputStream.CacheMode.FLUSH_PRE_SOFT, srcSliceShift,
- "./testOut.bin", MappedByteBufferInputStream.CacheMode.FLUSH_PRE_SOFT, dstSliceShift );
+ final long size = onePlusGiB;
+ testImpl(getSimpleTestName(".")+"_In.bin", size, MappedByteBufferInputStream.CacheMode.FLUSH_PRE_SOFT, srcSliceShift,
+ getSimpleTestName(".")+"_Out.bin", MappedByteBufferInputStream.CacheMode.FLUSH_PRE_SOFT, dstSliceShift );
}
@Test
public void test11() throws IOException {
final int srcSliceShift = 28; // 256M bytes per slice
final int dstSliceShift = 27; // 128M bytes per slice
- final long size = 3L * ( 1L << 30 ); // 3 GiB
- testImpl("./testIn.bin", size, MappedByteBufferInputStream.CacheMode.FLUSH_PRE_SOFT, srcSliceShift,
- "./testOut.bin", MappedByteBufferInputStream.CacheMode.FLUSH_PRE_SOFT, dstSliceShift );
+ final long size = onePlusGiB;
+ testImpl(getSimpleTestName(".")+"_In.bin", size, MappedByteBufferInputStream.CacheMode.FLUSH_PRE_SOFT, srcSliceShift,
+ getSimpleTestName(".")+"_Out.bin", MappedByteBufferInputStream.CacheMode.FLUSH_PRE_SOFT, dstSliceShift );
}
@Test
public void test12() throws IOException {
final int srcSliceShift = 27; // 128M bytes per slice
final int dstSliceShift = 28; // 256M bytes per slice
- final long size = 3L * ( 1L << 30 ); // 3 GiB
- testImpl("./testIn.bin", size, MappedByteBufferInputStream.CacheMode.FLUSH_PRE_SOFT, srcSliceShift,
- "./testOut.bin", MappedByteBufferInputStream.CacheMode.FLUSH_PRE_SOFT, dstSliceShift );
+ final long size = onePlusGiB;
+ testImpl(getSimpleTestName(".")+"_In.bin", size, MappedByteBufferInputStream.CacheMode.FLUSH_PRE_SOFT, srcSliceShift,
+ getSimpleTestName(".")+"_Out.bin", MappedByteBufferInputStream.CacheMode.FLUSH_PRE_SOFT, dstSliceShift );
}
public static void main(final String args[]) throws IOException {
diff --git a/src/junit/com/jogamp/common/nio/TestByteBufferOutputStream.java b/src/junit/com/jogamp/common/nio/TestByteBufferOutputStream.java
index c06dbe8..f57101e 100644
--- a/src/junit/com/jogamp/common/nio/TestByteBufferOutputStream.java
+++ b/src/junit/com/jogamp/common/nio/TestByteBufferOutputStream.java
@@ -52,180 +52,196 @@ public class TestByteBufferOutputStream extends JunitTracer {
final int sliceShift)
throws IOException
{
+ testImpl(fname, payLoad, payLoadOffset, postPayLoadFiller, endBytes, sliceShift, false);
+ testImpl(fname, payLoad, payLoadOffset, postPayLoadFiller, endBytes, sliceShift, true);
+ }
+ static void testImpl(final String fname,
+ final byte[] payLoad, final long payLoadOffset, final long postPayLoadFiller,
+ final byte[] endBytes,
+ final int sliceShift, final boolean synchronous)
+ throws IOException
+ {
final File file = new File(fname);
file.delete();
file.createNewFile();
file.deleteOnExit();
- final RandomAccessFile out = new RandomAccessFile(file, "rw");
- final MappedByteBufferInputStream.FileResizeOp szOp = new MappedByteBufferInputStream.FileResizeOp() {
- @Override
- public void setLength(final long newSize) throws IOException {
- out.setLength(newSize);
- }
- };
- final MappedByteBufferInputStream mis = new MappedByteBufferInputStream(out.getChannel(),
- FileChannel.MapMode.READ_WRITE,
- MappedByteBufferInputStream.CacheMode.FLUSH_PRE_SOFT,
- sliceShift);
- final MappedByteBufferOutputStream mos = mis.getOutputStream(szOp);
- // resize to payLoad start and position to it
- mos.setLength(payLoadOffset);
- Assert.assertEquals(payLoadOffset, out.length());
- Assert.assertEquals(payLoadOffset, mos.length());
- Assert.assertEquals(0, mos.position()); // no change
- mos.position(payLoadOffset);
- Assert.assertEquals(payLoadOffset, mos.position());
+ try {
+ final RandomAccessFile out = new RandomAccessFile(file, "rw");
+ final MappedByteBufferInputStream.FileResizeOp szOp = new MappedByteBufferInputStream.FileResizeOp() {
+ @Override
+ public void setLength(final long newSize) throws IOException {
+ out.setLength(newSize);
+ }
+ };
+ final MappedByteBufferInputStream mis = new MappedByteBufferInputStream(out.getChannel(),
+ FileChannel.MapMode.READ_WRITE,
+ MappedByteBufferInputStream.CacheMode.FLUSH_PRE_SOFT,
+ sliceShift);
+ final MappedByteBufferOutputStream mos = mis.getOutputStream(szOp);
+ mos.setSynchronous(synchronous);
- // mark, write-expand payLoad
- mis.mark(1);
- mos.write(payLoad);
- Assert.assertEquals(payLoadOffset+payLoad.length, out.length());
- Assert.assertEquals(payLoadOffset+payLoad.length, mos.length());
- Assert.assertEquals(payLoadOffset+payLoad.length, mos.position());
+ try {
+ // resize to payLoad start and position to it
+ mos.setLength(payLoadOffset);
+ Assert.assertEquals(payLoadOffset, out.length());
+ Assert.assertEquals(payLoadOffset, mos.length());
+ Assert.assertEquals(0, mos.position()); // no change
+ mos.position(payLoadOffset);
+ Assert.assertEquals(payLoadOffset, mos.position());
- // expand + 1
- mos.setLength(payLoadOffset+payLoad.length+1);
- Assert.assertEquals(payLoadOffset+payLoad.length+1, out.length());
- Assert.assertEquals(payLoadOffset+payLoad.length+1, mos.length());
- Assert.assertEquals(payLoadOffset+payLoad.length, mos.position()); // no change
+ // mark, write-expand payLoad
+ mis.mark(1);
+ mos.write(payLoad);
+ Assert.assertEquals(payLoadOffset+payLoad.length, out.length());
+ Assert.assertEquals(payLoadOffset+payLoad.length, mos.length());
+ Assert.assertEquals(payLoadOffset+payLoad.length, mos.position());
- // expand up-to very end, ahead of write - position to endBytes start
- mos.setLength(payLoadOffset+payLoad.length+postPayLoadFiller+endBytes.length);
- Assert.assertEquals(payLoadOffset+payLoad.length+postPayLoadFiller+endBytes.length, out.length());
- Assert.assertEquals(payLoadOffset+payLoad.length+postPayLoadFiller+endBytes.length, mos.length());
- Assert.assertEquals(payLoadOffset+payLoad.length, mos.position()); // no change
- mos.skip(postPayLoadFiller);
- Assert.assertEquals(payLoadOffset+payLoad.length+postPayLoadFiller, mos.position());
+ // expand + 1
+ mos.setLength(payLoadOffset+payLoad.length+1);
+ Assert.assertEquals(payLoadOffset+payLoad.length+1, out.length());
+ Assert.assertEquals(payLoadOffset+payLoad.length+1, mos.length());
+ Assert.assertEquals(payLoadOffset+payLoad.length, mos.position()); // no change
- // write endBytes (no resize)
- mos.write(endBytes);
- Assert.assertEquals(payLoadOffset+payLoad.length+postPayLoadFiller+endBytes.length, mos.position());
+ // expand up-to very end, ahead of write - position to endBytes start
+ mos.setLength(payLoadOffset+payLoad.length+postPayLoadFiller+endBytes.length);
+ Assert.assertEquals(payLoadOffset+payLoad.length+postPayLoadFiller+endBytes.length, out.length());
+ Assert.assertEquals(payLoadOffset+payLoad.length+postPayLoadFiller+endBytes.length, mos.length());
+ Assert.assertEquals(payLoadOffset+payLoad.length, mos.position()); // no change
+ mos.skip(postPayLoadFiller);
+ Assert.assertEquals(payLoadOffset+payLoad.length+postPayLoadFiller, mos.position());
- // Reset to payLoad, read it and verify
- mis.reset();
- Assert.assertEquals(payLoadOffset, mos.position());
- Assert.assertEquals(payLoadOffset, mis.position());
- final byte[] tmp = new byte[payLoad.length];
- Assert.assertEquals(payLoad.length, mis.read(tmp));
- Assert.assertEquals(payLoadOffset+payLoad.length, mos.position());
- Assert.assertEquals(payLoadOffset+payLoad.length, mis.position());
- Assert.assertArrayEquals(payLoad, tmp);
+ // write endBytes (no resize)
+ mos.write(endBytes);
+ Assert.assertEquals(payLoadOffset+payLoad.length+postPayLoadFiller+endBytes.length, mos.position());
- // Shrink to end of payLoad, mark, read >= 0, reset .. redo
- Assert.assertEquals(payLoadOffset+payLoad.length+postPayLoadFiller+endBytes.length, out.length());
- Assert.assertEquals(payLoadOffset+payLoad.length+postPayLoadFiller+endBytes.length, mos.length());
- mos.setLength(payLoadOffset+payLoad.length+1);
- Assert.assertEquals(payLoadOffset+payLoad.length+1, out.length());
- Assert.assertEquals(payLoadOffset+payLoad.length+1, mos.length());
- Assert.assertEquals(payLoadOffset+payLoad.length, mos.position());
- mis.mark(1);
- Assert.assertTrue(mis.read()>=0);
- Assert.assertEquals(payLoadOffset+payLoad.length+1, mos.position());
- mis.reset();
- Assert.assertEquals(payLoadOffset+payLoad.length, mos.position());
- Assert.assertTrue(mis.read()>=0);
- Assert.assertEquals(payLoadOffset+payLoad.length+1, mos.position());
+ // Reset to payLoad, read it and verify
+ mis.reset();
+ Assert.assertEquals(payLoadOffset, mos.position());
+ Assert.assertEquals(payLoadOffset, mis.position());
+ final byte[] tmp = new byte[payLoad.length];
+ Assert.assertEquals(payLoad.length, mis.read(tmp));
+ Assert.assertEquals(payLoadOffset+payLoad.length, mos.position());
+ Assert.assertEquals(payLoadOffset+payLoad.length, mis.position());
+ Assert.assertArrayEquals(payLoad, tmp);
- // Shrink -1, read EOS
- mos.setLength(payLoadOffset+payLoad.length);
- Assert.assertEquals(payLoadOffset+payLoad.length, out.length());
- Assert.assertEquals(payLoadOffset+payLoad.length, mos.length());
- Assert.assertEquals(payLoadOffset+payLoad.length, mos.position());
- Assert.assertEquals(-1, mis.read());
+ // Shrink to end of payLoad, mark, read >= 0, reset .. redo
+ Assert.assertEquals(payLoadOffset+payLoad.length+postPayLoadFiller+endBytes.length, out.length());
+ Assert.assertEquals(payLoadOffset+payLoad.length+postPayLoadFiller+endBytes.length, mos.length());
+ mos.setLength(payLoadOffset+payLoad.length+1);
+ Assert.assertEquals(payLoadOffset+payLoad.length+1, out.length());
+ Assert.assertEquals(payLoadOffset+payLoad.length+1, mos.length());
+ Assert.assertEquals(payLoadOffset+payLoad.length, mos.position());
+ mis.mark(1);
+ Assert.assertTrue(mis.read()>=0);
+ Assert.assertEquals(payLoadOffset+payLoad.length+1, mos.position());
+ mis.reset();
+ Assert.assertEquals(payLoadOffset+payLoad.length, mos.position());
+ Assert.assertTrue(mis.read()>=0);
+ Assert.assertEquals(payLoadOffset+payLoad.length+1, mos.position());
- // Expand + 1, mark, read >= 0, reset .. redo
- mos.setLength(payLoadOffset+payLoad.length+1);
- Assert.assertEquals(payLoadOffset+payLoad.length+1, out.length());
- Assert.assertEquals(payLoadOffset+payLoad.length+1, mos.length());
- Assert.assertEquals(payLoadOffset+payLoad.length, mos.position());
- mis.mark(1);
- Assert.assertTrue(mis.read()>=0);
- Assert.assertEquals(payLoadOffset+payLoad.length+1, mos.position());
- mis.reset();
- Assert.assertEquals(payLoadOffset+payLoad.length, mos.position());
- Assert.assertTrue(mis.read()>=0);
- Assert.assertEquals(payLoadOffset+payLoad.length+1, mos.position());
+ // Shrink -1, read EOS
+ mos.setLength(payLoadOffset+payLoad.length);
+ Assert.assertEquals(payLoadOffset+payLoad.length, out.length());
+ Assert.assertEquals(payLoadOffset+payLoad.length, mos.length());
+ Assert.assertEquals(payLoadOffset+payLoad.length, mos.position());
+ Assert.assertEquals(-1, mis.read());
- // Shrink -1, read EOS, write-expand, reset and verify
- mos.setLength(payLoadOffset+payLoad.length);
- Assert.assertEquals(payLoadOffset+payLoad.length, out.length());
- Assert.assertEquals(payLoadOffset+payLoad.length, mos.length());
- Assert.assertEquals(payLoadOffset+payLoad.length, mos.position());
- Assert.assertEquals(-1, mis.read());
- mos.write('Z'); // expand while writing ..
- Assert.assertEquals(payLoadOffset+payLoad.length+1, out.length());
- Assert.assertEquals(payLoadOffset+payLoad.length+1, mos.length());
- Assert.assertEquals(payLoadOffset+payLoad.length+1, mos.position());
- mis.reset();
- Assert.assertEquals(payLoadOffset+payLoad.length, mos.position());
- Assert.assertEquals(payLoadOffset+payLoad.length, mis.position());
- Assert.assertEquals('Z', mis.read());
- Assert.assertEquals(payLoadOffset+payLoad.length+1, mos.position());
- Assert.assertEquals(payLoadOffset+payLoad.length+1, mis.position());
+ // Expand + 1, mark, read >= 0, reset .. redo
+ mos.setLength(payLoadOffset+payLoad.length+1);
+ Assert.assertEquals(payLoadOffset+payLoad.length+1, out.length());
+ Assert.assertEquals(payLoadOffset+payLoad.length+1, mos.length());
+ Assert.assertEquals(payLoadOffset+payLoad.length, mos.position());
+ mis.mark(1);
+ Assert.assertTrue(mis.read()>=0);
+ Assert.assertEquals(payLoadOffset+payLoad.length+1, mos.position());
+ mis.reset();
+ Assert.assertEquals(payLoadOffset+payLoad.length, mos.position());
+ Assert.assertTrue(mis.read()>=0);
+ Assert.assertEquals(payLoadOffset+payLoad.length+1, mos.position());
- // Shrink -2, shall clear mark, test reset failure
- mos.setLength(payLoadOffset+payLoad.length-1);
- Assert.assertEquals(payLoadOffset+payLoad.length-1, out.length());
- Assert.assertEquals(payLoadOffset+payLoad.length-1, mos.length());
- Assert.assertEquals(payLoadOffset+payLoad.length-1, mos.position());
- try {
- mis.reset();
- Assert.assertTrue(false); // shall not reach
- } catch( final IOException ioe ) {
- Assert.assertNotNull(ioe);
- }
- mis.mark(1);
+ // Shrink -1, read EOS, write-expand, reset and verify
+ mos.setLength(payLoadOffset+payLoad.length);
+ Assert.assertEquals(payLoadOffset+payLoad.length, out.length());
+ Assert.assertEquals(payLoadOffset+payLoad.length, mos.length());
+ Assert.assertEquals(payLoadOffset+payLoad.length, mos.position());
+ Assert.assertEquals(-1, mis.read());
+ mos.write('Z'); // expand while writing ..
+ Assert.assertEquals(payLoadOffset+payLoad.length+1, out.length());
+ Assert.assertEquals(payLoadOffset+payLoad.length+1, mos.length());
+ Assert.assertEquals(payLoadOffset+payLoad.length+1, mos.position());
+ mis.reset();
+ Assert.assertEquals(payLoadOffset+payLoad.length, mos.position());
+ Assert.assertEquals(payLoadOffset+payLoad.length, mis.position());
+ Assert.assertEquals('Z', mis.read());
+ Assert.assertEquals(payLoadOffset+payLoad.length+1, mos.position());
+ Assert.assertEquals(payLoadOffset+payLoad.length+1, mis.position());
- // ZERO file, test reset failure, read EOS, write-expand
- mos.setLength(0);
- Assert.assertEquals(0, out.length());
- Assert.assertEquals(0, mos.length());
- Assert.assertEquals(0, mos.position());
- try {
- mis.reset();
- Assert.assertTrue(false); // shall not reach
- } catch( final IOException ioe ) {
- Assert.assertNotNull(ioe);
- }
- Assert.assertEquals(-1, mis.read());
- mos.write('Z'); // expand while writing ..
- Assert.assertEquals(1, out.length());
- Assert.assertEquals(1, mos.length());
- Assert.assertEquals(1, mos.position());
- mis.position(0);
- Assert.assertEquals(0, mos.position());
- Assert.assertEquals(0, mis.position());
- Assert.assertEquals('Z', mis.read());
+ // Shrink -2, shall clear mark, test reset failure
+ mos.setLength(payLoadOffset+payLoad.length-1);
+ Assert.assertEquals(payLoadOffset+payLoad.length-1, out.length());
+ Assert.assertEquals(payLoadOffset+payLoad.length-1, mos.length());
+ Assert.assertEquals(payLoadOffset+payLoad.length-1, mos.position());
+ try {
+ mis.reset();
+ Assert.assertTrue(false); // shall not reach
+ } catch( final IOException ioe ) {
+ Assert.assertNotNull(ioe);
+ }
+ mis.mark(1);
- mos.close();
- mis.close();
- out.close();
- file.delete();
+ // ZERO file, test reset failure, read EOS, write-expand
+ mos.setLength(0);
+ Assert.assertEquals(0, out.length());
+ Assert.assertEquals(0, mos.length());
+ Assert.assertEquals(0, mos.position());
+ try {
+ mis.reset();
+ Assert.assertTrue(false); // shall not reach
+ } catch( final IOException ioe ) {
+ Assert.assertNotNull(ioe);
+ }
+ Assert.assertEquals(-1, mis.read());
+ mos.write('Z'); // expand while writing ..
+ Assert.assertEquals(1, out.length());
+ Assert.assertEquals(1, mos.length());
+ Assert.assertEquals(1, mos.position());
+ mis.position(0);
+ Assert.assertEquals(0, mos.position());
+ Assert.assertEquals(0, mis.position());
+ Assert.assertEquals('Z', mis.read());
+ } finally {
+ mos.close();
+ mis.close();
+ out.close();
+ }
+ } finally {
+ file.delete();
+ }
}
@Test
public void test00() throws IOException {
final int sliceShift = 13; // 8192 bytes per slice
- testImpl("./test01.bin", "123456789AB".getBytes(), 0L, 0L, "EOF".getBytes(), sliceShift);
+ testImpl(getSimpleTestName(".")+".bin", "123456789AB".getBytes(), 0L, 0L, "EOF".getBytes(), sliceShift);
}
@Test
public void test01() throws IOException {
final int sliceShift = 13; // 8192 bytes per slice
- testImpl("./test01.bin", "123456789AB".getBytes(), 9000L, 100L, "EOF".getBytes(), sliceShift);
+ testImpl(getSimpleTestName(".")+".bin", "123456789AB".getBytes(), 9000L, 100L, "EOF".getBytes(), sliceShift);
}
@Test
public void test02() throws IOException {
final int sliceShift = 13; // 8192 bytes per slice
- testImpl("./test01.bin", "123456789AB".getBytes(), 8189L, 9001L, "EOF".getBytes(), sliceShift);
+ testImpl(getSimpleTestName(".")+".bin", "123456789AB".getBytes(), 8189L, 9001L, "EOF".getBytes(), sliceShift);
}
@Test
public void test03() throws IOException {
final int sliceShift = 13; // 8192 bytes per slice
- testImpl("./test01.bin", "123456789AB".getBytes(), 58189L, 109001L, "EOF".getBytes(), sliceShift);
+ testImpl(getSimpleTestName(".")+".bin", "123456789AB".getBytes(), 58189L, 109001L, "EOF".getBytes(), sliceShift);
}
@Test
@@ -235,7 +251,7 @@ public class TestByteBufferOutputStream extends JunitTracer {
for(int i=0; i<payLoad.length; i++) {
payLoad[i] = (byte)('A' + i%26);
}
- testImpl("./test01.bin", payLoad, 0L, 0L, "EOF".getBytes(), sliceShift);
+ testImpl(getSimpleTestName(".")+".bin", payLoad, 0L, 0L, "EOF".getBytes(), sliceShift);
}
@Test
@@ -245,7 +261,7 @@ public class TestByteBufferOutputStream extends JunitTracer {
for(int i=0; i<payLoad.length; i++) {
payLoad[i] = (byte)('A' + i%26);
}
- testImpl("./test01.bin", payLoad, 1030L, 99L, "EOF".getBytes(), sliceShift);
+ testImpl(getSimpleTestName(".")+".bin", payLoad, 1030L, 99L, "EOF".getBytes(), sliceShift);
}
@Test
@@ -255,7 +271,7 @@ public class TestByteBufferOutputStream extends JunitTracer {
for(int i=0; i<payLoad.length; i++) {
payLoad[i] = (byte)('A' + i%26);
}
- testImpl("./test01.bin", payLoad, 1021L, 1301L, "EOF".getBytes(), sliceShift);
+ testImpl(getSimpleTestName(".")+".bin", payLoad, 1021L, 1301L, "EOF".getBytes(), sliceShift);
}
@Test
@@ -265,7 +281,7 @@ public class TestByteBufferOutputStream extends JunitTracer {
for(int i=0; i<payLoad.length; i++) {
payLoad[i] = (byte)('A' + i%26);
}
- testImpl("./test01.bin", payLoad, 3021L, 6301L, "EOF".getBytes(), sliceShift);
+ testImpl(getSimpleTestName(".")+".bin", payLoad, 3021L, 6301L, "EOF".getBytes(), sliceShift);
}
public static void main(final String args[]) throws IOException {
diff --git a/src/junit/com/jogamp/common/util/TestIOUtil01.java b/src/junit/com/jogamp/common/util/TestIOUtil01.java
index 2a9c857..68f472f 100644
--- a/src/junit/com/jogamp/common/util/TestIOUtil01.java
+++ b/src/junit/com/jogamp/common/util/TestIOUtil01.java
@@ -38,6 +38,7 @@ import java.io.OutputStream;
import java.net.URLConnection;
import java.nio.ByteBuffer;
+import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -60,6 +61,7 @@ public class TestIOUtil01 extends JunitTracer {
@BeforeClass
public static void setup() throws IOException {
final File tfile = new File(tfilename);
+ tfile.deleteOnExit();
final OutputStream tout = new BufferedOutputStream(new FileOutputStream(tfile));
for(int i=0; i<tsz; i++) {
final byte b = (byte) (i%256);
@@ -69,6 +71,12 @@ public class TestIOUtil01 extends JunitTracer {
tout.close();
}
+ @AfterClass
+ public static void cleanup() {
+ final File tfile = new File(tfilename);
+ tfile.delete();
+ }
+
@Test
public void testCopyStream01Array() throws IOException {
final URLConnection urlConn = IOUtil.getResource(this.getClass(), tfilename);
@@ -109,21 +117,26 @@ public class TestIOUtil01 extends JunitTracer {
Assert.assertNotNull(urlConn1);
final File file2 = new File(tfilename2);
- IOUtil.copyURLConn2File(urlConn1, file2);
- final URLConnection urlConn2 = IOUtil.getResource(this.getClass(), tfilename2);
- Assert.assertNotNull(urlConn2);
-
- final BufferedInputStream bis = new BufferedInputStream( urlConn2.getInputStream() );
- final ByteBuffer bb;
+ file2.deleteOnExit();
try {
- bb = IOUtil.copyStream2ByteBuffer( bis );
+ IOUtil.copyURLConn2File(urlConn1, file2);
+ final URLConnection urlConn2 = IOUtil.getResource(this.getClass(), tfilename2);
+ Assert.assertNotNull(urlConn2);
+
+ final BufferedInputStream bis = new BufferedInputStream( urlConn2.getInputStream() );
+ final ByteBuffer bb;
+ try {
+ bb = IOUtil.copyStream2ByteBuffer( bis );
+ } finally {
+ IOUtil.close(bis, false);
+ }
+ Assert.assertEquals("Byte number not equal orig vs buffer", orig.length, bb.limit());
+ int i;
+ for(i=tsz-1; i>=0 && orig[i]==bb.get(i); i--) ;
+ Assert.assertTrue("Bytes not equal orig vs array", 0>i);
} finally {
- IOUtil.close(bis, false);
+ file2.delete();
}
- Assert.assertEquals("Byte number not equal orig vs buffer", orig.length, bb.limit());
- int i;
- for(i=tsz-1; i>=0 && orig[i]==bb.get(i); i--) ;
- Assert.assertTrue("Bytes not equal orig vs array", 0>i);
}
public static void main(final String args[]) throws IOException {