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