summaryrefslogtreecommitdiffstats
path: root/nio/src
diff options
context:
space:
mode:
authorThe Android Open Source Project <initial-contribution@android.com>2009-02-10 15:43:57 -0800
committerThe Android Open Source Project <initial-contribution@android.com>2009-02-10 15:43:57 -0800
commitb7926325a1c1a370c84c81db80372f59af240a53 (patch)
treeb1d0214be443ea674d0ded8c502a8e074e50bdd2 /nio/src
parent687f18b91f4a0a728a027579110953ee729adcb8 (diff)
downloadlibcore-b7926325a1c1a370c84c81db80372f59af240a53.zip
libcore-b7926325a1c1a370c84c81db80372f59af240a53.tar.gz
libcore-b7926325a1c1a370c84c81db80372f59af240a53.tar.bz2
auto import from //branches/cupcake/...@130745
Diffstat (limited to 'nio/src')
-rw-r--r--nio/src/main/java/java/nio/MappedByteBufferAdapter.java58
-rw-r--r--nio/src/test/java/org/apache/harmony/nio/tests/java/nio/AbstractBufferTest.java6
-rw-r--r--nio/src/test/java/org/apache/harmony/nio/tests/java/nio/AllTests.java94
-rw-r--r--nio/src/test/java/org/apache/harmony/nio/tests/java/nio/ByteBufferTest.java182
-rw-r--r--nio/src/test/java/org/apache/harmony/nio/tests/java/nio/CharBufferTest.java57
-rw-r--r--nio/src/test/java/org/apache/harmony/nio/tests/java/nio/DirectByteBufferTest.java13
-rw-r--r--nio/src/test/java/org/apache/harmony/nio/tests/java/nio/DirectCharBufferTest.java8
-rw-r--r--nio/src/test/java/org/apache/harmony/nio/tests/java/nio/DirectIntBufferTest.java44
-rw-r--r--nio/src/test/java/org/apache/harmony/nio/tests/java/nio/DirectShortBufferTest.java45
-rw-r--r--nio/src/test/java/org/apache/harmony/nio/tests/java/nio/DoubleBufferTest.java17
-rw-r--r--nio/src/test/java/org/apache/harmony/nio/tests/java/nio/FloatBufferTest.java17
-rw-r--r--nio/src/test/java/org/apache/harmony/nio/tests/java/nio/HeapByteBufferTest.java36
-rw-r--r--nio/src/test/java/org/apache/harmony/nio/tests/java/nio/HeapCharBufferTest.java2
-rw-r--r--nio/src/test/java/org/apache/harmony/nio/tests/java/nio/HeapDoubleBufferTest.java2
-rw-r--r--nio/src/test/java/org/apache/harmony/nio/tests/java/nio/HeapFloatBufferTest.java2
-rw-r--r--nio/src/test/java/org/apache/harmony/nio/tests/java/nio/HeapIntBufferTest.java2
-rw-r--r--nio/src/test/java/org/apache/harmony/nio/tests/java/nio/HeapLongBufferTest.java2
-rw-r--r--nio/src/test/java/org/apache/harmony/nio/tests/java/nio/HeapShortBufferTest.java2
-rw-r--r--nio/src/test/java/org/apache/harmony/nio/tests/java/nio/IntBufferTest.java43
-rw-r--r--nio/src/test/java/org/apache/harmony/nio/tests/java/nio/LongBufferTest.java17
-rw-r--r--nio/src/test/java/org/apache/harmony/nio/tests/java/nio/MappedByteBufferTest.java61
-rw-r--r--nio/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyCharBufferTest.java2
-rw-r--r--nio/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyWrappedCharBufferTest1.java6
-rw-r--r--nio/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyWrappedDoubleBufferTest.java6
-rw-r--r--nio/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyWrappedFloatBufferTest.java6
-rw-r--r--nio/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyWrappedIntBufferTest.java4
-rw-r--r--nio/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyWrappedLongBufferTest.java4
-rw-r--r--nio/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyWrappedShortBufferTest.java4
-rw-r--r--nio/src/test/java/org/apache/harmony/nio/tests/java/nio/ShortBufferTest.java44
-rw-r--r--nio/src/test/java/org/apache/harmony/nio/tests/java/nio/SliceDirectByteBufferTest.java2
-rw-r--r--nio/src/test/java/org/apache/harmony/nio/tests/java/nio/SliceHeapByteBufferTest.java2
-rw-r--r--nio/src/test/java/org/apache/harmony/nio/tests/java/nio/SliceWrappedByteBufferTest.java2
-rw-r--r--nio/src/test/java/org/apache/harmony/nio/tests/java/nio/WrappedByteBufferTest.java34
-rw-r--r--nio/src/test/java/org/apache/harmony/nio/tests/java/nio/WrappedCharBufferTest1.java2
-rw-r--r--nio/src/test/java/org/apache/harmony/nio/tests/java/nio/WrappedCharBufferTest2.java12
-rw-r--r--nio/src/test/java/org/apache/harmony/nio/tests/java/nio/WrappedDoubleBufferTest.java4
-rw-r--r--nio/src/test/java/org/apache/harmony/nio/tests/java/nio/WrappedFloatBufferTest.java2
-rw-r--r--nio/src/test/java/org/apache/harmony/nio/tests/java/nio/WrappedIntBufferTest.java2
-rw-r--r--nio/src/test/java/org/apache/harmony/nio/tests/java/nio/WrappedLongBufferTest.java2
-rw-r--r--nio/src/test/java/org/apache/harmony/nio/tests/java/nio/WrappedShortBufferTest.java2
-rw-r--r--nio/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/FileChannelTest.java1
-rw-r--r--nio/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/FileLockTest.java15
-rw-r--r--nio/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/SelectorTest.java2
-rw-r--r--nio/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/ServerSocketChannelTest.java4
-rw-r--r--nio/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/SinkChannelTest.java4
-rwxr-xr-xnio/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/SocketChannelTest.java9
46 files changed, 577 insertions, 310 deletions
diff --git a/nio/src/main/java/java/nio/MappedByteBufferAdapter.java b/nio/src/main/java/java/nio/MappedByteBufferAdapter.java
index a3f5d7e..83a51c1 100644
--- a/nio/src/main/java/java/nio/MappedByteBufferAdapter.java
+++ b/nio/src/main/java/java/nio/MappedByteBufferAdapter.java
@@ -17,6 +17,7 @@
// BEGIN android-note
// updated to a newer version of harmony
+// added some missing updates on position and limit
// END android-note
package java.nio;
@@ -105,32 +106,44 @@ final class MappedByteBufferAdapter extends MappedByteBuffer implements DirectBu
}
public byte get() {
+ this.wrapped.limit(this.limit);
+ this.wrapped.position(this.position);
byte result = this.wrapped.get();
this.position++;
return result;
}
public byte get(int index) {
+ this.wrapped.limit(this.limit);
+ this.wrapped.position(this.position);
return this.wrapped.get(index);
}
public char getChar() {
+ this.wrapped.limit(this.limit);
+ this.wrapped.position(this.position);
char result = this.wrapped.getChar();
this.position += CHAR_SIZE;
return result;
}
public char getChar(int index) {
+ this.wrapped.limit(this.limit);
+ this.wrapped.position(this.position);
return this.wrapped.getChar(index);
}
public double getDouble() {
+ this.wrapped.limit(this.limit);
+ this.wrapped.position(this.position);
double result = this.wrapped.getDouble();
this.position += DOUBLE_SIZE;
return result;
}
public double getDouble(int index) {
+ this.wrapped.limit(this.limit);
+ this.wrapped.position(this.position);
return this.wrapped.getDouble(index);
}
@@ -139,42 +152,58 @@ final class MappedByteBufferAdapter extends MappedByteBuffer implements DirectBu
}
public float getFloat() {
+ this.wrapped.limit(this.limit);
+ this.wrapped.position(this.position);
float result = this.wrapped.getFloat();
this.position += FLOAT_SIZE;
return result;
}
public float getFloat(int index) {
+ this.wrapped.limit(this.limit);
+ this.wrapped.position(this.position);
return this.wrapped.getFloat(index);
}
public int getInt() {
+ this.wrapped.limit(this.limit);
+ this.wrapped.position(this.position);
int result = this.wrapped.getInt();
this.position += INTEGER_SIZE;
return result;
}
public int getInt(int index) {
+ this.wrapped.limit(this.limit);
+ this.wrapped.position(this.position);
return this.wrapped.getInt(index);
}
public long getLong() {
+ this.wrapped.limit(this.limit);
+ this.wrapped.position(this.position);
long result = this.wrapped.getLong();
this.position += LONG_SIZE;
return result;
}
public long getLong(int index) {
+ this.wrapped.limit(this.limit);
+ this.wrapped.position(this.position);
return this.wrapped.getLong(index);
}
public short getShort() {
+ this.wrapped.limit(this.limit);
+ this.wrapped.position(this.position);
short result = this.wrapped.getShort();
this.position += SHORT_SIZE;
return result;
}
public short getShort(int index) {
+ this.wrapped.limit(this.limit);
+ this.wrapped.position(this.position);
return this.wrapped.getShort(index);
}
@@ -192,12 +221,15 @@ final class MappedByteBufferAdapter extends MappedByteBuffer implements DirectBu
}
public ByteBuffer put(byte b) {
+ this.wrapped.limit(this.limit);
+ this.wrapped.position(this.position);
this.wrapped.put(b);
this.position++;
return this;
}
public ByteBuffer put(byte[] src, int off, int len) {
+ this.wrapped.limit(this.limit);
this.wrapped.position(this.position);
this.wrapped.put(src, off, len);
this.position += len;
@@ -205,71 +237,97 @@ final class MappedByteBufferAdapter extends MappedByteBuffer implements DirectBu
}
public ByteBuffer put(int index, byte b) {
+ this.wrapped.limit(this.limit);
+ this.wrapped.position(this.position);
this.wrapped.put(index, b);
return this;
}
public ByteBuffer putChar(char value) {
+ this.wrapped.limit(this.limit);
+ this.wrapped.position(this.position);
this.wrapped.putChar(value);
this.position += CHAR_SIZE;
return this;
}
public ByteBuffer putChar(int index, char value) {
+ this.wrapped.limit(this.limit);
+ this.wrapped.position(this.position);
this.wrapped.putChar(index, value);
return this;
}
public ByteBuffer putDouble(double value) {
+ this.wrapped.limit(this.limit);
+ this.wrapped.position(this.position);
this.wrapped.putDouble(value);
this.position += DOUBLE_SIZE;
return this;
}
public ByteBuffer putDouble(int index, double value) {
+ this.wrapped.limit(this.limit);
+ this.wrapped.position(this.position);
this.wrapped.putDouble(index, value);
return this;
}
public ByteBuffer putFloat(float value) {
+ this.wrapped.limit(this.limit);
+ this.wrapped.position(this.position);
this.wrapped.putFloat(value);
this.position += FLOAT_SIZE;
return this;
}
public ByteBuffer putFloat(int index, float value) {
+ this.wrapped.limit(this.limit);
+ this.wrapped.position(this.position);
this.wrapped.putFloat(index, value);
return this;
}
public ByteBuffer putInt(int index, int value) {
+ this.wrapped.limit(this.limit);
+ this.wrapped.position(this.position);
this.wrapped.putInt(index, value);
return this;
}
public ByteBuffer putInt(int value) {
+ this.wrapped.limit(this.limit);
+ this.wrapped.position(this.position);
this.wrapped.putInt(value);
this.position += INTEGER_SIZE;
return this;
}
public ByteBuffer putLong(int index, long value) {
+ this.wrapped.limit(this.limit);
+ this.wrapped.position(this.position);
this.wrapped.putLong(index, value);
return this;
}
public ByteBuffer putLong(long value) {
+ this.wrapped.limit(this.limit);
+ this.wrapped.position(this.position);
this.wrapped.putLong(value);
this.position += LONG_SIZE;
return this;
}
public ByteBuffer putShort(int index, short value) {
+ this.wrapped.limit(this.limit);
+ this.wrapped.position(this.position);
this.wrapped.putShort(index, value);
return this;
}
public ByteBuffer putShort(short value) {
+ this.wrapped.limit(this.limit);
+ this.wrapped.position(this.position);
this.wrapped.putShort(value);
this.position += SHORT_SIZE;
return this;
diff --git a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/AbstractBufferTest.java b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/AbstractBufferTest.java
index 901a2a6..d0fc537 100644
--- a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/AbstractBufferTest.java
+++ b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/AbstractBufferTest.java
@@ -30,7 +30,7 @@ import junit.framework.TestCase;
* Tests a java.nio.Buffer instance.
*/
@TestTargetClass(java.nio.Buffer.class)
-public class AbstractBufferTest extends TestCase {
+public abstract class AbstractBufferTest extends TestCase {
protected Buffer baseBuf;
protected int capacity;
@@ -139,9 +139,7 @@ public class AbstractBufferTest extends TestCase {
method = "isReadOnly",
args = {}
)
- public void testIsReadOnly() {
- baseBuf.isReadOnly();
- }
+ public abstract void testIsReadOnly();
/*
* Class under test for int limit()
diff --git a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/AllTests.java b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/AllTests.java
index 6528c22..6bf13f1 100644
--- a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/AllTests.java
+++ b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/AllTests.java
@@ -33,69 +33,61 @@ public class AllTests {
public static Test suite() {
TestSuite suite = tests.TestSuiteFactory.createTestSuite("Tests for java.nio");
//$JUnit-BEGIN$
- suite.addTestSuite(ReadOnlyHeapShortBufferTest.class);
- suite.addTestSuite(ReadOnlyLongBufferTest.class);
suite.addTestSuite(BufferOverflowExceptionTest.class);
- suite.addTestSuite(CharBufferTest.class);
- suite.addTestSuite(DirectShortBufferTest.class);
- suite.addTestSuite(ReadOnlyHeapIntBufferTest.class);
- suite.addTestSuite(HeapIntBufferTest.class);
- suite.addTestSuite(WrappedDoubleBufferTest.class);
- suite.addTestSuite(WrappedCharBufferTest2.class);
- suite.addTestSuite(HeapLongBufferTest.class);
+ suite.addTestSuite(BufferUnderflowExceptionTest.class);
suite.addTestSuite(ByteOrderTest.class);
- suite.addTestSuite(ReadOnlyFloatBufferTest.class);
- suite.addTestSuite(WrappedFloatBufferTest.class);
- suite.addTestSuite(DirectLongBufferTest.class);
- suite.addTestSuite(ReadOnlyWrappedByteBufferTest.class);
- suite.addTestSuite(ReadOnlyWrappedLongBufferTest.class);
- suite.addTestSuite(HeapFloatBufferTest.class);
- suite.addTestSuite(WrappedCharBufferTest1.class);
- suite.addTestSuite(WrappedShortBufferTest.class);
- suite.addTestSuite(ReadOnlyWrappedIntBufferTest.class);
- suite.addTestSuite(AbstractBufferTest.class);
- suite.addTestSuite(ReadOnlyCharBufferTest.class);
- suite.addTestSuite(SliceHeapByteBufferTest.class);
- suite.addTestSuite(LongBufferTest.class);
- suite.addTestSuite(DuplicateWrappedByteBufferTest.class);
- suite.addTestSuite(FloatBufferTest.class);
- suite.addTestSuite(ReadOnlyHeapCharBufferTest.class);
- suite.addTestSuite(WrappedLongBufferTest.class);
- suite.addTestSuite(ReadOnlyWrappedShortBufferTest.class);
- suite.addTestSuite(ByteBufferTest.class);
- suite.addTestSuite(ReadOnlyBufferExceptionTest.class);
- suite.addTestSuite(ReadOnlyDirectByteBufferTest.class);
- suite.addTestSuite(ReadOnlyHeapDoubleBufferTest.class);
- suite.addTestSuite(ReadOnlyShortBufferTest.class);
- suite.addTestSuite(DoubleBufferTest.class);
- suite.addTestSuite(ReadOnlyWrappedFloatBufferTest.class);
- suite.addTestSuite(ShortBufferTest.class);
- suite.addTestSuite(DirectFloatBufferTest.class);
- suite.addTestSuite(SliceWrappedByteBufferTest.class);
+ suite.addTestSuite(DirectByteBufferTest.class);
suite.addTestSuite(DirectCharBufferTest.class);
- suite.addTestSuite(SliceDirectByteBufferTest.class);
- suite.addTestSuite(ReadOnlyHeapLongBufferTest.class);
+ suite.addTestSuite(DirectDoubleBufferTest.class);
+ suite.addTestSuite(DirectFloatBufferTest.class);
suite.addTestSuite(DirectIntBufferTest.class);
- suite.addTestSuite(HeapByteBufferTest.class);
- suite.addTestSuite(ReadOnlyWrappedDoubleBufferTest.class);
+ suite.addTestSuite(DirectLongBufferTest.class);
+ suite.addTestSuite(DirectShortBufferTest.class);
+ suite.addTestSuite(DuplicateDirectByteBufferTest.class);
suite.addTestSuite(DuplicateHeapByteBufferTest.class);
+ suite.addTestSuite(DuplicateWrappedByteBufferTest.class);
+ suite.addTestSuite(HeapByteBufferTest.class);
+ suite.addTestSuite(HeapCharBufferTest.class);
+ suite.addTestSuite(HeapDoubleBufferTest.class);
+ suite.addTestSuite(HeapFloatBufferTest.class);
+ suite.addTestSuite(HeapIntBufferTest.class);
+ suite.addTestSuite(HeapLongBufferTest.class);
suite.addTestSuite(HeapShortBufferTest.class);
suite.addTestSuite(InvalidMarkExceptionTest.class);
- suite.addTestSuite(DirectDoubleBufferTest.class);
+ suite.addTestSuite(MappedByteBufferTest.class);
+ suite.addTestSuite(ReadOnlyBufferExceptionTest.class);
+ suite.addTestSuite(ReadOnlyCharBufferTest.class);
+ suite.addTestSuite(ReadOnlyDirectByteBufferTest.class);
+ suite.addTestSuite(ReadOnlyDoubleBufferTest.class);
+ suite.addTestSuite(ReadOnlyFloatBufferTest.class);
suite.addTestSuite(ReadOnlyHeapByteBufferTest.class);
+ suite.addTestSuite(ReadOnlyHeapCharBufferTest.class);
+ suite.addTestSuite(ReadOnlyHeapDoubleBufferTest.class);
+ suite.addTestSuite(ReadOnlyHeapFloatBufferTest.class);
+ suite.addTestSuite(ReadOnlyHeapIntBufferTest.class);
+ suite.addTestSuite(ReadOnlyHeapLongBufferTest.class);
+ suite.addTestSuite(ReadOnlyHeapShortBufferTest.class);
suite.addTestSuite(ReadOnlyIntBufferTest.class);
- suite.addTestSuite(HeapDoubleBufferTest.class);
- suite.addTestSuite(DirectByteBufferTest.class);
+ suite.addTestSuite(ReadOnlyLongBufferTest.class);
+ suite.addTestSuite(ReadOnlyShortBufferTest.class);
+ suite.addTestSuite(ReadOnlyWrappedByteBufferTest.class);
suite.addTestSuite(ReadOnlyWrappedCharBufferTest1.class);
- suite.addTestSuite(IntBufferTest.class);
- suite.addTestSuite(ReadOnlyDoubleBufferTest.class);
- suite.addTestSuite(ReadOnlyHeapFloatBufferTest.class);
+ suite.addTestSuite(ReadOnlyWrappedDoubleBufferTest.class);
+ suite.addTestSuite(ReadOnlyWrappedFloatBufferTest.class);
+ suite.addTestSuite(ReadOnlyWrappedIntBufferTest.class);
+ suite.addTestSuite(ReadOnlyWrappedLongBufferTest.class);
+ suite.addTestSuite(ReadOnlyWrappedShortBufferTest.class);
+ suite.addTestSuite(SliceDirectByteBufferTest.class);
+ suite.addTestSuite(SliceHeapByteBufferTest.class);
+ suite.addTestSuite(SliceWrappedByteBufferTest.class);
suite.addTestSuite(WrappedByteBufferTest.class);
- suite.addTestSuite(BufferUnderflowExceptionTest.class);
- suite.addTestSuite(DuplicateDirectByteBufferTest.class);
+ suite.addTestSuite(WrappedCharBufferTest1.class);
+ suite.addTestSuite(WrappedCharBufferTest2.class);
+ suite.addTestSuite(WrappedDoubleBufferTest.class);
+ suite.addTestSuite(WrappedFloatBufferTest.class);
suite.addTestSuite(WrappedIntBufferTest.class);
- suite.addTestSuite(HeapCharBufferTest.class);
- suite.addTestSuite(MappedByteBufferTest.class);
+ suite.addTestSuite(WrappedLongBufferTest.class);
+ suite.addTestSuite(WrappedShortBufferTest.class);
//$JUnit-END$
return suite;
}
diff --git a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/ByteBufferTest.java b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/ByteBufferTest.java
index 8bf0208..acc2c6e 100644
--- a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/ByteBufferTest.java
+++ b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/ByteBufferTest.java
@@ -20,6 +20,7 @@ package org.apache.harmony.nio.tests.java.nio;
import dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetNew;
import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.AndroidOnly;
import java.nio.BufferOverflowException;
import java.nio.BufferUnderflowException;
@@ -40,20 +41,23 @@ import java.util.Arrays;
*
*/
@TestTargetClass(ByteBuffer.class)
-public class ByteBufferTest extends AbstractBufferTest {
+public abstract class ByteBufferTest extends AbstractBufferTest {
protected static final int SMALL_TEST_LENGTH = 5;
protected static final int BUFFER_LENGTH = 250;
protected ByteBuffer buf;
protected void setUp() throws Exception {
- capacity = 10;
- buf = ByteBuffer.allocate(10);
+ capacity = BUFFER_LENGTH;
+ buf = ByteBuffer.allocate(BUFFER_LENGTH);
+ loadTestData1(buf);
baseBuf = buf;
}
protected void tearDown() throws Exception {
super.tearDown();
+ buf = null;
+ baseBuf = null;
}
/*
@@ -192,6 +196,7 @@ public class ByteBufferTest extends AbstractBufferTest {
args = {}
)
public void testAsReadOnlyBuffer() {
+ loadTestData1(buf);
buf.clear();
buf.mark();
buf.position(buf.limit());
@@ -221,6 +226,7 @@ public class ByteBufferTest extends AbstractBufferTest {
method = "compact",
args = {}
)
+ @AndroidOnly("Fails on RI. See comment below")
public void testCompact() {
if (buf.isReadOnly()) {
try {
@@ -242,6 +248,9 @@ public class ByteBufferTest extends AbstractBufferTest {
assertEquals(buf.capacity(), buf.limit());
assertContentLikeTestData1(buf, 0, (byte) 0, buf.capacity());
try {
+ // Fails on RI. Spec doesn't specify the behavior if
+ // actually nothing to be done by compact(). So RI doesn't reset
+ // mark position
buf.reset();
fail("Should throw Exception"); //$NON-NLS-1$
} catch (InvalidMarkException e) {
@@ -361,6 +370,8 @@ public class ByteBufferTest extends AbstractBufferTest {
args = {java.lang.Object.class}
)
public void testEquals() {
+ loadTestData1(buf);
+
// equal to self
assertTrue(buf.equals(buf));
ByteBuffer readonly = buf.asReadOnlyBuffer();
@@ -380,6 +391,10 @@ public class ByteBufferTest extends AbstractBufferTest {
buf.limit(buf.capacity() - 1).position(0);
duplicate.limit(duplicate.capacity()).position(0);
assertFalse(buf.equals(duplicate));
+
+ buf.limit(buf.capacity() - 1).position(0);
+ duplicate.limit(duplicate.capacity()).position(1);
+ assertFalse(buf.equals(duplicate));
}
/*
@@ -392,6 +407,7 @@ public class ByteBufferTest extends AbstractBufferTest {
args = {}
)
public void testGet() {
+ loadTestData1(buf);
buf.clear();
for (int i = 0; i < buf.capacity(); i++) {
assertEquals(i, buf.position());
@@ -416,6 +432,7 @@ public class ByteBufferTest extends AbstractBufferTest {
)
public void testGetbyteArray() {
byte array[] = new byte[1];
+ loadTestData1(buf);
buf.clear();
for (int i = 0; i < buf.capacity(); i++) {
assertEquals(i, buf.position());
@@ -451,6 +468,7 @@ public class ByteBufferTest extends AbstractBufferTest {
args = {byte[].class, int.class, int.class}
)
public void testGetbyteArrayintint() {
+ loadTestData1(buf);
buf.clear();
byte array[] = new byte[buf.capacity()];
@@ -524,6 +542,7 @@ public class ByteBufferTest extends AbstractBufferTest {
args = {int.class}
)
public void testGetint() {
+ loadTestData1(buf);
buf.clear();
for (int i = 0; i < buf.capacity(); i++) {
assertEquals(i, buf.position());
@@ -545,24 +564,13 @@ public class ByteBufferTest extends AbstractBufferTest {
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
+ notes = "Verifies hasArray method for wrapped ByteBuffer.",
method = "hasArray",
args = {}
)
public void testHasArray() {
- if (buf.hasArray()) {
- assertNotNull(buf.array());
- } else {
- try {
- buf.array();
- fail("Should throw Exception"); //$NON-NLS-1$
- } catch (UnsupportedOperationException e) {
- // expected
- // Note:can not tell when to catch
- // UnsupportedOperationException or
- // ReadOnlyBufferException, so catch all.
- }
- }
+ assertTrue(buf.hasArray());
+ assertNotNull(buf.array());
}
@TestTargetNew(
@@ -603,12 +611,22 @@ public class ByteBufferTest extends AbstractBufferTest {
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
- notes = "Abstract method.",
+ notes = "Verifies isDirect method with not direct buffer.",
method = "isDirect",
args = {}
)
public void testIsDirect() {
- buf.isDirect();
+ assertFalse(buf.isDirect());
+ }
+
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "isReadOnly",
+ args = {}
+ )
+ public void testIsReadOnly() {
+ assertFalse(buf.isReadOnly());
}
@TestTargetNew(
@@ -943,6 +961,7 @@ public class ByteBufferTest extends AbstractBufferTest {
args = {}
)
public void testSlice() {
+ loadTestData1(buf);
assertTrue(buf.capacity() > SMALL_TEST_LENGTH);
buf.position(1);
buf.limit(buf.capacity() - 1);
@@ -994,6 +1013,7 @@ public class ByteBufferTest extends AbstractBufferTest {
CharBuffer charBuffer;
byte bytes[] = new byte[2];
char value;
+ loadTestData1(buf);
// test BIG_ENDIAN char buffer, read
buf.clear();
@@ -1056,6 +1076,7 @@ public class ByteBufferTest extends AbstractBufferTest {
DoubleBuffer doubleBuffer;
byte bytes[] = new byte[8];
double value;
+ loadTestData1(buf);
// test BIG_ENDIAN double buffer, read
buf.clear();
@@ -1092,7 +1113,7 @@ public class ByteBufferTest extends AbstractBufferTest {
doubleBuffer = buf.asDoubleBuffer();
assertSame(ByteOrder.BIG_ENDIAN, doubleBuffer.order());
while (doubleBuffer.remaining() > 0) {
- value = (double) doubleBuffer.remaining();
+ value = doubleBuffer.remaining();
doubleBuffer.put(value);
buf.get(bytes);
assertTrue(Arrays.equals(bytes, double2bytes(value, buf.order())));
@@ -1104,7 +1125,7 @@ public class ByteBufferTest extends AbstractBufferTest {
doubleBuffer = buf.asDoubleBuffer();
assertSame(ByteOrder.LITTLE_ENDIAN, doubleBuffer.order());
while (doubleBuffer.remaining() > 0) {
- value = (double) doubleBuffer.remaining();
+ value = doubleBuffer.remaining();
doubleBuffer.put(value);
buf.get(bytes);
assertTrue(Arrays.equals(bytes, double2bytes(value, buf.order())));
@@ -1125,6 +1146,7 @@ public class ByteBufferTest extends AbstractBufferTest {
FloatBuffer floatBuffer;
byte bytes[] = new byte[4];
float value;
+ loadTestData1(buf);
// test BIG_ENDIAN float buffer, read
buf.clear();
@@ -1161,7 +1183,7 @@ public class ByteBufferTest extends AbstractBufferTest {
floatBuffer = buf.asFloatBuffer();
assertSame(ByteOrder.BIG_ENDIAN, floatBuffer.order());
while (floatBuffer.remaining() > 0) {
- value = (float) floatBuffer.remaining();
+ value = floatBuffer.remaining();
floatBuffer.put(value);
buf.get(bytes);
assertTrue(Arrays.equals(bytes, float2bytes(value, buf.order())));
@@ -1173,7 +1195,7 @@ public class ByteBufferTest extends AbstractBufferTest {
floatBuffer = buf.asFloatBuffer();
assertSame(ByteOrder.LITTLE_ENDIAN, floatBuffer.order());
while (floatBuffer.remaining() > 0) {
- value = (float) floatBuffer.remaining();
+ value = floatBuffer.remaining();
floatBuffer.put(value);
buf.get(bytes);
assertTrue(Arrays.equals(bytes, float2bytes(value, buf.order())));
@@ -1194,6 +1216,7 @@ public class ByteBufferTest extends AbstractBufferTest {
IntBuffer intBuffer;
byte bytes[] = new byte[4];
int value;
+ loadTestData1(buf);
// test BIG_ENDIAN int buffer, read
buf.clear();
@@ -1224,7 +1247,7 @@ public class ByteBufferTest extends AbstractBufferTest {
intBuffer = buf.asIntBuffer();
assertSame(ByteOrder.BIG_ENDIAN, intBuffer.order());
while (intBuffer.remaining() > 0) {
- value = (int) intBuffer.remaining();
+ value = intBuffer.remaining();
intBuffer.put(value);
buf.get(bytes);
assertTrue(Arrays.equals(bytes, int2bytes(value, buf.order())));
@@ -1236,7 +1259,7 @@ public class ByteBufferTest extends AbstractBufferTest {
intBuffer = buf.asIntBuffer();
assertSame(ByteOrder.LITTLE_ENDIAN, intBuffer.order());
while (intBuffer.remaining() > 0) {
- value = (int) intBuffer.remaining();
+ value = intBuffer.remaining();
intBuffer.put(value);
buf.get(bytes);
assertTrue(Arrays.equals(bytes, int2bytes(value, buf.order())));
@@ -1257,6 +1280,7 @@ public class ByteBufferTest extends AbstractBufferTest {
LongBuffer longBuffer;
byte bytes[] = new byte[8];
long value;
+ loadTestData1(buf);
// test BIG_ENDIAN long buffer, read
buf.clear();
@@ -1287,7 +1311,7 @@ public class ByteBufferTest extends AbstractBufferTest {
longBuffer = buf.asLongBuffer();
assertSame(ByteOrder.BIG_ENDIAN, longBuffer.order());
while (longBuffer.remaining() > 0) {
- value = (long) longBuffer.remaining();
+ value = longBuffer.remaining();
longBuffer.put(value);
buf.get(bytes);
assertTrue(Arrays.equals(bytes, long2bytes(value, buf.order())));
@@ -1299,7 +1323,7 @@ public class ByteBufferTest extends AbstractBufferTest {
longBuffer = buf.asLongBuffer();
assertSame(ByteOrder.LITTLE_ENDIAN, longBuffer.order());
while (longBuffer.remaining() > 0) {
- value = (long) longBuffer.remaining();
+ value = longBuffer.remaining();
longBuffer.put(value);
buf.get(bytes);
assertTrue(Arrays.equals(bytes, long2bytes(value, buf.order())));
@@ -1320,6 +1344,7 @@ public class ByteBufferTest extends AbstractBufferTest {
ShortBuffer shortBuffer;
byte bytes[] = new byte[2];
short value;
+ loadTestData1(buf);
// test BIG_ENDIAN short buffer, read
buf.clear();
@@ -1383,6 +1408,8 @@ public class ByteBufferTest extends AbstractBufferTest {
int nbytes = 2;
byte bytes[] = new byte[nbytes];
char value;
+ loadTestData1(buf);
+
buf.clear();
for (int i = 0; buf.remaining() >= nbytes; i++) {
buf.order(i % 2 == 0 ? ByteOrder.BIG_ENDIAN
@@ -1415,6 +1442,8 @@ public class ByteBufferTest extends AbstractBufferTest {
int nbytes = 2;
byte bytes[] = new byte[nbytes];
char value;
+ loadTestData1(buf);
+
buf.clear();
for (int i = 0; i <= buf.limit() - nbytes; i++) {
buf.order(i % 2 == 0 ? ByteOrder.BIG_ENDIAN
@@ -1473,7 +1502,8 @@ public class ByteBufferTest extends AbstractBufferTest {
assertEquals((i + 1) * nbytes, buf.position());
buf.reset();
buf.get(bytes);
- assertTrue(Arrays.equals(char2bytes(value, buf.order()), bytes));
+ assertTrue("Wrong value at " + i,
+ Arrays.equals(char2bytes(value, buf.order()), bytes));
}
try {
@@ -1522,7 +1552,8 @@ public class ByteBufferTest extends AbstractBufferTest {
buf.putChar(i, value);
assertEquals(i, buf.position());
buf.get(bytes);
- assertTrue(Arrays.equals(char2bytes(value, buf.order()), bytes));
+ assertTrue("Wrong value at " + i,
+ Arrays.equals(char2bytes(value, buf.order()), bytes));
}
try {
@@ -1562,6 +1593,8 @@ public class ByteBufferTest extends AbstractBufferTest {
int nbytes = 8;
byte bytes[] = new byte[nbytes];
double value;
+ loadTestData1(buf);
+
buf.clear();
for (int i = 0; buf.remaining() >= nbytes; i++) {
buf.order(i % 2 == 0 ? ByteOrder.BIG_ENDIAN
@@ -1597,6 +1630,8 @@ public class ByteBufferTest extends AbstractBufferTest {
int nbytes = 8;
byte bytes[] = new byte[nbytes];
double value;
+ loadTestData1(buf);
+
buf.clear();
for (int i = 0; i <= buf.limit() - nbytes; i++) {
buf.order(i % 2 == 0 ? ByteOrder.BIG_ENDIAN
@@ -1643,7 +1678,7 @@ public class ByteBufferTest extends AbstractBufferTest {
if (buf.isReadOnly()) {
try {
buf.clear();
- buf.putDouble((double) 1);
+ buf.putDouble(1);
fail("Should throw Exception"); //$NON-NLS-1$
} catch (ReadOnlyBufferException e) {
// expected
@@ -1658,13 +1693,14 @@ public class ByteBufferTest extends AbstractBufferTest {
for (int i = 0; buf.remaining() >= nbytes; i++) {
buf.order(i % 2 == 0 ? ByteOrder.BIG_ENDIAN
: ByteOrder.LITTLE_ENDIAN);
- value = (double) i;
+ value = i;
buf.mark();
buf.putDouble(value);
assertEquals((i + 1) * nbytes, buf.position());
buf.reset();
buf.get(bytes);
- assertTrue(Arrays.equals(double2bytes(value, buf.order()), bytes));
+ assertTrue("Wrong value at " + i,
+ Arrays.equals(double2bytes(value, buf.order()), bytes));
}
try {
@@ -1702,7 +1738,7 @@ public class ByteBufferTest extends AbstractBufferTest {
public void testPutDoubleint() {
if (buf.isReadOnly()) {
try {
- buf.putDouble(0, (double) 1);
+ buf.putDouble(0, 1);
fail("Should throw Exception"); //$NON-NLS-1$
} catch (ReadOnlyBufferException e) {
// expected
@@ -1717,12 +1753,13 @@ public class ByteBufferTest extends AbstractBufferTest {
for (int i = 0; i <= buf.limit() - nbytes; i++) {
buf.order(i % 2 == 0 ? ByteOrder.BIG_ENDIAN
: ByteOrder.LITTLE_ENDIAN);
- value = (double) i;
+ value = i;
buf.position(i);
buf.putDouble(i, value);
assertEquals(i, buf.position());
buf.get(bytes);
- assertTrue(Arrays.equals(double2bytes(value, buf.order()), bytes));
+ assertTrue("Wrong value at " + i,
+ Arrays.equals(double2bytes(value, buf.order()), bytes));
}
try {
@@ -1762,6 +1799,8 @@ public class ByteBufferTest extends AbstractBufferTest {
int nbytes = 4;
byte bytes[] = new byte[nbytes];
float value;
+ loadTestData1(buf);
+
buf.clear();
for (int i = 0; buf.remaining() >= nbytes; i++) {
buf.order(i % 2 == 0 ? ByteOrder.BIG_ENDIAN
@@ -1797,6 +1836,8 @@ public class ByteBufferTest extends AbstractBufferTest {
int nbytes = 4;
byte bytes[] = new byte[nbytes];
float value;
+ loadTestData1(buf);
+
buf.clear();
for (int i = 0; i <= buf.limit() - nbytes; i++) {
buf.order(i % 2 == 0 ? ByteOrder.BIG_ENDIAN
@@ -1837,7 +1878,7 @@ public class ByteBufferTest extends AbstractBufferTest {
if (buf.isReadOnly()) {
try {
buf.clear();
- buf.putFloat((float) 1);
+ buf.putFloat(1);
fail("Should throw Exception"); //$NON-NLS-1$
} catch (ReadOnlyBufferException e) {
// expected
@@ -1852,13 +1893,14 @@ public class ByteBufferTest extends AbstractBufferTest {
for (int i = 0; buf.remaining() >= nbytes; i++) {
buf.order(i % 2 == 0 ? ByteOrder.BIG_ENDIAN
: ByteOrder.LITTLE_ENDIAN);
- value = (float) i;
+ value = i;
buf.mark();
buf.putFloat(value);
assertEquals((i + 1) * nbytes, buf.position());
buf.reset();
buf.get(bytes);
- assertTrue(Arrays.equals(float2bytes(value, buf.order()), bytes));
+ assertTrue("Wrong value at " + i,
+ Arrays.equals(float2bytes(value, buf.order()), bytes));
}
try {
@@ -1896,7 +1938,7 @@ public class ByteBufferTest extends AbstractBufferTest {
public void testPutFloatint() {
if (buf.isReadOnly()) {
try {
- buf.putFloat(0, (float) 1);
+ buf.putFloat(0, 1);
fail("Should throw Exception"); //$NON-NLS-1$
} catch (ReadOnlyBufferException e) {
// expected
@@ -1911,12 +1953,13 @@ public class ByteBufferTest extends AbstractBufferTest {
for (int i = 0; i <= buf.limit() - nbytes; i++) {
buf.order(i % 2 == 0 ? ByteOrder.BIG_ENDIAN
: ByteOrder.LITTLE_ENDIAN);
- value = (float) i;
+ value = i;
buf.position(i);
buf.putFloat(i, value);
assertEquals(i, buf.position());
buf.get(bytes);
- assertTrue(Arrays.equals(float2bytes(value, buf.order()), bytes));
+ assertTrue("Wrong value at " + i,
+ Arrays.equals(float2bytes(value, buf.order()), bytes));
}
try {
@@ -1956,6 +1999,8 @@ public class ByteBufferTest extends AbstractBufferTest {
int nbytes = 4;
byte bytes[] = new byte[nbytes];
int value;
+ loadTestData1(buf);
+
buf.clear();
for (int i = 0; buf.remaining() >= nbytes; i++) {
buf.order(i % 2 == 0 ? ByteOrder.BIG_ENDIAN
@@ -1988,6 +2033,8 @@ public class ByteBufferTest extends AbstractBufferTest {
int nbytes = 4;
byte bytes[] = new byte[nbytes];
int value;
+ loadTestData1(buf);
+
buf.clear();
for (int i = 0; i <= buf.limit() - nbytes; i++) {
buf.order(i % 2 == 0 ? ByteOrder.BIG_ENDIAN
@@ -2030,7 +2077,7 @@ public class ByteBufferTest extends AbstractBufferTest {
if (buf.isReadOnly()) {
try {
buf.clear();
- buf.putInt((int) 1);
+ buf.putInt(1);
fail("Should throw Exception"); //$NON-NLS-1$
} catch (ReadOnlyBufferException e) {
// expected
@@ -2045,13 +2092,14 @@ public class ByteBufferTest extends AbstractBufferTest {
for (int i = 0; buf.remaining() >= nbytes; i++) {
buf.order(i % 2 == 0 ? ByteOrder.BIG_ENDIAN
: ByteOrder.LITTLE_ENDIAN);
- value = (int) i;
+ value = i;
buf.mark();
buf.putInt(value);
assertEquals((i + 1) * nbytes, buf.position());
buf.reset();
buf.get(bytes);
- assertTrue(Arrays.equals(int2bytes(value, buf.order()), bytes));
+ assertTrue("Wrong value at " + i,
+ Arrays.equals(int2bytes(value, buf.order()), bytes));
}
try {
@@ -2080,7 +2128,7 @@ public class ByteBufferTest extends AbstractBufferTest {
public void testPutIntint() {
if (buf.isReadOnly()) {
try {
- buf.putInt(0, (int) 1);
+ buf.putInt(0, 1);
fail("Should throw Exception"); //$NON-NLS-1$
} catch (ReadOnlyBufferException e) {
// expected
@@ -2095,12 +2143,13 @@ public class ByteBufferTest extends AbstractBufferTest {
for (int i = 0; i <= buf.limit() - nbytes; i++) {
buf.order(i % 2 == 0 ? ByteOrder.BIG_ENDIAN
: ByteOrder.LITTLE_ENDIAN);
- value = (int) i;
+ value = i;
buf.position(i);
buf.putInt(i, value);
assertEquals(i, buf.position());
buf.get(bytes);
- assertTrue(Arrays.equals(int2bytes(value, buf.order()), bytes));
+ assertTrue("Wrong value at " + i,
+ Arrays.equals(int2bytes(value, buf.order()), bytes));
}
try {
@@ -2134,6 +2183,8 @@ public class ByteBufferTest extends AbstractBufferTest {
int nbytes = 8;
byte bytes[] = new byte[nbytes];
long value;
+ loadTestData1(buf);
+
buf.clear();
for (int i = 0; buf.remaining() >= nbytes; i++) {
buf.order(i % 2 == 0 ? ByteOrder.BIG_ENDIAN
@@ -2166,6 +2217,8 @@ public class ByteBufferTest extends AbstractBufferTest {
int nbytes = 8;
byte bytes[] = new byte[nbytes];
long value;
+ loadTestData1(buf);
+
buf.clear();
for (int i = 0; i <= buf.limit() - nbytes; i++) {
buf.order(i % 2 == 0 ? ByteOrder.BIG_ENDIAN
@@ -2203,7 +2256,7 @@ public class ByteBufferTest extends AbstractBufferTest {
if (buf.isReadOnly()) {
try {
buf.clear();
- buf.putLong((long) 1);
+ buf.putLong(1);
fail("Should throw Exception"); //$NON-NLS-1$
} catch (ReadOnlyBufferException e) {
// expected
@@ -2218,13 +2271,14 @@ public class ByteBufferTest extends AbstractBufferTest {
for (int i = 0; buf.remaining() >= nbytes; i++) {
buf.order(i % 2 == 0 ? ByteOrder.BIG_ENDIAN
: ByteOrder.LITTLE_ENDIAN);
- value = (long) i;
+ value = i;
buf.mark();
buf.putLong(value);
assertEquals((i + 1) * nbytes, buf.position());
buf.reset();
buf.get(bytes);
- assertTrue(Arrays.equals(long2bytes(value, buf.order()), bytes));
+ assertTrue("Wrong value at " + i,
+ Arrays.equals(long2bytes(value, buf.order()), bytes));
}
try {
@@ -2253,7 +2307,7 @@ public class ByteBufferTest extends AbstractBufferTest {
public void testPutLongint() {
if (buf.isReadOnly()) {
try {
- buf.putLong(0, (long) 1);
+ buf.putLong(0, 1);
fail("Should throw Exception"); //$NON-NLS-1$
} catch (ReadOnlyBufferException e) {
// expected
@@ -2268,12 +2322,13 @@ public class ByteBufferTest extends AbstractBufferTest {
for (int i = 0; i <= buf.limit() - nbytes; i++) {
buf.order(i % 2 == 0 ? ByteOrder.BIG_ENDIAN
: ByteOrder.LITTLE_ENDIAN);
- value = (long) i;
+ value = i;
buf.position(i);
buf.putLong(i, value);
assertEquals(i, buf.position());
buf.get(bytes);
- assertTrue(Arrays.equals(long2bytes(value, buf.order()), bytes));
+ assertTrue("Wrong value at " + i,
+ Arrays.equals(long2bytes(value, buf.order()), bytes));
}
try {
@@ -2307,6 +2362,8 @@ public class ByteBufferTest extends AbstractBufferTest {
int nbytes = 2;
byte bytes[] = new byte[nbytes];
short value;
+ loadTestData1(buf);
+
buf.clear();
for (int i = 0; buf.remaining() >= nbytes; i++) {
buf.order(i % 2 == 0 ? ByteOrder.BIG_ENDIAN
@@ -2339,6 +2396,8 @@ public class ByteBufferTest extends AbstractBufferTest {
int nbytes = 2;
byte bytes[] = new byte[nbytes];
short value;
+ loadTestData1(buf);
+
buf.clear();
for (int i = 0; i <= buf.limit() - nbytes; i++) {
buf.order(i % 2 == 0 ? ByteOrder.BIG_ENDIAN
@@ -2397,7 +2456,8 @@ public class ByteBufferTest extends AbstractBufferTest {
assertEquals((i + 1) * nbytes, buf.position());
buf.reset();
buf.get(bytes);
- assertTrue(Arrays.equals(short2bytes(value, buf.order()), bytes));
+ assertTrue("Wrong value at " + i,
+ Arrays.equals(short2bytes(value, buf.order()), bytes));
}
try {
@@ -2446,7 +2506,8 @@ public class ByteBufferTest extends AbstractBufferTest {
buf.putShort(i, value);
assertEquals(i, buf.position());
buf.get(bytes);
- assertTrue(Arrays.equals(short2bytes(value, buf.order()), bytes));
+ assertTrue("Wrong value at " + i,
+ Arrays.equals(short2bytes(value, buf.order()), bytes));
}
try {
@@ -2569,26 +2630,29 @@ public class ByteBufferTest extends AbstractBufferTest {
}
}
- private void loadTestData1(byte array[], int offset, int length) {
+ protected void loadTestData1(byte array[], int offset, int length) {
for (int i = 0; i < length; i++) {
array[offset + i] = (byte) i;
}
}
- private void loadTestData2(byte array[], int offset, int length) {
+ protected void loadTestData2(byte array[], int offset, int length) {
for (int i = 0; i < length; i++) {
array[offset + i] = (byte) (length - i);
}
}
- private void loadTestData1(ByteBuffer buf) {
+ protected void loadTestData1(ByteBuffer buf) {
+ if (buf.isReadOnly()) {
+ return;
+ }
buf.clear();
for (int i = 0; i < buf.capacity(); i++) {
buf.put(i, (byte) i);
}
}
- private void loadTestData2(ByteBuffer buf) {
+ protected void loadTestData2(ByteBuffer buf) {
buf.clear();
for (int i = 0; i < buf.capacity(); i++) {
buf.put(i, (byte) (buf.capacity() - i));
diff --git a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/CharBufferTest.java b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/CharBufferTest.java
index 21d96a5..b3e866c 100644
--- a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/CharBufferTest.java
+++ b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/CharBufferTest.java
@@ -21,6 +21,7 @@ import dalvik.annotation.TestTargets;
import dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetNew;
import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.AndroidOnly;
import java.io.IOException;
import java.nio.BufferOverflowException;
@@ -35,7 +36,7 @@ import java.nio.ReadOnlyBufferException;
*
*/
@TestTargetClass(CharBuffer.class)
-public class CharBufferTest extends AbstractBufferTest {
+public abstract class CharBufferTest extends AbstractBufferTest {
protected static final int SMALL_TEST_LENGTH = 5;
protected static final int BUFFER_LENGTH = 20;
@@ -203,6 +204,7 @@ public class CharBufferTest extends AbstractBufferTest {
method = "compact",
args = {}
)
+ @AndroidOnly("fails on RI. See comment below")
public void testCompact() {
// case: buffer is full
buf.clear();
@@ -230,6 +232,8 @@ public class CharBufferTest extends AbstractBufferTest {
assertEquals(buf.limit(), buf.capacity());
assertContentLikeTestData1(buf, 0, (char) 0, buf.capacity());
try {
+ // failed on RI. Spec doesn't specify the behavior if
+ // actually nothing to be done by compact()
buf.reset();
fail("Should throw Exception"); //$NON-NLS-1$
} catch (InvalidMarkException e) {
@@ -938,6 +942,7 @@ public class CharBufferTest extends AbstractBufferTest {
method = "put",
args = {java.lang.String.class, int.class, int.class}
)
+ @AndroidOnly("Fails on RI. See commend below")
public void testPutStringintint() {
buf.clear();
String str = String.valueOf(new char[buf.capacity()]);
@@ -951,6 +956,11 @@ public class CharBufferTest extends AbstractBufferTest {
} catch (BufferOverflowException e) {
// expected
}
+
+ // Fails on RI. On RI put() starts transferring characters even if
+ // there's no free space for whole string
+ assertEquals(0, buf.position());
+
try {
buf.put((String) null, 0, buf.capacity() + 1);
fail("Should throw Exception"); //$NON-NLS-1$
@@ -1004,26 +1014,26 @@ public class CharBufferTest extends AbstractBufferTest {
assertSame(ret, buf);
}
- void loadTestData1(char array[], int offset, int length) {
+ protected void loadTestData1(char array[], int offset, int length) {
for (int i = 0; i < length; i++) {
array[offset + i] = (char) i;
}
}
- void loadTestData2(char array[], int offset, int length) {
+ protected void loadTestData2(char array[], int offset, int length) {
for (int i = 0; i < length; i++) {
array[offset + i] = (char) (length - i);
}
}
- void loadTestData1(CharBuffer buf) {
+ protected void loadTestData1(CharBuffer buf) {
buf.clear();
for (int i = 0; i < buf.capacity(); i++) {
buf.put(i, (char) i);
}
}
- void loadTestData2(CharBuffer buf) {
+ protected void loadTestData2(CharBuffer buf) {
buf.clear();
for (int i = 0; i < buf.capacity(); i++) {
buf.put(i, (char) (buf.capacity() - i));
@@ -1344,44 +1354,33 @@ public class CharBufferTest extends AbstractBufferTest {
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "hasArray",
+ notes = "Abstract method.",
+ method = "isReadOnly",
args = {}
)
- public void testHasArray() {
- if (buf.hasArray()) {
- assertNotNull(buf.array());
- } else {
- try {
- buf.array();
- fail("Should throw Exception"); //$NON-NLS-1$
- } catch (UnsupportedOperationException e) {
- // expected
- // Note:can not tell when to catch
- // UnsupportedOperationException or
- // ReadOnlyBufferException, so catch all.
- }
- }
+ public void testIsReadOnly() {
+ assertFalse(buf.isReadOnly());
}
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "order",
+ notes = "Verifies that hasArray returns true value.",
+ method = "hasArray",
args = {}
)
- public void testOrder() {
- assertEquals(ByteOrder.nativeOrder(), buf.order());
+ public void testHasArray() {
+ assertTrue(buf.hasArray());
+ assertNotNull(buf.array());
}
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
- notes = "Abstract method.",
- method = "isReadOnly",
+ notes = "",
+ method = "order",
args = {}
)
- public void testIsReadOnly() {
- assertFalse(buf.isReadOnly());
+ public void testOrder() {
+ assertEquals(ByteOrder.nativeOrder(), buf.order());
}
/*
diff --git a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/DirectByteBufferTest.java b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/DirectByteBufferTest.java
index 08e4813..e384a3d 100644
--- a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/DirectByteBufferTest.java
+++ b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/DirectByteBufferTest.java
@@ -25,14 +25,13 @@ import java.nio.ByteBuffer;
public class DirectByteBufferTest extends ByteBufferTest {
protected void setUp() throws Exception {
- super.setUp();
capacity = BUFFER_LENGTH;
buf = ByteBuffer.allocateDirect(BUFFER_LENGTH);
+ loadTestData1(buf);
baseBuf = buf;
}
protected void tearDown() throws Exception {
- super.tearDown();
buf = null;
baseBuf = null;
}
@@ -111,14 +110,4 @@ public class DirectByteBufferTest extends ByteBufferTest {
// expected
}
}
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies isReadOnly method for direct ByteBuffer.",
- method = "isReadOnly",
- args = {}
- )
- public void testIsReadOnly() {
- assertFalse(buf.isReadOnly());
- }
}
diff --git a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/DirectCharBufferTest.java b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/DirectCharBufferTest.java
index fb55e1d..e910f92 100644
--- a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/DirectCharBufferTest.java
+++ b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/DirectCharBufferTest.java
@@ -25,14 +25,14 @@ import java.nio.ByteOrder;
@TestTargetClass(java.nio.CharBuffer.class)
public class DirectCharBufferTest extends CharBufferTest {
- public void setUp(){
+ protected void setUp(){
capacity = BUFFER_LENGTH;
- buf = ByteBuffer.allocateDirect(BUFFER_LENGTH*2).asCharBuffer();
- super.loadTestData1(buf);
+ buf = ByteBuffer.allocateDirect(BUFFER_LENGTH * 2).asCharBuffer();
+ loadTestData1(buf);
baseBuf = buf;
}
- public void tearDown(){
+ protected void tearDown(){
buf = null;
baseBuf = null;
}
diff --git a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/DirectIntBufferTest.java b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/DirectIntBufferTest.java
index 4e72a43..489d265 100644
--- a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/DirectIntBufferTest.java
+++ b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/DirectIntBufferTest.java
@@ -19,6 +19,7 @@ import dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetNew;
import dalvik.annotation.TestTargetClass;
+import java.nio.BufferOverflowException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
@@ -94,4 +95,47 @@ public class DirectIntBufferTest extends IntBufferTest {
public void testOrder() {
assertEquals(ByteOrder.BIG_ENDIAN, buf.order());
}
+
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "Regression test for IntToByteBufferAdapter",
+ clazz = ByteBuffer.class,
+ method = "asIntBuffer",
+ args = {}
+ )
+ public void testRangeChecks() {
+ int[] myInts = new int[BUFFER_LENGTH];
+
+ for (int i = 0; i < BUFFER_LENGTH; i++) {
+ myInts[i] = 1000 + i;
+ }
+
+ buf.position(0);
+ buf.put(myInts, 0, BUFFER_LENGTH);
+ buf.position(0);
+ buf.put(myInts, 0, BUFFER_LENGTH);
+
+ try {
+ buf.put(myInts, 0, 1); // should fail
+ fail("BufferOverflowException expected but not thrown");
+ } catch (BufferOverflowException boe) {
+ // expected
+ }
+
+ try {
+ buf.position(0);
+ buf.put(myInts, 0, BUFFER_LENGTH + 1); // should fail
+ fail("BufferOverflowException expected but not thrown");
+ } catch (IndexOutOfBoundsException ioobe) {
+ // expected
+ }
+
+ try {
+ buf.position(BUFFER_LENGTH - 1);
+ buf.put(myInts, 0, 2); // should fail
+ fail("BufferOverflowException expected but not thrown");
+ } catch (BufferOverflowException boe) {
+ // expected
+ }
+ }
}
diff --git a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/DirectShortBufferTest.java b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/DirectShortBufferTest.java
index a76701f..a6e922b 100644
--- a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/DirectShortBufferTest.java
+++ b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/DirectShortBufferTest.java
@@ -19,8 +19,10 @@ import dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetNew;
import dalvik.annotation.TestTargetClass;
+import java.nio.BufferOverflowException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
+import java.nio.ShortBuffer;
@TestTargetClass(java.nio.ShortBuffer.class)
public class DirectShortBufferTest extends ShortBufferTest {
@@ -94,4 +96,47 @@ public class DirectShortBufferTest extends ShortBufferTest {
public void testOrder() {
assertEquals(ByteOrder.BIG_ENDIAN, buf.order());
}
+
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "Regression test for ShortToByteBufferAdapter",
+ clazz = ByteBuffer.class,
+ method = "asShortBuffer",
+ args = {}
+ )
+ public void testRangeChecks() {
+ short[] myShorts = new short[BUFFER_LENGTH];
+
+ for (short i = 0; i < BUFFER_LENGTH; i++) {
+ myShorts[i] = (short) (1000 + i);
+ }
+
+ buf.position(0);
+ buf.put(myShorts, 0, BUFFER_LENGTH);
+ buf.position(0);
+ buf.put(myShorts, 0, BUFFER_LENGTH);
+
+ try {
+ buf.put(myShorts, 0, 1); // should fail
+ fail("BufferOverflowException expected but not thrown");
+ } catch (BufferOverflowException boe) {
+ // expected
+ }
+
+ try {
+ buf.position(0);
+ buf.put(myShorts, 0, BUFFER_LENGTH + 1); // should fail
+ fail("BufferOverflowException expected but not thrown");
+ } catch (IndexOutOfBoundsException ioobe) {
+ // expected
+ }
+
+ try {
+ buf.position(BUFFER_LENGTH - 1);
+ buf.put(myShorts, 0, 2); // should fail
+ fail("BufferOverflowException expected but not thrown");
+ } catch (BufferOverflowException boe) {
+ // expected
+ }
+ }
}
diff --git a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/DoubleBufferTest.java b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/DoubleBufferTest.java
index 44f0ae7..033c289 100644
--- a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/DoubleBufferTest.java
+++ b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/DoubleBufferTest.java
@@ -20,6 +20,7 @@ package org.apache.harmony.nio.tests.java.nio;
import dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetNew;
import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.AndroidOnly;
import java.nio.BufferOverflowException;
import java.nio.BufferUnderflowException;
@@ -32,7 +33,7 @@ import java.nio.InvalidMarkException;
* Tests java.nio.DoubleBuffer
*/
@TestTargetClass(java.nio.DoubleBuffer.class)
-public class DoubleBufferTest extends AbstractBufferTest {
+public abstract class DoubleBufferTest extends AbstractBufferTest {
protected static final int SMALL_TEST_LENGTH = 5;
@@ -216,6 +217,7 @@ public class DoubleBufferTest extends AbstractBufferTest {
method = "compact",
args = {}
)
+ @AndroidOnly("Fails on RI. See comment below")
public void testCompact() {
// case: buffer is full
buf.clear();
@@ -243,6 +245,9 @@ public class DoubleBufferTest extends AbstractBufferTest {
assertEquals(buf.limit(), buf.capacity());
assertContentLikeTestData1(buf, 0, 0.0, buf.capacity());
try {
+ // Fails on RI. Spec doesn't specify the behavior if
+ // actually nothing to be done by compact(). So RI doesn't reset
+ // mark position
buf.reset();
fail("Should throw Exception"); //$NON-NLS-1$
} catch (InvalidMarkException e) {
@@ -569,6 +574,16 @@ public class DoubleBufferTest extends AbstractBufferTest {
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
+ notes = "Abstract method.",
+ method = "isReadOnly",
+ args = {}
+ )
+ public void testIsReadOnly() {
+ assertFalse(buf.isReadOnly());
+ }
+
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
notes = "",
method = "order",
args = {}
diff --git a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/FloatBufferTest.java b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/FloatBufferTest.java
index f140dd2..f0a629a 100644
--- a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/FloatBufferTest.java
+++ b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/FloatBufferTest.java
@@ -20,6 +20,7 @@ package org.apache.harmony.nio.tests.java.nio;
import dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetNew;
import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.AndroidOnly;
import java.nio.BufferOverflowException;
import java.nio.BufferUnderflowException;
@@ -33,7 +34,7 @@ import java.nio.InvalidMarkException;
*
*/
@TestTargetClass(java.nio.FloatBuffer.class)
-public class FloatBufferTest extends AbstractBufferTest {
+public abstract class FloatBufferTest extends AbstractBufferTest {
protected static final int SMALL_TEST_LENGTH = 5;
@@ -198,6 +199,7 @@ public class FloatBufferTest extends AbstractBufferTest {
method = "compact",
args = {}
)
+ @AndroidOnly("Fails on RI. See comment below")
public void testCompact() {
// case: buffer is full
@@ -226,6 +228,9 @@ public class FloatBufferTest extends AbstractBufferTest {
assertEquals(buf.limit(), buf.capacity());
assertContentLikeTestData1(buf, 0, 0.0f, buf.capacity());
try {
+ // Fails on RI. Spec doesn't specify the behavior if
+ // actually nothing to be done by compact(). So RI doesn't reset
+ // mark position
buf.reset();
fail("Should throw Exception"); //$NON-NLS-1$
} catch (InvalidMarkException e) {
@@ -578,6 +583,16 @@ public class FloatBufferTest extends AbstractBufferTest {
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
+ notes = "Abstract method.",
+ method = "isReadOnly",
+ args = {}
+ )
+ public void testIsReadOnly() {
+ assertFalse(buf.isReadOnly());
+ }
+
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
notes = "",
method = "order",
args = {}
diff --git a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/HeapByteBufferTest.java b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/HeapByteBufferTest.java
index 046350f..e7235ca 100644
--- a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/HeapByteBufferTest.java
+++ b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/HeapByteBufferTest.java
@@ -26,15 +26,10 @@ public class HeapByteBufferTest extends ByteBufferTest {
protected void setUp() throws Exception {
super.setUp();
- capacity = BUFFER_LENGTH;
- buf = ByteBuffer.allocate(BUFFER_LENGTH);
- baseBuf = buf;
}
protected void tearDown() throws Exception {
super.tearDown();
- buf = null;
- baseBuf = null;
}
/**
@@ -55,35 +50,4 @@ public class HeapByteBufferTest extends ByteBufferTest {
// expected
}
}
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies isDirect method with not direct buffer.",
- method = "isDirect",
- args = {}
- )
- public void testIsDirect() {
- assertFalse(buf.isDirect());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies that hasArray returns true value.",
- method = "hasArray",
- args = {}
- )
- public void testHasArray() {
- assertTrue(buf.hasArray());
- assertNotNull(buf.array());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies isReadOnly method with non read only buffer.",
- method = "isReadOnly",
- args = {}
- )
- public void testIsReadOnly() {
- assertFalse(buf.isReadOnly());
- }
}
diff --git a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/HeapCharBufferTest.java b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/HeapCharBufferTest.java
index 5c370a2..2ece6de 100644
--- a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/HeapCharBufferTest.java
+++ b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/HeapCharBufferTest.java
@@ -29,8 +29,6 @@ public class HeapCharBufferTest extends CharBufferTest {
protected void tearDown() throws Exception {
super.tearDown();
- buf = null;
- baseBuf = null;
}
@TestTargetNew(
diff --git a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/HeapDoubleBufferTest.java b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/HeapDoubleBufferTest.java
index ddef05f..c56f6a1 100644
--- a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/HeapDoubleBufferTest.java
+++ b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/HeapDoubleBufferTest.java
@@ -29,8 +29,6 @@ public class HeapDoubleBufferTest extends DoubleBufferTest {
protected void tearDown() throws Exception {
super.tearDown();
- buf = null;
- baseBuf = null;
}
@TestTargetNew(
diff --git a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/HeapFloatBufferTest.java b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/HeapFloatBufferTest.java
index 2a323c5..3a9fddc 100644
--- a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/HeapFloatBufferTest.java
+++ b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/HeapFloatBufferTest.java
@@ -29,8 +29,6 @@ public class HeapFloatBufferTest extends FloatBufferTest {
protected void tearDown() throws Exception {
super.tearDown();
- buf = null;
- baseBuf = null;
}
@TestTargetNew(
diff --git a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/HeapIntBufferTest.java b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/HeapIntBufferTest.java
index b92f7c6..203a743 100644
--- a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/HeapIntBufferTest.java
+++ b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/HeapIntBufferTest.java
@@ -29,8 +29,6 @@ public class HeapIntBufferTest extends IntBufferTest {
protected void tearDown() throws Exception {
super.tearDown();
- buf = null;
- baseBuf = null;
}
@TestTargetNew(
diff --git a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/HeapLongBufferTest.java b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/HeapLongBufferTest.java
index 7beedbb..667c7ed 100644
--- a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/HeapLongBufferTest.java
+++ b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/HeapLongBufferTest.java
@@ -29,8 +29,6 @@ public class HeapLongBufferTest extends LongBufferTest {
protected void tearDown() throws Exception {
super.tearDown();
- buf = null;
- baseBuf = null;
}
@TestTargetNew(
diff --git a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/HeapShortBufferTest.java b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/HeapShortBufferTest.java
index 4de5229..679b0bd 100644
--- a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/HeapShortBufferTest.java
+++ b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/HeapShortBufferTest.java
@@ -29,8 +29,6 @@ public class HeapShortBufferTest extends ShortBufferTest {
protected void tearDown() throws Exception {
super.tearDown();
- buf = null;
- baseBuf = null;
}
@TestTargetNew(
diff --git a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/IntBufferTest.java b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/IntBufferTest.java
index 1f26d5e..7bf973d 100644
--- a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/IntBufferTest.java
+++ b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/IntBufferTest.java
@@ -17,12 +17,15 @@
package org.apache.harmony.nio.tests.java.nio;
+import dalvik.annotation.KnownFailure;
import dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetNew;
import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.AndroidOnly;
import java.nio.BufferOverflowException;
import java.nio.BufferUnderflowException;
+import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.IntBuffer;
import java.nio.InvalidMarkException;
@@ -32,7 +35,7 @@ import java.nio.InvalidMarkException;
*
*/
@TestTargetClass(java.nio.IntBuffer.class)
-public class IntBufferTest extends AbstractBufferTest {
+public abstract class IntBufferTest extends AbstractBufferTest {
protected static final int SMALL_TEST_LENGTH = 5;
@@ -172,6 +175,7 @@ public class IntBufferTest extends AbstractBufferTest {
method = "compact",
args = {}
)
+ @AndroidOnly("Fails on RI. See comment below")
public void testCompact() {
// case: buffer is full
buf.clear();
@@ -199,6 +203,9 @@ public class IntBufferTest extends AbstractBufferTest {
assertEquals(buf.limit(), buf.capacity());
assertContentLikeTestData1(buf, 0, 0, buf.capacity());
try {
+ // Fails on RI. Spec doesn't specify the behavior if
+ // actually nothing to be done by compact(). So RI doesn't reset
+ // mark position
buf.reset();
fail("Should throw Exception"); //$NON-NLS-1$
} catch (InvalidMarkException e) {
@@ -530,6 +537,16 @@ public class IntBufferTest extends AbstractBufferTest {
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
+ notes = "Abstract method.",
+ method = "isReadOnly",
+ args = {}
+ )
+ public void testIsReadOnly() {
+ assertFalse(buf.isReadOnly());
+ }
+
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
notes = "",
method = "order",
args = {}
@@ -668,6 +685,30 @@ public class IntBufferTest extends AbstractBufferTest {
assertContentEquals(buf, array, 0, array.length);
assertSame(ret, buf);
}
+
+ /*
+ * Class under test for java.nio.IntBuffer put(int[], int, int)
+ */
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "Regression Test",
+ method = "put",
+ args = {int[].class, int.class, int.class}
+ )
+ @KnownFailure("ToT fixed")
+ public void testPutintArrayintint2() {
+ // Regression test
+ ByteBuffer buf = ByteBuffer.allocateDirect(20);
+ IntBuffer intBuf = buf.asIntBuffer();
+ int[] src = new int[5];
+ intBuf.put(src);
+ intBuf.clear();
+ try {
+ intBuf.put(src);
+ } catch (BufferOverflowException e) {
+ fail("should not throw a BufferOverflowException");
+ }
+ }
/*
* Class under test for java.nio.IntBuffer put(java.nio.IntBuffer)
diff --git a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/LongBufferTest.java b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/LongBufferTest.java
index c608f70..d6d8ed1 100644
--- a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/LongBufferTest.java
+++ b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/LongBufferTest.java
@@ -20,6 +20,7 @@ package org.apache.harmony.nio.tests.java.nio;
import dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetNew;
import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.AndroidOnly;
import java.nio.BufferOverflowException;
import java.nio.BufferUnderflowException;
@@ -32,7 +33,7 @@ import java.nio.LongBuffer;
*
*/
@TestTargetClass(java.nio.LongBuffer.class)
-public class LongBufferTest extends AbstractBufferTest {
+public abstract class LongBufferTest extends AbstractBufferTest {
protected static final int SMALL_TEST_LENGTH = 5;
@@ -172,6 +173,7 @@ public class LongBufferTest extends AbstractBufferTest {
method = "compact",
args = {}
)
+ @AndroidOnly("Fails on RI. See comment below")
public void testCompact() {
// case: buffer is full
buf.clear();
@@ -199,6 +201,9 @@ public class LongBufferTest extends AbstractBufferTest {
assertEquals(buf.limit(), buf.capacity());
assertContentLikeTestData1(buf, 0, 0, buf.capacity());
try {
+ // Fails on RI. Spec doesn't specify the behavior if
+ // actually nothing to be done by compact(). So RI doesn't reset
+ // mark position
buf.reset();
fail("Should throw Exception"); //$NON-NLS-1$
} catch (InvalidMarkException e) {
@@ -530,6 +535,16 @@ public class LongBufferTest extends AbstractBufferTest {
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
+ notes = "Abstract method.",
+ method = "isReadOnly",
+ args = {}
+ )
+ public void testIsReadOnly() {
+ assertFalse(buf.isReadOnly());
+ }
+
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
notes = "",
method = "order",
args = {}
diff --git a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/MappedByteBufferTest.java b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/MappedByteBufferTest.java
index d9eefaf..3161fe1 100644
--- a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/MappedByteBufferTest.java
+++ b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/MappedByteBufferTest.java
@@ -36,8 +36,6 @@ import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.channels.FileChannel.MapMode;
-import junit.framework.TestCase;
-
@TestTargetClass(
value = MappedByteBuffer.class,
untestedMethods = {
@@ -48,9 +46,10 @@ import junit.framework.TestCase;
)
}
)
-public class MappedByteBufferTest extends TestCase {
+public class MappedByteBufferTest extends DirectByteBufferTest {
File tmpFile;
+ FileChannel fc;
/**
* A regression test for failing to correctly set capacity of underlying
@@ -62,28 +61,23 @@ public class MappedByteBufferTest extends TestCase {
method = "asIntBuffer",
args = {}
)
- public void test_asIntBuffer() throws IOException {
- // Map file
- FileInputStream fis = new FileInputStream(tmpFile);
- FileChannel fc = fis.getChannel();
- MappedByteBuffer mmb = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc
- .size());
- int len = mmb.capacity();
- assertEquals("Got wrong number of bytes", 46, len); //$NON-NLS-1$
+ public void test_asIntBuffer() {
+ int len = buf.capacity();
+ assertEquals("Got wrong number of bytes", BUFFER_LENGTH, len); //$NON-NLS-1$
// Read in our 26 bytes
- for (int i = 0; i < 26; i++) {
- byte b = mmb.get();
- assertEquals("Got wrong byte value", (byte) 'A' + i, b); //$NON-NLS-1$
+ for (int i = 0; i < BUFFER_LENGTH - 20; i++) {
+ byte b = buf.get();
+ assertEquals("Got wrong byte value", (byte) i, b); //$NON-NLS-1$
}
// Now convert to an IntBuffer to read our ints
- IntBuffer ibuffer = mmb.asIntBuffer();
- for (int i = 0; i < 5; i++) {
+ IntBuffer ibuffer = buf.asIntBuffer();
+ for (int i = BUFFER_LENGTH - 20; i < BUFFER_LENGTH; i+=4) {
int val = ibuffer.get();
- assertEquals("Got wrong int value", i + 1, val); //$NON-NLS-1$
+ int res = i * 16777216 + (i + 1) * 65536 + (i + 2) * 256 + (i + 3);
+ assertEquals("Got wrong int value", res, val); //$NON-NLS-1$
}
- fc.close();
}
/**
@@ -167,20 +161,33 @@ public class MappedByteBufferTest extends TestCase {
protected void setUp() throws IOException {
// Create temp file with 26 bytes and 5 ints
- tmpFile = new File(System.getProperty("ctsdir"), "MappedByteBufferTest"); //$NON-NLS-1$//$NON-NLS-2$
+ tmpFile = File.createTempFile("MappedByteBufferTest", ".tmp"); //$NON-NLS-1$//$NON-NLS-2$
tmpFile.createNewFile();
tmpFile.deleteOnExit();
+
+ fillTempFile();
+
+ // Map file
+ RandomAccessFile raf = new RandomAccessFile(tmpFile, "rw");
+ fc = raf.getChannel();
+ capacity = (int) fc.size();
+ buf = fc.map(FileChannel.MapMode.READ_WRITE, 0, capacity);
+ baseBuf = buf;
+ }
+
+ protected void tearDown() throws IOException {
+ fc.close();
+ }
+
+ private void fillTempFile() throws IOException {
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();
+ ByteBuffer byteBuffer = ByteBuffer.allocateDirect(BUFFER_LENGTH);
+
+ loadTestData1(byteBuffer);
+ byteBuffer.clear();
fileChannel.write(byteBuffer);
+
fileChannel.close();
fileOutputStream.close();
}
diff --git a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyCharBufferTest.java b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyCharBufferTest.java
index e5d3573..97fd2c6 100644
--- a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyCharBufferTest.java
+++ b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyCharBufferTest.java
@@ -32,8 +32,6 @@ public class ReadOnlyCharBufferTest extends CharBufferTest {
}
protected void tearDown() throws Exception {
- buf = null;
- baseBuf = null;
super.tearDown();
}
diff --git a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyWrappedCharBufferTest1.java b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyWrappedCharBufferTest1.java
index 259e3d9..456a212 100644
--- a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyWrappedCharBufferTest1.java
+++ b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyWrappedCharBufferTest1.java
@@ -24,15 +24,15 @@ import java.nio.CharBuffer;
public class ReadOnlyWrappedCharBufferTest1 extends ReadOnlyCharBufferTest {
protected void setUp() throws Exception {
- super.setUp();
capacity = BUFFER_LENGTH;
buf = CharBuffer.wrap(new char[BUFFER_LENGTH]);
- super.loadTestData1(buf);
+ loadTestData1(buf);
buf = buf.asReadOnlyBuffer();
baseBuf = buf;
}
protected void tearDown() throws Exception {
- super.tearDown();
+ buf = null;
+ baseBuf = null;
}
}
diff --git a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyWrappedDoubleBufferTest.java b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyWrappedDoubleBufferTest.java
index 21951cf..43a0733 100644
--- a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyWrappedDoubleBufferTest.java
+++ b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyWrappedDoubleBufferTest.java
@@ -23,15 +23,15 @@ import java.nio.DoubleBuffer;
public class ReadOnlyWrappedDoubleBufferTest extends ReadOnlyDoubleBufferTest {
protected void setUp() throws Exception {
- super.setUp();
capacity = BUFFER_LENGTH;
buf = DoubleBuffer.wrap(new double[BUFFER_LENGTH]);
- super.loadTestData1(buf);
+ loadTestData1(buf);
buf = buf.asReadOnlyBuffer();
baseBuf = buf;
}
protected void tearDown() throws Exception {
- super.tearDown();
+ buf =null;
+ baseBuf = null;
}
}
diff --git a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyWrappedFloatBufferTest.java b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyWrappedFloatBufferTest.java
index cfbca11..62ab26a 100644
--- a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyWrappedFloatBufferTest.java
+++ b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyWrappedFloatBufferTest.java
@@ -23,15 +23,15 @@ import java.nio.FloatBuffer;
public class ReadOnlyWrappedFloatBufferTest extends ReadOnlyFloatBufferTest {
protected void setUp() throws Exception {
- super.setUp();
capacity = BUFFER_LENGTH;
buf = FloatBuffer.wrap(new float[BUFFER_LENGTH]);
- super.loadTestData1(buf);
+ loadTestData1(buf);
buf = buf.asReadOnlyBuffer();
baseBuf = buf;
}
protected void tearDown() throws Exception {
- super.tearDown();
+ buf = null;
+ baseBuf = null;
}
}
diff --git a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyWrappedIntBufferTest.java b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyWrappedIntBufferTest.java
index a9210d2..842b553 100644
--- a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyWrappedIntBufferTest.java
+++ b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyWrappedIntBufferTest.java
@@ -23,7 +23,6 @@ import java.nio.IntBuffer;
public class ReadOnlyWrappedIntBufferTest extends ReadOnlyIntBufferTest {
protected void setUp() throws Exception {
- super.setUp();
capacity = BUFFER_LENGTH;
buf = IntBuffer.wrap(new int[BUFFER_LENGTH]);
loadTestData1(buf);
@@ -32,6 +31,7 @@ public class ReadOnlyWrappedIntBufferTest extends ReadOnlyIntBufferTest {
}
protected void tearDown() throws Exception {
- super.tearDown();
+ buf = null;
+ baseBuf = null;
}
}
diff --git a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyWrappedLongBufferTest.java b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyWrappedLongBufferTest.java
index 392d9c5..6d04d6f 100644
--- a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyWrappedLongBufferTest.java
+++ b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyWrappedLongBufferTest.java
@@ -23,7 +23,6 @@ import java.nio.LongBuffer;
public class ReadOnlyWrappedLongBufferTest extends ReadOnlyLongBufferTest{
protected void setUp() throws Exception {
- super.setUp();
capacity = BUFFER_LENGTH;
buf = LongBuffer.wrap(new long[BUFFER_LENGTH]);
loadTestData1(buf);
@@ -32,6 +31,7 @@ public class ReadOnlyWrappedLongBufferTest extends ReadOnlyLongBufferTest{
}
protected void tearDown() throws Exception {
- super.tearDown();
+ buf = null;
+ baseBuf = null;
}
}
diff --git a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyWrappedShortBufferTest.java b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyWrappedShortBufferTest.java
index 32e5c29..eb604ab 100644
--- a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyWrappedShortBufferTest.java
+++ b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyWrappedShortBufferTest.java
@@ -23,7 +23,6 @@ import java.nio.ShortBuffer;
public class ReadOnlyWrappedShortBufferTest extends ReadOnlyShortBufferTest {
protected void setUp() throws Exception {
- super.setUp();
capacity = BUFFER_LENGTH;
buf = ShortBuffer.wrap(new short[BUFFER_LENGTH]);
loadTestData1(buf);
@@ -32,6 +31,7 @@ public class ReadOnlyWrappedShortBufferTest extends ReadOnlyShortBufferTest {
}
protected void tearDown() throws Exception {
- super.tearDown();
+ buf = null;
+ baseBuf = null;
}
}
diff --git a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/ShortBufferTest.java b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/ShortBufferTest.java
index 13af578..6c7cbff 100644
--- a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/ShortBufferTest.java
+++ b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/ShortBufferTest.java
@@ -17,13 +17,17 @@
package org.apache.harmony.nio.tests.java.nio;
+import dalvik.annotation.KnownFailure;
import dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetNew;
import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.AndroidOnly;
import java.nio.BufferOverflowException;
import java.nio.BufferUnderflowException;
+import java.nio.ByteBuffer;
import java.nio.ByteOrder;
+import java.nio.IntBuffer;
import java.nio.InvalidMarkException;
import java.nio.ShortBuffer;
@@ -32,7 +36,7 @@ import java.nio.ShortBuffer;
*
*/
@TestTargetClass(java.nio.ShortBuffer.class)
-public class ShortBufferTest extends AbstractBufferTest {
+public abstract class ShortBufferTest extends AbstractBufferTest {
protected static final int SMALL_TEST_LENGTH = 5;
@@ -171,6 +175,7 @@ public class ShortBufferTest extends AbstractBufferTest {
method = "compact",
args = {}
)
+ @AndroidOnly("Fails on RI. See comment below")
public void testCompact() {
// case: buffer is full
buf.clear();
@@ -198,6 +203,9 @@ public class ShortBufferTest extends AbstractBufferTest {
assertEquals(buf.limit(), buf.capacity());
assertContentLikeTestData1(buf, 0, (short) 0, buf.capacity());
try {
+ // Fails on RI. Spec doesn't specify the behavior if
+ // actually nothing to be done by compact(). So RI doesn't reset
+ // mark position
buf.reset();
fail("Should throw Exception"); //$NON-NLS-1$
} catch (InvalidMarkException e) {
@@ -523,6 +531,16 @@ public class ShortBufferTest extends AbstractBufferTest {
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
+ notes = "Abstract method.",
+ method = "isReadOnly",
+ args = {}
+ )
+ public void testIsReadOnly() {
+ assertFalse(buf.isReadOnly());
+ }
+
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
notes = "",
method = "order",
args = {}
@@ -661,6 +679,30 @@ public class ShortBufferTest extends AbstractBufferTest {
assertContentEquals(buf, array, 0, array.length);
assertSame(ret, buf);
}
+
+ /*
+ * Class under test for java.nio.IntBuffer put(int[], int, int)
+ */
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "Regression test",
+ method = "put",
+ args = {short[].class, int.class, int.class}
+ )
+ @KnownFailure("ToT fixed")
+ public void testPutshortArrayintint2() {
+ // Regression test
+ ByteBuffer buf = ByteBuffer.allocateDirect(10);
+ ShortBuffer shortBuf = buf.asShortBuffer();
+ short[] src = new short[5];
+ shortBuf.put(src);
+ shortBuf.clear();
+ try {
+ shortBuf.put(src);
+ } catch (BufferOverflowException e) {
+ fail("should not throw a BufferOverflowException");
+ }
+ }
/*
* Class under test for java.nio.ShortBuffer put(java.nio.ShortBuffer)
diff --git a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/SliceDirectByteBufferTest.java b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/SliceDirectByteBufferTest.java
index 8b94e3e..022739c 100644
--- a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/SliceDirectByteBufferTest.java
+++ b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/SliceDirectByteBufferTest.java
@@ -24,7 +24,7 @@ public class SliceDirectByteBufferTest extends DirectByteBufferTest {
protected void setUp() throws Exception {
super.setUp();
capacity = BUFFER_LENGTH - 2;
- buf.position(1).limit(BUFFER_LENGTH-1);
+ buf.position(1).limit(BUFFER_LENGTH - 1);
buf = buf.slice();
baseBuf = buf;
}
diff --git a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/SliceHeapByteBufferTest.java b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/SliceHeapByteBufferTest.java
index aafe47f..2325da0 100644
--- a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/SliceHeapByteBufferTest.java
+++ b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/SliceHeapByteBufferTest.java
@@ -24,7 +24,7 @@ public class SliceHeapByteBufferTest extends HeapByteBufferTest {
protected void setUp() throws Exception {
super.setUp();
capacity = BUFFER_LENGTH - 2;
- buf.position(1).limit(BUFFER_LENGTH-1);
+ buf.position(1).limit(BUFFER_LENGTH - 1);
buf = buf.slice();
baseBuf = buf;
}
diff --git a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/SliceWrappedByteBufferTest.java b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/SliceWrappedByteBufferTest.java
index d348916..0bfd339 100644
--- a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/SliceWrappedByteBufferTest.java
+++ b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/SliceWrappedByteBufferTest.java
@@ -24,7 +24,7 @@ public class SliceWrappedByteBufferTest extends WrappedByteBufferTest {
protected void setUp() throws Exception {
super.setUp();
capacity = BUFFER_LENGTH - 2;
- buf.position(1).limit(BUFFER_LENGTH-1);
+ buf.position(1).limit(BUFFER_LENGTH - 1);
buf = buf.slice();
baseBuf = buf;
}
diff --git a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/WrappedByteBufferTest.java b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/WrappedByteBufferTest.java
index 94c8418..ec01f03 100644
--- a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/WrappedByteBufferTest.java
+++ b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/WrappedByteBufferTest.java
@@ -26,14 +26,13 @@ import java.nio.ByteBuffer;
public class WrappedByteBufferTest extends ByteBufferTest {
protected void setUp() throws Exception {
- super.setUp();
capacity = BUFFER_LENGTH;
buf = ByteBuffer.wrap(new byte[BUFFER_LENGTH]);
+ loadTestData1(buf);
baseBuf = buf;
}
protected void tearDown() throws Exception {
- super.tearDown();
buf = null;
baseBuf = null;
}
@@ -94,35 +93,4 @@ public class WrappedByteBufferTest extends ByteBufferTest {
}
}
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies isDirect method for non direct ByteBuffer.",
- method = "isDirect",
- args = {}
- )
- public void testIsDirect() {
- assertFalse(buf.isDirect());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies hasArray method for wrapped ByteBuffer.",
- method = "hasArray",
- args = {}
- )
- public void testHasArray() {
- assertTrue(buf.hasArray());
- assertNotNull(buf.array());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "isReadOnly",
- args = {}
- )
- public void testIsReadOnly() {
- assertFalse(buf.isReadOnly());
- }
-
}
diff --git a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/WrappedCharBufferTest1.java b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/WrappedCharBufferTest1.java
index ff48762..2398cdb 100644
--- a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/WrappedCharBufferTest1.java
+++ b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/WrappedCharBufferTest1.java
@@ -26,7 +26,6 @@ import java.nio.CharBuffer;
public class WrappedCharBufferTest1 extends CharBufferTest {
protected void setUp() throws Exception {
- super.setUp();
capacity = BUFFER_LENGTH;
buf = CharBuffer.wrap(new char[BUFFER_LENGTH]);
loadTestData1(buf);
@@ -34,7 +33,6 @@ public class WrappedCharBufferTest1 extends CharBufferTest {
}
protected void tearDown() throws Exception {
- super.tearDown();
baseBuf = null;
buf = null;
}
diff --git a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/WrappedCharBufferTest2.java b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/WrappedCharBufferTest2.java
index e3a51c8..8365c1c 100644
--- a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/WrappedCharBufferTest2.java
+++ b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/WrappedCharBufferTest2.java
@@ -19,6 +19,7 @@ package org.apache.harmony.nio.tests.java.nio;
import dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetNew;
import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.AndroidOnly;
import java.nio.BufferOverflowException;
import java.nio.CharBuffer;
@@ -170,4 +171,15 @@ public class WrappedCharBufferTest2 extends ReadOnlyCharBufferTest {
// expected
}
}
+
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "slice",
+ args = {}
+ )
+ @AndroidOnly("Fails on RI")
+ public void testSlice() {
+ super.testSlice();
+ }
}
diff --git a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/WrappedDoubleBufferTest.java b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/WrappedDoubleBufferTest.java
index 4ea5c84..d47ed75 100644
--- a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/WrappedDoubleBufferTest.java
+++ b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/WrappedDoubleBufferTest.java
@@ -24,7 +24,6 @@ import java.nio.DoubleBuffer;
@TestTargetClass(java.nio.DoubleBuffer.class)
public class WrappedDoubleBufferTest extends DoubleBufferTest {
protected void setUp() throws Exception {
- super.setUp();
capacity = BUFFER_LENGTH;
buf = DoubleBuffer.wrap(new double[BUFFER_LENGTH]);
loadTestData1(buf);
@@ -32,9 +31,8 @@ public class WrappedDoubleBufferTest extends DoubleBufferTest {
}
protected void tearDown() throws Exception {
- super.tearDown();
- baseBuf = null;
buf = null;
+ baseBuf = null;
}
/**
diff --git a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/WrappedFloatBufferTest.java b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/WrappedFloatBufferTest.java
index 71f84a9..ee5095d 100644
--- a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/WrappedFloatBufferTest.java
+++ b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/WrappedFloatBufferTest.java
@@ -24,7 +24,6 @@ import java.nio.FloatBuffer;
@TestTargetClass(java.nio.FloatBuffer.class)
public class WrappedFloatBufferTest extends FloatBufferTest {
protected void setUp() throws Exception {
- super.setUp();
capacity = BUFFER_LENGTH;
buf = FloatBuffer.wrap(new float[BUFFER_LENGTH]);
loadTestData1(buf);
@@ -32,7 +31,6 @@ public class WrappedFloatBufferTest extends FloatBufferTest {
}
protected void tearDown() throws Exception {
- super.tearDown();
baseBuf = null;
buf = null;
}
diff --git a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/WrappedIntBufferTest.java b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/WrappedIntBufferTest.java
index 3041de7..b22258b 100644
--- a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/WrappedIntBufferTest.java
+++ b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/WrappedIntBufferTest.java
@@ -24,7 +24,6 @@ import java.nio.IntBuffer;
@TestTargetClass(java.nio.IntBuffer.class)
public class WrappedIntBufferTest extends IntBufferTest {
protected void setUp() throws Exception {
- super.setUp();
capacity = BUFFER_LENGTH;
buf = IntBuffer.wrap(new int[BUFFER_LENGTH]);
loadTestData1(buf);
@@ -32,7 +31,6 @@ public class WrappedIntBufferTest extends IntBufferTest {
}
protected void tearDown() throws Exception {
- super.tearDown();
baseBuf = null;
buf = null;
}
diff --git a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/WrappedLongBufferTest.java b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/WrappedLongBufferTest.java
index 552a1e3..3faec21 100644
--- a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/WrappedLongBufferTest.java
+++ b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/WrappedLongBufferTest.java
@@ -24,7 +24,6 @@ import java.nio.LongBuffer;
@TestTargetClass(java.nio.LongBuffer.class)
public class WrappedLongBufferTest extends LongBufferTest {
protected void setUp() throws Exception {
- super.setUp();
capacity = BUFFER_LENGTH;
buf = LongBuffer.wrap(new long[BUFFER_LENGTH]);
loadTestData1(buf);
@@ -32,7 +31,6 @@ public class WrappedLongBufferTest extends LongBufferTest {
}
protected void tearDown() throws Exception {
- super.tearDown();
baseBuf = null;
buf = null;
}
diff --git a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/WrappedShortBufferTest.java b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/WrappedShortBufferTest.java
index 9917ae0..aa3c76e 100644
--- a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/WrappedShortBufferTest.java
+++ b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/WrappedShortBufferTest.java
@@ -24,7 +24,6 @@ import java.nio.ShortBuffer;
@TestTargetClass(java.nio.ShortBuffer.class)
public class WrappedShortBufferTest extends ShortBufferTest {
protected void setUp() throws Exception {
- super.setUp();
capacity = BUFFER_LENGTH;
buf = ShortBuffer.wrap(new short[BUFFER_LENGTH]);
loadTestData1(buf);
@@ -32,7 +31,6 @@ public class WrappedShortBufferTest extends ShortBufferTest {
}
protected void tearDown() throws Exception {
- super.tearDown();
baseBuf = null;
buf = null;
}
diff --git a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/FileChannelTest.java b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/FileChannelTest.java
index 9a1a956..91d6d06 100644
--- a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/FileChannelTest.java
+++ b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/FileChannelTest.java
@@ -2439,6 +2439,7 @@ public class FileChannelTest extends TestCase {
method = "position",
args = {}
)
+ @AndroidOnly("Fails on RI. See comment below")
public void test_position_append() throws Exception {
// Regression test for Harmony-508
File tmpfile = File.createTempFile("FileOutputStream", "tmp");
diff --git a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/FileLockTest.java b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/FileLockTest.java
index 6dc127e..6148b6f 100644
--- a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/FileLockTest.java
+++ b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/FileLockTest.java
@@ -260,4 +260,19 @@ public class FileLockTest extends TestCase {
FileLock fileLock = fileChannel.lock();
assertTrue(fileLock.toString().length() > 0);
}
+
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Regression test",
+ method = "release",
+ args = {}
+ )
+ public void testFileLock() throws Exception {
+ String fileName = File.createTempFile("test", "tmp").getAbsolutePath();
+ RandomAccessFile raf = new RandomAccessFile(fileName, "rw");
+ FileLock lock = raf.getChannel().tryLock();
+ raf.write("file lock test".getBytes());
+ lock.release();
+ raf.close();
+ }
}
diff --git a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/SelectorTest.java b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/SelectorTest.java
index 883ca28..de69f9f 100644
--- a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/SelectorTest.java
+++ b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/SelectorTest.java
@@ -16,7 +16,6 @@
package org.apache.harmony.nio.tests.java.nio.channels;
-import dalvik.annotation.KnownFailure;
import dalvik.annotation.TestTargetNew;
import dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetClass;
@@ -340,7 +339,6 @@ public class SelectorTest extends TestCase {
method = "select",
args = {long.class}
)
- @KnownFailure("fixed in ToT")
public void test_selectJ_Empty_Keys() throws IOException {
// regression test, see HARMONY-3888.
// make sure select(long) does wait for specified amount of
diff --git a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/ServerSocketChannelTest.java b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/ServerSocketChannelTest.java
index 988cef6..ad1e78f 100644
--- a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/ServerSocketChannelTest.java
+++ b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/ServerSocketChannelTest.java
@@ -17,11 +17,11 @@
package org.apache.harmony.nio.tests.java.nio.channels;
-import dalvik.annotation.KnownFailure;
import dalvik.annotation.TestTargetNew;
import dalvik.annotation.TestTargets;
import dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.AndroidOnly;
import java.io.IOException;
import java.io.InputStream;
@@ -719,6 +719,7 @@ public class ServerSocketChannelTest extends TestCase {
method = "accept",
args = {}
)
+ @AndroidOnly("seems to run on newer RI versions")
public void test_accept_Security() throws IOException {
this.clientChannel.configureBlocking(true);
this.serverChannel.configureBlocking(true);
@@ -868,7 +869,6 @@ public class ServerSocketChannelTest extends TestCase {
method = "socket",
args = {}
)
- @KnownFailure("Fixed in ToT")
public void test_socket_getLocalPort() throws IOException {
// regression test for Harmony-4961
serverChannel.socket().bind(localAddr1);
diff --git a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/SinkChannelTest.java b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/SinkChannelTest.java
index 849ef12..04f0e6c 100644
--- a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/SinkChannelTest.java
+++ b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/SinkChannelTest.java
@@ -20,6 +20,7 @@ import dalvik.annotation.TestTargetNew;
import dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetClass;
import dalvik.annotation.TestTargets;
+import dalvik.annotation.AndroidOnly;
import java.io.IOException;
import java.net.InetAddress;
@@ -270,6 +271,7 @@ public class SinkChannelTest extends TestCase {
method = "write",
args = {java.nio.ByteBuffer[].class}
)
+ @AndroidOnly("seems to run on newer RI versions")
public void test_write_LByteBuffer_SourceClosed() throws IOException {
source.close();
int written = sink.write(buffer);
@@ -384,6 +386,7 @@ public class SinkChannelTest extends TestCase {
method = "write",
args = {java.nio.ByteBuffer[].class}
)
+ @AndroidOnly("seems to run on newer RI versions")
public void test_write_$LByteBuffer_SourceClosed() throws IOException {
ByteBuffer[] bufArray = { buffer };
source.close();
@@ -553,6 +556,7 @@ public class SinkChannelTest extends TestCase {
method = "write",
args = {java.nio.ByteBuffer[].class, int.class, int.class}
)
+ @AndroidOnly("seems to run on newer RI versions")
public void test_write_$LByteBufferII_SourceClosed() throws IOException {
ByteBuffer[] bufArray = { buffer };
source.close();
diff --git a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/SocketChannelTest.java b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/SocketChannelTest.java
index d31cd0a..69f245d 100755
--- a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/SocketChannelTest.java
+++ b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/SocketChannelTest.java
@@ -22,6 +22,7 @@ import dalvik.annotation.TestTargets;
import dalvik.annotation.TestTargetNew;
import dalvik.annotation.TestTargetClass;
import dalvik.annotation.TestLevel;
+import dalvik.annotation.AndroidOnly;
import java.io.IOException;
import java.io.InputStream;
@@ -517,9 +518,12 @@ public class SocketChannelTest extends TestCase {
method = "socket",
args = {}
)
+ @AndroidOnly("Fails on RI. See comment below")
public void testSocket_BasicStatusBeforeConnect() throws IOException {
assertFalse(this.channel1.isConnected());// not connected
Socket s1 = this.channel1.socket();
+ // RI fails here. RI returns 0 while spec says getLocalPort()
+ // shall return -1 for unbound socket
assertSocketBeforeConnect(s1);
Socket s2 = this.channel1.socket();
// same
@@ -551,6 +555,7 @@ public class SocketChannelTest extends TestCase {
method = "socket",
args = {}
)
+ @AndroidOnly("Fails on RI. See comment below")
public void testSocket_NonBlock_BasicStatusAfterConnect() throws Exception {
assertFalse(this.channel1.isConnected());// not connected
this.channel1.configureBlocking(false);
@@ -559,6 +564,8 @@ public class SocketChannelTest extends TestCase {
assertTrue(this.channel1.isConnectionPending());
Socket s1 = this.channel1.socket();
// status of not connected
+ // RI fails here. RI returns 0 while spec says getLocalPort()
+ // shall return -1 for unbound socket
assertSocketBeforeConnect(s1);
Socket s2 = this.channel1.socket();
// same
@@ -2666,7 +2673,7 @@ public class SocketChannelTest extends TestCase {
method = "write",
args = {java.nio.ByteBuffer.class}
)
- @KnownFailure("Fxed on ToT")
+ @KnownFailure("Fixed on ToT")
public void test_writeLjava_nio_ByteBuffer_Nonblocking_HugeData() throws IOException {
// initialize write content
ByteBuffer writeContent = ByteBuffer.allocate(CAPACITY_HUGE);