Elliott Hughes | dce2b2f | 2013-04-26 16:15:14 -0700 | [diff] [blame] | 1 | /* 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 Kamath | e5fea3d | 2013-11-15 11:02:26 +0000 | [diff] [blame] | 16 | package org.apache.harmony.tests.java.nio; |
Elliott Hughes | dce2b2f | 2013-04-26 16:15:14 -0700 | [diff] [blame] | 17 | |
| 18 | import java.nio.ByteBuffer; |
| 19 | import java.nio.ByteOrder; |
Shubham Ajmera | e0f383f | 2016-06-06 17:50:16 +0100 | [diff] [blame] | 20 | import java.nio.DirectByteBuffer; |
| 21 | import java.nio.DoubleBuffer; |
| 22 | import java.nio.NIOAccess; |
Elliott Hughes | dce2b2f | 2013-04-26 16:15:14 -0700 | [diff] [blame] | 23 | |
| 24 | public 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 Ajmera | e0f383f | 2016-06-06 17:50:16 +0100 | [diff] [blame] | 56 | // 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 Thierer | 229d4b2 | 2019-01-21 10:34:01 +0000 | [diff] [blame^] | 67 | assertEquals(doubleBufferBasePointer + Double.BYTES, NIOAccess.getBasePointer(doubleBuffer)); |
Shubham Ajmera | e0f383f | 2016-06-06 17:50:16 +0100 | [diff] [blame] | 68 | } |
| 69 | |
Elliott Hughes | dce2b2f | 2013-04-26 16:15:14 -0700 | [diff] [blame] | 70 | public void testIsDirect() { |
| 71 | assertTrue(buf.isDirect()); |
| 72 | } |
| 73 | |
| 74 | public void testOrder() { |
| 75 | assertEquals(ByteOrder.BIG_ENDIAN, buf.order()); |
| 76 | } |
| 77 | } |