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 */ 16 17package org.apache.harmony.tests.java.nio; 18 19import java.nio.ByteBuffer; 20 21public class WrappedByteBufferTest extends ByteBufferTest { 22 23 protected void setUp() throws Exception { 24 super.setUp(); 25 buf = ByteBuffer.wrap(new byte[BUFFER_LENGTH]); 26 baseBuf = buf; 27 } 28 29 protected void tearDown() throws Exception { 30 super.tearDown(); 31 buf = null; 32 baseBuf = null; 33 } 34 35 /** 36 * @tests java.nio.ByteBuffer#allocate(byte[],int,int) 37 * 38 */ 39 public void testWrappedByteBuffer_IllegalArg() { 40 byte array[] = new byte[BUFFER_LENGTH]; 41 try { 42 ByteBuffer.wrap(array, -1, 0); 43 fail("Should throw Exception"); //$NON-NLS-1$ 44 } catch (IndexOutOfBoundsException e) { 45 // expected 46 } 47 try { 48 ByteBuffer.wrap(array, BUFFER_LENGTH + 1, 0); 49 fail("Should throw Exception"); //$NON-NLS-1$ 50 } catch (IndexOutOfBoundsException e) { 51 // expected 52 } 53 try { 54 ByteBuffer.wrap(array, 0, -1); 55 fail("Should throw Exception"); //$NON-NLS-1$ 56 } catch (IndexOutOfBoundsException e) { 57 // expected 58 } 59 try { 60 ByteBuffer.wrap(array, 0, BUFFER_LENGTH + 1); 61 fail("Should throw Exception"); //$NON-NLS-1$ 62 } catch (IndexOutOfBoundsException e) { 63 // expected 64 } 65 try { 66 ByteBuffer.wrap(array, 1, Integer.MAX_VALUE); 67 fail("Should throw Exception"); //$NON-NLS-1$ 68 } catch (IndexOutOfBoundsException e) { 69 // expected 70 } 71 try { 72 ByteBuffer.wrap(array, Integer.MAX_VALUE, 1); 73 fail("Should throw Exception"); //$NON-NLS-1$ 74 } catch (IndexOutOfBoundsException e) { 75 // expected 76 } 77 try { 78 ByteBuffer.wrap((byte[])null, 1, Integer.MAX_VALUE); 79 fail("Should throw Exception"); //$NON-NLS-1$ 80 } catch (NullPointerException e) { 81 // expected 82 } 83 } 84 85 public void testIsDirect() { 86 assertFalse(buf.isDirect()); 87 } 88 89 public void testHasArray() { 90 assertTrue(buf.hasArray()); 91 } 92 93 public void testIsReadOnly() { 94 assertFalse(buf.isReadOnly()); 95 } 96 97} 98