You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by gh...@apache.org on 2006/06/30 11:35:29 UTC
svn commit: r418214 - in
/incubator/harmony/enhanced/classlib/trunk/modules/nio/src:
main/java/java/nio/ test/java/org/apache/harmony/tests/java/nio/
Author: gharley
Date: Fri Jun 30 02:35:29 2006
New Revision: 418214
URL: http://svn.apache.org/viewvc?rev=418214&view=rev
Log:
HARMONY 704 : refactor nio buffer test step 2 - CharBuffer tests
Added:
incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/DirectCharBufferTest.java (with props)
incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/HeapCharBufferTest.java (with props)
incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/ReadOnlyCharBufferTest.java (with props)
incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/ReadOnlyHeapCharBufferTest.java (with props)
incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/ReadOnlyWrappedCharBufferTest1.java (with props)
incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/WrappedCharBufferTest1.java (with props)
incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/WrappedCharBufferTest2.java (with props)
Modified:
incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/CharBuffer.java
incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/CharSequenceAdapter.java
incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadOnlyCharArrayBuffer.java
incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/AbstractBufferTest.java
incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/AllTests.java
incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/ByteBufferTest.java
incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/CharBufferTest.java
Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/CharBuffer.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/CharBuffer.java?rev=418214&r1=418213&r2=418214&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/CharBuffer.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/CharBuffer.java Fri Jun 30 02:35:29 2006
@@ -653,6 +653,9 @@
* If no changes may be made to the contents of this buffer
*/
public CharBuffer put(String str, int start, int end) {
+ if(str == null){
+ throw new NullPointerException();
+ }
if (start < 0 || end < start || end > str.length()) {
throw new IndexOutOfBoundsException();
}
Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/CharSequenceAdapter.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/CharSequenceAdapter.java?rev=418214&r1=418213&r2=418214&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/CharSequenceAdapter.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/CharSequenceAdapter.java Fri Jun 30 02:35:29 2006
@@ -116,10 +116,28 @@
}
public final CharBuffer put(char[] src, int off, int len) {
+ if ((off < 0 ) || (len < 0) || off + len > src.length) {
+ throw new IndexOutOfBoundsException();
+ }
+
+ if (len > remaining()) {
+ throw new BufferOverflowException();
+ }
+
+ if(src == null){
+ throw new NullPointerException();
+ }
+
throw new ReadOnlyBufferException();
}
public CharBuffer put(String src, int start, int end) {
+ if ((start < 0 ) || (end < 0) || start + end > src.length()) {
+ throw new IndexOutOfBoundsException();
+ }
+ if(src == null){
+ throw new NullPointerException();
+ }
throw new ReadOnlyBufferException();
}
Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadOnlyCharArrayBuffer.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadOnlyCharArrayBuffer.java?rev=418214&r1=418213&r2=418214&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadOnlyCharArrayBuffer.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadOnlyCharArrayBuffer.java Fri Jun 30 02:35:29 2006
@@ -83,8 +83,18 @@
public final CharBuffer put(char[] src, int off, int len) {
throw new ReadOnlyBufferException();
}
+
+ public final CharBuffer put(CharBuffer src) {
+ throw new ReadOnlyBufferException();
+ }
public CharBuffer put(String src, int start, int end) {
+ if ((start < 0 ) || (end < 0) || start + end > src.length()) {
+ throw new IndexOutOfBoundsException();
+ }
+ if(src == null){
+ throw new NullPointerException();
+ }
throw new ReadOnlyBufferException();
}
Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/AbstractBufferTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/AbstractBufferTest.java?rev=418214&r1=418213&r2=418214&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/AbstractBufferTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/AbstractBufferTest.java Fri Jun 30 02:35:29 2006
@@ -26,17 +26,15 @@
*/
public class AbstractBufferTest extends TestCase {
- private static final byte[] bytes = new byte[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
-
protected Buffer baseBuf;
-
- protected void setUp() throws Exception {
- super.setUp();
- baseBuf = ByteBuffer.wrap(bytes);
+
+ protected void setUp() throws Exception{
+ super.setUp();
+ baseBuf = ByteBuffer.allocate(10);
}
-
- protected void tearDown() throws Exception {
- super.tearDown();
+
+ protected void tearDown() throws Exception{
+ super.tearDown();
}
public void testCapacity() {
Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/AllTests.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/AllTests.java?rev=418214&r1=418213&r2=418214&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/AllTests.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/AllTests.java Fri Jun 30 02:35:29 2006
@@ -31,32 +31,38 @@
public static Test suite() {
TestSuite suite = new TestSuite("Tests for java.nio");
//$JUnit-BEGIN$
- suite.addTestSuite(ByteBufferTest.class);
+ suite.addTestSuite(InvalidMarkExceptionTest.class);
+ suite.addTestSuite(ReadOnlyCharBufferTest.class);
suite.addTestSuite(IntBufferTest.class);
- suite.addTestSuite(ReadOnlyWrappedByteBufferTest.class);
- suite.addTestSuite(AbstractBufferTest.class);
suite.addTestSuite(SliceWrappedByteBufferTest.class);
- suite.addTestSuite(DirectByteBufferTest.class);
suite.addTestSuite(ByteOrderTest.class);
- suite.addTestSuite(BufferTest.class);
- suite.addTestSuite(DuplicateWrappedByteBufferTest.class);
- suite.addTestSuite(WrappedByteBufferTest.class);
+ suite.addTestSuite(WrappedCharBufferTest1.class);
suite.addTestSuite(LongBufferTest.class);
suite.addTestSuite(HeapByteBufferTest.class);
- suite.addTestSuite(DoubleBufferTest.class);
suite.addTestSuite(ReadOnlyDirectByteBufferTest.class);
suite.addTestSuite(SliceDirectByteBufferTest.class);
- suite.addTestSuite(CharBufferTest.class);
- suite.addTestSuite(DuplicateHeapByteBufferTest.class);
+ suite.addTestSuite(ReadOnlyWrappedCharBufferTest1.class);
+ suite.addTestSuite(WrappedCharBufferTest2.class);
suite.addTestSuite(ShortBufferTest.class);
- suite.addTestSuite(ReadOnlyHeapByteBufferTest.class);
+ suite.addTestSuite(BufferUnderflowExceptionTest.class);
suite.addTestSuite(FloatBufferTest.class);
- suite.addTestSuite(SliceHeapByteBufferTest.class);
suite.addTestSuite(DuplicateDirectByteBufferTest.class);
+ suite.addTestSuite(DirectCharBufferTest.class);
+ suite.addTestSuite(ByteBufferTest.class);
+ suite.addTestSuite(ReadOnlyWrappedByteBufferTest.class);
+ suite.addTestSuite(DirectByteBufferTest.class);
suite.addTestSuite(BufferOverflowExceptionTest.class);
- suite.addTestSuite(BufferUnderflowExceptionTest.class);
- suite.addTestSuite(InvalidMarkExceptionTest.class);
+ suite.addTestSuite(BufferTest.class);
+ suite.addTestSuite(DuplicateWrappedByteBufferTest.class);
+ suite.addTestSuite(WrappedByteBufferTest.class);
suite.addTestSuite(ReadOnlyBufferExceptionTest.class);
+ suite.addTestSuite(DoubleBufferTest.class);
+ suite.addTestSuite(CharBufferTest.class);
+ suite.addTestSuite(HeapCharBufferTest.class);
+ suite.addTestSuite(DuplicateHeapByteBufferTest.class);
+ suite.addTestSuite(ReadOnlyHeapByteBufferTest.class);
+ suite.addTestSuite(ReadOnlyHeapCharBufferTest.class);
+ suite.addTestSuite(SliceHeapByteBufferTest.class);
//$JUnit-END$
return suite;
}
Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/ByteBufferTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/ByteBufferTest.java?rev=418214&r1=418213&r2=418214&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/ByteBufferTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/ByteBufferTest.java Fri Jun 30 02:35:29 2006
@@ -37,13 +37,10 @@
protected static final int SMALL_TEST_LENGTH = 5;
protected static final int BUFFER_LENGTH = 250;
- private static final byte[] bytes = new byte[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
-
protected ByteBuffer buf;
protected void setUp() throws Exception {
- super.setUp();
- buf = ByteBuffer.wrap(bytes);
+ buf = ByteBuffer.allocate(10);
baseBuf = buf;
}
Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/CharBufferTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/CharBufferTest.java?rev=418214&r1=418213&r2=418214&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/CharBufferTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/CharBufferTest.java Fri Jun 30 02:35:29 2006
@@ -18,136 +18,71 @@
import java.io.IOException;
import java.nio.BufferOverflowException;
import java.nio.BufferUnderflowException;
-import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.CharBuffer;
import java.nio.InvalidMarkException;
import java.nio.ReadOnlyBufferException;
-import junit.framework.TestCase;
-
/**
* Tests java.nio.CharBuffer
*
*/
-public class CharBufferTest extends TestCase {
+public class CharBufferTest extends AbstractBufferTest {
+ protected static final int SMALL_TEST_LENGTH = 5;
- public static void main(String[] args) {
- junit.textui.TestRunner.run(CharBufferTest.class);
- }
+ protected static final int BUFFER_LENGTH = 20;
- public static void testCharBufferInstance(CharBuffer buf) {
- // test Buffer functions
- BufferTest.testBufferInstance(buf);
-
- // test CharBuffer functions
- testHashCode(buf);
- testEquals(buf);
- testToString(buf);
- testSlice(buf);
- testDuplicate(buf);
- testAsReadOnlyBuffer(buf);
- testGet(buf);
- testPutchar(buf);
- testGetint(buf);
- testPutintchar(buf);
- testGetcharArrayintint(buf);
- testGetcharArray(buf);
- testPutCharBuffer(buf);
- testPutcharArrayintint(buf);
- testPutcharArray(buf);
- testHasArray(buf);
- testArray(buf);
- testArrayOffset(buf);
- testCompact(buf);
- testIsDirect(buf);
- testCompareTo(buf);
- testOrder(buf);
-
- testCharAt(buf);
- testLength(buf);
- testSubSequence(buf);
- testPutString(buf);
- testPutStringintint(buf);
- }
-
- public static void testArray(CharBuffer buf) {
- if (buf.hasArray()) {
- char array[] = buf.array();
- assertContentEquals(buf, array, buf.arrayOffset(), buf.capacity());
+ protected CharBuffer buf;
+
+ private static char[] chars = "123456789a".toCharArray();
+
+ protected void setUp() throws Exception{
+ char[] charscopy = new char[chars.length];
+ System.arraycopy(chars, 0, charscopy, 0, chars.length);
+ buf = CharBuffer.wrap(charscopy);
+ baseBuf = buf;
+ }
+
+ protected void tearDown() throws Exception{
+ buf = null;
+ baseBuf = null;
+ }
+
+ public void testArray() {
+ char array[] = buf.array();
+ assertContentEquals(buf, array, buf.arrayOffset(), buf.capacity());
- loadTestData1(array, buf.arrayOffset(), buf.capacity());
- assertContentEquals(buf, array, buf.arrayOffset(), buf.capacity());
+ loadTestData1(array, buf.arrayOffset(), buf.capacity());
+ assertContentEquals(buf, array, buf.arrayOffset(), buf.capacity());
- loadTestData2(array, buf.arrayOffset(), buf.capacity());
- assertContentEquals(buf, array, buf.arrayOffset(), buf.capacity());
+ loadTestData2(array, buf.arrayOffset(), buf.capacity());
+ assertContentEquals(buf, array, buf.arrayOffset(), buf.capacity());
- loadTestData1(buf);
- assertContentEquals(buf, array, buf.arrayOffset(), buf.capacity());
+ loadTestData1(buf);
+ assertContentEquals(buf, array, buf.arrayOffset(), buf.capacity());
- loadTestData2(buf);
- assertContentEquals(buf, array, buf.arrayOffset(), buf.capacity());
- } else {
- if (buf.isReadOnly()) {
- try {
- buf.array();
- fail("Should throw Exception"); //$NON-NLS-1$
- } catch (UnsupportedOperationException e) {
- // expected
- // Note:can not tell when to throw
- // UnsupportedOperationException
- // or ReadOnlyBufferException, so catch all.
- }
- } else {
- try {
- buf.array();
- fail("Should throw Exception"); //$NON-NLS-1$
- } catch (UnsupportedOperationException e) {
- // expected
- }
- }
- }
+ loadTestData2(buf);
+ assertContentEquals(buf, array, buf.arrayOffset(), buf.capacity());
}
- public static void testArrayOffset(CharBuffer buf) {
- if (buf.hasArray()) {
- char array[] = buf.array();
- assertContentEquals(buf, array, buf.arrayOffset(), buf.capacity());
+ public void testArrayOffset() {
+ char array[] = buf.array();
+ assertContentEquals(buf, array, buf.arrayOffset(), buf.capacity());
- loadTestData1(array, buf.arrayOffset(), buf.capacity());
- assertContentEquals(buf, array, buf.arrayOffset(), buf.capacity());
+ loadTestData1(array, buf.arrayOffset(), buf.capacity());
+ assertContentEquals(buf, array, buf.arrayOffset(), buf.capacity());
- loadTestData2(array, buf.arrayOffset(), buf.capacity());
- assertContentEquals(buf, array, buf.arrayOffset(), buf.capacity());
+ loadTestData2(array, buf.arrayOffset(), buf.capacity());
+ assertContentEquals(buf, array, buf.arrayOffset(), buf.capacity());
- loadTestData1(buf);
- assertContentEquals(buf, array, buf.arrayOffset(), buf.capacity());
+ loadTestData1(buf);
+ assertContentEquals(buf, array, buf.arrayOffset(), buf.capacity());
- loadTestData2(buf);
- assertContentEquals(buf, array, buf.arrayOffset(), buf.capacity());
- } else {
- if (buf.isReadOnly()) {
- try {
- buf.arrayOffset();
- fail("Should throw Exception"); //$NON-NLS-1$
- } catch (UnsupportedOperationException e) {
- // expected
- // Note:can not tell when to throw
- // UnsupportedOperationException
- // or ReadOnlyBufferException, so catch all.
- }
- } else {
- try {
- buf.arrayOffset();
- fail("Should throw Exception"); //$NON-NLS-1$
- } catch (UnsupportedOperationException e) {
- // expected
- }
- }
- }
+ loadTestData2(buf);
+ assertContentEquals(buf, array, buf.arrayOffset(), buf.capacity());
}
- public static void testAsReadOnlyBuffer(CharBuffer buf) {
+ public void testAsReadOnlyBuffer() {
buf.clear();
buf.mark();
buf.position(buf.limit());
@@ -160,6 +95,7 @@
assertEquals(buf.limit(), readonly.limit());
assertEquals(buf.isDirect(), readonly.isDirect());
assertEquals(buf.order(), readonly.order());
+ assertEquals(buf.capacity(), readonly.capacity());
assertContentEquals(buf, readonly);
// readonly's position, mark, and limit should be independent to buf
@@ -169,19 +105,34 @@
assertEquals(buf.position(), buf.limit());
buf.reset();
assertEquals(buf.position(), 0);
- }
- public static void testCompact(CharBuffer buf) {
- if (buf.isReadOnly()) {
- try {
- buf.compact();
- fail("Should throw Exception"); //$NON-NLS-1$
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- return;
- }
+ buf.clear();
+ int originalPosition = (buf.position() + buf.limit()) / 2;
+ buf.position(originalPosition);
+ buf.mark();
+ buf.position(buf.limit());
+ // readonly's contents should be the same as buf
+ readonly = buf.asReadOnlyBuffer();
+ assertNotSame(buf, readonly);
+ assertTrue(readonly.isReadOnly());
+ assertEquals(buf.position(), readonly.position());
+ assertEquals(buf.limit(), readonly.limit());
+ assertEquals(buf.isDirect(), readonly.isDirect());
+ assertEquals(buf.order(), readonly.order());
+ assertEquals(buf.capacity(), readonly.capacity());
+ assertContentEquals(buf, readonly);
+
+ // readonly's position, mark, and limit should be independent to buf
+ readonly.reset();
+ assertEquals(readonly.position(), originalPosition);
+ readonly.clear();
+ assertEquals(buf.position(), buf.limit());
+ buf.reset();
+ assertEquals(buf.position(), originalPosition);
+ }
+
+ public void testCompact() {
// case: buffer is full
buf.clear();
buf.mark();
@@ -232,33 +183,34 @@
}
}
- public static void testCompareTo(CharBuffer buf) {
+ public void testCompareTo() {
// compare to self
assertEquals(0, buf.compareTo(buf));
- // normal cases
- if (!buf.isReadOnly()) {
- assertTrue(buf.capacity() > 5);
- buf.clear();
- CharBuffer other = CharBuffer.allocate(buf.capacity());
- loadTestData1(buf);
- loadTestData1(other);
- assertEquals(0, buf.compareTo(other));
- assertEquals(0, other.compareTo(buf));
- buf.position(1);
- assertTrue(buf.compareTo(other) > 0);
- assertTrue(other.compareTo(buf) < 0);
- other.position(2);
- assertTrue(buf.compareTo(other) < 0);
- assertTrue(other.compareTo(buf) > 0);
- buf.position(2);
- other.limit(5);
- assertTrue(buf.compareTo(other) > 0);
- assertTrue(other.compareTo(buf) < 0);
- }
+ assertTrue(buf.capacity() > SMALL_TEST_LENGTH);
+ buf.clear();
+ CharBuffer other = CharBuffer.allocate(buf.capacity());
+ other.put(buf);
+ other.clear();
+ buf.clear();
+ assertEquals(0, buf.compareTo(other));
+ assertEquals(0, other.compareTo(buf));
+ buf.position(1);
+ assertTrue(buf.compareTo(other) > 0);
+ assertTrue(other.compareTo(buf) < 0);
+ other.position(2);
+ assertTrue(buf.compareTo(other) < 0);
+ assertTrue(other.compareTo(buf) > 0);
+ buf.position(2);
+ assertTrue(buf.compareTo(other) == 0);
+ assertTrue(other.compareTo(buf) == 0);
+ other.limit(SMALL_TEST_LENGTH);
+ assertTrue(buf.compareTo(other) > 0);
+ assertTrue(other.compareTo(buf) < 0);
}
- public static void testDuplicate(CharBuffer buf) {
+ public void testDuplicate() {
+ // mark the position 0
buf.clear();
buf.mark();
buf.position(buf.limit());
@@ -271,9 +223,11 @@
assertEquals(buf.isReadOnly(), duplicate.isReadOnly());
assertEquals(buf.isDirect(), duplicate.isDirect());
assertEquals(buf.order(), duplicate.order());
+ assertEquals(buf.capacity(), duplicate.capacity());
assertContentEquals(buf, duplicate);
- // duplicate's position, mark, and limit should be independent to buf
+ // duplicate's position, mark, and limit should be independent to
+ // buf
duplicate.reset();
assertEquals(duplicate.position(), 0);
duplicate.clear();
@@ -281,6 +235,33 @@
buf.reset();
assertEquals(buf.position(), 0);
+ // mark another position
+ buf.clear();
+ int originalPosition = (buf.position() + buf.limit()) / 2;
+ buf.position(originalPosition);
+ buf.mark();
+ buf.position(buf.limit());
+
+ // duplicate's contents should be the same as buf
+ duplicate = buf.duplicate();
+ assertNotSame(buf, duplicate);
+ assertEquals(buf.position(), duplicate.position());
+ assertEquals(buf.limit(), duplicate.limit());
+ assertEquals(buf.isReadOnly(), duplicate.isReadOnly());
+ assertEquals(buf.isDirect(), duplicate.isDirect());
+ assertEquals(buf.order(), duplicate.order());
+ assertEquals(buf.capacity(), duplicate.capacity());
+ assertContentEquals(buf, duplicate);
+
+ // duplicate's position, mark, and limit should be independent to
+ // buf
+ duplicate.reset();
+ assertEquals(duplicate.position(), originalPosition);
+ duplicate.clear();
+ assertEquals(buf.position(), buf.limit());
+ buf.reset();
+ assertEquals(buf.position(), originalPosition);
+
// duplicate share the same content with buf
if (!duplicate.isReadOnly()) {
loadTestData1(buf);
@@ -290,7 +271,7 @@
}
}
- public static void testEquals(CharBuffer buf) {
+ public void testEquals() {
// equal to self
assertTrue(buf.equals(buf));
CharBuffer readonly = buf.asReadOnlyBuffer();
@@ -315,7 +296,7 @@
/*
* Class under test for char get()
*/
- public static void testGet(CharBuffer buf) {
+ public void testGet() {
buf.clear();
for (int i = 0; i < buf.capacity(); i++) {
assertEquals(buf.position(), i);
@@ -332,7 +313,7 @@
/*
* Class under test for java.nio.CharBuffer get(char[])
*/
- public static void testGetcharArray(CharBuffer buf) {
+ public void testGetcharArray() {
char array[] = new char[1];
buf.clear();
for (int i = 0; i < buf.capacity(); i++) {
@@ -352,7 +333,7 @@
/*
* Class under test for java.nio.CharBuffer get(char[], int, int)
*/
- public static void testGetcharArrayintint(CharBuffer buf) {
+ public void testGetcharArrayintint() {
buf.clear();
char array[] = new char[buf.capacity()];
@@ -401,7 +382,7 @@
/*
* Class under test for char get(int)
*/
- public static void testGetint(CharBuffer buf) {
+ public void testGetint() {
buf.clear();
for (int i = 0; i < buf.capacity(); i++) {
assertEquals(buf.position(), i);
@@ -421,68 +402,21 @@
}
}
- public static void testHasArray(CharBuffer buf) {
- if (buf.hasArray()) {
- assertNotNull(buf.array());
- } else {
- if (buf.isReadOnly()) {
- try {
- buf.array();
- fail("Should throw Exception"); //$NON-NLS-1$
- } catch (UnsupportedOperationException e) {
- // expected
- // Note:can not tell when to throw
- // UnsupportedOperationException
- // or ReadOnlyBufferException, so catch all.
- }
- } else {
- try {
- buf.array();
- fail("Should throw Exception"); //$NON-NLS-1$
- } catch (UnsupportedOperationException e) {
- // expected
- }
- }
- }
- }
-
- public static void testHashCode(CharBuffer buf) {
+ public void testHashCode() {
buf.clear();
+ loadTestData1(buf);
CharBuffer readonly = buf.asReadOnlyBuffer();
CharBuffer duplicate = buf.duplicate();
assertTrue(buf.hashCode() == readonly.hashCode());
-
- assertTrue(buf.capacity() > 5);
+ assertTrue(buf.capacity() > SMALL_TEST_LENGTH);
duplicate.position(buf.capacity() / 2);
assertTrue(buf.hashCode() != duplicate.hashCode());
}
- public static void testIsDirect(CharBuffer buf) {
- buf.isDirect();
- }
-
- public static void testOrder(CharBuffer buf) {
- buf.order();
- if (buf.hasArray()) {
- assertEquals(ByteOrder.nativeOrder(), buf.order());
- }
- }
-
/*
* Class under test for java.nio.CharBuffer put(char)
*/
- public static void testPutchar(CharBuffer buf) {
- if (buf.isReadOnly()) {
- try {
- buf.clear();
- buf.put((char) 0);
- fail("Should throw Exception"); //$NON-NLS-1$
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- return;
- }
-
+ public void testPutchar() {
buf.clear();
for (int i = 0; i < buf.capacity(); i++) {
assertEquals(buf.position(), i);
@@ -501,17 +435,8 @@
/*
* Class under test for java.nio.CharBuffer put(char[])
*/
- public static void testPutcharArray(CharBuffer buf) {
+ public void testPutcharArray() {
char array[] = new char[1];
- if (buf.isReadOnly()) {
- try {
- buf.put(array);
- fail("Should throw Exception"); //$NON-NLS-1$
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- return;
- }
buf.clear();
for (int i = 0; i < buf.capacity(); i++) {
@@ -527,24 +452,26 @@
} catch (BufferOverflowException e) {
// expected
}
+ try {
+ buf.put((char[]) null);
+ fail("Should throw Exception"); //$NON-NLS-1$
+ } catch (NullPointerException e) {
+ // expected
+ }
}
/*
* Class under test for java.nio.CharBuffer put(char[], int, int)
*/
- public static void testPutcharArrayintint(CharBuffer buf) {
+ public void testPutcharArrayintint() {
buf.clear();
char array[] = new char[buf.capacity()];
- if (buf.isReadOnly()) {
- try {
- buf.put(array, 0, array.length);
- fail("Should throw Exception"); //$NON-NLS-1$
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- return;
+ try {
+ buf.put((char[]) null, 0, 1);
+ fail("Should throw NullPointerException"); //$NON-NLS-1$
+ } catch (NullPointerException e) {
+ // expected
}
-
try {
buf.put(new char[buf.capacity() + 1], 0, buf.capacity() + 1);
fail("Should throw Exception"); //$NON-NLS-1$
@@ -590,20 +517,16 @@
/*
* Class under test for java.nio.CharBuffer put(java.nio.CharBuffer)
*/
- public static void testPutCharBuffer(CharBuffer buf) {
+ public void testPutCharBuffer() {
CharBuffer other = CharBuffer.allocate(buf.capacity());
- if (buf.isReadOnly()) {
- try {
- buf.clear();
- buf.put(other);
- fail("Should throw Exception"); //$NON-NLS-1$
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- return;
- }
try {
+ buf.put((CharBuffer) null);
+ fail("Should throw Exception"); //$NON-NLS-1$
+ } catch (NullPointerException e) {
+ // expected
+ }
+ try {
buf.put(buf);
fail("Should throw Exception"); //$NON-NLS-1$
} catch (IllegalArgumentException e) {
@@ -629,17 +552,7 @@
/*
* Class under test for java.nio.CharBuffer put(int, char)
*/
- public static void testPutintchar(CharBuffer buf) {
- if (buf.isReadOnly()) {
- try {
- buf.put(0, (char) 0);
- fail("Should throw Exception"); //$NON-NLS-1$
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- return;
- }
-
+ public void testPutintchar() {
buf.clear();
for (int i = 0; i < buf.capacity(); i++) {
assertEquals(buf.position(), 0);
@@ -661,7 +574,7 @@
}
}
- public static void testSlice(CharBuffer buf) {
+ public void testSlice() {
assertTrue(buf.capacity() > 5);
buf.position(1);
buf.limit(buf.capacity() - 1);
@@ -689,7 +602,7 @@
}
}
- public static void testToString(CharBuffer buf) {
+ public void testToString() {
String expected = "";
for (int i = buf.position(); i < buf.limit(); i++) {
expected += buf.get(i);
@@ -698,7 +611,7 @@
assertEquals(expected, str);
}
- public static void testCharAt(CharBuffer buf) {
+ public void testCharAt() {
for (int i = 0; i < buf.remaining(); i++) {
assertEquals(buf.get(buf.position() + i), buf.charAt(i));
}
@@ -716,11 +629,11 @@
}
}
- public static void testLength(CharBuffer buf) {
+ public void testLength() {
assertEquals(buf.length(), buf.remaining());
}
- public static void testSubSequence(CharBuffer buf) {
+ public void testSubSequence() {
try {
buf.subSequence(-1, buf.length());
fail("Should throw Exception"); //$NON-NLS-1$
@@ -756,17 +669,8 @@
}
}
- public static void testPutString(CharBuffer buf) {
+ public void testPutString() {
String str = " ";
- if (buf.isReadOnly()) {
- try {
- buf.put(str);
- fail("Should throw Exception"); //$NON-NLS-1$
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- return;
- }
buf.clear();
for (int i = 0; i < buf.capacity(); i++) {
@@ -782,21 +686,20 @@
} catch (BufferOverflowException e) {
// expected
}
+ try {
+ buf.put((String) null);
+ fail("Should throw Exception"); //$NON-NLS-1$
+ } catch (NullPointerException e) {
+ // expected
+ }
}
- public static void testPutStringintint(CharBuffer buf) {
+ public void testPutStringintint() {
buf.clear();
String str = String.valueOf(new char[buf.capacity()]);
- if (buf.isReadOnly()) {
- try {
- buf.put(str, 0, str.length());
- fail("Should throw Exception"); //$NON-NLS-1$
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- return;
- }
+ // Throw a BufferOverflowException and no character is transfered to
+ // CharBuffer
try {
buf.put(String.valueOf(new char[buf.capacity() + 1]), 0, buf
.capacity() + 1);
@@ -804,7 +707,14 @@
} catch (BufferOverflowException e) {
// expected
}
- assertEquals(buf.position(), 0);
+ try {
+ buf.put((String) null, 0, buf.capacity() + 1);
+ fail("Should throw Exception"); //$NON-NLS-1$
+ } catch (NullPointerException e) {
+ // expected
+ }
+ assertEquals(0, buf.position());
+
buf.clear();
try {
buf.put(str, -1, str.length());
@@ -818,6 +728,12 @@
} catch (IndexOutOfBoundsException e) {
// expected
}
+ try {
+ buf.put((String) null, -1, 0);
+ fail("Should throw Exception"); //$NON-NLS-1$
+ } catch (NullPointerException e) {
+ // expected
+ }
buf.put(str, str.length(), str.length());
assertEquals(buf.position(), 0);
try {
@@ -844,48 +760,48 @@
assertSame(ret, buf);
}
- private static void loadTestData1(char array[], int offset, int length) {
+ void loadTestData1(char array[], int offset, int length) {
for (int i = 0; i < length; i++) {
array[offset + i] = (char) i;
}
}
- private static void loadTestData2(char array[], int offset, int length) {
+ void loadTestData2(char array[], int offset, int length) {
for (int i = 0; i < length; i++) {
array[offset + i] = (char) (length - i);
}
}
- private static void loadTestData1(CharBuffer buf) {
+ void loadTestData1(CharBuffer buf) {
buf.clear();
for (int i = 0; i < buf.capacity(); i++) {
buf.put(i, (char) i);
}
}
- private static void loadTestData2(CharBuffer buf) {
+ void loadTestData2(CharBuffer buf) {
buf.clear();
for (int i = 0; i < buf.capacity(); i++) {
buf.put(i, (char) (buf.capacity() - i));
}
}
- private static void assertContentEquals(CharBuffer buf, char array[],
- int offset, int length) {
+ private void assertContentEquals(CharBuffer buf, char array[], int offset,
+ int length) {
for (int i = 0; i < length; i++) {
assertEquals(buf.get(i), array[offset + i]);
}
}
- private static void assertContentEquals(CharBuffer buf, CharBuffer other) {
+ private void assertContentEquals(CharBuffer buf, CharBuffer other) {
assertEquals(buf.capacity(), other.capacity());
for (int i = 0; i < buf.capacity(); i++) {
assertEquals(buf.get(i), other.get(i));
}
}
- private static void assertContentLikeTestData1(CharBuffer buf,
- int startIndex, char startValue, int length) {
+ private void assertContentLikeTestData1(CharBuffer buf, int startIndex,
+ char startValue, int length) {
char value = startValue;
for (int i = 0; i < length; i++) {
assertEquals(buf.get(startIndex + i), value);
@@ -893,163 +809,32 @@
}
}
- public void testAllocatedCharBuffer() {
- try {
- CharBuffer.allocate(-1);
- fail("Should throw Exception"); //$NON-NLS-1$
- } catch (IllegalArgumentException e) {
- // expected
- }
- CharBuffer buf = CharBuffer.allocate(16);
- testCharBufferInstanceThoroughly(buf);
- }
-
- public void testWrappedCharBuffer() {
- CharBuffer buf = CharBuffer.wrap(new char[16]);
- testCharBufferInstanceThoroughly(buf);
- }
-
- public void testWrappedCharBuffer2() {
- char array[] = new char[20];
- try {
- CharBuffer.wrap(array, -1, 0);
- fail("Should throw Exception"); //$NON-NLS-1$
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- CharBuffer.wrap(array, 21, 0);
- fail("Should throw Exception"); //$NON-NLS-1$
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- CharBuffer.wrap(array, 0, -1);
- fail("Should throw Exception"); //$NON-NLS-1$
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- CharBuffer.wrap(array, 0, 21);
- fail("Should throw Exception"); //$NON-NLS-1$
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
-
- CharBuffer buf = CharBuffer.wrap(array, 2, 16);
- assertEquals(buf.position(), 2);
- assertEquals(buf.limit(), 18);
- assertEquals(buf.capacity(), 20);
- testCharBufferInstanceThoroughly(buf);
- }
-
- public void testWrappedCharSequence() {
- CharBuffer buf = CharBuffer.wrap("123456789abcdef12345");
- testCharBufferInstanceThoroughly(buf);
- }
-
- public void testWrappedCharSequence2() {
- String str = "123456789abcdef12345";
- try {
- CharBuffer.wrap(str, -1, 0);
- fail("Should throw Exception"); //$NON-NLS-1$
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- CharBuffer.wrap(str, 21, 21);
- fail("Should throw Exception"); //$NON-NLS-1$
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- CharBuffer.wrap(str, 2, 1);
- fail("Should throw Exception"); //$NON-NLS-1$
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- CharBuffer.wrap(str, 0, 21);
- fail("Should throw Exception"); //$NON-NLS-1$
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
-
- CharBuffer buf = CharBuffer.wrap(str, 2, 16);
- assertEquals(buf.position(), 2);
- assertEquals(buf.limit(), 16);
- assertEquals(buf.capacity(), 20);
- testCharBufferInstanceThoroughly(buf);
- }
-
- public void testByteBufferAsCharBuffer() {
- CharBuffer buf = ByteBuffer.allocate(160).asCharBuffer();
- testCharBufferInstanceThoroughly(buf);
+ public void testAppendSelf() throws Exception {
+ CharBuffer cb = CharBuffer.allocate(10);
+ CharBuffer cb2 = cb.duplicate();
+ cb.append(cb);
+ assertEquals(10, cb.position());
+ cb.clear();
+ assertEquals(cb2, cb);
+
+ cb.put("abc");
+ cb2 = cb.duplicate();
+ cb.append(cb);
+ assertEquals(10, cb.position());
+ cb.clear();
+ cb2.clear();
+ assertEquals(cb2, cb);
+
+ cb.put("edfg");
+ cb.clear();
+ cb2 = cb.duplicate();
+ cb.append(cb);
+ assertEquals(10, cb.position());
+ cb.clear();
+ cb2.clear();
+ assertEquals(cb, cb2);
}
- private void testCharBufferInstanceThoroughly(CharBuffer buf) {
- assertTrue(buf.capacity() > 15);
- buf.clear();
- if (!buf.isReadOnly()) {
- loadTestData1(buf);
- }
-
- buf.limit(15).position(1);
- testCharBufferInstance(buf);
- testCharBufferInstance(buf.duplicate());
- testCharBufferInstance(buf.asReadOnlyBuffer());
- buf.limit(15).position(1);
- testCharBufferInstance(buf.slice());
-
- CharBuffer duplicate = buf.duplicate();
- duplicate.limit(15).position(1);
- testCharBufferInstance(duplicate.duplicate());
- testCharBufferInstance(duplicate.asReadOnlyBuffer());
- duplicate.limit(15).position(1);
- testCharBufferInstance(duplicate.slice());
-
- CharBuffer readonly = buf.asReadOnlyBuffer();
- readonly.limit(15).position(1);
- testCharBufferInstance(readonly.duplicate());
- testCharBufferInstance(readonly.asReadOnlyBuffer());
- readonly.limit(15).position(1);
- testCharBufferInstance(readonly.slice());
-
- buf.limit(15).position(1);
- CharBuffer slice = buf.slice();
- slice.limit(10).position(1);
- testCharBufferInstance(slice.duplicate());
- testCharBufferInstance(slice.asReadOnlyBuffer());
- slice.limit(10).position(1);
- testCharBufferInstance(slice.slice());
- }
-
- public void testAppendSelf() throws Exception{
- CharBuffer cb = CharBuffer.allocate(10);
- CharBuffer cb2 = cb.duplicate();
- cb.append(cb);
- assertEquals(10, cb.position());
- cb.clear();
- assertEquals(cb2, cb);
-
- cb.put("abc");
- cb2 = cb.duplicate();
- cb.append(cb);
- assertEquals(10, cb.position());
- cb.clear();
- cb2.clear();
- assertEquals(cb2, cb);
-
- cb.put("edfg");
- cb.clear();
- cb2 = cb.duplicate();
- cb.append(cb);
- assertEquals(10, cb.position());
- cb.clear();
- cb2.clear();
- assertEquals(cb, cb2);
- }
-
public void testAppendOverFlow() throws IOException {
CharBuffer cb = CharBuffer.allocate(1);
CharSequence cs = "String";
@@ -1161,17 +946,16 @@
}
public void testReadCharBuffer() throws IOException {
- // happy path
CharBuffer source = CharBuffer.wrap("String");
CharBuffer target = CharBuffer.allocate(10);
assertEquals(6, source.read(target));
assertEquals("String", target.flip().toString());
// return -1 when nothing to read
assertEquals(-1, source.read(target));
- // npe
+ // NullPointerException
try {
assertEquals(-1, source.read(null));
- fail("should throw NPE.");
+ fail("should throw NullPointerException.");
} catch (NullPointerException ex) {
// expected;
}
@@ -1199,13 +983,29 @@
assertEquals("S", target.flip().toString());
assertEquals(1, source.position());
}
-
- public void testReadSelf() throws Exception{
- CharBuffer source = CharBuffer.wrap("abuffer");
- try {
- source.read(source);
- fail("should throw IAE.");
- } catch (IllegalArgumentException e) {
- }
- }
+
+ public void testReadSelf() throws Exception {
+ CharBuffer source = CharBuffer.wrap("abuffer");
+ try {
+ source.read(source);
+ fail("should throw IAE.");
+ } catch (IllegalArgumentException e) {
+ }
+ }
+
+ public void testIsDirect() {
+ assertFalse(buf.isDirect());
+ }
+
+ public void testHasArray() {
+ assertTrue(buf.hasArray());
+ }
+
+ public void testOrder() {
+ assertEquals(ByteOrder.nativeOrder(), buf.order());
+ }
+
+ public void testIsReadOnly() {
+ assertFalse(buf.isReadOnly());
+ }
}
Added: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/DirectCharBufferTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/DirectCharBufferTest.java?rev=418214&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/DirectCharBufferTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/DirectCharBufferTest.java Fri Jun 30 02:35:29 2006
@@ -0,0 +1,60 @@
+/* Copyright 2006 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.harmony.tests.java.nio;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+
+public class DirectCharBufferTest extends CharBufferTest {
+
+ public void setUp(){
+ buf = ByteBuffer.allocateDirect(BUFFER_LENGTH*2).asCharBuffer();
+ super.loadTestData1(buf);
+ baseBuf = buf;
+ }
+
+ public void tearDown(){
+ buf = null;
+ baseBuf = null;
+ }
+
+ public void testHasArray() {
+ assertFalse(buf.hasArray());
+ }
+
+ public void testArray() {
+ try {
+ buf.array();
+ fail("Should throw UnsupportedOperationException"); //$NON-NLS-1$
+ } catch (UnsupportedOperationException e) {
+ }
+ }
+
+ public void testArrayOffset() {
+ try {
+ buf.arrayOffset();
+ fail("Should throw UnsupportedOperationException"); //$NON-NLS-1$
+ } catch (UnsupportedOperationException e) {
+ }
+ }
+
+ public void testIsDirect() {
+ assertTrue(buf.isDirect());
+ }
+
+ public void testOrder() {
+ assertEquals(ByteOrder.BIG_ENDIAN, buf.order());
+ }
+}
Propchange: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/DirectCharBufferTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/HeapCharBufferTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/HeapCharBufferTest.java?rev=418214&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/HeapCharBufferTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/HeapCharBufferTest.java Fri Jun 30 02:35:29 2006
@@ -0,0 +1,43 @@
+/* Copyright 2006 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.harmony.tests.java.nio;
+
+import java.nio.CharBuffer;
+
+
+public class HeapCharBufferTest extends CharBufferTest {
+ protected void setUp() throws Exception {
+ super.setUp();
+ buf = CharBuffer.allocate(BUFFER_LENGTH);
+ loadTestData1(buf);
+ baseBuf = buf;
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ buf = null;
+ baseBuf = null;
+ }
+
+ public void testAllocatedCharBuffer_IllegalArg() {
+ try {
+ CharBuffer.allocate(-1);
+ fail("Should throw Exception"); //$NON-NLS-1$
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+ }
+}
Propchange: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/HeapCharBufferTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/ReadOnlyCharBufferTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/ReadOnlyCharBufferTest.java?rev=418214&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/ReadOnlyCharBufferTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/ReadOnlyCharBufferTest.java Fri Jun 30 02:35:29 2006
@@ -0,0 +1,208 @@
+/* Copyright 2006 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.harmony.tests.java.nio;
+
+import java.nio.CharBuffer;
+import java.nio.ReadOnlyBufferException;
+
+public class ReadOnlyCharBufferTest extends CharBufferTest {
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ loadTestData1(buf);
+ buf = buf.asReadOnlyBuffer();
+ baseBuf = buf;
+ }
+
+ protected void tearDown() throws Exception {
+ buf = null;
+ baseBuf = null;
+ super.tearDown();
+ }
+
+ public void testIsReadOnly() {
+ assertTrue(buf.isReadOnly());
+ }
+
+ public void testHasArray() {
+ assertFalse(buf.hasArray());
+ }
+
+ public void testArray() {
+ try {
+ buf.array();
+ fail("Should throw ReadOnlyBufferException"); //$NON-NLS-1$
+ } catch (ReadOnlyBufferException e) {
+ }
+ }
+
+ public void testHashCode() {
+ CharBuffer duplicate = buf.duplicate();
+ assertEquals(buf.hashCode(), duplicate.hashCode());
+ }
+
+ public void testArrayOffset() {
+ try {
+ buf.arrayOffset();
+ fail("Should throw Exception"); //$NON-NLS-1$
+ } catch (UnsupportedOperationException e) {
+ }
+ }
+
+ public void testCompact() {
+ try {
+ buf.compact();
+ fail("Should throw Exception"); //$NON-NLS-1$
+ } catch (ReadOnlyBufferException e) {
+ // expected
+ }
+ }
+
+ public void testPutchar() {
+ try {
+ buf.put((char) 0);
+ fail("Should throw Exception"); //$NON-NLS-1$
+ } catch (ReadOnlyBufferException e) {
+ // expected
+ }
+ }
+
+ public void testPutcharArray() {
+ char array[] = new char[1];
+ try {
+ buf.put(array);
+ fail("Should throw Exception"); //$NON-NLS-1$
+ } catch (ReadOnlyBufferException e) {
+ // expected
+ }
+ try {
+ buf.put((char[]) null);
+ fail("Should throw Exception"); //$NON-NLS-1$
+ } catch (NullPointerException e) {
+ // expected
+ }
+ }
+
+ public void testPutcharArrayintint() {
+ char array[] = new char[1];
+ try {
+ buf.put(array, 0, array.length);
+ fail("Should throw ReadOnlyBufferException"); //$NON-NLS-1$
+ } catch (ReadOnlyBufferException e) {
+ // expected
+ }
+ try {
+ buf.put((char[]) null, 0, 1);
+ fail("Should throw ReadOnlyBufferException"); //$NON-NLS-1$
+ } catch (ReadOnlyBufferException e) {
+ // expected
+ }
+ try {
+ buf.put(new char[buf.capacity() + 1], 0, buf.capacity() + 1);
+ fail("Should throw ReadOnlyBufferException"); //$NON-NLS-1$
+ } catch (ReadOnlyBufferException e) {
+ // expected
+ }
+ try {
+ buf.put(array, -1, array.length);
+ fail("Should throw ReadOnlyBufferException"); //$NON-NLS-1$
+ } catch (ReadOnlyBufferException e) {
+ // expected
+ }
+ }
+
+ public void testPutCharBuffer() {
+ CharBuffer other = CharBuffer.allocate(1);
+ try {
+ buf.put(other);
+ fail("Should throw ReadOnlyBufferException"); //$NON-NLS-1$
+ } catch (ReadOnlyBufferException e) {
+ // expected
+ }
+ try {
+ buf.put((CharBuffer) null);
+ fail("Should throw ReadOnlyBufferException"); //$NON-NLS-1$
+ } catch (ReadOnlyBufferException e) {
+ // expected
+ }
+ try {
+ buf.put(buf);
+ fail("Should throw ReadOnlyBufferException"); //$NON-NLS-1$
+ } catch (ReadOnlyBufferException e) {
+ // expected
+ }
+ }
+
+ public void testPutintchar() {
+ try {
+ buf.put(0, (char) 0);
+ fail("Should throw ReadOnlyBufferException"); //$NON-NLS-1$
+ } catch (ReadOnlyBufferException e) {
+ // expected
+ }
+ try {
+ buf.put(-1, (char) 0);
+ fail("Should throw ReadOnlyBufferException"); //$NON-NLS-1$
+ } catch (ReadOnlyBufferException e) {
+ // expected
+ }
+ }
+
+ public void testPutStringintint() {
+ buf.clear();
+ String str = String.valueOf(new char[buf.capacity()]);
+ try {
+ buf.put(str, 0, str.length());
+ fail("Should throw Exception"); //$NON-NLS-1$
+ } catch (ReadOnlyBufferException e) {
+ // expected
+ }
+ try {
+ buf.put((String) null, 0, 0);
+ fail("Should throw Exception"); //$NON-NLS-1$
+ } catch (NullPointerException e) {
+ // expected
+ }
+ try {
+ buf.put(str, -1, str.length());
+ fail("Should throw Exception"); //$NON-NLS-1$
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+ String longStr = String.valueOf(new char[buf.capacity()+1]);
+ try {
+ buf.put(longStr, 0, longStr.length());
+ fail("Should throw Exception"); //$NON-NLS-1$
+ } catch (ReadOnlyBufferException e) {
+ // expected
+ }
+ }
+
+ public void testPutString() {
+ String str = " ";
+ try {
+ buf.put(str);
+ fail("Should throw Exception"); //$NON-NLS-1$
+ } catch (ReadOnlyBufferException e) {
+ // expected
+ }
+ try {
+ buf.put((String)null);
+ fail("Should throw Exception"); //$NON-NLS-1$
+ } catch (NullPointerException e) {
+ // expected
+ }
+ }
+}
Propchange: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/ReadOnlyCharBufferTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/ReadOnlyHeapCharBufferTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/ReadOnlyHeapCharBufferTest.java?rev=418214&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/ReadOnlyHeapCharBufferTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/ReadOnlyHeapCharBufferTest.java Fri Jun 30 02:35:29 2006
@@ -0,0 +1,34 @@
+/* Copyright 2006 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.harmony.tests.java.nio;
+
+import java.nio.CharBuffer;
+
+
+public class ReadOnlyHeapCharBufferTest extends ReadOnlyCharBufferTest {
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ buf = CharBuffer.allocate(BUFFER_LENGTH);
+ super.loadTestData1(buf);
+ buf = buf.asReadOnlyBuffer();
+ baseBuf = buf;
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+}
Propchange: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/ReadOnlyHeapCharBufferTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/ReadOnlyWrappedCharBufferTest1.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/ReadOnlyWrappedCharBufferTest1.java?rev=418214&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/ReadOnlyWrappedCharBufferTest1.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/ReadOnlyWrappedCharBufferTest1.java Fri Jun 30 02:35:29 2006
@@ -0,0 +1,33 @@
+/* Copyright 2006 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.harmony.tests.java.nio;
+
+import java.nio.CharBuffer;
+
+public class ReadOnlyWrappedCharBufferTest1 extends ReadOnlyCharBufferTest {
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ buf = CharBuffer.wrap(new char[BUFFER_LENGTH]);
+ super.loadTestData1(buf);
+ buf = buf.asReadOnlyBuffer();
+ baseBuf = buf;
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+}
Propchange: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/ReadOnlyWrappedCharBufferTest1.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/WrappedCharBufferTest1.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/WrappedCharBufferTest1.java?rev=418214&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/WrappedCharBufferTest1.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/WrappedCharBufferTest1.java Fri Jun 30 02:35:29 2006
@@ -0,0 +1,66 @@
+/* Copyright 2006 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.harmony.tests.java.nio;
+
+import java.nio.CharBuffer;
+
+public class WrappedCharBufferTest1 extends CharBufferTest {
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ buf = CharBuffer.wrap(new char[BUFFER_LENGTH]);
+ loadTestData1(buf);
+ baseBuf = buf;
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ baseBuf = null;
+ buf = null;
+ }
+
+ /**
+ * @tests java.nio.CharBuffer#allocate(char[],int,int)
+ *
+ */
+ public void testWrappedCharBuffer_IllegalArg() {
+ char array[] = new char[BUFFER_LENGTH];
+ try {
+ CharBuffer.wrap(array, -1, 0);
+ fail("Should throw Exception"); //$NON-NLS-1$
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+ try {
+ CharBuffer.wrap(array, BUFFER_LENGTH + 1, 0);
+ fail("Should throw Exception"); //$NON-NLS-1$
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+ try {
+ CharBuffer.wrap(array, 0, -1);
+ fail("Should throw Exception"); //$NON-NLS-1$
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+ try {
+ CharBuffer.wrap(array, 0, BUFFER_LENGTH + 1);
+ fail("Should throw Exception"); //$NON-NLS-1$
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+ }
+}
Propchange: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/WrappedCharBufferTest1.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/WrappedCharBufferTest2.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/WrappedCharBufferTest2.java?rev=418214&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/WrappedCharBufferTest2.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/WrappedCharBufferTest2.java Fri Jun 30 02:35:29 2006
@@ -0,0 +1,122 @@
+/* Copyright 2006 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.harmony.tests.java.nio;
+
+import java.nio.BufferOverflowException;
+import java.nio.CharBuffer;
+import java.nio.ReadOnlyBufferException;
+
+public class WrappedCharBufferTest2 extends ReadOnlyCharBufferTest {
+ protected static final String TEST_STRING = "123456789abcdef12345";
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ buf = CharBuffer.wrap(TEST_STRING);
+ baseBuf = buf;
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ baseBuf = null;
+ buf = null;
+ }
+
+ public void testWrappedCharSequence_IllegalArg() {
+ String str = TEST_STRING;
+ try {
+ CharBuffer.wrap(str, -1, 0);
+ fail("Should throw Exception"); //$NON-NLS-1$
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+ try {
+ CharBuffer.wrap(str, 21, 21);
+ fail("Should throw Exception"); //$NON-NLS-1$
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+ try {
+ CharBuffer.wrap(str, 2, 1);
+ fail("Should throw Exception"); //$NON-NLS-1$
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+ try {
+ CharBuffer.wrap(str, 0, 21);
+ fail("Should throw Exception"); //$NON-NLS-1$
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+ }
+
+ public void testArray() {
+ try {
+ buf.array();
+ fail("Should throw UnsupportedOperationException"); //$NON-NLS-1$
+ } catch (UnsupportedOperationException e) {
+ }
+ }
+
+ public void testPutcharArrayintint() {
+ char array[] = new char[1];
+ try {
+ buf.put(array, 0, array.length);
+ fail("Should throw ReadOnlyBufferException"); //$NON-NLS-1$
+ } catch (ReadOnlyBufferException e) {
+ // expected
+ }
+ try {
+ buf.put((char[]) null, 0, 1);
+ fail("Should throw NullPointerException"); //$NON-NLS-1$
+ } catch (NullPointerException e) {
+ // expected
+ }
+ try {
+ buf.put(new char[buf.capacity() + 1], 0, buf.capacity() + 1);
+ fail("Should throw BufferOverflowException"); //$NON-NLS-1$
+ } catch (BufferOverflowException e) {
+ // expected
+ }
+ try {
+ buf.put(array, -1, array.length);
+ fail("Should throw IndexOutOfBoundsException"); //$NON-NLS-1$
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+ }
+
+ public void testPutCharBuffer() {
+ CharBuffer other = CharBuffer.allocate(1);
+ try {
+ buf.put(other);
+ fail("Should throw ReadOnlyBufferException"); //$NON-NLS-1$
+ } catch (ReadOnlyBufferException e) {
+ // expected
+ }
+ try {
+ buf.put((CharBuffer) null);
+ fail("Should throw NullPointerException"); //$NON-NLS-1$
+ } catch (NullPointerException e) {
+ // expected
+ }
+ try {
+ buf.put(buf);
+ fail("Should throw IllegalArgumentException"); //$NON-NLS-1$
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+ }
+}
Propchange: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/WrappedCharBufferTest2.java
------------------------------------------------------------------------------
svn:eol-style = native