harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From py...@apache.org
Subject svn commit: r424907 - in /incubator/harmony/enhanced/classlib/trunk/modules/nio/src: main/java/java/nio/ test/java/common/org/apache/harmony/tests/java/nio/
Date Mon, 24 Jul 2006 05:35:09 GMT
Author: pyang
Date: Sun Jul 23 22:35:08 2006
New Revision: 424907

URL: http://svn.apache.org/viewvc?rev=424907&view=rev
Log:
Fix for HARMONY-862 ([classlib][nio]refactory nio buffer test step 7 - ShortBuffer tests)

Added:
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/DirectShortBufferTest.java
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/HeapShortBufferTest.java
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/ReadOnlyHeapShortBufferTest.java
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/ReadOnlyShortBufferTest.java
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/ReadOnlyWrappedShortBufferTest.java
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/WrappedShortBufferTest.java
Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadOnlyShortArrayBuffer.java
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadWriteShortArrayBuffer.java
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ShortArrayBuffer.java
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ShortBuffer.java
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/AllTests.java
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/ShortBufferTest.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadOnlyShortArrayBuffer.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadOnlyShortArrayBuffer.java?rev=424907&r1=424906&r2=424907&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadOnlyShortArrayBuffer.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadOnlyShortArrayBuffer.java Sun Jul 23 22:35:08 2006
@@ -1,4 +1,4 @@
-/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+/* Copyright 2004, 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.
@@ -71,6 +71,10 @@
 	protected boolean protectedHasArray() {
 		return false;
 	}
+    
+    public ShortBuffer put(ShortBuffer buf) {
+        throw new ReadOnlyBufferException();
+    }
 
 	public ShortBuffer put(short c) {
 		throw new ReadOnlyBufferException();

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadWriteShortArrayBuffer.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadWriteShortArrayBuffer.java?rev=424907&r1=424906&r2=424907&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadWriteShortArrayBuffer.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadWriteShortArrayBuffer.java Sun Jul 23 22:35:08 2006
@@ -1,4 +1,4 @@
-/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+/* Copyright 2004, 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.
@@ -104,7 +104,8 @@
 	}
 
     public ShortBuffer put(short[] src, int off, int len) {
-        if (off < 0 || len < 0 || (long)off + (long)len > src.length) {
+        int length = src.length;
+        if (off < 0 || len < 0 || (long)off + (long)len > length) {
             throw new IndexOutOfBoundsException();
         }
         if (len > remaining()) {

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ShortArrayBuffer.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ShortArrayBuffer.java?rev=424907&r1=424906&r2=424907&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ShortArrayBuffer.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ShortArrayBuffer.java Sun Jul 23 22:35:08 2006
@@ -1,4 +1,4 @@
-/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+/* Copyright 2004, 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.
@@ -64,7 +64,8 @@
 	}
 
     public final ShortBuffer get(short[] dest, int off, int len) {
-        if (off < 0 || len < 0 || off + len > dest.length) {
+        int length = dest.length;
+        if (off < 0 || len < 0 || off + len > length) {
             throw new IndexOutOfBoundsException();
         }
         if (len > remaining()) {

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ShortBuffer.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ShortBuffer.java?rev=424907&r1=424906&r2=424907&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ShortBuffer.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ShortBuffer.java Sun Jul 23 22:35:08 2006
@@ -1,4 +1,4 @@
-/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+/* Copyright 2004, 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.
@@ -306,7 +306,8 @@
 	 *                <code>remaining()</code>
 	 */
 	public ShortBuffer get(short[] dest, int off, int len) {
-        if (off < 0 || len < 0 || (long)off + (long)len > dest.length) {
+        int length = dest.length;
+        if (off < 0 || len < 0 || (long)off + (long)len > length) {
             throw new IndexOutOfBoundsException();
         }
 		if (len > remaining()) {
@@ -467,7 +468,8 @@
 	 *                If no changes may be made to the contents of this buffer
 	 */
 	public ShortBuffer put(short[] src, int off, int len) {
-        if (off < 0 || len < 0 || (long)off + (long)len > src.length) {
+        int length = src.length;
+        if (off < 0 || len < 0 || (long)off + (long)len > length) {
             throw new IndexOutOfBoundsException();
         }
         

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/AllTests.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/AllTests.java?rev=424907&r1=424906&r2=424907&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/AllTests.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/AllTests.java Sun Jul 23 22:35:08 2006
@@ -31,18 +31,25 @@
     public static Test suite() {
         TestSuite suite = new TestSuite("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(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);
@@ -51,22 +58,27 @@
         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(BufferTest.class);
         suite.addTestSuite(DirectFloatBufferTest.class);
-        suite.addTestSuite(ShortBufferTest.class);
         suite.addTestSuite(SliceWrappedByteBufferTest.class);
         suite.addTestSuite(DirectCharBufferTest.class);
         suite.addTestSuite(SliceDirectByteBufferTest.class);
+        suite.addTestSuite(ReadOnlyHeapLongBufferTest.class);
         suite.addTestSuite(DirectIntBufferTest.class);
         suite.addTestSuite(HeapByteBufferTest.class);
         suite.addTestSuite(ReadOnlyWrappedDoubleBufferTest.class);
         suite.addTestSuite(DuplicateHeapByteBufferTest.class);
+        suite.addTestSuite(HeapShortBufferTest.class);
         suite.addTestSuite(InvalidMarkExceptionTest.class);
         suite.addTestSuite(DirectDoubleBufferTest.class);
         suite.addTestSuite(ReadOnlyHeapByteBufferTest.class);
@@ -77,8 +89,8 @@
         suite.addTestSuite(IntBufferTest.class);
         suite.addTestSuite(ReadOnlyDoubleBufferTest.class);
         suite.addTestSuite(ReadOnlyHeapFloatBufferTest.class);
-        suite.addTestSuite(BufferUnderflowExceptionTest.class);
         suite.addTestSuite(WrappedByteBufferTest.class);
+        suite.addTestSuite(BufferUnderflowExceptionTest.class);
         suite.addTestSuite(DuplicateDirectByteBufferTest.class);
         suite.addTestSuite(WrappedIntBufferTest.class);
         suite.addTestSuite(HeapCharBufferTest.class);

Added: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/DirectShortBufferTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/DirectShortBufferTest.java?rev=424907&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/DirectShortBufferTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/DirectShortBufferTest.java Sun Jul 23 22:35:08 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 DirectShortBufferTest extends ShortBufferTest {
+    public void setUp(){
+        buf = ByteBuffer.allocateDirect(BUFFER_LENGTH*2).asShortBuffer();
+        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) {
+            //expected
+        }
+    }
+
+    public void testIsDirect() {
+        assertTrue(buf.isDirect());
+    }
+    
+    public void testOrder() {
+        assertEquals(ByteOrder.BIG_ENDIAN, buf.order());
+    }
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/HeapShortBufferTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/HeapShortBufferTest.java?rev=424907&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/HeapShortBufferTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/HeapShortBufferTest.java Sun Jul 23 22:35:08 2006
@@ -0,0 +1,41 @@
+/* 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.ShortBuffer;
+
+public class HeapShortBufferTest extends ShortBufferTest {
+    protected void setUp() throws Exception {
+        super.setUp();
+        buf = ShortBuffer.allocate(BUFFER_LENGTH); 
+        loadTestData1(buf);
+        baseBuf = buf;
+    }
+
+    protected void tearDown() throws Exception {
+        super.tearDown();
+        buf = null;
+        baseBuf = null;
+    }
+    
+    public void testAllocatedShortBuffer_IllegalArg() {
+        try {
+            ShortBuffer.allocate(-1);
+            fail("Should throw Exception"); //$NON-NLS-1$
+        } catch (IllegalArgumentException e) {
+            // expected
+        }
+    }
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/ReadOnlyHeapShortBufferTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/ReadOnlyHeapShortBufferTest.java?rev=424907&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/ReadOnlyHeapShortBufferTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/ReadOnlyHeapShortBufferTest.java Sun Jul 23 22:35:08 2006
@@ -0,0 +1,31 @@
+/* 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.ShortBuffer;
+
+public class ReadOnlyHeapShortBufferTest extends ReadOnlyShortBufferTest {
+    protected void setUp() throws Exception {
+        super.setUp();
+        buf = ShortBuffer.allocate(BUFFER_LENGTH);
+        super.loadTestData1(buf);
+        buf = buf.asReadOnlyBuffer();
+        baseBuf = buf;
+    }
+
+    protected void tearDown() throws Exception {
+        super.tearDown();
+    }
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/ReadOnlyShortBufferTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/ReadOnlyShortBufferTest.java?rev=424907&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/ReadOnlyShortBufferTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/ReadOnlyShortBufferTest.java Sun Jul 23 22:35:08 2006
@@ -0,0 +1,160 @@
+/* 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.ReadOnlyBufferException;
+import java.nio.ShortBuffer;
+
+public class ReadOnlyShortBufferTest extends ShortBufferTest {
+    protected void setUp() throws Exception {
+        super.setUp();
+        buf = buf.asReadOnlyBuffer();
+        baseBuf = buf;
+    }
+
+    protected void tearDown() throws Exception {
+        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) {
+            //expected
+        }
+    }
+
+    public void testHashCode() {
+        ShortBuffer duplicate = buf.duplicate();
+        assertEquals(buf.hashCode(), duplicate.hashCode());
+    }
+
+    public void testArrayOffset() {
+        try {
+            buf.arrayOffset();
+            fail("Should throw Exception"); //$NON-NLS-1$
+        } catch (UnsupportedOperationException e) {
+            //expected
+        }
+    }
+
+    public void testCompact() {
+        try {
+            buf.compact();
+            fail("Should throw Exception"); //$NON-NLS-1$
+        } catch (ReadOnlyBufferException e) {
+            // expected
+        }
+    }
+
+    public void testPutshort() {
+        try {
+            buf.put((short)0);
+            fail("Should throw Exception"); //$NON-NLS-1$
+        } catch (ReadOnlyBufferException e) {
+            // expected
+        }
+    }
+
+    public void testPutshortArray() {
+        short array[] = new short[1];
+        try {
+            buf.put(array);
+            fail("Should throw Exception"); //$NON-NLS-1$
+        } catch (ReadOnlyBufferException e) {
+            // expected
+        }
+        try {
+            buf.put((short[]) null);
+            fail("Should throw Exception"); //$NON-NLS-1$
+        } catch (NullPointerException e) {
+            // expected
+        }
+    }
+
+    public void testPutshortArrayintint() {
+        short array[] = new short[1];
+        try {
+            buf.put(array, 0, array.length);
+            fail("Should throw ReadOnlyBufferException"); //$NON-NLS-1$
+        } catch (ReadOnlyBufferException e) {
+            // expected
+        }
+        try {
+            buf.put((short[]) null, 0, 1);
+            fail("Should throw ReadOnlyBufferException"); //$NON-NLS-1$
+        } catch (ReadOnlyBufferException e) {
+            // expected
+        }
+        try {
+            buf.put(new short[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 testPutShortBuffer() {
+        ShortBuffer other = ShortBuffer.allocate(1);
+        try {
+            buf.put(other);
+            fail("Should throw ReadOnlyBufferException"); //$NON-NLS-1$
+        } catch (ReadOnlyBufferException e) {
+            // expected
+        }
+        try {
+            buf.put((ShortBuffer) 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 testPutintshort() {
+        try {
+            buf.put(0, (short) 0);
+            fail("Should throw ReadOnlyBufferException"); //$NON-NLS-1$
+        } catch (ReadOnlyBufferException e) {
+            // expected
+        }
+        try {
+            buf.put(-1, (short) 0);
+            fail("Should throw ReadOnlyBufferException"); //$NON-NLS-1$
+        } catch (ReadOnlyBufferException e) {
+            // expected
+        }
+    }
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/ReadOnlyWrappedShortBufferTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/ReadOnlyWrappedShortBufferTest.java?rev=424907&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/ReadOnlyWrappedShortBufferTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/ReadOnlyWrappedShortBufferTest.java Sun Jul 23 22:35:08 2006
@@ -0,0 +1,31 @@
+/* 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.ShortBuffer;
+
+public class ReadOnlyWrappedShortBufferTest extends ReadOnlyShortBufferTest {
+    protected void setUp() throws Exception {
+        super.setUp();
+        buf = ShortBuffer.wrap(new short[BUFFER_LENGTH]);
+        super.loadTestData1(buf);
+        buf = buf.asReadOnlyBuffer();
+        baseBuf = buf;
+    }
+
+    protected void tearDown() throws Exception {
+        super.tearDown();
+    }
+}

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/ShortBufferTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/ShortBufferTest.java?rev=424907&r1=424906&r2=424907&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/ShortBufferTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/ShortBufferTest.java Sun Jul 23 22:35:08 2006
@@ -17,130 +17,68 @@
 
 import java.nio.BufferOverflowException;
 import java.nio.BufferUnderflowException;
-import java.nio.ByteBuffer;
 import java.nio.ByteOrder;
-import java.nio.ShortBuffer;
 import java.nio.InvalidMarkException;
-import java.nio.ReadOnlyBufferException;
-
-import junit.framework.TestCase;
+import java.nio.ShortBuffer;
 
 /**
  * Tests java.nio.ShortBuffer
  *
  */
-public class ShortBufferTest extends TestCase {
+public class ShortBufferTest extends AbstractBufferTest {
+    
+    protected static final int SMALL_TEST_LENGTH = 5;
+
+    protected static final int BUFFER_LENGTH = 20;
+
+    protected ShortBuffer buf;
+
+    protected void setUp() throws Exception {
+        buf = ShortBuffer.allocate(BUFFER_LENGTH);
+        loadTestData1(buf);
+        baseBuf = buf;
+    }
 
-    public static void main(String[] args) {
-        junit.textui.TestRunner.run(ShortBufferTest.class);
+    protected void tearDown() throws Exception {
+        buf = null;
+        baseBuf = null;
     }
 
-    public static void testShortBufferInstance(ShortBuffer buf) {
-        // test Buffer functions
-        BufferTest.testBufferInstance(buf);
-
-        // test ShortBuffer functions
-        testHashCode(buf);
-        testEquals(buf);
-        testToString(buf);
-        testSlice(buf);
-        testDuplicate(buf);
-        testAsReadOnlyBuffer(buf);
-        testGet(buf);
-        testPutshort(buf);
-        testGetint(buf);
-        testPutintshort(buf);
-        testGetshortArrayintint(buf);
-        testGetshortArray(buf);
-        testPutShortBuffer(buf);
-        testPutshortArrayintint(buf);
-        testPutshortArray(buf);
-        testHasArray(buf);
-        testArray(buf);
-        testArrayOffset(buf);
-        testCompact(buf);
-        testIsDirect(buf);
-        testCompareTo(buf);
-        testOrder(buf);
-    }
-
-    public static void testArray(ShortBuffer buf) {
-        if (buf.hasArray()) {
-            short array[] = buf.array();
-            assertContentEquals(buf, array, buf.arrayOffset(), buf.capacity());
+    public void testArray() {
+        short 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(ShortBuffer buf) {
-        if (buf.hasArray()) {
-            short array[] = buf.array();
-            assertContentEquals(buf, array, buf.arrayOffset(), buf.capacity());
+    public void testArrayOffset() {
+        short 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(ShortBuffer buf) {
+    public void testAsReadOnlyBuffer() {
         buf.clear();
         buf.mark();
         buf.position(buf.limit());
@@ -164,17 +102,7 @@
         assertEquals(buf.position(), 0);
     }
 
-    public static void testCompact(ShortBuffer buf) {
-        if (buf.isReadOnly()) {
-            try {
-                buf.compact();
-                fail("Should throw Exception"); //$NON-NLS-1$
-            } catch (ReadOnlyBufferException e) {
-                // expected
-            }
-            return;
-        }
-
+    public void testCompact() {
         // case: buffer is full
         buf.clear();
         buf.mark();
@@ -225,33 +153,30 @@
         }
     }
 
-    public static void testCompareTo(ShortBuffer buf) {
+    public void testCompareTo() {
         // compare to self
         assertEquals(0, buf.compareTo(buf));
 
         // normal cases
-        if (!buf.isReadOnly()) {
-            assertTrue(buf.capacity() > 5);
-            buf.clear();
-            ShortBuffer other = ShortBuffer.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() > 5);
+        buf.clear();
+        ShortBuffer other = ShortBuffer.allocate(buf.capacity());
+        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);
     }
 
-    public static void testDuplicate(ShortBuffer buf) {
+    public void testDuplicate() {
         buf.clear();
         buf.mark();
         buf.position(buf.limit());
@@ -283,7 +208,7 @@
         }
     }
 
-    public static void testEquals(ShortBuffer buf) {
+    public void testEquals() {
         // equal to self
         assertTrue(buf.equals(buf));
         ShortBuffer readonly = buf.asReadOnlyBuffer();
@@ -308,7 +233,7 @@
     /*
      * Class under test for short get()
      */
-    public static void testGet(ShortBuffer buf) {
+    public void testGet() {
         buf.clear();
         for (int i = 0; i < buf.capacity(); i++) {
             assertEquals(buf.position(), i);
@@ -325,7 +250,7 @@
     /*
      * Class under test for java.nio.ShortBuffer get(short[])
      */
-    public static void testGetshortArray(ShortBuffer buf) {
+    public void testGetshortArray() {
         short array[] = new short[1];
         buf.clear();
         for (int i = 0; i < buf.capacity(); i++) {
@@ -345,7 +270,7 @@
     /*
      * Class under test for java.nio.ShortBuffer get(short[], int, int)
      */
-    public static void testGetshortArrayintint(ShortBuffer buf) {
+    public void testGetshortArrayintint() {
         buf.clear();
         short array[] = new short[buf.capacity()];
 
@@ -394,7 +319,7 @@
     /*
      * Class under test for short get(int)
      */
-    public static void testGetint(ShortBuffer buf) {
+    public void testGetint() {
         buf.clear();
         for (int i = 0; i < buf.capacity(); i++) {
             assertEquals(buf.position(), i);
@@ -414,32 +339,11 @@
         }
     }
 
-    public static void testHasArray(ShortBuffer 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 void testHasArray() {
+        assertNotNull(buf.array());
     }
 
-    public static void testHashCode(ShortBuffer buf) {
+    public void testHashCode() {
         buf.clear();
         ShortBuffer readonly = buf.asReadOnlyBuffer();
         ShortBuffer duplicate = buf.duplicate();
@@ -450,32 +354,19 @@
         assertTrue(buf.hashCode() != duplicate.hashCode());
     }
 
-    public static void testIsDirect(ShortBuffer buf) {
-        buf.isDirect();
+    public void testIsDirect() {
+        assertFalse(buf.isDirect());
     }
 
-    public static void testOrder(ShortBuffer buf) {
+    public void testOrder() {
         buf.order();
-        if (buf.hasArray()) {
-            assertEquals(ByteOrder.nativeOrder(), buf.order());
-        }
+        assertEquals(ByteOrder.nativeOrder(), buf.order());
     }
 
     /*
      * Class under test for java.nio.ShortBuffer put(short)
      */
-    public static void testPutshort(ShortBuffer buf) {
-        if (buf.isReadOnly()) {
-            try {
-                buf.clear();
-                buf.put((short) 0);
-                fail("Should throw Exception"); //$NON-NLS-1$
-            } catch (ReadOnlyBufferException e) {
-                // expected
-            }
-            return;
-        }
-
+    public void testPutshort() {
         buf.clear();
         for (int i = 0; i < buf.capacity(); i++) {
             assertEquals(buf.position(), i);
@@ -494,18 +385,8 @@
     /*
      * Class under test for java.nio.ShortBuffer put(short[])
      */
-    public static void testPutshortArray(ShortBuffer buf) {
+    public void testPutshortArray() {
         short array[] = new short[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++) {
             assertEquals(buf.position(), i);
@@ -520,24 +401,21 @@
         } catch (BufferOverflowException e) {
             // expected
         }
+        try {
+            buf.position(buf.limit());
+            buf.put((short[])null);
+            fail("Should throw Exception"); //$NON-NLS-1$
+        } catch (NullPointerException e) {
+            // expected
+        }
     }
 
     /*
      * Class under test for java.nio.ShortBuffer put(short[], int, int)
      */
-    public static void testPutshortArrayintint(ShortBuffer buf) {
+    public void testPutshortArrayintint() {
         buf.clear();
         short array[] = new short[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(new short[buf.capacity() + 1], 0, buf.capacity() + 1);
             fail("Should throw Exception"); //$NON-NLS-1$
@@ -566,11 +444,29 @@
             // expected
         }
         try {
+            buf.put((short[])null, 0, -1);
+            fail("Should throw Exception"); //$NON-NLS-1$
+        } catch (NullPointerException e) {
+            // expected
+        }
+        try {
             buf.put(array, 2, array.length);
             fail("Should throw Exception"); //$NON-NLS-1$
         } catch (IndexOutOfBoundsException e) {
             // expected
         }
+        try {
+            buf.put(array, Integer.MAX_VALUE, 1);
+            fail("Should throw Exception"); //$NON-NLS-1$
+        } catch (IndexOutOfBoundsException e) {
+            // expected
+        }
+        try {
+            buf.put(array, 1, Integer.MAX_VALUE);
+            fail("Should throw Exception"); //$NON-NLS-1$
+        } catch (IndexOutOfBoundsException e) {
+            // expected
+        }
         assertEquals(buf.position(), 0);
 
         loadTestData2(array, 0, array.length);
@@ -583,19 +479,8 @@
     /*
      * Class under test for java.nio.ShortBuffer put(java.nio.ShortBuffer)
      */
-    public static void testPutShortBuffer(ShortBuffer buf) {
+    public void testPutShortBuffer() {
         ShortBuffer other = ShortBuffer.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(buf);
             fail("Should throw Exception"); //$NON-NLS-1$
@@ -608,6 +493,13 @@
         } catch (BufferOverflowException e) {
             // expected
         }
+        try {
+            buf.flip();
+            buf.put((ShortBuffer)null);
+            fail("Should throw Exception"); //$NON-NLS-1$
+        } catch (NullPointerException e) {
+            // expected
+        }
 
         loadTestData2(other);
         other.clear();
@@ -622,17 +514,7 @@
     /*
      * Class under test for java.nio.ShortBuffer put(int, short)
      */
-    public static void testPutintshort(ShortBuffer buf) {
-        if (buf.isReadOnly()) {
-            try {
-                buf.put(0, (short) 0);
-                fail("Should throw Exception"); //$NON-NLS-1$
-            } catch (ReadOnlyBufferException e) {
-                // expected
-            }
-            return;
-        }
-
+    public void testPutintshort() {
         buf.clear();
         for (int i = 0; i < buf.capacity(); i++) {
             assertEquals(buf.position(), 0);
@@ -654,7 +536,7 @@
         }
     }
 
-    public static void testSlice(ShortBuffer buf) {
+    public void testSlice() {
         assertTrue(buf.capacity() > 5);
         buf.position(1);
         buf.limit(buf.capacity() - 1);
@@ -682,7 +564,7 @@
         }
     }
 
-    public static void testToString(ShortBuffer buf) {
+    public void testToString() {
         String str = buf.toString();
         assertTrue(str.indexOf("Short") >= 0 || str.indexOf("short") >= 0);
         assertTrue(str.indexOf("" + buf.position()) >= 0);
@@ -690,47 +572,47 @@
         assertTrue(str.indexOf("" + buf.capacity()) >= 0);
     }
 
-    private static void loadTestData1(short array[], int offset, int length) {
+    void loadTestData1(short array[], int offset, int length) {
         for (int i = 0; i < length; i++) {
             array[offset + i] = (short) i;
         }
     }
 
-    private static void loadTestData2(short array[], int offset, int length) {
+    void loadTestData2(short array[], int offset, int length) {
         for (int i = 0; i < length; i++) {
             array[offset + i] = (short) (length - i);
         }
     }
 
-    private static void loadTestData1(ShortBuffer buf) {
+    void loadTestData1(ShortBuffer buf) {
         buf.clear();
         for (int i = 0; i < buf.capacity(); i++) {
             buf.put(i, (short) i);
         }
     }
 
-    private static void loadTestData2(ShortBuffer buf) {
+    void loadTestData2(ShortBuffer buf) {
         buf.clear();
         for (int i = 0; i < buf.capacity(); i++) {
             buf.put(i, (short) (buf.capacity() - i));
         }
     }
 
-    private static void assertContentEquals(ShortBuffer buf, short array[],
+    void assertContentEquals(ShortBuffer buf, short array[],
             int offset, int length) {
         for (int i = 0; i < length; i++) {
             assertEquals(buf.get(i), array[offset + i]);
         }
     }
 
-    private static void assertContentEquals(ShortBuffer buf, ShortBuffer other) {
+    void assertContentEquals(ShortBuffer buf, ShortBuffer 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(ShortBuffer buf,
+    void assertContentLikeTestData1(ShortBuffer buf,
             int startIndex, short startValue, int length) {
         short value = startValue;
         for (int i = 0; i < length; i++) {
@@ -738,108 +620,4 @@
             value = (short) (value + 1);
         }
     }
-
-    public void testAllocatedShortBuffer() {
-        try {
-            ShortBuffer.allocate(-1);
-            fail("Should throw Exception"); //$NON-NLS-1$
-        } catch (IllegalArgumentException e) {
-            // expected 
-        }
-        ShortBuffer buf = ShortBuffer.allocate(16);
-        testShortBufferInstanceThoroughly(buf);
-    }
-
-    public void testWrappedShortBuffer() {
-        ShortBuffer buf = ShortBuffer.wrap(new short[16]);
-        testShortBufferInstanceThoroughly(buf);
-    }
-
-    public void testWrappedShortBuffer2() {
-        short array[] = new short[20];
-        try {
-            ShortBuffer.wrap(array, -1, 0);
-            fail("Should throw Exception"); //$NON-NLS-1$
-        } catch (IndexOutOfBoundsException e) {
-            // expected
-        }
-        try {
-            ShortBuffer.wrap(array, 21, 0);
-            fail("Should throw Exception"); //$NON-NLS-1$
-        } catch (IndexOutOfBoundsException e) {
-            // expected
-        }
-        try {
-            ShortBuffer.wrap(array, 0, -1);
-            fail("Should throw Exception"); //$NON-NLS-1$
-        } catch (IndexOutOfBoundsException e) {
-            // expected
-        }
-        try {
-            ShortBuffer.wrap(array, 0, 21);
-            fail("Should throw Exception"); //$NON-NLS-1$
-        } catch (IndexOutOfBoundsException e) {
-            // expected
-        }
-
-        ShortBuffer buf = ShortBuffer.wrap(array, 2, 16);
-        assertEquals(buf.position(), 2);
-        assertEquals(buf.limit(), 18);
-        assertEquals(buf.capacity(), 20);
-        testShortBufferInstanceThoroughly(buf);
-    }
-
-    /**
-     * @tests java.nio.ShortBuffer.wrap(short[],int,int)
-     */
-    public void testWrappedShortBuffer_null_array() {
-        // Regression for HARMONY-264
-        short array[] = null;
-        try {
-            ShortBuffer.wrap(array, -1, 0);
-            fail("Should throw NPE"); //$NON-NLS-1$
-        } catch (NullPointerException e) {
-        }
-    }
-
-    public void testByteBufferAsShortBuffer() {
-        ShortBuffer buf = ByteBuffer.allocate(160).asShortBuffer();
-        testShortBufferInstanceThoroughly(buf);
-    }
-
-    private void testShortBufferInstanceThoroughly(ShortBuffer buf) {
-        assertTrue(buf.capacity() > 15);
-        buf.clear();
-        loadTestData1(buf);
-
-        buf.limit(15).position(1);
-        testShortBufferInstance(buf);
-        testShortBufferInstance(buf.duplicate());
-        testShortBufferInstance(buf.asReadOnlyBuffer());
-        buf.limit(15).position(1);
-        testShortBufferInstance(buf.slice());
-
-        ShortBuffer duplicate = buf.duplicate();
-        duplicate.limit(15).position(1);
-        testShortBufferInstance(duplicate.duplicate());
-        testShortBufferInstance(duplicate.asReadOnlyBuffer());
-        duplicate.limit(15).position(1);
-        testShortBufferInstance(duplicate.slice());
-
-        ShortBuffer readonly = buf.asReadOnlyBuffer();
-        readonly.limit(15).position(1);
-        testShortBufferInstance(readonly.duplicate());
-        testShortBufferInstance(readonly.asReadOnlyBuffer());
-        readonly.limit(15).position(1);
-        testShortBufferInstance(readonly.slice());
-
-        buf.limit(15).position(1);
-        ShortBuffer slice = buf.slice();
-        slice.limit(10).position(1);
-        testShortBufferInstance(slice.duplicate());
-        testShortBufferInstance(slice.asReadOnlyBuffer());
-        slice.limit(10).position(1);
-        testShortBufferInstance(slice.slice());
-    }
-
 }

Added: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/WrappedShortBufferTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/WrappedShortBufferTest.java?rev=424907&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/WrappedShortBufferTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/WrappedShortBufferTest.java Sun Jul 23 22:35:08 2006
@@ -0,0 +1,86 @@
+/* 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.ShortBuffer;
+
+public class WrappedShortBufferTest extends ShortBufferTest {
+    protected void setUp() throws Exception {
+        super.setUp();
+        buf = ShortBuffer.wrap(new short[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 testWrappedShortBuffer_IllegalArg() {
+        short array[] = new short[20];
+        try {
+            ShortBuffer.wrap(array, -1, 0);
+            fail("Should throw Exception"); //$NON-NLS-1$
+        } catch (IndexOutOfBoundsException e) {
+            // expected
+        }
+        try {
+            ShortBuffer.wrap(array, 21, 0);
+            fail("Should throw Exception"); //$NON-NLS-1$
+        } catch (IndexOutOfBoundsException e) {
+            // expected
+        }
+        try {
+            ShortBuffer.wrap(array, 0, -1);
+            fail("Should throw Exception"); //$NON-NLS-1$
+        } catch (IndexOutOfBoundsException e) {
+            // expected
+        }
+        try {
+            ShortBuffer.wrap(array, 0, 21);
+            fail("Should throw Exception"); //$NON-NLS-1$
+        } catch (IndexOutOfBoundsException e) {
+            // expected
+        }
+        try {
+            ShortBuffer.wrap(array, Integer.MAX_VALUE, 1);
+            fail("Should throw Exception"); //$NON-NLS-1$
+        } catch (IndexOutOfBoundsException e) {
+            // expected
+        }
+        try {
+            ShortBuffer.wrap(array, 1, Integer.MAX_VALUE);
+            fail("Should throw Exception"); //$NON-NLS-1$
+        } catch (IndexOutOfBoundsException e) {
+            // expected
+        }
+        try {
+            ShortBuffer.wrap((short[])null, -1, 0);
+            fail("Should throw NPE"); //$NON-NLS-1$
+        } catch (NullPointerException e) {
+        }
+
+        ShortBuffer buf = ShortBuffer.wrap(array, 2, 16);
+        assertEquals(buf.position(), 2);
+        assertEquals(buf.limit(), 18);
+        assertEquals(buf.capacity(), 20);
+    }
+}



Mime
View raw message