author | erikj |
Tue, 12 Sep 2017 19:03:39 +0200 | |
changeset 47216 | 71c04702a3d5 |
parent 38321 | jdk/test/java/nio/Buffer/Order.java@ff5b89346438 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
37913 | 2 |
* Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
5506 | 19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
2 | 22 |
*/ |
23 |
||
24 |
/* @test |
|
31723
2e16a59cc5cb
8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents:
5506
diff
changeset
|
25 |
* @bug 8065570 |
2 | 26 |
* @summary Unit test for X-Buffer.order methods |
27 |
*/ |
|
28 |
||
29 |
import java.nio.*; |
|
30 |
||
31 |
||
32 |
public class Order { |
|
33 |
||
34 |
static final ByteOrder be = ByteOrder.BIG_ENDIAN; |
|
35 |
static final ByteOrder le = ByteOrder.LITTLE_ENDIAN; |
|
36 |
static final ByteOrder nord = ByteOrder.nativeOrder(); |
|
37 |
||
31723
2e16a59cc5cb
8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents:
5506
diff
changeset
|
38 |
protected static final int LENGTH = 16; |
2e16a59cc5cb
8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents:
5506
diff
changeset
|
39 |
|
2 | 40 |
static void ck(ByteOrder ord, ByteOrder expected) { |
41 |
if (ord != expected) |
|
37913 | 42 |
throw new RuntimeException("Got " + ord + ", expected " + expected); |
2 | 43 |
} |
44 |
||
37913 | 45 |
private static void ckViews(ByteBuffer bb) { |
2 | 46 |
ck(bb.asCharBuffer().order(), bb.order()); |
37913 | 47 |
ck(bb.asShortBuffer().order(), bb.order()); |
2 | 48 |
ck(bb.asIntBuffer().order(), bb.order()); |
49 |
ck(bb.asLongBuffer().order(), bb.order()); |
|
50 |
ck(bb.asFloatBuffer().order(), bb.order()); |
|
51 |
ck(bb.asDoubleBuffer().order(), bb.order()); |
|
52 |
} |
|
53 |
||
38321
ff5b89346438
8150785: (bf) Hoist slice and duplicate methods up to java.nio.Buffer
prappo
parents:
37913
diff
changeset
|
54 |
private static void ckCopyViews(ByteBuffer bb) { |
ff5b89346438
8150785: (bf) Hoist slice and duplicate methods up to java.nio.Buffer
prappo
parents:
37913
diff
changeset
|
55 |
ck(bb.asReadOnlyBuffer().order(), be); |
ff5b89346438
8150785: (bf) Hoist slice and duplicate methods up to java.nio.Buffer
prappo
parents:
37913
diff
changeset
|
56 |
ck(bb.duplicate().order(), be); |
ff5b89346438
8150785: (bf) Hoist slice and duplicate methods up to java.nio.Buffer
prappo
parents:
37913
diff
changeset
|
57 |
ck(bb.slice().order(), be); |
ff5b89346438
8150785: (bf) Hoist slice and duplicate methods up to java.nio.Buffer
prappo
parents:
37913
diff
changeset
|
58 |
} |
ff5b89346438
8150785: (bf) Hoist slice and duplicate methods up to java.nio.Buffer
prappo
parents:
37913
diff
changeset
|
59 |
|
37913 | 60 |
private static void ckByteBuffer(ByteBuffer bb) { |
61 |
ckViews(bb); |
|
38321
ff5b89346438
8150785: (bf) Hoist slice and duplicate methods up to java.nio.Buffer
prappo
parents:
37913
diff
changeset
|
62 |
ckCopyViews(bb); |
2 | 63 |
bb.order(be); |
37913 | 64 |
ckViews(bb); |
38321
ff5b89346438
8150785: (bf) Hoist slice and duplicate methods up to java.nio.Buffer
prappo
parents:
37913
diff
changeset
|
65 |
ckCopyViews(bb); |
2 | 66 |
bb.order(le); |
37913 | 67 |
ckViews(bb); |
38321
ff5b89346438
8150785: (bf) Hoist slice and duplicate methods up to java.nio.Buffer
prappo
parents:
37913
diff
changeset
|
68 |
ckCopyViews(bb); |
2 | 69 |
} |
70 |
||
71 |
public static void main(String args[]) throws Exception { |
|
72 |
||
38321
ff5b89346438
8150785: (bf) Hoist slice and duplicate methods up to java.nio.Buffer
prappo
parents:
37913
diff
changeset
|
73 |
ck(ByteBuffer.wrap(new byte[LENGTH], LENGTH/2, LENGTH/2).order(), be); |
ff5b89346438
8150785: (bf) Hoist slice and duplicate methods up to java.nio.Buffer
prappo
parents:
37913
diff
changeset
|
74 |
ck(ByteBuffer.wrap(new byte[LENGTH]).order(), be); |
ff5b89346438
8150785: (bf) Hoist slice and duplicate methods up to java.nio.Buffer
prappo
parents:
37913
diff
changeset
|
75 |
ck(ByteBuffer.wrap(new byte[LENGTH], LENGTH/2, LENGTH/2).order(be).order(), be); |
ff5b89346438
8150785: (bf) Hoist slice and duplicate methods up to java.nio.Buffer
prappo
parents:
37913
diff
changeset
|
76 |
ck(ByteBuffer.wrap(new byte[LENGTH]).order(be).order(), be); |
ff5b89346438
8150785: (bf) Hoist slice and duplicate methods up to java.nio.Buffer
prappo
parents:
37913
diff
changeset
|
77 |
ck(ByteBuffer.wrap(new byte[LENGTH], LENGTH/2, LENGTH/2).order(le).order(), le); |
ff5b89346438
8150785: (bf) Hoist slice and duplicate methods up to java.nio.Buffer
prappo
parents:
37913
diff
changeset
|
78 |
ck(ByteBuffer.wrap(new byte[LENGTH]).order(le).order(), le); |
31723
2e16a59cc5cb
8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents:
5506
diff
changeset
|
79 |
ck(ByteBuffer.allocate(LENGTH).order(), be); |
2e16a59cc5cb
8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents:
5506
diff
changeset
|
80 |
ck(ByteBuffer.allocateDirect(LENGTH).order(), be); |
2e16a59cc5cb
8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents:
5506
diff
changeset
|
81 |
ck(ByteBuffer.allocate(LENGTH).order(be).order(), be); |
2e16a59cc5cb
8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents:
5506
diff
changeset
|
82 |
ck(ByteBuffer.allocate(LENGTH).order(le).order(), le); |
37913 | 83 |
ck(ByteBuffer.allocateDirect(LENGTH).order(be).order(), be); |
84 |
ck(ByteBuffer.allocateDirect(LENGTH).order(le).order(), le); |
|
2 | 85 |
|
31723
2e16a59cc5cb
8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents:
5506
diff
changeset
|
86 |
ckByteBuffer(ByteBuffer.allocate(LENGTH)); |
2e16a59cc5cb
8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents:
5506
diff
changeset
|
87 |
ckByteBuffer(ByteBuffer.allocateDirect(LENGTH)); |
2 | 88 |
|
31723
2e16a59cc5cb
8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents:
5506
diff
changeset
|
89 |
OrderChar.ckCharBuffer(); |
2e16a59cc5cb
8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents:
5506
diff
changeset
|
90 |
OrderShort.ckShortBuffer(); |
2e16a59cc5cb
8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents:
5506
diff
changeset
|
91 |
OrderInt.ckIntBuffer(); |
2e16a59cc5cb
8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents:
5506
diff
changeset
|
92 |
OrderLong.ckLongBuffer(); |
2e16a59cc5cb
8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents:
5506
diff
changeset
|
93 |
OrderFloat.ckFloatBuffer(); |
2e16a59cc5cb
8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents:
5506
diff
changeset
|
94 |
OrderDouble.ckDoubleBuffer(); |
2 | 95 |
} |
96 |
} |