You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by te...@apache.org on 2008/04/16 10:48:12 UTC
svn commit: r648625 -
/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/
Author: tellison
Date: Wed Apr 16 01:48:09 2008
New Revision: 648625
URL: http://svn.apache.org/viewvc?rev=648625&view=rev
Log:
Apply patch HARMONY-5739 ([classlib][nio][test] Add some testcases for uncovered method in java.nio package)
Modified:
harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/BufferOverflowExceptionTest.java
harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/BufferUnderflowExceptionTest.java
harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/InvalidMarkExceptionTest.java
harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/MappedByteBufferTest.java
harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/ReadOnlyBufferExceptionTest.java
Modified: harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/BufferOverflowExceptionTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/BufferOverflowExceptionTest.java?rev=648625&r1=648624&r2=648625&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/BufferOverflowExceptionTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/BufferOverflowExceptionTest.java Wed Apr 16 01:48:09 2008
@@ -39,4 +39,14 @@
SerializationTest.verifyGolden(this, new BufferOverflowException());
}
+
+ /**
+ *@tests {@link java.nio.BufferOverflowException#BufferOverflowException()}
+ */
+ public void test_Constructor() {
+ BufferOverflowException exception = new BufferOverflowException();
+ assertNull(exception.getMessage());
+ assertNull(exception.getLocalizedMessage());
+ assertNull(exception.getCause());
+ }
}
Modified: harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/BufferUnderflowExceptionTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/BufferUnderflowExceptionTest.java?rev=648625&r1=648624&r2=648625&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/BufferUnderflowExceptionTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/BufferUnderflowExceptionTest.java Wed Apr 16 01:48:09 2008
@@ -42,4 +42,14 @@
SerializationTest.verifyGolden(this, new BufferUnderflowException());
}
+
+ /**
+ *@tests {@link java.nio.BufferUnderflowException#BufferUnderflowException()}
+ */
+ public void test_Constructor() {
+ BufferUnderflowException exception = new BufferUnderflowException();
+ assertNull(exception.getMessage());
+ assertNull(exception.getLocalizedMessage());
+ assertNull(exception.getCause());
+ }
}
Modified: harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/InvalidMarkExceptionTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/InvalidMarkExceptionTest.java?rev=648625&r1=648624&r2=648625&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/InvalidMarkExceptionTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/InvalidMarkExceptionTest.java Wed Apr 16 01:48:09 2008
@@ -38,4 +38,14 @@
SerializationTest.verifyGolden(this, new InvalidMarkException());
}
+
+ /**
+ *@tests {@link java.nio.InvalidMarkException#InvalidMarkException()}
+ */
+ public void test_Constructor() {
+ InvalidMarkException exception = new InvalidMarkException();
+ assertNull(exception.getMessage());
+ assertNull(exception.getLocalizedMessage());
+ assertNull(exception.getCause());
+ }
}
Modified: harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/MappedByteBufferTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/MappedByteBufferTest.java?rev=648625&r1=648624&r2=648625&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/MappedByteBufferTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/MappedByteBufferTest.java Wed Apr 16 01:48:09 2008
@@ -21,37 +21,24 @@
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.IntBuffer;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
+import java.nio.channels.FileChannel.MapMode;
import junit.framework.TestCase;
public class MappedByteBufferTest extends TestCase {
+ File tmpFile;
+
/**
* A regression test for failing to correctly set capacity of underlying
* wrapped buffer from a mapped byte buffer.
*/
public void testasIntBuffer() throws IOException {
- // Create temp file with 26 bytes and 5 ints
- File tmpFile = File.createTempFile("harmony", "test"); //$NON-NLS-1$//$NON-NLS-2$
- tmpFile.deleteOnExit();
- FileOutputStream fileOutputStream = new FileOutputStream(tmpFile);
- FileChannel fileChannel = fileOutputStream.getChannel();
- ByteBuffer byteBuffer = ByteBuffer.allocateDirect(26 + 20);
- for (int i = 0; i < 26; i++) {
- byteBuffer.put((byte) ('A' + i));
- }
- for (int i = 0; i < 5; i++) {
- byteBuffer.putInt(i + 1);
- }
- byteBuffer.rewind();
- fileChannel.write(byteBuffer);
- fileChannel.close();
- fileOutputStream.close();
-
// Map file
FileInputStream fis = new FileInputStream(tmpFile);
FileChannel fc = fis.getChannel();
@@ -72,5 +59,102 @@
int val = ibuffer.get();
assertEquals("Got wrong int value", i + 1, val); //$NON-NLS-1$
}
+ }
+
+ /**
+ * @tests {@link java.nio.MappedByteBuffer#force()}
+ */
+ public void test_force() throws IOException {
+ // buffer was not mapped in read/write mode
+ FileInputStream fileInputStream = new FileInputStream(tmpFile);
+ FileChannel fileChannelRead = fileInputStream.getChannel();
+ MappedByteBuffer mmbRead = fileChannelRead.map(MapMode.READ_ONLY, 0,
+ fileChannelRead.size());
+
+ mmbRead.force();
+
+ FileInputStream inputStream = new FileInputStream(tmpFile);
+ FileChannel fileChannelR = inputStream.getChannel();
+ MappedByteBuffer resultRead = fileChannelR.map(MapMode.READ_ONLY, 0,
+ fileChannelR.size());
+
+ //If this buffer was not mapped in read/write mode, then invoking this method has no effect.
+ assertEquals(
+ "Invoking force() should have no effect when this buffer was not mapped in read/write mode",
+ mmbRead, resultRead);
+
+ // Buffer was mapped in read/write mode
+ RandomAccessFile randomFile = new RandomAccessFile(tmpFile, "rw");
+ FileChannel fileChannelReadWrite = randomFile.getChannel();
+ MappedByteBuffer mmbReadWrite = fileChannelReadWrite.map(
+ FileChannel.MapMode.READ_WRITE, 0, fileChannelReadWrite.size());
+
+ mmbReadWrite.put((byte) 'o');
+ mmbReadWrite.force();
+
+ RandomAccessFile random = new RandomAccessFile(tmpFile, "rw");
+ FileChannel fileChannelRW = random.getChannel();
+ MappedByteBuffer resultReadWrite = fileChannelRW.map(
+ FileChannel.MapMode.READ_WRITE, 0, fileChannelRW.size());
+
+ // Invoking force() will change the buffer
+ assertFalse(mmbReadWrite.equals(resultReadWrite));
+ }
+
+ /**
+ * @tests {@link java.nio.MappedByteBuffer#isLoaded()}
+ */
+ public void test_isload() throws IOException {
+ FileInputStream fileInputStream = new FileInputStream(tmpFile);
+ FileChannel fileChannelRead = fileInputStream.getChannel();
+ MappedByteBuffer mmbRead = fileChannelRead.map(MapMode.READ_ONLY, 0,
+ fileChannelRead.size());
+
+ assertFalse(mmbRead.isLoaded());
+
+ RandomAccessFile randomFile = new RandomAccessFile(tmpFile, "rw");
+ FileChannel fileChannelReadWrite = randomFile.getChannel();
+ MappedByteBuffer mmbReadWrite = fileChannelReadWrite.map(
+ FileChannel.MapMode.READ_WRITE, 0, fileChannelReadWrite.size());
+
+ assertFalse(mmbReadWrite.isLoaded());
+ }
+
+ /**
+ * @tests {@link java.nio.MappedByteBuffer#load()}
+ */
+ public void test_load() throws IOException {
+ FileInputStream fileInputStream = new FileInputStream(tmpFile);
+ FileChannel fileChannelRead = fileInputStream.getChannel();
+ MappedByteBuffer mmbRead = fileChannelRead.map(MapMode.READ_ONLY, 0,
+ fileChannelRead.size());
+
+ assertEquals(mmbRead, mmbRead.load());
+
+ RandomAccessFile randomFile = new RandomAccessFile(tmpFile, "rw");
+ FileChannel fileChannelReadWrite = randomFile.getChannel();
+ MappedByteBuffer mmbReadWrite = fileChannelReadWrite.map(
+ FileChannel.MapMode.READ_WRITE, 0, fileChannelReadWrite.size());
+
+ assertEquals(mmbReadWrite, mmbReadWrite.load());
+ }
+
+ protected void setUp() throws IOException {
+ // Create temp file with 26 bytes and 5 ints
+ tmpFile = File.createTempFile("harmony", "test"); //$NON-NLS-1$//$NON-NLS-2$
+ tmpFile.deleteOnExit();
+ FileOutputStream fileOutputStream = new FileOutputStream(tmpFile);
+ FileChannel fileChannel = fileOutputStream.getChannel();
+ ByteBuffer byteBuffer = ByteBuffer.allocateDirect(26 + 20);
+ for (int i = 0; i < 26; i++) {
+ byteBuffer.put((byte) ('A' + i));
+ }
+ for (int i = 0; i < 5; i++) {
+ byteBuffer.putInt(i + 1);
+ }
+ byteBuffer.rewind();
+ fileChannel.write(byteBuffer);
+ fileChannel.close();
+ fileOutputStream.close();
}
}
Modified: harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/ReadOnlyBufferExceptionTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/ReadOnlyBufferExceptionTest.java?rev=648625&r1=648624&r2=648625&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/ReadOnlyBufferExceptionTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/ReadOnlyBufferExceptionTest.java Wed Apr 16 01:48:09 2008
@@ -38,4 +38,14 @@
SerializationTest.verifyGolden(this, new ReadOnlyBufferException());
}
+
+ /**
+ *@tests {@link java.nio.ReadOnlyBufferException#ReadOnlyBufferException()}
+ */
+ public void test_Constructor() {
+ ReadOnlyBufferException exception = new ReadOnlyBufferException();
+ assertNull(exception.getMessage());
+ assertNull(exception.getLocalizedMessage());
+ assertNull(exception.getCause());
+ }
}