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 */ 16package org.apache.harmony.tests.java.nio; 17 18import java.nio.ByteBuffer; 19import java.nio.ByteOrder; 20import java.nio.DirectByteBuffer; 21import java.nio.DoubleBuffer; 22import java.nio.NIOAccess; 23import libcore.io.SizeOf; 24 25public class DirectDoubleBufferTest extends DoubleBufferTest { 26 public void setUp(){ 27 buf = ByteBuffer.allocateDirect(BUFFER_LENGTH*8).asDoubleBuffer(); 28 loadTestData1(buf); 29 baseBuf = buf; 30 } 31 32 public void tearDown(){ 33 buf = null; 34 baseBuf = null; 35 } 36 37 public void testHasArray() { 38 assertFalse(buf.hasArray()); 39 } 40 41 public void testArray() { 42 try { 43 buf.array(); 44 fail("Should throw UnsupportedOperationException"); //$NON-NLS-1$ 45 } catch (UnsupportedOperationException e) { 46 } 47 } 48 49 public void testArrayOffset() { 50 try { 51 buf.arrayOffset(); 52 fail("Should throw UnsupportedOperationException"); //$NON-NLS-1$ 53 } catch (UnsupportedOperationException e) { 54 } 55 } 56 57 // http://b/28964300 58 public void testJNIAccessByAddress() throws Exception { 59 DirectByteBuffer directByteBuffer = (DirectByteBuffer) ByteBuffer.allocateDirect(10); 60 directByteBuffer.put((byte)'a'); 61 DoubleBuffer doubleBuffer = directByteBuffer.asDoubleBuffer(); 62 long byteBufferBasePointer = NIOAccess.getBasePointer(directByteBuffer); 63 long doubleBufferBasePointer = NIOAccess.getBasePointer(doubleBuffer); 64 assertEquals(byteBufferBasePointer, doubleBufferBasePointer); 65 66 // Check if the NIOAccess method adds up the current position value. 67 doubleBuffer.put(1.0); 68 assertEquals(doubleBufferBasePointer + SizeOf.DOUBLE, NIOAccess.getBasePointer(doubleBuffer)); 69 } 70 71 public void testIsDirect() { 72 assertTrue(buf.isDirect()); 73 } 74 75 public void testOrder() { 76 assertEquals(ByteOrder.BIG_ENDIAN, buf.order()); 77 } 78} 79