1dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes/* Licensed to the Apache Software Foundation (ASF) under one or more 2dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes * contributor license agreements. See the NOTICE file distributed with 3dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes * this work for additional information regarding copyright ownership. 4dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes * The ASF licenses this file to You under the Apache License, Version 2.0 5dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes * (the "License"); you may not use this file except in compliance with 6dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes * the License. You may obtain a copy of the License at 7dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes * 8dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes * http://www.apache.org/licenses/LICENSE-2.0 9dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes * 10dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes * Unless required by applicable law or agreed to in writing, software 11dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes * distributed under the License is distributed on an "AS IS" BASIS, 12dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes * See the License for the specific language governing permissions and 14dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes * limitations under the License. 15dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes */ 16dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes 17e5fea3d504609d22337a5311d3ce0e72314bceeeNarayan Kamathpackage org.apache.harmony.tests.java.nio; 18dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes 19dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughesimport java.nio.CharBuffer; 20dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes 21dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughespublic class WrappedCharBufferTest1 extends CharBufferTest { 22dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes 23dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes protected void setUp() throws Exception { 24dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes super.setUp(); 25dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes buf = CharBuffer.wrap(new char[BUFFER_LENGTH]); 26dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes loadTestData1(buf); 27dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes baseBuf = buf; 28dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes } 29dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes 30dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes protected void tearDown() throws Exception { 31dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes super.tearDown(); 32dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes baseBuf = null; 33dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes buf = null; 34dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes } 35dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes 36dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes /** 37dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes * @tests java.nio.CharBuffer#allocate(char[],int,int) 38dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes * 39dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes */ 40dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes public void testWrappedCharBuffer_IllegalArg() { 41dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes char array[] = new char[BUFFER_LENGTH]; 42dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes try { 43dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes CharBuffer.wrap(array, -1, 0); 44dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes fail("Should throw Exception"); //$NON-NLS-1$ 45dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes } catch (IndexOutOfBoundsException e) { 46dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes // expected 47dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes } 48dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes try { 49dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes CharBuffer.wrap(array, BUFFER_LENGTH + 1, 0); 50dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes fail("Should throw Exception"); //$NON-NLS-1$ 51dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes } catch (IndexOutOfBoundsException e) { 52dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes // expected 53dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes } 54dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes try { 55dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes CharBuffer.wrap(array, 0, -1); 56dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes fail("Should throw Exception"); //$NON-NLS-1$ 57dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes } catch (IndexOutOfBoundsException e) { 58dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes // expected 59dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes } 60dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes try { 61dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes CharBuffer.wrap(array, 0, BUFFER_LENGTH + 1); 62dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes fail("Should throw Exception"); //$NON-NLS-1$ 63dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes } catch (IndexOutOfBoundsException e) { 64dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes // expected 65dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes } 66dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes try { 67dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes CharBuffer.wrap(array, Integer.MAX_VALUE, 1); 68dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes fail("Should throw Exception"); //$NON-NLS-1$ 69dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes } catch (IndexOutOfBoundsException e) { 70dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes // expected 71dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes } 72dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes try { 73dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes CharBuffer.wrap(array, 1, Integer.MAX_VALUE); 74dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes fail("Should throw Exception"); //$NON-NLS-1$ 75dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes } catch (IndexOutOfBoundsException e) { 76dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes // expected 77dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes } 78dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes try { 79dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes CharBuffer.wrap((char[])null, -1, 0); 80dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes fail("Should throw NPE"); //$NON-NLS-1$ 81dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes } catch (NullPointerException e) { 82dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes } 83dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes } 84dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes} 85