blob: dff392b8b90131765fcab64ff97a9015b698cd47 [file] [log] [blame]
Elliott Hughesdce2b2f2013-04-26 16:15:14 -07001/* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Narayan Kamathe5fea3d2013-11-15 11:02:26 +000016package org.apache.harmony.tests.java.nio;
Elliott Hughesdce2b2f2013-04-26 16:15:14 -070017
18import java.nio.ByteBuffer;
19import java.nio.ByteOrder;
Shubham Ajmerae0f383f2016-06-06 17:50:16 +010020import java.nio.DirectByteBuffer;
21import java.nio.DoubleBuffer;
22import java.nio.NIOAccess;
Elliott Hughesdce2b2f2013-04-26 16:15:14 -070023
24public class DirectDoubleBufferTest extends DoubleBufferTest {
25 public void setUp(){
26 buf = ByteBuffer.allocateDirect(BUFFER_LENGTH*8).asDoubleBuffer();
27 loadTestData1(buf);
28 baseBuf = buf;
29 }
30
31 public void tearDown(){
32 buf = null;
33 baseBuf = null;
34 }
35
36 public void testHasArray() {
37 assertFalse(buf.hasArray());
38 }
39
40 public void testArray() {
41 try {
42 buf.array();
43 fail("Should throw UnsupportedOperationException"); //$NON-NLS-1$
44 } catch (UnsupportedOperationException e) {
45 }
46 }
47
48 public void testArrayOffset() {
49 try {
50 buf.arrayOffset();
51 fail("Should throw UnsupportedOperationException"); //$NON-NLS-1$
52 } catch (UnsupportedOperationException e) {
53 }
54 }
55
Shubham Ajmerae0f383f2016-06-06 17:50:16 +010056 // http://b/28964300
57 public void testJNIAccessByAddress() throws Exception {
58 DirectByteBuffer directByteBuffer = (DirectByteBuffer) ByteBuffer.allocateDirect(10);
59 directByteBuffer.put((byte)'a');
60 DoubleBuffer doubleBuffer = directByteBuffer.asDoubleBuffer();
61 long byteBufferBasePointer = NIOAccess.getBasePointer(directByteBuffer);
62 long doubleBufferBasePointer = NIOAccess.getBasePointer(doubleBuffer);
63 assertEquals(byteBufferBasePointer, doubleBufferBasePointer);
64
65 // Check if the NIOAccess method adds up the current position value.
66 doubleBuffer.put(1.0);
Tobias Thierer229d4b22019-01-21 10:34:01 +000067 assertEquals(doubleBufferBasePointer + Double.BYTES, NIOAccess.getBasePointer(doubleBuffer));
Shubham Ajmerae0f383f2016-06-06 17:50:16 +010068 }
69
Elliott Hughesdce2b2f2013-04-26 16:15:14 -070070 public void testIsDirect() {
71 assertTrue(buf.isDirect());
72 }
73
74 public void testOrder() {
75 assertEquals(ByteOrder.BIG_ENDIAN, buf.order());
76 }
77}