jdk/test/java/nio/Buffer/Basic-X.java
author emcmanus
Thu, 05 Jun 2008 13:42:47 +0200
changeset 687 874e25a9844a
parent 2 90ce3da70b43
child 1634 3871c2046043
permissions -rw-r--r--
6562936: Support custom type mappings in MXBeans Reviewed-by: dfuchs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2000-2007 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/* Type-specific source code for unit test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * Regenerate the BasicX classes via genBasic.sh whenever this file changes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * We check in the generated source files so that the test tree can be used
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * independently of the rest of the source tree.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
#warn This file is preprocessed before being compiled
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.nio.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
public class Basic$Type$
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
    extends Basic
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    private static void relGet($Type$Buffer b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
        int n = b.capacity();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
        $type$ v;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
        for (int i = 0; i < n; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
            ck(b, (long)b.get(), (long)(($type$)ic(i)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
        b.rewind();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    private static void relGet($Type$Buffer b, int start) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
        int n = b.remaining();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        $type$ v;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        for (int i = start; i < n; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
            ck(b, (long)b.get(), (long)(($type$)ic(i)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        b.rewind();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    private static void absGet($Type$Buffer b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        int n = b.capacity();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        $type$ v;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        for (int i = 0; i < n; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
            ck(b, (long)b.get(), (long)(($type$)ic(i)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        b.rewind();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    private static void bulkGet($Type$Buffer b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        int n = b.capacity();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        $type$[] a = new $type$[n + 7];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        b.get(a, 7, n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        for (int i = 0; i < n; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
            ck(b, (long)a[i + 7], (long)(($type$)ic(i)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    private static void relPut($Type$Buffer b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        int n = b.capacity();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        b.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        for (int i = 0; i < n; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
            b.put(($type$)ic(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        b.flip();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    private static void absPut($Type$Buffer b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        int n = b.capacity();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        b.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        for (int i = 0; i < n; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            b.put(i, ($type$)ic(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        b.limit(n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        b.position(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    private static void bulkPutArray($Type$Buffer b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        int n = b.capacity();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        b.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        $type$[] a = new $type$[n + 7];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        for (int i = 0; i < n; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            a[i + 7] = ($type$)ic(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        b.put(a, 7, n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        b.flip();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    private static void bulkPutBuffer($Type$Buffer b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        int n = b.capacity();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        b.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        $Type$Buffer c = $Type$Buffer.allocate(n + 7);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        c.position(7);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        for (int i = 0; i < n; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            c.put(($type$)ic(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        c.flip();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        c.position(7);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        b.put(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        b.flip();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    //6231529
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    private static void callReset($Type$Buffer b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        b.position(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        b.mark();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        b.duplicate().reset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        b.asReadOnlyBuffer().reset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
#if[byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
#else[byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    // 6221101-6234263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    private static void putBuffer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        final int cap = 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        $Type$Buffer direct1 = ByteBuffer.allocateDirect(cap).as$Type$Buffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        $Type$Buffer nondirect1 = ByteBuffer.allocate(cap).as$Type$Buffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        direct1.put(nondirect1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        $Type$Buffer direct2 = ByteBuffer.allocateDirect(cap).as$Type$Buffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        $Type$Buffer nondirect2 = ByteBuffer.allocate(cap).as$Type$Buffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        nondirect2.put(direct2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        $Type$Buffer direct3 = ByteBuffer.allocateDirect(cap).as$Type$Buffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        $Type$Buffer direct4 = ByteBuffer.allocateDirect(cap).as$Type$Buffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        direct3.put(direct4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        $Type$Buffer nondirect3 = ByteBuffer.allocate(cap).as$Type$Buffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        $Type$Buffer nondirect4 = ByteBuffer.allocate(cap).as$Type$Buffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        nondirect3.put(nondirect4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
#end[byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
#if[char]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    private static void bulkPutString($Type$Buffer b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        int n = b.capacity();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        b.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        StringBuffer sb = new StringBuffer(n + 7);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        sb.append("1234567");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        for (int i = 0; i < n; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            sb.append((char)ic(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        b.put(sb.toString(), 7, 7 + n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        b.flip();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
#end[char]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    private static void checkSlice($Type$Buffer b, $Type$Buffer slice) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        ck(slice, 0, slice.position());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        ck(slice, b.remaining(), slice.limit());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        ck(slice, b.remaining(), slice.capacity());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        if (b.isDirect() != slice.isDirect())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            fail("Lost direction", slice);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        if (b.isReadOnly() != slice.isReadOnly())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            fail("Lost read-only", slice);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
#if[byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    private static void checkBytes(ByteBuffer b, byte[] bs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        int n = bs.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        int p = b.position();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        byte v;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        if (b.order() == ByteOrder.BIG_ENDIAN) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            for (int i = 0; i < n; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                ck(b, b.get(), bs[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            for (int i = n - 1; i >= 0; i--)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                ck(b, b.get(), bs[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        b.position(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    private static void testViews(int level, ByteBuffer b, boolean direct) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        ShortBuffer sb = b.asShortBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        BasicShort.test(level, sb, direct);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        checkBytes(b, new byte[] { 0, (byte)ic(0) });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        CharBuffer cb = b.asCharBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        BasicChar.test(level, cb, direct);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        checkBytes(b, new byte[] { 0, (byte)ic(0) });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        IntBuffer ib = b.asIntBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        BasicInt.test(level, ib, direct);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        checkBytes(b, new byte[] { 0, 0, 0, (byte)ic(0) });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        LongBuffer lb = b.asLongBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        BasicLong.test(level, lb, direct);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        checkBytes(b, new byte[] { 0, 0, 0, 0, 0, 0, 0, (byte)ic(0) });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        FloatBuffer fb = b.asFloatBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        BasicFloat.test(level, fb, direct);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        checkBytes(b, new byte[] { 0x42, (byte)0xc2, 0, 0 });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        DoubleBuffer db = b.asDoubleBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        BasicDouble.test(level, db, direct);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        checkBytes(b, new byte[] { 0x40, 0x58, 0x40, 0, 0, 0, 0, 0 });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    private static void testHet(int level, ByteBuffer b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        int p = b.position();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        b.limit(b.capacity());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        show(level, b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        out.print("    put:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        b.putChar((char)1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        b.putChar((char)Character.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        out.print(" char");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        b.putShort((short)1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        b.putShort((short)Short.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        out.print(" short");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        b.putInt(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        b.putInt(Integer.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        out.print(" int");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        b.putLong((long)1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        b.putLong((long)Long.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        out.print(" long");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        b.putFloat((float)1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        b.putFloat((float)Float.MIN_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        b.putFloat((float)Float.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        out.print(" float");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        b.putDouble((double)1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        b.putDouble((double)Double.MIN_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        b.putDouble((double)Double.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        out.print(" double");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        b.limit(b.position());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        b.position(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        show(level, b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        out.print("    get:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        ck(b, b.getChar(), 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        ck(b, b.getChar(), Character.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        out.print(" char");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        ck(b, b.getShort(), 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        ck(b, b.getShort(), Short.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        out.print(" short");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        ck(b, b.getInt(), 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        ck(b, b.getInt(), Integer.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        out.print(" int");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        ck(b, b.getLong(), 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        ck(b, b.getLong(), Long.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        out.print(" long");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        ck(b, (long)b.getFloat(), 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        ck(b, (long)b.getFloat(), (long)Float.MIN_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        ck(b, (long)b.getFloat(), (long)Float.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        out.print(" float");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        ck(b, (long)b.getDouble(), 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        ck(b, (long)b.getDouble(), (long)Double.MIN_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        ck(b, (long)b.getDouble(), (long)Double.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        out.print(" double");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
#end[byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    private static void tryCatch(Buffer b, Class ex, Runnable thunk) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        boolean caught = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
            thunk.run();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        } catch (Throwable x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            if (ex.isAssignableFrom(x.getClass()))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                caught = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        if (!caught)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            fail(ex.getName() + " not thrown", b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    private static void tryCatch($type$ [] t, Class ex, Runnable thunk) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        tryCatch($Type$Buffer.wrap(t), ex, thunk);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    public static void test(int level, final $Type$Buffer b, boolean direct) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        show(level, b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        if (direct != b.isDirect())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            fail("Wrong direction", b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        // Gets and puts
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        relPut(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        relGet(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        absGet(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        bulkGet(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        absPut(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        relGet(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        absGet(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        bulkGet(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        bulkPutArray(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        relGet(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        bulkPutBuffer(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        relGet(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
#if[char]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        bulkPutString(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        relGet(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        b.position(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        b.limit(7);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        ck(b, b.toString().equals("bcdefg"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        // CharSequence ops
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        b.position(2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        ck(b, b.charAt(1), 'd');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        CharBuffer c = (CharBuffer)b.subSequence(1, 4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        ck(b, b.subSequence(1, 4).toString().equals("def"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        // 4938424
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        b.position(4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        ck(b, b.charAt(1), 'f');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        ck(b, b.subSequence(1, 3).toString().equals("fg"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
#end[char]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        // Compact
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        relPut(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        b.position(13);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        b.compact();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        b.flip();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        relGet(b, 13);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        // Exceptions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        boolean caught = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        relPut(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        b.limit(b.capacity() / 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        b.position(b.limit());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        tryCatch(b, BufferUnderflowException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                    b.get();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        tryCatch(b, BufferOverflowException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                    b.put(($type$)42);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        // The index must be non-negative and lesss than the buffer's limit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
                    b.get(b.limit());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                    b.get(-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
                    b.put(b.limit(), ($type$)42);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        // Values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        b.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        b.put(($type$)0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        b.put(($type$)-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        b.put(($type$)1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        b.put($Fulltype$.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        b.put($Fulltype$.MIN_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
#if[float]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        b.put(-Float.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        b.put(-Float.MIN_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        b.put(Float.NEGATIVE_INFINITY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        b.put(Float.POSITIVE_INFINITY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        b.put(Float.NaN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        b.put(0.91697687f);             // Changes value if incorrectly swapped
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
#end[float]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
#if[double]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        b.put(-Double.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        b.put(-Double.MIN_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        b.put(Double.NEGATIVE_INFINITY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        b.put(Double.POSITIVE_INFINITY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        b.put(Double.NaN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        b.put(0.5121609353879392);      // Changes value if incorrectly swapped
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
#end[double]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        $type$ v;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        b.flip();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        ck(b, b.get(), 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        ck(b, b.get(), ($type$)-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        ck(b, b.get(), 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        ck(b, b.get(), $Fulltype$.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        ck(b, b.get(), $Fulltype$.MIN_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
#if[float]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        ck(b, b.get(), -Float.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        ck(b, b.get(), -Float.MIN_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        ck(b, b.get(), Float.NEGATIVE_INFINITY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        ck(b, b.get(), Float.POSITIVE_INFINITY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        if (Float.floatToRawIntBits(v = b.get()) != Float.floatToRawIntBits(Float.NaN))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            fail(b, (long)Float.NaN, (long)v);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        ck(b, b.get(), 0.91697687f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
#end[float]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
#if[double]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        ck(b, b.get(), -Double.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        ck(b, b.get(), -Double.MIN_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        ck(b, b.get(), Double.NEGATIVE_INFINITY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        ck(b, b.get(), Double.POSITIVE_INFINITY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        if (Double.doubleToRawLongBits(v = b.get())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
            != Double.doubleToRawLongBits(Double.NaN))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
            fail(b, (long)Double.NaN, (long)v);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        ck(b, b.get(), 0.5121609353879392);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
#end[double]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        // Comparison
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        b.rewind();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        $Type$Buffer b2 = $Type$Buffer.allocate(b.capacity());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        b2.put(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        b2.flip();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        b.position(2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        b2.position(2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        if (!b.equals(b2)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
            for (int i = 2; i < b.limit(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
                $type$ x = b.get(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
                $type$ y = b2.get(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
                if (x != y
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
#if[double]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
                    || Double.compare(x, y) != 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
#end[double]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
#if[float]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
                    || Float.compare(x, y) != 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
#end[float]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
                    )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                    out.println("[" + i + "] " + x + " != " + y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
            fail("Identical buffers not equal", b, b2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        if (b.compareTo(b2) != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
            fail("Comparison to identical buffer != 0", b, b2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        b.limit(b.limit() + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        b.position(b.limit() - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        b.put(($type$)99);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        b.rewind();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        b2.rewind();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        if (b.equals(b2))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
            fail("Non-identical buffers equal", b, b2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        if (b.compareTo(b2) <= 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
            fail("Comparison to shorter buffer <= 0", b, b2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        b.limit(b.limit() - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        b.put(2, ($type$)42);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        if (b.equals(b2))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
            fail("Non-identical buffers equal", b, b2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        if (b.compareTo(b2) <= 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
            fail("Comparison to lesser buffer <= 0", b, b2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        // Sub, dup
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        relPut(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        relGet(b.duplicate());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        b.position(13);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        relGet(b.duplicate(), 13);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        relGet(b.duplicate().slice(), 13);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        relGet(b.slice(), 13);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        relGet(b.slice().duplicate(), 13);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        // Slice
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        b.position(5);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        $Type$Buffer sb = b.slice();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        checkSlice(b, sb);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        b.position(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        $Type$Buffer sb2 = sb.slice();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        checkSlice(sb, sb2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        if (!sb.equals(sb2))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
            fail("Sliced slices do not match", sb, sb2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        if ((sb.hasArray()) && (sb.arrayOffset() != sb2.arrayOffset()))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
            fail("Array offsets do not match: "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
                 + sb.arrayOffset() + " != " + sb2.arrayOffset(), sb, sb2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
#if[byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        // Views
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        b.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        b.order(ByteOrder.BIG_ENDIAN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
        testViews(level + 1, b, direct);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        for (int i = 1; i <= 9; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
            b.position(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
            show(level + 1, b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
            testViews(level + 2, b, direct);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        b.position(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
        b.order(ByteOrder.LITTLE_ENDIAN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        testViews(level + 1, b, direct);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
        // Heterogeneous accessors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
        b.order(ByteOrder.BIG_ENDIAN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        for (int i = 0; i <= 9; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
            b.position(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
            testHet(level + 1, b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
        b.order(ByteOrder.LITTLE_ENDIAN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
        b.position(3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
        testHet(level + 1, b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
#end[byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        // Read-only views
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        b.rewind();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        final $Type$Buffer rb = b.asReadOnlyBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        if (!b.equals(rb))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
            fail("Buffer not equal to read-only view", b, rb);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
        show(level + 1, rb);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
                    relPut(rb);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
                    absPut(rb);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
                    bulkPutArray(rb);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
                    bulkPutBuffer(rb);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
                    rb.compact();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
#if[byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
                    rb.putChar((char)1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
                    rb.putChar(0, (char)1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
                    rb.putShort((short)1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
                    rb.putShort(0, (short)1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
                    rb.putInt(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
                    rb.putInt(0, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
                    rb.putLong((long)1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
                    rb.putLong(0, (long)1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
                    rb.putFloat((float)1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
                    rb.putFloat(0, (float)1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
                    rb.putDouble((double)1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
                    rb.putDouble(0, (double)1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
#end[byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
        if (rb.getClass().getName().startsWith("java.nio.Heap")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
            tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
                    public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
                        rb.array();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
                    }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
            tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
                    public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
                        rb.arrayOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
                    }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
            if (rb.hasArray())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
                fail("Read-only heap buffer's backing array is accessible",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
                     rb);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
        // Bulk puts from read-only buffers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
        b.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
        rb.rewind();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
        b.put(rb);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
#if[byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
        // For byte buffers, test both the direct and non-direct cases
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
        $Type$Buffer ob
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
            = (b.isDirect()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
               ? $Type$Buffer.allocate(rb.capacity())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
               : $Type$Buffer.allocateDirect(rb.capacity()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
        rb.rewind();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
        ob.put(rb);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
#end[byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
        relPut(b);                       // Required by testViews
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
#if[char]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
    private static void testStr() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
        final String s = "abcdefghijklm";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
        int start = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
        int end = 9;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
        final CharBuffer b = CharBuffer.wrap(s, start, end);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
        show(0, b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
        ck(b, b.toString().equals(s.substring(start, end)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
        ck(b, b.toString().equals("defghi"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
        ck(b, b.isReadOnly());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
                    b.put('x');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
        ck(b, start, b.position());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
        ck(b, end, b.limit());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
        ck(b, s.length(), b.capacity());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
        // The index, relative to the position, must be non-negative and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
        // smaller than remaining().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
        tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
                    b.charAt(-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
        tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
                    b.charAt(b.remaining());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
        // The index must be non-negative and less than the buffer's limit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
        tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
                    b.get(b.limit());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
        tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
                    b.get(-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
        // The start must be non-negative and no larger than remaining().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
        tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
                    b.subSequence(-1, b.remaining());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
        tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
                    b.subSequence(b.remaining() + 1, b.remaining());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
        // The end must be no smaller than start and no larger than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
        // remaining().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
        tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
                    b.subSequence(2, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
        tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
                    b.subSequence(0, b.remaining() + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
        // The offset must be non-negative and no larger than <array.length>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
        tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
                    $Type$Buffer.wrap(s, -1, s.length());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
        tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
                    $Type$Buffer.wrap(s, s.length() + 1, s.length());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
        tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
                    $Type$Buffer.wrap(s, 1, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
        tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
                    $Type$Buffer.wrap(s, 0, s.length() + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
#end[char]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
    public static void test(final $type$ [] ba) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
        int offset = 47;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
        int length = 900;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
        final $Type$Buffer b = $Type$Buffer.wrap(ba, offset, length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
        show(0, b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
        ck(b, b.capacity(), ba.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
        ck(b, b.position(), offset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
        ck(b, b.limit(), offset + length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
        // The offset must be non-negative and no larger than <array.length>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
        tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
                    $Type$Buffer.wrap(ba, -1, ba.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
        tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
                    $Type$Buffer.wrap(ba, ba.length + 1, ba.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
        tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
                    $Type$Buffer.wrap(ba, 0, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
        tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
                    $Type$Buffer.wrap(ba, 0, ba.length + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
        // A NullPointerException will be thrown if the array is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
        tryCatch(ba, NullPointerException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
                    $Type$Buffer.wrap(($type$ []) null, 0, 5);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
        tryCatch(ba, NullPointerException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
                    $Type$Buffer.wrap(($type$ []) null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
    private static void testAllocate() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
        // An IllegalArgumentException will be thrown for negative capacities.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
        tryCatch((Buffer) null, IllegalArgumentException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
                    $Type$Buffer.allocate(-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
#if[byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
        tryCatch((Buffer) null, IllegalArgumentException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
                    $Type$Buffer.allocateDirect(-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
#end[byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
    public static void test() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
        testAllocate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
        test(0, $Type$Buffer.allocate(7 * 1024), false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
        test(0, $Type$Buffer.wrap(new $type$[7 * 1024], 0, 7 * 1024), false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
        test(new $type$[1024]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
#if[byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
        $Type$Buffer b = $Type$Buffer.allocateDirect(7 * 1024);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
        for (b.position(0); b.position() < b.limit(); )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
            ck(b, b.get(), 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
        test(0, b, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
#end[byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
#if[char]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
        testStr();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
#end[char]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
        callReset($Type$Buffer.allocate(10));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
#if[byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
#else[byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
        putBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
#end[byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
}