Initial load
diff --git a/test/java/nio/Buffer/AllocateDirectInit.java b/test/java/nio/Buffer/AllocateDirectInit.java
new file mode 100644
index 0000000..e30882d
--- /dev/null
+++ b/test/java/nio/Buffer/AllocateDirectInit.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2001-2007 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/**
+ * @test
+ * @bug 4490253 6535542
+ * @summary Verify that newly allocated direct buffers are initialized.
+ */
+
+import java.nio.ByteBuffer;
+
+public class AllocateDirectInit {
+ public static void main(String [] args){
+ for (int i = 0; i < 1024; i++) {
+ ByteBuffer bb = ByteBuffer.allocateDirect(1024);
+// printByteBuffer(bb);
+ for (bb.position(0); bb.position() < bb.limit(); ) {
+ if ((bb.get() & 0xff) != 0)
+ throw new RuntimeException("uninitialized buffer, position = "
+ + bb.position());
+ }
+ }
+ }
+
+ private static void printByteBuffer(ByteBuffer bb) {
+ System.out.print("byte [");
+ for (bb.position(0); bb.position() < bb.limit(); )
+ System.out.print(" " + Integer.toHexString(bb.get() & 0xff));
+ System.out.println(" ]");
+ }
+}
diff --git a/test/java/nio/Buffer/Basic-X.java b/test/java/nio/Buffer/Basic-X.java
new file mode 100644
index 0000000..a28793c
--- /dev/null
+++ b/test/java/nio/Buffer/Basic-X.java
@@ -0,0 +1,828 @@
+/*
+ * Copyright 2000-2007 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/* Type-specific source code for unit test
+ *
+ * Regenerate the BasicX classes via genBasic.sh whenever this file changes.
+ * We check in the generated source files so that the test tree can be used
+ * independently of the rest of the source tree.
+ */
+
+#warn This file is preprocessed before being compiled
+
+import java.nio.*;
+
+
+public class Basic$Type$
+ extends Basic
+{
+
+ private static void relGet($Type$Buffer b) {
+ int n = b.capacity();
+ $type$ v;
+ for (int i = 0; i < n; i++)
+ ck(b, (long)b.get(), (long)(($type$)ic(i)));
+ b.rewind();
+ }
+
+ private static void relGet($Type$Buffer b, int start) {
+ int n = b.remaining();
+ $type$ v;
+ for (int i = start; i < n; i++)
+ ck(b, (long)b.get(), (long)(($type$)ic(i)));
+ b.rewind();
+ }
+
+ private static void absGet($Type$Buffer b) {
+ int n = b.capacity();
+ $type$ v;
+ for (int i = 0; i < n; i++)
+ ck(b, (long)b.get(), (long)(($type$)ic(i)));
+ b.rewind();
+ }
+
+ private static void bulkGet($Type$Buffer b) {
+ int n = b.capacity();
+ $type$[] a = new $type$[n + 7];
+ b.get(a, 7, n);
+ for (int i = 0; i < n; i++)
+ ck(b, (long)a[i + 7], (long)(($type$)ic(i)));
+ }
+
+ private static void relPut($Type$Buffer b) {
+ int n = b.capacity();
+ b.clear();
+ for (int i = 0; i < n; i++)
+ b.put(($type$)ic(i));
+ b.flip();
+ }
+
+ private static void absPut($Type$Buffer b) {
+ int n = b.capacity();
+ b.clear();
+ for (int i = 0; i < n; i++)
+ b.put(i, ($type$)ic(i));
+ b.limit(n);
+ b.position(0);
+ }
+
+ private static void bulkPutArray($Type$Buffer b) {
+ int n = b.capacity();
+ b.clear();
+ $type$[] a = new $type$[n + 7];
+ for (int i = 0; i < n; i++)
+ a[i + 7] = ($type$)ic(i);
+ b.put(a, 7, n);
+ b.flip();
+ }
+
+ private static void bulkPutBuffer($Type$Buffer b) {
+ int n = b.capacity();
+ b.clear();
+ $Type$Buffer c = $Type$Buffer.allocate(n + 7);
+ c.position(7);
+ for (int i = 0; i < n; i++)
+ c.put(($type$)ic(i));
+ c.flip();
+ c.position(7);
+ b.put(c);
+ b.flip();
+ }
+
+ //6231529
+ private static void callReset($Type$Buffer b) {
+ b.position(0);
+ b.mark();
+
+ b.duplicate().reset();
+ b.asReadOnlyBuffer().reset();
+ }
+
+#if[byte]
+#else[byte]
+ // 6221101-6234263
+
+ private static void putBuffer() {
+ final int cap = 10;
+
+ $Type$Buffer direct1 = ByteBuffer.allocateDirect(cap).as$Type$Buffer();
+ $Type$Buffer nondirect1 = ByteBuffer.allocate(cap).as$Type$Buffer();
+ direct1.put(nondirect1);
+
+ $Type$Buffer direct2 = ByteBuffer.allocateDirect(cap).as$Type$Buffer();
+ $Type$Buffer nondirect2 = ByteBuffer.allocate(cap).as$Type$Buffer();
+ nondirect2.put(direct2);
+
+ $Type$Buffer direct3 = ByteBuffer.allocateDirect(cap).as$Type$Buffer();
+ $Type$Buffer direct4 = ByteBuffer.allocateDirect(cap).as$Type$Buffer();
+ direct3.put(direct4);
+
+ $Type$Buffer nondirect3 = ByteBuffer.allocate(cap).as$Type$Buffer();
+ $Type$Buffer nondirect4 = ByteBuffer.allocate(cap).as$Type$Buffer();
+ nondirect3.put(nondirect4);
+ }
+#end[byte]
+
+#if[char]
+
+ private static void bulkPutString($Type$Buffer b) {
+ int n = b.capacity();
+ b.clear();
+ StringBuffer sb = new StringBuffer(n + 7);
+ sb.append("1234567");
+ for (int i = 0; i < n; i++)
+ sb.append((char)ic(i));
+ b.put(sb.toString(), 7, 7 + n);
+ b.flip();
+ }
+
+#end[char]
+
+ private static void checkSlice($Type$Buffer b, $Type$Buffer slice) {
+ ck(slice, 0, slice.position());
+ ck(slice, b.remaining(), slice.limit());
+ ck(slice, b.remaining(), slice.capacity());
+ if (b.isDirect() != slice.isDirect())
+ fail("Lost direction", slice);
+ if (b.isReadOnly() != slice.isReadOnly())
+ fail("Lost read-only", slice);
+ }
+
+#if[byte]
+
+ private static void checkBytes(ByteBuffer b, byte[] bs) {
+ int n = bs.length;
+ int p = b.position();
+ byte v;
+ if (b.order() == ByteOrder.BIG_ENDIAN) {
+ for (int i = 0; i < n; i++)
+ ck(b, b.get(), bs[i]);
+ } else {
+ for (int i = n - 1; i >= 0; i--)
+ ck(b, b.get(), bs[i]);
+ }
+ b.position(p);
+ }
+
+ private static void testViews(int level, ByteBuffer b, boolean direct) {
+
+ ShortBuffer sb = b.asShortBuffer();
+ BasicShort.test(level, sb, direct);
+ checkBytes(b, new byte[] { 0, (byte)ic(0) });
+
+ CharBuffer cb = b.asCharBuffer();
+ BasicChar.test(level, cb, direct);
+ checkBytes(b, new byte[] { 0, (byte)ic(0) });
+
+ IntBuffer ib = b.asIntBuffer();
+ BasicInt.test(level, ib, direct);
+ checkBytes(b, new byte[] { 0, 0, 0, (byte)ic(0) });
+
+ LongBuffer lb = b.asLongBuffer();
+ BasicLong.test(level, lb, direct);
+ checkBytes(b, new byte[] { 0, 0, 0, 0, 0, 0, 0, (byte)ic(0) });
+
+ FloatBuffer fb = b.asFloatBuffer();
+ BasicFloat.test(level, fb, direct);
+ checkBytes(b, new byte[] { 0x42, (byte)0xc2, 0, 0 });
+
+ DoubleBuffer db = b.asDoubleBuffer();
+ BasicDouble.test(level, db, direct);
+ checkBytes(b, new byte[] { 0x40, 0x58, 0x40, 0, 0, 0, 0, 0 });
+
+ }
+
+ private static void testHet(int level, ByteBuffer b) {
+
+ int p = b.position();
+ b.limit(b.capacity());
+ show(level, b);
+ out.print(" put:");
+
+ b.putChar((char)1);
+ b.putChar((char)Character.MAX_VALUE);
+ out.print(" char");
+
+ b.putShort((short)1);
+ b.putShort((short)Short.MAX_VALUE);
+ out.print(" short");
+
+ b.putInt(1);
+ b.putInt(Integer.MAX_VALUE);
+ out.print(" int");
+
+ b.putLong((long)1);
+ b.putLong((long)Long.MAX_VALUE);
+ out.print(" long");
+
+ b.putFloat((float)1);
+ b.putFloat((float)Float.MIN_VALUE);
+ b.putFloat((float)Float.MAX_VALUE);
+ out.print(" float");
+
+ b.putDouble((double)1);
+ b.putDouble((double)Double.MIN_VALUE);
+ b.putDouble((double)Double.MAX_VALUE);
+ out.print(" double");
+
+ out.println();
+ b.limit(b.position());
+ b.position(p);
+ show(level, b);
+ out.print(" get:");
+
+ ck(b, b.getChar(), 1);
+ ck(b, b.getChar(), Character.MAX_VALUE);
+ out.print(" char");
+
+ ck(b, b.getShort(), 1);
+ ck(b, b.getShort(), Short.MAX_VALUE);
+ out.print(" short");
+
+ ck(b, b.getInt(), 1);
+ ck(b, b.getInt(), Integer.MAX_VALUE);
+ out.print(" int");
+
+ ck(b, b.getLong(), 1);
+ ck(b, b.getLong(), Long.MAX_VALUE);
+ out.print(" long");
+
+ ck(b, (long)b.getFloat(), 1);
+ ck(b, (long)b.getFloat(), (long)Float.MIN_VALUE);
+ ck(b, (long)b.getFloat(), (long)Float.MAX_VALUE);
+ out.print(" float");
+
+ ck(b, (long)b.getDouble(), 1);
+ ck(b, (long)b.getDouble(), (long)Double.MIN_VALUE);
+ ck(b, (long)b.getDouble(), (long)Double.MAX_VALUE);
+ out.print(" double");
+
+ out.println();
+
+ }
+
+#end[byte]
+
+ private static void tryCatch(Buffer b, Class ex, Runnable thunk) {
+ boolean caught = false;
+ try {
+ thunk.run();
+ } catch (Throwable x) {
+ if (ex.isAssignableFrom(x.getClass()))
+ caught = true;
+ }
+ if (!caught)
+ fail(ex.getName() + " not thrown", b);
+ }
+
+ private static void tryCatch($type$ [] t, Class ex, Runnable thunk) {
+ tryCatch($Type$Buffer.wrap(t), ex, thunk);
+ }
+
+ public static void test(int level, final $Type$Buffer b, boolean direct) {
+
+ show(level, b);
+
+ if (direct != b.isDirect())
+ fail("Wrong direction", b);
+
+ // Gets and puts
+
+ relPut(b);
+ relGet(b);
+ absGet(b);
+ bulkGet(b);
+
+ absPut(b);
+ relGet(b);
+ absGet(b);
+ bulkGet(b);
+
+ bulkPutArray(b);
+ relGet(b);
+
+ bulkPutBuffer(b);
+ relGet(b);
+
+#if[char]
+
+ bulkPutString(b);
+ relGet(b);
+ b.position(1);
+ b.limit(7);
+ ck(b, b.toString().equals("bcdefg"));
+
+ // CharSequence ops
+
+ b.position(2);
+ ck(b, b.charAt(1), 'd');
+ CharBuffer c = (CharBuffer)b.subSequence(1, 4);
+ ck(b, b.subSequence(1, 4).toString().equals("def"));
+
+ // 4938424
+ b.position(4);
+ ck(b, b.charAt(1), 'f');
+ ck(b, b.subSequence(1, 3).toString().equals("fg"));
+
+#end[char]
+
+ // Compact
+
+ relPut(b);
+ b.position(13);
+ b.compact();
+ b.flip();
+ relGet(b, 13);
+
+ // Exceptions
+
+ boolean caught = false;
+ relPut(b);
+ b.limit(b.capacity() / 2);
+ b.position(b.limit());
+
+ tryCatch(b, BufferUnderflowException.class, new Runnable() {
+ public void run() {
+ b.get();
+ }});
+
+ tryCatch(b, BufferOverflowException.class, new Runnable() {
+ public void run() {
+ b.put(($type$)42);
+ }});
+
+ // The index must be non-negative and lesss than the buffer's limit.
+ tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ b.get(b.limit());
+ }});
+ tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ b.get(-1);
+ }});
+
+ tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ b.put(b.limit(), ($type$)42);
+ }});
+
+ // Values
+
+ b.clear();
+ b.put(($type$)0);
+ b.put(($type$)-1);
+ b.put(($type$)1);
+ b.put($Fulltype$.MAX_VALUE);
+ b.put($Fulltype$.MIN_VALUE);
+#if[float]
+ b.put(-Float.MAX_VALUE);
+ b.put(-Float.MIN_VALUE);
+ b.put(Float.NEGATIVE_INFINITY);
+ b.put(Float.POSITIVE_INFINITY);
+ b.put(Float.NaN);
+ b.put(0.91697687f); // Changes value if incorrectly swapped
+#end[float]
+#if[double]
+ b.put(-Double.MAX_VALUE);
+ b.put(-Double.MIN_VALUE);
+ b.put(Double.NEGATIVE_INFINITY);
+ b.put(Double.POSITIVE_INFINITY);
+ b.put(Double.NaN);
+ b.put(0.5121609353879392); // Changes value if incorrectly swapped
+#end[double]
+
+ $type$ v;
+ b.flip();
+ ck(b, b.get(), 0);
+ ck(b, b.get(), ($type$)-1);
+ ck(b, b.get(), 1);
+ ck(b, b.get(), $Fulltype$.MAX_VALUE);
+ ck(b, b.get(), $Fulltype$.MIN_VALUE);
+
+#if[float]
+ ck(b, b.get(), -Float.MAX_VALUE);
+ ck(b, b.get(), -Float.MIN_VALUE);
+ ck(b, b.get(), Float.NEGATIVE_INFINITY);
+ ck(b, b.get(), Float.POSITIVE_INFINITY);
+ if (Float.floatToRawIntBits(v = b.get()) != Float.floatToRawIntBits(Float.NaN))
+ fail(b, (long)Float.NaN, (long)v);
+ ck(b, b.get(), 0.91697687f);
+#end[float]
+#if[double]
+ ck(b, b.get(), -Double.MAX_VALUE);
+ ck(b, b.get(), -Double.MIN_VALUE);
+ ck(b, b.get(), Double.NEGATIVE_INFINITY);
+ ck(b, b.get(), Double.POSITIVE_INFINITY);
+ if (Double.doubleToRawLongBits(v = b.get())
+ != Double.doubleToRawLongBits(Double.NaN))
+ fail(b, (long)Double.NaN, (long)v);
+ ck(b, b.get(), 0.5121609353879392);
+#end[double]
+
+
+ // Comparison
+ b.rewind();
+ $Type$Buffer b2 = $Type$Buffer.allocate(b.capacity());
+ b2.put(b);
+ b2.flip();
+ b.position(2);
+ b2.position(2);
+ if (!b.equals(b2)) {
+ for (int i = 2; i < b.limit(); i++) {
+ $type$ x = b.get(i);
+ $type$ y = b2.get(i);
+ if (x != y
+#if[double]
+ || Double.compare(x, y) != 0
+#end[double]
+#if[float]
+ || Float.compare(x, y) != 0
+#end[float]
+ )
+ out.println("[" + i + "] " + x + " != " + y);
+ }
+ fail("Identical buffers not equal", b, b2);
+ }
+ if (b.compareTo(b2) != 0)
+ fail("Comparison to identical buffer != 0", b, b2);
+
+ b.limit(b.limit() + 1);
+ b.position(b.limit() - 1);
+ b.put(($type$)99);
+ b.rewind();
+ b2.rewind();
+ if (b.equals(b2))
+ fail("Non-identical buffers equal", b, b2);
+ if (b.compareTo(b2) <= 0)
+ fail("Comparison to shorter buffer <= 0", b, b2);
+ b.limit(b.limit() - 1);
+
+ b.put(2, ($type$)42);
+ if (b.equals(b2))
+ fail("Non-identical buffers equal", b, b2);
+ if (b.compareTo(b2) <= 0)
+ fail("Comparison to lesser buffer <= 0", b, b2);
+
+ // Sub, dup
+
+ relPut(b);
+ relGet(b.duplicate());
+ b.position(13);
+ relGet(b.duplicate(), 13);
+ relGet(b.duplicate().slice(), 13);
+ relGet(b.slice(), 13);
+ relGet(b.slice().duplicate(), 13);
+
+ // Slice
+
+ b.position(5);
+ $Type$Buffer sb = b.slice();
+ checkSlice(b, sb);
+ b.position(0);
+ $Type$Buffer sb2 = sb.slice();
+ checkSlice(sb, sb2);
+
+ if (!sb.equals(sb2))
+ fail("Sliced slices do not match", sb, sb2);
+ if ((sb.hasArray()) && (sb.arrayOffset() != sb2.arrayOffset()))
+ fail("Array offsets do not match: "
+ + sb.arrayOffset() + " != " + sb2.arrayOffset(), sb, sb2);
+
+#if[byte]
+
+ // Views
+
+ b.clear();
+ b.order(ByteOrder.BIG_ENDIAN);
+ testViews(level + 1, b, direct);
+
+ for (int i = 1; i <= 9; i++) {
+ b.position(i);
+ show(level + 1, b);
+ testViews(level + 2, b, direct);
+ }
+
+ b.position(0);
+ b.order(ByteOrder.LITTLE_ENDIAN);
+ testViews(level + 1, b, direct);
+
+ // Heterogeneous accessors
+
+ b.order(ByteOrder.BIG_ENDIAN);
+ for (int i = 0; i <= 9; i++) {
+ b.position(i);
+ testHet(level + 1, b);
+ }
+ b.order(ByteOrder.LITTLE_ENDIAN);
+ b.position(3);
+ testHet(level + 1, b);
+
+#end[byte]
+
+ // Read-only views
+
+ b.rewind();
+ final $Type$Buffer rb = b.asReadOnlyBuffer();
+ if (!b.equals(rb))
+ fail("Buffer not equal to read-only view", b, rb);
+ show(level + 1, rb);
+
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ relPut(rb);
+ }});
+
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ absPut(rb);
+ }});
+
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ bulkPutArray(rb);
+ }});
+
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ bulkPutBuffer(rb);
+ }});
+
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ rb.compact();
+ }});
+
+#if[byte]
+
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ rb.putChar((char)1);
+ }});
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ rb.putChar(0, (char)1);
+ }});
+
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ rb.putShort((short)1);
+ }});
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ rb.putShort(0, (short)1);
+ }});
+
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ rb.putInt(1);
+ }});
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ rb.putInt(0, 1);
+ }});
+
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ rb.putLong((long)1);
+ }});
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ rb.putLong(0, (long)1);
+ }});
+
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ rb.putFloat((float)1);
+ }});
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ rb.putFloat(0, (float)1);
+ }});
+
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ rb.putDouble((double)1);
+ }});
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ rb.putDouble(0, (double)1);
+ }});
+
+#end[byte]
+
+ if (rb.getClass().getName().startsWith("java.nio.Heap")) {
+
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ rb.array();
+ }});
+
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ rb.arrayOffset();
+ }});
+
+ if (rb.hasArray())
+ fail("Read-only heap buffer's backing array is accessible",
+ rb);
+
+ }
+
+ // Bulk puts from read-only buffers
+
+ b.clear();
+ rb.rewind();
+ b.put(rb);
+
+#if[byte]
+ // For byte buffers, test both the direct and non-direct cases
+ $Type$Buffer ob
+ = (b.isDirect()
+ ? $Type$Buffer.allocate(rb.capacity())
+ : $Type$Buffer.allocateDirect(rb.capacity()));
+ rb.rewind();
+ ob.put(rb);
+#end[byte]
+
+ relPut(b); // Required by testViews
+
+ }
+
+#if[char]
+
+ private static void testStr() {
+ final String s = "abcdefghijklm";
+ int start = 3;
+ int end = 9;
+ final CharBuffer b = CharBuffer.wrap(s, start, end);
+ show(0, b);
+ ck(b, b.toString().equals(s.substring(start, end)));
+ ck(b, b.toString().equals("defghi"));
+ ck(b, b.isReadOnly());
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ b.put('x');
+ }});
+ ck(b, start, b.position());
+ ck(b, end, b.limit());
+ ck(b, s.length(), b.capacity());
+
+ // The index, relative to the position, must be non-negative and
+ // smaller than remaining().
+ tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ b.charAt(-1);
+ }});
+ tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ b.charAt(b.remaining());
+ }});
+
+ // The index must be non-negative and less than the buffer's limit.
+ tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ b.get(b.limit());
+ }});
+ tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ b.get(-1);
+ }});
+
+ // The start must be non-negative and no larger than remaining().
+ tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ b.subSequence(-1, b.remaining());
+ }});
+ tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ b.subSequence(b.remaining() + 1, b.remaining());
+ }});
+
+ // The end must be no smaller than start and no larger than
+ // remaining().
+ tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ b.subSequence(2, 1);
+ }});
+ tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ b.subSequence(0, b.remaining() + 1);
+ }});
+
+ // The offset must be non-negative and no larger than <array.length>.
+ tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ $Type$Buffer.wrap(s, -1, s.length());
+ }});
+ tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ $Type$Buffer.wrap(s, s.length() + 1, s.length());
+ }});
+ tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ $Type$Buffer.wrap(s, 1, 0);
+ }});
+ tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ $Type$Buffer.wrap(s, 0, s.length() + 1);
+ }});
+ }
+
+#end[char]
+
+ public static void test(final $type$ [] ba) {
+ int offset = 47;
+ int length = 900;
+ final $Type$Buffer b = $Type$Buffer.wrap(ba, offset, length);
+ show(0, b);
+ ck(b, b.capacity(), ba.length);
+ ck(b, b.position(), offset);
+ ck(b, b.limit(), offset + length);
+
+ // The offset must be non-negative and no larger than <array.length>.
+ tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ $Type$Buffer.wrap(ba, -1, ba.length);
+ }});
+ tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ $Type$Buffer.wrap(ba, ba.length + 1, ba.length);
+ }});
+ tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ $Type$Buffer.wrap(ba, 0, -1);
+ }});
+ tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ $Type$Buffer.wrap(ba, 0, ba.length + 1);
+ }});
+
+ // A NullPointerException will be thrown if the array is null.
+ tryCatch(ba, NullPointerException.class, new Runnable() {
+ public void run() {
+ $Type$Buffer.wrap(($type$ []) null, 0, 5);
+ }});
+ tryCatch(ba, NullPointerException.class, new Runnable() {
+ public void run() {
+ $Type$Buffer.wrap(($type$ []) null);
+ }});
+ }
+
+ private static void testAllocate() {
+ // An IllegalArgumentException will be thrown for negative capacities.
+ tryCatch((Buffer) null, IllegalArgumentException.class, new Runnable() {
+ public void run() {
+ $Type$Buffer.allocate(-1);
+ }});
+#if[byte]
+ tryCatch((Buffer) null, IllegalArgumentException.class, new Runnable() {
+ public void run() {
+ $Type$Buffer.allocateDirect(-1);
+ }});
+#end[byte]
+ }
+
+ public static void test() {
+ testAllocate();
+ test(0, $Type$Buffer.allocate(7 * 1024), false);
+ test(0, $Type$Buffer.wrap(new $type$[7 * 1024], 0, 7 * 1024), false);
+ test(new $type$[1024]);
+#if[byte]
+ $Type$Buffer b = $Type$Buffer.allocateDirect(7 * 1024);
+ for (b.position(0); b.position() < b.limit(); )
+ ck(b, b.get(), 0);
+ test(0, b, true);
+#end[byte]
+#if[char]
+ testStr();
+#end[char]
+
+ callReset($Type$Buffer.allocate(10));
+
+#if[byte]
+#else[byte]
+ putBuffer();
+#end[byte]
+ }
+
+}
diff --git a/test/java/nio/Buffer/Basic.java b/test/java/nio/Buffer/Basic.java
new file mode 100644
index 0000000..0716a5b
--- /dev/null
+++ b/test/java/nio/Buffer/Basic.java
@@ -0,0 +1,141 @@
+/*
+ * Copyright 2000-2007 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/* @test
+ * @summary Unit test for buffers
+ * @bug 4413135 4414911 4416536 4416562 4418782 4471053 4472779 4490253 4523725
+ * 4526177 4463011 4660660 4661219 4663521 4782970 4804304 4938424 6231529
+ * 6221101 6234263 6535542 6591971
+ * @author Mark Reinhold
+ */
+
+
+import java.io.PrintStream;
+
+import java.nio.Buffer;
+import java.nio.ByteBuffer;
+import java.nio.CharBuffer;
+
+
+public class Basic {
+
+ static PrintStream out = System.err;
+
+ static long ic(int i) {
+ int j = i % 54;
+ return j + 'a' + ((j > 26) ? 128 : 0);
+ }
+
+ static String toString(Buffer b) {
+ return (b.getClass().getName()
+ + "[pos=" + b.position()
+ + " lim=" + b.limit()
+ + " cap=" + b.capacity()
+ + "]");
+ }
+
+ static void show(int level, Buffer b) {
+ for (int i = 0; i < level; i++)
+ out.print(" ");
+ out.println(toString(b) + " " + Integer.toHexString(b.hashCode()));
+ }
+
+ static void fail(String s) {
+ throw new RuntimeException(s);
+ }
+
+ static void fail(String s, Buffer b) {
+ throw new RuntimeException(s + ": " + toString(b));
+ }
+
+ static void fail(String s, Buffer b, Buffer b2) {
+ throw new RuntimeException(s + ": "
+ + toString(b) + ", " + toString(b2));
+ }
+
+ static void fail(Buffer b,
+ String expected, char expectedChar,
+ String got, char gotChar)
+ {
+ if (b instanceof ByteBuffer) {
+ ByteBuffer bb = (ByteBuffer)b;
+ int n = Math.min(16, bb.limit());
+ for (int i = 0; i < n; i++)
+ out.print(" " + Integer.toHexString(bb.get(i) & 0xff));
+ out.println();
+ }
+ if (b instanceof CharBuffer) {
+ CharBuffer bb = (CharBuffer)b;
+ int n = Math.min(16, bb.limit());
+ for (int i = 0; i < n; i++)
+ out.print(" " + Integer.toHexString(bb.get(i) & 0xffff));
+ out.println();
+ }
+ throw new RuntimeException(toString(b)
+ + ": Expected '" + expectedChar + "'=0x"
+ + expected
+ + ", got '" + gotChar + "'=0x"
+ + got);
+ }
+
+ static void fail(Buffer b, long expected, long got) {
+ fail(b,
+ Long.toHexString(expected), (char)expected,
+ Long.toHexString(got), (char)got);
+ }
+
+ static void ck(Buffer b, boolean cond) {
+ if (!cond)
+ fail("Condition failed", b);
+ }
+
+ static void ck(Buffer b, long got, long expected) {
+ if (expected != got)
+ fail(b, expected, got);
+ }
+
+ static void ck(Buffer b, float got, float expected) {
+ if (expected != got)
+ fail(b,
+ Float.toString(expected), (char)expected,
+ Float.toString(got), (char)got);
+ }
+
+ static void ck(Buffer b, double got, double expected) {
+ if (expected != got)
+ fail(b,
+ Double.toString(expected), (char)expected,
+ Double.toString(got), (char)got);
+ }
+
+ public static void main(String[] args) {
+ BasicByte.test();
+ BasicChar.test();
+ BasicShort.test();
+ BasicInt.test();
+ BasicLong.test();
+ BasicFloat.test();
+ BasicDouble.test();
+ }
+
+}
diff --git a/test/java/nio/Buffer/BasicByte.java b/test/java/nio/Buffer/BasicByte.java
new file mode 100644
index 0000000..539af2c
--- /dev/null
+++ b/test/java/nio/Buffer/BasicByte.java
@@ -0,0 +1,828 @@
+/*
+ * Copyright 2000-2007 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/* Type-specific source code for unit test
+ *
+ * Regenerate the BasicX classes via genBasic.sh whenever this file changes.
+ * We check in the generated source files so that the test tree can be used
+ * independently of the rest of the source tree.
+ */
+
+// -- This file was mechanically generated: Do not edit! -- //
+
+import java.nio.*;
+
+
+public class BasicByte
+ extends Basic
+{
+
+ private static void relGet(ByteBuffer b) {
+ int n = b.capacity();
+ byte v;
+ for (int i = 0; i < n; i++)
+ ck(b, (long)b.get(), (long)((byte)ic(i)));
+ b.rewind();
+ }
+
+ private static void relGet(ByteBuffer b, int start) {
+ int n = b.remaining();
+ byte v;
+ for (int i = start; i < n; i++)
+ ck(b, (long)b.get(), (long)((byte)ic(i)));
+ b.rewind();
+ }
+
+ private static void absGet(ByteBuffer b) {
+ int n = b.capacity();
+ byte v;
+ for (int i = 0; i < n; i++)
+ ck(b, (long)b.get(), (long)((byte)ic(i)));
+ b.rewind();
+ }
+
+ private static void bulkGet(ByteBuffer b) {
+ int n = b.capacity();
+ byte[] a = new byte[n + 7];
+ b.get(a, 7, n);
+ for (int i = 0; i < n; i++)
+ ck(b, (long)a[i + 7], (long)((byte)ic(i)));
+ }
+
+ private static void relPut(ByteBuffer b) {
+ int n = b.capacity();
+ b.clear();
+ for (int i = 0; i < n; i++)
+ b.put((byte)ic(i));
+ b.flip();
+ }
+
+ private static void absPut(ByteBuffer b) {
+ int n = b.capacity();
+ b.clear();
+ for (int i = 0; i < n; i++)
+ b.put(i, (byte)ic(i));
+ b.limit(n);
+ b.position(0);
+ }
+
+ private static void bulkPutArray(ByteBuffer b) {
+ int n = b.capacity();
+ b.clear();
+ byte[] a = new byte[n + 7];
+ for (int i = 0; i < n; i++)
+ a[i + 7] = (byte)ic(i);
+ b.put(a, 7, n);
+ b.flip();
+ }
+
+ private static void bulkPutBuffer(ByteBuffer b) {
+ int n = b.capacity();
+ b.clear();
+ ByteBuffer c = ByteBuffer.allocate(n + 7);
+ c.position(7);
+ for (int i = 0; i < n; i++)
+ c.put((byte)ic(i));
+ c.flip();
+ c.position(7);
+ b.put(c);
+ b.flip();
+ }
+
+ //6231529
+ private static void callReset(ByteBuffer b) {
+ b.position(0);
+ b.mark();
+
+ b.duplicate().reset();
+ b.asReadOnlyBuffer().reset();
+ }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ private static void checkSlice(ByteBuffer b, ByteBuffer slice) {
+ ck(slice, 0, slice.position());
+ ck(slice, b.remaining(), slice.limit());
+ ck(slice, b.remaining(), slice.capacity());
+ if (b.isDirect() != slice.isDirect())
+ fail("Lost direction", slice);
+ if (b.isReadOnly() != slice.isReadOnly())
+ fail("Lost read-only", slice);
+ }
+
+
+
+ private static void checkBytes(ByteBuffer b, byte[] bs) {
+ int n = bs.length;
+ int p = b.position();
+ byte v;
+ if (b.order() == ByteOrder.BIG_ENDIAN) {
+ for (int i = 0; i < n; i++)
+ ck(b, b.get(), bs[i]);
+ } else {
+ for (int i = n - 1; i >= 0; i--)
+ ck(b, b.get(), bs[i]);
+ }
+ b.position(p);
+ }
+
+ private static void testViews(int level, ByteBuffer b, boolean direct) {
+
+ ShortBuffer sb = b.asShortBuffer();
+ BasicShort.test(level, sb, direct);
+ checkBytes(b, new byte[] { 0, (byte)ic(0) });
+
+ CharBuffer cb = b.asCharBuffer();
+ BasicChar.test(level, cb, direct);
+ checkBytes(b, new byte[] { 0, (byte)ic(0) });
+
+ IntBuffer ib = b.asIntBuffer();
+ BasicInt.test(level, ib, direct);
+ checkBytes(b, new byte[] { 0, 0, 0, (byte)ic(0) });
+
+ LongBuffer lb = b.asLongBuffer();
+ BasicLong.test(level, lb, direct);
+ checkBytes(b, new byte[] { 0, 0, 0, 0, 0, 0, 0, (byte)ic(0) });
+
+ FloatBuffer fb = b.asFloatBuffer();
+ BasicFloat.test(level, fb, direct);
+ checkBytes(b, new byte[] { 0x42, (byte)0xc2, 0, 0 });
+
+ DoubleBuffer db = b.asDoubleBuffer();
+ BasicDouble.test(level, db, direct);
+ checkBytes(b, new byte[] { 0x40, 0x58, 0x40, 0, 0, 0, 0, 0 });
+
+ }
+
+ private static void testHet(int level, ByteBuffer b) {
+
+ int p = b.position();
+ b.limit(b.capacity());
+ show(level, b);
+ out.print(" put:");
+
+ b.putChar((char)1);
+ b.putChar((char)Character.MAX_VALUE);
+ out.print(" char");
+
+ b.putShort((short)1);
+ b.putShort((short)Short.MAX_VALUE);
+ out.print(" short");
+
+ b.putInt(1);
+ b.putInt(Integer.MAX_VALUE);
+ out.print(" int");
+
+ b.putLong((long)1);
+ b.putLong((long)Long.MAX_VALUE);
+ out.print(" long");
+
+ b.putFloat((float)1);
+ b.putFloat((float)Float.MIN_VALUE);
+ b.putFloat((float)Float.MAX_VALUE);
+ out.print(" float");
+
+ b.putDouble((double)1);
+ b.putDouble((double)Double.MIN_VALUE);
+ b.putDouble((double)Double.MAX_VALUE);
+ out.print(" double");
+
+ out.println();
+ b.limit(b.position());
+ b.position(p);
+ show(level, b);
+ out.print(" get:");
+
+ ck(b, b.getChar(), 1);
+ ck(b, b.getChar(), Character.MAX_VALUE);
+ out.print(" char");
+
+ ck(b, b.getShort(), 1);
+ ck(b, b.getShort(), Short.MAX_VALUE);
+ out.print(" short");
+
+ ck(b, b.getInt(), 1);
+ ck(b, b.getInt(), Integer.MAX_VALUE);
+ out.print(" int");
+
+ ck(b, b.getLong(), 1);
+ ck(b, b.getLong(), Long.MAX_VALUE);
+ out.print(" long");
+
+ ck(b, (long)b.getFloat(), 1);
+ ck(b, (long)b.getFloat(), (long)Float.MIN_VALUE);
+ ck(b, (long)b.getFloat(), (long)Float.MAX_VALUE);
+ out.print(" float");
+
+ ck(b, (long)b.getDouble(), 1);
+ ck(b, (long)b.getDouble(), (long)Double.MIN_VALUE);
+ ck(b, (long)b.getDouble(), (long)Double.MAX_VALUE);
+ out.print(" double");
+
+ out.println();
+
+ }
+
+
+
+ private static void tryCatch(Buffer b, Class ex, Runnable thunk) {
+ boolean caught = false;
+ try {
+ thunk.run();
+ } catch (Throwable x) {
+ if (ex.isAssignableFrom(x.getClass()))
+ caught = true;
+ }
+ if (!caught)
+ fail(ex.getName() + " not thrown", b);
+ }
+
+ private static void tryCatch(byte [] t, Class ex, Runnable thunk) {
+ tryCatch(ByteBuffer.wrap(t), ex, thunk);
+ }
+
+ public static void test(int level, final ByteBuffer b, boolean direct) {
+
+ show(level, b);
+
+ if (direct != b.isDirect())
+ fail("Wrong direction", b);
+
+ // Gets and puts
+
+ relPut(b);
+ relGet(b);
+ absGet(b);
+ bulkGet(b);
+
+ absPut(b);
+ relGet(b);
+ absGet(b);
+ bulkGet(b);
+
+ bulkPutArray(b);
+ relGet(b);
+
+ bulkPutBuffer(b);
+ relGet(b);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ // Compact
+
+ relPut(b);
+ b.position(13);
+ b.compact();
+ b.flip();
+ relGet(b, 13);
+
+ // Exceptions
+
+ boolean caught = false;
+ relPut(b);
+ b.limit(b.capacity() / 2);
+ b.position(b.limit());
+
+ tryCatch(b, BufferUnderflowException.class, new Runnable() {
+ public void run() {
+ b.get();
+ }});
+
+ tryCatch(b, BufferOverflowException.class, new Runnable() {
+ public void run() {
+ b.put((byte)42);
+ }});
+
+ // The index must be non-negative and lesss than the buffer's limit.
+ tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ b.get(b.limit());
+ }});
+ tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ b.get(-1);
+ }});
+
+ tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ b.put(b.limit(), (byte)42);
+ }});
+
+ // Values
+
+ b.clear();
+ b.put((byte)0);
+ b.put((byte)-1);
+ b.put((byte)1);
+ b.put(Byte.MAX_VALUE);
+ b.put(Byte.MIN_VALUE);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ byte v;
+ b.flip();
+ ck(b, b.get(), 0);
+ ck(b, b.get(), (byte)-1);
+ ck(b, b.get(), 1);
+ ck(b, b.get(), Byte.MAX_VALUE);
+ ck(b, b.get(), Byte.MIN_VALUE);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ // Comparison
+ b.rewind();
+ ByteBuffer b2 = ByteBuffer.allocate(b.capacity());
+ b2.put(b);
+ b2.flip();
+ b.position(2);
+ b2.position(2);
+ if (!b.equals(b2)) {
+ for (int i = 2; i < b.limit(); i++) {
+ byte x = b.get(i);
+ byte y = b2.get(i);
+ if (x != y
+
+
+
+
+
+
+ )
+ out.println("[" + i + "] " + x + " != " + y);
+ }
+ fail("Identical buffers not equal", b, b2);
+ }
+ if (b.compareTo(b2) != 0)
+ fail("Comparison to identical buffer != 0", b, b2);
+
+ b.limit(b.limit() + 1);
+ b.position(b.limit() - 1);
+ b.put((byte)99);
+ b.rewind();
+ b2.rewind();
+ if (b.equals(b2))
+ fail("Non-identical buffers equal", b, b2);
+ if (b.compareTo(b2) <= 0)
+ fail("Comparison to shorter buffer <= 0", b, b2);
+ b.limit(b.limit() - 1);
+
+ b.put(2, (byte)42);
+ if (b.equals(b2))
+ fail("Non-identical buffers equal", b, b2);
+ if (b.compareTo(b2) <= 0)
+ fail("Comparison to lesser buffer <= 0", b, b2);
+
+ // Sub, dup
+
+ relPut(b);
+ relGet(b.duplicate());
+ b.position(13);
+ relGet(b.duplicate(), 13);
+ relGet(b.duplicate().slice(), 13);
+ relGet(b.slice(), 13);
+ relGet(b.slice().duplicate(), 13);
+
+ // Slice
+
+ b.position(5);
+ ByteBuffer sb = b.slice();
+ checkSlice(b, sb);
+ b.position(0);
+ ByteBuffer sb2 = sb.slice();
+ checkSlice(sb, sb2);
+
+ if (!sb.equals(sb2))
+ fail("Sliced slices do not match", sb, sb2);
+ if ((sb.hasArray()) && (sb.arrayOffset() != sb2.arrayOffset()))
+ fail("Array offsets do not match: "
+ + sb.arrayOffset() + " != " + sb2.arrayOffset(), sb, sb2);
+
+
+
+ // Views
+
+ b.clear();
+ b.order(ByteOrder.BIG_ENDIAN);
+ testViews(level + 1, b, direct);
+
+ for (int i = 1; i <= 9; i++) {
+ b.position(i);
+ show(level + 1, b);
+ testViews(level + 2, b, direct);
+ }
+
+ b.position(0);
+ b.order(ByteOrder.LITTLE_ENDIAN);
+ testViews(level + 1, b, direct);
+
+ // Heterogeneous accessors
+
+ b.order(ByteOrder.BIG_ENDIAN);
+ for (int i = 0; i <= 9; i++) {
+ b.position(i);
+ testHet(level + 1, b);
+ }
+ b.order(ByteOrder.LITTLE_ENDIAN);
+ b.position(3);
+ testHet(level + 1, b);
+
+
+
+ // Read-only views
+
+ b.rewind();
+ final ByteBuffer rb = b.asReadOnlyBuffer();
+ if (!b.equals(rb))
+ fail("Buffer not equal to read-only view", b, rb);
+ show(level + 1, rb);
+
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ relPut(rb);
+ }});
+
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ absPut(rb);
+ }});
+
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ bulkPutArray(rb);
+ }});
+
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ bulkPutBuffer(rb);
+ }});
+
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ rb.compact();
+ }});
+
+
+
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ rb.putChar((char)1);
+ }});
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ rb.putChar(0, (char)1);
+ }});
+
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ rb.putShort((short)1);
+ }});
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ rb.putShort(0, (short)1);
+ }});
+
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ rb.putInt(1);
+ }});
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ rb.putInt(0, 1);
+ }});
+
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ rb.putLong((long)1);
+ }});
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ rb.putLong(0, (long)1);
+ }});
+
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ rb.putFloat((float)1);
+ }});
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ rb.putFloat(0, (float)1);
+ }});
+
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ rb.putDouble((double)1);
+ }});
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ rb.putDouble(0, (double)1);
+ }});
+
+
+
+ if (rb.getClass().getName().startsWith("java.nio.Heap")) {
+
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ rb.array();
+ }});
+
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ rb.arrayOffset();
+ }});
+
+ if (rb.hasArray())
+ fail("Read-only heap buffer's backing array is accessible",
+ rb);
+
+ }
+
+ // Bulk puts from read-only buffers
+
+ b.clear();
+ rb.rewind();
+ b.put(rb);
+
+
+ // For byte buffers, test both the direct and non-direct cases
+ ByteBuffer ob
+ = (b.isDirect()
+ ? ByteBuffer.allocate(rb.capacity())
+ : ByteBuffer.allocateDirect(rb.capacity()));
+ rb.rewind();
+ ob.put(rb);
+
+
+ relPut(b); // Required by testViews
+
+ }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ public static void test(final byte [] ba) {
+ int offset = 47;
+ int length = 900;
+ final ByteBuffer b = ByteBuffer.wrap(ba, offset, length);
+ show(0, b);
+ ck(b, b.capacity(), ba.length);
+ ck(b, b.position(), offset);
+ ck(b, b.limit(), offset + length);
+
+ // The offset must be non-negative and no larger than <array.length>.
+ tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ ByteBuffer.wrap(ba, -1, ba.length);
+ }});
+ tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ ByteBuffer.wrap(ba, ba.length + 1, ba.length);
+ }});
+ tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ ByteBuffer.wrap(ba, 0, -1);
+ }});
+ tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ ByteBuffer.wrap(ba, 0, ba.length + 1);
+ }});
+
+ // A NullPointerException will be thrown if the array is null.
+ tryCatch(ba, NullPointerException.class, new Runnable() {
+ public void run() {
+ ByteBuffer.wrap((byte []) null, 0, 5);
+ }});
+ tryCatch(ba, NullPointerException.class, new Runnable() {
+ public void run() {
+ ByteBuffer.wrap((byte []) null);
+ }});
+ }
+
+ private static void testAllocate() {
+ // An IllegalArgumentException will be thrown for negative capacities.
+ tryCatch((Buffer) null, IllegalArgumentException.class, new Runnable() {
+ public void run() {
+ ByteBuffer.allocate(-1);
+ }});
+
+ tryCatch((Buffer) null, IllegalArgumentException.class, new Runnable() {
+ public void run() {
+ ByteBuffer.allocateDirect(-1);
+ }});
+
+ }
+
+ public static void test() {
+ testAllocate();
+ test(0, ByteBuffer.allocate(7 * 1024), false);
+ test(0, ByteBuffer.wrap(new byte[7 * 1024], 0, 7 * 1024), false);
+ test(new byte[1024]);
+
+ ByteBuffer b = ByteBuffer.allocateDirect(7 * 1024);
+ for (b.position(0); b.position() < b.limit(); )
+ ck(b, b.get(), 0);
+ test(0, b, true);
+
+
+
+
+
+ callReset(ByteBuffer.allocate(10));
+
+
+
+
+
+ }
+
+}
diff --git a/test/java/nio/Buffer/BasicChar.java b/test/java/nio/Buffer/BasicChar.java
new file mode 100644
index 0000000..10111cc
--- /dev/null
+++ b/test/java/nio/Buffer/BasicChar.java
@@ -0,0 +1,828 @@
+/*
+ * Copyright 2000-2007 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/* Type-specific source code for unit test
+ *
+ * Regenerate the BasicX classes via genBasic.sh whenever this file changes.
+ * We check in the generated source files so that the test tree can be used
+ * independently of the rest of the source tree.
+ */
+
+// -- This file was mechanically generated: Do not edit! -- //
+
+import java.nio.*;
+
+
+public class BasicChar
+ extends Basic
+{
+
+ private static void relGet(CharBuffer b) {
+ int n = b.capacity();
+ char v;
+ for (int i = 0; i < n; i++)
+ ck(b, (long)b.get(), (long)((char)ic(i)));
+ b.rewind();
+ }
+
+ private static void relGet(CharBuffer b, int start) {
+ int n = b.remaining();
+ char v;
+ for (int i = start; i < n; i++)
+ ck(b, (long)b.get(), (long)((char)ic(i)));
+ b.rewind();
+ }
+
+ private static void absGet(CharBuffer b) {
+ int n = b.capacity();
+ char v;
+ for (int i = 0; i < n; i++)
+ ck(b, (long)b.get(), (long)((char)ic(i)));
+ b.rewind();
+ }
+
+ private static void bulkGet(CharBuffer b) {
+ int n = b.capacity();
+ char[] a = new char[n + 7];
+ b.get(a, 7, n);
+ for (int i = 0; i < n; i++)
+ ck(b, (long)a[i + 7], (long)((char)ic(i)));
+ }
+
+ private static void relPut(CharBuffer b) {
+ int n = b.capacity();
+ b.clear();
+ for (int i = 0; i < n; i++)
+ b.put((char)ic(i));
+ b.flip();
+ }
+
+ private static void absPut(CharBuffer b) {
+ int n = b.capacity();
+ b.clear();
+ for (int i = 0; i < n; i++)
+ b.put(i, (char)ic(i));
+ b.limit(n);
+ b.position(0);
+ }
+
+ private static void bulkPutArray(CharBuffer b) {
+ int n = b.capacity();
+ b.clear();
+ char[] a = new char[n + 7];
+ for (int i = 0; i < n; i++)
+ a[i + 7] = (char)ic(i);
+ b.put(a, 7, n);
+ b.flip();
+ }
+
+ private static void bulkPutBuffer(CharBuffer b) {
+ int n = b.capacity();
+ b.clear();
+ CharBuffer c = CharBuffer.allocate(n + 7);
+ c.position(7);
+ for (int i = 0; i < n; i++)
+ c.put((char)ic(i));
+ c.flip();
+ c.position(7);
+ b.put(c);
+ b.flip();
+ }
+
+ //6231529
+ private static void callReset(CharBuffer b) {
+ b.position(0);
+ b.mark();
+
+ b.duplicate().reset();
+ b.asReadOnlyBuffer().reset();
+ }
+
+
+
+ // 6221101-6234263
+
+ private static void putBuffer() {
+ final int cap = 10;
+
+ CharBuffer direct1 = ByteBuffer.allocateDirect(cap).asCharBuffer();
+ CharBuffer nondirect1 = ByteBuffer.allocate(cap).asCharBuffer();
+ direct1.put(nondirect1);
+
+ CharBuffer direct2 = ByteBuffer.allocateDirect(cap).asCharBuffer();
+ CharBuffer nondirect2 = ByteBuffer.allocate(cap).asCharBuffer();
+ nondirect2.put(direct2);
+
+ CharBuffer direct3 = ByteBuffer.allocateDirect(cap).asCharBuffer();
+ CharBuffer direct4 = ByteBuffer.allocateDirect(cap).asCharBuffer();
+ direct3.put(direct4);
+
+ CharBuffer nondirect3 = ByteBuffer.allocate(cap).asCharBuffer();
+ CharBuffer nondirect4 = ByteBuffer.allocate(cap).asCharBuffer();
+ nondirect3.put(nondirect4);
+ }
+
+
+
+
+ private static void bulkPutString(CharBuffer b) {
+ int n = b.capacity();
+ b.clear();
+ StringBuffer sb = new StringBuffer(n + 7);
+ sb.append("1234567");
+ for (int i = 0; i < n; i++)
+ sb.append((char)ic(i));
+ b.put(sb.toString(), 7, 7 + n);
+ b.flip();
+ }
+
+
+
+ private static void checkSlice(CharBuffer b, CharBuffer slice) {
+ ck(slice, 0, slice.position());
+ ck(slice, b.remaining(), slice.limit());
+ ck(slice, b.remaining(), slice.capacity());
+ if (b.isDirect() != slice.isDirect())
+ fail("Lost direction", slice);
+ if (b.isReadOnly() != slice.isReadOnly())
+ fail("Lost read-only", slice);
+ }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ private static void tryCatch(Buffer b, Class ex, Runnable thunk) {
+ boolean caught = false;
+ try {
+ thunk.run();
+ } catch (Throwable x) {
+ if (ex.isAssignableFrom(x.getClass()))
+ caught = true;
+ }
+ if (!caught)
+ fail(ex.getName() + " not thrown", b);
+ }
+
+ private static void tryCatch(char [] t, Class ex, Runnable thunk) {
+ tryCatch(CharBuffer.wrap(t), ex, thunk);
+ }
+
+ public static void test(int level, final CharBuffer b, boolean direct) {
+
+ show(level, b);
+
+ if (direct != b.isDirect())
+ fail("Wrong direction", b);
+
+ // Gets and puts
+
+ relPut(b);
+ relGet(b);
+ absGet(b);
+ bulkGet(b);
+
+ absPut(b);
+ relGet(b);
+ absGet(b);
+ bulkGet(b);
+
+ bulkPutArray(b);
+ relGet(b);
+
+ bulkPutBuffer(b);
+ relGet(b);
+
+
+
+ bulkPutString(b);
+ relGet(b);
+ b.position(1);
+ b.limit(7);
+ ck(b, b.toString().equals("bcdefg"));
+
+ // CharSequence ops
+
+ b.position(2);
+ ck(b, b.charAt(1), 'd');
+ CharBuffer c = (CharBuffer)b.subSequence(1, 4);
+ ck(b, b.subSequence(1, 4).toString().equals("def"));
+
+ // 4938424
+ b.position(4);
+ ck(b, b.charAt(1), 'f');
+ ck(b, b.subSequence(1, 3).toString().equals("fg"));
+
+
+
+ // Compact
+
+ relPut(b);
+ b.position(13);
+ b.compact();
+ b.flip();
+ relGet(b, 13);
+
+ // Exceptions
+
+ boolean caught = false;
+ relPut(b);
+ b.limit(b.capacity() / 2);
+ b.position(b.limit());
+
+ tryCatch(b, BufferUnderflowException.class, new Runnable() {
+ public void run() {
+ b.get();
+ }});
+
+ tryCatch(b, BufferOverflowException.class, new Runnable() {
+ public void run() {
+ b.put((char)42);
+ }});
+
+ // The index must be non-negative and lesss than the buffer's limit.
+ tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ b.get(b.limit());
+ }});
+ tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ b.get(-1);
+ }});
+
+ tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ b.put(b.limit(), (char)42);
+ }});
+
+ // Values
+
+ b.clear();
+ b.put((char)0);
+ b.put((char)-1);
+ b.put((char)1);
+ b.put(Character.MAX_VALUE);
+ b.put(Character.MIN_VALUE);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ char v;
+ b.flip();
+ ck(b, b.get(), 0);
+ ck(b, b.get(), (char)-1);
+ ck(b, b.get(), 1);
+ ck(b, b.get(), Character.MAX_VALUE);
+ ck(b, b.get(), Character.MIN_VALUE);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ // Comparison
+ b.rewind();
+ CharBuffer b2 = CharBuffer.allocate(b.capacity());
+ b2.put(b);
+ b2.flip();
+ b.position(2);
+ b2.position(2);
+ if (!b.equals(b2)) {
+ for (int i = 2; i < b.limit(); i++) {
+ char x = b.get(i);
+ char y = b2.get(i);
+ if (x != y
+
+
+
+
+
+
+ )
+ out.println("[" + i + "] " + x + " != " + y);
+ }
+ fail("Identical buffers not equal", b, b2);
+ }
+ if (b.compareTo(b2) != 0)
+ fail("Comparison to identical buffer != 0", b, b2);
+
+ b.limit(b.limit() + 1);
+ b.position(b.limit() - 1);
+ b.put((char)99);
+ b.rewind();
+ b2.rewind();
+ if (b.equals(b2))
+ fail("Non-identical buffers equal", b, b2);
+ if (b.compareTo(b2) <= 0)
+ fail("Comparison to shorter buffer <= 0", b, b2);
+ b.limit(b.limit() - 1);
+
+ b.put(2, (char)42);
+ if (b.equals(b2))
+ fail("Non-identical buffers equal", b, b2);
+ if (b.compareTo(b2) <= 0)
+ fail("Comparison to lesser buffer <= 0", b, b2);
+
+ // Sub, dup
+
+ relPut(b);
+ relGet(b.duplicate());
+ b.position(13);
+ relGet(b.duplicate(), 13);
+ relGet(b.duplicate().slice(), 13);
+ relGet(b.slice(), 13);
+ relGet(b.slice().duplicate(), 13);
+
+ // Slice
+
+ b.position(5);
+ CharBuffer sb = b.slice();
+ checkSlice(b, sb);
+ b.position(0);
+ CharBuffer sb2 = sb.slice();
+ checkSlice(sb, sb2);
+
+ if (!sb.equals(sb2))
+ fail("Sliced slices do not match", sb, sb2);
+ if ((sb.hasArray()) && (sb.arrayOffset() != sb2.arrayOffset()))
+ fail("Array offsets do not match: "
+ + sb.arrayOffset() + " != " + sb2.arrayOffset(), sb, sb2);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ // Read-only views
+
+ b.rewind();
+ final CharBuffer rb = b.asReadOnlyBuffer();
+ if (!b.equals(rb))
+ fail("Buffer not equal to read-only view", b, rb);
+ show(level + 1, rb);
+
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ relPut(rb);
+ }});
+
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ absPut(rb);
+ }});
+
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ bulkPutArray(rb);
+ }});
+
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ bulkPutBuffer(rb);
+ }});
+
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ rb.compact();
+ }});
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ if (rb.getClass().getName().startsWith("java.nio.Heap")) {
+
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ rb.array();
+ }});
+
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ rb.arrayOffset();
+ }});
+
+ if (rb.hasArray())
+ fail("Read-only heap buffer's backing array is accessible",
+ rb);
+
+ }
+
+ // Bulk puts from read-only buffers
+
+ b.clear();
+ rb.rewind();
+ b.put(rb);
+
+
+
+
+
+
+
+
+
+
+
+ relPut(b); // Required by testViews
+
+ }
+
+
+
+ private static void testStr() {
+ final String s = "abcdefghijklm";
+ int start = 3;
+ int end = 9;
+ final CharBuffer b = CharBuffer.wrap(s, start, end);
+ show(0, b);
+ ck(b, b.toString().equals(s.substring(start, end)));
+ ck(b, b.toString().equals("defghi"));
+ ck(b, b.isReadOnly());
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ b.put('x');
+ }});
+ ck(b, start, b.position());
+ ck(b, end, b.limit());
+ ck(b, s.length(), b.capacity());
+
+ // The index, relative to the position, must be non-negative and
+ // smaller than remaining().
+ tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ b.charAt(-1);
+ }});
+ tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ b.charAt(b.remaining());
+ }});
+
+ // The index must be non-negative and less than the buffer's limit.
+ tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ b.get(b.limit());
+ }});
+ tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ b.get(-1);
+ }});
+
+ // The start must be non-negative and no larger than remaining().
+ tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ b.subSequence(-1, b.remaining());
+ }});
+ tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ b.subSequence(b.remaining() + 1, b.remaining());
+ }});
+
+ // The end must be no smaller than start and no larger than
+ // remaining().
+ tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ b.subSequence(2, 1);
+ }});
+ tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ b.subSequence(0, b.remaining() + 1);
+ }});
+
+ // The offset must be non-negative and no larger than <array.length>.
+ tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ CharBuffer.wrap(s, -1, s.length());
+ }});
+ tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ CharBuffer.wrap(s, s.length() + 1, s.length());
+ }});
+ tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ CharBuffer.wrap(s, 1, 0);
+ }});
+ tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ CharBuffer.wrap(s, 0, s.length() + 1);
+ }});
+ }
+
+
+
+ public static void test(final char [] ba) {
+ int offset = 47;
+ int length = 900;
+ final CharBuffer b = CharBuffer.wrap(ba, offset, length);
+ show(0, b);
+ ck(b, b.capacity(), ba.length);
+ ck(b, b.position(), offset);
+ ck(b, b.limit(), offset + length);
+
+ // The offset must be non-negative and no larger than <array.length>.
+ tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ CharBuffer.wrap(ba, -1, ba.length);
+ }});
+ tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ CharBuffer.wrap(ba, ba.length + 1, ba.length);
+ }});
+ tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ CharBuffer.wrap(ba, 0, -1);
+ }});
+ tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ CharBuffer.wrap(ba, 0, ba.length + 1);
+ }});
+
+ // A NullPointerException will be thrown if the array is null.
+ tryCatch(ba, NullPointerException.class, new Runnable() {
+ public void run() {
+ CharBuffer.wrap((char []) null, 0, 5);
+ }});
+ tryCatch(ba, NullPointerException.class, new Runnable() {
+ public void run() {
+ CharBuffer.wrap((char []) null);
+ }});
+ }
+
+ private static void testAllocate() {
+ // An IllegalArgumentException will be thrown for negative capacities.
+ tryCatch((Buffer) null, IllegalArgumentException.class, new Runnable() {
+ public void run() {
+ CharBuffer.allocate(-1);
+ }});
+
+
+
+
+
+
+ }
+
+ public static void test() {
+ testAllocate();
+ test(0, CharBuffer.allocate(7 * 1024), false);
+ test(0, CharBuffer.wrap(new char[7 * 1024], 0, 7 * 1024), false);
+ test(new char[1024]);
+
+
+
+
+
+
+
+ testStr();
+
+
+ callReset(CharBuffer.allocate(10));
+
+
+
+ putBuffer();
+
+ }
+
+}
diff --git a/test/java/nio/Buffer/BasicDouble.java b/test/java/nio/Buffer/BasicDouble.java
new file mode 100644
index 0000000..3da2396
--- /dev/null
+++ b/test/java/nio/Buffer/BasicDouble.java
@@ -0,0 +1,828 @@
+/*
+ * Copyright 2000-2007 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/* Type-specific source code for unit test
+ *
+ * Regenerate the BasicX classes via genBasic.sh whenever this file changes.
+ * We check in the generated source files so that the test tree can be used
+ * independently of the rest of the source tree.
+ */
+
+// -- This file was mechanically generated: Do not edit! -- //
+
+import java.nio.*;
+
+
+public class BasicDouble
+ extends Basic
+{
+
+ private static void relGet(DoubleBuffer b) {
+ int n = b.capacity();
+ double v;
+ for (int i = 0; i < n; i++)
+ ck(b, (long)b.get(), (long)((double)ic(i)));
+ b.rewind();
+ }
+
+ private static void relGet(DoubleBuffer b, int start) {
+ int n = b.remaining();
+ double v;
+ for (int i = start; i < n; i++)
+ ck(b, (long)b.get(), (long)((double)ic(i)));
+ b.rewind();
+ }
+
+ private static void absGet(DoubleBuffer b) {
+ int n = b.capacity();
+ double v;
+ for (int i = 0; i < n; i++)
+ ck(b, (long)b.get(), (long)((double)ic(i)));
+ b.rewind();
+ }
+
+ private static void bulkGet(DoubleBuffer b) {
+ int n = b.capacity();
+ double[] a = new double[n + 7];
+ b.get(a, 7, n);
+ for (int i = 0; i < n; i++)
+ ck(b, (long)a[i + 7], (long)((double)ic(i)));
+ }
+
+ private static void relPut(DoubleBuffer b) {
+ int n = b.capacity();
+ b.clear();
+ for (int i = 0; i < n; i++)
+ b.put((double)ic(i));
+ b.flip();
+ }
+
+ private static void absPut(DoubleBuffer b) {
+ int n = b.capacity();
+ b.clear();
+ for (int i = 0; i < n; i++)
+ b.put(i, (double)ic(i));
+ b.limit(n);
+ b.position(0);
+ }
+
+ private static void bulkPutArray(DoubleBuffer b) {
+ int n = b.capacity();
+ b.clear();
+ double[] a = new double[n + 7];
+ for (int i = 0; i < n; i++)
+ a[i + 7] = (double)ic(i);
+ b.put(a, 7, n);
+ b.flip();
+ }
+
+ private static void bulkPutBuffer(DoubleBuffer b) {
+ int n = b.capacity();
+ b.clear();
+ DoubleBuffer c = DoubleBuffer.allocate(n + 7);
+ c.position(7);
+ for (int i = 0; i < n; i++)
+ c.put((double)ic(i));
+ c.flip();
+ c.position(7);
+ b.put(c);
+ b.flip();
+ }
+
+ //6231529
+ private static void callReset(DoubleBuffer b) {
+ b.position(0);
+ b.mark();
+
+ b.duplicate().reset();
+ b.asReadOnlyBuffer().reset();
+ }
+
+
+
+ // 6221101-6234263
+
+ private static void putBuffer() {
+ final int cap = 10;
+
+ DoubleBuffer direct1 = ByteBuffer.allocateDirect(cap).asDoubleBuffer();
+ DoubleBuffer nondirect1 = ByteBuffer.allocate(cap).asDoubleBuffer();
+ direct1.put(nondirect1);
+
+ DoubleBuffer direct2 = ByteBuffer.allocateDirect(cap).asDoubleBuffer();
+ DoubleBuffer nondirect2 = ByteBuffer.allocate(cap).asDoubleBuffer();
+ nondirect2.put(direct2);
+
+ DoubleBuffer direct3 = ByteBuffer.allocateDirect(cap).asDoubleBuffer();
+ DoubleBuffer direct4 = ByteBuffer.allocateDirect(cap).asDoubleBuffer();
+ direct3.put(direct4);
+
+ DoubleBuffer nondirect3 = ByteBuffer.allocate(cap).asDoubleBuffer();
+ DoubleBuffer nondirect4 = ByteBuffer.allocate(cap).asDoubleBuffer();
+ nondirect3.put(nondirect4);
+ }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ private static void checkSlice(DoubleBuffer b, DoubleBuffer slice) {
+ ck(slice, 0, slice.position());
+ ck(slice, b.remaining(), slice.limit());
+ ck(slice, b.remaining(), slice.capacity());
+ if (b.isDirect() != slice.isDirect())
+ fail("Lost direction", slice);
+ if (b.isReadOnly() != slice.isReadOnly())
+ fail("Lost read-only", slice);
+ }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ private static void tryCatch(Buffer b, Class ex, Runnable thunk) {
+ boolean caught = false;
+ try {
+ thunk.run();
+ } catch (Throwable x) {
+ if (ex.isAssignableFrom(x.getClass()))
+ caught = true;
+ }
+ if (!caught)
+ fail(ex.getName() + " not thrown", b);
+ }
+
+ private static void tryCatch(double [] t, Class ex, Runnable thunk) {
+ tryCatch(DoubleBuffer.wrap(t), ex, thunk);
+ }
+
+ public static void test(int level, final DoubleBuffer b, boolean direct) {
+
+ show(level, b);
+
+ if (direct != b.isDirect())
+ fail("Wrong direction", b);
+
+ // Gets and puts
+
+ relPut(b);
+ relGet(b);
+ absGet(b);
+ bulkGet(b);
+
+ absPut(b);
+ relGet(b);
+ absGet(b);
+ bulkGet(b);
+
+ bulkPutArray(b);
+ relGet(b);
+
+ bulkPutBuffer(b);
+ relGet(b);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ // Compact
+
+ relPut(b);
+ b.position(13);
+ b.compact();
+ b.flip();
+ relGet(b, 13);
+
+ // Exceptions
+
+ boolean caught = false;
+ relPut(b);
+ b.limit(b.capacity() / 2);
+ b.position(b.limit());
+
+ tryCatch(b, BufferUnderflowException.class, new Runnable() {
+ public void run() {
+ b.get();
+ }});
+
+ tryCatch(b, BufferOverflowException.class, new Runnable() {
+ public void run() {
+ b.put((double)42);
+ }});
+
+ // The index must be non-negative and lesss than the buffer's limit.
+ tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ b.get(b.limit());
+ }});
+ tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ b.get(-1);
+ }});
+
+ tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ b.put(b.limit(), (double)42);
+ }});
+
+ // Values
+
+ b.clear();
+ b.put((double)0);
+ b.put((double)-1);
+ b.put((double)1);
+ b.put(Double.MAX_VALUE);
+ b.put(Double.MIN_VALUE);
+
+
+
+
+
+
+
+
+
+ b.put(-Double.MAX_VALUE);
+ b.put(-Double.MIN_VALUE);
+ b.put(Double.NEGATIVE_INFINITY);
+ b.put(Double.POSITIVE_INFINITY);
+ b.put(Double.NaN);
+ b.put(0.5121609353879392); // Changes value if incorrectly swapped
+
+
+ double v;
+ b.flip();
+ ck(b, b.get(), 0);
+ ck(b, b.get(), (double)-1);
+ ck(b, b.get(), 1);
+ ck(b, b.get(), Double.MAX_VALUE);
+ ck(b, b.get(), Double.MIN_VALUE);
+
+
+
+
+
+
+
+
+
+
+
+ ck(b, b.get(), -Double.MAX_VALUE);
+ ck(b, b.get(), -Double.MIN_VALUE);
+ ck(b, b.get(), Double.NEGATIVE_INFINITY);
+ ck(b, b.get(), Double.POSITIVE_INFINITY);
+ if (Double.doubleToRawLongBits(v = b.get())
+ != Double.doubleToRawLongBits(Double.NaN))
+ fail(b, (long)Double.NaN, (long)v);
+ ck(b, b.get(), 0.5121609353879392);
+
+
+
+ // Comparison
+ b.rewind();
+ DoubleBuffer b2 = DoubleBuffer.allocate(b.capacity());
+ b2.put(b);
+ b2.flip();
+ b.position(2);
+ b2.position(2);
+ if (!b.equals(b2)) {
+ for (int i = 2; i < b.limit(); i++) {
+ double x = b.get(i);
+ double y = b2.get(i);
+ if (x != y
+
+ || Double.compare(x, y) != 0
+
+
+
+
+ )
+ out.println("[" + i + "] " + x + " != " + y);
+ }
+ fail("Identical buffers not equal", b, b2);
+ }
+ if (b.compareTo(b2) != 0)
+ fail("Comparison to identical buffer != 0", b, b2);
+
+ b.limit(b.limit() + 1);
+ b.position(b.limit() - 1);
+ b.put((double)99);
+ b.rewind();
+ b2.rewind();
+ if (b.equals(b2))
+ fail("Non-identical buffers equal", b, b2);
+ if (b.compareTo(b2) <= 0)
+ fail("Comparison to shorter buffer <= 0", b, b2);
+ b.limit(b.limit() - 1);
+
+ b.put(2, (double)42);
+ if (b.equals(b2))
+ fail("Non-identical buffers equal", b, b2);
+ if (b.compareTo(b2) <= 0)
+ fail("Comparison to lesser buffer <= 0", b, b2);
+
+ // Sub, dup
+
+ relPut(b);
+ relGet(b.duplicate());
+ b.position(13);
+ relGet(b.duplicate(), 13);
+ relGet(b.duplicate().slice(), 13);
+ relGet(b.slice(), 13);
+ relGet(b.slice().duplicate(), 13);
+
+ // Slice
+
+ b.position(5);
+ DoubleBuffer sb = b.slice();
+ checkSlice(b, sb);
+ b.position(0);
+ DoubleBuffer sb2 = sb.slice();
+ checkSlice(sb, sb2);
+
+ if (!sb.equals(sb2))
+ fail("Sliced slices do not match", sb, sb2);
+ if ((sb.hasArray()) && (sb.arrayOffset() != sb2.arrayOffset()))
+ fail("Array offsets do not match: "
+ + sb.arrayOffset() + " != " + sb2.arrayOffset(), sb, sb2);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ // Read-only views
+
+ b.rewind();
+ final DoubleBuffer rb = b.asReadOnlyBuffer();
+ if (!b.equals(rb))
+ fail("Buffer not equal to read-only view", b, rb);
+ show(level + 1, rb);
+
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ relPut(rb);
+ }});
+
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ absPut(rb);
+ }});
+
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ bulkPutArray(rb);
+ }});
+
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ bulkPutBuffer(rb);
+ }});
+
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ rb.compact();
+ }});
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ if (rb.getClass().getName().startsWith("java.nio.Heap")) {
+
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ rb.array();
+ }});
+
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ rb.arrayOffset();
+ }});
+
+ if (rb.hasArray())
+ fail("Read-only heap buffer's backing array is accessible",
+ rb);
+
+ }
+
+ // Bulk puts from read-only buffers
+
+ b.clear();
+ rb.rewind();
+ b.put(rb);
+
+
+
+
+
+
+
+
+
+
+
+ relPut(b); // Required by testViews
+
+ }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ public static void test(final double [] ba) {
+ int offset = 47;
+ int length = 900;
+ final DoubleBuffer b = DoubleBuffer.wrap(ba, offset, length);
+ show(0, b);
+ ck(b, b.capacity(), ba.length);
+ ck(b, b.position(), offset);
+ ck(b, b.limit(), offset + length);
+
+ // The offset must be non-negative and no larger than <array.length>.
+ tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ DoubleBuffer.wrap(ba, -1, ba.length);
+ }});
+ tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ DoubleBuffer.wrap(ba, ba.length + 1, ba.length);
+ }});
+ tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ DoubleBuffer.wrap(ba, 0, -1);
+ }});
+ tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ DoubleBuffer.wrap(ba, 0, ba.length + 1);
+ }});
+
+ // A NullPointerException will be thrown if the array is null.
+ tryCatch(ba, NullPointerException.class, new Runnable() {
+ public void run() {
+ DoubleBuffer.wrap((double []) null, 0, 5);
+ }});
+ tryCatch(ba, NullPointerException.class, new Runnable() {
+ public void run() {
+ DoubleBuffer.wrap((double []) null);
+ }});
+ }
+
+ private static void testAllocate() {
+ // An IllegalArgumentException will be thrown for negative capacities.
+ tryCatch((Buffer) null, IllegalArgumentException.class, new Runnable() {
+ public void run() {
+ DoubleBuffer.allocate(-1);
+ }});
+
+
+
+
+
+
+ }
+
+ public static void test() {
+ testAllocate();
+ test(0, DoubleBuffer.allocate(7 * 1024), false);
+ test(0, DoubleBuffer.wrap(new double[7 * 1024], 0, 7 * 1024), false);
+ test(new double[1024]);
+
+
+
+
+
+
+
+
+
+
+ callReset(DoubleBuffer.allocate(10));
+
+
+
+ putBuffer();
+
+ }
+
+}
diff --git a/test/java/nio/Buffer/BasicFloat.java b/test/java/nio/Buffer/BasicFloat.java
new file mode 100644
index 0000000..9bd702b
--- /dev/null
+++ b/test/java/nio/Buffer/BasicFloat.java
@@ -0,0 +1,828 @@
+/*
+ * Copyright 2000-2007 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/* Type-specific source code for unit test
+ *
+ * Regenerate the BasicX classes via genBasic.sh whenever this file changes.
+ * We check in the generated source files so that the test tree can be used
+ * independently of the rest of the source tree.
+ */
+
+// -- This file was mechanically generated: Do not edit! -- //
+
+import java.nio.*;
+
+
+public class BasicFloat
+ extends Basic
+{
+
+ private static void relGet(FloatBuffer b) {
+ int n = b.capacity();
+ float v;
+ for (int i = 0; i < n; i++)
+ ck(b, (long)b.get(), (long)((float)ic(i)));
+ b.rewind();
+ }
+
+ private static void relGet(FloatBuffer b, int start) {
+ int n = b.remaining();
+ float v;
+ for (int i = start; i < n; i++)
+ ck(b, (long)b.get(), (long)((float)ic(i)));
+ b.rewind();
+ }
+
+ private static void absGet(FloatBuffer b) {
+ int n = b.capacity();
+ float v;
+ for (int i = 0; i < n; i++)
+ ck(b, (long)b.get(), (long)((float)ic(i)));
+ b.rewind();
+ }
+
+ private static void bulkGet(FloatBuffer b) {
+ int n = b.capacity();
+ float[] a = new float[n + 7];
+ b.get(a, 7, n);
+ for (int i = 0; i < n; i++)
+ ck(b, (long)a[i + 7], (long)((float)ic(i)));
+ }
+
+ private static void relPut(FloatBuffer b) {
+ int n = b.capacity();
+ b.clear();
+ for (int i = 0; i < n; i++)
+ b.put((float)ic(i));
+ b.flip();
+ }
+
+ private static void absPut(FloatBuffer b) {
+ int n = b.capacity();
+ b.clear();
+ for (int i = 0; i < n; i++)
+ b.put(i, (float)ic(i));
+ b.limit(n);
+ b.position(0);
+ }
+
+ private static void bulkPutArray(FloatBuffer b) {
+ int n = b.capacity();
+ b.clear();
+ float[] a = new float[n + 7];
+ for (int i = 0; i < n; i++)
+ a[i + 7] = (float)ic(i);
+ b.put(a, 7, n);
+ b.flip();
+ }
+
+ private static void bulkPutBuffer(FloatBuffer b) {
+ int n = b.capacity();
+ b.clear();
+ FloatBuffer c = FloatBuffer.allocate(n + 7);
+ c.position(7);
+ for (int i = 0; i < n; i++)
+ c.put((float)ic(i));
+ c.flip();
+ c.position(7);
+ b.put(c);
+ b.flip();
+ }
+
+ //6231529
+ private static void callReset(FloatBuffer b) {
+ b.position(0);
+ b.mark();
+
+ b.duplicate().reset();
+ b.asReadOnlyBuffer().reset();
+ }
+
+
+
+ // 6221101-6234263
+
+ private static void putBuffer() {
+ final int cap = 10;
+
+ FloatBuffer direct1 = ByteBuffer.allocateDirect(cap).asFloatBuffer();
+ FloatBuffer nondirect1 = ByteBuffer.allocate(cap).asFloatBuffer();
+ direct1.put(nondirect1);
+
+ FloatBuffer direct2 = ByteBuffer.allocateDirect(cap).asFloatBuffer();
+ FloatBuffer nondirect2 = ByteBuffer.allocate(cap).asFloatBuffer();
+ nondirect2.put(direct2);
+
+ FloatBuffer direct3 = ByteBuffer.allocateDirect(cap).asFloatBuffer();
+ FloatBuffer direct4 = ByteBuffer.allocateDirect(cap).asFloatBuffer();
+ direct3.put(direct4);
+
+ FloatBuffer nondirect3 = ByteBuffer.allocate(cap).asFloatBuffer();
+ FloatBuffer nondirect4 = ByteBuffer.allocate(cap).asFloatBuffer();
+ nondirect3.put(nondirect4);
+ }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ private static void checkSlice(FloatBuffer b, FloatBuffer slice) {
+ ck(slice, 0, slice.position());
+ ck(slice, b.remaining(), slice.limit());
+ ck(slice, b.remaining(), slice.capacity());
+ if (b.isDirect() != slice.isDirect())
+ fail("Lost direction", slice);
+ if (b.isReadOnly() != slice.isReadOnly())
+ fail("Lost read-only", slice);
+ }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ private static void tryCatch(Buffer b, Class ex, Runnable thunk) {
+ boolean caught = false;
+ try {
+ thunk.run();
+ } catch (Throwable x) {
+ if (ex.isAssignableFrom(x.getClass()))
+ caught = true;
+ }
+ if (!caught)
+ fail(ex.getName() + " not thrown", b);
+ }
+
+ private static void tryCatch(float [] t, Class ex, Runnable thunk) {
+ tryCatch(FloatBuffer.wrap(t), ex, thunk);
+ }
+
+ public static void test(int level, final FloatBuffer b, boolean direct) {
+
+ show(level, b);
+
+ if (direct != b.isDirect())
+ fail("Wrong direction", b);
+
+ // Gets and puts
+
+ relPut(b);
+ relGet(b);
+ absGet(b);
+ bulkGet(b);
+
+ absPut(b);
+ relGet(b);
+ absGet(b);
+ bulkGet(b);
+
+ bulkPutArray(b);
+ relGet(b);
+
+ bulkPutBuffer(b);
+ relGet(b);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ // Compact
+
+ relPut(b);
+ b.position(13);
+ b.compact();
+ b.flip();
+ relGet(b, 13);
+
+ // Exceptions
+
+ boolean caught = false;
+ relPut(b);
+ b.limit(b.capacity() / 2);
+ b.position(b.limit());
+
+ tryCatch(b, BufferUnderflowException.class, new Runnable() {
+ public void run() {
+ b.get();
+ }});
+
+ tryCatch(b, BufferOverflowException.class, new Runnable() {
+ public void run() {
+ b.put((float)42);
+ }});
+
+ // The index must be non-negative and lesss than the buffer's limit.
+ tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ b.get(b.limit());
+ }});
+ tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ b.get(-1);
+ }});
+
+ tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ b.put(b.limit(), (float)42);
+ }});
+
+ // Values
+
+ b.clear();
+ b.put((float)0);
+ b.put((float)-1);
+ b.put((float)1);
+ b.put(Float.MAX_VALUE);
+ b.put(Float.MIN_VALUE);
+
+ b.put(-Float.MAX_VALUE);
+ b.put(-Float.MIN_VALUE);
+ b.put(Float.NEGATIVE_INFINITY);
+ b.put(Float.POSITIVE_INFINITY);
+ b.put(Float.NaN);
+ b.put(0.91697687f); // Changes value if incorrectly swapped
+
+
+
+
+
+
+
+
+
+
+ float v;
+ b.flip();
+ ck(b, b.get(), 0);
+ ck(b, b.get(), (float)-1);
+ ck(b, b.get(), 1);
+ ck(b, b.get(), Float.MAX_VALUE);
+ ck(b, b.get(), Float.MIN_VALUE);
+
+
+ ck(b, b.get(), -Float.MAX_VALUE);
+ ck(b, b.get(), -Float.MIN_VALUE);
+ ck(b, b.get(), Float.NEGATIVE_INFINITY);
+ ck(b, b.get(), Float.POSITIVE_INFINITY);
+ if (Float.floatToRawIntBits(v = b.get()) != Float.floatToRawIntBits(Float.NaN))
+ fail(b, (long)Float.NaN, (long)v);
+ ck(b, b.get(), 0.91697687f);
+
+
+
+
+
+
+
+
+
+
+
+
+
+ // Comparison
+ b.rewind();
+ FloatBuffer b2 = FloatBuffer.allocate(b.capacity());
+ b2.put(b);
+ b2.flip();
+ b.position(2);
+ b2.position(2);
+ if (!b.equals(b2)) {
+ for (int i = 2; i < b.limit(); i++) {
+ float x = b.get(i);
+ float y = b2.get(i);
+ if (x != y
+
+
+
+
+ || Float.compare(x, y) != 0
+
+ )
+ out.println("[" + i + "] " + x + " != " + y);
+ }
+ fail("Identical buffers not equal", b, b2);
+ }
+ if (b.compareTo(b2) != 0)
+ fail("Comparison to identical buffer != 0", b, b2);
+
+ b.limit(b.limit() + 1);
+ b.position(b.limit() - 1);
+ b.put((float)99);
+ b.rewind();
+ b2.rewind();
+ if (b.equals(b2))
+ fail("Non-identical buffers equal", b, b2);
+ if (b.compareTo(b2) <= 0)
+ fail("Comparison to shorter buffer <= 0", b, b2);
+ b.limit(b.limit() - 1);
+
+ b.put(2, (float)42);
+ if (b.equals(b2))
+ fail("Non-identical buffers equal", b, b2);
+ if (b.compareTo(b2) <= 0)
+ fail("Comparison to lesser buffer <= 0", b, b2);
+
+ // Sub, dup
+
+ relPut(b);
+ relGet(b.duplicate());
+ b.position(13);
+ relGet(b.duplicate(), 13);
+ relGet(b.duplicate().slice(), 13);
+ relGet(b.slice(), 13);
+ relGet(b.slice().duplicate(), 13);
+
+ // Slice
+
+ b.position(5);
+ FloatBuffer sb = b.slice();
+ checkSlice(b, sb);
+ b.position(0);
+ FloatBuffer sb2 = sb.slice();
+ checkSlice(sb, sb2);
+
+ if (!sb.equals(sb2))
+ fail("Sliced slices do not match", sb, sb2);
+ if ((sb.hasArray()) && (sb.arrayOffset() != sb2.arrayOffset()))
+ fail("Array offsets do not match: "
+ + sb.arrayOffset() + " != " + sb2.arrayOffset(), sb, sb2);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ // Read-only views
+
+ b.rewind();
+ final FloatBuffer rb = b.asReadOnlyBuffer();
+ if (!b.equals(rb))
+ fail("Buffer not equal to read-only view", b, rb);
+ show(level + 1, rb);
+
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ relPut(rb);
+ }});
+
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ absPut(rb);
+ }});
+
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ bulkPutArray(rb);
+ }});
+
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ bulkPutBuffer(rb);
+ }});
+
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ rb.compact();
+ }});
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ if (rb.getClass().getName().startsWith("java.nio.Heap")) {
+
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ rb.array();
+ }});
+
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ rb.arrayOffset();
+ }});
+
+ if (rb.hasArray())
+ fail("Read-only heap buffer's backing array is accessible",
+ rb);
+
+ }
+
+ // Bulk puts from read-only buffers
+
+ b.clear();
+ rb.rewind();
+ b.put(rb);
+
+
+
+
+
+
+
+
+
+
+
+ relPut(b); // Required by testViews
+
+ }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ public static void test(final float [] ba) {
+ int offset = 47;
+ int length = 900;
+ final FloatBuffer b = FloatBuffer.wrap(ba, offset, length);
+ show(0, b);
+ ck(b, b.capacity(), ba.length);
+ ck(b, b.position(), offset);
+ ck(b, b.limit(), offset + length);
+
+ // The offset must be non-negative and no larger than <array.length>.
+ tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ FloatBuffer.wrap(ba, -1, ba.length);
+ }});
+ tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ FloatBuffer.wrap(ba, ba.length + 1, ba.length);
+ }});
+ tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ FloatBuffer.wrap(ba, 0, -1);
+ }});
+ tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ FloatBuffer.wrap(ba, 0, ba.length + 1);
+ }});
+
+ // A NullPointerException will be thrown if the array is null.
+ tryCatch(ba, NullPointerException.class, new Runnable() {
+ public void run() {
+ FloatBuffer.wrap((float []) null, 0, 5);
+ }});
+ tryCatch(ba, NullPointerException.class, new Runnable() {
+ public void run() {
+ FloatBuffer.wrap((float []) null);
+ }});
+ }
+
+ private static void testAllocate() {
+ // An IllegalArgumentException will be thrown for negative capacities.
+ tryCatch((Buffer) null, IllegalArgumentException.class, new Runnable() {
+ public void run() {
+ FloatBuffer.allocate(-1);
+ }});
+
+
+
+
+
+
+ }
+
+ public static void test() {
+ testAllocate();
+ test(0, FloatBuffer.allocate(7 * 1024), false);
+ test(0, FloatBuffer.wrap(new float[7 * 1024], 0, 7 * 1024), false);
+ test(new float[1024]);
+
+
+
+
+
+
+
+
+
+
+ callReset(FloatBuffer.allocate(10));
+
+
+
+ putBuffer();
+
+ }
+
+}
diff --git a/test/java/nio/Buffer/BasicInt.java b/test/java/nio/Buffer/BasicInt.java
new file mode 100644
index 0000000..4a58871
--- /dev/null
+++ b/test/java/nio/Buffer/BasicInt.java
@@ -0,0 +1,828 @@
+/*
+ * Copyright 2000-2007 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/* Type-specific source code for unit test
+ *
+ * Regenerate the BasicX classes via genBasic.sh whenever this file changes.
+ * We check in the generated source files so that the test tree can be used
+ * independently of the rest of the source tree.
+ */
+
+// -- This file was mechanically generated: Do not edit! -- //
+
+import java.nio.*;
+
+
+public class BasicInt
+ extends Basic
+{
+
+ private static void relGet(IntBuffer b) {
+ int n = b.capacity();
+ int v;
+ for (int i = 0; i < n; i++)
+ ck(b, (long)b.get(), (long)((int)ic(i)));
+ b.rewind();
+ }
+
+ private static void relGet(IntBuffer b, int start) {
+ int n = b.remaining();
+ int v;
+ for (int i = start; i < n; i++)
+ ck(b, (long)b.get(), (long)((int)ic(i)));
+ b.rewind();
+ }
+
+ private static void absGet(IntBuffer b) {
+ int n = b.capacity();
+ int v;
+ for (int i = 0; i < n; i++)
+ ck(b, (long)b.get(), (long)((int)ic(i)));
+ b.rewind();
+ }
+
+ private static void bulkGet(IntBuffer b) {
+ int n = b.capacity();
+ int[] a = new int[n + 7];
+ b.get(a, 7, n);
+ for (int i = 0; i < n; i++)
+ ck(b, (long)a[i + 7], (long)((int)ic(i)));
+ }
+
+ private static void relPut(IntBuffer b) {
+ int n = b.capacity();
+ b.clear();
+ for (int i = 0; i < n; i++)
+ b.put((int)ic(i));
+ b.flip();
+ }
+
+ private static void absPut(IntBuffer b) {
+ int n = b.capacity();
+ b.clear();
+ for (int i = 0; i < n; i++)
+ b.put(i, (int)ic(i));
+ b.limit(n);
+ b.position(0);
+ }
+
+ private static void bulkPutArray(IntBuffer b) {
+ int n = b.capacity();
+ b.clear();
+ int[] a = new int[n + 7];
+ for (int i = 0; i < n; i++)
+ a[i + 7] = (int)ic(i);
+ b.put(a, 7, n);
+ b.flip();
+ }
+
+ private static void bulkPutBuffer(IntBuffer b) {
+ int n = b.capacity();
+ b.clear();
+ IntBuffer c = IntBuffer.allocate(n + 7);
+ c.position(7);
+ for (int i = 0; i < n; i++)
+ c.put((int)ic(i));
+ c.flip();
+ c.position(7);
+ b.put(c);
+ b.flip();
+ }
+
+ //6231529
+ private static void callReset(IntBuffer b) {
+ b.position(0);
+ b.mark();
+
+ b.duplicate().reset();
+ b.asReadOnlyBuffer().reset();
+ }
+
+
+
+ // 6221101-6234263
+
+ private static void putBuffer() {
+ final int cap = 10;
+
+ IntBuffer direct1 = ByteBuffer.allocateDirect(cap).asIntBuffer();
+ IntBuffer nondirect1 = ByteBuffer.allocate(cap).asIntBuffer();
+ direct1.put(nondirect1);
+
+ IntBuffer direct2 = ByteBuffer.allocateDirect(cap).asIntBuffer();
+ IntBuffer nondirect2 = ByteBuffer.allocate(cap).asIntBuffer();
+ nondirect2.put(direct2);
+
+ IntBuffer direct3 = ByteBuffer.allocateDirect(cap).asIntBuffer();
+ IntBuffer direct4 = ByteBuffer.allocateDirect(cap).asIntBuffer();
+ direct3.put(direct4);
+
+ IntBuffer nondirect3 = ByteBuffer.allocate(cap).asIntBuffer();
+ IntBuffer nondirect4 = ByteBuffer.allocate(cap).asIntBuffer();
+ nondirect3.put(nondirect4);
+ }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ private static void checkSlice(IntBuffer b, IntBuffer slice) {
+ ck(slice, 0, slice.position());
+ ck(slice, b.remaining(), slice.limit());
+ ck(slice, b.remaining(), slice.capacity());
+ if (b.isDirect() != slice.isDirect())
+ fail("Lost direction", slice);
+ if (b.isReadOnly() != slice.isReadOnly())
+ fail("Lost read-only", slice);
+ }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ private static void tryCatch(Buffer b, Class ex, Runnable thunk) {
+ boolean caught = false;
+ try {
+ thunk.run();
+ } catch (Throwable x) {
+ if (ex.isAssignableFrom(x.getClass()))
+ caught = true;
+ }
+ if (!caught)
+ fail(ex.getName() + " not thrown", b);
+ }
+
+ private static void tryCatch(int [] t, Class ex, Runnable thunk) {
+ tryCatch(IntBuffer.wrap(t), ex, thunk);
+ }
+
+ public static void test(int level, final IntBuffer b, boolean direct) {
+
+ show(level, b);
+
+ if (direct != b.isDirect())
+ fail("Wrong direction", b);
+
+ // Gets and puts
+
+ relPut(b);
+ relGet(b);
+ absGet(b);
+ bulkGet(b);
+
+ absPut(b);
+ relGet(b);
+ absGet(b);
+ bulkGet(b);
+
+ bulkPutArray(b);
+ relGet(b);
+
+ bulkPutBuffer(b);
+ relGet(b);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ // Compact
+
+ relPut(b);
+ b.position(13);
+ b.compact();
+ b.flip();
+ relGet(b, 13);
+
+ // Exceptions
+
+ boolean caught = false;
+ relPut(b);
+ b.limit(b.capacity() / 2);
+ b.position(b.limit());
+
+ tryCatch(b, BufferUnderflowException.class, new Runnable() {
+ public void run() {
+ b.get();
+ }});
+
+ tryCatch(b, BufferOverflowException.class, new Runnable() {
+ public void run() {
+ b.put((int)42);
+ }});
+
+ // The index must be non-negative and lesss than the buffer's limit.
+ tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ b.get(b.limit());
+ }});
+ tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ b.get(-1);
+ }});
+
+ tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ b.put(b.limit(), (int)42);
+ }});
+
+ // Values
+
+ b.clear();
+ b.put((int)0);
+ b.put((int)-1);
+ b.put((int)1);
+ b.put(Integer.MAX_VALUE);
+ b.put(Integer.MIN_VALUE);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ int v;
+ b.flip();
+ ck(b, b.get(), 0);
+ ck(b, b.get(), (int)-1);
+ ck(b, b.get(), 1);
+ ck(b, b.get(), Integer.MAX_VALUE);
+ ck(b, b.get(), Integer.MIN_VALUE);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ // Comparison
+ b.rewind();
+ IntBuffer b2 = IntBuffer.allocate(b.capacity());
+ b2.put(b);
+ b2.flip();
+ b.position(2);
+ b2.position(2);
+ if (!b.equals(b2)) {
+ for (int i = 2; i < b.limit(); i++) {
+ int x = b.get(i);
+ int y = b2.get(i);
+ if (x != y
+
+
+
+
+
+
+ )
+ out.println("[" + i + "] " + x + " != " + y);
+ }
+ fail("Identical buffers not equal", b, b2);
+ }
+ if (b.compareTo(b2) != 0)
+ fail("Comparison to identical buffer != 0", b, b2);
+
+ b.limit(b.limit() + 1);
+ b.position(b.limit() - 1);
+ b.put((int)99);
+ b.rewind();
+ b2.rewind();
+ if (b.equals(b2))
+ fail("Non-identical buffers equal", b, b2);
+ if (b.compareTo(b2) <= 0)
+ fail("Comparison to shorter buffer <= 0", b, b2);
+ b.limit(b.limit() - 1);
+
+ b.put(2, (int)42);
+ if (b.equals(b2))
+ fail("Non-identical buffers equal", b, b2);
+ if (b.compareTo(b2) <= 0)
+ fail("Comparison to lesser buffer <= 0", b, b2);
+
+ // Sub, dup
+
+ relPut(b);
+ relGet(b.duplicate());
+ b.position(13);
+ relGet(b.duplicate(), 13);
+ relGet(b.duplicate().slice(), 13);
+ relGet(b.slice(), 13);
+ relGet(b.slice().duplicate(), 13);
+
+ // Slice
+
+ b.position(5);
+ IntBuffer sb = b.slice();
+ checkSlice(b, sb);
+ b.position(0);
+ IntBuffer sb2 = sb.slice();
+ checkSlice(sb, sb2);
+
+ if (!sb.equals(sb2))
+ fail("Sliced slices do not match", sb, sb2);
+ if ((sb.hasArray()) && (sb.arrayOffset() != sb2.arrayOffset()))
+ fail("Array offsets do not match: "
+ + sb.arrayOffset() + " != " + sb2.arrayOffset(), sb, sb2);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ // Read-only views
+
+ b.rewind();
+ final IntBuffer rb = b.asReadOnlyBuffer();
+ if (!b.equals(rb))
+ fail("Buffer not equal to read-only view", b, rb);
+ show(level + 1, rb);
+
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ relPut(rb);
+ }});
+
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ absPut(rb);
+ }});
+
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ bulkPutArray(rb);
+ }});
+
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ bulkPutBuffer(rb);
+ }});
+
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ rb.compact();
+ }});
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ if (rb.getClass().getName().startsWith("java.nio.Heap")) {
+
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ rb.array();
+ }});
+
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ rb.arrayOffset();
+ }});
+
+ if (rb.hasArray())
+ fail("Read-only heap buffer's backing array is accessible",
+ rb);
+
+ }
+
+ // Bulk puts from read-only buffers
+
+ b.clear();
+ rb.rewind();
+ b.put(rb);
+
+
+
+
+
+
+
+
+
+
+
+ relPut(b); // Required by testViews
+
+ }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ public static void test(final int [] ba) {
+ int offset = 47;
+ int length = 900;
+ final IntBuffer b = IntBuffer.wrap(ba, offset, length);
+ show(0, b);
+ ck(b, b.capacity(), ba.length);
+ ck(b, b.position(), offset);
+ ck(b, b.limit(), offset + length);
+
+ // The offset must be non-negative and no larger than <array.length>.
+ tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ IntBuffer.wrap(ba, -1, ba.length);
+ }});
+ tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ IntBuffer.wrap(ba, ba.length + 1, ba.length);
+ }});
+ tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ IntBuffer.wrap(ba, 0, -1);
+ }});
+ tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ IntBuffer.wrap(ba, 0, ba.length + 1);
+ }});
+
+ // A NullPointerException will be thrown if the array is null.
+ tryCatch(ba, NullPointerException.class, new Runnable() {
+ public void run() {
+ IntBuffer.wrap((int []) null, 0, 5);
+ }});
+ tryCatch(ba, NullPointerException.class, new Runnable() {
+ public void run() {
+ IntBuffer.wrap((int []) null);
+ }});
+ }
+
+ private static void testAllocate() {
+ // An IllegalArgumentException will be thrown for negative capacities.
+ tryCatch((Buffer) null, IllegalArgumentException.class, new Runnable() {
+ public void run() {
+ IntBuffer.allocate(-1);
+ }});
+
+
+
+
+
+
+ }
+
+ public static void test() {
+ testAllocate();
+ test(0, IntBuffer.allocate(7 * 1024), false);
+ test(0, IntBuffer.wrap(new int[7 * 1024], 0, 7 * 1024), false);
+ test(new int[1024]);
+
+
+
+
+
+
+
+
+
+
+ callReset(IntBuffer.allocate(10));
+
+
+
+ putBuffer();
+
+ }
+
+}
diff --git a/test/java/nio/Buffer/BasicLong.java b/test/java/nio/Buffer/BasicLong.java
new file mode 100644
index 0000000..0ef145c
--- /dev/null
+++ b/test/java/nio/Buffer/BasicLong.java
@@ -0,0 +1,828 @@
+/*
+ * Copyright 2000-2007 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/* Type-specific source code for unit test
+ *
+ * Regenerate the BasicX classes via genBasic.sh whenever this file changes.
+ * We check in the generated source files so that the test tree can be used
+ * independently of the rest of the source tree.
+ */
+
+// -- This file was mechanically generated: Do not edit! -- //
+
+import java.nio.*;
+
+
+public class BasicLong
+ extends Basic
+{
+
+ private static void relGet(LongBuffer b) {
+ int n = b.capacity();
+ long v;
+ for (int i = 0; i < n; i++)
+ ck(b, (long)b.get(), (long)((long)ic(i)));
+ b.rewind();
+ }
+
+ private static void relGet(LongBuffer b, int start) {
+ int n = b.remaining();
+ long v;
+ for (int i = start; i < n; i++)
+ ck(b, (long)b.get(), (long)((long)ic(i)));
+ b.rewind();
+ }
+
+ private static void absGet(LongBuffer b) {
+ int n = b.capacity();
+ long v;
+ for (int i = 0; i < n; i++)
+ ck(b, (long)b.get(), (long)((long)ic(i)));
+ b.rewind();
+ }
+
+ private static void bulkGet(LongBuffer b) {
+ int n = b.capacity();
+ long[] a = new long[n + 7];
+ b.get(a, 7, n);
+ for (int i = 0; i < n; i++)
+ ck(b, (long)a[i + 7], (long)((long)ic(i)));
+ }
+
+ private static void relPut(LongBuffer b) {
+ int n = b.capacity();
+ b.clear();
+ for (int i = 0; i < n; i++)
+ b.put((long)ic(i));
+ b.flip();
+ }
+
+ private static void absPut(LongBuffer b) {
+ int n = b.capacity();
+ b.clear();
+ for (int i = 0; i < n; i++)
+ b.put(i, (long)ic(i));
+ b.limit(n);
+ b.position(0);
+ }
+
+ private static void bulkPutArray(LongBuffer b) {
+ int n = b.capacity();
+ b.clear();
+ long[] a = new long[n + 7];
+ for (int i = 0; i < n; i++)
+ a[i + 7] = (long)ic(i);
+ b.put(a, 7, n);
+ b.flip();
+ }
+
+ private static void bulkPutBuffer(LongBuffer b) {
+ int n = b.capacity();
+ b.clear();
+ LongBuffer c = LongBuffer.allocate(n + 7);
+ c.position(7);
+ for (int i = 0; i < n; i++)
+ c.put((long)ic(i));
+ c.flip();
+ c.position(7);
+ b.put(c);
+ b.flip();
+ }
+
+ //6231529
+ private static void callReset(LongBuffer b) {
+ b.position(0);
+ b.mark();
+
+ b.duplicate().reset();
+ b.asReadOnlyBuffer().reset();
+ }
+
+
+
+ // 6221101-6234263
+
+ private static void putBuffer() {
+ final int cap = 10;
+
+ LongBuffer direct1 = ByteBuffer.allocateDirect(cap).asLongBuffer();
+ LongBuffer nondirect1 = ByteBuffer.allocate(cap).asLongBuffer();
+ direct1.put(nondirect1);
+
+ LongBuffer direct2 = ByteBuffer.allocateDirect(cap).asLongBuffer();
+ LongBuffer nondirect2 = ByteBuffer.allocate(cap).asLongBuffer();
+ nondirect2.put(direct2);
+
+ LongBuffer direct3 = ByteBuffer.allocateDirect(cap).asLongBuffer();
+ LongBuffer direct4 = ByteBuffer.allocateDirect(cap).asLongBuffer();
+ direct3.put(direct4);
+
+ LongBuffer nondirect3 = ByteBuffer.allocate(cap).asLongBuffer();
+ LongBuffer nondirect4 = ByteBuffer.allocate(cap).asLongBuffer();
+ nondirect3.put(nondirect4);
+ }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ private static void checkSlice(LongBuffer b, LongBuffer slice) {
+ ck(slice, 0, slice.position());
+ ck(slice, b.remaining(), slice.limit());
+ ck(slice, b.remaining(), slice.capacity());
+ if (b.isDirect() != slice.isDirect())
+ fail("Lost direction", slice);
+ if (b.isReadOnly() != slice.isReadOnly())
+ fail("Lost read-only", slice);
+ }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ private static void tryCatch(Buffer b, Class ex, Runnable thunk) {
+ boolean caught = false;
+ try {
+ thunk.run();
+ } catch (Throwable x) {
+ if (ex.isAssignableFrom(x.getClass()))
+ caught = true;
+ }
+ if (!caught)
+ fail(ex.getName() + " not thrown", b);
+ }
+
+ private static void tryCatch(long [] t, Class ex, Runnable thunk) {
+ tryCatch(LongBuffer.wrap(t), ex, thunk);
+ }
+
+ public static void test(int level, final LongBuffer b, boolean direct) {
+
+ show(level, b);
+
+ if (direct != b.isDirect())
+ fail("Wrong direction", b);
+
+ // Gets and puts
+
+ relPut(b);
+ relGet(b);
+ absGet(b);
+ bulkGet(b);
+
+ absPut(b);
+ relGet(b);
+ absGet(b);
+ bulkGet(b);
+
+ bulkPutArray(b);
+ relGet(b);
+
+ bulkPutBuffer(b);
+ relGet(b);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ // Compact
+
+ relPut(b);
+ b.position(13);
+ b.compact();
+ b.flip();
+ relGet(b, 13);
+
+ // Exceptions
+
+ boolean caught = false;
+ relPut(b);
+ b.limit(b.capacity() / 2);
+ b.position(b.limit());
+
+ tryCatch(b, BufferUnderflowException.class, new Runnable() {
+ public void run() {
+ b.get();
+ }});
+
+ tryCatch(b, BufferOverflowException.class, new Runnable() {
+ public void run() {
+ b.put((long)42);
+ }});
+
+ // The index must be non-negative and lesss than the buffer's limit.
+ tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ b.get(b.limit());
+ }});
+ tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ b.get(-1);
+ }});
+
+ tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ b.put(b.limit(), (long)42);
+ }});
+
+ // Values
+
+ b.clear();
+ b.put((long)0);
+ b.put((long)-1);
+ b.put((long)1);
+ b.put(Long.MAX_VALUE);
+ b.put(Long.MIN_VALUE);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ long v;
+ b.flip();
+ ck(b, b.get(), 0);
+ ck(b, b.get(), (long)-1);
+ ck(b, b.get(), 1);
+ ck(b, b.get(), Long.MAX_VALUE);
+ ck(b, b.get(), Long.MIN_VALUE);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ // Comparison
+ b.rewind();
+ LongBuffer b2 = LongBuffer.allocate(b.capacity());
+ b2.put(b);
+ b2.flip();
+ b.position(2);
+ b2.position(2);
+ if (!b.equals(b2)) {
+ for (int i = 2; i < b.limit(); i++) {
+ long x = b.get(i);
+ long y = b2.get(i);
+ if (x != y
+
+
+
+
+
+
+ )
+ out.println("[" + i + "] " + x + " != " + y);
+ }
+ fail("Identical buffers not equal", b, b2);
+ }
+ if (b.compareTo(b2) != 0)
+ fail("Comparison to identical buffer != 0", b, b2);
+
+ b.limit(b.limit() + 1);
+ b.position(b.limit() - 1);
+ b.put((long)99);
+ b.rewind();
+ b2.rewind();
+ if (b.equals(b2))
+ fail("Non-identical buffers equal", b, b2);
+ if (b.compareTo(b2) <= 0)
+ fail("Comparison to shorter buffer <= 0", b, b2);
+ b.limit(b.limit() - 1);
+
+ b.put(2, (long)42);
+ if (b.equals(b2))
+ fail("Non-identical buffers equal", b, b2);
+ if (b.compareTo(b2) <= 0)
+ fail("Comparison to lesser buffer <= 0", b, b2);
+
+ // Sub, dup
+
+ relPut(b);
+ relGet(b.duplicate());
+ b.position(13);
+ relGet(b.duplicate(), 13);
+ relGet(b.duplicate().slice(), 13);
+ relGet(b.slice(), 13);
+ relGet(b.slice().duplicate(), 13);
+
+ // Slice
+
+ b.position(5);
+ LongBuffer sb = b.slice();
+ checkSlice(b, sb);
+ b.position(0);
+ LongBuffer sb2 = sb.slice();
+ checkSlice(sb, sb2);
+
+ if (!sb.equals(sb2))
+ fail("Sliced slices do not match", sb, sb2);
+ if ((sb.hasArray()) && (sb.arrayOffset() != sb2.arrayOffset()))
+ fail("Array offsets do not match: "
+ + sb.arrayOffset() + " != " + sb2.arrayOffset(), sb, sb2);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ // Read-only views
+
+ b.rewind();
+ final LongBuffer rb = b.asReadOnlyBuffer();
+ if (!b.equals(rb))
+ fail("Buffer not equal to read-only view", b, rb);
+ show(level + 1, rb);
+
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ relPut(rb);
+ }});
+
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ absPut(rb);
+ }});
+
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ bulkPutArray(rb);
+ }});
+
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ bulkPutBuffer(rb);
+ }});
+
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ rb.compact();
+ }});
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ if (rb.getClass().getName().startsWith("java.nio.Heap")) {
+
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ rb.array();
+ }});
+
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ rb.arrayOffset();
+ }});
+
+ if (rb.hasArray())
+ fail("Read-only heap buffer's backing array is accessible",
+ rb);
+
+ }
+
+ // Bulk puts from read-only buffers
+
+ b.clear();
+ rb.rewind();
+ b.put(rb);
+
+
+
+
+
+
+
+
+
+
+
+ relPut(b); // Required by testViews
+
+ }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ public static void test(final long [] ba) {
+ int offset = 47;
+ int length = 900;
+ final LongBuffer b = LongBuffer.wrap(ba, offset, length);
+ show(0, b);
+ ck(b, b.capacity(), ba.length);
+ ck(b, b.position(), offset);
+ ck(b, b.limit(), offset + length);
+
+ // The offset must be non-negative and no larger than <array.length>.
+ tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ LongBuffer.wrap(ba, -1, ba.length);
+ }});
+ tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ LongBuffer.wrap(ba, ba.length + 1, ba.length);
+ }});
+ tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ LongBuffer.wrap(ba, 0, -1);
+ }});
+ tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ LongBuffer.wrap(ba, 0, ba.length + 1);
+ }});
+
+ // A NullPointerException will be thrown if the array is null.
+ tryCatch(ba, NullPointerException.class, new Runnable() {
+ public void run() {
+ LongBuffer.wrap((long []) null, 0, 5);
+ }});
+ tryCatch(ba, NullPointerException.class, new Runnable() {
+ public void run() {
+ LongBuffer.wrap((long []) null);
+ }});
+ }
+
+ private static void testAllocate() {
+ // An IllegalArgumentException will be thrown for negative capacities.
+ tryCatch((Buffer) null, IllegalArgumentException.class, new Runnable() {
+ public void run() {
+ LongBuffer.allocate(-1);
+ }});
+
+
+
+
+
+
+ }
+
+ public static void test() {
+ testAllocate();
+ test(0, LongBuffer.allocate(7 * 1024), false);
+ test(0, LongBuffer.wrap(new long[7 * 1024], 0, 7 * 1024), false);
+ test(new long[1024]);
+
+
+
+
+
+
+
+
+
+
+ callReset(LongBuffer.allocate(10));
+
+
+
+ putBuffer();
+
+ }
+
+}
diff --git a/test/java/nio/Buffer/BasicShort.java b/test/java/nio/Buffer/BasicShort.java
new file mode 100644
index 0000000..42fe98b
--- /dev/null
+++ b/test/java/nio/Buffer/BasicShort.java
@@ -0,0 +1,828 @@
+/*
+ * Copyright 2000-2007 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/* Type-specific source code for unit test
+ *
+ * Regenerate the BasicX classes via genBasic.sh whenever this file changes.
+ * We check in the generated source files so that the test tree can be used
+ * independently of the rest of the source tree.
+ */
+
+// -- This file was mechanically generated: Do not edit! -- //
+
+import java.nio.*;
+
+
+public class BasicShort
+ extends Basic
+{
+
+ private static void relGet(ShortBuffer b) {
+ int n = b.capacity();
+ short v;
+ for (int i = 0; i < n; i++)
+ ck(b, (long)b.get(), (long)((short)ic(i)));
+ b.rewind();
+ }
+
+ private static void relGet(ShortBuffer b, int start) {
+ int n = b.remaining();
+ short v;
+ for (int i = start; i < n; i++)
+ ck(b, (long)b.get(), (long)((short)ic(i)));
+ b.rewind();
+ }
+
+ private static void absGet(ShortBuffer b) {
+ int n = b.capacity();
+ short v;
+ for (int i = 0; i < n; i++)
+ ck(b, (long)b.get(), (long)((short)ic(i)));
+ b.rewind();
+ }
+
+ private static void bulkGet(ShortBuffer b) {
+ int n = b.capacity();
+ short[] a = new short[n + 7];
+ b.get(a, 7, n);
+ for (int i = 0; i < n; i++)
+ ck(b, (long)a[i + 7], (long)((short)ic(i)));
+ }
+
+ private static void relPut(ShortBuffer b) {
+ int n = b.capacity();
+ b.clear();
+ for (int i = 0; i < n; i++)
+ b.put((short)ic(i));
+ b.flip();
+ }
+
+ private static void absPut(ShortBuffer b) {
+ int n = b.capacity();
+ b.clear();
+ for (int i = 0; i < n; i++)
+ b.put(i, (short)ic(i));
+ b.limit(n);
+ b.position(0);
+ }
+
+ private static void bulkPutArray(ShortBuffer b) {
+ int n = b.capacity();
+ b.clear();
+ short[] a = new short[n + 7];
+ for (int i = 0; i < n; i++)
+ a[i + 7] = (short)ic(i);
+ b.put(a, 7, n);
+ b.flip();
+ }
+
+ private static void bulkPutBuffer(ShortBuffer b) {
+ int n = b.capacity();
+ b.clear();
+ ShortBuffer c = ShortBuffer.allocate(n + 7);
+ c.position(7);
+ for (int i = 0; i < n; i++)
+ c.put((short)ic(i));
+ c.flip();
+ c.position(7);
+ b.put(c);
+ b.flip();
+ }
+
+ //6231529
+ private static void callReset(ShortBuffer b) {
+ b.position(0);
+ b.mark();
+
+ b.duplicate().reset();
+ b.asReadOnlyBuffer().reset();
+ }
+
+
+
+ // 6221101-6234263
+
+ private static void putBuffer() {
+ final int cap = 10;
+
+ ShortBuffer direct1 = ByteBuffer.allocateDirect(cap).asShortBuffer();
+ ShortBuffer nondirect1 = ByteBuffer.allocate(cap).asShortBuffer();
+ direct1.put(nondirect1);
+
+ ShortBuffer direct2 = ByteBuffer.allocateDirect(cap).asShortBuffer();
+ ShortBuffer nondirect2 = ByteBuffer.allocate(cap).asShortBuffer();
+ nondirect2.put(direct2);
+
+ ShortBuffer direct3 = ByteBuffer.allocateDirect(cap).asShortBuffer();
+ ShortBuffer direct4 = ByteBuffer.allocateDirect(cap).asShortBuffer();
+ direct3.put(direct4);
+
+ ShortBuffer nondirect3 = ByteBuffer.allocate(cap).asShortBuffer();
+ ShortBuffer nondirect4 = ByteBuffer.allocate(cap).asShortBuffer();
+ nondirect3.put(nondirect4);
+ }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ private static void checkSlice(ShortBuffer b, ShortBuffer slice) {
+ ck(slice, 0, slice.position());
+ ck(slice, b.remaining(), slice.limit());
+ ck(slice, b.remaining(), slice.capacity());
+ if (b.isDirect() != slice.isDirect())
+ fail("Lost direction", slice);
+ if (b.isReadOnly() != slice.isReadOnly())
+ fail("Lost read-only", slice);
+ }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ private static void tryCatch(Buffer b, Class ex, Runnable thunk) {
+ boolean caught = false;
+ try {
+ thunk.run();
+ } catch (Throwable x) {
+ if (ex.isAssignableFrom(x.getClass()))
+ caught = true;
+ }
+ if (!caught)
+ fail(ex.getName() + " not thrown", b);
+ }
+
+ private static void tryCatch(short [] t, Class ex, Runnable thunk) {
+ tryCatch(ShortBuffer.wrap(t), ex, thunk);
+ }
+
+ public static void test(int level, final ShortBuffer b, boolean direct) {
+
+ show(level, b);
+
+ if (direct != b.isDirect())
+ fail("Wrong direction", b);
+
+ // Gets and puts
+
+ relPut(b);
+ relGet(b);
+ absGet(b);
+ bulkGet(b);
+
+ absPut(b);
+ relGet(b);
+ absGet(b);
+ bulkGet(b);
+
+ bulkPutArray(b);
+ relGet(b);
+
+ bulkPutBuffer(b);
+ relGet(b);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ // Compact
+
+ relPut(b);
+ b.position(13);
+ b.compact();
+ b.flip();
+ relGet(b, 13);
+
+ // Exceptions
+
+ boolean caught = false;
+ relPut(b);
+ b.limit(b.capacity() / 2);
+ b.position(b.limit());
+
+ tryCatch(b, BufferUnderflowException.class, new Runnable() {
+ public void run() {
+ b.get();
+ }});
+
+ tryCatch(b, BufferOverflowException.class, new Runnable() {
+ public void run() {
+ b.put((short)42);
+ }});
+
+ // The index must be non-negative and lesss than the buffer's limit.
+ tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ b.get(b.limit());
+ }});
+ tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ b.get(-1);
+ }});
+
+ tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ b.put(b.limit(), (short)42);
+ }});
+
+ // Values
+
+ b.clear();
+ b.put((short)0);
+ b.put((short)-1);
+ b.put((short)1);
+ b.put(Short.MAX_VALUE);
+ b.put(Short.MIN_VALUE);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ short v;
+ b.flip();
+ ck(b, b.get(), 0);
+ ck(b, b.get(), (short)-1);
+ ck(b, b.get(), 1);
+ ck(b, b.get(), Short.MAX_VALUE);
+ ck(b, b.get(), Short.MIN_VALUE);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ // Comparison
+ b.rewind();
+ ShortBuffer b2 = ShortBuffer.allocate(b.capacity());
+ b2.put(b);
+ b2.flip();
+ b.position(2);
+ b2.position(2);
+ if (!b.equals(b2)) {
+ for (int i = 2; i < b.limit(); i++) {
+ short x = b.get(i);
+ short y = b2.get(i);
+ if (x != y
+
+
+
+
+
+
+ )
+ out.println("[" + i + "] " + x + " != " + y);
+ }
+ fail("Identical buffers not equal", b, b2);
+ }
+ if (b.compareTo(b2) != 0)
+ fail("Comparison to identical buffer != 0", b, b2);
+
+ b.limit(b.limit() + 1);
+ b.position(b.limit() - 1);
+ b.put((short)99);
+ b.rewind();
+ b2.rewind();
+ if (b.equals(b2))
+ fail("Non-identical buffers equal", b, b2);
+ if (b.compareTo(b2) <= 0)
+ fail("Comparison to shorter buffer <= 0", b, b2);
+ b.limit(b.limit() - 1);
+
+ b.put(2, (short)42);
+ if (b.equals(b2))
+ fail("Non-identical buffers equal", b, b2);
+ if (b.compareTo(b2) <= 0)
+ fail("Comparison to lesser buffer <= 0", b, b2);
+
+ // Sub, dup
+
+ relPut(b);
+ relGet(b.duplicate());
+ b.position(13);
+ relGet(b.duplicate(), 13);
+ relGet(b.duplicate().slice(), 13);
+ relGet(b.slice(), 13);
+ relGet(b.slice().duplicate(), 13);
+
+ // Slice
+
+ b.position(5);
+ ShortBuffer sb = b.slice();
+ checkSlice(b, sb);
+ b.position(0);
+ ShortBuffer sb2 = sb.slice();
+ checkSlice(sb, sb2);
+
+ if (!sb.equals(sb2))
+ fail("Sliced slices do not match", sb, sb2);
+ if ((sb.hasArray()) && (sb.arrayOffset() != sb2.arrayOffset()))
+ fail("Array offsets do not match: "
+ + sb.arrayOffset() + " != " + sb2.arrayOffset(), sb, sb2);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ // Read-only views
+
+ b.rewind();
+ final ShortBuffer rb = b.asReadOnlyBuffer();
+ if (!b.equals(rb))
+ fail("Buffer not equal to read-only view", b, rb);
+ show(level + 1, rb);
+
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ relPut(rb);
+ }});
+
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ absPut(rb);
+ }});
+
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ bulkPutArray(rb);
+ }});
+
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ bulkPutBuffer(rb);
+ }});
+
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ rb.compact();
+ }});
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ if (rb.getClass().getName().startsWith("java.nio.Heap")) {
+
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ rb.array();
+ }});
+
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ rb.arrayOffset();
+ }});
+
+ if (rb.hasArray())
+ fail("Read-only heap buffer's backing array is accessible",
+ rb);
+
+ }
+
+ // Bulk puts from read-only buffers
+
+ b.clear();
+ rb.rewind();
+ b.put(rb);
+
+
+
+
+
+
+
+
+
+
+
+ relPut(b); // Required by testViews
+
+ }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ public static void test(final short [] ba) {
+ int offset = 47;
+ int length = 900;
+ final ShortBuffer b = ShortBuffer.wrap(ba, offset, length);
+ show(0, b);
+ ck(b, b.capacity(), ba.length);
+ ck(b, b.position(), offset);
+ ck(b, b.limit(), offset + length);
+
+ // The offset must be non-negative and no larger than <array.length>.
+ tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ ShortBuffer.wrap(ba, -1, ba.length);
+ }});
+ tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ ShortBuffer.wrap(ba, ba.length + 1, ba.length);
+ }});
+ tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ ShortBuffer.wrap(ba, 0, -1);
+ }});
+ tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ ShortBuffer.wrap(ba, 0, ba.length + 1);
+ }});
+
+ // A NullPointerException will be thrown if the array is null.
+ tryCatch(ba, NullPointerException.class, new Runnable() {
+ public void run() {
+ ShortBuffer.wrap((short []) null, 0, 5);
+ }});
+ tryCatch(ba, NullPointerException.class, new Runnable() {
+ public void run() {
+ ShortBuffer.wrap((short []) null);
+ }});
+ }
+
+ private static void testAllocate() {
+ // An IllegalArgumentException will be thrown for negative capacities.
+ tryCatch((Buffer) null, IllegalArgumentException.class, new Runnable() {
+ public void run() {
+ ShortBuffer.allocate(-1);
+ }});
+
+
+
+
+
+
+ }
+
+ public static void test() {
+ testAllocate();
+ test(0, ShortBuffer.allocate(7 * 1024), false);
+ test(0, ShortBuffer.wrap(new short[7 * 1024], 0, 7 * 1024), false);
+ test(new short[1024]);
+
+
+
+
+
+
+
+
+
+
+ callReset(ShortBuffer.allocate(10));
+
+
+
+ putBuffer();
+
+ }
+
+}
diff --git a/test/java/nio/Buffer/CharAt.java b/test/java/nio/Buffer/CharAt.java
new file mode 100644
index 0000000..245fb7e
--- /dev/null
+++ b/test/java/nio/Buffer/CharAt.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2001 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/* @test
+ * @summary Test charAt index checking
+ * @bug 4510323
+ */
+
+import java.nio.*;
+
+public class CharAt {
+ public static void main (String[] args) {
+ CharSequence cs = CharBuffer.wrap("foo");
+ for (int i = 0; i < cs.length(); i++)
+ System.err.print(cs.charAt(i));
+ System.err.println();
+ }
+}
diff --git a/test/java/nio/Buffer/Chew.java b/test/java/nio/Buffer/Chew.java
new file mode 100644
index 0000000..605097c
--- /dev/null
+++ b/test/java/nio/Buffer/Chew.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2004 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/* @test
+ * @bug 5046110
+ * @summary Ensure that direct memory can be unreserved
+ * as the reserving thread sleeps
+ *
+ * @run main/othervm -mx16M Chew
+ */
+
+import java.nio.*;
+
+
+public class Chew {
+
+ public static void main(String[] args) {
+ for (int i = 0; i < 64; i++)
+ ByteBuffer.allocateDirect(1 << 20);
+ }
+
+}
diff --git a/test/java/nio/Buffer/CopyDirect-X-Memory.java b/test/java/nio/Buffer/CopyDirect-X-Memory.java
new file mode 100644
index 0000000..802ca55
--- /dev/null
+++ b/test/java/nio/Buffer/CopyDirect-X-Memory.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2002-2007 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+#warn This file is preprocessed before being compiled
+
+import java.nio.*;
+
+public class CopyDirect$Type$Memory
+ extends CopyDirectMemory
+{
+ private static void init($Type$Buffer b) {
+ int n = b.capacity();
+ b.clear();
+ for (int i = 0; i < n; i++)
+ b.put(i, ($type$)ic(i));
+ b.limit(n);
+ b.position(0);
+ }
+
+ private static void init($type$ [] a) {
+ for (int i = 0; i < a.length; i++)
+ a[i] = ($type$)ic(i + 1);
+ }
+
+ public static void test() {
+#if[byte]
+ ByteBuffer b = ByteBuffer.allocateDirect(1024 * 1024 + 1024);
+#else[byte]
+ ByteBuffer bb = ByteBuffer.allocateDirect(1024 * 1024 + 1024);
+ $Type$Buffer b = bb.as$Type$Buffer();
+#end[byte]
+ init(b);
+ $type$ [] a = new $type$[b.capacity()];
+ init(a);
+
+ // copyFrom$Type$Array (a -> b)
+ b.put(a);
+ for (int i = 0; i < a.length; i++)
+ ck(b, b.get(i), ($type$)ic(i + 1));
+
+ // copyTo$Type$Array (b -> a)
+ init(b);
+ init(a);
+ b.get(a);
+ for (int i = 0; i < a.length; i++)
+ if (a[i] != b.get(i))
+ fail("Copy failed at " + i + ": '"
+ + a[i] + "' != '" + b.get(i) + "'");
+ }
+}
diff --git a/test/java/nio/Buffer/CopyDirectByteMemory.java b/test/java/nio/Buffer/CopyDirectByteMemory.java
new file mode 100644
index 0000000..686fc90
--- /dev/null
+++ b/test/java/nio/Buffer/CopyDirectByteMemory.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2002-2007 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+// -- This file was mechanically generated: Do not edit! -- //
+
+import java.nio.*;
+
+public class CopyDirectByteMemory
+ extends CopyDirectMemory
+{
+ private static void init(ByteBuffer b) {
+ int n = b.capacity();
+ b.clear();
+ for (int i = 0; i < n; i++)
+ b.put(i, (byte)ic(i));
+ b.limit(n);
+ b.position(0);
+ }
+
+ private static void init(byte [] a) {
+ for (int i = 0; i < a.length; i++)
+ a[i] = (byte)ic(i + 1);
+ }
+
+ public static void test() {
+
+ ByteBuffer b = ByteBuffer.allocateDirect(1024 * 1024 + 1024);
+
+
+
+
+ init(b);
+ byte [] a = new byte[b.capacity()];
+ init(a);
+
+ // copyFromByteArray (a -> b)
+ b.put(a);
+ for (int i = 0; i < a.length; i++)
+ ck(b, b.get(i), (byte)ic(i + 1));
+
+ // copyToByteArray (b -> a)
+ init(b);
+ init(a);
+ b.get(a);
+ for (int i = 0; i < a.length; i++)
+ if (a[i] != b.get(i))
+ fail("Copy failed at " + i + ": '"
+ + a[i] + "' != '" + b.get(i) + "'");
+ }
+}
diff --git a/test/java/nio/Buffer/CopyDirectCharMemory.java b/test/java/nio/Buffer/CopyDirectCharMemory.java
new file mode 100644
index 0000000..db134b2
--- /dev/null
+++ b/test/java/nio/Buffer/CopyDirectCharMemory.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2002-2007 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+// -- This file was mechanically generated: Do not edit! -- //
+
+import java.nio.*;
+
+public class CopyDirectCharMemory
+ extends CopyDirectMemory
+{
+ private static void init(CharBuffer b) {
+ int n = b.capacity();
+ b.clear();
+ for (int i = 0; i < n; i++)
+ b.put(i, (char)ic(i));
+ b.limit(n);
+ b.position(0);
+ }
+
+ private static void init(char [] a) {
+ for (int i = 0; i < a.length; i++)
+ a[i] = (char)ic(i + 1);
+ }
+
+ public static void test() {
+
+
+
+ ByteBuffer bb = ByteBuffer.allocateDirect(1024 * 1024 + 1024);
+ CharBuffer b = bb.asCharBuffer();
+
+ init(b);
+ char [] a = new char[b.capacity()];
+ init(a);
+
+ // copyFromCharArray (a -> b)
+ b.put(a);
+ for (int i = 0; i < a.length; i++)
+ ck(b, b.get(i), (char)ic(i + 1));
+
+ // copyToCharArray (b -> a)
+ init(b);
+ init(a);
+ b.get(a);
+ for (int i = 0; i < a.length; i++)
+ if (a[i] != b.get(i))
+ fail("Copy failed at " + i + ": '"
+ + a[i] + "' != '" + b.get(i) + "'");
+ }
+}
diff --git a/test/java/nio/Buffer/CopyDirectDoubleMemory.java b/test/java/nio/Buffer/CopyDirectDoubleMemory.java
new file mode 100644
index 0000000..1ed65d7
--- /dev/null
+++ b/test/java/nio/Buffer/CopyDirectDoubleMemory.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2002-2007 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+// -- This file was mechanically generated: Do not edit! -- //
+
+import java.nio.*;
+
+public class CopyDirectDoubleMemory
+ extends CopyDirectMemory
+{
+ private static void init(DoubleBuffer b) {
+ int n = b.capacity();
+ b.clear();
+ for (int i = 0; i < n; i++)
+ b.put(i, (double)ic(i));
+ b.limit(n);
+ b.position(0);
+ }
+
+ private static void init(double [] a) {
+ for (int i = 0; i < a.length; i++)
+ a[i] = (double)ic(i + 1);
+ }
+
+ public static void test() {
+
+
+
+ ByteBuffer bb = ByteBuffer.allocateDirect(1024 * 1024 + 1024);
+ DoubleBuffer b = bb.asDoubleBuffer();
+
+ init(b);
+ double [] a = new double[b.capacity()];
+ init(a);
+
+ // copyFromDoubleArray (a -> b)
+ b.put(a);
+ for (int i = 0; i < a.length; i++)
+ ck(b, b.get(i), (double)ic(i + 1));
+
+ // copyToDoubleArray (b -> a)
+ init(b);
+ init(a);
+ b.get(a);
+ for (int i = 0; i < a.length; i++)
+ if (a[i] != b.get(i))
+ fail("Copy failed at " + i + ": '"
+ + a[i] + "' != '" + b.get(i) + "'");
+ }
+}
diff --git a/test/java/nio/Buffer/CopyDirectFloatMemory.java b/test/java/nio/Buffer/CopyDirectFloatMemory.java
new file mode 100644
index 0000000..79ddb5c
--- /dev/null
+++ b/test/java/nio/Buffer/CopyDirectFloatMemory.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2002-2007 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+// -- This file was mechanically generated: Do not edit! -- //
+
+import java.nio.*;
+
+public class CopyDirectFloatMemory
+ extends CopyDirectMemory
+{
+ private static void init(FloatBuffer b) {
+ int n = b.capacity();
+ b.clear();
+ for (int i = 0; i < n; i++)
+ b.put(i, (float)ic(i));
+ b.limit(n);
+ b.position(0);
+ }
+
+ private static void init(float [] a) {
+ for (int i = 0; i < a.length; i++)
+ a[i] = (float)ic(i + 1);
+ }
+
+ public static void test() {
+
+
+
+ ByteBuffer bb = ByteBuffer.allocateDirect(1024 * 1024 + 1024);
+ FloatBuffer b = bb.asFloatBuffer();
+
+ init(b);
+ float [] a = new float[b.capacity()];
+ init(a);
+
+ // copyFromFloatArray (a -> b)
+ b.put(a);
+ for (int i = 0; i < a.length; i++)
+ ck(b, b.get(i), (float)ic(i + 1));
+
+ // copyToFloatArray (b -> a)
+ init(b);
+ init(a);
+ b.get(a);
+ for (int i = 0; i < a.length; i++)
+ if (a[i] != b.get(i))
+ fail("Copy failed at " + i + ": '"
+ + a[i] + "' != '" + b.get(i) + "'");
+ }
+}
diff --git a/test/java/nio/Buffer/CopyDirectIntMemory.java b/test/java/nio/Buffer/CopyDirectIntMemory.java
new file mode 100644
index 0000000..da06bc0
--- /dev/null
+++ b/test/java/nio/Buffer/CopyDirectIntMemory.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2002-2007 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+// -- This file was mechanically generated: Do not edit! -- //
+
+import java.nio.*;
+
+public class CopyDirectIntMemory
+ extends CopyDirectMemory
+{
+ private static void init(IntBuffer b) {
+ int n = b.capacity();
+ b.clear();
+ for (int i = 0; i < n; i++)
+ b.put(i, (int)ic(i));
+ b.limit(n);
+ b.position(0);
+ }
+
+ private static void init(int [] a) {
+ for (int i = 0; i < a.length; i++)
+ a[i] = (int)ic(i + 1);
+ }
+
+ public static void test() {
+
+
+
+ ByteBuffer bb = ByteBuffer.allocateDirect(1024 * 1024 + 1024);
+ IntBuffer b = bb.asIntBuffer();
+
+ init(b);
+ int [] a = new int[b.capacity()];
+ init(a);
+
+ // copyFromIntArray (a -> b)
+ b.put(a);
+ for (int i = 0; i < a.length; i++)
+ ck(b, b.get(i), (int)ic(i + 1));
+
+ // copyToIntArray (b -> a)
+ init(b);
+ init(a);
+ b.get(a);
+ for (int i = 0; i < a.length; i++)
+ if (a[i] != b.get(i))
+ fail("Copy failed at " + i + ": '"
+ + a[i] + "' != '" + b.get(i) + "'");
+ }
+}
diff --git a/test/java/nio/Buffer/CopyDirectLongMemory.java b/test/java/nio/Buffer/CopyDirectLongMemory.java
new file mode 100644
index 0000000..97caa21
--- /dev/null
+++ b/test/java/nio/Buffer/CopyDirectLongMemory.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2002-2007 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+// -- This file was mechanically generated: Do not edit! -- //
+
+import java.nio.*;
+
+public class CopyDirectLongMemory
+ extends CopyDirectMemory
+{
+ private static void init(LongBuffer b) {
+ int n = b.capacity();
+ b.clear();
+ for (int i = 0; i < n; i++)
+ b.put(i, (long)ic(i));
+ b.limit(n);
+ b.position(0);
+ }
+
+ private static void init(long [] a) {
+ for (int i = 0; i < a.length; i++)
+ a[i] = (long)ic(i + 1);
+ }
+
+ public static void test() {
+
+
+
+ ByteBuffer bb = ByteBuffer.allocateDirect(1024 * 1024 + 1024);
+ LongBuffer b = bb.asLongBuffer();
+
+ init(b);
+ long [] a = new long[b.capacity()];
+ init(a);
+
+ // copyFromLongArray (a -> b)
+ b.put(a);
+ for (int i = 0; i < a.length; i++)
+ ck(b, b.get(i), (long)ic(i + 1));
+
+ // copyToLongArray (b -> a)
+ init(b);
+ init(a);
+ b.get(a);
+ for (int i = 0; i < a.length; i++)
+ if (a[i] != b.get(i))
+ fail("Copy failed at " + i + ": '"
+ + a[i] + "' != '" + b.get(i) + "'");
+ }
+}
diff --git a/test/java/nio/Buffer/CopyDirectMemory.java b/test/java/nio/Buffer/CopyDirectMemory.java
new file mode 100644
index 0000000..4ab33f6
--- /dev/null
+++ b/test/java/nio/Buffer/CopyDirectMemory.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2002-2007 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/* @test
+ * @summary Test view buffer bulk operations for large buffers.
+ * @bug 4463011
+ *
+ * @build Basic
+ * @run main CopyDirectMemory
+ */
+
+import java.nio.*;
+
+public class CopyDirectMemory
+ extends Basic
+{
+ public static void main(String [] args) {
+ CopyDirectByteMemory.test();
+ CopyDirectCharMemory.test();
+ CopyDirectShortMemory.test();
+ CopyDirectIntMemory.test();
+ CopyDirectLongMemory.test();
+ CopyDirectFloatMemory.test();
+ CopyDirectDoubleMemory.test();
+ }
+}
diff --git a/test/java/nio/Buffer/CopyDirectShortMemory.java b/test/java/nio/Buffer/CopyDirectShortMemory.java
new file mode 100644
index 0000000..fab996a
--- /dev/null
+++ b/test/java/nio/Buffer/CopyDirectShortMemory.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2002-2007 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+// -- This file was mechanically generated: Do not edit! -- //
+
+import java.nio.*;
+
+public class CopyDirectShortMemory
+ extends CopyDirectMemory
+{
+ private static void init(ShortBuffer b) {
+ int n = b.capacity();
+ b.clear();
+ for (int i = 0; i < n; i++)
+ b.put(i, (short)ic(i));
+ b.limit(n);
+ b.position(0);
+ }
+
+ private static void init(short [] a) {
+ for (int i = 0; i < a.length; i++)
+ a[i] = (short)ic(i + 1);
+ }
+
+ public static void test() {
+
+
+
+ ByteBuffer bb = ByteBuffer.allocateDirect(1024 * 1024 + 1024);
+ ShortBuffer b = bb.asShortBuffer();
+
+ init(b);
+ short [] a = new short[b.capacity()];
+ init(a);
+
+ // copyFromShortArray (a -> b)
+ b.put(a);
+ for (int i = 0; i < a.length; i++)
+ ck(b, b.get(i), (short)ic(i + 1));
+
+ // copyToShortArray (b -> a)
+ init(b);
+ init(a);
+ b.get(a);
+ for (int i = 0; i < a.length; i++)
+ if (a[i] != b.get(i))
+ fail("Copy failed at " + i + ": '"
+ + a[i] + "' != '" + b.get(i) + "'");
+ }
+}
diff --git a/test/java/nio/Buffer/Order.java b/test/java/nio/Buffer/Order.java
new file mode 100644
index 0000000..3ce57c5
--- /dev/null
+++ b/test/java/nio/Buffer/Order.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2001 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/* @test
+ * @summary Unit test for X-Buffer.order methods
+ */
+
+import java.io.*;
+import java.nio.*;
+
+
+public class Order {
+
+ static final ByteOrder be = ByteOrder.BIG_ENDIAN;
+ static final ByteOrder le = ByteOrder.LITTLE_ENDIAN;
+ static final ByteOrder nord = ByteOrder.nativeOrder();
+
+ static void ck(ByteOrder ord, ByteOrder expected) {
+ if (ord != expected)
+ throw new RuntimeException("Got " + ord
+ + ", expected " + expected);
+ }
+
+ static void ckViews(ByteBuffer bb, ByteOrder ord) {
+ ck(bb.asCharBuffer().order(), bb.order());
+ ck(bb.asIntBuffer().order(), bb.order());
+ ck(bb.asLongBuffer().order(), bb.order());
+ ck(bb.asFloatBuffer().order(), bb.order());
+ ck(bb.asDoubleBuffer().order(), bb.order());
+ }
+
+ static void ckByteBuffer(ByteBuffer bb) {
+ ckViews(bb, bb.order());
+ bb.order(be);
+ ckViews(bb, be);
+ bb.order(le);
+ ckViews(bb, le);
+ }
+
+ public static void main(String args[]) throws Exception {
+
+ ck(ByteBuffer.allocate(10).order(), be);
+ ck(ByteBuffer.allocateDirect(10).order(), be);
+ ck(ByteBuffer.allocate(10).order(be).order(), be);
+ ck(ByteBuffer.allocate(10).order(le).order(), le);
+
+ ckByteBuffer(ByteBuffer.allocate(10));
+ ckByteBuffer(ByteBuffer.allocateDirect(10));
+
+ }
+
+}
diff --git a/test/java/nio/Buffer/StringCharBufferSliceTest.java b/test/java/nio/Buffer/StringCharBufferSliceTest.java
new file mode 100644
index 0000000..5677002
--- /dev/null
+++ b/test/java/nio/Buffer/StringCharBufferSliceTest.java
@@ -0,0 +1,79 @@
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/* @test
+ * @bug 4997655
+ * @summary (bf) CharBuffer.slice() on wrapped CharSequence results in wrong position
+ */
+
+import java.nio.*;
+
+public class StringCharBufferSliceTest {
+ public static void main( String[] args) throws Exception {
+ System.out.println(
+ ">>> StringCharBufferSliceTest-main: testing the slice method...");
+
+ final String in = "for testing";
+
+ System.out.println(
+ ">>> StringCharBufferSliceTest-main: testing with the position 0.");
+
+ CharBuffer buff = CharBuffer.wrap(in);
+ test(buff, buff.slice());
+
+ System.out.println(
+ ">>> StringCharBufferSliceTest-main: testing with new position.");
+
+ buff.position(2);
+ test(buff, buff.slice());
+
+ System.out.println(
+ ">>> StringCharBufferSliceTest-main: testing with non zero initial position.");
+
+ buff = CharBuffer.wrap(in, 3, in.length());
+ test(buff, buff.slice());
+
+ System.out.println(">>> StringCharBufferSliceTest-main: done!");
+ }
+
+ public static void test(CharBuffer buff, CharBuffer slice) throws RuntimeException {
+ boolean marked = false;
+
+ try {
+ slice.reset();
+
+ marked = true;
+ } catch (InvalidMarkException ime) {
+ // expected
+ }
+
+ if (marked ||
+ slice.position() != 0 ||
+ buff.remaining() != slice.limit() ||
+ buff.remaining() != slice.capacity()) {
+
+ throw new RuntimeException(
+ "Calling the CharBuffer.slice method failed.");
+ }
+ }
+}
diff --git a/test/java/nio/Buffer/SwapMicroBenchmark.java b/test/java/nio/Buffer/SwapMicroBenchmark.java
new file mode 100644
index 0000000..cb5fcd1
--- /dev/null
+++ b/test/java/nio/Buffer/SwapMicroBenchmark.java
@@ -0,0 +1,247 @@
+/*
+ * Copyright (c) 2007 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * This is not a regression test, but a micro-benchmark.
+ * To exercise swap, run with filter=LITTLE_ENDIAN on sparc,
+ * filter=BIG_ENDIAN on x86.
+ *
+ * I have run this as follows:
+ *
+ * for f in -client -server; do mergeBench dolphin . jr -dsa -da $f SwapMicroBenchmark.java filter=LITTLE_ENDIAN; done
+ *
+ * @author Martin Buchholz
+ */
+
+import java.util.*;
+import java.nio.*;
+import java.util.concurrent.*;
+import java.util.regex.Pattern;
+
+public class SwapMicroBenchmark {
+ abstract static class Job {
+ private final String name;
+ public Job(String name) { this.name = name; }
+ public String name() { return name; }
+ public abstract void work() throws Throwable;
+ }
+
+ private static void collectAllGarbage() {
+ final java.util.concurrent.CountDownLatch drained
+ = new java.util.concurrent.CountDownLatch(1);
+ try {
+ System.gc(); // enqueue finalizable objects
+ new Object() { protected void finalize() {
+ drained.countDown(); }};
+ System.gc(); // enqueue detector
+ drained.await(); // wait for finalizer queue to drain
+ System.gc(); // cleanup finalized objects
+ } catch (InterruptedException e) { throw new Error(e); }
+ }
+
+ /**
+ * Runs each job for long enough that all the runtime compilers
+ * have had plenty of time to warm up, i.e. get around to
+ * compiling everything worth compiling.
+ * Returns array of average times per job per run.
+ */
+ private static long[] time0(Job ... jobs) throws Throwable {
+ final long warmupNanos = 10L * 1000L * 1000L * 1000L;
+ long[] nanoss = new long[jobs.length];
+ for (int i = 0; i < jobs.length; i++) {
+ collectAllGarbage();
+ long t0 = System.nanoTime();
+ long t;
+ int j = 0;
+ do { jobs[i].work(); j++; }
+ while ((t = System.nanoTime() - t0) < warmupNanos);
+ nanoss[i] = t/j;
+ }
+ return nanoss;
+ }
+
+ private static void time(Job ... jobs) throws Throwable {
+
+ long[] warmup = time0(jobs); // Warm up run
+ long[] nanoss = time0(jobs); // Real timing run
+ long[] milliss = new long[jobs.length];
+ double[] ratios = new double[jobs.length];
+
+ final String nameHeader = "Method";
+ final String millisHeader = "Millis";
+ final String ratioHeader = "Ratio";
+
+ int nameWidth = nameHeader.length();
+ int millisWidth = millisHeader.length();
+ int ratioWidth = ratioHeader.length();
+
+ for (int i = 0; i < jobs.length; i++) {
+ nameWidth = Math.max(nameWidth, jobs[i].name().length());
+
+ milliss[i] = nanoss[i]/(1000L * 1000L);
+ millisWidth = Math.max(millisWidth,
+ String.format("%d", milliss[i]).length());
+
+ ratios[i] = (double) nanoss[i] / (double) nanoss[0];
+ ratioWidth = Math.max(ratioWidth,
+ String.format("%.3f", ratios[i]).length());
+ }
+
+ String format = String.format("%%-%ds %%%dd %%%d.3f%%n",
+ nameWidth, millisWidth, ratioWidth);
+ String headerFormat = String.format("%%-%ds %%%ds %%%ds%%n",
+ nameWidth, millisWidth, ratioWidth);
+ System.out.printf(headerFormat, "Method", "Millis", "Ratio");
+
+ // Print out absolute and relative times, calibrated against first job
+ for (int i = 0; i < jobs.length; i++)
+ System.out.printf(format, jobs[i].name(), milliss[i], ratios[i]);
+ }
+
+ private static String keywordValue(String[] args, String keyword) {
+ for (String arg : args)
+ if (arg.startsWith(keyword))
+ return arg.substring(keyword.length() + 1);
+ return null;
+ }
+
+ private static int intArg(String[] args, String keyword, int defaultValue) {
+ String val = keywordValue(args, keyword);
+ return val == null ? defaultValue : Integer.parseInt(val);
+ }
+
+ private static Pattern patternArg(String[] args, String keyword) {
+ String val = keywordValue(args, keyword);
+ return val == null ? null : Pattern.compile(val);
+ }
+
+ private static Job[] filter(Pattern filter, Job[] jobs) {
+ if (filter == null) return jobs;
+ Job[] newJobs = new Job[jobs.length];
+ int n = 0;
+ for (Job job : jobs)
+ if (filter.matcher(job.name()).find())
+ newJobs[n++] = job;
+ // Arrays.copyOf not available in JDK 5
+ Job[] ret = new Job[n];
+ System.arraycopy(newJobs, 0, ret, 0, n);
+ return ret;
+ }
+
+ private static void deoptimize(int sum) {
+ if (sum == 42)
+ System.out.println("the answer");
+ }
+
+ /**
+ * Usage: [iterations=N] [size=N] [filter=REGEXP]
+ */
+ public static void main(String[] args) throws Throwable {
+ final int iterations = intArg(args, "iterations", 10000);
+ final int size = intArg(args, "size", 1024);
+ final Pattern filter = patternArg(args, "filter");
+
+ final Random rnd = new Random();
+
+ final ByteBuffer b = ByteBuffer.allocateDirect(8*size);
+ for (int i = 0; i < b.limit(); i++)
+ b.put(i, (byte) rnd.nextInt());
+
+ Job[] jobs = {
+ new Job("swap char BIG_ENDIAN") {
+ public void work() throws Throwable {
+ b.order(ByteOrder.BIG_ENDIAN);
+ CharBuffer x = b.asCharBuffer();
+ for (int i = 0; i < iterations; i++) {
+ int sum = 0;
+ for (int j = 0, end = x.limit(); j < end; j++)
+ sum += x.get(j);
+ deoptimize(sum);}}},
+ new Job("swap char LITTLE_ENDIAN") {
+ public void work() throws Throwable {
+ b.order(ByteOrder.LITTLE_ENDIAN);
+ CharBuffer x = b.asCharBuffer();
+ for (int i = 0; i < iterations; i++) {
+ int sum = 0;
+ for (int j = 0, end = x.limit(); j < end; j++)
+ sum += x.get(j);
+ deoptimize(sum);}}},
+ new Job("swap short BIG_ENDIAN") {
+ public void work() throws Throwable {
+ b.order(ByteOrder.BIG_ENDIAN);
+ ShortBuffer x = b.asShortBuffer();
+ for (int i = 0; i < iterations; i++) {
+ int sum = 0;
+ for (int j = 0, end = x.limit(); j < end; j++)
+ sum += x.get(j);
+ deoptimize(sum);}}},
+ new Job("swap short LITTLE_ENDIAN") {
+ public void work() throws Throwable {
+ b.order(ByteOrder.LITTLE_ENDIAN);
+ ShortBuffer x = b.asShortBuffer();
+ for (int i = 0; i < iterations; i++) {
+ int sum = 0;
+ for (int j = 0, end = x.limit(); j < end; j++)
+ sum += x.get(j);
+ deoptimize(sum);}}},
+ new Job("swap int BIG_ENDIAN") {
+ public void work() throws Throwable {
+ b.order(ByteOrder.BIG_ENDIAN);
+ IntBuffer x = b.asIntBuffer();
+ for (int i = 0; i < iterations; i++) {
+ int sum = 0;
+ for (int j = 0, end = x.limit(); j < end; j++)
+ sum += x.get(j);
+ deoptimize(sum);}}},
+ new Job("swap int LITTLE_ENDIAN") {
+ public void work() throws Throwable {
+ b.order(ByteOrder.LITTLE_ENDIAN);
+ IntBuffer x = b.asIntBuffer();
+ for (int i = 0; i < iterations; i++) {
+ int sum = 0;
+ for (int j = 0, end = x.limit(); j < end; j++)
+ sum += x.get(j);
+ deoptimize(sum);}}},
+ new Job("swap long BIG_ENDIAN") {
+ public void work() throws Throwable {
+ b.order(ByteOrder.BIG_ENDIAN);
+ LongBuffer x = b.asLongBuffer();
+ for (int i = 0; i < iterations; i++) {
+ int sum = 0;
+ for (int j = 0, end = x.limit(); j < end; j++)
+ sum += x.get(j);
+ deoptimize(sum);}}},
+ new Job("swap long LITTLE_ENDIAN") {
+ public void work() throws Throwable {
+ b.order(ByteOrder.LITTLE_ENDIAN);
+ LongBuffer x = b.asLongBuffer();
+ for (int i = 0; i < iterations; i++) {
+ int sum = 0;
+ for (int j = 0, end = x.limit(); j < end; j++)
+ sum += x.get(j);
+ deoptimize(sum);}}}
+ };
+
+ time(filter(filter, jobs));
+ }
+}
diff --git a/test/java/nio/Buffer/genBasic.sh b/test/java/nio/Buffer/genBasic.sh
new file mode 100644
index 0000000..b045567
--- /dev/null
+++ b/test/java/nio/Buffer/genBasic.sh
@@ -0,0 +1,38 @@
+#! /bin/sh
+
+#
+# Copyright 2000-2007 Sun Microsystems, Inc. All Rights Reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+# CA 95054 USA or visit www.sun.com if you need additional information or
+# have any questions.
+#
+
+SPP='sh ../../../../make/java/nio/spp.sh'
+
+gen() {
+ $SPP -K$1 -Dtype=$1 -DType=$2 -DFulltype=$3 <Basic-X.java >Basic$2.java
+}
+
+gen byte Byte Byte
+gen char Char Character
+gen short Short Short
+gen int Int Integer
+gen long Long Long
+gen float Float Float
+gen double Double Double
diff --git a/test/java/nio/Buffer/genCopyDirectMemory.sh b/test/java/nio/Buffer/genCopyDirectMemory.sh
new file mode 100644
index 0000000..588a179
--- /dev/null
+++ b/test/java/nio/Buffer/genCopyDirectMemory.sh
@@ -0,0 +1,39 @@
+#! /bin/sh
+
+#
+# Copyright 2002-2007 Sun Microsystems, Inc. All Rights Reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+# CA 95054 USA or visit www.sun.com if you need additional information or
+# have any questions.
+#
+
+SPP='sh ../../../../make/java/nio/spp.sh'
+
+gen() {
+ $SPP -K$1 -Dtype=$1 -DType=$2 -DFulltype=$3<CopyDirect-X-Memory.java >CopyDirect$2Memory.java
+}
+
+gen byte Byte Byte
+gen char Char Character
+gen short Short Short
+gen int Int Integer
+gen long Long Long
+gen float Float Float
+gen double Double Double
+