jdk/test/java/nio/Buffer/Basic-X.java.template
author bpb
Fri, 24 Jul 2015 11:52:30 -0700
changeset 31873 87b015c2cd36
parent 14342 8435a30053c1
child 36933 3e6453e2d833
permissions -rw-r--r--
8065556: (bf) Buffer.position and other methods should include detail in IAE Summary: Add messages to IAEs which have none. Reviewed-by: alanb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
14342
8435a30053c1 7197491: update copyright year to match last edit in jdk8 jdk repository
alanb
parents: 14001
diff changeset
     2
 * Copyright (c) 2000, 2012, Oracle and/or its affiliates. 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
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4502
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4502
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4502
diff changeset
    21
 * questions.
2
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
4502
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
    41
    private static final $type$[] VALUES = {
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
    42
        $Fulltype$.MIN_VALUE,
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
    43
        ($type$) -1,
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
    44
        ($type$) 0,
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
    45
        ($type$) 1,
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
    46
        $Fulltype$.MAX_VALUE,
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
    47
#if[float]
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
    48
        $Fulltype$.NEGATIVE_INFINITY,
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
    49
        $Fulltype$.POSITIVE_INFINITY,
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
    50
        $Fulltype$.NaN,
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
    51
        ($type$) -0.0,
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
    52
#end[float]
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
    53
#if[double]
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
    54
        $Fulltype$.NEGATIVE_INFINITY,
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
    55
        $Fulltype$.POSITIVE_INFINITY,
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
    56
        $Fulltype$.NaN,
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
    57
        ($type$) -0.0,
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
    58
#end[double]
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
    59
    };
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
    60
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    private static void relGet($Type$Buffer b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        int n = b.capacity();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        $type$ v;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        for (int i = 0; i < n; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
            ck(b, (long)b.get(), (long)(($type$)ic(i)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        b.rewind();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    private static void relGet($Type$Buffer b, int start) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        int n = b.remaining();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        $type$ v;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        for (int i = start; i < n; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
            ck(b, (long)b.get(), (long)(($type$)ic(i)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        b.rewind();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    private static void absGet($Type$Buffer b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        int n = b.capacity();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        $type$ v;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        for (int i = 0; i < n; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            ck(b, (long)b.get(), (long)(($type$)ic(i)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        b.rewind();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    private static void bulkGet($Type$Buffer b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        int n = b.capacity();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        $type$[] a = new $type$[n + 7];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        b.get(a, 7, n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        for (int i = 0; i < n; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            ck(b, (long)a[i + 7], (long)(($type$)ic(i)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    private static void relPut($Type$Buffer b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        int n = b.capacity();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        b.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        for (int i = 0; i < n; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            b.put(($type$)ic(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        b.flip();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    private static void absPut($Type$Buffer b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        int n = b.capacity();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        b.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        for (int i = 0; i < n; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            b.put(i, ($type$)ic(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        b.limit(n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        b.position(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    private static void bulkPutArray($Type$Buffer b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        int n = b.capacity();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        b.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        $type$[] a = new $type$[n + 7];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        for (int i = 0; i < n; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            a[i + 7] = ($type$)ic(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        b.put(a, 7, n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        b.flip();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    private static void bulkPutBuffer($Type$Buffer b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        int n = b.capacity();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        b.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        $Type$Buffer c = $Type$Buffer.allocate(n + 7);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        c.position(7);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        for (int i = 0; i < n; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            c.put(($type$)ic(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        c.flip();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        c.position(7);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        b.put(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        b.flip();
31873
87b015c2cd36 8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents: 14342
diff changeset
   131
        try {
87b015c2cd36 8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents: 14342
diff changeset
   132
            b.put(b);
87b015c2cd36 8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents: 14342
diff changeset
   133
            fail("IllegalArgumentException expected for put into same buffer");
87b015c2cd36 8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents: 14342
diff changeset
   134
        } catch (IllegalArgumentException e) {
87b015c2cd36 8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents: 14342
diff changeset
   135
            if (e.getMessage() == null) {
87b015c2cd36 8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents: 14342
diff changeset
   136
                fail("Non-null IllegalArgumentException message expected from"
87b015c2cd36 8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents: 14342
diff changeset
   137
                     + " put into same buffer");
87b015c2cd36 8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents: 14342
diff changeset
   138
            }
87b015c2cd36 8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents: 14342
diff changeset
   139
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    //6231529
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    private static void callReset($Type$Buffer b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        b.position(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        b.mark();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        b.duplicate().reset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        b.asReadOnlyBuffer().reset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
#if[byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
#else[byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    // 6221101-6234263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    private static void putBuffer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        final int cap = 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        $Type$Buffer direct1 = ByteBuffer.allocateDirect(cap).as$Type$Buffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        $Type$Buffer nondirect1 = ByteBuffer.allocate(cap).as$Type$Buffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        direct1.put(nondirect1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        $Type$Buffer direct2 = ByteBuffer.allocateDirect(cap).as$Type$Buffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        $Type$Buffer nondirect2 = ByteBuffer.allocate(cap).as$Type$Buffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        nondirect2.put(direct2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        $Type$Buffer direct3 = ByteBuffer.allocateDirect(cap).as$Type$Buffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        $Type$Buffer direct4 = ByteBuffer.allocateDirect(cap).as$Type$Buffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        direct3.put(direct4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        $Type$Buffer nondirect3 = ByteBuffer.allocate(cap).as$Type$Buffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        $Type$Buffer nondirect4 = ByteBuffer.allocate(cap).as$Type$Buffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        nondirect3.put(nondirect4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
#end[byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
#if[char]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    private static void bulkPutString($Type$Buffer b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        int n = b.capacity();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        b.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        StringBuffer sb = new StringBuffer(n + 7);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        sb.append("1234567");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        for (int i = 0; i < n; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            sb.append((char)ic(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        b.put(sb.toString(), 7, 7 + n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        b.flip();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
#end[char]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    private static void checkSlice($Type$Buffer b, $Type$Buffer slice) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        ck(slice, 0, slice.position());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        ck(slice, b.remaining(), slice.limit());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        ck(slice, b.remaining(), slice.capacity());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        if (b.isDirect() != slice.isDirect())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            fail("Lost direction", slice);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        if (b.isReadOnly() != slice.isReadOnly())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            fail("Lost read-only", slice);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
#if[byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    private static void checkBytes(ByteBuffer b, byte[] bs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        int n = bs.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        int p = b.position();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        byte v;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        if (b.order() == ByteOrder.BIG_ENDIAN) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            for (int i = 0; i < n; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                ck(b, b.get(), bs[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            for (int i = n - 1; i >= 0; i--)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                ck(b, b.get(), bs[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        b.position(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
1634
3871c2046043 6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents: 2
diff changeset
   217
    private static void compact(Buffer b) {
3871c2046043 6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents: 2
diff changeset
   218
        try {
3871c2046043 6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents: 2
diff changeset
   219
            Class<?> cl = b.getClass();
3871c2046043 6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents: 2
diff changeset
   220
            Method m = cl.getDeclaredMethod("compact");
3871c2046043 6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents: 2
diff changeset
   221
            m.setAccessible(true);
3871c2046043 6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents: 2
diff changeset
   222
            m.invoke(b);
3871c2046043 6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents: 2
diff changeset
   223
        } catch (Exception e) {
3871c2046043 6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents: 2
diff changeset
   224
            fail(e.getMessage(), b);
3871c2046043 6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents: 2
diff changeset
   225
        }
3871c2046043 6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents: 2
diff changeset
   226
    }
3871c2046043 6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents: 2
diff changeset
   227
3871c2046043 6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents: 2
diff changeset
   228
    private static void checkInvalidMarkException(final Buffer b) {
3871c2046043 6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents: 2
diff changeset
   229
        tryCatch(b, InvalidMarkException.class, new Runnable() {
3871c2046043 6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents: 2
diff changeset
   230
            public void run() {
3871c2046043 6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents: 2
diff changeset
   231
                b.mark();
3871c2046043 6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents: 2
diff changeset
   232
                compact(b);
3871c2046043 6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents: 2
diff changeset
   233
                b.reset();
3871c2046043 6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents: 2
diff changeset
   234
            }});
3871c2046043 6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents: 2
diff changeset
   235
    }
3871c2046043 6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents: 2
diff changeset
   236
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    private static void testViews(int level, ByteBuffer b, boolean direct) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        ShortBuffer sb = b.asShortBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        BasicShort.test(level, sb, direct);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        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
   242
        checkInvalidMarkException(sb);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        CharBuffer cb = b.asCharBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        BasicChar.test(level, cb, direct);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        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
   247
        checkInvalidMarkException(cb);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        IntBuffer ib = b.asIntBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        BasicInt.test(level, ib, direct);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        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
   252
        checkInvalidMarkException(ib);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        LongBuffer lb = b.asLongBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        BasicLong.test(level, lb, direct);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        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
   257
        checkInvalidMarkException(lb);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        FloatBuffer fb = b.asFloatBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        BasicFloat.test(level, fb, direct);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        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
   262
        checkInvalidMarkException(fb);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        DoubleBuffer db = b.asDoubleBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        BasicDouble.test(level, db, direct);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        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
   267
        checkInvalidMarkException(db);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    private static void testHet(int level, ByteBuffer b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        int p = b.position();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        b.limit(b.capacity());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        show(level, b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        out.print("    put:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        b.putChar((char)1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        b.putChar((char)Character.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        out.print(" char");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        b.putShort((short)1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        b.putShort((short)Short.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        out.print(" short");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        b.putInt(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        b.putInt(Integer.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        out.print(" int");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        b.putLong((long)1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        b.putLong((long)Long.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        out.print(" long");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        b.putFloat((float)1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        b.putFloat((float)Float.MIN_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        b.putFloat((float)Float.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        out.print(" float");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        b.putDouble((double)1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        b.putDouble((double)Double.MIN_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        b.putDouble((double)Double.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        out.print(" double");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        b.limit(b.position());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        b.position(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        show(level, b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        out.print("    get:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        ck(b, b.getChar(), 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        ck(b, b.getChar(), Character.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        out.print(" char");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        ck(b, b.getShort(), 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        ck(b, b.getShort(), Short.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        out.print(" short");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        ck(b, b.getInt(), 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        ck(b, b.getInt(), Integer.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        out.print(" int");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        ck(b, b.getLong(), 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        ck(b, b.getLong(), Long.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        out.print(" long");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        ck(b, (long)b.getFloat(), 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        ck(b, (long)b.getFloat(), (long)Float.MIN_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        ck(b, (long)b.getFloat(), (long)Float.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        out.print(" float");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        ck(b, (long)b.getDouble(), 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        ck(b, (long)b.getDouble(), (long)Double.MIN_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        ck(b, (long)b.getDouble(), (long)Double.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        out.print(" double");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
#end[byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
4502
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   341
    private static void fail(String problem,
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   342
                             $Type$Buffer xb, $Type$Buffer yb,
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   343
                             $type$ x, $type$ y) {
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   344
        fail(problem + String.format(": x=%s y=%s", x, y), xb, yb);
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   345
    }
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   346
14001
e8e8413ad49a 7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents: 13563
diff changeset
   347
    private static void tryCatch(Buffer b, Class<?> ex, Runnable thunk) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        boolean caught = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
            thunk.run();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        } catch (Throwable x) {
1634
3871c2046043 6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents: 2
diff changeset
   352
            if (ex.isAssignableFrom(x.getClass())) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                caught = true;
1634
3871c2046043 6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents: 2
diff changeset
   354
            } else {
3871c2046043 6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents: 2
diff changeset
   355
                fail(x.getMessage() + " not expected");
3871c2046043 6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents: 2
diff changeset
   356
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        if (!caught)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            fail(ex.getName() + " not thrown", b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
14001
e8e8413ad49a 7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents: 13563
diff changeset
   362
    private static void tryCatch($type$ [] t, Class<?> ex, Runnable thunk) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        tryCatch($Type$Buffer.wrap(t), ex, thunk);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    public static void test(int level, final $Type$Buffer b, boolean direct) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        show(level, b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        if (direct != b.isDirect())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
            fail("Wrong direction", b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        // Gets and puts
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        relPut(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        relGet(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        absGet(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        bulkGet(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        absPut(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        relGet(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        absGet(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        bulkGet(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        bulkPutArray(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        relGet(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        bulkPutBuffer(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        relGet(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
#if[char]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        bulkPutString(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        relGet(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        b.position(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        b.limit(7);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        ck(b, b.toString().equals("bcdefg"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        // CharSequence ops
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        b.position(2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        ck(b, b.charAt(1), 'd');
2593
76032557be03 6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents: 1639
diff changeset
   403
        CharBuffer c = b.subSequence(1, 4);
76032557be03 6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents: 1639
diff changeset
   404
        ck(c, c.capacity(), b.capacity());
76032557be03 6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents: 1639
diff changeset
   405
        ck(c, c.position(), b.position()+1);
76032557be03 6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents: 1639
diff changeset
   406
        ck(c, c.limit(), b.position()+4);
76032557be03 6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents: 1639
diff changeset
   407
        ck(c, b.subSequence(1, 4).toString().equals("def"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        // 4938424
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        b.position(4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        ck(b, b.charAt(1), 'f');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        ck(b, b.subSequence(1, 3).toString().equals("fg"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
13563
13c8e8f0302b 7190219: (bf) CharBuffer.put(String,int,int) modifies position even if BufferOverflowException thrown
luchsh
parents: 5506
diff changeset
   414
        // String ops
13c8e8f0302b 7190219: (bf) CharBuffer.put(String,int,int) modifies position even if BufferOverflowException thrown
luchsh
parents: 5506
diff changeset
   415
13c8e8f0302b 7190219: (bf) CharBuffer.put(String,int,int) modifies position even if BufferOverflowException thrown
luchsh
parents: 5506
diff changeset
   416
        // 7190219
13c8e8f0302b 7190219: (bf) CharBuffer.put(String,int,int) modifies position even if BufferOverflowException thrown
luchsh
parents: 5506
diff changeset
   417
        b.clear();
13c8e8f0302b 7190219: (bf) CharBuffer.put(String,int,int) modifies position even if BufferOverflowException thrown
luchsh
parents: 5506
diff changeset
   418
        int pos = b.position();
13c8e8f0302b 7190219: (bf) CharBuffer.put(String,int,int) modifies position even if BufferOverflowException thrown
luchsh
parents: 5506
diff changeset
   419
        tryCatch(b, BufferOverflowException.class, new Runnable() {
13c8e8f0302b 7190219: (bf) CharBuffer.put(String,int,int) modifies position even if BufferOverflowException thrown
luchsh
parents: 5506
diff changeset
   420
            public void run() {
13c8e8f0302b 7190219: (bf) CharBuffer.put(String,int,int) modifies position even if BufferOverflowException thrown
luchsh
parents: 5506
diff changeset
   421
                b.put(String.valueOf(new char[b.capacity() + 1]), 0,
13c8e8f0302b 7190219: (bf) CharBuffer.put(String,int,int) modifies position even if BufferOverflowException thrown
luchsh
parents: 5506
diff changeset
   422
                        b.capacity() + 1);
13c8e8f0302b 7190219: (bf) CharBuffer.put(String,int,int) modifies position even if BufferOverflowException thrown
luchsh
parents: 5506
diff changeset
   423
            }});
13c8e8f0302b 7190219: (bf) CharBuffer.put(String,int,int) modifies position even if BufferOverflowException thrown
luchsh
parents: 5506
diff changeset
   424
        ck(b, b.position(), pos);
13c8e8f0302b 7190219: (bf) CharBuffer.put(String,int,int) modifies position even if BufferOverflowException thrown
luchsh
parents: 5506
diff changeset
   425
        relGet(b);
13c8e8f0302b 7190219: (bf) CharBuffer.put(String,int,int) modifies position even if BufferOverflowException thrown
luchsh
parents: 5506
diff changeset
   426
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
#end[char]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        // Compact
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        relPut(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        b.position(13);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        b.compact();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        b.flip();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        relGet(b, 13);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        // Exceptions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        relPut(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        b.limit(b.capacity() / 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        b.position(b.limit());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        tryCatch(b, BufferUnderflowException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                    b.get();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        tryCatch(b, BufferOverflowException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                    b.put(($type$)42);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        // The index must be non-negative and lesss than the buffer's limit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
                    b.get(b.limit());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                    b.get(-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
                    b.put(b.limit(), ($type$)42);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
1634
3871c2046043 6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents: 2
diff changeset
   468
        tryCatch(b, InvalidMarkException.class, new Runnable() {
3871c2046043 6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents: 2
diff changeset
   469
                public void run() {
3871c2046043 6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents: 2
diff changeset
   470
                    b.position(0);
3871c2046043 6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents: 2
diff changeset
   471
                    b.mark();
3871c2046043 6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents: 2
diff changeset
   472
                    b.compact();
3871c2046043 6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents: 2
diff changeset
   473
                    b.reset();
3871c2046043 6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents: 2
diff changeset
   474
                }});
3871c2046043 6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents: 2
diff changeset
   475
31873
87b015c2cd36 8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents: 14342
diff changeset
   476
        try {
87b015c2cd36 8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents: 14342
diff changeset
   477
            b.position(b.limit() + 1);
87b015c2cd36 8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents: 14342
diff changeset
   478
            fail("IllegalArgumentException expected for position beyond limit");
87b015c2cd36 8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents: 14342
diff changeset
   479
        } catch (IllegalArgumentException e) {
87b015c2cd36 8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents: 14342
diff changeset
   480
            if (e.getMessage() == null) {
87b015c2cd36 8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents: 14342
diff changeset
   481
                fail("Non-null IllegalArgumentException message expected for"
87b015c2cd36 8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents: 14342
diff changeset
   482
                     + " position beyond limit");
87b015c2cd36 8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents: 14342
diff changeset
   483
            }
87b015c2cd36 8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents: 14342
diff changeset
   484
        }
87b015c2cd36 8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents: 14342
diff changeset
   485
87b015c2cd36 8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents: 14342
diff changeset
   486
        try {
87b015c2cd36 8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents: 14342
diff changeset
   487
            b.position(-1);
87b015c2cd36 8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents: 14342
diff changeset
   488
            fail("IllegalArgumentException expected for negative position");
87b015c2cd36 8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents: 14342
diff changeset
   489
        } catch (IllegalArgumentException e) {
87b015c2cd36 8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents: 14342
diff changeset
   490
            if (e.getMessage() == null) {
87b015c2cd36 8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents: 14342
diff changeset
   491
                fail("Non-null IllegalArgumentException message expected for"
87b015c2cd36 8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents: 14342
diff changeset
   492
                     + " negative position");
87b015c2cd36 8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents: 14342
diff changeset
   493
            }
87b015c2cd36 8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents: 14342
diff changeset
   494
        }
87b015c2cd36 8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents: 14342
diff changeset
   495
87b015c2cd36 8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents: 14342
diff changeset
   496
        try {
87b015c2cd36 8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents: 14342
diff changeset
   497
            b.limit(b.capacity() + 1);
87b015c2cd36 8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents: 14342
diff changeset
   498
            fail("IllegalArgumentException expected for limit beyond capacity");
87b015c2cd36 8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents: 14342
diff changeset
   499
        } catch (IllegalArgumentException e) {
87b015c2cd36 8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents: 14342
diff changeset
   500
            if (e.getMessage() == null) {
87b015c2cd36 8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents: 14342
diff changeset
   501
                fail("Non-null IllegalArgumentException message expected for"
87b015c2cd36 8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents: 14342
diff changeset
   502
                     + " limit beyond capacity");
87b015c2cd36 8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents: 14342
diff changeset
   503
            }
87b015c2cd36 8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents: 14342
diff changeset
   504
        }
87b015c2cd36 8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents: 14342
diff changeset
   505
87b015c2cd36 8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents: 14342
diff changeset
   506
        try {
87b015c2cd36 8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents: 14342
diff changeset
   507
            b.limit(-1);
87b015c2cd36 8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents: 14342
diff changeset
   508
            fail("IllegalArgumentException expected for negative limit");
87b015c2cd36 8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents: 14342
diff changeset
   509
        } catch (IllegalArgumentException e) {
87b015c2cd36 8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents: 14342
diff changeset
   510
            if (e.getMessage() == null) {
87b015c2cd36 8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents: 14342
diff changeset
   511
                fail("Non-null IllegalArgumentException message expected for"
87b015c2cd36 8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents: 14342
diff changeset
   512
                     + " negative limit");
87b015c2cd36 8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents: 14342
diff changeset
   513
            }
87b015c2cd36 8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents: 14342
diff changeset
   514
        }
87b015c2cd36 8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents: 14342
diff changeset
   515
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        // Values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        b.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        b.put(($type$)0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        b.put(($type$)-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        b.put(($type$)1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        b.put($Fulltype$.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        b.put($Fulltype$.MIN_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
#if[float]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        b.put(-Float.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
        b.put(-Float.MIN_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        b.put(Float.NEGATIVE_INFINITY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
        b.put(Float.POSITIVE_INFINITY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
        b.put(Float.NaN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        b.put(0.91697687f);             // Changes value if incorrectly swapped
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
#end[float]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
#if[double]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        b.put(-Double.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        b.put(-Double.MIN_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
        b.put(Double.NEGATIVE_INFINITY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
        b.put(Double.POSITIVE_INFINITY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
        b.put(Double.NaN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
        b.put(0.5121609353879392);      // Changes value if incorrectly swapped
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
#end[double]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
        $type$ v;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        b.flip();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        ck(b, b.get(), 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        ck(b, b.get(), ($type$)-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        ck(b, b.get(), 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        ck(b, b.get(), $Fulltype$.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        ck(b, b.get(), $Fulltype$.MIN_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
#if[float]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        ck(b, b.get(), -Float.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
        ck(b, b.get(), -Float.MIN_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
        ck(b, b.get(), Float.NEGATIVE_INFINITY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
        ck(b, b.get(), Float.POSITIVE_INFINITY);
31873
87b015c2cd36 8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents: 14342
diff changeset
   554
        if (Float.floatToRawIntBits(v = b.get()) !=
87b015c2cd36 8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents: 14342
diff changeset
   555
            Float.floatToRawIntBits(Float.NaN))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
            fail(b, (long)Float.NaN, (long)v);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
        ck(b, b.get(), 0.91697687f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
#end[float]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
#if[double]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        ck(b, b.get(), -Double.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
        ck(b, b.get(), -Double.MIN_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
        ck(b, b.get(), Double.NEGATIVE_INFINITY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
        ck(b, b.get(), Double.POSITIVE_INFINITY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
        if (Double.doubleToRawLongBits(v = b.get())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
            != Double.doubleToRawLongBits(Double.NaN))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
            fail(b, (long)Double.NaN, (long)v);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
        ck(b, b.get(), 0.5121609353879392);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
#end[double]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        // Comparison
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
        b.rewind();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        $Type$Buffer b2 = $Type$Buffer.allocate(b.capacity());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
        b2.put(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
        b2.flip();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        b.position(2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
        b2.position(2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
        if (!b.equals(b2)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
            for (int i = 2; i < b.limit(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
                $type$ x = b.get(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
                $type$ y = b2.get(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
                if (x != y
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
#if[double]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
                    || Double.compare(x, y) != 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
#end[double]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
#if[float]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
                    || Float.compare(x, y) != 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
#end[float]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
                    )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
                    out.println("[" + i + "] " + x + " != " + y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
            fail("Identical buffers not equal", b, b2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
        if (b.compareTo(b2) != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
            fail("Comparison to identical buffer != 0", b, b2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        b.limit(b.limit() + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
        b.position(b.limit() - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
        b.put(($type$)99);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
        b.rewind();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        b2.rewind();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
        if (b.equals(b2))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
            fail("Non-identical buffers equal", b, b2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
        if (b.compareTo(b2) <= 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
            fail("Comparison to shorter buffer <= 0", b, b2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
        b.limit(b.limit() - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
        b.put(2, ($type$)42);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
        if (b.equals(b2))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
            fail("Non-identical buffers equal", b, b2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
        if (b.compareTo(b2) <= 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
            fail("Comparison to lesser buffer <= 0", b, b2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
4502
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   614
        // Check equals and compareTo with interesting values
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   615
        for ($type$ x : VALUES) {
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   616
            $Type$Buffer xb = $Type$Buffer.wrap(new $type$[] { x });
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   617
            if (xb.compareTo(xb) != 0) {
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   618
                fail("compareTo not reflexive", xb, xb, x, x);
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   619
            }
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   620
            if (! xb.equals(xb)) {
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   621
                fail("equals not reflexive", xb, xb, x, x);
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   622
            }
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   623
            for ($type$ y : VALUES) {
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   624
                $Type$Buffer yb = $Type$Buffer.wrap(new $type$[] { y });
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   625
                if (xb.compareTo(yb) != - yb.compareTo(xb)) {
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   626
                    fail("compareTo not anti-symmetric",
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   627
                         xb, yb, x, y);
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   628
                }
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   629
                if ((xb.compareTo(yb) == 0) != xb.equals(yb)) {
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   630
                    fail("compareTo inconsistent with equals",
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   631
                         xb, yb, x, y);
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   632
                }
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   633
                if (xb.compareTo(yb) != $Fulltype$.compare(x, y)) {
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   634
#if[float]
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   635
                    if (x == 0.0 && y == 0.0) continue;
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   636
#end[float]
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   637
#if[double]
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   638
                    if (x == 0.0 && y == 0.0) continue;
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   639
#end[double]
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   640
                    fail("Incorrect results for $Type$Buffer.compareTo",
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   641
                         xb, yb, x, y);
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   642
                }
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   643
                if (xb.equals(yb) != ((x == y) || ((x != x) && (y != y)))) {
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   644
                    fail("Incorrect results for $Type$Buffer.equals",
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   645
                         xb, yb, x, y);
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   646
                }
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   647
            }
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   648
        }
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   649
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
        // Sub, dup
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
        relPut(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
        relGet(b.duplicate());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
        b.position(13);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
        relGet(b.duplicate(), 13);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
        relGet(b.duplicate().slice(), 13);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
        relGet(b.slice(), 13);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
        relGet(b.slice().duplicate(), 13);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
        // Slice
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
        b.position(5);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
        $Type$Buffer sb = b.slice();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
        checkSlice(b, sb);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
        b.position(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
        $Type$Buffer sb2 = sb.slice();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
        checkSlice(sb, sb2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
        if (!sb.equals(sb2))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
            fail("Sliced slices do not match", sb, sb2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
        if ((sb.hasArray()) && (sb.arrayOffset() != sb2.arrayOffset()))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
            fail("Array offsets do not match: "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
                 + sb.arrayOffset() + " != " + sb2.arrayOffset(), sb, sb2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
#if[byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
        // Views
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
        b.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
        b.order(ByteOrder.BIG_ENDIAN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
        testViews(level + 1, b, direct);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
        for (int i = 1; i <= 9; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
            b.position(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
            show(level + 1, b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
            testViews(level + 2, b, direct);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
        b.position(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
        b.order(ByteOrder.LITTLE_ENDIAN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
        testViews(level + 1, b, direct);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
        // Heterogeneous accessors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
        b.order(ByteOrder.BIG_ENDIAN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
        for (int i = 0; i <= 9; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
            b.position(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
            testHet(level + 1, b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
        b.order(ByteOrder.LITTLE_ENDIAN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
        b.position(3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
        testHet(level + 1, b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
#end[byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
        // Read-only views
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
        b.rewind();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
        final $Type$Buffer rb = b.asReadOnlyBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
        if (!b.equals(rb))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
            fail("Buffer not equal to read-only view", b, rb);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
        show(level + 1, rb);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
                    relPut(rb);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
                    absPut(rb);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
                    bulkPutArray(rb);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
                    bulkPutBuffer(rb);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
14001
e8e8413ad49a 7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents: 13563
diff changeset
   734
        // put($Type$Buffer) should not change source position
e8e8413ad49a 7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents: 13563
diff changeset
   735
        final $Type$Buffer src = $Type$Buffer.allocate(1);
e8e8413ad49a 7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents: 13563
diff changeset
   736
        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
e8e8413ad49a 7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents: 13563
diff changeset
   737
                public void run() {
e8e8413ad49a 7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents: 13563
diff changeset
   738
                    rb.put(src);
e8e8413ad49a 7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents: 13563
diff changeset
   739
                 }});
e8e8413ad49a 7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents: 13563
diff changeset
   740
        ck(src, src.position(), 0);
e8e8413ad49a 7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents: 13563
diff changeset
   741
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
                    rb.compact();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
#if[byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
                    rb.putChar((char)1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
                    rb.putChar(0, (char)1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
                    rb.putShort((short)1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
                    rb.putShort(0, (short)1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
                    rb.putInt(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
                    rb.putInt(0, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
                    rb.putLong((long)1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
                    rb.putLong(0, (long)1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
                    rb.putFloat((float)1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
                    rb.putFloat(0, (float)1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
                    rb.putDouble((double)1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
                    rb.putDouble(0, (double)1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
#end[byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
14001
e8e8413ad49a 7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents: 13563
diff changeset
   805
#if[char]
e8e8413ad49a 7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents: 13563
diff changeset
   806
e8e8413ad49a 7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents: 13563
diff changeset
   807
        // 7199551
e8e8413ad49a 7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents: 13563
diff changeset
   808
        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
e8e8413ad49a 7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents: 13563
diff changeset
   809
            public void run() {
e8e8413ad49a 7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents: 13563
diff changeset
   810
                String s = new String(new char[rb.remaining() + 1]);
e8e8413ad49a 7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents: 13563
diff changeset
   811
                rb.put(s);
e8e8413ad49a 7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents: 13563
diff changeset
   812
            }});
e8e8413ad49a 7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents: 13563
diff changeset
   813
        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
e8e8413ad49a 7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents: 13563
diff changeset
   814
            public void run() {
e8e8413ad49a 7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents: 13563
diff changeset
   815
                String s = new String(new char[rb.remaining() + 1]);
e8e8413ad49a 7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents: 13563
diff changeset
   816
                rb.append(s);
e8e8413ad49a 7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents: 13563
diff changeset
   817
            }});
e8e8413ad49a 7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents: 13563
diff changeset
   818
e8e8413ad49a 7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents: 13563
diff changeset
   819
#end[char]
e8e8413ad49a 7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents: 13563
diff changeset
   820
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
        if (rb.getClass().getName().startsWith("java.nio.Heap")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
            tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
                    public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
                        rb.array();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
                    }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
            tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
                    public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
                        rb.arrayOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
                    }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
            if (rb.hasArray())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
                fail("Read-only heap buffer's backing array is accessible",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
                     rb);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
        // Bulk puts from read-only buffers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
        b.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
        rb.rewind();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
        b.put(rb);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
#if[byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
        // For byte buffers, test both the direct and non-direct cases
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
        $Type$Buffer ob
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
            = (b.isDirect()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
               ? $Type$Buffer.allocate(rb.capacity())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
               : $Type$Buffer.allocateDirect(rb.capacity()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
        rb.rewind();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
        ob.put(rb);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
#end[byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
        relPut(b);                       // Required by testViews
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
#if[char]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
    private static void testStr() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
        final String s = "abcdefghijklm";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
        int start = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
        int end = 9;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
        final CharBuffer b = CharBuffer.wrap(s, start, end);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
        show(0, b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
        ck(b, b.toString().equals(s.substring(start, end)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
        ck(b, b.toString().equals("defghi"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
        ck(b, b.isReadOnly());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
                    b.put('x');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
        ck(b, start, b.position());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
        ck(b, end, b.limit());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
        ck(b, s.length(), b.capacity());
2593
76032557be03 6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents: 1639
diff changeset
   877
        b.position(6);
76032557be03 6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents: 1639
diff changeset
   878
        ck(b, b.subSequence(0,3).toString().equals("ghi"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
        // The index, relative to the position, must be non-negative and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
        // smaller than remaining().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
        tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
                    b.charAt(-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
        tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
                    b.charAt(b.remaining());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
        // The index must be non-negative and less than the buffer's limit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
        tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
                    b.get(b.limit());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
        tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
                    b.get(-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
        // The start must be non-negative and no larger than remaining().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
        tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
                    b.subSequence(-1, b.remaining());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
        tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
                    b.subSequence(b.remaining() + 1, b.remaining());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
        // The end must be no smaller than start and no larger than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
        // remaining().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
        tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
                    b.subSequence(2, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
        tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
                    b.subSequence(0, b.remaining() + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
        // The offset must be non-negative and no larger than <array.length>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
        tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
                    $Type$Buffer.wrap(s, -1, s.length());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
        tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
                    $Type$Buffer.wrap(s, s.length() + 1, s.length());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
        tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
                    $Type$Buffer.wrap(s, 1, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
        tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
                    $Type$Buffer.wrap(s, 0, s.length() + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
#end[char]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
    public static void test(final $type$ [] ba) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
        int offset = 47;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
        int length = 900;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
        final $Type$Buffer b = $Type$Buffer.wrap(ba, offset, length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
        show(0, b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
        ck(b, b.capacity(), ba.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
        ck(b, b.position(), offset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
        ck(b, b.limit(), offset + length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
        // The offset must be non-negative and no larger than <array.length>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
        tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
                    $Type$Buffer.wrap(ba, -1, ba.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
        tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
                    $Type$Buffer.wrap(ba, ba.length + 1, ba.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
        tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
                    $Type$Buffer.wrap(ba, 0, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
        tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
                    $Type$Buffer.wrap(ba, 0, ba.length + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
        // A NullPointerException will be thrown if the array is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
        tryCatch(ba, NullPointerException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
                    $Type$Buffer.wrap(($type$ []) null, 0, 5);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
        tryCatch(ba, NullPointerException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
                    $Type$Buffer.wrap(($type$ []) null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
    private static void testAllocate() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
        // An IllegalArgumentException will be thrown for negative capacities.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
        tryCatch((Buffer) null, IllegalArgumentException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
                    $Type$Buffer.allocate(-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
                }});
31873
87b015c2cd36 8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents: 14342
diff changeset
   987
        try {
87b015c2cd36 8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents: 14342
diff changeset
   988
            $Type$Buffer.allocate(-1);
87b015c2cd36 8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents: 14342
diff changeset
   989
        } catch (IllegalArgumentException e) {
87b015c2cd36 8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents: 14342
diff changeset
   990
            if (e.getMessage() == null) {
87b015c2cd36 8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents: 14342
diff changeset
   991
                fail("Non-null IllegalArgumentException message expected for"
87b015c2cd36 8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents: 14342
diff changeset
   992
                     + " attempt to allocate negative capacity buffer");
87b015c2cd36 8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents: 14342
diff changeset
   993
            }
87b015c2cd36 8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents: 14342
diff changeset
   994
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
#if[byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
        tryCatch((Buffer) null, IllegalArgumentException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
                    $Type$Buffer.allocateDirect(-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
                }});
31873
87b015c2cd36 8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents: 14342
diff changeset
  1000
        try {
87b015c2cd36 8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents: 14342
diff changeset
  1001
            $Type$Buffer.allocateDirect(-1);
87b015c2cd36 8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents: 14342
diff changeset
  1002
        } catch (IllegalArgumentException e) {
87b015c2cd36 8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents: 14342
diff changeset
  1003
            if (e.getMessage() == null) {
87b015c2cd36 8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents: 14342
diff changeset
  1004
                fail("Non-null IllegalArgumentException message expected for"
87b015c2cd36 8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents: 14342
diff changeset
  1005
                     + " attempt to allocate negative capacity direct buffer");
87b015c2cd36 8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents: 14342
diff changeset
  1006
            }
87b015c2cd36 8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents: 14342
diff changeset
  1007
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
#end[byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
    public static void test() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
        testAllocate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
        test(0, $Type$Buffer.allocate(7 * 1024), false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
        test(0, $Type$Buffer.wrap(new $type$[7 * 1024], 0, 7 * 1024), false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
        test(new $type$[1024]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
#if[byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
        $Type$Buffer b = $Type$Buffer.allocateDirect(7 * 1024);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
        for (b.position(0); b.position() < b.limit(); )
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
            ck(b, b.get(), 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
        test(0, b, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
#end[byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
#if[char]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
        testStr();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
#end[char]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
        callReset($Type$Buffer.allocate(10));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
#if[byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
#else[byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
        putBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
#end[byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
}